diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index b3a87bf9..bf081aa3 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -204,6 +204,26 @@ void MainWindowViewer::createActions() openAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(OPEN_ACTION_Y)); connect(openAction, SIGNAL(triggered()), this, SLOT(open())); +#ifdef Q_OS_MAC + newInstanceAction = new QAction(tr("New instance"), this); + newInstanceAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(NEW_INSTANCE_ACTION_Y)); + connect(newInstanceAction, &QAction::triggered, + [=]() { + QStringList possiblePaths { QDir::cleanPath(QCoreApplication::applicationDirPath() + "/../../../") }; + possiblePaths += QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation); + + for (auto &&ypath : possiblePaths) { + QString yacreaderPath = QDir::cleanPath(ypath + "/YACReader.app"); + if (QFileInfo(yacreaderPath).exists()) { + QStringList parameters { "-n", "-a", yacreaderPath }; + QProcess::startDetached("open", parameters); + break; + } + } + }); + newInstanceAction->setData(NEW_INSTANCE_ACTION_Y); +#endif + openFolderAction = new QAction(tr("Open Folder"), this); openFolderAction->setIcon(QIcon(":/images/viewer_toolbar/openFolder.png")); openFolderAction->setToolTip(tr("Open image folder")); @@ -645,6 +665,8 @@ void MainWindowViewer::createToolBars() //file auto fileMenu = new QMenu(tr("File")); + fileMenu->addAction(newInstanceAction); + fileMenu->addSeparator(); fileMenu->addAction(openAction); fileMenu->addAction(openLatestComicAction); fileMenu->addAction(openFolderAction); @@ -1258,7 +1280,11 @@ void MainWindowViewer::setUpShortcutsManagement() << showFlowAction << toggleFullScreenAction << toggleToolbarsAction - << showEditShortcutsAction); + << showEditShortcutsAction +#ifdef Q_OS_MAC + << newInstanceAction +#endif + ); allActions << tmpList; diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index 6d230611..21ad8cdd 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -106,6 +106,9 @@ private: //! Actions QAction *openAction; +#ifdef Q_OS_MAC + QAction *newInstanceAction; //needed in macos +#endif QAction *openFolderAction; QAction *openLatestComicAction; QList recentFilesActionList; diff --git a/shortcuts_management/shortcuts_manager.cpp b/shortcuts_management/shortcuts_manager.cpp index 6acda3a7..541e4efd 100644 --- a/shortcuts_management/shortcuts_manager.cpp +++ b/shortcuts_management/shortcuts_manager.cpp @@ -74,6 +74,10 @@ void ShortcutsManager::initDefaultShorcuts() defaultShorcuts.insert(ZOOM_IN_MGLASS_ACTION_Y, Qt::Key_Asterisk); defaultShorcuts.insert(ZOOM_OUT_MGLASS_ACTION_Y, Qt::Key_Underscore); +#ifdef Q_OS_MAC + defaultShorcuts.insert(NEW_INSTANCE_ACTION_Y, Qt::Key_N); +#endif + #endif } diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h index abca8918..2aee76a5 100644 --- a/shortcuts_management/shortcuts_manager.h +++ b/shortcuts_management/shortcuts_manager.h @@ -85,6 +85,7 @@ public: //ACTION NAMES YACReader #define OPEN_ACTION_Y "OPEN_ACTION_Y" +#define NEW_INSTANCE_ACTION_Y "NEW_INSTANCE_ACTION_Y" #define OPEN_FOLDER_ACTION_Y "OPEN_FOLDER_ACTION_Y" #define SAVE_IMAGE_ACTION_Y "SAVE_IMAGE_ACTION_Y" #define OPEN_PREVIOUS_COMIC_ACTION_Y "OPEN_PREVIOUS_COMIC_ACTION_Y"