Commit 331ce588 authored by Simon Depiets's avatar Simon Depiets
Browse files

Fix a bug in recent files list with non-project file opens

BUG:412820
There was a bug in recent files list when the files were not open from within a project but from File/Open.
I also added a check to prevent reopening the same file twice (via File/Open), to align behavior on project mode.
Tested with command line/project/file open
parent d708e9a9
......@@ -802,7 +802,7 @@ void EditorTab::updateCaptionPath()
_captionPath = _captionPath.mid(2);
}
bool EditorTab::fileOpen(QString filePath, QString suggestedDirPath, bool silent)
bool EditorTab::fileOpen(QString filePath, QString suggestedDirPath, QMap<QString, QMdiSubWindow*> openedFiles, bool silent)
{
if (!m_catalog->isClean()) {
switch (KMessageBox::warningYesNoCancel(SettingsController::instance()->mainWindowPtr(),
......@@ -839,6 +839,11 @@ bool EditorTab::fileOpen(QString filePath, QString suggestedDirPath, bool silent
}
if (filePath.isEmpty())
return false;
QMap<QString, QMdiSubWindow*>::const_iterator it = openedFiles.constFind(filePath);
if (it != openedFiles.constEnd()) {
qCWarning(LOKALIZE_LOG) << "already opened:" << filePath;
return false;
}
QApplication::setOverrideCursor(Qt::WaitCursor);
......
......@@ -33,6 +33,8 @@
#include "lokalizesubwindowbase.h"
#include <QHash>
#include <QMdiSubWindow>
#include <QMap>
#include <KProcess>
namespace Sonnet
......@@ -128,7 +130,7 @@ public:
//wrapper for cmdline handling
void mergeOpen(QString mergeFilePath);
bool fileOpen(QString filePath = QString(), QString suggestedDirPath = QString(), bool silent = false);
bool fileOpen(QString filePath = QString(), QString suggestedDirPath = QString(), QMap<QString, QMdiSubWindow*> openedFiles = QMap<QString, QMdiSubWindow*>(), bool silent = false);
public slots:
//for undo/redo, views
void gotoEntry(DocPosition pos);
......
......@@ -291,7 +291,7 @@ EditorTab* LokalizeMainWindow::fileOpen(QString filePath, int entry, bool setAsA
if (fp.length()) suggestedDirPath = QFileInfo(fp).absolutePath();
}
if (!w->fileOpen(filePath, suggestedDirPath, silent)) {
if (!w->fileOpen(filePath, suggestedDirPath, m_fileToEditor, silent)) {
if (sw) {
m_mdiArea->removeSubWindow(sw);
sw->deleteLater();
......@@ -299,6 +299,8 @@ EditorTab* LokalizeMainWindow::fileOpen(QString filePath, int entry, bool setAsA
w->deleteLater();
return 0;
}
filePath = w->currentFilePath();
m_openRecentFileAction->addUrl(QUrl::fromLocalFile(filePath));//(w->currentUrl());
if (!sw)
sw = m_mdiArea->addSubWindow(w);
......@@ -326,13 +328,11 @@ EditorTab* LokalizeMainWindow::fileOpen(QString filePath, int entry, bool setAsA
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<const QString &, const QString &, const QString &, const bool>::of(&EditorTab::fileOpenRequested), this, QOverload<const QString &, const QString &, const QString &, const bool>::of(&LokalizeMainWindow::fileOpen));
connect(w, QOverload<const QString &, const QString &>::of(&EditorTab::tmLookupRequested), this, QOverload<const QString &, const QString &>::of(&LokalizeMainWindow::lookupInTranslationMemory));
filePath = w->currentFilePath();
QStringRef fnSlashed = filePath.midRef(filePath.lastIndexOf('/'));
FileToEditor::const_iterator i = m_fileToEditor.constBegin();
while (i != m_fileToEditor.constEnd()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment