From aa3acd6358e6fb6b86761bdfa3f336eb82502893 Mon Sep 17 00:00:00 2001 From: John Levon Date: Tue, 8 Apr 2003 19:17:00 +0000 Subject: [PATCH] toolbar changes git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6738 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ChangeLog | 5 +++ lib/ui/default.ui | 40 +++++++++++------------ src/ChangeLog | 6 ++++ src/ToolbarBackend.C | 47 ++++++++++++++++++++++++---- src/ToolbarBackend.h | 26 +++++++++------ src/frontends/ChangeLog | 4 +++ src/frontends/Toolbar.C | 3 +- src/frontends/qt2/ChangeLog | 5 +++ src/frontends/qt2/Toolbar_pimpl.C | 46 ++------------------------- src/frontends/qt2/Toolbar_pimpl.h | 2 +- src/frontends/xforms/ChangeLog | 4 +++ src/frontends/xforms/Toolbar_pimpl.C | 6 ++-- src/frontends/xforms/Toolbar_pimpl.h | 2 +- 13 files changed, 110 insertions(+), 86 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 701adece64..bb14ef8005 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,8 @@ +2003-04-08 John Levon + + * ui/default.ui: add tooltips for toolbar items, + s/Icon/Item + 2003-04-03 Tomasz Luczak * layouts/mwbk.layout: small fix diff --git a/lib/ui/default.ui b/lib/ui/default.ui index 6d0bdd8053..9bfaff6dc9 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -394,11 +394,11 @@ End # Setup your favorite Toolbar here: # Only three commands are allowed inside the begin_toolbar and end_toolbar # directives: -# Icon " []" adds an icon to the toolbar performing +# Item " []" adds an icon to the toolbar performing # " " # Examples: -# Icon "font-size small" -# Icon set-emph +# Item "font-size small" +# Item set-emph # # Layouts adds the layouts combo-box to the toolbar # @@ -413,26 +413,26 @@ End Toolbar Layouts - Icon "file-open" - Icon "buffer-write" - Icon "buffer-print" + Item "Open document" "file-open" + Item "Save document" "buffer-write" + Item "Print document" "buffer-print" Separator - Icon "cut" - Icon "copy" - Icon "paste" + Item "Cut selection" "cut" + Item "Copy selection" "copy" + Item "Paste" "paste" Separator - Icon "font-emph" - Icon "font-noun" - Icon "font-free-apply" + Item "Toggle emphasis style" "font-emph" + Item "Toggle noun style" "font-noun" + Item "Toggle free style" "font-free-apply" Separator - Icon "ert-insert" - Icon "math-mode" - #Icon "math-panel" + Item "Insert TeX" "ert-insert" + Item "Insert math" "math-mode" + #Item "math-panel" Separator - Icon "footnote-insert" - Icon "marginalnote-insert" - Icon "depth-increment" + Item "Insert footnote" "footnote-insert" + Item "Insert margin note" "marginalnote-insert" + Item "Increase depth" "depth-increment" Separator - Icon "dialog-show-new-inset graphics" - Icon "tabular-insert" + Item "Insert graphics" "dialog-show-new-inset graphics" + Item "Insert table" "tabular-insert" End diff --git a/src/ChangeLog b/src/ChangeLog index 3577220367..e76d403c32 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-04-08 John Levon + + * ToolbarBackend.h: + * ToolbarBackend.C: add getIcon(), handle tooltip, + and change from "Icon" to "Item". + 2003-04-08 Alfredo Braunstein * BufferView.C (lockInset): another bad getchar crunched diff --git a/src/ToolbarBackend.C b/src/ToolbarBackend.C index 3c2a8d08b9..442129bf3e 100644 --- a/src/ToolbarBackend.C +++ b/src/ToolbarBackend.C @@ -15,7 +15,12 @@ #include "lyxlex.h" #include "debug.h" #include "lyxlex.h" +#include "gettext.h" + #include "support/lstrings.h" +#include "support/filetools.h" + +#include "frontends/controllers/ControlMath.h" using std::endl; @@ -35,7 +40,7 @@ enum _tooltags { struct keyword_item toolTags[TO_LAST - 1] = { { "end", TO_ENDTOOLBAR }, - { "icon", TO_ADD }, + { "item", TO_ADD }, { "layouts", TO_LAYOUTS }, { "newline", TO_NEWLINE }, { "separator", TO_SEPARATOR } @@ -49,9 +54,9 @@ ToolbarBackend::ToolbarBackend() } -void ToolbarBackend::add(int action) +void ToolbarBackend::add(int action, string const & tooltip) { - items.push_back(action); + items.push_back(make_pair(action, tooltip)); } @@ -74,11 +79,13 @@ void ToolbarBackend::read(LyXLex & lex) switch (lex.lex()) { case TO_ADD: if (lex.next(true)) { + string const tooltip = _(lex.getString()); + lex.next(true); string const func = lex.getString(); lyxerr[Debug::PARSER] << "ToolbarBackend::read TO_ADD func: `" << func << '\'' << endl; - add(func); + add(func, tooltip); } break; @@ -107,7 +114,7 @@ void ToolbarBackend::read(LyXLex & lex) } -void ToolbarBackend::add(string const & func) +void ToolbarBackend::add(string const & func, string const & tooltip) { int const tf = lyxaction.LookupFunc(func); @@ -115,6 +122,34 @@ void ToolbarBackend::add(string const & func) lyxerr << "ToolbarBackend::add: no LyX command called `" << func << "' exists!" << endl; } else { - add(tf); + add(tf, tooltip); } } + + +string const ToolbarBackend::getIcon(int action) +{ + string fullname; + FuncRequest f = lyxaction.retrieveActionArg(action); + + if (f.action == LFUN_INSERT_MATH && !f.argument.empty()) { + fullname = find_xpm(f.argument.substr(1)); + } else { + string const name = lyxaction.getActionName(f.action); + string xpm_name(name); + + if (!f.argument.empty()) + xpm_name = subst(name + ' ' + f.argument, ' ', '_'); + + fullname = LibFileSearch("images", xpm_name, "xpm"); + } + + + if (!fullname.empty()) { + lyxerr[Debug::GUI] << "Full icon name is `" + << fullname << '\'' << endl; + return fullname; + } + + return LibFileSearch("images", "unknown", "xpm"); +} diff --git a/src/ToolbarBackend.h b/src/ToolbarBackend.h index 7e609ac8c4..0819908ee2 100644 --- a/src/ToolbarBackend.h +++ b/src/ToolbarBackend.h @@ -13,6 +13,7 @@ #define TOOLBAR_BACKEND_H #include +#include #include "LString.h" @@ -31,11 +32,14 @@ public: NEWLINE = -1 }; - /// - typedef std::vector Items; - /// + /// action, tooltip + typedef std::pair Item; + + /// the toolbar items + typedef std::vector > Items; + typedef Items::iterator iterator; - /// + typedef Items::const_iterator const_iterator; /// ToolbarBackend(); @@ -57,12 +61,16 @@ public: } /// void read(LyXLex &); + + /// return a full path of an XPM for the given action + static string const getIcon(int action); + private: - /// This func is just to make it easy for me... - void add(int); - /// - void add(string const &); - /// + /// add the given lfun with tooltip if relevant + void add(int, string const & tooltip = string()); + /// add the given lfun with tooltip if relevant + void add(string const &, string const & tooltip); + /// all the items Items items; }; diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 6631d63eec..24d131de53 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,7 @@ +2003-04-08 John Levon + + * Toolbar.C: handle tooltip + 2003-04-07 John Levon * LyXView.h: add clearMessage() diff --git a/src/frontends/Toolbar.C b/src/frontends/Toolbar.C index 9f4bfecc7f..c19f215149 100644 --- a/src/frontends/Toolbar.C +++ b/src/frontends/Toolbar.C @@ -27,8 +27,7 @@ Toolbar::Toolbar(LyXView * o, int x, int y, ToolbarBackend const & backend) // extracts the toolbar actions from the backend for (ToolbarBackend::const_iterator cit = backend.begin(); cit != backend.end(); ++cit) { - pimpl_->add((*cit)); - lyxerr[Debug::GUI] << "tool action: " << (*cit) << endl; + pimpl_->add(cit->first, cit->second); } } diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index cea4694e53..49bbc50d04 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,8 @@ +2003-04-08 John Levon + + * Toolbar_pimpl.C: move xpm code into ToolbarBackend, + handle tooltip + 2003-04-07 John Levon * ui/QIncludeDialogBase.ui: make "Show preview" diff --git a/src/frontends/qt2/Toolbar_pimpl.C b/src/frontends/qt2/Toolbar_pimpl.C index 534ec09eae..fcc866c07f 100644 --- a/src/frontends/qt2/Toolbar_pimpl.C +++ b/src/frontends/qt2/Toolbar_pimpl.C @@ -26,8 +26,6 @@ #include "support/filetools.h" #include "support/lstrings.h" -#include "ControlMath.h" - #include #include "QtView.h" @@ -40,44 +38,6 @@ using std::endl; -namespace { - -QPixmap getIconPixmap(int action) -{ - FuncRequest f = lyxaction.retrieveActionArg(action); - - string fullname; - - if (f.action == LFUN_INSERT_MATH && !f.argument.empty()) { - fullname = find_xpm(f.argument.substr(1)); - } else { - string const name = lyxaction.getActionName(f.action); - string xpm_name(name); - - if (!f.argument.empty()) - xpm_name = subst(name + ' ' + f.argument, ' ','_'); - - fullname = LibFileSearch("images", xpm_name, "xpm"); - } - - - if (!fullname.empty()) { - lyxerr[Debug::GUI] << "Full icon name is `" - << fullname << '\'' << endl; - return QPixmap(toqstr(fullname)); - } - - lyxerr << "Unable to find icon `" << fullname << '\'' << endl; - fullname = LibFileSearch("images", "unknown", "xpm"); - if (!fullname.empty()) { - lyxerr[Debug::GUI] << "Using default `unknown' icon" - << endl; - } - return QPixmap(toqstr(fullname)); -} - -} // namespace anon - class QLComboBox : public QComboBox { public: @@ -233,7 +193,7 @@ void Toolbar::Pimpl::openLayoutList() } -void Toolbar::Pimpl::add(int action) +void Toolbar::Pimpl::add(int action, string const & tooltip) { if (!toolbars_.size()) { toolbars_.push_back(new QToolBar(owner_)); @@ -258,9 +218,9 @@ void Toolbar::Pimpl::add(int action) break; } default: { + QPixmap p = QPixmap(toolbarbackend.getIcon(action).c_str()); QToolButton * tb = - new QToolButton(getIconPixmap(action), - qt_(lyxaction.helpText(action)), "", + new QToolButton(p, toqstr(tooltip), "", proxy_.get(), SLOT(button_selected()), toolbars_.back()); map_[tb] = action; diff --git a/src/frontends/qt2/Toolbar_pimpl.h b/src/frontends/qt2/Toolbar_pimpl.h index 5f40f331c9..fe8769e35d 100644 --- a/src/frontends/qt2/Toolbar_pimpl.h +++ b/src/frontends/qt2/Toolbar_pimpl.h @@ -38,7 +38,7 @@ public: ~Pimpl(); /// add a new button to the toolbar. - void add(int action); + void add(int action, string const & tooltip); /// update the state of the icons void update(); diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index d401586e66..f44356e8f2 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,7 @@ +2003-04-08 John Levon + + * Toolbar_pimpl.C: handle tooltip + 2003-04-03 Angus Leeming * combox.[ch]: diff --git a/src/frontends/xforms/Toolbar_pimpl.C b/src/frontends/xforms/Toolbar_pimpl.C index 021f56e7a7..6126f53117 100644 --- a/src/frontends/xforms/Toolbar_pimpl.C +++ b/src/frontends/xforms/Toolbar_pimpl.C @@ -301,7 +301,7 @@ void setPixmap(FL_OBJECT * obj, int action) } // namespace anon -void Toolbar::Pimpl::add(int action) +void Toolbar::Pimpl::add(int action, string const & tooltip) { toolbarItem item; item.action = action; @@ -348,9 +348,7 @@ void Toolbar::Pimpl::add(int action) // Remove the blue feedback rectangle fl_set_pixmapbutton_focus_outline(obj, 0); - // initialise the tooltip - string const tip = _(lyxaction.helpText(obj->argument)); - tooltip_->init(obj, tip); + tooltip_->init(obj, tooltip); // The view that this object belongs to. obj->u_vdata = owner_; diff --git a/src/frontends/xforms/Toolbar_pimpl.h b/src/frontends/xforms/Toolbar_pimpl.h index 26db1ca671..73b8a0ba1d 100644 --- a/src/frontends/xforms/Toolbar_pimpl.h +++ b/src/frontends/xforms/Toolbar_pimpl.h @@ -32,7 +32,7 @@ public: ~Pimpl(); /// add a new button to the toolbar. - void add(int action); + void add(int action, string const & tooltip); /// update the state of the icons void update(); -- 2.39.5