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

Proposed by Artem Anufrij
Status: Merged
Approved by: Artem Anufrij
Approved revision: 1409
Merged at revision: 1405
Proposed branch: lp:~artem-anufrij/scratch/Bugfix-1032565
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 188 lines (+63/-30)
2 files modified
plugins/terminal/terminal.vala (+57/-29)
src/MainWindow.vala (+6/-1)
To merge this branch: bzr merge lp:~artem-anufrij/scratch/Bugfix-1032565
Reviewer Review Type Date Requested Status
Danielle Foré Needs Fixing
Robert Roth (community) code Approve
elementary UX ux Pending
Review via email: mp+240365@code.launchpad.net

Commit message

Press CTRL+ALT+t for switching between terminal and editor.

Description of the change

Press CTRL+ALT+t for switching between terminal and editor.

To post a comment you must log in.
1403. By artem-anufrij

diconnect key_event on deactivate terminal plug in

1404. By artem-anufrij

improved code design

1405. By artem-anufrij

code design was improved

1406. By artem-anufrij

code design was improved

1407. By artem-anufrij

check if windown != null

Revision history for this message
Robert Roth (evfool) wrote :

Code-wise this looks OK, but we need an UX review based on comment https://bugs.launchpad.net/scratch/+bug/1032565/comments/2 tomake sure they are OK with F12 (I also use that shortcut for my dropdown terminal).

review: Approve (code)
Revision history for this message
Robert Roth (evfool) wrote :

The proposal is almost perfect code-wise, see my only inline comment :)

Revision history for this message
Cody Garver (codygarver) wrote :

I'm concerned about hardcoding this to F12. As commented on the bug report, that's a popular key. Is it possible to make this easily configurable somehow in dconf? Not only for the users, but we (OS team) could even end up reconfiguring this in the future at Design Team's request and a dconf entry is convenient for all who are concerned.

If it's not simple, let's further discuss if F12 is what we really want before merging this.

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

Hey Cody. Yes, it's possible. We need to create a new settings item, than I can use it for this plug in.

Revision history for this message
Danielle Foré (danrabbit) wrote :

Yeah I'm -1 on using F keys. Especially because on keyboards with media keys this can mean you need to hold down the "Fn" key first. So it's kind of inconvenient.

We should probably be using something Ctrl based. If it's not already being used for something in Scratch, it seems like "Ctrl T" would be the most logical.

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

Give me 5 minutes ... :)

1408. By artem-anufrij

Hotkey: CTRL+ALT+t

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

Hotkey: CTRL+ALT+t

1409. By artem-anufrij

