]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
minimal effort implementation of:
[lyx.git] / src / lyxfunc.C
index 98c25f9312797ede70fc72a17154d50cb477ccf1..2d1f1b65eba6fd7f58f4d55a84d040a3e31c9746 100644 (file)
@@ -92,6 +92,7 @@
 #include "support/systemcall.h"
 #include "support/convert.h"
 #include "support/os.h"
+#include "support/unicode.h"
 
 #include <boost/current_function.hpp>
 #include <boost/filesystem/operations.hpp>
@@ -191,7 +192,7 @@ Change::Type lookupChangeType(DocIterator const & dit, bool outer = false)
                CursorSlice const & slice = dit[i];
                if (!slice.inset().inMathed()
                    && slice.pos() < slice.paragraph().size()) {
-                       Change::Type const ch = slice.paragraph().lookupChangeType(slice.pos());
+                       Change::Type const ch = slice.paragraph().lookupChange(slice.pos()).type;
                        if (ch != Change::UNCHANGED)
                                return ch;
                }
@@ -248,7 +249,8 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
 
        Encoding const * encoding = view()->cursor().getEncoding();
 
-       encoded_last_key = keysym->getISOEncoded(encoding ? encoding->name() : "");
+       //encoded_last_key = keysym->getISOEncoded(encoding ? encoding->name() : "");
+       size_t encoded_last_key = keysym->getUCSEncoded();
 
        // Do a one-deep top-level lookup for
        // cancel and meta-fake keys. RVDK_PATCH_5
@@ -321,7 +323,8 @@ void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
 
        if (func.action == LFUN_SELF_INSERT) {
                if (encoded_last_key != 0) {
-                       string const arg(1, encoded_last_key);
+                       std::vector<char> tmp = ucs4_to_utf8(encoded_last_key);
+                       string const arg(tmp.begin(), tmp.end());
                        dispatch(FuncRequest(LFUN_SELF_INSERT, arg,
                                             FuncRequest::KEYBOARD));
                        lyxerr[Debug::KEY]
@@ -397,7 +400,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        // to handle (Andre')
        bool enable = true;
        switch (cmd.action) {
-       case LFUN_TOGGLE_TOOLTIPS:
+       case LFUN_TOOLTIPS_TOGGLE:
                flag.setOnOff(owner->getDialogs().tooltipsEnabled());
                break;
 
@@ -562,7 +565,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        }
 
        case LFUN_BUFFER_NEW:
-       case LFUN_BUFFER_NEWTMPLT:
+       case LFUN_BUFFER_NEW_TEMPLATE:
        case LFUN_WORD_FIND_FORWARD:
        case LFUN_WORD_FIND_BACKWARD:
        case LFUN_COMMAND_PREFIX:
@@ -611,7 +614,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        case LFUN_BUFFER_SAVE_AS_DEFAULT:
        case LFUN_BUFFER_PARAMS_APPLY:
        case LFUN_LYXRC_APPLY:
-       case LFUN_SCREEN_DOWNBUFFER:
+       case LFUN_BUFFER_NEXT:
        case LFUN_BUFFER_PREVIOUS:
                // these are handled in our dispatch()
                break;
@@ -724,7 +727,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
        dispatch_buffer.erase();
 
        // redraw the screen at the end (first of the two drawing steps).
-       //This is done unless explicitely requested otherwise 
+       //This is done unless explicitely requested otherwise
        bool update = true;
        // also do the second redrawing step. Only done if requested.
        bool updateforce = false;
@@ -738,10 +741,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                       << endl;
                setErrorMessage(flag.message());
        } else {
-
-               if (view()->available())
-                       view()->hideCursor();
-
                switch (action) {
 
                case LFUN_WORD_FIND_FORWARD:
@@ -802,7 +801,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        menuNew(argument, false);
                        break;
 
-               case LFUN_BUFFER_NEWTMPLT:
+               case LFUN_BUFFER_NEW_TEMPLATE:
                        menuNew(argument, true);
                        break;
 
@@ -841,22 +840,18 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                case LFUN_BUFFER_UPDATE:
                        Exporter::Export(owner->buffer(), argument, true);
-                       view()->showErrorList(bufferFormat(*owner->buffer()));
                        break;
 
                case LFUN_BUFFER_VIEW:
                        Exporter::preview(owner->buffer(), argument);
-                       view()->showErrorList(bufferFormat(*owner->buffer()));
                        break;
 
                case LFUN_BUILD_PROGRAM:
                        Exporter::Export(owner->buffer(), "program", true);
-                       view()->showErrorList(_("Build"));
                        break;
 
                case LFUN_BUFFER_CHKTEX:
                        owner->buffer()->runChktex();
-                       view()->showErrorList(_("ChkTeX"));
                        break;
 
                case LFUN_BUFFER_EXPORT:
@@ -864,7 +859,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                owner->getDialogs().show("sendto");
                        else {
                                Exporter::Export(owner->buffer(), argument, false);
-                               view()->showErrorList(bufferFormat(*owner->buffer()));
                        }
                        break;
 
@@ -896,8 +890,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                        break;
 
                        } else {
-                               Exporter::Export(buffer, format_name, true,
-                                                filename);
+                               Exporter::Export(buffer, format_name, true, filename);
                        }
 
                        // Substitute $$FName for filename
@@ -1046,7 +1039,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        }
                        owner->message(bformat(_("Opening help file %1$s..."),
                                makeDisplayPath(fname)));
-                       view()->loadLyXFile(fname, false);
+                       owner->loadLyXFile(fname, false);
                        break;
                }
 
