Browse Source

Very early beginnings of a settings dialog

Douglas Thrift 9 years ago
parent
commit
7d636fbaf3

+ 14 - 1
ssh-handler/SshHandler.cs

@@ -35,6 +35,7 @@ public class SshHandler
     };
     private static Handler handler = null;
 
+    [STAThread]
     public static int Main(string[] args)
     {
         Application.EnableVisualStyles();
@@ -42,6 +43,7 @@ public class SshHandler
         try
         {
             Regex usage = new Regex(@"^(?:/|--?)(?:h|help|usage|\?)$", RegexOptions.IgnoreCase);
+            Regex settings = new Regex(@"^(?:/|--?)settings$", RegexOptions.IgnoreCase);
             IList<string> uriParts = null;
 
             foreach (string arg in args)
@@ -50,6 +52,9 @@ public class SshHandler
                     if (usage.IsMatch(arg))
                         return Usage(0);
 
+                    if (settings.IsMatch(arg))
+                        return Settings();
+
                     if (!MatchHandler(arg))
                         uriParts = new List<string>(new string[] { arg });
                 }
@@ -82,15 +87,23 @@ public class SshHandler
 
     private static int Usage(int code)
     {
-        MessageBox.Show("ssh-handler " +
+        MessageBox.Show("ssh-handler [/settings] " +
             string.Join(" ", handlers.SelectMany(handler => handler.Options.Select(option => "[" + option + "]"))) +
             " <ssh-url>\n\n" +
+            "/settings -- Show settings dialog\n\n" +
             string.Join("\n\n", handlers.SelectMany(handler => handler.Options.Zip(handler.Usages, (option, usage) => option + " -- " + usage))),
             "SSH Handler Usage",
             MessageBoxButtons.OK, MessageBoxIcon.Information);
         return code;
     }
 
+    private static int Settings()
+    {
+        new SshHandlerSettings().ShowDialog();
+
+        return 0;
+    }
+
     private static bool MatchHandler(string arg)
     {
         foreach (Handler handler in handlers)

+ 38 - 0
ssh-handler/SshHandlerSettings.xaml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<Window
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    x:Class="SshHandlerSettings"
+    Title="SSH Handler Settings"
+    Height="510"
+    Width="437"
+    ResizeMode="NoResize"
+    >
+    <Grid>
+        <StackPanel
+            VerticalAlignment="Bottom"
+            Orientation="Horizontal"
+            HorizontalAlignment="Right"
+            Margin="7,7,7,8"
+            >
+            <Button
+                Content="OK"
+                Margin="0,0,6,0"
+                Width="73"
+                IsDefault="True"
+                />
+            <Button
+                Content="Cancel"
+                Margin="0,0,6,0"
+                Width="73"
+                IsCancel="True"
+                />
+            <Button
+                Content="_Apply"
+                Margin="0,0,0,0"
+                Width="73"
+                IsEnabled="False"
+                />
+        </StackPanel>
+    </Grid>
+</Window>

+ 9 - 0
ssh-handler/SshHandlerSettings.xaml.cs

@@ -0,0 +1,9 @@
+using System.Windows;
+
+public partial class SshHandlerSettings : Window
+{
+    public SshHandlerSettings()
+    {
+        InitializeComponent();
+    }
+}

+ 13 - 1
ssh-handler/ssh-handler.csproj

@@ -48,8 +48,11 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="PresentationCore" />
+    <Reference Include="PresentationFramework" />
     <Reference Include="System" />
     <Reference Include="System.Core" />
+    <Reference Include="System.Xaml" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
     <Reference Include="Microsoft.CSharp" />
@@ -58,8 +61,8 @@
     <Reference Include="System.Drawing" />
     <Reference Include="System.Windows.Forms" />
     <Reference Include="System.Xml" />
+    <Reference Include="WindowsBase" />
   </ItemGroup>
-  <ItemGroup />
   <ItemGroup>
     <Compile Include="AbstractHandler.cs" />
     <Compile Include="AutoYesNoOption.cs" />
@@ -69,6 +72,9 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="PuttyHandler.cs" />
     <Compile Include="SshHandler.cs" />
+    <Compile Include="SshHandlerSettings.xaml.cs">
+      <DependentUpon>SshHandlerSettings.xaml</DependentUpon>
+    </Compile>
   </ItemGroup>
   <ItemGroup>
     <BootstrapperPackage Include=".NETFramework,Version=v4.5">
@@ -90,6 +96,12 @@
   <ItemGroup>
     <None Include="app.config" />
   </ItemGroup>
+  <ItemGroup>
+    <Page Include="SshHandlerSettings.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.