Embedding: handle readOnly files correctly.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20262 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2007-09-13 15:09:56 +00:00
parent a750970781
commit 1109af0b0f
3 changed files with 24 additions and 2 deletions

View File

@ -67,6 +67,12 @@ void ControlEmbeddedFiles::dispatchMessage(string const & msg)
} }
bool ControlEmbeddedFiles::isReadonly()
{
return buffer().isReadonly();
}
void ControlEmbeddedFiles::setEmbedding(bool enable) void ControlEmbeddedFiles::setEmbedding(bool enable)
{ {
if (embeddedFiles().enabled() == enable) if (embeddedFiles().enabled() == enable)

View File

@ -38,12 +38,14 @@ public:
/// ///
bool canApply() const { return true; } bool canApply() const { return true; }
/// ///
virtual bool canApplyToReadOnly() const { return true; } virtual bool canApplyToReadOnly() const { return false; }
/// ///
void dispatchMessage(std::string const & msg); void dispatchMessage(std::string const & msg);
/// ///
void dispatchParams() {}; void dispatchParams() {};
/// ///
bool isReadonly();
///
void setEmbedding(bool enable); void setEmbedding(bool enable);
/// ///
void goTo(EmbeddedFile const & item, int idx); void goTo(EmbeddedFile const & item, int idx);

View File

@ -48,6 +48,9 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemChanged(QListWidgetItem* item)
void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged() void GuiEmbeddedFilesDialog::on_filesLW_itemSelectionChanged()
{ {
if (controller_.isReadonly())
return;
QList<QListWidgetItem *> selection = filesLW->selectedItems(); QList<QListWidgetItem *> selection = filesLW->selectedItems();
if (selection.empty()) { if (selection.empty()) {
@ -107,6 +110,15 @@ void GuiEmbeddedFilesDialog::on_filesLW_itemDoubleClicked(QListWidgetItem* item)
void GuiEmbeddedFilesDialog::updateView() void GuiEmbeddedFilesDialog::updateView()
{ {
bool readOnly = controller_.isReadonly();
fullpathLE->setEnabled(!readOnly);
selectPB->setEnabled(!readOnly);
unselectPB->setEnabled(!readOnly);
addPB->setEnabled(!readOnly);
extractPB->setEnabled(!readOnly);
updatePB->setEnabled(!readOnly);
enableCB->setEnabled(!readOnly);
filesLW->clear(); filesLW->clear();
EmbeddedFiles const & files = controller_.embeddedFiles(); EmbeddedFiles const & files = controller_.embeddedFiles();
enableCB->setCheckState(files.enabled() ? Qt::Checked : Qt::Unchecked); enableCB->setCheckState(files.enabled() ? Qt::Checked : Qt::Unchecked);
@ -117,7 +129,9 @@ void GuiEmbeddedFilesDialog::updateView()
if (it->refCount() > 1) if (it->refCount() > 1)
label += " (1/" + QString::number(it->refCount()) + ")"; label += " (1/" + QString::number(it->refCount()) + ")";
QListWidgetItem * item = new QListWidgetItem(label); QListWidgetItem * item = new QListWidgetItem(label);
Qt::ItemFlags flag = Qt::ItemIsUserCheckable | Qt::ItemIsSelectable; Qt::ItemFlags flag = Qt::ItemIsSelectable;
if (!readOnly)
flag |= Qt::ItemIsUserCheckable;
if (it->valid()) if (it->valid())
flag |= Qt::ItemIsEnabled; flag |= Qt::ItemIsEnabled;
item->setFlags(flag); item->setFlags(flag);