aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2015-07-03 22:40:14 +0200
committerAdrian Kummerlaender2015-07-03 22:40:14 +0200
commitefc816a292d8c6c8d51b4a445db2d867f8c86887 (patch)
treee2534cfa8391b90390ae1287993d83b43badc4ad
parent2c768162da03d91e37d84210eec0b9fdc9e7e20e (diff)
downloadMetaTerm-efc816a292d8c6c8d51b4a445db2d867f8c86887.tar
MetaTerm-efc816a292d8c6c8d51b4a445db2d867f8c86887.tar.gz
MetaTerm-efc816a292d8c6c8d51b4a445db2d867f8c86887.tar.bz2
MetaTerm-efc816a292d8c6c8d51b4a445db2d867f8c86887.tar.lz
MetaTerm-efc816a292d8c6c8d51b4a445db2d867f8c86887.tar.xz
MetaTerm-efc816a292d8c6c8d51b4a445db2d867f8c86887.tar.zst
MetaTerm-efc816a292d8c6c8d51b4a445db2d867f8c86887.zip
Introduced last and first terminal selector actions
They are active in normal mode and move the focus to the last respectively first element of the list.
-rw-r--r--MetaTerm.qml70
1 files changed, 57 insertions, 13 deletions
diff --git a/MetaTerm.qml b/MetaTerm.qml
index 36728ae..0b2046a 100644
--- a/MetaTerm.qml
+++ b/MetaTerm.qml
@@ -9,7 +9,7 @@ Rectangle {
color: "#161616"
- Component.onCompleted: terminalList.focusItem()
+ Component.onCompleted: terminalList.focusCurrent()
Flickable {
id: terminalListFlickable
@@ -41,27 +41,53 @@ Rectangle {
}
}
- function nextItem() {
+ function scrollTo(index) {
+ if ( terminalList.height >= terminalListFlickable.height ) {
+ var offset = children[index].y
+ + (children[index].height / 2)
+ - (terminalListFlickable.height / 2);
+
+ var bound = terminalList.height
+ - terminalListFlickable.height;
+
+ if ( offset < 0 ) {
+ terminalListFlickable.contentY = 0;
+ } else if ( offset >= bound ) {
+ terminalListFlickable.contentY = bound;
+ } else {
+ terminalListFlickable.contentY = offset;
+ }
+ }
+ }
+
+ function selectItem(index) {
+ children[activeItem].deselect();
+ children[index ].select();
+
+ activeItem = index;
+
+ scrollTo(index);
+ }
+
+ function selectNext() {
if ( activeItem < (children.length - 1) ) {
- children[ activeItem].deselect();
- children[++activeItem].select();
+ selectItem(activeItem + 1);
} else {
insertTerminalAction.trigger();
}
}
- function prevItem() {
+ function selectPrev() {
if ( activeItem > 0 ) {
- children[ activeItem].deselect();
- children[--activeItem].select();
+ selectItem(activeItem - 1);
}
}
- function focusItem() {
+ function focusCurrent() {
children[activeItem].forceActiveFocus();
}
- function unfocusItem() {
+ function unfocusCurrent() {
children[activeItem].unfocus();
}
@@ -81,8 +107,10 @@ Rectangle {
insertTerminalAction.enabled = false;
nextTerminalAction.enabled = false;
prevTerminalAction.enabled = false;
+ lastTerminalAction.enabled = false;
+ firstTerminalAction.enabled = false;
- terminalList.focusItem();
+ terminalList.focusCurrent();
}
}
@@ -94,9 +122,11 @@ Rectangle {
insertTerminalAction.enabled = true;
nextTerminalAction.enabled = true;
prevTerminalAction.enabled = true;
+ lastTerminalAction.enabled = true;
+ firstTerminalAction.enabled = true;
root.forceActiveFocus();
- terminalList.unfocusItem();
+ terminalList.unfocusCurrent();
}
}
@@ -104,14 +134,28 @@ Rectangle {
id: nextTerminalAction
shortcut: "j"
enabled: false
- onTriggered: terminalList.nextItem()
+ onTriggered: terminalList.selectNext()
}
Action {
id: prevTerminalAction
shortcut: "k"
enabled: false
- onTriggered: terminalList.prevItem()
+ onTriggered: terminalList.selectPrev()
+ }
+
+ Action {
+ id: lastTerminalAction
+ shortcut: "Shift+G"
+ enabled: false
+ onTriggered: terminalList.selectItem(terminalList.children.length - 1)
+ }
+
+ Action {
+ id: firstTerminalAction
+ shortcut: "g"
+ enabled: false
+ onTriggered: terminalList.selectItem(0)
}
ScrollBar {