Abdelrazak Younes wrote:
Also a Toolbar button to show the two math toolbars in the main toolbar is very much needed.

the attached patch would allow to put a "toggle math toolbar" button on the main toolbar. we could then add a "toggle math panels" button on the math toolbar...
Index: src/frontends/qt4/QLToolbar.cpp
===================================================================
--- src/frontends/qt4/QLToolbar.cpp     (revision 18446)
+++ src/frontends/qt4/QLToolbar.cpp     (working copy)
@@ -298,6 +298,12 @@
 }
 
 
+bool QLToolbar::isVisible() const
+{
+       return QToolBar::isVisible();
+}
+
+
 void QLToolbar::saveInfo(ToolbarSection::ToolbarInfo & tbinfo)
 {
        // if tbinfo.state == auto *do not* set on/off
Index: src/frontends/qt4/QLToolbar.h
===================================================================
--- src/frontends/qt4/QLToolbar.h       (revision 18446)
+++ src/frontends/qt4/QLToolbar.h       (working copy)
@@ -69,6 +69,7 @@
        void add(ToolbarItem const & item);
        void hide(bool);
        void show(bool);
+       bool isVisible() const;
        void saveInfo(ToolbarSection::ToolbarInfo & info);
        void update();
        LayoutBox * layout() const { return layout_.get(); }
Index: src/frontends/Toolbars.cpp
===================================================================
--- src/frontends/Toolbars.cpp  (revision 18446)
+++ src/frontends/Toolbars.cpp  (working copy)
@@ -151,14 +151,13 @@
        for (; cit != end; ++cit) {
                if (cit->name == name) {
                        unsigned int flags = cit->flags;
+                       TurnOffFlag(ON);
+                       TurnOffFlag(OFF);
                        TurnOffFlag(AUTO);
-                       if (show) {
+                       if (show)
                                TurnOnFlag(ON);
+                       else
                                TurnOnFlag(OFF);
-                       } else {
-                               TurnOnFlag(OFF);
-                               TurnOnFlag(ON);
-                       }
                        cit->flags = 
static_cast<lyx::ToolbarInfo::Flags>(flags);
                        displayToolbar(*cit, show);
                        return;
@@ -248,6 +247,16 @@
 }
 
 
+bool Toolbars::visible(string const & name) const
+{
+       std::map<string, ToolbarPtr>::const_iterator it =
+               toolbars_.find(name);
+       if (it == toolbars_.end())
+               return false;
+       return it->second.get()->isVisible();
+}
+
+
 void Toolbars::saveToolbarInfo()
 {
        ToolbarSection & tb = LyX::ref().session().toolbars();
Index: src/frontends/Toolbars.h
===================================================================
--- src/frontends/Toolbars.h    (revision 18446)
+++ src/frontends/Toolbars.h    (working copy)
@@ -70,6 +70,8 @@
        */
        virtual void saveInfo(ToolbarSection::ToolbarInfo & tbinfo) = 0;
 
+       /// whether toolbar is visible
+       virtual bool isVisible() const = 0;
        /// Refresh the contents of the bar.
        virtual void update() = 0;
        /// Accessor to the layout combox, if any.
@@ -90,13 +92,16 @@
 
        /// get toolbar state (on/off/auto)
        ToolbarInfo::Flags getToolbarState(std::string const & name);
-       
+
        /// toggle the state of toolbars (on/off/auto)
        void toggleToolbarState(std::string const & name);
 
        /// Update the state of the toolbars.
        void update(bool in_math, bool in_table, bool review);
 
+       /// Is the Toolbar currently visible?
+       bool visible(std::string const & name) const;
+
        /// save toolbar information
        void saveToolbarInfo();
 
Index: src/lfuns.h
===================================================================
--- src/lfuns.h (revision 18446)
+++ src/lfuns.h (working copy)
@@ -381,6 +381,7 @@
        LFUN_CLEARDOUBLEPAGE_INSERT,     // Ugras 20061125
        //290
        LFUN_LISTING_INSERT,             // Herbert 20011110, bpeng 20070502
+       LFUN_TOOLBAR_TOGGLE,             // Edwin 20070521
 
        LFUN_LASTACTION                  // end of the table
 };
Index: src/LyXAction.cpp
===================================================================
--- src/LyXAction.cpp   (revision 18446)
+++ src/LyXAction.cpp   (working copy)
@@ -367,6 +367,7 @@
                { LFUN_WINDOW_CLOSE, "window-close", NoBuffer },
                { LFUN_UNICODE_INSERT, "unicode-insert", Noop },
                { LFUN_TOOLBAR_TOGGLE_STATE, "", NoBuffer },
+               { LFUN_TOOLBAR_TOGGLE, "toolbar-toggle", NoBuffer },
                { LFUN_NOMENCL_INSERT, "nomencl-insert", Noop },
                { LFUN_NOMENCL_PRINT, "nomencl-print", Noop },
                { LFUN_CLEARPAGE_INSERT, "clearpage-insert", Noop },
Index: src/LyXFunc.cpp
===================================================================
--- src/LyXFunc.cpp     (revision 18446)
+++ src/LyXFunc.cpp     (working copy)
@@ -623,6 +623,11 @@
                break;
        }
 
+       case LFUN_TOOLBAR_TOGGLE: {
+               bool const current = 
lyx_view_->getToolbars().visible(cmd.getArg(0));
+               flag.setOnOff(current);
+               break;
+       }
        // this one is difficult to get right. As a half-baked
        // solution, we consider only the first action of the sequence
        case LFUN_COMMAND_SEQUENCE: {
@@ -1752,6 +1757,14 @@
                        lyx_view_->toggleToolbarState(argument);
                        break;
 
+               case LFUN_TOOLBAR_TOGGLE: {
+                       BOOST_ASSERT(lyx_view_);
+                       string const name = to_utf8(cmd.argument());
+                       bool const current = 
lyx_view_->getToolbars().visible(name);
+                       lyx_view_->getToolbars().display(name, !current);
+                       break;
+               }
+
                default: {
                        BOOST_ASSERT(lyx_view_);
                        view()->cursor().dispatch(cmd);

Reply via email to