X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLyXFunc.cpp;h=27f558a5fbb4cfff95810d829d61f6356ced4813;hb=608603a31d6ae4e3d08ae4e9c18a11d9e705dcf4;hp=490d0f6757e8f3e8f86b2446b76efec6a7379d94;hpb=699fd5a7b45e512e78cbee7ec9317280a51cd38f;p=lyx.git diff --git a/src/LyXFunc.cpp b/src/LyXFunc.cpp index 490d0f6757..27f558a5fb 100644 --- a/src/LyXFunc.cpp +++ b/src/LyXFunc.cpp @@ -18,6 +18,7 @@ */ #include +#include #include "LyXFunc.h" @@ -67,6 +68,7 @@ #include "insets/InsetERT.h" #include "insets/InsetExternal.h" #include "insets/InsetFloat.h" +#include "insets/InsetListings.h" #include "insets/InsetGraphics.h" #include "insets/InsetInclude.h" #include "insets/InsetNote.h" @@ -271,7 +273,7 @@ void LyXFunc::gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer) // see http://bugzilla.lyx.org/show_bug.cgi?id=3092 if (bm.bottom_pit != new_pit || bm.bottom_pos != new_pos || bm.top_id != new_id ) const_cast(bm).updatePos(new_pit, new_pos, new_id); - } + } } @@ -519,6 +521,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case Inset::BOX_CODE: enable = cmd.argument() == "box"; break; + case Inset::LISTINGS_CODE: + enable = cmd.argument() == "listings"; + break; default: break; } @@ -546,6 +551,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case LFUN_DIALOG_TOGGLE: flag.setOnOff(lyx_view_->getDialogs().visible(cmd.getArg(0))); + // fall through to set "enable" case LFUN_DIALOG_SHOW: { string const name = cmd.getArg(0); if (!buf) @@ -557,7 +563,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const enable = Exporter::isExportable(*buf, "dvi") && lyxrc.print_command != "none"; else if (name == "character") - enable = cur.inset().lyxCode() != Inset::ERT_CODE; + enable = cur.inset().lyxCode() != Inset::ERT_CODE && + cur.inset().lyxCode() != Inset::LISTINGS_CODE; else if (name == "latexlog") enable = isFileReadable(FileName(buf->getLogName().second)); else if (name == "spellchecker") @@ -572,7 +579,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const } case LFUN_DIALOG_SHOW_NEW_INSET: - enable = cur.inset().lyxCode() != Inset::ERT_CODE; + enable = cur.inset().lyxCode() != Inset::ERT_CODE && + cur.inset().lyxCode() != Inset::LISTINGS_CODE; if (cur.inset().lyxCode() == Inset::CAPTION_CODE) { FuncStatus flag; if (cur.inset().getStatus(cur, cmd, flag)) @@ -609,10 +617,13 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const enable = LyX::ref().session().bookmarks().size() > 0; break; - case LFUN_TOOLBAR_TOGGLE_STATE: { - ToolbarInfo::Flags flags = lyx_view_->getToolbarState(to_utf8(cmd.argument())); - if (!(flags & ToolbarInfo::AUTO)) - flag.setOnOff(flags & ToolbarInfo::ON); + case LFUN_TOOLBAR_TOGGLE: { + bool const current = lyx_view_->getToolbars().visible(cmd.getArg(0)); + flag.setOnOff(current); + break; + } + case LFUN_WINDOW_CLOSE: { + enable = (theApp()->gui().viewIds().size() > 1); break; } @@ -676,7 +687,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case LFUN_BUFFER_NEXT: case LFUN_BUFFER_PREVIOUS: case LFUN_WINDOW_NEW: - case LFUN_WINDOW_CLOSE: case LFUN_LYX_QUIT: // these are handled in our dispatch() break; @@ -881,7 +891,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) menuWrite(lyx_view_->buffer()); lyx_view_->message(str + _(" done.")); } else { - writeAs(lyx_view_->buffer()); + writeAs(lyx_view_->buffer()); } updateFlags = Update::None; break; @@ -898,7 +908,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) 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, 0, 1, _("&Revert"), _("&Cancel")); + text, 1, 1, _("&Revert"), _("&Cancel")); if (ret == 0) reloadBuffer(); @@ -1050,6 +1060,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd) 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)); @@ -1061,10 +1073,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd) if (fs::exists(filename.toFilesystemEncoding())) { docstring text = bformat( _("The file %1$s already exists.\n\n" - "Do you want to over-write that file?"), + "Do you want to overwrite that file?"), makeDisplayPath(filename.absFilename())); - if (Alert::prompt(_("Over-write file?"), - text, 0, 1, _("&Over-write"), _("&Cancel")) != 0) + if (Alert::prompt(_("Overwrite file?"), + text, 0, 1, _("&Overwrite"), _("&Cancel")) != 0) break; } command += lyxrc.print_to_file @@ -1316,6 +1328,9 @@ void LyXFunc::dispatch(FuncRequest const & cmd) } else if (name == "float") { InsetFloatParams p; data = InsetFloatMailer::params2string(p); + } else if (name == "listings") { + InsetListingsParams p; + data = InsetListingsMailer::params2string(p); } else if (name == "graphics") { InsetGraphicsParams p; Buffer const & buffer = *lyx_view_->buffer(); @@ -1395,21 +1410,34 @@ void LyXFunc::dispatch(FuncRequest const & cmd) } case LFUN_BUFFER_CHILD_OPEN: { + // takes an optional argument, "|bool", at the end + // indicating whether this file is being opened automatically + // by LyX itself, in which case we will not want to switch + // buffers after opening. The default is false, so in practice + // it is used only when true. BOOST_ASSERT(lyx_view_); - FileName const filename = + int const arglength = argument.length(); + FileName filename; + bool autoOpen = false; + if (argument.substr(arglength - 5, 5) == "|true") { + autoOpen = true; + filename = makeAbsPath(argument.substr(0, arglength - 5), + lyx_view_->buffer()->filePath()); + } else if (argument.substr(arglength - 6, 6) == "|false") { + filename = makeAbsPath(argument.substr(0, arglength - 6), + lyx_view_->buffer()->filePath()); + } else filename = makeAbsPath(argument, lyx_view_->buffer()->filePath()); - setMessage(bformat(_("Opening child document %1$s..."), - makeDisplayPath(filename.absFilename()))); view()->saveBookmark(false); - string const parentfilename = lyx_view_->buffer()->fileName(); - if (theBufferList().exists(filename.absFilename())) - lyx_view_->setBuffer(theBufferList().getBuffer(filename.absFilename())); - else - lyx_view_->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. - lyx_view_->buffer()->setParentName(parentfilename); + if (theBufferList().exists(filename.absFilename())) { + Buffer * buf = theBufferList().getBuffer(filename.absFilename()); + if (!autoOpen) + lyx_view_->setBuffer(buf, true); + else + buf->setParentName(lyx_view_->buffer()->fileName()); + } else + lyx_view_->loadLyXFile(filename, true, true, autoOpen); + break; } @@ -1466,8 +1494,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd) case LFUN_PREFERENCES_SAVE: { lyxrc.write(makeAbsPath("preferences", - package().user_support().absFilename()), - false); + package().user_support().absFilename()), + false); break; } @@ -1611,7 +1639,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) if (defaults.writeFile(FileName(defaults.fileName()))) setMessage(bformat(_("Document defaults saved in %1$s"), - makeDisplayPath(fname))); + makeDisplayPath(fname))); else setErrorMessage(from_ascii(N_("Unable to save document defaults"))); break; @@ -1738,9 +1766,25 @@ void LyXFunc::dispatch(FuncRequest const & cmd) LyX::ref().session().bookmarks().clear(); break; - case LFUN_TOOLBAR_TOGGLE_STATE: - lyx_view_->toggleToolbarState(argument); + case LFUN_TOOLBAR_TOGGLE: { + BOOST_ASSERT(lyx_view_); + string const name = cmd.getArg(0); + bool const allowauto = cmd.getArg(1) == "allowauto"; + lyx_view_->toggleToolbarState(name, allowauto); + ToolbarInfo::Flags const flags = + lyx_view_->getToolbarState(name); + docstring state; + if (flags & ToolbarInfo::ON) + state = _("on"); + else if (flags & ToolbarInfo::OFF) + state = _("off"); + else if (flags & ToolbarInfo::AUTO) + state = _("auto"); + + setMessage(bformat(_("Toolbar \"%1$s\" state set to %2$s"), + from_ascii(name), state)); break; + } default: { BOOST_ASSERT(lyx_view_); @@ -2024,9 +2068,9 @@ void LyXFunc::doImport(string const & argument) docstring const file = makeDisplayPath(lyxfile.absFilename(), 30); docstring text = bformat(_("The document %1$s already exists.\n\n" - "Do you want to over-write that document?"), file); - int const ret = Alert::prompt(_("Over-write document?"), - text, 0, 1, _("&Over-write"), _("&Cancel")); + "Do you want to overwrite that document?"), file); + int const ret = Alert::prompt(_("Overwrite document?"), + text, 0, 1, _("&Overwrite"), _("&Cancel")); if (ret == 1) { lyx_view_->message(_("Canceled.")); @@ -2045,16 +2089,8 @@ void LyXFunc::closeBuffer() // goto bookmark to update bookmark pit. for (size_t i = 0; i < LyX::ref().session().bookmarks().size(); ++i) gotoBookmark(i+1, false, false); - if (theBufferList().close(lyx_view_->buffer(), true) && !quitting) { - if (theBufferList().empty()) { - // need this otherwise SEGV may occur while - // trying to set variables that don't exist - // since there's no current buffer - lyx_view_->getDialogs().hideBufferDependent(); - } else { - lyx_view_->setBuffer(theBufferList().first()); - } - } + + theBufferList().close(lyx_view_->buffer(), true); }