mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kdeui: simplify reading and writing of shortcut settings
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
bbf7fddba4
commit
f9fdbc6a7e
6 changed files with 26 additions and 109 deletions
|
@ -61,14 +61,9 @@ public:
|
|||
|
||||
QList<KActionCollection*> m_collections;
|
||||
|
||||
void undoChanges()
|
||||
{
|
||||
m_keyChooser->undoChanges();
|
||||
}
|
||||
|
||||
void save()
|
||||
{
|
||||
m_keyChooser->save();
|
||||
m_keyChooser->exportConfiguration();
|
||||
emit q->saved();
|
||||
}
|
||||
|
||||
|
@ -83,14 +78,14 @@ KShortcutsDialog::KShortcutsDialog(KShortcutsEditor::ActionTypes types,
|
|||
d(new KShortcutsDialogPrivate(this))
|
||||
{
|
||||
setCaption(i18n("Configure Shortcuts"));
|
||||
setButtons(Reset|Ok|Cancel);
|
||||
setButtons(KDialog::Reset | KDialog::Ok| KDialog::Cancel);
|
||||
setModal(true);
|
||||
d->m_keyChooser = new KShortcutsEditor(this, types, allowLetterShortcuts);
|
||||
setMainWidget( d->m_keyChooser );
|
||||
setButtonText(Reset,i18n("Reset to Defaults"));
|
||||
|
||||
connect(this, SIGNAL(resetClicked()), d->m_keyChooser, SLOT(allDefault()));
|
||||
connect(this, SIGNAL(cancelClicked()), SLOT(undoChanges()));
|
||||
connect(this, SIGNAL(okClicked()), this, SLOT(save()));
|
||||
|
||||
KConfigGroup group(KGlobal::config(), "KShortcutsDialog Settings");
|
||||
resize(group.readEntry( "Dialog Size", sizeHint()));
|
||||
|
@ -116,20 +111,14 @@ QList<KActionCollection*> KShortcutsDialog::actionCollections() const
|
|||
return d->m_collections;
|
||||
}
|
||||
|
||||
//FIXME should there be a setSaveSettings method?
|
||||
bool KShortcutsDialog::configure(bool saveSettings)
|
||||
bool KShortcutsDialog::configure()
|
||||
{
|
||||
disconnect(this, SIGNAL(okClicked()), this, SLOT(save()));
|
||||
if (saveSettings) {
|
||||
connect(this, SIGNAL(okClicked()), this, SLOT(save()));
|
||||
}
|
||||
if (isModal()) {
|
||||
int retcode = exec();
|
||||
return retcode;
|
||||
} else {
|
||||
show();
|
||||
return false;
|
||||
}
|
||||
show();
|
||||
return false;
|
||||
}
|
||||
|
||||
QSize KShortcutsDialog::sizeHint() const
|
||||
|
@ -139,12 +128,12 @@ QSize KShortcutsDialog::sizeHint() const
|
|||
|
||||
int KShortcutsDialog::configure(KActionCollection *collection,
|
||||
KShortcutsEditor::LetterShortcuts allowLetterShortcuts,
|
||||
QWidget *parent, bool saveSettings)
|
||||
QWidget *parent)
|
||||
{
|
||||
kDebug(125) << "KShortcutsDialog::configureKeys( KActionCollection*, " << saveSettings << " )";
|
||||
kDebug(125) << "KShortcutsDialog::configure()" << collection;
|
||||
KShortcutsDialog dlg(KShortcutsEditor::AllActions, allowLetterShortcuts, parent);
|
||||
dlg.d->m_keyChooser->addCollection(collection);
|
||||
return dlg.configure(saveSettings);
|
||||
return dlg.configure();
|
||||
}
|
||||
|
||||
#include "moc_kshortcutsdialog.cpp"
|
||||
|
|
|
@ -99,10 +99,9 @@ public:
|
|||
QList<KActionCollection*> actionCollections() const;
|
||||
|
||||
/**
|
||||
* Run the dialog and call writeSettings() on the action collections
|
||||
* that were added if @p bSaveSettings is true.
|
||||
* Run the dialog, changes are saved if the dialog is not canceled.
|
||||
*/
|
||||
bool configure(bool saveSettings = true);
|
||||
bool configure();
|
||||
|
||||
/** @see QWidget::sizeHint() */
|
||||
virtual QSize sizeHint() const;
|
||||
|
@ -115,14 +114,12 @@ public:
|
|||
* @param allowLetterShortcuts set to KShortcutsEditor::LetterShortcutsDisallowed if unmodified alphanumeric
|
||||
* keys ('A', '1', etc.) are not permissible shortcuts.
|
||||
* @param parent the parent widget to attach to
|
||||
* @param bSaveSettings if true, the settings will also be saved back
|
||||
* by calling writeSettings() on the action collections that were added.
|
||||
*
|
||||
* @return Accept if the dialog was closed with OK, Reject otherwise.
|
||||
*/
|
||||
static int configure(KActionCollection *collection,
|
||||
KShortcutsEditor::LetterShortcuts allowLetterShortcuts = KShortcutsEditor::LetterShortcutsAllowed,
|
||||
QWidget *parent = nullptr, bool bSaveSettings = true);
|
||||
QWidget *parent = nullptr);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
|
@ -132,7 +129,6 @@ Q_SIGNALS:
|
|||
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d, void save())
|
||||
Q_PRIVATE_SLOT(d, void undoChanges())
|
||||
|
||||
class KShortcutsDialogPrivate;
|
||||
friend class KShortcutsDialogPrivate;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "kkeysequencewidget.h"
|
||||
#include "kaboutdata.h"
|
||||
#include "kconfiggroup.h"
|
||||
#include "kglobal.h"
|
||||
#include "klocale.h"
|
||||
#include "kdebug.h"
|
||||
|
||||
|
@ -181,9 +182,8 @@ void KShortcutsEditor::addCollection(KActionCollection *collection, const QStrin
|
|||
|
||||
void KShortcutsEditor::importConfiguration(KConfigBase *config)
|
||||
{
|
||||
Q_ASSERT(config);
|
||||
if (!config) {
|
||||
return;
|
||||
config = KGlobal::config().data();
|
||||
}
|
||||
|
||||
if (d->actionTypes & KShortcutsEditor::LocalAction) {
|
||||
|
@ -202,9 +202,8 @@ void KShortcutsEditor::importConfiguration(KConfigBase *config)
|
|||
|
||||
void KShortcutsEditor::exportConfiguration(KConfigBase *config) const
|
||||
{
|
||||
Q_ASSERT(config);
|
||||
if (!config) {
|
||||
return;
|
||||
config = KGlobal::config().data();
|
||||
}
|
||||
|
||||
if (d->actionTypes & KShortcutsEditor::LocalAction) {
|
||||
|
@ -221,30 +220,6 @@ void KShortcutsEditor::exportConfiguration(KConfigBase *config) const
|
|||
}
|
||||
}
|
||||
|
||||
void KShortcutsEditor::writeConfiguration(KConfigGroup *config) const
|
||||
{
|
||||
foreach (KActionCollection* collection, d->actionCollections) {
|
||||
collection->writeSettings(config);
|
||||
}
|
||||
}
|
||||
|
||||
void KShortcutsEditor::commit()
|
||||
{
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
void KShortcutsEditor::save()
|
||||
{
|
||||
writeConfiguration();
|
||||
commit();
|
||||
}
|
||||
|
||||
void KShortcutsEditor::undoChanges()
|
||||
{
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
|
||||
void KShortcutsEditor::allDefault()
|
||||
{
|
||||
// TODO: implement
|
||||
|
|
|
@ -109,46 +109,6 @@ public:
|
|||
*/
|
||||
void addCollection(KActionCollection *, const QString &title = QString());
|
||||
|
||||
/**
|
||||
* Undo all change made since the last commit().
|
||||
*/
|
||||
void undoChanges();
|
||||
|
||||
/**
|
||||
* Save the changes.
|
||||
*
|
||||
* Before saving the changes are committed. This saves the actions to disk.
|
||||
* Any KActionCollection objects with the xmlFile() value set will be
|
||||
* written to an XML file. All other will be written to the application's
|
||||
* rc file.
|
||||
*/
|
||||
void save();
|
||||
|
||||
/**
|
||||
* Commit the changes without saving.
|
||||
*
|
||||
* This commits the changes without saving.
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
void commit();
|
||||
|
||||
/**
|
||||
* Write the current settings to the \p config object.
|
||||
*
|
||||
* This does not initialize the \p config object. It adds the
|
||||
* configuration.
|
||||
*
|
||||
* @note this will not save the global configuration! globalaccel holds
|
||||
* that part of the configuration.
|
||||
* @see writeGlobalConfig()
|
||||
*
|
||||
* @param config Config object to save to or, or null to use the
|
||||
* applications config object
|
||||
*
|
||||
*/
|
||||
void writeConfiguration(KConfigGroup* config = nullptr) const;
|
||||
|
||||
/**
|
||||
* Export the current setting to configuration @p config.
|
||||
*
|
||||
|
@ -157,7 +117,7 @@ public:
|
|||
*
|
||||
* @param config Config object
|
||||
*/
|
||||
void exportConfiguration(KConfigBase *config) const;
|
||||
void exportConfiguration(KConfigBase *config = nullptr) const;
|
||||
|
||||
/**
|
||||
* Import the settings from configuration @p config.
|
||||
|
@ -167,7 +127,7 @@ public:
|
|||
*
|
||||
* @param config Config object
|
||||
*/
|
||||
void importConfiguration(KConfigBase *config);
|
||||
void importConfiguration(KConfigBase *config = nullptr);
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
|
|
|
@ -726,7 +726,7 @@ void KXMLGUIFactoryPrivate::applyShortcutScheme(KXMLGUIClient *client, const QLi
|
|||
}
|
||||
}
|
||||
|
||||
int KXMLGUIFactory::configureShortcuts(bool letterCutsOk , bool bSaveSettings )
|
||||
int KXMLGUIFactory::configureShortcuts(bool letterCutsOk )
|
||||
{
|
||||
KShortcutsDialog dlg(KShortcutsEditor::AllActions,
|
||||
letterCutsOk ? KShortcutsEditor::LetterShortcutsAllowed : KShortcutsEditor::LetterShortcutsDisallowed,
|
||||
|
@ -736,7 +736,7 @@ int KXMLGUIFactory::configureShortcuts(bool letterCutsOk , bool bSaveSettings )
|
|||
dlg.addCollection(client->actionCollection());
|
||||
}
|
||||
}
|
||||
return dlg.configure(bSaveSettings);
|
||||
return dlg.configure();
|
||||
}
|
||||
|
||||
// Find or create
|
||||
|
|
|
@ -23,20 +23,19 @@
|
|||
#include <kdeui_export.h>
|
||||
#include <kcomponentdata.h>
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
#include <QObject>
|
||||
#include <QAction>
|
||||
class KXMLGUIFactoryPrivate;
|
||||
class KXMLGUIClient;
|
||||
class KXMLGUIBuilder;
|
||||
class KComponentData;
|
||||
|
||||
#include <QDomAttr>
|
||||
#include <QDomDocument>
|
||||
#include <QDomElement>
|
||||
#include <QDomNode>
|
||||
#include <QDomNamedNodeMap>
|
||||
|
||||
class KXMLGUIFactoryPrivate;
|
||||
class KXMLGUIClient;
|
||||
class KXMLGUIBuilder;
|
||||
class KComponentData;
|
||||
|
||||
namespace KXMLGUI
|
||||
{
|
||||
struct MergingIndex;
|
||||
|
@ -192,10 +191,8 @@ class KDEUI_EXPORT KXMLGUIFactory : public QObject
|
|||
*
|
||||
* @param bAllowLetterShortcuts Set to false if unmodified alphanumeric
|
||||
* keys ('A', '1', etc.) are not permissible shortcuts.
|
||||
* @param bSaveSettings if true, the settings will also be saved back to
|
||||
* the *uirc file which they were intially read from.
|
||||
*/
|
||||
int configureShortcuts(bool bAllowLetterShortcuts = true, bool bSaveSettings = true);
|
||||
int configureShortcuts(bool bAllowLetterShortcuts = true);
|
||||
|
||||
void changeShortcutScheme(const QString &scheme);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue