- 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_CLOSE_ALL:
- lyx_view_->closeBufferAll();
- 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, /**/);
- string format = argument;
- if (argument.empty())
- format = buffer->getDefaultOutputFormat();
- buffer->doExport(format, true);
- break;
- }
-
- case LFUN_BUFFER_VIEW: {
- LASSERT(lyx_view_ && buffer, /**/);
- string format = argument;
- if (argument.empty())
- format = buffer->getDefaultOutputFormat();
- buffer->preview(format);
- break;
- }
-
- case LFUN_MASTER_BUFFER_UPDATE: {
- LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
- string format = argument;
- if (argument.empty())
- format = buffer->masterBuffer()->getDefaultOutputFormat();
- buffer->masterBuffer()->doExport(format, true);
- break;
- }
-
- case LFUN_MASTER_BUFFER_VIEW: {
- LASSERT(lyx_view_ && buffer && buffer->masterBuffer(), /**/);
- string format = argument;
- if (argument.empty())
- format = buffer->masterBuffer()->getDefaultOutputFormat();
- buffer->masterBuffer()->preview(format);
- 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;
- }
-
- // 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_utf8(N_("Missing argument")));
- break;
- }
- FileName fname = i18nLibFileSearch("doc", arg, "lyx");
- if (fname.empty())
- fname = i18nLibFileSearch("examples", 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) {
- buf->updateLabels();
- lyx_view_->setBuffer(buf);
- buf->errors("Parse");
- }
- updateFlags = Update::None;
- break;
- }
-
- // --- version control -------------------------------
- case LFUN_VC_REGISTER:
- LASSERT(lyx_view_ && buffer, /**/);
- if (!ensureBufferClean(view()))
- break;
- if (!buffer->lyxvc().inUse()) {
- if (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_LOCKING_TOGGLE:
- LASSERT(lyx_view_ && buffer, /**/);
- if (!ensureBufferClean(view()) || buffer->isReadonly())
- break;
- if (buffer->lyxvc().inUse()) {
- string res = buffer->lyxvc().lockingToggle();
- if (res.empty())
- frontend::Alert::error(_("Revision control error."),
- _("Error when setting the locking property."));
- else {
- setMessage(from_utf8(res));
- 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;
- string const abstmp = package().temp_dir().absFilename();
- string const realtmp = package().temp_dir().realPath();
- // We have to use os::path_prefix_is() here, instead of
- // simply prefixIs(), because the file name comes from
- // an external application and may need case adjustment.
- if (os::path_prefix_is(file_name, abstmp, os::CASE_ADJUSTED)
- || os::path_prefix_is(file_name, realtmp, os::CASE_ADJUSTED)) {
- // Needed by inverse dvi search. If it is a file
- // 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 {
- // 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 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) {
- updateFlags = Update::None;
- break;
- }
-
- buf->updateLabels();
- 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 NOMENCL_PRINT_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 PHANTOM_CODE: {
- InsetPhantomParams p;
- data = InsetPhantom::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);
- child->masterBuffer()->updateLabels();
- 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;
- }
-