mirror of
https://github.com/Swordfish90/cool-retro-term.git
synced 2026-02-08 00:32:27 +00:00
Allow creating a new tab from the top bar. Fix application title.
This commit is contained in:
@@ -24,14 +24,15 @@ import QtQuick.Layouts
|
|||||||
Item {
|
Item {
|
||||||
id: tabsRoot
|
id: tabsRoot
|
||||||
|
|
||||||
readonly property string title: stack.currentItem ? stack.currentItem.title : ""
|
readonly property int innerPadding: 6
|
||||||
|
readonly property string currentTitle: tabsModel.get(currentIndex).title ?? "cool-retro-term"
|
||||||
readonly property size terminalSize: stack.currentItem ? stack.currentItem.terminalSize : Qt.size(0, 0)
|
readonly property size terminalSize: stack.currentItem ? stack.currentItem.terminalSize : Qt.size(0, 0)
|
||||||
property alias currentIndex: tabBar.currentIndex
|
property alias currentIndex: tabBar.currentIndex
|
||||||
readonly property int count: tabsModel.count
|
readonly property int count: tabsModel.count
|
||||||
property var hostWindow
|
property var hostWindow
|
||||||
|
|
||||||
function addTab() {
|
function addTab() {
|
||||||
tabsModel.append({ title: qsTr("Tab %1").arg(tabsModel.count + 1) })
|
tabsModel.append({ title: "" })
|
||||||
tabBar.currentIndex = tabsModel.count - 1
|
tabBar.currentIndex = tabsModel.count - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,9 +43,7 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tabsModel.remove(index)
|
tabsModel.remove(index)
|
||||||
if (tabBar.currentIndex >= tabsModel.count) {
|
tabBar.currentIndex = Math.min(tabBar.currentIndex, tabsModel.count - 1)
|
||||||
tabBar.currentIndex = tabsModel.count - 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
@@ -57,15 +56,23 @@ Item {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: tabRow
|
||||||
|
Layout.fillWidth: true
|
||||||
|
height: rowLayout.implicitHeight
|
||||||
|
color: palette.window
|
||||||
|
visible: tabsModel.count > 1
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
id: rowLayout
|
||||||
|
anchors.fill: parent
|
||||||
|
spacing: 0
|
||||||
|
|
||||||
TabBar {
|
TabBar {
|
||||||
id: tabBar
|
id: tabBar
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
Layout.fillHeight: true
|
||||||
focusPolicy: Qt.NoFocus
|
focusPolicy: Qt.NoFocus
|
||||||
visible: tabsModel.count > 1
|
|
||||||
|
|
||||||
background: Rectangle {
|
|
||||||
color: palette.window
|
|
||||||
}
|
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
model: tabsModel
|
model: tabsModel
|
||||||
@@ -73,8 +80,8 @@ Item {
|
|||||||
id: tabButton
|
id: tabButton
|
||||||
contentItem: RowLayout {
|
contentItem: RowLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors { leftMargin: 6; rightMargin: 6 }
|
anchors { leftMargin: innerPadding; rightMargin: innerPadding }
|
||||||
spacing: 6
|
spacing: innerPadding
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: model.title
|
text: model.title
|
||||||
@@ -86,8 +93,7 @@ Item {
|
|||||||
ToolButton {
|
ToolButton {
|
||||||
text: "\u00d7"
|
text: "\u00d7"
|
||||||
focusPolicy: Qt.NoFocus
|
focusPolicy: Qt.NoFocus
|
||||||
visible: tabsModel.count > 1
|
padding: innerPadding
|
||||||
enabled: visible
|
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
onClicked: tabsRoot.closeTab(index)
|
onClicked: tabsRoot.closeTab(index)
|
||||||
}
|
}
|
||||||
@@ -96,6 +102,18 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ToolButton {
|
||||||
|
id: addTabButton
|
||||||
|
text: "+"
|
||||||
|
focusPolicy: Qt.NoFocus
|
||||||
|
Layout.fillHeight: true
|
||||||
|
padding: innerPadding
|
||||||
|
Layout.alignment: Qt.AlignVCenter
|
||||||
|
onClicked: tabsRoot.addTab()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StackLayout {
|
StackLayout {
|
||||||
id: stack
|
id: stack
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
@@ -111,10 +129,9 @@ Item {
|
|||||||
activate()
|
activate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onTitleChanged: tabsModel.setProperty(index, "title", title)
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
onTitleChanged: tabsModel.setProperty(index, "title", title)
|
|
||||||
onSessionFinished: tabsRoot.closeTab(index)
|
onSessionFinished: tabsRoot.closeTab(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ ApplicationWindow {
|
|||||||
|
|
||||||
color: "#00000000"
|
color: "#00000000"
|
||||||
|
|
||||||
title: terminalTabs.title || qsTr(appSettings.wintitle)
|
title: terminalTabs.currentTitle
|
||||||
|
|
||||||
Action {
|
Action {
|
||||||
id: showMenubarAction
|
id: showMenubarAction
|
||||||
|
|||||||
Reference in New Issue
Block a user