Hi,

Anyone against putting this in master?

JMarc

>From 5488f8f06eae75bf2265e88a344be246130b9ada Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <[email protected]>
Date: Mon, 24 Jul 2017 00:21:43 +0200
Subject: [PATCH] Make "devel mode" configurable at run time

Traditionally LyX behaves differently when the directive DEVEL_VERSION
is defined at compile time. This covers
* more detailed description of current position in status bar
* the help files are open in read/write mode
* more detailed debug output in the View Source panel

This patch introduces the new function devel-mode-toggle that allows
to use devel mode in stable releases, and vice versa.

The information is saved in the session file. Only the default value
depends on the compile-time #define.
---
 src/BufferView.cpp                     |  2 +-
 src/Cursor.cpp                         | 23 ++++++++++++-----------
 src/Cursor.h                           |  4 ++--
 src/FuncCode.h                         |  1 +
 src/LyXAction.cpp                      | 13 +++++++++++++
 src/Text.cpp                           | 34 +++++++++++++++++-----------------
 src/Text.h                             |  4 ++--
 src/frontends/qt4/GuiApplication.cpp   |  7 +------
 src/frontends/qt4/GuiCommandBuffer.cpp |  6 ------
 src/frontends/qt4/GuiCommandBuffer.h   |  3 ---
 src/frontends/qt4/GuiView.cpp          | 28 +++++++++++++++++++++++++---
 src/frontends/qt4/GuiView.h            |  5 +++++
 src/frontends/qt4/GuiViewSource.cpp    | 27 ++++++++++++++-------------
 src/mathed/InsetMathHull.cpp           |  2 +-
 14 files changed, 94 insertions(+), 65 deletions(-)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 2f256369f6..03e7723fd1 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -1391,7 +1391,7 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 		break;
 
 	case LFUN_FONT_STATE:
-		dr.setMessage(cur.currentState());
+		dr.setMessage(cur.currentState(false));
 		break;
 
 	case LFUN_BOOKMARK_SAVE:
diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index 1223782c35..b99ab6cb53 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -1057,7 +1057,7 @@ void Cursor::updateTextTargetOffset()
 }
 
 
-void Cursor::info(odocstream & os) const
+void Cursor::info(odocstream & os, bool devel_mode) const
 {
 	for (int i = 1, n = depth(); i < n; ++i) {
 		operator[](i).inset().infoize(os);
@@ -1069,6 +1069,14 @@ void Cursor::info(odocstream & os) const
 		if (inset)
 			prevInset()->infoize2(os);
 	}
+	if (devel_mode) {
+		InsetMath * math = inset().asInsetMath();
+		if (math)
+			os << _(", Inset: ") << math->id();
+		os << _(", Cell: ") << idx();
+		os << _(", Position: ") << pos();
+	}
+
 }
 
 
@@ -2106,23 +2114,16 @@ docstring Cursor::selectionAsString(bool with_label) const
 }
 
 
-docstring Cursor::currentState() const
+docstring Cursor::currentState(bool devel_mode) const
 {
 	if (inMathed()) {
 		odocstringstream os;
-		info(os);
-#ifdef DEVEL_VERSION
-		InsetMath * math = inset().asInsetMath();
-		if (math)
-			os << _(", Inset: ") << math->id();
-		os << _(", Cell: ") << idx();
-		os << _(", Position: ") << pos();
-#endif
+		info(os, devel_mode);
 		return os.str();
 	}
 
 	if (inTexted())
-		return text()->currentState(*this);
+		return text()->currentState(*this, devel_mode);
 
 	return docstring();
 }
diff --git a/src/Cursor.h b/src/Cursor.h
index d1e13f684e..5c675c493a 100644
--- a/src/Cursor.h
+++ b/src/Cursor.h
@@ -205,7 +205,7 @@ public:
 	///
 	docstring selectionAsString(bool with_label) const;
 	///
-	docstring currentState() const;
+	docstring currentState(bool devel_mode) const;
 
 	/// auto-correct mode
 	bool autocorrect() const { return autocorrect_; }
@@ -300,7 +300,7 @@ public:
 	/// access to owning BufferView
 	BufferView & bv() const;
 	/// get some interesting description of top position
-	void info(odocstream & os) const;
+	void info(odocstream & os, bool devel_mode) const;
 	/// are we in math mode (2), text mode (1) or unsure (0)?
 	int currentMode();
 	/// reset cursor bottom to the beginning of the top inset
