mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Show builtin vars in shortcut list
This commit is contained in:
parent
f3c4120395
commit
5879c843b0
8 changed files with 81 additions and 36 deletions
|
|
@ -1,18 +1,40 @@
|
|||
using System;
|
||||
using NLog.Time;
|
||||
using System;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Security.RightsManagement;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Flow.Launcher.Infrastructure.UserSettings
|
||||
{
|
||||
public class CustomShortcutBaseModel
|
||||
|
||||
public class CustomShortcutModel
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string Value { get; set; }
|
||||
public bool CanBeEdited { get; private set; } // Can be edited by user via dialog
|
||||
|
||||
[JsonIgnore]
|
||||
public Func<string> Expand { get; set; } = () => { return ""; };
|
||||
|
||||
public CustomShortcutModel(string key, string value)
|
||||
{
|
||||
Key = key;
|
||||
Value = value;
|
||||
CanBeEdited = true;
|
||||
Expand = () => { return Value; };
|
||||
}
|
||||
|
||||
public CustomShortcutModel(string key, string description, Func<string> expand)
|
||||
{
|
||||
Key = key;
|
||||
Value = description;
|
||||
CanBeEdited = false;
|
||||
Expand = expand;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is CustomShortcutBaseModel other &&
|
||||
return obj is CustomShortcutModel other &&
|
||||
Key == other.Key;
|
||||
}
|
||||
|
||||
|
|
@ -20,21 +42,6 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
{
|
||||
return HashCode.Combine(Key);
|
||||
}
|
||||
};
|
||||
|
||||
public class CustomShortcutModel : CustomShortcutBaseModel
|
||||
{
|
||||
public string Value
|
||||
{
|
||||
get { return Expand(); }
|
||||
set { Expand = () => { return value; }; }
|
||||
}
|
||||
|
||||
public CustomShortcutModel(string key, string value)
|
||||
{
|
||||
Key = key;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public void Deconstruct(out string key, out string value)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ using System.Collections.Generic;
|
|||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Windows;
|
||||
using Flow.Launcher.Plugin;
|
||||
using Flow.Launcher.Plugin.SharedModels;
|
||||
using Flow.Launcher;
|
||||
using Flow.Launcher.ViewModel;
|
||||
|
||||
namespace Flow.Launcher.Infrastructure.UserSettings
|
||||
{
|
||||
public class Settings : BaseModel
|
||||
|
|
@ -175,8 +175,14 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
|
||||
|
||||
public ObservableCollection<CustomPluginHotkey> CustomPluginHotkeys { get; set; } = new ObservableCollection<CustomPluginHotkey>();
|
||||
|
||||
public ObservableCollection<CustomShortcutModel> CustomShortcuts { get; set; } = new ObservableCollection<CustomShortcutModel>();
|
||||
|
||||
[JsonIgnore]
|
||||
public ObservableCollection<CustomShortcutModel> BuiltinShortcuts { get; set; } = new ObservableCollection<CustomShortcutModel>() {
|
||||
new CustomShortcutModel("{clipboard}", "Get text from clipboard.", Clipboard.GetText)
|
||||
};
|
||||
|
||||
public bool DontPromptUpdateMsg { get; set; }
|
||||
public bool EnableUpdateLog { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@
|
|||
x:Name="btnAdd"
|
||||
MinWidth="140"
|
||||
Margin="5,0,10,0"
|
||||
Click="btnAdd_OnClick"
|
||||
Click="BtnAdd_OnClick"
|
||||
Style="{StaticResource AccentButtonStyle}">
|
||||
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ namespace Flow.Launcher
|
|||
Close();
|
||||
}
|
||||
|
||||
private void btnAdd_OnClick(object sender, RoutedEventArgs e)
|
||||
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!update && _settings.CustomShortcuts.Contains(new CustomShortcutModel(Key, Value)))
|
||||
if (!update && (_settings.CustomShortcuts.Contains(new CustomShortcutModel(Key, Value)) || _settings.BuiltinShortcuts.Contains(new CustomShortcutModel(Key, Value))))
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("dulplicateShortcut"));
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -2223,7 +2223,7 @@
|
|||
<Button
|
||||
MinWidth="100"
|
||||
Margin="10,10,0,10"
|
||||
Click="OnAddCustomeShortCutClick"
|
||||
Click="OnAddCustomShortCutClick"
|
||||
Content="{DynamicResource add}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
|
|
|||
|
|
@ -381,6 +381,11 @@ namespace Flow.Launcher
|
|||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
|
||||
return;
|
||||
}
|
||||
else if (!item.CanBeEdited)
|
||||
{
|
||||
MessageBox.Show("This shortcut cannot be deleted or edited."); // TODO
|
||||
return;
|
||||
}
|
||||
|
||||
string deleteWarning =
|
||||
string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomShortcutWarning"),
|
||||
|
|
@ -389,7 +394,7 @@ namespace Flow.Launcher
|
|||
MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"),
|
||||
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
settings.CustomShortcuts.Remove(item);
|
||||
viewModel.RemoveShortcut(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -398,10 +403,15 @@ namespace Flow.Launcher
|
|||
var item = viewModel.SelectedCustomShortcut;
|
||||
if (item != null)
|
||||
{
|
||||
if (!item.CanBeEdited)
|
||||
{
|
||||
MessageBox.Show("This shortcut cannot be deleted or edited.");
|
||||
return;
|
||||
}
|
||||
var shortcutSettingWindow = new CustomShortcutSetting(item, settings);
|
||||
if (shortcutSettingWindow.ShowDialog() == true)
|
||||
{
|
||||
settings.CustomShortcuts[viewModel.SelectCustomShortcutIndex.Value] = shortcutSettingWindow.ShortCut;
|
||||
viewModel.EditShortcut(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -410,12 +420,12 @@ namespace Flow.Launcher
|
|||
}
|
||||
}
|
||||
|
||||
private void OnAddCustomeShortCutClick(object sender, RoutedEventArgs e)
|
||||
private void OnAddCustomShortCutClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var shortcutSettingWindow = new CustomShortcutSetting(settings);
|
||||
if (shortcutSettingWindow.ShowDialog() == true)
|
||||
{
|
||||
settings.CustomShortcuts.Add(shortcutSettingWindow.ShortCut);
|
||||
viewModel.AddShortcut(shortcutSettingWindow.ShortCut);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -554,7 +554,7 @@ namespace Flow.Launcher.ViewModel
|
|||
return;
|
||||
}
|
||||
|
||||
var query = ConstructQuery(QueryText, _settings.CustomShortcuts);
|
||||
var query = ConstructQuery(QueryText, _settings.CustomShortcuts, _settings.BuiltinShortcuts);
|
||||
|
||||
|
||||
_updateSource?.Dispose();
|
||||
|
|
@ -662,21 +662,24 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
private static Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel> shortcuts)
|
||||
private static Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel> customShortcuts, IEnumerable<CustomShortcutModel> builtInShortcuts)
|
||||
{
|
||||
StringBuilder queryBuilder = new(queryText);
|
||||
|
||||
foreach (var (key, value) in shortcuts)
|
||||
foreach (var shortcut in customShortcuts)
|
||||
{
|
||||
if (queryBuilder.Equals(key))
|
||||
if (queryBuilder.Equals(shortcut.Key))
|
||||
{
|
||||
queryBuilder.Replace(key, value);
|
||||
queryBuilder.Replace(shortcut.Key, shortcut.Expand());
|
||||
}
|
||||
|
||||
queryBuilder.Replace('@' + key, value);
|
||||
queryBuilder.Replace('@' + shortcut.Key, shortcut.Expand());
|
||||
}
|
||||
|
||||
foreach (var shortcut in builtInShortcuts)
|
||||
{
|
||||
queryBuilder.Replace(shortcut.Key, shortcut.Expand());
|
||||
}
|
||||
|
||||
queryBuilder.Replace("{clipboard}", Clipboard.GetText());
|
||||
|
||||
var query = QueryBuilder.Build(queryBuilder.ToString().Trim(), PluginManager.NonGlobalPlugins);
|
||||
return query;
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ namespace Flow.Launcher.ViewModel
|
|||
break;
|
||||
}
|
||||
};
|
||||
ShortCuts = new ObservableCollection<CustomShortcutModel>(Settings.CustomShortcuts.Union(Settings.BuiltinShortcuts));
|
||||
}
|
||||
|
||||
public Settings Settings { get; set; }
|
||||
|
|
@ -180,7 +181,7 @@ namespace Flow.Launcher.ViewModel
|
|||
public List<Language> Languages => _translater.LoadAvailableLanguages();
|
||||
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
|
||||
|
||||
public ObservableCollection<CustomShortcutModel> ShortCuts => Settings.CustomShortcuts;
|
||||
public ObservableCollection<CustomShortcutModel> ShortCuts { get; set; } = new ObservableCollection<CustomShortcutModel>();
|
||||
|
||||
public string TestProxy()
|
||||
{
|
||||
|
|
@ -544,6 +545,24 @@ namespace Flow.Launcher.ViewModel
|
|||
public CustomShortcutModel? SelectedCustomShortcut { get; set; }
|
||||
public int? SelectCustomShortcutIndex { get; set; }
|
||||
|
||||
public void AddShortcut(CustomShortcutModel shortcut)
|
||||
{
|
||||
Settings.CustomShortcuts.Add(shortcut);
|
||||
ShortCuts.Add(shortcut);
|
||||
}
|
||||
|
||||
public void EditShortcut(CustomShortcutModel shortcut)
|
||||
{
|
||||
Settings.CustomShortcuts[ShortCuts.IndexOf(shortcut)] = shortcut;
|
||||
ShortCuts[ShortCuts.IndexOf(shortcut)] = shortcut;
|
||||
}
|
||||
|
||||
public void RemoveShortcut(CustomShortcutModel shortcut)
|
||||
{
|
||||
Settings.CustomShortcuts.Remove(shortcut);
|
||||
ShortCuts.Remove(shortcut);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region about
|
||||
|
|
|
|||
Loading…
Reference in a new issue