Merge lp:~nikwen/ubuntu-terminal-app/keyboard-shortcuts into lp:~ubuntu-terminal-dev/ubuntu-terminal-app/reboot

Proposed by Niklas Wenzel
Status: Merged
Approved by: Alan Pope 🍺🐧🐱 πŸ¦„
Approved revision: 95
Merged at revision: 101
Proposed branch: lp:~nikwen/ubuntu-terminal-app/keyboard-shortcuts
Merge into: lp:~ubuntu-terminal-dev/ubuntu-terminal-app/reboot
Prerequisite: lp:~nikwen/ubuntu-terminal-app/exit-handling
Diff against target: 141 lines (+88/-3)
4 files modified
src/app/qml/SettingsPage.qml (+9/-2)
src/app/qml/TerminalComponent.qml (+8/-0)
src/app/qml/TerminalKeyboardShortcutHandler.qml (+66/-0)
src/app/qml/TerminalSettings.qml (+5/-1)
To merge this branch: bzr merge lp:~nikwen/ubuntu-terminal-app/keyboard-shortcuts
Reviewer Review Type Date Requested Status
Filippo Scognamiglio Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Alan Pope 🍺🐧🐱 πŸ¦„ (community) Needs Fixing
Review via email: mp+261787@code.launchpad.net

Commit message

Added keyboard shortcuts for desktop use.

Available commands:

Open Tab: Shift+Ctrl+T
Close Tab: Shift+Ctrl+W
Close Window: Shift+Ctrl+Q

Previous Tab: Ctrl+PageUp
Next Tab: Ctrl+PageDown

Copy: Shift+Ctrl+C
Paste: Shift+Ctrl+V

Zoom In: Ctrl++
Zoom Out: Ctrl+-
Normal Size: Ctrl+0

Description of the change

Added keyboard shortcuts which are known to users from gnome-terminal.

As this uses a function for tab closing which I introduced in the MP for proper handling of the "exit" command (https://code.launchpad.net/~nikwen/ubuntu-terminal-app/exit-handling/+merge/261770), that one needs to be merged first.

The detailed list:

Open Tab: Shift+Ctrl+T
Close Tab: Shift+Ctrl+W
Close Window: Shift+Ctrl+Q

Previous Tab: Ctrl+PageUp
Next Tab: Ctrl+PageDown

Copy: Shift+Ctrl+C
Paste: Shift+Ctrl+V

Zoom In: Ctrl++
Zoom Out: Ctrl+-
Normal Size: Ctrl+0

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Pope 🍺🐧🐱 πŸ¦„ (popey) wrote :

For me they all work except CTRL++ which doesn't make any difference when I press it and nothing in the log when I do.

review: Needs Fixing
Revision history for this message
Niklas Wenzel (nikwen) wrote :

Thank you for reviewing this, Alan.

Are you using the British keyboard layout? I'll test it with that one.

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Ok, I'm able to reproduce this with the British keyboard layout. Let me fix it. ;)

91. By Niklas Wenzel

Fix Ctrl++ shortcut for some keyboard layouts

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Here you go. ;)

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Niklas Wenzel (nikwen) wrote :

Suggestion from David Planella: Another shortcut that I find quite useful is the one to switch between tabs: Ctrl+PgUp or Ctrl+PgDown.

I'll add these.

92. By Niklas Wenzel

Add tab switching shortcuts

93. By Niklas Wenzel

Revert po directory

94. By Niklas Wenzel

Merge master

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Here you go. Should be ready for merging now. :)

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Filippo Scognamiglio (flscogna) wrote :

Hi Niklas. I approve the work here, but it could use some refactoring. Please move the shortcut logic to a separate component (shortcutManager or something like that) in order to increase readability and maintainability. We should also investigate the use of Actions which in the future will probably support shortcuts natively.

review: Needs Fixing
95. By Niklas Wenzel

Create TerminalKeyboardShortcutHandler component

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Hi Filippo,

Thank you very much for reviewing this. :)
I agree that another component increases maintainability, so I added one. ;)
However, I think that we should wait with using Actions until support for keyboard shortcuts is actually there, as right now it will only make the code clumsier in my opinion.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Filippo Scognamiglio (flscogna) :
review: Approve
Revision history for this message
Niklas Wenzel (nikwen) wrote :

