Commit 10920771 authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Use a Loader for deferring creation of dialogs in main files

Several dialogs are being constructed during startup, while we do not
really need them until they actually are about to be shown. Do the same
trick d_ed did for the NewStuff dialog and move them into loaders that
are activated on demand.
parent 3582f4b0
......@@ -27,7 +27,6 @@ Kirigami.ApplicationWindow {
id: pagePoolObject
}
globalDrawer: Kirigami.GlobalDrawer {
id: globalDrawer
......@@ -160,44 +159,41 @@ Kirigami.ApplicationWindow {
]
}
Page.PageDialog {
Page.DialogLoader {
id: pageDialog
title: i18nc("@window:title", "Add New Page")
onAccepted: {
var fileName = name.toLowerCase().replace(" ", "_");
var newPage = pagesModel.addPage(fileName, {title: name, icon: iconName, margin: margin})
var row = newPage.insertChild(0, {name: "row-0", isTitle: false, title: ""})
var column = row.insertChild(0, {name: "column-0", showBackground: true})
column.insertChild(0, {name: "section-0", isSeparator: false})
newPage.savePage()
const pageAction = Array.from(globalDrawer.actions).find(action => action.pageData.fileName == newPage.fileName)
pageAction.trigger()
app.pageStack.currentItem.edit = true
sourceComponent: Page.PageDialog {
title: i18nc("@window:title", "Add New Page")
visible: true
onAccepted: {
var fileName = name.toLowerCase().replace(" ", "_");
var newPage = pagesModel.addPage(fileName, {title: name, icon: iconName, margin: margin})
var row = newPage.insertChild(0, {name: "row-0", isTitle: false, title: ""})
var column = row.insertChild(0, {name: "column-0", showBackground: true})
column.insertChild(0, {name: "section-0", isSeparator: false})
newPage.savePage()
const pageAction = Array.from(globalDrawer.actions).find(action => action.pageData.fileName == newPage.fileName)
pageAction.trigger()
app.pageStack.currentItem.edit = true
}
}
}
Page.PageSortDialog {
Page.DialogLoader {
id: pageSortDialog
title: i18nc("@window:title", "Edit Pages")
model: pagesModel
}
Loader {
id: getNewPageDialog
function open() {
if (item) {
item.open()
} else {
active = true;
}
sourceComponent: Page.PageSortDialog {
title: i18nc("@window:title", "Edit Pages")
model: pagesModel
visible: true
}
}
active: false
asynchronous: true
Page.DialogLoader {
id: getNewPageDialog
sourceComponent: NewStuff.Dialog {
configFile: "plasma-systemmonitor.knsrc"
......
......@@ -27,6 +27,7 @@ set(page_QML
EditorToolBar.qml
MoveButton.qml
PageSortDialog.qml
DialogLoader.qml
)
add_library(PagePlugin SHARED ${page_SRCS})
......
/*
* SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import QtQuick 2.15
Loader {
width: parent.width
height: parent.height
function open() {
if (item) {
item.open()
} else {
active = true;
}
}
active: false
asynchronous: true
}
......@@ -195,26 +195,28 @@ Kirigami.ScrollablePage {
}
}
PageDialog {
DialogLoader {
id: pageDialog
title: i18nc("@title:window %1 is page title", "Configure Page \"%1\"", page.pageData.title)
acceptText: i18nc("@action:button", "Save")
acceptIcon: "document-save"
onAboutToShow: {
name = page.pageData.title
iconName = page.pageData.icon
margin = page.pageData.margin
pageData = page.pageData
actionsFace = page.pageData.actionsFace ? page.pageData.actionsFace : ""
}
sourceComponent: PageDialog {
title: i18nc("@title:window %1 is page title", "Configure Page \"%1\"", page.pageData.title)
acceptText: i18nc("@action:button", "Save")
acceptIcon: "document-save"
onAboutToShow: {
name = page.pageData.title
iconName = page.pageData.icon
margin = page.pageData.margin
pageData = page.pageData
actionsFace = page.pageData.actionsFace ? page.pageData.actionsFace : ""
}
onAccepted: {
pageData.title = name
pageData.icon = iconName
pageData.margin = margin
pageData.actionsFace = actionsFace
onAccepted: {
pageData.title = name
pageData.icon = iconName
pageData.margin = margin
pageData.actionsFace = actionsFace
}
}
}
......
......@@ -69,34 +69,41 @@ Kirigami.ScrollablePage {
}
]
LoadPresetDialog {
DialogLoader {
id: loadPresetDialog
sourceComponent: LoadPresetDialog {
controller: loader.controller
controller: loader.controller
onAccepted: {
loader.controller.title = selectedTitle;
if (selectedFace) {
loader.controller.faceId = selectedFace
onAccepted: {
loader.controller.title = selectedTitle;
if (selectedFace) {
loader.controller.faceId = selectedFace
}
loader.controller.loadPreset(selectedPreset);
message.text = i18nc("@info:status %1 is preset name", "Loaded preset %1.", selectedTitle);
message.visible = true
}
loader.controller.loadPreset(selectedPreset);
message.text = i18nc("@info:status %1 is preset name", "Loaded preset %1.", selectedTitle);
message.visible = true
}
}
NewStuff.Dialog {
DialogLoader {
id: newPresetDialog
downloadNewWhat: i18nc("@title:window", "Presets")
configFile: "systemmonitor-presets.knsrc"
onChangedEntriesChanged: loader.controller.availablePresetsModel.reload();
sourceComponent: NewStuff.Dialog {
downloadNewWhat: i18nc("@title:window", "Presets")
configFile: "systemmonitor-presets.knsrc"
onChangedEntriesChanged: loader.controller.availablePresetsModel.reload();
}
}
NewStuff.Dialog {
DialogLoader {
id: newFaceDialog
downloadNewWhat: i18nc("@title:window", "Display Styles")
configFile: "systemmonitor-faces.knsrc"
onChangedEntriesChanged: loader.controller.availableFacesModel.reload();
sourceComponent: NewStuff.Dialog {
id: newFaceDialog
downloadNewWhat: i18nc("@title:window", "Display Styles")
configFile: "systemmonitor-faces.knsrc"
onChangedEntriesChanged: loader.controller.availableFacesModel.reload();
}
}
ColumnLayout {
......
......@@ -19,3 +19,4 @@ LoadPresetDialog 1.0 LoadPresetDialog.qml
MoveButton 1.0 MoveButton.qml
PageSortDialog 1.0 PageSortDialog.qml
GetNewPageDialog 1.0 GetNewPageDialog.qml
DialogLoader 1.0 DialogLoader.qml
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