mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-04 08:37:52 +00:00
half of another one
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20784 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
c0afc10375
commit
f39116c9df
src/frontends/qt4
@ -19,7 +19,6 @@
|
||||
#include "GuiBibitem.h"
|
||||
#include "GuiDelimiter.h"
|
||||
#include "GuiDocument.h"
|
||||
#include "GuiEmbeddedFiles.h"
|
||||
#include "GuiExternal.h"
|
||||
#include "GuiGraphics.h"
|
||||
#include "GuiIndex.h"
|
||||
@ -101,6 +100,7 @@ Dialog * createGuiCharacter(LyXView & lv);
|
||||
Dialog * createGuiCitation(LyXView & lv);
|
||||
Dialog * createGuiDelimiter(LyXView & lv);
|
||||
Dialog * createGuiDocument(LyXView & lv);
|
||||
Dialog * createGuiEmbeddedFiles(LyXView & lv);
|
||||
Dialog * createGuiErrorList(LyXView & lv);
|
||||
Dialog * createGuiERT(LyXView & lv);
|
||||
Dialog * createGuiExternal(LyXView & lv);
|
||||
@ -163,8 +163,7 @@ Dialog * Dialogs::build(string const & name)
|
||||
} else if (name == "document") {
|
||||
dialog = new GuiDocumentDialog(lyxview_);
|
||||
} else if (name == "embedding") {
|
||||
dialog = new DockView<ControlEmbeddedFiles, GuiEmbeddedFilesDialog>(
|
||||
guiview, name, Qt::RightDockWidgetArea);
|
||||
dialog = createGuiEmbeddedFiles(lyxview_);
|
||||
} else if (name == "errorlist") {
|
||||
dialog = createGuiErrorList(lyxview_);
|
||||
} else if (name == "ert") {
|
||||
|
@ -11,12 +11,29 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "GuiEmbeddedFiles.h"
|
||||
|
||||
#include "Buffer.h"
|
||||
|
||||
#include "FuncRequest.h"
|
||||
#include "gettext.h"
|
||||
#include "debug.h"
|
||||
#include "Format.h"
|
||||
#include "LyXRC.h"
|
||||
|
||||
#include "frontend_helpers.h"
|
||||
#include "frontends/LyXView.h"
|
||||
|
||||
#include "support/FileFilterList.h"
|
||||
#include "support/convert.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
using support::FileFilterList;
|
||||
|
||||
GuiEmbeddedFilesDialog::GuiEmbeddedFilesDialog
|
||||
(ControlEmbeddedFiles & controller)
|
||||
: controller_(controller)
|
||||
@ -214,6 +231,147 @@ void GuiEmbeddedFilesDialog::on_enableCB_toggled(bool enable)
|
||||
}
|
||||
|
||||
|
||||
|
||||
ControlEmbeddedFiles::ControlEmbeddedFiles(Dialog & parent)
|
||||
: Controller(parent)
|
||||
{}
|
||||
|
||||
|
||||
EmbeddedFiles & ControlEmbeddedFiles::embeddedFiles()
|
||||
{
|
||||
return buffer().embeddedFiles();
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::initialiseParams(string const &)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::updateEmbeddedFiles()
|
||||
{
|
||||
// copy buffer embeddedFiles to a local copy
|
||||
buffer().embeddedFiles().update();
|
||||
buffer().embeddingChanged();
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::dispatchMessage(string const & msg)
|
||||
{
|
||||
// FIXME: the right thing to do? QT guys?
|
||||
// lyx view will only be updated if we do something to the main window. :-)
|
||||
dispatch(FuncRequest(LFUN_MESSAGE, msg));
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::isReadonly()
|
||||
{
|
||||
return buffer().isReadonly();
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::setEmbedding(bool enable)
|
||||
{
|
||||
if (embeddedFiles().enabled() == enable)
|
||||
return;
|
||||
embeddedFiles().enable(enable);
|
||||
buffer().markDirty();
|
||||
if (enable)
|
||||
dispatchMessage("Stop saving in bundled format.");
|
||||
else
|
||||
dispatchMessage("Save in bundled format.");
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::goTo(EmbeddedFile const & item, int idx)
|
||||
{
|
||||
BOOST_ASSERT(idx < item.refCount());
|
||||
item.saveBookmark(&buffer(), idx);
|
||||
lyxview().dispatch(FuncRequest(LFUN_BOOKMARK_GOTO, "0"));
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::view(EmbeddedFile const & item)
|
||||
{
|
||||
formats.view(buffer(), item, formats.getFormatFromFile(item));
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed, bool update)
|
||||
{
|
||||
if (item.embedded() == embed)
|
||||
return;
|
||||
item.setEmbed(embed);
|
||||
if (update) {
|
||||
if (embed)
|
||||
item.updateFromExternalFile(&buffer());
|
||||
else
|
||||
item.extract(&buffer());
|
||||
item.updateInsets(&buffer());
|
||||
// FIXME: unless we record the type of file item, we will
|
||||
// need to update all possible dialogs (bibtex etc).
|
||||
updateDialog("graphics");
|
||||
}
|
||||
if (embed)
|
||||
dispatchMessage("Embed file " + item.outputFilename(buffer().filePath()));
|
||||
else
|
||||
dispatchMessage("Stop embedding file " + item.outputFilename(buffer().filePath()));
|
||||
buffer().markDirty();
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::browseAndAddFile()
|
||||
{
|
||||
std::pair<docstring, docstring> dir1(_("Documents|#o#O"),
|
||||
from_utf8(lyxrc.document_path));
|
||||
FileFilterList const filter(_("All file (*.*)"));
|
||||
docstring const file = browseRelFile(docstring(), from_utf8(bufferFilepath()),
|
||||
_("Select a file to embed"),
|
||||
filter, false, dir1);
|
||||
if (!file.empty()) {
|
||||
EmbeddedFile & ef = embeddedFiles().registerFile(to_utf8(file), true);
|
||||
if (embeddedFiles().enabled())
|
||||
ef.updateFromExternalFile(&buffer());
|
||||
buffer().markDirty();
|
||||
dispatchMessage("Add an embedded file" + to_utf8(file));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::extract(EmbeddedFile const & item)
|
||||
{
|
||||
if (item.embedded())
|
||||
return item.extract(&buffer());
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::update(EmbeddedFile const & item)
|
||||
{
|
||||
if (item.embedded())
|
||||
return item.updateFromExternalFile(&buffer());
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
GuiEmbeddedFiles::GuiEmbeddedFiles(LyXView & lv)
|
||||
: DockView<ControlEmbeddedFiles, GuiEmbeddedFilesDialog>(
|
||||
static_cast<GuiViewBase &>(lv),
|
||||
"embedded", Qt::RightDockWidgetArea)
|
||||
{}
|
||||
|
||||
|
||||
Dialog * createGuiEmbeddedFiles(LyXView & lv)
|
||||
{
|
||||
return new GuiEmbeddedFiles(lv);
|
||||
}
|
||||
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
|
@ -13,13 +13,59 @@
|
||||
#define GUIEMBEDDEDFILES_H
|
||||
|
||||
#include "GuiDialog.h"
|
||||
#include "DockView.h"
|
||||
#include "EmbeddedFiles.h"
|
||||
#include "ControlEmbeddedFiles.h"
|
||||
#include "ui_EmbeddedFilesUi.h"
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
class ControlEmbeddedFiles : public Controller {
|
||||
public:
|
||||
///
|
||||
ControlEmbeddedFiles(Dialog &);
|
||||
///
|
||||
~ControlEmbeddedFiles() {}
|
||||
///
|
||||
EmbeddedFiles & embeddedFiles();
|
||||
///
|
||||
bool initialiseParams(std::string const &);
|
||||
/// obtain embedded files from buffer
|
||||
void updateEmbeddedFiles();
|
||||
///
|
||||
void clearParams() {}
|
||||
///
|
||||
bool isBufferDependent() const { return true; }
|
||||
///
|
||||
bool canApply() const { return true; }
|
||||
///
|
||||
bool canApplyToReadOnly() const { return false; }
|
||||
///
|
||||
void dispatchMessage(std::string const & msg);
|
||||
///
|
||||
void dispatchParams() {}
|
||||
///
|
||||
bool isReadonly();
|
||||
///
|
||||
void setEmbedding(bool enable);
|
||||
///
|
||||
void goTo(EmbeddedFile const & item, int idx);
|
||||
///
|
||||
void view(EmbeddedFile const & item);
|
||||
///
|
||||
void setEmbed(EmbeddedFile & item, bool embed, bool update);
|
||||
///
|
||||
bool browseAndAddFile();
|
||||
///
|
||||
bool extract(EmbeddedFile const & item);
|
||||
///
|
||||
bool update(EmbeddedFile const & item);
|
||||
|
||||
protected:
|
||||
//
|
||||
std::string message_;
|
||||
};
|
||||
|
||||
class GuiEmbeddedFilesDialog : public QWidget, public Ui::GuiEmbeddedFilesUi
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -50,6 +96,15 @@ private:
|
||||
void set_embedding_status(bool embed);
|
||||
};
|
||||
|
||||
|
||||
class GuiEmbeddedFiles
|
||||
: public DockView<ControlEmbeddedFiles, GuiEmbeddedFilesDialog>
|
||||
{
|
||||
public:
|
||||
GuiEmbeddedFiles(LyXView & lv);
|
||||
};
|
||||
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user