diff options
author | Grant Limberg <grant.limberg@zerotier.com> | 2016-11-18 11:33:46 -0800 |
---|---|---|
committer | Grant Limberg <grant.limberg@zerotier.com> | 2016-11-18 11:33:46 -0800 |
commit | 6536474b94b7ce74e262307778ab7d9e69e57143 (patch) | |
tree | 07c77fce07741e62122009a5b2967759c65f2ba7 /windows | |
parent | a4c274085233fe085efd68869dc979ea56183c87 (diff) | |
download | infinitytier-6536474b94b7ce74e262307778ab7d9e69e57143.tar.gz infinitytier-6536474b94b7ce74e262307778ab7d9e69e57143.zip |
moved stuff around again. WPF didnt like things once they were moved. Also wired up Join dialog.
Diffstat (limited to 'windows')
-rw-r--r-- | windows/WinUI/AboutView.xaml (renamed from windows/WinUI/Views/AboutView.xaml) | 0 | ||||
-rw-r--r-- | windows/WinUI/AboutView.xaml.cs (renamed from windows/WinUI/Views/AboutView.xaml.cs) | 0 | ||||
-rw-r--r-- | windows/WinUI/JoinNetworkView.xaml | 16 | ||||
-rw-r--r-- | windows/WinUI/JoinNetworkView.xaml.cs | 126 | ||||
-rw-r--r-- | windows/WinUI/NetworkInfoView.xaml (renamed from windows/WinUI/Views/NetworkInfoView.xaml) | 0 | ||||
-rw-r--r-- | windows/WinUI/NetworkInfoView.xaml.cs (renamed from windows/WinUI/Views/NetworkInfoView.xaml.cs) | 0 | ||||
-rw-r--r-- | windows/WinUI/NetworkListView.xaml (renamed from windows/WinUI/Views/NetworkListView.xaml) | 0 | ||||
-rw-r--r-- | windows/WinUI/NetworkListView.xaml.cs (renamed from windows/WinUI/Views/NetworkListView.xaml.cs) | 0 | ||||
-rw-r--r-- | windows/WinUI/NetworksPage.xaml (renamed from windows/WinUI/Views/NetworksPage.xaml) | 0 | ||||
-rw-r--r-- | windows/WinUI/NetworksPage.xaml.cs (renamed from windows/WinUI/Views/NetworksPage.xaml.cs) | 0 | ||||
-rw-r--r-- | windows/WinUI/PeersPage.xaml (renamed from windows/WinUI/Views/PeersPage.xaml) | 0 | ||||
-rw-r--r-- | windows/WinUI/PeersPage.xaml.cs (renamed from windows/WinUI/Views/PeersPage.xaml.cs) | 0 | ||||
-rw-r--r-- | windows/WinUI/ToolbarItem.xaml (renamed from windows/WinUI/Views/ToolbarItem.xaml) | 0 | ||||
-rw-r--r-- | windows/WinUI/ToolbarItem.xaml.cs (renamed from windows/WinUI/Views/ToolbarItem.xaml.cs) | 10 | ||||
-rw-r--r-- | windows/WinUI/Views/JoinNetworkView.xaml | 12 | ||||
-rw-r--r-- | windows/WinUI/Views/JoinNetworkView.xaml.cs | 27 | ||||
-rw-r--r-- | windows/WinUI/WinUI.csproj | 14 |
17 files changed, 164 insertions, 41 deletions
diff --git a/windows/WinUI/Views/AboutView.xaml b/windows/WinUI/AboutView.xaml index b32ac327..b32ac327 100644 --- a/windows/WinUI/Views/AboutView.xaml +++ b/windows/WinUI/AboutView.xaml diff --git a/windows/WinUI/Views/AboutView.xaml.cs b/windows/WinUI/AboutView.xaml.cs index 38c6134a..38c6134a 100644 --- a/windows/WinUI/Views/AboutView.xaml.cs +++ b/windows/WinUI/AboutView.xaml.cs diff --git a/windows/WinUI/JoinNetworkView.xaml b/windows/WinUI/JoinNetworkView.xaml new file mode 100644 index 00000000..789be106 --- /dev/null +++ b/windows/WinUI/JoinNetworkView.xaml @@ -0,0 +1,16 @@ +<Window x:Class="WinUI.JoinNetworkView" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:local="clr-namespace:WinUI" + mc:Ignorable="d" + Title="Join a Network" Height="120" Width="320"> + <Grid HorizontalAlignment="Left" Margin="0,0,0,0" Width="315"> + <TextBox x:Name="joinNetworkBox" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="291" PreviewTextInput="joinNetworkBox_OnTextEntered" PreviewKeyDown="joinNetworkBox_OnKeyDown"/> + <CheckBox x:Name="allowManagedCheckbox" Content="Allow Managed" HorizontalAlignment="Left" Margin="10,38,0,0" VerticalAlignment="Top" IsChecked="True"/> + <CheckBox x:Name="allowGlobalCheckbox" Content="Allow Global" HorizontalAlignment="Left" Margin="118,38,0,0" VerticalAlignment="Top"/> + <CheckBox x:Name="allowDefaultCheckbox" Content="Allow Default" HorizontalAlignment="Left" Margin="210,38,-6,0" VerticalAlignment="Top"/> + <Button x:Name="joinButton" Content="Join" HorizontalAlignment="Left" Margin="226,58,0,0" Background="#FFFFB354" VerticalAlignment="Top" Width="75" Click="joinButton_Click" IsEnabled="False"/> + </Grid> +</Window> diff --git a/windows/WinUI/JoinNetworkView.xaml.cs b/windows/WinUI/JoinNetworkView.xaml.cs new file mode 100644 index 00000000..548a51e6 --- /dev/null +++ b/windows/WinUI/JoinNetworkView.xaml.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace WinUI +{ + /// <summary> + /// Interaction logic for JoinNetworkView.xaml + /// </summary> + public partial class JoinNetworkView : Window + { + Regex charRegex = new Regex("[0-9a-fxA-FX]"); + Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$"); + + public JoinNetworkView() + { + InitializeComponent(); + + DataObject.AddPastingHandler(joinNetworkBox, onPaste); + DataObject.AddCopyingHandler(joinNetworkBox, onCopyCut); + } + + private void joinNetworkBox_OnTextEntered(object sender, TextCompositionEventArgs e) + { + e.Handled = !charRegex.IsMatch(e.Text); + + if ( (joinNetworkBox.Text.Length + e.Text.Length) == 16) + { + joinButton.IsEnabled = true; + } + else + { + joinButton.IsEnabled = false; + } + } + + private void joinNetworkBox_OnKeyDown(object sender, KeyEventArgs e) + { + if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) + { + if (e.Key == Key.X && joinNetworkBox.IsSelectionActive) + { + // handle ctrl-x removing characters + joinButton.IsEnabled = false; + } + } + else if (e.Key == Key.Delete || e.Key == Key.Back) + { + if ((joinNetworkBox.Text.Length - 1) == 16) + { + joinButton.IsEnabled = true; + } + else + { + joinButton.IsEnabled = false; + } + } + else + { + if ((joinNetworkBox.Text.Length + 1) > 16) + { + e.Handled = true; + } + } + } + + private void onPaste(object sender, DataObjectPastingEventArgs e) + { + var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true); + if (!isText) + { + joinButton.IsEnabled = false; + return; + } + + var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string; + + if (!wholeStringRegex.IsMatch(text)) + { + e.Handled = true; + e.CancelCommand(); + } + + if (text.Length == 16 || (joinNetworkBox.Text.Length + text.Length) == 16) + { + joinButton.IsEnabled = true; + } + else if (text.Length > 16 || (joinNetworkBox.Text.Length + text.Length) > 16) + { + e.Handled = true; + e.CancelCommand(); + } + else + { + joinButton.IsEnabled = false; + } + } + + private void onCopyCut(object sender, DataObjectCopyingEventArgs e) + { + + } + + private void joinButton_Click(object sender, RoutedEventArgs e) + { + bool allowDefault = allowDefaultCheckbox.IsChecked.Value; + bool allowGlobal = allowGlobalCheckbox.IsChecked.Value; + bool allowManaged = allowManagedCheckbox.IsChecked.Value; + + APIHandler.Instance.JoinNetwork(joinNetworkBox.Text, allowManaged, allowGlobal, allowDefault); + + Close(); + } + } +} diff --git a/windows/WinUI/Views/NetworkInfoView.xaml b/windows/WinUI/NetworkInfoView.xaml index b3e8cae0..b3e8cae0 100644 --- a/windows/WinUI/Views/NetworkInfoView.xaml +++ b/windows/WinUI/NetworkInfoView.xaml diff --git a/windows/WinUI/Views/NetworkInfoView.xaml.cs b/windows/WinUI/NetworkInfoView.xaml.cs index ed4cc628..ed4cc628 100644 --- a/windows/WinUI/Views/NetworkInfoView.xaml.cs +++ b/windows/WinUI/NetworkInfoView.xaml.cs diff --git a/windows/WinUI/Views/NetworkListView.xaml b/windows/WinUI/NetworkListView.xaml index a1e74531..a1e74531 100644 --- a/windows/WinUI/Views/NetworkListView.xaml +++ b/windows/WinUI/NetworkListView.xaml diff --git a/windows/WinUI/Views/NetworkListView.xaml.cs b/windows/WinUI/NetworkListView.xaml.cs index c89d4bcc..c89d4bcc 100644 --- a/windows/WinUI/Views/NetworkListView.xaml.cs +++ b/windows/WinUI/NetworkListView.xaml.cs diff --git a/windows/WinUI/Views/NetworksPage.xaml b/windows/WinUI/NetworksPage.xaml index 6f95bc05..6f95bc05 100644 --- a/windows/WinUI/Views/NetworksPage.xaml +++ b/windows/WinUI/NetworksPage.xaml diff --git a/windows/WinUI/Views/NetworksPage.xaml.cs b/windows/WinUI/NetworksPage.xaml.cs index 39a2fefc..39a2fefc 100644 --- a/windows/WinUI/Views/NetworksPage.xaml.cs +++ b/windows/WinUI/NetworksPage.xaml.cs diff --git a/windows/WinUI/Views/PeersPage.xaml b/windows/WinUI/PeersPage.xaml index 57b11edf..57b11edf 100644 --- a/windows/WinUI/Views/PeersPage.xaml +++ b/windows/WinUI/PeersPage.xaml diff --git a/windows/WinUI/Views/PeersPage.xaml.cs b/windows/WinUI/PeersPage.xaml.cs index fac22a49..fac22a49 100644 --- a/windows/WinUI/Views/PeersPage.xaml.cs +++ b/windows/WinUI/PeersPage.xaml.cs diff --git a/windows/WinUI/Views/ToolbarItem.xaml b/windows/WinUI/ToolbarItem.xaml index bbc17649..bbc17649 100644 --- a/windows/WinUI/Views/ToolbarItem.xaml +++ b/windows/WinUI/ToolbarItem.xaml diff --git a/windows/WinUI/Views/ToolbarItem.xaml.cs b/windows/WinUI/ToolbarItem.xaml.cs index 15aeb24b..b7ac793f 100644 --- a/windows/WinUI/Views/ToolbarItem.xaml.cs +++ b/windows/WinUI/ToolbarItem.xaml.cs @@ -30,6 +30,7 @@ namespace WinUI private APIHandler handler = APIHandler.Instance; private NetworkListView netListView = null; + private JoinNetworkView joinNetView = null; private NetworkMonitor mon = NetworkMonitor.Instance; @@ -127,12 +128,17 @@ namespace WinUI private void ToolbarItem_JoinNetworkClicked(object sender, System.EventArgs e) { - + if (joinNetView == null) + { + joinNetView = new JoinNetworkView(); + joinNetView.Closed += JoinNetworkClosed; + joinNetView.Show(); + } } private void JoinNetworkClosed(object sender, System.EventArgs e) { - + joinNetView = null; } private void ToolbarItem_NetworkClicked(object sender, System.Windows.RoutedEventArgs e) diff --git a/windows/WinUI/Views/JoinNetworkView.xaml b/windows/WinUI/Views/JoinNetworkView.xaml deleted file mode 100644 index b359fcd8..00000000 --- a/windows/WinUI/Views/JoinNetworkView.xaml +++ /dev/null @@ -1,12 +0,0 @@ -<Window x:Class="WinUI.JoinNetworkView" - xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:local="clr-namespace:WinUI" - mc:Ignorable="d" - Title="JoinNetworkView" Height="300" Width="300"> - <Grid> - - </Grid> -</Window> diff --git a/windows/WinUI/Views/JoinNetworkView.xaml.cs b/windows/WinUI/Views/JoinNetworkView.xaml.cs deleted file mode 100644 index eca0647e..00000000 --- a/windows/WinUI/Views/JoinNetworkView.xaml.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Shapes; - -namespace WinUI -{ - /// <summary> - /// Interaction logic for JoinNetworkView.xaml - /// </summary> - public partial class JoinNetworkView : Window - { - public JoinNetworkView() - { - InitializeComponent(); - } - } -} diff --git a/windows/WinUI/WinUI.csproj b/windows/WinUI/WinUI.csproj index 92ee586a..53f715d0 100644 --- a/windows/WinUI/WinUI.csproj +++ b/windows/WinUI/WinUI.csproj @@ -101,6 +101,12 @@ <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </ApplicationDefinition> + <Compile Include="AboutView.xaml.cs"> + <DependentUpon>AboutView.xaml</DependentUpon> + </Compile> + <Compile Include="JoinNetworkView.xaml.cs"> + <DependentUpon>JoinNetworkView.xaml</DependentUpon> + </Compile> <Compile Include="NetworkMonitor.cs" /> <Compile Include="NetworkRoute.cs" /> <Compile Include="NetworksPage.xaml.cs"> @@ -116,6 +122,14 @@ <Compile Include="ZeroTierPeer.cs" /> <Compile Include="ZeroTierNetwork.cs" /> <Compile Include="ZeroTierStatus.cs" /> + <Page Include="AboutView.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> + <Page Include="JoinNetworkView.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="NetworkListView.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> |