diff --git a/.gitmodules b/.gitmodules index e1c714f..53e7bea 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/app/app.pro b/app/app.pro index 3256b1a..ca301de 100644 --- a/app/app.pro +++ b/app/app.pro @@ -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 diff --git a/app/main.cpp b/app/main.cpp index 448ba19..f02d20f 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -8,6 +8,8 @@ #include #include +#include + #include #include @@ -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(); } diff --git a/app/qml/SettingsWindow.qml b/app/qml/SettingsWindow.qml index 8f5b22e..eae71ff 100644 --- a/app/qml/SettingsWindow.qml +++ b/app/qml/SettingsWindow.qml @@ -30,7 +30,7 @@ ApplicationWindow { id: settings_window title: qsTr("Settings") width: 640 - height: 480 + height: 520 Item { anchors { fill: parent; } diff --git a/app/qml/TerminalTabs.qml b/app/qml/TerminalTabs.qml index 6fe61cb..0c87d36 100644 --- a/app/qml/TerminalTabs.qml +++ b/app/qml/TerminalTabs.qml @@ -44,10 +44,6 @@ Item { } } - function closeCurrentTab() { - closeTab(tabBar.currentIndex) - } - ListModel { id: tabsModel } diff --git a/app/qml/TerminalWindow.qml b/app/qml/TerminalWindow.qml index fd5a668..53559a6 100644 --- a/app/qml/TerminalWindow.qml +++ b/app/qml/TerminalWindow.qml @@ -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 diff --git a/app/qml/menus/FullContextMenu.qml b/app/qml/menus/FullContextMenu.qml index c22d1f8..3cb3aa8 100644 --- a/app/qml/menus/FullContextMenu.qml +++ b/app/qml/menus/FullContextMenu.qml @@ -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 } diff --git a/app/qml/menus/OSXMenu.qml b/app/qml/menus/OSXMenu.qml index 6faa917..0cd2b05 100644 --- a/app/qml/menus/OSXMenu.qml +++ b/app/qml/menus/OSXMenu.qml @@ -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() diff --git a/app/qml/menus/ShortContextMenu.qml b/app/qml/menus/ShortContextMenu.qml index 95cef0e..9d8f63b 100644 --- a/app/qml/menus/ShortContextMenu.qml +++ b/app/qml/menus/ShortContextMenu.qml @@ -28,14 +28,4 @@ Menu { MenuItem { action: pasteAction } - MenuSeparator {} - Menu { - title: qsTr("Tabs") - MenuItem { - action: newTabAction - } - MenuItem { - action: closeTabAction - } - } } diff --git a/app/qml/menus/WindowMenu.qml b/app/qml/menus/WindowMenu.qml index 145af97..e3b9377 100644 --- a/app/qml/menus/WindowMenu.qml +++ b/app/qml/menus/WindowMenu.qml @@ -29,6 +29,10 @@ MenuBar { MenuItem { action: newWindowAction } + MenuItem { + action: newTabAction + } + MenuSeparator {} MenuItem { action: quitAction } diff --git a/cool-retro-term.desktop b/cool-retro-term.desktop index 8c0d278..e9af133 100644 --- a/cool-retro-term.desktop +++ b/cool-retro-term.desktop @@ -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 diff --git a/singleapplication b/singleapplication new file mode 160000 index 0000000..a8da87d --- /dev/null +++ b/singleapplication @@ -0,0 +1 @@ +Subproject commit a8da87d78238ac9ac92d2cda41793d4879c188b3