mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Separate custom & built-in shortcuts
This commit is contained in:
parent
cde272ae4d
commit
23ecd39dc7
7 changed files with 36 additions and 62 deletions
|
|
@ -3,35 +3,13 @@ using System.Text.Json.Serialization;
|
|||
|
||||
namespace Flow.Launcher.Infrastructure.UserSettings
|
||||
{
|
||||
|
||||
public class CustomShortcutModel
|
||||
public abstract class ShortcutBaseModel
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string Value { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool CanBeEdited { get; private set; } // Can be edited by user from settings window
|
||||
|
||||
[JsonIgnore]
|
||||
public Func<string> Expand { get; set; } = () => { return ""; };
|
||||
|
||||
[JsonConstructorAttribute]
|
||||
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 CustomShortcutModel other &&
|
||||
|
|
@ -42,6 +20,19 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
{
|
||||
return HashCode.Combine(Key);
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomShortcutModel : ShortcutBaseModel
|
||||
{
|
||||
public string Value { get; set; }
|
||||
|
||||
[JsonConstructorAttribute]
|
||||
public CustomShortcutModel(string key, string value)
|
||||
{
|
||||
Key = key;
|
||||
Value = value;
|
||||
Expand = () => { return Value; };
|
||||
}
|
||||
|
||||
public void Deconstruct(out string key, out string value)
|
||||
{
|
||||
|
|
@ -59,4 +50,16 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
return new CustomShortcutModel(shortcut.Key, shortcut.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public class BuiltinShortcutModel : ShortcutBaseModel
|
||||
{
|
||||
public string Description { get; set; }
|
||||
|
||||
public BuiltinShortcutModel(string key, string description, Func<string> expand)
|
||||
{
|
||||
Key = key;
|
||||
Description = description;
|
||||
Expand = expand ?? (() => { return ""; });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -180,8 +180,8 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
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 ObservableCollection<BuiltinShortcutModel> BuiltinShortcuts { get; set; } = new ObservableCollection<BuiltinShortcutModel>() {
|
||||
new BuiltinShortcutModel("{clipboard}", "Get text from clipboard.", Clipboard.GetText)
|
||||
};
|
||||
|
||||
public bool DontPromptUpdateMsg { get; set; }
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace Flow.Launcher
|
|||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("emptyShortcut"));
|
||||
return;
|
||||
}
|
||||
if (!update && (_settings.CustomShortcuts.Contains(new CustomShortcutModel(Key, Value)) || _settings.BuiltinShortcuts.Contains(new CustomShortcutModel(Key, Value))))
|
||||
if (!update && (_settings.CustomShortcuts.Contains(new CustomShortcutModel(Key, Value)) || _settings.BuiltinShortcuts.Contains(new BuiltinShortcutModel(Key, Value, null))))
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("dulplicateShortcut"));
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -217,7 +217,6 @@
|
|||
<system:String x:Key="customeQueryShortcutTips">Enter a shortcut that automatically expands to the specified query.</system:String>
|
||||
<system:String x:Key="dulplicateShortcut">Shortcut is dulplicate, please enter a new Shortcut or edit the existing one.</system:String>
|
||||
<system:String x:Key="emptyShortcut">Shortcut and/or its expansion is empty.</system:String>
|
||||
<system:String x:Key="uneditableShortcut">This shortcut cannot be deleted or edited.</system:String>
|
||||
|
||||
<!-- Hotkey Control -->
|
||||
<system:String x:Key="hotkeyUnavailable">Hotkey Unavailable</system:String>
|
||||
|
|
|
|||
|
|
@ -381,11 +381,6 @@ namespace Flow.Launcher
|
|||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
|
||||
return;
|
||||
}
|
||||
else if (!item.CanBeEdited)
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("uneditableShortcut"));
|
||||
return;
|
||||
}
|
||||
|
||||
string deleteWarning =
|
||||
string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomShortcutWarning"),
|
||||
|
|
@ -394,7 +389,7 @@ namespace Flow.Launcher
|
|||
MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"),
|
||||
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
viewModel.RemoveShortcut(item);
|
||||
settings.CustomShortcuts.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -406,16 +401,12 @@ namespace Flow.Launcher
|
|||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
|
||||
return;
|
||||
}
|
||||
else if (!item.CanBeEdited)
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("uneditableShortcut"));
|
||||
return;
|
||||
}
|
||||
|
||||
var shortcutSettingWindow = new CustomShortcutSetting(item, settings);
|
||||
if (shortcutSettingWindow.ShowDialog() == true)
|
||||
{
|
||||
viewModel.EditShortcut(item, shortcutSettingWindow.ShortCut);
|
||||
settings.CustomShortcuts.Remove(item);
|
||||
settings.CustomShortcuts.Add(shortcutSettingWindow.ShortCut);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -424,7 +415,7 @@ namespace Flow.Launcher
|
|||
var shortcutSettingWindow = new CustomShortcutSetting(settings);
|
||||
if (shortcutSettingWindow.ShowDialog() == true)
|
||||
{
|
||||
viewModel.AddShortcut(shortcutSettingWindow.ShortCut);
|
||||
settings.CustomShortcuts.Add(shortcutSettingWindow.ShortCut);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -662,7 +662,7 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
private static Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel> customShortcuts, IEnumerable<CustomShortcutModel> builtInShortcuts)
|
||||
private static Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel> customShortcuts, IEnumerable<BuiltinShortcutModel> builtInShortcuts)
|
||||
{
|
||||
StringBuilder queryBuilder = new(queryText);
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ namespace Flow.Launcher.ViewModel
|
|||
break;
|
||||
}
|
||||
};
|
||||
ShortCuts = new ObservableCollection<CustomShortcutModel>(Settings.CustomShortcuts.Union(Settings.BuiltinShortcuts));
|
||||
}
|
||||
|
||||
public Settings Settings { get; set; }
|
||||
|
|
@ -181,7 +180,7 @@ namespace Flow.Launcher.ViewModel
|
|||
public List<Language> Languages => _translater.LoadAvailableLanguages();
|
||||
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
|
||||
|
||||
public ObservableCollection<CustomShortcutModel> ShortCuts { get; set; } = new ObservableCollection<CustomShortcutModel>();
|
||||
public ObservableCollection<CustomShortcutModel> ShortCuts => Settings.CustomShortcuts;
|
||||
|
||||
public string TestProxy()
|
||||
{
|
||||
|
|
@ -538,30 +537,12 @@ namespace Flow.Launcher.ViewModel
|
|||
|
||||
#endregion
|
||||
|
||||
#region hotkey
|
||||
#region hotkey & shortcut
|
||||
|
||||
public CustomPluginHotkey SelectedCustomPluginHotkey { get; set; }
|
||||
|
||||
public CustomShortcutModel? SelectedCustomShortcut { get; set; }
|
||||
|
||||
public void AddShortcut(CustomShortcutModel shortcut)
|
||||
{
|
||||
Settings.CustomShortcuts.Add(shortcut);
|
||||
ShortCuts.Add(shortcut);
|
||||
}
|
||||
|
||||
public void EditShortcut(CustomShortcutModel oldShortcut, CustomShortcutModel newShortcut)
|
||||
{
|
||||
RemoveShortcut(oldShortcut);
|
||||
AddShortcut(newShortcut);
|
||||
}
|
||||
|
||||
public void RemoveShortcut(CustomShortcutModel shortcut)
|
||||
{
|
||||
Settings.CustomShortcuts.Remove(shortcut);
|
||||
ShortCuts.Remove(shortcut);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region about
|
||||
|
|
|
|||
Loading…
Reference in a new issue