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

« back to all changes in this revision

Viewing changes to Do/src/Do.Core/Controller.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:
30
30
using Do.UI;
31
31
using Do.Universe;
32
32
using Do.Platform;
 
33
using Do.Platform.Common;
33
34
using Do.Interface;
34
35
 
35
36
namespace Do.Core
103
104
 
104
105
                public void Initialize ()
105
106
                {
 
107
                        if (Do.Preferences.Theme == "Docky") {
 
108
                                string message = Catalog.GetString (
 
109
                                        "<b>Docky is no longer a Do theme!</b>\n" + 
 
110
                                        "It is now available as a stand-alone application. " +
 
111
                                        "Your GNOME Do theme has been reset to Classic. " +
 
112
                                        "Please feel free to change it in Preferences."
 
113
                                );
 
114
 
 
115
                                Gtk.MessageDialog md = new Gtk.MessageDialog (null, Gtk.DialogFlags.DestroyWithParent, 
 
116
                                        Gtk.MessageType.Info, Gtk.ButtonsType.Ok, true, message);
 
117
                                md.Response += (o, args) => md.Destroy ();
 
118
                                md.ShowAll ();
 
119
                                Do.Preferences.Theme = "Classic";
 
120
                        }
 
121
                        
106
122
                        SetTheme (Do.Preferences.Theme);
107
123
                        Do.Preferences.ThemeChanged += OnThemeChanged;
108
124
                        Screen.Default.CompositedChanged += OnCompositingChanged;
109
125
                        
110
126
                        // Register Shortcuts
111
 
                        // TODO: Localize the text here.
112
 
                        // Previous shortcuts
113
 
                        Do.Keybindings.RegisterShortcut (
114
 
                                        new Shortcut ("SummonKey", 
115
 
                                                Catalog.GetString ("Summon GNOME Do"), 
116
 
                                                OnSummonKeyPressEvent),
117
 
                                        "<Super>space");
118
 
                        Do.Keybindings.RegisterShortcut (
119
 
                                        new Shortcut ("TextModeKey",
120
 
                                                Catalog.GetString ("Enter text mode"),
121
 
                                                OnTextModePressEvent),
122
 
                                        "period");
123
 
                        // New shortcuts
124
 
                        Do.Keybindings.RegisterShortcut (
125
 
                                        new Shortcut ("CopyKey",
126
 
                                                Catalog.GetString ("Copy Text"),
127
 
                                                OnCopyEvent),
128
 
                                        "<Control>c");
129
 
                        Do.Keybindings.RegisterShortcut (
130
 
                                        new Shortcut ("PasteKey",
131
 
                                                Catalog.GetString ("Paste Text"),
132
 
                                                OnPasteEvent),
133
 
                                        "<Control>v");
134
 
                        Do.Keybindings.RegisterShortcut (
135
 
                                        new Shortcut ("AlternateEscapeKey",
136
 
                                                Catalog.GetString ("Alternate Escape"),
137
 
                                                OnEscapeKeyPressEvent));
138
 
                        Do.Keybindings.RegisterShortcut (
139
 
                                        new Shortcut ("AlternateActivateKey",
140
 
                                                Catalog.GetString ("Alternate Activate"),
141
 
                                                OnActivateKeyPressEvent));
142
 
                        Do.Keybindings.RegisterShortcut (
143
 
                                        new Shortcut ("AlternateDeleteKey",
144
 
                                                Catalog.GetString ("Alternate Delete"),
145
 
                                                OnDeleteKeyPressEvent));
146
 
                        Do.Keybindings.RegisterShortcut (
147
 
                                        new Shortcut ("ShiftTabKey",
148
 
                                                Catalog.GetString ("Previous Pane"),
149
 
                                                OnShiftTabKeyPressEvent),
150
 
                                        "ISO_Left_Tab");
151
 
                        Do.Keybindings.RegisterShortcut (
152
 
                                        new Shortcut ("TabKey",
153
 
                                                Catalog.GetString ("Next Pane"),
154
 
                                                OnTabKeyPressEvent),
155
 
                                        "Tab");
156
 
                        Do.Keybindings.RegisterShortcut (
157
 
                                        new Shortcut ("UpKey",
158
 
                                                Catalog.GetString ("Previous Result"),
159
 
                                                OnUpKeyPressEvent),
160
 
                                        "Up");
161
 
                        Do.Keybindings.RegisterShortcut (
162
 
                                        new Shortcut ("DownKey",
163
 
                                                Catalog.GetString ("Next Result"),
164
 
                                                OnDownKeyPressEvent),
165
 
                                        "Down");
166
 
                        Do.Keybindings.RegisterShortcut (
167
 
                                        new Shortcut ("HomeKey",
168
 
                                                Catalog.GetString ("First Result"),
169
 
                                                OnHomeKeyPressEvent),
170
 
                                        "Home");
171
 
                        Do.Keybindings.RegisterShortcut (
172
 
                                        new Shortcut ("EndKey",
173
 
                                                Catalog.GetString ("Last Result"),
174
 
                                                OnEndKeyPressEvent),
175
 
                                        "End");
176
 
                        Do.Keybindings.RegisterShortcut (
177
 
                                        new Shortcut ("PageUpKey",
178
 
                                                Catalog.GetString ("Previous 5 Results"),
179
 
                                                OnPageUpKeyPressEvent),
180
 
                                        "Page_Up");
181
 
                        Do.Keybindings.RegisterShortcut (
182
 
                                        new Shortcut ("PageDownKey",
183
 
                                                Catalog.GetString ("Next 5 Results"),
184
 
                                                OnPageDownKeyPressEvent),
185
 
                                        "Page_Down");
186
 
                        Do.Keybindings.RegisterShortcut (
187
 
                                        new Shortcut ("LeftKey",
188
 
                                                Catalog.GetString ("Step out of Item"),
189
 
                                                OnLeftKeyPressEvent),
190
 
                                        "Left");
191
 
                        Do.Keybindings.RegisterShortcut (
192
 
                                        new Shortcut ("RightKey",
193
 
                                                Catalog.GetString ("Browse Into Item"),
194
 
                                                OnRightKeyPressEvent),
195
 
                                        "Right");
196
 
                        Do.Keybindings.RegisterShortcut (
197
 
                                        new Shortcut ("CommaKey",
198
 
                                                Catalog.GetString ("Multiple selection"),
199
 
                                                OnSelectionKeyPressEvent),
200
 
                                        "comma");
 
127
                        SetupKeybindings ();
 
128
                }
 
