]> git.lyx.org Git - lyx.git/blobdiff - src/LyXFunc.cpp
* configure.py:
[lyx.git] / src / LyXFunc.cpp
index d42b70b5b59b099c92c77563e7d3c58cf403adfe..256f136dc8ca63304a0e555334c7639bed110122 100644 (file)
@@ -457,11 +457,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                        flag.setOnOff(true);
                break;
 
-       case LFUN_BUFFER_EXPORT:
-               enable = cmd.argument() == "custom"
-                       || buf->isExportable(to_utf8(cmd.argument()));
-               break;
-
        case LFUN_BUFFER_CHKTEX:
                enable = buf->isLatex() && !lyxrc.chktex_command.empty();
                break;
@@ -588,6 +583,30 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                break;
        }
 
+       case LFUN_MASTER_BUFFER_UPDATE:
+       case LFUN_MASTER_BUFFER_VIEW: 
+               if (!buf->parent()) {
+                       enable = false;
+                       break;
+               }
+       case LFUN_BUFFER_UPDATE:
+       case LFUN_BUFFER_VIEW: {
+               string format = to_utf8(cmd.argument());
+               if (cmd.argument().empty())
+                       format = buf->getDefaultOutputFormat();
+               typedef vector<Format const *> Formats;
+               Formats formats;
+               formats = buf->exportableFormats(true);
+               Formats::const_iterator fit = formats.begin();
+               Formats::const_iterator end = formats.end();
+               enable = false;
+               for (; fit != end ; ++fit) {
+                       if ((*fit)->name() == format)
+                               enable = true;
+               }
+               break;
+       }
+
        case LFUN_WORD_FIND_FORWARD:
        case LFUN_WORD_FIND_BACKWARD:
        case LFUN_WORD_FINDADV:
@@ -596,10 +615,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        case LFUN_CANCEL:
        case LFUN_META_PREFIX:
        case LFUN_BUFFER_CLOSE:
-       case LFUN_BUFFER_UPDATE:
-       case LFUN_BUFFER_VIEW:
-       case LFUN_MASTER_BUFFER_UPDATE:
-       case LFUN_MASTER_BUFFER_VIEW:
        case LFUN_BUFFER_IMPORT:
        case LFUN_BUFFER_AUTO_SAVE:
        case LFUN_RECONFIGURE:
@@ -619,7 +634,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
        case LFUN_KEYMAP_TOGGLE:
        case LFUN_REPEAT:
        case LFUN_BUFFER_EXPORT_CUSTOM:
-       case LFUN_BUFFER_PRINT:
        case LFUN_PREFERENCES_SAVE:
        case LFUN_MESSAGE:
        case LFUN_INSET_EDIT:
@@ -653,8 +667,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                if (lyx_view_->getStatus(cmd, flag))
                        break;
 
-               // If we have a BufferView, try cursor position and
-               // then the BufferView.
+               // If we do not have a BufferView, then other functions are disabled
                if (!view()) {
                        enable = false;
                        break;
@@ -666,8 +679,13 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                    && inset && inset->getStatus(view()->cursor(), cmd, flag))
                        break;
 
-               if (!getLocalStatus(view()->cursor(), cmd, flag))
-                       flag = view()->getStatus(cmd);
+               bool decided = getLocalStatus(view()->cursor(), cmd, flag);
+               if (!decided)
+                       // try the BufferView
+                       decided = view()->getStatus(cmd, flag);
+               if (!decided)
+                       // try the Buffer
+                       view()->buffer().getStatus(cmd, flag);
        }
 
        if (!enable)
