forked from qt-creator/qt-creator
QmlProject: Allow opening individual .ui.qml files in "lite" QDS
QDS nowadays provides an option "-qml-lite-designer" that starts it in a "lite" mode. When opening QDS from Qt Creator, use the "normal" QDS when a .qmlproject file is found. Otherwise start it with "-qml-lite-designer". Switches to Process::startDetached with "-client" and "-qml-lite- designer" on macOS too, since "open" wouldn't work for instance sharing depending on the "-qml-lite-designer" option that we can do with the "- client" option. Task-number: QTCREATORBUG-31005 Change-Id: Ia9e00e0ed5ecad8c3c383ee46a6fd2594ee7b2e7 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -87,7 +87,7 @@ void QdsLandingPage::openQds(bool rememberSelection)
|
||||
|
||||
auto editor = Core::EditorManager::currentEditor();
|
||||
if (editor)
|
||||
openInQDSWithProject(editor->document()->filePath());
|
||||
openInQds(editor->document()->filePath());
|
||||
}
|
||||
|
||||
void QdsLandingPage::installQds()
|
||||
|
@@ -101,17 +101,19 @@ static void clearAlwaysOpenWithMode()
|
||||
ICore::settings()->remove(QmlProjectManager::Constants::ALWAYS_OPEN_UI_MODE);
|
||||
}
|
||||
|
||||
void openQDS(const FilePath &fileName)
|
||||
namespace {
|
||||
enum class QdsMode { Lite, Full };
|
||||
}
|
||||
|
||||
static void openQds(const FilePath &fileName, QdsMode mode)
|
||||
{
|
||||
const FilePath qdsPath = qdsInstallationEntry();
|
||||
bool qdsStarted = false;
|
||||
qputenv(Constants::enviromentLaunchedQDS, "true");
|
||||
//-a and -client arguments help to append project to open design studio application
|
||||
if (HostOsInfo::isMacHost())
|
||||
qdsStarted = Process::startDetached(
|
||||
{"/usr/bin/open", {"-a", qdsPath.path(), fileName.toUrlishString()}});
|
||||
else
|
||||
qdsStarted = Process::startDetached({qdsPath, {"-client", fileName.toUrlishString()}});
|
||||
const QStringList modeArgument = mode == QdsMode::Lite ? QStringList("-qml-lite-designer")
|
||||
: QStringList();
|
||||
qdsStarted = Process::startDetached(
|
||||
{qdsPath, modeArgument + QStringList({"-client", fileName.toUrlishString()})});
|
||||
|
||||
if (!qdsStarted) {
|
||||
QMessageBox::warning(ICore::dialogParent(),
|
||||
@@ -174,37 +176,33 @@ static bool findAndOpenProject(const FilePath &filePath)
|
||||
{
|
||||
if (Project *project = ProjectManager::projectForFile(filePath)) {
|
||||
if (project->projectFilePath().suffix() == "qmlproject") {
|
||||
openQDS(project->projectFilePath());
|
||||
openQds(project->projectFilePath(), QdsMode::Full);
|
||||
return true;
|
||||
}
|
||||
FilePath projectFolder = project->rootProjectDirectory();
|
||||
FilePath qmlProjectFile = findQmlProject(projectFolder);
|
||||
if (qmlProjectFile.exists()) {
|
||||
openQDS(qmlProjectFile);
|
||||
openQds(qmlProjectFile, QdsMode::Full);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
FilePath qmlProjectFile = findQmlProjectUpwards(filePath);
|
||||
if (qmlProjectFile.exists()) {
|
||||
openQDS(qmlProjectFile);
|
||||
openQds(qmlProjectFile, QdsMode::Full);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void openInQDSWithProject(const FilePath &filePath)
|
||||
void openInQds(const FilePath &filePath)
|
||||
{
|
||||
if (findAndOpenProject(filePath)) {
|
||||
openQDS(filePath);
|
||||
openQds(filePath, QdsMode::Full);
|
||||
//The first one might be ignored when QDS is starting up
|
||||
QTimer::singleShot(4000, [filePath] { openQDS(filePath); });
|
||||
QTimer::singleShot(4000, [filePath] { openQds(filePath, QdsMode::Full); });
|
||||
} else {
|
||||
AsynchronousMessageBox::warning(
|
||||
Tr::tr("Qt Design Studio"),
|
||||
Tr::tr("No project file (*.qmlproject) found for Qt Design "
|
||||
"Studio.\nQt Design Studio requires a .qmlproject "
|
||||
"based project to open the .ui.qml file."));
|
||||
openQds(filePath, QdsMode::Lite);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,7 +226,7 @@ public:
|
||||
setDisplayName(Tr::tr("Qt Design Studio"));
|
||||
setMimeTypes({Utils::Constants::QMLUI_MIMETYPE});
|
||||
setEditorStarter([](const FilePath &filePath, [[maybe_unused]] QString *errorMessage) {
|
||||
openInQDSWithProject(filePath);
|
||||
openInQds(filePath);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@@ -480,7 +478,7 @@ void QmlProjectPlugin::openQds(bool permanent)
|
||||
hideQmlLandingPage();
|
||||
|
||||
if (IEditor *editor = EditorManager::currentEditor())
|
||||
openInQDSWithProject(editor->document()->filePath());
|
||||
openInQds(editor->document()->filePath());
|
||||
}
|
||||
|
||||
void QmlProjectPlugin::updateQmlLandingPageProjectInfo(const FilePath &projectFile)
|
||||
|
@@ -9,7 +9,6 @@ namespace Core { class IEditor; }
|
||||
|
||||
namespace QmlProjectManager::Internal {
|
||||
|
||||
void openQDS(const Utils::FilePath &fileName);
|
||||
Utils::FilePath qdsInstallationEntry();
|
||||
bool qdsInstallationExists();
|
||||
bool checkIfEditorIsuiQml(Core::IEditor *editor);
|
||||
@@ -17,7 +16,7 @@ Utils::FilePath projectFilePath();
|
||||
Utils::FilePaths rootCmakeFiles();
|
||||
QString qtVersion(const Utils::FilePath &projectFilePath);
|
||||
QString qdsVersion(const Utils::FilePath &projectFilePath);
|
||||
void openInQDSWithProject(const Utils::FilePath &filePath);
|
||||
void openInQds(const Utils::FilePath &filePath);
|
||||
const QString readFileContents(const Utils::FilePath &filePath);
|
||||
|
||||
} // QmlProject::Internal
|
||||
|
Reference in New Issue
Block a user