129
                
 
130
                void SetupKeybindings ()
 
131
                {
 
132
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Summon Do"), "<Super>space", 
 
133
                                OnSummonKeyPressEvent, true));
 
134
                        
 
135
                        // this keybinding is disabled by default - note the empty keybinding
 
136
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Summon in Text Mode"), "",
 
137
                                OnTextModeSummonKeyPressEvent, true));
 
138
                        
 
139
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Enter Text Mode"), "period",
 
140
                                OnTextModePressEvent));
 
141
                        
 
142
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Clear"), "Escape",
 
143
                                OnClearKeyPressEvent));
 
144
                        
 
145
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Copy to Clipboard"), "<Control>c",
 
146
                                OnCopyEvent));
 
147
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Paste from Clipboard"), "<Control>v",
 
148
                                OnPasteEvent));
 
149
                        
 
150
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Previous Pane"), "<Shift>Tab",
 
151
                                OnPreviousPanePressEvent));
 
152
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Next Pane"), "Tab",
 
153
                                OnNextPanePressEvent));
 
154
                        
 
155
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Previous Item"), "Up",
 
156
                                OnPreviousItemPressEvent));
 
157
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Next Item"), "Down",
 
158
                                OnNextItemPressEvent));
 
159
                        
 
160
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("First Item"), "Home",
 
