aboutsummaryrefslogtreecommitdiff
path: root/src/StateHandler.qml
blob: 118706cb4ea3a433c0690044ab07c00a3b4002e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import QtQuick 2.0
import QtQuick.Controls 1.2

Item {
	id: item

	state: "INSERT"

	function enterInsertMode() {
		enterInsertAction.trigger();
	}

	function enterNormalMode() {
		enterNormalAction.trigger();
	}

	states: [
		State {
			name: "NORMAL"

			PropertyChanges { target: enterNormalAction;      enabled: false }
			PropertyChanges { target: enterInsertAction;      enabled: true  }
			PropertyChanges { target: enterCommandAction;     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  }
			PropertyChanges { target: resetTerminalAction;    enabled: true  }
		},
		State {
			name: "INSERT"

			PropertyChanges { target: enterNormalAction;      enabled: true  }
			PropertyChanges { target: enterInsertAction;      enabled: false }
			PropertyChanges { target: enterCommandAction;     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 }
			PropertyChanges { target: resetTerminalAction;    enabled: false }
		},
		State {
			name: "COMMAND"

			PropertyChanges { target: enterNormalAction;      enabled: true  }
			PropertyChanges { target: enterInsertAction;      enabled: false }
			PropertyChanges { target: enterCommandAction;     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 }
			PropertyChanges { target: resetTerminalAction;    enabled: false }
		}
	]

	Action {
		id: enterNormalAction
		shortcut: settings.keybinding.normalMode
		onTriggered: {
			item.state = "NORMAL";

            terminalList.forceActiveFocus();
			terminalList.unfocusCurrent();
			command.unfocus();
		}
	}

	Action {
		id: enterInsertAction
		shortcut: settings.keybinding.insertMode
		onTriggered: {
			item.state = "INSERT";

			terminalList.focusCurrent();
		}
	}

	Action {
		id: enterCommandAction
		shortcut: settings.keybinding.commandMode
		onTriggered: {
			item.state = "COMMAND";

			command.focus(shortcut);
		}
	}

	Action {
		id: nextTerminalAction
		shortcut: settings.keybinding.nextItem
		onTriggered: terminalList.selectNext()
	}

	Action {
		id: heightenTerminalAction
		shortcut: settings.keybinding.heightenItem
		onTriggered: terminalList.getCurrent().heighten()
	}

	Action {
		id: shortenTerminalAction
		shortcut: settings.keybinding.shortenItem
		onTriggered: terminalList.getCurrent().shorten()
	}

	Action {
		id: prevTerminalAction
		shortcut: settings.keybinding.prevItem
		onTriggered: terminalList.selectPrev()
	}

	Action {
		id: lastTerminalAction
		shortcut: settings.keybinding.lastItem
		onTriggered: terminalList.selectItem(terminalList.children.length - 1)
	}

	Action {
		id: firstTerminalAction
		shortcut: settings.keybinding.firstItem
		onTriggered: terminalList.selectItem(0)
	}

	Action {
		id: resetTerminalAction
		shortcut: settings.keybinding.resetItem
		onTriggered: {
			terminalList.getCurrent().reset();
			terminalList.getCurrent().select();
		}
	}
}