]> git.lyx.org Git - features.git/blobdiff - src/lyxfunc.C
Replace LString.h with support/std_string.h,
[features.git] / src / lyxfunc.C
index 1669ff81bc6d9d54e45e6eb58de719e73b57baf5..1f6b7c98cf5372aef16088924fae5c001a2ef2f2 100644 (file)
@@ -1,41 +1,42 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file lyxfunc.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Alfredo Braunstein
+ * \author Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
+ * \author Angus Leeming
+ * \author John Levon
+ * \author André Pönitz
+ * \author Allan Rae
+ * \author Dekel Tsur
+ * \author Martin Vermeer
+ * \author Jürgen Vigna
  *
- *         Copyright 1995 Matthias Ettrich
- *          Copyright 1995-2001 The LyX Team.
- *
- * ====================================================== */
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
 #include "lyxfunc.h"
-#include "version.h"
 #include "kbmap.h"
-#include "lyxrow.h"
 #include "bufferlist.h"
 #include "buffer.h"
 #include "buffer_funcs.h"
 #include "BufferView.h"
+#include "funcrequest.h"
+#include "iterators.h"
 #include "lyxserver.h"
 #include "intl.h"
-#include "lyx_main.h"
 #include "lyx_cb.h"
 #include "LyXAction.h"
 #include "debug.h"
-#include "lyxrc.h"
-#include "lyxtext.h"
 #include "gettext.h"
-#include "Lsstream.h"
-#include "trans_mgr.h"
+#include "support/std_sstream.h"
 #include "encoding.h"
-#include "layout.h"
-#include "bufferview_funcs.h"
 #include "frontends/LyXView.h"
 #include "frontends/lyx_gui.h"
-#include "vspace.h"
-#include "FloatList.h"
 #include "format.h"
 #include "exporter.h"
 #include "importer.h"
@@ -48,9 +49,7 @@
 #include "insets/insetexternal.h"
 #include "insets/insettabular.h"
 
-#include "mathed/formulamacro.h"
 #include "mathed/math_cursor.h"
-#include "mathed/math_inset.h"
 
 #include "frontends/FileDialog.h"
 #include "frontends/Dialogs.h"
 #include "frontends/Menubar.h"
 #include "frontends/Alert.h"
 
-#include "graphics/GraphicsCache.h"
 
-#include "support/lyxalgo.h"
 #include "support/LAssert.h"
 #include "support/filetools.h"
 #include "support/FileInfo.h"
 #include "support/forkedcontr.h"
-#include "support/lstrings.h"
 #include "support/tostr.h"
 #include "support/path.h"
 #include "support/path_defines.h"
-#include "support/lyxfunctional.h"
 
-#include <ctime>
-#include <clocale>
-#include <cstdlib>
-#include <cctype>
 
-#include <utility>
-#include <algorithm>
 
 using namespace lyx::support;
 
@@ -115,12 +104,9 @@ LyXFunc::LyXFunc(LyXView * o)
 void LyXFunc::moveCursorUpdate()
 {
        LyXText * lt = view()->text;
-       if (lt->selection.mark()) {
+       if (lt->selection.mark())
                lt->setSelection();
-               if (!lt->isInInset())
-                   view()->repaint();
-       }
-       view()->update(lt, BufferView::SELECT);
+       view()->update();
        view()->switchKeyMap();
 }
 
@@ -139,7 +125,7 @@ void LyXFunc::handleKeyFunc(kb_action action)
        // actions
        keyseq.clear();
        // copied verbatim from do_accent_char
-       view()->update(view()->getLyXText(), BufferView::SELECT);
+       view()->update();
        view()->getLyXText()->selection.cursor = view()->getLyXText()->cursor;
 }
 
@@ -314,7 +300,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        switch (ev.action) {
        case LFUN_EXPORT:
                disable = ev.argument != "custom"
-                       && !Exporter::IsExportable(buf, ev.argument);
+                       && !Exporter::IsExportable(*buf, ev.argument);
                break;
        case LFUN_UNDO:
                disable = buf->undostack.empty();
@@ -340,7 +326,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                disable = !buf->isLatex() || lyxrc.chktex_command == "none";
                break;
        case LFUN_BUILDPROG:
-               disable = !Exporter::IsExportable(buf, "program");
+               disable = !Exporter::IsExportable(*buf, "program");
                break;
 
        case LFUN_LAYOUT_TABULAR:
@@ -509,6 +495,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                        case InsetOld::NOTE_CODE:
                                disable = ev.argument != "note";
                                break;
+                       case InsetOld::BRANCH_CODE:
+                               disable = ev.argument != "branch";
+                               break;
                        default:
                                break;
                }
