From 9d97154a7a95b97b0bc4d95bbfdad67542b0f75e Mon Sep 17 00:00:00 2001 From: reionwong Date: Wed, 20 Oct 2021 17:55:17 +0800 Subject: [PATCH] Fix protection close dialog --- src/qml/ExitPromptDialog.qml | 28 +++++++++++++++++----------- src/qml/main.qml | 27 ++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/qml/ExitPromptDialog.qml b/src/qml/ExitPromptDialog.qml index f9d13f8..ead3c70 100644 --- a/src/qml/ExitPromptDialog.qml +++ b/src/qml/ExitPromptDialog.qml @@ -23,31 +23,37 @@ import QtQuick.Layouts 1.12 import QtQuick.Window 2.12 import FishUI 1.0 as FishUI -Dialog { +Window { id: control - modal: true + property var contentWidth: _mainLayout.implicitWidth + FishUI.Units.largeSpacing * 2 + property var contentHeight: _mainLayout.implicitHeight + FishUI.Units.largeSpacing * 2 - width: _mainLayout.implicitWidth + FishUI.Units.largeSpacing * 3 - height: _mainLayout.implicitHeight + FishUI.Units.largeSpacing * 3 + flags: Qt.WindowStaysOnTopHint + modality: Qt.WindowModal - x: (parent.width - control.width) / 2 - y: (parent.height - control.height) / 2 + width: contentWidth + height: contentHeight + minimumWidth: contentWidth + minimumHeight: contentHeight + maximumWidth: contentWidth + maximumHeight: contentHeight signal okBtnClicked + Rectangle { + anchors.fill: parent + color: FishUI.Theme.secondBackgroundColor + } + ColumnLayout { id: _mainLayout anchors.fill: parent spacing: FishUI.Units.largeSpacing - anchors.leftMargin: FishUI.Units.smallSpacing - anchors.rightMargin: FishUI.Units.smallSpacing - anchors.topMargin: FishUI.Units.smallSpacing - anchors.bottomMargin: FishUI.Units.smallSpacing + anchors.margins: FishUI.Units.largeSpacing Label { text: qsTr("Process is running, are you sure you want to quit?") - Layout.alignment: Qt.AlignHCenter } RowLayout { diff --git a/src/qml/main.qml b/src/qml/main.qml index b6f6f0f..6074dea 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -47,7 +47,16 @@ FishUI.Window { ExitPromptDialog { id: exitPrompt - onOkBtnClicked: Qt.quit() + + property var index: -1 + + onOkBtnClicked: { + if (index != -1) { + closeTab(index) + } else { + onOkBtnClicked: Qt.quit() + } + } } SettingsDialog { @@ -71,6 +80,7 @@ FishUI.Window { for (var i = 0; i < tabsModel.count; ++i) { var obj = tabsModel.get(i) if (obj.session.hasActiveProcess) { + exitPrompt.index = -1 exitPrompt.visible = true close.accepted = false break @@ -160,7 +170,7 @@ FishUI.Window { Layout.preferredWidth: 24 size: 24 source: "qrc:/images/" + (FishUI.Theme.darkMode || isCurrent ? "dark/" : "light/") + "close.svg" - onClicked: closeTab(index) + onClicked: closeProtection(index) } } } @@ -227,6 +237,17 @@ FishUI.Window { } } + function closeProtection(index) { + var obj = tabsModel.get(index) + if (obj.session.hasActiveProcess) { + exitPrompt.index = index + exitPrompt.visible = true + return + } + + closeTab(index) + } + function closeTab(index) { tabsModel.remove(index) @@ -243,7 +264,7 @@ FishUI.Window { } function closeCurrentTab() { - closeTab(_view.currentIndex) + closeProtection(_view.currentIndex) } function toggleTab() {