more stuff

This commit is contained in:
Clint Rutkas
2024-09-03 23:26:20 -07:00
parent c212c9cbad
commit c2a47aed27
4 changed files with 97 additions and 34 deletions

View File

@@ -295,7 +295,6 @@ internal sealed class BookmarkPlaceholderForm: Microsoft.Windows.CommandPalette.
try
{
Uri? uri = UrlAction.GetUri(target);
if (uri != null)
{
@@ -430,12 +429,10 @@ public class BookmarksActionProvider : ICommandProvider
public BookmarksActionProvider()
{
_addNewCommand.AddedAction += _addNewCommand_AddedAction;
}
private void _addNewCommand_AddedAction(object sender, object? args)
{
_addNewCommand.AddedAction += _addNewCommand_AddedAction;
_commands.Clear();
}
@@ -465,8 +462,12 @@ public class BookmarksActionProvider : ICommandProvider
{
return;
}
var itemsJson = jsonObject["items"]?.AsArray();
if (itemsJson == null) { return; }
if (itemsJson == null)
{
return;
}
foreach (var item in itemsJson)
{
@@ -541,12 +542,11 @@ public class BookmarksActionProvider : ICommandProvider
{
// Get the path to our exe
var path = System.Reflection.Assembly.GetExecutingAssembly().Location;
// Get the directory of the exe
var directory = System.IO.Path.GetDirectoryName(path) ?? string.Empty;
// now, the state is just next to the exe
return System.IO.Path.Combine(directory, "state.json");
}
}

View File

@@ -13,9 +13,8 @@ namespace DeveloperCommandPalette;
// cribbed heavily from
//
// https://github.com/microsoft/WindowsAppSDK-Samples/tree/main/Samples/AppLifecycle/Instancing/cs2/cs-winui-packaged/CsWinUiDesktopInstancing
sealed class Program
sealed class Program
{
private static App? app;
// LOAD BEARING

View File

@@ -58,7 +58,6 @@ public class SectionInfoList : ObservableCollection<ListItemViewModel>
private void Items_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
// DispatcherQueue.TryEnqueue(() => {
if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null)
{
foreach (var i in e.NewItems)
@@ -98,7 +97,10 @@ public class SectionInfoList : ObservableCollection<ListItemViewModel>
public sealed class NoOpAction : InvokableCommand
{
public override ICommandResult Invoke() { return ActionResult.KeepOpen(); }
public override ICommandResult Invoke()
{
return ActionResult.KeepOpen();
}
}
public sealed class ErrorListItem : Microsoft.Windows.CommandPalette.Extensions.Helpers.ListItem
@@ -196,7 +198,6 @@ public sealed class ListPageViewModel : PageViewModel
internal async Task<Collection<SectionInfoList>> GetFilteredItems(string query)
{
if (query == Query)
{
return FilteredItems;
@@ -294,7 +295,10 @@ public sealed partial class ListPage : Page, System.ComponentModel.INotifyProper
{
base.OnNavigatedTo(e);
ViewModel = (ListPageViewModel?)e.Parameter;
if (ViewModel == null) return;
if (ViewModel == null)
{
return;
}
if (e.NavigationMode == NavigationMode.New)
{
@@ -302,7 +306,6 @@ public sealed partial class ListPage : Page, System.ComponentModel.INotifyProper
{
DispatcherQueue.TryEnqueue(async () => { await UpdateFilter(FilterBox.Text); });
});
}
else
{
@@ -320,8 +323,16 @@ public sealed partial class ListPage : Page, System.ComponentModel.INotifyProper
private void ListItem_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (sender is not ListViewItem listItem) return;
if (listItem.DataContext is not ListItemViewModel li) return;
if (sender is not ListViewItem listItem)
{
return;
}
if (listItem.DataContext is not ListItemViewModel li)
{
return;
}
if (e.OriginalKey == Windows.System.VirtualKey.Enter)
{
if (li.DefaultAction != null)
@@ -366,15 +377,31 @@ public sealed partial class ListPage : Page, System.ComponentModel.INotifyProper
private void ItemsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is not ListView lv) return;
if (lv.SelectedItem is not ListItemViewModel li) return;
if (sender is not ListView lv)
{
return;
}
if (lv.SelectedItem is not ListItemViewModel li)
{
return;
}
SelectedItem = li;
}
private void ActionListViewItem_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (sender is not ListViewItem listItem) return;
if (listItem.DataContext is not ContextItemViewModel vm) return;
if (sender is not ListViewItem listItem)
{
return;
}
if (listItem.DataContext is not ContextItemViewModel vm)
{
return;
}
if (e.Key == Windows.System.VirtualKey.Enter || e.Key == Windows.System.VirtualKey.Space)
{
DoAction(new(vm.Command));
@@ -384,8 +411,16 @@ public sealed partial class ListPage : Page, System.ComponentModel.INotifyProper
private void ActionListViewItem_Tapped(object sender, TappedRoutedEventArgs e)
{
if (sender is not ListViewItem listItem) return;
if (listItem.DataContext is not ContextItemViewModel vm) return;
if (sender is not ListViewItem listItem)
{
return;
}
if (listItem.DataContext is not ContextItemViewModel vm)
{
return;
}
DoAction(new(vm.Command));
e.Handled = true;
}
@@ -472,7 +507,10 @@ public sealed partial class ListPage : Page, System.ComponentModel.INotifyProper
private async Task UpdateFilter(string text)
{
if (ViewModel == null) return;
if (ViewModel == null)
{
return;
}
// ViewModel.Query = text;
@@ -480,9 +518,12 @@ public sealed partial class ListPage : Page, System.ComponentModel.INotifyProper
// 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++)
@@ -514,6 +555,7 @@ public sealed partial class ListPage : Page, System.ComponentModel.INotifyProper
// {
// ViewModel.FilteredItems.Add(newMatches[ViewModel.FilteredItems.Count]);
// }
*/
// set the selected index to the first item in the list
if (ItemsList.Items.Count > 0)

View File

@@ -90,7 +90,9 @@ public sealed partial class MarkdownPage : Page, System.ComponentModel.INotifyPr
ViewModel?.DoAction(actionViewModel);
}
private void Page_Loaded(object sender, RoutedEventArgs e) {}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
}
private void MarkdownScrollViewer_KeyDown(object sender, KeyRoutedEventArgs e)
{
@@ -117,11 +119,12 @@ public sealed partial class MarkdownPage : Page, System.ComponentModel.INotifyPr
{
FlyoutShowOptions options = new FlyoutShowOptions
{
ShowMode = FlyoutShowMode.Standard
ShowMode = FlyoutShowMode.Standard,
};
MoreCommandsButton.Flyout.ShowAt(MoreCommandsButton, options);
//ActionsDropdown.SelectedIndex = 0;
//ActionsDropdown.Focus(FocusState.Programmatic);
// ActionsDropdown.SelectedIndex = 0;
// ActionsDropdown.Focus(FocusState.Programmatic);
}
#pragma warning disable CA1822 // Mark members as static
@@ -129,8 +132,16 @@ public sealed partial class MarkdownPage : Page, System.ComponentModel.INotifyPr
private void ActionListViewItem_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (sender is not ListViewItem listItem) return;
if (listItem.DataContext is not ContextItemViewModel vm) return;
if (sender is not ListViewItem listItem)
{
return;
}
if (listItem.DataContext is not ContextItemViewModel vm)
{
return;
}
if (e.Key == Windows.System.VirtualKey.Enter || e.Key == Windows.System.VirtualKey.Space)
{
DoAction(new(vm.Command));
@@ -140,15 +151,27 @@ public sealed partial class MarkdownPage : Page, System.ComponentModel.INotifyPr
private void ActionListViewItem_Tapped(object sender, TappedRoutedEventArgs e)
{
if (sender is not ListViewItem listItem) return;
if (listItem.DataContext is not ContextItemViewModel vm) return;
if (sender is not ListViewItem listItem)
{
return;
}
if (listItem.DataContext is not ContextItemViewModel vm)
{
return;
}
DoAction(new(vm.Command));
e.Handled = true;
}
private void RootGrid_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Handled) return;
if (e.Handled)
{
return;
}
var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(Windows.System.VirtualKey.Control).HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down);
if (ctrlPressed && e.Key == Windows.System.VirtualKey.K)
@@ -158,7 +181,7 @@ public sealed partial class MarkdownPage : Page, System.ComponentModel.INotifyPr
{
FlyoutShowOptions options = new FlyoutShowOptions
{
ShowMode = FlyoutShowMode.Standard
ShowMode = FlyoutShowMode.Standard,
};
MoreCommandsButton.Flyout.ShowAt(MoreCommandsButton, options);
ActionsDropdown.SelectedIndex = 0;
@@ -166,5 +189,4 @@ public sealed partial class MarkdownPage : Page, System.ComponentModel.INotifyPr
}
}
}
}