Merge lp:~philip.scott/scratch/restore-docs-per-tab into lp:~elementary-apps/scratch/scratch
- restore-docs-per-tab
- Merge into scratch
Proposed by
Felipe Escoto
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Approved by: | Danielle Foré | ||||||||
Approved revision: | 1788 | ||||||||
Merged at revision: | 1789 | ||||||||
Proposed branch: | lp:~philip.scott/scratch/restore-docs-per-tab | ||||||||
Merge into: | lp:~elementary-apps/scratch/scratch | ||||||||
Diff against target: |
424 lines (+169/-84) 6 files modified
schemas/org.pantheon.scratch.gschema.xml (+14/-4) src/MainWindow.vala (+82/-41) src/Scratch.vala (+1/-35) src/Services/Settings.vala (+4/-2) src/Widgets/DocumentView.vala (+52/-1) src/Widgets/SplitView.vala (+16/-1) |
||||||||
To merge this branch: | bzr merge lp:~philip.scott/scratch/restore-docs-per-tab | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Danielle Foré | Approve | ||
Review via email: mp+313086@code.launchpad.net |
Commit message
- Save and restore opened documents per view
- Prevent New Docs from not saving
Description of the change
The settings schema for the opened docs is now split into two, one per view. This is updated when you open, close or move a tab, so it's always up to date
To post a comment you must log in.
- 1788. By Felipe Escoto
-
Save documents per view
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'schemas/org.pantheon.scratch.gschema.xml' | |||
2 | --- schemas/org.pantheon.scratch.gschema.xml 2016-04-13 05:03:04 +0000 | |||
3 | +++ schemas/org.pantheon.scratch.gschema.xml 2016-12-13 02:07:05 +0000 | |||
4 | @@ -59,9 +59,14 @@ | |||
5 | 59 | <summary>Show the welcome screen or the last opened files at Scratch launch</summary> | 59 | <summary>Show the welcome screen or the last opened files at Scratch launch</summary> |
6 | 60 | <description>Show the welcome screen or the last opened files at Scratch launch.</description> | 60 | <description>Show the welcome screen or the last opened files at Scratch launch.</description> |
7 | 61 | </key> | 61 | </key> |
11 | 62 | <key type="as" name="opened-files"> | 62 | <key name="opened-files-view1" type="as"> |
12 | 63 | <default>['']</default> | 63 | <default>[]</default> |
13 | 64 | <summary>Files opened in the previously session of Scratch</summary> | 64 | <summary>Files opened in the previously session of Scratch on the first view</summary> |
14 | 65 | <description>It is used to open the files opened in the last Scratch session</description> | ||
15 | 66 | </key> | ||
16 | 67 | <key name="opened-files-view2" type="as"> | ||
17 | 68 | <default>[]</default> | ||
18 | 69 | <summary>Files opened in the previously session of Scratch on the second view</summary> | ||
19 | 65 | <description>It is used to open the files opened in the last Scratch session</description> | 70 | <description>It is used to open the files opened in the last Scratch session</description> |
20 | 66 | </key> | 71 | </key> |
21 | 67 | <key name="autosave" type="b"> | 72 | <key name="autosave" type="b"> |
22 | @@ -139,7 +144,12 @@ | |||
23 | 139 | <summary>Preferred Style Scheme</summary> | 144 | <summary>Preferred Style Scheme</summary> |
24 | 140 | <description>Set the preferred style scheme.</description> | 145 | <description>Set the preferred style scheme.</description> |
25 | 141 | </key> | 146 | </key> |
27 | 142 | <key name="focused-document" type="s"> | 147 | <key name="focused-document-view1" type="s"> |
28 | 148 | <default>''</default> | ||
29 | 149 | <summary>Remember the last focused document.</summary> | ||
30 | 150 | <description>Restore the focused document from a previous session when opening Scratch.</description> | ||
31 | 151 | </key> | ||
32 | 152 | <key name="focused-document-view2" type="s"> | ||
33 | 143 | <default>''</default> | 153 | <default>''</default> |
34 | 144 | <summary>Remember the last focused document.</summary> | 154 | <summary>Remember the last focused document.</summary> |
35 | 145 | <description>Restore the focused document from a previous session when opening Scratch.</description> | 155 | <description>Restore the focused document from a previous session when opening Scratch.</description> |
36 | 146 | 156 | ||
37 | === modified file 'src/MainWindow.vala' | |||
38 | --- src/MainWindow.vala 2016-08-27 15:11:14 +0000 | |||
39 | +++ src/MainWindow.vala 2016-12-13 02:07:05 +0000 | |||
40 | @@ -294,6 +294,74 @@ | |||
41 | 294 | set_widgets_sensitive (!split_view.is_empty ()); | 294 | set_widgets_sensitive (!split_view.is_empty ()); |
42 | 295 | } | 295 | } |
43 | 296 | 296 | ||
44 | 297 | public void restore_opened_documents () { | ||
45 | 298 | if (settings.show_at_start == "last-tabs") { | ||
46 | 299 | start_loading (); | ||
47 | 300 | |||
48 | 301 | string[] uris_view1 = settings.opened_files_view1; | ||
49 | 302 | string[] uris_view2 = settings.opened_files_view2; | ||
50 | 303 | string focused_document1 = settings.focused_document_view1; | ||
51 | 304 | string focused_document2 = settings.focused_document_view2; | ||
52 | 305 | |||
53 | 306 | if (uris_view1.length > 0) { | ||
54 | 307 | var view = add_view (); | ||
55 | 308 | load_files_for_view (view, uris_view1); | ||
56 | 309 | set_focused_document (view, focused_document1); | ||
57 | 310 | |||
58 | 311 | if (view.is_empty ()) { | ||
59 | 312 | split_view.remove_view (view); | ||
60 | 313 | } | ||
61 | 314 | } | ||
62 | 315 | |||
63 | 316 | if (uris_view2.length > 0) { | ||
64 | 317 | var view = add_view (); | ||
65 | 318 | load_files_for_view (view, uris_view2); | ||
66 | 319 | set_focused_document (view, focused_document2); | ||
67 | 320 | |||
68 | 321 | if (view.is_empty ()) { | ||
69 | 322 | split_view.remove_view (view); | ||
70 | 323 | } | ||
71 | 324 | } | ||
72 | 325 | |||
73 | 326 | stop_loading (); | ||
74 | 327 | } | ||
75 | 328 | } | ||
76 | 329 | |||
77 | 330 | private void load_files_for_view (Scratch.Widgets.DocumentView view, string[] uris) { | ||
78 | 331 | foreach (string uri in uris) { | ||
79 | 332 | if (uri != "") { | ||
80 | 333 | var file = File.new_for_uri (uri); | ||
81 | 334 | if (file.query_exists ()) { | ||
82 | 335 | var doc = new Scratch.Services.Document (main_actions, file); | ||
83 | 336 | |||
84 | 337 | if (!doc.is_file_temporary || doc.exists ()) { | ||
85 | 338 | open_document (doc, view); | ||
86 | 339 | } | ||
87 | 340 | } | ||
88 | 341 | } | ||
89 | 342 | } | ||
90 | 343 | } | ||
91 | 344 | |||
92 | 345 | // Set focus to last focused document, after all documents finished loading | ||
93 | 346 | private void set_focused_document (Scratch.Widgets.DocumentView view, string focused_document) { | ||
94 | 347 | if (focused_document != "") { | ||
95 | 348 | Scratch.Services.Document document_to_focus = null; | ||
96 | 349 | |||
97 | 350 | foreach (Scratch.Services.Document doc in view.docs) { | ||
98 | 351 | if (doc.file != null) { | ||
99 | 352 | if (doc.file.get_uri() == focused_document) { | ||
100 | 353 | document_to_focus = doc; | ||
101 | 354 | break; | ||
102 | 355 | } | ||
103 | 356 | } | ||
104 | 357 | } | ||
105 | 358 | |||
106 | 359 | if (document_to_focus != null) { | ||
107 | 360 | view.notebook.current = document_to_focus; | ||
108 | 361 | } | ||
109 | 362 | } | ||
110 | 363 | } | ||
111 | 364 | |||
112 | 297 | private bool on_key_pressed (Gdk.EventKey event) { | 365 | private bool on_key_pressed (Gdk.EventKey event) { |
113 | 298 | switch (Gdk.keyval_name (event.keyval)) { | 366 | switch (Gdk.keyval_name (event.keyval)) { |
114 | 299 | case "Escape": | 367 | case "Escape": |
115 | @@ -392,17 +460,25 @@ | |||
116 | 392 | } | 460 | } |
117 | 393 | 461 | ||
118 | 394 | // Open a document | 462 | // Open a document |
120 | 395 | public void open_document (Scratch.Services.Document doc) { | 463 | public void open_document (Scratch.Services.Document doc, Scratch.Widgets.DocumentView? view_ = null) { |
121 | 396 | while (Gtk.events_pending ()) { | 464 | while (Gtk.events_pending ()) { |
122 | 397 | Gtk.main_iteration (); | 465 | Gtk.main_iteration (); |
123 | 398 | } | 466 | } |
124 | 399 | 467 | ||
126 | 400 | Scratch.Widgets.DocumentView? view = null; | 468 | Scratch.Widgets.DocumentView view = null; |
127 | 469 | |||
128 | 470 | if (view_ != null) { | ||
129 | 471 | view = view_; | ||
130 | 472 | } | ||
131 | 473 | |||
132 | 401 | if (this.split_view.is_empty ()) { | 474 | if (this.split_view.is_empty ()) { |
133 | 402 | view = split_view.add_view (); | 475 | view = split_view.add_view (); |
134 | 403 | view.open_document (doc); | 476 | view.open_document (doc); |
135 | 404 | } else { | 477 | } else { |
137 | 405 | view = split_view.get_focus_child () as Scratch.Widgets.DocumentView; | 478 | if (view == null) { |
138 | 479 | view = split_view.get_focus_child () as Scratch.Widgets.DocumentView; | ||
139 | 480 | } | ||
140 | 481 | |||
141 | 406 | if (view == null) { | 482 | if (view == null) { |
142 | 407 | view = this.split_view.current_view; | 483 | view = this.split_view.current_view; |
143 | 408 | } | 484 | } |
144 | @@ -452,6 +528,7 @@ | |||
145 | 452 | if (!is_empty ()) { | 528 | if (!is_empty ()) { |
146 | 453 | foreach (var w in this.split_view.views) { | 529 | foreach (var w in this.split_view.views) { |
147 | 454 | var view = w as Scratch.Widgets.DocumentView; | 530 | var view = w as Scratch.Widgets.DocumentView; |
148 | 531 | view.is_closing = true; | ||
149 | 455 | foreach (var doc in view.docs) { | 532 | foreach (var doc in view.docs) { |
150 | 456 | if (!doc.close (true)) { | 533 | if (!doc.close (true)) { |
151 | 457 | view.set_current_document (doc); | 534 | view.set_current_document (doc); |
152 | @@ -530,41 +607,6 @@ | |||
153 | 530 | Scratch.saved_state.vp_size = vp.get_position (); | 607 | Scratch.saved_state.vp_size = vp.get_position (); |
154 | 531 | } | 608 | } |
155 | 532 | 609 | ||
156 | 533 | // Update files-opened settings key | ||
157 | 534 | private void update_opened_files () { | ||
158 | 535 | // File list | ||
159 | 536 | string[] opened_files = {}; | ||
160 | 537 | this.split_view.views.foreach ((view) => { | ||
161 | 538 | view.notebook.tabs.foreach ((tab) => { | ||
162 | 539 | var doc = tab as Scratch.Services.Document; | ||
163 | 540 | if (doc.file != null && doc.exists ()) { | ||
164 | 541 | opened_files += doc.file.get_uri (); | ||
165 | 542 | } | ||
166 | 543 | }); | ||
167 | 544 | }); | ||
168 | 545 | |||
169 | 546 | |||
170 | 547 | // Update the opened-files setting | ||
171 | 548 | if (settings.show_at_start == "last-tabs") { | ||
172 | 549 | settings.opened_files = opened_files; | ||
173 | 550 | |||
174 | 551 | // Update the focused-document setting | ||
175 | 552 | string file_uri = ""; | ||
176 | 553 | if (this.split_view.current_view != null) { | ||
177 | 554 | var current_document = this.split_view.current_view.get_current_document(); | ||
178 | 555 | if (current_document != null) { | ||
179 | 556 | file_uri = current_document.file.get_uri(); | ||
180 | 557 | } | ||
181 | 558 | } | ||
182 | 559 | |||
183 | 560 | if (file_uri != "") { | ||
184 | 561 | settings.focused_document = file_uri; | ||
185 | 562 | } else { | ||
186 | 563 | settings.schema.reset ("focused-document"); | ||
187 | 564 | } | ||
188 | 565 | } | ||
189 | 566 | } | ||
190 | 567 | |||
191 | 568 | // SIGTERM/SIGINT Handling | 610 | // SIGTERM/SIGINT Handling |
192 | 569 | public bool quit_source_func () { | 611 | public bool quit_source_func () { |
193 | 570 | action_quit (); | 612 | action_quit (); |
194 | @@ -574,7 +616,6 @@ | |||
195 | 574 | // For exit cleanup | 616 | // For exit cleanup |
196 | 575 | private void handle_quit () { | 617 | private void handle_quit () { |
197 | 576 | update_saved_state (); | 618 | update_saved_state (); |
198 | 577 | update_opened_files (); | ||
199 | 578 | } | 619 | } |
200 | 579 | 620 | ||
201 | 580 | public void set_default_zoom () { | 621 | public void set_default_zoom () { |
202 | @@ -762,9 +803,9 @@ | |||
203 | 762 | if (fetch_action.sensitive) { | 803 | if (fetch_action.sensitive) { |
204 | 763 | /* Toggling the fetch action causes this function to be called again but the search_revealer child | 804 | /* Toggling the fetch action causes this function to be called again but the search_revealer child |
205 | 764 | * is still not revealed so nothing more happens. We use the map signal on the search entry | 805 | * is still not revealed so nothing more happens. We use the map signal on the search entry |
207 | 765 | * to set it up once it has been revealed. */ | 806 | * to set it up once it has been revealed. */ |
208 | 766 | fetch_action.active = true; | 807 | fetch_action.active = true; |
210 | 767 | } | 808 | } |
211 | 768 | } else { | 809 | } else { |
212 | 769 | set_search_text (); | 810 | set_search_text (); |
213 | 770 | } | 811 | } |
214 | 771 | 812 | ||
215 | === modified file 'src/Scratch.vala' | |||
216 | --- src/Scratch.vala 2016-09-01 04:13:38 +0000 | |||
217 | +++ src/Scratch.vala 2016-12-13 02:07:05 +0000 | |||
218 | @@ -242,44 +242,10 @@ | |||
219 | 242 | if (window == null) { | 242 | if (window == null) { |
220 | 243 | window = this.new_window (); | 243 | window = this.new_window (); |
221 | 244 | window.show (); | 244 | window.show (); |
256 | 245 | // Restore opened documents | 245 | window.restore_opened_documents (); |
223 | 246 | if (settings.show_at_start == "last-tabs") { | ||
224 | 247 | window.start_loading (); | ||
225 | 248 | |||
226 | 249 | string[] uris = settings.schema.get_strv ("opened-files"); | ||
227 | 250 | |||
228 | 251 | foreach (string uri in uris) { | ||
229 | 252 | if (uri != "") { | ||
230 | 253 | var file = File.new_for_uri (uri); | ||
231 | 254 | if (file.query_exists ()) { | ||
232 | 255 | var doc = new Scratch.Services.Document (window.main_actions, file); | ||
233 | 256 | window.open_document (doc); | ||
234 | 257 | } | ||
235 | 258 | } | ||
236 | 259 | } | ||
237 | 260 | |||
238 | 261 | // Set focus to last focused document, after all documents finished loading | ||
239 | 262 | string focused_document = settings.schema.get_string("focused-document"); | ||
240 | 263 | if (focused_document != "" && window.split_view.current_view != null) { | ||
241 | 264 | Scratch.Services.Document document_to_focus = null; | ||
242 | 265 | var document_view = window.split_view.current_view; | ||
243 | 266 | foreach (Scratch.Services.Document doc in document_view.docs) { | ||
244 | 267 | if (doc.file != null) { | ||
245 | 268 | if (doc.file.get_uri() == focused_document) { | ||
246 | 269 | document_to_focus = doc; | ||
247 | 270 | break; | ||
248 | 271 | } | ||
249 | 272 | } | ||
250 | 273 | } | ||
251 | 274 | if (document_to_focus != null) | ||
252 | 275 | window.split_view.current_view.notebook.current = document_to_focus; | ||
253 | 276 | } | ||
254 | 277 | window.stop_loading (); | ||
255 | 278 | } | ||
257 | 279 | } else { | 246 | } else { |
258 | 280 | window.present (); | 247 | window.present (); |
259 | 281 | } | 248 | } |
260 | 282 | |||
261 | 283 | } | 249 | } |
262 | 284 | 250 | ||
263 | 285 | protected override void open (File[] files, string hint) { | 251 | protected override void open (File[] files, string hint) { |
264 | 286 | 252 | ||
265 | === modified file 'src/Services/Settings.vala' | |||
266 | --- src/Services/Settings.vala 2016-04-13 05:03:04 +0000 | |||
267 | +++ src/Services/Settings.vala 2016-12-13 02:07:05 +0000 | |||
268 | @@ -62,9 +62,11 @@ | |||
269 | 62 | public string style_scheme { get; set; } | 62 | public string style_scheme { get; set; } |
270 | 63 | public string[] plugins_enabled { get; set;} | 63 | public string[] plugins_enabled { get; set;} |
271 | 64 | public string show_at_start { get; set; } | 64 | public string show_at_start { get; set; } |
273 | 65 | public string[] opened_files { get; set; } | 65 | public string[] opened_files_view1 { get; set; } |
274 | 66 | public string[] opened_files_view2 { get; set; } | ||
275 | 66 | public bool autosave { get; set; } | 67 | public bool autosave { get; set; } |
277 | 67 | public string focused_document { get; set; } | 68 | public string focused_document_view1 { get; set; } |
278 | 69 | public string focused_document_view2 { get; set; } | ||
279 | 68 | public bool show_mini_map { get; set; } | 70 | public bool show_mini_map { get; set; } |
280 | 69 | 71 | ||
281 | 70 | public Settings () { | 72 | public Settings () { |
282 | 71 | 73 | ||
283 | === modified file 'src/Widgets/DocumentView.vala' | |||
284 | --- src/Widgets/DocumentView.vala 2015-11-09 21:25:02 +0000 | |||
285 | +++ src/Widgets/DocumentView.vala 2016-12-13 02:07:05 +0000 | |||
286 | @@ -36,6 +36,9 @@ | |||
287 | 36 | } | 36 | } |
288 | 37 | } | 37 | } |
289 | 38 | 38 | ||
290 | 39 | public uint view_id = -1; | ||
291 | 40 | public bool is_closing = false; | ||
292 | 41 | |||
293 | 39 | // Signals | 42 | // Signals |
294 | 40 | public signal void document_change (Services.Document? document); | 43 | public signal void document_change (Services.Document? document); |
295 | 41 | public signal void empty (); | 44 | public signal void empty (); |
296 | @@ -70,6 +73,7 @@ | |||
297 | 70 | 73 | ||
298 | 71 | this.notebook.tab_switched.connect ((old_tab, new_tab) => { | 74 | this.notebook.tab_switched.connect ((old_tab, new_tab) => { |
299 | 72 | document_change (new_tab as Services.Document); | 75 | document_change (new_tab as Services.Document); |
300 | 76 | save_current_file (new_tab as Services.Document); | ||
301 | 73 | }); | 77 | }); |
302 | 74 | 78 | ||
303 | 75 | this.notebook.tab_restored.connect ((label, restore_data, icon) => { | 79 | this.notebook.tab_restored.connect ((label, restore_data, icon) => { |
304 | @@ -224,7 +228,7 @@ | |||
305 | 224 | doc.source_view.focus_in_event.connect (this.on_focus_in_event); | 228 | doc.source_view.focus_in_event.connect (this.on_focus_in_event); |
306 | 225 | doc.source_view.drag_data_received.connect (this.drag_received); | 229 | doc.source_view.drag_data_received.connect (this.drag_received); |
307 | 226 | doc.source_view.drag_motion.connect (this.drag_motion); | 230 | doc.source_view.drag_motion.connect (this.drag_motion); |
309 | 227 | 231 | save_opened_files (); | |
310 | 228 | } | 232 | } |
311 | 229 | 233 | ||
312 | 230 | private void on_doc_removed (Granite.Widgets.Tab tab) { | 234 | private void on_doc_removed (Granite.Widgets.Tab tab) { |
313 | @@ -239,6 +243,10 @@ | |||
314 | 239 | if (this.is_empty ()) { | 243 | if (this.is_empty ()) { |
315 | 240 | empty (); | 244 | empty (); |
316 | 241 | } | 245 | } |
317 | 246 | |||
318 | 247 | if (!is_closing) { | ||
319 | 248 | save_opened_files (); | ||
320 | 249 | } | ||
321 | 242 | } | 250 | } |
322 | 243 | 251 | ||
323 | 244 | private void on_doc_moved (Granite.Widgets.Tab tab, int x, int y) { | 252 | private void on_doc_moved (Granite.Widgets.Tab tab, int x, int y) { |
324 | @@ -266,6 +274,8 @@ | |||
325 | 266 | this.docs.insert (doc, new_pos); | 274 | this.docs.insert (doc, new_pos); |
326 | 267 | 275 | ||
327 | 268 | doc.focus (); | 276 | doc.focus (); |
328 | 277 | |||
329 | 278 | save_opened_files (); | ||
330 | 269 | } | 279 | } |
331 | 270 | 280 | ||
332 | 271 | private bool on_focus_in_event () { | 281 | private bool on_focus_in_event () { |
333 | @@ -293,5 +303,46 @@ | |||
334 | 293 | Gtk.drag_finish (ctx, true, false, time); | 303 | Gtk.drag_finish (ctx, true, false, time); |
335 | 294 | } | 304 | } |
336 | 295 | } | 305 | } |
337 | 306 | |||
338 | 307 | public void save_opened_files () { | ||
339 | 308 | if (settings.show_at_start == "last-tabs") { | ||
340 | 309 | string[] opened_files = {}; | ||
341 | 310 | |||
342 | 311 | notebook.tabs.foreach ((tab) => { | ||
343 | 312 | var doc = tab as Scratch.Services.Document; | ||
344 | 313 | if (doc.file != null && doc.exists ()) { | ||
345 | 314 | opened_files += doc.file.get_uri (); | ||
346 | 315 | } | ||
347 | 316 | }); | ||
348 | 317 | |||
349 | 318 | if (view_id == 1) { | ||
350 | 319 | settings.opened_files_view1 = opened_files; | ||
351 | 320 | } else { | ||
352 | 321 | settings.opened_files_view2 = opened_files; | ||
353 | 322 | } | ||
354 | 323 | } | ||
355 | 324 | } | ||
356 | 325 | |||
357 | 326 | public void save_current_file (Services.Document? current_document) { | ||
358 | 327 | string file_uri = ""; | ||
359 | 328 | |||
360 | 329 | if (current_document != null) { | ||
361 | 330 | file_uri = current_document.file.get_uri(); | ||
362 | 331 | } | ||
363 | 332 | |||
364 | 333 | if (file_uri != "") { | ||
365 | 334 | if (view_id == 1) { | ||
366 | 335 | settings.focused_document_view1 = file_uri; | ||
367 | 336 | } else { | ||
368 | 337 | settings.focused_document_view2 = file_uri; | ||
369 | 338 | } | ||
370 | 339 | } else { | ||
371 | 340 | if (view_id == 1) { | ||
372 | 341 | settings.schema.reset ("focused-document_view1"); | ||
373 | 342 | } else { | ||
374 | 343 | settings.schema.reset ("focused-document_view2"); | ||
375 | 344 | } | ||
376 | 345 | } | ||
377 | 346 | } | ||
378 | 296 | } | 347 | } |
379 | 297 | } | 348 | } |
380 | 298 | 349 | ||
381 | === modified file 'src/Widgets/SplitView.vala' | |||
382 | --- src/Widgets/SplitView.vala 2016-11-20 10:49:23 +0000 | |||
383 | +++ src/Widgets/SplitView.vala 2016-12-13 02:07:05 +0000 | |||
384 | @@ -120,11 +120,13 @@ | |||
385 | 120 | view.show_all (); | 120 | view.show_all (); |
386 | 121 | 121 | ||
387 | 122 | views.append (view); | 122 | views.append (view); |
388 | 123 | view.view_id = views.length (); | ||
389 | 123 | this.current_view = view; | 124 | this.current_view = view; |
390 | 124 | debug ("View added successfully"); | 125 | debug ("View added successfully"); |
391 | 125 | 126 | ||
392 | 126 | // Enbale/Disable useless GtkActions about views | 127 | // Enbale/Disable useless GtkActions about views |
393 | 127 | check_actions (); | 128 | check_actions (); |
394 | 129 | |||
395 | 128 | return view; | 130 | return view; |
396 | 129 | } | 131 | } |
397 | 130 | 132 | ||
398 | @@ -137,12 +139,25 @@ | |||
399 | 137 | return; | 139 | return; |
400 | 138 | } | 140 | } |
401 | 139 | 141 | ||
402 | 142 | foreach (var doc in view.docs) { | ||
403 | 143 | if (!doc.close (true)) { | ||
404 | 144 | view.set_current_document (doc); | ||
405 | 145 | return; | ||
406 | 146 | } | ||
407 | 147 | } | ||
408 | 148 | |||
409 | 140 | // Swap the position of the second view in the pane when we delete the first one | 149 | // Swap the position of the second view in the pane when we delete the first one |
410 | 141 | if (get_child1 () == view && get_child2 () != null) { | 150 | if (get_child1 () == view && get_child2 () != null) { |
412 | 142 | var right_view = get_child2 (); | 151 | var right_view = get_child2 () as Scratch.Widgets.DocumentView; |
413 | 143 | remove (view); | 152 | remove (view); |
414 | 144 | remove (right_view); | 153 | remove (right_view); |
415 | 145 | pack1 (right_view, true, true); | 154 | pack1 (right_view, true, true); |
416 | 155 | |||
417 | 156 | view.view_id = 2; | ||
418 | 157 | right_view.view_id = 1; | ||
419 | 158 | |||
420 | 159 | view.save_opened_files (); | ||
421 | 160 | right_view.save_opened_files (); | ||
422 | 146 | } else { | 161 | } else { |
423 | 147 | remove (view); | 162 | remove (view); |
424 | 148 | } | 163 | } |
I can confirm that this works as expected