@@ -545,7 +534,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                }
 
                if (name == "print") {
-                       disable = !Exporter::IsExportable(buf, "dvi") ||
+                       disable = !Exporter::IsExportable(*buf, "dvi") ||
                                lyxrc.print_command == "none";
                } else if (name == "character") {
                        UpdatableInset * tli = view()->theLockingInset();
@@ -637,6 +626,11 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
        case LFUN_INSERT_NOTE:
                code = InsetOld::NOTE_CODE;
                break;
+       case LFUN_INSERT_BRANCH:
+               code = InsetOld::BRANCH_CODE;
+               if (buf->params.branchlist.empty())
+                       disable = true;
+               break;
        case LFUN_INSERT_LABEL:
                code = InsetOld::LABEL_CODE;
                break;
@@ -676,6 +670,20 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
                if (!mathcursor)
                        code = InsetOld::SPACE_CODE;
                break;
+       case LFUN_INSET_DIALOG_SHOW: {
+                       LyXText * lt = view()->getLyXText();
+                       InsetOld * inset = lt->getInset();
+                       disable = !inset;
+                       if (!disable) {
+                               code = inset->lyxCode();
+                               if (!(code == InsetOld::INCLUDE_CODE 
+                                       || code == InsetOld::BIBTEX_CODE 
+                                       || code == InsetOld::FLOAT_LIST_CODE 
+                                       || code == InsetOld::TOC_CODE))
+                                       disable = true;
+                       }
+               }
+               break;
        default:
                break;
        }
@@ -906,11 +914,11 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                                goto exit_with_message;
                        } else if (result == FINISHED_UP) {
                                RowList::iterator const irow = view()->text->cursorIRow();
-                               if (irow != view()->text->rows().begin()) {
+                               if (irow != view()->text->firstRow()) {
 #if 1
                                        view()->text->setCursorFromCoordinates(
-                                               view()->text->cursor.ix() + inset_x,
-                                               view()->text->cursor.iy() -
+                                               view()->text->cursor.x() + inset_x,
+                                               view()->text->cursor.y() -
                                                irow->baseline() - 1);
                                        view()->text->cursor.x_fix(view()->text->cursor.x());
 #else
@@ -918,17 +926,17 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
 #endif
                                        moveCursorUpdate();
                                } else {
-                                       view()->update(view()->text, BufferView::SELECT);
+                                       view()->update();
                                }
                                owner->clearMessage();
                                goto exit_with_message;
                        } else if (result == FINISHED_DOWN) {
                                RowList::iterator const irow = view()->text->cursorIRow();
-                               if (boost::next(irow) != view()->text->rows().end()) {
+                               if (irow != view()->text->lastRow()) {
 #if 1
                                        view()->text->setCursorFromCoordinates(
-                                               view()->text->cursor.ix() + inset_x,
-                                               view()->text->cursor.iy() -
+                                               view()->text->cursor.x() + inset_x,
+                                               view()->text->cursor.y() -
                                                irow->baseline() +
                                                irow->height() + 1);
                                        view()->text->cursor.x_fix(view()->text->cursor.x());
@@ -968,7 +976,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                                        }
                                        goto exit_with_message;
                                case LFUN_DOWN:
-                                       if (boost::next(view()->text->cursorRow()) != view()->text->rows().end())
+                                       if (view()->text->cursorRow() != view()->text->lastRow())
                                                view()->text->cursorDown(view());
                                        else
                                                view()->text->cursorRight(view());
@@ -1026,7 +1034,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
 
        case LFUN_PREFIX:
                if (view()->available() && !view()->theLockingInset())
-                       view()->update(view()->text, BufferView::SELECT);
+                       view()->update();
                owner->message(keyseq.printOptions());
                break;
 
@@ -1447,6 +1455,16 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
        }
        break;
 
+       case LFUN_INSET_DIALOG_SHOW: {
+               LyXText * lt = view()->getLyXText();
+               InsetOld * inset = lt->getInset();
+               if (inset) {
+                       FuncRequest cmd(view(), LFUN_INSET_DIALOG_SHOW);
+                       inset->localDispatch(cmd);
+               }
+       }
+       break;                                                   
+       
        case LFUN_DIALOG_UPDATE: {
                string const & name = argument;
                // Can only update a dialog connected to an existing inset
@@ -1535,7 +1553,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                // if values really changed...but not very important right now. (Lgb)
                // All visible buffers will need resize
                view()->resize();
-               view()->repaint();
+               view()->update();
        }
        break;
 
@@ -1574,7 +1592,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
 #endif
                }
 
-               view()->repaint();
+               view()->update();
                break;
        }
 
@@ -1618,10 +1636,15 @@ exit_with_message:
        view()->owner()->updateLayoutChoice();
 
        if (view()->available()) {
-               view()->fitCursor();
+               if (view()->fitCursor()) {
+                       lyxerr << "LyXFunc->fitCursor->update" << endl;
+
+                       view()->update();
+               }
 
                // If we executed a mutating lfun, mark the buffer as dirty
-               if (!lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)
+               if (!getStatus(ev).disabled()
+                   && !lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)
                    && !lyxaction.funcHasFlag(ev.action, LyXAction::ReadOnly))
                        view()->buffer()->markDirty();
        }
@@ -1964,4 +1987,3 @@ bool LyXFunc::wasMetaKey() const
 {
        return (meta_fake_bit != key_modifier::none);
 }
-