Commit d5e8c5a2 authored by Philip K. Gisslow's avatar Philip K. Gisslow Committed by Christoph Cullmann
Browse files

Mouse forward/backward buttons configurable

Hi guys, love the project. I have been suffering from keyboard RSI for some time now and have been adapting to a more mouse oriented way of working to ease it. I am a big user of the LSP client and by issuing ctrl+click I can easily go to the definition of the symbol of interest but not so easily go back to where I was before. Consequently I added this configurabiliby to help me to go back and forward. This is my first contribution to the project so any feedback would be greatly appreciated.

Rather than being hardcoded to moving backwards and forwards between
open tabs, this commits enables the backward and forward buttons of
the mouse to be configurable to jump back and forwards on the history
stack as well.
parent 785721f3
Pipeline #166508 passed with stage
in 10 minutes and 32 seconds
......@@ -204,6 +204,34 @@ void KateConfigDialog::addBehaviorPage()
layout->addWidget(buttonGroup);
buttonGroup = new QGroupBox(i18n("&Mouse"), generalFrame);
vbox = new QVBoxLayout;
layout->addWidget(buttonGroup);
hlayout = new QHBoxLayout;
label = new QLabel(i18n("&Backward button pressed:"), buttonGroup);
hlayout->addWidget(label);
m_mouseBackActions = new QComboBox(buttonGroup);
hlayout->addWidget(m_mouseBackActions);
label->setBuddy(m_mouseBackActions);
m_mouseBackActions->addItems({i18n("Previous tab"), i18n("History back")});
m_mouseBackActions->setCurrentIndex(cgGeneral.readEntry("Mouse back button action", 0));
connect(m_mouseBackActions, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &KateConfigDialog::slotChanged);
vbox->addLayout(hlayout);
hlayout = new QHBoxLayout;
label = new QLabel(i18n("&Forward button pressed:"), buttonGroup);
hlayout->addWidget(label);
m_mouseForwardActions = new QComboBox(buttonGroup);
hlayout->addWidget(m_mouseForwardActions);
label->setBuddy(m_mouseForwardActions);
m_mouseForwardActions->addItems({i18n("Next tab"), i18n("History forward")});
m_mouseForwardActions->setCurrentIndex(cgGeneral.readEntry("Mouse forward button action", 0));
connect(m_mouseForwardActions, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &KateConfigDialog::slotChanged);
vbox->addLayout(hlayout);
buttonGroup->setLayout(vbox);
layout->addStretch(1); // :-] works correct without autoadd
}
......@@ -403,6 +431,9 @@ void KateConfigDialog::slotApply()
cg.writeEntry("Show output view for message type", m_messageTypes->currentIndex());
}
cg.writeEntry("Mouse back button action", m_mouseBackActions->currentIndex());
cg.writeEntry("Mouse forward button action", m_mouseForwardActions->currentIndex());
cg.writeEntry("Stash unsaved file changes", sessionConfigUi.stashUnsavedFilesChanges->isChecked());
KateApp::self()->stashManager()->setStashUnsavedChanges(sessionConfigUi.stashUnsavedFilesChanges->isChecked());
cg.writeEntry("Stash new unsaved files", sessionConfigUi.stashNewUnsavedFiles->isChecked());
......
......@@ -86,6 +86,8 @@ private:
bool m_dataChanged = false;
QComboBox *m_messageTypes = nullptr;
QComboBox *m_mouseBackActions = nullptr;
QComboBox *m_mouseForwardActions = nullptr;
QCheckBox *m_modNotifications;
QComboBox *m_cmbQuickOpenListMode;
QSpinBox *m_tabLimit;
......
......@@ -143,6 +143,7 @@ KateMainWindow::KateMainWindow(KConfig *sconfig, const QString &sgroup)
}
connect(KateApp::self()->documentManager(), &KateDocManager::documentCreated, this, &KateMainWindow::slotDocumentCreated);
connect(KateApp::self(), &KateApp::configurationChanged, this, &KateMainWindow::readOptions);
readOptions();
......@@ -691,6 +692,9 @@ void KateMainWindow::readOptions()
m_paShowTabBar->setChecked(generalGroup.readEntry("Show Tab Bar", true));
m_paShowUrlNavBar->setChecked(generalGroup.readEntry("Show Url Nav Bar", KateApp::isKate()));
m_mouseButtonBackAction = (MouseBackButtonAction)generalGroup.readEntry("Mouse back button action", 0);
m_mouseButtonForwardAction = (MouseForwardButtonAction)generalGroup.readEntry("Mouse forward button action", 0);
// emit signal to hide/show statusbars
toggleShowStatusBar();
toggleShowTabBar();
......@@ -1308,10 +1312,10 @@ void KateMainWindow::mousePressEvent(QMouseEvent *e)
{
switch (e->button()) {
case Qt::ForwardButton:
slotFocusNextTab();
handleForwardButtonAction();
break;
case Qt::BackButton:
slotFocusPrevTab();
handleBackButtonAction();
break;
default:;
}
......@@ -1331,6 +1335,36 @@ void KateMainWindow::slotFocusNextTab()
}
}
void KateMainWindow::handleBackButtonAction()
{
if (m_viewManager->activeViewSpace()) {
switch (m_mouseButtonBackAction) {
case PreviousTab:
m_viewManager->activeViewSpace()->focusPrevTab();
break;
case HistoryBack:
m_viewManager->activeViewSpace()->goBack();
break;
default:;
}
}
}
void KateMainWindow::handleForwardButtonAction()
{
if (m_viewManager->activeViewSpace()) {
switch (m_mouseButtonForwardAction) {
case NextTab:
m_viewManager->activeViewSpace()->focusNextTab();
break;
case HistoryForward:
m_viewManager->activeViewSpace()->goForward();
break;
default:;
}
}
}
void KateMainWindow::slotQuickOpen()
{
/**
......
......@@ -627,6 +627,25 @@ private:
*/
KateOutputView *m_outputView = nullptr;
public:
/**
* The available actions for the mouse back button, used as indexing
* for the comboboxes of the config window
*/
enum MouseBackButtonAction { PreviousTab = 0, HistoryBack };
/**
* The available actions for the mouse forward button, used as indexing
* for the comboboxes of the config window
*/
enum MouseForwardButtonAction { NextTab = 0, HistoryForward };
private:
MouseBackButtonAction m_mouseButtonBackAction = PreviousTab;
MouseForwardButtonAction m_mouseButtonForwardAction = NextTab;
void handleBackButtonAction();
void handleForwardButtonAction();
public:
/**
* Accessor for unique output view per main window.
......
Supports Markdown
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