~ubuntu-branches/debian/squeeze/f-spot/squeeze

« back to all changes in this revision

Viewing changes to src/Widgets/EditorPage.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane, Mirco Bauer, Iain Lane
  • Date: 2009-02-07 20:23:32 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20090207202332-oc93rfjo1st0571s
Tags: 0.5.0.3-2
[ Mirco Bauer]
* Upload to unstable.
* debian/control:
  + Lowered GNOME# build-deps to 2.0 ABI as that transition didn't happen
    yet in unstable.

[ Iain Lane ]
* debian/patches/svn-r4545_locales-import.dpatch: Patch backported from SVN
  trunk revision 4545 - initialize the translation catalog earlier (LP: #293305)
  (Closes: #514457). Thanks to Florian Heinle for finding the patch and to
  Chris Coulson for preparing the update.
* debian/control: Build-depend on libmono-dev (>= 1.2.4) to match configure
  checks.
* debian/rules: Pass CSC=/usr/bin/csc to configure for gio-sharp to fix FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Widgets.EditorPage.cs
 
3
 *
 
4
 * Author(s)
 
5
 *      Ruben Vermeersch <ruben@savanne.be>
 
6
 *
 
7
 * This is free software. See COPYING for details.
 
8
 */
 
9
 
 
10
using FSpot;
 
11
using FSpot.Editors;
 
12
using FSpot.UI.Dialog;
 
13
using FSpot.Utils;
 
14
 
 
15
using Gtk;
 
16
 
 
17
using Mono.Addins;
 
18
using Mono.Unix;
 
19
 
 
20
using System;
 
21
using System.Collections.Generic;
 
22
 
 
23
namespace FSpot.Widgets {
 
24
        public class EditorPage : SidebarPage {
 
25
                internal bool InPhotoView;
 
26
                private readonly EditorPageWidget EditorPageWidget;
 
27
 
 
28
                public EditorPage () : base (new EditorPageWidget (),
 
29
                                                                           Catalog.GetString ("Edit"),
 
30
                                                                           "mode-image-edit") {
 
31
                        // TODO: Somebody might need to change the icon to something more suitable.
 
32
                        // FIXME: The icon isn't shown in the menu, are we missing a size?
 
33
                        EditorPageWidget = SidebarWidget as EditorPageWidget;
 
34
                        EditorPageWidget.Page = this;
 
35
                }
 
36
 
 
37
                protected override void AddedToSidebar () {
 
38
                        Sidebar.SelectionChanged += delegate (IBrowsableCollection collection) { EditorPageWidget.ShowTools (); };
 
39
                        Sidebar.ContextChanged += HandleContextChanged;
 
40
                }
 
41
 
 
42
                private void HandleContextChanged (object sender, EventArgs args)
 
43
                {
 
44
                        InPhotoView = (Sidebar.Context == ViewContext.Edit);
 
45
                        EditorPageWidget.ChangeButtonVisibility ();
 
46
                }
 
47
        }
 
48
 
 
49
        public class EditorPageWidget : ScrolledWindow {
 
50
                private VBox widgets;
 
51
                private VButtonBox buttons;
 
52
                private Widget active_editor;
 
53
 
 
54
                private List<Editor> editors;
 
55
                private Editor current_editor;
 
56
 
 
57
                // Used to make buttons insensitive when selecting multiple images.
 
58
                private Dictionary<Editor, Button> editor_buttons;
 
59
 
 
60
                private EditorPage page;
 
61
                internal EditorPage Page {
 
62
                        get { return page; }
 
63
                        set { page = value; ChangeButtonVisibility (); }
 
64
                }
 
65
 
 
66
                public EditorPageWidget () {
 
67
                        editors = new List<Editor> ();
 
68
                        editor_buttons = new Dictionary<Editor, Button> ();
 
69
                        ShowTools ();
 
70
                        AddinManager.AddExtensionNodeHandler ("/FSpot/Editors", OnExtensionChanged);
 
71
 
 
72
                }
 
73
 
 
74
                private void OnExtensionChanged (object s, ExtensionNodeEventArgs args) {
 
75
                        // FIXME: We do not do run-time removal of editors yet!
 
76
                        if (args.Change == ExtensionChange.Add) {
 
77
                                Editor editor = (args.ExtensionNode as EditorNode).GetEditor ();
 
78
                                editor.ProcessingStarted += OnProcessingStarted;
 
79
                                editor.ProcessingStep += OnProcessingStep;
 
80
                                editor.ProcessingFinished += OnProcessingFinished;
 
81
                                editors.Add (editor);
 
82
                                PackButton (editor);
 
83
                        }
 
84
                }
 
85
 
 
86
                private ProgressDialog progress;
 
87
 
 
88
                private void OnProcessingStarted (string name, int count) {
 
89
                        progress = new ProgressDialog (name, ProgressDialog.CancelButtonType.None, count, MainWindow.Toplevel.Window);
 
90
                }
 
91
 
 
92
                private void OnProcessingStep (int done) {
 
93
                        if (progress != null)
 
94
                                progress.Update (String.Empty);
 
95
                }
 
96
 
 
97
                private void OnProcessingFinished () {
 
98
                        if (progress != null) {
 
99
                                progress.Destroy ();
 
100
                                progress = null;
 
101
                        }
 
102
                }
 
103
 
 
104
                internal void ChangeButtonVisibility () {
 
105
                        foreach (Editor editor in editors) {
 
106
                                Button button;
 
107
                                if (editor_buttons.TryGetValue (editor, out button))
 
108
                                        button.Visible = Page.InPhotoView || editor.CanHandleMultiple;
 
109
                        }
 
110
                }
 
111
 
 
112
                void PackButton (Editor editor)
 
113
                {
 
114
                        Button button = new Button (editor.Label);
 
115
                        if (editor.IconName != null)
 
116
                                button.Image = new Image (GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, editor.IconName, 22, (Gtk.IconLookupFlags)0));
 
117
                        button.Clicked += delegate (object o, EventArgs e) { ChooseEditor (editor); };
 
118
                        button.Show ();
 
119
                        buttons.Add (button);
 
120
                        editor_buttons.Add (editor, button);
 
121
                }
 
122
 
 
123
                public void ShowTools () {
 
124
                        // Remove any open editor, if present.
 
125
                        if (current_editor != null) {
 
126
                                active_editor.Hide ();
 
127
                                widgets.Remove (active_editor);
 
128
                                active_editor = null;
 
129
                                current_editor.Restore ();
 
130
                                current_editor = null;
 
131
                        }
 
132
 
 
133
                        // No need to build the widget twice.
 
134
                        if (buttons != null) {
 
135
                                buttons.Show ();
 
136
                                return;
 
137
                        }
 
138
 
 
139
                        if (widgets == null) {
 
140
                                widgets = new VBox (false, 0);
 
141
                                widgets.NoShowAll = true;
 
142
                                widgets.Show ();
 
143
                                Viewport widgets_port = new Viewport ();
 
144
                                widgets_port.Add (widgets);
 
145
                                Add (widgets_port);
 
146
                                widgets_port.ShowAll ();
 
147
                        }
 
148
 
 
149
                        // Build the widget (first time we call this method).
 
150
                        buttons = new VButtonBox ();
 
151
                        buttons.BorderWidth = 5;
 
152
                        buttons.Spacing = 5;
 
153
                        buttons.LayoutStyle = ButtonBoxStyle.Start;
 
154
 
 
155
                        foreach (Editor editor in editors) 
 
156
                                PackButton (editor);
 
157
 
 
158
                        buttons.Show ();
 
159
                        widgets.Add (buttons);
 
160
                }
 
161
 
 
162
                private void ChooseEditor (Editor editor) {
 
163
                        SetupEditor (editor);
 
164
 
 
165
                        if (!editor.CanBeApplied || editor.HasSettings)
 
166
                                ShowEditor (editor);
 
167
                        else
 
168
                                Apply (editor); // Instant apply
 
169
                }
 
170
 
 
171
                private bool SetupEditor (Editor editor) {
 
172
                        EditorState state = editor.CreateState ();
 
173
 
 
174
                        EditorSelection selection = new EditorSelection ();
 
175
                        PhotoImageView photo_view = MainWindow.Toplevel.PhotoView.View;
 
176
 
 
177
                        if (Page.InPhotoView && photo_view != null) {
 
178
                                if (photo_view.GetSelection (out selection.x, out selection.y,
 
179
                                                        out selection.width, out selection.height))
 
180
                                        state.Selection = selection;
 
181
                                else
 
182
                                        state.Selection = null;
 
183
                                state.PhotoImageView = photo_view;
 
184
                        } else {
 
185
                                state.Selection = null;
 
186
                                state.PhotoImageView = null;
 
187
                        }
 
188
                        if (Page.Sidebar.Selection == null)
 
189
                                return false;
 
190
                        state.Items = Page.Sidebar.Selection.Items;
 
191
 
 
192
                        editor.Initialize (state);
 
193
                        return true;
 
194
                }
 
195
 
 
196
                private void Apply (Editor editor) {
 
197
                        if (!SetupEditor (editor))
 
198
                                return;
 
199
 
 
200
                        if (!editor.CanBeApplied) {
 
201
                                string msg = Catalog.GetString ("No selection available");
 
202
                                string desc = Catalog.GetString ("This tool requires an active selection. Please select a region of the photo and try the operation again");
 
203
 
 
204
                                HigMessageDialog md = new HigMessageDialog (MainWindow.Toplevel.Window,
 
205
                                                                                DialogFlags.DestroyWithParent,
 
206
                                                                                Gtk.MessageType.Error, ButtonsType.Ok,
 
207
                                                                                msg,
 
208
                                                                                desc);
 
209
 
 
210
                                md.Run ();
 
211
                                md.Destroy ();
 
212
                                return;
 
213
                        }
 
214
 
 
215
                        // TODO: Might need to do some nicer things for multiple selections (progress?)
 
216
                        try {
 
217
                                editor.Apply ();
 
218
                        } catch (Exception e) {
 
219
                                string msg = Catalog.GetPluralString ("Error saving adjusted photo", "Error saving adjusted photos", 
 
220
                                                                        editor.State.Items.Length);
 
221
                                string desc = String.Format (Catalog.GetString ("Received exception \"{0}\". Note that you have to develop RAW files into JPEG before you can edit them."),
 
222
                                                             e.Message);
 
223
 
 
224
                                HigMessageDialog md = new HigMessageDialog (MainWindow.Toplevel.Window,
 
225
                                                                            DialogFlags.DestroyWithParent,
 
226
                                                                            Gtk.MessageType.Error, ButtonsType.Ok,
 
227
                                                                            msg,
 
228
                                                                            desc);
 
229
                                md.Run ();
 
230
                                md.Destroy ();
 
231
                        }
 
232
                        ShowTools ();
 
233
                }
 
234
 
 
235
                private void ShowEditor (Editor editor) {
 
236
                        SetupEditor (editor);
 
237
                        current_editor = editor;
 
238
 
 
239
                        buttons.Hide ();
 
240
 
 
241
                        // Top label
 
242
                        VBox vbox = new VBox (false, 4);
 
243
                        Label label = new Label ();
 
244
                        label.Markup = String.Format("<big><b>{0}</b></big>", editor.Label);
 
245
                        vbox.PackStart (label, false, false, 5);
 
246
 
 
247
                        // Optional config widget
 
248
                        Widget config = editor.ConfigurationWidget ();
 
249
                        if (config != null) {
 
250
                                vbox.PackStart (config, false, false, 0);
 
251
                        }
 
252
 
 
253
                        // Apply / Cancel buttons
 
254
                        HButtonBox tool_buttons = new HButtonBox ();
 
255
                        tool_buttons.LayoutStyle = ButtonBoxStyle.End;
 
256
                        tool_buttons.Spacing = 5;
 
257
                        tool_buttons.BorderWidth = 5;
 
258
                        tool_buttons.Homogeneous = false;
 
259
 
 
260
                        Button cancel = new Button (Stock.Cancel);
 
261
                        cancel.Clicked += HandleCancel;
 
262
                        tool_buttons.Add (cancel);
 
263
 
 
264
                        Button apply = new Button (editor.ApplyLabel);
 
265
                        apply.Image = new Image (GtkUtil.TryLoadIcon (FSpot.Global.IconTheme, editor.IconName, 22, (Gtk.IconLookupFlags)0));
 
266
                        apply.Clicked += delegate { Apply (editor); };
 
267
                        tool_buttons.Add (apply);
 
268
 
 
269
                        // Pack it all together
 
270
                        vbox.PackEnd (tool_buttons, false, false, 0);
 
271
                        active_editor = vbox;
 
272
                        widgets.Add (active_editor);
 
273
                        active_editor.ShowAll ();
 
274
                }
 
275
 
 
276
                void HandleCancel (object sender, System.EventArgs args) {
 
277
                        ShowTools ();
 
278
                }
 
279
        }
 
280
}