Core: Use FilePath in ExternalEditor interface

Change-Id: If3360eb7db9cec373551c2eb0fcffaf3bc5460e6
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-05-25 07:05:32 +02:00
parent ce04dcdcf2
commit 2ccf5e2795
8 changed files with 27 additions and 23 deletions

View File

@@ -2942,7 +2942,7 @@ void EditorManager::populateOpenWithMenu(QMenu *menu, const QString &fileName)
QAction *action = menu->addAction(externalEditor->displayName());
Utils::Id editorId = externalEditor->id();
connect(action, &QAction::triggered, [fileName, editorId]() {
EditorManager::openExternalEditor(fileName, editorId);
EditorManager::openExternalEditor(FilePath::fromString(fileName), editorId);
});
}
}
@@ -3173,7 +3173,7 @@ bool EditorManager::isAutoSaveFile(const QString &filePath)
}
/*!
Opens the document specified by \a fileName in the external editor specified
Opens the document specified by \a filePath in the external editor specified
by \a editorId.
Returns \c false and displays an error message if \a editorId is not the ID
@@ -3181,7 +3181,7 @@ bool EditorManager::isAutoSaveFile(const QString &filePath)
\sa openEditor()
*/
bool EditorManager::openExternalEditor(const QString &fileName, Id editorId)
bool EditorManager::openExternalEditor(const FilePath &filePath, Id editorId)
{
IExternalEditor *ee = Utils::findOrDefault(IExternalEditor::allExternalEditors(),
Utils::equal(&IExternalEditor::id, editorId));
@@ -3189,7 +3189,7 @@ bool EditorManager::openExternalEditor(const QString &fileName, Id editorId)
return false;
QString errorMessage;
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
const bool ok = ee->startEditor(fileName, &errorMessage);
const bool ok = ee->startEditor(filePath, &errorMessage);
QApplication::restoreOverrideCursor();
if (!ok)
QMessageBox::critical(ICore::dialogParent(), tr("Opening File"), errorMessage);

View File

@@ -116,7 +116,7 @@ public:
static bool skipOpeningBigTextFile(const Utils::FilePath &filePath);
static void clearUniqueId(IDocument *document);
static bool openExternalEditor(const QString &fileName, Utils::Id editorId);
static bool openExternalEditor(const Utils::FilePath &filePath, Utils::Id editorId);
static void addCloseEditorListener(const std::function<bool(IEditor *)> &listener);
static QStringList getOpenFileNames();

View File

@@ -32,6 +32,8 @@
#include <QObject>
namespace Utils { class FilePath; }
namespace Core {
class IExternalEditor;
@@ -52,7 +54,7 @@ public:
virtual QStringList mimeTypes() const = 0;
virtual Utils::Id id() const = 0;
virtual QString displayName() const = 0;
virtual bool startEditor(const QString &fileName, QString *errorMessage) = 0;
virtual bool startEditor(const Utils::FilePath &filePath, QString *errorMessage) = 0;
};
} // namespace Core

View File

@@ -25,6 +25,8 @@
#include "systemeditor.h"
#include <utils/fileutils.h>
#include <QStringList>
#include <QUrl>
#include <QDesktopServices>
@@ -53,11 +55,11 @@ QString SystemEditor::displayName() const
return tr("System Editor");
}
bool SystemEditor::startEditor(const QString &fileName, QString *errorMessage)
bool SystemEditor::startEditor(const FilePath &filePath, QString *errorMessage)
{
Q_UNUSED(errorMessage)
QUrl url;
url.setPath(fileName);
url.setPath(filePath.toString());
url.setScheme(QLatin1String("file"));
if (!QDesktopServices::openUrl(url)) {
if (errorMessage)

View File

@@ -41,7 +41,7 @@ public:
Utils::Id id() const override;
QString displayName() const override;
bool startEditor(const QString &fileName, QString *errorMessage) override;
bool startEditor(const Utils::FilePath &filePath, QString *errorMessage) override;
};
} // namespace Internal

View File

@@ -948,7 +948,7 @@ void MainWindow::openFileWith()
if (!editorId.isValid())
continue;
if (isExternal)
EditorManager::openExternalEditor(fileName, editorId);
EditorManager::openExternalEditor(FilePath::fromString(fileName), editorId);
else
EditorManagerPrivate::openEditorWith(FilePath::fromString(fileName), editorId);
}

View File

