]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
Move init() back to LyXView
[lyx.git] / src / lyxfunc.C
index 63afaf34d77d18ec8c7e67a96d8aec49e45feb1d..26a1b6aae34ee20166b5e8bd1e6852d7bdbe276f 100644 (file)
@@ -20,7 +20,7 @@
 #include "lyxrow.h"
 #include "bufferlist.h"
 #include "BufferView.h"
-#include "ColorHandler.h"
+#include "frontends/xforms/ColorHandler.h"
 #include "lyxserver.h"
 #include "intl.h"
 #include "lyx_main.h"
 #include "bufferview_funcs.h"
 #include "minibuffer.h"
 #include "vspace.h"
-#include "LyXView.h"
+#include "frontends/LyXView.h"
 #include "FloatList.h"
 #include "converter.h"
 #include "exporter.h"
 #include "importer.h"
-#include "FontLoader.h"
+#include "frontends/font_loader.h"
 #include "TextCache.h"
 #include "lyxfind.h"
 #include "undo_funcs.h"
@@ -165,7 +165,7 @@ LyXFunc::LyXFunc(LyXView * o)
        keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
        cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get())
 {
-       meta_fake_bit = 0;
+       meta_fake_bit = key_modifier::none;
        lyx_dead_action = LFUN_NOACTION;
        lyx_calling_dead_action = LFUN_NOACTION;
 }
@@ -222,7 +222,7 @@ void LyXFunc::handleKeyFunc(kb_action action)
 }
 
 
-void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
+void LyXFunc::processKeySym(KeySym keysym, key_modifier::state state)
 {
        string argument;
 
@@ -232,8 +232,7 @@ void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
                lyxerr << "KeySym is "
                       << stm
                       << "["
-                      << keysym << "] State is ["
-                      << state << "]"
+                      << keysym
                       << endl;
        }
        // Do nothing if we have nothing (JMarc)
@@ -256,33 +255,30 @@ void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
        // cancel and meta-fake keys. RVDK_PATCH_5
        cancel_meta_seq.reset();
 
-       int action = cancel_meta_seq.addkey(keysym, state
-                                           &(ShiftMask|ControlMask
-                                             |Mod1Mask));
+       int action = cancel_meta_seq.addkey(keysym, state);
        if (lyxerr.debugging(Debug::KEY)) {
                lyxerr << "action first set to [" << action << "]" << endl;
        }
 
        // When not cancel or meta-fake, do the normal lookup.
        // Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
-       // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
+       // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
        if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
+#if 0
                if (lyxerr.debugging(Debug::KEY)) {
                        lyxerr << "meta_fake_bit is ["
                               << meta_fake_bit << "]" << endl;
                }
+#endif
                // remove Caps Lock and Mod2 as a modifiers
-               action = keyseq.addkey(keysym,
-                                      (state | meta_fake_bit)
-                                      &(ShiftMask|ControlMask
-                                        |Mod1Mask));
+               action = keyseq.addkey(keysym, (state | meta_fake_bit));
                if (lyxerr.debugging(Debug::KEY)) {
                        lyxerr << "action now set to ["
                               << action << "]" << endl;
                }
        }
        // Dont remove this unless you know what you are doing.
