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

« back to all changes in this revision

Viewing changes to src/selections.js

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-08-22 10:01:18 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20120822100118-3837rqfy72e1op72
Tags: 3.5.90-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
const Clutter = imports.gi.Clutter;
23
23
const EvView = imports.gi.EvinceView;
24
 
const Gd = imports.gi.Gd;
 
24
const GdPrivate = imports.gi.GdPrivate;
25
25
const Gdk = imports.gi.Gdk;
26
26
const GLib = imports.gi.GLib;
27
27
const GObject = imports.gi.GObject;
34
34
const Global = imports.global;
35
35
const Manager = imports.manager;
36
36
const Notifications = imports.notifications;
 
37
const Properties = imports.properties;
37
38
const Query = imports.query;
38
39
const Tweener = imports.util.tweener;
39
40
const Utils = imports.utils;
483
484
        this._viewCol.add_attribute(this._rendererText,
484
485
                                    'text', OrganizeModelColumns.NAME);
485
486
 
486
 
        this._rendererDetail = new Gd.StyledTextRenderer({ xpad: 16 });
 
487
        this._rendererDetail = new GdPrivate.StyledTextRenderer({ xpad: 16 });
487
488
        this._rendererDetail.add_class('dim-label');
488
489
        this._viewCol.pack_start(this._rendererDetail, false);
489
490
        this._viewCol.set_cell_data_func(this._rendererDetail,
715
716
});
716
717
Signals.addSignalMethods(SelectionController.prototype);
717
718
 
 
719
const _SELECTION_TOOLBAR_DEFAULT_WIDTH = 500;
 
720
 
718
721
const SelectionToolbar = new Lang.Class({
719
722
    Name: 'SelectionToolbar',
720
723
 
726
729
        this.widget = new Gtk.Toolbar({ show_arrow: false,
727
730
                                        icon_size: Gtk.IconSize.LARGE_TOOLBAR });
728
731
        this.widget.get_style_context().add_class('osd');
 
732
        this.widget.set_size_request(_SELECTION_TOOLBAR_DEFAULT_WIDTH, -1);
729
733
 
730
734
        this.actor = new GtkClutter.Actor({ contents: this.widget,
731
735
                                            show_on_set_parent: false,
732
736
                                            opacity: 0 });
733
737
        Utils.alphaGtkWidget(this.actor.get_widget());
734
738
 
735
 
        let widthConstraint =
736
 
            new Clutter.BindConstraint({ source: this._parentActor,
737
 
                                         coordinate: Clutter.BindCoordinate.WIDTH,
738
 
                                         offset: - 300 });
739
 
        this.actor.add_constraint(widthConstraint);
740
 
        this.actor.connect('notify::width', Lang.bind(this,
741
 
            function() {
742
 
                let width = this._parentActor.width;
743
 
                let offset = 300;
744
 
 
745
 
                if (width > 1000)
746
 
                    offset += (width - 1000);
747
 
                else if (width < 600)
748
 
                    offset -= (600 - width);
749
 
 
750
 
                widthConstraint.offset = - offset;
751
 
            }));
752
 
 
753
739
        this.actor.add_constraint(
754
740
            new Clutter.AlignConstraint({ align_axis: Clutter.AlignAxis.X_AXIS,
755
741
                                          source: this._parentActor,
763
749
        this._leftGroup = new Gtk.ToolItem({ child: this._leftBox });
764
750
        this.widget.insert(this._leftGroup, -1);
765
751
 
766
 
        this._toolbarFavorite = new Gtk.ToggleButton({ child: new Gtk.Image ({ icon_name: 'emblem-favorite-symbolic',
767
 
                                                                               pixel_size: 32 })});
768
 
        this._leftBox.add(this._toolbarFavorite);
769
 
        this._toolbarFavorite.connect('clicked', Lang.bind(this, this._onToolbarFavorite));
 
752
        // open button
 
753
        this._toolbarOpen = new Gtk.Button({ child: new Gtk.Image ({ icon_name: 'folder-symbolic',
 
754
                                                                     pixel_size: 16 })});
 
755
        this._leftBox.add(this._toolbarOpen);
 
756
        this._toolbarOpen.connect('clicked', Lang.bind(this, this._onToolbarOpen));
770
757
 
 
758
        // print button
771
759
        this._toolbarPrint = new Gtk.Button({ child: new Gtk.Image ({ icon_name: 'printer-symbolic',
772
 
                                                                      pixel_size: 32 })});
 
760
                                                                      pixel_size: 16 })});
773
761
        this._toolbarPrint.set_tooltip_text(_("Print"));
774
762
        this._leftBox.add(this._toolbarPrint);
775
763
        this._toolbarPrint.connect('clicked', Lang.bind(this, this._onToolbarPrint));
776
764
 
 
765
        // trash button
 
766
        this._toolbarTrash = new Gtk.Button({ child: new Gtk.Image ({ icon_name: 'user-trash-symbolic',
 
767
                                                                      pixel_size: 16 })});
 
768
        this._toolbarTrash.set_tooltip_text(_("Delete"));
 
769
        this._leftBox.add(this._toolbarTrash);
 
770
        this._toolbarTrash.connect('clicked', Lang.bind(this, this._onToolbarTrash));
 
771
 
777
772
        this._separator = new Gtk.SeparatorToolItem({ draw: false,
778
773
                                                      visible: true });
779
774
        this._separator.set_expand(true);
783
778
        this._rightGroup = new Gtk.ToolItem({ child: this._rightBox });
784
779
        this.widget.insert(this._rightGroup, -1);
785
780
 
 
781
        // organize button
786
782
        this._toolbarCollection = new Gtk.Button({ child: new Gtk.Image ({ icon_name: 'list-add-symbolic',
787
 
                                                                           pixel_size: 32 })});
 
783
                                                                           pixel_size: 16 })});
