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
1=== modified file 'plugins/outline/CtagsSymbolResolver.vala'
2--- plugins/outline/CtagsSymbolResolver.vala 2014-04-13 08:35:48 +0000
3+++ plugins/outline/CtagsSymbolResolver.vala 2014-04-25 14:53:01 +0000
4@@ -30,6 +30,8 @@
5 Granite.Widgets.SourceList store;
6 Granite.Widgets.SourceList.ExpandableItem root;
7
8+ public int n_symbols { get; protected set; }
9+
10 public CtagsSymbolOutline (Scratch.Services.Document _doc)
11 {
12 doc = _doc;
13@@ -37,6 +39,8 @@
14
15 root = new Granite.Widgets.SourceList.ExpandableItem (_("Symbols"));
16
17+ this.n_symbols = 0;
18+
19 store = new Granite.Widgets.SourceList ();
20 store.get_style_context ().add_class ("sidebar");
21 store.item_selected.connect ((selected) => {
22@@ -133,6 +137,7 @@
23 } else
24 parent_dependent.add (new CtagsSymbolIter (name, parent, line, icon));
25 }
26+ this.n_symbols++;
27
28 var found_something = true;
29 while (found_something && parent_dependent.size > 0) {
30@@ -173,6 +178,8 @@
31 void parse_fields (string fields, out int line, out string parent)
32 {
33 var index = -1;
34+ line = -1;
35+ parent = null;
36 if ((index = fields.index_of ("line:")) > -1) {
37 line = int.parse (fields.substring (index + 5, int.max (fields.index_of (" ", index + 6) - index, -1)));
38 }
39
40=== modified file 'plugins/outline/OutlinePlugin.vala'
41--- plugins/outline/OutlinePlugin.vala 2014-04-13 08:35:48 +0000
42+++ plugins/outline/OutlinePlugin.vala 2014-04-25 14:53:01 +0000
43@@ -25,6 +25,7 @@
44 {
45 public abstract Scratch.Services.Document doc { get; protected set; }
46 public abstract void parse_symbols ();
47+ public abstract int n_symbols { get; protected set; }
48 public abstract Granite.Widgets.SourceList get_source_list ();
49 public signal void closed ();
50 public signal void goto (Scratch.Services.Document doc, int line);
51@@ -37,6 +38,7 @@
52 Scratch.Services.Interface scratch_interface;
53 SymbolOutline? current_view = null;
54 Gtk.EventBox? container = null;
55+ Gtk.Notebook? notebook = null;
56
57 uint refresh_timeout = 0;
58
59@@ -60,11 +62,11 @@
60 void on_hook_context (Gtk.Notebook notebook) {
61 if (container != null)
62 return;
63-
64+ if (this.notebook == null)
65+ this.notebook = notebook;
66+
67 container = new Gtk.EventBox ();
68- container.visible = false;
69- notebook.append_page (container, new Gtk.Label (_("Symbols")));
70- container.show_all ();
71+ container.visible = false;
72 }
73
74 void on_hook_document (Scratch.Services.Document doc) {
75@@ -81,7 +83,7 @@
76 break;
77 }
78 }
79- if (view == null) {
80+ if (view == null && doc.file != null) {
81 if (doc.get_mime_type () == "text/x-vala") {
82 view = new ValaSymbolOutline (doc);
83 } else {
84@@ -98,14 +100,33 @@
85 container.add (view.get_source_list ());
86 container.show_all ();
87 current_view = view;
88+
89+ if (view.n_symbols > 1) {
90+ add_container ();
91+ }
92+ else if (doc.file == null || view.n_symbols <= 1) {
93+ remove_container ();
94+ }
95+ }
96+
97+ void add_container () {
98+ if(notebook.page_num (container) == -1) {
99+ notebook.append_page (container, new Gtk.Label (_("Symbols")));
100+ container.show_all ();
101+ }
102+ }
103+
104+ void remove_container () {
105+ if (notebook.page_num (container) != -1)
106+ notebook.remove (container);
107 }
108
109 void on_hook_split_view (Scratch.Widgets.SplitView view) {
110 view.welcome_shown.connect (() => {
111- container.visible = false;
112+ remove_container ();
113 });
114 view.welcome_hidden.connect (() => {
115- container.visible = true;
116+ add_container ();
117 });
118 }
119
120@@ -144,4 +165,4 @@
121 {
122 var objmodule = module as Peas.ObjectModule;
123 objmodule.register_extension_type (typeof (Peas.Activatable), typeof (Scratch.Plugins.OutlinePlugin));
124-}
125+}
126\ No newline at end of file
127
128=== modified file 'plugins/outline/ValaSymbolResolver.vala'
129--- plugins/outline/ValaSymbolResolver.vala 2014-04-23 11:16:47 +0000
130+++ plugins/outline/ValaSymbolResolver.vala 2014-04-25 14:53:01 +0000
131@@ -40,7 +40,9 @@
132 Vala.CodeContext context;
133 Vala.Parser parser;
134 SymbolResolver resolver;
135-
136+
137+ public int n_symbols { get; protected set; }
138+
139 SymbolIter cache;
140
141 Gee.List<Vala.Field> field_blacklist;
142@@ -70,6 +72,8 @@
143 field_blacklist.add (f);
144 });
145
146+ this.n_symbols = 0;
147+
148 init_context ();
149 }
150
151@@ -117,7 +121,7 @@
152 init_context ();
153
154 Thread<void*> thread = new Thread<void*>("parse-symbols", () => {
155- parse_symbols_async ();
156+ parse_symbols_async.begin ();
157 return null;
158 });
159
160@@ -126,8 +130,6 @@
161 root.clear ();
162 construct_tree (cache, root);
163
164- filter_generated_fields (root);
165-
166 store.root.expand_all ();
167 }
168
169@@ -135,11 +137,14 @@
170 Granite.Widgets.SourceList.ExpandableItem tree_parent)
171 {
172 foreach (var iter_child in iter_parent.children) {
173+ if (iter_child == null)
174+ continue;
175 var tree_child = new Symbol (doc, iter_child.symbol);
176 tree_child.icon = iter_child.icon;
177 tree_parent.add (tree_child);
178
179 construct_tree (iter_child, tree_child);
180+ this.n_symbols++;
181 }
182 }
183
184@@ -159,20 +164,6 @@
185 return match;
186 }
187
188- // vala generates for each property a field which we do not want to display
189- void filter_generated_fields (Granite.Widgets.SourceList.ExpandableItem parent)
190- {
191- var children = parent.children.to_array ();
192- foreach (var child in children) {
193- var child_symbol = child as Symbol;
194- if (field_blacklist.contains (child_symbol.symbol as Vala.Field)) {
195- parent.remove (child);
196- } else {
197- filter_generated_fields (child_symbol);
198- }
199- }
200- }
201-
202 void add_symbol (Vala.Symbol symbol, string icon = "", Icon? real_icon = null)
203 {
204 if (symbol.name == null)

Subscribers

People subscribed via source and target branches