]> git.lyx.org Git - features.git/blobdiff - src/frontends/qt/GuiToolbar.cpp
Fix broken Apple speller interface
[features.git] / src / frontends / qt / GuiToolbar.cpp
index fbfa967c06f04c274788d67967fe3ce48c3db7f3..51699c98a8741a2f2e451464f3e501b9cda49a5a 100644 (file)
@@ -62,6 +62,11 @@ using namespace lyx::support;
 namespace lyx {
 namespace frontend {
 
+QIcon DynamicMenuButton::icon_textstyle_apply_;
+QIcon DynamicMenuButton::icon_undo_;
+QIcon DynamicMenuButton::icon_paste_;
+
+
 GuiToolbar::GuiToolbar(ToolbarInfo const & tbinfo, GuiView & owner)
        : QToolBar(toqstr(tbinfo.gui_name), &owner), visibility_(0),
          owner_(owner), command_buffer_(nullptr), tbinfo_(tbinfo), filled_(false),
@@ -116,6 +121,14 @@ void GuiToolbar::fill()
 }
 
 
+void GuiToolbar::refill()
+{
+       filled_ = false;
+       clear();
+       fill();
+}
+
+
 void GuiToolbar::showEvent(QShowEvent * ev)
 {
        fill();
@@ -129,17 +142,23 @@ void GuiToolbar::setVisibility(int visibility)
 }
 
 
-Action * GuiToolbar::addItem(ToolbarItem const & item)
+Action * GuiToolbar::addItem(ToolbarItem const & item, bool menu)
 {
        QString text = toqstr(item.label);
+       QString tooltip = text;
        // Get the keys bound to this action, but keep only the
        // first one later
        KeyMap::Bindings bindings = theTopLevelKeymap().findBindings(*item.func);
-       if (!bindings.empty())
-               text += " [" + toqstr(bindings.begin()->print(KeySequence::ForGui)) + "]";
+       if (!bindings.empty()) {
+               QString binding = toqstr(bindings.begin()->print(KeySequence::ForGui));
+               if (menu)
+                       text += '\t' + binding;
+               else
+                       tooltip += " [" + binding + "]";
+       }
 
        Action * act = new Action(item.func, getIcon(*item.func, false), text,
-                                                         text, this);
+                                 tooltip, this);
        if (item.type == ToolbarItem::BIDICOMMAND)
                act->setRtlIcon(getIcon(*item.func, false, true));
 
@@ -264,7 +283,7 @@ void StaticMenuButton::initialize()
        ToolbarInfo::item_iterator const end = tbinfo->items.end();
        for (; it != end; ++it)
                if (!getStatus(*it->func).unknown())
-                       m->add(bar_->addItem(*it));
+                       m->add(bar_->addItem(*it, true));
        setMenu(m);
 }
 
@@ -341,6 +360,14 @@ bool DynamicMenuButton::isMenuType(string const & s)
 }
 
 
+void DynamicMenuButton::resetIconCache()
+{
+       icon_textstyle_apply_ = getIcon(FuncRequest(LFUN_TEXTSTYLE_APPLY), false);
+       icon_undo_ =  getIcon(FuncRequest(LFUN_UNDO), false);
+       icon_paste_ = getIcon(FuncRequest(LFUN_PASTE), false);
+}
+
+
 void DynamicMenuButton::updateTriggered()
 {
        QMenu * m = menu();
@@ -382,7 +409,7 @@ void DynamicMenuButton::updateTriggered()
                m->clear();
                setPopupMode(QToolButton::MenuButtonPopup);
                if (!bv) {
-                       QToolButton::setIcon(getIcon(FuncRequest(LFUN_TEXTSTYLE_APPLY), false));
+                       QToolButton::setIcon(icon_textstyle_apply_);
                        setEnabled(false);
                        return;
                }
@@ -403,20 +430,20 @@ void DynamicMenuButton::updateTriggered()
                }
                // Add item to reset to defaults
                Action * reset_act = new Action(FuncRequest(LFUN_FONT_DEFAULT, FuncRequest::TOOLBAR),
-                                               getIcon(FuncRequest(LFUN_UNDO), false),
+                                               icon_undo_,
                                                qt_("&Reset to default"),
                                                qt_("Reset all font settings to their defaults"), this);
                m->addAction(reset_act);
                if (default_act)
                        QToolButton::setDefaultAction(default_act);
