aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qml/StateHandler.qml98
-rw-r--r--qml/main.qml81
-rw-r--r--qml/ui.qrc1
3 files changed, 103 insertions, 77 deletions
diff --git a/qml/StateHandler.qml b/qml/StateHandler.qml
new file mode 100644
index 0000000..4334a6b
--- /dev/null
+++ b/qml/StateHandler.qml
@@ -0,0 +1,98 @@
+import QtQuick 2.0
+import QtQuick.Controls 1.2
+
+Item {
+ id: item
+
+ property Item terminalList : null
+
+ state: "INSERT"
+
+ function enterInsertMode() {
+ insertTerminalAction.trigger();
+ }
+
+ states: [
+ State {
+ name: "NORMAL"
+
+ PropertyChanges { target: escapeTerminalAction; enabled: false }
+ PropertyChanges { target: insertTerminalAction; enabled: true }
+ PropertyChanges { target: nextTerminalAction; enabled: true }
+ PropertyChanges { target: heightenTerminalAction; enabled: true }
+ PropertyChanges { target: shortenTerminalAction; enabled: true }
+ PropertyChanges { target: prevTerminalAction; enabled: true }
+ PropertyChanges { target: lastTerminalAction; enabled: true }
+ PropertyChanges { target: firstTerminalAction; enabled: true }
+ },
+ State {
+ name: "INSERT"
+
+ PropertyChanges { target: escapeTerminalAction; enabled: true }
+ PropertyChanges { target: insertTerminalAction; enabled: false }
+ PropertyChanges { target: nextTerminalAction; enabled: false }
+ PropertyChanges { target: heightenTerminalAction; enabled: false }
+ PropertyChanges { target: shortenTerminalAction; enabled: false }
+ PropertyChanges { target: prevTerminalAction; enabled: false }
+ PropertyChanges { target: lastTerminalAction; enabled: false }
+ PropertyChanges { target: firstTerminalAction; enabled: false }
+ }
+ ]
+
+ Action {
+ id: insertTerminalAction
+ shortcut: "i"
+ onTriggered: {
+ item.state = "INSERT";
+
+ terminalList.focusCurrent();
+ }
+ }
+
+ Action {
+ id: escapeTerminalAction
+ shortcut: "Shift+ESC"
+ onTriggered: {
+ item.state = "NORMAL";
+
+ terminalList.forceActiveFocus();
+ terminalList.unfocusCurrent();
+ }
+ }
+
+ Action {
+ id: nextTerminalAction
+ shortcut: "j"
+ onTriggered: terminalList.selectNext()
+ }
+
+ Action {
+ id: heightenTerminalAction
+ shortcut: "Shift+J"
+ onTriggered: terminalList.getCurrent().heighten()
+ }
+
+ Action {
+ id: shortenTerminalAction
+ shortcut: "Shift+K"
+ onTriggered: terminalList.getCurrent().shorten()
+ }
+
+ Action {
+ id: prevTerminalAction
+ shortcut: "k"
+ onTriggered: terminalList.selectPrev()
+ }
+
+ Action {
+ id: lastTerminalAction
+ shortcut: "Shift+G"
+ onTriggered: terminalList.selectItem(terminalList.children.length - 1)
+ }
+
+ Action {
+ id: firstTerminalAction
+ shortcut: "g"
+ onTriggered: terminalList.selectItem(0)
+ }
+}
diff --git a/qml/main.qml b/qml/main.qml
index ef17a99..11337f3 100644
--- a/qml/main.qml
+++ b/qml/main.qml
@@ -6,7 +6,6 @@ ApplicationWindow {
id: root
visible: true
-
color: "#161616"
Component.onCompleted: terminalList.focusCurrent()
@@ -84,7 +83,7 @@ ApplicationWindow {
if ( activeItem < (children.length - 1) ) {
selectItem(activeItem + 1);
} else {
- insertTerminalAction.trigger();
+ state.enterInsertMode();
}
}
@@ -113,81 +112,9 @@ ApplicationWindow {
}
}
- Action {
- id: insertTerminalAction
- shortcut: "i"
- enabled: false
- onTriggered: {
- escapeTerminalAction.enabled = true;
- insertTerminalAction.enabled = false;
- nextTerminalAction.enabled = false;
- heightenTerminalAction.enabled = false;
- shortenTerminalAction.enabled = false;
- prevTerminalAction.enabled = false;
- lastTerminalAction.enabled = false;
- firstTerminalAction.enabled = false;
-
- terminalList.focusCurrent();
- }
- }
-
- Action {
- id: escapeTerminalAction
- shortcut: "Shift+ESC"
- onTriggered: {
- escapeTerminalAction.enabled = false;
- insertTerminalAction.enabled = true;
- nextTerminalAction.enabled = true;
- heightenTerminalAction.enabled = true;
- shortenTerminalAction.enabled = true;
- prevTerminalAction.enabled = true;
- lastTerminalAction.enabled = true;
- firstTerminalAction.enabled = true;
-
- terminalList.forceActiveFocus();
- terminalList.unfocusCurrent();
- }
- }
-
- Action {
- id: nextTerminalAction
- shortcut: "j"
- enabled: false
- onTriggered: terminalList.selectNext()
- }
-
- Action {
- id: heightenTerminalAction
- shortcut: "Shift+J"
- enabled: false
- onTriggered: terminalList.getCurrent().heighten()
- }
-
- Action {
- id: shortenTerminalAction
- shortcut: "Shift+K"
- enabled: false
- onTriggered: terminalList.getCurrent().shorten()
- }
-
- Action {
- id: prevTerminalAction
- shortcut: "k"
- enabled: false
- onTriggered: terminalList.selectPrev()
- }
-
- Action {
- id: lastTerminalAction
- shortcut: "Shift+G"
- enabled: false
- onTriggered: terminalList.selectItem(terminalList.children.length - 1)
- }
+ StateHandler {
+ id: state
- Action {
- id: firstTerminalAction
- shortcut: "g"
- enabled: false
- onTriggered: terminalList.selectItem(0)
+ terminalList: terminalList
}
}
diff --git a/qml/ui.qrc b/qml/ui.qrc
index add7048..2705e7e 100644
--- a/qml/ui.qrc
+++ b/qml/ui.qrc
@@ -1,6 +1,7 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
+ <file>StateHandler.qml</file>
<file>TerminalItem.qml</file>
<file>EmbeddedTerminal.qml</file>
</qresource>