Merge lp:~artem-anufrij/scratch/Bugfix-1392937 into lp:~elementary-apps/scratch/scratch

Proposed by Artem Anufrij
Status: Merged
Merged at revision: 1418
Proposed branch: lp:~artem-anufrij/scratch/Bugfix-1392937
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 146 lines (+53/-28)
2 files modified
plugins/browser-preview/BrowserView.vala (+1/-1)
plugins/browser-preview/browser-preview.vala (+52/-27)
To merge this branch: bzr merge lp:~artem-anufrij/scratch/Bugfix-1392937
Reviewer Review Type Date Requested Status
Artem Anufrij (community) merge Needs Information
Raphael Isemann (community) Needs Fixing
Review via email: mp+242842@code.launchpad.net

Description of the change

Save the browser preview state for all tabs.

To post a comment you must log in.
Revision history for this message
Raphael Isemann (teemperor) wrote :

When i hit Ctrl+Alt+S (Save as) and save it somewhere else, the refresh stops working. You should check if the URL has changed. Same happens when you open a new tab, type some html and then try to save it somewhere else than the scratch-temp-folder.

review: Needs Fixing
Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

Ok...

This is a small thing.

Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

Oh shit ... I merged it Directly into the scratch... Can it be reversed?

review: Needs Information (merge)
Revision history for this message
Raphael Isemann (teemperor) wrote :

Just make a new merge proposal with the fixes to the ctrl alt s problem.
I'm already in bed and it's easier to just approve a second branch :)
Am 01.12.2014 00:29 schrieb "Artem Anufrij" <email address hidden>:

> Review: Needs Information merge
>
> Oh shit ... I merged it Directly into the scratch... Can it be reversed?
> --
>
> https://code.launchpad.net/~artem-anufrij/scratch/Bugfix-1392937/+merge/242842
> You are reviewing the proposed merge of
> lp:~artem-anufrij/scratch/Bugfix-1392937 into lp:scratch.
>

Revision history for this message
Artem Anufrij (artem-anufrij) wrote :

<ctrl+als+s> was fixed :)

Revision history for this message
Raphael Isemann (teemperor) wrote :

Ok, late review on the already merged branch:

What is "is_app_launch" used for in Scratch.vala? Any reason for that? Looks to me as if you wanted to fix another bug by the way.

