From: Jean-Marc Lasgouttes Date: Wed, 4 Oct 2000 09:54:31 +0000 (+0000) Subject: Move some special code from menu frontend to backend. X-Git-Tag: 1.6.10~21937 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=df13cd9f7c5e0522f8dc93af3d48ca77efb8b426;p=features.git Move some special code from menu frontend to backend. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1079 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/ChangeLog b/ChangeLog index 6c2f10ecce..0428b02521 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2000-10-04 Jean-Marc Lasgouttes + + * src/frontends/xforms/Menubar_pimpl.C (create_submenu): use + Menu::expand. + (add_lastfiles): removed. + (add_documents): removed. + (add_formats): removed. + + * src/frontends/Menubar.C: remove useless "using" directive. + + * src/MenuBackend.h: add a new MenuItem constructor. + + * src/MenuBackend.[Ch] (Menu::expand): new method. Used in the + xforms frontend. + 2000-10-04 Allan Rae * lib/Makefile.am (listerrors): diff --git a/src/MenuBackend.C b/src/MenuBackend.C index 896100436b..5fedfbbdbc 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -21,10 +21,18 @@ #include "LyXAction.h" #include "debug.h" #include "gettext.h" +#include "lastfiles.h" +#include "bufferlist.h" +#include "exporter.h" +#include "support/filetools.h" extern LyXAction lyxaction; +extern LastFiles * lastfiles; +extern BufferList bufferlist; using std::endl; +using std::vector; +using std::pair; // This is the global menu definition MenuBackend menubackend; @@ -184,6 +192,83 @@ Menu & Menu::read(LyXLex & lex) return *this; } +void Menu::expand(Menu & tomenu, Buffer *buf) const +{ + for (const_iterator cit = begin(); + cit != end() ; ++cit) { + switch ((*cit).kind()) { + case MenuItem::Lastfiles: { + int ii = 1; + for (LastFiles::const_iterator lfit = lastfiles->begin(); + lfit != lastfiles->end() && ii < 10; + ++lfit, ++ii) { + string label = tostr(ii) + ". " + + MakeDisplayPath((*lfit), 30) + + '|' + tostr(ii); + int action = lyxaction. + getPseudoAction(LFUN_FILE_OPEN, + (*lfit)); + tomenu.add(MenuItem(MenuItem::Command, + label, action)); + } + } + break; + + case MenuItem::Documents: { + vector names = bufferlist.getFileNames(); + + if (names.empty()) { + tomenu.add(MenuItem(MenuItem::Command, + _("No Documents Open!"), + LFUN_NOACTION)); + break; + } + + for (vector::const_iterator docit = names.begin(); + docit != names.end() ; ++docit) { + int action = + lyxaction.getPseudoAction(LFUN_SWITCHBUFFER, *docit); + string label = MakeDisplayPath(*docit, 30); + tomenu.add(MenuItem(MenuItem::Command, + label, action)); + } + } + break; + + case MenuItem::ViewFormats: + case MenuItem::UpdateFormats: + case MenuItem::ExportFormats: { + vector > names; + kb_action action; + if ((*cit).kind() == MenuItem::ViewFormats) { + names = Exporter::GetViewableFormats(buf); + action = LFUN_PREVIEW; + } else if ((*cit).kind() == MenuItem::UpdateFormats) { + names = Exporter::GetViewableFormats(buf); + action = LFUN_UPDATE; + } else { + names = Exporter::GetExportableFormats(buf); + action = LFUN_EXPORT; + } + + for (vector >::const_iterator fit = names.begin(); + fit != names.end() ; ++fit) { + int action2 = + lyxaction.getPseudoAction(action, + (*fit).first); + string label = (*fit).second; + tomenu.add(MenuItem(MenuItem::Command, + label, action2)); + } + } + break; + + + default: + tomenu.add(*cit); + } + } +} void MenuBackend::read(LyXLex & lex) { diff --git a/src/MenuBackend.h b/src/MenuBackend.h index 7ceb6c6ec5..f03bf57ec9 100644 --- a/src/MenuBackend.h +++ b/src/MenuBackend.h @@ -23,6 +23,7 @@ #include class LyXLex; +class Buffer; /// class MenuItem { @@ -46,13 +47,13 @@ public: /// References, /** This is a list of viewable formats - typically for the Documents menu. */ + typically for the File->View menu. */ ViewFormats, /** This is a list of updatable formats - typically for the Documents menu. */ + typically for the File->Update menu. */ UpdateFormats, /** This is a list of exportable formats - typically for the Documents menu. */ + typically for the File->Export menu. */ ExportFormats }; /// Create a Command type MenuItem @@ -60,6 +61,13 @@ public: string const & label = string(), string const & command = string(), bool optional = false); + MenuItem(Kind kind, + string const & label, + int action, + bool optional = false) + : kind_(kind), label_(label), + action_(action), submenu_(), optional_(optional) {} + /// The label of a given menuitem string const label() const { return token(label_, '|', 0); } /// @@ -94,12 +102,18 @@ public: /// typedef ItemList::const_iterator const_iterator; /// - explicit Menu(string const & name, bool mb = false) + explicit Menu(string const & name = string(), bool mb = false) : menubar_(mb), name_(name) {} /// Menu & add(MenuItem const &); /// Menu & read(LyXLex &); + /// Expands some special entries of the menu + /** The entries with the following kind are exanded to a + sequence of Command MenuItems: Lastfiles, Documents, + ViewFormats, ExportFormats, UpdateFormats + */ + void expand(Menu & tomenu, Buffer *) const; /// bool menubar() const { return menubar_; } /// diff --git a/src/frontends/Menubar.C b/src/frontends/Menubar.C index 9404465d13..dbf60fabf4 100644 --- a/src/frontends/Menubar.C +++ b/src/frontends/Menubar.C @@ -20,9 +20,6 @@ #include "Menubar.h" #include "Menubar_pimpl.h" -using std::endl; - - Menubar::Menubar(LyXView * o, MenuBackend const & md) { pimpl_ = new Pimpl(o, md); diff --git a/src/frontends/xforms/Menubar_pimpl.C b/src/frontends/xforms/Menubar_pimpl.C index 5136e7c20e..8f465b990f 100644 --- a/src/frontends/xforms/Menubar_pimpl.C +++ b/src/frontends/xforms/Menubar_pimpl.C @@ -14,22 +14,18 @@ #include #include -#include +//#include #include "support/lstrings.h" -#include "support/filetools.h" #include "support/LAssert.h" #include "debug.h" #include "LyXAction.h" #include "lyxfunc.h" #include "kbmap.h" -#include "bufferlist.h" -#include "lastfiles.h" +#include "buffer.h" #include "LyXView.h" #include "MenuBackend.h" #include "Menubar_pimpl.h" -#include "exporter.h" -using std::pair; using std::endl; using std::vector; using std::max; @@ -39,8 +35,6 @@ typedef vector::size_type size_type; extern kb_keymap * toplevel_keymap; extern LyXAction lyxaction; -extern BufferList bufferlist; -extern LastFiles * lastfiles; // Some constants const int MENU_LABEL_SIZE = FL_NORMAL_SIZE; @@ -187,52 +181,6 @@ void Menubar::Pimpl::openByName(string const & name) } -void Menubar::Pimpl::add_lastfiles(int menu, string const & extra_label) -{ - int ii = 1; - for (LastFiles::const_iterator cit = lastfiles->begin(); - cit != lastfiles->end() && ii < 10; ++cit, ++ii) { - - int action = - lyxaction.getPseudoAction(LFUN_FILE_OPEN, (*cit)); - string label = tostr(ii) + ". " - + MakeDisplayPath((*cit),30) - + "%x" + tostr(action) + "%h"; - if ((cit + 1) == lastfiles->end()) - label += extra_label; - string shortcut = tostr(ii) + "#" + tostr(ii); - lyxerr[Debug::GUI] << "shortcut is " << shortcut << - endl; - - fl_addtopup(menu, label.c_str(), shortcut.c_str()); - } - -} - -void Menubar::Pimpl::add_documents(int menu, string const & extra_label) -{ - vector names = bufferlist.getFileNames(); - - if (names.empty()) { - fl_addtopup(menu,_("No Documents Open!%i")); - return; - } - - for (vector::const_iterator cit = names.begin(); - cit != names.end() ; ++cit) { - int action = - lyxaction.getPseudoAction(LFUN_SWITCHBUFFER, *cit); - string label = MakeDisplayPath(*cit, 30) - + "%x" + tostr(action); - if ((cit + 1) == names.end()) - label += extra_label; - - fl_addtopup(menu, label.c_str()); - } - -} - - string limit_string_length(string const & str) { string::size_type const max_item_length = 45; @@ -497,28 +445,6 @@ void Menubar::Pimpl::add_references(int menu, string const & extra_label, } -void Menubar::Pimpl::add_formats(int menu, string const & extra_label, - kb_action action, bool viewable) -{ - vector > names = - viewable - ? Exporter::GetViewableFormats(owner_->buffer()) - : Exporter::GetExportableFormats(owner_->buffer()); - - for (vector >::const_iterator cit = names.begin(); - cit != names.end() ; ++cit) { - int action2 = - lyxaction.getPseudoAction(action, (*cit).first); - string label = (*cit).second - + "%x" + tostr(action2); - if ((cit + 1) == names.end()) - label += extra_label; - - fl_addtopup(menu, label.c_str()); - } -} - - int Menubar::Pimpl::create_submenu(Window win, LyXView * view, string const & menu_name, vector & smn) @@ -528,7 +454,8 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view, << menu_name << "'" << endl; return -1; } - Menu md = menubackend_->getMenu(menu_name); + Menu md = Menu(); + menubackend_->getMenu(menu_name).expand(md, owner_->buffer()); int menu = fl_newpup(win); fl_setpup_softedge(menu, true); @@ -657,14 +584,6 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view, // we just ignore it. break; - case MenuItem::Documents: - add_documents(menu, extra_label); - break; - - case MenuItem::Lastfiles: - add_lastfiles(menu, extra_label); - break; - case MenuItem::Toc: add_toc(menu, extra_label, smn, win); break; @@ -673,16 +592,13 @@ int Menubar::Pimpl::create_submenu(Window win, LyXView * view, add_references(menu, extra_label, smn, win); break; + case MenuItem::Documents: + case MenuItem::Lastfiles: case MenuItem::ViewFormats: - add_formats(menu, extra_label, LFUN_PREVIEW, true); - break; - case MenuItem::UpdateFormats: - add_formats(menu, extra_label, LFUN_UPDATE, true); - break; - case MenuItem::ExportFormats: - add_formats(menu, extra_label, LFUN_EXPORT, false); + lyxerr << "Menubar::Pimpl::create_submenu: " + "this should not happen" << endl; break; } diff --git a/src/frontends/xforms/Menubar_pimpl.h b/src/frontends/xforms/Menubar_pimpl.h index 7fbc5880ef..9ffce98ca3 100644 --- a/src/frontends/xforms/Menubar_pimpl.h +++ b/src/frontends/xforms/Menubar_pimpl.h @@ -29,8 +29,6 @@ class MenuBackend; class MenuItem; class Menu; -#include "debug.h" - /** The LyX GUI independent menubar class The GUI interface is implemented in the corresponding Menubar_pimpl class. */ @@ -48,18 +46,6 @@ public: /// static void MenuCallback(FL_OBJECT *, long); - /** Add to "menu" the list of last opened files - (add "extra_label" to the last entry) - */ - void add_lastfiles(int menu, string const & extra_label); - /** Add to "menu" the list of opened documents - (add "extra_label" to the last entry) - */ - void add_documents(int menu, string const & extra_label); - /// Add to "menu" the list of exportable/viewable formats - /// (add "extra_label" to the last entry) - void add_formats(int menu, string const & extra_label, - kb_action action, bool viewable); /// void add_toc(int menu, string const & extra_label, std::vector & smn, Window win);