~ubuntu-branches/ubuntu/saucy/f-spot/saucy

« back to all changes in this revision

Viewing changes to lib/Hyena/src/Hyena.Gui/Hyena.Gui/ActionManager.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-05-24 10:35:57 UTC
  • mfrom: (2.4.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20100524103557-1j0i8f66caybci2n
Tags: 0.7.0-1
* New upstream release 0.7.0
 + First release of the unstable 0.7 development series. Massive changes.
 + Reparenting and detaching support (Anton Keks) (Closes: #559745)
 + A new Mallard-based documentation (Harold Schreckengost)
 + No longer embeds flickrnet, uses distribution copy (Iain Lane)
 + Adoption of a large amount of Hyena functionality (Paul Lange, Peter
   Goetz)
 + No longer embeds gnome-keyring-sharp
 + Completely rewritten import, much faster and less memory hungry (Ruben
   Vermeersch) (Closes: #559080, #492658, #341790, #357811, #426017) (LP:
   #412091)
 + No longer use gphoto2-sharp, now uses gvfs which is less crash-pron
   (Ruben Vermeersch)
 + Fix Facebook support (Ruben Vermeersch)
 + Modernized unit tests
 + Revamped build (Mike Gemünde)
 + Much improved duplicate detection (much faster too) (Ruben Vermeersch)
 + Mouse selection in Iconview (Vincent Pomey)
 + Image panning support using middle mouse button (Wojciech Dzierżanowski)
 + Timeline slider now restricted to the size of the window (Iain Churcher)
 + Over 100 bugs closed (http://bit.ly/cyVjnD)
   - No more warnings about schema defaults (Closes: #584215) (LP: #586132)
* debian/control: Clean up build deps to match configure checks
* debian/rules: Don't run dh_makeshilbs as we don't ship any shared
  libraries. There are some private ones though, which get picked up and
  result in a useless postinst/postrm call to ldconfig. Thanks, lintian.
* debian/patches/debian_fix-distclean.patch,
  debian/patches/debian_fix_f-spot.exe.config.patch,
  debian/patches/debian_link-system-flickrnet.patch,
  debian/patches/debian_link-system-gnome-keyring.patch,
  debian/patches/debian_disable-unit-tests,
  debian/patches/git_transition_duration.patch,
  debian/patches/ubuntu_fix_folder_export_hang.patch:
  Clean up obsolete patches which are no longer necessary 
* debian/patches/*: Temporarily disable patches which originated from Ubuntu
  and no longer apply cleanly. We will get these back in a future upstream
  development release.
* debian/patches/*: Refresh to apply cleanly 
* debian/rules: Add new include dir to autoreconf call to pick up f-spot
  macros 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// ActionManager.cs
 
3
//
 
4
// Author:
 
5
//   Aaron Bockover <abockover@novell.com>
 
6
//
 
7
// Copyright (C) 2006-2007 Novell, Inc.
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
//
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
//
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
using System.IO;
 
31
using System.Reflection;
 
32
using System.Collections.Generic;
 
33
 
 
34
using Gtk;
 
35
using Action = Gtk.Action;
 
36
 
 
37
using Hyena;
 
38
 
 
39
namespace Hyena.Gui
 
40
{
 
41
    public class ActionManager
 
42
    {
 
43
        private UIManager ui_manager;
 
44
        private Dictionary<string, ActionGroup> action_groups = new Dictionary<string, ActionGroup> ();
 
45
 
 
46
        public ActionManager ()
 
47
        {
 
48
            ui_manager = new UIManager ();
 
49
        }
 
50
 
 
51
        public virtual void Initialize ()
 
52
        {
 
53
        }
 
54
 
 
55
        private void InnerAddActionGroup (ActionGroup group)
 
56
        {
 
57
            action_groups.Add (group.Name, group);
 
58
            ui_manager.InsertActionGroup (group, 0);
 
59
        }
 
60
 
 
61
        public void AddActionGroup (string name)
 
62
        {
 
63
            lock (this) {
 
64
                if (action_groups.ContainsKey (name)) {
 
65
                    throw new ApplicationException ("Group already exists");
 
66
                }
 
67
 
 
68
                InnerAddActionGroup (new ActionGroup (name));
 
69
            }
 
70
        }
 
71
 
 
72
        public void AddActionGroup (ActionGroup group)
 
73
        {
 
74
            lock (this) {
 
75
                if (action_groups.ContainsKey (group.Name)) {
 
76
                    throw new ApplicationException ("Group already exists");
 
77
                }
 
78
 
 
79
                InnerAddActionGroup (group);
 
80
            }
 
81
        }
 
82
 
 
83
        public void RemoveActionGroup (string name)
 
84
        {
 
85
            lock (this) {
 
86
                if (action_groups.ContainsKey (name)) {
 
87
                    ActionGroup group = action_groups[name];
 
88
                    ui_manager.RemoveActionGroup (group);
 
89
                    action_groups.Remove (name);
 
90
                }
 
91
            }
 
92
        }
 
93
 
 
94
        public void RemoveActionGroup (ActionGroup group)
 
95
        {
 
96
            RemoveActionGroup (group.Name);
 
97
        }
 
98
 
 
99
        public ActionGroup FindActionGroup (string actionGroupId)
 
100
        {
 
101
            foreach (ActionGroup group in action_groups.Values) {
 
102
                if (group.Name == actionGroupId) {
 
103
                    return group;
 
104
                }
 
105
            }
 
106
 
 
107
            return null;
 
108
        }
 
109
 
 
110
        public Gtk.Action FindAction (string actionId)
 
111
        {
 
112
            string [] parts = actionId.Split ('.');
 
113
 
 
114
            if (parts == null || parts.Length < 2) {
 
115
                return null;
 
116
            }
 
117
 
 
118
            string group_name = parts[0];
 
119
            string action_name = parts[1];
 
120
 
 
121
            ActionGroup group = FindActionGroup (group_name);
 
122
            return group == null ? null : group.GetAction (action_name);
 
123
        }
 
124
 
 
125
        public void PopulateToolbarPlaceholder (Toolbar toolbar, string path, Widget item)
 
126
        {
 
127
            PopulateToolbarPlaceholder (toolbar, path, item, false);
 
128
        }
 
129
 
 
130
        public void PopulateToolbarPlaceholder (Toolbar toolbar, string path, Widget item, bool expand)
 
131
        {
 
132
            ToolItem placeholder = (ToolItem)UIManager.GetWidget (path);
 
133
            int position = toolbar.GetItemIndex (placeholder);
 
134
            toolbar.Remove (placeholder);
 
135
 
 
136
            if (item is ToolItem) {
 
137
                ((ToolItem)item).Expand = expand;
 
138
                toolbar.Insert ((ToolItem)item, position);
 
139
            } else {
 
140
                ToolItem container_item = new Hyena.Widgets.GenericToolItem<Widget> (item);
 
141
                container_item.Expand = expand;
 
142
                container_item.Show ();
 
143
                toolbar.Insert (container_item, position);
 
144
            }
 
145
        }
 
146
 
 
147
        public uint AddUiFromFileInCurrentAssembly (string ui_file)
 
148
        {
 
149
            return AddUiFromFile (ui_file, Assembly.GetCallingAssembly ());
 
150
        }
 
151
 
 
152
        public uint AddUiFromFile (string ui_file, Assembly assembly)
 
153
        {
 
154
            if (ui_file != null) {
 
155
                using (StreamReader reader = new StreamReader (assembly.GetManifestResourceStream (ui_file))) {
 
156
                    return ui_manager.AddUiFromString (reader.ReadToEnd ());
 
157
                }
 
158
            }
 
159
            return 0;
 
160
        }
 
161
 
 
162
        public Gtk.Action this[string actionId] {
 
163
            get { return FindAction (actionId); }
 
164
        }
 
165
 
 
166
        public UIManager UIManager {
 
167
            get { return ui_manager; }
 
168
        }
 
169
    }
 
170
}