Commit 99346bf1 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

Minor changes in AppColorSchemeChooser

- refactor the code
- remove redundant includes
- change the string used in the GUI to "window color scheme", to differentiate
  between it and the terminal color schemes
parent dc8ad830
......@@ -39,7 +39,7 @@
<DefineGroup name="session-settings"/>
<Action name="manage-profiles"/>
<Action name="show-menubar"/>
<Action name="colorscheme-menu"/>
<Action name="window-colorscheme-menu"/>
<Separator/>
<Action name="view-full-screen"/>
<Separator/>
......
......@@ -8,14 +8,8 @@
#include "AppColorSchemeChooser.h"
#include "konsoledebug.h"
#include <QActionGroup>
#include <QDirIterator>
#include <QFileInfo>
#include <QMenu>
#include <QModelIndex>
#include <QStandardPaths>
#include <QStringList>
#include <QtGlobal>
#include <KActionCollection>
#include <KActionMenu>
......@@ -23,17 +17,15 @@
#include <KLocalizedString>
#include <KSharedConfig>
#include "MainWindow.h"
AppColorSchemeChooser::AppColorSchemeChooser(QObject *parent)
: QAction(parent)
{
auto manager = new KColorSchemeManager(parent);
auto *manager = new KColorSchemeManager(parent);
const auto scheme(currentSchemeName());
const QString scheme(currentSchemeName());
qCDebug(KonsoleDebug) << "Color scheme : " << scheme;
auto selectionMenu = manager->createSchemeSelectionMenu(scheme, this);
auto *selectionMenu = manager->createSchemeSelectionMenu(scheme, this);
connect(selectionMenu->menu(), &QMenu::triggered, this, &AppColorSchemeChooser::slotSchemeChanged);
......@@ -41,39 +33,28 @@ AppColorSchemeChooser::AppColorSchemeChooser(QObject *parent)
setMenu(selectionMenu->menu());
menu()->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-color")));
menu()->setTitle(i18n("&Color Scheme"));
}
QString AppColorSchemeChooser::loadCurrentScheme() const
{
KSharedConfigPtr config = KSharedConfig::openConfig();
KConfigGroup cg(config, "UiSettings");
return cg.readEntry("ColorScheme", QString());
}
void AppColorSchemeChooser::saveCurrentScheme(const QString &name)
{
KSharedConfigPtr config = KSharedConfig::openConfig();
KConfigGroup cg(config, "UiSettings");
cg.writeEntry("ColorScheme", name);
cg.sync();
menu()->setTitle(i18n("&Window Color Scheme"));
}
QString AppColorSchemeChooser::currentSchemeName() const
{
if (!menu()) {
return loadCurrentScheme();
KSharedConfigPtr config = KSharedConfig::openConfig();
KConfigGroup cg(config, "UiSettings");
return cg.readEntry("WindowColorScheme", QString());
}
QAction *const action = menu()->activeAction();
if (action) {
if (QAction *const action = menu()->activeAction()) {
return KLocalizedString::removeAcceleratorMarker(action->text());
}
return QString();
}
void AppColorSchemeChooser::slotSchemeChanged(QAction *triggeredAction)
{
saveCurrentScheme(KLocalizedString::removeAcceleratorMarker(triggeredAction->text()));
KSharedConfigPtr config = KSharedConfig::openConfig();
KConfigGroup cg(config, "UiSettings");
cg.writeEntry("WindowColorScheme", KLocalizedString::removeAcceleratorMarker(triggeredAction->text()));
cg.sync();
}
......@@ -9,9 +9,7 @@
#define KONSOLE_COLOR_SCHEME_CHOOSER_H
#include <QAction>
#include <QApplication>
#include <QObject>
#include <QString>
#include <KColorSchemeManager>
......@@ -31,12 +29,9 @@ public:
AppColorSchemeChooser(QObject *parent);
QString currentSchemeName() const;
private Q_SLOTS:
void slotSchemeChanged(QAction *triggeredAction);
private:
QString loadCurrentScheme() const;
void saveCurrentScheme(const QString &name);
};
#endif
......@@ -338,7 +338,7 @@ void MainWindow::setupActions()
_toggleMenuBarAction = KStandardAction::showMenubar(menuBar(), &QMenuBar::setVisible, collection);
collection->setDefaultShortcut(_toggleMenuBarAction, Konsole::ACCEL | Qt::SHIFT | Qt::Key_M);
// Set up themes
actionCollection()->addAction(QStringLiteral("colorscheme-menu"), new AppColorSchemeChooser(actionCollection()));
actionCollection()->addAction(QStringLiteral("window-colorscheme-menu"), new AppColorSchemeChooser(actionCollection()));
// Full Screen
menuAction = KStandardAction::fullScreen(this, &MainWindow::viewFullScreen, this, collection);
......
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