- case LFUN_WORD_FIND_FORWARD:
- case LFUN_WORD_FIND_BACKWARD: {
- LASSERT(lyx_view_ && lyx_view_->view(), /**/);
- static docstring last_search;
- docstring searched_string;
-
- if (!cmd.argument().empty()) {
- last_search = cmd.argument();
- searched_string = cmd.argument();
- } else {
- searched_string = last_search;
- }
-
- if (searched_string.empty())
- break;
-
- bool const fw = action == LFUN_WORD_FIND_FORWARD;
- docstring const data =
- find2string(searched_string, true, false, fw);
- find(view(), FuncRequest(LFUN_WORD_FIND, data));
- break;
- }
-
- case LFUN_COMMAND_PREFIX:
- LASSERT(lyx_view_, /**/);
- lyx_view_->message(keyseq.printOptions(true));
- break;
-
- case LFUN_CANCEL:
- LASSERT(lyx_view_ && lyx_view_->view(), /**/);
- keyseq.reset();
- meta_fake_bit = NoModifier;
- if (buffer)
- // cancel any selection
- dispatch(FuncRequest(LFUN_MARK_OFF));
- setMessage(from_ascii(N_("Cancel")));
- break;
-
- case LFUN_META_PREFIX:
- meta_fake_bit = AltModifier;
- setMessage(keyseq.print(KeySequence::ForGui));
- break;
-
- case LFUN_BUFFER_TOGGLE_READ_ONLY: {
- LASSERT(lyx_view_ && lyx_view_->view() && buffer, /**/);
- if (buffer->lyxvc().inUse())
- buffer->lyxvc().toggleReadOnly();
- else
- buffer->setReadonly(!buffer->isReadonly());
- break;
- }
-
- // --- Menus -----------------------------------------------
- case LFUN_BUFFER_CLOSE:
- lyx_view_->closeBuffer();
- buffer = 0;
- updateFlags = Update::None;
- break;
-
- case LFUN_BUFFER_RELOAD: {
- LASSERT(lyx_view_ && buffer, /**/);
- docstring const file = makeDisplayPath(buffer->absFileName(), 20);
- docstring text = bformat(_("Any changes will be lost. Are you sure "
- "you want to revert to the saved version of the document %1$s?"), file);
- int const ret = Alert::prompt(_("Revert to saved document?"),
- text, 1, 1, _("&Revert"), _("&Cancel"));
-
- if (ret == 0)
- reloadBuffer();
- break;
- }
-
- case LFUN_BUFFER_UPDATE:
- LASSERT(lyx_view_ && buffer, /**/);
- buffer->doExport(argument, true);
- break;
-
- case LFUN_BUFFER_VIEW:
- LASSERT(lyx_view_ && buffer, /**/);
- buffer->preview(argument);
- break;
-
- case LFUN_MASTER_BUFFER_UPDATE:
- LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
- buffer->masterBuffer()->doExport(argument, true);
- break;
-
- case LFUN_MASTER_BUFFER_VIEW:
- LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
- buffer->masterBuffer()->preview(argument);
- break;
-
- case LFUN_BUILD_PROGRAM:
- LASSERT(lyx_view_ && buffer, /**/);
- buffer->doExport("program", true);
- break;
-
- case LFUN_BUFFER_CHKTEX:
- LASSERT(lyx_view_ && buffer, /**/);
- buffer->runChktex();
- break;
-
- case LFUN_BUFFER_EXPORT:
- LASSERT(lyx_view_ && buffer, /**/);
- if (argument == "custom")
- dispatch(FuncRequest(LFUN_DIALOG_SHOW, "sendto"));
- else
- buffer->doExport(argument, false);
- break;
-
- case LFUN_BUFFER_EXPORT_CUSTOM: {
- LASSERT(lyx_view_ && buffer, /**/);
- string format_name;
- string command = split(argument, format_name, ' ');
- Format const * format = formats.getFormat(format_name);
- if (!format) {
- lyxerr << "Format \"" << format_name
- << "\" not recognized!"
- << endl;
- break;
- }
-
- // The name of the file created by the conversion process
- string filename;
-
- // Output to filename
- if (format->name() == "lyx") {
- string const latexname = buffer->latexName(false);
- filename = changeExtension(latexname,
- format->extension());
- filename = addName(buffer->temppath(), filename);
-
- if (!buffer->writeFile(FileName(filename)))
- break;
-
- } else {
- buffer->doExport(format_name, true, filename);
- }
-
- // Substitute $$FName for filename
- if (!contains(command, "$$FName"))
- command = "( " + command + " ) < $$FName";
- command = subst(command, "$$FName", filename);
-
- // Execute the command in the background
- Systemcall call;
- call.startscript(Systemcall::DontWait, command);
- 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:
- doImport(argument);
- break;
- */
-
- case LFUN_BUFFER_AUTO_SAVE:
- buffer->autoSave();
- break;
-
- case LFUN_RECONFIGURE:
- // argument is any additional parameter to the configure.py command
- reconfigure(lyx_view_, argument);
- break;
-
- case LFUN_HELP_OPEN: {
- if (lyx_view_ == 0)
- theApp()->dispatch(FuncRequest(LFUN_WINDOW_NEW));
- string const arg = argument;
- if (arg.empty()) {
- setErrorMessage(from_ascii(N_("Missing argument")));
- break;
- }
- FileName const fname = i18nLibFileSearch("doc", arg, "lyx");
- if (fname.empty()) {
- lyxerr << "LyX: unable to find documentation file `"
- << arg << "'. Bad installation?" << endl;
- break;
- }
- lyx_view_->message(bformat(_("Opening help file %1$s..."),
- makeDisplayPath(fname.absFilename())));
- Buffer * buf = lyx_view_->loadDocument(fname, false);
- if (buf) {
- updateLabels(*buf);
- lyx_view_->setBuffer(buf);
- buf->errors("Parse");
- }
- updateFlags = Update::None;
- break;
- }
-
- // --- version control -------------------------------
- case LFUN_VC_REGISTER:
- LASSERT(lyx_view_ && buffer, /**/);
- if (!ensureBufferClean(view()) || buffer->isUnnamed())
- break;
- if (!buffer->lyxvc().inUse()) {
- buffer->lyxvc().registrer();
- reloadBuffer();
- }
- updateFlags = Update::Force;
- break;
-
- case LFUN_VC_CHECK_IN:
- LASSERT(lyx_view_ && buffer, /**/);
- if (!ensureBufferClean(view()))
- break;
- if (buffer->lyxvc().inUse()
- && !buffer->isReadonly()) {
- setMessage(from_utf8(buffer->lyxvc().checkIn()));
- reloadBuffer();
- }
- break;
-
- case LFUN_VC_CHECK_OUT:
- LASSERT(lyx_view_ && buffer, /**/);
- if (!ensureBufferClean(view()))
- break;
- if (buffer->lyxvc().inUse()) {
- setMessage(from_utf8(buffer->lyxvc().checkOut()));
- reloadBuffer();
- }
- break;
-
- case LFUN_VC_REVERT:
- LASSERT(lyx_view_ && buffer, /**/);
- buffer->lyxvc().revert();
- reloadBuffer();
- break;
-
- case LFUN_VC_UNDO_LAST:
- LASSERT(lyx_view_ && buffer, /**/);
- buffer->lyxvc().undoLast();
- reloadBuffer();
- break;
-
- // --- lyxserver commands ----------------------------
- case LFUN_SERVER_GET_FILENAME:
- LASSERT(lyx_view_ && buffer, /**/);
- setMessage(from_utf8(buffer->absFileName()));
- LYXERR(Debug::INFO, "FNAME["
- << buffer->absFileName() << ']');
- break;
-
- case LFUN_SERVER_NOTIFY:
- dispatch_buffer = keyseq.print(KeySequence::Portable);
- theServer().notifyClient(to_utf8(dispatch_buffer));
- break;
-
- case LFUN_SERVER_GOTO_FILE_ROW: {
- LASSERT(lyx_view_, /**/);
- string file_name;
- int row;
- istringstream is(argument);
- is >> file_name >> row;
- Buffer * buf = 0;
- bool loaded = false;
- if (prefixIs(file_name, package().temp_dir().absFilename()))
- // Needed by inverse dvi search. If it is a file
- // in tmpdir, call the apropriated function
- buf = theBufferList().getBufferFromTmp(file_name);
- 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 {
- buf = lyx_view_->loadDocument(s);
- loaded = true;
- }
- }
-
- if (!buf) {
- updateFlags = Update::None;
- break;
- }
-
- updateLabels(*buf);
- lyx_view_->setBuffer(buf);
- view()->setCursorFromRow(row);
- if (loaded)
- buf->errors("Parse");
- updateFlags = Update::FitCursor;
- break;
- }
-
-
- case LFUN_DIALOG_SHOW_NEW_INSET: {
- LASSERT(lyx_view_, /**/);
- string const name = cmd.getArg(0);
- InsetCode code = insetCode(name);
- string data = trim(to_utf8(cmd.argument()).substr(name.size()));
- bool insetCodeOK = true;
- switch (code) {
- case BIBITEM_CODE:
- case BIBTEX_CODE:
- case INDEX_CODE:
- case LABEL_CODE:
- case NOMENCL_CODE:
- case REF_CODE:
- case TOC_CODE:
- case HYPERLINK_CODE: {
- InsetCommandParams p(code);
- data = InsetCommand::params2string(name, p);
- break;
- }
- case INCLUDE_CODE: {
- // data is the include type: one of "include",
- // "input", "verbatiminput" or "verbatiminput*"
- if (data.empty())
- // default type is requested
- data = "include";
- InsetCommandParams p(INCLUDE_CODE, data);
- data = InsetCommand::params2string("include", p);
- break;
- }
- case BOX_CODE: {
- // \c data == "Boxed" || "Frameless" etc
- InsetBoxParams p(data);
- data = InsetBox::params2string(p);
- break;
- }
- case BRANCH_CODE: {
- InsetBranchParams p;
- data = InsetBranch::params2string(p);
- break;
- }
- case CITE_CODE: {
- InsetCommandParams p(CITE_CODE);
- data = InsetCommand::params2string(name, p);
- break;
- }
- case ERT_CODE: {
- data = InsetERT::params2string(InsetCollapsable::Open);
- break;
- }
- case EXTERNAL_CODE: {
- InsetExternalParams p;
- data = InsetExternal::params2string(p, *buffer);
- break;
- }
- case FLOAT_CODE: {
- InsetFloatParams p;
- data = InsetFloat::params2string(p);
- break;
- }
- case LISTINGS_CODE: {
- InsetListingsParams p;
- data = InsetListings::params2string(p);
- break;
- }
- case GRAPHICS_CODE: {
- InsetGraphicsParams p;
- data = InsetGraphics::params2string(p, *buffer);
- break;
- }
- case NOTE_CODE: {
- InsetNoteParams p;
- data = InsetNote::params2string(p);
- break;
- }
- case SPACE_CODE: {
- InsetSpaceParams p;
- data = InsetSpace::params2string(p);
- break;
- }
- case VSPACE_CODE: {
- VSpace space;
- data = InsetVSpace::params2string(space);
- break;
- }
- case WRAP_CODE: {
- InsetWrapParams p;
- data = InsetWrap::params2string(p);
- break;
- }
- default:
- lyxerr << "Inset type '" << name <<
- "' not recognized in LFUN_DIALOG_SHOW_NEW_INSET" << endl;
- insetCodeOK = false;
- break;
- } // end switch(code)
- if (insetCodeOK)
- dispatch(FuncRequest(LFUN_DIALOG_SHOW, name + " " + data));
- break;
- }
-
- case LFUN_CITATION_INSERT: {
- LASSERT(lyx_view_, /**/);
- if (!argument.empty()) {
- // we can have one optional argument, delimited by '|'
- // citation-insert <key>|<text_before>
- // this should be enhanced to also support text_after
- // and citation style
- string arg = argument;
- string opt1;
- if (contains(argument, "|")) {
- arg = token(argument, '|', 0);
- opt1 = token(argument, '|', 1);
- }
- InsetCommandParams icp(CITE_CODE);
- icp["key"] = from_utf8(arg);
- if (!opt1.empty())
- icp["before"] = from_utf8(opt1);
- string icstr = InsetCommand::params2string("citation", icp);
- FuncRequest fr(LFUN_INSET_INSERT, icstr);
- dispatch(fr);
- } else
- dispatch(FuncRequest(LFUN_DIALOG_SHOW_NEW_INSET, "citation"));
- break;
- }
-
- case LFUN_BUFFER_CHILD_OPEN: {
- LASSERT(lyx_view_ && buffer, /**/);
- FileName filename = makeAbsPath(argument, buffer->filePath());
- view()->saveBookmark(false);
- Buffer * child = 0;
- bool parsed = false;
- if (theBufferList().exists(filename)) {
- child = theBufferList().getBuffer(filename);
- } else {
- setMessage(bformat(_("Opening child document %1$s..."),
- makeDisplayPath(filename.absFilename())));
- child = lyx_view_->loadDocument(filename, false);
- parsed = true;
- }
- if (child) {
- // 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.
- child->setParent(buffer);
- updateLabels(*child->masterBuffer());
- lyx_view_->setBuffer(child);
- if (parsed)
- child->errors("Parse");
- }
-
- // If a screen update is required (in case where auto_open is false),
- // setBuffer() would have taken care of it already. Otherwise we shall
- // reset the update flag because it can cause a circular problem.
- // See bug 3970.
- updateFlags = Update::None;
- break;
- }
-