Commit 9c2d8b76 authored by David Redondo's avatar David Redondo 🏎
Browse files

Allow specifying which page to open on start

Adds a combobox to the page edit dialog where one can choose with which
page to start or always open the last opened page.
BUG:429417
CCBUG:435279
FIXED-IN:5.22
parent 5dbbfbe2
......@@ -50,10 +50,6 @@ public:
{
m_pageId = parser.value("page-id");
m_pageName = parser.value("page-name");
if (m_pageId.isEmpty() && m_pageName.isEmpty()) {
m_pageId = QStringLiteral("overview.page");
}
}
QVariant aboutData() const
......
......@@ -145,12 +145,19 @@ Kirigami.ApplicationWindow {
pagePool: pagePoolObject
pageData: model.data
visible: !model.hidden
onTriggered: {
config.lastVisitedPage = model.fileName
}
Component.onCompleted: {
if (CommandLineArguments.pageId && model.fileName == CommandLineArguments.pageId) {
trigger()
} else if (CommandLineArguments.pageName && model.title == CommandLineArguments.pageName) {
trigger()
} else if (config.startPage == model.fileName) {
trigger()
} else if (config.startPage == "" && config.lastVisitedPage == model.fileName) {
trigger()
}
}
}
......@@ -212,6 +219,10 @@ Kirigami.ApplicationWindow {
sourceComponent: Page.PageSortDialog {
title: i18nc("@window:title", "Edit Pages")
model: pagesModel
startPage: config.startPage
onAccepted: {
config.startPage = startPage
}
}
}
......@@ -252,6 +263,8 @@ Kirigami.ApplicationWindow {
property alias sidebarCollapsed: globalDrawer.collapsed
property alias pageOrder: pagesModel.pageOrder
property alias hiddenPages: pagesModel.hiddenPages
property string startPage
property string lastVisitedPage
}
Component {
......
......@@ -9,11 +9,14 @@ import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import org.kde.kirigami 2.12 as Kirigami
import org.kde.kitemmodels 1.0 as KItemModels
import org.kde.ksysguard.page 1.0 as Page
Dialog {
property alias model : sortModel.sourceModel
property string startPage
modal: true
focus: true
......@@ -33,10 +36,12 @@ Dialog {
onAboutToShow: {
sortModel.sourceModel = model
startPageBox.currentIndex = startPageBox.indexOfValue(startPage)
}
onAccepted: {
sortModel.applyChangesToSourceModel()
startPage = startPageBox.currentValue
}
Kirigami.Theme.colorSet: Kirigami.Theme.View
......@@ -192,4 +197,64 @@ Dialog {
}
Kirigami.Separator { Layout.fillWidth: true; }
}
footer: DialogButtonBox {
// Use an AbstractButton so the button box includes it
AbstractButton {
implicitWidth: childrenRect.width
DialogButtonBox.buttonRole: DialogButtonBox.ActionRole
RowLayout {
Label {
text: i18nc("@label:listbox", "Start with:")
}
ComboBox {
id: startPageBox
textRole: "title"
valueRole: "fileName"
model: createModel()
function createModel() {
var result = [{fileName: "", title: i18n("Last Visited Page"), icon: "clock"}];
for (var i = 0; i < sortModel.rowCount(); ++i) {
const index = sortModel.index(i, 0)
if (sortModel.data(index, Page.PagesModel.HiddenRole)) {
continue
}
if (sortModel.data(index, Page.PageSortModel.ShouldRemoveFilesRole)
&& sortModel.data(index, Page.PagesModel.FilesWriteableRole) == Page.PagesModel.AllWriteable) {
continue
}
result.push({fileName: sortModel.data(index, Page.PagesModel.FileNameRole),
title: sortModel.data(index, Page.PagesModel.TitleRole),
icon: sortModel.data(index, Page.PagesModel.IconRole)})
}
return result
}
Connections {
target: sortModel
function onDataChanged() { startPageBox.model = startPageBox.createModel() }
function onRowsMoved() { startPageBox.model = startPageBox.createModel() }
}
delegate: ItemDelegate {
width: parent.width
highlighted: startPageBox.highlightedIndex == index
contentItem: RowLayout {
Kirigami.Icon {
color: highlighted ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
source: modelData.icon
Layout.preferredHeight: Kirigami.Units.iconSizes.small
Layout.preferredWidth: Kirigami.Units.iconSizes.small
}
Label {
text: modelData.title
color: highlighted ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
Layout.fillWidth: true
}
}
}
}
}
}
}
}
......@@ -28,5 +28,9 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
</entry>
<entry name="hiddenPages" type="StringList">
</entry>
<entry name="startPage" type="String">
<default>overview.page</default>
</entry>
<entry name="lastVisitedPage" type="String"/>
</group>
</kcfg>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment