Commit 53026e71 authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Re-add history actions to mainwindow



History actions are back in main-window to allow shortcut usage and make
the navigation toolbar work again. Clicking the action will move you back
or forward in history in the current active viewspace. Similarly, the actions
will be auto enabled / disabled when switching view-spaces according to the
available history for that view-space
Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent d513a291
......@@ -459,6 +459,23 @@ void KateMainWindow::setupActions()
// quick open menu ;)
a = new KateSessionsAction(i18n("&Quick Open Session"), this);
actionCollection()->addAction(QStringLiteral("sessions_list"), a);
// location history actions
a = actionCollection()->addAction(QStringLiteral("view_history_back"));
a->setIcon(QIcon::fromTheme(QStringLiteral("arrow-left")));
a->setText(i18n("Go back"));
connect(a, &QAction::triggered, this, [this] {
m_viewManager->activeViewSpace()->goBack();
});
connect(this->m_viewManager, &KateViewManager::historyBackEnabled, a, &QAction::setEnabled);
a = actionCollection()->addAction(QStringLiteral("view_history_forward"));
a->setIcon(QIcon::fromTheme(QStringLiteral("arrow-right")));
a->setText(i18n("Go forward"));
connect(a, &QAction::triggered, this, [this] {
m_viewManager->activeViewSpace()->goForward();
});
connect(this->m_viewManager, &KateViewManager::historyForwardEnabled, a, &QAction::setEnabled);
}
void KateMainWindow::slotDocumentCloseAll()
......
......@@ -552,6 +552,10 @@ void KateViewManager::setActiveSpace(KateViewSpace *vs)
}
vs->setActive(true);
// signal update history buttons in mainWindow
Q_EMIT historyBackEnabled(vs->isHistoryBackEnabled());
Q_EMIT historyForwardEnabled(vs->isHistoryForwardEnabled());
}
void KateViewManager::setActiveView(KTextEditor::View *view)
......
......@@ -92,6 +92,9 @@ Q_SIGNALS:
void viewChanged(KTextEditor::View *);
void viewCreated(KTextEditor::View *);
void historyBackEnabled(bool e);
void historyForwardEnabled(bool e);
public:
/**
* create and activate a new view for doc, if doc == 0, then
......
......@@ -499,10 +499,12 @@ void KateViewSpace::addJump(const QUrl &url, KTextEditor::Cursor c)
currentLocation = m_locations.size() - 1;
// disable forward button as we are at the end now
m_historyForward->setEnabled(false);
Q_EMIT m_viewManager->historyForwardEnabled(false);
// renable back
if (currentLocation > 0) {
m_historyBack->setEnabled(true);
Q_EMIT m_viewManager->historyBackEnabled(true);
}
}
int KateViewSpace::hiddenDocuments() const
......@@ -699,6 +701,7 @@ void KateViewSpace::goBack()
if (currentLocation <= 0) {
m_historyBack->setEnabled(false);
Q_EMIT m_viewManager->historyBackEnabled(false);
}
if (auto v = m_viewManager->activeView()) {
......@@ -707,6 +710,7 @@ void KateViewSpace::goBack()
m_viewManager->activeView()->setCursorPosition(location.cursor);
// enable forward
m_historyForward->setEnabled(true);
Q_EMIT m_viewManager->historyForwardEnabled(false);
return;
}
}
......@@ -714,8 +718,19 @@ void KateViewSpace::goBack()
auto v = m_viewManager->openUrlWithView(location.url, QString());
const QSignalBlocker blocker(v);
v->setCursorPosition(location.cursor);
// enable forward
// enable forward in viewspace + mainwindow
m_historyForward->setEnabled(true);
Q_EMIT m_viewManager->historyForwardEnabled(false);
}
bool KateViewSpace::isHistoryBackEnabled() const
{
return m_historyBack->isEnabled();
}
bool KateViewSpace::isHistoryForwardEnabled() const
{
return m_historyForward->isEnabled();
}
void KateViewSpace::goForward()
......@@ -731,6 +746,7 @@ void KateViewSpace::goForward()
currentLocation++;
if (currentLocation + 1 >= m_locations.size()) {
Q_EMIT m_viewManager->historyForwardEnabled(false);
m_historyForward->setEnabled(false);
}
......@@ -740,6 +756,7 @@ void KateViewSpace::goForward()
}
m_historyBack->setEnabled(true);
Q_EMIT m_viewManager->historyBackEnabled(true);
if (auto v = m_viewManager->activeView()) {
if (v->document() && v->document()->url() == location.url) {
......
......@@ -91,6 +91,26 @@ public:
*/
void focusNextTab();
/**
* go forward in location history
*/
void goForward();
/**
* go back in location history
*/
void goBack();
/**
* Is back history avail?
*/
bool isHistoryBackEnabled() const;
/**
* Is forward history avail?
*/
bool isHistoryForwardEnabled() const;
public Q_SLOTS:
void documentDestroyed(QObject *doc);
void updateDocumentName(KTextEditor::Document *doc);
......@@ -141,9 +161,6 @@ private:
*/
void addJump(const QUrl &url, KTextEditor::Cursor);
void goForward();
void goBack();
private:
// Kate's view manager
KateViewManager *m_viewManager;
......
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