1
0
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:
Filippo Scognamiglio
2026-01-11 21:19:35 +01:00
parent 1c49b02763
commit 56144f757d
2 changed files with 52 additions and 35 deletions

View File

@@ -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,42 +56,61 @@ Item {
anchors.fill: parent anchors.fill: parent
spacing: 0 spacing: 0
TabBar { Rectangle {
id: tabBar id: tabRow
Layout.fillWidth: true Layout.fillWidth: true
focusPolicy: Qt.NoFocus height: rowLayout.implicitHeight
color: palette.window
visible: tabsModel.count > 1 visible: tabsModel.count > 1
background: Rectangle { RowLayout {
color: palette.window id: rowLayout
} anchors.fill: parent
spacing: 0
Repeater { TabBar {
model: tabsModel id: tabBar
TabButton { Layout.fillWidth: true
id: tabButton Layout.fillHeight: true
contentItem: RowLayout { focusPolicy: Qt.NoFocus
anchors.fill: parent
anchors { leftMargin: 6; rightMargin: 6 }
spacing: 6
Label { Repeater {
text: model.title model: tabsModel
elide: Text.ElideRight TabButton {
Layout.fillWidth: true id: tabButton
Layout.alignment: Qt.AlignVCenter contentItem: RowLayout {
} anchors.fill: parent
anchors { leftMargin: innerPadding; rightMargin: innerPadding }
spacing: innerPadding
ToolButton { Label {
text: "\u00d7" text: model.title
focusPolicy: Qt.NoFocus elide: Text.ElideRight
visible: tabsModel.count > 1 Layout.fillWidth: true
enabled: visible Layout.alignment: Qt.AlignVCenter
Layout.alignment: Qt.AlignVCenter }
onClicked: tabsRoot.closeTab(index)
ToolButton {
text: "\u00d7"
focusPolicy: Qt.NoFocus
padding: innerPadding
Layout.alignment: Qt.AlignVCenter
onClicked: tabsRoot.closeTab(index)
}
}
} }
} }
} }
ToolButton {
id: addTabButton
text: "+"
focusPolicy: Qt.NoFocus
Layout.fillHeight: true
padding: innerPadding
Layout.alignment: Qt.AlignVCenter
onClicked: tabsRoot.addTab()
}
} }
} }
@@ -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)
} }
} }

View File

@@ -72,7 +72,7 @@ ApplicationWindow {
color: "#00000000" color: "#00000000"
title: terminalTabs.title || qsTr(appSettings.wintitle) title: terminalTabs.currentTitle
Action { Action {
id: showMenubarAction id: showMenubarAction