Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/crutkas/white space #10

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public static bool IsMSIX
// TODO! for whatever reason, when I ported this into the PT
// codebase, this no longer compiled. We're only ever using it for
// the hacked up settings and ignoring it anyways, so I'm leaving
// it commented out for now.
//
// it commented out for now.
//
// See also:
// * https://github.com/microsoft/win32metadata/commit/6fee67ba73bfe1b126ce524f7de8d367f0317715
// * https://github.com/microsoft/win32metadata/issues/1311
//uint length = 0;
//return PInvoke.GetCurrentPackageFullName(ref length, null) != WIN32_ERROR.APPMODEL_ERROR_NO_PACKAGE;
// uint length = 0;
// return PInvoke.GetCurrentPackageFullName(ref length, null) != WIN32_ERROR.APPMODEL_ERROR_NO_PACKAGE;
#pragma warning disable IDE0025 // Use expression body for property
return true;
#pragma warning restore IDE0025 // Use expression body for property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class LocalSettingsService : ILocalSettingsService

public LocalSettingsService(IFileService fileService, IOptions<LocalSettingsOptions> options)
{
_isMsix = false;// RuntimeHelper.IsMSIX;
_isMsix = false; // RuntimeHelper.IsMSIX;

_fileService = fileService;
_options = options.Value;
Expand Down Expand Up @@ -91,8 +91,10 @@ public async Task<bool> HasSettingAsync(string key)
if (_settings != null && _settings.TryGetValue(key, out var obj))
{
var s = obj.ToString();
if (s !=null)
if (s != null)
{
return await Json.ToObjectAsync<T>(s);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/cmdpal/src/WindowsCommandPalette/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ public App()

//// Main window: Allow access to the main window
//// from anywhere in the application.
//services.AddSingleton(_ => MainWindow);
// services.AddSingleton(_ => MainWindow);

//// DispatcherQueue: Allow access to the DispatcherQueue for
//// the main window for general purpose UI thread access.
//services.AddSingleton(_ => MainWindow.DispatcherQueue);
// services.AddSingleton(_ => MainWindow.DispatcherQueue);

// Configuration
services.Configure<LocalSettingsOptions>(context.Configuration.GetSection(nameof(LocalSettingsOptions)));
Expand Down
26 changes: 13 additions & 13 deletions src/modules/cmdpal/src/WindowsCommandPalette/BookmarkActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ public override ActionResult SubmitForm(string payload)
bookmarkType = "web";
}



// Construct a new json blob with the name and url
var json = "";

Expand All @@ -161,9 +159,13 @@ public override ActionResult SubmitForm(string payload)
var newItem = new JsonObject();
newItem["name"] = formName;
newItem["bookmark"] = formBookmark;
var formData = new BookmarkData() { name = formName.ToString(), bookmark=formBookmark.ToString(), type = bookmarkType };
var formData = new BookmarkData()
{
name = formName.ToString(),
bookmark = formBookmark.ToString(),
type = bookmarkType,
};
items.Add(JsonSerializer.SerializeToNode(formData, typeof(BookmarkData), SourceGenerationContext.Default));
//items.Add(newItem);
json = jsonState?.ToString();
}
}
Expand Down Expand Up @@ -490,21 +492,19 @@ public IListItem[] TopLevelCommands()
new CommandContextItem(new OpenInTerminalAction(urlAction.Url))
];
}
//listItem.Subtitle = "Bookmark";

