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