]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
Compilation fix
[lyx.git] / src / lyxfunc.C
index 1e55b9f504b93daebe18cc8058d4f673f2096e76..f14984b7f1c134715f3d5c54a4632b1a0a13b1d3 100644 (file)
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "lyxfunc.h"
 #include "version.h"
 #include "kbmap.h"
@@ -38,7 +34,7 @@
 #include "frontends/lyx_gui.h"
 #include "vspace.h"
 #include "FloatList.h"
-#include "converter.h"
+#include "format.h"
 #include "exporter.h"
 #include "importer.h"
 #include "TextCache.h"
@@ -47,6 +43,8 @@
 #include "ParagraphParameters.h"
 
 #include "insets/insetcommand.h"
+#include "insets/inseterror.h"
+#include "insets/insetert.h"
 #include "insets/insettabular.h"
 
 #include "mathed/formulamacro.h"
@@ -124,7 +122,7 @@ void LyXFunc::moveCursorUpdate(bool flag, bool selecting)
 {
        if (selecting || TEXT(flag)->selection.mark()) {
                TEXT(flag)->setSelection(view());
-               if (TEXT(flag)->bv_owner)
+               if (TEXT(flag)->isTopLevel())
                    view()->toggleToggle();
        }
        view()->update(TEXT(flag), BufferView::SELECT|BufferView::FITCUR);
@@ -221,7 +219,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym,
                owner->message(keyseq.print());
        }
 
+
        // Maybe user can only reach the key via holding down shift.
        // Let's see. But only if shift is the only modifier
        if (action == LFUN_UNKNOWN_ACTION && state == key_modifier::shift) {
@@ -229,7 +227,7 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym,
                action = keyseq.addkey(keysym, key_modifier::none);
                lyxerr[Debug::KEY] << "Action now " << action << endl;
        }
+
        if (action == LFUN_UNKNOWN_ACTION) {
                // Hmm, we didn't match any of the keysequences. See
                // if it's normal insertable text not already covered
@@ -286,7 +284,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        default:
                flag |= lyx_gui::getStatus(ev);
        }
