Commit b3fb485b authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Enable/Disable forward/back buttons as necessary


Signed-off-by: Waqar Ahmed's avatarWaqar Ahmed <waqar.17a@gmail.com>
parent a722a83a
......@@ -689,6 +689,24 @@ void KateMainWindow::removeMenuBarActionFromContextMenu()
}
}
void KateMainWindow::setForwardButtonEnabled(bool val)
{
if (auto v = activeView()) {
if (auto kvs = qobject_cast<KateViewSpace *>(v->parentWidget()->parentWidget())) {
kvs->setForwardButtonEnabled(val);
}
}
}
void KateMainWindow::setBackButtonEnabled(bool val)
{
if (auto v = activeView()) {
if (auto kvs = qobject_cast<KateViewSpace *>(v->parentWidget()->parentWidget())) {
kvs->setBackButtonEnabled(val);
}
}
}
void KateMainWindow::toggleShowStatusBar()
{
Q_EMIT statusBarToggled();
......@@ -1192,6 +1210,11 @@ void KateMainWindow::addJump(QUrl url, KTextEditor::Cursor c)
m_locations.push_back({url, c});
// set to last
currentLocation = m_locations.size() - 1;
// renable back
if (currentLocation > 0) {
setBackButtonEnabled(true);
}
}
void KateMainWindow::mousePressEvent(QMouseEvent *e)
......@@ -1263,6 +1286,10 @@ void KateMainWindow::goBack()
const auto &location = m_locations.at(currentLocation - 1);
currentLocation--;
if (currentLocation <= 0) {
setBackButtonEnabled(false);
}
if (!location.url.isValid() || !location.cursor.isValid()) {
QVariantMap genericMessage;
genericMessage.insert(QStringLiteral("type"), QStringLiteral("Error"));
......@@ -1278,12 +1305,16 @@ void KateMainWindow::goBack()
if (activeView() && activeView()->document() && activeView()->document()->url() == location.url) {
const QSignalBlocker blocker(activeView());
activeView()->setCursorPosition(location.cursor);
// enable forward
setForwardButtonEnabled(true);
return;
}
auto v = openUrl(location.url);
const QSignalBlocker blocker(v);
v->setCursorPosition(location.cursor);
// enable forward
setForwardButtonEnabled(true);
}
void KateMainWindow::goForward()
......@@ -1298,6 +1329,10 @@ void KateMainWindow::goForward()
const auto &location = m_locations.at(currentLocation + 1);
currentLocation++;
if (currentLocation + 1 >= m_locations.size()) {
setForwardButtonEnabled(false);
}
if (!location.url.isValid() || !location.cursor.isValid()) {
QVariantMap genericMessage;
genericMessage.insert(QStringLiteral("type"), QStringLiteral("Error"));
......
......@@ -149,6 +149,9 @@ private:
void addMenuBarActionToContextMenu();
void removeMenuBarActionFromContextMenu();
void setForwardButtonEnabled(bool v);
void setBackButtonEnabled(bool v);
/**
* read some global options from katerc
*/
......@@ -172,10 +175,6 @@ public Q_SLOTS:
void slotCommandBarOpen();
void goBack();
void goForward();
/**
* Overwrite size hint for better default window sizes
* @return size hint
......@@ -215,6 +214,10 @@ private Q_SLOTS:
void slotListRecursiveEntries(KIO::Job *job, const KIO::UDSEntryList &list);
// jump in location history
void goBack();
void goForward();
private Q_SLOTS:
void toggleShowMenuBar(bool showMessage = true);
void toggleShowStatusBar();
......
......@@ -68,6 +68,10 @@ KateViewSpace::KateViewSpace(KateViewManager *viewManager, QWidget *parent, cons
m_historyRight->installEventFilter(this); // on click, active this view space
hLayout->addWidget(m_historyRight);
// deactive in the beginning for now
setBackButtonEnabled(false);
setForwardButtonEnabled(false);
// add tab bar
m_tabBar = new KateTabBar(this);
connect(m_tabBar, &KateTabBar::currentChanged, this, &KateViewSpace::changeView);
......@@ -463,6 +467,16 @@ void KateViewSpace::focusNextTab()
}
}
void KateViewSpace::setForwardButtonEnabled(bool active)
{
m_historyRight->setEnabled(active);
}
void KateViewSpace::setBackButtonEnabled(bool active)
{
m_historyLeft->setEnabled(active);
}
int KateViewSpace::hiddenDocuments() const
{
const int hiddenDocs = KateApp::self()->documents().count() - m_tabBar->count();
......
......@@ -91,6 +91,16 @@ public:
*/
void focusNextTab();
/**
* set Forward Button Active
*/
void setForwardButtonEnabled(bool active);
/**
* set Back Button Active
*/
void setBackButtonEnabled(bool active);
public Q_SLOTS:
void documentDestroyed(QObject *doc);
void updateDocumentName(KTextEditor::Document *doc);
......
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