29
using Do.Platform.Common;
28
33
public class KeybindingTreeView : TreeView
38
43
public KeybindingTreeView ()
40
Model = new ListStore (typeof (string), typeof (string), typeof (string), typeof (string));
45
Model = new ListStore (typeof (string), typeof (string), typeof (string), typeof (KeyBinding));
42
47
CellRendererText actionCell = new CellRendererText ();
43
actionCell.Width = 150;
48
actionCell.Width = 175;
44
49
InsertColumn (-1, Catalog.GetString ("Action"), actionCell, "text", (int)Column.Action);
46
51
CellRendererAccel bindingCell = new CellRendererAccel ();
47
bindingCell.AccelMode = CellRendererAccelMode.Gtk;
52
bindingCell.AccelMode = CellRendererAccelMode.Other;
48
53
bindingCell.Editable = true;
49
54
bindingCell.AccelEdited += new AccelEditedHandler (OnAccelEdited);
50
55
bindingCell.AccelCleared += new AccelClearedHandler (OnAccelCleared);
51
InsertColumn (-1, Catalog.GetString ("Shortcut"), bindingCell, "text", (int)Column.Binding);
53
CellRendererText defaultbindingCell = new CellRendererText ();
54
actionCell.Width = 150;
55
// InsertColumn (-1, Catalog.GetString ("Default Shortcut"), defaultbindingCell, "text", (int)Column.DefaultKeybinding);
56
InsertColumn (-1, Catalog.GetString ("Shortcut"), bindingCell, "text", (int)Column.BoundKeyString);
57
58
RowActivated += new RowActivatedHandler (OnRowActivated);
58
59
ButtonPressEvent += new ButtonPressEventHandler (OnButtonPress);
66
67
ListStore store = Model as ListStore;
69
foreach (Shortcut sc in Do.Keybindings.Shortcuts) {
70
store.AppendValues (sc.FriendlyName, Do.Keybindings.GetKeybinding (sc),
71
Do.Keybindings.GetDefaultKeybinding (sc), sc.ShortcutName);
72
foreach (KeyBinding binding in Services.Keybinder.Bindings) {
73
ks = (string.IsNullOrEmpty (binding.KeyString)) ? Catalog.GetString ("Disabled") : binding.KeyString;
74
store.AppendValues (binding.Description, ks, binding.DefaultKeyString, binding);
82
85
if (GetPathAtPos ((int) args.Event.X, (int) args.Event.Y,out path)) {
84
SetCursor (path, GetColumn ((int) Column.Binding), true);
87
SetCursor (path, GetColumn ((int) Column.BoundKeyString), true);
88
91
private void OnRowActivated (object o, RowActivatedArgs args)
91
SetCursor (args.Path, GetColumn ((int) Column.Binding), true);
94
SetCursor (args.Path, GetColumn ((int) Column.BoundKeyString), true);
94
97
private bool ClearPreviousBinding (TreeModel model, TreePath path, TreeIter treeiter, string keyBinding)
96
string binding = model.GetValue (treeiter, (int) Column.Binding) as string;
99
string binding = model.GetValue (treeiter, (int) Column.BoundKeyString) as string;
97
100
if (binding == keyBinding) {
98
model.SetValue (treeiter, (int) Column.Binding, "");
101
model.SetValue (treeiter, (int) Column.BoundKeyString, Catalog.GetString ("Disabled"));
111
114
string realKey = Gtk.Accelerator.Name (args.AccelKey, args.AccelMods);
116
if (args.AccelKey == (uint) Gdk.Key.Super_L || args.AccelKey == (uint) Gdk.Key.Super_R) {
117
//setting CellRenderAccelMode to "Other" ignores the Super key as a modifier
118
//this prevents us from grabbing _only_ the Super key.
113
122
// Look for any other rows that have the same binding and then zero that binding out
114
123
Model.Foreach ((model, path, treeiter) => ClearPreviousBinding (model, path, treeiter, realKey));
116
store.SetValue (iter, (int) Column.Binding, realKey);
125
store.SetValue (iter, (int) Column.BoundKeyString, realKey);
126
135
store = Model as ListStore;
127
136
store.GetIter (out iter, new TreePath (args.PathString));
129
139
string defaultVal = store.GetValue (iter, (int) Column.DefaultKeybinding).ToString ();
130
store.SetValue (iter, (int) Column.Binding, defaultVal);
131
} catch (Exception e) {
132
store.SetValue (iter, (int) Column.Binding, "");
140
defaultVal = (string.IsNullOrEmpty (defaultVal)) ? Catalog.GetString ("Disabled") : defaultVal;
141
store.SetValue (iter, (int) Column.BoundKeyString, defaultVal);
142
} catch (Exception) {
143
store.SetValue (iter, (int) Column.BoundKeyString, Catalog.GetString ("Disabled"));
143
154
private bool SaveBindingsForeachFunc (TreeModel model, TreePath path, TreeIter iter)
145
string binding, shortcutname;
146
binding = model.GetValue (iter, (int) Column.Binding) as string;
147
shortcutname = model.GetValue (iter, (int) Column.ShortcutName) as string;
149
if (binding != null && binding != "DISABLED" && binding != Do.Keybindings.GetKeybinding (shortcutname))
150
Do.Keybindings.BindShortcut (shortcutname, binding);
156
string newKeyString = model.GetValue (iter, (int) Column.BoundKeyString) as string;
157
KeyBinding binding = model.GetValue (iter, (int) Column.Binding) as KeyBinding;
159
newKeyString = (newKeyString == Catalog.GetString ("Disabled")) ? "" : newKeyString;
161
//only save if the keystring changed
162
if (newKeyString != null && binding.KeyString != newKeyString) {
164
if (!Services.Keybinder.SetKeyString (binding, newKeyString)) {
165
//if we fail reset to the default value
166
model.SetValue (iter, (int) Column.BoundKeyString, binding.DefaultKeyString);
167
Services.Keybinder.SetKeyString (binding, binding.DefaultKeyString);