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 {
|
||||
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)
|
||||
property alias currentIndex: tabBar.currentIndex
|
||||
readonly property int count: tabsModel.count
|
||||
property var hostWindow
|
||||
|
||||
function addTab() {
|
||||
tabsModel.append({ title: qsTr("Tab %1").arg(tabsModel.count + 1) })
|
||||
tabsModel.append({ title: "" })
|
||||
tabBar.currentIndex = tabsModel.count - 1
|
||||
}
|
||||
|
||||
@@ -42,9 +43,7 @@ Item {
|
||||
}
|
||||
|
||||
tabsModel.remove(index)
|
||||
if (tabBar.currentIndex >= tabsModel.count) {
|
||||
tabBar.currentIndex = tabsModel.count - 1
|
||||
}
|
||||
tabBar.currentIndex = Math.min(tabBar.currentIndex, tabsModel.count - 1)
|
||||
}
|
||||
|
||||
ListModel {
|
||||
@@ -57,15 +56,23 @@ Item {
|
||||
anchors.fill: parent
|
||||
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 {
|
||||
id: tabBar
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
focusPolicy: Qt.NoFocus
|
||||
visible: tabsModel.count > 1
|
||||
|
||||
background: Rectangle {
|
||||
color: palette.window
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: tabsModel
|
||||
@@ -73,8 +80,8 @@ Item {
|
||||
id: tabButton
|
||||
contentItem: RowLayout {
|
||||
anchors.fill: parent
|
||||
anchors { leftMargin: 6; rightMargin: 6 }
|
||||
spacing: 6
|
||||
anchors { leftMargin: innerPadding; rightMargin: innerPadding }
|
||||
spacing: innerPadding
|
||||
|
||||
Label {
|
||||
text: model.title
|
||||
@@ -86,8 +93,7 @@ Item {
|
||||
ToolButton {
|
||||
text: "\u00d7"
|
||||
focusPolicy: Qt.NoFocus
|
||||
visible: tabsModel.count > 1
|
||||
enabled: visible
|
||||
padding: innerPadding
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
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 {
|
||||
id: stack
|
||||
Layout.fillWidth: true
|
||||
@@ -111,10 +129,9 @@ Item {
|
||||
activate()
|
||||
}
|
||||
}
|
||||
|
||||
onTitleChanged: tabsModel.setProperty(index, "title", title)
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
onTitleChanged: tabsModel.setProperty(index, "title", title)
|
||||
onSessionFinished: tabsRoot.closeTab(index)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ ApplicationWindow {
|
||||
|
||||
color: "#00000000"
|
||||
|
||||
title: terminalTabs.title || qsTr(appSettings.wintitle)
|
||||
title: terminalTabs.currentTitle
|
||||
|
||||
Action {
|
||||
id: showMenubarAction
|
||||
|
||||
Reference in New Issue
Block a user