Semi-yearly copyright bump
[quassel.git] / src / uisupport / bufferview.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include "bufferview.h"
22
23 #include <QApplication>
24 #include <QAction>
25 #include <QFlags>
26 #include <QHeaderView>
27 #include <QLineEdit>
28 #include <QMenu>
29 #include <QMessageBox>
30 #include <QSet>
31
32 #include "action.h"
33 #include "buffermodel.h"
34 #include "bufferviewfilter.h"
35 #include "buffersettings.h"
36 #include "buffersyncer.h"
37 #include "client.h"
38 #include "contextmenuactionprovider.h"
39 #include "graphicalui.h"
40 #include "network.h"
41 #include "networkmodel.h"
42 #include "contextmenuactionprovider.h"
43
44 /*****************************************
45 * The TreeView showing the Buffers
46 *****************************************/
47 // Please be carefull when reimplementing methods which are used to inform the view about changes to the data
48 // to be on the safe side: call QTreeView's method aswell (or TreeViewTouch's)
49 BufferView::BufferView(QWidget *parent)
50     : TreeViewTouch(parent)
51 {
52     connect(this, SIGNAL(collapsed(const QModelIndex &)), SLOT(storeExpandedState(const QModelIndex &)));
53     connect(this, SIGNAL(expanded(const QModelIndex &)), SLOT(storeExpandedState(const QModelIndex &)));
54
55     setSelectionMode(QAbstractItemView::ExtendedSelection);
56
57     QAbstractItemDelegate *oldDelegate = itemDelegate();
58     BufferViewDelegate *tristateDelegate = new BufferViewDelegate(this);
59     setItemDelegate(tristateDelegate);
60     delete oldDelegate;
61 }
62
63
64 void BufferView::init()
65 {
66     header()->setContextMenuPolicy(Qt::ActionsContextMenu);
67     hideColumn(1);
68     hideColumn(2);
69     setIndentation(10);
70
71     // New entries will be expanded automatically when added; no need to call expandAll()
72
73     header()->hide(); // nobody seems to use this anyway
74
75     // breaks with Qt 4.8
76     if (QString("4.8.0") > qVersion()) // FIXME breaks with Qt versions >= 4.10!
77         setAnimated(true);
78
79     // FIXME This is to workaround bug #663
80     setUniformRowHeights(true);
81
82 #ifndef QT_NO_DRAGANDDROP
83     setDragEnabled(true);
84     setAcceptDrops(true);
85     setDropIndicatorShown(true);
86 #endif
87
88     setSortingEnabled(true);
89     sortByColumn(0, Qt::AscendingOrder);
90
91 #if defined Q_OS_MACOS || defined Q_OS_WIN
92     // afaik this is better on Mac and Windows
93     disconnect(this, SIGNAL(activated(QModelIndex)), this, SLOT(joinChannel(QModelIndex)));
94     connect(this, SIGNAL(activated(QModelIndex)), SLOT(joinChannel(QModelIndex)));
95 #else
96     disconnect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(joinChannel(QModelIndex)));
97     connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(joinChannel(QModelIndex)));
98 #endif
99 }
100
101
102 void BufferView::setModel(QAbstractItemModel *model)
103 {
104     delete selectionModel();
105
106     TreeViewTouch::setModel(model);
107     init();
108     // remove old Actions
109     QList<QAction *> oldactions = header()->actions();
110     foreach(QAction *action, oldactions) {
111         header()->removeAction(action);
112         action->deleteLater();
113     }
114
115     if (!model)
116         return;
117
118     QString sectionName;
119     QAction *showSection;
120     for (int i = 1; i < model->columnCount(); i++) {
121         sectionName = (model->headerData(i, Qt::Horizontal, Qt::DisplayRole)).toString();
122         showSection = new QAction(sectionName, header());
123         showSection->setCheckable(true);
124         showSection->setChecked(!isColumnHidden(i));
125         showSection->setProperty("column", i);
126         connect(showSection, SIGNAL(toggled(bool)), this, SLOT(toggleHeader(bool)));
127         header()->addAction(showSection);
128     }
129
130     connect(model, SIGNAL(layoutChanged()), this, SLOT(on_layoutChanged()));
131
132     // Make sure collapsation is correct after setting a model
133     // This might not be needed here, only in BufferView::setFilteredModel().  If issues arise, just
134     // move down to setFilteredModel (which calls this function).
135     setExpandedState();
136 }
137
138
139 void BufferView::setFilteredModel(QAbstractItemModel *model_, BufferViewConfig *config)
140 {
141     BufferViewFilter *filter = qobject_cast<BufferViewFilter *>(model());
142     if (filter) {
143         filter->setConfig(config);
144         setConfig(config);
145         return;
146     }
147
148     if (model()) {
149         disconnect(this, 0, model(), 0);
150         disconnect(model(), 0, this, 0);
151     }
152
153     if (!model_) {
154         setModel(model_);
155     }
156     else {
157         BufferViewFilter *filter = new BufferViewFilter(model_, config);
158         setModel(filter);
159         connect(filter, SIGNAL(configChanged()), this, SLOT(on_configChanged()));
160     }
161     setConfig(config);
162 }
163
164
165 void BufferView::setConfig(BufferViewConfig *config)
166 {
167     if (_config == config)
168         return;
169
170     if (_config) {
171         disconnect(_config, 0, this, 0);
172     }
173
174     _config = config;
175     if (config) {
176         connect(config, SIGNAL(networkIdSet(const NetworkId &)), this, SLOT(setRootIndexForNetworkId(const NetworkId &)));
177         setRootIndexForNetworkId(config->networkId());
178     }
179     else {
180         setIndentation(10);
181         setRootIndex(QModelIndex());
182     }
183 }
184
185
186 void BufferView::setRootIndexForNetworkId(const NetworkId &networkId)
187 {
188     if (!networkId.isValid() || !model()) {
189         setIndentation(10);
190         setRootIndex(QModelIndex());
191     }
192     else {
193         setIndentation(5);
194         int networkCount = model()->rowCount();
195         QModelIndex child;
196         for (int i = 0; i < networkCount; i++) {
197             child = model()->index(i, 0);
198             if (networkId == model()->data(child, NetworkModel::NetworkIdRole).value<NetworkId>())
199                 setRootIndex(child);
200         }
201     }
202 }
203
204
205 void BufferView::joinChannel(const QModelIndex &index)
206 {
207     BufferInfo::Type bufferType = (BufferInfo::Type)index.data(NetworkModel::BufferTypeRole).value<int>();
208
209     if (bufferType != BufferInfo::ChannelBuffer)
210         return;
211
212     BufferInfo bufferInfo = index.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
213
214     Client::userInput(bufferInfo, QString("/JOIN %1").arg(bufferInfo.bufferName()));
215 }
216
217
218 void BufferView::keyPressEvent(QKeyEvent *event)
219 {
220     if (event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete) {
221         event->accept();
222         removeSelectedBuffers();
223     }
224     TreeViewTouch::keyPressEvent(event);
225 }
226
227
228 void BufferView::dropEvent(QDropEvent *event)
229 {
230     QModelIndex index = indexAt(event->pos());
231
232     QRect indexRect = visualRect(index);
233     QPoint cursorPos = event->pos();
234
235     // check if we're really _on_ the item and not indicating a move to just above or below the item
236     // Magic margin number for this is from QAbstractItemViewPrivate::position()
237     const int margin = 2;
238     if (cursorPos.y() - indexRect.top() < margin
239         || indexRect.bottom() - cursorPos.y() < margin)
240         return TreeViewTouch::dropEvent(event);
241
242     // If more than one buffer was being dragged, treat this as a rearrangement instead of a merge request
243     QList<QPair<NetworkId, BufferId> > bufferList = Client::networkModel()->mimeDataToBufferList(event->mimeData());
244     if (bufferList.count() != 1)
245         return TreeViewTouch::dropEvent(event);
246
247     // Get the Buffer ID of the buffer that was being dragged
248     BufferId bufferId2 = bufferList[0].second;
249
250     // Get the Buffer ID of the target buffer
251     BufferId bufferId1 = index.data(NetworkModel::BufferIdRole).value<BufferId>();
252
253     // If the source and target are the same buffer, this was an aborted rearrangement
254     if (bufferId1 == bufferId2)
255         return TreeViewTouch::dropEvent(event);
256
257     // Get index of buffer that was being dragged
258     QModelIndex index2 = Client::networkModel()->bufferIndex(bufferId2);
259
260     // If the buffer being dragged is a channel and we're still joined to it, treat this as a rearrangement
261     // This prevents us from being joined to a channel with no associated UI elements
262     if (index2.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer && index2.data(NetworkModel::ItemActiveRole) == true)
263         return TreeViewTouch::dropEvent(event);
264
265     //If the source buffer is not mergeable(AKA not a Channel and not a Query), try rearranging instead
266     if (index2.data(NetworkModel::BufferTypeRole) != BufferInfo::ChannelBuffer && index2.data(NetworkModel::BufferTypeRole) != BufferInfo::QueryBuffer)
267         return TreeViewTouch::dropEvent(event);
268
269     // If the target buffer is not mergeable(AKA not a Channel and not a Query), try rearranging instead
270     if (index.data(NetworkModel::BufferTypeRole) != BufferInfo::ChannelBuffer && index.data(NetworkModel::BufferTypeRole) != BufferInfo::QueryBuffer)
271         return TreeViewTouch::dropEvent(event);
272
273     // Confirm that the user really wants to merge the buffers before doing so
274     int res = QMessageBox::question(0, tr("Merge buffers permanently?"),
275         tr("Do you want to merge the buffer \"%1\" permanently into buffer \"%2\"?\n This cannot be reversed!").arg(Client::networkModel()->bufferName(bufferId2)).arg(Client::networkModel()->bufferName(bufferId1)),
276         QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
277     if (res == QMessageBox::Yes) {
278         Client::mergeBuffersPermanently(bufferId1, bufferId2);
279     }
280 }
281
282
283 void BufferView::removeSelectedBuffers(bool permanently)
284 {
285     if (!config())
286         return;
287
288     BufferId bufferId;
289     QSet<BufferId> removedRows;
290     foreach(QModelIndex index, selectionModel()->selectedIndexes()) {
291         if (index.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType)
292             continue;
293
294         bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
295         if (removedRows.contains(bufferId))
296             continue;
297
298         removedRows << bufferId;
299     }
300
301     foreach(BufferId bufferId, removedRows) {
302         if (permanently)
303             config()->requestRemoveBufferPermanently(bufferId);
304         else
305             config()->requestRemoveBuffer(bufferId);
306     }
307 }
308
309
310 void BufferView::rowsInserted(const QModelIndex &parent, int start, int end)
311 {
312     TreeViewTouch::rowsInserted(parent, start, end);
313
314     // ensure that newly inserted network nodes are expanded per default
315     if (parent.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
316         return;
317
318     setExpandedState(parent);
319 }
320
321
322 void BufferView::on_layoutChanged()
323 {
324     int numNets = model()->rowCount(QModelIndex());
325     for (int row = 0; row < numNets; row++) {
326         QModelIndex networkIdx = model()->index(row, 0, QModelIndex());
327         setExpandedState(networkIdx);
328     }
329 }
330
331
332 void BufferView::on_configChanged()
333 {
334     Q_ASSERT(model());
335
336     // Expand/collapse as needed
337     setExpandedState();
338
339     if (config()) {
340         // update selection to current one
341         Client::bufferModel()->synchronizeView(this);
342     }
343 }
344
345
346 void BufferView::setExpandedState()
347 {
348     // Expand all active networks, collapse inactive ones... unless manually changed
349     QModelIndex networkIdx;
350     NetworkId networkId;
351     for (int row = 0; row < model()->rowCount(); row++) {
352         networkIdx = model()->index(row, 0);
353         if (model()->rowCount(networkIdx) ==  0)
354             continue;
355
356         networkId = model()->data(networkIdx, NetworkModel::NetworkIdRole).value<NetworkId>();
357         if (!networkId.isValid())
358             continue;
359
360         setExpandedState(networkIdx);
361     }
362 }
363
364
365 void BufferView::storeExpandedState(const QModelIndex &networkIdx)
366 {
367     NetworkId networkId = model()->data(networkIdx, NetworkModel::NetworkIdRole).value<NetworkId>();
368
369     int oldState = 0;
370     if (isExpanded(networkIdx))
371         oldState |= WasExpanded;
372     if (model()->data(networkIdx, NetworkModel::ItemActiveRole).toBool())
373         oldState |= WasActive;
374
375     _expandedState[networkId] = oldState;
376 }
377
378
379 void BufferView::setExpandedState(const QModelIndex &networkIdx)
380 {
381     if (model()->data(networkIdx, NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
382         return;
383
384     if (model()->rowCount(networkIdx) == 0)
385         return;
386
387     NetworkId networkId = model()->data(networkIdx, NetworkModel::NetworkIdRole).value<NetworkId>();
388
389     bool networkActive = model()->data(networkIdx, NetworkModel::ItemActiveRole).toBool();
390     bool expandNetwork = networkActive;
391     if (_expandedState.contains(networkId)) {
392         int oldState = _expandedState[networkId];
393         if ((bool)(oldState & WasActive) == networkActive)
394             expandNetwork = (bool)(oldState & WasExpanded);
395     }
396
397     if (expandNetwork != isExpanded(networkIdx)) {
398         update(networkIdx);
399         setExpanded(networkIdx, expandNetwork);
400     }
401     storeExpandedState(networkIdx); // this call is needed to keep track of the isActive state
402 }
403
404 #if QT_VERSION < 0x050000
405 void BufferView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
406 {
407     TreeViewTouch::dataChanged(topLeft, bottomRight);
408 #else
409 void BufferView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
410 {
411     TreeViewTouch::dataChanged(topLeft, bottomRight, roles);
412 #endif
413
414     // determine how many items have been changed and if any of them is a networkitem
415     // which just swichted from active to inactive or vice versa
416     if (topLeft.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
417         return;
418
419     for (int i = topLeft.row(); i <= bottomRight.row(); i++) {
420         QModelIndex networkIdx = topLeft.sibling(i, 0);
421         setExpandedState(networkIdx);
422     }
423 }
424
425
426 void BufferView::toggleHeader(bool checked)
427 {
428     QAction *action = qobject_cast<QAction *>(sender());
429     header()->setSectionHidden((action->property("column")).toInt(), !checked);
430 }
431
432
433 void BufferView::contextMenuEvent(QContextMenuEvent *event)
434 {
435     QModelIndex index = indexAt(event->pos());
436     if (!index.isValid())
437         index = rootIndex();
438
439     QMenu contextMenu(this);
440
441     if (index.isValid()) {
442         addActionsToMenu(&contextMenu, index);
443     }
444
445     addFilterActions(&contextMenu, index);
446
447     if (!contextMenu.actions().isEmpty())
448         contextMenu.exec(QCursor::pos());
449 }
450
451
452 void BufferView::addActionsToMenu(QMenu *contextMenu, const QModelIndex &index)
453 {
454     QModelIndexList indexList = selectedIndexes();
455     // make sure the item we clicked on is first
456     indexList.removeAll(index);
457     indexList.prepend(index);
458
459     GraphicalUi::contextMenuActionProvider()->addActions(contextMenu, indexList, this, "menuActionTriggered", (bool)config());
460 }
461
462
463 void BufferView::addFilterActions(QMenu *contextMenu, const QModelIndex &index)
464 {
465     BufferViewFilter *filter = qobject_cast<BufferViewFilter *>(model());
466     if (filter) {
467         QList<QAction *> filterActions = filter->actions(index);
468         if (!filterActions.isEmpty()) {
469             contextMenu->addSeparator();
470             foreach(QAction *action, filterActions) {
471                 contextMenu->addAction(action);
472             }
473         }
474     }
475 }
476
477
478 void BufferView::menuActionTriggered(QAction *result)
479 {
480     ContextMenuActionProvider::ActionType type = (ContextMenuActionProvider::ActionType)result->data().toInt();
481     switch (type) {
482     case ContextMenuActionProvider::HideBufferTemporarily:
483         removeSelectedBuffers();
484         break;
485     case ContextMenuActionProvider::HideBufferPermanently:
486         removeSelectedBuffers(true);
487         break;
488     default:
489         return;
490     }
491 }
492
493
494 void BufferView::nextBuffer()
495 {
496     changeBuffer(Forward);
497 }
498
499
500 void BufferView::previousBuffer()
501 {
502     changeBuffer(Backward);
503 }
504
505
506 void BufferView::changeBuffer(Direction direction)
507 {
508     QModelIndex currentIndex = selectionModel()->currentIndex();
509     QModelIndex resultingIndex;
510
511     if (currentIndex.parent().isValid()) {
512         //If we are a child node just switch among siblings unless it's the first/last child
513         resultingIndex = currentIndex.sibling(currentIndex.row() + direction, 0);
514
515         if (!resultingIndex.isValid()) {
516             QModelIndex parent = currentIndex.parent();
517             if (direction == Backward)
518                 resultingIndex = parent;
519             else
520                 resultingIndex = parent.sibling(parent.row() + direction, 0);
521         }
522     }
523     else {
524         //If we have a toplevel node, try and get an adjacent child
525         if (direction == Backward) {
526             QModelIndex newParent = currentIndex.sibling(currentIndex.row() - 1, 0);
527             if (model()->hasChildren(newParent))
528                 resultingIndex = newParent.child(model()->rowCount(newParent) - 1, 0);
529             else
530                 resultingIndex = newParent;
531         }
532         else {
533             if (model()->hasChildren(currentIndex))
534                 resultingIndex = currentIndex.child(0, 0);
535             else
536                 resultingIndex = currentIndex.sibling(currentIndex.row() + 1, 0);
537         }
538     }
539
540     if (!resultingIndex.isValid())
541         return;
542
543     selectionModel()->setCurrentIndex(resultingIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
544     selectionModel()->select(resultingIndex, QItemSelectionModel::ClearAndSelect);
545 }
546
547
548 void BufferView::wheelEvent(QWheelEvent *event)
549 {
550     if (ItemViewSettings().mouseWheelChangesBuffer() == (bool)(event->modifiers() & Qt::AltModifier))
551         return TreeViewTouch::wheelEvent(event);
552
553     int rowDelta = (event->delta() > 0) ? -1 : 1;
554     changeBuffer((Direction)rowDelta);
555 }
556
557
558 void BufferView::hideCurrentBuffer()
559 {
560     QModelIndex index = selectionModel()->currentIndex();
561     if (index.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType)
562         return;
563
564     BufferId bufferId = index.data(NetworkModel::BufferIdRole).value<BufferId>();
565
566     //The check above means we won't be looking at a network, which should always be the first row, so we can just go backwards.
567     changeBuffer(Backward);
568
569     /*if(removedRows.contains(bufferId))
570       continue;
571
572     removedRows << bufferId;*/
573     /*if(permanently)
574       config()->requestRemoveBufferPermanently(bufferId);
575     else*/
576     config()->requestRemoveBuffer(bufferId);
577 }
578
579
580 QSize BufferView::sizeHint() const
581 {
582     return TreeViewTouch::sizeHint();
583
584     if (!model())
585         return TreeViewTouch::sizeHint();
586
587     if (model()->rowCount() == 0)
588         return QSize(120, 50);
589
590     int columnSize = 0;
591     for (int i = 0; i < model()->columnCount(); i++) {
592         if (!isColumnHidden(i))
593             columnSize += sizeHintForColumn(i);
594     }
595     return QSize(columnSize, 50);
596 }
597
598
599 // ****************************************
600 //  BufferViewDelgate
601 // ****************************************
602 class ColorsChangedEvent : public QEvent
603 {
604 public:
605     ColorsChangedEvent() : QEvent(QEvent::User) {};
606 };
607
608
609 BufferViewDelegate::BufferViewDelegate(QObject *parent)
610     : QStyledItemDelegate(parent)
611 {
612 }
613
614
615 void BufferViewDelegate::customEvent(QEvent *event)
616 {
617     if (event->type() != QEvent::User)
618         return;
619
620     event->accept();
621 }
622
623
624 bool BufferViewDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
625 {
626     if (event->type() != QEvent::MouseButtonRelease)
627         return QStyledItemDelegate::editorEvent(event, model, option, index);
628
629     if (!(model->flags(index) & Qt::ItemIsUserCheckable))
630         return QStyledItemDelegate::editorEvent(event, model, option, index);
631
632     QVariant value = index.data(Qt::CheckStateRole);
633     if (!value.isValid())
634         return QStyledItemDelegate::editorEvent(event, model, option, index);
635
636 #if QT_VERSION < 0x050000
637     QStyleOptionViewItemV4 viewOpt(option);
638 #else
639     QStyleOptionViewItem viewOpt(option);
640 #endif
641     initStyleOption(&viewOpt, index);
642
643     QRect checkRect = viewOpt.widget->style()->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &viewOpt, viewOpt.widget);
644     QMouseEvent *me = static_cast<QMouseEvent *>(event);
645
646     if (me->button() != Qt::LeftButton || !checkRect.contains(me->pos()))
647         return QStyledItemDelegate::editorEvent(event, model, option, index);
648
649     Qt::CheckState state = static_cast<Qt::CheckState>(value.toInt());
650     if (state == Qt::Unchecked)
651         state = Qt::PartiallyChecked;
652     else if (state == Qt::PartiallyChecked)
653         state = Qt::Checked;
654     else
655         state = Qt::Unchecked;
656     model->setData(index, state, Qt::CheckStateRole);
657     return true;
658 }
659
660
661 // ==============================
662 //  BufferView Dock
663 // ==============================
664 BufferViewDock::BufferViewDock(BufferViewConfig *config, QWidget *parent)
665     : QDockWidget(parent),
666     _active(false),
667     _title(config->bufferViewName())
668 {
669     setObjectName("BufferViewDock-" + QString::number(config->bufferViewId()));
670     toggleViewAction()->setData(config->bufferViewId());
671     setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea);
672     connect(config, SIGNAL(bufferViewNameSet(const QString &)), this, SLOT(bufferViewRenamed(const QString &)));
673     updateTitle();
674 }
675
676
677 void BufferViewDock::updateTitle()
678 {
679     QString title = _title;
680     if (isActive())
681         title.prepend(QString::fromUtf8("• "));
682     setWindowTitle(title);
683 }
684
685
686 void BufferViewDock::setActive(bool active)
687 {
688     if (active != isActive()) {
689         _active = active;
690         updateTitle();
691         if (active)
692             raise();  // for tabbed docks
693     }
694 }
695
696
697 void BufferViewDock::bufferViewRenamed(const QString &newName)
698 {
699     _title = newName;
700     updateTitle();
701     toggleViewAction()->setText(newName);
702 }
703
704
705 int BufferViewDock::bufferViewId() const
706 {
707     BufferView *view = bufferView();
708     if (!view)
709         return 0;
710
711     if (view->config())
712         return view->config()->bufferViewId();
713     else
714         return 0;
715 }
716
717
718 BufferViewConfig *BufferViewDock::config() const
719 {
720     BufferView *view = bufferView();
721     if (!view)
722         return 0;
723     else
724         return view->config();
725 }