~brad-fie/fiecac/scgui

« back to all changes in this revision

Viewing changes to SCGuiWindow.cs

  • Committer: Brad Friedman
  • Date: 2012-04-21 19:29:46 UTC
  • Revision ID: brad@fie.us-20120421192946-er9uksmojtkkax6y
fixed splaying.  fixed project manager.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//Copyright (C) 2011, FIE LLC.
 
 
b'//See LICENSE.TXT for details.'
 
 
b'using System;'
 
 
b'using System.Collections.Generic;'
 
 
b'using System.ComponentModel;'
 
 
b'using System.Data;'
 
 
b'using System.Text;'
 
 
b'using System.Windows.Forms;'
 
 
b'namespace scgui'
 
 
b'{'
2
1
   public partial class SCGuiWindow : Form
3
2
   {
4
3
       libscclient.ISCUIAppContextClient scguiContext;
5
4
       bool branchingAllowed = true;
6
5
       public libscclient.ISCUIAppContextClient SCGuiContext
7
6
       {
8
7
           get { return scguiContext; }
9
8
           set { scguiContext = value; }
10
9
       }
11
10
       private libscclient.LaunchableContextSettingsPlatform launchers;
 
 
b'\t\tprivate libscclient.IPedestalClient pedestal;'
 
 
b'\t\tprivate libscclient.Client client;'
12
11
       private TreeNode CreateNode(TreeNode root, string path)
13
12
       {
14
13
           TreeNode current = root.Nodes[path];
15
14
           if (current == null)
16
15
           {
17
16
               current = new TreeNode(path);
18
17
               current.Name = path;
19
18
               root.Nodes.Add(current);
20
19
           }
21
20
           return current;
22
21
       }
23
22
       private void AddNodeAtPath(TreeNode parentNode, string newNodeName, string[] path)
24
23
       {
25
24
           TreeNode currentNode = parentNode;
26
25
           
27
26
           if (path != null)
28
27
           {
29
28
               foreach (string s in path)
30
29
               {
31
30
                   currentNode = CreateNode(currentNode, s);                    
32
31
               }
33
32
           }
34
33
           TreeNode nodeToAdd = new ContextTreeNode(newNodeName);
35
34
           nodeToAdd.Name = newNodeName;
36
35
           currentNode.Nodes.Add(nodeToAdd);
37
36
       }
38
37
       private void BuildTree()
39
38
       {
40
39
           string currentNamespace = null;
41
40
           string reason = string.Empty;
 
 
b'\t\t\t'
 
 
b'\t\t\tlibscclient.IContextClient[] stack = client.GetStack();'
 
 
b'\t\t\t'
42
41
           if (stack.Length > 1)
43
42
           {
 
 
b'\t\t\t\tcurrentNamespace = stack[stack.Length - 2].GetSettings().NameSpace;'
44
43
           }
45
44
           TreeNode nsRootNode = null;
46
45
           foreach (string ns in launchers.Data.Keys)
47
46
           {
48
47
               // Create namespace root node.
49
48
               nsRootNode = new NamespaceTreeNode(ns);
50
49
               nsRootNode.Name = ns;
51
50
               this.treeView1.Nodes.Add(nsRootNode);
52
51
               // Iterate through launchers for this ns
 
 
b'\t\t\t\tforeach (string name in launchers.Data[ns].Keys){'
 
 
b'\t\t\t\t\tlibscclient.LaunchableContextSettings launchableSettings = launchers.Data[ns][name];'
 
 
b'\t\t\t\t\tif (launchableSettings.CanRun){'
53
52
                       // create node
54
53
                       AddNodeAtPath(nsRootNode, name, launchableSettings.Path);
55
54
                   }
56
55
                   else
57
56
                   {
58
57
                       System.Console.WriteLine("context cannot run: " + launchableSettings.Reason);
59
58
                   }
60
59
               }
61
60
               if (ns == currentNamespace || currentNamespace == null)
62
61
               {
63
62
                   nsRootNode.Expand();
64
63
               }
65
64
               else
66
65
               {
67
66
                   nsRootNode.Collapse();
68
67
               }
69
68
           }
70
69
       }
71
70
       public SCGuiWindow(libscclient.ISCUIAppContextClient currentContext, bool allowBranching, libscclient.Client client, libscclient.IPedestalClient pedestal)
72
71
       {
73
72
           this.scguiContext = currentContext;
74
73
           this.branchingAllowed = allowBranching;
 
 
b'\t\t\tthis.pedestal = pedestal;'
 
 
b'\t\t\tthis.client = client;'
75
74
           this.launchers = client.GetLaunchPlatformSettings();
76
75
           InitializeComponent();
77
76
           BuildTree();
78
77
       }
