Embedding: fix a file selection and a file copy bug

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19986 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2007-09-02 05:36:39 +00:00
parent 452348f4ce
commit f8422ebb00
2 changed files with 22 additions and 10 deletions

View File

@ -64,6 +64,7 @@ using support::bformat;
using support::zipFiles; using support::zipFiles;
using support::prefixIs; using support::prefixIs;
using support::sum; using support::sum;
using support::makedir;
EmbeddedFile::EmbeddedFile(string const & file, string const & inzip_name, EmbeddedFile::EmbeddedFile(string const & file, string const & inzip_name,
@ -134,6 +135,10 @@ bool EmbeddedFile::extract(Buffer const * buf) const
// copy file in the previous case, and a new case // copy file in the previous case, and a new case
if (copyFile || (!fs::exists(ext_file) && fs::exists(emb_file))) { if (copyFile || (!fs::exists(ext_file) && fs::exists(emb_file))) {
try { try {
// need to make directory?
string path = onlyPath(ext_file);
if (!fs::is_directory(path))
makedir(const_cast<char*>(path.c_str()), 0755);
fs::copy_file(emb_file, ext_file, false); fs::copy_file(emb_file, ext_file, false);
return true; return true;
} catch (fs::filesystem_error const & fe) { } catch (fs::filesystem_error const & fe) {

View File

@ -64,19 +64,28 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged()
EmbeddedFiles & files = form_->embeddedFiles(); EmbeddedFiles & files = form_->embeddedFiles();
QList<QListWidgetItem *> selection = filesLW->selectedItems(); QList<QListWidgetItem *> selection = filesLW->selectedItems();
fullpathLE->setEnabled(selection.size() == 1); fullpathLE->setEnabled(selection.size() == 1);
EmbeddedFile::STATUS mode = EmbeddedFile::NONE;
// try to find a common mode, otherwise return NONE. // try to find a common mode, otherwise return NONE.
for (QList<QListWidgetItem*>::iterator it = selection.begin(); QList<QListWidgetItem*>::iterator it = selection.begin();
it != selection.end(); ++it) { QList<QListWidgetItem*>::iterator it_end = selection.end();
if (selection.size() == 1) // if the selection is not empty
fullpathLE->setText(toqstr(files[filesLW->row(*it)].absFilename())); if (it != it_end) {
int idx = filesLW->row(*it);
fullpathLE->setText(toqstr(files[idx].absFilename()));
// go to the first selected item
form_->goTo(files[idx]);
}
EmbeddedFile::STATUS mode = EmbeddedFile::NONE;
for (; it != it_end; ++it) {
int idx = filesLW->row(*it);
if (mode == EmbeddedFile::NONE) { if (mode == EmbeddedFile::NONE) {
mode = files[filesLW->row(*it)].status(); mode = files[idx].status();
continue; continue;
} }
if (mode != files[filesLW->row(*it)].status()) { if (mode != files[idx].status()) {
mode = EmbeddedFile::NONE; mode = EmbeddedFile::NONE;
break; break;
} }
@ -85,8 +94,6 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged()
autoRB->setChecked(mode == EmbeddedFile::AUTO); autoRB->setChecked(mode == EmbeddedFile::AUTO);
embeddedRB->setChecked(mode == EmbeddedFile::EMBEDDED); embeddedRB->setChecked(mode == EmbeddedFile::EMBEDDED);
externalRB->setChecked(mode == EmbeddedFile::EXTERNAL); externalRB->setChecked(mode == EmbeddedFile::EXTERNAL);
// go to the first selected item
form_->goTo(files[filesLW->row(*selection.begin())]);
} }