@@ -730,15 +748,6 @@ bool LyXFunc::ensureBufferClean(BufferView * bv)
 
 namespace {
 
-void showPrintError(string const & name)
-{
-       docstring str = bformat(_("Could not print the document %1$s.\n"
-                                           "Check that your printer is set up correctly."),
-                            makeDisplayPath(name, 50));
-       Alert::error(_("Print document failed"), str);
-}
-
-
 bool loadLayoutFile(string const & name, string const & buf_path)
 {
        if (!LayoutFileList::get().haveClass(name)) {
@@ -865,25 +874,41 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_BUFFER_UPDATE:
+               case LFUN_BUFFER_UPDATE: {
                        LASSERT(lyx_view_ && buffer, /**/);
-                       buffer->doExport(argument, true);
+                       string format = argument;
+                       if (argument.empty())
+                               format = buffer->getDefaultOutputFormat();
+                       buffer->doExport(format, true);
                        break;
+               }
 
-               case LFUN_BUFFER_VIEW:
+               case LFUN_BUFFER_VIEW: {
                        LASSERT(lyx_view_ && buffer, /**/);
-                       buffer->preview(argument);
+                       string format = argument;
+                       if (argument.empty())
+                               format = buffer->getDefaultOutputFormat();
+                       buffer->preview(format);
                        break;
+               }
 
-               case LFUN_MASTER_BUFFER_UPDATE:
+               case LFUN_MASTER_BUFFER_UPDATE: {
                        LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
-                       buffer->masterBuffer()->doExport(argument, true);
+                       string format = argument;
+                       if (argument.empty())
+                               format = buffer->masterBuffer()->getDefaultOutputFormat();
+                       buffer->masterBuffer()->doExport(format, true);
                        break;
+               }
 
-               case LFUN_MASTER_BUFFER_VIEW:
+               case LFUN_MASTER_BUFFER_VIEW: {
                        LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
-                       buffer->masterBuffer()->preview(argument);
+                       string format = argument;
+                       if (argument.empty())
+                               format = buffer->masterBuffer()->getDefaultOutputFormat();
+                       buffer->masterBuffer()->preview(format);
                        break;
+               }
 
                case LFUN_BUILD_PROGRAM:
                        LASSERT(lyx_view_ && buffer, /**/);
@@ -943,111 +968,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               case LFUN_BUFFER_PRINT: {
-                       LASSERT(lyx_view_ && buffer, /**/);
-                       // FIXME: cmd.getArg() might fail if one of the arguments
-                       // contains double quotes
-                       string target = cmd.getArg(0);
-                       string target_name = cmd.getArg(1);
-                       string command = cmd.getArg(2);
-
-                       if (target.empty()
-                           || target_name.empty()
-                           || command.empty()) {
-                               lyxerr << "Unable to parse \""
-                                      << argument << '"' << endl;
-                               break;
-                       }
-                       if (target != "printer" && target != "file") {
-                               lyxerr << "Unrecognized target \""
-                                      << target << '"' << endl;
-                               break;
-                       }
-
-                       if (!buffer->doExport("dvi", true)) {
-                               showPrintError(buffer->absFileName());
-                               break;
-                       }
-
-                       // Push directory path.
-                       string const path = buffer->temppath();
-                       // Prevent the compiler from optimizing away p
-                       FileName pp(path);
-                       PathChanger p(pp);
-
-                       // there are three cases here:
-                       // 1. we print to a file
-                       // 2. we print directly to a printer
-                       // 3. we print using a spool command (print to file first)
-                       Systemcall one;
-                       int res = 0;
-                       string const dviname =
-                               changeExtension(buffer->latexName(true), "dvi");
-
-                       if (target == "printer") {
-                               if (!lyxrc.print_spool_command.empty()) {
-                                       // case 3: print using a spool
-                                       string const psname =
-                                               changeExtension(dviname,".ps");
-                                       command += ' ' + lyxrc.print_to_file
-                                               + quoteName(psname)
-                                               + ' '
-                                               + quoteName(dviname);
-
-                                       string command2 =
-                                               lyxrc.print_spool_command + ' ';
-                                       if (target_name != "default") {
-                                               command2 += lyxrc.print_spool_printerprefix
-                                                       + target_name
-                                                       + ' ';
-                                       }
-                                       command2 += quoteName(psname);
-                                       // First run dvips.
-                                       // If successful, then spool command
-                                       res = one.startscript(
-                                               Systemcall::Wait,
-                                               command);
-
-                                       if (res == 0)
-                                               res = one.startscript(
-                                                       Systemcall::DontWait,
-                                                       command2);
-                               } else {
-                                       // case 2: print directly to a printer
-                                       if (target_name != "default")
-                                               command += ' ' + lyxrc.print_to_printer + target_name + ' ';
-                                       res = one.startscript(
-                                               Systemcall::DontWait,
-                                               command + quoteName(dviname));
-                               }
-
-                       } else {
-                               // case 1: print to a file
-                               FileName const filename(makeAbsPath(target_name,
-                                                       buffer->filePath()));
-                               FileName const dvifile(makeAbsPath(dviname, path));
-                               if (filename.exists()) {
-                                       docstring text = bformat(
-                                               _("The file %1$s already exists.\n\n"
-                                                 "Do you want to overwrite that file?"),
-                                               makeDisplayPath(filename.absFilename()));
-                                       if (Alert::prompt(_("Overwrite file?"),
-                                           text, 0, 1, _("&Overwrite"), _("&Cancel")) != 0)
-                                               break;
-                               }
-                               command += ' ' + lyxrc.print_to_file
-                                       + quoteName(filename.toFilesystemEncoding())
-                                       + ' '
-                                       + quoteName(dvifile.toFilesystemEncoding());
-                               res = one.startscript(Systemcall::DontWait,
-                                                     command);
-                       }
-
-                       if (res != 0)
-                               showPrintError(buffer->absFileName());
-                       break;
-               }
-
                // FIXME: There is need for a command-line import.
                /*
                case LFUN_BUFFER_IMPORT:
@@ -1159,21 +1079,30 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                        is >> file_name >> row;
                        Buffer * buf = 0;
                        bool loaded = false;
-                       if (prefixIs(file_name, package().temp_dir().absFilename()))
+                       string const abstmp = package().temp_dir().absFilename();
+                       string const realtmp = package().temp_dir().realPath();
+                       if (prefixIs(file_name, abstmp) || prefixIs(file_name, realtmp)) {
                                // Needed by inverse dvi search. If it is a file
-                               // in tmpdir, call the apropriated function
+                               // in tmpdir, call the apropriated function.
+                               // If tmpdir is a symlink, we may have the real
+                               // path passed back, so we correct for that.
+                               if (!prefixIs(file_name, abstmp))
+                                       file_name = subst(file_name, realtmp, abstmp);
                                buf = theBufferList().getBufferFromTmp(file_name);
-                       else {
+                       else {
                                // Must replace extension of the file to be .lyx
                                // and get full path
                                FileName const s = fileSearch(string(), changeExtension(file_name, ".lyx"), "lyx");
                                // Either change buffer or load the file
                                if (theBufferList().exists(s))
                                        buf = theBufferList().getBuffer(s);
-                               else {
+                               else if (s.exists()) {
                                        buf = lyx_view_->loadDocument(s);
                                        loaded = true;
-                               }
+                               } else
+                                       lyx_view_->message(bformat(
+                                               _("File does not exist: %1$s"),
+                                               makeDisplayPath(file_name)));
                        }
 
                        if (!buf) {
@@ -1712,6 +1641,14 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                                break;
                        }
 
+                       // OK, so try the Buffer itself
+                       DispatchResult dr;
+                       view()->buffer().dispatch(cmd, dr);
+                       if (dr.dispatched()) {
+                               updateFlags = dr.update();
+                               break;
+                       }
+
                        // Is this a function that acts on inset at point?
                        Inset * inset = view()->cursor().nextInset();
                        if (lyxaction.funcHasFlag(action, LyXAction::AtPoint)
@@ -1943,6 +1880,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_AUTOSAVE:
        case LyXRC::RC_AUTO_NUMBER:
        case LyXRC::RC_BACKUPDIR_PATH:
+       case LyXRC::RC_BIBTEX_ALTERNATIVES:
        case LyXRC::RC_BIBTEX_COMMAND:
        case LyXRC::RC_BINDFILE:
        case LyXRC::RC_CHECKLASTFILES:
@@ -1963,12 +1901,11 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_COPIER:
        case LyXRC::RC_CURSOR_FOLLOWS_SCROLLBAR:
        case LyXRC::RC_SCROLL_BELOW_DOCUMENT:
-       case LyXRC::RC_CUSTOM_EXPORT_COMMAND:
-       case LyXRC::RC_CUSTOM_EXPORT_FORMAT:
        case LyXRC::RC_DATE_INSERT_FORMAT:
        case LyXRC::RC_DEFAULT_LANGUAGE:
        case LyXRC::RC_GUI_LANGUAGE:
        case LyXRC::RC_DEFAULT_PAPERSIZE:
+       case LyXRC::RC_DEFAULT_VIEW_FORMAT:
        case LyXRC::RC_DEFFILE:
        case LyXRC::RC_DIALOGS_ICONIFY_WITH_MAIN:
        case LyXRC::RC_DISPLAY_GRAPHICS:
@@ -1983,7 +1920,10 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_FONT_ENCODING:
        case LyXRC::RC_FORMAT:
        case LyXRC::RC_GROUP_LAYOUTS:
+       case LyXRC::RC_INDEX_ALTERNATIVES:
        case LyXRC::RC_INDEX_COMMAND:
+       case LyXRC::RC_JBIBTEX_COMMAND:
+       case LyXRC::RC_JINDEX_COMMAND:
        case LyXRC::RC_NOMENCL_COMMAND:
        case LyXRC::RC_INPUT:
        case LyXRC::RC_KBMAP:
@@ -2048,6 +1988,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
        case LyXRC::RC_OPEN_BUFFERS_IN_TABS:
        case LyXRC::RC_SPELL_COMMAND:
        case LyXRC::RC_SPELLCHECK_CONTINUOUSLY:
+       case LyXRC::RC_SPLITINDEX_COMMAND:
        case LyXRC::RC_TEMPDIRPATH:
        case LyXRC::RC_TEMPLATEPATH:
        case LyXRC::RC_TEX_ALLOWS_SPACES: