This moves the generation of a few insets behind a common interface.
[The Plan is, of course, to have most/all of them there at some point of
time...]
Andre'
--
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.294
diff -u -p -r1.294 BufferView_pimpl.C
--- BufferView_pimpl.C 26 Aug 2002 13:25:47 -0000 1.294
+++ BufferView_pimpl.C 26 Aug 2002 15:19:34 -0000
@@ -41,6 +41,7 @@
#include "undo_funcs.h"
#include "funcrequest.h"
#include "language.h"
+#include "factory.h"
#include "insets/insetbib.h"
#include "insets/insettext.h"
@@ -50,22 +51,11 @@
#include "insets/insetref.h"
#include "insets/insetparent.h"
#include "insets/insetindex.h"
-#include "insets/insetnote.h"
#include "insets/insetinclude.h"
#include "insets/insetcite.h"
-#include "insets/insetert.h"
-#include "insets/insetexternal.h"
#include "insets/insetgraphics.h"
-#include "insets/insetfoot.h"
#include "insets/insetmarginal.h"
-#include "insets/insetminipage.h"
-#include "insets/insetfloat.h"
#include "insets/insettabular.h"
-#include "insets/insetoptarg.h"
-#if 0
-#include "insets/insettheorem.h"
-#include "insets/insetlist.h"
-#endif
#include "insets/insetcaption.h"
#include "insets/insetfloatlist.h"
@@ -1626,67 +1616,41 @@ bool BufferView::Pimpl::dispatch(FuncReq
}
break;
+#if 0
+ case LFUN_INSET_LIST:
+ case LFUN_INSET_THEOREM:
+#endif
+ case LFUN_INSERT_NOTE:
case LFUN_INSET_ERT:
- insertAndEditInset(new InsetERT(buffer_->params));
- break;
-
case LFUN_INSET_EXTERNAL:
- insertAndEditInset(new InsetExternal);
- break;
-
+ case LFUN_INSET_FLOAT:
case LFUN_INSET_FOOTNOTE:
- insertAndEditInset(new InsetFoot(buffer_->params));
- break;
-
case LFUN_INSET_MARGINAL:
- insertAndEditInset(new InsetMarginal(buffer_->params));
- break;
-
case LFUN_INSET_MINIPAGE:
- insertAndEditInset(new InsetMinipage(buffer_->params));
- break;
-
- case LFUN_INSERT_NOTE:
- insertAndEditInset(new InsetNote(buffer_->params));
- break;
-
case LFUN_INSET_OPTARG:
- insertAndEditInset(new InsetOptArg(buffer_->params));
- break;
-
- case LFUN_INSET_FLOAT:
- // check if the float type exist
- if (floatList.typeExist(ev.argument)) {
- insertAndEditInset(new InsetFloat(buffer_->params,
- ev.argument));
- } else {
- lyxerr << "Non-existent float type: "
- << ev.argument << endl;
- }
- break;
-
case LFUN_INSET_WIDE_FLOAT:
- // check if the float type exist
- if (floatList.typeExist(ev.argument)) {
- InsetFloat * new_inset =
- new InsetFloat(buffer_->params, ev.argument);
- new_inset->wide(true);
- insertAndEditInset(new_inset);
- } else {
- lyxerr << "Non-existent float type: "
- << ev.argument << endl;
- }
- break;
+ {
+ FuncRequest cmd = ev;
+ cmd.setView(bv_);
+ Inset * inset = createInset(cmd);
+ if (inset) {
+ bool gotsel = false;
-#if 0
- case LFUN_INSET_LIST:
- insertAndEditInset(new InsetList);
- break;
+ if (bv_->getLyXText()->selection.set()) {
+ bv_->getLyXText()->cutSelection(bv_, true, false);
+ gotsel = true;
+ }
- case LFUN_INSET_THEOREM:
- insertAndEditInset(new InsetTheorem);
+ if (insertInset(inset)) {
+ inset->edit(bv_);
+ if (gotsel)
+
+owner_->dispatch(FuncRequest(LFUN_PASTESELECTION));
+ }
+ else
+ delete inset;
+ }
break;
-#endif
+ }
case LFUN_INSET_CAPTION:
{
@@ -1991,32 +1955,6 @@ void BufferView::Pimpl::smartQuote()
pos).language()->lang() == "hebrew" ||
(!insertInset(new InsetQuotes(c, buffer_->params))))
bv_->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
-}
-
-
-void BufferView::Pimpl::insertAndEditInset(Inset * inset)
-{
-#if 0
- if (insertInset(inset))
- inset->edit(bv_);
- else
- delete inset;
-#else
- bool gotsel = false;
-
- if (bv_->getLyXText()->selection.set()) {
- bv_->getLyXText()->cutSelection(bv_, true, false);
- gotsel = true;
- }
-
- if (insertInset(inset)) {
- inset->edit(bv_);
- if (gotsel)
- owner_->dispatch(FuncRequest(LFUN_PASTESELECTION));
- }
- else
- delete inset;
-#endif
}
Index: BufferView_pimpl.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.h,v
retrieving revision 1.70
diff -u -p -r1.70 BufferView_pimpl.h
--- BufferView_pimpl.h 22 Aug 2002 13:02:14 -0000 1.70
+++ BufferView_pimpl.h 26 Aug 2002 15:19:34 -0000
@@ -145,8 +145,6 @@ private:
///
void smartQuote();
///
- void insertAndEditInset(Inset *);
- ///
void gotoInset(std::vector<Inset::Code> const & codes,
bool same_content);
///
Index: Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/Makefile.am,v
retrieving revision 1.146
diff -u -p -r1.146 Makefile.am
--- Makefile.am 20 Aug 2002 21:50:08 -0000 1.146
+++ Makefile.am 26 Aug 2002 15:19:34 -0000
@@ -117,6 +117,8 @@ lyx_SOURCES = \
exporter.h \
gettext.C \
gettext.h \
+ factory.h \
+ factory.C \
funcrequest.h \
funcrequest.C \
importer.C \
Index: factory.C
===================================================================
RCS file: factory.C
diff -N factory.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ factory.C 26 Aug 2002 15:19:34 -0000
@@ -0,0 +1,65 @@
+
+#include "funcrequest.h"
+#include "bufferparams.h"
+#include "buffer.h"
+#include "FloatList.h"
+#include "debug.h"
+#include "BufferView.h"
+#include "insets/insetert.h"
+#include "insets/insetexternal.h"
+#include "insets/insetfloat.h"
+#include "insets/insetfoot.h"
+#include "insets/insetmarginal.h"
+#include "insets/insetminipage.h"
+#include "insets/insetnote.h"
+#include "insets/insetoptarg.h"
+#include "insets/insetparent.h"
+#include "insets/insetref.h"
+#include "insets/insettext.h"
+
+
+Inset * createInset(FuncRequest const & cmd)
+{
+ BufferParams const & params = cmd.view()->buffer()->params;
+ switch (cmd.action) {
+ case LFUN_INSET_MINIPAGE:
+ return new InsetMinipage(params);
+ case LFUN_INSERT_NOTE:
+ return new InsetNote(params);
+ case LFUN_INSET_ERT:
+ return new InsetERT(params);
+ case LFUN_INSET_EXTERNAL:
+ return new InsetExternal;
+ case LFUN_INSET_FOOTNOTE:
+ return new InsetFoot(params);
+ case LFUN_INSET_MARGINAL:
+ return new InsetMarginal(params);
+ case LFUN_INSET_OPTARG:
+ return new InsetOptArg(params);
+ case LFUN_INSET_FLOAT:
+ // check if the float type exist
+ if (floatList.typeExist(cmd.argument))
+ return new InsetFloat(params, cmd.argument);
+ lyxerr << "Non-existent float type: " << cmd.argument << endl;
+ return 0;
+ case LFUN_INSET_WIDE_FLOAT:
+ // check if the float type exist
+ if (floatList.typeExist(cmd.argument)) {
+ InsetFloat * p = new InsetFloat(params, cmd.argument);
+ p->wide(true);
+ }
+ lyxerr << "Non-existent float type: " << cmd.argument << endl;
+ return 0;
+#if 0
+ case LFUN_INSET_LIST:
+ return new InsetList;
+ case LFUN_INSET_THEOREM:
+ return new InsetTheorem;
+#endif
+ default:
+ break;
+ }
+ return 0;
+}
+
+
Index: factory.h
===================================================================
RCS file: factory.h
diff -N factory.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ factory.h 26 Aug 2002 15:19:34 -0000
@@ -0,0 +1,21 @@
+// -*- C++ -*-
+/* This file is part of
+ * ======================================================
+ *
+ * LyX, The Document Processor
+ *
+ * Copyright 2002 The LyX Team.
+ *
+ * ====================================================== */
+
+#ifndef FACTORY_H
+#define FACTORY_H
+
+class Inset;
+class FuncRequest;
+
+/// creates inset according to 'cmd'
+Inset * createInset(FuncRequest const & cmd);
+
+#endif
+