#include "frontends/LyXView.h"
#include "frontends/Menubar.h"
#include "frontends/Toolbars.h"
+#include "frontends/Selection.h"
#include "support/environment.h"
#include "support/FileFilterList.h"
void LyXFunc::setLyXView(LyXView * lv)
{
+ if (!quitting && lyx_view_ && lyx_view_ != lv)
+ // save current selection to the selection buffer to allow
+ // middle-button paste in another window
+ cap::saveSelection(lyx_view_->view()->cursor());
lyx_view_ = lv;
}
enable = buf->lyxvc().inUse();
break;
case LFUN_BUFFER_RELOAD:
- enable = !buf->isUnnamed() && !buf->isClean();
+ enable = !buf->isUnnamed() && fs::exists(buf->fileName())
+ && (!buf->isClean() || buf->isExternallyModified(Buffer::timestamp_method));
break;
case LFUN_INSET_SETTINGS: {
break;
}
+
+ case LFUN_BUFFER_WRITE_ALL: {
+ // We enable the command only if there are some modified buffers
+ Buffer * first = theBufferList().first();
+ bool modified = false;
+ if (first) {
+ Buffer * b = first;
+
+ // We cannot use a for loop as the buffer list is a cycle.
+ do {
+ if (!b->isClean()) {
+ modified = true;
+ break;
+ }
+ b = theBufferList().next(b);
+ } while (b != first);
+ }
+
+ enable = modified;
+
+ break;
+ }
+
case LFUN_BOOKMARK_GOTO: {
const unsigned int num = convert<unsigned int>(to_utf8(cmd.argument()));
enable = LyX::ref().session().bookmarks().isValid(num);
updateFlags = Update::None;
break;
+ case LFUN_BUFFER_WRITE_ALL: {
+ Buffer * first = theBufferList().first();
+ if (first) {
+ Buffer * b = first;
+ lyx_view_->message(_("Saving all documents..."));
+
+ // We cannot use a for loop as the buffer list cycles.
+ do {
+ if (!b->isClean()) {
+ if (!b->isUnnamed()) {
+ menuWrite(b);
+ lyxerr[Debug::ACTION] << "Saved " << b->fileName() << endl;
+ } else
+ writeAs(b);
+ }
+ b = theBufferList().next(b);
+ } while (b != first);
+ lyx_view_->message(_("All documents saved."));
+ }
+
+ updateFlags = Update::None;
+ break;
+ }
+
case LFUN_BUFFER_RELOAD: {
BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
docstring const file = makeDisplayPath(view()->buffer()->fileName(), 20);
case LFUN_BUFFER_PRINT: {
BOOST_ASSERT(lyx_view_ && lyx_view_->buffer());
- string target;
- string target_name;
- string command = split(split(argument, target, ' '),
- target_name, ' ');
+ // 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 << '"' << std::endl;
+ << argument << '"' << endl;
break;
}
if (target != "printer" && target != "file") {
lyxerr << "Unrecognized target \""
- << target << '"' << std::endl;
+ << target << '"' << endl;
break;
}
// case 3: print using a spool
string const psname =
changeExtension(dviname,".ps");
- command += lyxrc.print_to_file
+ command += ' ' + lyxrc.print_to_file
+ quoteName(psname)
+ ' '
+ quoteName(dviname);
string command2 =
- lyxrc.print_spool_command +' ';
+ lyxrc.print_spool_command + ' ';
if (target_name != "default") {
command2 += lyxrc.print_spool_printerprefix
+ target_name
} else {
// case 2: print directly to a printer
if (target_name != "default")
- command += lyxrc.print_to_printer + target_name + ' ';
+ 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, path));
+ FileName const filename(makeAbsPath(target_name,
+ lyx_view_->buffer()->filePath()));
+ FileName const dvifile(makeAbsPath(dviname, path));
if (fs::exists(filename.toFilesystemEncoding())) {
docstring text = bformat(
_("The file %1$s already exists.\n\n"
text, 0, 1, _("&Overwrite"), _("&Cancel")) != 0)
break;
}
- command += lyxrc.print_to_file
+ command += ' ' + lyxrc.print_to_file
+ quoteName(filename.toFilesystemEncoding())
+ ' '
- + quoteName(dviname);
+ + quoteName(dvifile.toFilesystemEncoding());
res = one.startscript(Systemcall::DontWait,
command);
}
case LFUN_BUFFER_SWITCH:
BOOST_ASSERT(lyx_view_);
lyx_view_->setBuffer(theBufferList().getBuffer(argument));
+ updateFlags = Update::Force;
break;
case LFUN_BUFFER_NEXT:
BOOST_ASSERT(lyx_view_);
lyx_view_->setBuffer(theBufferList().next(view()->buffer()));
+ updateFlags = Update::Force;
break;
case LFUN_BUFFER_PREVIOUS:
BOOST_ASSERT(lyx_view_);
lyx_view_->setBuffer(theBufferList().previous(view()->buffer()));
+ updateFlags = Update::Force;
break;
case LFUN_FILE_NEW:
}
case LFUN_DIALOG_HIDE:
- Dialogs::hide(argument, 0);
+ LyX::cref().hideDialogs(argument, 0);
break;
case LFUN_DIALOG_TOGGLE: {
}
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.
+ // 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_);
- int const arglength = argument.length();
+ 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());
+ 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());
view()->saveBookmark(false);
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());
+ 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;
+ lyx_view_->loadLyXFile(filename, true, true, autoOpen);
+
+ // If a screen update is required (in case where auto_open is false),
+ // loadLyXFile() 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;
}
case LFUN_TOGGLE_CURSOR_FOLLOWS_SCROLLBAR:
theApp()->updateColor(lcolor.getFromLyXName(lyx_name));
if (graphicsbg_changed) {
-#ifdef WITH_WARNINGS
-#warning FIXME!! The graphics cache no longer has a changeDisplay method.
-#endif
+ // FIXME: The graphics cache no longer has a changeDisplay method.
#if 0
graphics::GCache::get().changeDisplay(true);
#endif
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);
+ ToolbarInfo * tbi = lyx_view_->getToolbarInfo(name);
+ if (!tbi) {
+ setMessage(bformat(_("Unknown toolbar \"%1$s\""),
+ from_utf8(name)));
+ break;
+ }
docstring state;
- if (flags & ToolbarInfo::ON)
+ if (tbi->flags & ToolbarInfo::ON)
state = _("on");
- else if (flags & ToolbarInfo::OFF)
+ else if (tbi->flags & ToolbarInfo::OFF)
state = _("off");
- else if (flags & ToolbarInfo::AUTO)
+ else if (tbi->flags & ToolbarInfo::AUTO)
state = _("auto");
setMessage(bformat(_("Toolbar \"%1$s\" state set to %2$s"),
- from_ascii(name), state));
+ _(tbi->gui_name), state));
break;
}
&& !lyxaction.funcHasFlag(action, LyXAction::ReadOnly))
view()->buffer()->markDirty();
+ //Do we have a selection?
+ theSelection().haveSelection(view()->cursor().selection());
+
if (view()->cursor().inTexted()) {
lyx_view_->updateLayoutChoice();
}
}
}
- if (!quitting) {
+ if (!quitting && lyx_view_) {
lyx_view_->updateMenubar();
lyx_view_->updateToolbars();
// Some messages may already be translated, so we cannot use _()
Buffer * const b = newFile(filename, templname, !name.empty());
if (b) {
- updateLabels(*b);
+ //updateLabels(*b);
lyx_view_->setBuffer(b);
}
}
// 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);
}