]> git.lyx.org Git - features.git/commitdiff
split Menu::expand in chunks
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 22 Jul 2002 20:12:08 +0000 (20:12 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 22 Jul 2002 20:12:08 +0000 (20:12 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4749 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/MenuBackend.C
src/MenuBackend.h

index 62ecb5b95078f7004f46d9b42d17169d3cab0a21..87fdcb028a068307f6b4d40693f4294acd245733 100644 (file)
@@ -1,3 +1,12 @@
+2002-07-22  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * MenuBackend.C (expandLastfiles): 
+       (expandDocuments): 
+       (expandFormats): 
+       (expandFloatListInsert): 
+       (expandFloatInsert): 
+       (expand): split expand in parts
+
 2002-07-22  John Levon  <moz@compsoc.man.ac.uk>
 
        * lyx_gui.C: use lyx_gui::exit()
index d5cee4136467c04153308269fc06ab62701156b7..812e1f3fadf22a156b8304f19e3bf3deb0f194f7 100644 (file)
@@ -258,167 +258,169 @@ public:
        }
 };
 
-} // namespace anon
+void expandLastfiles(Menu & tomenu)
+{
+       int ii = 1;
+       LastFiles::const_iterator lfit = lastfiles->begin();
+       LastFiles::const_iterator end = lastfiles->end();
+
+       for (; lfit != end && ii < 10; ++lfit, ++ii) {
+               string const label = tostr(ii) + ". "
+                       + MakeDisplayPath((*lfit), 30)
+                       + '|' + tostr(ii);
+               int const action = lyxaction.
+                       getPseudoAction(LFUN_FILE_OPEN,
+                                       (*lfit));
+               tomenu.add(MenuItem(MenuItem::Command,
+                                   label, action));
+       }
+}
 