79
78
       private void nodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
80
79
       {
81
80
           TreeNode selectedNode = e.Node;
82
81
           if (selectedNode is ContextTreeNode)
83
82
           {
84
83
               string name = selectedNode.Name;
85
84
               TreeNode currentNode = selectedNode.Parent;
86
85
               while (currentNode.Parent != null)
87
86
               {
88
87
                   currentNode = currentNode.Parent;
89
88
               }
90
89
               string ns = currentNode.Name;
 
 
b'\t\t\t\tlibscclient.LaunchableContextSettings launchableSettings;'
 
 
b'\t\t\t\tlaunchableSettings = this.launchers.Data[ns][name];'
91
90
               //branch based on modifier keys
92
91
               if (Control.ModifierKeys == Keys.Shift)
93
92
               {
 
 
b'//                    //shift key pressed.'
 
 
b'//                    //this means leave this SCGui up and make a new on with the selected context.'
 
 
b'//                    //does nothing if branching is not allowed.'
 
 
b'//'
 
 
b'//                    libscclient.ContextSettings settings = launchableSettings.Settings;'
 
 
b'//                    if (launchableSettings.IsIntermediate)'
 
 
b'//                    {'
 
 
b'//                        //the new context is not interactive.  So we should set scgui'
 
 
b'//                        //as the next context before running it.'
 
 
b'//                        '
 
 
b'//\t\t\t\t\t\t//no longer needed becasue we recycle the current one.  To change it, you run it explicitly.'
 
 
b'//\t\t\t\t\t\t//libsc.SCGUIAppContextSettings uisettings = new libsc.SCGUIAppContextSettings();'
 
 
b'//\t\t\t\t\t\t'
 
 
b'//                        settings.AppendToEnd(this.scguiContext.GetSettings()); '
 
 
b'//'
 
 
b'//                    }'
 
 
b'//                    byte[] buffer;'
 
 
b'//                    if (scguiContext.HasParent()){'
 
 
b'//                        buffer = libsc.Context.GetAs<libsc.IntermediateContext>(scguiContext.GetParent()).GetSerializedContextStack(settings.SerializedVersion());'
 
 
b'//                    } else {'
 
 
b'//                        buffer = settings.SerializedVersion();'
 
 
b'//                    }'
 
 
b'//                    System.Diagnostics.Process p = libsc.CurrentContext.SplayContext(buffer);'
94
93
                   
95
94
               }
96
95
               else if (Control.ModifierKeys == Keys.Alt)
97
96
               {
98
97
                   //alt key pressed.
99
98
                   //this opens the settings for the given context and allows them to
100
99
                   //be edited.
 
 
b'\t                System.Windows.Forms.Form f = new Form();'
101
100
                   libpropsguiwf.PropertyPageControl ppc = new libpropsguiwf.PropertyPageControl(launchableSettings.Settings);
 
 
b'\t                f.Controls.Add(ppc);'
 
 
b'\t\t\t\t\tppc.Dock = DockStyle.Fill;'
102
101
                   System.Windows.Forms.Button cancel = new Button();
103
102
                   cancel.Text = "&Close";
104
103
                   f.Controls.Add(cancel);
105
104
                   cancel.Dock = DockStyle.Bottom;
106
105
                   f.MaximizeBox = false;
107
106
                   f.ShowInTaskbar = false;
108
107
                   f.Text = launchableSettings.Settings.NameSpace + ":" + launchableSettings.Settings.Name + " Settings";
109
108
                   f.CancelButton = cancel;
 
 
b'\t                f.ShowDialog(this);'
110
109
                   ppc.DisconnectAllEvents();
111
110
               }
112
111
               else
113
112
               {
114
113
                   //no relevant modifier keys pressed.  run the selected context in this one's place.
115
114
                   libscclient.ContextSettings settings = launchableSettings.Settings;
116
115
                   if (launchableSettings.IsIntermediate)
117
116
                   {
118
117
                       //the new context is not interactive.  So we should set scgui
119
118
                       //as the next context before running it.
 
 
b'\t\t\t\t\t\t'
 
 
b'\t\t\t\t\t\t//not used because we recycle the current one.'
120
119
                       //libsc.SCGUIAppContextSettings uisettings = new libsc.SCGUIAppContextSettings();
 
 
b'\t\t\t\t\t\t'
121
120
                       settings.AppendToEnd(this.SCGuiContext.GetSettings()); 
122
121
                   }
123
122
                   scguiContext.SetSuccessor(settings);
124
123
                   this.Close();
 
 
b'\t\t\t\t\t//System.Windows.Forms.Application.ExitThread();'
125
124
                   //System.Windows.Forms.Application.Exit();
126
125
                   return;
127
126
               }
128
127
           }
129
128
       }
