Hello,

The following patch uses Qt built-in mechanism for creating window title. This means that changed status is shown using an asterisk (except on Mac OS) and that read-only and version-control and not shown anymore. The patch also adds two widgets to the status bar that provide this information

I let it to people who like programming GUIs to:
 * tell Git/SVN/RCS... instead of VC (trivial)
 * add a tooltip that describes the current revision to the VC label
 * add context menus to both labels.
 * Maybe find a nice icon for the read-only status instead of the text
 status.

The application name which is displayed is currently the name of the
binary. It could be replaced by a plain "LyX", although I wonder whether we want to reflect the version suffix somehow. Suggestions welcome.

JMarc
>From d5a28eefa22e62ec5afead05d34ff07f96085a55 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Tue, 6 Sep 2016 11:17:10 +0200
Subject: [PATCH] Set window title according to platform UI

Let Qt handle the file name, application name and "changed" status of
the document.

Use the status bar to show the "read only" and "version control" status.
---
 src/frontends/qt4/GuiView.cpp     | 30 ++++++++++++++++++++++++++----
 src/frontends/qt4/GuiView.h       | 10 ++++++++--
 src/frontends/qt4/GuiWorkArea.cpp | 29 +----------------------------
 3 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index c74163a..09f22b6 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -577,6 +577,20 @@ GuiView::GuiView(int id)
 	connect(&d.processing_thread_watcher_, SIGNAL(finished()), 
 		busylabel, SLOT(hide()));
 
+	read_only_ = new QLabel(" " + qt_("Read only") + " ", statusBar());
+	read_only_->setMinimumSize(read_only_->sizeHint());
+	read_only_->setText(QString());
+	read_only_->setAlignment(Qt::AlignHCenter);
+	read_only_->setFrameStyle(QFrame::Panel | QFrame::Sunken);
+	statusBar()->addPermanentWidget(read_only_);
+
+	version_control_ = new QLabel(" " + qt_("VC Lock") + " ", statusBar());
+	version_control_->setMinimumSize(read_only_->sizeHint());
+	version_control_->setText(QString());
+	version_control_->setAlignment(Qt::AlignHCenter);
+	version_control_->setFrameStyle(QFrame::Panel | QFrame::Sunken);
+	statusBar()->addPermanentWidget(version_control_);
+
 	statusBar()->setSizeGripEnabled(true);
 	updateStatusBar();
 
@@ -1144,14 +1158,22 @@ void GuiView::updateWindowTitle(GuiWorkArea * wa)
 	if (wa != d.current_work_area_
 		|| wa->bufferView().buffer().isInternal())
 		return;
-	setWindowTitle(qt_("LyX: ") + wa->windowTitle());
+	Buffer const & buf = wa->bufferView().buffer();
+	setWindowTitle(QString());
 	setWindowIconText(wa->windowIconText());
-#if (QT_VERSION >= 0x040400)
 	// Sets the path for the window: this is used by OSX to 
 	// allow a context click on the title bar showing a menu
 	// with the path up to the file
-	setWindowFilePath(toqstr(wa->bufferView().buffer().absFileName()));
-#endif
+	setWindowFilePath(toqstr(buf.absFileName()));
+	setWindowModified(!buf.isClean());
+	read_only_->setText(buf.isReadonly() ? qt_("Read only") : QString());
+	if (buf.lyxvc().inUse()) {
+		if (buf.lyxvc().locking())
+			version_control_->setText(qt_("VC lock"));
+		else
+			version_control_->setText(qt_("VC"));
+	} else
+		version_control_->setText(QString());
 }
 
 
diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h
index 0d8cf8d..e5fb5d9 100644
--- a/src/frontends/qt4/GuiView.h
+++ b/src/frontends/qt4/GuiView.h
@@ -24,6 +24,7 @@
 class QCloseEvent;
 class QDragEnterEvent;
 class QDropEvent;
+class QLabel;
 class QMenu;
 class QShowEvent;
 
@@ -220,10 +221,10 @@ public Q_SLOTS:
 	/// idle timeout.
 	/// clear any temporary message and replace with current status.
 	void clearMessage();
-
-private Q_SLOTS:
 	///
 	void updateWindowTitle(GuiWorkArea * wa);
+
+private Q_SLOTS:
 	///
 	void resetWindowTitleAndIconText();
 
@@ -455,6 +456,11 @@ private:
 	/// Request to give focus to minibuffer
 	bool minibuffer_focus_;
 
+	/// Statusbar widget that shows read-only status
+	QLabel * read_only_;
+	/// Statusbar widget that shows version control status
+	QLabel * version_control_;
+
 };
 
 } // namespace frontend
diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp
index 69090b3..2cb5a7b 100644
--- a/src/frontends/qt4/GuiWorkArea.cpp
+++ b/src/frontends/qt4/GuiWorkArea.cpp
@@ -1387,34 +1387,7 @@ QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
 
 void GuiWorkArea::updateWindowTitle()
 {
-	docstring maximize_title;
-	docstring minimize_title;
-
-	Buffer const & buf = d->buffer_view_->buffer();
-	FileName const file_name = buf.fileName();
-	if (!file_name.empty()) {
-		maximize_title = file_name.displayName(130);
-		minimize_title = from_utf8(file_name.onlyFileName());
-		if (buf.lyxvc().inUse()) {
-			if (buf.lyxvc().locking())
-				maximize_title +=  _(" (version control, locking)");
-			else
-				maximize_title +=  _(" (version control)");
-		}
-		if (!buf.isClean()) {
-			maximize_title += _(" (changed)");
-			minimize_title += char_type('*');
-		}
-		if (buf.isReadonly())
-			maximize_title += _(" (read only)");
-	}
-
-	QString const new_title = toqstr(maximize_title);
-	if (new_title != windowTitle()) {
-		QWidget::setWindowTitle(new_title);
-		QWidget::setWindowIconText(toqstr(minimize_title));
-		titleChanged(this);
-	}
+	d->lyx_view_->updateWindowTitle(this);
 }
 
 
-- 
2.7.4

Reply via email to