Merge lp:~mefrio-g/scratch/fix-1258260 into lp:~elementary-apps/scratch/scratch

Proposed by Mario Guerriero
Status: Merged
Approved by: Niclas Lockner
Approved revision: 1281
Merged at revision: 1292
Proposed branch: lp:~mefrio-g/scratch/fix-1258260
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 204 lines (+45/-26)
3 files modified
plugins/outline/CtagsSymbolResolver.vala (+7/-0)
plugins/outline/OutlinePlugin.vala (+29/-8)
plugins/outline/ValaSymbolResolver.vala (+9/-18)
To merge this branch: bzr merge lp:~mefrio-g/scratch/fix-1258260
Reviewer Review Type Date Requested Status
Niclas Lockner (community) Approve
Review via email: mp+215567@code.launchpad.net

Commit message

Don't show outline pane if there is nothing to outline. Fixes bug #1258260

To post a comment you must log in.
Revision history for this message
Niclas Lockner (niclasl) wrote :

The filter_generated_fields method in ValaSymbolResolver in unused now that the call at diff line 118 is removed. Should n't it be removed as well?

I noticed three situations where it doesn't work as expected:

When I start Scratch, the empty outline pane is shown alongside the welcome screen.

If the outline pane is shown when the last tab is closed (e.g. one single vala file opened and then closed), the outline pane is still shown alongside the welcome screen. If I instead let the last closed tab be a non-vala file, it works as expected.

If I open some new tabs with new or existing non-vala documents and then switch between them, the outline pane appears. It hides itself when I open yet another tab.

review: Needs Fixing
Revision history for this message
Niclas Lockner (niclasl) wrote :

And when I say that the pane is shown alongside the welcome screen, I mean that the buttons on the welcome screen are no longer centered and there's a large empty space to the right where the pane will be once a vala file is opened.

lp:~mefrio-g/scratch/fix-1258260 updated
1278. By Mario Guerriero

fixed welcome screen and unsaved documents problems

Revision history for this message
Mario Guerriero (mefrio-g) wrote :

It should work as expected now. I also fixed some compilation warnings.

Revision history for this message
Niclas Lockner (niclasl) wrote :

It still doesn't work that well for me:

Open scratch (No tabs are open and the welcome screen is shown)

Open a Vala file
=> Outline pane has two Symbols tabs (the inactive tab isn't clickable)

Open a second Vala file
Switch between the tabs
=> The output pane no longer shows any content
=> For each switch, a new Symbols tab is added to the Outline pane

Close both tabs
=> failed assertion and SIGABRT when the last tab is closed

If I instead open Scratch, create a new document and then open a Vala document, it seems to work.
I can switch between the two tabs and the outline pane is shown or hidden accordingly. The outline pane also has the right content.

review: Needs Fixing
lp:~mefrio-g/scratch/fix-1258260 updated
1279. By Mario Guerriero

do not add several useless symbols view to the left pane

Revision history for this message
Mario Guerriero (mefrio-g) wrote :

Everything should work as expected now. Thanks for your patience.

Revision history for this message
Niclas Lockner (niclasl) wrote :

Now it works much better, but there's still one bug:

If I open a vala file and a regular file (not a new document but an existing one) and then switch tab from the vala file to the non-vala file, the outline pane becomes empty but doesn't hide as it should.

If I instead open a vala file and a new empty document, it works as long as the new document isn't saved. Once saved, Scratch behaves as above.

Also, there's a conflict with trunk's ValaSymbolResolver.vala

review: Needs Fixing
Revision history for this message
Niclas Lockner (niclasl) wrote :

And if the code style is to be strictly followed:

Newline before diff line 26
Remove spaces on diff lines 66, 97, 104, 137, 139
Add space after if on diff line 99
Make a cuddled else if on diff lines 92-93

lp:~mefrio-g/scratch/fix-1258260 updated
1280. By Mario Guerriero

fixed switch between vala and non-vala files

Revision history for this message
Mario Guerriero (mefrio-g) wrote :

It now works fine. I see the conflict project but to be honest I don't know how to fix it. Could you help me?

Revision history for this message
Niclas Lockner (niclasl) wrote :

Yes, now it works as expected :) Just the code style issues and the conflict left then.

To resolve the conflict, first merge with trunk:
bzr merge lp:scratch

which should give you:
Text conflict in plugins/outline/ValaSymbolResolver.vala
1 conflicts encountered.

After that, open plugins/outline/ValaSymbolResolver.vala and edit it so that it looks good (i.e. remove line 167-183 in this case)

After that, mark all conflicts as resolved:
bzr resolve

and commit the changes:
bzr commit -m "Merge changes from lp:scratch"

lp:~mefrio-g/scratch/fix-1258260 updated
1281. By Mario Guerriero

Merge changes from lp:scratch

Revision history for this message
Mario Guerriero (mefrio-g) wrote :

It should be everything fine now. Thanks.