@@ -1092,15 +1085,15 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                // --- buffers ----------------------------------------
                case LFUN_BUFFER_SWITCH:
-                       view()->setBuffer(bufferlist.getBuffer(argument));
+                       owner->setBuffer(bufferlist.getBuffer(argument));
                        break;
 
-               case LFUN_SCREEN_DOWNBUFFER:
-                       view()->setBuffer(bufferlist.next(view()->buffer()));
+               case LFUN_BUFFER_NEXT:
+                       owner->setBuffer(bufferlist.next(view()->buffer()));
                        break;
 
                case LFUN_BUFFER_PREVIOUS:
-                       view()->setBuffer(bufferlist.previous(view()->buffer()));
+                       owner->setBuffer(bufferlist.previous(view()->buffer()));
                        break;
 
                case LFUN_FILE_NEW:
@@ -1140,16 +1133,16 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        if (prefixIs(file_name, package().temp_dir())) {
                                // Needed by inverse dvi search. If it is a file
                                // in tmpdir, call the apropriated function
-                               view()->setBuffer(bufferlist.getBufferFromTmp(file_name));
+                               owner->setBuffer(bufferlist.getBufferFromTmp(file_name));
                        } else {
                                // Must replace extension of the file to be .lyx
                                // and get full path
                                string const s = changeExtension(file_name, ".lyx");
                                // Either change buffer or load the file
                                if (bufferlist.exists(s)) {
-                                       view()->setBuffer(bufferlist.getBuffer(s));
+                                       owner->setBuffer(bufferlist.getBuffer(s));
                                } else {
-                                       view()->loadLyXFile(s);
+                                       owner->loadLyXFile(s);
                                }
                        }
 
@@ -1157,7 +1150,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
 
                        view()->center();
                        // see BufferView_pimpl::center()
-                       view()->updateScrollbar();
                        break;
                }
 
@@ -1180,11 +1172,11 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                        data = "literate ";
                                        break;
                                }
-                               data += logfile.second;
+                               data += LyXLex::quoteString(logfile.second);
                                owner->getDialogs().show("log", data);
                        } else if (name == "vclog") {
                                string const data = "vc " +
-                                       owner->buffer()->lyxvc().getLogFile();
+                                       LyXLex::quoteString(owner->buffer()->lyxvc().getLogFile());
                                owner->getDialogs().show("log", data);
                        } else
                                owner->getDialogs().show(name, data);
@@ -1301,9 +1293,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        view()->savePosition(0);
                        string const parentfilename = owner->buffer()->fileName();
                        if (bufferlist.exists(filename))
-                               view()->setBuffer(bufferlist.getBuffer(filename));
+                               owner->setBuffer(bufferlist.getBuffer(filename));
                        else
-                               view()->loadLyXFile(filename);
+                               owner->loadLyXFile(filename);
                        // Set the parent name of the child document.
                        // This makes insertion of citations and references in the child work,
                        // when the target is in the parent or another child document.
@@ -1409,7 +1401,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        owner->message(argument);
                        break;
 
-               case LFUN_TOGGLE_TOOLTIPS:
+               case LFUN_TOOLTIPS_TOGGLE:
                        owner->getDialogs().toggleTooltips();
                        break;
 
@@ -1560,14 +1552,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        recordUndoFullDocument(view());
                        buffer->params().textclass = new_class;
                        StableDocIterator backcur(view()->cursor());
-                       ErrorList el;
+                       ErrorList & el = buffer->errorList("Class Switch");
                        lyx::cap::switchBetweenClasses(
                                old_class, new_class,
-                               buffer->paragraphs(), el);
+                               static_cast<InsetText &>(buffer->inset()), el);
 
                        view()->setCursor(backcur.asDocIterator(&(buffer->inset())));
