Hi, all, Attached is an updated toolbar/session patch that works for qt3/4. Can I apply?
Problems: 1. view->toolbars->.... is lacking. 2. For both qt3/4, session info is only saved with the close button. File->exit does not work. As far as I remember, File->exit worked before. 3. I do not know what extra information I can save/restore so I only save/restore on/off right now. Cheers, 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,11 @@ ToolbarPtr tb_ptr = owner_.makeToolbar(tbb); toolbars_[tbb.name] = tb_ptr; - if (tbb.flags & ToolbarBackend::ON) + lyx::Session & session = LyX::ref().session(); + string status = session.loadSessionInfo(tbb.name + "Toolbar"); + // status can be empty (no session info saved for this toolbar, use default), "On", + // or "Off". This part should be changed if more information is saved. + if (status == "On" || (status.empty() && tbb.flags & ToolbarBackend::ON)) tb_ptr->show(false); else tb_ptr->hide(false); @@ -142,6 +150,30 @@ } +vector<string> Toolbars::toolbarNames() const +{ + vector<string> names; + ToolbarsMap::const_iterator it = toolbars_.begin(); + ToolbarsMap::const_iterator const end = toolbars_.end(); + for (; it != end; ++it) + names.push_back(it->first); + return names; +} + + +string Toolbars::toolbarStatus(string const & name) const +{ + ToolbarsMap::const_iterator it = toolbars_.find(name); + BOOST_ASSERT(it != toolbars_.end()); + // right now, we only return on/off for a toolbar + // more information like position may be returned later + if (it->second->isVisible()) + return "On"; + else + return "Off"; +} + + void Toolbars::update() { ToolbarsMap::const_iterator it = toolbars_.begin(); Index: src/frontends/qt3/QLToolbar.C =================================================================== --- src/frontends/qt3/QLToolbar.C (revision 15344) +++ src/frontends/qt3/QLToolbar.C (working copy) @@ -218,6 +218,12 @@ } +bool QLToolbar::isVisible() +{ + return toolbar_->isVisible(); +} + + void QLToolbar::update() { ButtonMap::const_iterator p = map_.begin(); Index: src/frontends/qt3/QLToolbar.h =================================================================== --- src/frontends/qt3/QLToolbar.h (revision 15344) +++ src/frontends/qt3/QLToolbar.h (working copy) @@ -64,6 +64,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/qt3/QtView.C =================================================================== --- src/frontends/qt3/QtView.C (revision 15344) +++ src/frontends/qt3/QtView.C (working copy) @@ -221,6 +221,11 @@ session.saveSessionInfo("WindowPosX", convert<string>(geometry.x())); session.saveSessionInfo("WindowPosY", convert<string>(geometry.y())); } + // save toolbar information + Toolbars const & toolbars = getToolbars(); + std::vector<string> toolbarNames = toolbars.toolbarNames(); + for(std::vector<string>::iterator it = toolbarNames.begin(); it != toolbarNames.end(); ++it) + session.saveSessionInfo(*it + "Toolbar", toolbars.toolbarStatus(*it)); // 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/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,11 @@ session.saveSessionInfo("WindowPosX", convert<string>(geometry.x())); session.saveSessionInfo("WindowPosY", convert<string>(geometry.y())); } + // save toolbar information + Toolbars const & toolbars = getToolbars(); + std::vector<string> toolbarNames = toolbars.toolbarNames(); + for(std::vector<string>::iterator it = toolbarNames.begin(); it != toolbarNames.end(); ++it) + session.saveSessionInfo(*it + "Toolbar", toolbars.toolbarStatus(*it)); // 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,13 @@ /// Show/hide the named toolbar. void display(std::string const & name, bool show); + + /// return the name of all toolbars + std::vector<std::string> toolbarNames() const; + + /// return the status (on/off) of a toolbar + std::string toolbarStatus(std::string const & name) const; + /// Update the state of the toolbars. void update(bool in_math, bool in_table);