diff --git a/interfaces/isourceformattercontroller.h b/interfaces/isourceformattercontroller.h
--- a/interfaces/isourceformattercontroller.h
+++ b/interfaces/isourceformattercontroller.h
@@ -44,19 +44,25 @@
~ISourceFormatterController() override;
/** \return The formatter corresponding to the language
- * of the document corresponding to the \arg url.
+ * of the document corresponding to the \p url.
+ * The language is then activated and the style is loaded.
+ * The source formatter is then ready to use.
+ * If mimetype of url is known already, use
+ * formatterForUrl(const QUrl& url, const QMimeType& mime) instead.
*/
virtual ISourceFormatter* formatterForUrl(const QUrl &url) = 0;
- /** Loads and returns a source formatter for this mime type.
+ /** \return The formatter corresponding to the language
+ * of the document corresponding to the \p url.
* The language is then activated and the style is loaded.
- * The source formatter is then ready to use on a file.
+ * The source formatter is then ready to use.
+ * @param mime known mimetype of the url
*/
- virtual ISourceFormatter* formatterForMimeType(const QMimeType &mime) = 0;
+ virtual ISourceFormatter* formatterForUrl(const QUrl& url, const QMimeType& mime) = 0;
/** \return Whether this mime type is supported by any plugin.
*/
virtual bool isMimeTypeSupported(const QMimeType &mime) = 0;
- virtual KDevelop::SourceFormatterStyle styleForMimeType( const QMimeType& mime ) = 0;
+ virtual KDevelop::SourceFormatterStyle styleForUrl(const QUrl& url, const QMimeType& mime) = 0;
///Set whether or not source formatting is disabled with \arg disable
virtual void disableSourceFormatting(bool disable) = 0;
diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt
--- a/plugins/CMakeLists.txt
+++ b/plugins/CMakeLists.txt
@@ -15,6 +15,7 @@
add_subdirectory(execute)
add_subdirectory(externalscript)
add_subdirectory(documentswitcher)
+add_subdirectory(sourceformatter)
add_subdirectory(patchreview)
add_subdirectory(openwith)
add_subdirectory(grepview)
diff --git a/plugins/sourceformatter/CMakeLists.txt b/plugins/sourceformatter/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/plugins/sourceformatter/CMakeLists.txt
@@ -0,0 +1,29 @@
+add_definitions(-DTRANSLATION_DOMAIN=\"kdevsourceformatter\")
+
+set(kdevsourceformatter_CONFIG_SRCS
+ config/projectconfigpage.cpp
+)
+
+ki18n_wrap_ui(kdevsourceformatter_CONFIG_SRCS
+ config/projectconfigpage.ui
+)
+
+kconfig_add_kcfg_files(kdevsourceformatter_CONFIG_SRCS
+ config/projectconfig.kcfgc
+)
+
+set(kdevsourceformatter_SRCS
+ sourceformatterplugin.cpp
+ ${kdevsourceformatter_CONFIG_SRCS}
+)
+
+kdevplatform_add_plugin(kdevsourceformatter
+ JSON kdevsourceformatter.json
+ SOURCES ${kdevsourceformatter_SRCS}
+)
+
+target_link_libraries(kdevsourceformatter
+ KDev::Interfaces
+ KDev::Project
+ KDev::Shell
+)
diff --git a/plugins/sourceformatter/Messages.sh b/plugins/sourceformatter/Messages.sh
new file mode 100644
--- /dev/null
+++ b/plugins/sourceformatter/Messages.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+$EXTRACTRC `find . -name \*.rc` `find . -name \*.ui` >> rc.cpp
+$XGETTEXT `find . -name \*.cc -o -name \*.cpp -o -name \*.h` -o $podir/kdevsourceformatter.pot
+rm -f rc.cpp
diff --git a/plugins/sourceformatter/config/projectconfig.kcfg b/plugins/sourceformatter/config/projectconfig.kcfg
new file mode 100644
--- /dev/null
+++ b/plugins/sourceformatter/config/projectconfig.kcfg
@@ -0,0 +1,17 @@
+
+
+
+
+ true
+
+
+ false
+
+
+ false
+
+
+
diff --git a/plugins/sourceformatter/config/projectconfig.kcfgc b/plugins/sourceformatter/config/projectconfig.kcfgc
new file mode 100644
--- /dev/null
+++ b/plugins/sourceformatter/config/projectconfig.kcfgc
@@ -0,0 +1,3 @@
+File=projectconfig.kcfg
+NameSpace=SourceFormatter
+ClassName=ProjectConfig
diff --git a/plugins/sourceformatter/config/projectconfigpage.h b/plugins/sourceformatter/config/projectconfigpage.h
new file mode 100644
--- /dev/null
+++ b/plugins/sourceformatter/config/projectconfigpage.h
@@ -0,0 +1,65 @@
+/*
+ * This file is part of KDevelop
+ * Copyright (C) 2017 Friedrich W. H. Kossebau
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef PROJECTCONFIGPAGE_H
+#define PROJECTCONFIGPAGE_H
+
+#include
+
+namespace KDevelop
+{
+class IProject;
+}
+
+namespace SourceFormatter
+{
+
+namespace Ui
+{
+class ProjectConfigPage;
+}
+
+class ProjectConfigPage : public KDevelop::ConfigPage
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Constructor
+ */
+ ProjectConfigPage(KDevelop::IPlugin* plugin, KDevelop::IProject* project, QWidget* parent);
+ ~ProjectConfigPage() override;
+
+ QString name() const override;
+ QString fullName() const override;
+ QIcon icon() const override;
+
+ void apply() override;
+ void reset() override;
+
+private Q_SLOTS:
+ void disableCustomSettings(bool checked);
+
+private:
+ QScopedPointer ui;
+};
+
+}
+
+#endif // PROJECTCONFIGPAGE_H
diff --git a/plugins/sourceformatter/config/projectconfigpage.cpp b/plugins/sourceformatter/config/projectconfigpage.cpp
new file mode 100644
--- /dev/null
+++ b/plugins/sourceformatter/config/projectconfigpage.cpp
@@ -0,0 +1,94 @@
+/*
+ * This file is part of KDevelop
+ * Copyright (C) 2017 Friedrich W. H. Kossebau
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "projectconfigpage.h"
+#include "ui_projectconfigpage.h"
+
+#include
+#include
+
+#include "projectconfig.h"
+
+#include
+
+namespace SourceFormatter
+{
+
+namespace Strings {
+QString SourceFormatter() { return QStringLiteral("SourceFormatter"); }
+}
+
+
+ProjectConfigPage::ProjectConfigPage(KDevelop::IPlugin* plugin, KDevelop::IProject* project, QWidget* parent)
+ : ConfigPage(plugin, new ProjectConfig, parent)
+ , ui(new Ui::ProjectConfigPage)
+{
+ configSkeleton()->setSharedConfig(project->projectConfiguration());
+ configSkeleton()->load();
+
+ ui->setupUi(this);
+
+ connect(ui->kcfg_useDefault, &QAbstractButton::toggled,
+ this, &ProjectConfigPage::disableCustomSettings);
+ connect(ui->formatterSelectionEdit, &KDevelop::SourceFormatterSelectionEdit::changed,
+ this, &ProjectConfigPage::changed);
+}
+
+ProjectConfigPage::~ProjectConfigPage() = default;
+
+QString ProjectConfigPage::name() const
+{
+ return i18n("Source Formatter");
+}
+
+QString ProjectConfigPage::fullName() const
+{
+ return i18n("Configure Source Formatter");
+}
+
+QIcon ProjectConfigPage::icon() const
+{
+ return QIcon::fromTheme(QStringLiteral("text-field"));
+}
+
+void ProjectConfigPage::disableCustomSettings(bool checked)
+{
+ ui->generalGroupBox->setEnabled(! checked);
+ ui->formattinStylesGroupBox->setEnabled(! checked);
+}
+
+void ProjectConfigPage::reset()
+{
+ auto config = configSkeleton()->sharedConfig()->group(Strings::SourceFormatter());
+ ui->formatterSelectionEdit->loadSettings(config);
+ ConfigPage::reset();
+}
+
+void ProjectConfigPage::apply()
+{
+ auto config = configSkeleton()->sharedConfig()->group(Strings::SourceFormatter());
+ ui->formatterSelectionEdit->saveSettings(config);
+
+ ConfigPage::apply();
+
+ // TODO: fix exception of accessing internal API, find a better way to notify about settings change
+ KDevelop::Core::self()->sourceFormatterControllerInternal()->settingsChanged();
+}
+
+}
diff --git a/plugins/sourceformatter/config/projectconfigpage.ui b/plugins/sourceformatter/config/projectconfigpage.ui
new file mode 100644
--- /dev/null
+++ b/plugins/sourceformatter/config/projectconfigpage.ui
@@ -0,0 +1,88 @@
+
+
+ SourceFormatter::ProjectConfigPage
+
+
+
+ 0
+ 0
+ 407
+ 315
+
+
+
+ -
+
+
-
+
+
+ &Use default:
+
+
+ kcfg_useDefault
+
+
+
+ -
+
+
+
+
+
+
+
+
+ -
+
+
+ General
+
+
+
-
+
+
+ Override the editor indentation mode according to the formatting style for documents without Kate modeline.
+
+
+ Override Kate Indentation Mode
+
+
+
+ -
+
+
+ Add a Kate modeline according to the formatting style to formatted documents.
+
+
+ Add Kate Modeline
+
+
+
+
+
+
+ -
+
+
+ Formatting Styles
+
+
+
-
+
+
+
+
+
+
+
+
+
+ KDevelop::SourceFormatterSelectionEdit
+ QWidget
+ sourceformatterselectionedit.h
+ 1
+
+
+
+
+
diff --git a/plugins/sourceformatter/kdevsourceformatter.json b/plugins/sourceformatter/kdevsourceformatter.json
new file mode 100644
--- /dev/null
+++ b/plugins/sourceformatter/kdevsourceformatter.json
@@ -0,0 +1,15 @@
+{
+ "KPlugin": {
+ "Id": "kdevsourceformatter",
+ "Name": "Source Formatter",
+ "Description": "",
+ "Icon": "text-field",
+ "Category": "Utilities",
+ "ServiceTypes": [
+ "KDevelop/Plugin"
+ ]
+ },
+ "X-KDevelop-Category": "Project",
+ "X-KDevelop-LoadMode": "AlwaysOn",
+ "X-KDevelop-Mode": "GUI"
+}
diff --git a/plugins/sourceformatter/sourceformatterplugin.h b/plugins/sourceformatter/sourceformatterplugin.h
new file mode 100644
--- /dev/null
+++ b/plugins/sourceformatter/sourceformatterplugin.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of KDevelop
+ * Copyright (C) 2017 Friedrich W. H. Kossebau
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef SOURCEFORMATTERPLUGIN_H
+#define SOURCEFORMATTERPLUGIN_H
+
+#include
+
+class SourceFormatterPlugin : public KDevelop::IPlugin
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Constructor with arguments as needed with KPluginFactory
+ */
+ SourceFormatterPlugin(QObject* parent, const QVariantList& args);
+ ~SourceFormatterPlugin() override;
+
+ int perProjectConfigPages() const override;
+ KDevelop::ConfigPage* perProjectConfigPage(int number, const KDevelop::ProjectConfigOptions& options, QWidget* parent) override;
+
+private:
+};
+
+#endif // SOURCEFORMATTERPLUGIN_H
diff --git a/plugins/sourceformatter/sourceformatterplugin.cpp b/plugins/sourceformatter/sourceformatterplugin.cpp
new file mode 100644
--- /dev/null
+++ b/plugins/sourceformatter/sourceformatterplugin.cpp
@@ -0,0 +1,54 @@
+/*
+ * This file is part of KDevelop
+ * Copyright (C) 2017 Friedrich W. H. Kossebau
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "sourceformatterplugin.h"
+
+#include "config/projectconfigpage.h"
+
+#include
+
+#include
+
+K_PLUGIN_FACTORY_WITH_JSON(SourceFormatterPluginFactory, "kdevsourceformatter.json", registerPlugin();)
+
+SourceFormatterPlugin::SourceFormatterPlugin(QObject* parent, const QVariantList& args)
+ : KDevelop::IPlugin(QStringLiteral("kdevsourceformatter"), parent)
+{
+ Q_UNUSED(args);
+
+}
+
+SourceFormatterPlugin::~SourceFormatterPlugin() = default;
+
+int SourceFormatterPlugin::perProjectConfigPages() const
+{
+ return 1;
+}
+
+KDevelop::ConfigPage* SourceFormatterPlugin::perProjectConfigPage(int number, const KDevelop::ProjectConfigOptions& options, QWidget* parent)
+{
+ if (number != 0) {
+ return nullptr;
+ }
+
+ return new SourceFormatter::ProjectConfigPage(this, options.project, parent);
+}
+
+// needed for QObject class created from K_PLUGIN_FACTORY_WITH_JSON
+#include "sourceformatterplugin.moc"
diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt
--- a/shell/CMakeLists.txt
+++ b/shell/CMakeLists.txt
@@ -52,6 +52,7 @@
configdialog.cpp
editorconfigpage.cpp
environmentconfigurebutton.cpp
+ sourceformatterselectionedit.cpp
runtimecontroller.cpp
checkerstatus.cpp
@@ -110,6 +111,7 @@
projectinfopage.ui
launchconfigurationdialog.ui
projectsourcepage.ui
+ sourceformatterselectionedit.ui
settings/uiconfig.ui
settings/editstyledialog.ui
settings/sourceformattersettings.ui
@@ -181,6 +183,7 @@
runcontroller.h
launchconfiguration.h
environmentconfigurebutton.h
+ sourceformatterselectionedit.h
checkerstatus.h
problem.h
problemmodel.h
diff --git a/shell/settings/sourceformattersettings.h b/shell/settings/sourceformattersettings.h
--- a/shell/settings/sourceformattersettings.h
+++ b/shell/settings/sourceformattersettings.h
@@ -20,37 +20,10 @@
#ifndef KDEVPLATFORM_SOURCEFORMATTERSETTINGS_H
#define KDEVPLATFORM_SOURCEFORMATTERSETTINGS_H
-#include
-
#include
-#include "sourceformattercontroller.h"
-
#include "ui_sourceformattersettings.h"
-class QListWidgetItem;
-
-namespace KTextEditor
-{
-class Document;
-class View;
-}
-
-namespace KDevelop
-{
-class ISourceFormatter;
-class SourceFormatterStyle;
-}
-
-struct LanguageSettings {
- LanguageSettings();
- QList mimetypes;
- QSet formatters;
- // weak pointers to selected formatter and style, no ownership
- KDevelop::SourceFormatter* selectedFormatter; // Should never be zero
- KDevelop::SourceFormatterStyle* selectedStyle; // TODO: can this be zero? Assume that not
-};
-
/** \short The settings modulefor the Source formatter plugin.
* It supports predefined and custom styles. A live preview of the style
* is shown on the right side of the page.s
@@ -71,27 +44,8 @@
void reset() override;
void apply() override;
void defaults() override;
-private Q_SLOTS:
- void deleteStyle();
- void editStyle();
- void newStyle();
- void selectLanguage( int );
- void selectFormatter( int );
- void selectStyle( int );
- void styleNameChanged( QListWidgetItem* );
- void somethingChanged();
+
private:
- void updatePreview();
- QListWidgetItem* addStyle( const KDevelop::SourceFormatterStyle& s );
- void enableStyleButtons();
- // Language name -> language settings
- typedef QMap LanguageMap;
- LanguageMap languages;
- // formatter name -> formatter. Formatters owned by this
- typedef QMap FormatterMap;
- FormatterMap formatters;
- KTextEditor::Document* m_document;
- KTextEditor::View* m_view;
};
#endif // KDEVPLATFORM_SOURCEFORMATTERSETTINGS_H
diff --git a/shell/settings/sourceformattersettings.cpp b/shell/settings/sourceformattersettings.cpp
--- a/shell/settings/sourceformattersettings.cpp
+++ b/shell/settings/sourceformattersettings.cpp
@@ -19,243 +19,53 @@
*/
#include "sourceformattersettings.h"
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
#include
#include
-#include
-#include
-#include
#include
-#include
-#include
-#include
+#include
-#include "editstyledialog.h"
#include "debug.h"
-#define STYLE_ROLE (Qt::UserRole+1)
-
using KDevelop::Core;
-using KDevelop::ISourceFormatter;
-using KDevelop::SourceFormatterStyle;
using KDevelop::SourceFormatterController;
-using KDevelop::SourceFormatter;
-
-namespace {
-namespace Strings {
-QString userStylePrefix() { return QStringLiteral("User"); }
-}
-}
-
-LanguageSettings::LanguageSettings()
- : selectedFormatter(nullptr), selectedStyle(nullptr) {
-}
SourceFormatterSettings::SourceFormatterSettings(QWidget* parent)
: KDevelop::ConfigPage(nullptr, nullptr, parent)
{
setupUi(this);
- connect( cbLanguages, static_cast(&KComboBox::currentIndexChanged), this, &SourceFormatterSettings::selectLanguage );
- connect( cbFormatters, static_cast(&KComboBox::currentIndexChanged), this, &SourceFormatterSettings::selectFormatter );
- connect( chkKateModelines, &QCheckBox::toggled, this, &SourceFormatterSettings::somethingChanged );
- connect( chkKateOverrideIndentation, &QCheckBox::toggled, this, &SourceFormatterSettings::somethingChanged );
- connect( styleList, &QListWidget::currentRowChanged, this, &SourceFormatterSettings::selectStyle );
- connect( btnDelStyle, &QPushButton::clicked, this, &SourceFormatterSettings::deleteStyle );
- connect( btnNewStyle, &QPushButton::clicked, this, &SourceFormatterSettings::newStyle );
- connect( btnEditStyle, &QPushButton::clicked, this, &SourceFormatterSettings::editStyle );
- connect( styleList, &QListWidget::itemChanged, this, &SourceFormatterSettings::styleNameChanged );
-
- m_document = KTextEditor::Editor::instance()->createDocument(this);
- m_document->setReadWrite(false);
-
- m_view = m_document->createView(textEditor);
- m_view->setStatusBarEnabled(false);
-
- QVBoxLayout *layout2 = new QVBoxLayout(textEditor);
- layout2->addWidget(m_view);
- textEditor->setLayout(layout2);
- m_view->show();
-
- KTextEditor::ConfigInterface *iface =
- qobject_cast(m_view);
- if (iface) {
- iface->setConfigValue(QStringLiteral("dynamic-word-wrap"), false);
- iface->setConfigValue(QStringLiteral("icon-bar"), false);
- }
}
SourceFormatterSettings::~SourceFormatterSettings()
{
- qDeleteAll(formatters);
-}
-
-void selectAvailableStyle(LanguageSettings& lang) {
- Q_ASSERT(!lang.selectedFormatter->styles.empty());
- lang.selectedStyle = *lang.selectedFormatter->styles.begin();
}
void SourceFormatterSettings::reset()
{
- SourceFormatterController* fmtctrl = Core::self()->sourceFormatterControllerInternal();
- QList plugins = KDevelop::ICore::self()->pluginController()->allPluginsForExtension( QStringLiteral("org.kdevelop.ISourceFormatter") );
- foreach( KDevelop::IPlugin* plugin, plugins )
- {
- KDevelop::ISourceFormatter* ifmt = plugin->extension();
- auto info = KDevelop::Core::self()->pluginControllerInternal()->pluginInfo( plugin );
- KDevelop::SourceFormatter* formatter;
- FormatterMap::const_iterator iter = formatters.constFind(ifmt->name());
- if (iter == formatters.constEnd()) {
- formatter = fmtctrl->createFormatterForPlugin(ifmt);
- formatters[ifmt->name()] = formatter;
- } else {
- formatter = iter.value();
- }
- foreach ( const SourceFormatterStyle* style, formatter->styles ) {
- foreach ( const SourceFormatterStyle::MimeHighlightPair& item, style->mimeTypes() ) {
- QMimeType mime = QMimeDatabase().mimeTypeForName(item.mimeType);
- if (!mime.isValid()) {
- qCWarning(SHELL) << "plugin" << info.name() << "supports unknown mimetype entry" << item.mimeType;
- continue;
- }
- QString languageName = item.highlightMode;
- LanguageSettings& l = languages[languageName];
- l.mimetypes.append(mime);
- l.formatters.insert( formatter );
- }
- }
- }
-
- // Sort the languages, preferring firstly active, then loaded languages
- QList sortedLanguages;
-
- foreach(const auto language,
- KDevelop::ICore::self()->languageController()->activeLanguages() +
- KDevelop::ICore::self()->languageController()->loadedLanguages())
- {
- if( languages.contains( language->name() ) && !sortedLanguages.contains(language->name()) ) {
- sortedLanguages.push_back( language->name() );
- }
- }
-
- foreach( const QString& name, languages.keys() )
- if( !sortedLanguages.contains( name ) )
- sortedLanguages.push_back( name );
+ KConfigGroup sessionConfig = Core::self()->sourceFormatterControllerInternal()->sessionConfig();
- foreach( const QString& name, sortedLanguages )
- {
- // Pick the first appropriate mimetype for this language
- KConfigGroup grp = fmtctrl->sessionConfig();
- LanguageSettings& l = languages[name];
- const QList mimetypes = l.mimetypes;
- foreach (const QMimeType& mimetype, mimetypes) {
- QStringList formatterAndStyleName = grp.readEntry(mimetype.name(), QString()).split(QStringLiteral("||"), QString::KeepEmptyParts);
- FormatterMap::const_iterator formatterIter = formatters.constFind(formatterAndStyleName.first());
- if (formatterIter == formatters.constEnd()) {
- qCDebug(SHELL) << "Reference to unknown formatter" << formatterAndStyleName.first();
- Q_ASSERT(!l.formatters.empty()); // otherwise there should be no entry for 'name'
- l.selectedFormatter = *l.formatters.begin();
- selectAvailableStyle(l);
- } else {
- l.selectedFormatter = formatterIter.value();
- SourceFormatter::StyleMap::const_iterator styleIter = l.selectedFormatter->styles.constFind(formatterAndStyleName.at( 1 ));
- if (styleIter == l.selectedFormatter->styles.constEnd()) {
- qCDebug(SHELL) << "No style" << formatterAndStyleName.at( 1 ) << "found for formatter" << formatterAndStyleName.first();
- selectAvailableStyle(l);
- } else {
- l.selectedStyle = styleIter.value();
- }
- }
- }
- if (!l.selectedFormatter) {
- Q_ASSERT(!l.formatters.empty());
- l.selectedFormatter = *l.formatters.begin();
- }
- if (!l.selectedStyle) {
- selectAvailableStyle(l);
- }
- }
bool b = blockSignals( true );
- cbLanguages->blockSignals( !b );
- cbFormatters->blockSignals( !b );
- styleList->blockSignals( !b );
chkKateModelines->blockSignals( !b );
chkKateOverrideIndentation->blockSignals( !b );
- cbLanguages->clear();
- cbFormatters->clear();
- styleList->clear();
- chkKateModelines->setChecked( fmtctrl->sessionConfig().readEntry( SourceFormatterController::kateModeLineConfigKey(), false ) );
- chkKateOverrideIndentation->setChecked( fmtctrl->sessionConfig().readEntry( SourceFormatterController::kateOverrideIndentationConfigKey(), false ) );
- foreach( const QString& name, sortedLanguages )
- {
- cbLanguages->addItem( name );
- }
- if( cbLanguages->count() == 0 )
- {
- cbLanguages->setEnabled( false );
- selectLanguage( -1 );
- } else
- {
- cbLanguages->setCurrentIndex( 0 );
- selectLanguage( 0 );
- }
- updatePreview();
+ chkKateModelines->setChecked(sessionConfig.readEntry(SourceFormatterController::kateModeLineConfigKey(), false));
+ chkKateOverrideIndentation->setChecked(sessionConfig.readEntry(SourceFormatterController::kateOverrideIndentationConfigKey(), false));
blockSignals( b );
- cbLanguages->blockSignals( b );
- cbFormatters->blockSignals( b );
- styleList->blockSignals( b );
chkKateModelines->blockSignals( b );
chkKateOverrideIndentation->blockSignals( b );
+
+ formatterSelectionEdit->loadSettings(sessionConfig);
}
void SourceFormatterSettings::apply()
{
- KConfigGroup globalConfig = Core::self()->sourceFormatterControllerInternal()->globalConfig();
-
- foreach( SourceFormatter* fmt, formatters )
- {
- KConfigGroup fmtgrp = globalConfig.group( fmt->formatter->name() );
-
- // delete all styles so we don't leave any behind when all user styles are deleted
- foreach( const QString& subgrp, fmtgrp.groupList() )
- {
- if( subgrp.startsWith( Strings::userStylePrefix() ) ) {
- fmtgrp.deleteGroup( subgrp );
- }
- }
- foreach( const SourceFormatterStyle* style, fmt->styles )
- {
- if( style->name().startsWith( Strings::userStylePrefix() ) )
- {
- KConfigGroup stylegrp = fmtgrp.group( style->name() );
- stylegrp.writeEntry( SourceFormatterController::styleCaptionKey(), style->caption() );
- stylegrp.writeEntry( SourceFormatterController::styleContentKey(), style->content() );
- stylegrp.writeEntry( SourceFormatterController::styleMimeTypesKey(), style->mimeTypesVariant() );
- stylegrp.writeEntry( SourceFormatterController::styleSampleKey(), style->overrideSample() );
- }
- }
- }
-
KConfigGroup sessionConfig = Core::self()->sourceFormatterControllerInternal()->sessionConfig();
- for ( LanguageMap::const_iterator iter = languages.constBegin(); iter != languages.constEnd(); ++iter ) {
- foreach(const QMimeType& mime, iter.value().mimetypes) {
- sessionConfig.writeEntry(mime.name(), QStringLiteral("%1||%2").arg(iter.value().selectedFormatter->formatter->name(), iter.value().selectedStyle->name()));
- }
- }
+
sessionConfig.writeEntry( SourceFormatterController::kateModeLineConfigKey(), chkKateModelines->isChecked() );
sessionConfig.writeEntry( SourceFormatterController::kateOverrideIndentationConfigKey(), chkKateOverrideIndentation->isChecked() );
+ formatterSelectionEdit->saveSettings(sessionConfig);
+
sessionConfig.sync();
- globalConfig.sync();
Core::self()->sourceFormatterControllerInternal()->settingsChanged();
}
@@ -266,263 +76,6 @@
}
-void SourceFormatterSettings::enableStyleButtons()
-{
- bool userEntry = styleList->currentItem()
- && styleList->currentItem()->data( STYLE_ROLE ).toString().startsWith( Strings::userStylePrefix() );
-
- QString languageName = cbLanguages->currentText();
- QMap< QString, LanguageSettings >::const_iterator it = languages.constFind(languageName);
- bool hasEditWidget = false;
- if (it != languages.constEnd()) {
- const LanguageSettings& l = it.value();
- Q_ASSERT(l.selectedFormatter);
- ISourceFormatter* fmt = l.selectedFormatter->formatter;
- hasEditWidget = ( fmt && QScopedPointer(fmt->editStyleWidget( l.mimetypes.first() )) );
- }
- btnDelStyle->setEnabled( userEntry );
- btnEditStyle->setEnabled( userEntry && hasEditWidget );
- btnNewStyle->setEnabled( cbFormatters->currentIndex() >= 0 && hasEditWidget );
-}
-
-void SourceFormatterSettings::selectLanguage( int idx )
-{
- cbFormatters->clear();
- if( idx < 0 )
- {
- cbFormatters->setEnabled( false );
- selectFormatter( -1 );
- return;
- }
- cbFormatters->setEnabled( true );
- {
- QSignalBlocker blocker(cbFormatters);
- LanguageSettings& l = languages[cbLanguages->itemText( idx )];
- foreach( const SourceFormatter* fmt, l.formatters )
- {
- cbFormatters->addItem( fmt->formatter->caption(), fmt->formatter->name() );
- }
- cbFormatters->setCurrentIndex(cbFormatters->findData(l.selectedFormatter->formatter->name()));
- }
- selectFormatter( cbFormatters->currentIndex() );
- emit changed();
-}
-
-void SourceFormatterSettings::selectFormatter( int idx )
-{
- styleList->clear();
- if( idx < 0 )
- {
- styleList->setEnabled( false );
- enableStyleButtons();
- return;
- }
- styleList->setEnabled( true );
- LanguageSettings& l = languages[ cbLanguages->currentText() ];
- Q_ASSERT( idx < l.formatters.size() );
- FormatterMap::const_iterator formatterIter = formatters.constFind(cbFormatters->itemData( idx ).toString());
- Q_ASSERT( formatterIter != formatters.constEnd() );
- Q_ASSERT( l.formatters.contains(formatterIter.value()) );
- if (l.selectedFormatter != formatterIter.value()) {
- l.selectedFormatter = formatterIter.value();
- l.selectedStyle = nullptr; // will hold 0 until a style is picked
- }
- foreach( const SourceFormatterStyle* style, formatterIter.value()->styles ) {
- if ( ! style->supportsLanguage(cbLanguages->currentText())) {
- // do not list items which do not support the selected language
- continue;
- }
- QListWidgetItem* item = addStyle( *style );
- if (style == l.selectedStyle) {
- styleList->setCurrentItem(item);
- }
- }
- if (l.selectedStyle == nullptr) {
- styleList->setCurrentRow(0);
- }
- enableStyleButtons();
- emit changed();
-}
-
-void SourceFormatterSettings::selectStyle( int row )
-{
- if( row < 0 )
- {
- enableStyleButtons();
- return;
- }
- styleList->setCurrentRow( row );
- LanguageSettings& l = languages[ cbLanguages->currentText() ];
- l.selectedStyle = l.selectedFormatter->styles[styleList->item( row )->data( STYLE_ROLE ).toString()];
- enableStyleButtons();
- updatePreview();
- emit changed();
-}
-
-void SourceFormatterSettings::deleteStyle()
-{
- Q_ASSERT( styleList->currentRow() >= 0 );
-
- QListWidgetItem* item = styleList->currentItem();
-
- LanguageSettings& l = languages[ cbLanguages->currentText() ];
- SourceFormatter* fmt = l.selectedFormatter;
- SourceFormatter::StyleMap::iterator styleIter = fmt->styles.find(item->data( STYLE_ROLE ).toString());
- QStringList otherLanguageNames;
- QList otherlanguages;
- for ( LanguageMap::iterator languageIter = languages.begin(); languageIter != languages.end(); ++languageIter ) {
- if ( &languageIter.value() != &l && languageIter.value().selectedStyle == styleIter.value() ) {
- otherLanguageNames.append(languageIter.key());
- otherlanguages.append(&languageIter.value());
- }
- }
- if (!otherLanguageNames.empty() &&
- KMessageBox::warningContinueCancel(this,
- i18n("The style %1 is also used for the following languages:\n%2.\nAre you sure you want to delete it?",
- styleIter.value()->caption(), otherLanguageNames.join(QStringLiteral("\n"))), i18n("Style being deleted")) != KMessageBox::Continue) {
- return;
- }
- styleList->takeItem( styleList->currentRow() );
- fmt->styles.erase(styleIter);
- delete item;
- selectStyle( styleList->count() > 0 ? 0 : -1 );
- foreach (LanguageSettings* lang, otherlanguages) {
- selectAvailableStyle(*lang);
- }
- updatePreview();
- emit changed();
-}
-
-void SourceFormatterSettings::editStyle()
-{
- QString language = cbLanguages->currentText();
- Q_ASSERT( languages.contains( language ) );
- LanguageSettings& l = languages[ language ];
- SourceFormatter* fmt = l.selectedFormatter;
-
- QMimeType mimetype = l.mimetypes.first();
- if( QScopedPointer(fmt->formatter->editStyleWidget( mimetype )) ) {
- KDevelop::ScopedDialog dlg(fmt->formatter, mimetype, *l.selectedStyle, this);
- if( dlg->exec() == QDialog::Accepted )
- {
- l.selectedStyle->setContent(dlg->content());
- }
- updatePreview();
- emit changed();
- }
-}
-
-void SourceFormatterSettings::newStyle()
-{
- QListWidgetItem* item = styleList->currentItem();
- LanguageSettings& l = languages[ cbLanguages->currentText() ];
- SourceFormatter* fmt = l.selectedFormatter;
- int idx = 0;
- for( int i = 0; i < styleList->count(); i++ )
- {
- QString name = styleList->item( i )->data( STYLE_ROLE ).toString();
- if( name.startsWith( Strings::userStylePrefix() ) && name.midRef( Strings::userStylePrefix().length() ).toInt() >= idx )
- {
- idx = name.midRef( Strings::userStylePrefix().length() ).toInt();
- }
- }
- // Increase number for next style
- idx++;
- SourceFormatterStyle* s = new SourceFormatterStyle( QStringLiteral( "%1%2" ).arg( Strings::userStylePrefix() ).arg( idx ) );
- if( item ) {
- SourceFormatterStyle* existstyle = fmt->styles[ item->data( STYLE_ROLE ).toString() ];
- s->setCaption( i18n( "New %1", existstyle->caption() ) );
- s->copyDataFrom( existstyle );
- } else {
- s->setCaption( i18n( "New Style" ) );
- }
- fmt->styles[ s->name() ] = s;
- QListWidgetItem* newitem = addStyle( *s );
- selectStyle( styleList->row( newitem ) );
- styleList->editItem( newitem );
- emit changed();
-}
-
-void SourceFormatterSettings::styleNameChanged( QListWidgetItem* item )
-{
- if ( !item->isSelected() ) {
- return;
- }
-
- LanguageSettings& l = languages[ cbLanguages->currentText() ];
- l.selectedStyle->setCaption( item->text() );
- emit changed();
-}
-
-QListWidgetItem* SourceFormatterSettings::addStyle( const SourceFormatterStyle& s )
-{
- QListWidgetItem* item = new QListWidgetItem( styleList );
- item->setText( s.caption() );
- item->setData( STYLE_ROLE, s.name() );
- if( s.name().startsWith( Strings::userStylePrefix() ) )
- {
- item->setFlags( item->flags() | Qt::ItemIsEditable );
- }
- styleList->addItem( item );
- return item;
-}
-
-void SourceFormatterSettings::updatePreview()
-{
- m_document->setReadWrite( true );
-
- QString langName = cbLanguages->itemText( cbLanguages->currentIndex() );
- if( !langName.isEmpty() )
- {
- LanguageSettings& l = languages[ langName ];
- SourceFormatter* fmt = l.selectedFormatter;
- SourceFormatterStyle* style = l.selectedStyle;
-
- descriptionLabel->setText( style->description() );
-
- if( style->usePreview() )
- {
- ISourceFormatter* ifmt = fmt->formatter;
- QMimeType mime = l.mimetypes.first();
- m_document->setHighlightingMode( style->modeForMimetype( mime ) );
-
- //NOTE: this is ugly, but otherwise kate might remove tabs again :-/
- // see also: https://bugs.kde.org/show_bug.cgi?id=291074
- KTextEditor::ConfigInterface* iface = qobject_cast(m_document);
- QVariant oldReplaceTabs;
- if (iface) {
- oldReplaceTabs = iface->configValue(QStringLiteral("replace-tabs"));
- iface->setConfigValue(QStringLiteral("replace-tabs"), false);
- }
-
- m_document->setText( ifmt->formatSourceWithStyle( *style, ifmt->previewText( *style, mime ), QUrl(), mime ) );
-
- if (iface) {
- iface->setConfigValue(QStringLiteral("replace-tabs"), oldReplaceTabs);
- }
-
- previewLabel->show();
- textEditor->show();
- }else{
- previewLabel->hide();
- textEditor->hide();
- }
- } else
- {
- m_document->setText( i18n( "No Language selected" ) );
- }
- m_view->setCursorPosition( KTextEditor::Cursor( 0, 0 ) );
- m_document->setReadWrite( false );
-}
-
-void SourceFormatterSettings::somethingChanged()
-{
- // Widgets are managed manually, so we have to explicitly tell KCModule
- // that we have some changes, otherwise it won't call "save" and/or will not activate
- // "Appy"
- emit changed();
-}
-
QString SourceFormatterSettings::name() const
{
return i18n("Source Formatter");
diff --git a/shell/settings/sourceformattersettings.ui b/shell/settings/sourceformattersettings.ui
--- a/shell/settings/sourceformattersettings.ui
+++ b/shell/settings/sourceformattersettings.ui
@@ -54,161 +54,21 @@
Formatting Styles
-
- -
-
-
- Language:
-
-
- Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing
-
-
- 4
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
- 0
- 0
-
-
-
-
-
-
- Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
-
-
- true
-
-
-
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 10
-
-
-
-
- -
-
-
- Preview:
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
-
-
- -
-
-
- Formatter:
-
-
- Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing
-
-
- 4
-
-
-
- -
-
-
-
-
-
-
-
- -
-
-
- Style:
-
-
- Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing
-
-
- 4
-
-
- -1
-
-
-
- -
-
-
-
-
-
- New
-
-
-
- -
-
-
- Edit...
-
-
-
- -
-
-
- Delete
-
-
-
- -
-
-
- QAbstractItemView::SelectRows
-
-
- false
-
-
-
-
+
+ -
+
- KComboBox
- QComboBox
-
+ KDevelop::SourceFormatterSelectionEdit
+ QWidget
+ sourceformatterselectionedit.h
+ 1
diff --git a/shell/sourceformattercontroller.h b/shell/sourceformattercontroller.h
--- a/shell/sourceformattercontroller.h
+++ b/shell/sourceformattercontroller.h
@@ -104,7 +104,7 @@
* The language is then activated and the style is loaded.
* The source formatter is then ready to use on a file.
*/
- ISourceFormatter* formatterForMimeType(const QMimeType& mime) override;
+ ISourceFormatter* formatterForUrl(const QUrl& url, const QMimeType& mime) override;
/** \return Whether this mime type is supported by any plugin.
*/
bool isMimeTypeSupported(const QMimeType& mime) override;
@@ -124,8 +124,9 @@
KDevelop::ContextMenuExtension contextMenuExtension(KDevelop::Context* context, QWidget* parent);
- KDevelop::SourceFormatterStyle styleForMimeType(const QMimeType& mime) override;
+ KDevelop::SourceFormatterStyle styleForUrl(const QUrl& url, const QMimeType& mime) override;
+ KConfigGroup configForUrl(const QUrl& url) const;
KConfigGroup sessionConfig() const;
KConfigGroup globalConfig() const;
@@ -151,7 +152,8 @@
QString indentationMode(const QMimeType& mime);
void formatDocument(KDevelop::IDocument* doc, ISourceFormatter* formatter, const QMimeType& mime);
// Adapts the mode of the editor regarding indentation-style
- void adaptEditorIndentationMode(KTextEditor::Document* doc, KDevelop::ISourceFormatter* formatter, bool ignoreModeline = false);
+ void adaptEditorIndentationMode(KTextEditor::Document* doc, KDevelop::ISourceFormatter* formatter,
+ const QUrl& url, bool ignoreModeline = false);
// GUI actions
QAction* m_formatTextAction;
QAction* m_formatFilesAction;
diff --git a/shell/sourceformattercontroller.cpp b/shell/sourceformattercontroller.cpp
--- a/shell/sourceformattercontroller.cpp
+++ b/shell/sourceformattercontroller.cpp
@@ -43,6 +43,8 @@
#include
#include
#include
+#include
+#include
#include
#include
#include
@@ -61,6 +63,7 @@
namespace Strings {
QString SourceFormatter() { return QStringLiteral("SourceFormatter"); }
+QString UseDefault() { return QStringLiteral("UseDefault"); }
}
}
@@ -147,8 +150,9 @@
if (!doc->textDocument()) {
return;
}
- QMimeType mime = QMimeDatabase().mimeTypeForUrl(doc->url());
- adaptEditorIndentationMode( doc->textDocument(), formatterForMimeType(mime) );
+ const auto url = doc->url();
+ const auto mime = QMimeDatabase().mimeTypeForUrl(url);
+ adaptEditorIndentationMode(doc->textDocument(), formatterForUrl(url, mime), url);
}
void SourceFormatterController::initialize()
@@ -162,7 +166,21 @@
ISourceFormatter* SourceFormatterController::formatterForUrl(const QUrl &url)
{
QMimeType mime = QMimeDatabase().mimeTypeForUrl(url);
- return formatterForMimeType(mime);
+ return formatterForUrl(url, mime);
+}
+
+KConfigGroup SourceFormatterController::configForUrl(const QUrl& url) const
+{
+ auto core = KDevelop::Core::self();
+ auto project = core->projectController()->findProjectForUrl(url);
+ if (project) {
+ auto config = project->projectConfiguration()->group(Strings::SourceFormatter());
+ if (config.isValid() && !config.readEntry(Strings::UseDefault(), true)) {
+ return config;
+ }
+ }
+
+ return core->activeSession()->config()->group( Strings::SourceFormatter() );
}
KConfigGroup SourceFormatterController::sessionConfig() const
@@ -224,12 +242,13 @@
return formatter;
}
-ISourceFormatter* SourceFormatterController::formatterForMimeType(const QMimeType& mime)
+ISourceFormatter* SourceFormatterController::formatterForUrl(const QUrl& url, const QMimeType& mime)
{
if( !m_enabled || !isMimeTypeSupported( mime ) ) {
return nullptr;
}
- QString formatter = sessionConfig().readEntry( mime.name(), QString() );
+
+ const auto formatter = configForUrl(url).readEntry(mime.name(), QString());
if( formatter.isEmpty() )
{
@@ -273,11 +292,11 @@
// If there already is a modeline in the document, adapt it while formatting, even
// if "add modeline" is disabled.
- if( !sessionConfig().readEntry( SourceFormatterController::kateModeLineConfigKey(), false ) &&
+ if (!configForUrl(url).readEntry(SourceFormatterController::kateModeLineConfigKey(), false) &&
kateModelineWithNewline.indexIn( input ) == -1 )
return input;
- ISourceFormatter* fmt = formatterForMimeType( mime );
+ ISourceFormatter* fmt = formatterForUrl(url, mime);
ISourceFormatter::Indentation indentation = fmt->indentation(url);
if( !indentation.isValid() )
@@ -366,22 +385,23 @@
return;
KTextEditor::Document* doc = view->document();
// load the appropriate formatter
- QMimeType mime = QMimeDatabase().mimeTypeForUrl(doc->url());
- ISourceFormatter *formatter = formatterForMimeType(mime);
+ const auto url = idoc->url();
+ const auto mime = QMimeDatabase().mimeTypeForUrl(url);
+ ISourceFormatter* formatter = formatterForUrl(url, mime);
if( !formatter ) {
qCDebug(SHELL) << "no formatter available for" << mime.name();
return;
}
// Ignore the modeline, as the modeline will be changed anyway
- adaptEditorIndentationMode( doc, formatter, true );
+ adaptEditorIndentationMode(doc, formatter, url, true);
bool has_selection = view->selection();
if (has_selection) {
QString original = view->selectionText();
- QString output = formatter->formatSource(view->selectionText(), doc->url(), mime,
+ QString output = formatter->formatSource(view->selectionText(), url, mime,
doc->text(KTextEditor::Range(KTextEditor::Cursor(0,0),view->selectionRange().start())),
doc->text(KTextEditor::Range(view->selectionRange().end(), doc->documentRange().end())));
@@ -411,8 +431,9 @@
if (!view)
return;
// load the appropriate formatter
- QMimeType mime = QMimeDatabase().mimeTypeForUrl(doc->url());
- ISourceFormatter *formatter = formatterForMimeType(mime);
+ const auto url = doc->url();
+ const auto mime = QMimeDatabase().mimeTypeForUrl(url);
+ ISourceFormatter* formatter = formatterForUrl(url, mime);
if( !formatter ) {
qCDebug(SHELL) << "no formatter available for" << mime.name();
return;
@@ -456,9 +477,9 @@
void SourceFormatterController::settingsChanged()
{
- if( sessionConfig().readEntry( SourceFormatterController::kateOverrideIndentationConfigKey(), false ) )
- foreach( KDevelop::IDocument* doc, ICore::self()->documentController()->openDocuments() )
- adaptEditorIndentationMode( doc->textDocument(), formatterForUrl(doc->url()) );
+ foreach (KDevelop::IDocument* doc, ICore::self()->documentController()->openDocuments()) {
+ adaptEditorIndentationMode(doc->textDocument(), formatterForUrl(doc->url()), doc->url());
+ }
}
/**
@@ -473,12 +494,13 @@
* "set-tab-width X"
* */
-void SourceFormatterController::adaptEditorIndentationMode(KTextEditor::Document *doc, ISourceFormatter *formatter, bool ignoreModeline )
+void SourceFormatterController::adaptEditorIndentationMode(KTextEditor::Document *doc, ISourceFormatter *formatter,
+ const QUrl& url, bool ignoreModeline)
{
- if( !formatter || !sessionConfig().readEntry( SourceFormatterController::kateOverrideIndentationConfigKey(), false ) || !doc )
+ if (!formatter || !configForUrl(url).readEntry(SourceFormatterController::kateOverrideIndentationConfigKey(), false) || !doc)
return;
- qCDebug(SHELL) << "adapting mode for" << doc->url();
+ qCDebug(SHELL) << "adapting mode for" << url;
QRegExp kateModelineWithNewline("\\s*\\n//\\s*kate:(.*)$");
@@ -489,7 +511,7 @@
return;
}
- ISourceFormatter::Indentation indentation = formatter->indentation(doc->url());
+ ISourceFormatter::Indentation indentation = formatter->indentation(url);
if(indentation.isValid())
{
struct CommandCaller {
@@ -600,9 +622,9 @@
return ext;
}
-SourceFormatterStyle SourceFormatterController::styleForMimeType(const QMimeType& mime)
+SourceFormatterStyle SourceFormatterController::styleForUrl(const QUrl& url, const QMimeType& mime)
{
- QStringList formatter = sessionConfig().readEntry( mime.name(), QString() ).split( QStringLiteral("||"), QString::SkipEmptyParts );
+ const auto formatter = configForUrl(url).readEntry(mime.name(), QString()).split(QStringLiteral("||"), QString::SkipEmptyParts);
if( formatter.count() == 2 )
{
SourceFormatterStyle s( formatter.at( 1 ) );
diff --git a/shell/sourceformatterjob.cpp b/shell/sourceformatterjob.cpp
--- a/shell/sourceformatterjob.cpp
+++ b/shell/sourceformatterjob.cpp
@@ -122,7 +122,7 @@
// check mimetype
QMimeType mime = QMimeDatabase().mimeTypeForUrl(url);
qCDebug(SHELL) << "Checking file " << url << " of mime type " << mime.name() << endl;
- auto formatter = m_sourceFormatterController->formatterForMimeType(mime);
+ auto formatter = m_sourceFormatterController->formatterForUrl(url, mime);
if (!formatter) // unsupported mime type
return;
diff --git a/shell/sourceformatterselectionedit.h b/shell/sourceformatterselectionedit.h
new file mode 100644
--- /dev/null
+++ b/shell/sourceformatterselectionedit.h
@@ -0,0 +1,73 @@
+/* This file is part of KDevelop
+* Copyright (C) 2008 Cédric Pasteur
+ Copyright (C) 2017 Friedrich W. H. Kossebau
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
+
+*/
+
+#ifndef KDEVPLATFORM_SOURCEFORMATTERSELECTIONEDIT_H
+#define KDEVPLATFORM_SOURCEFORMATTERSELECTIONEDIT_H
+
+#include
+
+#include "shellexport.h"
+
+class KConfigGroup;
+class QListWidgetItem;
+
+namespace KDevelop
+{
+class SourceFormatterSelectionEditPrivate;
+class SourceFormatterStyle;
+
+class KDEVPLATFORMSHELL_EXPORT SourceFormatterSelectionEdit : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit SourceFormatterSelectionEdit(QWidget* parent = nullptr);
+ ~SourceFormatterSelectionEdit() override;
+
+public:
+ void loadSettings(const KConfigGroup& config);
+ void saveSettings(KConfigGroup& config);
+
+Q_SIGNALS:
+ void changed();
+
+private Q_SLOTS:
+ void deleteStyle();
+ void editStyle();
+ void newStyle();
+ void selectLanguage(int );
+ void selectFormatter(int );
+ void selectStyle(int );
+ void styleNameChanged(QListWidgetItem* );
+
+private:
+ void updatePreview();
+ QListWidgetItem* addStyle(const KDevelop::SourceFormatterStyle& s);
+ void enableStyleButtons();
+
+private:
+ SourceFormatterSelectionEditPrivate * const d;
+};
+
+}
+
+#endif
+
diff --git a/shell/settings/sourceformattersettings.cpp b/shell/sourceformatterselectionedit.cpp
copy from shell/settings/sourceformattersettings.cpp
copy to shell/sourceformatterselectionedit.cpp
--- a/shell/settings/sourceformattersettings.cpp
+++ b/shell/sourceformatterselectionedit.cpp
@@ -1,5 +1,6 @@
/* This file is part of KDevelop
* Copyright (C) 2008 Cédric Pasteur
+ Copyright (C) 2017 Friedrich W. H. Kossebau
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
@@ -17,106 +18,126 @@
Boston, MA 02110-1301, USA.
*/
-#include "sourceformattersettings.h"
-#include
-#include
-#include
-#include
+#include "sourceformatterselectionedit.h"
+#include "ui_sourceformatterselectionedit.h"
+
+#include "sourceformattercontroller.h"
+#include "settings/editstyledialog.h"
+#include "debug.h"
+#include "core.h"
+#include "plugincontroller.h"
+
+#include
+#include
+#include // TODO: remove later
#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
#include
-#include
+#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
-#include "editstyledialog.h"
-#include "debug.h"
#define STYLE_ROLE (Qt::UserRole+1)
-using KDevelop::Core;
-using KDevelop::ISourceFormatter;
-using KDevelop::SourceFormatterStyle;
-using KDevelop::SourceFormatterController;
-using KDevelop::SourceFormatter;
+using namespace KDevelop;
namespace {
namespace Strings {
QString userStylePrefix() { return QStringLiteral("User"); }
}
}
-LanguageSettings::LanguageSettings()
- : selectedFormatter(nullptr), selectedStyle(nullptr) {
-}
+struct LanguageSettings {
+ QList mimetypes;
+ QSet formatters;
+ // weak pointers to selected formatter and style, no ownership
+ KDevelop::SourceFormatter* selectedFormatter = nullptr; // Should never be zero
+ KDevelop::SourceFormatterStyle* selectedStyle = nullptr; // TODO: can this be zero? Assume that not
+};
+
+
+typedef QMap LanguageMap;
+typedef QMap FormatterMap;
-SourceFormatterSettings::SourceFormatterSettings(QWidget* parent)
- : KDevelop::ConfigPage(nullptr, nullptr, parent)
+
+class KDevelop::SourceFormatterSelectionEditPrivate
+{
+public:
+ Ui::SourceFormatterSelectionEdit ui;
+ // Language name -> language settings
+ LanguageMap languages;
+ // formatter name -> formatter. Formatters owned by this
+ FormatterMap formatters;
+ KTextEditor::Document* document;
+ KTextEditor::View* view;
+};
+
+SourceFormatterSelectionEdit::SourceFormatterSelectionEdit(QWidget* parent)
+ : QWidget(parent)
+ , d(new SourceFormatterSelectionEditPrivate)
{
- setupUi(this);
- connect( cbLanguages, static_cast(&KComboBox::currentIndexChanged), this, &SourceFormatterSettings::selectLanguage );
- connect( cbFormatters, static_cast(&KComboBox::currentIndexChanged), this, &SourceFormatterSettings::selectFormatter );
- connect( chkKateModelines, &QCheckBox::toggled, this, &SourceFormatterSettings::somethingChanged );
- connect( chkKateOverrideIndentation, &QCheckBox::toggled, this, &SourceFormatterSettings::somethingChanged );
- connect( styleList, &QListWidget::currentRowChanged, this, &SourceFormatterSettings::selectStyle );
- connect( btnDelStyle, &QPushButton::clicked, this, &SourceFormatterSettings::deleteStyle );
- connect( btnNewStyle, &QPushButton::clicked, this, &SourceFormatterSettings::newStyle );
- connect( btnEditStyle, &QPushButton::clicked, this, &SourceFormatterSettings::editStyle );
- connect( styleList, &QListWidget::itemChanged, this, &SourceFormatterSettings::styleNameChanged );
-
- m_document = KTextEditor::Editor::instance()->createDocument(this);
- m_document->setReadWrite(false);
-
- m_view = m_document->createView(textEditor);
- m_view->setStatusBarEnabled(false);
-
- QVBoxLayout *layout2 = new QVBoxLayout(textEditor);
- layout2->addWidget(m_view);
- textEditor->setLayout(layout2);
- m_view->show();
+ d->ui.setupUi(this);
+
+ connect(d->ui.cbLanguages, static_cast(&KComboBox::currentIndexChanged),
+ this, &SourceFormatterSelectionEdit::selectLanguage);
+ connect(d->ui.cbFormatters, static_cast(&KComboBox::currentIndexChanged),
+ this, &SourceFormatterSelectionEdit::selectFormatter);
+ connect(d->ui.styleList, &QListWidget::currentRowChanged, this, &SourceFormatterSelectionEdit::selectStyle);
+ connect(d->ui.btnDelStyle, &QPushButton::clicked, this, &SourceFormatterSelectionEdit::deleteStyle);
+ connect(d->ui.btnNewStyle, &QPushButton::clicked, this, &SourceFormatterSelectionEdit::newStyle);
+ connect(d->ui.btnEditStyle, &QPushButton::clicked, this, &SourceFormatterSelectionEdit::editStyle);
+ connect(d->ui.styleList, &QListWidget::itemChanged, this, &SourceFormatterSelectionEdit::styleNameChanged);
+
+ d->document = KTextEditor::Editor::instance()->createDocument(this);
+ d->document->setReadWrite(false);
+
+ d->view = d->document->createView(d->ui.textEditor);
+ d->view->setStatusBarEnabled(false);
+
+ QVBoxLayout *layout2 = new QVBoxLayout(d->ui.textEditor);
+ layout2->addWidget(d->view);
+ d->ui.textEditor->setLayout(layout2);
+ d->view->show();
KTextEditor::ConfigInterface *iface =
- qobject_cast(m_view);
+ qobject_cast(d->view);
if (iface) {
iface->setConfigValue(QStringLiteral("dynamic-word-wrap"), false);
iface->setConfigValue(QStringLiteral("icon-bar"), false);
}
}
-SourceFormatterSettings::~SourceFormatterSettings()
+SourceFormatterSelectionEdit::~SourceFormatterSelectionEdit()
{
- qDeleteAll(formatters);
+ qDeleteAll(d->formatters);
+ delete d;
}
-void selectAvailableStyle(LanguageSettings& lang) {
+static void selectAvailableStyle(LanguageSettings& lang)
+{
Q_ASSERT(!lang.selectedFormatter->styles.empty());
lang.selectedStyle = *lang.selectedFormatter->styles.begin();
}
-void SourceFormatterSettings::reset()
+void SourceFormatterSelectionEdit::loadSettings(const KConfigGroup& config)
{
SourceFormatterController* fmtctrl = Core::self()->sourceFormatterControllerInternal();
QList plugins = KDevelop::ICore::self()->pluginController()->allPluginsForExtension( QStringLiteral("org.kdevelop.ISourceFormatter") );
foreach( KDevelop::IPlugin* plugin, plugins )
{
KDevelop::ISourceFormatter* ifmt = plugin->extension();
auto info = KDevelop::Core::self()->pluginControllerInternal()->pluginInfo( plugin );
KDevelop::SourceFormatter* formatter;
- FormatterMap::const_iterator iter = formatters.constFind(ifmt->name());
- if (iter == formatters.constEnd()) {
+ FormatterMap::const_iterator iter = d->formatters.constFind(ifmt->name());
+ if (iter == d->formatters.constEnd()) {
formatter = fmtctrl->createFormatterForPlugin(ifmt);
- formatters[ifmt->name()] = formatter;
+ d->formatters[ifmt->name()] = formatter;
} else {
formatter = iter.value();
}
@@ -128,7 +149,7 @@
continue;
}
QString languageName = item.highlightMode;
- LanguageSettings& l = languages[languageName];
+ LanguageSettings& l = d->languages[languageName];
l.mimetypes.append(mime);
l.formatters.insert( formatter );
}
@@ -142,25 +163,24 @@
KDevelop::ICore::self()->languageController()->activeLanguages() +
KDevelop::ICore::self()->languageController()->loadedLanguages())
{
- if( languages.contains( language->name() ) && !sortedLanguages.contains(language->name()) ) {
+ if( d->languages.contains( language->name() ) && !sortedLanguages.contains(language->name()) ) {
sortedLanguages.push_back( language->name() );
}
}
- foreach( const QString& name, languages.keys() )
+ foreach( const QString& name, d->languages.keys() )
if( !sortedLanguages.contains( name ) )
sortedLanguages.push_back( name );
foreach( const QString& name, sortedLanguages )
{
// Pick the first appropriate mimetype for this language
- KConfigGroup grp = fmtctrl->sessionConfig();
- LanguageSettings& l = languages[name];
+ LanguageSettings& l = d->languages[name];
const QList mimetypes = l.mimetypes;
foreach (const QMimeType& mimetype, mimetypes) {
- QStringList formatterAndStyleName = grp.readEntry(mimetype.name(), QString()).split(QStringLiteral("||"), QString::KeepEmptyParts);
- FormatterMap::const_iterator formatterIter = formatters.constFind(formatterAndStyleName.first());
- if (formatterIter == formatters.constEnd()) {
+ QStringList formatterAndStyleName = config.readEntry(mimetype.name(), QString()).split(QStringLiteral("||"), QString::KeepEmptyParts);
+ FormatterMap::const_iterator formatterIter = d->formatters.constFind(formatterAndStyleName.first());
+ if (formatterIter == d->formatters.constEnd()) {
qCDebug(SHELL) << "Reference to unknown formatter" << formatterAndStyleName.first();
Q_ASSERT(!l.formatters.empty()); // otherwise there should be no entry for 'name'
l.selectedFormatter = *l.formatters.begin();
@@ -185,43 +205,38 @@
}
}
bool b = blockSignals( true );
- cbLanguages->blockSignals( !b );
- cbFormatters->blockSignals( !b );
- styleList->blockSignals( !b );
- chkKateModelines->blockSignals( !b );
- chkKateOverrideIndentation->blockSignals( !b );
- cbLanguages->clear();
- cbFormatters->clear();
- styleList->clear();
- chkKateModelines->setChecked( fmtctrl->sessionConfig().readEntry( SourceFormatterController::kateModeLineConfigKey(), false ) );
- chkKateOverrideIndentation->setChecked( fmtctrl->sessionConfig().readEntry( SourceFormatterController::kateOverrideIndentationConfigKey(), false ) );
+ d->ui.cbLanguages->blockSignals( !b );
+ d->ui.cbFormatters->blockSignals( !b );
+ d->ui.styleList->blockSignals( !b );
+ d->ui.cbLanguages->clear();
+ d->ui.cbFormatters->clear();
+ d->ui.styleList->clear();
foreach( const QString& name, sortedLanguages )
{
- cbLanguages->addItem( name );
+ d->ui.cbLanguages->addItem( name );
}
- if( cbLanguages->count() == 0 )
+ if( d->ui.cbLanguages->count() == 0 )
{
- cbLanguages->setEnabled( false );
+ d->ui.cbLanguages->setEnabled( false );
selectLanguage( -1 );
} else
{
- cbLanguages->setCurrentIndex( 0 );
+ d->ui.cbLanguages->setCurrentIndex( 0 );
selectLanguage( 0 );
}
updatePreview();
blockSignals( b );
- cbLanguages->blockSignals( b );
- cbFormatters->blockSignals( b );
- styleList->blockSignals( b );
- chkKateModelines->blockSignals( b );
- chkKateOverrideIndentation->blockSignals( b );
+ d->ui.cbLanguages->blockSignals( b );
+ d->ui.cbFormatters->blockSignals( b );
+ d->ui.styleList->blockSignals( b );
}
-void SourceFormatterSettings::apply()
+void SourceFormatterSelectionEdit::saveSettings(KConfigGroup& config)
{
+ // store formatters globally
KConfigGroup globalConfig = Core::self()->sourceFormatterControllerInternal()->globalConfig();
- foreach( SourceFormatter* fmt, formatters )
+ foreach( SourceFormatter* fmt, d->formatters )
{
KConfigGroup fmtgrp = globalConfig.group( fmt->formatter->name() );
@@ -244,133 +259,123 @@
}
}
}
+ globalConfig.sync();
- KConfigGroup sessionConfig = Core::self()->sourceFormatterControllerInternal()->sessionConfig();
- for ( LanguageMap::const_iterator iter = languages.constBegin(); iter != languages.constEnd(); ++iter ) {
- foreach(const QMimeType& mime, iter.value().mimetypes) {
- sessionConfig.writeEntry(mime.name(), QStringLiteral("%1||%2").arg(iter.value().selectedFormatter->formatter->name(), iter.value().selectedStyle->name()));
+ // store selected formatters in given language
+ for(const auto& setting : d->languages) {
+ for(const auto& mime : setting.mimetypes) {
+ const QString formatterId = setting.selectedFormatter->formatter->name() + QLatin1String("||") + setting.selectedStyle->name();
+ config.writeEntry(mime.name(), formatterId);
}
}
- sessionConfig.writeEntry( SourceFormatterController::kateModeLineConfigKey(), chkKateModelines->isChecked() );
- sessionConfig.writeEntry( SourceFormatterController::kateOverrideIndentationConfigKey(), chkKateOverrideIndentation->isChecked() );
-
- sessionConfig.sync();
- globalConfig.sync();
-
- Core::self()->sourceFormatterControllerInternal()->settingsChanged();
-}
-
-void SourceFormatterSettings::defaults()
-{
- // do nothing
}
-void SourceFormatterSettings::enableStyleButtons()
+void SourceFormatterSelectionEdit::enableStyleButtons()
{
- bool userEntry = styleList->currentItem()
- && styleList->currentItem()->data( STYLE_ROLE ).toString().startsWith( Strings::userStylePrefix() );
+ bool userEntry = d->ui.styleList->currentItem()
+ && d->ui.styleList->currentItem()->data( STYLE_ROLE ).toString().startsWith( Strings::userStylePrefix() );
- QString languageName = cbLanguages->currentText();
- QMap< QString, LanguageSettings >::const_iterator it = languages.constFind(languageName);
+ QString languageName = d->ui.cbLanguages->currentText();
+ QMap< QString, LanguageSettings >::const_iterator it = d->languages.constFind(languageName);
bool hasEditWidget = false;
- if (it != languages.constEnd()) {
+ if (it != d->languages.constEnd()) {
const LanguageSettings& l = it.value();
Q_ASSERT(l.selectedFormatter);
ISourceFormatter* fmt = l.selectedFormatter->formatter;
hasEditWidget = ( fmt && QScopedPointer(fmt->editStyleWidget( l.mimetypes.first() )) );
}
- btnDelStyle->setEnabled( userEntry );
- btnEditStyle->setEnabled( userEntry && hasEditWidget );
- btnNewStyle->setEnabled( cbFormatters->currentIndex() >= 0 && hasEditWidget );
+ d->ui.btnDelStyle->setEnabled( userEntry );
+ d->ui.btnEditStyle->setEnabled( userEntry && hasEditWidget );
+ d->ui.btnNewStyle->setEnabled( d->ui.cbFormatters->currentIndex() >= 0 && hasEditWidget );
}
-void SourceFormatterSettings::selectLanguage( int idx )
+void SourceFormatterSelectionEdit::selectLanguage( int idx )
{
- cbFormatters->clear();
+ d->ui.cbFormatters->clear();
if( idx < 0 )
{
- cbFormatters->setEnabled( false );
+ d->ui.cbFormatters->setEnabled( false );
selectFormatter( -1 );
return;
}
- cbFormatters->setEnabled( true );
+ d->ui.cbFormatters->setEnabled( true );
{
- QSignalBlocker blocker(cbFormatters);
- LanguageSettings& l = languages[cbLanguages->itemText( idx )];
+ QSignalBlocker blocker(d->ui.cbFormatters);
+ LanguageSettings& l = d->languages[d->ui.cbLanguages->itemText( idx )];
foreach( const SourceFormatter* fmt, l.formatters )
{
- cbFormatters->addItem( fmt->formatter->caption(), fmt->formatter->name() );
+ d->ui.cbFormatters->addItem( fmt->formatter->caption(), fmt->formatter->name() );
}
- cbFormatters->setCurrentIndex(cbFormatters->findData(l.selectedFormatter->formatter->name()));
+ d->ui.cbFormatters->setCurrentIndex(d->ui.cbFormatters->findData(l.selectedFormatter->formatter->name()));
}
- selectFormatter( cbFormatters->currentIndex() );
+ selectFormatter( d->ui.cbFormatters->currentIndex() );
emit changed();
}
-void SourceFormatterSettings::selectFormatter( int idx )
+void SourceFormatterSelectionEdit::selectFormatter( int idx )
{
- styleList->clear();
+ d->ui.styleList->clear();
if( idx < 0 )
{
- styleList->setEnabled( false );
+ d->ui.styleList->setEnabled( false );
enableStyleButtons();
return;
}
- styleList->setEnabled( true );
- LanguageSettings& l = languages[ cbLanguages->currentText() ];
+ d->ui.styleList->setEnabled( true );
+ LanguageSettings& l = d->languages[ d->ui.cbLanguages->currentText() ];
Q_ASSERT( idx < l.formatters.size() );
- FormatterMap::const_iterator formatterIter = formatters.constFind(cbFormatters->itemData( idx ).toString());
- Q_ASSERT( formatterIter != formatters.constEnd() );
+ FormatterMap::const_iterator formatterIter = d->formatters.constFind(d->ui.cbFormatters->itemData( idx ).toString());
+ Q_ASSERT( formatterIter != d->formatters.constEnd() );
Q_ASSERT( l.formatters.contains(formatterIter.value()) );
if (l.selectedFormatter != formatterIter.value()) {
l.selectedFormatter = formatterIter.value();
l.selectedStyle = nullptr; // will hold 0 until a style is picked
}
foreach( const SourceFormatterStyle* style, formatterIter.value()->styles ) {
- if ( ! style->supportsLanguage(cbLanguages->currentText())) {
+ if ( ! style->supportsLanguage(d->ui.cbLanguages->currentText())) {
// do not list items which do not support the selected language
continue;
}
QListWidgetItem* item = addStyle( *style );
if (style == l.selectedStyle) {
- styleList->setCurrentItem(item);
+ d->ui.styleList->setCurrentItem(item);
}
}
if (l.selectedStyle == nullptr) {
- styleList->setCurrentRow(0);
+ d->ui.styleList->setCurrentRow(0);
}
enableStyleButtons();
emit changed();
}
-void SourceFormatterSettings::selectStyle( int row )
+void SourceFormatterSelectionEdit::selectStyle( int row )
{
if( row < 0 )
{
enableStyleButtons();
return;
}
- styleList->setCurrentRow( row );
- LanguageSettings& l = languages[ cbLanguages->currentText() ];
- l.selectedStyle = l.selectedFormatter->styles[styleList->item( row )->data( STYLE_ROLE ).toString()];
+ d->ui.styleList->setCurrentRow( row );
+ LanguageSettings& l = d->languages[ d->ui.cbLanguages->currentText() ];
+ l.selectedStyle = l.selectedFormatter->styles[d->ui.styleList->item( row )->data( STYLE_ROLE ).toString()];
enableStyleButtons();
updatePreview();
emit changed();
}
-void SourceFormatterSettings::deleteStyle()
+void SourceFormatterSelectionEdit::deleteStyle()
{
- Q_ASSERT( styleList->currentRow() >= 0 );
+ Q_ASSERT( d->ui.styleList->currentRow() >= 0 );
- QListWidgetItem* item = styleList->currentItem();
+ QListWidgetItem* item = d->ui.styleList->currentItem();
- LanguageSettings& l = languages[ cbLanguages->currentText() ];
+ LanguageSettings& l = d->languages[ d->ui.cbLanguages->currentText() ];
SourceFormatter* fmt = l.selectedFormatter;
SourceFormatter::StyleMap::iterator styleIter = fmt->styles.find(item->data( STYLE_ROLE ).toString());
QStringList otherLanguageNames;
QList otherlanguages;
- for ( LanguageMap::iterator languageIter = languages.begin(); languageIter != languages.end(); ++languageIter ) {
+ for ( LanguageMap::iterator languageIter = d->languages.begin(); languageIter != d->languages.end(); ++languageIter ) {
if ( &languageIter.value() != &l && languageIter.value().selectedStyle == styleIter.value() ) {
otherLanguageNames.append(languageIter.key());
otherlanguages.append(&languageIter.value());
@@ -382,22 +387,22 @@
styleIter.value()->caption(), otherLanguageNames.join(QStringLiteral("\n"))), i18n("Style being deleted")) != KMessageBox::Continue) {
return;
}
- styleList->takeItem( styleList->currentRow() );
+ d->ui.styleList->takeItem( d->ui.styleList->currentRow() );
fmt->styles.erase(styleIter);
delete item;
- selectStyle( styleList->count() > 0 ? 0 : -1 );
+ selectStyle( d->ui.styleList->count() > 0 ? 0 : -1 );
foreach (LanguageSettings* lang, otherlanguages) {
selectAvailableStyle(*lang);
}
updatePreview();
emit changed();
}
-void SourceFormatterSettings::editStyle()
+void SourceFormatterSelectionEdit::editStyle()
{
- QString language = cbLanguages->currentText();
- Q_ASSERT( languages.contains( language ) );
- LanguageSettings& l = languages[ language ];
+ QString language = d->ui.cbLanguages->currentText();
+ Q_ASSERT( d->languages.contains( language ) );
+ LanguageSettings& l = d->languages[ language ];
SourceFormatter* fmt = l.selectedFormatter;
QMimeType mimetype = l.mimetypes.first();
@@ -412,15 +417,15 @@
}
}
-void SourceFormatterSettings::newStyle()
+void SourceFormatterSelectionEdit::newStyle()
{
- QListWidgetItem* item = styleList->currentItem();
- LanguageSettings& l = languages[ cbLanguages->currentText() ];
+ QListWidgetItem* item = d->ui.styleList->currentItem();
+ LanguageSettings& l = d->languages[ d->ui.cbLanguages->currentText() ];
SourceFormatter* fmt = l.selectedFormatter;
int idx = 0;
- for( int i = 0; i < styleList->count(); i++ )
+ for( int i = 0; i < d->ui.styleList->count(); i++ )
{
- QString name = styleList->item( i )->data( STYLE_ROLE ).toString();
+ QString name = d->ui.styleList->item( i )->data( STYLE_ROLE ).toString();
if( name.startsWith( Strings::userStylePrefix() ) && name.midRef( Strings::userStylePrefix().length() ).toInt() >= idx )
{
idx = name.midRef( Strings::userStylePrefix().length() ).toInt();
@@ -438,102 +443,79 @@
}
fmt->styles[ s->name() ] = s;
QListWidgetItem* newitem = addStyle( *s );
- selectStyle( styleList->row( newitem ) );
- styleList->editItem( newitem );
+ selectStyle( d->ui.styleList->row( newitem ) );
+ d->ui.styleList->editItem( newitem );
emit changed();
}
-void SourceFormatterSettings::styleNameChanged( QListWidgetItem* item )
+void SourceFormatterSelectionEdit::styleNameChanged( QListWidgetItem* item )
{
if ( !item->isSelected() ) {
return;
}
- LanguageSettings& l = languages[ cbLanguages->currentText() ];
+ LanguageSettings& l = d->languages[ d->ui.cbLanguages->currentText() ];
l.selectedStyle->setCaption( item->text() );
emit changed();
}
-QListWidgetItem* SourceFormatterSettings::addStyle( const SourceFormatterStyle& s )
+QListWidgetItem* SourceFormatterSelectionEdit::addStyle( const SourceFormatterStyle& s )
{
- QListWidgetItem* item = new QListWidgetItem( styleList );
+ QListWidgetItem* item = new QListWidgetItem( d->ui.styleList );
item->setText( s.caption() );
item->setData( STYLE_ROLE, s.name() );
if( s.name().startsWith( Strings::userStylePrefix() ) )
{
item->setFlags( item->flags() | Qt::ItemIsEditable );
}
- styleList->addItem( item );
+ d->ui.styleList->addItem( item );
return item;
}
-void SourceFormatterSettings::updatePreview()
+void SourceFormatterSelectionEdit::updatePreview()
{
- m_document->setReadWrite( true );
+ d->document->setReadWrite( true );
- QString langName = cbLanguages->itemText( cbLanguages->currentIndex() );
+ QString langName = d->ui.cbLanguages->itemText( d->ui.cbLanguages->currentIndex() );
if( !langName.isEmpty() )
{
- LanguageSettings& l = languages[ langName ];
+ LanguageSettings& l = d->languages[ langName ];
SourceFormatter* fmt = l.selectedFormatter;
SourceFormatterStyle* style = l.selectedStyle;
- descriptionLabel->setText( style->description() );
+ d->ui.descriptionLabel->setText( style->description() );
if( style->usePreview() )
{
ISourceFormatter* ifmt = fmt->formatter;
QMimeType mime = l.mimetypes.first();
- m_document->setHighlightingMode( style->modeForMimetype( mime ) );
+ d->document->setHighlightingMode( style->modeForMimetype( mime ) );
//NOTE: this is ugly, but otherwise kate might remove tabs again :-/
// see also: https://bugs.kde.org/show_bug.cgi?id=291074
- KTextEditor::ConfigInterface* iface = qobject_cast(m_document);
+ KTextEditor::ConfigInterface* iface = qobject_cast(d->document);
QVariant oldReplaceTabs;
if (iface) {
oldReplaceTabs = iface->configValue(QStringLiteral("replace-tabs"));
iface->setConfigValue(QStringLiteral("replace-tabs"), false);
}
- m_document->setText( ifmt->formatSourceWithStyle( *style, ifmt->previewText( *style, mime ), QUrl(), mime ) );
+ d->document->setText( ifmt->formatSourceWithStyle( *style, ifmt->previewText( *style, mime ), QUrl(), mime ) );
if (iface) {
iface->setConfigValue(QStringLiteral("replace-tabs"), oldReplaceTabs);
}
- previewLabel->show();
- textEditor->show();
+ d->ui.previewLabel->show();
+ d->ui.textEditor->show();
}else{
- previewLabel->hide();
- textEditor->hide();
+ d->ui.previewLabel->hide();
+ d->ui.textEditor->hide();
}
} else
{
- m_document->setText( i18n( "No Language selected" ) );
+ d->document->setText( i18n( "No Language selected" ) );
}
- m_view->setCursorPosition( KTextEditor::Cursor( 0, 0 ) );
- m_document->setReadWrite( false );
-}
-
-void SourceFormatterSettings::somethingChanged()
-{
- // Widgets are managed manually, so we have to explicitly tell KCModule
- // that we have some changes, otherwise it won't call "save" and/or will not activate
- // "Appy"
- emit changed();
-}
-
-QString SourceFormatterSettings::name() const
-{
- return i18n("Source Formatter");
-}
-
-QString SourceFormatterSettings::fullName() const
-{
- return i18n("Configure Source Formatter");
-}
-
-QIcon SourceFormatterSettings::icon() const
-{
- return QIcon::fromTheme(QStringLiteral("text-field"));
+ d->view->setCursorPosition( KTextEditor::Cursor( 0, 0 ) );
+ d->document->setReadWrite( false );
}
diff --git a/shell/sourceformatterselectionedit.ui b/shell/sourceformatterselectionedit.ui
new file mode 100644
--- /dev/null
+++ b/shell/sourceformatterselectionedit.ui
@@ -0,0 +1,181 @@
+
+
+ KDevelop::SourceFormatterSelectionEdit
+
+
+
+ 0
+ 0
+ 509
+ 344
+
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+ -
+
+
+ Language:
+
+
+ Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing
+
+
+ 4
+
+
+
+ -
+
+
-
+
+
+
+
+ -
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+ Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop
+
+
+ true
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 10
+
+
+
+
+ -
+
+
+ Preview:
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+
+
+ -
+
+
+ Formatter:
+
+
+ Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing
+
+
+ 4
+
+
+
+ -
+
+
-
+
+
+
+
+ -
+
+
+ Style:
+
+
+ Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing
+
+
+ 4
+
+
+ -1
+
+
+
+ -
+
+
-
+
+
+ New
+
+
+
+ -
+
+
+ Edit...
+
+
+
+ -
+
+
+ Delete
+
+
+
+ -
+
+
+ QAbstractItemView::SelectRows
+
+
+ false
+
+
+
+
+
+
+
+
+
+ KComboBox
+ QComboBox
+
+
+
+
+
+