Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 10 additions & 8 deletions Flow.Launcher/CustomQueryHotkeySetting.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@
using System.Windows.Input;
using System.Windows.Controls;
using Flow.Launcher.Core;
using Flow.Launcher.ViewModel;

namespace Flow.Launcher
{
public partial class CustomQueryHotkeySetting : Window
{
private SettingWindow _settingWidow;
private readonly Settings _settings;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to change this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For code quality.😂 I prefer _ prefix for readonly properties and majority of codes in FL uses this way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this is a field instead of property (maybe it worth to figure out the difference). For here, I think it's fine.

private readonly MainViewModel _mainViewModel;
private bool update;
private CustomPluginHotkey updateCustomHotkey;
public Settings Settings { get; }

public CustomQueryHotkeySetting(SettingWindow settingWidow, Settings settings)
public CustomQueryHotkeySetting(SettingWindow settingWidow, Settings settings, MainViewModel mainVM)
{
_settingWidow = settingWidow;
Settings = settings;
_settings = settings;
_mainViewModel = mainVM;
InitializeComponent();
}

Expand All @@ -33,13 +36,13 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)
{
if (!update)
{
Settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();
_settings.CustomPluginHotkeys ??= new ObservableCollection<CustomPluginHotkey>();

var pluginHotkey = new CustomPluginHotkey
{
Hotkey = HotkeyControl.CurrentHotkey.ToString(), ActionKeyword = tbAction.Text
};
Settings.CustomPluginHotkeys.Add(pluginHotkey);
_settings.CustomPluginHotkeys.Add(pluginHotkey);

HotKeyMapper.SetCustomQueryHotkey(pluginHotkey);
}
Expand All @@ -59,7 +62,7 @@ private void btnAdd_OnClick(object sender, RoutedEventArgs e)

public void UpdateItem(CustomPluginHotkey item)
{
updateCustomHotkey = Settings.CustomPluginHotkeys.FirstOrDefault(o =>
updateCustomHotkey = _settings.CustomPluginHotkeys.FirstOrDefault(o =>
o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
if (updateCustomHotkey == null)
{
Expand All @@ -77,8 +80,7 @@ public void UpdateItem(CustomPluginHotkey item)
private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e)
{
App.API.ChangeQuery(tbAction.Text);
Application.Current.MainWindow.Show();
Application.Current.MainWindow.Opacity = 1;
_mainViewModel.Show();
Application.Current.MainWindow.Focus();
}

Expand Down
8 changes: 5 additions & 3 deletions Flow.Launcher/CustomShortcutSetting.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
using System.Windows.Input;
using Flow.Launcher.SettingPages.ViewModels;
using Flow.Launcher.Core;
using Flow.Launcher.ViewModel;

namespace Flow.Launcher
{
public partial class CustomShortcutSetting : Window
{
private readonly SettingsPaneHotkeyViewModel _hotkeyVm;
private readonly MainViewModel _mainViewModel;
public string Key { get; set; } = String.Empty;
public string Value { get; set; } = String.Empty;
private string originalKey { get; } = null;
private string originalValue { get; } = null;
private bool update { get; } = false;

public CustomShortcutSetting(SettingsPaneHotkeyViewModel vm)
public CustomShortcutSetting(SettingsPaneHotkeyViewModel vm, MainViewModel mainVM)
{
_hotkeyVm = vm;
_mainViewModel = mainVM;
InitializeComponent();
}

Expand Down Expand Up @@ -65,8 +68,7 @@ private void cmdEsc_OnPress(object sender, ExecutedRoutedEventArgs e)
private void BtnTestShortcut_OnClick(object sender, RoutedEventArgs e)
{
App.API.ChangeQuery(tbExpand.Text);
Application.Current.MainWindow.Show();
Application.Current.MainWindow.Opacity = 1;
_mainViewModel.Show();
Application.Current.MainWindow.Focus();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void OpenSettingDialog()
{
Application.Current.Dispatcher.Invoke(() =>
{
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settingsVM);
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settingsVM, _mainVM);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using Flow.Launcher.Core;
using Flow.Launcher.ViewModel;

namespace Flow.Launcher.SettingPages.ViewModels;

public partial class SettingsPaneHotkeyViewModel : BaseModel
{
public Settings Settings { get; }
private MainViewModel MainVM { get; }

public CustomPluginHotkey SelectedCustomPluginHotkey { get; set; }
public CustomShortcutModel SelectedCustomShortcut { get; set; }
Expand All @@ -25,9 +27,10 @@ public partial class SettingsPaneHotkeyViewModel : BaseModel
$"{KeyConstant.Ctrl}+{KeyConstant.Alt}"
};

public SettingsPaneHotkeyViewModel(Settings settings)
public SettingsPaneHotkeyViewModel(Settings settings, MainViewModel mainVM)
{
Settings = settings;
MainVM = mainVM;
}

[RelayCommand]
Expand Down Expand Up @@ -71,15 +74,15 @@ private void CustomHotkeyEdit()
return;
}

var window = new CustomQueryHotkeySetting(null, Settings);
var window = new CustomQueryHotkeySetting(null, Settings, MainVM);
window.UpdateItem(item);
window.ShowDialog();
}

[RelayCommand]
private void CustomHotkeyAdd()
{
new CustomQueryHotkeySetting(null, Settings).ShowDialog();
new CustomQueryHotkeySetting(null, Settings, MainVM).ShowDialog();
}

[RelayCommand]
Expand Down Expand Up @@ -126,7 +129,7 @@ private void CustomShortcutEdit()
[RelayCommand]
private void CustomShortcutAdd()
{
var window = new CustomShortcutSetting(this);
var window = new CustomShortcutSetting(this, MainVM);
if (window.ShowDialog() is true)
{
var shortcut = new CustomShortcutModel(window.Key, window.Value);
Expand Down
4 changes: 2 additions & 2 deletions Flow.Launcher/SettingPages/Views/SettingsPaneHotkey.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (!IsInitialized)
{
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings })
if (e.ExtraData is not SettingWindow.PaneData { Settings: { } settings, MainViewModel: { } mainVM })
throw new ArgumentException("Settings are required for SettingsPaneHotkey.");
_viewModel = new SettingsPaneHotkeyViewModel(settings);
_viewModel = new SettingsPaneHotkeyViewModel(settings, mainVM);
DataContext = _viewModel;
InitializeComponent();
}
Expand Down
8 changes: 5 additions & 3 deletions Flow.Launcher/SettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public partial class SettingWindow
private readonly IPublicAPI _api;
private readonly Settings _settings;
private readonly SettingWindowViewModel _viewModel;
private readonly MainViewModel _mainVM;

public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel, MainViewModel mainVM)
{
_settings = viewModel.Settings;
DataContext = viewModel;
_viewModel = viewModel;
_mainVM = mainVM;
_api = api;
InitializePosition();
InitializeComponent();
Expand Down Expand Up @@ -160,7 +162,7 @@ private double WindowTop()

private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
var paneData = new PaneData(_settings, _viewModel.Updater, _viewModel.Portable);
var paneData = new PaneData(_settings, _viewModel.Updater, _viewModel.Portable, _mainVM);
if (args.IsSettingsSelected)
{
ContentFrame.Navigate(typeof(SettingsPaneGeneral), paneData);
Expand Down Expand Up @@ -206,5 +208,5 @@ private void ContentFrame_Loaded(object sender, RoutedEventArgs e)
NavView.SelectedItem ??= NavView.MenuItems[0]; /* Set First Page */
}

public record PaneData(Settings Settings, Updater Updater, IPortable Portable);
public record PaneData(Settings Settings, Updater Updater, IPortable Portable, MainViewModel MainViewModel);
}
Loading