Thanks for approving. Can we merge it yet?

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Thanks, Alan. :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/qml/SettingsPage.qml'
2--- src/app/qml/SettingsPage.qml 2015-04-01 22:50:53 +0000
3+++ src/app/qml/SettingsPage.qml 2015-06-23 17:39:11 +0000
4@@ -61,14 +61,21 @@
5 bottom: parent.bottom
6 margins: units.gu(2)
7 }
8- minimumValue: 8;
9- maximumValue: 32;
10+ minimumValue: settings.minFontSize;
11+ maximumValue: settings.maxFontSize;
12 onValueChanged: {
13 settings.fontSize = value;
14 }
15 Component.onCompleted: {
16 value = settings.fontSize;
17 }
18+
19+ Connections {
20+ target: settings
21+ onFontSizeChanged: {
22+ slFont.value = settings.fontSize
23+ }
24+ }
25 }
26 }
27
28
29=== modified file 'src/app/qml/TerminalComponent.qml'
30--- src/app/qml/TerminalComponent.qml 2015-06-11 21:33:57 +0000
31+++ src/app/qml/TerminalComponent.qml 2015-06-23 17:39:11 +0000
32@@ -23,6 +23,14 @@
33 onFinished: tabsModel.removeTabWithSession(terminalSession);
34 }
35
36+ Keys.onPressed: {
37+ keyboardShortcutHandler.handle(event)
38+ }
39+
40+ TerminalKeyboardShortcutHandler {
41+ id: keyboardShortcutHandler
42+ }
43+
44 QMLTermScrollbar {
45 z: parent.z + 2
46 terminal: parent
47
48=== added file 'src/app/qml/TerminalKeyboardShortcutHandler.qml'
49--- src/app/qml/TerminalKeyboardShortcutHandler.qml 1970-01-01 00:00:00 +0000
50+++ src/app/qml/TerminalKeyboardShortcutHandler.qml 2015-06-23 17:39:11 +0000
51@@ -0,0 +1,66 @@
52+import QtQuick 2.0
53+
54+Item {
55+
56+ function handle(event) {
57+ if (event.modifiers & Qt.ControlModifier) {
58+ if (event.modifiers & Qt.ShiftModifier) {
59+ event.accepted = true; // That way shortcuts will not be processed by the terminal widget (Ctrl + Shift is always interpreted as a shortcut)
60+
61+ switch (event.key) {
62+ // Window/tab handling
63+ case Qt.Key_T: // Open tab
64+ tabsModel.addTab();
65+ tabsModel.selectTab(tabsModel.count - 1);
66+ break;
67+ case Qt.Key_W: //Close tab
68+ tabsModel.removeTabWithSession(terminalSession);
69+ break;
70+ case Qt.Key_Q: //Close window
71+ for (var i = tabsModel.count - 1; i >= 0; i--) {
72+ tabsModel.removeTab(i); // This will also call Qt.quit()
73+ }
74+ break;
75+
76+ // Clipboard
77+ case Qt.Key_C: // Copy
78+ terminal.copyClipboard();
79+ break;
80+ case Qt.Key_V: // Paste
81+ terminal.pasteClipboard();
82+ break;
83+ }
84+ }
85+
86+ // The following may not reside in an else to the above if, as some keyboard layouts require
87+ // to press the shift key in order to type the plus character (and possibly others).
88+ // Do not automatically accept all keys here! Programs like nano may declare their own Ctrl-shortcuts.
89+
90+ switch (event.key) {
91+ // Font size
92+ case Qt.Key_Plus: // Zoom in
93+ event.accepted = true;
94+ settings.fontSize = Math.min(settings.fontSize + 1, settings.maxFontSize);
95+ break;
96+ case Qt.Key_Minus: // Zoom out
97+ event.accepted = true;
98+ settings.fontSize = Math.max(settings.fontSize - 1, settings.minFontSize);
99+ break;
100+ case Qt.Key_0: // Normal size
101+ event.accepted = true;
102+ settings.fontSize = settings.defaultFontSize;
103+ break;
104+
105+ // Tab switching
106+ case Qt.Key_PageUp: // Previous tab
107+ event.accepted = true;
108+ tabsModel.selectTab((tabsModel.selectedIndex - 1 + tabsModel.count) % tabsModel.count);
109+ break;
110+ case Qt.Key_PageDown: // Next tab
111+ event.accepted = true;
112+ tabsModel.selectTab((tabsModel.selectedIndex + 1) % tabsModel.count);
113+ break;
114+ }
115+ }
116+ }
117+}
118
119=== modified file 'src/app/qml/TerminalSettings.qml'
120--- src/app/qml/TerminalSettings.qml 2015-04-02 12:53:43 +0000
121+++ src/app/qml/TerminalSettings.qml 2015-06-23 17:39:11 +0000
122@@ -10,6 +10,10 @@
123 property alias colorScheme: innerSettings.colorScheme
124 property alias showKeyboardBar: innerSettings.showKeyboardBar
125
126+ readonly property int defaultFontSize: 14
127+ readonly property int minFontSize: 8
128+ readonly property int maxFontSize: 32
129+
130 property alias jsonVisibleProfiles: innerSettings.jsonVisibleProfiles
131
132 property ListModel profilesList: ListModel {}
133@@ -31,7 +35,7 @@
134
135 Settings {
136 id: innerSettings
137- property int fontSize: 14
138+ property int fontSize: defaultFontSize
139 property string fontStyle: "Ubuntu Mono"
140 property string colorScheme: "Ubuntu"
141 property bool showKeyboardBar: true

Subscribers

People subscribed via source and target branches