-       meta_fake_bit = 0;
+       meta_fake_bit = key_modifier::none;
 
        // can this happen now ?
        if (action == LFUN_NOACTION) {
@@ -307,7 +303,7 @@ void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
        if (action == LFUN_UNKNOWN_ACTION) {
                // It is unknown, but what if we remove all
                // the modifiers? (Lgb)
-               action = keyseq.addkey(keysym, 0);
+               action = keyseq.addkey(keysym, key_modifier::none);
 
                if (lyxerr.debugging(Debug::KEY)) {
                        lyxerr << "Removing modifiers...\n"
@@ -491,7 +487,7 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                break;
        }
        case LFUN_MATH_VALIGN:
-               if (mathcursor) {
+               if (mathcursor && mathcursor->formula()->getType() != LM_OT_SIMPLE) {
                        char align = mathcursor->valign();
                        if (align == '\0') {
                                disable = true;
@@ -511,7 +507,7 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                break;
 
        case LFUN_MATH_HALIGN:
-               if (mathcursor) {
+               if (mathcursor && mathcursor->formula()->getType() != LM_OT_SIMPLE) {
                        char align = mathcursor->halign();
                        if (align == '\0') {
                                disable = true;
@@ -541,6 +537,8 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                                flag.setOnOff(type == LM_OT_EQNARRAY);
                        } else if (argument == "align") {
                                flag.setOnOff(type == LM_OT_ALIGN);
+                       } else if (argument == "none") {
+                               flag.setOnOff(type == LM_OT_NONE);
                        } else {
                                disable = true;
                        }
@@ -563,7 +561,8 @@ FuncStatus LyXFunc::getStatus(kb_action action,
        case LFUN_MATH_ROW_DELETE:
        case LFUN_MATH_COLUMN_INSERT:
        case LFUN_MATH_COLUMN_DELETE:
-               disable = !mathcursor || !mathcursor->halign();
+               disable = !mathcursor || !mathcursor->halign() ||
+                       mathcursor->formula()->getType() == LM_OT_SIMPLE;
                break;
 
        default:
@@ -661,9 +660,13 @@ FuncStatus LyXFunc::getStatus(kb_action action,
        case LFUN_MENU_SEPARATOR:
        case LFUN_LDOTS:
        case LFUN_END_OF_SENTENCE:
-       case LFUN_PROTECTEDSPACE:
                code = Inset::SPECIALCHAR_CODE;
                break;
+       case LFUN_PROTECTEDSPACE:
+               // slight hack: we know this is allowed in math mode
+               if (!mathcursor)
+                       code = Inset::SPECIALCHAR_CODE;
+               break;
        default:
                break;
        }
@@ -723,28 +726,28 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                }
        }
        else {
-               MathTextCodes tc = mathcursor->getLastCode();
+               string tc = mathcursor->getLastCode();
                switch (action) {
                case LFUN_BOLD:
-                       flag.setOnOff(tc == LM_TC_BF);
+                       flag.setOnOff(tc == "mathbf");
                        break;
                case LFUN_SANS:
-                       flag.setOnOff(tc == LM_TC_SF);
+                       flag.setOnOff(tc == "mathsf");
                        break;
                case LFUN_EMPH:
-                       flag.setOnOff(tc == LM_TC_CAL);
+                       flag.setOnOff(tc == "mathcal");
                        break;
                case LFUN_ROMAN:
-                       flag.setOnOff(tc == LM_TC_RM);
+                       flag.setOnOff(tc == "mathrm");
                        break;
                case LFUN_CODE:
-                       flag.setOnOff(tc == LM_TC_TT);
+                       flag.setOnOff(tc == "mathtt");
                        break;
                case LFUN_NOUN:
-                       flag.setOnOff(tc == LM_TC_BB);
+                       flag.setOnOff(tc == "mathbb");
                        break;
                case LFUN_DEFAULT:
-                       flag.setOnOff(tc == LM_TC_VAR);
+                       flag.setOnOff(tc == "mathnormal");
                        break;
                default:
                        break;
@@ -885,6 +888,12 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
                                     (!keyseq.deleted())))
                {
+                       UpdatableInset * inset = owner->view()->theLockingInset();
+#if 1
+                       int inset_x;
+                       int dummy_y;
+                       inset->getCursorPos(owner->view(), inset_x, dummy_y);
+#endif
                        if ((action == LFUN_UNKNOWN_ACTION)
                            && argument.empty()) {
                                argument = keyseq.getiso();
@@ -896,7 +905,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                        } else if (action == LFUN_REDO) {
                                owner->view()->menuRedo();
                                goto exit_with_message;
-                       } else if (((result=owner->view()->theLockingInset()->
+                       } else if (((result=inset->
                                     // Hand-over to inset's own dispatch:
                                     localDispatch(owner->view(), action, argument)) ==
                                    UpdatableInset::DISPATCHED) ||
@@ -918,21 +927,43 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                                }
                                goto exit_with_message;
                        } else if (result == UpdatableInset::FINISHED_UP) {
-                               if (TEXT()->cursor.row()->previous()) {
+                               if (TEXT()->cursor.irow()->previous()) {
+#if 1
+                                       TEXT()->setCursorFromCoordinates(
+                                               owner->view(), TEXT()->cursor.ix() + inset_x,
+                                               TEXT()->cursor.iy() -
+                                               TEXT()->cursor.irow()->baseline() - 1);
+                                       TEXT()->cursor.x_fix(TEXT()->cursor.x());
+#else
                                        TEXT()->cursorUp(owner->view());
+#endif
                                        moveCursorUpdate(true, false);
                                        owner->showState();
+                               } else {
+                                       owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
                                }
                                goto exit_with_message;
                        } else if (result == UpdatableInset::FINISHED_DOWN) {
-                               if (TEXT()->cursor.row()->next())
+                               if (TEXT()->cursor.irow()->next()) {
+#if 1
+                                       TEXT()->setCursorFromCoordinates(
+                                               owner->view(), TEXT()->cursor.ix() + inset_x,
+                                               TEXT()->cursor.iy() -
+                                               TEXT()->cursor.irow()->baseline() +
+                                               TEXT()->cursor.irow()->height() + 1);
+                                       TEXT()->cursor.x_fix(TEXT()->cursor.x());
+#else
                                        TEXT()->cursorDown(owner->view());
-                               else
+#endif
+                               } else {
                                        TEXT()->cursorRight(owner->view());
+                               }
                                moveCursorUpdate(true, false);
                                owner->showState();
                                goto exit_with_message;
-                       } else {
+                       }
+#warning I am not sure this is still right, please have a look! (Jug 20020417)
+                       else { // result == UNDISPATCHED
                                //setMessage(N_("Text mode"));
                                switch (action) {
                                case LFUN_UNKNOWN_ACTION:
@@ -993,6 +1024,8 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                                                        true);
                        }
                        finishUndo();
+                       // Tell the paragraph dialog that we changed paragraph
+                       owner->getDialogs()->updateParagraph();
                }
        }
        break;
@@ -1041,7 +1074,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
 
        case LFUN_CANCEL:                   // RVDK_PATCH_5
                keyseq.reset();
-               meta_fake_bit = 0;
+               meta_fake_bit = key_modifier::none;
                if (owner->view()->available())
                        // cancel any selection
                        dispatch(LFUN_MARK_OFF);
@@ -1050,7 +1083,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
 
        case LFUN_META_FAKE:                                 // RVDK_PATCH_5
        {
-               meta_fake_bit = Mod1Mask;
+               meta_fake_bit = key_modifier::alt;
                setMessage(keyseq.print());
        }
        break;
@@ -1581,7 +1614,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                // Of course we should only do the resize and the textcache.clear
                // if values really changed...but not very important right now. (Lgb)
                // All visible buffers will need resize
-               owner->resize();
+               owner->view()->resize();
                // We also need to empty the textcache so that
                // the buffer will be formatted correctly after
                // a zoom change.
@@ -1880,15 +1913,16 @@ void LyXFunc::open(string const & fname)
 }
 
 
-// checks for running without gui are missing.
 void LyXFunc::doImport(string const & argument)
 {
        string format;
        string filename = split(argument, format, ' ');
+
        lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
                            << " file: " << filename << endl;
-
-       if (filename.empty()) { // need user interaction
+       // need user interaction
+       if (filename.empty()) {
                string initpath = lyxrc.document_path;
 
                if (owner->view()->available()) {
@@ -1925,7 +1959,6 @@ void LyXFunc::doImport(string const & argument)
                        owner->message(_("Canceled."));
        }
 
-       // still no filename? abort
        if (filename.empty())
                return;
 
@@ -1935,35 +1968,35 @@ void LyXFunc::doImport(string const & argument)
        string const lyxfile = ChangeExtension(filename, ".lyx");
 
        // Check if the document already is open
-       if (bufferlist.exists(lyxfile)) {
+       if (lyxrc.use_gui && bufferlist.exists(lyxfile)) {
                switch (Alert::askConfirmation(_("Document is already open:"),
                                        MakeDisplayPath(lyxfile, 50),
                                        _("Do you want to close that document now?\n"
                                          "('No' will just switch to the open version)")))
                        {
-                       case 1: // Yes: close the document
-                               if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
+                       case 1:
                                // If close is canceled, we cancel here too.
+                               if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
                                        return;
                                break;
-                       case 2: // No: switch to the open document
+                       case 2:
                                owner->view()->buffer(bufferlist.getBuffer(lyxfile));
                                return;
-                       case 3: // Cancel: Do nothing
+                       case 3:
                                owner->message(_("Canceled."));
                                return;
                        }
        }
 
-       // Check if a LyX document by the same root exists in filesystem
-       FileInfo const f(lyxfile, true);
-       if (f.exist() && !Alert::askQuestion(_("A document by the name"),
-                                     MakeDisplayPath(lyxfile),
-                                     _("already exists. Overwrite?"))) {
-               owner->message(_("Canceled"));
-               return;
+       // if the file exists already, and we didn't do 
+       // -i lyx thefile.lyx, warn
+       if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
+               if (!Alert::askQuestion(_("A document by the name"),
+                       MakeDisplayPath(lyxfile), _("already exists. Overwrite?"))) {
+                       owner->message(_("Canceled"));
+                       return;
+               }
        }
-       // filename should be valid now
 
        Importer::Import(owner, filename, format);
 }