// listItem.Subtitle = "Bookmark";
if (action is AddBookmarkPage) { }
else
{
listItem.Tags = [
new Tag() {
new Tag()
{
Text = "Bookmark",
//Icon = new("🔗"),
//Color=Windows.UI.Color.FromArgb(255, 255, 0, 255)

// Icon = new("🔗"),
// Color=Windows.UI.Color.FromArgb(255, 255, 0, 255)
},
//new Tag() {
// Text = "A test",
// //Icon = new("🔗"),
// Color=Windows.UI.Color.FromArgb(255, 255, 0, 0)
//}
];
}

Expand Down
12 changes: 6 additions & 6 deletions src/modules/cmdpal/src/WindowsCommandPalette/FormPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public FormViewModel(IForm form)

internal void InitialRender()
{
//var t = new Task<bool>(() => {
// var t = new Task<bool>(() => {
this.TemplateJson = this.form.TemplateJson();
try
{
Expand All @@ -45,11 +45,11 @@ internal void InitialRender()
{
this.DataJson = "{}";
}
//return true;
//});
//t.Start();
//await t;

// return true;
// });
// t.Start();
// await t;
AdaptiveCardTemplate template = new(TemplateJson);
var cardJson = template.Expand(DataJson);
this.card = AdaptiveCard.FromJsonString(cardJson);
Expand Down Expand Up @@ -138,7 +138,7 @@ public FormPage()
// yep it's this dumb
var foreground = settings.GetColorValue(UIColorType.Foreground);
var lightTheme = foreground.R < 128;
Renderer.HostConfig = AdaptiveHostConfig.FromJsonString(lightTheme? LightHostConfig : DarkHostConfig).HostConfig;
Renderer.HostConfig = AdaptiveHostConfig.FromJsonString(lightTheme ? LightHostConfig : DarkHostConfig).HostConfig;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,35 @@ namespace DeveloperCommandPalette;
public sealed class ListItemViewModel : INotifyPropertyChanged, IDisposable
{
private readonly DispatcherQueue DispatcherQueue;

internal IListItem ListItem { get; init; }

internal string Title { get; private set; }

internal string Subtitle { get; private set; }

internal string Icon { get; private set; }

internal Lazy<DetailsViewModel?> _Details;

internal DetailsViewModel? Details => _Details.Value;

internal IFallbackHandler? FallbackHandler => this.ListItem.FallbackHandler;

public event PropertyChangedEventHandler? PropertyChanged;

internal ICommand DefaultAction => ListItem.Command;

internal bool CanInvoke => DefaultAction != null && DefaultAction is IInvokableCommand or IPage;

internal IconElement IcoElement => Microsoft.Terminal.UI.IconPathConverter.IconMUX(Icon);

private IEnumerable<ICommandContextItem> contextActions => ListItem.MoreCommands == null ? [] : ListItem.MoreCommands.Where(i => i is ICommandContextItem).Select(i=> (ICommandContextItem)i);
private IEnumerable<ICommandContextItem> contextActions => ListItem.MoreCommands == null ? [] : ListItem.MoreCommands.Where(i => i is ICommandContextItem).Select(i => (ICommandContextItem)i);

internal bool HasMoreCommands => contextActions.Any();

internal TagViewModel[] Tags = [];

internal bool HasTags => Tags.Length > 0;

internal IList<ContextItemViewModel> ContextActions
Expand Down
56 changes: 31 additions & 25 deletions src/modules/cmdpal/src/WindowsCommandPalette/ListPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public SectionInfoList(ISection? section, IEnumerable<ListItemViewModel> items)
observable.CollectionChanged -= Items_CollectionChanged;
observable.CollectionChanged += Items_CollectionChanged;
}

if (this.DispatcherQueue == null)
{
throw new InvalidOperationException("DispatcherQueue is null");
Expand All @@ -50,7 +51,7 @@ public SectionInfoList(ISection? section, IEnumerable<ListItemViewModel> items)

private void Items_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
//DispatcherQueue.TryEnqueue(() => {
// DispatcherQueue.TryEnqueue(() => {
if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null)
{
foreach (var i in e.NewItems)
Expand All @@ -63,26 +64,29 @@ private void Items_CollectionChanged(object? sender, NotifyCollectionChangedEven
this.Add(vm);

}
//if (isDynamic)
//{

// if (isDynamic)
// {
// // Dynamic lists are in charge of their own
// // filtering. They know if this thing was already
// // filtered or not.
// FilteredItems.Add(vm);
//}
// }
}
}
}
else if (e.Action == NotifyCollectionChangedAction.Reset)
{
this.Clear();
//Items.Clear();
//if (isDynamic)
//{

// Items.Clear();
// if (isDynamic)
// {
// FilteredItems.Clear();
//}
// }
}
//});

// });
}
}

Expand Down Expand Up @@ -145,9 +149,8 @@ internal async Task UpdateListItems()
// we already have, then rebuilding it. We shouldn't do that. We should
// still use the results from GetItems and put them into the code in
// UpdateFilter to intelligently add/remove as needed.
//Items.Clear();
//FilteredItems.Clear();

// Items.Clear();
// FilteredItems.Clear();
Collection<SectionInfoList> newItems = new();

var size = sections.Length;
Expand All @@ -157,19 +160,20 @@ internal async Task UpdateListItems()
var sectionItems = new SectionInfoList(
section,
section.Items
.Where(i=>i!= null && !string.IsNullOrEmpty(i.Title))
.Where(i => i != null && !string.IsNullOrEmpty(i.Title))
.Select(i => new ListItemViewModel(i))
);

// var items = section.Items;
// for (var i = 0; i < items.Length; i++) {
// ListItemViewModel vm = new(items[i]);
// Items.Add(vm);
// FilteredItems.Add(vm);
// }

newItems.Add(sectionItems);
//Items.Add(sectionItems);
//FilteredItems.Add(sectionItems);

// Items.Add(sectionItems);
// FilteredItems.Add(sectionItems);
}

ListHelpers.InPlaceUpdateList(Items, newItems);
Expand Down Expand Up @@ -197,7 +201,7 @@ internal async Task<Collection<SectionInfoList>> GetFilteredItems(string query)
}

