~ubuntu-branches/ubuntu/precise/gnome-do/precise-proposed

« back to all changes in this revision

Viewing changes to Do/src/Do.UI/KeybindingTreeView.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2008-09-14 10:09:40 UTC
  • mto: (0.1.8 sid)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20080914100940-kyghudg7py14bu2z
Tags: upstream-0.6.0.0
ImportĀ upstreamĀ versionĀ 0.6.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* KeybindingTreeView.cs
 
2
 *
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * COPYRIGHT file distributed with this
 
5
 * source distribution.
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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/>.
 
19
 */
 
20
 
 
21
 
 
22
using System;
 
23
using Gtk;
 
24
 
 
25
namespace Do.UI
 
26
{
 
27
        public class KeybindingTreeView : TreeView
 
28
        {
 
29
                enum Column {
 
30
                        Action = 0,
 
31
                        Binding,
 
32
                        NumColumns
 
33
                }
 
34
                
 
35
                public KeybindingTreeView ()
 
36
                {       
 
37
                        Model = new ListStore (typeof (string), typeof (string));
 
38
                        
 
39
                        CellRendererText actionCell = new CellRendererText ();
 
40
                        actionCell.Width = 150;
 
41
                        InsertColumn (-1, "Action", actionCell, "text", (int)Column.Action);
 
42
                        
 
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);
 
48
                        
 
49
                        RowActivated += new RowActivatedHandler (OnRowActivated);
 
50
                        ButtonPressEvent += new ButtonPressEventHandler (OnButtonPress);
 
51
                        
 
52
                        AddBindings ();
 
53
                        Selection.SelectPath (TreePath.NewFirst ());
 
54
                }
 
55
                
 
56
                private void AddBindings ()
 
57
                {
 
58
                        ListStore store = Model as ListStore;
 
59
                        store.Clear ();
 
60
                        
 
61
                        store.AppendValues ("Summon", Do.Preferences.SummonKeyBinding);
 
62
                        store.AppendValues ("Text Mode", Do.Preferences.TextModeKeyBinding);
 
63
                }
 
64
                
 
65
                [GLib.ConnectBefore]
 
66
                private void OnButtonPress (object o, ButtonPressEventArgs args)
 
67
                {
 
68
                        TreePath path;
 
69
                        if (!args.Event.Window.Equals (BinWindow))
 
70
                                return;
 
71
                                
 
72
                        if (GetPathAtPos ((int)args.Event.X,(int)args.Event.Y,out path)) {
 
73
                                GrabFocus ();
 
74
                                SetCursor (path, GetColumn ((int)Column.Binding), true);
 
75
                        }                               
 
76
                }
 
77
                
 
78
                private void OnRowActivated (object o, RowActivatedArgs args)
 
79
                {
 
80
                        GrabFocus ();
 
81
                        SetCursor (args.Path, GetColumn ((int)Column.Binding), true);
 
82
                }
 
83
                
 
84
                private void OnAccelEdited (object o, AccelEditedArgs args)
 
85
                {
 
86
                        TreeIter iter;
 
87
                        ListStore store;
 
88
                        
 
89
                        store = Model as ListStore;
 
90
                        store.GetIter (out iter, new TreePath (args.PathString));
 
91
                        
 
92
                        string realKey = Gtk.Accelerator.Name (args.AccelKey, args.AccelMods);
 
93
                        
 
94
                        store.SetValue (iter, (int)Column.Binding, realKey);
 
95
                        SaveBindings ();
 
96
                }
 
97
                
 
98
                private void OnAccelCleared (object o, AccelClearedArgs args)
 
99
                {
 
100
                        TreeIter iter;
 
101
                        ListStore store;
 
102
                        
 
103
                        store = Model as ListStore;
 
104
                        store.GetIter (out iter, new TreePath (args.PathString));
 
105
                        store.SetValue (iter, (int)Column.Binding, "DISABLED");
 
106
                }
 
107
                
 
108
                private void SaveBindings ()
 
109
                {
 
110
                        Model.Foreach (SaveBindingsForeachFunc);
 
111
                }
 
112
                
 
113
                private bool SaveBindingsForeachFunc (TreeModel model, TreePath path, TreeIter iter)
 
114
                {
 
115
                        string action, binding;
 
116
                        action = model.GetValue (iter, (int)Column.Action) as string;
 
117
                        
 
118
                        switch (action.ToLower ()) {
 
119
                        case "summon":
 
120
                                binding = model.GetValue (iter, (int)Column.Binding) as string;
 
121
                                Do.Preferences.SummonKeyBinding = binding;
 
122
                                break;
 
123
                        case "text mode":
 
124
                                binding = model.GetValue (iter, (int)Column.Binding) as string;
 
125
                                Do.Preferences.TextModeKeyBinding = binding;
 
126
                                break;
 
127
                        }
 
128
                        return false;
 
129
                }
 
130
        }
 
131
}