]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/TocWidget.cpp
Remove the .aux and .bbl files and update the citation labels
[lyx.git] / src / frontends / qt4 / TocWidget.cpp
index b8de46efef8af74d2371f6c4fd5a9020be37dbb9..80c9db97d952a6ab773ca96eca3f0675fbc5f7a8 100644 (file)
 
 #include <vector>
 
+#define DELAY_UPDATE_VIEW
+
 using namespace std;
 
 namespace lyx {
 namespace frontend {
 
 TocWidget::TocWidget(GuiView & gui_view, QWidget * parent)
-       : QWidget(parent), depth_(0), persistent_(false), gui_view_(gui_view)
+       : QWidget(parent), depth_(0), persistent_(false), gui_view_(gui_view), update_delay_(0)
+
 {
        setupUi(this);
 
@@ -68,6 +71,7 @@ TocWidget::TocWidget(GuiView & gui_view, QWidget * parent)
 
        // Only one item selected at a time.
        tocTV->setSelectionMode(QAbstractItemView::SingleSelection);
+       setFocusProxy(tocTV);
 
        // The toc types combo won't change its model.
        typeCO->setModel(gui_view_.tocModels().nameModel());
@@ -139,7 +143,7 @@ bool TocWidget::getStatus(Cursor & cur, FuncRequest const & cmd,
        TocItem const & item =
                gui_view_.tocModels().currentItem(current_type_, index);
 
-       switch (cmd.action)
+       switch (cmd.action())
        {
        case LFUN_CHANGE_ACCEPT:
        case LFUN_CHANGE_REJECT:
@@ -179,7 +183,7 @@ void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd)
        // Start an undo group.
        cur.beginUndoGroup();
 
-       switch (cmd.action)
+       switch (cmd.action())
        {
        case LFUN_CHANGE_ACCEPT:
        case LFUN_CHANGE_REJECT:
@@ -200,7 +204,7 @@ void TocWidget::doDispatch(Cursor & cur, FuncRequest const & cmd)
        case LFUN_OUTLINE_DOWN:
        case LFUN_OUTLINE_IN:
        case LFUN_OUTLINE_OUT:
-               outline(cmd.action);
+               outline(cmd.action());
                break;
 
        default:
@@ -241,14 +245,14 @@ void TocWidget::on_updateTB_clicked()
        // The backend update can take some time so we disable
        // the controls while waiting.
        enableControls(false);
-       gui_view_.tocModels().updateBackend();
+       gui_view_.currentBufferView()->buffer().updateBuffer();
 }
 
 
 void TocWidget::on_sortCB_stateChanged(int state)
 {
        gui_view_.tocModels().sort(current_type_, state == Qt::Checked);
-       updateView();
+       updateViewForce();
 }
 
 
@@ -313,8 +317,10 @@ void TocWidget::setTreeDepth(int depth)
 
 void TocWidget::on_typeCO_currentIndexChanged(int index)
 {
+       if (index == -1)
+               return;
        current_type_ = typeCO->itemData(index).toString();
-       updateView();
+       updateViewForce();
        if (typeCO->hasFocus())
                gui_view_.setFocus();
 }
@@ -386,22 +392,38 @@ void TocWidget::enableControls(bool enable)
 
 void TocWidget::updateView()
 {
+// Enable if you dont want the delaying business, cf #7138.
+#ifndef DELAY_UPDATE_VIEW
+       updateViewForce();
+       return;
+#endif
+       // already scheduled?
+       if (update_delay_ == -1)
+               return;
+       QTimer::singleShot(update_delay_, this, SLOT(updateViewForce()));
+       // Subtler optimization for having the delay more UI invisible.
+       // We trigger update immediately for sparse editation actions,
+       // i.e. there was no editation/cursor movement in last 2 sec.
+       // At worst there will be +1 redraw after 2s in a such "calm" mode.
+       if (update_delay_ != 0)
+               updateViewForce();
+       update_delay_ = -1;
+}
+
+void TocWidget::updateViewForce()
+{
+       update_delay_ = 2000;
        if (!gui_view_.documentBufferView()) {
-               enableControls(false);
-               typeCO->setEnabled(false);
                tocTV->setModel(0);
-               tocTV->setEnabled(false);
                depthSL->setMaximum(0);
                depthSL->setValue(0);
-               persistentCB->setEnabled(false);
-               sortCB->setEnabled(false);
-               depthSL->setEnabled(false);
+               setEnabled(false);
                return;
        }
+       setEnabled(true);
        bool const is_sortable = isSortable();
        sortCB->setEnabled(is_sortable);
-       depthSL->setEnabled(true);
-       typeCO->setEnabled(true);
+       bool focus_ = tocTV->hasFocus();
        tocTV->setEnabled(false);
        tocTV->setUpdatesEnabled(false);
 
@@ -437,6 +459,8 @@ void TocWidget::updateView()
        filterContents();
        tocTV->setEnabled(true);
        tocTV->setUpdatesEnabled(true);
+       if (focus_)
+               tocTV->setFocus();
 }
 
 
@@ -455,7 +479,7 @@ void TocWidget::filterContents()
                QModelIndex index = indices[i];
                bool const matches =
                        index.data().toString().contains(
-                               filterLE->text(), Qt::CaseSensitive);
+                               filterLE->text(), Qt::CaseInsensitive);
                tocTV->setRowHidden(index.row(), index.parent(), !matches);
        }
        // recursively unhide parents of unhidden children 
@@ -495,7 +519,7 @@ void TocWidget::init(QString const & str)
                new_index = typeCO->findData(decodeType(str));
 
        // If everything else fails, settle on the table of contents which is
-       // guaranted to exist.
+       // guaranteed to exist.
        if (new_index == -1) {
                current_type_ = "tableofcontents";
                new_index = typeCO->findData(current_type_);
@@ -506,6 +530,9 @@ void TocWidget::init(QString const & str)
        typeCO->blockSignals(true);
        typeCO->setCurrentIndex(new_index);
        typeCO->blockSignals(false);
+
+       // no delay when the whole outliner is reseted.
+       update_delay_ = 0;
 }
 
 } // namespace frontend