Commit a0b08cb1 authored by Maximilian Schiller's avatar Maximilian Schiller
Browse files

Make it possible to configure the konsolepart shortcuts

This patch allows the user to configure the by konsolepart provided actions. For example it wasn't possible to configure the copy/paste shortcuts. Also many the "X is an ambiguous shortcut" can now be fixed and remapped if the user so desires.

Internally this is done by collecting the actioncollections from the kparts and then providing the first one to the shortcutconfigure dialog. After the shortcuts have been configured the actioncollections from all the other terminals get synchronized.

BUG: 412496
parent 59227025
......@@ -761,7 +761,38 @@ void MainWindow::updateWindowHeightMenu()
void MainWindow::configureKeys()
{
KShortcutsDialog::configure(actionCollection());
KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
dialog.addCollection(actionCollection());
const auto collections = m_sessionStack->getPartActionCollections();
if (collections.size() >= 1) {
dialog.addCollection(collections.at(0), QStringLiteral("Konsolepart"));
}
if (!dialog.configure()) {
return;
}
if (collections.size() >= 1) {
// We need to update all the other collections
// rootCollection is the collection which got updatet by the dialog
const auto rootCollection = collections.at(0);
// For all the other collections
for (auto i = 1; i < collections.size(); ++i) {
// Update all the action they share with rootCollection
const auto rootActions = rootCollection->actions();
for (const auto* action : rootActions) {
if (auto* destaction = collections.at(i)->action(action->objectName())) {
destaction->setShortcuts(action->shortcuts());
}
}
}
}
}
void MainWindow::configureNotifications()
......
......@@ -673,3 +673,30 @@ bool SessionStack::queryClose(int sessionId, QueryCloseType type)
return true;
}
QList<KActionCollection*> SessionStack::getPartActionCollections()
{
QList<KActionCollection*> actionCollections;
const auto sessions = m_sessions.values();
for (auto* session : sessions) {
const auto terminalIds = session->terminalIdList().split(QStringLiteral(","));
for (const auto& terminalID : terminalIds) {
auto *terminal = session->getTerminal(terminalID.toInt());
if (terminal) {
auto* collection = terminal->actionCollection();
if (collection) {
actionCollections.append(collection);
}
}
}
}
return actionCollections;
}
......@@ -34,6 +34,7 @@
class Session;
class VisualEventOverlay;
class KActionCollection;
class SessionStack : public QStackedWidget
{
......@@ -52,6 +53,7 @@ class SessionStack : public QStackedWidget
bool requiresVisualEventOverlay();
QList<KActionCollection*> getPartActionCollections();
public Q_SLOTS:
int addSessionImpl(Session::SessionType type = Session::Single);
......
......@@ -30,6 +30,7 @@
#include <KPluginLoader>
#include <KService>
#include <KXMLGUIFactory>
#include <KXMLGUIBuilder>
#include <QAction>
#include <QApplication>
......@@ -81,6 +82,20 @@ Terminal::Terminal(const QString& workingDir, QWidget* parent) : QObject(parent)
{
m_terminalWidget->setFocusPolicy(Qt::WheelFocus);
m_terminalWidget->installEventFilter(this);
if (!m_part->factory() && m_partWidget) {
if (!m_part->clientBuilder()) {
m_part->setClientBuilder(new KXMLGUIBuilder(m_partWidget));
}
auto factory = new KXMLGUIFactory(m_part->clientBuilder(), this);
factory->addClient(m_part);
// Prevents the KXMLGui warning about removing the client
connect(m_partWidget, &QObject::destroyed, this, [factory, this] {
factory->removeClient(m_part);
});
}
}
disableOffendingPartActions();
......@@ -320,3 +335,17 @@ QString Terminal::currentWorkingDirectory() const
{
return m_terminalInterface->currentWorkingDirectory();
}
KActionCollection* Terminal::actionCollection()
{
if (m_part->factory()) {
const auto guiClients = m_part->childClients();
for (auto* client : guiClients) {
if (client->actionCollection()->associatedWidgets().contains(m_terminalWidget)) {
return client->actionCollection();
}
}
}
return nullptr;
}
......@@ -70,6 +70,7 @@ class Terminal : public QObject
void deletePart();
KActionCollection* actionCollection();
Q_SIGNALS:
void titleChanged(int terminalId, const QString& title);
......@@ -80,7 +81,6 @@ class Terminal : public QObject
void silenceDetected(Terminal* terminal);
void destroyed(int terminalId);
private Q_SLOTS:
void setTitle(const QString& title);
void overrideShortcut(QKeyEvent* event, bool& override);
......
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