Browse Source

Progress on the settings dialog; it's a bit rough, but it's all there.

Douglas Thrift 9 years ago
parent
commit
87a4be3836

+ 1 - 2
.gitignore

@@ -96,8 +96,7 @@ publish/
 *.pubxml
 
 # NuGet Packages Directory
-## TODO: If you have NuGet Package Restore enabled, uncomment the next line
-#packages/
+packages/
 
 # Windows Azure Build Output
 csx

+ 17 - 1
ssh-handler/AbstractHandler.cs

@@ -27,7 +27,23 @@ using System.Text.RegularExpressions;
 
 public abstract class AbstractHandler
 {
-    public abstract IList<Setting> Settings
+    public IEnumerable<string> Options
+    {
+        get
+        {
+            return Settings.Select(setting => setting.pattern);
+        }
+    }
+
+    public IEnumerable<string> Usages
+    {
+        get
+        {
+            return Settings.Select(setting => setting.usage);
+        }
+    }
+
+    public abstract IEnumerable<Setting> Settings
     {
         get;
     }

+ 3 - 3
ssh-handler/Handler.cs

@@ -24,15 +24,15 @@ using System.Collections.Generic;
 
 public interface Handler
 {
-    IList<string> Options
+    IEnumerable<string> Options
     {
         get;
     }
-    IList<string> Usages
+    IEnumerable<string> Usages
     {
         get;
     }
-    IList<Setting> Settings
+    IEnumerable<Setting> Settings
     {
         get;
     }

+ 17 - 0
ssh-handler/HandlerSettingsBox.xaml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8" ?> 
+<GroupBox
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    x:Class="HandlerSettingsBox"
+    >
+    <GroupBox.Header>
+        <RadioButton
+            GroupName="Handlers"
+            Name="HandlerRadioButton"
+            Content="Handler"
+            />
+    </GroupBox.Header>
+    <StackPanel
+        Name="SettingsPanel"
+        />
+</GroupBox>

+ 49 - 0
ssh-handler/HandlerSettingsBox.xaml.cs

@@ -0,0 +1,49 @@
+// SSH Handler Settings
+//
+// Douglas Thrift
+//
+// HandlerSettingsBox.xaml.cs
+
+/*  Copyright 2014 Douglas Thrift
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+using System.Windows.Controls;
+
+public partial class HandlerSettingsBox : GroupBox
+{
+    private Handler handler;
+
+    public HandlerSettingsBox(Handler handler)
+    {
+        InitializeComponent();
+
+        this.handler = handler;
+        HandlerRadioButton.Content = handler.Setting.name;
+
+        foreach (Setting setting in handler.Settings)
+            switch (setting.type)
+            {
+            case SettingType.OptionalExecutable:
+                SettingsPanel.Children.Add(new OptionalExecutablePanel(setting));
+                break;
+            case SettingType.OptionalYesNoExecutable:
+                SettingsPanel.Children.Add(new OptionalYesNoExecutablePanel(setting));
+                break;
+            case SettingType.OptionalYesNoDirectory:
+                SettingsPanel.Children.Add(new OptionalYesNoDirectoryPanel(setting));
+                break;
+            }
+    }
+}

+ 5 - 33
ssh-handler/OpensshHandler.cs

@@ -42,44 +42,16 @@ public class OpensshHandler : AbstractHandler, Handler
     string minttyPath = null;
     string bashPath = null;
 
-    public IList<string> Options
-    {
-        get
-        {
-            return new string[]
-            {
-                "/openssh[:<openssh-path>]",
-                "/cygwin[:(yes|no|<cygwin-path>)]",
-                "/mintty[:(yes|no|<mintty-path>)]",
-                "/bash[:(yes|no|<bash-path>)]",
-            };
-        }
-    }
-
-    public IList<string> Usages
-    {
-        get
-        {
-            return new string[]
-            {
-                "Use OpenSSH to connect",
-                "Use Cygwin for OpenSSH (by default, Cygwin will be used for OpenSSH if detected)",
-                "Use MinTTY for OpenSSH (by default, MinTTY will be used for OpenSSH if detected)",
-                "Use Bash login shell for use with ssh-agent",
-            };
-        }
-    }
-
-    public override IList<Setting> Settings
+    public override IEnumerable<Setting> Settings
     {
         get
         {
             return new Setting[]
             {
-                new Setting("/openssh", "OpenSSH", SettingType.OptionalPath, true),
-                new Setting("/cygwin", "Cygwin", SettingType.OptionalYesNoDirectory),
-                new Setting("/mintty", "MinTTY", SettingType.OptionalYesNoExecutable),
-                new Setting("/bash", "Bash", SettingType.OptionalYesNoExecutable),
+                new Setting("/openssh", "/openssh[:<openssh-path>]", "OpenSSH", "Use OpenSSH to connect", SettingType.OptionalExecutable, true),
+                new Setting("/cygwin", "/cygwin[:(yes|no|<cygwin-path>)]", "Cygwin", "Use Cygwin for OpenSSH (by default, Cygwin will be used for OpenSSH if detected)", SettingType.OptionalYesNoDirectory),
+                new Setting("/mintty", "/mintty[:(yes|no|<mintty-path>)]", "MinTTY", "Use MinTTY for OpenSSH (by default, MinTTY will be used for OpenSSH if detected)", SettingType.OptionalYesNoExecutable),
+                new Setting("/bash", "/bash[:(yes|no|<bash-path>)]", "Bash", "Use Bash login shell for use with ssh-agent", SettingType.OptionalYesNoExecutable),
             };
         }
     }

+ 29 - 0
ssh-handler/OptionalExecutablePanel.xaml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<StackPanel
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
+    x:Class="OptionalExecutablePanel"
+    >
+    <Label>
+        <TextBlock
+            Name="SettingUsage"
+            TextWrapping="Wrap"
+            />
+    </Label>
+    <StackPanel
+        Orientation="Horizontal"
+        >
+        <CheckBox
+            Name="SettingCheckBox"
+            Content="Executable:"
+            />
+        <toolkit:AutoCompleteBox
+            Name="SettingExecutableBox"
+            />
+        <Button
+            Name="SettingExecutableBrowse"
+            Content="Browse..."
+            />
+    </StackPanel>
+</StackPanel>

+ 39 - 0
ssh-handler/OptionalExecutablePanel.xaml.cs

@@ -0,0 +1,39 @@
+// SSH Handler Settings
+//
+// Douglas Thrift
+//
+// OptionalExecutablePanel.xaml.cs
+
+/*  Copyright 2014 Douglas Thrift
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+using System.Windows.Controls;
+
+public partial class OptionalExecutablePanel : StackPanel
+{
+    private Setting setting;
+
+    public OptionalExecutablePanel(Setting setting)
+    {
+        InitializeComponent();
+
+        this.setting = setting;
+
+        if (!setting.handler)
+            SettingCheckBox.Content = setting.name + " Executable:";
+
+        SettingUsage.Text = setting.usage + ":";
+    }
+}

+ 41 - 0
ssh-handler/OptionalYesNoDirectoryPanel.xaml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8" ?> 
+<StackPanel
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
+    x:Class="OptionalYesNoDirectoryPanel"
+    >
+    <Label>
+        <TextBlock
+            Name="SettingUsage"
+            TextWrapping="Wrap"
+            />
+    </Label>
+    <StackPanel
+        Orientation="Horizontal"
+        >
+        <CheckBox
+            Name="SettingCheckBox"
+            Content="Executable:"
+            />
+        <RadioButton
+            Name="SettingYes"
+            Content="Yes"
+            />
+        <RadioButton
+            Name="SettingNo"
+            Content="No"
+            />
+        <RadioButton
+            Name="SettingDirectory"
+            Content="Directory:"
+            />
+        <toolkit:AutoCompleteBox
+            Name="SettingDirectoryBox"
+            />
+        <Button
+            Name="SettingDirectoryBrowse"
+            Content="Browse..."
+            />
+    </StackPanel>
+</StackPanel>

+ 39 - 0
ssh-handler/OptionalYesNoDirectoryPanel.xaml.cs

@@ -0,0 +1,39 @@
+// SSH Handler Settings
+//
+// Douglas Thrift
+//
+// OptionalYesNoDirectoryPanel.xaml.cs
+
+/*  Copyright 2014 Douglas Thrift
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+using System.Windows.Controls;
+
+public partial class OptionalYesNoDirectoryPanel : StackPanel
+{
+    private Setting setting;
+
+    public OptionalYesNoDirectoryPanel(Setting setting)
+    {
+        InitializeComponent();
+
+        this.setting = setting;
+
+        if (!setting.handler)
+            SettingCheckBox.Content = setting.name + ":";
+
+        SettingUsage.Text = setting.usage + ":";
+    }
+}

+ 41 - 0
ssh-handler/OptionalYesNoExecutablePanel.xaml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<StackPanel
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+    xmlns:toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
+    x:Class="OptionalYesNoExecutablePanel"
+    >
+    <Label>
+        <TextBlock
+            Name="SettingUsage"
+            TextWrapping="Wrap"
+            />
+    </Label>
+    <StackPanel
+        Orientation="Horizontal"
+        >
+        <CheckBox
+            Name="SettingCheckBox"
+            Content="Executable:"
+            />
+        <RadioButton
+            Name="SettingYes"
+            Content="Yes"
+            />
+        <RadioButton
+            Name="SettingNo"
+            Content="No"
+            />
+        <RadioButton
+            Name="SettingExecutable"
+            Content="Executable:"
+            />
+        <toolkit:AutoCompleteBox
+            Name="SettingExecutableBox"
+            />
+        <Button
+            Name="SettingExecutableBrowse"
+            Content="Browse..."
+            />
+    </StackPanel>
+</StackPanel>

+ 39 - 0
ssh-handler/OptionalYesNoExecutablePanel.xaml.cs

@@ -0,0 +1,39 @@
+// SSH Handler Settings
+//
+// Douglas Thrift
+//
+// OptionalYesNoExecutablePanel.xaml.cs
+
+/*  Copyright 2014 Douglas Thrift
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+using System.Windows.Controls;
+
+public partial class OptionalYesNoExecutablePanel : StackPanel
+{
+    private Setting setting;
+
+    public OptionalYesNoExecutablePanel(Setting setting)
+    {
+        InitializeComponent();
+
+        this.setting = setting;
+
+        if (!setting.handler)
+            SettingCheckBox.Content = setting.name + ":";
+
+        SettingUsage.Text = setting.usage + ":";
+    }
+}

+ 2 - 18
ssh-handler/PuttyHandler.cs

@@ -32,27 +32,11 @@ public class PuttyHandler : AbstractHandler, Handler
     private Regex regex = new Regex(@"^(?:/|--?)putty(?:[:=](?<putty_path>.*))?$", RegexOptions.IgnoreCase);
     private string path = null;
 
-    public IList<string> Options
+    public override IEnumerable<Setting> Settings
     {
         get
         {
-            return new string[] { "/putty[:<putty-path>]" };
-        }
-    }
-
-    public IList<string> Usages
-    {
-        get
-        {
-            return new string[] { "Use PuTTY to connect" };
-        }
-    }
-
-    public override IList<Setting> Settings
-    {
-        get
-        {
-            return new Setting[] { new Setting("/putty", "PuTTY", SettingType.OptionalPath, true) };
+            return new Setting[] { new Setting("/putty", "/putty[:<putty-path>]", "PuTTY", "Use PuTTY to connect", SettingType.OptionalExecutable, true) };
         }
     }
 

+ 5 - 1
ssh-handler/Setting.cs

@@ -22,14 +22,18 @@
 public struct Setting
 {
     public string option;
+    public string pattern;
     public string name;
+    public string usage;
     public SettingType type;
     public bool handler;
 
-    public Setting(string option, string name, SettingType type, bool handler = false)
+    public Setting(string option, string pattern, string name, string usage, SettingType type, bool handler = false)
     {
         this.option = option;
+        this.pattern = pattern;
         this.name = name;
+        this.usage = usage;
         this.type = type;
         this.handler = handler;
     }

+ 1 - 1
ssh-handler/SettingType.cs

@@ -21,7 +21,7 @@
 
 public enum SettingType
 {
-    OptionalPath,
+    OptionalExecutable,
     OptionalYesNoExecutable,
     OptionalYesNoDirectory,
 }

+ 1 - 1
ssh-handler/SshHandlerSettings.xaml → ssh-handler/SettingsDialog.xaml

@@ -2,7 +2,7 @@
 <Window
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-    x:Class="SshHandlerSettings"
+    x:Class="SettingsDialog"
     Title="SSH Handler Settings"
     Height="510"
     Width="437"

+ 4 - 28
ssh-handler/SshHandlerSettings.xaml.cs → ssh-handler/SettingsDialog.xaml.cs

@@ -2,7 +2,7 @@
 //
 // Douglas Thrift
 //
-// SshHandlerSettings.xaml.cs
+// SettingsDialog.xaml.cs
 
 /*  Copyright 2014 Douglas Thrift
  *
@@ -25,29 +25,14 @@ using System.Reflection;
 using System.Windows;
 using System.Windows.Controls;
 
-public partial class SshHandlerSettings : Window
+public partial class SettingsDialog : Window
 {
-    public SshHandlerSettings(IList<Handler> handlers)
+    public SettingsDialog(IList<Handler> handlers)
     {
         InitializeComponent();
 
         foreach (Handler handler in handlers)
-        {
-            GroupBox box = new GroupBox();
-            RadioButton button = new RadioButton();
-            StackPanel panel = new StackPanel();
-
-            button.Content = handler.Setting.name;
-            button.GroupName = "Handlers";
-
-            foreach (Setting setting in handler.Settings)
-                panel.Children.Add(ControlForSetting(setting));
-
-            box.Header = button;
-            box.Content = panel;
-
-            SettingsPanel.Children.Add(box);
-        }
+            SettingsPanel.Children.Add(new HandlerSettingsBox(handler));
     }
 
     private void OkButton_Click(object sender, RoutedEventArgs e)
@@ -68,13 +53,4 @@ public partial class SshHandlerSettings : Window
 
         Debug.WriteLine("\"{0}\" {1} \"%1\"", program, string.Join(" ", arguments));
     }
-
-    private UIElement ControlForSetting(Setting setting)
-    {
-        Label label = new Label();
-
-        label.Content = string.Format("{0} {1}", setting.name, setting.type);
-
-        return label;
-    }
 }

+ 1 - 1
ssh-handler/SshHandler.cs

@@ -99,7 +99,7 @@ public class SshHandler
 
     private static int Settings()
     {
-        SshHandlerSettings settings = new SshHandlerSettings(handlers);
+        SettingsDialog settings = new SettingsDialog(handlers);
         Nullable<bool> result = settings.ShowDialog();
         Debug.WriteLine("Settings result: {0}", result, null);
 

+ 4 - 0
ssh-handler/packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="WPFToolkit" version="3.5.50211.1" targetFramework="net40-Client" />
+</packages>

+ 41 - 3
ssh-handler/ssh-handler.csproj

@@ -52,6 +52,12 @@
     <Reference Include="PresentationFramework" />
     <Reference Include="System" />
     <Reference Include="System.Core" />
+    <Reference Include="System.Windows.Controls.Input.Toolkit">
+      <HintPath>..\packages\WPFToolkit.3.5.50211.1\lib\System.Windows.Controls.Input.Toolkit.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Windows.Controls.Layout.Toolkit">
+      <HintPath>..\packages\WPFToolkit.3.5.50211.1\lib\System.Windows.Controls.Layout.Toolkit.dll</HintPath>
+    </Reference>
     <Reference Include="System.Xaml" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
@@ -62,20 +68,35 @@
     <Reference Include="System.Windows.Forms" />
     <Reference Include="System.Xml" />
     <Reference Include="WindowsBase" />
+    <Reference Include="WPFToolkit">
+      <HintPath>..\packages\WPFToolkit.3.5.50211.1\lib\WPFToolkit.dll</HintPath>
+    </Reference>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="AbstractHandler.cs" />
     <Compile Include="AutoYesNoOption.cs" />
     <Compile Include="Handler.cs" />
+    <Compile Include="HandlerSettingsBox.xaml.cs">
+      <DependentUpon>HandlerSettingsBox.xaml</DependentUpon>
+    </Compile>
     <Compile Include="MatchOption.cs" />
     <Compile Include="OpensshHandler.cs" />
+    <Compile Include="OptionalExecutablePanel.xaml.cs">
+      <DependentUpon>OptionalExecutablePanel.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="OptionalYesNoDirectoryPanel.xaml.cs">
+      <DependentUpon>OptionalYesNoDirectoryPanel.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="OptionalYesNoExecutablePanel.xaml.cs">
+      <DependentUpon>OptionalYesNoExecutablePanel.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="PuttyHandler.cs" />
     <Compile Include="Setting.cs" />
     <Compile Include="SettingType.cs" />
     <Compile Include="SshHandler.cs" />
-    <Compile Include="SshHandlerSettings.xaml.cs">
-      <DependentUpon>SshHandlerSettings.xaml</DependentUpon>
+    <Compile Include="SettingsDialog.xaml.cs">
+      <DependentUpon>SettingsDialog.xaml</DependentUpon>
     </Compile>
   </ItemGroup>
   <ItemGroup>
@@ -97,9 +118,26 @@
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
+    <None Include="packages.config" />
   </ItemGroup>
   <ItemGroup>
-    <Page Include="SshHandlerSettings.xaml">
+    <Page Include="HandlerSettingsBox.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="OptionalExecutablePanel.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="OptionalYesNoDirectoryPanel.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="OptionalYesNoExecutablePanel.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="SettingsDialog.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>