-                       bufferErrors(*buffer, el);
-                       view()->showErrorList(_("Class switch"));
+
+                       buffer->errors("Class Switch");
                        updateLabels(*buffer);
                        updateforce = true;
                        break;
@@ -1612,18 +1604,21 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        else if (update)
                                view()->update(Update::FitCursor);
 
+                       owner->redrawWorkArea();
+
                        // if we executed a mutating lfun, mark the buffer as dirty
                        if (flag.enabled()
                            && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
                            && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly))
                                view()->buffer()->markDirty();
-               }
 
-               if (view()->cursor().inTexted()) {
-                       view()->owner()->updateLayoutChoice();
+                       if (view()->cursor().inTexted()) {
+                               view()->owner()->updateLayoutChoice();
+                       }
                }
        }
-       sendDispatchMessage(_(getMessage()), cmd);
+       if (!quitting)
+               sendDispatchMessage(_(getMessage()), cmd);
 }
 
 
@@ -1738,7 +1733,9 @@ void LyXFunc::menuNew(string const & name, bool fromTemplate)
                templname = result.second;
        }
 
-       view()->newFile(filename, templname, !name.empty());
+       Buffer * const b = newFile(filename, templname, !name.empty());
+       if (b)
+               owner->setBuffer(b);
 }
 
 
@@ -1792,15 +1789,17 @@ void LyXFunc::open(string const & fname)
 
        // if the file doesn't exist, let the user create one
        if (!fs::exists(filename)) {
-               // the user specifically chose this name. Believe them.
-               view()->newFile(filename, "", true);
+               // the user specifically chose this name. Believe him.
+               Buffer * const b = newFile(filename, string(), true);
+               if (b)
+                       owner->setBuffer(b);
                return;
        }
 
        owner->message(bformat(_("Opening document %1$s..."), disp_fn));
 
        string str2;
-       if (view()->loadLyXFile(filename)) {
+       if (owner->loadLyXFile(filename)) {
                str2 = bformat(_("Document %1$s opened."), disp_fn);
        } else {
                str2 = bformat(_("Could not open document %1$s"), disp_fn);
@@ -1888,7 +1887,9 @@ void LyXFunc::doImport(string const & argument)
                }
        }
 
-       Importer::Import(owner, filename, format);
+       ErrorList errorList;
+       Importer::Import(owner, filename, format, errorList);
+       // FIXME (Abdel 12/08/06): Is there a need to display the error list here?
 }
 
 
@@ -1904,7 +1905,7 @@ void LyXFunc::closeBuffer()
                        // since there's no current buffer
                        owner->getDialogs().hideBufferDependent();
                } else {
-                       view()->setBuffer(bufferlist.first());
+                       owner->setBuffer(bufferlist.first());
                }
        }
 }
@@ -1950,7 +1951,7 @@ string const LyXFunc::viewStatusMessage()
 BufferView * LyXFunc::view() const
 {
        BOOST_ASSERT(owner);
-       return owner->view().get();
+       return owner->view();
 }
 
 
@@ -1991,11 +1992,6 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
        case LyXRC::RC_CUSTOM_EXPORT_COMMAND:
        case LyXRC::RC_CUSTOM_EXPORT_FORMAT:
-       case LyXRC::RC_CYGWIN_PATH_FIX:
-               if (lyxrc_orig.cygwin_path_fix != lyxrc_new.cygwin_path_fix) {
-                       namespace os = lyx::support::os;
-                       os::cygwin_path_fix(lyxrc_new.cygwin_path_fix);
-               }
        case LyXRC::RC_DATE_INSERT_FORMAT:
        case LyXRC::RC_DEFAULT_LANGUAGE:
        case LyXRC::RC_DEFAULT_PAPERSIZE:
@@ -2081,6 +2077,11 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_TEMPDIRPATH:
        case LyXRC::RC_TEMPLATEPATH:
        case LyXRC::RC_TEX_ALLOWS_SPACES:
+       case LyXRC::RC_TEX_EXPECTS_WINDOWS_PATHS:
+               if (lyxrc_orig.windows_style_tex_paths != lyxrc_new.windows_style_tex_paths) {
+                       namespace os = lyx::support::os;
+                       os::windows_style_tex_paths(lyxrc_new.windows_style_tex_paths);
+               }
        case LyXRC::RC_UIFILE:
        case LyXRC::RC_USER_EMAIL:
        case LyXRC::RC_USER_NAME:
@@ -2092,7 +2093,6 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_USE_SPELL_LIB:
        case LyXRC::RC_VIEWDVI_PAPEROPTION:
        case LyXRC::RC_VIEWER:
-       case LyXRC::RC_WHEEL_JUMP:
        case LyXRC::RC_LAST:
                break;
        }