diff --git a/src/plugins/coreplugin/locator/filesystemfilter.cpp b/src/plugins/coreplugin/locator/filesystemfilter.cpp index fdc127e5d92..37b3ede81dd 100644 --- a/src/plugins/coreplugin/locator/filesystemfilter.cpp +++ b/src/plugins/coreplugin/locator/filesystemfilter.cpp @@ -64,6 +64,37 @@ void FileSystemFilter::prepareSearch(const QString &entry) m_currentIncludeHidden = m_includeHidden; } +static const char kAlwaysCreate[] = "Locator/FileSystemFilter/AlwaysCreate"; + +static void createAndOpen(const FilePath &filePath) +{ + if (!filePath.exists()) { + if (CheckableMessageBox::shouldAskAgain(ICore::settings(), kAlwaysCreate)) { + CheckableMessageBox messageBox(ICore::dialogParent()); + messageBox.setWindowTitle(Tr::tr("Create File")); + messageBox.setIcon(QMessageBox::Question); + messageBox.setText(Tr::tr("Create \"%1\"?").arg(filePath.shortNativePath())); + messageBox.setCheckBoxVisible(true); + messageBox.setCheckBoxText(Tr::tr("Always create")); + messageBox.setChecked(false); + messageBox.setStandardButtons(QDialogButtonBox::Cancel); + QPushButton *createButton = messageBox.addButton(Tr::tr("Create"), + QDialogButtonBox::AcceptRole); + messageBox.setDefaultButton(QDialogButtonBox::Cancel); + messageBox.exec(); + if (messageBox.clickedButton() != createButton) + return; + if (messageBox.isChecked()) + CheckableMessageBox::doNotAskAgain(ICore::settings(), kAlwaysCreate); + } + QFile file(filePath.toFSPathString()); + file.open(QFile::WriteOnly); + file.close(); + VcsManager::promptToAdd(filePath.absolutePath(), {filePath}); + } + EditorManager::openEditor(filePath); +} + QList FileSystemFilter::matchesFor(QFutureInterface &future, const QString &entry) { @@ -112,7 +143,13 @@ QList FileSystemFilter::matchesFor(QFutureInterface FileSystemFilter::matchesFor(QFutureInterface FileSystemFilter::matchesFor(QFutureInterface()); } -const char kAlwaysCreate[] = "Locator/FileSystemFilter/AlwaysCreate"; - -void FileSystemFilter::accept(const LocatorFilterEntry &selection, - QString *newText, - int *selectionStart, - int *selectionLength) const -{ - Q_UNUSED(selectionLength) - if (selection.filePath.isDir()) { - const QString value - = shortcutString() + ' ' - + selection.filePath.absoluteFilePath().cleanPath().pathAppended("/").toUserOutput(); - *newText = value; - *selectionStart = value.length(); - } else { - // Don't block locator filter execution with dialog - QMetaObject::invokeMethod(EditorManager::instance(), [selection] { - if (!selection.filePath.exists()) { - if (CheckableMessageBox::shouldAskAgain(ICore::settings(), kAlwaysCreate)) { - CheckableMessageBox messageBox(ICore::dialogParent()); - messageBox.setWindowTitle(Tr::tr("Create File")); - messageBox.setIcon(QMessageBox::Question); - messageBox.setText(Tr::tr("Create \"%1\"?").arg(selection.filePath.shortNativePath())); - messageBox.setCheckBoxVisible(true); - messageBox.setCheckBoxText(Tr::tr("Always create")); - messageBox.setChecked(false); - messageBox.setStandardButtons(QDialogButtonBox::Cancel); - QPushButton *createButton = messageBox.addButton(Tr::tr("Create"), - QDialogButtonBox::AcceptRole); - messageBox.setDefaultButton(QDialogButtonBox::Cancel); - messageBox.exec(); - if (messageBox.clickedButton() != createButton) - return; - if (messageBox.isChecked()) - CheckableMessageBox::doNotAskAgain(ICore::settings(), kAlwaysCreate); - } - QFile file(selection.filePath.toFSPathString()); - file.open(QFile::WriteOnly); - file.close(); - VcsManager::promptToAdd(selection.filePath.absolutePath(), {selection.filePath}); - } - EditorManager::openEditor(selection); - }, Qt::QueuedConnection); - } -} - class FileSystemFilterOptions : public QDialog { public: diff --git a/src/plugins/coreplugin/locator/filesystemfilter.h b/src/plugins/coreplugin/locator/filesystemfilter.h index fea41e5779e..f2983ad40af 100644 --- a/src/plugins/coreplugin/locator/filesystemfilter.h +++ b/src/plugins/coreplugin/locator/filesystemfilter.h @@ -22,8 +22,6 @@ public: void prepareSearch(const QString &entry) override; QList matchesFor(QFutureInterface &future, const QString &entry) override; - void accept(const LocatorFilterEntry &selection, - QString *newText, int *selectionStart, int *selectionLength) const override; void restoreState(const QByteArray &state) override; bool openConfigDialog(QWidget *parent, bool &needsRefresh) override;