mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 21:41:51 +02:00
Refactoring for tab selected event
This commit is contained in:
@@ -64,7 +64,7 @@ namespace Wox.Plugin
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Open setting dialog
|
/// Open setting dialog
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void OpenSettingDialog(string tabName = "general");
|
void OpenSettingDialog(int tab = 0);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Show loading animation
|
/// Show loading animation
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ namespace Wox
|
|||||||
var setting = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTraySettings"));
|
var setting = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTraySettings"));
|
||||||
setting.Click += (o, e) => App.API.OpenSettingDialog();
|
setting.Click += (o, e) => App.API.OpenSettingDialog();
|
||||||
var about = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayAbout"));
|
var about = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayAbout"));
|
||||||
about.Click += (o, e) => App.API.OpenSettingDialog("about");
|
about.Click += (o, e) => App.API.OpenSettingDialog((int) SettingWindowViewModel.Tab.About);
|
||||||
var exit = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayExit"));
|
var exit = new MenuItem(InternationalizationManager.Instance.GetTranslation("iconTrayExit"));
|
||||||
exit.Click += (o, e) => Close();
|
exit.Click += (o, e) => Close();
|
||||||
MenuItem[] childen = { open, setting, about, exit };
|
MenuItem[] childen = { open, setting, about, exit };
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ using Wox.Helper;
|
|||||||
using Wox.Infrastructure.Hotkey;
|
using Wox.Infrastructure.Hotkey;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
using Wox.ViewModel;
|
using Wox.ViewModel;
|
||||||
|
using static Wox.ViewModel.SettingWindowViewModel;
|
||||||
|
|
||||||
namespace Wox
|
namespace Wox
|
||||||
{
|
{
|
||||||
@@ -96,12 +97,12 @@ namespace Wox
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenSettingDialog(string tabName = "general")
|
public void OpenSettingDialog(int tab = 0)
|
||||||
{
|
{
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settingsViewModel);
|
SettingWindow sw = SingletonWindowOpener.Open<SettingWindow>(this, _settingsViewModel);
|
||||||
sw.SwitchTo(tabName);
|
_settingsViewModel.SelectedTab = (Tab) tab;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<Window.Resources>
|
<Window.Resources>
|
||||||
<image:ImagePathConverter x:Key="ImageConverter" />
|
<image:ImagePathConverter x:Key="ImageConverter" />
|
||||||
</Window.Resources>
|
</Window.Resources>
|
||||||
<TabControl Height="auto" x:Name="SettingTab" SelectionChanged="OnTabChanged">
|
<TabControl Height="auto" SelectedIndex="{Binding SelectedTab}">
|
||||||
<TabItem Header="{DynamicResource general}">
|
<TabItem Header="{DynamicResource general}">
|
||||||
<StackPanel Orientation="Vertical">
|
<StackPanel Orientation="Vertical">
|
||||||
<CheckBox IsChecked="{Binding Settings.StartWoxOnSystemStartup}" Margin="10">
|
<CheckBox IsChecked="{Binding Settings.StartWoxOnSystemStartup}" Margin="10">
|
||||||
@@ -57,7 +57,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem Header="{DynamicResource plugin}" x:Name="PluginTab">
|
<TabItem Header="{DynamicResource plugin}" Selector.Selected="OnPluginTabSelected">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="39.5" />
|
<ColumnDefinition Width="39.5" />
|
||||||
@@ -150,7 +150,7 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem Header="{DynamicResource theme}" x:Name="ThemeTab">
|
<TabItem Header="{DynamicResource theme}" Selector.Selected="OnThemeTabSelected">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="200" />
|
<ColumnDefinition Width="200" />
|
||||||
@@ -240,7 +240,7 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem Header="{DynamicResource hotkey}" x:Name="HotkeyTab">
|
<TabItem Header="{DynamicResource hotkey}" Selector.Selected="OnThemeTabSelected">
|
||||||
<Grid Margin="10">
|
<Grid Margin="10">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="30" />
|
<RowDefinition Height="30" />
|
||||||
|
|||||||
@@ -79,50 +79,6 @@ namespace Wox
|
|||||||
settingsLoaded = true;
|
settingsLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SwitchTo(string tabName)
|
|
||||||
{
|
|
||||||
switch (tabName)
|
|
||||||
{
|
|
||||||
case "general":
|
|
||||||
SettingTab.SelectedIndex = 0;
|
|
||||||
break;
|
|
||||||
case "plugin":
|
|
||||||
SettingTab.SelectedIndex = 1;
|
|
||||||
break;
|
|
||||||
case "theme":
|
|
||||||
SettingTab.SelectedIndex = 2;
|
|
||||||
break;
|
|
||||||
case "hotkey":
|
|
||||||
SettingTab.SelectedIndex = 3;
|
|
||||||
break;
|
|
||||||
case "proxy":
|
|
||||||
SettingTab.SelectedIndex = 4;
|
|
||||||
break;
|
|
||||||
case "about":
|
|
||||||
SettingTab.SelectedIndex = 5;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTabChanged(object sender, SelectionChangedEventArgs e)
|
|
||||||
{
|
|
||||||
// Update controls inside the selected tab
|
|
||||||
if (e.OriginalSource != SettingTab) return;
|
|
||||||
|
|
||||||
if (PluginTab.IsSelected)
|
|
||||||
{
|
|
||||||
OnPluginTabSelected();
|
|
||||||
}
|
|
||||||
else if (ThemeTab.IsSelected)
|
|
||||||
{
|
|
||||||
OnThemeTabSelected();
|
|
||||||
}
|
|
||||||
else if (HotkeyTab.IsSelected)
|
|
||||||
{
|
|
||||||
OnHotkeyTabSelected();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region General
|
#region General
|
||||||
|
|
||||||
void OnLanguageChanged(object sender, SelectionChangedEventArgs e)
|
void OnLanguageChanged(object sender, SelectionChangedEventArgs e)
|
||||||
@@ -247,7 +203,7 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnHotkeyTabSelected()
|
public void OnHotkeyTabSelected(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
HotkeyControl.HotkeyChanged += ctlHotkey_OnHotkeyChanged;
|
HotkeyControl.HotkeyChanged += ctlHotkey_OnHotkeyChanged;
|
||||||
HotkeyControl.SetHotkey(_settings.Hotkey, false);
|
HotkeyControl.SetHotkey(_settings.Hotkey, false);
|
||||||
@@ -310,7 +266,7 @@ namespace Wox
|
|||||||
Process.Start("http://www.getwox.com/theme");
|
Process.Start("http://www.getwox.com/theme");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnThemeTabSelected()
|
public void OnThemeTabSelected(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Stopwatch.Debug("theme load", () =>
|
Stopwatch.Debug("theme load", () =>
|
||||||
{
|
{
|
||||||
@@ -644,7 +600,7 @@ namespace Wox
|
|||||||
Process.Start("http://www.getwox.com/plugin");
|
Process.Start("http://www.getwox.com/plugin");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPluginTabSelected()
|
public void OnPluginTabSelected(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
var plugins = PluginManager.AllPlugins;
|
var plugins = PluginManager.AllPlugins;
|
||||||
//move all disabled to bottom
|
//move all disabled to bottom
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ namespace Wox.ViewModel
|
|||||||
public Settings Settings { get; set; }
|
public Settings Settings { get; set; }
|
||||||
public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages();
|
public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages();
|
||||||
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
|
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
|
||||||
|
public Tab SelectedTab { get; set; } = Tab.General;
|
||||||
|
|
||||||
public SettingWindowViewModel()
|
public SettingWindowViewModel()
|
||||||
{
|
{
|
||||||
_storage = new JsonStrorage<Settings>();
|
_storage = new JsonStrorage<Settings>();
|
||||||
@@ -33,6 +35,14 @@ namespace Wox.ViewModel
|
|||||||
_storage.Save();
|
_storage.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Tab
|
||||||
|
{
|
||||||
|
General = 0,
|
||||||
|
Plugin = 1,
|
||||||
|
Theme = 2,
|
||||||
|
Hotkey = 3,
|
||||||
|
Proxy = 4,
|
||||||
|
About = 5
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user