-               QToolButton::setIcon(getIcon(FuncRequest(LFUN_TEXTSTYLE_APPLY), false));
+               QToolButton::setIcon(icon_textstyle_apply_);
                setEnabled(lyx::getStatus(FuncRequest(LFUN_TEXTSTYLE_APPLY)).enabled()
                           || lyx::getStatus(FuncRequest(LFUN_FONT_DEFAULT)).enabled());
        } else if (menutype == "paste") {
                m->clear();
                setPopupMode(QToolButton::MenuButtonPopup);
                Action * default_action = new Action(FuncRequest(LFUN_PASTE),
-                                                    getIcon(FuncRequest(LFUN_PASTE), false),
+                                                    icon_paste_,
                                                     qt_("Paste"), qt_("Paste"), this);
                if (!bv) {
                        setEnabled(false);
@@ -448,11 +475,11 @@ void DynamicMenuButton::loadFlexInsets()
        QMenu * m = menu();
        m->clear();
        string const & menutype = tbitem_.name;
-       InsetLayout::InsetLyXType ftype;
+       InsetLyXType ftype;
        if (menutype == "dynamic-custom-insets")
-               ftype = InsetLayout::CUSTOM;
+               ftype = InsetLyXType::CUSTOM;
        else if (menutype == "dynamic-char-styles")
-               ftype = InsetLayout::CHARSTYLE;
+               ftype = InsetLyXType::CHARSTYLE;
        else {
                // this should have been taken care of earlier
                LASSERT(false, return);
@@ -605,42 +632,57 @@ void GuiToolbar::restoreSession()
 }
 
 
-bool GuiToolbar::isVisibiltyOn() const
+bool GuiToolbar::isVisibilityOn() const
 {
        return visibility_ & Toolbars::ON;
 }
 
 
-void GuiToolbar::toggle()
+void GuiToolbar::setState(string const state)
 {
-       docstring state;
-       if (visibility_ & Toolbars::ALLOWAUTO) {
-               if (!(visibility_ & Toolbars::AUTO)) {
+       docstring newstate;
+       if (state == "auto") {
+               if (visibility_ & Toolbars::ALLOWAUTO) {
                        visibility_ |= Toolbars::AUTO;
                        hide();
-                       state = _("auto");
-               } else {
-                       visibility_ &= ~Toolbars::AUTO;
-                       if (isVisible()) {
-                               hide();
-                               state = _("off");
-                       } else {
-                               show();
-                               state = _("on");
-                       }
-               }
+                       newstate = _("auto");
+               } else
+                       owner_.message(bformat(_("Toolbar \"%1$s\" does not support state \"auto\""),
+                               qstring_to_ucs4(windowTitle())));
        } else {
-               if (isVisible()) {
+               if (visibility_ & Toolbars::AUTO)
+                       visibility_ &= ~Toolbars::AUTO;
+               if (state == "off") {
                        hide();
-                       state = _("off");
-               } else {
+                       newstate = _("off");
+               } else if (state == "on") {
                        show();
-                       state = _("on");
+                       newstate = _("on");
                }
        }
 
        owner_.message(bformat(_("Toolbar \"%1$s\" state set to %2$s"),
-               qstring_to_ucs4(windowTitle()), state));
+               qstring_to_ucs4(windowTitle()), newstate));
+}
+
+
+void GuiToolbar::toggle()
+{
+       if (visibility_ & Toolbars::ALLOWAUTO) {
+               if (!(visibility_ & Toolbars::AUTO) && !isVisibilityOn()) {
+                       setState("auto");
+               } else {
+                       if (isVisibilityOn())
+                               setState("off");
+                       else
+                               setState("on");
+               }
+       } else {
+               if (isVisible())
+                       setState("off");
+               else
+                       setState("on");
+       }
 }
 
 void GuiToolbar::movable(bool silent)