mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
* BufferView:
- dispatch(): transfer LFUN_FILE_INSERT to GuiView::dispatch() - menuInsertLyXFile(): split in BufferView::insertLyXFile() and GuiView::insertLyXFile() git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21923 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
539061ddc8
commit
c68601da9f
@ -894,11 +894,6 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
|
||||
}
|
||||
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);
|
||||
@ -1735,57 +1730,21 @@ void BufferView::updateMetrics()
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
@ -1797,10 +1756,11 @@ void BufferView::menuInsertLyXFile(string const & filenm)
|
||||
res = _("Could not insert document %1$s");
|
||||
}
|
||||
|
||||
updateMetrics();
|
||||
buffer_.changed();
|
||||
// emit message signal.
|
||||
message(bformat(res, disp_fn));
|
||||
buffer_.errors("Parse");
|
||||
updateMetrics();
|
||||
}
|
||||
|
||||
|
||||
|
@ -245,6 +245,8 @@ public:
|
||||
bool asParagraph);
|
||||
// Insert plain text file (if filename is empty, prompt for one)
|
||||
void insertPlaintextFile(support::FileName const & f, bool asParagraph);
|
||||
///
|
||||
void insertLyXFile(support::FileName const & f);
|
||||
|
||||
private:
|
||||
/// noncopyable
|
||||
@ -273,8 +275,6 @@ private:
|
||||
Buffer & buffer_;
|
||||
|
||||
///
|
||||
void menuInsertLyXFile(std::string const & filen);
|
||||
|
||||
void updateOffsetRef();
|
||||
|
||||
struct Private;
|
||||
|
@ -14,8 +14,9 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "GuiView.h"
|
||||
#include "Dialog.h"
|
||||
|
||||
#include "Dialog.h"
|
||||
#include "frontends/FileDialog.h"
|
||||
#include "GuiApplication.h"
|
||||
#include "GuiWorkArea.h"
|
||||
#include "GuiKeySymbol.h"
|
||||
@ -49,9 +50,12 @@
|
||||
#include "ToolbarBackend.h"
|
||||
#include "version.h"
|
||||
|
||||
#include "support/FileFilterList.h"
|
||||
#include "support/FileName.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/os.h"
|
||||
#include "support/Package.h"
|
||||
#include "support/Timeout.h"
|
||||
|
||||
#include <QAction>
|
||||
@ -96,8 +100,11 @@ extern bool quitting;
|
||||
|
||||
namespace frontend {
|
||||
|
||||
using support::addPath;
|
||||
using support::bformat;
|
||||
using support::FileFilterList;
|
||||
using support::FileName;
|
||||
using support::package;
|
||||
using support::trim;
|
||||
|
||||
namespace {
|
||||
@ -1012,6 +1019,57 @@ FuncStatus GuiView::getStatus(FuncRequest const & cmd)
|
||||
}
|
||||
|
||||
|
||||
void GuiView::insertLyXFile(docstring const & fname)
|
||||
{
|
||||
BufferView * bv = view();
|
||||
if (!bv)
|
||||
return;
|
||||
|
||||
// FIXME UNICODE
|
||||
FileName filename(to_utf8(fname));
|
||||
|
||||
if (!filename.empty()) {
|
||||
bv->insertLyXFile(filename);
|
||||
return;
|
||||
}
|
||||
|
||||
// Launch a file browser
|
||||
// FIXME UNICODE
|
||||
string initpath = lyxrc.document_path;
|
||||
string const trypath = bv->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.set(to_utf8(result.second));
|
||||
|
||||
// check selected filename
|
||||
if (filename.empty()) {
|
||||
// emit message signal.
|
||||
message(_("Canceled."));
|
||||
return;
|
||||
}
|
||||
|
||||
bv->insertLyXFile(filename);
|
||||
}
|
||||
|
||||
|
||||
bool GuiView::dispatch(FuncRequest const & cmd)
|
||||
{
|
||||
BufferView * bv = view();
|
||||
@ -1046,6 +1104,10 @@ bool GuiView::dispatch(FuncRequest const & cmd)
|
||||
d.menubar_->openByName(toqstr(cmd.argument()));
|
||||
break;
|
||||
|
||||
case LFUN_FILE_INSERT:
|
||||
insertLyXFile(cmd.argument());
|
||||
break;
|
||||
|
||||
case LFUN_TOOLBAR_TOGGLE: {
|
||||
string const name = cmd.getArg(0);
|
||||
bool const allowauto = cmd.getArg(1) == "allowauto";
|
||||
|
@ -233,6 +233,8 @@ public:
|
||||
void disconnectDialog(std::string const & name);
|
||||
|
||||
private:
|
||||
///
|
||||
void insertLyXFile(docstring const & fname);
|
||||
///
|
||||
Inset * getOpenInset(std::string const & name) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user