Disable some Adv F&R widgets for read-only documents

This commit is contained in:
Jean-Marc Lasgouttes 2020-12-03 18:02:40 +01:00
parent a8ad60d603
commit c30b0aac4b
3 changed files with 13 additions and 2 deletions

View File

@ -3138,6 +3138,11 @@ ParConstIterator Buffer::par_iterator_end() const
return ParConstIterator(doc_iterator_end(this));
}
bool Buffer::empty() const
{
return paragraphs().size() == 1 && paragraphs().front().empty();
}
Language const * Buffer::language() const
{

View File

@ -567,6 +567,8 @@ public:
ParIterator par_iterator_end();
///
ParConstIterator par_iterator_end() const;
/// Is document empty ?
bool empty() const;
// Position of the child buffer where it appears first in the master.
DocIterator firstChildPosition(Buffer const * child);

View File

@ -67,7 +67,7 @@ FindAndReplaceWidget::FindAndReplaceWidget(GuiView & view)
// We don't want two cursors blinking.
find_work_area_->stopBlinkingCaret();
replace_work_area_->stopBlinkingCaret();
old_buffer_ = view_.documentBufferView() ?
old_buffer_ = view_.documentBufferView() ?
&(view_.documentBufferView()->buffer()) : 0;
// align items on top
@ -90,6 +90,7 @@ void FindAndReplaceWidget::dockLocationChanged(Qt::DockWidgetArea area)
bool FindAndReplaceWidget::eventFilter(QObject * obj, QEvent * event)
{
updateGUI();
if (event->type() != QEvent::KeyPress
|| (obj != find_work_area_ && obj != replace_work_area_))
return QWidget::eventFilter(obj, event);
@ -622,7 +623,10 @@ void FindAndReplaceWidget::updateGUI()
} else
old_buffer_ = nullptr;
bool const replace_enabled = bv && !bv->buffer().isReadonly();
bool const find_enabled = !find_work_area_->bufferView().buffer().empty();
findNextPB->setEnabled(find_enabled);
bool const replace_enabled = find_enabled && bv && !bv->buffer().isReadonly();
replaceLabel->setEnabled(replace_enabled);
replace_work_area_->setEnabled(replace_enabled);
replacePB->setEnabled(replace_enabled);
replaceallPB->setEnabled(replace_enabled);