mirror of
https://github.com/Swordfish90/cool-retro-term.git
synced 2026-02-08 00:32:27 +00:00
Use single instance application to handle multiple windows.
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -2,3 +2,6 @@
|
||||
path = qmltermwidget
|
||||
url = https://github.com/Swordfish90/qmltermwidget
|
||||
branch = unstable
|
||||
[submodule "singleapplication"]
|
||||
path = singleapplication
|
||||
url = https://github.com/itay-grudev/SingleApplication.git
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
QT += qml quick widgets sql quickcontrols2
|
||||
DEFINES += QAPPLICATION_CLASS=QApplication
|
||||
TARGET = cool-retro-term
|
||||
|
||||
include(../singleapplication/singleapplication.pri)
|
||||
|
||||
DESTDIR = $$OUT_PWD/../
|
||||
|
||||
HEADERS += \
|
||||
fileio.h \
|
||||
monospacefontmanager.h
|
||||
|
||||
SOURCES = main.cpp \
|
||||
SOURCES += main.cpp \
|
||||
fileio.cpp \
|
||||
monospacefontmanager.cpp
|
||||
|
||||
|
||||
24
app/main.cpp
24
app/main.cpp
@@ -8,6 +8,8 @@
|
||||
#include <QIcon>
|
||||
#include <QQuickStyle>
|
||||
|
||||
#include <singleapplication.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -78,9 +80,14 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
QApplication app(argc, argv);
|
||||
SingleApplication app(argc, argv, true);
|
||||
app.setAttribute(Qt::AA_MacDontSwapCtrlAndMeta, true);
|
||||
|
||||
if (app.isSecondary()) {
|
||||
app.sendMessage("new-window");
|
||||
return 0;
|
||||
}
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
FileIO fileIO;
|
||||
MonospaceFontManager monospaceFontManager;
|
||||
@@ -135,5 +142,20 @@ int main(int argc, char *argv[])
|
||||
// Quit the application when the engine closes.
|
||||
QObject::connect((QObject*) &engine, SIGNAL(quit()), (QObject*) &app, SLOT(quit()));
|
||||
|
||||
auto requestNewWindow = [&engine]() {
|
||||
if (engine.rootObjects().isEmpty())
|
||||
return;
|
||||
|
||||
QObject *rootObject = engine.rootObjects().constFirst();
|
||||
QMetaObject::invokeMethod(rootObject, "createWindow", Qt::QueuedConnection);
|
||||
};
|
||||
|
||||
QObject::connect(&app, &SingleApplication::receivedMessage, &app,
|
||||
[&requestNewWindow](quint32 instanceId, QByteArray message) {
|
||||
Q_UNUSED(instanceId);
|
||||
if (message.isEmpty() || message == QByteArray("new-window"))
|
||||
requestNewWindow();
|
||||
});
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ ApplicationWindow {
|
||||
id: settings_window
|
||||
title: qsTr("Settings")
|
||||
width: 640
|
||||
height: 480
|
||||
height: 520
|
||||
|
||||
Item {
|
||||
anchors { fill: parent; }
|
||||
|
||||
@@ -44,10 +44,6 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
function closeCurrentTab() {
|
||||
closeTab(tabBar.currentIndex)
|
||||
}
|
||||
|
||||
ListModel {
|
||||
id: tabsModel
|
||||
}
|
||||
|
||||
@@ -148,12 +148,6 @@ ApplicationWindow {
|
||||
text: qsTr("New Tab")
|
||||
onTriggered: terminalTabs.addTab()
|
||||
}
|
||||
Action {
|
||||
id: closeTabAction
|
||||
text: qsTr("Close Tab")
|
||||
enabled: terminalTabs.count > 1
|
||||
onTriggered: terminalTabs.closeCurrentTab()
|
||||
}
|
||||
TerminalTabs {
|
||||
id: terminalTabs
|
||||
width: parent.width
|
||||
|
||||
@@ -32,19 +32,15 @@ Menu {
|
||||
action: showsettingsAction
|
||||
}
|
||||
|
||||
MenuSeparator {}
|
||||
Menu {
|
||||
title: qsTr("Tabs")
|
||||
title: qsTr("File")
|
||||
MenuItem {
|
||||
action: newWindowAction
|
||||
}
|
||||
MenuItem {
|
||||
action: newTabAction
|
||||
}
|
||||
MenuItem {
|
||||
action: closeTabAction
|
||||
}
|
||||
}
|
||||
|
||||
Menu {
|
||||
title: qsTr("File")
|
||||
MenuSeparator {}
|
||||
MenuItem {
|
||||
action: quitAction
|
||||
}
|
||||
|
||||
@@ -31,6 +31,12 @@ MenuBar {
|
||||
shortcut: newWindowAction.shortcut
|
||||
onTriggered: newWindowAction.trigger()
|
||||
}
|
||||
MenuItem {
|
||||
text: newTabAction.text
|
||||
shortcut: newTabAction.shortcut
|
||||
onTriggered: newTabAction.trigger()
|
||||
}
|
||||
MenuSeparator {}
|
||||
MenuItem {
|
||||
text: quitAction.text
|
||||
onTriggered: quitAction.trigger()
|
||||
|
||||
@@ -28,14 +28,4 @@ Menu {
|
||||
MenuItem {
|
||||
action: pasteAction
|
||||
}
|
||||
MenuSeparator {}
|
||||
Menu {
|
||||
title: qsTr("Tabs")
|
||||
MenuItem {
|
||||
action: newTabAction
|
||||
}
|
||||
MenuItem {
|
||||
action: closeTabAction
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,10 @@ MenuBar {
|
||||
MenuItem {
|
||||
action: newWindowAction
|
||||
}
|
||||
MenuItem {
|
||||
action: newTabAction
|
||||
}
|
||||
MenuSeparator {}
|
||||
MenuItem {
|
||||
action: quitAction
|
||||
}
|
||||
|
||||
@@ -9,3 +9,8 @@ StartupNotify=true
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Keywords=shell;prompt;command;commandline;
|
||||
Actions=NewWindow;
|
||||
|
||||
[Desktop Action NewWindow]
|
||||
Name=New Window
|
||||
Exec=cool-retro-term
|
||||
|
||||
1
singleapplication
Submodule
1
singleapplication
Submodule
Submodule singleapplication added at a8da87d782
Reference in New Issue
Block a user