//// TODO! Probably bad that this turns list view models into listitems back to NEW view models
//return ListHelpers.FilterList(Items.Select(vm => vm.ListItem), Query).Select(li => new ListItemViewModel(li)).ToList();
// return ListHelpers.FilterList(Items.Select(vm => vm.ListItem), Query).Select(li => new ListItemViewModel(li)).ToList();
var allFilteredItems = ListHelpers.FilterList(Items.SelectMany(section => section).Select(vm => vm.ListItem), Query).Select(li => new ListItemViewModel(li));
var newSection = new SectionInfoList(null, allFilteredItems);
return [newSection];
Expand Down Expand Up @@ -306,9 +310,9 @@ private void ListItem_Tapped(object sender, TappedRoutedEventArgs e)
if (sender is not ListViewItem listItem) return;
if (listItem.DataContext is not ListItemViewModel li) return;
_ = li;
// For a bit I had double-clicks Invoke and single just select, but that crashes?
//ItemsList.SelectedItem = listItem;

// For a bit I had double-clicks Invoke and single just select, but that crashes?
// ItemsList.SelectedItem = listItem;
if (li.DefaultAction != null)
{
DoAction(new(li.DefaultAction));
Expand All @@ -317,12 +321,12 @@ private void ListItem_Tapped(object sender, TappedRoutedEventArgs e)

private void ListViewItem_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
{
//if (sender is not ListViewItem listItem) return;
//if (listItem.DataContext is not ListItemViewModel li) return;
//if (li.DefaultAction != null)
//{
// if (sender is not ListViewItem listItem) return;
// if (listItem.DataContext is not ListItemViewModel li) return;
// if (li.DefaultAction != null)
// {
// DoAction(new(li.DefaultAction));
//}
// }
}

private void ItemsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down Expand Up @@ -431,9 +435,11 @@ private async Task UpdateFilter(string text)
// into us initially. We handle the filtering of these ones. Commands
// from async querying happens later.
var newMatches = await ViewModel.GetFilteredItems(text);

// this.ItemsCVS.Source = ViewModel.FilteredItems;
// Returns back on the UI thread
ListHelpers.InPlaceUpdateList(ViewModel.FilteredItems, newMatches);

// for (var i = 0; i < ViewModel.FilteredItems.Count && i < newMatches.Count; i++)
// {
// for (var j = i; j < ViewModel.FilteredItems.Count; j++)
Expand All @@ -448,7 +454,7 @@ private async Task UpdateFilter(string text)
// }
// }

// if (ViewModel.FilteredItems[i] != newMatches[i])
// if (ViewModel.FilteredItems[i] != newMatches[i])
// {
// ViewModel.FilteredItems.Insert(i, newMatches[i]);
// }
Expand Down
4 changes: 2 additions & 2 deletions src/modules/cmdpal/src/WindowsCommandPalette/MainListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
using Microsoft.Windows.CommandPalette.Extensions.Helpers;
using Microsoft.Windows.CommandPalette.Extensions;
using Windows.Foundation;
//using Quicklinks;
//using Scripts;

namespace DeveloperCommandPalette;

public sealed class MainListItem : ListItem
{
private readonly IListItem _listItem;

public IListItem Item => _listItem;

internal MainListItem(IListItem listItem) : base(listItem.Command)
{
_listItem = listItem;
Expand Down
9 changes: 5 additions & 4 deletions src/modules/cmdpal/src/WindowsCommandPalette/MainListPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ public MainListSection(MainViewModel viewModel)
{
this._mainViewModel = viewModel;
_Items = new(_mainViewModel.TopLevelCommands.Select(a => new MainListItem(a)));
_Items.CollectionChanged += Bubble_CollectionChanged; ;
_Items.CollectionChanged += Bubble_CollectionChanged;
}

internal void UpdateQuery(string query)
{
var fallbacks = _Items.Select(i => i?.FallbackHandler).Where(fb => fb != null).Select(fb=>fb!);
var fallbacks = _Items.Select(i => i?.FallbackHandler).Where(fb => fb != null).Select(fb => fb!);
foreach (var fb in fallbacks)
{
fb.UpdateQuery(query);
Expand All @@ -118,6 +118,7 @@ private void Bubble_CollectionChanged(object? sender, NotifyCollectionChangedEve
CollectionChanged?.Invoke(this, e);
});
}

internal void Reset()
{
_Items.Clear();
Expand Down Expand Up @@ -189,7 +190,7 @@ internal string Query
//
// instead run the query once when the action query changes, and store the
// results.
public IListItem[] Items => itemsToEnumerate.Where(i => i!= null).ToArray();
public IListItem[] Items => itemsToEnumerate.Where(i => i != null).ToArray();


public FilteredListSection(MainViewModel viewModel)
Expand Down Expand Up @@ -224,7 +225,7 @@ public sealed class MainListPage : Microsoft.Windows.CommandPalette.Extensions.H

public MainListPage(MainViewModel viewModel)
{
this._mainViewModel= viewModel;
this._mainViewModel = viewModel;

_mainSection = new(_mainViewModel);
_recentsListSection = new(_mainViewModel);
Expand Down
Loading