30 private Builder _builder;
32#pragma warning disable 649
36 private Button cancelBut;
38 private TextView textBox;
40 private ComboBox funcsBox;
42 private Entry nameBox;
44 private ComboBox keysBox;
46 private ComboBox stateBox;
48 private ComboBox modifierBox;
50 private SpinButton valBox;
52 private Entry menuPath;
54 private Entry contextMenuPath;
56 private RadioButton imagejRadioBut;
58 private RadioButton bioRadioBut;
60 private Button setMacroFileBut;
62 private Button setScriptFileBut;
64 private Label fileLabel;
65#pragma warning restore 649
69 #region Constructors / Destructors
74 Builder builder =
new Builder(
new FileStream(System.IO.Path.GetDirectoryName(Environment.ProcessPath) +
"/" +
"Glade/Functions.glade", FileMode.Open));
75 return new Functions(builder, builder.GetObject(
"functions").Handle);
81 protected Functions(Builder builder, IntPtr handle) : base(handle)
84 builder.Autoconnect(
this);
87 App.ApplyStyles(
this);
97 funcsBox.Changed += FuncsBox_Changed;
98 keysBox.Changed += KeysBox_Changed;
99 stateBox.Changed += StateBox_Changed;
100 modifierBox.Changed += ModifiersBox_Changed;
101 okBut.Clicked += OkBut_Clicked;
102 cancelBut.Clicked += CancelBut_Clicked;
103 setMacroFileBut.Clicked += SetMacroFileBut_Clicked;
104 setScriptFileBut.Clicked += SetScriptFileBut_Clicked;
105 valBox.ChangeValue += ValBox_ChangeValue;
106 textBox.Buffer.Changed += Buffer_Changed;
107 imagejRadioBut.Clicked += ImagejRadioBut_Clicked;
108 bioRadioBut.Clicked += BioRadioBut_Clicked;
109 this.KeyPressEvent += Functions_KeyPressEvent;
110 this.DeleteEvent += Functions_DeleteEvent;
113 private bool IterateComboBoxItems(ITreeModel model, TreePath path, TreeIter iter)
116 string item = (string)model.GetValue(iter, 0);
117 if (item == func.Key.ToString())
123 private void Functions_KeyPressEvent(
object o, KeyPressEventArgs args)
126 func.Key = args.Event.Key;
127 keysBox.Model.Foreach(
new TreeModelForeachFunc(IterateComboBoxItems));
134 private void Functions_DeleteEvent(
object o, DeleteEventArgs args)
144 private void BioRadioBut_Clicked(
object sender, EventArgs e)
146 func.FuncType = Function.FunctionType.Script;
153 private void ImagejRadioBut_Clicked(
object sender, EventArgs e)
155 func.FuncType = Function.FunctionType.ImageJ;
163 private void Buffer_Changed(
object sender, EventArgs e)
165 func.Script = textBox.Buffer.Text;
166 if (bioRadioBut.Active)
167 func.FuncType = Function.FunctionType.Script;
169 func.FuncType = Function.FunctionType.ImageJ;
177 private void ValBox_ChangeValue(
object o, ChangeValueArgs args)
179 Func.Value = valBox.Value;
189 private void SetScriptFileBut_Clicked(
object sender, EventArgs e)
191 Gtk.FileChooserDialog filechooser =
192 new Gtk.FileChooserDialog(
"Choose the script file to open",
194 FileChooserAction.Open,
195 "Cancel", ResponseType.Cancel,
196 "Open", ResponseType.Ok);
197 if (filechooser.Run() != (
int)ResponseType.Ok)
199 func.File = filechooser.Filename;
200 fileLabel.Text = func.File;
201 func.FuncType = Function.FunctionType.Script;
211 private void SetMacroFileBut_Clicked(
object sender, EventArgs e)
213 Gtk.FileChooserDialog filechooser =
214 new Gtk.FileChooserDialog(
"Choose the ImageJ macro file to open",
216 FileChooserAction.Open,
217 "Cancel", ResponseType.Cancel,
218 "Open", ResponseType.Ok);
219 if (filechooser.Run() != (
int)ResponseType.Ok)
221 func.File = filechooser.Filename;
222 fileLabel.Text = func.File;
223 func.FuncType = Function.FunctionType.ImageJ;
230 private void CancelBut_Clicked(
object sender, EventArgs e)
239 private void OkBut_Clicked(
object sender, EventArgs e)
241 func.Name = nameBox.Text;
242 func.MenuPath = menuPath.Text;
243 func.ContextPath = contextMenuPath.Text;
244 func.Value = valBox.Value;
245 if (!Function.Functions.ContainsKey(func.Name))
247 Function.Functions.Add(func.Name, func);
251 Function.Functions[func.Name] = func;
253 if (func.MenuPath !=
null && func.MenuPath !=
"")
255 if (func.MenuPath.EndsWith(
"/"))
256 func.MenuPath = func.MenuPath.TrimEnd(
'/');
257 if (func.MenuPath.EndsWith(func.Name) && func.MenuPath.Contains(
"/"))
258 func.MenuPath.Remove(func.MenuPath.IndexOf(
'/'), func.MenuPath.Length - func.MenuPath.IndexOf(
'/'));
259 App.AddMenu(func.MenuPath);
261 if (func.ContextPath !=
null && func.ContextPath !=
"")
263 if (func.ContextPath.EndsWith(
"/"))
264 func.ContextPath = func.ContextPath.TrimEnd(
'/');
265 if (func.ContextPath.EndsWith(func.Name) && func.ContextPath.Contains(
"/"))
266 func.ContextPath.Remove(func.ContextPath.IndexOf(
'/'), func.ContextPath.Length - func.ContextPath.IndexOf(
'/'));
267 App.AddContextMenu(func.ContextPath);
279 private void ModifiersBox_Changed(
object sender, EventArgs e)
281 Func.Modifier = (Gdk.ModifierType)modifierBox.Active;
282 Func.FuncType = Function.FunctionType.Key;
290 private void StateBox_Changed(
object sender, EventArgs e)
292 Func.State = (Function.ButtonState)stateBox.Active;
293 Func.FuncType = Function.FunctionType.Key;
301 private void KeysBox_Changed(
object sender, EventArgs e)
303 Func.Key = (Gdk.Key)keysBox.Active;
304 Func.FuncType = Function.FunctionType.Key;
311 private void FuncsBox_Changed(
object sender, EventArgs e)
313 func = Function.Functions[funcsBox.ActiveId];
323 textBox.Buffer.Text = func.Script;
324 var funcs =
new ListStore(typeof(
string));
326 foreach (Function item
in Function.Functions.Values)
328 funcs.AppendValues(item.Name);
331 funcsBox.Model = funcs;
333 var renderer =
new CellRendererText();
334 funcsBox.PackStart(renderer,
false);
335 funcsBox.AddAttribute(renderer,
"text", 0);
337 nameBox.Text = func.Name;
339 var states =
new ListStore(typeof(
string));
341 foreach (Function.ButtonState val in Enum.GetValues(typeof(Function.ButtonState)))
343 states.AppendValues(val.ToString());
346 stateBox.Model = states;
348 var renderer2 =
new CellRendererText();
349 stateBox.PackStart(renderer2,
false);
350 stateBox.AddAttribute(renderer2,
"text", 0);
351 stateBox.Active = (int)func.State;
354 var keys =
new ListStore(typeof(
string));
355 foreach (Gdk.Key val in Enum.GetValues(typeof(Gdk.Key)))
357 keys.AppendValues(val.ToString());
359 keysBox.Model = keys;
361 var renderer3 =
new CellRendererText();
362 keysBox.PackStart(renderer3,
false);
363 keysBox.AddAttribute(renderer3,
"text", 0);
365 var mods =
new ListStore(typeof(
string));
366 foreach (ModifierType val
in Enum.GetValues(typeof(Gdk.ModifierType)))
368 mods.AppendValues(val.ToString());
370 modifierBox.Model = mods;
372 var renderer4 =
new CellRendererText();
373 modifierBox.PackStart(renderer4,
false);
374 modifierBox.AddAttribute(renderer4,
"text", 0);
375 valBox.Value = func.Value;
376 menuPath.Text = func.MenuPath;
377 contextMenuPath.Text = func.ContextPath;
380 private void UpdateItems()
382 textBox.Buffer.Text = func.Script;
383 nameBox.Text = func.Name;
384 stateBox.Active = (int)func.State;
385 keysBox.Active = (int)func.Key;
386 modifierBox.Active = (int)func.Modifier;
387 valBox.Value = func.Value;
388 if (func.FuncType == Function.FunctionType.ImageJ)
389 imagejRadioBut.Active =
true;
391 imagejRadioBut.Active =
false;
392 menuPath.Text = func.MenuPath;
393 contextMenuPath.Text = func.ContextPath;