+ : QDockWidget(parent),
+ _childWidget(0),
+ _widget(new QWidget(parent)),
+ _filterEdit(new QLineEdit(parent)),
+ _active(false),
+ _title(config->bufferViewName())
+{
+ setObjectName("BufferViewDock-" + QString::number(config->bufferViewId()));
+ toggleViewAction()->setData(config->bufferViewId());
+ setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
+ connect(config, SIGNAL(bufferViewNameSet(const QString &)), this, SLOT(bufferViewRenamed(const QString &)));
+ connect(config, SIGNAL(configChanged()), SLOT(configChanged()));
+ updateTitle();
+
+ _widget->setLayout(new QVBoxLayout);
+ _widget->layout()->setSpacing(0);
+ _widget->layout()->setContentsMargins(0, 0, 0, 0);
+
+ // We need to potentially hide it early, so it doesn't flicker
+ _filterEdit->setVisible(config->showSearch());
+ _filterEdit->setFocusPolicy(Qt::ClickFocus);
+ _filterEdit->installEventFilter(this);
+ _filterEdit->setPlaceholderText(tr("Search..."));
+ connect(_filterEdit, SIGNAL(returnPressed()), SLOT(onFilterReturnPressed()));
+
+ _widget->layout()->addWidget(_filterEdit);
+ QDockWidget::setWidget(_widget);
+}
+
+void BufferViewDock::setLocked(bool locked) {
+ if (locked) {
+ setFeatures(0);
+ }
+ else {
+ setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
+ }
+}
+
+void BufferViewDock::updateTitle()
+{
+ QString title = _title;
+ if (isActive())
+ title.prepend(QString::fromUtf8("• "));
+ setWindowTitle(title);
+}
+
+void BufferViewDock::configChanged()
+{
+ if (_filterEdit->isVisible() != config()->showSearch()) {
+ _filterEdit->setVisible(config()->showSearch());
+ _filterEdit->clear();
+ }
+}
+
+void BufferViewDock::onFilterReturnPressed()
+{
+ if (_oldFocusItem) {
+ _oldFocusItem->setFocus();
+ _oldFocusItem = 0;
+ }
+
+ if (!config()->showSearch()) {
+ _filterEdit->setVisible(false);
+ }
+
+ BufferView *view = bufferView();
+ if (!view || _filterEdit->text().isEmpty()) {
+ return;
+ }
+
+ view->selectFirstBuffer();
+ _filterEdit->clear();
+}
+
+void BufferViewDock::setActive(bool active)
+{
+ if (active != isActive()) {
+ _active = active;
+ updateTitle();
+ if (active) {
+ raise(); // for tabbed docks
+ }
+ }
+}
+
+bool BufferViewDock::eventFilter(QObject *object, QEvent *event)
+{
+ if (object != _filterEdit) {
+ return false;
+ }
+
+ if (event->type() == QEvent::FocusOut) {
+ if (!config()->showSearch() && _filterEdit->text().isEmpty()) {
+ _filterEdit->setVisible(false);
+ return true;
+ }
+ } else if (event->type() == QEvent::KeyRelease) {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
+ if (keyEvent->key() != Qt::Key_Escape) {
+ return false;
+ }
+
+ _filterEdit->clear();
+
+ if (_oldFocusItem) {
+ _oldFocusItem->setFocus();
+ _oldFocusItem = 0;
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
+void BufferViewDock::bufferViewRenamed(const QString &newName)
+{
+ _title = newName;
+ updateTitle();
+ toggleViewAction()->setText(newName);
+}
+
+
+int BufferViewDock::bufferViewId() const