From 31f6d268e2ae124ffb1d80cf83316390d72c3637 Mon Sep 17 00:00:00 2001 From: John Levon Date: Thu, 10 Apr 2003 14:08:06 +0000 Subject: [PATCH] toolbar3.diff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6768 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/ChangeLog | 10 ++++++++++ lib/ui/default.ui | 10 ++++++++-- src/BufferView_pimpl.C | 2 ++ src/ToolbarBackend.C | 15 +++++++++++++++ src/ToolbarBackend.h | 12 +++++++++++- src/frontends/ChangeLog | 7 +++++++ src/frontends/LyXView.C | 6 +++++- src/frontends/Toolbar.C | 26 ++++++++++++++++++++++---- src/frontends/Toolbar.h | 15 ++++++++------- src/frontends/qt2/ChangeLog | 8 ++++++++ src/frontends/qt2/QtView.C | 2 +- src/frontends/qt2/Toolbar_pimpl.C | 15 ++++++++++++++- src/frontends/qt2/Toolbar_pimpl.h | 5 ++++- src/frontends/xforms/ChangeLog | 6 ++++++ src/frontends/xforms/Toolbar_pimpl.h | 3 +++ src/frontends/xforms/XFormsView.C | 2 +- 16 files changed, 125 insertions(+), 19 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 9bda5ad60b..0ffaa8f35f 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,13 @@ +2003-04-10 John Levon + + * ui/default.ui: Add visibility tag to toolbars + + * BufferView_pimpl.C: updateToolbar on mouse click + + * ToolbarBackend.h: + * ToolbarBackend.C: handle toolbar on/off settings + + 2003-04-10 John Levon * images/: new icons, mostly taken from kdeart diff --git a/lib/ui/default.ui b/lib/ui/default.ui index 1fe6bf6134..6a7cc5231e 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -391,7 +391,13 @@ Menuset End -# Setup your favorite Toolbar here: +# A Toolbar starts like : +# +# Toolbar "Name" "on" +# +# The second parameter is the status, and can be "on", "off", "math" +# or "table". The last two make the toolbars appear and disappear automatically. +# # Only three commands are allowed inside the begin_toolbar and end_toolbar # directives: # Item " []" adds an icon to the toolbar performing @@ -411,7 +417,7 @@ End # # This is the default toolbar: -Toolbar "Standard" +Toolbar "Standard" "on" Layouts Item "Open document" "file-open" Item "Save document" "buffer-write" diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index a2acdf364d..d31a6af5e0 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -937,7 +937,9 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev_in) bool const res = dispatch(ev_in); + // FIXME: we should skip these when selecting bv_->owner()->updateLayoutChoice(); + bv_->owner()->updateToolbar(); bv_->fitCursor(); // slight hack: this is only called currently when diff --git a/src/ToolbarBackend.C b/src/ToolbarBackend.C index 61bfdc9260..b16f85120b 100644 --- a/src/ToolbarBackend.C +++ b/src/ToolbarBackend.C @@ -65,6 +65,21 @@ void ToolbarBackend::read(LyXLex & lex) Toolbar tb; tb.name = lex.getString(); + lex.next(true); + string type = lex.getString(); + if (!compare_ascii_no_case(type, "off")) + tb.display_type = OFF; + else if (!compare_ascii_no_case(type, "on")) + tb.display_type = ON; + else if (!compare_ascii_no_case(type, "math")) + tb.display_type = MATH; + else if (!compare_ascii_no_case(type, "table")) + tb.display_type = TABLE; + else { + lyxerr << "ToolbarBackend::read: unrecognised token:`" + << type << '\'' << endl; + } + bool quit = false; lex.pushTable(toolTags, TO_LAST - 1); diff --git a/src/ToolbarBackend.h b/src/ToolbarBackend.h index ba2bfa4c9a..952d2649cf 100644 --- a/src/ToolbarBackend.h +++ b/src/ToolbarBackend.h @@ -23,7 +23,7 @@ class LyXLex; class ToolbarBackend { public: /// The special toolbar actions - enum ItemType { + enum ItemType { /// adds space between buttons in the toolbar SEPARATOR = -3, /// a special combox insead of a button @@ -38,12 +38,22 @@ public: /// the toolbar items typedef std::vector > Items; + /// possibly display types + enum DisplayType { + OFF, //< never shown + ON, //< always shown + MATH, //< shown when in math + TABLE //< shown when in table + }; + /// a toolbar struct Toolbar { /// toolbar UI name string name; /// toolbar contents Items items; + /// display type + DisplayType display_type; }; typedef std::vector Toolbars; diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index dd9f5b356d..e9f60c1164 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,10 @@ +2003-04-10 John Levon + + * Toolbar.h: + * Toolbar.C: handle on/off etc. for toolbars + + * LyXView.C: update toolbar on/off etc. + 2003-04-09 John Levon * Toolbar.C: handle multiple toolbars diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index 1baa0ce1db..fd25d66e65 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -31,6 +31,7 @@ #include "Timeout.h" #include "Menubar.h" #include "controllers/ControlCommandBuffer.h" +#include "mathed/math_cursor.h" #include "support/filetools.h" // OnlyFilename() @@ -96,7 +97,10 @@ void LyXView::setLayout(string const & layout) void LyXView::updateToolbar() { - toolbar_->update(); + bool const math = mathcursor; + bool const table = + !getLyXFunc().getStatus(LFUN_LAYOUT_TABULAR).disabled(); + toolbar_->update(math, table); } diff --git a/src/frontends/Toolbar.C b/src/frontends/Toolbar.C index 836e40ce83..123b15d06f 100644 --- a/src/frontends/Toolbar.C +++ b/src/frontends/Toolbar.C @@ -19,14 +19,14 @@ using std::endl; -Toolbar::Toolbar(LyXView * o, int x, int y, ToolbarBackend const & backend) +Toolbar::Toolbar(LyXView * o, int x, int y) : last_textclass_(-1) { pimpl_ = new Pimpl(o, x, y); // extracts the toolbars from the backend - ToolbarBackend::Toolbars::const_iterator cit = backend.begin(); - ToolbarBackend::Toolbars::const_iterator end = backend.end(); + ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin(); + ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end(); for (; cit != end; ++cit) pimpl_->add(*cit); @@ -39,9 +39,27 @@ Toolbar::~Toolbar() } -void Toolbar::update() +void Toolbar::update(bool in_math, bool in_table) { pimpl_->update(); + + // extracts the toolbars from the backend + ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin(); + ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end(); + + for (; cit != end; ++cit) { + switch (cit->display_type) { + case ToolbarBackend::OFF: + case ToolbarBackend::ON: + break; + case ToolbarBackend::MATH: + pimpl_->displayToolbar(*cit, in_math); + break; + case ToolbarBackend::TABLE: + pimpl_->displayToolbar(*cit, in_table); + break; + } + } } diff --git a/src/frontends/Toolbar.h b/src/frontends/Toolbar.h index e59af253f2..c12a21b2f9 100644 --- a/src/frontends/Toolbar.h +++ b/src/frontends/Toolbar.h @@ -16,22 +16,23 @@ #include "LString.h" class LyXView; -class ToolbarBackend; -/** The LyX GUI independent toolbar class - The GUI interface is implemented in the corresponding Toolbar_pimpl class. - */ +/** + * The LyX GUI independent toolbar class + * + * The GUI interface is implemented in the corresponding Toolbar_pimpl class. + */ class Toolbar { public: /// - Toolbar(LyXView * o, int x, int y, ToolbarBackend const &); + Toolbar(LyXView * o, int x, int y); /// ~Toolbar(); - /// update the state of the icons - void update(); + /// update the state of the toolbars + void update(bool in_math, bool in_table); /// update the layout combox void setLayout(string const & layout); diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 130257b784..eeea3f4ae1 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,11 @@ +2003-04-10 John Levon + + * QtView.C: Toolbar ctor changed + + * Toolbar_pimpl.h: + * Toolbar_pimpl.C: store toolbars in a map + for show/hide as needed + 2003-04-09 John Levon * Toolbar_pimpl.h: diff --git a/src/frontends/qt2/QtView.C b/src/frontends/qt2/QtView.C index 6c432b6736..5d68030f83 100644 --- a/src/frontends/qt2/QtView.C +++ b/src/frontends/qt2/QtView.C @@ -64,7 +64,7 @@ QtView::QtView(unsigned int width, unsigned int height) ::current_view = bufferview_.get(); menubar_.reset(new Menubar(this, menubackend)); - toolbar_.reset(new Toolbar(this, 0, 0, toolbarbackend)); + toolbar_.reset(new Toolbar(this, 0, 0)); statusBar()->setSizeGripEnabled(false); diff --git a/src/frontends/qt2/Toolbar_pimpl.C b/src/frontends/qt2/Toolbar_pimpl.C index f00d776f3a..6320580445 100644 --- a/src/frontends/qt2/Toolbar_pimpl.C +++ b/src/frontends/qt2/Toolbar_pimpl.C @@ -58,6 +58,17 @@ Toolbar::Pimpl::~Pimpl() } +void Toolbar::Pimpl::displayToolbar(ToolbarBackend::Toolbar const & tb, bool show) +{ + QToolBar * qtb = toolbars_[tb.name]; + if (show) { + qtb->show(); + } else { + qtb->hide(); + } +} + + void Toolbar::Pimpl::update() { ButtonMap::const_iterator p = map_.begin(); @@ -201,7 +212,9 @@ void Toolbar::Pimpl::add(ToolbarBackend::Toolbar const & tb) for (; it != end; ++it) add(qtb, it->first, it->second); - toolbars_.push_back(qtb); + toolbars_[tb.name] = qtb; + displayToolbar(tb, tb.display_type == ToolbarBackend::ON); + } diff --git a/src/frontends/qt2/Toolbar_pimpl.h b/src/frontends/qt2/Toolbar_pimpl.h index 0f4d87934e..9ae211ec1c 100644 --- a/src/frontends/qt2/Toolbar_pimpl.h +++ b/src/frontends/qt2/Toolbar_pimpl.h @@ -44,6 +44,9 @@ public: /// add an item to a toolbar void add(QToolBar * tb, int action, string const & tooltip); + /// show or hide a toolbar + void displayToolbar(ToolbarBackend::Toolbar const & tb, bool show); + /// update the state of the icons void update(); @@ -64,7 +67,7 @@ private: boost::scoped_ptr proxy_; - std::vector toolbars_; + std::map toolbars_; QLComboBox * combo_; diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index bd8c681613..6fb94f5e88 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,9 @@ +2003-04-10 John Levon + + * XFormsView.C: + * Toolbar_pimpl.h: + * Toolbar_pimpl.C: API change for show/hide + 2003-04-09 Angus Leeming * FormAboutlyx.C: diff --git a/src/frontends/xforms/Toolbar_pimpl.h b/src/frontends/xforms/Toolbar_pimpl.h index 5c97ccceff..7fd210ad80 100644 --- a/src/frontends/xforms/Toolbar_pimpl.h +++ b/src/frontends/xforms/Toolbar_pimpl.h @@ -38,6 +38,9 @@ public: /// add an item to a toolbar void add(int action, string const & tooltip); + /// display toolbar, not implemented + void displayToolbar(ToolbarBackend::Toolbar const & tb, bool show) {} + /// update the state of the icons void update(); diff --git a/src/frontends/xforms/XFormsView.C b/src/frontends/xforms/XFormsView.C index 4d37ffd175..d4c7d4420b 100644 --- a/src/frontends/xforms/XFormsView.C +++ b/src/frontends/xforms/XFormsView.C @@ -142,7 +142,7 @@ void XFormsView::create_form_form_main(int width, int height) menubar_.reset(new Menubar(this, menubackend)); - toolbar_.reset(new Toolbar(this, air, 30 + air + bw, toolbarbackend)); + toolbar_.reset(new Toolbar(this, air, 30 + air + bw)); int const ywork = 60 + 2 * air + bw; int const workheight = height - ywork - (25 + 2 * air); -- 2.39.2