On Thu, Jul 31, 2003 at 02:05:37PM +0200, Jean-Marc Lasgouttes spake thusly:
> 
> >>>>> "Martin" == Martin Vermeer <[EMAIL PROTECTED]> writes:
> 
> Martin> Now added (at Juergen's request) dynamic menu items for
> Martin> inserting Branch insets. Attached the files that changed.
> 
> The code related to menu backend seems fine to me, except for the
> following function:
> 
> +void expandBranches(Menu & tomenu, LyXView const * view)
> +{
> +     int ii = 1;
> 
> why isn't this declared in the for() statement?

Yes, why not.
 
> +     BufferParams params = view->buffer()->params;
> +
> +     std::list<Branch>::const_iterator cit = params.branchlist.begin();
> +     std::list<Branch>::const_iterator end = params.branchlist.end();
> +     
> +     for (; cit != end && ii < 10; ++cit, ++ii) {
> 
> You limit your self artificially to 10 branches by doing this. Why?
> The code in expandDocuments has more flexibility.

Yes, done.
 
> +             string const label = tostr(ii) + " " +
> 
> Is numbering branches the best way to give shortcuts to them? Couldn't
> you declare shortcuts in the branch names somehow?

How? They are completely arbitrary user-chosen strings.

Of course in principle you could implement taking the first letter,
unless reserved already in which case the second letter, etc. Easy
with find_first_not_of. This is not guaranteed to finish however (but
in practice it usually will)

Is this what you had in mind? And is it worth the effort?
 
> +                             (cit->getSelected() ? "*" : " ") +
> 
> I do not like this way of marking selected branches like that. Is this
> needed in an Insert menu?

Needed no, useful perhaps. Matter of taste. Info overload? I'll remove it.
 
> use
>                               cit->getBranch() + '|' + tostr(ii);
> instead.
> 
> 
> 
> JMarc
> 

Martin

Index: MenuBackend.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/MenuBackend.C,v
retrieving revision 1.75
diff -u -p -r1.75 MenuBackend.C
--- MenuBackend.C       27 Jul 2003 13:18:54 -0000      1.75
+++ MenuBackend.C       31 Jul 2003 13:04:15 -0000
@@ -69,6 +69,7 @@ MenuItem::MenuItem(Kind kind, string con
        case FloatListInsert:
        case FloatInsert:
        case PasteRecent:
+       case Branches:
                break;
        case Command:
                action_ = lyxaction.LookupFunc(command);
@@ -189,6 +190,7 @@ Menu & Menu::read(LyXLex & lex)
 {
        enum Menutags {
                md_item = 1,
+               md_branches,
                md_documents,
                md_endmenu,
                md_exportformats,
@@ -208,6 +210,7 @@ Menu & Menu::read(LyXLex & lex)
        };
 
        struct keyword_item menutags[md_last - 1] = {
+               { "branches", md_branches },
                { "documents", md_documents },
                { "end", md_endmenu },
                { "exportformats", md_exportformats },
@@ -293,6 +296,10 @@ Menu & Menu::read(LyXLex & lex)
                        add(MenuItem(MenuItem::PasteRecent));
                        break;
 
+               case md_branches:
+                       add(MenuItem(MenuItem::Branches));
+                       break;
+
                case md_optsubmenu:
                        optional = true;
                        // fallback to md_submenu
@@ -635,6 +642,25 @@ void expandPasteRecent(Menu & tomenu, Ly
 }
 
 
+void expandBranches(Menu & tomenu, LyXView const * view)
+{
+       BufferParams const & params = view->buffer()->params;
+
+       std::list<Branch>::const_iterator cit = params.branchlist.begin();
+       std::list<Branch>::const_iterator end = params.branchlist.end();
+       
+       for (int ii = 1; cit != end; ++cit, ++ii) {
+               string label = cit->getBranch();
+               int const action = lyxaction.
+                       getPseudoAction(LFUN_INSERT_BRANCH,
+                                       (cit->getBranch()));
+               if (ii < 10)
+                       label = tostr(ii) + ". " + label + "|" + tostr(ii);
+               tomenu.add(MenuItem(MenuItem::Command, label, action), view);
+       }
+}
+
+
 } // namespace anon
 
 
@@ -669,6 +695,10 @@ void MenuBackend::expand(Menu const & fr
 
                case MenuItem::PasteRecent:
                        expandPasteRecent(tomenu, view);
+                       break;
+
+               case MenuItem::Branches:
+                       expandBranches(tomenu, view);
                        break;
 
                case MenuItem::Toc:

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to