Browse Source

Flesh out the UI a bit and progress on describing settings in handlers.

Douglas Thrift 9 years ago
parent
commit
3ebca9f84d

+ 4 - 0
ssh-handler/Handler.cs

@@ -32,6 +32,10 @@ public interface Handler
     {
         get;
     }
+    IList<Setting> Settings
+    {
+        get;
+    }
 
     MatchOption DoMatch(string arg);
     bool Find();

+ 14 - 0
ssh-handler/OpensshHandler.cs

@@ -70,6 +70,20 @@ public class OpensshHandler : AbstractHandler, Handler
         }
     }
 
+    public IList<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),
+            };
+        }
+    }
+
     public MatchOption DoMatch(string arg)
     {
         Match match;

+ 8 - 0
ssh-handler/PuttyHandler.cs

@@ -48,6 +48,14 @@ public class PuttyHandler : AbstractHandler, Handler
         }
     }
 
+    public IList<Setting> Settings
+    {
+        get
+        {
+            return new Setting[] { new Setting("/putty", "PuTTY", SettingType.OptionalPath, true) };
+        }
+    }
+
     public MatchOption DoMatch(string arg)
     {
         Match match;

+ 36 - 0
ssh-handler/Setting.cs

@@ -0,0 +1,36 @@
+// Setting
+//
+// Douglas Thrift
+//
+// Setting.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.
+ */
+
+public struct Setting
+{
+    public string option;
+    public string name;
+    public SettingType type;
+    public bool handler;
+
+    public Setting(string option, string name, SettingType type, bool handler = false)
+    {
+        this.option = option;
+        this.name = name;
+        this.type = type;
+        this.handler = handler;
+    }
+}

+ 27 - 0
ssh-handler/SettingType.cs

@@ -0,0 +1,27 @@
+// Setting Type
+//
+// Douglas Thrift
+//
+// SettingType.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.
+ */
+
+public enum SettingType
+{
+    OptionalPath,
+    OptionalYesNoExecutable,
+    OptionalYesNoDirectory,
+}

+ 3 - 1
ssh-handler/SshHandler.cs

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

+ 17 - 1
ssh-handler/SshHandlerSettings.xaml

@@ -9,6 +9,20 @@
     ResizeMode="NoResize"
     >
     <Grid>
+        <ScrollViewer
+            VerticalAlignment="Top"
+            HorizontalAlignment="Left"
+            Height="430"
+            Width="410"
+            Margin="6,7,0,0"
+            VerticalScrollBarVisibility="Auto"
+            >
+            <StackPanel>
+                <RadioButton
+                    Content="Find the first suitable SSH application"
+                    />
+            </StackPanel>
+        </ScrollViewer>
         <StackPanel
             VerticalAlignment="Bottom"
             Orientation="Horizontal"
@@ -20,6 +34,7 @@
                 Margin="0,0,6,0"
                 Width="73"
                 IsDefault="True"
+                Click="OkButton_Click"
                 />
             <Button
                 Content="Cancel"
@@ -32,7 +47,8 @@
                 Margin="0,0,0,0"
                 Width="73"
                 IsEnabled="False"
+                Click="ApplyButton_Click"
                 />
         </StackPanel>
     </Grid>
-</Window>
+</Window>

+ 44 - 2
ssh-handler/SshHandlerSettings.xaml.cs

@@ -1,4 +1,27 @@
-using System.Windows;
+// SSH Handler Settings
+//
+// Douglas Thrift
+//
+// SshHandlerSettings.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.Diagnostics;
+using System.Reflection;
+using System.Windows;
 
 public partial class SshHandlerSettings : Window
 {
@@ -6,4 +29,23 @@ public partial class SshHandlerSettings : Window
     {
         InitializeComponent();
     }
-}
+
+    private void OkButton_Click(object sender, RoutedEventArgs e)
+    {
+        Apply();
+        DialogResult = true;
+    }
+
+    private void ApplyButton_Click(object sender, RoutedEventArgs e)
+    {
+        Apply();
+    }
+
+    private void Apply()
+    {
+        string program = Assembly.GetEntryAssembly().Location;
+        string[] arguments = { "/openssh", "/bash" };
+
+        Debug.WriteLine("\"{0}\" {1} \"%1\"", program, string.Join(" ", arguments));
+    }
+}

+ 2 - 0
ssh-handler/ssh-handler.csproj

@@ -71,6 +71,8 @@
     <Compile Include="OpensshHandler.cs" />
     <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>