Author: vfr
Date: Mon Dec 5 14:12:57 2011
New Revision: 40377
URL: http://www.lyx.org/trac/changeset/40377
Log:
Fix bug #7916: Undo warning message when inserting plaintext file
LFUN_INSERT_PLAINTEXT is handled in GuiView because it might need to ask for a
filename. But if the filename is given as a paramater we can handle it in
BufferView immediately. Also, when we've asked for the filename in GuiView we
should dispatch the LFUN to BufferView in order to properly use the Undo
mechanism.
Modified:
lyx-devel/trunk/src/BufferView.cpp
lyx-devel/trunk/src/frontends/qt4/GuiView.cpp
Modified: lyx-devel/trunk/src/BufferView.cpp
==============================================================================
--- lyx-devel/trunk/src/BufferView.cpp Mon Dec 5 13:40:22 2011 (r40376)
+++ lyx-devel/trunk/src/BufferView.cpp Mon Dec 5 14:12:57 2011 (r40377)
@@ -1034,9 +1034,18 @@
// buffer clean/dirty status by itself.
flag.setEnabled(!buffer_.isReadonly() &&
buffer_.undo().hasRedoStack());
break;
- case LFUN_FILE_INSERT:
case LFUN_FILE_INSERT_PLAINTEXT_PARA:
- case LFUN_FILE_INSERT_PLAINTEXT:
+ case LFUN_FILE_INSERT_PLAINTEXT: {
+ bool enabled = true;
+ docstring const fname = cmd.argument();
+ if (!FileName::isAbsolute(to_utf8(fname))) {
+ flag.message(_("Absolute filename expected."));
+ return false;
+ }
+ flag.setEnabled(enabled && cur.inTexted());
+ break;
+ }
+ case LFUN_FILE_INSERT:
case LFUN_BOOKMARK_SAVE:
// FIXME: Actually, these LFUNS should be moved to Text
flag.setEnabled(cur.inTexted());
@@ -1937,6 +1946,16 @@
cur.setCurrentFont();
dr.forceBufferUpdate();
}
+ }
+
+ case LFUN_FILE_INSERT_PLAINTEXT_PARA:
+ case LFUN_FILE_INSERT_PLAINTEXT: {
+ bool const as_paragraph = (act ==
LFUN_FILE_INSERT_PLAINTEXT_PARA);
+ string const fname = to_utf8(cmd.argument());
+ if (!FileName::isAbsolute(fname))
+ dr.setMessage(_("Absolute filename expected."));
+ else
+ insertPlaintextFile(FileName(fname), as_paragraph);
break;
}
Modified: lyx-devel/trunk/src/frontends/qt4/GuiView.cpp
==============================================================================
--- lyx-devel/trunk/src/frontends/qt4/GuiView.cpp Mon Dec 5 13:40:22
2011 (r40376)
+++ lyx-devel/trunk/src/frontends/qt4/GuiView.cpp Mon Dec 5 14:12:57
2011 (r40377)
@@ -1867,6 +1867,15 @@
enable = !(lyxrc.forward_search_dvi.empty() &&
lyxrc.forward_search_pdf.empty());
break;
+ case LFUN_FILE_INSERT_PLAINTEXT:
+ case LFUN_FILE_INSERT_PLAINTEXT_PARA: {
+ if (BufferView const * bv = documentBufferView())
+ enable = bv->cursor().inTexted();
+ else
+ enable = false;
+ break;
+ }
+
default:
return false;
}
@@ -2228,49 +2237,6 @@
}
-void GuiView::insertPlaintextFile(docstring const & fname,
- bool asParagraph)
-{
- BufferView * bv = documentBufferView();
- if (!bv)
- return;
-
- if (!fname.empty() && !FileName::isAbsolute(to_utf8(fname))) {
- message(_("Absolute filename expected."));
- return;
- }
-
- // FIXME UNICODE
- FileName filename(to_utf8(fname));
-
- if (!filename.empty()) {
- bv->insertPlaintextFile(filename, asParagraph);
- return;
- }
-
- FileDialog dlg(qt_("Select file to insert"), (asParagraph ?
- LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT));
-
- FileDialog::Result result = dlg.open(toqstr(bv->buffer().filePath()),
- QStringList(qt_("All Files (*)")));
-
- if (result.first == FileDialog::Later)
- return;
-
- // FIXME UNICODE
- filename.set(fromqstr(result.second));
-
- // check selected filename
- if (filename.empty()) {
- // emit message signal.
- message(_("Canceled."));
- return;
- }
-
- bv->insertPlaintextFile(filename, asParagraph);
-}
-
-
bool GuiView::renameBuffer(Buffer & b, docstring const & newname)
{
FileName fname = b.fileName();
@@ -3355,13 +3321,37 @@
insertLyXFile(cmd.argument());
break;
- case LFUN_FILE_INSERT_PLAINTEXT_PARA:
- insertPlaintextFile(cmd.argument(), true);
- break;
-
case LFUN_FILE_INSERT_PLAINTEXT:
- insertPlaintextFile(cmd.argument(), false);
+ case LFUN_FILE_INSERT_PLAINTEXT_PARA: {
+ bool const as_paragraph = (cmd.action() ==
LFUN_FILE_INSERT_PLAINTEXT_PARA);
+ string const fname = to_utf8(cmd.argument());
+ if (!fname.empty() && !FileName::isAbsolute(fname)) {
+ dr.setMessage(_("Absolute filename expected."));
+ break;
+ }
+
+ FileName filename(fname);
+ if (fname.empty()) {
+ FileDialog dlg(qt_("Select file to insert"),
(as_paragraph ?
+ LFUN_FILE_INSERT_PLAINTEXT_PARA :
LFUN_FILE_INSERT_PLAINTEXT));
+
+ FileDialog::Result result =
dlg.open(toqstr(bv->buffer().filePath()),
+ QStringList(qt_("All Files (*)")));
+
+ if (result.first == FileDialog::Later ||
result.second.isEmpty()) {
+ dr.setMessage(_("Canceled."));
+ break;
+ }
+
+ filename.set(fromqstr(result.second));
+ }
+
+ if (bv) {
+ FuncRequest const new_cmd(cmd,
filename.absoluteFilePath());
+ bv->dispatch(new_cmd, dr);
+ }
break;
+ }
case LFUN_BUFFER_RELOAD: {
LASSERT(doc_buffer, break);