forked from qt-creator/qt-creator
CMakePM: Enable cmake format action only if the tool is present
If the tool is not present the menu action is disabled. Also add a link to the Qt Creator cmake-format documentation. Fixes: QTCREATORBUG-29415 Change-Id: I4afb33f0d5ce08975b0964d6bee80dfb41cfcde5 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -65,8 +65,15 @@ public:
|
|||||||
|
|
||||||
setLayouter([this] {
|
setLayouter([this] {
|
||||||
using namespace Layouting;
|
using namespace Layouting;
|
||||||
|
|
||||||
|
auto cmakeFormatter = new QLabel(
|
||||||
|
Tr::tr("<a href=\"%1\">CMakeFormat</a> command:")
|
||||||
|
.arg("qthelp://org.qt-project.qtcreator/doc/"
|
||||||
|
"creator-project-cmake.html#formatting-cmake-files"));
|
||||||
|
cmakeFormatter->setOpenExternalLinks(true);
|
||||||
|
|
||||||
return Column {
|
return Column {
|
||||||
Row { Tr::tr("CMakeFormat command:"), command },
|
Row { cmakeFormatter, command },
|
||||||
Space(10),
|
Space(10),
|
||||||
Group {
|
Group {
|
||||||
title(Tr::tr("Automatic Formatting on File Save")),
|
title(Tr::tr("Automatic Formatting on File Save")),
|
||||||
@@ -97,7 +104,9 @@ public:
|
|||||||
|
|
||||||
auto updateActions = [this] {
|
auto updateActions = [this] {
|
||||||
auto editor = EditorManager::currentEditor();
|
auto editor = EditorManager::currentEditor();
|
||||||
formatFile.setEnabled(editor && isApplicable(editor->document()));
|
|
||||||
|
formatFile.setEnabled(haveValidFormatCommand && editor
|
||||||
|
&& isApplicable(editor->document()));
|
||||||
};
|
};
|
||||||
|
|
||||||
connect(&autoFormatMime, &Utils::StringAspect::changed,
|
connect(&autoFormatMime, &Utils::StringAspect::changed,
|
||||||
@@ -108,6 +117,15 @@ public:
|
|||||||
this, &CMakeFormatterSettings::applyIfNecessary);
|
this, &CMakeFormatterSettings::applyIfNecessary);
|
||||||
|
|
||||||
readSettings();
|
readSettings();
|
||||||
|
|
||||||
|
const FilePath commandPath = command().searchInPath();
|
||||||
|
haveValidFormatCommand = commandPath.exists() && commandPath.isExecutableFile();
|
||||||
|
|
||||||
|
formatFile.setEnabled(haveValidFormatCommand);
|
||||||
|
connect(&command, &FilePathAspect::validChanged, this, [this](bool validState) {
|
||||||
|
haveValidFormatCommand = validState;
|
||||||
|
formatFile.setEnabled(haveValidFormatCommand);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isApplicable(const IDocument *document) const;
|
bool isApplicable(const IDocument *document) const;
|
||||||
@@ -125,6 +143,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
FilePathAspect command{this};
|
FilePathAspect command{this};
|
||||||
|
bool haveValidFormatCommand{false};
|
||||||
BoolAspect autoFormatOnSave{this};
|
BoolAspect autoFormatOnSave{this};
|
||||||
BoolAspect autoFormatOnlyCurrentProject{this};
|
BoolAspect autoFormatOnlyCurrentProject{this};
|
||||||
StringAspect autoFormatMime{this};
|
StringAspect autoFormatMime{this};
|
||||||
|
Reference in New Issue
Block a user