Browse Source

Progress on building UI from handlers.

Douglas Thrift 9 years ago
parent
commit
3789791fff

+ 13 - 0
ssh-handler/AbstractHandler.cs

@@ -27,6 +27,19 @@ using System.Text.RegularExpressions;
 
 public abstract class AbstractHandler
 {
+    public abstract IList<Setting> Settings
+    {
+        get;
+    }
+
+    public Setting Setting
+    {
+        get
+        {
+            return Settings.Single(setting => setting.handler);
+        }
+    }
+
     protected string FindInPath(string program)
     {
         foreach (string location in Environment.GetEnvironmentVariable("PATH").Split(Path.PathSeparator))

+ 4 - 0
ssh-handler/Handler.cs

@@ -36,6 +36,10 @@ public interface Handler
     {
         get;
     }
+    Setting Setting
+    {
+        get;
+    }
 
     MatchOption DoMatch(string arg);
     bool Find();

+ 1 - 1
ssh-handler/OpensshHandler.cs

@@ -70,7 +70,7 @@ public class OpensshHandler : AbstractHandler, Handler
         }
     }
 
-    public IList<Setting> Settings
+    public override IList<Setting> Settings
     {
         get
         {

+ 1 - 1
ssh-handler/PuttyHandler.cs

@@ -48,7 +48,7 @@ public class PuttyHandler : AbstractHandler, Handler
         }
     }
 
-    public IList<Setting> Settings
+    public override IList<Setting> Settings
     {
         get
         {

+ 1 - 1
ssh-handler/SshHandler.cs

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

+ 9 - 4
ssh-handler/SshHandlerSettings.xaml

@@ -17,10 +17,15 @@
             Margin="6,7,0,0"
             VerticalScrollBarVisibility="Auto"
             >
-            <StackPanel>
-                <RadioButton
-                    Content="Find the first suitable SSH application"
-                    />
+            <StackPanel Name="SettingsPanel">
+                <GroupBox>
+                    <GroupBox.Header>
+                        <RadioButton
+                            Content="Find the first suitable SSH application"
+                            GroupName="Handlers"
+                            />
+                    </GroupBox.Header>
+                </GroupBox>
             </StackPanel>
         </ScrollViewer>
         <StackPanel

+ 30 - 1
ssh-handler/SshHandlerSettings.xaml.cs

@@ -19,15 +19,35 @@
  *  limitations under the License.
  */
 
+using System.Collections.Generic;
 using System.Diagnostics;
 using System.Reflection;
 using System.Windows;
+using System.Windows.Controls;
 
 public partial class SshHandlerSettings : Window
 {
-    public SshHandlerSettings()
+    public SshHandlerSettings(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);
+        }
     }
 
     private void OkButton_Click(object sender, RoutedEventArgs e)
@@ -48,4 +68,13 @@ 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;
+    }
 }