ollie/kde/gui/NewSessionDialog.qml

177 lines
5.0 KiB
QML

// NewSessionDialog.qml — Dialog for creating a new session
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
Dialog {
id: root
title: "New Session"
width: 380
modal: false
x: (parent ? (parent.width - width) / 2 : 0)
y: (parent ? (parent.height - height) / 2 : 0)
property bool dragging: false
// Keep the non-modal dialog visually separate from the application behind it.
background: Item {
// A dark offset layer reads as a shadow instead of a bright outline.
Rectangle {
x: 4
y: 6
width: parent.width
height: parent.height
color: Qt.rgba(0, 0, 0, 0.28)
radius: 4
}
Rectangle {
anchors.fill: parent
color: theme.windowColor
border.color: theme.dialogOutlineColor
border.width: 3
radius: 4
Rectangle {
anchors.fill: parent
anchors.margins: 3
color: "transparent"
border.color: theme.lightColor
border.width: 1
radius: 3
}
}
}
header: Rectangle {
implicitHeight: 36
color: theme.buttonColor
Text {
anchors.centerIn: parent
text: root.title
color: theme.buttonTextColor
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.SizeAllCursor
property point pressPosition
onPressed: pressPosition = Qt.point(mouse.x, mouse.y)
onPositionChanged: if (pressed) {
root.x += mouse.x - pressPosition.x
root.y += mouse.y - pressPosition.y
}
}
}
signal sessionCreated()
contentItem: ColumnLayout {
spacing: 16
Layout.margins: 16
Label {
id: errorLabel
Layout.fillWidth: true
visible: text !== ""
color: "red"
wrapMode: Text.Wrap
}
RowLayout {
Layout.fillWidth: true
Label { text: "Name:"; Layout.preferredWidth: 80 }
TextField {
id: nameField
Layout.fillWidth: true
placeholderText: "(auto-generated)"
}
}
RowLayout {
Layout.fillWidth: true
Label { text: "Directory:"; Layout.preferredWidth: 80 }
TextField {
id: cwdField
Layout.fillWidth: true
placeholderText: "/path/to/project"
}
Button {
text: "Browse..."
onClicked: {
var folder = theme.chooseFolder("Select Working Directory", cwdField.text || "")
if (folder !== "")
cwdField.text = folder
}
}
}
RowLayout {
Layout.fillWidth: true
Label { text: "Remote:"; Layout.preferredWidth: 80 }
TextField {
id: remoteField
Layout.fillWidth: true
placeholderText: "user@host (optional)"
}
}
RowLayout {
Layout.fillWidth: true
Label { text: "Workflow:"; Layout.preferredWidth: 80 }
ComboBox {
id: workflowCombo
Layout.fillWidth: true
enabled: ollie.workflowsLoaded
model: ollie.availableWorkflows
currentIndex: {
var idx = ollie.availableWorkflows.indexOf("conductor")
return idx >= 0 ? idx : 0
}
}
}
Component.onCompleted: {
if (!ollie.workflowsLoaded) ollie.loadWorkflows()
}
}
footer: RowLayout {
Layout.fillWidth: true
Item { Layout.fillWidth: true }
Button {
id: okButton
text: "OK"
onClicked: {
errorLabel.text = ""
var name = nameField.text.trim()
var remote = remoteField.text.trim()
var cwd = cwdField.text.trim()
var workflow = workflowCombo.currentText
var err = ollie.createSession(name, remote, cwd, workflow)
if (err === "") {
ollie.refreshSessions()
root.sessionCreated()
root.close()
} else {
errorLabel.text = err
}
}
}
Button {
text: "Cancel"
onClicked: root.close()
}
}
// Do not request keyboard focus while opening. Clicking a field still focuses it.
focus: false
onOpened: {
errorLabel.text = ""
nameField.text = ""
cwdField.text = ""
remoteField.text = ""
var idx = ollie.availableWorkflows.indexOf("conductor")
workflowCombo.currentIndex = idx >= 0 ? idx : 0
}
}