RibbonWindow: Add windowStatus property.

1. RibbonWindow.Status.Stardard: Create new window instance whether it already has one or not.
2. RibbonWindow.Status.SingleTask: If it already has one instance, the current instance will be closed and a new one will be created.
2. RibbonWindow.Status.SingleInstance: If it already has one instance, the current instance will be activated, no new instance will be created.
This commit is contained in:
Mentalflow 2024-04-20 21:54:29 +08:00
parent 6419045f0e
commit 56f21299f0
Signed by: Mentalflow
GPG Key ID: 5AE68D4401A2EE71
1 changed files with 23 additions and 10 deletions

View File

@ -5,7 +5,13 @@ import org.wangwenx190.FramelessHelper
Window { Window {
id:window id:window
minimumWidth: title_bar.minimumWidth minimumWidth: title_bar.minimumWidth
enum Status {
Stardard,
SingleTask,
SingleInstance
}
default property alias content: container.data default property alias content: container.data
property int windowStatus: RibbonWindow.Status.Stardard
property alias window_items: window_items property alias window_items: window_items
property alias title_bar: titleBar property alias title_bar: titleBar
property alias popup: pop property alias popup: pop
@ -114,22 +120,29 @@ Window {
function show_window(window_url, args){ function show_window(window_url, args){
let sub_windows = RibbonUI.windowsSet let sub_windows = RibbonUI.windowsSet
if (sub_windows.hasOwnProperty(window_url)) if (sub_windows.hasOwnProperty(window_url)&&sub_windows[window_url]['windowStatus'] !== RibbonWindow.Status.Stardard)
{ {
if (args && Object.keys(args).length) if (sub_windows[window_url]['windowStatus'] === RibbonWindow.Status.SingleInstance)
{ {
for (let arg in args){ if (args && Object.keys(args).length)
sub_windows[window_url][arg] = args[arg] {
for (let arg in args){
sub_windows[window_url][arg] = args[arg]
}
} }
if (!sub_windows[window_url].visible)
{
sub_windows[window_url].show()
}
sub_windows[window_url].raise()
sub_windows[window_url].requestActivate()
RibbonUI.windowsSet = sub_windows
return
} }
if (!sub_windows[window_url].visible) else
{ {
sub_windows[window_url].show() sub_windows[window_url].close()
} }
sub_windows[window_url].raise()
sub_windows[window_url].requestActivate()
RibbonUI.windowsSet = sub_windows
return
} }
var component = Qt.createComponent(window_url, Component.PreferSynchronous, undefined); var component = Qt.createComponent(window_url, Component.PreferSynchronous, undefined);
if (component.status === Component.Ready) { if (component.status === Component.Ready) {