Rest of the code seems to be fine.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/browser-preview/BrowserView.vala'
2--- plugins/browser-preview/BrowserView.vala 2014-11-09 16:08:42 +0000
3+++ plugins/browser-preview/BrowserView.vala 2014-11-25 20:59:43 +0000
4@@ -22,7 +22,7 @@
5
6 internal class BrowserView : WebKit.WebView {
7
8- Gtk.Paned? paned = null;
9+ public Gtk.Paned? paned = null;
10
11 private unowned WebKit.WebView show_inspector_view (WebKit.WebView v) {
12 debug ("Show inspector");
13
14=== modified file 'plugins/browser-preview/browser-preview.vala'
15--- plugins/browser-preview/browser-preview.vala 2014-11-10 18:09:21 +0000
16+++ plugins/browser-preview/browser-preview.vala 2014-11-25 20:59:43 +0000
17@@ -26,11 +26,12 @@
18 public class BrowserPreviewPlugin : Peas.ExtensionBase, Peas.Activatable {
19
20 Gtk.ToolButton? tool_button = null;
21+ GLib.HashTable<Scratch.Services.Document, BrowserPreview.BrowserView> previews = new GLib.HashTable<Scratch.Services.Document, BrowserPreview.BrowserView> (null, null);
22+
23 BrowserPreview.BrowserView? view = null;
24- Gtk.Paned? plugin_tab = null;
25 Scratch.Services.Document? doc = null;
26
27- Gtk.Notebook notebook;
28+ Gtk.Notebook? notebook = null;
29
30 Scratch.Services.Interface plugins;
31 public Object object { owned get; construct; }
32@@ -42,7 +43,7 @@
33 plugins = (Scratch.Services.Interface) object;
34
35 plugins.hook_window.connect ((w) => {
36- set_current_document (w.get_current_document ());
37+ this.doc = w.get_current_document ();
38 });
39
40 plugins.hook_document.connect (set_current_document);
41@@ -58,8 +59,10 @@
42 if (tool_button != null)
43 tool_button.destroy ();
44
45- if (plugin_tab != null)
46- plugin_tab.destroy ();
47+ previews.foreach ((key, val) => {
48+ key.doc_saved.disconnect (show_preview);
49+ val.paned.destroy ();
50+ });
51 }
52
53 void on_hook_split_view (Scratch.Widgets.SplitView view) {
54@@ -88,48 +91,70 @@
55 }
56
57 void on_hook_context (Gtk.Notebook notebook) {
58- if (plugin_tab != null)
59+ if (this.notebook != null)
60 return;
61
62 this.notebook = notebook;
63
64- plugin_tab = new Gtk.Paned (Gtk.Orientation.VERTICAL);
65-
66- view = new BrowserPreview.BrowserView (plugin_tab);
67-
68- notebook.append_page (plugin_tab, new Gtk.Label (_("Web preview")));
69-
70- plugin_tab.show_all ();
71+ set_current_document (this.doc);
72 }
73
74- void toggle_plugin_visibility () {
75- if (notebook.page_num (plugin_tab) == -1) {
76- notebook.append_page (plugin_tab, new Gtk.Label (_("Web preview")));
77+ void toggle_plugin_visibility () {
78+ if (notebook.page_num (view.paned) == -1) {
79+ notebook.append_page (view.paned, new Gtk.Label (_("Web preview")));
80 tool_button.tooltip_text = _("Hide preview");
81 } else {
82- notebook.remove (plugin_tab);
83+ notebook.remove (view.paned);
84 tool_button.tooltip_text = _("Show preview");
85 }
86 }
87
88 void set_current_document (Scratch.Services.Document? d) {
89 if (d != null) {
90+
91 this.doc = d;
92- this.doc.doc_saved.disconnect (show_preview);
93- this.doc.doc_saved.connect (show_preview);
94+
95+ if (previews.get (this.doc) == null) {
96+
97+ previews.insert (this.doc, new BrowserPreview.BrowserView (new Gtk.Paned (Gtk.Orientation.VERTICAL)));
98+
99+ this.doc.doc_saved.disconnect (show_preview);
100+ this.doc.doc_saved.connect (show_preview);
101+ }
102+
103 show_preview ();
104 }
105 }
106
107 void show_preview () {
108- // Get uri
109- if (this.doc.file == null)
110- return;
111- string uri = this.doc.file.get_uri ();
112-
113- debug ("Previewing: " + this.doc.file.get_basename ());
114-
115- view.load_uri (uri);
116+
117+ bool tab_is_selected = false;
118+ int tab_page_number = 0;
119+
120+ // Remove preview tab
121+ if (view != null) {
122+ // Check if Preview-Tab is selected
123+ tab_page_number = notebook.page_num (view.paned);
124+ tab_is_selected = notebook.get_current_page () == tab_page_number;
125+ notebook.remove (view.paned);
126+ }
127+
128+ view = previews.get (this.doc);
129+ view.paned.show_all ();
130+
131+ // Check if removed tab was visible
132+ if (tab_page_number > -1) {
133+ notebook.insert_page (view.paned, new Gtk.Label (_("Web preview")), tab_page_number);
134+
135+ // Select new tab if the removed tab was selected
136+ if (tab_is_selected)
137+ notebook.set_current_page (tab_page_number);
138+ }
139+
140+ if (view.uri == null || view.uri == "")
141+ view.load_uri (this.doc.file.get_uri ());
142+ else
143+ view.reload ();
144 }
145 }
146 }

Subscribers

People subscribed via source and target branches