From 1ed6dfcd2eb9878b2ad25c42358d9a21839a1951 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 25 Jul 2015 20:07:14 +0200 Subject: Reimplemented `delete` command as more of a `reset` command Pressing `d` in normal mode causes the current embedded terminal to be destroyed and the containing terminal item to be reset into its initial state. This allows for much more flexible usage of _MetaTerm_. To prevent unnecessary terminal item instantiations the `onExecuted` signal was extended to provide a `index` argument containing the sender terminal's index. --- qml/StateHandler.qml | 8 ++++---- qml/TerminalItem.qml | 17 +++++++++++++++-- qml/main.qml | 14 +++++++------- 3 files changed, 26 insertions(+), 13 deletions(-) (limited to 'qml') diff --git a/qml/StateHandler.qml b/qml/StateHandler.qml index aacb0fa..53ca3af 100644 --- a/qml/StateHandler.qml +++ b/qml/StateHandler.qml @@ -24,7 +24,7 @@ Item { PropertyChanges { target: prevTerminalAction; enabled: true } PropertyChanges { target: lastTerminalAction; enabled: true } PropertyChanges { target: firstTerminalAction; enabled: true } - PropertyChanges { target: deleteTerminalAction; enabled: true } + PropertyChanges { target: resetTerminalAction; enabled: true } }, State { name: "INSERT" @@ -37,7 +37,7 @@ Item { PropertyChanges { target: prevTerminalAction; enabled: false } PropertyChanges { target: lastTerminalAction; enabled: false } PropertyChanges { target: firstTerminalAction; enabled: false } - PropertyChanges { target: deleteTerminalAction; enabled: false } + PropertyChanges { target: resetTerminalAction; enabled: false } } ] @@ -99,8 +99,8 @@ Item { } Action { - id: deleteTerminalAction + id: resetTerminalAction shortcut: "d" - onTriggered: terminalList.deleteCurrent() + onTriggered: terminalList.getCurrent().reset() } } diff --git a/qml/TerminalItem.qml b/qml/TerminalItem.qml index 0650b1e..26793da 100644 --- a/qml/TerminalItem.qml +++ b/qml/TerminalItem.qml @@ -8,7 +8,7 @@ Item { property int index : 0 property EmbeddedTerminal terminal : null - signal executed + signal executed (int index) anchors { left: parent.left @@ -63,6 +63,19 @@ Item { } } + function reset() { + if ( terminal !== null ) { + terminal.destroy(); + + terminal = null; + command.readOnly = false; + command.focus = true; + + unfocus(); + select(); + } + } + FocusScope { id: scope @@ -146,7 +159,7 @@ Item { focus = false; elementList.createTerminal(text); - item.executed(); + item.executed(item.index); highlighter.deselect(); } } diff --git a/qml/main.qml b/qml/main.qml index f9e7162..836f97c 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -38,6 +38,12 @@ ApplicationWindow { onHeightChanged: scrollTo(activeItem) + function onItemExecuted(index) { + if ( index === (children.length - 1) ) { + createItem(); + } + } + function createItem() { var terminalItem = Qt.createComponent("qrc:/TerminalItem.qml"); var instantiateTerminal = function() { @@ -45,7 +51,7 @@ ApplicationWindow { "index": itemIndex, "width": terminalListFlickable.width }); - instance.onExecuted.connect(createItem); + instance.onExecuted.connect(onItemExecuted); ++itemIndex; } @@ -110,12 +116,6 @@ ApplicationWindow { function getCurrent() { return children[activeItem]; } - - function deleteCurrent() { - if ( children[activeItem].terminal != null ) { - children[activeItem].destroy(); - } - } } } -- cgit v1.2.3