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 "Qt2BC.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// GuiEmbeddedFilesDialog
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
#define INVALID_COLOR "gray"
|
|
|
|
#define AUTO_COLOR "green"
|
|
|
|
#define EMBEDDED_COLOR "black"
|
|
|
|
#define EXTERNAL_COLOR "blue"
|
|
|
|
|
|
|
|
GuiEmbeddedFilesDialog::GuiEmbeddedFilesDialog(GuiEmbeddedFiles * form)
|
|
|
|
: form_(form)
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
form_->updateEmbeddedFiles();
|
|
|
|
|
2007-08-31 22:02:34 +00:00
|
|
|
EmbeddedFiles const & files = form_->embeddedFiles();
|
|
|
|
enableCB->setChecked(files.enabled());
|
|
|
|
EmbeddedFiles::EmbeddedFileList::const_iterator it = files.begin();
|
|
|
|
EmbeddedFiles::EmbeddedFileList::const_iterator it_end = files.end();
|
2007-08-31 15:42:35 +00:00
|
|
|
for (; it != it_end; ++it) {
|
|
|
|
QListWidgetItem * item = new QListWidgetItem(toqstr(it->inzipName()));
|
|
|
|
if (!it->valid())
|
|
|
|
item->setTextColor(INVALID_COLOR);
|
|
|
|
else if(it->status() == EmbeddedFile::AUTO)
|
|
|
|
item->setTextColor(AUTO_COLOR);
|
|
|
|
else if(it->status() == EmbeddedFile::EMBEDDED)
|
|
|
|
item->setTextColor(EMBEDDED_COLOR);
|
|
|
|
else
|
|
|
|
item->setTextColor(EXTERNAL_COLOR);
|
|
|
|
filesLW->addItem(item);
|
|
|
|
}
|
|
|
|
filesLW->setCurrentRow(0);
|
|
|
|
//
|
|
|
|
actionCB->addItem("No action");
|
|
|
|
actionCB->addItem("Add file");
|
|
|
|
actionCB->addItem("Extract file");
|
|
|
|
actionCB->addItem("Extract all");
|
|
|
|
actionCB->addItem("Embed all");
|
|
|
|
actionCB->addItem("Embed layout file");
|
|
|
|
actionCB->addItem("View file");
|
|
|
|
actionCB->addItem("Edit file");
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged()
|
|
|
|
{
|
2007-08-31 22:02:34 +00:00
|
|
|
EmbeddedFiles & files = form_->embeddedFiles();
|
2007-08-31 15:42:35 +00:00
|
|
|
|
|
|
|
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
|
|
|
fullpathLE->setEnabled(selection.size() == 1);
|
|
|
|
|
|
|
|
EmbeddedFile::STATUS mode = EmbeddedFile::NONE;
|
|
|
|
// try to find a common mode, otherwise return NONE.
|
|
|
|
for (QList<QListWidgetItem*>::iterator it = selection.begin();
|
|
|
|
it != selection.end(); ++it) {
|
|
|
|
if (selection.size() == 1)
|
2007-08-31 22:02:34 +00:00
|
|
|
fullpathLE->setText(toqstr(files[filesLW->row(*it)].absFilename()));
|
2007-08-31 15:42:35 +00:00
|
|
|
if (mode == EmbeddedFile::NONE) {
|
2007-08-31 22:02:34 +00:00
|
|
|
mode = files[filesLW->row(*it)].status();
|
2007-08-31 15:42:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-08-31 22:02:34 +00:00
|
|
|
if (mode != files[filesLW->row(*it)].status()) {
|
2007-08-31 15:42:35 +00:00
|
|
|
mode = EmbeddedFile::NONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
autoRB->setChecked(mode == EmbeddedFile::AUTO);
|
|
|
|
embeddedRB->setChecked(mode == EmbeddedFile::EMBEDDED);
|
|
|
|
externalRB->setChecked(mode == EmbeddedFile::EXTERNAL);
|
2007-08-31 22:02:34 +00:00
|
|
|
// go to the first selected item
|
|
|
|
form_->goTo(files[filesLW->row(*selection.begin())]);
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_filesLW_itemDoubleClicked()
|
|
|
|
{
|
2007-08-31 22:02:34 +00:00
|
|
|
EmbeddedFiles & files = form_->embeddedFiles();
|
|
|
|
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
|
|
|
form_->view(files[filesLW->row(*selection.begin())]);
|
2007-08-31 15:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::update()
|
|
|
|
{
|
2007-08-31 22:02:34 +00:00
|
|
|
EmbeddedFiles const & files = form_->embeddedFiles();
|
2007-08-31 15:42:35 +00:00
|
|
|
|
2007-08-31 22:02:34 +00:00
|
|
|
bool enabled = files.enabled();
|
2007-08-31 15:42:35 +00:00
|
|
|
enableCB->setChecked(enabled);
|
|
|
|
statusGB->setEnabled(enabled);
|
|
|
|
filesLW->setEnabled(enabled);
|
|
|
|
fullpathLE->setEnabled(enabled);
|
|
|
|
actionCB->setEnabled(enabled);
|
|
|
|
actionPB->setEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_actionPB_clicked()
|
|
|
|
{
|
|
|
|
// FIXME.
|
|
|
|
|
|
|
|
// ACTION
|
|
|
|
string action = fromqstr(actionCB->currentText());
|
|
|
|
if (action == "Add file") {
|
|
|
|
} else if (action == "Extract file") {
|
|
|
|
} else if (action == "Extract all") {
|
|
|
|
} else if (action == "Embed all") {
|
|
|
|
} else if (action == "Embed layout file") {
|
|
|
|
} else if (action == "View file") {
|
|
|
|
} else if (action == "Edit file") {
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_actionCB_stateChanged(int idx)
|
|
|
|
{
|
|
|
|
// valid action, enable action button
|
|
|
|
actionPB->setEnabled(idx != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-08-31 22:02:34 +00:00
|
|
|
form_->embeddedFiles().enable(enable);
|
2007-08-31 15:42:35 +00:00
|
|
|
update();
|
|
|
|
// immediately post the change to buffer (and bufferView)
|
|
|
|
if (enable)
|
|
|
|
form_->setMessage("Enable file embedding");
|
|
|
|
else
|
|
|
|
form_->setMessage("Disable file embedding");
|
|
|
|
// update bufferView
|
|
|
|
form_->dispatchParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::set_embedding_status(EmbeddedFile::STATUS status)
|
|
|
|
{
|
2007-08-31 22:02:34 +00:00
|
|
|
EmbeddedFiles & files = form_->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
|
|
|
|
if (status != files[row].status())
|
|
|
|
files[row].setStatus(status);
|
2007-08-31 15:42:35 +00:00
|
|
|
if(status == EmbeddedFile::AUTO)
|
|
|
|
(*it)->setTextColor(AUTO_COLOR);
|
|
|
|
else if(status == EmbeddedFile::EMBEDDED)
|
|
|
|
(*it)->setTextColor(EMBEDDED_COLOR);
|
|
|
|
else
|
|
|
|
(*it)->setTextColor(EXTERNAL_COLOR);
|
|
|
|
}
|
|
|
|
if (status == EmbeddedFile::AUTO)
|
|
|
|
form_->setMessage("Switch to auto embedding");
|
|
|
|
else if (status == EmbeddedFile::EMBEDDED)
|
|
|
|
form_->setMessage("Switch to always embedding");
|
|
|
|
else
|
|
|
|
form_->setMessage("Switch to never embedding");
|
|
|
|
autoRB->setChecked(status == EmbeddedFile::AUTO);
|
|
|
|
embeddedRB->setChecked(status == EmbeddedFile::EMBEDDED);
|
|
|
|
externalRB->setChecked(status == EmbeddedFile::EXTERNAL);
|
|
|
|
// update bufferView
|
|
|
|
form_->dispatchParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_autoRB_clicked()
|
|
|
|
{
|
|
|
|
set_embedding_status(EmbeddedFile::AUTO);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_embeddedRB_clicked()
|
|
|
|
{
|
|
|
|
set_embedding_status(EmbeddedFile::EMBEDDED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiEmbeddedFilesDialog::on_externalRB_clicked()
|
|
|
|
{
|
|
|
|
set_embedding_status(EmbeddedFile::EXTERNAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#include "GuiEmbeddedFiles_moc.cpp"
|