~artem-anufrij/scratch/Bugfix-1399017-PlugIn-Switcher

« back to all changes in this revision

Viewing changes to plugins/outline/OutlinePlugin.vala

  • Committer: artem-anufrij
  • Date: 2014-12-12 20:20:46 UTC
  • Revision ID: artem-anufrij-20141212202046-mcjme5geqra71v5a
OUTLINE: moved plugin from the right side to the left side

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    public class OutlinePlugin : Peas.ExtensionBase, Peas.Activatable {
36
36
        public Object object { owned get; construct; }
37
37
 
38
 
        Gtk.ToggleToolButton? tool_button = null;
 
38
        //Gtk.ToggleToolButton? tool_button = null;
39
39
        Scratch.Services.Interface scratch_interface;
40
40
        SymbolOutline? current_view = null;
41
41
        Gtk.EventBox? container = null;
50
50
 
51
51
            scratch_interface.hook_document.connect (on_hook_document);
52
52
 
53
 
            scratch_interface.hook_split_view.connect (on_hook_split_view);
54
 
 
55
 
            scratch_interface.hook_notebook_context.connect (on_hook_context);
56
 
 
57
 
            scratch_interface.hook_toolbar.connect (on_hook_toolbar);
 
53
            scratch_interface.hook_notebook_sidebar.connect (on_hook_sidebar);
58
54
 
59
55
            views = new Gee.LinkedList<SymbolOutline> ();
60
56
        }
61
57
 
62
58
        public void deactivate () {
63
 
            if (tool_button != null)
64
 
                tool_button.destroy ();
65
 
 
66
59
            container.destroy ();
67
60
        }
68
61
 
69
62
        public void update_state () {
70
63
        }
71
64
 
72
 
        void on_hook_toolbar (Scratch.Widgets.Toolbar toolbar) {
73
 
            if (tool_button != null)
74
 
                return;
75
 
 
76
 
            var icon = new Gtk.Image.from_icon_name ("error", Gtk.IconSize.LARGE_TOOLBAR);
77
 
            tool_button = new Gtk.ToggleToolButton ();
78
 
            tool_button.set_icon_widget (icon);
79
 
            tool_button.tooltip_text = _("Show Ouline");
80
 
            tool_button.toggled.connect (toggle_plugin_visibility);
81
 
 
82
 
            tool_button.show_all ();
83
 
 
84
 
            toolbar.pack_end (tool_button);
85
 
        }
86
 
 
87
 
        void toggle_plugin_visibility () {
88
 
            if (tool_button.active) {
89
 
                notebook.set_current_page (notebook.append_page (container, new Gtk.Label (_("Symbols"))));
90
 
                tool_button.tooltip_text = _("Hide Outline");
91
 
            } else {
92
 
                notebook.remove (container);
93
 
                tool_button.tooltip_text = _("Show Outline");
94
 
            }
95
 
        }
96
 
 
97
 
        void on_hook_context (Gtk.Notebook notebook) {
 
65
        void on_hook_sidebar (Gtk.Notebook notebook) {
98
66
            if (container != null)
99
67
                return;
100
68
            if (this.notebook == null)
101
69
                this.notebook = notebook;
102
70
 
103
 
            this.notebook.switch_page.connect ((page, page_num) => {
104
 
                if(tool_button.active != (container == page))
105
 
                    tool_button.active = (container == page);
106
 
            });
107
 
 
108
71
            container = new Gtk.EventBox ();
109
72
            container.visible = false;
110
 
            if (this.notebook == null)
 
73
            if (this.notebook != null)
111
74
                notebook.append_page (container, new Gtk.Label (_("Symbols")));
112
75
        }
113
76
 
125
88
                    break;
126
89
                }
127
90
            }
 
91
 
128
92
            if (view == null && doc.file != null) {
129
93
                if (doc.get_mime_type () == "text/x-vala") {
130
94
                    view = new ValaSymbolOutline (doc);
163
127
                notebook.remove (container);
164
128
        }
165
129
 
166
 
        void on_hook_split_view (Scratch.Widgets.SplitView view) {
167
 
            this.tool_button.visible = ! view.is_empty ();
168
 
            view.welcome_shown.connect (() => {
169
 
                this.tool_button.visible = false;
170
 
            });
171
 
            view.welcome_hidden.connect (() => {
172
 
                this.tool_button.visible = true;
173
 
            });
174
 
        }
175
 
 
176
130
        void update_timeout () {
177
131
            if (refresh_timeout != 0)
178
132
                Source.remove (refresh_timeout);
206
160
[ModuleInit]
207
161
public void peas_register_types (GLib.TypeModule module)
208
162
{
209
 
  var objmodule = module as Peas.ObjectModule;
210
 
  objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.OutlinePlugin));
 
163
    var objmodule = module as Peas.ObjectModule;
 
164
    objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.OutlinePlugin));
211
165
}