~ubuntu-branches/ubuntu/quantal/gnome-documents/quantal

« back to all changes in this revision

Viewing changes to src/mainToolbar.js

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2012-08-07 22:03:19 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120807220319-cwvu1sb3x9lo9osb
Tags: 0.5.5-0ubuntu1
* New upstream release.
* debian/control.in:
  - Bump minimum libgdata 
  - Drop explicit liboauth-dev from build-depends to match
    configure.ac change

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
const Global = imports.global;
37
37
const Searchbar = imports.searchbar;
38
38
const Tweener = imports.util.tweener;
39
 
const WindowMode = imports.windowMode;
40
39
 
41
40
const MainToolbar = new Lang.Class({
42
41
    Name: 'MainToolbar',
44
43
    _init: function() {
45
44
        this._model = null;
46
45
 
47
 
        this._collBackButton = null;
48
 
        this._collectionId = 0;
49
 
        this._selectionChangedId = 0;
50
 
 
51
46
        this.widget = new Gd.MainToolbar({ icon_size: Gtk.IconSize.MENU });
52
47
        this.widget.get_style_context().add_class(Gtk.STYLE_CLASS_MENUBAR);
53
48
        this.widget.show();
61
56
                         false, true, false,
62
57
                         Clutter.BoxAlignment.CENTER, Clutter.BoxAlignment.START);
63
58
 
 
59
        this.createSearchbar();
 
60
    },
 
61
 
 
62
    createSearchbar: function() {
 
63
        log('Error: MainToolbar subclasses must implement createSearchbar');
 
64
    },
 
65
 
 
66
    handleEvent: function(event) {
 
67
        let res = this._searchbar.handleEvent(event);
 
68
        return res;
 
69
    },
 
70
 
 
71
    addSearchButton: function() {
 
72
        let searchButton =
 
73
            this.widget.add_toggle('edit-find-symbolic', _("Search"), false);
 
74
        searchButton.action_name = 'app.search';
 
75
    }
 
76
});
 
77
 
 
78
const OverviewToolbar = new Lang.Class({
 
79
    Name: 'OverviewToolbar',
 
80
    Extends: MainToolbar,
 
81
 
 
82
    _init: function(viewLayout) {
 
83
        this._viewLayout = viewLayout;
 
84
        this._collBackButton = null;
 
85
        this._collectionId = 0;
 
86
        this._selectionChangedId = 0;
 
87
 
 
88
        this.parent();
 
89
 
64
90
        // setup listeners to mode changes that affect the toolbar layout
65
91
        this._searchStringId =
66
92
            Global.searchController.connect('search-string-changed',
77
103
        this._selectionModeId =
78
104
            Global.selectionController.connect('selection-mode-changed',
79
105
                                               Lang.bind(this, this._resetToolbarMode));
80
 
        this._windowModeId =
81
 
            Global.modeController.connect('window-mode-changed',
82
 
                                          Lang.bind(this, this._resetToolbarMode));
83
106
        this._resetToolbarMode();
84
107
 
85
108
        this.widget.connect('destroy', Lang.bind(this,
86
109
            function() {
87
110
                this._clearStateData();
88
111
 
89
 
                if (this._windowModeId != 0) {
90
 
                    Global.modeController.disconnect(this._windowModeId);
91
 
                    this._windowModeId = 0;
92
 
                }
93
 
 
94
112
                if (this._selectionModeId != 0) {
95
113
                    Global.selectionController.disconnect(this._selectionModeId);
96
114
                    this._selectionModeId = 0;
118
136
            }));
119
137
    },
120
138
 
121
 
    _clearStateData: function() {
122
 
        this._model = null;
123
 
        this._collBackButton = null;
124
 
 
125
 
        if (this._collectionId != 0) {
126
 
            Global.collectionManager.disconnect(this._collectionId);
127
 
            this._collectionId = 0;
128
 
        }
129
 
 
130
 
        if (this._selectionChangedId != 0) {
131
 
            Global.selectionController.disconnect(this._selectionChangedId);
132
 
            this._selectionChangedId = 0;
133
 
        }
134
 
    },
135
 
 
136
 
    _clearToolbar: function() {
137
 
        this._clearStateData();
138
 
 
139
 
        this.widget.get_style_context().remove_class('documents-selection-mode');
140
 
        this.widget.reset_style();
141
 
        this.widget.clear();
142
 
    },
143
 
 
144
139
    _setToolbarTitle: function() {
145
 
        let windowMode = Global.modeController.getWindowMode();
146
140
        let selectionMode = Global.selectionController.getSelectionMode();
147
141
        let activeCollection = Global.collectionManager.getActiveItem();
148
142
        let primary = null;
149
143
        let detail = null;
150
144
 
151
 
        if (windowMode == WindowMode.WindowMode.OVERVIEW) {
152
 
            if (!selectionMode) {
153
 
                if (activeCollection) {
154
 
                    primary = activeCollection.name;
 
145
        if (!selectionMode) {
 
146
            if (activeCollection) {
 
147
                primary = activeCollection.name;
 
148
            } else {
 
149
                let string = Global.searchController.getString();
 
150
 
 
151
                if (string == '') {
 
152
                    let searchType = Global.searchTypeManager.getActiveItem();
 
153
                    let searchSource = Global.sourceManager.getActiveItem();
 
154
 
 
155
                    if (searchType.id != 'all')
 
156
                        primary = searchType.name;
 
157
                    else
 
158
                        primary = _("New and Recent");
 
159
 
 
160
                    if (searchSource.id != 'all')
 
161
                        detail = searchSource.name;
155
162
                } else {
156
 
                    let string = Global.searchController.getString();
157
 
 
158
 
                    if (string == '') {
159
 
                        let searchType = Global.searchTypeManager.getActiveItem();
160
 
                        let searchSource = Global.sourceManager.getActiveItem();
161
 
 
162
 
                        if (searchType.id != 'all')
163
 
                            primary = searchType.name;
164
 
                        else
165
 
                            primary = _("New and Recent");
166
 
 
167
 
                        if (searchSource.id != 'all')
168
 
                            detail = searchSource.name;
169
 
                    } else {
170
 
                        let searchMatch = Global.searchMatchManager.getActiveItem();
171
 
 
172
 
                        primary = _("Results for \"%s\"").format(string);
173
 
                        if (searchMatch.id == 'title')
174
 
                            detail = _("filtered by title");
175
 
                        else if (searchMatch.id == 'author')
176
 
                            detail = _("filtered by author");
177
 
                    }
178
 
                }
179
 
            } else {
180
 
                let length = Global.selectionController.getSelection().length;
181
 
 
182
 
                if (length == 0)
183
 
                    detail = _("Click on items to select them");
184
 
                else
185
 
                    detail = Gettext.ngettext("%d selected",
186
 
                                              "%d selected",
187
 
                                              length).format(length);
188
 
 
189
 
                if (activeCollection) {
190
 
                    primary = activeCollection.name;
191
 
                } else if (length != 0) {
192
 
                    primary = detail;
193
 
                    detail = null;
 
163
                    let searchMatch = Global.searchMatchManager.getActiveItem();
 
164
 
 
165
                    primary = _("Results for \"%s\"").format(string);
 
166
                    if (searchMatch.id == 'title')
 
167
                        detail = _("filtered by title");
 
168
                    else if (searchMatch.id == 'author')
 
169
                        detail = _("filtered by author");
194
170
                }
195
171
            }
196
 
        } else if (windowMode == WindowMode.WindowMode.PREVIEW) {
197
 
            let doc = Global.documentManager.getActiveItem();
198
 
            primary = doc.name;
199
 
 
200
 
            if (this._model) {
201
 
                let curPage, totPages;
202
 
 
203
 
                curPage = this._model.get_page();
204
 
                totPages = this._model.get_document().get_n_pages();
205
 
 
206
 
                detail = _("%d of %d").format(curPage + 1, totPages);
 
172
        } else {
 
173
            let length = Global.selectionController.getSelection().length;
 
174
 
 
175
            if (length == 0)
 
176
                detail = _("Click on items to select them");
 
177
            else
 
178
                detail = Gettext.ngettext("%d selected",
 
179
                                          "%d selected",
 
180
                                          length).format(length);
 
181
 
 
182
            if (activeCollection) {
 
183
                primary = activeCollection.name;
 
184
            } else if (length != 0) {
 
185
                primary = detail;
 
186
                detail = null;
207
187
            }
208
188
        }
209
189
 
217
197
        this.widget.get_style_context().add_class('documents-selection-mode');
218
198
        this.widget.reset_style();
219
199
 
 
200
        this.addSearchButton();
 
201
 
220
202
        let selectionButton =
221
203
            this.widget.add_button(null, _("Done"), false);
222
204
        selectionButton.connect('clicked', Lang.bind(this,
230
212
                                               Lang.bind(this, this._setToolbarTitle));
231
213
    },
232
214
 
233
 
    _populateForPreview: function(model) {
234
 
        let iconName =
235
 
            (this.widget.get_direction() == Gtk.TextDirection.RTL) ?
236
 
            'go-next-symbolic' : 'go-previous-symbolic';
237
 
 
238
 
        let backButton =
239
 
            this.widget.add_button(iconName, _("Back"), true);
240
 
        backButton.connect('clicked', Lang.bind(this,
241
 
            function() {
242
 
                Global.modeController.setWindowMode(WindowMode.WindowMode.OVERVIEW);
243
 
            }));
244
 
    },
245
 
 
246
 
    _populateForOverview: function() {
247
 
        let selectionButton =
248
 
            this.widget.add_button('emblem-default-symbolic', _("Select Items"), false);
249
 
        selectionButton.connect('clicked', Lang.bind(this,
250
 
            function() {
251
 
                Global.selectionController.setSelectionMode(true);
252
 
            }));
253
 
 
254
 
        // connect to active collection changes while in this mode
255
 
        this._collectionId =
256
 
            Global.collectionManager.connect('active-changed',
257
 
                                             Lang.bind(this, this._onActiveCollectionChanged));
258
 
        this._onActiveCollectionChanged();
259
 
    },
260
 
 
261
215
    _onActiveCollectionChanged: function() {
262
216
        let item = Global.collectionManager.getActiveItem();
263
217
 
274
228
        }
275
229
 
276
230
        this._setToolbarTitle();
277
 
        this.searchbar.hide();
 
231
        Global.application.change_action_state('search', GLib.Variant.new('b', false));
 
232
    },
 
233
 
 
234
    _populateForOverview: function() {
 
235
        this.addSearchButton();
 
236
 
 
237
        let selectionButton =
 
238
            this.widget.add_button('object-select-symbolic', _("Select Items"), false);
 
239
        selectionButton.connect('clicked', Lang.bind(this,
 
240
            function() {
 
241
                Global.selectionController.setSelectionMode(true);
 
242
            }));
 
243
 
 
244
        // connect to active collection changes while in this mode
 
245
        this._collectionId =
 
246
            Global.collectionManager.connect('active-changed',
 
247
                                             Lang.bind(this, this._onActiveCollectionChanged));
 
248
    },
 
249
 
 
250
    _clearStateData: function() {
 
251
        this._collBackButton = null;
 
252
 
 
253
        if (this._collectionId != 0) {
 
254
            Global.collectionManager.disconnect(this._collectionId);
 
255
            this._collectionId = 0;
 
256
        }
 
257
 
 
258
        if (this._selectionChangedId != 0) {
 
259
            Global.selectionController.disconnect(this._selectionChangedId);
 
260
            this._selectionChangedId = 0;
 
261
        }
 
262
    },
 
263
 
 
264
    _clearToolbar: function() {
 
265
        this._clearStateData();
 
266
 
 
267
        this.widget.get_style_context().remove_class('documents-selection-mode');
 
268
        this.widget.reset_style();
 
269
        this.widget.clear();
278
270
    },
279
271
 
280
272
    _resetToolbarMode: function() {
281
273
        this._clearToolbar();
282
274
 
283
 
        let windowMode = Global.modeController.getWindowMode();
284
 
        if (windowMode == WindowMode.WindowMode.OVERVIEW) {
285
 
            let selectionMode = Global.selectionController.getSelectionMode();
286
 
            if (selectionMode)
287
 
                this._populateForSelectionMode();
288
 
            else
289
 
                this._populateForOverview();
290
 
        } else if (windowMode == WindowMode.WindowMode.PREVIEW) {
291
 
            this._populateForPreview();
292
 
        }
 
275
        let selectionMode = Global.selectionController.getSelectionMode();
 
276
        if (selectionMode)
 
277
            this._populateForSelectionMode();
 
278
        else
 
279
            this._populateForOverview();
293
280
 
294
281
        this._setToolbarTitle();
295
282
        this.widget.show_all();
296
 
    },
297
 
 
298
 
    setModel: function(model) {
299
 
        if (!model)
300
 
            return;
301
 
 
302
 
        this._model = model;
303
 
        this._model.connect('page-changed', Lang.bind(this,
304
 
            function() {
305
 
                this._setToolbarTitle();
306
 
            }));
307
 
 
308
 
        this._setToolbarTitle();
309
 
    }
310
 
});
311
 
 
312
 
const PreviewToolbar = new Lang.Class({
313
 
    Name: 'PreviewToolbar',
314
 
    Extends: MainToolbar,
315
 
 
316
 
    _init: function() {
317
 
        this.parent();
318
 
 
319
 
        this.actor.y = -(this.widget.get_preferred_height()[1]);
320
 
    },
321
 
 
322
 
    show: function() {
323
 
        Tweener.addTween(this.actor,
324
 
                         { y: 0,
325
 
                           time: 0.20,
326
 
                           transition: 'easeInQuad' });
327
 
    },
328
 
 
329
 
    hide: function() {
330
 
        Tweener.addTween(this.actor,
331
 
                         { y: -(this.widget.get_preferred_height()[1]),
332
 
                           time: 0.20,
333
 
                           transition: 'easeOutQuad' });
334
 
    }
335
 
});
336
 
 
337
 
const OverviewToolbar = new Lang.Class({
338
 
    Name: 'OverviewToolbar',
339
 
    Extends: MainToolbar,
340
 
 
341
 
    _init: function() {
342
 
        this.parent();
343
 
 
344
 
        this.searchbar = new Searchbar.Searchbar();
345
 
        this.layout.pack_start = true;
346
 
        this.layout.pack(this.searchbar.actor, false, true, false,
 
283
 
 
284
        if (Global.searchController.getString() != '')
 
285
            Global.application.change_action_state('search', GLib.Variant.new('b', true));
 
286
    },
 
287
 
 
288
    createSearchbar: function() {
 
289
        // create the dropdown for the search bar, it's hidden by default
 
290
        let dropdown = new Searchbar.Dropdown();
 
291
        this._viewLayout.add(dropdown.actor,
 
292
            Clutter.BinAlignment.CENTER, Clutter.BinAlignment.FIXED);
 
293
 
 
294
        this._searchbar = new Searchbar.OverviewSearchbar(dropdown);
 
295
        this.layout.pack_start = false;
 
296
        this.layout.pack(this._searchbar.actor, false, true, false,
347
297
                         Clutter.BoxAlignment.CENTER, Clutter.BoxAlignment.START);
348
 
    },
349
 
 
350
 
    _resetToolbarMode: function() {
351
 
        this.parent();
352
 
 
353
 
        let mode = Global.modeController.getWindowMode();
354
 
 
355
 
        if (mode == WindowMode.WindowMode.PREVIEW)
356
 
            this.searchbar.hide();
357
 
        else if (mode == WindowMode.WindowMode.OVERVIEW &&
358
 
                 Global.searchController.getString() != '')
359
 
            this.searchbar.show();
360
298
    }
361
299
});