Commit 2c78f70a authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

urlbar: handle untitled docs

For now, untitled docs will just show a "Untitled.." instead of the
urlbar getting hidden.
parent ad827f3a
Pipeline #139427 passed with stage
in 2 minutes and 31 seconds
......@@ -9,6 +9,7 @@
#include <KTextEditor/Document>
#include <KTextEditor/View>
#include <KLocalizedString>
#include <QAbstractListModel>
#include <QAction>
#include <QApplication>
......@@ -22,6 +23,7 @@
#include <QMimeDatabase>
#include <QPainter>
#include <QScrollBar>
#include <QStackedWidget>
#include <QStandardItemModel>
#include <QStyledItemDelegate>
#include <QToolButton>
......@@ -429,16 +431,20 @@ Q_SIGNALS:
KateUrlBar::KateUrlBar(KateViewSpace *parent)
: QWidget(parent)
, m_stack(new QStackedWidget(this))
, m_breadCrumbView(new BreadCrumbView(this))
, m_untitledDocLabel(new QLabel(this))
{
setFixedHeight(24);
setContentsMargins({});
m_stack->addWidget(m_untitledDocLabel);
m_stack->addWidget(m_breadCrumbView);
auto *layout = new QHBoxLayout(this);
layout->setContentsMargins({});
layout->setSpacing(0);
m_breadCrumbView = new BreadCrumbView(this);
layout->addWidget(m_breadCrumbView);
layout->addWidget(m_stack);
auto *vm = parent->viewManger();
connect(vm, &KateViewManager::viewChanged, this, &KateUrlBar::onViewChanged);
......@@ -463,7 +469,8 @@ void KateUrlBar::onViewChanged(KTextEditor::View *v)
{
if (!v) {
updateForDocument(nullptr);
hide();
m_untitledDocLabel->setText(i18n("Untitled"));
m_stack->setCurrentWidget(m_untitledDocLabel);
return;
}
......@@ -484,21 +491,23 @@ void KateUrlBar::updateForDocument(KTextEditor::Document *doc)
// we want to watch for url changed
connect(m_currentDoc, &KTextEditor::Document::documentUrlChanged, this, &KateUrlBar::updateForDocument);
auto *vm = static_cast<KateViewSpace *>(parentWidget())->viewManger();
if (vm && !vm->showUrlNavBar()) {
if (m_currentDoc->url().isEmpty() || !m_currentDoc->url().isLocalFile()) {
m_untitledDocLabel->setText(m_currentDoc->documentName());
m_stack->setCurrentWidget(m_untitledDocLabel);
return;
}
const auto url = doc->url();
if (url.isEmpty() || !url.isLocalFile()) {
hide();
if (m_stack->currentWidget() != m_breadCrumbView) {
m_stack->setCurrentWidget(m_breadCrumbView);
}
auto *vm = static_cast<KateViewSpace *>(parentWidget())->viewManger();
if (vm && !vm->showUrlNavBar()) {
return;
}
const auto url = doc->url();
m_breadCrumbView->setUrl(url);
if (isHidden())
show();
}
#include "kateurlbar.moc"
......@@ -22,7 +22,9 @@ Q_SIGNALS:
private:
void onViewChanged(KTextEditor::View *v);
void updateForDocument(KTextEditor::Document *doc);
class BreadCrumbView *m_breadCrumbView;
class QStackedWidget *const m_stack;
class BreadCrumbView *const m_breadCrumbView;
class QLabel *const m_untitledDocLabel;
// document for which the url bar is currently active
// might be nullptr
......
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