+void expandDocuments(Menu & tomenu)
+{
+       typedef vector<string> Strings;
+       Strings const names = bufferlist.getFileNames();
 
-void Menu::expand(Menu & tomenu, Buffer * buf) const
+       if (names.empty()) {
+               tomenu.add(MenuItem(MenuItem::Command, _("No Documents Open!"),
+                                   LFUN_NOACTION));
+               return;
+       }
+       
+       int ii = 1;
+       Strings::const_iterator docit = names.begin();
+       Strings::const_iterator end = names.end();
+       for (; docit != end; ++docit, ++ii) {
+               int const action =
+                       lyxaction.getPseudoAction(LFUN_SWITCHBUFFER, *docit);
+               string label = MakeDisplayPath(*docit, 30);
+               if (ii < 10)
+                       label = tostr(ii) + ". " + label + '|' + tostr(ii);
+               tomenu.add(MenuItem(MenuItem::Command, label, action));
+       }
+}
+
+
+void expandFormats(MenuItem::Kind kind, Menu & tomenu, Buffer const * buf)
 {
-       for (const_iterator cit = begin();
-            cit != end() ; ++cit) {
-               switch (cit->kind()) {
-               case MenuItem::Lastfiles: {
-                       int ii = 1;
-                       LastFiles::const_iterator lfit = lastfiles->begin();
-                       LastFiles::const_iterator end = lastfiles->end();
-
-                       for (; lfit != end && ii < 10; ++lfit, ++ii) {
-                               string const label = tostr(ii) + ". "
-                                       + MakeDisplayPath((*lfit), 30)
-                                       + '|' + tostr(ii);
-                               int const action = lyxaction.
-                                       getPseudoAction(LFUN_FILE_OPEN,
-                                                       (*lfit));
-                               tomenu.add(MenuItem(MenuItem::Command,
-                                                   label, action));
-                       }
-               }
+       if (!buf && kind != MenuItem::ImportFormats) {
+               tomenu.add(MenuItem(MenuItem::Command,
+                                   _("No Documents Open!"), LFUN_NOACTION));
+               return;
+       }                               
+                       
+       typedef vector<Format const *> Formats;
+       Formats formats;
+       kb_action action;
+       
+       switch (kind) {
+       case MenuItem::ImportFormats:
+               formats = Importer::GetImportableFormats();
+               action = LFUN_IMPORT;
+               break;
+       case MenuItem::ViewFormats:
+               formats = Exporter::GetExportableFormats(buf, true);
+               action = LFUN_PREVIEW;
+               break;
+       case MenuItem::UpdateFormats:
+               formats = Exporter::GetExportableFormats(buf, true);
+               action = LFUN_UPDATE;
                break;
+       default:
+               formats = Exporter::GetExportableFormats(buf, false);
+               action = LFUN_EXPORT;
+       }
+       sort(formats.begin(), formats.end(), compare_format());
 
-               case MenuItem::Documents: {
-                       typedef vector<string> Strings;
+       Formats::const_iterator fit = formats.begin();
+       Formats::const_iterator end = formats.end();
+       for (; fit != end ; ++fit) {
+               if ((*fit)->dummy())
+                       continue;
+               string label = (*fit)->prettyname();
+               // we need to hide the default graphic export formats
+               // from the external menu, because we need them only
+               // for the internal lyx-view and external latex run
+               if (label == "EPS" || label == "XPM" || label == "PNG")
+                       continue;
 
-                       Strings const names = bufferlist.getFileNames();
+               if (kind == MenuItem::ImportFormats)
+                       if ((*fit)->name() == "text")
+                               label = _("Ascii text as lines");
+                       else if ((*fit)->name() == "textparagraph")
+                               label = _("Ascii text as paragraphs");
+               if (!(*fit)->shortcut().empty())
+                       label += "|" + (*fit)->shortcut();
+               int const action2 = lyxaction.
+                       getPseudoAction(action, (*fit)->name());
+               tomenu.add(MenuItem(MenuItem::Command, label, action2));
+       }
+}
 
-                       if (names.empty()) {
-                               tomenu.add(MenuItem(MenuItem::Command,
-                                                   _("No Documents Open!"),
-                                                   LFUN_NOACTION));
-                               break;
-                       }
+void expandFloatListInsert(Menu & tomenu)
+{
+       FloatList::const_iterator cit = floatList.begin();
+       FloatList::const_iterator end = floatList.end();
+       for (; cit != end; ++cit) {
+               int const action =  lyxaction
+                       .getPseudoAction(LFUN_FLOAT_LIST, cit->second.type());
+               tomenu.add(MenuItem(MenuItem::Command,
+                                   _(cit->second.listName()),
+                                   action));
+       }
+}
 
-                       int ii = 1;
-                       Strings::const_iterator docit = names.begin();
-                       Strings::const_iterator end = names.end();
-                       for (; docit != end; ++docit, ++ii) {
-                               int const action = lyxaction
-                                       .getPseudoAction(LFUN_SWITCHBUFFER,
-                                                        *docit);
-                               string label = MakeDisplayPath(*docit, 30);
-                               if (ii < 10)
-                                       label = tostr(ii) + ". "
-                                               + label + '|' + tostr(ii);
-                               tomenu.add(MenuItem(MenuItem::Command,
-                                                   label, action));
-                       }
-               }
-               break;
+void expandFloatInsert(Menu & tomenu)
+{
+       FloatList::const_iterator cit = floatList.begin();
+       FloatList::const_iterator end = floatList.end();
+       for (; cit != end; ++cit) {
+               // normal float
+               int const action =
+                       lyxaction.getPseudoAction(LFUN_INSET_FLOAT,
+                                                 cit->second.type());
+               string const label = _(cit->second.name());
+               tomenu.add(MenuItem(MenuItem::Command, label, action));
+               
+               // and the wide version
+               int const action2 =
+                       lyxaction.getPseudoAction(LFUN_INSET_WIDE_FLOAT,
+                                                 cit->second.type());
+               string const label2 = label + _(" (wide)");
+               tomenu.add(MenuItem(MenuItem::Command, label2, action2));
+       }
+}
+
+} // namespace anon
+
+
+void Menu::expand(Menu & tomenu, Buffer const * buf) const
+{
+       for (const_iterator cit = begin();
+            cit != end() ; ++cit) {
+               switch (cit->kind()) {
+               case MenuItem::Lastfiles: 
+                       expandLastfiles(tomenu);
+                       break;
+
+               case MenuItem::Documents:
+                       expandDocuments(tomenu);
+                       break;
 
                case MenuItem::ImportFormats:
                case MenuItem::ViewFormats:
                case MenuItem::UpdateFormats:
-               case MenuItem::ExportFormats: {
-
-                       if (!buf && cit->kind() != MenuItem::ImportFormats) {
-                               tomenu.add(MenuItem(MenuItem::Command,
-                                                   _("No Documents Open!"),
-                                                   LFUN_NOACTION));
-                               continue;
-                       }                               
-                       
-                       typedef vector<Format const *> Formats;
-
-                       Formats formats;
-
-                       kb_action action;
-                       switch (cit->kind()) {
-                       case MenuItem::ImportFormats:
-                               formats = Importer::GetImportableFormats();
-                               action = LFUN_IMPORT;
-                               break;
-                       case MenuItem::ViewFormats:
-                               formats = Exporter::GetExportableFormats(buf, true);
-                               action = LFUN_PREVIEW;
-                               break;
-                       case MenuItem::UpdateFormats:
-                               formats = Exporter::GetExportableFormats(buf, true);
-                               action = LFUN_UPDATE;
-                               break;
-                       default:
-                               formats = Exporter::GetExportableFormats(buf, false);
-                               action = LFUN_EXPORT;
-                       }
-                       sort(formats.begin(), formats.end(), compare_format());
-
-                       Formats::const_iterator fit = formats.begin();
-                       Formats::const_iterator end = formats.end();
-
-                       for (; fit != end ; ++fit) {
-                               if ((*fit)->dummy())
-                                       continue;
-                               string label = (*fit)->prettyname();
-                               // we need to hide the default graphic export
-                               // formats from the external menu, because we
-                               // need them only for the internal lyx-view and
-                               // external latex run
-                               if (label == "EPS" ||
-                                   label == "XPM" ||
-                                   label == "PNG")
-                                       continue;
-
-                               if (cit->kind() == MenuItem::ImportFormats)
-                                       if ((*fit)->name() == "text")
-                                               label = _("Ascii text as lines");
-                                       else if ((*fit)->name() == "textparagraph")
-                                               label = _("Ascii text as paragraphs");
-                               if (!(*fit)->shortcut().empty())
-                                       label += "|" + (*fit)->shortcut();
-                               int const action2 = lyxaction.
-                                       getPseudoAction(action,
-                                                       (*fit)->name());
-                               tomenu.add(MenuItem(MenuItem::Command,
-                                                   label, action2));
-                       }
-               }
-               break;
+               case MenuItem::ExportFormats:
+                       expandFormats(cit->kind(), tomenu, buf);
+                       break;
 
                case MenuItem::FloatListInsert:
-               {
-                       FloatList::const_iterator cit = floatList.begin();
-                       FloatList::const_iterator end = floatList.end();
-                       for (; cit != end; ++cit) {
-                               int const action =  lyxaction
-                                       .getPseudoAction(LFUN_FLOAT_LIST,
-                                                        cit->second.type());
-                               tomenu.add(MenuItem(MenuItem::Command,
-                                                   _(cit->second.listName()),
-                                                   action));
-                       }
-               }
-               break;
+                       expandFloatListInsert(tomenu);
+                       break;
 
                case MenuItem::FloatInsert:
-               {
-                       FloatList::const_iterator cit = floatList.begin();
-                       FloatList::const_iterator end = floatList.end();
-                       for (; cit != end; ++cit) {
-                               // normal float
-                               int const action = lyxaction
-                                       .getPseudoAction(LFUN_INSET_FLOAT,
-                                                        cit->second.type());
-                               string const label = _(cit->second.name());
-                               tomenu.add(MenuItem(MenuItem::Command,
-                                                   label, action));
-
-                               // and the wide version
-                               int const action2 = lyxaction
-                                       .getPseudoAction(LFUN_INSET_WIDE_FLOAT,
-                                                        cit->second.type());
-                               string const label2 = label + _(" (wide)");
-                               tomenu.add(MenuItem(MenuItem::Command,
-                                                   label2, action2));
-                       }
-               }
-               break;
+                       expandFloatInsert(tomenu);
+                       break;
 
                default:
                        tomenu.add(*cit);
index af49d96e1e5fd6ed85a937eb0ad352aea40f3e05..b630c54e4cc8b7d205229a3d8619a967758fafa6 100644 (file)
@@ -121,7 +121,7 @@ public:
            sequence of Command MenuItems: Lastfiles, Documents,
            ViewFormats, ExportFormats, UpdateFormats
        */
-       void expand(Menu & tomenu, Buffer *) const;
+       void expand(Menu & tomenu, Buffer const *) const;
        ///
        string const & name() const { return name_; }
        ///