Revision history for this message
Niclas Lockner (niclasl) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/outline/CtagsSymbolResolver.vala'
--- plugins/outline/CtagsSymbolResolver.vala 2014-04-13 08:35:48 +0000
+++ plugins/outline/CtagsSymbolResolver.vala 2014-04-25 14:53:01 +0000
@@ -30,6 +30,8 @@
30 Granite.Widgets.SourceList store;30 Granite.Widgets.SourceList store;
31 Granite.Widgets.SourceList.ExpandableItem root;31 Granite.Widgets.SourceList.ExpandableItem root;
3232
33 public int n_symbols { get; protected set; }
34
33 public CtagsSymbolOutline (Scratch.Services.Document _doc)35 public CtagsSymbolOutline (Scratch.Services.Document _doc)
34 {36 {
35 doc = _doc;37 doc = _doc;
@@ -37,6 +39,8 @@
3739
38 root = new Granite.Widgets.SourceList.ExpandableItem (_("Symbols"));40 root = new Granite.Widgets.SourceList.ExpandableItem (_("Symbols"));
3941
42 this.n_symbols = 0;
43
40 store = new Granite.Widgets.SourceList ();44 store = new Granite.Widgets.SourceList ();
41 store.get_style_context ().add_class ("sidebar");45 store.get_style_context ().add_class ("sidebar");
42 store.item_selected.connect ((selected) => {46 store.item_selected.connect ((selected) => {
@@ -133,6 +137,7 @@
133 } else137 } else
134 parent_dependent.add (new CtagsSymbolIter (name, parent, line, icon));138 parent_dependent.add (new CtagsSymbolIter (name, parent, line, icon));
135 }139 }
140 this.n_symbols++;
136141
137 var found_something = true;142 var found_something = true;
138 while (found_something && parent_dependent.size > 0) {143 while (found_something && parent_dependent.size > 0) {
@@ -173,6 +178,8 @@
173 void parse_fields (string fields, out int line, out string parent)178 void parse_fields (string fields, out int line, out string parent)
174 {179 {
175 var index = -1;180 var index = -1;
181 line = -1;
182 parent = null;
176 if ((index = fields.index_of ("line:")) > -1) {183 if ((index = fields.index_of ("line:")) > -1) {
177 line = int.parse (fields.substring (index + 5, int.max (fields.index_of (" ", index + 6) - index, -1)));184 line = int.parse (fields.substring (index + 5, int.max (fields.index_of (" ", index + 6) - index, -1)));
178 }185 }
179186
=== modified file 'plugins/outline/OutlinePlugin.vala'
--- plugins/outline/OutlinePlugin.vala 2014-04-13 08:35:48 +0000
+++ plugins/outline/OutlinePlugin.vala 2014-04-25 14:53:01 +0000
@@ -25,6 +25,7 @@
25{25{
26 public abstract Scratch.Services.Document doc { get; protected set; }26 public abstract Scratch.Services.Document doc { get; protected set; }
27 public abstract void parse_symbols ();27 public abstract void parse_symbols ();
28 public abstract int n_symbols { get; protected set; }
28 public abstract Granite.Widgets.SourceList get_source_list ();29 public abstract Granite.Widgets.SourceList get_source_list ();
29 public signal void closed ();30 public signal void closed ();
30 public signal void goto (Scratch.Services.Document doc, int line);31 public signal void goto (Scratch.Services.Document doc, int line);
@@ -37,6 +38,7 @@
37 Scratch.Services.Interface scratch_interface;38 Scratch.Services.Interface scratch_interface;
38 SymbolOutline? current_view = null;39 SymbolOutline? current_view = null;
39 Gtk.EventBox? container = null;40 Gtk.EventBox? container = null;
41 Gtk.Notebook? notebook = null;
4042
41 uint refresh_timeout = 0;43 uint refresh_timeout = 0;
4244
@@ -60,11 +62,11 @@
60 void on_hook_context (Gtk.Notebook notebook) {62 void on_hook_context (Gtk.Notebook notebook) {
61 if (container != null)63 if (container != null)
62 return;64 return;
63 65 if (this.notebook == null)
66 this.notebook = notebook;
67
64 container = new Gtk.EventBox ();68 container = new Gtk.EventBox ();
65 container.visible = false; 69 container.visible = false;
66 notebook.append_page (container, new Gtk.Label (_("Symbols")));
67 container.show_all ();
68 }70 }
6971
70 void on_hook_document (Scratch.Services.Document doc) {72 void on_hook_document (Scratch.Services.Document doc) {
@@ -81,7 +83,7 @@
81 break;83 break;
82 }84 }
83 }85 }
84 if (view == null) {86 if (view == null && doc.file != null) {
85 if (doc.get_mime_type () == "text/x-vala") {87 if (doc.get_mime_type () == "text/x-vala") {
86 view = new ValaSymbolOutline (doc);88 view = new ValaSymbolOutline (doc);
87 } else {89 } else {
@@ -98,14 +100,33 @@
98 container.add (view.get_source_list ());100 container.add (view.get_source_list ());
99 container.show_all ();101 container.show_all ();
100 current_view = view;102 current_view = view;
103
104 if (view.n_symbols > 1) {
105 add_container ();
106 }
107 else if (doc.file == null || view.n_symbols <= 1) {
108 remove_container ();
109 }
110 }
111
112 void add_container () {
113 if(notebook.page_num (container) == -1) {
114 notebook.append_page (container, new Gtk.Label (_("Symbols")));
115 container.show_all ();
116 }
117 }
118
119 void remove_container () {
120 if (notebook.page_num (container) != -1)
121 notebook.remove (container);
101 }122 }
102 123
103 void on_hook_split_view (Scratch.Widgets.SplitView view) {124 void on_hook_split_view (Scratch.Widgets.SplitView view) {
104 view.welcome_shown.connect (() => {125 view.welcome_shown.connect (() => {
105 container.visible = false;126 remove_container ();
106 });127 });
107 view.welcome_hidden.connect (() => {128 view.welcome_hidden.connect (() => {
108 container.visible = true;129 add_container ();
109 });130 });
110 }131 }
111 132
@@ -144,4 +165,4 @@
144{165{
145 var objmodule = module as Peas.ObjectModule;166 var objmodule = module as Peas.ObjectModule;
146 objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.OutlinePlugin));167 objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.OutlinePlugin));
147}168}
148\ No newline at end of file169\ No newline at end of file
149170
=== modified file 'plugins/outline/ValaSymbolResolver.vala'
--- plugins/outline/ValaSymbolResolver.vala 2014-04-23 11:16:47 +0000
+++ plugins/outline/ValaSymbolResolver.vala 2014-04-25 14:53:01 +0000
@@ -40,7 +40,9 @@
40 Vala.CodeContext context;40 Vala.CodeContext context;
41 Vala.Parser parser;41 Vala.Parser parser;
42 SymbolResolver resolver;42 SymbolResolver resolver;
4343
44 public int n_symbols { get; protected set; }
45
44 SymbolIter cache;46 SymbolIter cache;
4547
46 Gee.List<Vala.Field> field_blacklist;48 Gee.List<Vala.Field> field_blacklist;
@@ -70,6 +72,8 @@
70 field_blacklist.add (f);72 field_blacklist.add (f);
71 });73 });
7274
75 this.n_symbols = 0;
76
73 init_context ();77 init_context ();
74 }78 }
7579
@@ -117,7 +121,7 @@
117 init_context ();121 init_context ();
118 122
119 Thread<void*> thread = new Thread<void*>("parse-symbols", () => {123 Thread<void*> thread = new Thread<void*>("parse-symbols", () => {
120 parse_symbols_async ();124 parse_symbols_async.begin ();
121 return null;125 return null;
122 });126 });
123127
@@ -126,8 +130,6 @@
126 root.clear ();130 root.clear ();
127 construct_tree (cache, root);131 construct_tree (cache, root);
128132
129 filter_generated_fields (root);
130
131 store.root.expand_all ();133 store.root.expand_all ();
132 }134 }
133135
@@ -135,11 +137,14 @@
135 Granite.Widgets.SourceList.ExpandableItem tree_parent)137 Granite.Widgets.SourceList.ExpandableItem tree_parent)
136 {138 {
137 foreach (var iter_child in iter_parent.children) {139 foreach (var iter_child in iter_parent.children) {
140 if (iter_child == null)
141 continue;
138 var tree_child = new Symbol (doc, iter_child.symbol);142 var tree_child = new Symbol (doc, iter_child.symbol);
139 tree_child.icon = iter_child.icon;143 tree_child.icon = iter_child.icon;
140 tree_parent.add (tree_child);144 tree_parent.add (tree_child);
141145
142 construct_tree (iter_child, tree_child);146 construct_tree (iter_child, tree_child);
147 this.n_symbols++;
143 }148 }
144 }149 }
145150
@@ -159,20 +164,6 @@
159 return match;164 return match;
160 }165 }
161166
162 // vala generates for each property a field which we do not want to display
163 void filter_generated_fields (Granite.Widgets.SourceList.ExpandableItem parent)
164 {
165 var children = parent.children.to_array ();
166 foreach (var child in children) {
167 var child_symbol = child as Symbol;
168 if (field_blacklist.contains (child_symbol.symbol as Vala.Field)) {
169 parent.remove (child);
170 } else {
171 filter_generated_fields (child_symbol);
172 }
173 }
174 }
175
176 void add_symbol (Vala.Symbol symbol, string icon = "", Icon? real_icon = null)167 void add_symbol (Vala.Symbol symbol, string icon = "", Icon? real_icon = null)
177 {168 {
178 if (symbol.name == null)169 if (symbol.name == null)

Subscribers

People subscribed via source and target branches