mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-03-10 22:44:21 +00:00
moved stuff around again. WPF didnt like things once they were moved. Also wired up Join dialog.
This commit is contained in:
parent
a4c2740852
commit
6536474b94
16
windows/WinUI/JoinNetworkView.xaml
Normal file
16
windows/WinUI/JoinNetworkView.xaml
Normal file
@ -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>
|
126
windows/WinUI/JoinNetworkView.xaml.cs
Normal file
126
windows/WinUI/JoinNetworkView.xaml.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
@ -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>
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user