~artem-anufrij/scratch/improve-split-view

« back to all changes in this revision

Viewing changes to plugins/browser-preview/browser-preview.vala

  • Committer: artem-anufrij
  • Date: 2014-12-07 16:37:18 UTC
  • mfrom: (1421.2.5 scratch)
  • Revision ID: artem-anufrij-20141207163718-iiky9875sfdiyph3
dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
    public class BrowserPreviewPlugin : Peas.ExtensionBase,  Peas.Activatable {
27
27
 
28
 
        Gtk.ToolButton? tool_button = null;
 
28
        Gtk.ToggleToolButton? tool_button = null;
29
29
        GLib.HashTable<Scratch.Services.Document, BrowserPreview.BrowserView> previews = new  GLib.HashTable<Scratch.Services.Document, BrowserPreview.BrowserView> (null, null);
30
30
 
31
31
        BrowserPreview.BrowserView? view = null;
80
80
                return;
81
81
 
82
82
            var icon = new Gtk.Image.from_icon_name ("emblem-web", Gtk.IconSize.LARGE_TOOLBAR);
83
 
            tool_button = new Gtk.ToolButton (icon, _("Get preview!"));
84
 
            tool_button.tooltip_text = _("Hide preview");
85
 
            tool_button.clicked.connect (toggle_plugin_visibility);
86
 
 
87
 
            icon.show ();
88
 
            tool_button.show ();
89
 
 
90
 
            toolbar.pack_start (tool_button);
 
83
            tool_button = new Gtk.ToggleToolButton ();
 
84
            tool_button.set_icon_widget (icon);
 
85
            tool_button.tooltip_text = _("Hide Preview");
 
86
            tool_button.toggled.connect (toggle_plugin_visibility);
 
87
 
 
88
            tool_button.show_all ();
 
89
 
 
90
            toolbar.pack_end (tool_button);
91
91
        }
92
92
 
93
93
        void on_hook_context (Gtk.Notebook notebook) {
100
100
        }
101
101
 
102
102
        void toggle_plugin_visibility () {
103
 
            if (notebook.page_num (view.paned) == -1) {
104
 
                notebook.append_page (view.paned, new Gtk.Label (_("Web preview")));
105
 
                tool_button.tooltip_text = _("Hide preview");
 
103
            if (tool_button.active) {
 
104
                notebook.set_current_page (notebook.append_page (view.paned, new Gtk.Label (_("Web Preview"))));
 
105
                tool_button.tooltip_text = _("Hide Preview");
106
106
            } else {
107
107
                notebook.remove (view.paned);
108
 
                tool_button.tooltip_text = _("Show preview");
 
108
                tool_button.tooltip_text = _("Show Preview");
109
109
            }
110
110
        }
111
111
 
139
139
                notebook.remove (view.paned);
140
140
            }
141
141
 
142
 
            view = previews.get (this.doc);          
 
142
            view = previews.get (this.doc);
143
143
            view.paned.show_all ();
144
144
 
145
145
            // Check if removed tab was visible
146
 
            if (tab_page_number > -1) {
147
 
                notebook.insert_page (view.paned, new Gtk.Label (_("Web preview")), tab_page_number);
 
146
            if (tool_button.active) {
 
147
                notebook.insert_page (view.paned, new Gtk.Label (_("Web Preview")), tab_page_number);
148
148
 
149
149
                // Select new tab if the removed tab was selected
150
150
                if (tab_is_selected)
153
153
 
154
154
            if (view.uri == null || view.uri == "" || view.uri != this.doc.file.get_uri ())
155
155
                view.load_uri (this.doc.file.get_uri ());
156
 
            else 
 
156
            else
157
157
                view.reload ();
158
158
        }
159
159
    }