File indexing completed on 2024-12-22 04:14:05
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Michael Abrahams <miabraha@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 0008 #include "KisShortcutsDialog_p.h" 0009 #include "kshortcutschemeshelper_p.h" 0010 #include "kxmlguiclient.h" 0011 #include <QDomDocument> 0012 #include "kactioncollection.h" 0013 #include "kxmlguifactory.h" 0014 #include <QAction> 0015 #include <QApplication> 0016 #include <QDebug> 0017 #include "kis_action_registry.h" 0018 #include <KSharedConfig> 0019 #include <KConfigGroup> 0020 #include <KisCursorOverrideLock.h> 0021 0022 0023 QKeySequence primarySequence(const QList<QKeySequence> &sequences) 0024 { 0025 return sequences.isEmpty() ? QKeySequence() : sequences.at(0); 0026 } 0027 0028 QKeySequence alternateSequence(const QList<QKeySequence> &sequences) 0029 { 0030 return sequences.size() <= 1 ? QKeySequence() : sequences.at(1); 0031 } 0032 0033 0034 KisShortcutsDialog::KisShortcutsDialogPrivate::KisShortcutsDialogPrivate(KisShortcutsDialog *q) 0035 : q(q) 0036 { } 0037 0038 void KisShortcutsDialog::KisShortcutsDialogPrivate::changeShortcutScheme(const QString &schemeName) 0039 { 0040 // KTreeWidgetSearchLine is unhappy if the contents of the tree change 0041 m_shortcutsEditor->clearSearch(); 0042 0043 QString dialogText = i18n("The current shortcut scheme is modified. Save before switching to the new one?"); 0044 if (m_shortcutsEditor->isModified() && 0045 KMessageBox::questionYesNo( q,dialogText ) == KMessageBox::Yes) { 0046 m_shortcutsEditor->save(); 0047 } else { 0048 m_shortcutsEditor->undo(); 0049 } 0050 0051 KisCursorOverrideLock cursorLock(Qt::WaitCursor); 0052 m_shortcutsEditor->clearCollections(); 0053 0054 KConfigGroup cg = KSharedConfig::openConfig()->group("Shortcut Schemes"); 0055 cg.writeEntry("Current Scheme", schemeName); 0056 KisActionRegistry::instance()->loadShortcutScheme(schemeName); 0057 0058 0059 // Update actions themselves, and re-add to dialog box to refresh 0060 auto it = m_collections.constBegin(); 0061 while (it != m_collections.constEnd()) { 0062 it.value()->updateShortcuts(); 0063 // TODO: BAD 0064 m_shortcutsEditor->addCollection(it.value(), it.key()); 0065 it++; 0066 } 0067 } 0068 0069 void KisShortcutsDialog::KisShortcutsDialogPrivate::undo() 0070 { 0071 m_shortcutsEditor->undo(); 0072 } 0073 0074 void KisShortcutsDialog::KisShortcutsDialogPrivate::save() 0075 { 0076 m_shortcutsEditor->save(); 0077 } 0078 0079 #include "moc_KisShortcutsDialog_p.cpp"