161
                                OnFirstItemPressEvent));
 
162
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Last Item"), "End",
 
163
                                OnLastItemPressEvent));
 
164
                        
 
165
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Previous 5 Results"), "Page_Up",
 
166
                                OnNextItemPagePressEvent));
 
167
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Next 5 Results"), "Page_Down",
 
168
                                OnPreviousItemPagePressEvent));
 
169
                        
 
170
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Step Out of Item"), "Left",
 
171
                                OnStepOutItemPressEvent));
 
172
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Step Into Item"), "Right",
 
173
                                OnStepInItemPressEvent));
 
174
                        
 
175
                        Services.Keybinder.RegisterKeyBinding (new KeyBinding (Catalog.GetString ("Select Multiple Items"), "comma",
 
176
                                OnSelectionKeyPressEvent));
201
177
                }
202
178
 
203
179
                void OnSummoned ()
206
182
                        Summoned (this, EventArgs.Empty);
207
183
                }
208
184
                
209
 
                void OnCompositingChanged(object sender, EventArgs args)
 
185
                void OnCompositingChanged (object sender, EventArgs args)
210
186
                {
211
 
                        UnsetTheme();
212
 
                        SetTheme(Do.Preferences.Theme);
 
187
                        UnsetTheme ();
 
188
                        SetTheme (Do.Preferences.Theme);
213
189
                }
214
190
                
 
191
                private string LastTheme { get; set; }
 
192
                
215
193
                void OnThemeChanged (object sender, PreferencesChangedEventArgs e)
216
194
                {
217
 
                        string oldTheme = e.OldValue as string, newTheme = Do.Preferences.Theme;
 
195
                        string newTheme = e.Value as string;
218
196
                        
219
197
                        // Only change the theme of the old and new themes are different.
220
 
                        if (oldTheme != newTheme) {
 
198
                        if (LastTheme != newTheme && !string.IsNullOrEmpty (newTheme)) {
221
199
                                UnsetTheme ();
222
200
                                SetTheme (newTheme);
223
201
                        }
236
214
                void SetTheme (string themeName)
237
215
                {
238
216
                        Log<Controller>.Debug ("Setting theme {0}", themeName);
 
217
                        LastTheme = themeName;
239
218
                        
240
219
                        Orientation = ControlOrientation.Vertical;
241
220
 
482
461
 
483
462
#region KeyPress Handling
484
463
 
485
 
                Key IfVertical (Key ifKey, Key elseKey)
486
 
                {
487
 
                        return Orientation == ControlOrientation.Vertical ? ifKey : elseKey;
488
 
                }
489
 
 
490
 
                Key UpKey    { get { return IfVertical (Key.Up, Key.Left); } }
491
 
                Key DownKey  { get { return IfVertical (Key.Down, Key.Right); } }
492
 
                Key LeftKey  { get { return IfVertical (Key.Left, Key.Up); } }
493
 
                Key RightKey { get { return IfVertical (Key.Right, Key.Down); } }
494
 
                
495
464
                private void KeyPressWrap (EventKey evnt)
496
465
                {
497
466
                        Key key = (Key) evnt.KeyValue;
498
 
 
499
467
                        
500
 
                        // Currently - only hardcoded are enter keys, escape and delete/backspace
501
 
                        if (key == Key.Escape) {
502
 
                                OnEscapeKeyPressEvent (evnt);
503
 
                        } else if (key == Key.Return ||
 
468
                        // Currently - only hardcoded are enter keys and delete/backspace
 
469
                        if (key == Key.Return ||
504
470
                                   key == Key.ISO_Enter ||
505
471
                                   key == Key.KP_Enter) {
506
472
                                OnActivateKeyPressEvent (evnt);
507
473
                        } else if (key == Key.Delete ||
508
474
                                   key == Key.BackSpace) {
509
475
                                OnDeleteKeyPressEvent (evnt);
510
 
                        } else {
 
476
                        } else if (Services.Keybinder.Bindings.Any (k => k.KeyString == Services.Keybinder.KeyEventToString (evnt))) {
511
477
                                // User set keybindings
512
 
                                Shortcut sc = Do.Keybindings.GetShortcutByKeycode (KeyEventToString (evnt));
513
 
                                if (sc != null) {
514
 
                                        sc.Callback (evnt);
515
 
                                        return;
516
 
                                }
 
478
                                Services.Keybinder.Bindings.First (k => k.KeyString == Services.Keybinder.KeyEventToString (evnt)).Callback (evnt);
 
479
                        } else {
517
480
                                OnInputKeyPressEvent (evnt);
518
481
                        }
519
482
                }
569
532
                
570
533
                void OnSummonKeyPressEvent (EventKey evnt)
571
534
                {
572
 
                        Reset ();
573
 
                        Vanish ();
574
 
                }
575
 
                
576
 
                void OnEscapeKeyPressEvent (EventKey evnt)
 
535
                        if (IsSummoned) {
 
536
                                Reset ();
 
537
                                Vanish ();
 
538
                        } else {
 
539
                                Summon ();
 
540
                        }
 
541
                }
 
542
                
 
543
                void OnTextModeSummonKeyPressEvent (EventKey evnt)
 
544
                {
 
545
                        Summon (); 
 
546
                        SearchController.TextMode = true; 
 
547
                        UpdatePane (CurrentPane);
 
548
                }
 
549
                
 
550
                void OnClearKeyPressEvent (EventKey evnt)
577
551
                {
578
552
                        im_context.Reset ();
579
553
                        if (SearchController.TextType == TextModeType.Explicit) {
622
596
                        }
623
597
                }
624
598
                
625
 
                void OnLeftKeyPressEvent (EventKey evnt)
 
599
                void OnStepOutItemPressEvent (EventKey evnt)
626
600
                {
627
601
                        im_context.Reset ();
628
602
                        if (!SearchController.Results.Any ()) return;
637
611
                }
638
612
 
639
613
                // Hmm.
640
 
                void OnRightKeyPressEvent (EventKey evnt)
 
614
                void OnStepInItemPressEvent (EventKey evnt)
641
615
                {
642
616
                        im_context.Reset ();
643
617
                        if (!SearchController.Results.Any ()) return;
648
622
                        if (SearchController.ItemChildSearch ()) GrowResults ();
649
623
                }
650
624
 
651
 
                void OnTabKeyPressEvent (EventKey evnt)
 
625
                void OnNextPanePressEvent (EventKey evnt)
652
626
                {
653
627
                        im_context.Reset ();
654
628
                        ShrinkResults ();
661
635
                        UpdatePane (CurrentPane);
662
636
                }
663
637
 
664
 
                void OnShiftTabKeyPressEvent (EventKey evnt)
 
638
                void OnPreviousPanePressEvent (EventKey evnt)
665
639
                {
666
640
                        im_context.Reset ();
667
641
                        ShrinkResults ();
689
663
                        UpdatePane (CurrentPane);
690
664
                }
691
665
                
692
 
                void OnUpKeyPressEvent (EventKey evnt)
 
666
                void OnPreviousItemPressEvent (EventKey evnt)
693
667
                {
694
668
                        im_context.Reset ();
695
669
                        if (!results_grown) {
705
679
                        }
706
680
                }
707
681
 
708
 
                void OnDownKeyPressEvent (EventKey evnt)
 
682
                void OnNextItemPressEvent (EventKey evnt)
709
683
                {
710
684
                        im_context.Reset ();
711
685
                        if (!results_grown) {
715
689
                        SearchController.Cursor++;
716
690
                }
717
691
                
718
 
                void OnHomeKeyPressEvent (EventKey evnt)
 
692
                void OnFirstItemPressEvent (EventKey evnt)
719
693
                {
720
694
                        im_context.Reset ();
721
695
                        SearchController.Cursor = 0;
722
696
                }
723
697
 
724
 
                void OnEndKeyPressEvent (EventKey evnt)
 
698
                void OnLastItemPressEvent (EventKey evnt)
725
699
                {
726
700
                        im_context.Reset ();
727
701
                        SearchController.Cursor = SearchController.Results.Count - 1;
728
702
                }
729
703
 
730
 
                void OnPageUpKeyPressEvent (EventKey evnt)
 
704
                void OnNextItemPagePressEvent (EventKey evnt)
731
705
                {
732
706
                        im_context.Reset ();
733
707
                        SearchController.Cursor -= 5;
734
708
                }
735
709
                
736
 
                void OnPageDownKeyPressEvent (EventKey evnt)
 
710
                void OnPreviousItemPagePressEvent (EventKey evnt)
737
711
                {
738
712
                        im_context.Reset ();
739
713
                        SearchController.Cursor += 5;
740
714
                }
741
 
                                
742
 
                /// <summary>
743
 
                /// Converts a keypress into a human readable string for comparing
744
 
                /// against values in GConf.
745
 
                /// </summary>
746
 
                /// <param name="evnt">
747
 
                /// A <see cref="EventKey"/>
748
 
                /// </param>
749
 
                /// <returns>
750
 
                /// A <see cref="System.String"/> in the form "<Modifier>key"
751
 
                /// </returns>
752
 
                string KeyEventToString (EventKey evnt) {
753
 
                        string modifier = "";
754
 
                        if ((evnt.State & ModifierType.ControlMask) != 0) {
755
 
                                modifier += "<Control>";
756
 
                        }
757
 
                        if ((evnt.State & ModifierType.SuperMask) != 0) {
758
 
                                modifier += "<Super>";
759
 
                        }
760
 
                        if ((evnt.State & ModifierType.Mod1Mask) != 0) {
761
 
                                modifier += "<Alt>";
762
 
                        }
763
 
                        return modifier + evnt.Key.ToString ();
764
 
                }
765
715
#endregion
766
716
                
767
717
                /// <summary>
961
911
                                        item.IncreaseRelevance (itemQuery, null);
962
912
 
963
913
                                // Increase the relevance of the action /for each item/:
964
 
                                foreach (Item item in items)
965
 
                                        action.IncreaseRelevance (actionQuery, item);
 
914
                                if (action != null) {
 
915
                                        foreach (Item item in items)
 
916
                                                action.IncreaseRelevance (actionQuery, item);
 
917
                                } else {
 
918
                                        Log<Controller>.Debug ("Action is null in 2nd pane!");
 
919
                                }
966
920
                        } else {
967
921
                                // Act is in first pane.
968
922
                                // Increase the relevance of each item for the action.
969
923
                                foreach (Item item in items)
970
924
                                        item.IncreaseRelevance (itemQuery, action);
971
 
                                action.IncreaseRelevance (actionQuery, null);
 
925
                                if (action != null)
 
926
                                        action.IncreaseRelevance (actionQuery, null);
 
927
                                else
 
928
                                        Log<Controller>.Debug ("Action is null in 1st pane!");
972
929
                        }
973
930
 
974
931
                        if (ThirdPaneVisible) {
1054
1011
                        logo = "gnome-do.svg";
1055
1012
 
1056
1013
                        AboutDialog.Logo = IconProvider.PixbufFromIconName (logo, 140);
1057
 
                        AboutDialog.Copyright = Catalog.GetString ("Copyright \xa9 2008 GNOME Do Developers");
 
1014
                        AboutDialog.Copyright = Catalog.GetString ("Copyright \xa9 2009 GNOME Do Developers");
1058
1015
                        AboutDialog.Comments = Catalog.GetString ("Do things as quickly as possible\n" +
1059
1016
                                "(but no quicker) with your files, bookmarks,\n" +
1060
1017
                                "applications, music, contacts, and more!");