[rkward] /: Remove conflicing kate shortcuts, automatically.

Thomas Friedrichsmeier null at kde.org
Sat May 2 21:11:55 BST 2020


Git commit 983db76abfbf465e885d5a29fa16365b8f6367bf by Thomas Friedrichsmeier.
Committed on 02/05/2020 at 20:10.
Pushed by tfry into branch 'master'.

Remove conflicing kate shortcuts, automatically.

This is a bit lame, but I think it's the only future-proof way to deal with all new shortcut additions.
In the context of RKWard, our own actions are really more worthy of a memorizable shortcut than some rarely used generic kate action.

M  +1    -2    ChangeLog
M  +29   -0    rkward/windows/rkcommandeditorwindow.cpp

https://commits.kde.org/rkward/983db76abfbf465e885d5a29fa16365b8f6367bf

diff --git a/ChangeLog b/ChangeLog
index 3e6e8773..781181af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,8 +13,7 @@
   * TODO: Some plugins still have UI issues. E.g.:
     - SQL plugin fails to add toplevel menu
     - Text filter plugin always shows menu entry, but should be limited to script windows
-- TODO:
-  - Ctrl+Enter action now clashes with kate part...
+- Fixed: Avoid shorcut clash with kate part by removing conflicting (default) shortcuts, automatically
 
 --- Version 0.7.1 - Jan-23-2020
 - Code hinting in script editor windows has been reworked, and now also completes argument names
diff --git a/rkward/windows/rkcommandeditorwindow.cpp b/rkward/windows/rkcommandeditorwindow.cpp
index 73337bfd..a682fba5 100644
--- a/rkward/windows/rkcommandeditorwindow.cpp
+++ b/rkward/windows/rkcommandeditorwindow.cpp
@@ -217,6 +217,35 @@ RKCommandEditorWindow::RKCommandEditorWindow (QWidget *parent, const QUrl _url,
 	fixupPartGUI ();
 	setMetaInfo (i18n ("Script Editor"), QUrl (), RKSettings::PageCommandEditor);
 	initializeActions (part->actionCollection ());
+	// The kate part is quite a beast to embed, when it comes to shortcuts. New ones get added, conflicting with ours.
+	// In this context we show no mercy, and rip out any conflicting shortcuts.
+	auto kate_acs = m_view->findChildren<KActionCollection*>();
+	kate_acs.append(m_view->actionCollection());
+	QList<KActionCollection*> own_acs;
+	own_acs.append(part->actionCollection());
+	own_acs.append(standardActionCollection());
+	auto own_actions = part->actionCollection()->actions();
+	// How's this for a nested for loop...
+	for (const auto ac : own_acs) {
+		auto own_actions = ac->actions();
+		for (const auto a : own_actions) {
+			for (const auto k : ac->defaultShortcuts(a)) {
+				for (const auto kac : kate_acs) {
+					for (auto ka : kac->actions()) {
+						auto action_shortcuts = kac->defaultShortcuts(ka);
+						for (const auto kk : action_shortcuts) {
+							if (k.matches(kk) != QKeySequence::NoMatch || kk.matches(k) != QKeySequence::NoMatch) {
+								RK_DEBUG(EDITOR, DL_WARNING, "Removing conflicting shortcut %s in kate part (%s, conflicting with %s)", qPrintable(kk.toString()), qPrintable(ka->objectName()), qPrintable(a->objectName()));
+								action_shortcuts.removeAll(k);
+								kac->setDefaultShortcuts(ka, action_shortcuts);
+								break;
+							}
+						}
+					}
+				}
+			}
+		}
+	}
 	initializeActivationSignals ();
 	RKXMLGUISyncer::self()->registerChangeListener (m_view, this, SLOT (fixupPartGUI()));
 



More information about the rkward-tracker mailing list