~noskcaj/ubuntu/trusty/gnome-documents/3.10.2

« back to all changes in this revision

Viewing changes to src/view.js

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson, Thomas Bechtold
  • Date: 2013-04-04 13:32:08 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130404133208-n19gqczi05z31ogb
Tags: 3.8.0-1
[ Thomas Bechtold ]
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 */
21
21
 
22
22
const Gd = imports.gi.Gd;
23
 
const GdPrivate = imports.gi.GdPrivate;
24
23
const Gdk = imports.gi.Gdk;
25
24
const GdkPixbuf = imports.gi.GdkPixbuf;
26
25
const Gettext = imports.gettext;
32
31
const Lang = imports.lang;
33
32
const Mainloop = imports.mainloop;
34
33
 
 
34
const Application = imports.application;
35
35
const Documents = imports.documents;
36
 
const Global = imports.global;
37
36
const TrackerUtils = imports.trackerUtils;
38
37
const WindowMode = imports.windowMode;
39
38
const Utils = imports.utils;
44
43
    _init: function() {
45
44
        this._block = false;
46
45
 
47
 
        this._controller = Global.offsetController;
 
46
        this._controller = Application.offsetController;
48
47
        this._controllerId =
49
48
            this._controller.connect('item-count-changed',
50
49
                                     Lang.bind(this, this._onItemCountChanged));
51
50
 
52
 
        this.widget = new Gtk.Button({ no_show_all: true });
 
51
        let child = new Gtk.Grid({ column_spacing: 10,
 
52
                                   hexpand: true,
 
53
                                   halign: Gtk.Align.CENTER,
 
54
                                   visible: true });
 
55
 
 
56
        this._spinner = new Gtk.Spinner({ halign: Gtk.Align.CENTER,
 
57
                                          no_show_all: true });
 
58
        this._spinner.set_size_request(16, 16);
 
59
        child.add(this._spinner);
 
60
 
 
61
        this._label = new Gtk.Label({ label: _("Load More"),
 
62
                                      visible: true });
 
63
        child.add(this._label);
 
64
 
 
65
        this.widget = new Gtk.Button({ no_show_all: true,
 
66
                                       child: child });
53
67
        this.widget.get_style_context().add_class('documents-load-more');
54
68
        this.widget.connect('clicked', Lang.bind(this,
55
69
            function() {
 
70
                this._label.label = _("Loading…");
 
71
                this._spinner.show();
 
72
                this._spinner.start();
 
73
 
56
74
                this._controller.increaseOffset();
57
75
            }));
58
76
 
66
84
 
67
85
    _onItemCountChanged: function() {
68
86
        let remainingDocs = this._controller.getRemainingDocs();
69
 
        let offsetStep = this._controller.getOffsetStep();
 
87
        let visible = !(remainingDocs <= 0 || this._block);
 
88
        this.widget.set_visible(visible);
70
89
 
71
 
        if (remainingDocs <= 0 || this._block) {
72
 
            this.widget.hide();
73
 
            return;
 
90
        if (!visible) {
 
91
            this._label.label = _("Load More");
 
92
            this._spinner.stop();
 
93
            this._spinner.hide();
74
94
        }
75
 
 
76
 
        if (remainingDocs > offsetStep)
77
 
            remainingDocs = offsetStep;
78
 
 
79
 
        this.widget.label = Gettext.ngettext("Load %d more document",
80
 
                                             "Load %d more documents",
81
 
                                             remainingDocs).format(remainingDocs);
82
 
        this.widget.show();
83
95
    },
84
96
 
85
97
    setBlock: function(block) {
106
118
        this.model.set_sort_column_id(Gd.MainColumns.MTIME,
107
119
                                      Gtk.SortType.DESCENDING);
108
120
 
109
 
        Global.documentManager.connect('item-added',
 
121
        Application.documentManager.connect('item-added',
110
122
            Lang.bind(this, this._onItemAdded));
111
 
        Global.documentManager.connect('item-removed',
 
123
        Application.documentManager.connect('item-removed',
112
124
            Lang.bind(this, this._onItemRemoved));
113
 
        Global.documentManager.connect('clear',
 
125
        Application.documentManager.connect('clear',
114
126
            Lang.bind(this, this._onClear));
115
127
 
116
128
        // populate with the intial items
117
 
        let items = Global.documentManager.getItems();
 
129
        let items = Application.documentManager.getItems();
118
130
        for (let idx in items) {
119
131
            this._onItemAdded(null, items[idx]);
120
132
        }
175
187
        this._model = new ViewModel();
176
188
 
177
189
        this.widget = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL });
178
 
        this.view = new Gd.MainView();
 
190
        this.view = new Gd.MainView({ shadow_type: Gtk.ShadowType.NONE });
179
191
        this.widget.add(this.view);
180
192
 
181
193
        this._loadMore = new LoadMoreButton();
191
203
                            Lang.bind(this, this._onViewSelectionChanged));
192
204
 
193
205
        // connect to settings change for list/grid view
194
 
        this._viewSettingsId =
195
 
            Global.settings.connect('changed::view-as',
196
 
                                    Lang.bind(this, this._updateTypeForSettings));
 
206
        this._viewSettingsId = Application.settings.connect('changed::view-as',
 
207
            Lang.bind(this, this._updateTypeForSettings));
197
208
        this._updateTypeForSettings();
198
209
 
199
210
        // setup selection controller => view
200
 
        this._selectionModeId =
201
 
            Global.selectionController.connect('selection-mode-changed',
202
 
                                               Lang.bind(this, this._onSelectionModeChanged));
 
211
        this._selectionModeId = Application.selectionController.connect('selection-mode-changed',
 
212
            Lang.bind(this, this._onSelectionModeChanged));
203
213
        this._onSelectionModeChanged();
204
214
 
205
 
        Global.modeController.connect('window-mode-changed',
206
 
                                      Lang.bind(this, this._onWindowModeChanged));
 
215
        Application.modeController.connect('window-mode-changed',
 
216
            Lang.bind(this, this._onWindowModeChanged));
207
217
        this._onWindowModeChanged();
208
218
 
209
 
        let selectAll = Global.application.lookup_action('select-all');
 
219
        let selectAll = Application.application.lookup_action('select-all');
210
220
        selectAll.connect('activate', Lang.bind(this,
211
221
            function() {
212
222
                this.view.select_all();
213
223
            }));
214
224
 
215
 
        let selectNone = Global.application.lookup_action('select-none');
 
225
        let selectNone = Application.application.lookup_action('select-none');
216
226
        selectNone.connect('activate', Lang.bind(this,
217
227
            function() {
218
228
                this.view.unselect_all();
219
229
            }));
220
230
 
221
 
        this._queryId =
222
 
            Global.trackerController.connect('query-status-changed',
223
 
                                             Lang.bind(this, this._onQueryStatusChanged));
 
231
        this._queryId = Application.trackerController.connect('query-status-changed',
 
232
            Lang.bind(this, this._onQueryStatusChanged));
224
233
        // ensure the tracker controller is started
225
 
        Global.trackerController.start();
 
234
        Application.trackerController.start();
226
235
 
227
236
        // this will create the model if we're done querying
228
237
        this._onQueryStatusChanged();
229
238
    },
230
239
 
231
240
    _updateTypeForSettings: function() {
232
 
        let viewType = Global.settings.get_enum('view-as');
 
241
        let viewType = Application.settings.get_enum('view-as');
233
242
        this.view.set_view_type(viewType);
234
243
 
235
244
        if (viewType == Gd.MainViewType.LIST)
240
249
        let listWidget = this.view.get_generic_view();
241
250
 
242
251
        let typeRenderer =
243
 
            new GdPrivate.StyledTextRenderer({ xpad: 16 });
 
252
            new Gd.StyledTextRenderer({ xpad: 16 });
244
253
        typeRenderer.add_class('dim-label');
245
254
        listWidget.add_renderer(typeRenderer, Lang.bind(this,
246
255
            function(col, cell, model, iter) {
247
256
                let id = model.get_value(iter, Gd.MainColumns.ID);
248
 
                let doc = Global.documentManager.getItemById(id);
 
257
                let doc = Application.documentManager.getItemById(id);
249
258
 
250
259
                typeRenderer.text = doc.typeDescription;
251
260
            }));
252
261
 
253
262
        let whereRenderer =
254
 
            new GdPrivate.StyledTextRenderer({ xpad: 16 });
 
263
            new Gd.StyledTextRenderer({ xpad: 16 });
255
264
        whereRenderer.add_class('dim-label');
256
265
        listWidget.add_renderer(whereRenderer, Lang.bind(this,
257
266
            function(col, cell, model, iter) {
258
267
                let id = model.get_value(iter, Gd.MainColumns.ID);
259
 
                let doc = Global.documentManager.getItemById(id);
 
268
                let doc = Application.documentManager.getItemById(id);
260
269
 
261
270
                whereRenderer.text = doc.sourceName;
262
271
            }));
266
275
        listWidget.add_renderer(dateRenderer, Lang.bind(this,
267
276
            function(col, cell, model, iter) {
268
277
                let id = model.get_value(iter, Gd.MainColumns.ID);
269
 
                let doc = Global.documentManager.getItemById(id);
 
278
                let doc = Application.documentManager.getItemById(id);
270
279
                let DAY = 86400000000;
271
280
 
272
281
                let now = GLib.DateTime.new_now_local();
308
317
    },
309
318
 
310
319
    _onSelectionModeRequest: function() {
311
 
        Global.selectionController.setSelectionMode(true);
 
320
        Application.selectionController.setSelectionMode(true);
312
321
    },
313
322
 
314
323
    _onItemActivated: function(widget, id, path) {
315
 
        Global.documentManager.setActiveItemById(id);
 
324
        Application.documentManager.setActiveItemById(id);
316
325
    },
317
326
 
318
327
    _onQueryStatusChanged: function() {
319
 
        let status = Global.trackerController.getQueryStatus();
 
328
        let status = Application.trackerController.getQueryStatus();
320
329
 
321
330
        if (!status) {
322
331
            // setup a model if we're not querying
323
332
            this.view.set_model(this._model.model);
324
333
 
325
334
            // unfreeze selection
326
 
            Global.selectionController.freezeSelection(false);
 
335
            Application.selectionController.freezeSelection(false);
327
336
            this._updateSelection();
328
337
        } else {
329
338
            // save the last selection
330
 
            Global.selectionController.freezeSelection(true);
 
339
            Application.selectionController.freezeSelection(true);
331
340
 
332
341
            // if we're querying, clear the model from the view,
333
342
            // so that we don't uselessly refresh the rows
336
345
    },
337
346
 
338
347
    _updateSelection: function() {
339
 
        let selected = Global.selectionController.getSelection();
 
348
        let selected = Application.selectionController.getSelection();
340
349
        let newSelection = [];
341
350
 
342
351
        if (!selected.length)
365
374
                return false;
366
375
            }));
367
376
 
368
 
        Global.selectionController.setSelection(newSelection);
 
377
        Application.selectionController.setSelection(newSelection);
369
378
    },
370
379
 
371
380
    _onSelectionModeChanged: function() {
372
 
        let selectionMode = Global.selectionController.getSelectionMode();
 
381
        let selectionMode = Application.selectionController.getSelectionMode();
373
382
        this.view.set_selection_mode(selectionMode);
374
383
    },
375
384
 
377
386
        // update the selection on the controller when the view signals a change
378
387
        let selectedURNs = Utils.getURNsFromPaths(this.view.get_selection(),
379
388
                                                  this._model.model);
380
 
        Global.selectionController.setSelection(selectedURNs);
 
389
        Application.selectionController.setSelection(selectedURNs);
381
390
    },
382
391
 
383
392
    _onWindowModeChanged: function() {
384
 
        let mode = Global.modeController.getWindowMode();
 
393
        let mode = Application.modeController.getWindowMode();
385
394
        if (mode == WindowMode.WindowMode.OVERVIEW)
386
395
            this._connectView();
387
396
        else