130
129
       private void SCGuiWindow_Load(object sender, EventArgs e)
131
130
       {
132
131
       }
133
132
   }
 
 
b'}'
 
 
b'\\ No newline at end of file'
 
133
//Copyright (C) 2011, FIE LLC.
 
 
b'//See LICENSE.TXT for details.'
 
 
b'using System;'
 
 
b'using System.Collections.Generic;'
 
 
b'using System.ComponentModel;'
 
 
b'using System.Data;'
 
 
b'using System.Text;'
 
 
b'using System.Windows.Forms;'
 
 
b'namespace scgui'
 
 
b'{'
134
134
   public partial class SCGuiWindow : Form
135
135
   {
136
136
       libscclient.ISCUIAppContextClient scguiContext;
137
137
       bool branchingAllowed = true;
138
138
       public libscclient.ISCUIAppContextClient SCGuiContext
139
139
       {
140
140
           get { return scguiContext; }
141
141
           set { scguiContext = value; }
142
142
       }
143
143
       private libscclient.LaunchableContextSettingsPlatform launchers;
 
 
b'\t\tprivate libscclient.IPedestalClient pedestal;'
 
 
b'\t\tprivate libscclient.Client client;'
144
144
       private TreeNode CreateNode(TreeNode root, string path)
145
145
       {
146
146
           TreeNode current = root.Nodes[path];
147
147
           if (current == null)
148
148
           {
149
149
               current = new TreeNode(path);
150
150
               current.Name = path;
151
151
               root.Nodes.Add(current);
152
152
           }
153
153
           return current;
154
154
       }
155
155
       private void AddNodeAtPath(TreeNode parentNode, string newNodeName, string[] path)
156
156
       {
157
157
           TreeNode currentNode = parentNode;
158
158
           
159
159
           if (path != null)
160
160
           {
161
161
               foreach (string s in path)
162
162
               {
163
163
                   currentNode = CreateNode(currentNode, s);                    
164
164
               }
165
165
           }
166
166
           TreeNode nodeToAdd = new ContextTreeNode(newNodeName);
167
167
           nodeToAdd.Name = newNodeName;
168
168
           currentNode.Nodes.Add(nodeToAdd);
169
169
       }
170
170
       private void BuildTree()
171
171
       {
172
172
           string currentNamespace = null;
173
173
           string reason = string.Empty;
 
 
b'\t\t\t'
 
 
b'\t\t\tlibscclient.IContextClient[] stack = client.GetStack();'
 
 
b'\t\t\t'
174
174
           if (stack.Length > 1)
175
175
           {
 
 
b'\t\t\t\tcurrentNamespace = stack[stack.Length - 2].GetSettings().NameSpace;'
176
176
           }
177
177
           TreeNode nsRootNode = null;
178
178
           foreach (string ns in launchers.Data.Keys)
179
179
           {
180
180
               // Create namespace root node.
181
181
               nsRootNode = new NamespaceTreeNode(ns);
182
182
               nsRootNode.Name = ns;
183
183
               this.treeView1.Nodes.Add(nsRootNode);
184
184
               // Iterate through launchers for this ns
 
 
b'\t\t\t\tforeach (string name in launchers.Data[ns].Keys){'
 
 
b'\t\t\t\t\tlibscclient.LaunchableContextSettings launchableSettings = launchers.Data[ns][name];'
 
 
b'\t\t\t\t\tif (launchableSettings.CanRun){'
185
185
                       // create node
186
186
                       AddNodeAtPath(nsRootNode, name, launchableSettings.Path);
187
187
                   }
188
188
                   else
189
189
                   {
190
190
                       System.Console.WriteLine("context cannot run: " + launchableSettings.Reason);
191
191
                   }
192
192
               }
193
193
               if (ns == currentNamespace || currentNamespace == null)
194
194
               {
195
195
                   nsRootNode.Expand();
196
196
               }
197
197
               else
198
198
               {
199
199
                   nsRootNode.Collapse();
200
200
               }
201
201
           }
202
202
       }
203
203
       public SCGuiWindow(libscclient.ISCUIAppContextClient currentContext, bool allowBranching, libscclient.Client client, libscclient.IPedestalClient pedestal)
204
204
       {
205
205
           this.scguiContext = currentContext;
206
206
           this.branchingAllowed = allowBranching;
 
 
b'\t\t\tthis.pedestal = pedestal;'
 
 
b'\t\t\tthis.client = client;'
207
207
           this.launchers = client.GetLaunchPlatformSettings();
208
208
           InitializeComponent();
209
209
           BuildTree();
210
210
       }
