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-08 04:10:43 +00:00
|
|
|
#include "support/convert.h"
|
2007-08-31 15:42:35 +00:00
|
|
|
|
2007-09-08 04:10:43 +00:00
|
|
|
using std::string;
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-08-31 15:42:35 +00:00
|
|
|
namespace lyx {
|
2007-09-08 04:10:43 +00:00
|
|
|
|
2007-08-31 15:42:35 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2007-09-10 19:02:11 +00:00
|
|
|
GuiEmbeddedFilesDialog::GuiEmbeddedFilesDialog
|
|
|
|
(ControlEmbeddedFiles & controller)
|
2007-09-08 20:04:28 +00:00
|
|
|
: controller_(controller)
|
2007-08-31 15:42:35 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-10 19:02:11 +00:00
|
|
|
setWindowTitle("LyX: " + qt_("Embedded Files"));
|
2007-09-05 20:33:29 +00:00
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-07 16:33:55 +00:00
|
|
|
void GuiEmbeddedFilesDialog::on_filesLW_itemChanged(QListWidgetItem* item)
|
|
|
|
{
|
2007-09-08 20:04:28 +00:00
|
|
|
EmbeddedFiles & files = controller_.embeddedFiles();
|
2007-09-07 16:33:55 +00:00
|
|
|
if (item->checkState() == Qt::Checked) {
|
2007-09-08 04:10:43 +00:00
|
|
|
if (files[filesLW->row(item)].embedded())
|
|
|
|
return;
|
2007-09-11 16:00:16 +00:00
|
|
|
// this should not be needed after EmbeddedFiles are updated correctly.
|
|
|
|
files.update();
|
|
|
|
controller_.setEmbed(files[filesLW->row(item)], true, files.enabled());
|
2007-09-08 20:04:28 +00:00
|
|
|
controller_.dispatchMessage("Embed file " + fromqstr(item->text()));
|
2007-09-07 16:33:55 +00:00
|
|
|
} else {
|
2007-09-08 04:10:43 +00:00
|
|
|
if (!files[filesLW->row(item)].embedded())
|
|
|
|
return;
|
2007-09-11 16:00:16 +00:00
|
|
|
// this should not be needed after EmbeddedFiles are updated correctly.
|
|
|
|
files.update();
|
|
|
|
controller_.setEmbed(files[filesLW->row(item)], false, files.enabled());
|
2007-09-08 20:04:28 +00:00
|
|
|
controller_.dispatchMessage("Stop embedding file " + fromqstr(item->text()));
|
2007-09-07 16:33:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-31 15:42:35 +00:00
|
|
|
void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged()
|
|
|
|
{
|
|
|
|
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
2007-09-02 05:36:39 +00:00
|
|
|
|
2007-09-07 16:33:55 +00:00
|
|
|
if (selection.empty()) {
|
|
|
|
fullpathLE->setEnabled(false);
|
|
|
|
selectPB->setEnabled(false);
|
|
|
|
unselectPB->setEnabled(false);
|
|
|
|
extractPB->setEnabled(false);
|
|
|
|
updatePB->setEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-08-31 15:42:35 +00:00
|
|
|
fullpathLE->setEnabled(selection.size() == 1);
|
2007-09-02 05:36:39 +00:00
|
|
|
|
2007-09-07 16:33:55 +00:00
|
|
|
// try to find a common embedding status
|
|
|
|
bool hasSelected = false;
|
|
|
|
bool hasUnselected = false;
|
2007-09-08 04:10:43 +00:00
|
|
|
QList<QListWidgetItem*>::iterator it = selection.begin();
|
|
|
|
QList<QListWidgetItem*>::iterator it_end = selection.end();
|
2007-09-02 05:36:39 +00:00
|
|
|
for (; it != it_end; ++it) {
|
2007-09-07 16:33:55 +00:00
|
|
|
if ((*it)->checkState() == Qt::Checked)
|
|
|
|
hasSelected = true;
|
|
|
|
else
|
|
|
|
hasUnselected = true;
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
2007-09-07 16:33:55 +00:00
|
|
|
selectPB->setEnabled(hasUnselected);
|
|
|
|
unselectPB->setEnabled(hasSelected);
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-08 04:10:43 +00:00
|
|
|
void GuiEmbeddedFilesDialog::on_filesLW_itemClicked(QListWidgetItem* item)
|
2007-08-31 15:42:35 +00:00
|
|
|
{
|
2007-09-08 20:04:28 +00:00
|
|
|
EmbeddedFiles & files = controller_.embeddedFiles();
|
2007-09-08 04:10:43 +00:00
|
|
|
int idx = filesLW->row(item);
|
|
|
|
fullpathLE->setText(toqstr(files[idx].absFilename()));
|
|
|
|
if (files[idx].refCount() > 1) {
|
|
|
|
// if multiple insets are referred, click again will move
|
|
|
|
// to another inset
|
|
|
|
int k = item->data(Qt::UserRole).toInt();
|
2007-09-08 20:04:28 +00:00
|
|
|
controller_.goTo(files[idx], k);
|
2007-09-08 04:10:43 +00:00
|
|
|
k = (k + 1) % files[idx].refCount();
|
|
|
|
item->setData(Qt::UserRole, k);
|
|
|
|
// update label
|
|
|
|
string label = files[idx].inzipName() + " ("
|
|
|
|
+ convert<string>(k + 1) + "/"
|
|
|
|
+ convert<string>(files[idx].refCount()) + ")";
|
|
|
|
item->setText(toqstr(label));
|
|
|
|
} else
|
2007-09-08 20:04:28 +00:00
|
|
|
controller_.goTo(files[idx], 0);
|
2007-09-08 04:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_filesLW_itemDoubleClicked(QListWidgetItem* item)
|
|
|
|
{
|
2007-09-08 20:04:28 +00:00
|
|
|
EmbeddedFiles & files = controller_.embeddedFiles();
|
|
|
|
controller_.view(files[filesLW->row(item)]);
|
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-08 20:04:28 +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) {
|
2007-09-08 04:10:43 +00:00
|
|
|
string label = it->inzipName();
|
|
|
|
if (it->refCount() > 1)
|
|
|
|
label += " (1/" + convert<string>(it->refCount()) + ")";
|
|
|
|
QListWidgetItem * item = new QListWidgetItem(toqstr(label));
|
2007-09-07 16:33:55 +00:00
|
|
|
Qt::ItemFlags flag = Qt::ItemIsUserCheckable | Qt::ItemIsSelectable;
|
|
|
|
if (it->valid())
|
|
|
|
flag |= Qt::ItemIsEnabled;
|
|
|
|
item->setFlags(flag);
|
|
|
|
if(it->embedded())
|
|
|
|
item->setCheckState(Qt::Checked);
|
2007-09-03 04:03:43 +00:00
|
|
|
else
|
2007-09-07 16:33:55 +00:00
|
|
|
item->setCheckState(Qt::Unchecked);
|
2007-09-08 04:10:43 +00:00
|
|
|
// index of the currently used ParConstIterator
|
|
|
|
item->setData(Qt::UserRole, 0);
|
2007-09-03 04:03:43 +00:00
|
|
|
filesLW->addItem(item);
|
|
|
|
}
|
2007-09-07 16:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_selectPB_clicked()
|
|
|
|
{
|
2007-09-08 20:04:28 +00:00
|
|
|
EmbeddedFiles & files = controller_.embeddedFiles();
|
2007-09-11 16:00:16 +00:00
|
|
|
// this should not be needed after EmbeddedFiles are updated correctly.
|
|
|
|
files.update();
|
2007-09-07 16:33:55 +00:00
|
|
|
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
|
|
|
for (QList<QListWidgetItem*>::iterator it = selection.begin();
|
|
|
|
it != selection.end(); ++it) {
|
|
|
|
(*it)->setCheckState(Qt::Checked);
|
2007-09-11 16:00:16 +00:00
|
|
|
controller_.setEmbed(files[filesLW->row(*it)], true, files.enabled());
|
2007-09-07 16:33:55 +00:00
|
|
|
}
|
2007-09-08 20:04:28 +00:00
|
|
|
controller_.dispatchMessage("Embedding files");
|
2007-09-07 16:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_unselectPB_clicked()
|
|
|
|
{
|
2007-09-08 20:04:28 +00:00
|
|
|
EmbeddedFiles & files = controller_.embeddedFiles();
|
2007-09-11 16:00:16 +00:00
|
|
|
// this should not be needed after EmbeddedFiles are updated correctly.
|
|
|
|
files.update();
|
2007-09-07 16:33:55 +00:00
|
|
|
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
|
|
|
for (QList<QListWidgetItem*>::iterator it = selection.begin();
|
|
|
|
it != selection.end(); ++it) {
|
|
|
|
(*it)->setCheckState(Qt::Checked);
|
2007-09-11 16:00:16 +00:00
|
|
|
controller_.setEmbed(files[filesLW->row(*it)], false, files.enabled());
|
2007-09-07 16:33:55 +00:00
|
|
|
}
|
2007-09-08 20:04:28 +00:00
|
|
|
controller_.dispatchMessage("Stop embedding files");
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 20:48:51 +00:00
|
|
|
void GuiEmbeddedFilesDialog::on_addPB_clicked()
|
2007-09-01 04:20:34 +00:00
|
|
|
{
|
2007-09-08 20:04:28 +00:00
|
|
|
docstring const file = controller_.browseFile();
|
2007-09-01 04:20:34 +00:00
|
|
|
if (!file.empty()) {
|
2007-09-08 20:04:28 +00:00
|
|
|
EmbeddedFiles & files = controller_.embeddedFiles();
|
2007-09-07 03:02:24 +00:00
|
|
|
files.registerFile(to_utf8(file), true);
|
2007-09-07 16:33:55 +00:00
|
|
|
}
|
2007-09-08 20:04:28 +00:00
|
|
|
controller_.dispatchMessage("Add an embedded file");
|
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-08 20:04:28 +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-08 20:04:28 +00:00
|
|
|
controller_.extract(files[filesLW->row(*it)]);
|
2007-09-07 16:33:55 +00:00
|
|
|
// FIXME: collect extraction status and display a dialog
|
2007-09-08 20:04:28 +00:00
|
|
|
controller_.dispatchMessage("Extract embedded files");
|
2007-09-07 16:33:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_updatePB_clicked()
|
|
|
|
{
|
2007-09-08 20:04:28 +00:00
|
|
|
EmbeddedFiles const & files = controller_.embeddedFiles();
|
2007-09-07 16:33:55 +00:00
|
|
|
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
|
|
|
for (QList<QListWidgetItem*>::iterator it = selection.begin();
|
|
|
|
it != selection.end(); ++it)
|
2007-09-08 20:04:28 +00:00
|
|
|
controller_.update(files[filesLW->row(*it)]);
|
2007-09-07 16:33:55 +00:00
|
|
|
// FIXME: collect update status and display a dialog
|
2007-09-08 20:04:28 +00:00
|
|
|
controller_.dispatchMessage("Update embedded files from external file");
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-07 16:33:55 +00:00
|
|
|
|
2007-08-31 15:42:35 +00:00
|
|
|
void GuiEmbeddedFilesDialog::on_enableCB_toggled(bool enable)
|
|
|
|
{
|
|
|
|
//
|
2007-09-08 20:04:28 +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-08 20:04:28 +00:00
|
|
|
controller_.dispatchMessage("Enable file embedding");
|
2007-08-31 15:42:35 +00:00
|
|
|
else
|
2007-09-08 20:04:28 +00:00
|
|
|
controller_.dispatchMessage("Disable file embedding");
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#include "GuiEmbeddedFiles_moc.cpp"
|