Changeset View
Changeset View
Standalone View
Standalone View
src/ViewContainer.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
42 | #include "IncrementalSearchBar.h" | 42 | #include "IncrementalSearchBar.h" | ||
43 | #include "ViewProperties.h" | 43 | #include "ViewProperties.h" | ||
44 | #include "ProfileList.h" | 44 | #include "ProfileList.h" | ||
45 | #include "ViewManager.h" | 45 | #include "ViewManager.h" | ||
46 | #include "KonsoleSettings.h" | 46 | #include "KonsoleSettings.h" | ||
47 | #include "SessionController.h" | 47 | #include "SessionController.h" | ||
48 | #include "DetachableTabBar.h" | 48 | #include "DetachableTabBar.h" | ||
49 | #include "TerminalDisplay.h" | 49 | #include "TerminalDisplay.h" | ||
50 | #include "ViewSplitter.h" | ||||
50 | 51 | | |||
51 | // TODO Perhaps move everything which is Konsole-specific into different files | 52 | // TODO Perhaps move everything which is Konsole-specific into different files | ||
52 | 53 | | |||
53 | using namespace Konsole; | 54 | using namespace Konsole; | ||
54 | 55 | | |||
55 | 56 | | |||
56 | TabbedViewContainer::TabbedViewContainer(ViewManager *connectedViewManager, QWidget *parent) : | 57 | TabbedViewContainer::TabbedViewContainer(ViewManager *connectedViewManager, QWidget *parent) : | ||
57 | QTabWidget(parent), | 58 | QTabWidget(parent), | ||
58 | _connectedViewManager(connectedViewManager), | 59 | _connectedViewManager(connectedViewManager), | ||
59 | _newTabButton(new QToolButton()), | 60 | _newTabButton(new QToolButton()), | ||
60 | _closeTabButton(new QToolButton()), | 61 | _closeTabButton(new QToolButton()), | ||
61 | _contextMenuTabIndex(-1), | 62 | _contextMenuTabIndex(-1), | ||
62 | _navigationVisibility(ViewManager::NavigationVisibility::NavigationNotSet), | 63 | _navigationVisibility(ViewManager::NavigationVisibility::NavigationNotSet) | ||
63 | _tabHistoryIndex(-1) | | |||
64 | { | 64 | { | ||
65 | setAcceptDrops(true); | 65 | setAcceptDrops(true); | ||
66 | 66 | | |||
67 | auto tabBarWidget = new DetachableTabBar(); | 67 | auto tabBarWidget = new DetachableTabBar(); | ||
68 | setTabBar(tabBarWidget); | 68 | setTabBar(tabBarWidget); | ||
69 | setDocumentMode(true); | 69 | setDocumentMode(true); | ||
70 | setMovable(true); | 70 | setMovable(true); | ||
71 | connect(tabBarWidget, &DetachableTabBar::moveTabToWindow, this, &TabbedViewContainer::moveTabToWindow); | 71 | connect(tabBarWidget, &DetachableTabBar::moveTabToWindow, this, &TabbedViewContainer::moveTabToWindow); | ||
Show All 9 Lines | |||||
81 | connect(_closeTabButton, &QToolButton::clicked, this, [this]{ | 81 | connect(_closeTabButton, &QToolButton::clicked, this, [this]{ | ||
82 | closeCurrentTab(); | 82 | closeCurrentTab(); | ||
83 | }); | 83 | }); | ||
84 | 84 | | |||
85 | connect(tabBar(), &QTabBar::tabBarDoubleClicked, this, | 85 | connect(tabBar(), &QTabBar::tabBarDoubleClicked, this, | ||
86 | &Konsole::TabbedViewContainer::tabDoubleClicked); | 86 | &Konsole::TabbedViewContainer::tabDoubleClicked); | ||
87 | connect(tabBar(), &QTabBar::customContextMenuRequested, this, | 87 | connect(tabBar(), &QTabBar::customContextMenuRequested, this, | ||
88 | &Konsole::TabbedViewContainer::openTabContextMenu); | 88 | &Konsole::TabbedViewContainer::openTabContextMenu); | ||
89 | | ||||
89 | connect(tabBarWidget, &DetachableTabBar::detachTab, this, [this](int idx) { | 90 | connect(tabBarWidget, &DetachableTabBar::detachTab, this, [this](int idx) { | ||
90 | emit detachTab(this, terminalAt(idx)); | 91 | emit detachTab(this); | ||
91 | }); | 92 | }); | ||
93 | | ||||
92 | connect(this, &TabbedViewContainer::currentChanged, this, &TabbedViewContainer::currentTabChanged); | 94 | connect(this, &TabbedViewContainer::currentChanged, this, &TabbedViewContainer::currentTabChanged); | ||
93 | 95 | | |||
94 | // The context menu of tab bar | 96 | // The context menu of tab bar | ||
95 | _contextPopupMenu = new QMenu(tabBar()); | 97 | _contextPopupMenu = new QMenu(tabBar()); | ||
96 | connect(_contextPopupMenu, &QMenu::aboutToHide, this, [this]() { | 98 | connect(_contextPopupMenu, &QMenu::aboutToHide, this, [this]() { | ||
97 | // Remove the read-only action when the popup closes | 99 | // Remove the read-only action when the popup closes | ||
98 | for (auto &action : _contextPopupMenu->actions()) { | 100 | for (auto &action : _contextPopupMenu->actions()) { | ||
99 | if (action->objectName() == QStringLiteral("view-readonly")) { | 101 | if (action->objectName() == QStringLiteral("view-readonly")) { | ||
100 | _contextPopupMenu->removeAction(action); | 102 | _contextPopupMenu->removeAction(action); | ||
101 | break; | 103 | break; | ||
102 | } | 104 | } | ||
103 | } | 105 | } | ||
104 | }); | 106 | }); | ||
105 | 107 | | |||
106 | #if defined(ENABLE_DETACHING) | 108 | #if defined(ENABLE_DETACHING) | ||
107 | auto detachAction = _contextPopupMenu->addAction( | 109 | auto detachAction = _contextPopupMenu->addAction( | ||
108 | QIcon::fromTheme(QStringLiteral("tab-detach")), | 110 | QIcon::fromTheme(QStringLiteral("tab-detach")), | ||
109 | i18nc("@action:inmenu", "&Detach Tab"), this, | 111 | i18nc("@action:inmenu", "&Detach Tab"), this, | ||
110 | [this] { emit detachTab(this, terminalAt(_contextMenuTabIndex)); } | 112 | [this] { emit detachTab(this); } | ||
111 | ); | 113 | ); | ||
112 | detachAction->setObjectName(QStringLiteral("tab-detach")); | 114 | detachAction->setObjectName(QStringLiteral("tab-detach")); | ||
113 | #endif | 115 | #endif | ||
114 | 116 | | |||
115 | auto editAction = _contextPopupMenu->addAction( | 117 | auto editAction = _contextPopupMenu->addAction( | ||
116 | QIcon::fromTheme(QStringLiteral("edit-rename")), | 118 | QIcon::fromTheme(QStringLiteral("edit-rename")), | ||
117 | i18nc("@action:inmenu", "&Rename Tab..."), this, | 119 | i18nc("@action:inmenu", "&Rename Tab..."), this, | ||
118 | [this]{ renameTab(_contextMenuTabIndex); } | 120 | [this]{ renameTab(_contextMenuTabIndex); } | ||
Show All 21 Lines | |||||
140 | TabbedViewContainer::~TabbedViewContainer() | 142 | TabbedViewContainer::~TabbedViewContainer() | ||
141 | { | 143 | { | ||
142 | for(int i = 0, end = count(); i < end; i++) { | 144 | for(int i = 0, end = count(); i < end; i++) { | ||
143 | auto view = widget(i); | 145 | auto view = widget(i); | ||
144 | disconnect(view, &QWidget::destroyed, this, &Konsole::TabbedViewContainer::viewDestroyed); | 146 | disconnect(view, &QWidget::destroyed, this, &Konsole::TabbedViewContainer::viewDestroyed); | ||
145 | } | 147 | } | ||
146 | } | 148 | } | ||
147 | 149 | | |||
148 | TerminalDisplay *TabbedViewContainer::terminalAt(int index) | 150 | ViewSplitter *TabbedViewContainer::activeViewSplitter() | ||
151 | { | ||||
152 | return viewSplitterAt(currentIndex()); | ||||
153 | } | ||||
154 | | ||||
155 | ViewSplitter *TabbedViewContainer::viewSplitterAt(int index) | ||||
149 | { | 156 | { | ||
150 | return qobject_cast<TerminalDisplay*>(widget(index)); | 157 | return qobject_cast<ViewSplitter*>(widget(index)); | ||
151 | } | 158 | } | ||
152 | 159 | | |||
153 | void TabbedViewContainer::moveTabToWindow(int index, QWidget *window) | 160 | void TabbedViewContainer::moveTabToWindow(int index, QWidget *window) | ||
154 | { | 161 | { | ||
162 | // TODO: Fix Detaching. | ||||
163 | /* | ||||
155 | const int id = terminalAt(index)->sessionController()->identifier(); | 164 | const int id = terminalAt(index)->sessionController()->identifier(); | ||
156 | // This one line here will be removed as soon as I finish my new split handling. | 165 | // This one line here will be removed as soon as I finish my new split handling. | ||
157 | // it's hacky but it works. | 166 | // it's hacky but it works. | ||
158 | const auto widgets = window->findChildren<TabbedViewContainer*>(); | 167 | const auto widgets = window->findChildren<TabbedViewContainer*>(); | ||
159 | const auto currentPos = QCursor::pos(); | 168 | const auto currentPos = QCursor::pos(); | ||
160 | for(const auto dropWidget : widgets) { | 169 | for(const auto dropWidget : widgets) { | ||
161 | if (dropWidget->rect().contains(dropWidget->mapFromGlobal(currentPos))) { | 170 | if (dropWidget->rect().contains(dropWidget->mapFromGlobal(currentPos))) { | ||
162 | emit dropWidget->moveViewRequest(-1, id); | 171 | emit dropWidget->moveViewRequest(-1, id); | ||
163 | removeView(terminalAt(index)); | 172 | removeView(terminalAt(index)); | ||
164 | } | 173 | } | ||
165 | } | 174 | } | ||
175 | */ | ||||
166 | } | 176 | } | ||
167 | 177 | | |||
168 | void TabbedViewContainer::konsoleConfigChanged() | 178 | void TabbedViewContainer::konsoleConfigChanged() | ||
169 | { | 179 | { | ||
170 | // don't show tabs if we are in KParts mode. | 180 | // don't show tabs if we are in KParts mode. | ||
171 | // This is a hack, and this needs to be rewritten. | 181 | // This is a hack, and this needs to be rewritten. | ||
172 | // The container should not be part of the KParts, perhaps just the | 182 | // The container should not be part of the KParts, perhaps just the | ||
173 | // TerminalDisplay should. | 183 | // TerminalDisplay should. | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | |||||
230 | void TabbedViewContainer::moveActiveView(MoveDirection direction) | 240 | void TabbedViewContainer::moveActiveView(MoveDirection direction) | ||
231 | { | 241 | { | ||
232 | if (count() < 2) { // return if only one view | 242 | if (count() < 2) { // return if only one view | ||
233 | return; | 243 | return; | ||
234 | } | 244 | } | ||
235 | const int currentIndex = indexOf(currentWidget()); | 245 | const int currentIndex = indexOf(currentWidget()); | ||
236 | int newIndex = direction == MoveViewLeft ? qMax(currentIndex - 1, 0) : qMin(currentIndex + 1, count() - 1); | 246 | int newIndex = direction == MoveViewLeft ? qMax(currentIndex - 1, 0) : qMin(currentIndex + 1, count() - 1); | ||
237 | 247 | | |||
238 | auto swappedWidget = terminalAt(newIndex); | 248 | auto swappedWidget = viewSplitterAt(newIndex); | ||
239 | auto currentWidget = terminalAt(currentIndex); | 249 | auto swappedTitle = tabBar()->tabText(newIndex); | ||
240 | auto swappedContext = swappedWidget->sessionController(); | 250 | auto swappedIcon = tabBar()->tabIcon(newIndex); | ||
241 | auto currentContext = currentWidget->sessionController(); | 251 | | ||
252 | auto currentWidget = viewSplitterAt(currentIndex); | ||||
253 | auto currentTitle = tabBar()->tabText(currentIndex); | ||||
254 | auto currentIcon = tabBar()->tabIcon(currentIndex); | ||||
242 | 255 | | |||
243 | if (newIndex < currentIndex) { | 256 | if (newIndex < currentIndex) { | ||
244 | insertTab(newIndex, currentWidget, currentContext->icon(), currentContext->title()); | 257 | insertTab(newIndex, currentWidget, currentIcon, currentTitle); | ||
245 | insertTab(currentIndex, swappedWidget, swappedContext->icon(), swappedContext->title()); | 258 | insertTab(currentIndex, swappedWidget, swappedIcon, swappedTitle); | ||
246 | } else { | 259 | } else { | ||
247 | insertTab(currentIndex, swappedWidget, swappedContext->icon(), swappedContext->title()); | 260 | insertTab(currentIndex, swappedWidget, swappedIcon, swappedTitle); | ||
248 | insertTab(newIndex, currentWidget, currentContext->icon(), currentContext->title()); | 261 | insertTab(newIndex, currentWidget, currentIcon, currentTitle); | ||
249 | } | 262 | } | ||
250 | setCurrentIndex(newIndex); | 263 | setCurrentIndex(newIndex); | ||
251 | } | 264 | } | ||
252 | 265 | | |||
266 | void TabbedViewContainer::addSplitter(ViewSplitter *viewSplitter, int index) { | ||||
267 | if (index == -1) { | ||||
268 | index = addTab(viewSplitter, QString()); | ||||
269 | } else { | ||||
270 | insertTab(index, viewSplitter, QString()); | ||||
271 | } | ||||
272 | connect(viewSplitter, &ViewSplitter::destroyed, this, &TabbedViewContainer::viewDestroyed); | ||||
273 | foreach(TerminalDisplay* terminal, viewSplitter->getTerminalDisplays()) { | ||||
274 | connectTerminalDisplay(terminal); | ||||
275 | } | ||||
276 | setCurrentIndex(index); | ||||
277 | } | ||||
278 | | ||||
253 | void TabbedViewContainer::addView(TerminalDisplay *view, int index) | 279 | void TabbedViewContainer::addView(TerminalDisplay *view, int index) | ||
254 | { | 280 | { | ||
281 | auto viewSplitter = new ViewSplitter(); | ||||
282 | viewSplitter->addTerminalDisplay(view, Qt::Horizontal); | ||||
255 | auto item = view->sessionController(); | 283 | auto item = view->sessionController(); | ||
256 | if (index == -1) { | 284 | if (index == -1) { | ||
257 | addTab(view, item->icon(), item->title()); | 285 | index = addTab(viewSplitter, item->icon(), item->title()); | ||
258 | } else { | 286 | } else { | ||
259 | insertTab(index, view, item->icon(), item->title()); | 287 | insertTab(index, viewSplitter, item->icon(), item->title()); | ||
288 | } | ||||
289 | | ||||
290 | connectTerminalDisplay(view); | ||||
291 | connect(viewSplitter, &ViewSplitter::destroyed, this, &TabbedViewContainer::viewDestroyed); | ||||
292 | setCurrentIndex(index); | ||||
293 | emit viewAdded(view); | ||||
294 | } | ||||
295 | | ||||
296 | void TabbedViewContainer::splitView(TerminalDisplay *view, Qt::Orientation orientation) | ||||
297 | { | ||||
298 | auto viewSplitter = qobject_cast<ViewSplitter*>(currentWidget()); | ||||
299 | viewSplitter->addTerminalDisplay(view, orientation); | ||||
300 | connectTerminalDisplay(view); | ||||
260 | } | 301 | } | ||
261 | 302 | | |||
262 | _tabHistory.append(view); | 303 | void TabbedViewContainer::connectTerminalDisplay(TerminalDisplay *display) | ||
304 | { | ||||
305 | auto item = display->sessionController(); | ||||
306 | connect(item, &Konsole::SessionController::focused, this, | ||||
307 | &Konsole::TabbedViewContainer::currentSessionControllerChanged); | ||||
308 | | ||||
263 | connect(item, &Konsole::ViewProperties::titleChanged, this, | 309 | connect(item, &Konsole::ViewProperties::titleChanged, this, | ||
264 | &Konsole::TabbedViewContainer::updateTitle); | 310 | &Konsole::TabbedViewContainer::updateTitle); | ||
311 | | ||||
265 | connect(item, &Konsole::ViewProperties::iconChanged, this, | 312 | connect(item, &Konsole::ViewProperties::iconChanged, this, | ||
266 | &Konsole::TabbedViewContainer::updateIcon); | 313 | &Konsole::TabbedViewContainer::updateIcon); | ||
314 | | ||||
267 | connect(item, &Konsole::ViewProperties::activity, this, | 315 | connect(item, &Konsole::ViewProperties::activity, this, | ||
268 | &Konsole::TabbedViewContainer::updateActivity); | 316 | &Konsole::TabbedViewContainer::updateActivity); | ||
269 | connect(view, &QWidget::destroyed, this, | 317 | } | ||
270 | &Konsole::TabbedViewContainer::viewDestroyed); | 318 | | ||
271 | emit viewAdded(view); | 319 | void TabbedViewContainer::disconnectTerminalDisplay(TerminalDisplay *display) | ||
320 | { | ||||
321 | auto item = display->sessionController(); | ||||
322 | disconnect(item, &Konsole::SessionController::focused, this, | ||||
323 | &Konsole::TabbedViewContainer::currentSessionControllerChanged); | ||||
324 | | ||||
325 | disconnect(item, &Konsole::ViewProperties::titleChanged, this, | ||||
326 | &Konsole::TabbedViewContainer::updateTitle); | ||||
327 | | ||||
328 | disconnect(item, &Konsole::ViewProperties::iconChanged, this, | ||||
329 | &Konsole::TabbedViewContainer::updateIcon); | ||||
330 | | ||||
331 | disconnect(item, &Konsole::ViewProperties::activity, this, | ||||
332 | &Konsole::TabbedViewContainer::updateActivity); | ||||
272 | } | 333 | } | ||
273 | 334 | | |||
274 | void TabbedViewContainer::viewDestroyed(QObject *view) | 335 | void TabbedViewContainer::viewDestroyed(QObject *view) | ||
275 | { | 336 | { | ||
276 | auto widget = static_cast<TerminalDisplay*>(view); | 337 | auto widget = static_cast<ViewSplitter*>(view); | ||
277 | const auto idx = indexOf(widget); | 338 | const auto idx = indexOf(widget); | ||
278 | 339 | | |||
279 | removeTab(idx); | 340 | removeTab(idx); | ||
280 | forgetView(widget); | 341 | forgetView(widget); | ||
281 | } | 342 | } | ||
282 | 343 | | |||
283 | void TabbedViewContainer::forgetView(TerminalDisplay *view) | 344 | void TabbedViewContainer::forgetView(ViewSplitter *view) | ||
284 | { | 345 | { | ||
285 | updateTabHistory(view, true); | 346 | //TODO: Needed ? | ||
286 | emit viewRemoved(view); | 347 | // emit viewRemoved(view); | ||
287 | if (count() == 0) { | 348 | if (count() == 0) { | ||
288 | emit empty(this); | 349 | emit empty(this); | ||
289 | } | 350 | } | ||
290 | } | 351 | } | ||
291 | 352 | | |||
292 | void TabbedViewContainer::removeView(TerminalDisplay *view) | 353 | void TabbedViewContainer::removeView(TerminalDisplay *view) | ||
293 | { | 354 | { | ||
294 | const int idx = indexOf(view); | 355 | /* TODO: This is absolutely the wrong place. | ||
295 | disconnect(view, &QWidget::destroyed, this, &Konsole::TabbedViewContainer::viewDestroyed); | 356 | * We are removing a terminal display from a ViewSplitter, | ||
296 | removeTab(idx); | 357 | * this should be inside of the view splitter or something. | ||
297 | forgetView(view); | 358 | */ | ||
359 | view->setParent(nullptr); | ||||
298 | } | 360 | } | ||
299 | 361 | | |||
300 | void TabbedViewContainer::activateNextView() | 362 | void TabbedViewContainer::activateNextView() | ||
301 | { | 363 | { | ||
302 | QWidget *active = currentWidget(); | 364 | QWidget *active = currentWidget(); | ||
303 | int index = indexOf(active); | 365 | int index = indexOf(active); | ||
304 | setCurrentIndex(index == count() - 1 ? 0 : index + 1); | 366 | setCurrentIndex(index == count() - 1 ? 0 : index + 1); | ||
305 | } | 367 | } | ||
306 | 368 | | |||
307 | void TabbedViewContainer::activateLastView() | 369 | void TabbedViewContainer::activateLastView() | ||
308 | { | 370 | { | ||
309 | setCurrentIndex(count() - 1); | 371 | setCurrentIndex(count() - 1); | ||
310 | } | 372 | } | ||
311 | 373 | | |||
312 | void TabbedViewContainer::activatePreviousView() | 374 | void TabbedViewContainer::activatePreviousView() | ||
313 | { | 375 | { | ||
314 | QWidget *active = currentWidget(); | 376 | QWidget *active = currentWidget(); | ||
315 | int index = indexOf(active); | 377 | int index = indexOf(active); | ||
316 | setCurrentIndex(index == 0 ? count() - 1 : index - 1); | 378 | setCurrentIndex(index == 0 ? count() - 1 : index - 1); | ||
317 | } | 379 | } | ||
318 | 380 | | |||
319 | void TabbedViewContainer::activateLastUsedView(bool reverse) | | |||
320 | { | | |||
321 | if (_tabHistory.count() <= 1) { | | |||
322 | return; | | |||
323 | } | | |||
324 | | ||||
325 | if (_tabHistoryIndex == -1) { | | |||
326 | _tabHistoryIndex = reverse ? _tabHistory.count() - 1 : 1; | | |||
327 | } else if (reverse) { | | |||
328 | if (_tabHistoryIndex == 0) { | | |||
329 | _tabHistoryIndex = _tabHistory.count() - 1; | | |||
330 | } else { | | |||
331 | _tabHistoryIndex--; | | |||
332 | } | | |||
333 | } else { | | |||
334 | if (_tabHistoryIndex >= _tabHistory.count() - 1) { | | |||
335 | _tabHistoryIndex = 0; | | |||
336 | } else { | | |||
337 | _tabHistoryIndex++; | | |||
338 | } | | |||
339 | } | | |||
340 | | ||||
341 | int index = indexOf(_tabHistory[_tabHistoryIndex]); | | |||
342 | setCurrentIndex(index); | | |||
343 | } | | |||
344 | | ||||
345 | // Jump to last view - this allows toggling between two views | | |||
346 | // Using "Last Used Tabs" shortcut will cause "Toggle between two tabs" | | |||
347 | // shortcut to be incorrect the first time. | | |||
348 | void TabbedViewContainer::toggleLastUsedView() | | |||
349 | { | | |||
350 | if (_tabHistory.count() <= 1) { | | |||
351 | return; | | |||
352 | } | | |||
353 | | ||||
354 | setCurrentIndex(indexOf(_tabHistory.at(1))); | | |||
355 | } | | |||
356 | | ||||
357 | void TabbedViewContainer::keyReleaseEvent(QKeyEvent* event) | 381 | void TabbedViewContainer::keyReleaseEvent(QKeyEvent* event) | ||
358 | { | 382 | { | ||
359 | if (_tabHistoryIndex != -1 && event->modifiers() == Qt::NoModifier) { | 383 | if (event->modifiers() == Qt::NoModifier) { | ||
360 | _tabHistoryIndex = -1; | 384 | _connectedViewManager->updateTerminalDisplayHistory(); | ||
361 | auto *active = qobject_cast<TerminalDisplay*>(currentWidget()); | | |||
362 | if (active != _tabHistory[0]) { | | |||
363 | // Update the tab history now that we have ended the walk-through | | |||
364 | updateTabHistory(active); | | |||
365 | } | | |||
366 | } | | |||
367 | } | | |||
368 | | ||||
369 | void TabbedViewContainer::updateTabHistory(TerminalDisplay* view, bool remove) | | |||
370 | { | | |||
371 | if (_tabHistoryIndex != -1 && !remove) { | | |||
372 | // Do not reorder the tab history while we are walking through it | | |||
373 | return; | | |||
374 | } | | |||
375 | | ||||
376 | for (int i = 0; i < _tabHistory.count(); ++i ) { | | |||
377 | if (_tabHistory[i] == view) { | | |||
378 | _tabHistory.removeAt(i); | | |||
379 | if (!remove) { | | |||
380 | _tabHistory.prepend(view); | | |||
381 | } | | |||
382 | break; | | |||
383 | } | | |||
384 | } | 385 | } | ||
385 | } | 386 | } | ||
386 | 387 | | |||
387 | void TabbedViewContainer::closeCurrentTab() | 388 | void TabbedViewContainer::closeCurrentTab() | ||
388 | { | 389 | { | ||
389 | if (currentIndex() != -1) { | 390 | if (currentIndex() != -1) { | ||
390 | closeTerminalTab(currentIndex()); | 391 | closeTerminalTab(currentIndex()); | ||
391 | } | 392 | } | ||
392 | } | 393 | } | ||
393 | 394 | | |||
394 | void TabbedViewContainer::tabDoubleClicked(int index) | 395 | void TabbedViewContainer::tabDoubleClicked(int index) | ||
395 | { | 396 | { | ||
396 | if (index >= 0) { | 397 | if (index >= 0) { | ||
397 | renameTab(index); | 398 | renameTab(index); | ||
398 | } else { | 399 | } else { | ||
399 | emit newViewRequest(this); | 400 | emit newViewRequest(this); | ||
400 | } | 401 | } | ||
401 | } | 402 | } | ||
402 | 403 | | |||
403 | void TabbedViewContainer::renameTab(int index) | 404 | void TabbedViewContainer::renameTab(int index) | ||
404 | { | 405 | { | ||
405 | if (index != -1) { | 406 | if (index != -1) { | ||
406 | terminalAt(index)->sessionController()->rename(); | 407 | setCurrentIndex(index); | ||
408 | viewSplitterAt(index) | ||||
409 | -> activeTerminalDisplay() | ||||
410 | -> sessionController() | ||||
411 | -> rename(); | ||||
407 | } | 412 | } | ||
408 | } | 413 | } | ||
409 | 414 | | |||
410 | void TabbedViewContainer::openTabContextMenu(const QPoint &point) | 415 | void TabbedViewContainer::openTabContextMenu(const QPoint &point) | ||
411 | { | 416 | { | ||
412 | if (point.isNull()) { | 417 | if (point.isNull()) { | ||
413 | return; | 418 | return; | ||
414 | } | 419 | } | ||
415 | 420 | | |||
416 | _contextMenuTabIndex = tabBar()->tabAt(point); | 421 | _contextMenuTabIndex = tabBar()->tabAt(point); | ||
417 | if (_contextMenuTabIndex < 0) { | 422 | if (_contextMenuTabIndex < 0) { | ||
418 | return; | 423 | return; | ||
419 | } | 424 | } | ||
420 | 425 | | |||
421 | //TODO: add a countChanged signal so we can remove this for. | 426 | //TODO: add a countChanged signal so we can remove this for. | ||
422 | // Detaching in mac causes crashes. | 427 | // Detaching in mac causes crashes. | ||
423 | #if defined(ENABLE_DETACHING) | 428 | #if defined(ENABLE_DETACHING) | ||
424 | for(auto action : _contextPopupMenu->actions()) { | 429 | for(auto action : _contextPopupMenu->actions()) { | ||
425 | if (action->objectName() == QStringLiteral("tab-detach")) { | 430 | if (action->objectName() == QStringLiteral("tab-detach")) { | ||
426 | action->setEnabled(count() > 1); | 431 | action->setEnabled(count() > 1); | ||
427 | } | 432 | } | ||
428 | } | 433 | } | ||
429 | #endif | 434 | #endif | ||
430 | 435 | | |||
436 | /* This needs to nove away fro the tab or to lock every thing inside of it. | ||||
437 | * for now, disable. | ||||
438 | * */ | ||||
439 | // | ||||
431 | // Add the read-only action | 440 | // Add the read-only action | ||
432 | auto controller = terminalAt(_contextMenuTabIndex)->sessionController(); | 441 | #if 0 | ||
433 | auto sessionController = qobject_cast<SessionController*>(controller); | 442 | auto sessionController = terminalAt(_contextMenuTabIndex)->sessionController(); | ||
434 | 443 | | |||
435 | if (sessionController != nullptr) { | 444 | if (sessionController != nullptr) { | ||
436 | auto collection = sessionController->actionCollection(); | 445 | auto collection = sessionController->actionCollection(); | ||
437 | auto readonlyAction = collection->action(QStringLiteral("view-readonly")); | 446 | auto readonlyAction = collection->action(QStringLiteral("view-readonly")); | ||
438 | if (readonlyAction != nullptr) { | 447 | if (readonlyAction != nullptr) { | ||
439 | const auto readonlyActions = _contextPopupMenu->actions(); | 448 | const auto readonlyActions = _contextPopupMenu->actions(); | ||
440 | _contextPopupMenu->insertAction(readonlyActions.last(), readonlyAction); | 449 | _contextPopupMenu->insertAction(readonlyActions.last(), readonlyAction); | ||
441 | } | 450 | } | ||
442 | 451 | | |||
443 | // Disable tab rename | 452 | // Disable tab rename | ||
444 | for (auto &action : _contextPopupMenu->actions()) { | 453 | for (auto &action : _contextPopupMenu->actions()) { | ||
445 | if (action->objectName() == QStringLiteral("edit-rename")) { | 454 | if (action->objectName() == QStringLiteral("edit-rename")) { | ||
446 | action->setEnabled(!sessionController->isReadOnly()); | 455 | action->setEnabled(!sessionController->isReadOnly()); | ||
447 | break; | 456 | break; | ||
448 | } | 457 | } | ||
449 | } | 458 | } | ||
450 | } | 459 | } | ||
451 | 460 | #endif | |||
452 | _contextPopupMenu->exec(tabBar()->mapToGlobal(point)); | 461 | _contextPopupMenu->exec(tabBar()->mapToGlobal(point)); | ||
453 | } | 462 | } | ||
454 | 463 | | |||
455 | void TabbedViewContainer::currentTabChanged(int index) | 464 | void TabbedViewContainer::currentTabChanged(int index) | ||
456 | { | 465 | { | ||
457 | if (index != -1) { | 466 | if (index != -1) { | ||
458 | auto *view = terminalAt(index); | 467 | auto splitview = qobject_cast<ViewSplitter*>(widget(index)); | ||
459 | view->setFocus(); | 468 | auto view = splitview->activeTerminalDisplay(); | ||
460 | updateTabHistory(view); | | |||
461 | emit activeViewChanged(view); | 469 | emit activeViewChanged(view); | ||
462 | setTabActivity(index, false); | 470 | setTabActivity(index, false); | ||
463 | } else { | 471 | } else { | ||
464 | deleteLater(); | 472 | deleteLater(); | ||
465 | } | 473 | } | ||
466 | } | 474 | } | ||
467 | 475 | | |||
468 | void TabbedViewContainer::wheelScrolled(int delta) | 476 | void TabbedViewContainer::wheelScrolled(int delta) | ||
Show All 25 Lines | |||||
494 | { | 502 | { | ||
495 | auto controller = qobject_cast<SessionController*>(item); | 503 | auto controller = qobject_cast<SessionController*>(item); | ||
496 | auto index = indexOf(controller->view()); | 504 | auto index = indexOf(controller->view()); | ||
497 | if (index != currentIndex()) { | 505 | if (index != currentIndex()) { | ||
498 | setTabActivity(index, true); | 506 | setTabActivity(index, true); | ||
499 | } | 507 | } | ||
500 | } | 508 | } | ||
501 | 509 | | |||
510 | void TabbedViewContainer::currentSessionControllerChanged(SessionController *controller) | ||||
511 | { | ||||
512 | updateTitle(qobject_cast<ViewProperties*>(controller)); | ||||
513 | } | ||||
514 | | ||||
502 | void TabbedViewContainer::updateTitle(ViewProperties *item) | 515 | void TabbedViewContainer::updateTitle(ViewProperties *item) | ||
503 | { | 516 | { | ||
504 | auto controller = qobject_cast<SessionController*>(item); | 517 | auto controller = qobject_cast<SessionController*>(item); | ||
518 | auto topLevelSplitter = qobject_cast<ViewSplitter*>(controller->view()->parentWidget())->getToplevelSplitter(); | ||||
505 | 519 | | |||
506 | const int index = indexOf(controller->view()); | 520 | const int index = indexOf(topLevelSplitter); | ||
507 | QString tabText = item->title(); | 521 | QString tabText = item->title(); | ||
508 | 522 | | |||
509 | setTabToolTip(index, tabText); | 523 | setTabToolTip(index, tabText); | ||
510 | 524 | | |||
511 | // To avoid having & replaced with _ (shortcut indicator) | 525 | // To avoid having & replaced with _ (shortcut indicator) | ||
512 | tabText.replace(QLatin1Char('&'), QLatin1String("&&")); | 526 | tabText.replace(QLatin1Char('&'), QLatin1String("&&")); | ||
513 | setTabText(index, tabText); | 527 | setTabText(index, tabText); | ||
514 | } | 528 | } | ||
515 | 529 | | |||
516 | void TabbedViewContainer::updateIcon(ViewProperties *item) | 530 | void TabbedViewContainer::updateIcon(ViewProperties *item) | ||
517 | { | 531 | { | ||
518 | auto controller = qobject_cast<SessionController*>(item); | 532 | auto controller = qobject_cast<SessionController*>(item); | ||
519 | const int index = indexOf(controller->view()); | 533 | const int index = indexOf(controller->view()); | ||
520 | setTabIcon(index, item->icon()); | 534 | setTabIcon(index, item->icon()); | ||
521 | } | 535 | } | ||
522 | 536 | | |||
523 | void TabbedViewContainer::closeTerminalTab(int idx) { | 537 | void TabbedViewContainer::closeTerminalTab(int idx) { | ||
524 | terminalAt(idx)->sessionController()->closeSession(); | 538 | //TODO: This for should probably go to the ViewSplitter | ||
539 | for (auto terminal : viewSplitterAt(idx)->findChildren<TerminalDisplay*>()) { | ||||
540 | terminal->sessionController()->closeSession(); | ||||
541 | } | ||||
525 | } | 542 | } | ||
526 | 543 | | |||
527 | ViewManager *TabbedViewContainer::connectedViewManager() | 544 | ViewManager *TabbedViewContainer::connectedViewManager() | ||
528 | { | 545 | { | ||
529 | return _connectedViewManager; | 546 | return _connectedViewManager; | ||
530 | } | 547 | } | ||
531 | 548 | | |||
532 | void TabbedViewContainer::setNavigationVisibility(ViewManager::NavigationVisibility navigationVisibility) { | 549 | void TabbedViewContainer::setNavigationVisibility(ViewManager::NavigationVisibility navigationVisibility) { | ||
533 | if (navigationVisibility == ViewManager::NavigationNotSet) { | 550 | if (navigationVisibility == ViewManager::NavigationNotSet) { | ||
534 | return; | 551 | return; | ||
535 | } | 552 | } | ||
536 | 553 | | |||
537 | setTabBarAutoHide(navigationVisibility == ViewManager::ShowNavigationAsNeeded); | 554 | setTabBarAutoHide(navigationVisibility == ViewManager::ShowNavigationAsNeeded); | ||
538 | if (navigationVisibility == ViewManager::AlwaysShowNavigation) { | 555 | if (navigationVisibility == ViewManager::AlwaysShowNavigation) { | ||
539 | tabBar()->setVisible(true); | 556 | tabBar()->setVisible(true); | ||
540 | } else if (navigationVisibility == ViewManager::AlwaysHideNavigation) { | 557 | } else if (navigationVisibility == ViewManager::AlwaysHideNavigation) { | ||
541 | tabBar()->setVisible(false); | 558 | tabBar()->setVisible(false); | ||
542 | } | 559 | } | ||
543 | } | 560 | } | ||
561 | | ||||
562 | void TabbedViewContainer::maximizeCurrentTerminal() | ||||
563 | { | ||||
564 | activeViewSplitter()->maximizeCurrentTerminal(); | ||||
565 | } | ||||
566 | | ||||
567 | void TabbedViewContainer::restoreOtherTerminals() | ||||
568 | { | ||||
569 | activeViewSplitter()->restoreOtherTerminals(); | ||||
570 | } |