diff --git a/lib/ChangeLog b/lib/ChangeLog index 0173e2175b..1e56d08515 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,9 @@ +2003-06-11 John Levon + + * ui/stdtoolbars.ui: move flags to ... + + * ui/default.ui: ... Toolbars section here + 2003-06-11 John Levon * ui/stdtoolbars.ui: show Extra toolbar by default diff --git a/lib/ui/default.ui b/lib/ui/default.ui index 821d183f43..412ac8f5f8 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -4,3 +4,24 @@ Include "stdmenus.ui" Include "stdtoolbars.ui" + +# Which toolbars to use. +# +# The second parameter are the flags : +# +# on: the toolbar is visible +# off: the toolbar is not visible +# math: the toolbar is visible only when in math +# table: the toolbar is visible only when in a table +# top: the toolbar should be at the top of the window +# bottom: the toolbar should be at the bottom of the window +# left: the toolbar should be at the left of the window +# right: the toolbar should be at the right of the window +# +Toolbars + "Standard" "on,top" + "Extra" "on,top" + "Table" "off,bottom" + "Math" "off,bottom" + "Command Buffer" "off,bottom" +End diff --git a/lib/ui/stdtoolbars.ui b/lib/ui/stdtoolbars.ui index c40ca152c2..4cadcc909d 100644 --- a/lib/ui/stdtoolbars.ui +++ b/lib/ui/stdtoolbars.ui @@ -1,17 +1,6 @@ # A Toolbar starts like : # -# Toolbar "Name" "on" -# -# The second parameter are the flags : -# -# on: the toolbar is visible -# off: the toolbar is not visible -# math: the toolbar is visible only when in math -# table: the toolbar is visible only when in a table -# top: the toolbar should be at the top of the window -# bottom: the toolbar should be at the bottom of the window -# left: the toolbar should be at the left of the window -# right: the toolbar should be at the right of the window +# Toolbar "Name" # # Only four commands are allowed inside the begin_toolbar and end_toolbar # directives: @@ -36,8 +25,6 @@ # # This is the default toolbar: -# slight rationalisations here - Toolbar "Standard" "on,top" Layouts Item "New document" "buffer-new" diff --git a/src/ChangeLog b/src/ChangeLog index 0578d83184..dad0094c64 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2003-06-11 John Levon + + * lyx_main.C: + * ToolbarBackend.h: + * ToolbarBackend.C: add "Toolbars" section and + put the flags there + 2003-06-10 Angus Leeming * lfuns.h: diff --git a/src/ToolbarBackend.C b/src/ToolbarBackend.C index 0d15ccc091..756c49b510 100644 --- a/src/ToolbarBackend.C +++ b/src/ToolbarBackend.C @@ -71,38 +71,6 @@ void ToolbarBackend::read(LyXLex & lex) tb.name = lex.getString(); lex.next(true); - tb.flags = static_cast(0); - string flagstr = lex.getString(); - vector flags = getVectorFromString(flagstr); - - vector::const_iterator cit = flags.begin(); - vector::const_iterator end = flags.end(); - - for (; cit != end; ++cit) { - int flag = 0; - if (!compare_ascii_no_case(*cit, "off")) - flag = OFF; - else if (!compare_ascii_no_case(*cit, "on")) - flag = ON; - else if (!compare_ascii_no_case(*cit, "math")) - flag = MATH; - else if (!compare_ascii_no_case(*cit, "table")) - flag = TABLE; - else if (!compare_ascii_no_case(*cit, "top")) - flag = TOP; - else if (!compare_ascii_no_case(*cit, "bottom")) - flag = BOTTOM; - else if (!compare_ascii_no_case(*cit, "left")) - flag = LEFT; - else if (!compare_ascii_no_case(*cit, "right")) - flag = RIGHT; - else { - lyxerr << "ToolbarBackend::read: unrecognised token:`" - << *cit << '\'' << endl; - } - tb.flags = static_cast(tb.flags | flag); - } - bool quit = false; lex.pushTable(toolTags, TO_LAST - 1); @@ -152,6 +120,74 @@ void ToolbarBackend::read(LyXLex & lex) } +void ToolbarBackend::readToolbars(LyXLex & lex) +{ + //consistency check + if (compare_ascii_no_case(lex.getString(), "toolbars")) { + lyxerr << "ToolbarBackend::read: ERROR wrong token:`" + << lex.getString() << '\'' << endl; + } + + lex.next(true); + + while (lex.isOK()) { + string name = lex.getString(); + lex.next(true); + + if (!compare_ascii_no_case(name, "end")) + return; + + Toolbars::iterator tcit = toolbars.begin(); + Toolbars::iterator tend = toolbars.end(); + for (; tcit != tend; ++tcit) { + if (tcit->name == name) + break; + } + + if (tcit == tend) { + lyxerr << "ToolbarBackend: undefined toolbar " + << name << endl; + return; + } + + tcit->flags = static_cast(0); + string flagstr = lex.getString(); + lex.next(true); + vector flags = getVectorFromString(flagstr); + + vector::const_iterator cit = flags.begin(); + vector::const_iterator end = flags.end(); + + for (; cit != end; ++cit) { + int flag = 0; + if (!compare_ascii_no_case(*cit, "off")) + flag = OFF; + else if (!compare_ascii_no_case(*cit, "on")) + flag = ON; + else if (!compare_ascii_no_case(*cit, "math")) + flag = MATH; + else if (!compare_ascii_no_case(*cit, "table")) + flag = TABLE; + else if (!compare_ascii_no_case(*cit, "top")) + flag = TOP; + else if (!compare_ascii_no_case(*cit, "bottom")) + flag = BOTTOM; + else if (!compare_ascii_no_case(*cit, "left")) + flag = LEFT; + else if (!compare_ascii_no_case(*cit, "right")) + flag = RIGHT; + else { + lyxerr << "ToolbarBackend::read: unrecognised token:`" + << *cit << '\'' << endl; + } + tcit->flags = static_cast(tcit->flags | flag); + } + + usedtoolbars.push_back(*tcit); + } +} + + void ToolbarBackend::add(Toolbar & tb, int action, string const & tooltip) { tb.items.push_back(make_pair(action, tooltip)); diff --git a/src/ToolbarBackend.h b/src/ToolbarBackend.h index bbc3498f5e..9a84eee9bc 100644 --- a/src/ToolbarBackend.h +++ b/src/ToolbarBackend.h @@ -68,16 +68,19 @@ public: /// iterator for all toolbars Toolbars::const_iterator begin() const { - return toolbars.begin(); + return usedtoolbars.begin(); } Toolbars::const_iterator end() const { - return toolbars.end(); + return usedtoolbars.end(); } /// read a toolbar from the file void read(LyXLex &); + /// read the used toolbars + void readToolbars(LyXLex &); + /// return a full path of an XPM for the given action static string const getIcon(int action); @@ -90,6 +93,9 @@ private: /// all the toolbars Toolbars toolbars; + + /// toolbars listed + Toolbars usedtoolbars; }; /// The global instance diff --git a/src/lyx_main.C b/src/lyx_main.C index 5f1a44cfc0..f323a19069 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -635,6 +635,7 @@ void LyX::readUIFile(string const & name) enum Uitags { ui_menuset = 1, ui_toolbar, + ui_toolbars, ui_include, ui_last }; @@ -642,7 +643,8 @@ void LyX::readUIFile(string const & name) struct keyword_item uitags[ui_last - 1] = { { "include", ui_include }, { "menuset", ui_menuset }, - { "toolbar", ui_toolbar } + { "toolbar", ui_toolbar }, + { "toolbars", ui_toolbars } }; // Ensure that a file is read only once (prevents include loops) @@ -697,6 +699,10 @@ void LyX::readUIFile(string const & name) toolbarbackend.read(lex); break; + case ui_toolbars: + toolbarbackend.readToolbars(lex); + break; + default: if (!rtrim(lex.getString()).empty()) lex.printError("LyX::ReadUIFile: "