#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:
- // FIXME UNICODE
- menuInsertLyXFile(to_utf8(cmd.argument()));
- 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;
}
-void BufferView::menuInsertLyXFile(string const & filenm)
+void BufferView::insertLyXFile(FileName const & fname)
{
BOOST_ASSERT(d->cursor_.inTexted());
- string filename = filenm;
-
- if (filename.empty()) {
- // Launch a file browser
- // FIXME UNICODE
- string initpath = lyxrc.document_path;
- string const trypath = buffer_.filePath();
- // If directory is writeable, use this as default.
- if (FileName(trypath).isDirWritable())
- initpath = trypath;
-
- // FIXME UNICODE
- FileDialog dlg(_("Select LyX document to insert"), LFUN_FILE_INSERT);
- dlg.setButton1(_("Documents|#o#O"), from_utf8(lyxrc.document_path));
- dlg.setButton2(_("Examples|#E#e"),
- from_utf8(addPath(package().system_support().absFilename(),
- "examples")));
-
- FileDialog::Result result =
- dlg.open(from_utf8(initpath),
- FileFilterList(_("LyX Documents (*.lyx)")),
- docstring());
-
- if (result.first == FileDialog::Later)
- return;
-
- // FIXME UNICODE
- filename = to_utf8(result.second);
-
- // check selected filename
- if (filename.empty()) {
- // emit message signal.
- message(_("Canceled."));
- return;
- }
- }
// Get absolute path of file and add ".lyx"
// to the filename if necessary
- filename = fileSearch(string(), filename, "lyx").absFilename();
+ FileName filename = fileSearch(string(), fname.absFilename(), "lyx");
- docstring const disp_fn = makeDisplayPath(filename);
+ docstring const disp_fn = makeDisplayPath(filename.absFilename());
// emit message signal.
message(bformat(_("Inserting document %1$s..."), disp_fn));
docstring res;
Buffer buf("", false);
- if (buf.loadLyXFile(FileName(filename))) {
+ if (buf.loadLyXFile(filename)) {
ErrorList & el = buffer_.errorList("Parse");
// Copy the inserted document error list into the current buffer one.
el = buf.errorList("Parse");
res = _("Could not insert document %1$s");
}
+ updateMetrics();
+ buffer_.changed();
// emit message signal.
message(bformat(res, disp_fn));
buffer_.errors("Parse");
- updateMetrics();
}
// 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