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
|
path = qmltermwidget
|
||||||
url = https://github.com/Swordfish90/qmltermwidget
|
url = https://github.com/Swordfish90/qmltermwidget
|
||||||
branch = unstable
|
branch = unstable
|
||||||
|
[submodule "singleapplication"]
|
||||||
|
path = singleapplication
|
||||||
|
url = https://github.com/itay-grudev/SingleApplication.git
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
QT += qml quick widgets sql quickcontrols2
|
QT += qml quick widgets sql quickcontrols2
|
||||||
|
DEFINES += QAPPLICATION_CLASS=QApplication
|
||||||
TARGET = cool-retro-term
|
TARGET = cool-retro-term
|
||||||
|
|
||||||
|
include(../singleapplication/singleapplication.pri)
|
||||||
|
|
||||||
DESTDIR = $$OUT_PWD/../
|
DESTDIR = $$OUT_PWD/../
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
fileio.h \
|
fileio.h \
|
||||||
monospacefontmanager.h
|
monospacefontmanager.h
|
||||||
|
|
||||||
SOURCES = main.cpp \
|
SOURCES += main.cpp \
|
||||||
fileio.cpp \
|
fileio.cpp \
|
||||||
monospacefontmanager.cpp
|
monospacefontmanager.cpp
|
||||||
|
|
||||||
|
|||||||
24
app/main.cpp
24
app/main.cpp
@@ -8,6 +8,8 @@
|
|||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QQuickStyle>
|
#include <QQuickStyle>
|
||||||
|
|
||||||
|
#include <singleapplication.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -78,9 +80,14 @@ int main(int argc, char *argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QApplication app(argc, argv);
|
SingleApplication app(argc, argv, true);
|
||||||
app.setAttribute(Qt::AA_MacDontSwapCtrlAndMeta, true);
|
app.setAttribute(Qt::AA_MacDontSwapCtrlAndMeta, true);
|
||||||
|
|
||||||
|
if (app.isSecondary()) {
|
||||||
|
app.sendMessage("new-window");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
FileIO fileIO;
|
FileIO fileIO;
|
||||||
MonospaceFontManager monospaceFontManager;
|
MonospaceFontManager monospaceFontManager;
|
||||||
@@ -135,5 +142,20 @@ int main(int argc, char *argv[])
|
|||||||
// Quit the application when the engine closes.
|
// Quit the application when the engine closes.
|
||||||
QObject::connect((QObject*) &engine, SIGNAL(quit()), (QObject*) &app, SLOT(quit()));
|
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();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ ApplicationWindow {
|
|||||||
id: settings_window
|
id: settings_window
|
||||||
title: qsTr("Settings")
|
title: qsTr("Settings")
|
||||||
width: 640
|
width: 640
|
||||||
height: 480
|
height: 520
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
anchors { fill: parent; }
|
anchors { fill: parent; }
|
||||||
|
|||||||
@@ -44,10 +44,6 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeCurrentTab() {
|
|
||||||
closeTab(tabBar.currentIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
ListModel {
|
ListModel {
|
||||||
id: tabsModel
|
id: tabsModel
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,12 +148,6 @@ ApplicationWindow {
|
|||||||
text: qsTr("New Tab")
|
text: qsTr("New Tab")
|
||||||
onTriggered: terminalTabs.addTab()
|
onTriggered: terminalTabs.addTab()
|
||||||
}
|
}
|
||||||
Action {
|
|
||||||
id: closeTabAction
|
|
||||||
text: qsTr("Close Tab")
|
|
||||||
enabled: terminalTabs.count > 1
|
|
||||||
onTriggered: terminalTabs.closeCurrentTab()
|
|
||||||
}
|
|
||||||
TerminalTabs {
|
TerminalTabs {
|
||||||
id: terminalTabs
|
id: terminalTabs
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
|||||||
@@ -32,19 +32,15 @@ Menu {
|
|||||||
action: showsettingsAction
|
action: showsettingsAction
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuSeparator {}
|
|
||||||
Menu {
|
Menu {
|
||||||
title: qsTr("Tabs")
|
title: qsTr("File")
|
||||||
|
MenuItem {
|
||||||
|
action: newWindowAction
|
||||||
|
}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
action: newTabAction
|
action: newTabAction
|
||||||
}
|
}
|
||||||
MenuItem {
|
MenuSeparator {}
|
||||||
action: closeTabAction
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Menu {
|
|
||||||
title: qsTr("File")
|
|
||||||
MenuItem {
|
MenuItem {
|
||||||
action: quitAction
|
action: quitAction
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ MenuBar {
|
|||||||
shortcut: newWindowAction.shortcut
|
shortcut: newWindowAction.shortcut
|
||||||
onTriggered: newWindowAction.trigger()
|
onTriggered: newWindowAction.trigger()
|
||||||
}
|
}
|
||||||
|
MenuItem {
|
||||||
|
text: newTabAction.text
|
||||||
|
shortcut: newTabAction.shortcut
|
||||||
|
onTriggered: newTabAction.trigger()
|
||||||
|
}
|
||||||
|
MenuSeparator {}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: quitAction.text
|
text: quitAction.text
|
||||||
onTriggered: quitAction.trigger()
|
onTriggered: quitAction.trigger()
|
||||||
|
|||||||
@@ -28,14 +28,4 @@ Menu {
|
|||||||
MenuItem {
|
MenuItem {
|
||||||
action: pasteAction
|
action: pasteAction
|
||||||
}
|
}
|
||||||
MenuSeparator {}
|
|
||||||
Menu {
|
|
||||||
title: qsTr("Tabs")
|
|
||||||
MenuItem {
|
|
||||||
action: newTabAction
|
|
||||||
}
|
|
||||||
MenuItem {
|
|
||||||
action: closeTabAction
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ MenuBar {
|
|||||||
MenuItem {
|
MenuItem {
|
||||||
action: newWindowAction
|
action: newWindowAction
|
||||||
}
|
}
|
||||||
|
MenuItem {
|
||||||
|
action: newTabAction
|
||||||
|
}
|
||||||
|
MenuSeparator {}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
action: quitAction
|
action: quitAction
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,3 +9,8 @@ StartupNotify=true
|
|||||||
Terminal=false
|
Terminal=false
|
||||||
Type=Application
|
Type=Application
|
||||||
Keywords=shell;prompt;command;commandline;
|
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