#include "frontends/alert.h"
#include "frontends/Delegates.h"
-#include "frontends/FileDialog.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include "frontends/Selection.h"
}
break;
- case LFUN_FILE_INSERT_PLAINTEXT_PARA:
- // FIXME UNICODE
- insertPlaintextFile(FileName(to_utf8(cmd.argument())), true);
- break;
-
- case LFUN_FILE_INSERT_PLAINTEXT:
- // FIXME UNICODE
- insertPlaintextFile(FileName(to_utf8(cmd.argument())), false);
- break;
-
case LFUN_FONT_STATE:
cur.message(cur.currentState());
break;
// FIXME: Move this out of BufferView again
-docstring BufferView::contentsOfPlaintextFile(FileName const & fname,
- bool asParagraph)
+docstring BufferView::contentsOfPlaintextFile(FileName const & fname)
{
- if (fname.empty()) {
- FileDialog dlg(_("Select file to insert"),
- ( asParagraph
- ? LFUN_FILE_INSERT_PLAINTEXT_PARA
- : LFUN_FILE_INSERT_PLAINTEXT) );
-
- FileDialog::Result result =
- dlg.open(from_utf8(buffer().filePath()),
- FileFilterList(), docstring());
-
- if (result.first == FileDialog::Later)
- return docstring();
-
- if (result.second.empty())
- return docstring();
-
- return contentsOfPlaintextFile(FileName(to_utf8(result.second)), false);
- }
-
if (!fname.isReadableFile()) {
docstring const error = from_ascii(strerror(errno));
docstring const file = makeDisplayPath(fname.absFilename(), 50);
void BufferView::insertPlaintextFile(FileName const & f, bool asParagraph)
{
- docstring const tmpstr = contentsOfPlaintextFile(f, asParagraph);
+ docstring const tmpstr = contentsOfPlaintextFile(f);
if (tmpstr.empty())
return;
cur.innerText()->insertStringAsParagraphs(cur, tmpstr);
else
cur.innerText()->insertStringAsLines(cur, tmpstr);
+
+ updateMetrics();
+ buffer_.changed();
}
} // namespace lyx
void setGuiDelegate(frontend::GuiBufferViewDelegate *);
///
- docstring contentsOfPlaintextFile(support::FileName const & f,
- bool asParagraph);
+ docstring contentsOfPlaintextFile(support::FileName const & f);
// Insert plain text file (if filename is empty, prompt for one)
void insertPlaintextFile(support::FileName const & f, bool asParagraph);
///
}
+void GuiView::insertPlaintextFile(docstring const & fname,
+ bool asParagraph)
+{
+ BufferView * bv = view();
+ if (!bv)
+ return;
+
+ // FIXME UNICODE
+ FileName filename(to_utf8(fname));
+
+ if (!filename.empty()) {
+ bv->insertPlaintextFile(filename, asParagraph);
+ return;
+ }
+
+ FileDialog dlg(_("Select file to insert"), (asParagraph ?
+ LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT));
+
+ FileDialog::Result result = dlg.open(from_utf8(bv->buffer().filePath()),
+ FileFilterList(), docstring());
+
+ if (result.first == FileDialog::Later)
+ return;
+
+ // FIXME UNICODE
+ filename.set(to_utf8(result.second));
+
+ // check selected filename
+ if (filename.empty()) {
+ // emit message signal.
+ message(_("Canceled."));
+ return;
+ }
+
+ bv->insertPlaintextFile(filename, asParagraph);
+}
+
+
bool GuiView::dispatch(FuncRequest const & cmd)
{
BufferView * bv = view();
case LFUN_FILE_INSERT:
insertLyXFile(cmd.argument());
break;
+ case LFUN_FILE_INSERT_PLAINTEXT_PARA:
+ insertPlaintextFile(cmd.argument(), true);
+ break;
+
+ case LFUN_FILE_INSERT_PLAINTEXT:
+ insertPlaintextFile(cmd.argument(), false);
+ break;
+
case LFUN_TOOLBAR_TOGGLE: {
string const name = cmd.getArg(0);
///
void insertLyXFile(docstring const & fname);
///
+ void insertPlaintextFile(docstring const & fname,
+ bool asParagraph);
+ ///
Inset * getOpenInset(std::string const & name) const;
/// Is the dialog currently visible?
case LFUN_FILE_INSERT_PLAINTEXT: {
// FIXME UNICODE
docstring const tmpstr = cur.bv().contentsOfPlaintextFile(
- FileName(to_utf8(cmd.argument())), false);
+ FileName(to_utf8(cmd.argument())));
if (tmpstr.empty())
break;
cur.recordUndoInset(INSERT_UNDO);