forked from qt-creator/qt-creator
Core: Use FilePath in ExternalEditor interface
Change-Id: If3360eb7db9cec373551c2eb0fcffaf3bc5460e6 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -2942,7 +2942,7 @@ void EditorManager::populateOpenWithMenu(QMenu *menu, const QString &fileName)
|
|||||||
QAction *action = menu->addAction(externalEditor->displayName());
|
QAction *action = menu->addAction(externalEditor->displayName());
|
||||||
Utils::Id editorId = externalEditor->id();
|
Utils::Id editorId = externalEditor->id();
|
||||||
connect(action, &QAction::triggered, [fileName, editorId]() {
|
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.
|
by \a editorId.
|
||||||
|
|
||||||
Returns \c false and displays an error message if \a editorId is not the ID
|
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()
|
\sa openEditor()
|
||||||
*/
|
*/
|
||||||
bool EditorManager::openExternalEditor(const QString &fileName, Id editorId)
|
bool EditorManager::openExternalEditor(const FilePath &filePath, Id editorId)
|
||||||
{
|
{
|
||||||
IExternalEditor *ee = Utils::findOrDefault(IExternalEditor::allExternalEditors(),
|
IExternalEditor *ee = Utils::findOrDefault(IExternalEditor::allExternalEditors(),
|
||||||
Utils::equal(&IExternalEditor::id, editorId));
|
Utils::equal(&IExternalEditor::id, editorId));
|
||||||
@@ -3189,7 +3189,7 @@ bool EditorManager::openExternalEditor(const QString &fileName, Id editorId)
|
|||||||
return false;
|
return false;
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
||||||
const bool ok = ee->startEditor(fileName, &errorMessage);
|
const bool ok = ee->startEditor(filePath, &errorMessage);
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
if (!ok)
|
if (!ok)
|
||||||
QMessageBox::critical(ICore::dialogParent(), tr("Opening File"), errorMessage);
|
QMessageBox::critical(ICore::dialogParent(), tr("Opening File"), errorMessage);
|
||||||
|
@@ -116,7 +116,7 @@ public:
|
|||||||
static bool skipOpeningBigTextFile(const Utils::FilePath &filePath);
|
static bool skipOpeningBigTextFile(const Utils::FilePath &filePath);
|
||||||
static void clearUniqueId(IDocument *document);
|
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 void addCloseEditorListener(const std::function<bool(IEditor *)> &listener);
|
||||||
|
|
||||||
static QStringList getOpenFileNames();
|
static QStringList getOpenFileNames();
|
||||||
|
@@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace Utils { class FilePath; }
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
class IExternalEditor;
|
class IExternalEditor;
|
||||||
@@ -52,7 +54,7 @@ public:
|
|||||||
virtual QStringList mimeTypes() const = 0;
|
virtual QStringList mimeTypes() const = 0;
|
||||||
virtual Utils::Id id() const = 0;
|
virtual Utils::Id id() const = 0;
|
||||||
virtual QString displayName() 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
|
} // namespace Core
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "systemeditor.h"
|
#include "systemeditor.h"
|
||||||
|
|
||||||
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
@@ -53,11 +55,11 @@ QString SystemEditor::displayName() const
|
|||||||
return tr("System Editor");
|
return tr("System Editor");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SystemEditor::startEditor(const QString &fileName, QString *errorMessage)
|
bool SystemEditor::startEditor(const FilePath &filePath, QString *errorMessage)
|
||||||
{
|
{
|
||||||
Q_UNUSED(errorMessage)
|
Q_UNUSED(errorMessage)
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setPath(fileName);
|
url.setPath(filePath.toString());
|
||||||
url.setScheme(QLatin1String("file"));
|
url.setScheme(QLatin1String("file"));
|
||||||
if (!QDesktopServices::openUrl(url)) {
|
if (!QDesktopServices::openUrl(url)) {
|
||||||
if (errorMessage)
|
if (errorMessage)
|
||||||
|
@@ -41,7 +41,7 @@ public:
|
|||||||
Utils::Id id() const override;
|
Utils::Id id() const override;
|
||||||
QString displayName() 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
|
} // namespace Internal
|
||||||
|
@@ -948,7 +948,7 @@ void MainWindow::openFileWith()
|
|||||||
if (!editorId.isValid())
|
if (!editorId.isValid())
|
||||||
continue;
|
continue;
|
||||||
if (isExternal)
|
if (isExternal)
|
||||||
EditorManager::openExternalEditor(fileName, editorId);
|
EditorManager::openExternalEditor(FilePath::fromString(fileName), editorId);
|
||||||
else
|
else
|
||||||
EditorManagerPrivate::openEditorWith(FilePath::fromString(fileName), editorId);
|
EditorManagerPrivate::openEditorWith(FilePath::fromString(fileName), editorId);
|
||||||
}
|
}
|
||||||
|
@@ -156,7 +156,7 @@ static QString findFirstCommand(QVector<QtSupport::BaseQtVersion *> qtVersions,
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExternalQtEditor::getEditorLaunchData(const QString &fileName,
|
bool ExternalQtEditor::getEditorLaunchData(const Utils::FilePath &filePath,
|
||||||
LaunchData *data,
|
LaunchData *data,
|
||||||
QString *errorMessage) const
|
QString *errorMessage) const
|
||||||
{
|
{
|
||||||
@@ -168,7 +168,7 @@ bool ExternalQtEditor::getEditorLaunchData(const QString &fileName,
|
|||||||
// As fallback check PATH
|
// As fallback check PATH
|
||||||
data->workingDirectory.clear();
|
data->workingDirectory.clear();
|
||||||
QVector<QtSupport::BaseQtVersion *> qtVersionsToCheck; // deduplicated after being filled
|
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();
|
data->workingDirectory = project->projectDirectory().toString();
|
||||||
// active kit
|
// active kit
|
||||||
if (const Target *target = project->activeTarget()) {
|
if (const Target *target = project->activeTarget()) {
|
||||||
@@ -193,7 +193,7 @@ bool ExternalQtEditor::getEditorLaunchData(const QString &fileName,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Setup binary + arguments, use Mac Open if appropriate
|
// Setup binary + arguments, use Mac Open if appropriate
|
||||||
data->arguments.push_back(fileName);
|
data->arguments.push_back(filePath.toString());
|
||||||
if (Utils::HostOsInfo::isMacHost())
|
if (Utils::HostOsInfo::isMacHost())
|
||||||
*data = createMacOpenCommand(*data);
|
*data = createMacOpenCommand(*data);
|
||||||
if (debug)
|
if (debug)
|
||||||
@@ -201,10 +201,10 @@ bool ExternalQtEditor::getEditorLaunchData(const QString &fileName,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExternalQtEditor::startEditor(const QString &fileName, QString *errorMessage)
|
bool ExternalQtEditor::startEditor(const Utils::FilePath &filePath, QString *errorMessage)
|
||||||
{
|
{
|
||||||
LaunchData data;
|
LaunchData data;
|
||||||
return getEditorLaunchData(fileName, &data, errorMessage)
|
return getEditorLaunchData(filePath, &data, errorMessage)
|
||||||
&& startEditorProcess(data, errorMessage);
|
&& startEditorProcess(data, errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,11 +244,11 @@ void DesignerExternalEditor::processTerminated(const QString &binary)
|
|||||||
socket->deleteLater();
|
socket->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DesignerExternalEditor::startEditor(const QString &fileName, QString *errorMessage)
|
bool DesignerExternalEditor::startEditor(const Utils::FilePath &filePath, QString *errorMessage)
|
||||||
{
|
{
|
||||||
LaunchData data;
|
LaunchData data;
|
||||||
// Find the editor binary
|
// Find the editor binary
|
||||||
if (!getEditorLaunchData(fileName, &data, errorMessage)) {
|
if (!getEditorLaunchData(filePath, &data, errorMessage)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Known one?
|
// Known one?
|
||||||
@@ -256,9 +256,9 @@ bool DesignerExternalEditor::startEditor(const QString &fileName, QString *error
|
|||||||
if (it != m_processCache.end()) {
|
if (it != m_processCache.end()) {
|
||||||
// Process is known, write to its socket to cause it to open the file
|
// Process is known, write to its socket to cause it to open the file
|
||||||
if (debug)
|
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();
|
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());
|
*errorMessage = tr("Qt Designer is not responding (%1).").arg(socket->errorString());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -272,7 +272,7 @@ bool DesignerExternalEditor::startEditor(const QString &fileName, QString *error
|
|||||||
}
|
}
|
||||||
const quint16 port = server.serverPort();
|
const quint16 port = server.serverPort();
|
||||||
if (debug)
|
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'
|
// Start first one with file and socket as '-client port file'
|
||||||
// Wait for the socket listening
|
// Wait for the socket listening
|
||||||
data.arguments.push_front(QString::number(port));
|
data.arguments.push_front(QString::number(port));
|
||||||
|
@@ -62,7 +62,7 @@ public:
|
|||||||
Utils::Id id() const override;
|
Utils::Id id() const override;
|
||||||
QString displayName() 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
|
// Data required to launch the editor
|
||||||
struct LaunchData {
|
struct LaunchData {
|
||||||
@@ -79,7 +79,7 @@ protected:
|
|||||||
|
|
||||||
// Try to retrieve the binary of the editor from the Qt version,
|
// Try to retrieve the binary of the editor from the Qt version,
|
||||||
// prepare arguments accordingly (Mac "open" if desired)
|
// prepare arguments accordingly (Mac "open" if desired)
|
||||||
bool getEditorLaunchData(const QString &fileName,
|
bool getEditorLaunchData(const Utils::FilePath &filePath,
|
||||||
LaunchData *data,
|
LaunchData *data,
|
||||||
QString *errorMessage) const;
|
QString *errorMessage) const;
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ class DesignerExternalEditor : public ExternalQtEditor
|
|||||||
public:
|
public:
|
||||||
DesignerExternalEditor();
|
DesignerExternalEditor();
|
||||||
|
|
||||||
bool startEditor(const QString &fileName, QString *errorMessage) override;
|
bool startEditor(const Utils::FilePath &filePath, QString *errorMessage) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processTerminated(const QString &binary);
|
void processTerminated(const QString &binary);
|
||||||
|
Reference in New Issue
Block a user