diff --git a/kate/CMakeLists.txt b/kate/CMakeLists.txt --- a/kate/CMakeLists.txt +++ b/kate/CMakeLists.txt @@ -26,6 +26,7 @@ kateviewspace.cpp katesavemodifieddialog.cpp katemwmodonhddialog.cpp + katecolorschemechooser.cpp katetabbutton.cpp katetabbar.cpp diff --git a/kate/data/kateui.rc b/kate/data/kateui.rc --- a/kate/data/kateui.rc +++ b/kate/data/kateui.rc @@ -100,6 +100,7 @@ &Settings + &Help diff --git a/kate/katecolorschemechooser.h b/kate/katecolorschemechooser.h new file mode 100644 --- /dev/null +++ b/kate/katecolorschemechooser.h @@ -0,0 +1,54 @@ +/************************************************************************************* + * This file is part of KDevPlatform * + * Copyright 2016 Zhigalin Alexander * + * * + * 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) version 3, or any * + * later version accepted by the membership of KDE e.V. (or its * + * successor approved by the membership of KDE e.V.), which shall * + * act as a proxy defined in Section 6 of version 3 of the license. * + * * + * 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, see . * + *************************************************************************************/ + +#ifndef COLORSCHEMECHOOSER_H +#define COLORSCHEMECHOOSER_H + +#include +#include +#include +#include + +#include + +class KActionCollection; + +/** +* Provides a menu that will offer to change the color scheme +* +* Furthermore, it will save the selection in the user configuration. +*/ +class KateColorSchemeChooser : public QAction +{ + public: + KateColorSchemeChooser(QObject* parent); + + QString currentSchemeName() const; + private Q_SLOTS: + void slotSchemeChanged(QAction* triggeredAction); + + private: + QString loadCurrentScheme() const; + void saveCurrentScheme(const QString &name); + QString currentDesktopDefaultScheme() const; +}; + +#endif // COLORSCHEMECHOOSER_H diff --git a/kate/katecolorschemechooser.cpp b/kate/katecolorschemechooser.cpp new file mode 100644 --- /dev/null +++ b/kate/katecolorschemechooser.cpp @@ -0,0 +1,100 @@ +/************************************************************************************* + * This file is part of KDevPlatform * + * Copyright 2016 Zhigalin Alexander * + * * + * 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) version 3, or any * + * later version accepted by the membership of KDE e.V. (or its * + * successor approved by the membership of KDE e.V.), which shall * + * act as a proxy defined in Section 6 of version 3 of the license. * + * * + * 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, see . * + *************************************************************************************/ + +#include "katecolorschemechooser.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "katemainwindow.h" +#include "katedebug.h" + + +KateColorSchemeChooser::KateColorSchemeChooser(QObject* parent) +: QAction(parent) +{ + auto manager = new KColorSchemeManager(parent); + + const auto scheme(currentSchemeName()); + qCDebug(LOG_KATE) << "Color scheme : " << scheme; + + auto selectionMenu = manager->createSchemeSelectionMenu(scheme, this); + + connect(selectionMenu->menu(), &QMenu::triggered, + this, &KateColorSchemeChooser::slotSchemeChanged); + + manager->activateScheme(manager->indexForScheme(scheme)); + + setMenu(selectionMenu->menu()); + menu()->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-color"))); + menu()->setTitle(i18n("&Color Theme")); +} + +QString KateColorSchemeChooser::loadCurrentScheme() const +{ + KSharedConfigPtr config = KSharedConfig::openConfig(); + KConfigGroup cg(config, "UiSettings"); + return cg.readEntry("ColorScheme", currentDesktopDefaultScheme()); +} + +void KateColorSchemeChooser::saveCurrentScheme(const QString &name) +{ + KSharedConfigPtr config = KSharedConfig::openConfig(); + KConfigGroup cg(config, "UiSettings"); + cg.writeEntry("ColorScheme", name); + cg.sync(); +} + +QString KateColorSchemeChooser::currentDesktopDefaultScheme() const +{ + KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("kdeglobals")); + KConfigGroup group(config, "General"); + return group.readEntry("ColorScheme", QStringLiteral("Breeze")); +} + +QString KateColorSchemeChooser::currentSchemeName() const +{ + if(!menu()) return loadCurrentScheme(); + + QAction* const action = menu()->activeAction(); + + if(action) return KLocalizedString::removeAcceleratorMarker(action->text()); + return currentDesktopDefaultScheme(); +} + +void KateColorSchemeChooser::slotSchemeChanged(QAction* triggeredAction) +{ + saveCurrentScheme(KLocalizedString::removeAcceleratorMarker(triggeredAction->text())); +} diff --git a/kate/katemainwindow.h b/kate/katemainwindow.h --- a/kate/katemainwindow.h +++ b/kate/katemainwindow.h @@ -523,6 +523,7 @@ KToggleAction *m_paShowMenuBar; KToggleAction *m_paShowStatusBar; KToggleAction *m_paShowTabBar; + QWidget *m_bottomViewBarContainer; KateContainerStackedLayout *m_bottomContainerStack; diff --git a/kate/katemainwindow.cpp b/kate/katemainwindow.cpp --- a/kate/katemainwindow.cpp +++ b/kate/katemainwindow.cpp @@ -36,6 +36,7 @@ #include "katequickopen.h" #include "kateupdatedisabler.h" #include "katedebug.h" +#include "katecolorschemechooser.h" #include #include @@ -79,6 +80,7 @@ #include #include + //END KateMwModOnHdDialog *KateMainWindow::s_modOnHdDialog = nullptr; @@ -229,6 +231,9 @@ connect(m_paShowPath, SIGNAL(toggled(bool)), this, SLOT(updateCaption())); m_paShowPath->setWhatsThis(i18n("Show the complete document path in the window caption")); + // Load themes + actionCollection()->addAction(QStringLiteral("colorscheme_menu"), new KateColorSchemeChooser(actionCollection())); + QAction * a = actionCollection()->addAction(KStandardAction::Back, QStringLiteral("view_prev_tab")); a->setText(i18n("&Previous Tab")); a->setWhatsThis(i18n("Focus the previous tab."));