mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-13 11:09:28 +08:00
Databinding for proxy tab
This commit is contained in:
parent
cb56b98222
commit
b3119749d9
@ -14,7 +14,7 @@
|
||||
Height="600" Width="800" PreviewKeyDown="Window_PreviewKeyDown"
|
||||
d:DataContext="{d:DesignInstance vm:SettingWindowViewModel}">
|
||||
<TabControl Height="auto" SelectedIndex="0">
|
||||
<TabItem Header="{DynamicResource general}" Height="24" VerticalAlignment="Top">
|
||||
<TabItem Header="{DynamicResource general}">
|
||||
<StackPanel Orientation="Vertical">
|
||||
<CheckBox IsChecked="{Binding Settings.StartWoxOnSystemStartup}" Margin="10">
|
||||
<TextBlock Text="{DynamicResource startWoxOnSystemStartup}" />
|
||||
@ -61,9 +61,11 @@
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<DockPanel Grid.Column="0">
|
||||
<TextBlock DockPanel.Dock="Top" Margin="10" Cursor="Hand"
|
||||
MouseUp="OnMorePluginsClicked" Foreground="Blue"
|
||||
Text="{DynamicResource browserMorePlugins}" />
|
||||
<TextBlock DockPanel.Dock="Top" Margin="10">
|
||||
<Hyperlink NavigateUri="{Binding Plugin, Mode=OneWay}" RequestNavigate="OnRequestNavigate">
|
||||
<Run Text="{DynamicResource browserMorePlugins}"/>
|
||||
</Hyperlink>
|
||||
</TextBlock>
|
||||
<ListBox SelectedIndex="0" SelectedItem="{Binding SelectedPlugin}"
|
||||
ItemsSource="{Binding PluginViewModels}"
|
||||
Margin="10, 0, 10, 10" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
|
||||
@ -160,9 +162,12 @@
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<DockPanel Grid.Column="0">
|
||||
<TextBlock DockPanel.Dock="Top" Margin="10" HorizontalAlignment="Left" Cursor="Hand"
|
||||
MouseUp="OnMoreThemesClick" Foreground="Blue"
|
||||
Text="{DynamicResource browserMoreThemes}" />
|
||||
<TextBlock DockPanel.Dock="Top" Margin="10" HorizontalAlignment="Left">
|
||||
<Hyperlink NavigateUri="{Binding Theme, Mode=OneWay}" RequestNavigate="OnRequestNavigate">
|
||||
<Run Text="{DynamicResource browserMoreThemes}"/>
|
||||
</Hyperlink>
|
||||
</TextBlock>
|
||||
|
||||
<ListBox SelectedItem="{Binding SelectedTheme}" ItemsSource="{Binding Themes}"
|
||||
Margin="10, 0, 10, 10" Width="180"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
|
||||
@ -287,53 +292,33 @@
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="{DynamicResource proxy}" Height="22" VerticalAlignment="Top">
|
||||
<TabItem Header="{DynamicResource proxy}" >
|
||||
<StackPanel>
|
||||
<CheckBox x:Name="ToggleProxy" Margin="10" Checked="ProxyToggled" Unchecked="ProxyToggled">
|
||||
<CheckBox Margin="10" IsChecked="{Binding Settings.ProxyEnabled}">
|
||||
<TextBlock Text="{DynamicResource enableProxy}" />
|
||||
</CheckBox>
|
||||
<Grid Margin="10" IsEnabled="{Binding IsChecked, ElementName=ToggleProxy}">
|
||||
<Grid Margin="10" IsEnabled="{Binding Settings.ProxyEnabled}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="80" />
|
||||
<ColumnDefinition Width="220" />
|
||||
<ColumnDefinition Width="80" />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="100" />
|
||||
<ColumnDefinition Width="200" />
|
||||
<ColumnDefinition Width="100" />
|
||||
<ColumnDefinition Width="200"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border Grid.Row="0" Grid.Column="0" Padding="5">
|
||||
<TextBlock Text="{DynamicResource server}" />
|
||||
</Border>
|
||||
<Border Grid.Row="0" Grid.Column="1" Padding="5">
|
||||
<TextBox Width="200" HorizontalAlignment="Left" x:Name="ProxyServer" />
|
||||
</Border>
|
||||
<Border Grid.Row="0" Grid.Column="2" Padding="5">
|
||||
<TextBlock Text="{DynamicResource port}" />
|
||||
</Border>
|
||||
<Border Grid.Row="0" Grid.Column="3" Padding="5">
|
||||
<TextBox Width="50" HorizontalAlignment="Left" x:Name="ProxyPort" />
|
||||
</Border>
|
||||
<Border Grid.Row="1" Grid.Column="0" Padding="5">
|
||||
<TextBlock Text="{DynamicResource userName}" />
|
||||
</Border>
|
||||
<Border Grid.Row="1" Grid.Column="1" Padding="5">
|
||||
<TextBox Width="200" HorizontalAlignment="Left" x:Name="ProxyUserName" />
|
||||
</Border>
|
||||
<Border Grid.Row="1" Grid.Column="2" Padding="5">
|
||||
<TextBlock Text="{DynamicResource password}" />
|
||||
</Border>
|
||||
<Border Grid.Row="1" Grid.Column="3" Padding="5">
|
||||
<PasswordBox Width="200" HorizontalAlignment="Left" x:Name="ProxyPassword" />
|
||||
</Border>
|
||||
<TextBlock Text="{DynamicResource server}" Grid.Row="0" Grid.Column="0" Padding="5" />
|
||||
<TextBox Text="{Binding Settings.ProxyServer}" Grid.Row="0" Grid.Column="1" Padding="5" />
|
||||
<TextBlock Text="{DynamicResource port}" Grid.Row="0" Grid.Column="2" Padding="5"/>
|
||||
<TextBox Text="{Binding Settings.ProxyPort}" Grid.Row="0" Grid.Column="3" Padding="5"/>
|
||||
<TextBlock Text="{DynamicResource userName}" Grid.Row="1" Grid.Column="0" Padding="5"/>
|
||||
<TextBox Text="{Binding Settings.ProxyUserName}" Grid.Row="1" Grid.Column="1" Padding="5"/>
|
||||
<TextBlock Text="{DynamicResource password}" Grid.Row="1" Grid.Column="2" Padding="5" />
|
||||
<TextBox Text="{Binding Settings.ProxyPassword}" Grid.Row="1" Grid.Column="3" Padding="5" />
|
||||
</Grid>
|
||||
<StackPanel Orientation="Horizontal" IsEnabled="{Binding IsChecked, ElementName=ToggleProxy}">
|
||||
<Button Width="80" HorizontalAlignment="Left" Margin="10" Click="btnTestProxy_Click"
|
||||
Content="{DynamicResource testProxy}" />
|
||||
<Button Width="80" HorizontalAlignment="Left" Margin="10" Click="btnSaveProxy_Click"
|
||||
Content="{DynamicResource save}" />
|
||||
</StackPanel>
|
||||
<Button Content="{DynamicResource testProxy}" IsEnabled="{Binding Settings.ProxyEnabled}"
|
||||
Width="80" HorizontalAlignment="Left" Margin="10" Click="OnTestProxyClick"/>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem Header="{DynamicResource about}">
|
||||
@ -354,34 +339,27 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock x:Name="ActivatedTimes" Grid.Row="0" Grid.ColumnSpan="3"
|
||||
Text="{DynamicResource about_activate_times}" />
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="1" Text="{DynamicResource website}" />
|
||||
<TextBlock Grid.Column="1" Grid.Row="1" HorizontalAlignment="Left">
|
||||
<Hyperlink NavigateUri="https://github.com/Wox-launcher/Wox" RequestNavigate="OnRequestNavigate">
|
||||
https://github.com/Wox-launcher/Wox
|
||||
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" Text="{Binding ActivatedTimes}" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Text="{DynamicResource website}"/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left">
|
||||
<Hyperlink NavigateUri="{Binding Github, Mode=OneWay}" RequestNavigate="OnRequestNavigate">
|
||||
<Run Text="{Binding Github, Mode=OneWay}"/>
|
||||
</Hyperlink>
|
||||
</TextBlock>
|
||||
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="2" Text="{DynamicResource version}" />
|
||||
<TextBlock Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" x:Name="Version" Text="1.0.0" />
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="3" Text="{DynamicResource releaseNotes}" />
|
||||
<TextBlock Grid.Column="1" Grid.Row="3" HorizontalAlignment="Left">
|
||||
<Hyperlink NavigateUri="https://github.com/Wox-launcher/Wox/releases/latest"
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Text="{DynamicResource version}" />
|
||||
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Version}" />
|
||||
<TextBlock Grid.Row="3" Grid.Column="0" Text="{DynamicResource releaseNotes}" />
|
||||
<TextBlock Grid.Row="3" Grid.Column="1" >
|
||||
<Hyperlink NavigateUri="{Binding ReleaseNotes, Mode=OneWay}"
|
||||
RequestNavigate="OnRequestNavigate">
|
||||
https://github.com/Wox-launcher/Wox/releases/latest
|
||||
<Run Text="{Binding ReleaseNotes, Mode=OneWay}"/>
|
||||
</Hyperlink>
|
||||
</TextBlock>
|
||||
|
||||
<Button Grid.Column="0" Grid.Row="4" Content="{DynamicResource checkUpdates}"
|
||||
HorizontalAlignment="Left" Margin="10 10 10 10" Click="OnCheckUpdates" />
|
||||
<TextBlock Grid.Column="1" Grid.Row="4" Name="NewVersionTips" HorizontalAlignment="Left"
|
||||
Text="{DynamicResource newVersionTips}" Visibility="Hidden" />
|
||||
|
||||
<Button Grid.Row="4" Grid.Column="0"
|
||||
Content="{DynamicResource checkUpdates}" Click="OnCheckUpdates"
|
||||
HorizontalAlignment="Left" Margin="10 10 10 10" />
|
||||
<TextBlock Grid.Row="4" Grid.Column="1" Text="{Binding NewVersionTips}"
|
||||
HorizontalAlignment="Left" Visibility="{Binding NewVersionTipsVisibility}" />
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
|
@ -26,8 +26,6 @@ namespace Wox
|
||||
private const string StartupPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||
|
||||
public readonly IPublicAPI _api;
|
||||
bool settingsLoaded;
|
||||
private bool themeTabLoaded;
|
||||
private Settings _settings;
|
||||
private SettingWindowViewModel _viewModel;
|
||||
|
||||
@ -38,39 +36,6 @@ namespace Wox
|
||||
DataContext = viewModel;
|
||||
_viewModel = viewModel;
|
||||
_api = api;
|
||||
Loaded += Setting_Loaded;
|
||||
}
|
||||
|
||||
private void ProxyToggled(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_settings.ProxyEnabled = ToggleProxy.IsChecked ?? false;
|
||||
}
|
||||
|
||||
private void Setting_Loaded(object sender, RoutedEventArgs ev)
|
||||
{
|
||||
#region Proxy
|
||||
|
||||
ToggleProxy.IsChecked = _settings.ProxyEnabled;
|
||||
ProxyServer.Text = _settings.ProxyServer;
|
||||
if (_settings.ProxyPort != 0)
|
||||
{
|
||||
ProxyPort.Text = _settings.ProxyPort.ToString();
|
||||
}
|
||||
ProxyUserName.Text = _settings.ProxyUserName;
|
||||
ProxyPassword.Password = _settings.ProxyPassword;
|
||||
|
||||
#endregion
|
||||
|
||||
#region About
|
||||
|
||||
string activateTimes = string.Format(
|
||||
InternationalizationManager.Instance.GetTranslation("about_activate_times"), _settings.ActivateTimes);
|
||||
ActivatedTimes.Text = activateTimes;
|
||||
Version.Text = Infrastructure.Constant.Version;
|
||||
|
||||
#endregion
|
||||
|
||||
settingsLoaded = true;
|
||||
}
|
||||
|
||||
#region General
|
||||
@ -245,14 +210,6 @@ namespace Wox
|
||||
|
||||
#endregion
|
||||
|
||||
#region Theme
|
||||
|
||||
private void OnMoreThemesClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
Process.Start("http://www.getwox.com/theme");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Plugin
|
||||
|
||||
private void OnPluginToggled(object sender, RoutedEventArgs e)
|
||||
@ -301,82 +258,40 @@ namespace Wox
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMorePluginsClicked(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
Process.Start("http://www.getwox.com/plugin");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Proxy
|
||||
|
||||
private void btnSaveProxy_Click(object sender, RoutedEventArgs e)
|
||||
private void OnTestProxyClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
_settings.ProxyEnabled = ToggleProxy.IsChecked ?? false;
|
||||
|
||||
int port = 80;
|
||||
if (_settings.ProxyEnabled)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ProxyServer.Text))
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(ProxyPort.Text))
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
|
||||
return;
|
||||
}
|
||||
if (!int.TryParse(ProxyPort.Text, out port))
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPortFormat"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_settings.ProxyServer = ProxyServer.Text;
|
||||
_settings.ProxyPort = port;
|
||||
_settings.ProxyUserName = ProxyUserName.Text;
|
||||
_settings.ProxyPassword = ProxyPassword.Password;
|
||||
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("saveProxySuccessfully"));
|
||||
}
|
||||
|
||||
private void btnTestProxy_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ProxyServer.Text))
|
||||
if (string.IsNullOrEmpty(_settings.ProxyServer))
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(ProxyPort.Text))
|
||||
if (_settings.ProxyPort > 0)
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
|
||||
return;
|
||||
}
|
||||
int port;
|
||||
if (!int.TryParse(ProxyPort.Text, out port))
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPortFormat"));
|
||||
return;
|
||||
}
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.baidu.com");
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Infrastructure.Constant.Github);
|
||||
request.Timeout = 1000 * 5;
|
||||
request.ReadWriteTimeout = 1000 * 5;
|
||||
if (string.IsNullOrEmpty(ProxyUserName.Text))
|
||||
if (string.IsNullOrEmpty(_settings.ProxyUserName) || string.IsNullOrEmpty(_settings.ProxyPassword))
|
||||
{
|
||||
request.Proxy = new WebProxy(ProxyServer.Text, port);
|
||||
request.Proxy = new WebProxy(_settings.ProxyServer, _settings.ProxyPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
request.Proxy = new WebProxy(ProxyServer.Text, port);
|
||||
request.Proxy.Credentials = new NetworkCredential(ProxyUserName.Text, ProxyPassword.Password);
|
||||
request.Proxy = new WebProxy(_settings.ProxyServer, _settings.ProxyPort)
|
||||
{
|
||||
Credentials = new NetworkCredential(_settings.ProxyUserName, _settings.ProxyPassword)
|
||||
};
|
||||
}
|
||||
try
|
||||
{
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
var response = (HttpWebResponse)request.GetResponse();
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyIsCorrect"));
|
||||
@ -412,9 +327,8 @@ namespace Wox
|
||||
var oldVersion = Updater.NumericVersion(Infrastructure.Constant.Version);
|
||||
if (newVersion > oldVersion)
|
||||
{
|
||||
NewVersionTips.Text = string.Format(NewVersionTips.Text, version);
|
||||
NewVersionTips.Visibility = Visibility.Visible;
|
||||
Updater.UpdateApp();
|
||||
_viewModel.NewVersionTips = version;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -424,7 +338,5 @@ namespace Wox
|
||||
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,14 +21,15 @@ namespace Wox.ViewModel
|
||||
public class SettingWindowViewModel
|
||||
{
|
||||
public Settings Settings { get; set; }
|
||||
|
||||
private readonly JsonStrorage<Settings> _storage;
|
||||
|
||||
#region general
|
||||
public List<Language> Languages => InternationalizationManager.Instance.LoadAvailableLanguages();
|
||||
public List<Language> Languages => _translater.LoadAvailableLanguages();
|
||||
private Internationalization _translater => InternationalizationManager.Instance;
|
||||
public IEnumerable<int> MaxResultsRange => Enumerable.Range(2, 16);
|
||||
#endregion
|
||||
#region plugin
|
||||
public static string Plugin => "http://www.getwox.com/plugin";
|
||||
public PluginViewModel SelectedPlugin { get; set; }
|
||||
public IList<PluginViewModel> PluginViewModels
|
||||
{
|
||||
@ -72,13 +73,13 @@ namespace Wox.ViewModel
|
||||
{
|
||||
multipleActionKeywordsProvider.ActionKeywordsChanged += (o, e) =>
|
||||
{
|
||||
// update in-memory data
|
||||
PluginManager.UpdateActionKeywordForPlugin(SelectedPlugin.PluginPair, e.OldActionKeyword,
|
||||
e.NewActionKeyword);
|
||||
// update persistant data
|
||||
Settings.PluginSettings.UpdateActionKeyword(SelectedPlugin.Metadata);
|
||||
// update in-memory data
|
||||
PluginManager.UpdateActionKeywordForPlugin(SelectedPlugin.PluginPair, e.OldActionKeyword,
|
||||
e.NewActionKeyword);
|
||||
// update persistant data
|
||||
Settings.PluginSettings.UpdateActionKeyword(SelectedPlugin.Metadata);
|
||||
|
||||
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
|
||||
MessageBox.Show(_translater.GetTranslation("succeed"));
|
||||
};
|
||||
}
|
||||
var control = settingProvider.CreateSettingPanel();
|
||||
@ -95,6 +96,7 @@ namespace Wox.ViewModel
|
||||
#endregion
|
||||
#region theme
|
||||
|
||||
public static string Theme => @"http://www.getwox.com/theme";
|
||||
public string SelectedTheme
|
||||
{
|
||||
get
|
||||
@ -139,8 +141,7 @@ namespace Wox.ViewModel
|
||||
{
|
||||
|
||||
const string image = "app.png";
|
||||
const string theme = "http://www.getwox.com/theme/builder";
|
||||
const string plugin = "http://www.getwox.com/plugin";
|
||||
|
||||
List<Result> results = new List<Result>
|
||||
{
|
||||
new Result
|
||||
@ -164,12 +165,12 @@ namespace Wox.ViewModel
|
||||
new Result
|
||||
{
|
||||
Title = "Build custom themes at: ",
|
||||
SubTitle = theme,
|
||||
SubTitle = Theme,
|
||||
},
|
||||
new Result
|
||||
{
|
||||
Title = "Install plugins from: ",
|
||||
SubTitle = plugin,
|
||||
SubTitle = Plugin,
|
||||
IcoPath = image,
|
||||
},
|
||||
new Result
|
||||
@ -278,8 +279,25 @@ namespace Wox.ViewModel
|
||||
|
||||
#endregion
|
||||
#region hotkey
|
||||
public CustomPluginHotkey SelectedCustomPluginHotkey { get; set; }
|
||||
#endregion
|
||||
#region about
|
||||
|
||||
public CustomPluginHotkey SelectedCustomPluginHotkey {get;set;}
|
||||
public static string Github => Infrastructure.Constant.Github;
|
||||
public static string ReleaseNotes => @"https://github.com/Wox-launcher/Wox/releases/latest";
|
||||
public static string Version => Infrastructure.Constant.Version;
|
||||
public string ActivatedTimes => Format(_translater.GetTranslation("about_activate_times"), Settings.ActivateTimes);
|
||||
private string _newVersionTips;
|
||||
public string NewVersionTips
|
||||
{
|
||||
get { return _newVersionTips; }
|
||||
set
|
||||
{
|
||||
_newVersionTips = Format(_translater.GetTranslation("newVersionTips"), value);
|
||||
NewVersionTipsVisibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
public Visibility NewVersionTipsVisibility { get; set; }
|
||||
#endregion
|
||||
public SettingWindowViewModel()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user