forked from qt-creator/qt-creator
Core: Do not open documents for all dropped files
Only open one visible editor and add all other dropped files as suspended documents to the document model. Change-Id: Iade95b3891fb90c06cc8852859346bbfe10bc292 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -432,10 +432,12 @@ DocumentModel::Entry *DocumentModelPrivate::addSuspendedDocument(const QString &
|
||||
const QString &displayName,
|
||||
Id id)
|
||||
{
|
||||
QTC_CHECK(id.isValid());
|
||||
auto entry = new DocumentModel::Entry;
|
||||
entry->document = new IDocument;
|
||||
entry->document->setFilePath(Utils::FilePath::fromString(fileName));
|
||||
entry->document->setPreferredDisplayName(displayName);
|
||||
if (!displayName.isEmpty())
|
||||
entry->document->setPreferredDisplayName(displayName);
|
||||
entry->document->setId(id);
|
||||
entry->isSuspended = true;
|
||||
d->addEntry(entry);
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/locator/locatorconstants.h>
|
||||
#include <coreplugin/minisplitter.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/infobar.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/theme/theme.h>
|
||||
@@ -400,14 +401,27 @@ void EditorView::closeSplit()
|
||||
|
||||
void EditorView::openDroppedFiles(const QList<DropSupport::FileSpec> &files)
|
||||
{
|
||||
const int count = files.size();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
const DropSupport::FileSpec spec = files.at(i);
|
||||
EditorManagerPrivate::openEditorAt(this, spec.filePath, spec.line, spec.column, Id(),
|
||||
i < count - 1 ? EditorManager::DoNotChangeCurrentEditor
|
||||
| EditorManager::DoNotMakeVisible
|
||||
: EditorManager::NoFlags);
|
||||
}
|
||||
bool first = true;
|
||||
auto openEntry = [&](const DropSupport::FileSpec &spec) {
|
||||
if (first) {
|
||||
first = false;
|
||||
EditorManagerPrivate::openEditorAt(this, spec.filePath, spec.line, spec.column);
|
||||
} else if (spec.column != -1 || spec.line != -1) {
|
||||
EditorManagerPrivate::openEditorAt(this,
|
||||
spec.filePath,
|
||||
spec.line,
|
||||
spec.column,
|
||||
Id(),
|
||||
EditorManager::DoNotChangeCurrentEditor
|
||||
| EditorManager::DoNotMakeVisible);
|
||||
} else {
|
||||
auto *factory = IEditorFactory::preferredEditorFactories(spec.filePath).value(0);
|
||||
DocumentModelPrivate::addSuspendedDocument(spec.filePath,
|
||||
{},
|
||||
factory ? factory->id() : Id());
|
||||
}
|
||||
};
|
||||
Utils::reverseForeach(files, openEntry);
|
||||
}
|
||||
|
||||
void EditorView::setParentSplitterOrView(SplitterOrView *splitterOrView)
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
#include <coreplugin/dialogs/externaltoolconfig.h>
|
||||
#include <coreplugin/dialogs/newdialog.h>
|
||||
#include <coreplugin/dialogs/shortcutsettings.h>
|
||||
#include <coreplugin/editormanager/documentmodel_p.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/editormanager_p.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
@@ -877,7 +878,7 @@ IDocument *MainWindow::openFiles(const QStringList &fileNames,
|
||||
const QList<IDocumentFactory*> documentFactories = IDocumentFactory::allDocumentFactories();
|
||||
IDocument *res = nullptr;
|
||||
|
||||
foreach (const QString &fileName, fileNames) {
|
||||
for (const QString &fileName : fileNames) {
|
||||
const QDir workingDir(workingDirectory.isEmpty() ? QDir::currentPath() : workingDirectory);
|
||||
const QFileInfo fi(workingDir, fileName);
|
||||
const QString absoluteFilePath = fi.absoluteFilePath();
|
||||
@@ -898,12 +899,19 @@ IDocument *MainWindow::openFiles(const QStringList &fileNames,
|
||||
emFlags |= EditorManager::CanContainLineAndColumnNumber;
|
||||
if (flags & ICore::SwitchSplitIfAlreadyVisible)
|
||||
emFlags |= EditorManager::SwitchSplitIfAlreadyVisible;
|
||||
IEditor *editor = EditorManager::openEditor(absoluteFilePath, Id(), emFlags);
|
||||
if (!editor) {
|
||||
if (flags & ICore::StopOnLoadFail)
|
||||
return res;
|
||||
} else if (!res) {
|
||||
res = editor->document();
|
||||
if (emFlags != EditorManager::NoFlags || !res) {
|
||||
IEditor *editor = EditorManager::openEditor(absoluteFilePath, Id(), emFlags);
|
||||
if (!editor) {
|
||||
if (flags & ICore::StopOnLoadFail)
|
||||
return res;
|
||||
} else if (!res) {
|
||||
res = editor->document();
|
||||
}
|
||||
} else {
|
||||
auto *factory = IEditorFactory::preferredEditorFactories(absoluteFilePath).value(0);
|
||||
DocumentModelPrivate::addSuspendedDocument(absoluteFilePath,
|
||||
{},
|
||||
factory ? factory->id() : Id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user