mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Embedding: fix the add file feature (update dialog, mark buffer dirty, copy embedded file ...)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20256 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
4e7fa2bfef
commit
2bf225183b
@ -256,7 +256,7 @@ void EmbeddedFiles::enable(bool flag)
|
||||
}
|
||||
|
||||
|
||||
void EmbeddedFiles::registerFile(string const & filename,
|
||||
EmbeddedFile & EmbeddedFiles::registerFile(string const & filename,
|
||||
bool embed, Inset const * inset, string const & inzipName)
|
||||
{
|
||||
// filename can be relative or absolute, translate to absolute filename
|
||||
@ -271,11 +271,12 @@ void EmbeddedFiles::registerFile(string const & filename,
|
||||
if (it != file_list_.end()) {
|
||||
it->addInset(inset);
|
||||
it->validate();
|
||||
return;
|
||||
return *it;
|
||||
}
|
||||
// try to be more careful
|
||||
file_list_.push_back(EmbeddedFile(abs_filename,
|
||||
getInzipName(abs_filename, inzipName), embed, inset));
|
||||
return file_list_.back();
|
||||
}
|
||||
|
||||
|
||||
|
@ -197,7 +197,7 @@ public:
|
||||
* \param inset Inset pointer
|
||||
* \param inzipName suggested inzipname
|
||||
*/
|
||||
void registerFile(std::string const & filename, bool embed = false,
|
||||
EmbeddedFile & registerFile(std::string const & filename, bool embed = false,
|
||||
Inset const * inset = 0,
|
||||
std::string const & inzipName = std::string());
|
||||
|
||||
|
@ -114,14 +114,23 @@ void ControlEmbeddedFiles::setEmbed(EmbeddedFile & item, bool embed, bool update
|
||||
}
|
||||
|
||||
|
||||
docstring const ControlEmbeddedFiles::browseFile()
|
||||
bool ControlEmbeddedFiles::browseAndAddFile()
|
||||
{
|
||||
std::pair<docstring, docstring> dir1(_("Documents|#o#O"),
|
||||
from_utf8(lyxrc.document_path));
|
||||
FileFilterList const filter(_("All file (*.*)"));
|
||||
return browseRelFile(docstring(), from_utf8(bufferFilepath()),
|
||||
docstring const file = browseRelFile(docstring(), from_utf8(bufferFilepath()),
|
||||
_("Select a file to embed"),
|
||||
filter, false, dir1);
|
||||
if (!file.empty()) {
|
||||
EmbeddedFile & ef = embeddedFiles().registerFile(to_utf8(file), true);
|
||||
if (embeddedFiles().enabled())
|
||||
ef.updateFromExternalFile(&buffer());
|
||||
buffer().markDirty();
|
||||
dispatchMessage("Add an embedded file" + to_utf8(file));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
///
|
||||
void setEmbed(EmbeddedFile & item, bool embed, bool update);
|
||||
///
|
||||
docstring const browseFile();
|
||||
bool browseAndAddFile();
|
||||
///
|
||||
bool extract(EmbeddedFile const & item);
|
||||
///
|
||||
|
@ -93,7 +93,7 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemClicked(QListWidgetItem* item)
|
||||
QString label = toqstr(files[idx].inzipName())
|
||||
+ QString(" (%1/%2)").arg(k + 1).arg(files[idx].refCount());
|
||||
item->setText(label);
|
||||
} else
|
||||
} else if (files[idx].refCount() == 1)
|
||||
controller_.goTo(files[idx], 0);
|
||||
}
|
||||
|
||||
@ -164,12 +164,8 @@ void GuiEmbeddedFilesDialog::on_unselectPB_clicked()
|
||||
|
||||
void GuiEmbeddedFilesDialog::on_addPB_clicked()
|
||||
{
|
||||
docstring const file = controller_.browseFile();
|
||||
if (!file.empty()) {
|
||||
EmbeddedFiles & files = controller_.embeddedFiles();
|
||||
files.registerFile(to_utf8(file), true);
|
||||
}
|
||||
controller_.dispatchMessage("Add an embedded file");
|
||||
if (controller_.browseAndAddFile())
|
||||
updateView();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user