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

small whitespace checkin part 1 #11

Merged
merged 1 commit into from
Aug 29, 2024
Merged
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 @@ -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,11 @@ 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
11 changes: 9 additions & 2 deletions src/modules/cmdpal/src/WindowsCommandPalette/BookmarkActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,22 @@ public override ActionResult SubmitForm(string payload)
var state = File.ReadAllText(BookmarksActionProvider.StateJsonPath());
var jsonState = JsonNode.Parse(state);
var items = jsonState?["items"]?.AsArray();

if (items != null)
{
// var items = jsonState["items"];
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
26 changes: 24 additions & 2 deletions src/modules/cmdpal/src/WindowsCommandPalette/ListItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,44 @@ namespace DeveloperCommandPalette;
public sealed class ListItemViewModel : INotifyPropertyChanged, IDisposable
{
private readonly DispatcherQueue DispatcherQueue;

internal ExtensionObject<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;

public event PropertyChangedEventHandler? PropertyChanged;

internal ICommand? DefaultAction { get {try{ return ListItem.Unsafe.Command;} catch (COMException){return null;}}}
internal ICommand? DefaultAction
{
get
{
try
{
return ListItem.Unsafe.Command;
}
catch (COMException)
{
return null;
}
}
}

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

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

private IEnumerable<ICommandContextItem> contextActions
{
get {
get
{
try
{
var item = ListItem.Unsafe;
Expand All @@ -45,9 +65,11 @@ private IEnumerable<ICommandContextItem> contextActions
}
}
}

internal bool HasMoreCommands => contextActions.Any();

internal TagViewModel[] Tags = [];

internal bool HasTags => Tags.Length > 0;

internal IList<ContextItemViewModel> ContextActions
Expand Down
9 changes: 5 additions & 4 deletions src/modules/cmdpal/src/WindowsCommandPalette/ListPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,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
27 changes: 17 additions & 10 deletions src/modules/cmdpal/src/WindowsCommandPalette/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public sealed class MainViewModel
internal bool LoadedApps;

public event TypedEventHandler<object, object?>? HideRequested;

public event TypedEventHandler<object, object?>? SummonRequested;

public event TypedEventHandler<object, object?>? AppsReady;
Expand Down Expand Up @@ -65,7 +65,8 @@ internal void RequestHide()
handlers?.Invoke(this, null);
}

public void Summon(){
public void Summon()
{
var handlers = SummonRequested;
handlers?.Invoke(this, null);
}
Expand All @@ -75,20 +76,26 @@ private static string CreateHash(string? title, string? subtitle)
return title + subtitle;
}

private string[] _recentCommandHashes = [];// ["SpotifySpotify", "All Apps", "GitHub Issues", "Microsoft/GithubBookmark"];
private string[] _recentCommandHashes = [];

public IEnumerable<IListItem> RecentActions => TopLevelCommands
.Select(i=>i.Unsafe)
.Where((i) => {
.Select(i => i.Unsafe)
.Where((i) =>
{
if (i != null)
{
try{
try
{
return _recentCommandHashes.Contains(CreateHash(i.Title, i.Subtitle));
} catch(COMException){ return false; }
}
catch (COMException)
{
return false;
}
}

return false;
})
.Select(i=>i!);
}).Select(i => i!);

public IEnumerable<IListItem> AppItems => LoadedApps? apps.GetItems().First().Items : [];

Expand Down Expand Up @@ -139,7 +146,7 @@ internal void PushRecentAction(ICommand action)
return;
}
}
catch(COMException){ /* log something */ }
catch (COMException) { /* log something */ }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static async Task<string> GetSettingsDataJson()
var hotkey = "win+ctrl+.";
try
{
hotkey = await Application.Current.GetService<ILocalSettingsService>().ReadSettingAsync<string>("GlobalHotkey") ;
hotkey = await Application.Current.GetService<ILocalSettingsService>().ReadSettingAsync<string>("GlobalHotkey");
}
catch (Exception ex)
{
Expand All @@ -94,7 +94,9 @@ private static async Task<string> GetSettingsDataJson()
}
""";
}

public override string StateJson() => throw new NotImplementedException();

public override ActionResult SubmitForm(string payload)
{
var formInput = JsonNode.Parse(payload)?.AsObject();
Expand Down