mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Embedding: bring embedding dialog back to shape
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20129 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
92065820e5
commit
e9a2729037
@ -139,7 +139,7 @@ bool EmbeddedFile::extract(Buffer const * buf) const
|
||||
}
|
||||
|
||||
|
||||
bool EmbeddedFile::embed(Buffer const * buf)
|
||||
bool EmbeddedFile::update(Buffer const * buf) const
|
||||
{
|
||||
string ext_file = absFilename();
|
||||
string emb_file = embeddedFile(buf);
|
||||
@ -161,17 +161,16 @@ bool EmbeddedFile::embed(Buffer const * buf)
|
||||
if (!fs::is_directory(path))
|
||||
makedir(const_cast<char*>(path.c_str()), 0755);
|
||||
fs::copy_file(ext_file, emb_file, false);
|
||||
embedded_ = true;
|
||||
} catch (fs::filesystem_error const & fe) {
|
||||
Alert::error(_("Copy file failure"),
|
||||
bformat(_("Cannot copy file %1$s to %2$s.\n"
|
||||
"Please check whether the directory exists and is writeable."),
|
||||
from_utf8(ext_file), from_utf8(emb_file)));
|
||||
LYXERR(Debug::DEBUG) << "Fs error: " << fe.what() << endl;
|
||||
embedded_ = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return embedded_;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -207,7 +206,8 @@ void EmbeddedFiles::registerFile(string const & filename,
|
||||
// find this filename
|
||||
if (it != file_list_.end()) {
|
||||
it->setParIter(pit);
|
||||
it->embed(buffer_);
|
||||
it->update(buffer_);
|
||||
it->setEmbed(true);
|
||||
it->validate();
|
||||
return;
|
||||
}
|
||||
|
@ -127,6 +127,9 @@ public:
|
||||
|
||||
/// embedding status of this file
|
||||
bool embedded() const { return embedded_; }
|
||||
/// set embedding status. update() should be called before this
|
||||
/// to sync the embedded file with external one.
|
||||
bool setEmbed(bool embed) { embedded_ = embed; }
|
||||
|
||||
// A flag indicating whether or not this filename is valid.
|
||||
// When lyx runs, InsetGraphics etc may be added or removed so filename
|
||||
@ -137,10 +140,11 @@ public:
|
||||
bool valid() const { return valid_; }
|
||||
void validate() { valid_ = true; }
|
||||
void invalidate() { valid_ = false; }
|
||||
///
|
||||
|
||||
/// extract file, does not change embedding status
|
||||
bool extract(Buffer const * buf) const;
|
||||
///
|
||||
bool embed(Buffer const * buf);
|
||||
/// update embedded file from external file, does not change embedding status
|
||||
bool update(Buffer const * buf) const;
|
||||
|
||||
private:
|
||||
/// filename in zip file
|
||||
|
@ -59,10 +59,11 @@ void ControlEmbeddedFiles::updateEmbeddedFiles()
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::dispatchParams()
|
||||
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. :-)
|
||||
kernel().dispatch(FuncRequest(LFUN_MESSAGE, message_));
|
||||
kernel().dispatch(FuncRequest(LFUN_MESSAGE, msg));
|
||||
}
|
||||
|
||||
|
||||
@ -82,6 +83,16 @@ void ControlEmbeddedFiles::view(EmbeddedFile const & item)
|
||||
}
|
||||
|
||||
|
||||
void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed)
|
||||
{
|
||||
if (embed)
|
||||
item.update(&kernel().buffer());
|
||||
else
|
||||
item.extract(&kernel().buffer());
|
||||
item.setEmbed(embed);
|
||||
}
|
||||
|
||||
|
||||
docstring const ControlEmbeddedFiles::browseFile()
|
||||
{
|
||||
std::pair<docstring, docstring> dir1(_("Documents|#o#O"),
|
||||
@ -99,5 +110,10 @@ bool ControlEmbeddedFiles::extract(EmbeddedFile const & item)
|
||||
}
|
||||
|
||||
|
||||
bool ControlEmbeddedFiles::update(EmbeddedFile const & item)
|
||||
{
|
||||
return item.update(&kernel().buffer());
|
||||
}
|
||||
|
||||
} // namespace frontend
|
||||
} // namespace lyx
|
||||
|
@ -40,17 +40,21 @@ public:
|
||||
///
|
||||
virtual bool canApplyToReadOnly() const { return true; }
|
||||
///
|
||||
void setMessage(std::string const & msg) { message_ = msg; }
|
||||
void dispatchMessage(std::string const & msg);
|
||||
///
|
||||
void dispatchParams();
|
||||
void dispatchParams() {};
|
||||
///
|
||||
void goTo(EmbeddedFile const & item);
|
||||
///
|
||||
void view(EmbeddedFile const & item);
|
||||
///
|
||||
void setEmbed(EmbeddedFile & item, bool embed);
|
||||
///
|
||||
docstring const browseFile();
|
||||
///
|
||||
bool extract(EmbeddedFile const & item);
|
||||
///
|
||||
bool update(EmbeddedFile const & item);
|
||||
|
||||
protected:
|
||||
//
|
||||
|
@ -17,10 +17,6 @@
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
static QString const INVALID_COLOR = "gray";
|
||||
static QString const EMBEDDED_COLOR = "black";
|
||||
static QString const EXTERNAL_COLOR = "blue";
|
||||
|
||||
|
||||
GuiEmbeddedFilesDialog::GuiEmbeddedFilesDialog(LyXView & lv)
|
||||
: GuiDialog(lv, "embedding")
|
||||
@ -44,34 +40,56 @@ ControlEmbeddedFiles & GuiEmbeddedFilesDialog::controller() const
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_filesLW_itemChanged(QListWidgetItem* item)
|
||||
{
|
||||
EmbeddedFiles & files = controller().embeddedFiles();
|
||||
if (item->checkState() == Qt::Checked) {
|
||||
controller().setEmbed(files[filesLW->row(item)], true);
|
||||
controller().dispatchMessage("Embed file " + fromqstr(item->text()));
|
||||
} else {
|
||||
controller().setEmbed(files[filesLW->row(item)], false);
|
||||
controller().dispatchMessage("Stop embedding file " + fromqstr(item->text()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged()
|
||||
{
|
||||
EmbeddedFiles & files = controller().embeddedFiles();
|
||||
|
||||
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
||||
|
||||
if (selection.empty()) {
|
||||
fullpathLE->setEnabled(false);
|
||||
selectPB->setEnabled(false);
|
||||
unselectPB->setEnabled(false);
|
||||
extractPB->setEnabled(false);
|
||||
updatePB->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
fullpathLE->setEnabled(selection.size() == 1);
|
||||
|
||||
// try to find a common mode, otherwise return NONE.
|
||||
// try to find a common embedding status
|
||||
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
|
||||
controller().goTo(files[idx]);
|
||||
}
|
||||
|
||||
bool mode = false;
|
||||
// are the items all selected or unselected?
|
||||
bool hasSelected = false;
|
||||
bool hasUnselected = false;
|
||||
for (; it != it_end; ++it) {
|
||||
int idx = filesLW->row(*it);
|
||||
if (mode) {
|
||||
mode = true;
|
||||
continue;
|
||||
}
|
||||
if ((*it)->checkState() == Qt::Checked)
|
||||
hasSelected = true;
|
||||
else
|
||||
hasUnselected = true;
|
||||
}
|
||||
|
||||
selectPB->setEnabled(hasUnselected);
|
||||
unselectPB->setEnabled(hasSelected);
|
||||
}
|
||||
|
||||
|
||||
@ -86,25 +104,48 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemDoubleClicked()
|
||||
void GuiEmbeddedFilesDialog::updateView()
|
||||
{
|
||||
filesLW->clear();
|
||||
|
||||
//
|
||||
EmbeddedFiles const & files = controller().embeddedFiles();
|
||||
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);
|
||||
else if(it->embedded())
|
||||
item->setTextColor(EMBEDDED_COLOR);
|
||||
Qt::ItemFlags flag = Qt::ItemIsUserCheckable | Qt::ItemIsSelectable;
|
||||
if (it->valid())
|
||||
flag |= Qt::ItemIsEnabled;
|
||||
item->setFlags(flag);
|
||||
if(it->embedded())
|
||||
item->setCheckState(Qt::Checked);
|
||||
else
|
||||
item->setTextColor(EXTERNAL_COLOR);
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
filesLW->addItem(item);
|
||||
}
|
||||
//
|
||||
bool enabled = files.enabled();
|
||||
enableCB->setChecked(enabled);
|
||||
fullpathLE->setEnabled(enabled);
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_selectPB_clicked()
|
||||
{
|
||||
EmbeddedFiles & files = controller().embeddedFiles();
|
||||
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
||||
for (QList<QListWidgetItem*>::iterator it = selection.begin();
|
||||
it != selection.end(); ++it) {
|
||||
(*it)->setCheckState(Qt::Checked);
|
||||
controller().setEmbed(files[filesLW->row(*it)], true);
|
||||
}
|
||||
controller().dispatchMessage("Embedding files");
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_unselectPB_clicked()
|
||||
{
|
||||
EmbeddedFiles & files = controller().embeddedFiles();
|
||||
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
||||
for (QList<QListWidgetItem*>::iterator it = selection.begin();
|
||||
it != selection.end(); ++it) {
|
||||
(*it)->setCheckState(Qt::Checked);
|
||||
controller().setEmbed(files[filesLW->row(*it)], false);
|
||||
}
|
||||
controller().dispatchMessage("Stop embedding files");
|
||||
}
|
||||
|
||||
|
||||
@ -114,7 +155,8 @@ void GuiEmbeddedFilesDialog::on_addPB_clicked()
|
||||
if (!file.empty()) {
|
||||
EmbeddedFiles & files = controller().embeddedFiles();
|
||||
files.registerFile(to_utf8(file), true);
|
||||
}
|
||||
}
|
||||
controller().dispatchMessage("Add an embedded file");
|
||||
}
|
||||
|
||||
|
||||
@ -125,46 +167,33 @@ void GuiEmbeddedFilesDialog::on_extractPB_clicked()
|
||||
for (QList<QListWidgetItem*>::iterator it = selection.begin();
|
||||
it != selection.end(); ++it)
|
||||
controller().extract(files[filesLW->row(*it)]);
|
||||
// FIXME: collect extraction status and display a dialog
|
||||
controller().dispatchMessage("Extract embedded files");
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_updatePB_clicked()
|
||||
{
|
||||
EmbeddedFiles const & files = controller().embeddedFiles();
|
||||
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
||||
for (QList<QListWidgetItem*>::iterator it = selection.begin();
|
||||
it != selection.end(); ++it)
|
||||
controller().update(files[filesLW->row(*it)]);
|
||||
// FIXME: collect update status and display a dialog
|
||||
controller().dispatchMessage("Update embedded files from external file");
|
||||
}
|
||||
|
||||
|
||||
|
||||
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!!!
|
||||
//
|
||||
controller().embeddedFiles().enable(enable);
|
||||
// immediately post the change to buffer (and bufferView)
|
||||
if (enable)
|
||||
controller().setMessage("Enable file embedding");
|
||||
controller().dispatchMessage("Enable file embedding");
|
||||
else
|
||||
controller().setMessage("Disable file embedding");
|
||||
// update bufferView
|
||||
controller().dispatchParams();
|
||||
}
|
||||
|
||||
|
||||
void GuiEmbeddedFilesDialog::set_embedding_status(bool embed)
|
||||
{
|
||||
EmbeddedFiles & files = controller().embeddedFiles();
|
||||
QList<QListWidgetItem *> selection = filesLW->selectedItems();
|
||||
for (QList<QListWidgetItem*>::iterator it = selection.begin();
|
||||
it != selection.end(); ++it) {
|
||||
int row = filesLW->row(*it);
|
||||
// FIXME: mark buffer dirty
|
||||
if(embed)
|
||||
(*it)->setTextColor(EMBEDDED_COLOR);
|
||||
else
|
||||
(*it)->setTextColor(EXTERNAL_COLOR);
|
||||
}
|
||||
if (embed)
|
||||
controller().setMessage("Embed file");
|
||||
else
|
||||
controller().setMessage("Extract file");
|
||||
// update bufferView
|
||||
controller().dispatchParams();
|
||||
controller().dispatchMessage("Disable file embedding");
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,17 +29,19 @@ public:
|
||||
|
||||
public Q_SLOTS:
|
||||
///
|
||||
void on_filesLW_itemChanged(QListWidgetItem* item);
|
||||
void on_filesLW_itemSelectionChanged();
|
||||
///
|
||||
void on_filesLW_itemDoubleClicked();
|
||||
///
|
||||
void updateView();
|
||||
///
|
||||
void on_enableCB_toggled(bool enable);
|
||||
///
|
||||
void on_selectPB_clicked();
|
||||
void on_unselectPB_clicked();
|
||||
void on_addPB_clicked();
|
||||
//
|
||||
void on_extractPB_clicked();
|
||||
void on_updatePB_clicked();
|
||||
|
||||
private:
|
||||
ControlEmbeddedFiles & controller() const;
|
||||
|
@ -8,7 +8,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>145</width>
|
||||
<width>199</width>
|
||||
<height>390</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -25,7 +25,14 @@
|
||||
<item>
|
||||
<widget class="QCheckBox" name="enableCB" >
|
||||
<property name="text" >
|
||||
<string>Enable embedding</string>
|
||||
<string>Save file in bundled format</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label" >
|
||||
<property name="text" >
|
||||
<string>Embedding status</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -60,6 +67,44 @@
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="selectPB" >
|
||||
<property name="toolTip" >
|
||||
<string>Embed selected files</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset>../../../../lib/images/tabular-feature_set-all-lines.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize" >
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="unselectPB" >
|
||||
<property name="toolTip" >
|
||||
<string>Do not embed selected files</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset>../../../../lib/images/tabular-feature_set-all-lines.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize" >
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="addPB" >
|
||||
<property name="toolTip" >
|
||||
@ -82,7 +127,7 @@
|
||||
<item>
|
||||
<widget class="QToolButton" name="extractPB" >
|
||||
<property name="toolTip" >
|
||||
<string>Extract selected file.</string>
|
||||
<string>Extract selected file, without changing embedding status.</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>...</string>
|
||||
@ -107,7 +152,7 @@
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset>../../../../lib/images/copy.png</iconset>
|
||||
<iconset>../../../../lib/images/depth-decrement.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize" >
|
||||
<size>
|
||||
|
Loading…
Reference in New Issue
Block a user