@@ -156,7 +156,7 @@ static QString findFirstCommand(QVector<QtSupport::BaseQtVersion *> qtVersions,
return QString();
}
bool ExternalQtEditor::getEditorLaunchData(const QString &fileName,
bool ExternalQtEditor::getEditorLaunchData(const Utils::FilePath &filePath,
LaunchData *data,
QString *errorMessage) const
{
@@ -168,7 +168,7 @@ bool ExternalQtEditor::getEditorLaunchData(const QString &fileName,
// As fallback check PATH
data->workingDirectory.clear();
QVector<QtSupport::BaseQtVersion *> qtVersionsToCheck; // deduplicated after being filled
if (const Project *project = SessionManager::projectForFile(Utils::FilePath::fromString(fileName))) {
if (const Project *project = SessionManager::projectForFile(filePath)) {
data->workingDirectory = project->projectDirectory().toString();
// active kit
if (const Target *target = project->activeTarget()) {
@@ -193,7 +193,7 @@ bool ExternalQtEditor::getEditorLaunchData(const QString &fileName,
return false;
}
// Setup binary + arguments, use Mac Open if appropriate
data->arguments.push_back(fileName);
data->arguments.push_back(filePath.toString());
if (Utils::HostOsInfo::isMacHost())
*data = createMacOpenCommand(*data);
if (debug)
@@ -201,10 +201,10 @@ bool ExternalQtEditor::getEditorLaunchData(const QString &fileName,
return true;
}
bool ExternalQtEditor::startEditor(const QString &fileName, QString *errorMessage)
bool ExternalQtEditor::startEditor(const Utils::FilePath &filePath, QString *errorMessage)
{
LaunchData data;
return getEditorLaunchData(fileName, &data, errorMessage)
return getEditorLaunchData(filePath, &data, errorMessage)
&& startEditorProcess(data, errorMessage);
}
@@ -244,11 +244,11 @@ void DesignerExternalEditor::processTerminated(const QString &binary)
socket->deleteLater();
}
bool DesignerExternalEditor::startEditor(const QString &fileName, QString *errorMessage)
bool DesignerExternalEditor::startEditor(const Utils::FilePath &filePath, QString *errorMessage)
{
LaunchData data;
// Find the editor binary
if (!getEditorLaunchData(fileName, &data, errorMessage)) {
if (!getEditorLaunchData(filePath, &data, errorMessage)) {
return false;
}
// Known one?
@@ -256,9 +256,9 @@ bool DesignerExternalEditor::startEditor(const QString &fileName, QString *error
if (it != m_processCache.end()) {
// Process is known, write to its socket to cause it to open the file
if (debug)
qDebug() << Q_FUNC_INFO << "\nWriting to socket:" << data.binary << fileName;
qDebug() << Q_FUNC_INFO << "\nWriting to socket:" << data.binary << filePath;
QTcpSocket *socket = it.value();
if (!socket->write(fileName.toUtf8() + '\n')) {
if (!socket->write(filePath.toString().toUtf8() + '\n')) {
*errorMessage = tr("Qt Designer is not responding (%1).").arg(socket->errorString());
return false;
}
@@ -272,7 +272,7 @@ bool DesignerExternalEditor::startEditor(const QString &fileName, QString *error
}
const quint16 port = server.serverPort();
if (debug)
qDebug() << Q_FUNC_INFO << "\nLaunching server:" << port << data.binary << fileName;
qDebug() << Q_FUNC_INFO << "\nLaunching server:" << port << data.binary << filePath;
// Start first one with file and socket as '-client port file'
// Wait for the socket listening
data.arguments.push_front(QString::number(port));

View File

@@ -62,7 +62,7 @@ public:
Utils::Id id() const override;
QString displayName() const override;
bool startEditor(const QString &fileName, QString *errorMessage) override;
bool startEditor(const Utils::FilePath &filePath, QString *errorMessage) override;
// Data required to launch the editor
struct LaunchData {
@@ -79,7 +79,7 @@ protected:
// Try to retrieve the binary of the editor from the Qt version,
// prepare arguments accordingly (Mac "open" if desired)
bool getEditorLaunchData(const QString &fileName,
bool getEditorLaunchData(const Utils::FilePath &filePath,
LaunchData *data,
QString *errorMessage) const;
@@ -104,7 +104,7 @@ class DesignerExternalEditor : public ExternalQtEditor
public:
DesignerExternalEditor();
bool startEditor(const QString &fileName, QString *errorMessage) override;
bool startEditor(const Utils::FilePath &filePath, QString *errorMessage) override;
private:
void processTerminated(const QString &binary);