-
-
Notifications
You must be signed in to change notification settings - Fork 452
Custom Query Shortcut + built-in variables #930
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
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
efd34c9
Draft Query Shortcut
taooceros 4340c08
Draft Query Shortcut
taooceros 2fa0b52
Merge remote-tracking branch 'origin/Shortcut' into Shortcut
taooceros 0a8405f
Resolve issue and add partial replacement trick
taooceros 0d355bd
Draft Query Shortcut
taooceros 2bb8812
Resolve issue and add partial replacement trick
taooceros 9ccebd9
Merge remote-tracking branch 'origin/Shortcut' into Shortcut
taooceros b837d45
Merge remote-tracking branch 'origin/dev' into Shortcut
taooceros 4d42e52
- Move the 'Shorcut' to Hotkey tab from General
onesounds c0a61c0
slightly code adjustment
taooceros d60ba01
Implement {clipboard} feature and the setting panel
taooceros 8ebdff0
Merge branch 'dev' into Shortcut
taooceros 0c75dfe
Update delete message
taooceros 806720d
Remove ignore executable check
taooceros 609e8e8
Remove testing code
taooceros 3d20a60
Rename ShortcutModel to CustomShortcutModel
VictoriousRaptor 099b1d6
Rename Settings.ShortCuts to CustomShortcuts
VictoriousRaptor 99d1807
Move CustomShortcutModel definition to a new file
VictoriousRaptor a0c70a3
Inherit
VictoriousRaptor c2b1481
Warn if trying to add existing shortcut
VictoriousRaptor e789948
Text update
VictoriousRaptor f3c4120
Shortcut settings dialog preview & text & bugfix
VictoriousRaptor 5879c84
Show builtin vars in shortcut list
VictoriousRaptor 334d58d
Fix json load
VictoriousRaptor d394d86
Bugfix
VictoriousRaptor cde272a
Fix hard-coded text
VictoriousRaptor 23ecd39
Separate custom & built-in shortcuts
VictoriousRaptor ce60f41
bugfix
VictoriousRaptor 951ba4c
Add Listview for builtin shortcuts
VictoriousRaptor 2489bfa
Merge pull request #1474 from VictoriousRaptor/Shortcut
taooceros 3372a40
Fix mixed usage of \t and space
VictoriousRaptor 40dda13
Merge branch 'Flow-Launcher:Shortcut' into Shortcut
VictoriousRaptor fe5859a
Merge pull request #1478 from VictoriousRaptor/Shortcut
jjw24 cbbb3b8
Merge branch 'dev' into Shortcut
VictoriousRaptor 532f7ce
Fix merging
VictoriousRaptor 3d36513
Add MinHeight for ListViews
VictoriousRaptor 12721bc
Revert accidental change in Log.cs
VictoriousRaptor 0eedb7b
renaming
VictoriousRaptor 1296b0e
minor changes
VictoriousRaptor fc7ed31
Use reference when editing
VictoriousRaptor 473626f
Fix duplicates when editing
VictoriousRaptor 7fe81b4
Add text
VictoriousRaptor 977ec33
Move logic to viewmodel
VictoriousRaptor 5d3e6e0
Move dialog logic to vm
VictoriousRaptor 019019e
Fix
VictoriousRaptor 224b1df
Translate BuiltinShortcut desc
VictoriousRaptor 9ccdf59
change text textbox when expanding builtin shortcuts
VictoriousRaptor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
Flow.Launcher.Infrastructure/UserSettings/CustomShortcutModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Flow.Launcher.Infrastructure.UserSettings | ||
{ | ||
public abstract class ShortcutBaseModel | ||
{ | ||
public string Key { get; set; } | ||
|
||
[JsonIgnore] | ||
public Func<string> Expand { get; set; } = () => { return ""; }; | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return obj is ShortcutBaseModel other && | ||
Key == other.Key; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Key.GetHashCode(); | ||
} | ||
} | ||
|
||
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) | ||
{ | ||
key = Key; | ||
value = Value; | ||
} | ||
|
||
public static implicit operator (string Key, string Value)(CustomShortcutModel shortcut) | ||
{ | ||
return (shortcut.Key, shortcut.Value); | ||
} | ||
|
||
public static implicit operator CustomShortcutModel((string Key, string Value) shortcut) | ||
{ | ||
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 ""; }); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows.Data; | ||
using Flow.Launcher.Core.Resource; | ||
|
||
namespace Flow.Launcher.Converters | ||
{ | ||
public class TranlationConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
var key = value.ToString(); | ||
if (String.IsNullOrEmpty(key)) | ||
return key; | ||
return InternationalizationManager.Instance.GetTranslation(key); | ||
} | ||
|
||
public object ConvertBack(object value, System.Type targetType, object parameter, CultureInfo culture) => throw new System.InvalidOperationException(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<Window | ||
x:Class="Flow.Launcher.CustomShortcutSetting" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:flowlauncher="clr-namespace:Flow.Launcher" | ||
Title="{DynamicResource customeQueryShortcutTitle}" | ||
Width="530" | ||
Background="{DynamicResource PopuBGColor}" | ||
Foreground="{DynamicResource PopupTextColor}" | ||
Icon="Images\app.png" | ||
ResizeMode="NoResize" | ||
SizeToContent="Height" | ||
WindowStartupLocation="CenterScreen" | ||
DataContext="{Binding RelativeSource={RelativeSource Self}}"> | ||
<WindowChrome.WindowChrome> | ||
<WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" /> | ||
</WindowChrome.WindowChrome> | ||
<Window.InputBindings> | ||
<KeyBinding Key="Escape" Command="Close" /> | ||
</Window.InputBindings> | ||
<Window.CommandBindings> | ||
<CommandBinding Command="Close" Executed="cmdEsc_OnPress" /> | ||
</Window.CommandBindings> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition /> | ||
<RowDefinition Height="80" /> | ||
</Grid.RowDefinitions> | ||
<StackPanel Grid.Row="0"> | ||
<StackPanel> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
<Button | ||
Grid.Column="4" | ||
Click="BtnCancel_OnClick" | ||
Style="{StaticResource TitleBarCloseButtonStyle}"> | ||
<Path | ||
Width="46" | ||
Height="32" | ||
Data="M 18,11 27,20 M 18,20 27,11" | ||
Stroke="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}" | ||
StrokeThickness="1"> | ||
<Path.Style> | ||
<Style TargetType="Path"> | ||
<Style.Triggers> | ||
<DataTrigger Binding="{Binding Path=IsActive, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Value="False"> | ||
<Setter Property="Opacity" Value="0.5" /> | ||
</DataTrigger> | ||
</Style.Triggers> | ||
</Style> | ||
</Path.Style> | ||
</Path> | ||
</Button> | ||
</Grid> | ||
</StackPanel> | ||
<StackPanel Margin="26,0,26,0"> | ||
<StackPanel Grid.Row="0" Margin="0,0,0,12"> | ||
<TextBlock | ||
Grid.Column="0" | ||
Margin="0,0,0,0" | ||
FontFamily="Segoe UI" | ||
FontSize="20" | ||
FontWeight="SemiBold" | ||
Text="{DynamicResource customQueryShortcut}" | ||
TextAlignment="Left" /> | ||
</StackPanel> | ||
<StackPanel> | ||
<TextBlock | ||
FontSize="14" | ||
Text="{DynamicResource customeQueryShortcutTips}" | ||
TextAlignment="Left" | ||
TextWrapping="WrapWithOverflow" /> | ||
</StackPanel> | ||
|
||
<StackPanel Margin="0,20,0,0" Orientation="Horizontal"> | ||
<Grid Width="470"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition /> | ||
<RowDefinition /> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="*" /> | ||
</Grid.ColumnDefinitions> | ||
<TextBlock | ||
Grid.Row="0" | ||
Grid.Column="0" | ||
Margin="10" | ||
HorizontalAlignment="Left" | ||
VerticalAlignment="Center" | ||
FontSize="14" | ||
Text="{DynamicResource customShortcut}" /> | ||
<TextBox | ||
Grid.Row="0" | ||
Grid.Column="1" | ||
Margin="10" | ||
Text="{Binding Key}" | ||
/> | ||
<TextBlock | ||
Grid.Row="1" | ||
Grid.Column="0" | ||
Margin="10" | ||
HorizontalAlignment="Left" | ||
VerticalAlignment="Center" | ||
FontSize="14" | ||
Text="{DynamicResource customShortcutExpansion}" /> | ||
|
||
<DockPanel | ||
Grid.Row="1" | ||
Grid.Column="1" | ||
LastChildFill="True"> | ||
<Button | ||
x:Name="btnTestShortcut" | ||
Margin="0,0,10,0" | ||
Padding="10,5,10,5" | ||
Click="BtnTestShortcut_OnClick" | ||
Content="{DynamicResource preview}" | ||
DockPanel.Dock="Right" /> | ||
<TextBox | ||
x:Name="tbExpand" | ||
Margin="10" | ||
HorizontalAlignment="Stretch" | ||
Text="{Binding Value}" | ||
VerticalAlignment="Center" /> | ||
</DockPanel> | ||
</Grid> | ||
</StackPanel> | ||
</StackPanel> | ||
</StackPanel> | ||
<Border | ||
Grid.Row="1" | ||
Margin="0,14,0,0" | ||
Background="{DynamicResource PopupButtonAreaBGColor}" | ||
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}" | ||
BorderThickness="0,1,0,0"> | ||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal"> | ||
<Button | ||
x:Name="btnCancel" | ||
MinWidth="140" | ||
Margin="10,0,5,0" | ||
Click="BtnCancel_OnClick" | ||
Content="{DynamicResource cancel}" /> | ||
<Button | ||
x:Name="btnAdd" | ||
MinWidth="140" | ||
Margin="5,0,10,0" | ||
Click="BtnAdd_OnClick" | ||
Style="{StaticResource AccentButtonStyle}"> | ||
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" /> | ||
</Button> | ||
</StackPanel> | ||
</Border> | ||
</Grid> | ||
</Window> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Flow.Launcher.Core.Resource; | ||
using Flow.Launcher.ViewModel; | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Input; | ||
|
||
namespace Flow.Launcher | ||
{ | ||
public partial class CustomShortcutSetting : Window | ||
{ | ||
private SettingWindowViewModel viewModel; | ||
public string Key { get; set; } = String.Empty; | ||
public string Value { get; set; } = String.Empty; | ||
private string originalKey { get; init; } = null; | ||
private string originalValue { get; init; } = null; | ||
private bool update { get; init; } = false; | ||
|
||
public CustomShortcutSetting(SettingWindowViewModel vm) | ||
{ | ||
viewModel = vm; | ||
InitializeComponent(); | ||
} | ||
|
||
public CustomShortcutSetting(string key, string value, SettingWindowViewModel vm) | ||
{ | ||
viewModel = vm; | ||
Key = key; | ||
Value = value; | ||
originalKey = key; | ||
originalValue = value; | ||
update = true; | ||
InitializeComponent(); | ||
} | ||
|
||
private void BtnCancel_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
DialogResult = false; | ||
Close(); | ||
} | ||
|
||
private void BtnAdd_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
if (String.IsNullOrEmpty(Key) || String.IsNullOrEmpty(Value)) | ||
{ | ||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("emptyShortcut")); | ||
return; | ||
} | ||
// Check if key is modified or adding a new one | ||
if (((update && originalKey != Key) || !update) | ||
&& viewModel.ShortcutExists(Key)) | ||
{ | ||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("duplicateShortcut")); | ||
return; | ||
} | ||
DialogResult = !update || originalKey != Key || originalValue != Value; | ||
Close(); | ||
} | ||
|
||
private void cmdEsc_OnPress(object sender, ExecutedRoutedEventArgs e) | ||
{ | ||
DialogResult = false; | ||
Close(); | ||
} | ||
|
||
private void BtnTestShortcut_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
App.API.ChangeQuery(tbExpand.Text); | ||
Application.Current.MainWindow.Show(); | ||
Application.Current.MainWindow.Opacity = 1; | ||
Application.Current.MainWindow.Focus(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.