I have a proof of principle and working implementation of my plan to clean 
up the controllers. Needless to say it's implemented for my favourite 
citation inset and is a little clunky still. However, I'm suffering 
primarily from a lack of imagination: what to call the LFUNs!

I'm edging towards LFUN_CITATION_SHOW and LFUN_CITATION_APPLY as a first 
step towards the most general LFUN_DIALOG_SHOW and LFUN_DIALOG_APPLY. Do 
these names sound reasonable or does anybody have a better idea?

Angus


Index: src/BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.323
diff -u -p -r1.323 BufferView_pimpl.C
--- src/BufferView_pimpl.C      8 Feb 2003 19:17:42 -0000       1.323
+++ src/BufferView_pimpl.C      12 Feb 2003 22:35:24 -0000
@@ -27,6 +27,7 @@
 #include "frontends/LyXView.h"
 #include "commandtags.h"
 #include "lyxfunc.h"
+#include "lyxlex.h"
 #include "debug.h"
 #include "bufferview_funcs.h"
 #include "TextCache.h"
@@ -1188,19 +1189,28 @@ bool BufferView::Pimpl::dispatch(FuncReq
                mathDispatch(FuncRequest(bv_, ev.action, ev.argument));
                break;
 
-       case LFUN_CITATION_INSERT:
+       case LFUN_CITATION_APPLY:
        {
-               InsetCommandParams p;
-               p.setFromString(ev.argument);
-
-               InsetCitation * inset = new InsetCitation(p);
-               if (!insertInset(inset))
-                       delete inset;
-               else {
-                       inset->setLoadingBuffer(bv_->buffer(), false);
-                       updateInset(inset, true);
+               stringstream data(ev.argument);
+               LyXLex lex(0,0);
+               lex.setStream(data);
+               InsetCommandParams params;
+               params.read(lex);
+
+               Inset * base = owner_->getDialogs().getOpenDialog("citation");
+               InsetCitation * inset = static_cast<InsetCitation *>(base);
+               if (inset) {
+                       inset->setParams(params);
+               } else {
+                       inset = new InsetCitation(params);
+                       if (!insertInset(inset)) {
+                               delete inset;
+                               break;
+                       } else {
+                               inset->setLoadingBuffer(bv_->buffer(), false);
+                       }
                }
-
+               updateInset(inset, true);
        }
        break;
 
Index: src/LyXAction.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LyXAction.C,v
retrieving revision 1.145
diff -u -p -r1.145 LyXAction.C
--- src/LyXAction.C     8 Feb 2003 19:17:43 -0000       1.145
+++ src/LyXAction.C     12 Feb 2003 22:35:25 -0000
@@ -155,9 +155,9 @@ void LyXAction::init()
                  ReadOnly },
                { LFUN_RIGHT, "char-forward", N_("Go one char forward"),
                  ReadOnly },
-               { LFUN_CITATION_CREATE, "citation-insert",
+               { LFUN_CITATION_SHOW, "citation-insert",
                  N_("Insert citation"), Noop },
-               { LFUN_CITATION_INSERT, "", "internal only", Noop },
+               { LFUN_CITATION_APPLY, "", "internal only", Noop },
                { LFUN_EXEC_COMMAND, "command-execute", "", NoBuffer },
                { LFUN_PREFIX, "command-prefix",
                  N_("Execute command"), NoBuffer },
Index: src/commandtags.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/commandtags.h,v
retrieving revision 1.105
diff -u -p -r1.105 commandtags.h
--- src/commandtags.h   8 Feb 2003 19:17:44 -0000       1.105
+++ src/commandtags.h   12 Feb 2003 22:35:26 -0000
@@ -190,7 +190,6 @@ enum kb_action {
        LFUN_MENUNEWTMPLT,              // Asger 1997-02-02
        LFUN_MENURELOAD,                // Asger 1997-02-02
        LFUN_RECONFIGURE, // 170        // Asger 1997-02-14
-       LFUN_CITATION_INSERT,           // AAS 97-02-23
        LFUN_INSERT_BIBTEX,             // AAS 97-02-23
        LFUN_INDEX_PRINT,               // Lgb 97-02-27
        LFUN_APROPOS,                   // Asger 1997-02-27
@@ -258,7 +257,6 @@ enum kb_action {
        LFUN_INSET_LIST,                // Lgb 20000627
        LFUN_INSET_THEOREM,             // Lgb 20000630
 #endif
-       LFUN_CITATION_CREATE, // 240    // Angus 20000705
        LFUN_INSET_CAPTION,             // Lgb 20000718
        LFUN_SWITCHBUFFER,  // and where is this coming from?
        LFUN_INSERT_URL,                // Angus 20000726
@@ -296,6 +294,8 @@ enum kb_action {
        LFUN_REJECT_CHANGE,             // Levon 20021016
        LFUN_ACCEPT_ALL_CHANGES,        // Levon 20021016
        LFUN_REJECT_ALL_CHANGES,        // Levon 20021016
+       LFUN_CITATION_APPLY,
+       LFUN_CITATION_SHOW,
        LFUN_LASTACTION  /* this marks the end of the table */
 };
 
Index: src/lyxfunc.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfunc.C,v
retrieving revision 1.395
diff -u -p -r1.395 lyxfunc.C
--- src/lyxfunc.C       8 Feb 2003 19:17:44 -0000       1.395
+++ src/lyxfunc.C       12 Feb 2003 22:35:27 -0000
@@ -560,8 +560,8 @@ FuncStatus LyXFunc::getStatus(FuncReques
        case LFUN_REF_INSERT:
                code = Inset::REF_CODE;
                break;
-       case LFUN_CITATION_CREATE:
-       case LFUN_CITATION_INSERT:
+       case LFUN_CITATION_APPLY:
+       case LFUN_CITATION_SHOW:
                code = Inset::CITE_CODE;
                break;
        case LFUN_INSERT_BIBTEX:
@@ -1378,7 +1378,7 @@ void LyXFunc::dispatch(FuncRequest const
                owner->getDialogs().showMathPanel();
                break;
 
-       case LFUN_CITATION_CREATE:
+       case LFUN_CITATION_SHOW:
        {
                InsetCommandParams p("cite");
 
@@ -1393,9 +1393,15 @@ void LyXFunc::dispatch(FuncRequest const
                        } else {
                                p.setContents(argument);
                        }
-                       dispatch(FuncRequest(view(), LFUN_CITATION_INSERT, 
p.getAsString()));
-               } else
-                       owner->getDialogs().createCitation(p.getAsString());
+                       stringstream data;
+                       p.write(data);
+                       dispatch(FuncRequest(view(), LFUN_CITATION_APPLY,
+                                            data.str()));
+               } else {
+                       stringstream data;
+                       p.write(data);
+                       owner->getDialogs().show("citation", data, 0);
+               }
        }
        break;
 

-- 
Angus

Reply via email to