diff --git a/src/FuncCode.h b/src/FuncCode.h
index 7949bce41a..92d5e35268 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -473,6 +473,7 @@ enum FuncCode
 	LFUN_BUFFER_ZOOM,               // daniel, 20161028
 	LFUN_TOOLBAR_MOVABLE,           // daniel, 20160712
 	LFUN_FONT_CROSSOUT,             // uwestoehr 20170404
+	LFUN_DEVEL_MODE_TOGGLE,         // lasgouttes 20170723
 	LFUN_LASTACTION                 // end of the table
 };
 
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 56b810306e..6aaec92428 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -1396,6 +1396,19 @@ void LyXAction::init()
 
 
 /*!
+ * \var lyx::FuncCode lyx::LFUN_DEVEL_MODE_TOGGLE
+ * \li Action: toggle a mode where more information is given in UI
+ * \li Syntax: devel-mode-toggle
+ * \li Notion: in so called "devel" mode, the information given in the
+ *             status bar is more precise, and the help documents are
+ *             open in editing mode.
+ * \li Origin: lasgouttes, 23 Jul 2017
+ * \endvar
+ */
+		{ LFUN_DEVEL_MODE_TOGGLE, "devel-mode-toggle", NoBuffer, System },
+
+
+/*!
  * \var lyx::FuncCode lyx::LFUN_DIALOG_DISCONNECT_INSET
  * \li Action: Closes opened connection to opened inset.
  * \li Notion: Connection is used for apply functions.
diff --git a/src/Text.cpp b/src/Text.cpp
index 1224406682..6b944fadbf 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -1896,7 +1896,7 @@ bool Text::read(Lexer & lex,
 
 
 // Returns the current font and depth as a message.
-docstring Text::currentState(Cursor const & cur) const
+docstring Text::currentState(Cursor const & cur, bool devel_mode) const
 {
 	LBUFERR(this == cur.text());
 	Buffer & buf = *cur.buffer();
@@ -1953,22 +1953,22 @@ docstring Text::currentState(Cursor const & cur) const
 		}
 	}
 
-#ifdef DEVEL_VERSION
-	os << _(", Inset: ") << &cur.inset();
-	os << _(", Paragraph: ") << cur.pit();
-	os << _(", Id: ") << par.id();
-	os << _(", Position: ") << cur.pos();
-	// FIXME: Why is the check for par.size() needed?
-	// We are called with cur.pos() == par.size() quite often.
-	if (!par.empty() && cur.pos() < par.size()) {
-		// Force output of code point, not character
-		size_t const c = par.getChar(cur.pos());
-		os << _(", Char: 0x") << hex << c;
-	}
-	os << _(", Boundary: ") << cur.boundary();
-//	Row & row = cur.textRow();
-//	os << bformat(_(", Row b:%1$d e:%2$d"), row.pos(), row.endpos());
-#endif
+	if (devel_mode) {
+		os << _(", Inset: ") << &cur.inset();
+		os << _(", Paragraph: ") << cur.pit();
+		os << _(", Id: ") << par.id();
+		os << _(", Position: ") << cur.pos();
+		// FIXME: Why is the check for par.size() needed?
+		// We are called with cur.pos() == par.size() quite often.
+		if (!par.empty() && cur.pos() < par.size()) {
+			// Force output of code point, not character
+			size_t const c = par.getChar(cur.pos());
+			os << _(", Char: 0x") << hex << c;
+		}
+		os << _(", Boundary: ") << cur.boundary();
+//		Row & row = cur.textRow();
+//		os << bformat(_(", Row b:%1$d e:%2$d"), row.pos(), row.endpos());
+	}
 	return os.str();
 }
 
diff --git a/src/Text.h b/src/Text.h
index fc602fcf97..046ca9d4c8 100644
--- a/src/Text.h
+++ b/src/Text.h
@@ -157,8 +157,8 @@ public:
 	/// read-write access to individual paragraph
 	Paragraph & getPar(pit_type pit) { return pars_[pit]; }
 	// Returns the current font and depth as a message.
-	/// FIXME: replace Cursor with DocIterator.
-	docstring currentState(Cursor const & cur) const;
+	// When \param devel_mode is true, add more precise information
+	docstring currentState(Cursor const & cur, bool devel_mode) const;
 
 	/** Find the word under \c from in the relative location
 	 *  defined by \c word_location.
diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp
index eb80393c52..29246a8e1f 100644
--- a/src/frontends/qt4/GuiApplication.cpp
+++ b/src/frontends/qt4/GuiApplication.cpp
@@ -1727,13 +1727,8 @@ void GuiApplication::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 		current_view_->message(bformat(_("Opening help file %1$s..."),
 					       makeDisplayPath(fname.absFileName())));
 		Buffer * buf = current_view_->loadDocument(fname, false);
-
-#ifndef DEVEL_VERSION
 		if (buf)
-			buf->setReadonly(true);
-#else
-		(void) buf;
-#endif
+			buf->setReadonly(!current_view_->develMode());
 		break;
 	}
 
diff --git a/src/frontends/qt4/GuiCommandBuffer.cpp b/src/frontends/qt4/GuiCommandBuffer.cpp
index f14ba879ad..87e66da1f3 100644
--- a/src/frontends/qt4/GuiCommandBuffer.cpp
+++ b/src/frontends/qt4/GuiCommandBuffer.cpp
@@ -295,12 +295,6 @@ string const GuiCommandBuffer::historyDown()
 }
 
 
-docstring const GuiCommandBuffer::getCurrentState() const
-{
-	return view_->currentBufferView()->cursor().currentState();
-}
-
-
 vector<string> const
 GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
 {
diff --git a/src/frontends/qt4/GuiCommandBuffer.h b/src/frontends/qt4/GuiCommandBuffer.h
index 49ed9bf043..41b39d2644 100644
--- a/src/frontends/qt4/GuiCommandBuffer.h
+++ b/src/frontends/qt4/GuiCommandBuffer.h
@@ -65,9 +65,6 @@ private:
 	/// return the next history entry if any
 	std::string const historyDown();
 
-	/// return the font and depth in the active BufferView as a message.
-	docstring const getCurrentState() const;
-
 	/// open a listbox and show the contents of the list. When reversed
 	/// is true, the contents of the list is filled bottom-up.
 	void showList(std::vector<std::string> const & list,
diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp
index 5ff15c8e49..bb0dbd8d41 100644
--- a/src/frontends/qt4/GuiView.cpp
+++ b/src/frontends/qt4/GuiView.cpp
@@ -508,7 +508,12 @@ QSet<Buffer const *> GuiView::GuiViewPrivate::busyBuffers;
 
 GuiView::GuiView(int id)
 	: d(*new GuiViewPrivate(this)), id_(id), closing_(false), busy_(0),
-	  command_execute_(false), minibuffer_focus_(false)
+	  command_execute_(false), minibuffer_focus_(false),
+#ifdef DEVEL_VERSION
+	  devel_mode_(true)
+#else
+	  devel_mode_(false)
+#endif
 {
 	connect(this, SIGNAL(bufferViewChanged()),
 	        this, SLOT(onBufferViewChanged()));
@@ -715,6 +720,7 @@ void GuiView::saveLayout() const
 {
 	QSettings settings;
 	settings.setValue("zoom", lyxrc.currentZoom);
+	settings.setValue("devel_mode", devel_mode_);
 	settings.beginGroup("views");
 	settings.beginGroup(QString::number(id_));
 #if defined(Q_WS_X11) || defined(QPA_XCB)
@@ -746,6 +752,7 @@ bool GuiView::restoreLayout()
 	QSettings settings;
 	lyxrc.currentZoom = settings.value("zoom", lyxrc.zoom).toInt();
 	lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM, convert<docstring>(lyxrc.currentZoom)));
+	devel_mode_ = settings.value("devel_mode", devel_mode_).toBool();
 	settings.beginGroup("views");
 	settings.beginGroup(QString::number(id_));
 	QString const icon_key = "icon_size";
@@ -1148,7 +1155,10 @@ void GuiView::updateWindowTitle(GuiWorkArea * wa)
 		updateToolbars();
 	}
 #ifndef Q_WS_MAC
-	title += from_ascii(" - LyX");
+	if (devel_mode_)
+		title += from_ascii(" - LyX ") + from_ascii(lyx_version);
+	else
+		title += from_ascii(" - LyX");
 #endif
 	setWindowTitle(toqstr(title));
 	// Sets the path for the window: this is used by OSX to
@@ -1254,7 +1264,7 @@ void GuiView::showMessage()
 	if (msg.isEmpty()) {
 		BufferView const * bv = currentBufferView();
 		if (bv)
-			msg = toqstr(bv->cursor().currentState());
+			msg = toqstr(bv->cursor().currentState(devel_mode_));
 		else
 			msg = qt_("Welcome to LyX!");
 	}
@@ -1900,6 +1910,10 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 		enable = d.tabWorkAreaCount() > 1;
 		break;
 
+	case LFUN_DEVEL_MODE_TOGGLE:
+		flag.setOnOff(devel_mode_);
+		break;
+
 	case LFUN_TOOLBAR_TOGGLE: {
 		string const name = cmd.getArg(0);
 		if (GuiToolbar * t = toolbar(name))
@@ -3861,6 +3875,14 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 			closeBufferAll();
 			break;
 
+		case LFUN_DEVEL_MODE_TOGGLE:
+			devel_mode_ = !devel_mode_;
+			if (devel_mode_)
+				dr.setMessage(_("Developer mode is now enabled."));
+			else
+				dr.setMessage(_("Developer mode is now disabled."));
+			break;
+
 		case LFUN_TOOLBAR_TOGGLE: {
 			string const name = cmd.getArg(0);
 			if (GuiToolbar * t = toolbar(name))
diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h
index a3158a42f3..998fcc255b 100644
--- a/src/frontends/qt4/GuiView.h
+++ b/src/frontends/qt4/GuiView.h
@@ -343,6 +343,8 @@ public:
 	void hideDialog(std::string const & name, Inset * inset);
 	///
 	void disconnectDialog(std::string const & name);
+	///
+	bool develMode() const { return devel_mode_; }
 
 private:
 	/// Saves the layout and geometry of the window
@@ -469,6 +471,9 @@ private:
 
 	// movability flag of all toolbars
 	bool toolbarsMovable_;
+
+	// developer mode
+	bool devel_mode_;
 };
 
 } // namespace frontend
diff --git a/src/frontends/qt4/GuiViewSource.cpp b/src/frontends/qt4/GuiViewSource.cpp
index d58e173837..80d3c0b459 100644
--- a/src/frontends/qt4/GuiViewSource.cpp
+++ b/src/frontends/qt4/GuiViewSource.cpp
@@ -197,20 +197,21 @@ void ViewSourceWidget::updateView(BufferView const * bv)
 	           masterPerspectiveCB->isChecked());
 	QString old = document_->toPlainText();
 	QString qcontent = toqstr(content);
-#ifdef DEVEL_VERSION
-	// output tex<->row correspondences in the source panel if the "-dbg latex"
-	// option is given.
-	if (texrow_ && lyx::lyxerr.debugging(Debug::LATEX)) {
-		QStringList list = qcontent.split(QChar('\n'));
-		docstring_list dlist;
-		for (QStringList::const_iterator it = list.begin(); it != list.end(); ++it)
-			dlist.push_back(from_utf8(fromqstr(*it)));
-		texrow_->prepend(dlist);
-		qcontent.clear();
-		for (docstring_list::iterator it = dlist.begin(); it != dlist.end(); ++it)
-			qcontent += toqstr(*it) + '\n';
+	if (guiApp->currentView()->develMode()) {
+		// output tex<->row correspondences in the source panel if the "-dbg latex"
+		// option is given.
+		if (texrow_ && lyx::lyxerr.debugging(Debug::LATEX)) {
+			QStringList list = qcontent.split(QChar('\n'));
+			docstring_list dlist;
+			for (QStringList::const_iterator it = list.begin(); it != list.end(); ++it)
+				dlist.push_back(from_utf8(fromqstr(*it)));
+			texrow_->prepend(dlist);
+			qcontent.clear();
+			for (docstring_list::iterator it = dlist.begin(); it != dlist.end(); ++it)
+				qcontent += toqstr(*it) + '\n';
+		}
 	}
-#endif
+
 	// prevent gotoCursor()
 	QSignalBlocker blocker(viewSourceTV);
 	bool const changed = setText(qcontent);
diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp
index f4005d9124..366b09a5ae 100644
--- a/src/mathed/InsetMathHull.cpp
+++ b/src/mathed/InsetMathHull.cpp
@@ -2248,7 +2248,7 @@ void InsetMathHull::revealCodes(Cursor & cur) const
 	if (!cur.inMathed())
 		return;
 	odocstringstream os;
-	cur.info(os);
+	cur.info(os, false);
 	cur.message(os.str());
 /*
 	// write something to the minibuffer
-- 
2.11.0

Reply via email to