3
using System.Collections;
9
internal class ActionGroupToolbar: Gtk.Toolbar
11
Wrapper.ActionGroupCollection actionGroups;
14
ActionGroup currentGroup;
15
ArrayList internalButtons = new ArrayList ();
18
ActionGroupDesignerFrontend frontend;
19
Editor.ActionGroupEditor agroupEditor;
20
Gtk.ToolButton addButton;
21
Gtk.ToolButton removeButton;
23
public event ActionGroupEventHandler ActiveGroupChanged;
24
public event ActionGroupEventHandler ActiveGroupCreated;
26
public ActionGroupToolbar (ActionGroupDesignerFrontend frontend, bool singleGroupMode)
28
Initialize (frontend, null, singleGroupMode);
31
public ActionGroupToolbar (ActionGroupDesignerFrontend frontend, Wrapper.ActionGroup actionGroup)
33
currentGroup = actionGroup;
34
Initialize (frontend, null, true);
37
public ActionGroupToolbar (ActionGroupDesignerFrontend frontend, Wrapper.ActionGroupCollection actionGroups)
39
Initialize (frontend, actionGroups, false);
42
public bool AllowActionBinding {
43
get { return allowBinding; }
44
set { allowBinding = value; }
47
void Initialize (ActionGroupDesignerFrontend frontend, Wrapper.ActionGroupCollection actionGroups, bool singleGroupMode)
49
this.frontend = frontend;
50
this.singleGroupMode = singleGroupMode;
51
IconSize = Gtk.IconSize.SmallToolbar;
52
Orientation = Gtk.Orientation.Horizontal;
53
ToolbarStyle = Gtk.ToolbarStyle.BothHoriz;
55
combo = Gtk.ComboBox.NewText ();
57
if (!singleGroupMode) {
58
combo.Changed += OnActiveChanged;
60
Gtk.ToolItem comboItem = new Gtk.ToolItem ();
61
Gtk.HBox cbox = new Gtk.HBox ();
62
cbox.PackStart (new Gtk.Label (Catalog.GetString ("Action Group:") + " "), false, false, 3);
63
cbox.PackStart (combo, true, true, 3);
66
Insert (comboItem, -1);
67
internalButtons.Add (comboItem);
69
addButton = new Gtk.ToolButton (Gtk.Stock.Add);
70
addButton.Clicked += OnAddGroup;
71
Insert (addButton, -1);
72
internalButtons.Add (addButton);
74
removeButton = new Gtk.ToolButton (Gtk.Stock.Remove);
75
removeButton.Clicked += OnRemoveGroup;
76
Insert (removeButton, -1);
77
internalButtons.Add (removeButton);
79
ActionGroups = actionGroups;
81
if (actionGroups != null && actionGroups.Count > 0)
84
UpdateActionCommands (null);
90
public override void Dispose ()
92
combo.Changed -= OnActiveChanged;
93
if (addButton != null) {
94
addButton.Clicked -= OnAddGroup;
95
removeButton.Clicked -= OnRemoveGroup;
98
if (agroupEditor != null) {
99
agroupEditor.SelectionChanged -= OnEditorSelectionChanged;
103
if (!singleGroupMode)
108
public Wrapper.ActionGroupCollection ActionGroups {
109
get { return actionGroups; }
112
throw new InvalidOperationException ("ActionGroups can't be set in single group mode");
114
if (actionGroups != null) {
115
actionGroups.ActionGroupAdded -= OnCollectionChanged;
116
actionGroups.ActionGroupRemoved -= OnCollectionChanged;
117
actionGroups.ActionGroupChanged -= OnCollectionChanged;
120
this.actionGroups = value;
122
if (actionGroups != null) {
123
actionGroups.ActionGroupAdded += OnCollectionChanged;
124
actionGroups.ActionGroupRemoved += OnCollectionChanged;
125
actionGroups.ActionGroupChanged += OnCollectionChanged;
131
public void Bind (Editor.ActionGroupEditor agroupEditor)
133
this.agroupEditor = agroupEditor;
134
agroupEditor.SelectionChanged += OnEditorSelectionChanged;
135
agroupEditor.ActionGroup = ActiveGroup;
138
public void OnEditorSelectionChanged (object s, EventArgs a)
140
UpdateActionCommands (agroupEditor.SelectedAction);
143
public ActionGroup ActiveGroup {
148
if (singleGroupMode) {
149
currentGroup = value;
150
UpdateActionCommands (null);
151
NotifyActiveGroupChanged ();
153
int i = actionGroups.IndexOf (value);
165
while (combo.Model.IterNChildren () > 0)
166
combo.RemoveText (0);
167
if (actionGroups != null) {
168
foreach (ActionGroup group in actionGroups)
169
combo.AppendText (group.Name);
173
void OnCollectionChanged (object s, ActionGroupEventArgs args)
175
// Avoid firing the selection change event if the selected
176
// group is the same after the refresh
177
ActionGroup oldGroup = currentGroup;
180
int i = combo.Active;
182
if (actionGroups.Count == 0) {
183
combo.Sensitive = false;
187
combo.Sensitive = true;
190
if (i < actionGroups.Count)
193
combo.Active = actionGroups.Count - 1;
194
currentGroup = (ActionGroup) actionGroups [combo.Active];
197
if (currentGroup != oldGroup)
198
OnActiveChanged (null, null);
199
frontend.NotifyModified ();
202
void OnAddGroup (object s, EventArgs args)
204
ActionGroup group = new ActionGroup ();
205
group.Name = Catalog.GetString ("New Action Group");
206
actionGroups.Add (group);
207
combo.Active = actionGroups.Count - 1;
208
if (ActiveGroupCreated != null)
209
ActiveGroupCreated (this, new ActionGroupEventArgs (ActiveGroup));
211
if (agroupEditor != null)
212
agroupEditor.StartEditing ();
215
void OnRemoveGroup (object s, EventArgs args)
217
if (combo.Active != -1)
218
actionGroups.RemoveAt (combo.Active);
221
void OnActiveChanged (object s, EventArgs args)
224
UpdateActionCommands (null);
225
if (combo.Active != -1)
226
currentGroup = (ActionGroup) actionGroups [combo.Active];
229
NotifyActiveGroupChanged ();
233
void NotifyActiveGroupChanged ()
235
if (agroupEditor != null)
236
agroupEditor.ActionGroup = ActiveGroup;
237
if (ActiveGroupChanged != null)
238
ActiveGroupChanged (this, new ActionGroupEventArgs (ActiveGroup));
241
void UpdateActionCommands (Wrapper.Action action)
243
foreach (Gtk.Widget w in Children) {
244
if (!internalButtons.Contains (w)) {
249
AddActionCommands (action);
251
if (internalButtons.Count > 0 && internalButtons.Count != Children.Length) {
252
Insert (new Gtk.SeparatorToolItem (), internalButtons.Count);
257
protected virtual void AddActionCommands (Wrapper.Action action)
260
Gtk.ToolButton bindButton = new Gtk.ToolButton (null, Catalog.GetString ("Bind to Field"));
261
bindButton.IsImportant = true;
263
Insert (bindButton, -1);
265
bindButton.Sensitive = false;
267
bindButton.Clicked += delegate { frontend.NotifyBindField (); };