merge lp:scratch

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/terminal/terminal.vala'
--- plugins/terminal/terminal.vala 2014-08-07 00:33:31 +0000
+++ plugins/terminal/terminal.vala 2014-11-09 10:53:41 +0000
@@ -1,21 +1,21 @@
1// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-1// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
2/***2/***
3 BEGIN LICENSE3 BEGIN LICENSE
4 4
5 Copyright (C) 2011-2013 Mario Guerriero <mario@elementaryos.org>5 Copyright (C) 2011-2013 Mario Guerriero <mario@elementaryos.org>
6 This program is free software: you can redistribute it and/or modify it 6 This program is free software: you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License version 3, as published 7 under the terms of the GNU Lesser General Public License version 3, as published
8 by the Free Software Foundation.8 by the Free Software Foundation.
9 9
10 This program is distributed in the hope that it will be useful, but 10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranties of 11 WITHOUT ANY WARRANTY; without even the implied warranties of
12 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 12 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13 PURPOSE. See the GNU General Public License for more details.13 PURPOSE. See the GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License along 15 You should have received a copy of the GNU General Public License along
16 with this program. If not, see <http://www.gnu.org/licenses/> 16 with this program. If not, see <http://www.gnu.org/licenses/>
17 17
18 END LICENSE 18 END LICENSE
19***/19***/
2020
21using Vte;21using Vte;
@@ -24,20 +24,46 @@
24public const string DESCRIPTION = N_("A terminal in your text editor");24public const string DESCRIPTION = N_("A terminal in your text editor");
2525
26public class Scratch.Plugins.Terminal : Peas.ExtensionBase, Peas.Activatable {26public class Scratch.Plugins.Terminal : Peas.ExtensionBase, Peas.Activatable {
27 27
28 MainWindow window = null;
28 Gtk.Notebook? bottombar = null;29 Gtk.Notebook? bottombar = null;
29 Vte.Terminal terminal;30 Vte.Terminal terminal;
30 Gtk.Grid grid;31 Gtk.Grid grid;
31 32 ulong? connect_handler;
33
32 Scratch.Services.Interface plugins;34 Scratch.Services.Interface plugins;
33 public Object object { owned get; construct; }35 public Object object { owned get; construct; }
34 36
35 public void update_state () {37 public void update_state () {
36 }38 }
3739
38 public void activate () {40 public void activate () {
39 plugins = (Scratch.Services.Interface) object; 41 plugins = (Scratch.Services.Interface) object;
40 plugins.hook_notebook_bottom.connect ((n) => { 42
43 plugins.hook_window.connect ((w) => {
44 if (window != null)
45 return;
46
47 window = w;
48 connect_handler = window.key_press_event.connect ((event) => {
49 if (event.keyval == Gdk.Key.t
50 && Gdk.ModifierType.MOD1_MASK in event.state
51 && Gdk.ModifierType.CONTROL_MASK in event.state) {
52 if (terminal.has_focus && window.get_current_document () != null) {
53 window.get_current_document ().focus ();
54 debug ("Move focus: EDITOR.");
55 return true;
56 } else if (window.get_current_document () != null && window.get_current_document ().source_view.has_focus) {
57 terminal.grab_focus ();
58 debug ("Move focus: TERMINAL.");
59 return true;
60 }
61 }
62 return false;
63 });
64 });
65
66 plugins.hook_notebook_bottom.connect ((n) => {
41 if (bottombar == null) {67 if (bottombar == null) {
42 this.bottombar = n;68 this.bottombar = n;
43 on_hook (this.bottombar);69 on_hook (this.bottombar);
@@ -50,12 +76,14 @@
50 public void deactivate () {76 public void deactivate () {
51 if (terminal != null)77 if (terminal != null)
52 grid.destroy ();78 grid.destroy ();
79 if (connect_handler != null)
80 window.disconnect ((ulong)connect_handler);
53 }81 }
54 82
55 void on_hook (Gtk.Notebook notebook) {83 void on_hook (Gtk.Notebook notebook) {
56 this.terminal = new Vte.Terminal ();84 this.terminal = new Vte.Terminal ();
57 this.terminal.scrollback_lines = -1;85 this.terminal.scrollback_lines = -1;
58 86
59 // Set terminal font to system default font87 // Set terminal font to system default font
60 var system_settings = new GLib.Settings ("org.gnome.desktop.interface");88 var system_settings = new GLib.Settings ("org.gnome.desktop.interface");
61 string font_name = system_settings.get_string ("monospace-font-name");89 string font_name = system_settings.get_string ("monospace-font-name");
@@ -117,21 +145,21 @@
117145
118 // Popup menu146 // Popup menu
119 var menu = new Gtk.Menu ();147 var menu = new Gtk.Menu ();
120 148
121 var copy = new Gtk.MenuItem.with_label (_("Copy"));149 var copy = new Gtk.MenuItem.with_label (_("Copy"));
122 copy.activate.connect (() => {150 copy.activate.connect (() => {
123 terminal.copy_clipboard ();151 terminal.copy_clipboard ();
124 });152 });
125 menu.append (copy);153 menu.append (copy);
126 copy.show ();154 copy.show ();
127 155
128 var paste = new Gtk.MenuItem.with_label (_("Paste"));156 var paste = new Gtk.MenuItem.with_label (_("Paste"));
129 paste.activate.connect (() => {157 paste.activate.connect (() => {
130 terminal.paste_clipboard ();158 terminal.paste_clipboard ();
131 });159 });
132 menu.append (paste);160 menu.append (paste);
133 paste.show ();161 paste.show ();
134 162
135 this.terminal.button_press_event.connect ((event) => {163 this.terminal.button_press_event.connect ((event) => {
136 if (event.button == 3) {164 if (event.button == 3) {
137 menu.select_first (false);165 menu.select_first (false);
@@ -139,24 +167,24 @@
139 }167 }
140 return false;168 return false;
141 });169 });
142 170
143 try {171 try {
144 this.terminal.fork_command_full (Vte.PtyFlags.DEFAULT, "~/", { Vte.get_user_shell () }, null, GLib.SpawnFlags.SEARCH_PATH, null, null);172 this.terminal.fork_command_full (Vte.PtyFlags.DEFAULT, "~/", { Vte.get_user_shell () }, null, GLib.SpawnFlags.SEARCH_PATH, null, null);
145 } catch (GLib.Error e) {173 } catch (GLib.Error e) {
146 warning (e.message);174 warning (e.message);
147 }175 }
148 176
149 grid = new Gtk.Grid ();177 grid = new Gtk.Grid ();
150 var sb = new Gtk.Scrollbar (Gtk.Orientation.VERTICAL, terminal.vadjustment);178 var sb = new Gtk.Scrollbar (Gtk.Orientation.VERTICAL, terminal.vadjustment);
151 grid.attach (terminal, 0, 0, 1, 1);179 grid.attach (terminal, 0, 0, 1, 1);
152 grid.attach (sb, 1, 0, 1, 1);180 grid.attach (sb, 1, 0, 1, 1);
153 181
154 // Make the terminal occupy the whole GUI182 // Make the terminal occupy the whole GUI
155 terminal.vexpand = true;183 terminal.vexpand = true;
156 terminal.hexpand = true;184 terminal.hexpand = true;
157 185
158 notebook.append_page (grid, new Gtk.Label (_("Terminal")));186 notebook.append_page (grid, new Gtk.Label (_("Terminal")));
159 187
160 grid.show_all ();188 grid.show_all ();
161189
162 }190 }
@@ -167,4 +195,4 @@
167 var objmodule = module as Peas.ObjectModule;195 var objmodule = module as Peas.ObjectModule;
168 objmodule.register_extension_type (typeof (Peas.Activatable),196 objmodule.register_extension_type (typeof (Peas.Activatable),
169 typeof (Scratch.Plugins.Terminal));197 typeof (Scratch.Plugins.Terminal));
170}198}
171\ No newline at end of file199\ No newline at end of file
172200
=== modified file 'src/MainWindow.vala'
--- src/MainWindow.vala 2014-10-30 19:06:19 +0000
+++ src/MainWindow.vala 2014-11-09 10:53:41 +0000
@@ -334,8 +334,13 @@
334334
335 // Get current document335 // Get current document
336 public Scratch.Services.Document? get_current_document () {336 public Scratch.Services.Document? get_current_document () {
337 Scratch.Services.Document? doc = null;
338
337 var view = this.get_current_view ();339 var view = this.get_current_view ();
338 return view.get_current_document ();340 if (view != null)
341 doc = view.get_current_document ();
342
343 return doc;
339 }344 }
340345
341 // Add new view346 // Add new view

Subscribers

People subscribed via source and target branches