aboutsummaryrefslogtreecommitdiff
path: root/src/StateHandler.qml
blob: 3267f53aef105bfe32d09cc5167e735598f388af (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
139
140
141
142
143
144
145
146
147
148
149
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: nextAction;         enabled: true  }
			PropertyChanges { target: heightenAction;     enabled: true  }
			PropertyChanges { target: shortenAction;      enabled: true  }
			PropertyChanges { target: prevAction;         enabled: true  }
			PropertyChanges { target: lastAction;         enabled: true  }
			PropertyChanges { target: firstAction;        enabled: true  }
			PropertyChanges { target: resetAction;        enabled: true  }
			PropertyChanges { target: killAction;         enabled: true  }
		},
		State {
			name: "INSERT"

			PropertyChanges { target: enterNormalAction;  enabled: true  }
			PropertyChanges { target: enterInsertAction;  enabled: false }
			PropertyChanges { target: enterCommandAction; enabled: false }
			PropertyChanges { target: nextAction;         enabled: false }
			PropertyChanges { target: heightenAction;     enabled: false }
			PropertyChanges { target: shortenAction;      enabled: false }
			PropertyChanges { target: prevAction;         enabled: false }
			PropertyChanges { target: lastAction;         enabled: false }
			PropertyChanges { target: firstAction;        enabled: false }
			PropertyChanges { target: resetAction;        enabled: false }
			PropertyChanges { target: killAction;         enabled: false }
		},
		State {
			name: "COMMAND"

			PropertyChanges { target: enterNormalAction;  enabled: true  }
			PropertyChanges { target: enterInsertAction;  enabled: false }
			PropertyChanges { target: enterCommandAction; enabled: false }
			PropertyChanges { target: nextAction;         enabled: false }
			PropertyChanges { target: heightenAction;     enabled: false }
			PropertyChanges { target: shortenAction;      enabled: false }
			PropertyChanges { target: prevAction;         enabled: false }
			PropertyChanges { target: lastAction;         enabled: false }
			PropertyChanges { target: firstAction;        enabled: false }
			PropertyChanges { target: resetAction;        enabled: false }
			PropertyChanges { target: killAction;         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: nextAction
		shortcut: settings.keybinding.nextItem
		onTriggered: terminalList.selectNext()
	}

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

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

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

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

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

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

	Action {
		id: killAction
		shortcut: settings.keybinding.killItem
		onTriggered: {
			terminalList.getCurrent().terminate();
		}
	}
}