-       
+
        if (flag.unknown()) {
                setStatusMessage(N_("Unknown action"));
                return flag;
@@ -327,8 +325,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                        || lyxrc.print_command == "none";
                break;
        case LFUN_EXPORT:
-               disable = ev.argument == "fax" &&
-                       !Exporter::IsExportable(buf, ev.argument);
+               disable = ev.argument != "custom"
+                       && !Exporter::IsExportable(buf, ev.argument);
                break;
        case LFUN_UNDO:
                disable = buf->undostack.empty();
@@ -338,9 +336,12 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                break;
        case LFUN_CUT:
        case LFUN_COPY:
-               if (tli && tli->lyxCode() == Inset::TABULAR_CODE) {
-                       InsetTabular * t(static_cast<InsetTabular*>(tli));
-                       if (t->hasSelection()) {
+               if (tli) {
+                       UpdatableInset * in = tli;
+                       if (in->lyxCode() != Inset::TABULAR_CODE) {
+                               in = tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE);
+                       }
+                       if (in && static_cast<InsetTabular*>(in)->hasSelection()) {
                                disable = false;
                                break;
                        }
@@ -455,10 +456,20 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        case LFUN_VC_HISTORY:
                disable = !buf->lyxvc.inUse();
                break;
+       case LFUN_MENURELOAD:
+               disable = buf->isUnnamed() || buf->isClean();
+               break;
        case LFUN_BOOKMARK_GOTO:
                disable =  !view()->
                        isSavedPosition(strToUnsignedInt(ev.argument));
                break;
+       case LFUN_MERGE_CHANGES:
+       case LFUN_ACCEPT_CHANGE:
+       case LFUN_REJECT_CHANGE:
+       case LFUN_ACCEPT_ALL_CHANGES:
+       case LFUN_REJECT_ALL_CHANGES:
+               disable = !buf->params.tracking_changes;
+               break;
        case LFUN_INSET_TOGGLE: {
                LyXText * lt = view()->getLyXText();
                disable = !(isEditableInset(lt->getInset())
@@ -550,13 +561,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        case LFUN_REF_INSERT:
                code = Inset::REF_CODE;
                break;
-       case LFUN_CITATION_CREATE:
-       case LFUN_CITATION_INSERT:
-               code = Inset::CITE_CODE;
-               break;
-       case LFUN_INSERT_BIBTEX:
-               code = Inset::BIBTEX_CODE;
-               break;
        case LFUN_INDEX_INSERT:
                code = Inset::INDEX_CODE;
                break;
@@ -621,6 +625,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                if (ev.argument == buf->fileName())
                        flag.setOnOff(true);
                break;
+       case LFUN_TRACK_CHANGES:
+               flag.setOnOff(buf->params.tracking_changes);
+               break;
        default:
                break;
        }
@@ -777,21 +784,21 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                        } else if (((result=inset->
                                     // Hand-over to inset's own dispatch:
                                     localDispatch(FuncRequest(view(), action, argument))) ==
-                                   UpdatableInset::DISPATCHED) ||
-                                  (result == UpdatableInset::DISPATCHED_NOUPDATE))
+                                   DISPATCHED) ||
+                                  (result == DISPATCHED_NOUPDATE))
                                goto exit_with_message;
                                        // If UNDISPATCHED, just soldier on
-                       else if (result == UpdatableInset::FINISHED) {
+                       else if (result == FINISHED) {
                                goto exit_with_message;
                                // We do not need special RTL handling here:
                                // FINISHED means that the cursor should be
                                // one position after the inset.
-                       } else if (result == UpdatableInset::FINISHED_RIGHT) {
+                       } else if (result == FINISHED_RIGHT) {
                                TEXT()->cursorRight(view());
                                moveCursorUpdate(true, false);
                                owner->view_state_changed();
                                goto exit_with_message;
-                       } else if (result == UpdatableInset::FINISHED_UP) {
+                       } else if (result == FINISHED_UP) {
                                if (TEXT()->cursor.irow()->previous()) {
 #if 1
                                        TEXT()->setCursorFromCoordinates(
@@ -808,7 +815,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                                        view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
                                }
                                goto exit_with_message;
-                       } else if (result == UpdatableInset::FINISHED_DOWN) {
+                       } else if (result == FINISHED_DOWN) {
                                if (TEXT()->cursor.irow()->next()) {
 #if 1
                                        TEXT()->setCursorFromCoordinates(
@@ -1035,27 +1042,10 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                break;
 
        case LFUN_TOCVIEW:
-#if 0
-       case LFUN_LOFVIEW:
-       case LFUN_LOTVIEW:
-       case LFUN_LOAVIEW:
-#endif
        {
-               InsetCommandParams p;
-
-#if 0
-               if (action == LFUN_TOCVIEW)
-#endif
-                       p.setCmdName("tableofcontents");
-#if 0
-               else if (action == LFUN_LOAVIEW)
-                       p.setCmdName("listof{algorithm}{List of Algorithms}");
-               else if (action == LFUN_LOFVIEW)
-                       p.setCmdName("listoffigures");
-               else
-                       p.setCmdName("listoftables");
-#endif
-               owner->getDialogs().createTOC(p.getAsString());
+               InsetCommandParams p("tableofcontents");
+               string const data = InsetCommandMailer::params2string("toc", p);
+               owner->getDialogs().show("toc", data, 0);
                break;
        }
 
@@ -1130,12 +1120,10 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                        setErrorMessage(N_("Missing argument"));
                        break;
                }
-               owner->prohibitInput();
                string const fname = i18nLibFileSearch("doc", arg, "lyx");
                if (fname.empty()) {
                        lyxerr << "LyX: unable to find documentation file `"
                               << arg << "'. Bad installation?" << endl;
-                       owner->allowInput();
                        break;
                }
                ostringstream str;
@@ -1148,7 +1136,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
 #endif
                owner->message(STRCONV(str.str()));
                view()->buffer(bufferlist.loadLyXFile(fname, false));
-               owner->allowInput();
                break;
        }
 
@@ -1365,27 +1352,80 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                owner->getDialogs().showMathPanel();
                break;
 
-       case LFUN_CITATION_CREATE:
-       {
-               InsetCommandParams p("cite");
+       case LFUN_DIALOG_SHOW_NEW_INSET: {
+               string const & name = argument;
+               string data;
+               if (name == "bibitem" ||
+                   name == "bibtex" ||
+                   name == "index" ||
+                   name == "ref" ||
+                   name == "toc" ||
+                   name == "url") {
+                       InsetCommandParams p(name);
+                       data = InsetCommandMailer::params2string(name, p);
+               } else if (name == "citation") {
+                       InsetCommandParams p("cite");
+                       data = InsetCommandMailer::params2string(name, p);
+               } else if (name == "ert") {
+                       data = InsetERTMailer::params2string(name,
+                                                            InsetERT::Open);
+               }
+                owner->getDialogs().show(name, data, 0);
+       }
+       break;
 
-               if (!argument.empty()) {
-                       // This should be set at source, ie when typing
-                       // "citation-insert foo" in the minibuffer.
-                       // Question: would pybibliographer also need to be
-                       // changed. Suspect so. Leave as-is therefore.
-                       if (contains(argument, "|")) {
-                               p.setContents(token(argument, '|', 0));
-                               p.setOptions(token(argument, '|', 1));
-                       } else {
-                               p.setContents(argument);
-                       }
-                       dispatch(FuncRequest(view(), LFUN_CITATION_INSERT, p.getAsString()));
-               } else
-                       owner->getDialogs().createCitation(p.getAsString());
+       case LFUN_DIALOG_SHOW_NEXT_INSET: {
        }
        break;
 
+       case LFUN_DIALOG_UPDATE: {
+               string const & name = argument;
+               // Can only update a dialog connected to an existing inset
+               InsetBase * i = owner->getDialogs().getOpenInset(name);
+               if (!i)
+                       break;
+
+               if (name == "bibitem" ||
+                   name == "bibtex" ||
+                   name == "citation" ||
+                   name == "index" ||
+                   name == "ref" ||
+                   name == "toc" ||
+                   name == "url") {
+                       InsetCommand * inset = dynamic_cast<InsetCommand *>(i);
+                       if (!inset)
+                               break;
+
+                       InsetCommandMailer mailer(name, *inset);
+                       mailer.updateDialog();
+
+               } else if (name == "error") {
+                       InsetError * inset = dynamic_cast<InsetError *>(i);
+                       if (!inset)
+                               break;
+
+                       owner->getDialogs().update("error",
+                                                  inset->getContents());
+
+               } else if (name == "ert") {
+                       InsetERT * inset = dynamic_cast<InsetERT *>(i);
+                       if (!inset)
+                               break;
+
+                       InsetERTMailer mailer(*inset);
+                       mailer.updateDialog();
+               }
+       }
+       break;
+
+       case LFUN_DIALOG_HIDE:
+               owner ->getDialogs().hide(argument);
+               break;
+
+       case LFUN_DIALOG_DISCONNECT_INSET:
+                owner->getDialogs().disconnect(argument);
+               break;
+
        case LFUN_CHILDOPEN:
        {
                string const filename =
@@ -1635,7 +1675,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
        // The template stuff
        string templname;
        if (fromTemplate) {
-               FileDialog fileDlg(owner, _("Select template file"),
+               FileDialog fileDlg(_("Select template file"),
                        LFUN_SELECT_FILE_SYNC,
                        make_pair(string(_("Documents|#o#O")),
                                  string(lyxrc.document_path)),
@@ -1644,7 +1684,7 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
 
                FileDialog::Result result =
                        fileDlg.open(lyxrc.template_path,
-                                      _("*.lyx|LyX Documents (*.lyx)"));
+                                      _("*.lyx| LyX Documents (*.lyx)"));
 
                if (result.first == FileDialog::Later)
                        return;
@@ -1674,7 +1714,7 @@ void LyXFunc::open(string const & fname)
        string filename;
 
        if (fname.empty()) {
-               FileDialog fileDlg(owner, _("Select document to open"),
+               FileDialog fileDlg(_("Select document to open"),
                        LFUN_FILE_OPEN,
                        make_pair(string(_("Documents|#o#O")),
                                  string(lyxrc.document_path)),
@@ -1683,7 +1723,7 @@ void LyXFunc::open(string const & fname)
 
                FileDialog::Result result =
                        fileDlg.open(initpath,
-                                      "*.lyx|LyX Documents (*.lyx)");
+                                      _("*.lyx| LyX Documents (*.lyx)"));
 
                if (result.first == FileDialog::Later)
                        return;
@@ -1779,7 +1819,7 @@ void LyXFunc::doImport(string const & argument)
                        + _(" file to import");;
 #endif
 
-               FileDialog fileDlg(owner, text,
+               FileDialog fileDlg(text,
                        LFUN_IMPORT,
                        make_pair(string(_("Documents|#o#O")),
                                  string(lyxrc.document_path)),