Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Commit

Permalink
Add group & import remote from clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ExcitedCodes committed May 20, 2020
1 parent de0fb9a commit 8e8a194
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 10 deletions.
9 changes: 4 additions & 5 deletions NaiveWPF/AddRemoteWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ public AddRemoteWindow(RemoteConfig config)
text_add.Text = MainWindow.GetLocalized("AddRemote_EditSave");
}

public AddRemoteWindow(RemoteConfigGroup group, string URI = null)
public AddRemoteWindow(RemoteConfigGroup group, string name = null, string uri = null, bool padding = false)
{
InitializeComponent();
DataContext = this;
Group = group;

if (URI != null)
{
RemoteURI.Value = URI;
}
RemoteName.Value = name ?? "";
RemoteURI.Value = uri ?? "";
EnablePadding.Value = padding;
}

private void ButtonAdd_Click(object sender, RoutedEventArgs e)
Expand Down
1 change: 1 addition & 0 deletions NaiveWPF/NaiveWPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand Down
4 changes: 2 additions & 2 deletions NaiveWPF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.1.2")]
[assembly: AssemblyFileVersion("2.0.1.2")]
[assembly: AssemblyVersion("2.0.2.0")]
[assembly: AssemblyFileVersion("2.0.2.0")]
30 changes: 29 additions & 1 deletion NaiveWPF/Properties/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion NaiveWPF/Properties/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<value>Remote</value>
</data>
<data name="Proxy_RemoteMenu_Add" xml:space="preserve">
<value>Add</value>
<value>Add Remote</value>
</data>
<data name="Proxy_RemoteMenu_Delete" xml:space="preserve">
<value>Delete</value>
Expand Down Expand Up @@ -237,6 +237,12 @@ Items with same name will be overrided!</value>
<data name="Settings_AllowWindowResize" xml:space="preserve">
<value>Allow window resize</value>
</data>
<data name="Proxy_RemoteMenu_AddGroup" xml:space="preserve">
<value>Add Group</value>
</data>
<data name="Proxy_RemoteMenu_Import" xml:space="preserve">
<value>Import from clipboard</value>
</data>
<data name="AddRemote_Add" xml:space="preserve">
<value>Add</value>
</data>
Expand Down Expand Up @@ -270,4 +276,8 @@ Items with same name will be overrided!</value>
<data name="AddSubscription_URI" xml:space="preserve">
<value>Subscription URL</value>
</data>
<data name="YAAAY_9" xml:space="preserve">
<value>Input the group name.
If there's group with same name, nothing will happen.</value>
</data>
</root>
12 changes: 11 additions & 1 deletion NaiveWPF/Properties/Strings.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<value>服务器</value>
</data>
<data name="Proxy_RemoteMenu_Add" xml:space="preserve">
<value>添加</value>
<value>添加服务器</value>
</data>
<data name="Proxy_RemoteMenu_Delete" xml:space="preserve">
<value>删除</value>
Expand Down Expand Up @@ -237,6 +237,12 @@ http://127.0.0.1:8388</value>
<data name="Settings_AllowWindowResize" xml:space="preserve">
<value>允许修改窗口尺寸</value>
</data>
<data name="Proxy_RemoteMenu_AddGroup" xml:space="preserve">
<value>添加组</value>
</data>
<data name="Proxy_RemoteMenu_Import" xml:space="preserve">
<value>从剪贴板导入</value>
</data>
<data name="AddRemote_Add" xml:space="preserve">
<value>添加</value>
</data>
Expand Down Expand Up @@ -270,4 +276,8 @@ http://127.0.0.1:8388</value>
<data name="AddSubscription_URI" xml:space="preserve">
<value>订阅 URL</value>
</data>
<data name="YAAAY_9" xml:space="preserve">
<value>输入新组名
如果存在同名组, 什么都不会发生</value>
</data>
</root>
2 changes: 2 additions & 0 deletions NaiveWPF/View/ProxyTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
</ContextMenu>
<ContextMenu x:Key="RemoteGroupMenu">
<MenuItem Header="{lex:Loc Proxy_RemoteMenu_Add}" Click="MenuItemAddRemote_Click"/>
<MenuItem Header="{lex:Loc Proxy_RemoteMenu_Import}" Click="MenuItemImport_Click"/>
<Separator/>
<MenuItem Header="{lex:Loc Proxy_RemoteMenu_AddGroup}" Click="MenuItemAddGroup_Click"/>
<MenuItem Header="{lex:Loc Proxy_RemoteMenu_Rename}" Click="MenuItemRename_Click"/>
<MenuItem Header="{lex:Loc Proxy_RemoteMenu_Delete}" Click="MenuItemDelete_Click"/>
</ContextMenu>
Expand Down
41 changes: 41 additions & 0 deletions NaiveWPF/View/ProxyTab.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Web;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
Expand Down Expand Up @@ -205,5 +206,45 @@ private void MenuItemRename_Click(object sender, RoutedEventArgs e)
private void MenuItemEdit_Click(object sender, RoutedEventArgs e) => new AddRemoteWindow((RemoteConfig)(sender as MenuItem).DataContext).ShowDialog();

private void MenuItemAddRemote_Click(object sender, RoutedEventArgs e) => new AddRemoteWindow((RemoteConfigGroup)(sender as MenuItem).DataContext).ShowDialog();

private void MenuItemAddGroup_Click(object sender, RoutedEventArgs e)
{
var name = App.YAAYYYYYAAAAAAAAAAYYYYYYYYYYVBYAAAAAAAAAAAY(MainWindow.GetLocalized("YAAAY_9"), "", "Add Group");
if (name == "")
{
return;
}
foreach (var search in Main.Remotes)
{
if (search.Name == name)
{
return;
}
}
Main.Remotes.Add(new RemoteConfigGroup(name));
Main.Save();
}

private void MenuItemImport_Click(object sender, RoutedEventArgs e)
{
try
{
var uri = new UriBuilder(Clipboard.GetText());
var query = HttpUtility.ParseQueryString(uri.Query);

var name = query["name"];
var padding = query["padding"] != null && query["padding"].ToLower() == "true";

query.Remove("name");
query.Remove("padding");
uri.Query = query.Count == 0 ? null : query.ToString();

new AddRemoteWindow((RemoteConfigGroup)(sender as MenuItem).DataContext, name, uri.ToString(), padding).ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}

0 comments on commit 8e8a194

Please sign in to comment.