~ubuntu-branches/ubuntu/wily/gnome-do/wily

« 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: 2011-02-15 21:50:02 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110215215002-1j8ylb69o15asb06
Tags: 0.8.4-0ubuntu1
* The Race Against FF upload.  Merge from unreleased Debian git.
  Remaining Ubuntu changes:
  + debian/patches/05_disable_resize_grips.patch.diff:
    Disable resize handles for the Do windows.
  + debian/control:
    Bump gtk# build dep for HasResizeGrip API.
* New Debian changes:
* The long fortold release
  + Fixes a threadsafety issue resulting in 100% CPU usage (Closes: 565591,
    LP: #450852).
  + Proxies all keyring calls to the GTK main thread, as required by the new
    gnome-keyring (Closes: 603876, LP: #553643)
* debian/patches/00_bundledlibs.dpatch:
* debian/rules:
  + Upstream has dropped bundled gmcs binary; now 100% DFSG-free, so we don't
    have to repack the tarball or patch the buildsystem.
* debian/patches/03_disable_docky.dpatch:
  + Drop.  Docky is now gone in the upstream tarball.
* debian/rules:
* debian/control:
* debian/patches/*:
  + Switch to quilt to harmonise with other pkg-cli-* packages.
* debian/control:
  + Drop recommends on gnome-do-docklets.  Docky is now a separate package,
    so the docklets are useless for Do.
  + Bump Breaks on gnome-do-plugins to 0.8.3.  Do no longer provides the Wink
    library, which has been imported into the 0.8.3 do-plugins sources.
  + Bump standards-version; no changes needed.
  + Migrate to git and update VCS fields appropriately

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
 
22
22
using System;
 
23
using System.Linq;
 
24
 
23
25
using Gtk;
24
26
using Mono.Unix;
25
27
 
 
28
using Do.Platform;
 
29
using Do.Platform.Common;
 
30
 
26
31
namespace Do.UI
27
32
{
28
33
        public class KeybindingTreeView : TreeView
29
34
        {
30
35
                enum Column {
31
36
                        Action = 0,
 
37
                        BoundKeyString,
 
38
                        DefaultKeybinding,
32
39
                        Binding,
33
 
                        DefaultKeybinding,
34
 
                        ShortcutName, 
35
40
                        NumColumns
36
41
                }
37
42
                
38
43
                public KeybindingTreeView ()
39
44
                {       
40
 
                        Model = new ListStore (typeof (string), typeof (string), typeof (string), typeof (string));
 
45
                        Model = new ListStore (typeof (string), typeof (string), typeof (string), typeof (KeyBinding));
41
46
                        
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);
45
50
                        
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);
52
 
                        
53
 
                        CellRendererText defaultbindingCell = new CellRendererText ();
54
 
                        actionCell.Width = 150;
55
 
//                      InsertColumn (-1, Catalog.GetString ("Default Shortcut"), defaultbindingCell, "text", (int)Column.DefaultKeybinding);
56
 
                        
 
56
                        InsertColumn (-1, Catalog.GetString ("Shortcut"), bindingCell, "text", (int)Column.BoundKeyString);
 
57
                                                
57
58
                        RowActivated += new RowActivatedHandler (OnRowActivated);
58
59
                        ButtonPressEvent += new ButtonPressEventHandler (OnButtonPress);
59
60
                        
66
67
                        ListStore store = Model as ListStore;
67
68
                        store.Clear ();
68
69
 
69
 
                        foreach (Shortcut sc in Do.Keybindings.Shortcuts) {
70
 
                                store.AppendValues (sc.FriendlyName, Do.Keybindings.GetKeybinding (sc), 
71
 
                                        Do.Keybindings.GetDefaultKeybinding (sc), sc.ShortcutName);
 
70
                        string ks;
 
71
 
 
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);
72
75
                        }
73
76
                }
74
77
                
81
84
                                
82
85
                        if (GetPathAtPos ((int) args.Event.X, (int) args.Event.Y,out path)) {
83
86
                                GrabFocus ();
84
 
                                SetCursor (path, GetColumn ((int) Column.Binding), true);
 
87
                                SetCursor (path, GetColumn ((int) Column.BoundKeyString), true);
85
88
                        }                               
86
89
                }
87
90
                
88
91
                private void OnRowActivated (object o, RowActivatedArgs args)
89
92
                {
90
93
                        GrabFocus ();
91
 
                        SetCursor (args.Path, GetColumn ((int) Column.Binding), true);
 
94
                        SetCursor (args.Path, GetColumn ((int) Column.BoundKeyString), true);
92
95
                }
93
96
 
94
97
                private bool ClearPreviousBinding (TreeModel model, TreePath path, TreeIter treeiter, string keyBinding) 
95
98
                {
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"));
99
102
                        }
100
103
                        return false;
101
104
                }
110
113
                        
111
114
                        string realKey = Gtk.Accelerator.Name (args.AccelKey, args.AccelMods);
112
115
                        
 
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.
 
119
                                return;
 
120
                        }
 
121
                        
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));
115
124
 
116
 
                        store.SetValue (iter, (int) Column.Binding, realKey);
 
125
                        store.SetValue (iter, (int) Column.BoundKeyString, realKey);
117
126
 
118
127
                        SaveBindings ();
119
128
                }
125
134
 
126
135
                        store = Model as ListStore;
127
136
                        store.GetIter (out iter, new TreePath (args.PathString));
 
137
                        
128
138
                        try {
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"));
133
144
                        }
134
145
 
135
146
                        SaveBindings ();
142
153
                
143
154
                private bool SaveBindingsForeachFunc (TreeModel model, TreePath path, TreeIter iter)
144
155
                {
145
 
                        string binding, shortcutname;
146
 
                        binding = model.GetValue (iter, (int) Column.Binding) as string;
147
 
                        shortcutname = model.GetValue (iter, (int) Column.ShortcutName) as string;
148
 
                        
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;
 
158
                        
 
159
                        newKeyString = (newKeyString == Catalog.GetString ("Disabled")) ? "" : newKeyString;
 
160
                        
 
161
                        //only save if the keystring changed
 
162
                        if (newKeyString != null && binding.KeyString != newKeyString) {
 
163
                                //try to save
 
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);
 
168
                                }
 
169
                        }
151
170
                        return false;
152
 
                }
153
 
                
 
171
                }       
154
172
        }
155
 
 
156
173
}