From 164a34a3406369b631b07f5b61ce969465451fa3 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Sat, 21 May 2016 23:42:23 +0100 Subject: [PATCH] Refactoring for tab selected event --- Wox.Plugin/IPublicAPI.cs | 2 +- Wox/MainWindow.xaml.cs | 2 +- Wox/PublicAPIInstance.cs | 5 ++- Wox/SettingWindow.xaml | 8 ++-- Wox/SettingWindow.xaml.cs | 50 ++----------------------- Wox/ViewModel/SettingWindowViewModel.cs | 12 +++++- 6 files changed, 23 insertions(+), 56 deletions(-) diff --git a/Wox.Plugin/IPublicAPI.cs b/Wox.Plugin/IPublicAPI.cs index 2c19c0a3bd..1cb9df7035 100644 --- a/Wox.Plugin/IPublicAPI.cs +++ b/Wox.Plugin/IPublicAPI.cs @@ -64,7 +64,7 @@ namespace Wox.Plugin /// /// Open setting dialog /// - void OpenSettingDialog(string tabName = "general"); + void OpenSettingDialog(int tab = 0); /// /// Show loading animation diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index bc350b5375..e65f050a5c 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -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 }; diff --git a/Wox/PublicAPIInstance.cs b/Wox/PublicAPIInstance.cs index 693edfb48d..687e634258 100644 --- a/Wox/PublicAPIInstance.cs +++ b/Wox/PublicAPIInstance.cs @@ -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(this, _settingsViewModel); - sw.SwitchTo(tabName); + _settingsViewModel.SelectedTab = (Tab) tab; }); } diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index f2498b4daa..2d86053d2c 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -18,7 +18,7 @@ - + @@ -57,7 +57,7 @@ - + @@ -150,7 +150,7 @@ - + @@ -240,7 +240,7 @@ - + diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index aaaa2f3f51..03db10edc5 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -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 diff --git a/Wox/ViewModel/SettingWindowViewModel.cs b/Wox/ViewModel/SettingWindowViewModel.cs index a3eebe3064..e20245d2e6 100644 --- a/Wox/ViewModel/SettingWindowViewModel.cs +++ b/Wox/ViewModel/SettingWindowViewModel.cs @@ -22,6 +22,8 @@ namespace Wox.ViewModel public Settings Settings { get; set; } public List Languages => InternationalizationManager.Instance.LoadAvailableLanguages(); public IEnumerable MaxResultsRange => Enumerable.Range(2, 16); + public Tab SelectedTab { get; set; } = Tab.General; + public SettingWindowViewModel() { _storage = new JsonStrorage(); @@ -33,6 +35,14 @@ namespace Wox.ViewModel _storage.Save(); } - + public enum Tab + { + General = 0, + Plugin = 1, + Theme = 2, + Hotkey = 3, + Proxy = 4, + About = 5 + } } }