Hi, All

Attached is a patch to save/restore toolbar status. Any opinion? (It
is qt4 only right now, and is not thoroughly tested).

Bo
Index: src/frontends/Toolbars.C
===================================================================
--- src/frontends/Toolbars.C	(revision 15344)
+++ src/frontends/Toolbars.C	(working copy)
@@ -20,11 +20,15 @@
 #include "FuncStatus.h"
 #include "gettext.h"
 #include "lyxfunc.h"
+#include "lyx_main.h"
+#include "session.h"
+
 #include "lyxtextclass.h"
 #include "LyXView.h"
 
 using std::endl;
 using std::string;
+using std::vector;
 
 
 Toolbars::Toolbars(LyXView & owner)
@@ -119,7 +123,10 @@
 	ToolbarPtr tb_ptr = owner_.makeToolbar(tbb);
 	toolbars_[tbb.name] = tb_ptr;
 
-	if (tbb.flags & ToolbarBackend::ON)
+	// load last saved toolbasr status, if possible
+	lyx::Session & session = LyX::ref().session();
+	string visibleToolbars = session.loadSessionInfo("VisibleToolBars", false);
+	if (tbb.flags & ToolbarBackend::ON & (visibleToolbars.empty() || visibleToolbars.find(tbb.name) != string::npos) )
 		tb_ptr->show(false);
 	else
 		tb_ptr->hide(false);
@@ -142,6 +149,18 @@
 }
 
 
+vector<string> Toolbars::visibleToolbars()
+{
+	vector<string> toolbars;
+	ToolbarsMap::const_iterator it = toolbars_.begin();
+	ToolbarsMap::const_iterator const end = toolbars_.end();
+	for (; it != end; ++it)
+		if(it->second->isVisible())
+			toolbars.push_back(it->first);
+	return toolbars;
+}
+
+
 void Toolbars::update()
 {
 	ToolbarsMap::const_iterator it = toolbars_.begin();
Index: src/frontends/qt4/QLToolbar.C
===================================================================
--- src/frontends/qt4/QLToolbar.C	(revision 15344)
+++ src/frontends/qt4/QLToolbar.C	(working copy)
@@ -215,6 +215,10 @@
 	QToolBar::show();
 }
 
+bool QLToolbar::isVisible()
+{
+	return QToolBar::isVisible();
+}
 
 void QLToolbar::update()
 {
Index: src/frontends/qt4/QLToolbar.h
===================================================================
--- src/frontends/qt4/QLToolbar.h	(revision 15344)
+++ src/frontends/qt4/QLToolbar.h	(working copy)
@@ -67,6 +67,7 @@
 	void add(FuncRequest const & func, lyx::docstring const & tooltip);
 	void hide(bool);
 	void show(bool);
+	bool isVisible();
 	void update();
 	LayoutBox * layout() const { return layout_.get(); }
 
Index: src/frontends/qt4/GuiView.C
===================================================================
--- src/frontends/qt4/GuiView.C	(revision 15344)
+++ src/frontends/qt4/GuiView.C	(working copy)
@@ -251,6 +251,12 @@
 		session.saveSessionInfo("WindowPosX", convert<string>(geometry.x()));
 		session.saveSessionInfo("WindowPosY", convert<string>(geometry.y()));
 	}
+	// save toolbar information
+	std::vector<string> toolbars = getToolbars().visibleToolbars();
+	string names = "";
+	for(std::vector<string>::iterator it = toolbars.begin(); it != toolbars.end(); ++it)
+		names += *it + " ";
+	session.saveSessionInfo("VisibleToolBars", names);
 	// trigger LFUN_LYX_QUIT instead of quit directly
 	// since LFUN_LYX_QUIT may have more cleanup stuff
 	dispatch(FuncRequest(LFUN_LYX_QUIT));
Index: src/frontends/Toolbars.h
===================================================================
--- src/frontends/Toolbars.h	(revision 15344)
+++ src/frontends/Toolbars.h	(working copy)
@@ -64,6 +64,8 @@
 	 */
 	virtual void show(bool update_metrics) = 0;
 
+	/// if the toolbar is visible
+	virtual bool isVisible() = 0;
 	/// Refresh the contents of the bar.
 	virtual void update() = 0;
 	/// Accessor to the layout combox, if any.
@@ -81,6 +83,10 @@
 
 	/// Show/hide the named toolbar.
 	void display(std::string const & name, bool show);
+
+	/// return the name of active toolbars
+	std::vector<std::string> visibleToolbars();
+
 	/// Update the state of the toolbars.
 	void update(bool in_math, bool in_table);
 

Reply via email to