788
784
        this._toolbarCollection.set_tooltip_text(_("Organize"));
789
785
        this._rightBox.add(this._toolbarCollection);
790
786
        this._toolbarCollection.connect('clicked', Lang.bind(this, this._onToolbarCollection));
791
787
        this._toolbarCollection.show_all();
792
788
 
793
 
        this._toolbarTrash = new Gtk.Button({ child: new Gtk.Image ({ icon_name: 'user-trash-symbolic',
794
 
                                                                      pixel_size: 32 })});
795
 
        this._toolbarTrash.set_tooltip_text(_("Delete"));
796
 
        this._rightBox.add(this._toolbarTrash);
797
 
        this._toolbarTrash.connect('clicked', Lang.bind(this, this._onToolbarTrash));
798
 
 
799
 
        this._toolbarOpen = new Gtk.Button({ child: new Gtk.Image ({ icon_name: 'document-open-symbolic',
800
 
                                                                     pixel_size: 32 })});
801
 
        this._rightBox.add(this._toolbarOpen);
802
 
        this._toolbarOpen.connect('clicked', Lang.bind(this, this._onToolbarOpen));
 
789
        // properties button
 
790
        this._toolbarProperties = new Gtk.Button({ child: new Gtk.Image ({ icon_name: 'document-properties-symbolic',
 
791
                                                                           pixel_size: 16 })});
 
792
        this._toolbarProperties.set_tooltip_text(_("Properties"));
 
793
        this._rightBox.add(this._toolbarProperties);
 
794
        this._toolbarProperties.connect('clicked', Lang.bind(this, this._onToolbarProperties));
803
795
 
804
796
        this.widget.show_all();
805
797
 
848
840
 
849
841
    _setItemVisibility: function() {
850
842
        let apps = [];
851
 
        let favCount = 0;
852
 
        let showFavorite = true;
853
843
        let showTrash = true;
854
844
        let showPrint = true;
 
845
        let showProperties = true;
855
846
        let showOpen = true;
856
847
 
857
848
        this._insideRefresh = true;
861
852
            function(urn) {
862
853
                let doc = Global.documentManager.getItemById(urn);
863
854
 
864
 
                if (doc.favorite)
865
 
                    favCount++;
866
 
 
867
855
                if ((doc.defaultAppName) &&
868
856
                    (apps.indexOf(doc.defaultAppName) == -1))
869
857
                    apps.push(doc.defaultAppName);
872
860
                showPrint &= !doc.collection;
873
861
            }));
874
862
 
875
 
        showFavorite &= ((favCount == 0) || (favCount == selection.length));
876
863
        showOpen = (apps.length > 0);
877
864
 
878
 
        if (selection.length > 1)
 
865
        if (selection.length > 1) {
879
866
            showPrint = false;
 
867
            showProperties = false;
 
868
        }
880
869
 
881
870
        let openLabel = null;
882
871
        if (apps.length == 1) {
888
877
        }
889
878
        this._toolbarOpen.set_tooltip_text(openLabel);
890
879
 
891
 
        if (showFavorite) {
892
 
            let isFavorite = (favCount == selection.length);
893
 
            let favoriteLabel = '';
894
 
 
895
 
            if (isFavorite) {
896
 
                favoriteLabel = _("Remove from favorites");
897
 
                this._toolbarFavorite.set_active(true);
898
 
                this._toolbarFavorite.get_style_context().add_class('documents-favorite');
899
 
            } else {
900
 
                favoriteLabel = _("Add to favorites");
901
 
                this._toolbarFavorite.set_active(false);
902
 
                this._toolbarFavorite.get_style_context().remove_class('documents-favorite');
903
 
            }
904
 
 
905
 
            this._toolbarFavorite.reset_style();
906
 
            this._toolbarFavorite.set_tooltip_text(favoriteLabel);
907
 
        }
908
 
 
909
880
        this._toolbarPrint.set_visible(showPrint);
 
881
        this._toolbarProperties.set_visible(showProperties);
910
882
        this._toolbarTrash.set_visible(showTrash);
911
883
        this._toolbarOpen.set_visible(showOpen);
912
 
        this._toolbarFavorite.set_visible(showFavorite);
913
884
 
914
885
        this._insideRefresh = false;
915
886
    },
941
912
            }));
942
913
    },
943
914
 
944
 
    _onToolbarFavorite: function(widget) {
945
 
        if (this._insideRefresh)
946
 
            return;
947
 
 
948
 
        let selection = Global.selectionController.getSelection();
949
 
 
950
 
        selection.forEach(Lang.bind(this,
951
 
            function(urn) {
952
 
                let doc = Global.documentManager.getItemById(urn);
953
 
                doc.setFavorite(!doc.favorite);
954
 
            }));
955
 
    },
956
 
 
957
915
    _onToolbarTrash: function(widget) {
958
916
        let selection = Global.selectionController.getSelection();
959
917
 
964
922
            }));
965
923
    },
966
924
 
 
925
    _onToolbarProperties: function(widget) {
 
926
        let selection = Global.selectionController.getSelection();
 
927
        let dialog = new Properties.PropertiesDialog(selection[0]);
 
928
        this._fadeOut();
 
929
 
 
930
        dialog.widget.connect('response', Lang.bind(this,
 
931
            function(widget, response) {
 
932
                dialog.widget.destroy();
 
933
                this._fadeIn();
 
934
            }));
 
935
    },
 
936
 
967
937
    _onToolbarPrint: function(widget) {
968
938
        let selection = Global.selectionController.getSelection();
969
939