mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-24 05:40:59 +00:00
Embedding: add option \extra_embedded_files to buffer params. This increase
LyX file format to 318. The Embedded files panel of document settings has been simplied, with working add and remove buttons. Note that bease BufferParams lacks buffer path information, extraEmbeddedFiles are vector<string>, instead of EmbeddedFileList (as previously planned). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23606 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
63e712c8a4
commit
932998494b
@ -1,6 +1,9 @@
|
||||
LyX file-format changes
|
||||
-----------------------
|
||||
|
||||
2008-03-09 Bo Peng <ben.bob@gmail.com>
|
||||
* Format incremented to 318: add \extra_embedded_files to buffer params
|
||||
|
||||
2008-03-02 Uwe Stöhr <uwestoehr@web.de>
|
||||
* Format incremented to 317: support floating placements for wrap floats
|
||||
|
||||
|
@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)),
|
||||
("1_3", [221], minor_versions("1.3" , 7)),
|
||||
("1_4", range(222,246), minor_versions("1.4" , 5)),
|
||||
("1_5", range(246,277), minor_versions("1.5" , 2)),
|
||||
("1_6", range(277,318), minor_versions("1.6" , 0))] # Uwe: wrap placement
|
||||
("1_6", range(277,319), minor_versions("1.6" , 0))]
|
||||
|
||||
|
||||
def formats_list():
|
||||
|
@ -1380,6 +1380,14 @@ def revert_wrapplacement(document):
|
||||
i = i + 1
|
||||
|
||||
|
||||
def remove_extra_embedded_files(document):
|
||||
"Remove \extra_embedded_files from buffer params"
|
||||
i = find_token(document.header, '\\extra_embedded_files', 0)
|
||||
if i == -1:
|
||||
document.warning("Malformed lyx document: Missing '\\extra_embedded_files'.")
|
||||
return
|
||||
document.header.pop(i)
|
||||
|
||||
##
|
||||
# Conversion hub
|
||||
#
|
||||
@ -1425,10 +1433,12 @@ convert = [[277, [fix_wrong_tables]],
|
||||
[314, []],
|
||||
[315, []],
|
||||
[316, [convert_subfig]],
|
||||
[317, []]
|
||||
[317, []],
|
||||
[318, []],
|
||||
]
|
||||
|
||||
revert = [[316, [revert_wrapplacement]],
|
||||
revert = [[317, [remove_extra_embedded_files]],
|
||||
[316, [revert_wrapplacement]],
|
||||
[315, [revert_subfig]],
|
||||
[314, [revert_colsep]],
|
||||
[313, []],
|
||||
|
@ -117,7 +117,7 @@ namespace os = support::os;
|
||||
|
||||
namespace {
|
||||
|
||||
int const LYX_FORMAT = 317; // Uwe Stöhr: float placement support for wrap floats
|
||||
int const LYX_FORMAT = 318;
|
||||
|
||||
typedef map<string, bool> DepClean;
|
||||
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
|
||||
|
@ -275,6 +275,7 @@ public:
|
||||
|
||||
AuthorList authorlist;
|
||||
BranchList branchlist;
|
||||
vector<string> extraEmbeddedFiles;
|
||||
Bullet temp_bullets[4];
|
||||
Bullet user_defined_bullets[4];
|
||||
Spacing spacing;
|
||||
@ -379,6 +380,18 @@ AuthorList const & BufferParams::authors() const
|
||||
}
|
||||
|
||||
|
||||
vector<string> & BufferParams::extraEmbeddedFiles()
|
||||
{
|
||||
return pimpl_->extraEmbeddedFiles;
|
||||
}
|
||||
|
||||
|
||||
vector<string> const & BufferParams::extraEmbeddedFiles() const
|
||||
{
|
||||
return pimpl_->extraEmbeddedFiles;
|
||||
}
|
||||
|
||||
|
||||
BranchList & BufferParams::branchlist()
|
||||
{
|
||||
return pimpl_->branchlist;
|
||||
@ -658,6 +671,16 @@ string const BufferParams::readToken(Lexer & lex, string const & token,
|
||||
toktmp << endl;
|
||||
return toktmp;
|
||||
}
|
||||
} else if (token == "\\extra_embedded_files") {
|
||||
extraEmbeddedFiles().clear();
|
||||
string par;
|
||||
lex >> par;
|
||||
string tmp;
|
||||
par = split(par, tmp, ',');
|
||||
while (!tmp.empty()) {
|
||||
extraEmbeddedFiles().push_back(tmp);
|
||||
par = split(par, tmp, ',');
|
||||
}
|
||||
} else {
|
||||
lyxerr << "BufferParams::readToken(): Unknown token: " <<
|
||||
token << endl;
|
||||
@ -811,6 +834,19 @@ void BufferParams::writeFile(ostream & os) const
|
||||
else
|
||||
os << "\\author " << Author() << "\n";
|
||||
}
|
||||
|
||||
vector<string>::const_iterator e_it = extraEmbeddedFiles().begin();
|
||||
vector<string>::const_iterator e_end = extraEmbeddedFiles().end();
|
||||
os << "\\extra_embedded_files \"";
|
||||
bool first = true;
|
||||
for (; e_it != e_end; ++e_it) {
|
||||
if (!first)
|
||||
os << ",";
|
||||
else
|
||||
first = false;
|
||||
os << *e_it;
|
||||
}
|
||||
os << "\"\n";
|
||||
}
|
||||
|
||||
|
||||
|
@ -270,6 +270,9 @@ public:
|
||||
bool compressed;
|
||||
///
|
||||
bool embedded;
|
||||
///
|
||||
std::vector<std::string> & extraEmbeddedFiles();
|
||||
std::vector<std::string> const & extraEmbeddedFiles() const;
|
||||
|
||||
/// the author list for the document
|
||||
AuthorList & authors();
|
||||
|
@ -59,7 +59,8 @@ void EmbeddedFile::set(std::string const & filename, std::string const & buffer_
|
||||
if (filename.empty())
|
||||
return;
|
||||
|
||||
inzip_name_ = calcInzipName(buffer_path);
|
||||
if (!buffer_path.empty())
|
||||
inzip_name_ = calcInzipName(buffer_path);
|
||||
}
|
||||
|
||||
|
||||
@ -386,8 +387,8 @@ void EmbeddedFileList::enable(bool flag, Buffer & buffer, bool updateFile)
|
||||
|
||||
int count_embedded = 0;
|
||||
int count_external = 0;
|
||||
std::vector<EmbeddedFile>::iterator it = begin();
|
||||
std::vector<EmbeddedFile>::iterator it_end = end();
|
||||
iterator it = begin();
|
||||
iterator it_end = end();
|
||||
// an exception may be thrown
|
||||
for (; it != it_end; ++it) {
|
||||
it->enable(flag, &buffer, updateFile);
|
||||
@ -443,6 +444,7 @@ void EmbeddedFileList::registerFile(EmbeddedFile const & file,
|
||||
return;
|
||||
}
|
||||
//
|
||||
file.clearInsets();
|
||||
push_back(file);
|
||||
back().addInset(inset);
|
||||
}
|
||||
@ -454,6 +456,17 @@ void EmbeddedFileList::update(Buffer const & buffer)
|
||||
|
||||
for (InsetIterator it = inset_iterator_begin(buffer.inset()); it; ++it)
|
||||
it->registerEmbeddedFiles(*this);
|
||||
|
||||
// add extra embedded files
|
||||
vector<string> extra = buffer.params().extraEmbeddedFiles();
|
||||
vector<string>::iterator it = extra.begin();
|
||||
vector<string>::iterator it_end = extra.end();
|
||||
for (; it != it_end; ++it) {
|
||||
EmbeddedFile file = EmbeddedFile(*it, buffer.filePath());
|
||||
file.setEmbed(true);
|
||||
file.enable(buffer.embedded(), &buffer, true);
|
||||
insert(end(), file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -468,8 +481,9 @@ bool EmbeddedFileList::writeFile(DocFileName const & filename, Buffer const & bu
|
||||
filenames.push_back(make_pair(content, "content.lyx"));
|
||||
// prepare list of embedded file
|
||||
update(buffer);
|
||||
std::vector<EmbeddedFile>::iterator it = begin();
|
||||
std::vector<EmbeddedFile>::iterator it_end = end();
|
||||
//
|
||||
iterator it = begin();
|
||||
iterator it_end = end();
|
||||
for (; it != it_end; ++it) {
|
||||
if (it->embedded()) {
|
||||
string file = it->embeddedFile();
|
||||
|
@ -137,7 +137,7 @@ public:
|
||||
|
||||
/// add an inset that refers to this file
|
||||
void addInset(Inset const * inset);
|
||||
int refCount() const { return inset_list_.size(); }
|
||||
void clearInsets() const { inset_list_.clear(); }
|
||||
|
||||
/// embedding status of this file
|
||||
bool embedded() const { return embedded_; }
|
||||
@ -180,7 +180,7 @@ private:
|
||||
bool embedded_;
|
||||
/// Insets that contains this file item. Because a
|
||||
/// file item can be referred by several Insets, a vector is used.
|
||||
std::vector<Inset const *> inset_list_;
|
||||
mutable std::vector<Inset const *> inset_list_;
|
||||
/// Embedded file needs to know whether enbedding is enabled,
|
||||
/// and where is the lyx temporary directory. Such information can
|
||||
/// be retrived from a buffer, but a buffer is not always available when
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "BufferParams.h"
|
||||
#include "BufferView.h"
|
||||
#include "Color.h"
|
||||
#include "EmbeddedFiles.h"
|
||||
#include "Encoding.h"
|
||||
#include "FloatPlacement.h"
|
||||
#include "FuncRequest.h"
|
||||
@ -44,6 +43,7 @@
|
||||
|
||||
#include "support/debug.h"
|
||||
#include "support/FileName.h"
|
||||
#include "support/FileFilterList.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/lstrings.h"
|
||||
|
||||
@ -919,12 +919,10 @@ GuiDocument::GuiDocument(GuiView & lv)
|
||||
|
||||
// embedded files
|
||||
embeddedFilesModule = new UiWidget<Ui::EmbeddedFilesUi>;
|
||||
connect(embeddedFilesModule->bundleCB, SIGNAL(toggled(bool)),
|
||||
this, SLOT(change_adaptor()));
|
||||
connect(embeddedFilesModule->addPB, SIGNAL(clicked()),
|
||||
this, SLOT(change_adaptor()));
|
||||
this, SLOT(addExtraEmbeddedFile()));
|
||||
connect(embeddedFilesModule->removePB, SIGNAL(clicked()),
|
||||
this, SLOT(change_adaptor()));
|
||||
this, SLOT(removeExtraEmbeddedFile()));
|
||||
|
||||
// PDF support
|
||||
pdfSupportModule = new UiWidget<Ui::PDFSupportUi>;
|
||||
@ -1359,28 +1357,32 @@ void GuiDocument::updateModuleInfo()
|
||||
}
|
||||
|
||||
|
||||
void GuiDocument::updateEmbeddedFileList()
|
||||
void GuiDocument::setExtraEmbeddedFileList()
|
||||
{
|
||||
embeddedFilesModule->filesLW->clear();
|
||||
embeddedFilesModule->extraLW->clear();
|
||||
// add current embedded files
|
||||
EmbeddedFileList & files = buffer().embeddedFiles();
|
||||
files.update(buffer());
|
||||
EmbeddedFileList::iterator fit = files.begin();
|
||||
EmbeddedFileList::iterator fit_end = files.end();
|
||||
for (; fit != fit_end; ++fit) {
|
||||
QString label = toqstr(fit->relFilename(buffer().filePath()));
|
||||
if (fit->refCount() > 1)
|
||||
label += " (" + QString::number(fit->refCount()) + ")";
|
||||
QListWidgetItem * item = new QListWidgetItem(label);
|
||||
item->setFlags(item->flags() | Qt::ItemIsSelectable
|
||||
| Qt::ItemIsUserCheckable);
|
||||
if(fit->embedded())
|
||||
item->setCheckState(Qt::Checked);
|
||||
else
|
||||
item->setCheckState(Qt::Unchecked);
|
||||
// index of the currently used ParConstIterator
|
||||
embeddedFilesModule->filesLW->addItem(item);
|
||||
}
|
||||
vector<string> const & files = buffer().params().extraEmbeddedFiles();
|
||||
vector<string>::const_iterator fit = files.begin();
|
||||
vector<string>::const_iterator fit_end = files.end();
|
||||
for (; fit != fit_end; ++fit)
|
||||
embeddedFilesModule->extraLW->addItem(toqstr(*fit));
|
||||
}
|
||||
|
||||
|
||||
void GuiDocument::addExtraEmbeddedFile()
|
||||
{
|
||||
QString file = browseRelFile(QString(), bufferFilepath(),
|
||||
qt_("Extra embedded file"), FileFilterList(), true);
|
||||
|
||||
if (embeddedFilesModule->extraLW->findItems(file, Qt::MatchExactly).empty())
|
||||
embeddedFilesModule->extraLW->addItem(file);
|
||||
}
|
||||
|
||||
|
||||
void GuiDocument::removeExtraEmbeddedFile()
|
||||
{
|
||||
int index = embeddedFilesModule->extraLW->currentRow();
|
||||
delete embeddedFilesModule->extraLW->takeItem(index);
|
||||
}
|
||||
|
||||
|
||||
@ -1688,7 +1690,12 @@ void GuiDocument::apply(BufferParams & params)
|
||||
fromqstr(pdfSupportModule->optionsLE->text()));
|
||||
|
||||
// Embedded files
|
||||
// FIXME
|
||||
vector<string> & files = params.extraEmbeddedFiles();
|
||||
files.clear();
|
||||
for (size_t i = 0; i < embeddedFilesModule->extraLW->count(); ++i) {
|
||||
QListWidgetItem * item = embeddedFilesModule->extraLW->item(i);
|
||||
files.push_back(fromqstr(item->text()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1993,9 +2000,8 @@ void GuiDocument::updateParams(BufferParams const & params)
|
||||
|
||||
pdfSupportModule->optionsLE->setText(
|
||||
toqstr(pdf.quoted_options));
|
||||
|
||||
// embedded files
|
||||
updateEmbeddedFileList();
|
||||
|
||||
setExtraEmbeddedFileList();
|
||||
}
|
||||
|
||||
|
||||
|
@ -137,7 +137,9 @@ private Q_SLOTS:
|
||||
void portraitChanged();
|
||||
void classChanged();
|
||||
void updateModuleInfo();
|
||||
void updateEmbeddedFileList();
|
||||
void setExtraEmbeddedFileList();
|
||||
void addExtraEmbeddedFile();
|
||||
void removeExtraEmbeddedFile();
|
||||
|
||||
private:
|
||||
UiWidget<Ui::TextLayoutUi> *textLayoutModule;
|
||||
|
@ -19,7 +19,31 @@
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="6" column="1" >
|
||||
<item row="0" column="0" >
|
||||
<widget class="QLabel" name="extraLBL" >
|
||||
<property name="text" >
|
||||
<string>Extra embedded files:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item rowspan="3" row="1" column="0" >
|
||||
<widget class="QListWidget" name="extraLW" />
|
||||
</item>
|
||||
<item row="1" column="1" >
|
||||
<widget class="QPushButton" name="addPB" >
|
||||
<property name="text" >
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" >
|
||||
<widget class="QPushButton" name="removePB" >
|
||||
<property name="text" >
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -32,47 +56,6 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="5" column="1" >
|
||||
<widget class="QPushButton" name="removePB" >
|
||||
<property name="text" >
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1" >
|
||||
<widget class="QPushButton" name="addPB" >
|
||||
<property name="text" >
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item rowspan="3" row="4" column="0" >
|
||||
<widget class="QListWidget" name="extraLW" />
|
||||
</item>
|
||||
<item row="3" column="0" >
|
||||
<widget class="QLabel" name="extraLBL" >
|
||||
<property name="text" >
|
||||
<string>Extra embedded files:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" >
|
||||
<widget class="QListWidget" name="filesLW" />
|
||||
</item>
|
||||
<item row="0" column="0" >
|
||||
<widget class="QCheckBox" name="bundleCB" >
|
||||
<property name="text" >
|
||||
<string>Save this document in bundled format</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QLabel" name="filesLBL" >
|
||||
<property name="text" >
|
||||
<string>Embedded files:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11" />
|
||||
|
Loading…
Reference in New Issue
Block a user