2007-08-31 15:42:35 +00:00
|
|
|
/**
|
|
|
|
* \file GuiEmbeddedFiles.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Bo Peng
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "GuiEmbeddedFiles.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-08-31 15:42:35 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
static QString const INVALID_COLOR = "gray";
|
|
|
|
static QString const EMBEDDED_COLOR = "black";
|
|
|
|
static QString const EXTERNAL_COLOR = "blue";
|
2007-08-31 15:42:35 +00:00
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
GuiEmbeddedFilesDialog::GuiEmbeddedFilesDialog(LyXView & lv)
|
|
|
|
: GuiDialog(lv, "embedding")
|
2007-08-31 15:42:35 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
setController(new ControlEmbeddedFiles(*this));
|
|
|
|
setViewTitle(_("Embedded Files"));
|
|
|
|
|
|
|
|
//setView(new DockView<GuiEmbeddedFiles, GuiEmbeddedFilesDialog>(
|
|
|
|
// *dialog, qef, &gui_view, _("Embedded Files"), Qt::RightDockWidgetArea));
|
|
|
|
|
|
|
|
bc().setPolicy(ButtonPolicy::OkCancelPolicy);
|
|
|
|
|
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ControlEmbeddedFiles & GuiEmbeddedFilesDialog::controller() const
|
|
|
|
{
|
|
|
|
return static_cast<ControlEmbeddedFiles &>(Dialog::controller());
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged()
|
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
EmbeddedFiles & files = controller().embeddedFiles();
|
2007-08-31 15:42:35 +00:00
|
|
|
|
|
|
|
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
2007-09-02 05:36:39 +00:00
|
|
|
|
2007-08-31 15:42:35 +00:00
|
|
|
fullpathLE->setEnabled(selection.size() == 1);
|
2007-09-02 05:36:39 +00:00
|
|
|
|
2007-08-31 15:42:35 +00:00
|
|
|
// try to find a common mode, otherwise return NONE.
|
2007-09-02 05:36:39 +00:00
|
|
|
QList<QListWidgetItem*>::iterator it = selection.begin();
|
|
|
|
QList<QListWidgetItem*>::iterator it_end = selection.end();
|
|
|
|
// if the selection is not empty
|
|
|
|
if (it != it_end) {
|
|
|
|
int idx = filesLW->row(*it);
|
|
|
|
fullpathLE->setText(toqstr(files[idx].absFilename()));
|
|
|
|
// go to the first selected item
|
2007-09-05 20:33:29 +00:00
|
|
|
controller().goTo(files[idx]);
|
2007-09-02 05:36:39 +00:00
|
|
|
}
|
|
|
|
|
2007-09-07 03:02:24 +00:00
|
|
|
bool mode = false;
|
2007-09-02 05:36:39 +00:00
|
|
|
for (; it != it_end; ++it) {
|
|
|
|
int idx = filesLW->row(*it);
|
2007-09-07 03:02:24 +00:00
|
|
|
if (mode) {
|
|
|
|
mode = true;
|
2007-08-31 15:42:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_filesLW_itemDoubleClicked()
|
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
EmbeddedFiles & files = controller().embeddedFiles();
|
2007-08-31 22:02:34 +00:00
|
|
|
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
2007-09-05 20:33:29 +00:00
|
|
|
controller().view(files[filesLW->row(*selection.begin())]);
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-03 20:28:26 +00:00
|
|
|
void GuiEmbeddedFilesDialog::updateView()
|
2007-08-31 15:42:35 +00:00
|
|
|
{
|
2007-09-03 04:03:43 +00:00
|
|
|
filesLW->clear();
|
|
|
|
|
|
|
|
//
|
2007-09-05 20:33:29 +00:00
|
|
|
EmbeddedFiles const & files = controller().embeddedFiles();
|
2007-09-03 04:03:43 +00:00
|
|
|
EmbeddedFiles::EmbeddedFileList::const_iterator it = files.begin();
|
|
|
|
EmbeddedFiles::EmbeddedFileList::const_iterator it_end = files.end();
|
|
|
|
for (; it != it_end; ++it) {
|
|
|
|
QListWidgetItem * item = new QListWidgetItem(toqstr(it->inzipName()));
|
|
|
|
if (!it->valid())
|
|
|
|
item->setTextColor(INVALID_COLOR);
|
2007-09-07 03:02:24 +00:00
|
|
|
else if(it->embedded())
|
2007-09-03 04:03:43 +00:00
|
|
|
item->setTextColor(EMBEDDED_COLOR);
|
|
|
|
else
|
|
|
|
item->setTextColor(EXTERNAL_COLOR);
|
|
|
|
filesLW->addItem(item);
|
|
|
|
}
|
|
|
|
//
|
2007-08-31 22:02:34 +00:00
|
|
|
bool enabled = files.enabled();
|
2007-08-31 15:42:35 +00:00
|
|
|
enableCB->setChecked(enabled);
|
|
|
|
fullpathLE->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 20:48:51 +00:00
|
|
|
void GuiEmbeddedFilesDialog::on_addPB_clicked()
|
2007-09-01 04:20:34 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
docstring const file = controller().browseFile();
|
2007-09-01 04:20:34 +00:00
|
|
|
if (!file.empty()) {
|
2007-09-05 20:33:29 +00:00
|
|
|
EmbeddedFiles & files = controller().embeddedFiles();
|
2007-09-07 03:02:24 +00:00
|
|
|
files.registerFile(to_utf8(file), true);
|
2007-09-01 04:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 20:48:51 +00:00
|
|
|
void GuiEmbeddedFilesDialog::on_extractPB_clicked()
|
2007-09-01 20:08:16 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
EmbeddedFiles const & files = controller().embeddedFiles();
|
2007-09-01 20:08:16 +00:00
|
|
|
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
2007-09-01 20:48:51 +00:00
|
|
|
for (QList<QListWidgetItem*>::iterator it = selection.begin();
|
|
|
|
it != selection.end(); ++it)
|
2007-09-05 20:33:29 +00:00
|
|
|
controller().extract(files[filesLW->row(*it)]);
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_enableCB_toggled(bool enable)
|
|
|
|
{
|
|
|
|
// FIXME:
|
|
|
|
//
|
|
|
|
// When a embedded file is turned to disabled, it should save its
|
|
|
|
// embedded files. Otherwise, embedded files will be lost!!!
|
|
|
|
//
|
2007-09-05 20:33:29 +00:00
|
|
|
controller().embeddedFiles().enable(enable);
|
2007-08-31 15:42:35 +00:00
|
|
|
// immediately post the change to buffer (and bufferView)
|
|
|
|
if (enable)
|
2007-09-05 20:33:29 +00:00
|
|
|
controller().setMessage("Enable file embedding");
|
2007-08-31 15:42:35 +00:00
|
|
|
else
|
2007-09-05 20:33:29 +00:00
|
|
|
controller().setMessage("Disable file embedding");
|
2007-08-31 15:42:35 +00:00
|
|
|
// update bufferView
|
2007-09-05 20:33:29 +00:00
|
|
|
controller().dispatchParams();
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-07 03:02:24 +00:00
|
|
|
void GuiEmbeddedFilesDialog::set_embedding_status(bool embed)
|
2007-08-31 15:42:35 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
EmbeddedFiles & files = controller().embeddedFiles();
|
2007-08-31 15:42:35 +00:00
|
|
|
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
|
|
|
for (QList<QListWidgetItem*>::iterator it = selection.begin();
|
|
|
|
it != selection.end(); ++it) {
|
2007-08-31 22:02:34 +00:00
|
|
|
int row = filesLW->row(*it);
|
|
|
|
// FIXME: mark buffer dirty
|
2007-09-07 03:02:24 +00:00
|
|
|
if(embed)
|
2007-08-31 15:42:35 +00:00
|
|
|
(*it)->setTextColor(EMBEDDED_COLOR);
|
|
|
|
else
|
|
|
|
(*it)->setTextColor(EXTERNAL_COLOR);
|
|
|
|
}
|
2007-09-07 03:02:24 +00:00
|
|
|
if (embed)
|
|
|
|
controller().setMessage("Embed file");
|
2007-08-31 15:42:35 +00:00
|
|
|
else
|
2007-09-07 03:02:24 +00:00
|
|
|
controller().setMessage("Extract file");
|
2007-08-31 15:42:35 +00:00
|
|
|
// update bufferView
|
2007-09-05 20:33:29 +00:00
|
|
|
controller().dispatchParams();
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#include "GuiEmbeddedFiles_moc.cpp"
|