211
211
       private void nodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
212
212
       {
213
213
           TreeNode selectedNode = e.Node;
214
214
           if (selectedNode is ContextTreeNode)
215
215
           {
216
216
               string name = selectedNode.Name;
217
217
               TreeNode currentNode = selectedNode.Parent;
218
218
               while (currentNode.Parent != null)
219
219
               {
220
220
                   currentNode = currentNode.Parent;
221
221
               }
222
222
               string ns = currentNode.Name;
 
 
b'\t\t\t\tlibscclient.LaunchableContextSettings launchableSettings;'
 
 
b'\t\t\t\tlaunchableSettings = this.launchers.Data[ns][name];'
223
223
               //branch based on modifier keys
224
224
               if (Control.ModifierKeys == Keys.Shift)
225
225
               {
226
226
                   //shift key pressed.
227
227
                   //this means leave this SCGui up and make a new on with the selected context.
228
228
                   //does nothing if branching is not allowed.
229
229
                   libscclient.ContextSettings settings = launchableSettings.Settings;
230
230
                   if (launchableSettings.IsIntermediate)
231
231
                   {
232
232
                       //the new context is not interactive.  So we should set scgui
233
233
                       //as the next context before running it.
234
234
                       //no longer needed becasue we recycle the current one.  To change it, you run it explicitly.
235
235
                       //libsc.SCGUIAppContextSettings uisettings = new libsc.SCGUIAppContextSettings();
236
236
                       settings.NextSettings = this.scguiContext.GetSettings().SerializedVersionNothingNext();
237
237
                   }
238
238
                   libscclient.ContextSettings splaySettingsStack;
239
239
                   if (scguiContext.HasParent())
240
240
                   {
241
241
                       splaySettingsStack = client.GetSettingsStack(client.GetParent(scguiContext),settings);
242
242
                   }
243
243
                   else
244
244
                   {
245
245
                       splaySettingsStack = settings;
246
246
                   }
247
247
                   pedestal.SplayContextStack(splaySettingsStack);
248
248
                   
249
249
               }
250
250
               else if (Control.ModifierKeys == Keys.Alt)
251
251
               {
252
252
                   //alt key pressed.
253
253
                   //this opens the settings for the given context and allows them to
254
254
                   //be edited.
 
 
b'\t                System.Windows.Forms.Form f = new Form();'
255
255
                   libpropsguiwf.PropertyPageControl ppc = new libpropsguiwf.PropertyPageControl(launchableSettings.Settings);
 
 
b'\t                f.Controls.Add(ppc);'
 
 
b'\t\t\t\t\tppc.Dock = DockStyle.Fill;'
256
256
                   System.Windows.Forms.Button cancel = new Button();
257
257
                   cancel.Text = "&Close";
258
258
                   f.Controls.Add(cancel);
259
259
                   cancel.Dock = DockStyle.Bottom;
260
260
                   f.MaximizeBox = false;
261
261
                   f.ShowInTaskbar = false;
262
262
                   f.Text = launchableSettings.Settings.NameSpace + ":" + launchableSettings.Settings.Name + " Settings";
263
263
                   f.CancelButton = cancel;
 
 
b'\t                f.ShowDialog(this);'
264
264
                   ppc.DisconnectAllEvents();
265
265
               }
266
266
               else
267
267
               {
268
268
                   //no relevant modifier keys pressed.  run the selected context in this one's place.
269
269
                   libscclient.ContextSettings settings = launchableSettings.Settings;
270
270
                   if (launchableSettings.IsIntermediate)
271
271
                   {
272
272
                       //the new context is not interactive.  So we should set scgui
273
273
                       //as the next context before running it.
 
 
b'\t\t\t\t\t\t'
 
 
b'\t\t\t\t\t\t//not used because we recycle the current one.'
274
274
                       //libsc.SCGUIAppContextSettings uisettings = new libsc.SCGUIAppContextSettings();
 
 
b'\t\t\t\t\t\t'
275
275
                       settings.AppendToEnd(this.SCGuiContext.GetSettings()); 
276
276
                   }
277
277
                   scguiContext.SetSuccessor(settings);
278
278
                   this.Close();
 
 
b'\t\t\t\t\t//System.Windows.Forms.Application.ExitThread();'
279
279
                   //System.Windows.Forms.Application.Exit();
280
280
                   return;
281
281
               }
282
282
           }
283
283
       }
284
284
       private void SCGuiWindow_Load(object sender, EventArgs e)
285
285
       {
286
286
       }
287
287
   }
 
 
b'}'
 
 
b'\\ No newline at end of file'