Commit 181f1506 authored by Igor Kushnir's avatar Igor Kushnir
Browse files

Show a usage hint for CustomScriptPlugin in configuration UI

When a formatter tool referenced in CustomScriptPlugin's style cannot be
found (not installed), error messages are easy to miss. They are written
not into systemd journal, but into ~/.xsession-errors, because the error
occurs in the shell rather than in KDevelop directly.

The usage hint that emphasizes the external tool executable dependency
of each custom script style should reduce usage mistakes and wrong
assumptions by users.
parent c1dd6ae5
Pipeline #95905 canceled with stage
......@@ -27,6 +27,11 @@ ISourceFormatter::~ISourceFormatter()
{
}
QString ISourceFormatter::usageHint() const
{
return QString();
}
SourceFormatterStyle::SourceFormatterStyle()
{
}
......
......@@ -139,6 +139,14 @@ class KDEVPLATFORMINTERFACES_EXPORT ISourceFormatter
*/
virtual QString description() const = 0;
/**
* @return important information to display in style configuration UI
*
* @note The default implementation returns an empty string, which conveniently
* saves UI space if there is no important information to display.
*/
virtual QString usageHint() const;
/** Formats using the current style.
* @param text The text to format
* @param url The URL to which the text belongs (its contents must not be changed).
......
......@@ -400,6 +400,15 @@ void SourceFormatterSelectionEdit::selectFormatter( int idx )
l.selectedFormatter = formatterIter.value();
l.selectedStyle = nullptr; // will hold 0 until a style is picked
}
const auto usageHint = l.selectedFormatter->formatter->usageHint();
if (usageHint.isEmpty()) {
d->ui.usageHintLabel->hide(); // save UI space
} else {
d->ui.usageHintLabel->setText(usageHint);
d->ui.usageHintLabel->show();
}
for (const SourceFormatterStyle* style : qAsConst(formatterIter.value()->styles)) {
if (!style->supportsLanguage(d->ui.cbLanguages->currentText())) {
// do not list items which do not support the selected language
......
......@@ -43,7 +43,7 @@
</item>
</layout>
</item>
<item row="0" column="2" rowspan="3">
<item row="0" column="2" rowspan="4">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,3">
<item>
<widget class="QLabel" name="descriptionLabel">
......@@ -116,7 +116,17 @@
</item>
</layout>
</item>
<item row="2" column="0">
<item row="2" column="1">
<widget class="QLabel" name="usageHintLabel">
<property name="text">
<string notr="true">&lt;usage hint&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string comment="@label:listbox">Style:</string>
......@@ -132,7 +142,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="btnNewStyle">
......
......@@ -91,6 +91,13 @@ QString CustomScriptPlugin::description() const
"can be easily shared by all team members, independent of their preferred IDE.");
}
QString CustomScriptPlugin::usageHint() const
{
return i18nc("@info formatter usage hint",
"Note: each custom script style requires a certain tool executable "
"to be installed. Otherwise, code will not be formatted.");
}
QString CustomScriptPlugin::formatSourceWithStyle(SourceFormatterStyle style, const QString& text, const QUrl& url, const QMimeType& /*mime*/, const QString& leftContext, const QString& rightContext) const
{
KProcess proc;
......
......@@ -30,6 +30,7 @@ public:
QString name() const override;
QString caption() const override;
QString description() const override;
QString usageHint() const override;
/** Formats using the current style.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment