diff --git a/src/editortab.h b/src/editortab.h --- a/src/editortab.h +++ b/src/editortab.h @@ -377,7 +377,7 @@ Q_SCRIPTABLE void srcFileOpenRequested(const QString& srcPath, int line); - void fileOpenRequested(const QString& filePath, const QString& str, const QString& ctxt); + void fileOpenRequested(const QString& filePath, const QString& str, const QString& ctxt, const bool setAsActive); //emitted when mainwindow is closed or another file is opened void fileClosed(); diff --git a/src/filesearch/filesearchtab.h b/src/filesearch/filesearchtab.h --- a/src/filesearch/filesearchtab.h +++ b/src/filesearch/filesearchtab.h @@ -101,8 +101,8 @@ void replaceJobDone(MassReplaceJob*); signals: - void fileOpenRequested(const QString& filePath, DocPosition docPos, int selection); - void fileOpenRequested(const QString& filePath); + void fileOpenRequested(const QString& filePath, DocPosition docPos, int selection, const bool setAsActive); + void fileOpenRequested(const QString& filePath, const bool setAsActive); private: void dragEnterEvent(QDragEnterEvent* event); @@ -230,7 +230,7 @@ void clear(); void requestFileOpen(const QModelIndex&); signals: - void fileOpenRequested(const QString& filePath); + void fileOpenRequested(const QString& filePath, const bool setAsActive); private: QTreeView* m_browser; diff --git a/src/filesearch/filesearchtab.cpp b/src/filesearch/filesearchtab.cpp --- a/src/filesearch/filesearchtab.cpp +++ b/src/filesearch/filesearchtab.cpp @@ -114,8 +114,7 @@ void SearchFileListView::requestFileOpen(const QModelIndex& item) { - emit fileOpenRequested(item.data(Qt::UserRole).toString()); - + emit fileOpenRequested(item.data(Qt::UserRole).toString(), true); } void SearchFileListView::addFiles(const QStringList& files) @@ -527,7 +526,7 @@ //m_searchFileListView->hide(); addDockWidget(Qt::RightDockWidgetArea, m_searchFileListView); srf->addAction(QStringLiteral("showfilelist_action"), m_searchFileListView->toggleViewAction()); - connect(m_searchFileListView, &SearchFileListView::fileOpenRequested, this, QOverload::of(&FileSearchTab::fileOpenRequested)); + connect(m_searchFileListView, &SearchFileListView::fileOpenRequested, this, QOverload::of(&FileSearchTab::fileOpenRequested)); m_massReplaceView = new MassReplaceView(this); addDockWidget(Qt::RightDockWidgetArea, m_massReplaceView); @@ -669,7 +668,7 @@ selection = sr.targetPositions.first().len; } qCDebug(LOKALIZE_LOG) << "fileOpenRequest" << docPos.offset << selection; - emit fileOpenRequested(sr.filepath, docPos, selection); + emit fileOpenRequested(sr.filepath, docPos, selection, true); } void FileSearchTab::fileSearchNext() diff --git a/src/lokalizemainwindow.h b/src/lokalizemainwindow.h --- a/src/lokalizemainwindow.h +++ b/src/lokalizemainwindow.h @@ -136,13 +136,13 @@ //Q_SCRIPTABLE void processEvents(); //returns 0 if error - EditorTab* fileOpen_(QString url); + EditorTab* fileOpen_(QString url, const bool setAsActive); EditorTab* fileOpen(QString url = QString(), int entry = 0, bool setAsActive = true, const QString& mergeFile = QString(), bool silent = false); - EditorTab* fileOpen(const QString& url, const QString& source, const QString& ctxt); - EditorTab* fileOpen(const QString& url, DocPosition docPos, int selection); + EditorTab* fileOpen(const QString& url, const QString& source, const QString& ctxt, const bool setAsActive); + EditorTab* fileOpen(const QString& url, DocPosition docPos, int selection, const bool setAsActive); EditorTab* fileOpen(const QUrl& url) { - return fileOpen(url.toLocalFile()); + return fileOpen(url.toLocalFile(), 0, true); } TM::TMTab* showTM(); FileSearchTab* showFileSearch(bool activate = true); diff --git a/src/lokalizemainwindow.cpp b/src/lokalizemainwindow.cpp --- a/src/lokalizemainwindow.cpp +++ b/src/lokalizemainwindow.cpp @@ -93,7 +93,7 @@ //prevent relayout of dockwidgets m_mdiArea->setOption(QMdiArea::DontMaximizeSubWindowOnActivation, true); - connect(Project::instance(), QOverload::of(&Project::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen_), Qt::QueuedConnection); + connect(Project::instance(), QOverload::of(&Project::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen_), Qt::QueuedConnection); connect(Project::instance(), &Project::configChanged, this, &LokalizeMainWindow::projectSettingsChanged); connect(Project::instance(), &Project::closed, this, &LokalizeMainWindow::closeProject); showProjectOverview(); @@ -144,7 +144,7 @@ disconnect(*sw, &QMdiSubWindow::destroyed, this, &LokalizeMainWindow::editorClosed); EditorTab* w = static_cast((*sw)->widget()); disconnect(w, &EditorTab::aboutToBeClosed, this, &LokalizeMainWindow::resetMultiEditorAdaptor); - disconnect(w, QOverload::of(&EditorTab::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen)); + disconnect(w, QOverload::of(&EditorTab::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen)); disconnect(w, QOverload::of(&EditorTab::tmLookupRequested), this, QOverload::of(&LokalizeMainWindow::lookupInTranslationMemory)); } @@ -251,9 +251,9 @@ } return ok; } -EditorTab* LokalizeMainWindow::fileOpen_(QString filePath) +EditorTab* LokalizeMainWindow::fileOpen_(QString filePath, const bool setAsActive) { - return fileOpen(filePath); + return fileOpen(filePath, 0, setAsActive); } EditorTab* LokalizeMainWindow::fileOpen(QString filePath, int entry, bool setAsActive, const QString& mergeFile, bool silent) { @@ -304,16 +304,18 @@ if (setAsActive) { m_toBeActiveSubWindow = sw; QTimer::singleShot(0, this, &LokalizeMainWindow::applyToBeActiveSubWindow); - } else + } else { + m_mdiArea->setActiveSubWindow(activeSW); sw->setUpdatesEnabled(false); //QTBUG-23289 + } if (!mergeFile.isEmpty()) w->mergeOpen(mergeFile); m_openRecentFileAction->addUrl(QUrl::fromLocalFile(filePath));//(w->currentUrl()); connect(sw, &QMdiSubWindow::destroyed, this, &LokalizeMainWindow::editorClosed); connect(w, &EditorTab::aboutToBeClosed, this, &LokalizeMainWindow::resetMultiEditorAdaptor); - connect(w, QOverload::of(&EditorTab::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen)); + connect(w, QOverload::of(&EditorTab::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen)); connect(w, QOverload::of(&EditorTab::tmLookupRequested), this, QOverload::of(&LokalizeMainWindow::lookupInTranslationMemory)); filePath = w->currentFilePath(); @@ -343,17 +345,17 @@ m_fileToEditor.remove(m_fileToEditor.key(static_cast(obj))); } -EditorTab* LokalizeMainWindow::fileOpen(const QString& filePath, const QString& source, const QString& ctxt) +EditorTab* LokalizeMainWindow::fileOpen(const QString& filePath, const QString& source, const QString& ctxt, const bool setAsActive) { - EditorTab* w = fileOpen(filePath, 0, true); + EditorTab* w = fileOpen(filePath, 0, setAsActive); if (!w) return 0;//TODO message w->findEntryBySourceContext(source, ctxt); return w; } -EditorTab* LokalizeMainWindow::fileOpen(const QString& filePath, DocPosition docPos, int selection) +EditorTab* LokalizeMainWindow::fileOpen(const QString& filePath, DocPosition docPos, int selection, const bool setAsActive) { - EditorTab* w = fileOpen(filePath, 0, true); + EditorTab* w = fileOpen(filePath, 0, setAsActive); if (!w) return 0;//TODO message w->gotoEntry(docPos, selection); @@ -367,7 +369,7 @@ m_projectSubWindow = m_mdiArea->addSubWindow(w); w->showMaximized(); m_projectSubWindow->showMaximized(); - connect(w, QOverload::of(&ProjectTab::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen_)); + connect(w, QOverload::of(&ProjectTab::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen_)); connect(w, QOverload::of(&ProjectTab::projectOpenRequested), this, QOverload::of(&LokalizeMainWindow::openProject)); connect(w, QOverload<>::of(&ProjectTab::projectOpenRequested), this, QOverload<>::of(&LokalizeMainWindow::openProject)); connect(w, QOverload::of(&ProjectTab::searchRequested), this, QOverload::of(&LokalizeMainWindow::addFilesToSearch)); @@ -395,7 +397,7 @@ m_translationMemorySubWindow = m_mdiArea->addSubWindow(w); w->showMaximized(); m_translationMemorySubWindow->showMaximized(); - connect(w, QOverload::of(&TM::TMTab::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen)); + connect(w, QOverload::of(&TM::TMTab::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen)); } m_mdiArea->setActiveSubWindow(m_translationMemorySubWindow); @@ -411,8 +413,8 @@ m_fileSearchSubWindow = m_mdiArea->addSubWindow(w); w->showMaximized(); m_fileSearchSubWindow->showMaximized(); - connect(w, QOverload::of(&FileSearchTab::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen)); - connect(w, QOverload::of(&FileSearchTab::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen_)); + connect(w, QOverload::of(&FileSearchTab::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen)); + connect(w, QOverload::of(&FileSearchTab::fileOpenRequested), this, QOverload::of(&LokalizeMainWindow::fileOpen_)); } if (activate) { @@ -922,7 +924,7 @@ int LokalizeMainWindow::openFileInEditorAt(const QString& path, const QString& source, const QString& ctxt) { - EditorTab* w = fileOpen(path, source, ctxt); + EditorTab* w = fileOpen(path, source, ctxt, true); if (!w) return -1; return w->dbusId(); } diff --git a/src/nokde-stubs/prefs.cpp b/src/nokde-stubs/prefs.cpp --- a/src/nokde-stubs/prefs.cpp +++ b/src/nokde-stubs/prefs.cpp @@ -210,7 +210,7 @@ // m_openRecentFileAction->addUrl(QUrl::fromLocalFile(filePath));//(w->currentUrl()); connect(w, SIGNAL(destroyed(QObject*)), this, SLOT(editorClosed(QObject*))); - connect(w, SIGNAL(fileOpenRequested(QString, QString, QString)), this, SLOT(fileOpen(QString, QString, QString))); + connect(w, SIGNAL(fileOpenRequested(QString, QString, QString, bool)), this, SLOT(fileOpen(QString, QString, QString, bool))); connect(w, SIGNAL(tmLookupRequested(QString, QString)), this, SLOT(lookupInTranslationMemory(QString, QString))); filePath = w->currentFilePath(); @@ -229,18 +229,18 @@ return w; } -EditorTab* ProjectBase::fileOpen(const QString& filePath, const QString& source, const QString& ctxt) +EditorTab* ProjectBase::fileOpen(const QString& filePath, const QString& source, const QString& ctxt, const bool setAsActive) { - EditorTab* w = fileOpen(filePath, 0, true); + EditorTab* w = fileOpen(filePath, 0, setAsActive); if (!w) return 0;//TODO message w->findEntryBySourceContext(source, ctxt); return w; } -EditorTab* ProjectBase::fileOpen(const QString& filePath, DocPosition docPos, int selection) +EditorTab* ProjectBase::fileOpen(const QString& filePath, DocPosition docPos, int selection, const bool setAsActive) { - EditorTab* w = fileOpen(filePath, 0, true); + EditorTab* w = fileOpen(filePath, 0, setAsActive); if (!w) return 0;//TODO message w->gotoEntry(docPos, selection); @@ -272,7 +272,7 @@ { if (!m_tmTab) { m_tmTab = new TM::TMTab(0); - connect(m_tmTab, SIGNAL(fileOpenRequested(QString, QString, QString)), this, SLOT(fileOpen(QString, QString, QString))); + connect(m_tmTab, SIGNAL(fileOpenRequested(QString, QString, QString, bool)), this, SLOT(fileOpen(QString, QString, QString, bool))); } m_tmTab->show(); m_tmTab->activateWindow(); @@ -283,8 +283,8 @@ { if (!m_fileSearchTab) { m_fileSearchTab = new FileSearchTab(0); - connect(m_fileSearchTab, SIGNAL(fileOpenRequested(QString, DocPosition, int)), this, SLOT(fileOpen(QString, DocPosition, int))); - connect(m_fileSearchTab, SIGNAL(fileOpenRequested(QString)), this, SLOT(fileOpen(QString))); + connect(m_fileSearchTab, SIGNAL(fileOpenRequested(QString, DocPosition, int, bool)), this, SLOT(fileOpen(QString, DocPosition, int, bool))); + connect(m_fileSearchTab, SIGNAL(fileOpenRequested(QString, bool)), this, SLOT(fileOpen(QString, bool))); } if (EditorTab* e = qobject_cast(QApplication::activeWindow())) { diff --git a/src/nokde-stubs/projectbase.h b/src/nokde-stubs/projectbase.h --- a/src/nokde-stubs/projectbase.h +++ b/src/nokde-stubs/projectbase.h @@ -33,8 +33,8 @@ public slots: EditorTab* fileOpen(QString url = QString(), int entry = 0, bool setAsActive = true, const QString& mergeFile = QString(), bool silent = false); - EditorTab* fileOpen(const QString& filePath, const QString& source, const QString& ctxt); - EditorTab* fileOpen(const QString& filePath, DocPosition docPos, int selection); + EditorTab* fileOpen(const QString& filePath, const QString& source, const QString& ctxt, const bool setAsActive); + EditorTab* fileOpen(const QString& filePath, DocPosition docPos, int selection, const bool setAsActive); void lookupInTranslationMemory(const QString& source, const QString& target); TM::TMTab* showTM(); diff --git a/src/project/project.h b/src/project/project.h --- a/src/project/project.h +++ b/src/project/project.h @@ -162,7 +162,7 @@ signals: Q_SCRIPTABLE void loaded(); - void fileOpenRequested(const QString&); + void fileOpenRequested(const QString&, const bool setAsActive); void closed(); public slots: diff --git a/src/project/project.cpp b/src/project/project.cpp --- a/src/project/project.cpp +++ b/src/project/project.cpp @@ -513,7 +513,7 @@ Project::instance()->load(fi.absoluteDir().absoluteFilePath(trFolderName) + QLatin1String("/index.lokalize"), targetLangCode, fi.baseName() % '-' % targetLangCode); - emit fileOpenRequested(args.at(1)); + emit fileOpenRequested(args.at(1), true); } diff --git a/src/project/projecttab.h b/src/project/projecttab.h --- a/src/project/projecttab.h +++ b/src/project/projecttab.h @@ -69,7 +69,7 @@ void projectOpenRequested(QString path); void projectOpenRequested(); - void fileOpenRequested(const QString&); + void fileOpenRequested(const QString&, const bool setAsActive); void searchRequested(const QStringList&); void replaceRequested(const QStringList&); diff --git a/src/project/projecttab.cpp b/src/project/projecttab.cpp --- a/src/project/projecttab.cpp +++ b/src/project/projecttab.cpp @@ -27,6 +27,7 @@ #include "projectwidget.h" #include "tmscanapi.h" #include "prefs.h" +#include "catalog.h" #include #include @@ -244,7 +245,10 @@ QMenu* menu = new QMenu(this); connect(menu, &QMenu::aboutToHide, menu, &QMenu::deleteLater); - if (m_browser->currentIsTranslationFile()) { + if (m_browser->selectedItems().size() > 1 || (m_browser->selectedItems().size() == 1 && !m_browser->currentIsTranslationFile())) { + menu->addAction(i18nc("@action:inmenu", "Open selected files"), this, SLOT(openFile())); + menu->addSeparator(); + } else if (m_browser->currentIsTranslationFile()) { menu->addAction(i18nc("@action:inmenu", "Open"), this, SLOT(openFile())); menu->addSeparator(); } @@ -299,7 +303,13 @@ void ProjectTab::openFile() { - emit fileOpenRequested(m_browser->currentItem()); + QStringList files = m_browser->selectedItems(); + int i = files.size(); + while (--i >= 0) { + if (Catalog::extIsSupported(files.at(i))) { + emit fileOpenRequested(files.at(i), true); + } + } } void ProjectTab::findInFiles() { diff --git a/src/project/projectwidget.h b/src/project/projectwidget.h --- a/src/project/projectwidget.h +++ b/src/project/projectwidget.h @@ -64,7 +64,7 @@ void toggleTranslatedFiles(); signals: - void fileOpenRequested(const QString&); + void fileOpenRequested(const QString&, const bool setAsActive); void newWindowOpenRequested(const QUrl&); private slots: diff --git a/src/project/projectwidget.cpp b/src/project/projectwidget.cpp --- a/src/project/projectwidget.cpp +++ b/src/project/projectwidget.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -371,7 +372,7 @@ QModelIndex srcIndex = static_cast(m_proxyModel)->mapToSource(index); QUrl fileUrl = srcModel->beginEditing(srcIndex); - emit fileOpenRequested(fileUrl.toLocalFile()); + emit fileOpenRequested(fileUrl.toLocalFile(), !(QApplication::keyboardModifiers() & Qt::ControlModifier)); } } diff --git a/src/tm/tmtab.h b/src/tm/tmtab.h --- a/src/tm/tmtab.h +++ b/src/tm/tmtab.h @@ -94,7 +94,7 @@ void setQAMode(bool enabled); signals: - void fileOpenRequested(const QString& url, const QString& source, const QString& ctxt); + void fileOpenRequested(const QString& url, const QString& source, const QString& ctxt, const bool setAsActive); private: void dragEnterEvent(QDragEnterEvent* event); diff --git a/src/tm/tmtab.cpp b/src/tm/tmtab.cpp --- a/src/tm/tmtab.cpp +++ b/src/tm/tmtab.cpp @@ -631,7 +631,8 @@ } emit fileOpenRequested(item.sibling(item.row(), TMDBModel::Filepath).data(Qt::UserRole).toString(), item.sibling(item.row(), TMDBModel::Source).data().toString(), - item.sibling(item.row(), TMDBModel::Context).data().toString()); + item.sibling(item.row(), TMDBModel::Context).data().toString(), + true); } void TMTab::setQAMode() diff --git a/src/tm/tmview.h b/src/tm/tmview.h --- a/src/tm/tmview.h +++ b/src/tm/tmview.h @@ -61,7 +61,7 @@ // void textReplaceRequested(const QString&); void refreshRequested(); void textInsertRequested(const QString&); - void fileOpenRequested(const QString& filePath, const QString& str, const QString& ctxt); + void fileOpenRequested(const QString& filePath, const QString& str, const QString& ctxt, const bool setAsActive); public slots: void slotNewEntryDisplayed(); diff --git a/src/tm/tmview.cpp b/src/tm/tmview.cpp --- a/src/tm/tmview.cpp +++ b/src/tm/tmview.cpp @@ -620,7 +620,7 @@ if (r->data().toInt() == Remove) { removeEntry(e); } else if (r->data().toInt() == Open) { - emit fileOpenRequested(e.file, e.source.string, e.ctxt); + emit fileOpenRequested(e.file, e.source.string, e.ctxt, true); } else if ((r->data().toInt() == RemoveFile) && KMessageBox::Yes == KMessageBox::questionYesNo(this, i18n("Do you really want to remove this missing file:
%1
from translation memory %2?", e.file, e.dbName), i18nc("@title:window", "Translation Memory Missing File Removal"))) {