1
/* KeybindingTreeView.cs
3
* GNOME Do is the legal property of its developers. Please refer to the
4
* COPYRIGHT file distributed with this
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
27
public class KeybindingTreeView : TreeView
35
public KeybindingTreeView ()
37
Model = new ListStore (typeof (string), typeof (string));
39
CellRendererText actionCell = new CellRendererText ();
40
actionCell.Width = 150;
41
InsertColumn (-1, "Action", actionCell, "text", (int)Column.Action);
43
CellRendererAccel bindingCell = new CellRendererAccel ();
44
bindingCell.Editable = true;
45
bindingCell.AccelEdited += new AccelEditedHandler (OnAccelEdited);
46
bindingCell.AccelCleared += new AccelClearedHandler (OnAccelCleared);
47
InsertColumn (-1, "Shortcut", bindingCell, "text", (int)Column.Binding);
49
RowActivated += new RowActivatedHandler (OnRowActivated);
50
ButtonPressEvent += new ButtonPressEventHandler (OnButtonPress);
53
Selection.SelectPath (TreePath.NewFirst ());
56
private void AddBindings ()
58
ListStore store = Model as ListStore;
61
store.AppendValues ("Summon", Do.Preferences.SummonKeyBinding);
62
store.AppendValues ("Text Mode", Do.Preferences.TextModeKeyBinding);
66
private void OnButtonPress (object o, ButtonPressEventArgs args)
69
if (!args.Event.Window.Equals (BinWindow))
72
if (GetPathAtPos ((int)args.Event.X,(int)args.Event.Y,out path)) {
74
SetCursor (path, GetColumn ((int)Column.Binding), true);
78
private void OnRowActivated (object o, RowActivatedArgs args)
81
SetCursor (args.Path, GetColumn ((int)Column.Binding), true);
84
private void OnAccelEdited (object o, AccelEditedArgs args)
89
store = Model as ListStore;
90
store.GetIter (out iter, new TreePath (args.PathString));
92
string realKey = Gtk.Accelerator.Name (args.AccelKey, args.AccelMods);
94
store.SetValue (iter, (int)Column.Binding, realKey);
98
private void OnAccelCleared (object o, AccelClearedArgs args)
103
store = Model as ListStore;
104
store.GetIter (out iter, new TreePath (args.PathString));
105
store.SetValue (iter, (int)Column.Binding, "DISABLED");
108
private void SaveBindings ()
110
Model.Foreach (SaveBindingsForeachFunc);
113
private bool SaveBindingsForeachFunc (TreeModel model, TreePath path, TreeIter iter)
115
string action, binding;
116
action = model.GetValue (iter, (int)Column.Action) as string;
118
switch (action.ToLower ()) {
120
binding = model.GetValue (iter, (int)Column.Binding) as string;
121
Do.Preferences.SummonKeyBinding = binding;
124
binding = model.GetValue (iter, (int)Column.Binding) as string;
125
Do.Preferences.TextModeKeyBinding = binding;