Changeset View
Changeset View
Standalone View
Standalone View
src/ViewManager.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
47 | #include "ViewContainer.h" | 47 | #include "ViewContainer.h" | ||
48 | 48 | | |||
49 | using namespace Konsole; | 49 | using namespace Konsole; | ||
50 | 50 | | |||
51 | int ViewManager::lastManagerId = 0; | 51 | int ViewManager::lastManagerId = 0; | ||
52 | 52 | | |||
53 | ViewManager::ViewManager(QObject *parent, KActionCollection *collection) : | 53 | ViewManager::ViewManager(QObject *parent, KActionCollection *collection) : | ||
54 | QObject(parent), | 54 | QObject(parent), | ||
55 | _viewSplitter(nullptr), | 55 | _viewContainer(nullptr), | ||
56 | _pluggedController(nullptr), | 56 | _pluggedController(nullptr), | ||
57 | _sessionMap(QHash<TerminalDisplay *, Session *>()), | 57 | _sessionMap(QHash<TerminalDisplay *, Session *>()), | ||
58 | _actionCollection(collection), | 58 | _actionCollection(collection), | ||
59 | _navigationMethod(NoNavigation), | 59 | _navigationMethod(NoNavigation), | ||
60 | _navigationVisibility(NavigationNotSet), | 60 | _navigationVisibility(NavigationNotSet), | ||
61 | _newTabBehavior(PutNewTabAtTheEnd), | 61 | _newTabBehavior(PutNewTabAtTheEnd), | ||
62 | _managerId(0) | 62 | _managerId(0) | ||
63 | { | 63 | { | ||
64 | // create main view area | 64 | _viewContainer = createContainer(); | ||
65 | _viewSplitter = new ViewSplitter(nullptr); | | |||
66 | KAcceleratorManager::setNoAccel(_viewSplitter); | | |||
67 | | ||||
68 | // the ViewSplitter class supports both recursive and non-recursive splitting, | | |||
69 | // in non-recursive mode, all containers are inserted into the same top-level splitter | | |||
70 | // widget, and all the divider lines between the containers have the same orientation | | |||
71 | // | | |||
72 | // the ViewManager class is not currently able to handle a ViewSplitter in recursive-splitting | | |||
73 | // mode | | |||
74 | _viewSplitter->setRecursiveSplitting(false); | | |||
75 | _viewSplitter->setFocusPolicy(Qt::NoFocus); | | |||
76 | | ||||
77 | // setup actions which are related to the views | 65 | // setup actions which are related to the views | ||
78 | setupActions(); | 66 | setupActions(); | ||
79 | 67 | | |||
68 | /* TODO: Reconnect | ||||
80 | // emit a signal when all of the views held by this view manager are destroyed | 69 | // emit a signal when all of the views held by this view manager are destroyed | ||
81 | connect(_viewSplitter.data(), &Konsole::ViewSplitter::allContainersEmpty, | 70 | */ | ||
71 | connect(_viewContainer.data(), &Konsole::TabbedViewContainer::empty, | ||||
82 | this, &Konsole::ViewManager::empty); | 72 | this, &Konsole::ViewManager::empty); | ||
83 | connect(_viewSplitter.data(), &Konsole::ViewSplitter::empty, this, | | |||
84 | &Konsole::ViewManager::empty); | | |||
85 | 73 | | |||
86 | // listen for profile changes | 74 | // listen for profile changes | ||
87 | connect(ProfileManager::instance(), &Konsole::ProfileManager::profileChanged, | 75 | connect(ProfileManager::instance(), &Konsole::ProfileManager::profileChanged, | ||
88 | this, &Konsole::ViewManager::profileChanged); | 76 | this, &Konsole::ViewManager::profileChanged); | ||
89 | connect(SessionManager::instance(), &Konsole::SessionManager::sessionUpdated, | 77 | connect(SessionManager::instance(), &Konsole::SessionManager::sessionUpdated, | ||
90 | this, &Konsole::ViewManager::updateViewsForSession); | 78 | this, &Konsole::ViewManager::updateViewsForSession); | ||
91 | 79 | | |||
92 | //prepare DBus communication | 80 | //prepare DBus communication | ||
93 | new WindowAdaptor(this); | 81 | new WindowAdaptor(this); | ||
94 | 82 | | |||
95 | _managerId = ++lastManagerId; | 83 | _managerId = ++lastManagerId; | ||
96 | QDBusConnection::sessionBus().registerObject(QLatin1String("/Windows/") | 84 | QDBusConnection::sessionBus().registerObject(QLatin1String("/Windows/") | ||
97 | + QString::number(_managerId), this); | 85 | + QString::number(_managerId), this); | ||
98 | | ||||
99 | _viewSplitter->addContainer(createContainer(), Qt::Vertical); | | |||
100 | } | 86 | } | ||
101 | 87 | | |||
102 | ViewManager::~ViewManager() = default; | 88 | ViewManager::~ViewManager() = default; | ||
103 | 89 | | |||
104 | int ViewManager::managerId() const | 90 | int ViewManager::managerId() const | ||
105 | { | 91 | { | ||
106 | return _managerId; | 92 | return _managerId; | ||
107 | } | 93 | } | ||
108 | 94 | | |||
109 | QWidget *ViewManager::activeView() const | 95 | QWidget *ViewManager::activeView() const | ||
110 | { | 96 | { | ||
111 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 97 | return _viewContainer->currentWidget(); | ||
112 | if (container != nullptr) { | | |||
113 | return container->currentWidget(); | | |||
114 | } else { | | |||
115 | return nullptr; | | |||
116 | } | | |||
117 | } | 98 | } | ||
118 | 99 | | |||
119 | QWidget *ViewManager::widget() const | 100 | QWidget *ViewManager::widget() const | ||
120 | { | 101 | { | ||
121 | return _viewSplitter; | 102 | return _viewContainer; | ||
122 | } | 103 | } | ||
123 | 104 | | |||
124 | void ViewManager::setupActions() | 105 | void ViewManager::setupActions() | ||
125 | { | 106 | { | ||
126 | Q_ASSERT(_actionCollection); | 107 | Q_ASSERT(_actionCollection); | ||
127 | if (_actionCollection == nullptr) { | 108 | if (_actionCollection == nullptr) { | ||
128 | return; | 109 | return; | ||
129 | } | 110 | } | ||
Show All 28 Lines | |||||
158 | 139 | | |||
159 | QAction *splitTopBottomAction = new QAction(QIcon::fromTheme(QStringLiteral("view-split-top-bottom")), | 140 | QAction *splitTopBottomAction = new QAction(QIcon::fromTheme(QStringLiteral("view-split-top-bottom")), | ||
160 | i18nc("@action:inmenu", | 141 | i18nc("@action:inmenu", | ||
161 | "Split View Top/Bottom"), this); | 142 | "Split View Top/Bottom"), this); | ||
162 | collection->setDefaultShortcut(splitTopBottomAction, Konsole::ACCEL + Qt::Key_ParenRight); | 143 | collection->setDefaultShortcut(splitTopBottomAction, Konsole::ACCEL + Qt::Key_ParenRight); | ||
163 | collection->addAction(QStringLiteral("split-view-top-bottom"), splitTopBottomAction); | 144 | collection->addAction(QStringLiteral("split-view-top-bottom"), splitTopBottomAction); | ||
164 | connect(splitTopBottomAction, &QAction::triggered, this, &Konsole::ViewManager::splitTopBottom); | 145 | connect(splitTopBottomAction, &QAction::triggered, this, &Konsole::ViewManager::splitTopBottom); | ||
165 | 146 | | |||
166 | QAction *closeActiveAction = new QAction(i18nc("@action:inmenu Close Active View", "Close Active"), this); | | |||
167 | closeActiveAction->setIcon(QIcon::fromTheme(QStringLiteral("view-close"))); | | |||
168 | collection->setDefaultShortcut(closeActiveAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_X); | | |||
169 | closeActiveAction->setEnabled(false); | | |||
170 | collection->addAction(QStringLiteral("close-active-view"), closeActiveAction); | | |||
171 | connect(closeActiveAction, &QAction::triggered, this, | | |||
172 | &Konsole::ViewManager::closeActiveContainer); | | |||
173 | | ||||
174 | multiViewOnlyActions << closeActiveAction; | | |||
175 | | ||||
176 | QAction *closeOtherAction = new QAction(i18nc("@action:inmenu Close Other Views", | | |||
177 | "Close Others"), this); | | |||
178 | collection->setDefaultShortcut(closeOtherAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_O); | | |||
179 | closeOtherAction->setEnabled(false); | | |||
180 | collection->addAction(QStringLiteral("close-other-views"), closeOtherAction); | | |||
181 | connect(closeOtherAction, &QAction::triggered, this, | | |||
182 | &Konsole::ViewManager::closeOtherContainers); | | |||
183 | | ||||
184 | multiViewOnlyActions << closeOtherAction; | | |||
185 | | ||||
186 | // Expand & Shrink Active View | 147 | // Expand & Shrink Active View | ||
187 | QAction *expandActiveAction = new QAction(i18nc("@action:inmenu", "Expand View"), this); | 148 | QAction *expandActiveAction = new QAction(i18nc("@action:inmenu", "Expand View"), this); | ||
188 | collection->setDefaultShortcut(expandActiveAction, | 149 | collection->setDefaultShortcut(expandActiveAction, | ||
189 | Konsole::ACCEL + Qt::SHIFT + Qt::Key_BracketRight); | 150 | Konsole::ACCEL + Qt::SHIFT + Qt::Key_BracketRight); | ||
190 | expandActiveAction->setEnabled(false); | 151 | expandActiveAction->setEnabled(false); | ||
191 | collection->addAction(QStringLiteral("expand-active-view"), expandActiveAction); | 152 | collection->addAction(QStringLiteral("expand-active-view"), expandActiveAction); | ||
192 | connect(expandActiveAction, &QAction::triggered, this, | 153 | connect(expandActiveAction, &QAction::triggered, this, | ||
193 | &Konsole::ViewManager::expandActiveContainer); | 154 | &Konsole::ViewManager::expandActiveContainer); | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 181 | #endif | |||
244 | foreach (QAction *action, multiViewOnlyActions) { | 205 | foreach (QAction *action, multiViewOnlyActions) { | ||
245 | connect(this, &Konsole::ViewManager::splitViewToggle, action, &QAction::setEnabled); | 206 | connect(this, &Konsole::ViewManager::splitViewToggle, action, &QAction::setEnabled); | ||
246 | } | 207 | } | ||
247 | 208 | | |||
248 | // keyboard shortcut only actions | 209 | // keyboard shortcut only actions | ||
249 | const QList<QKeySequence> nextViewActionKeys{Qt::SHIFT + Qt::Key_Right, Qt::CTRL + Qt::Key_PageDown}; | 210 | const QList<QKeySequence> nextViewActionKeys{Qt::SHIFT + Qt::Key_Right, Qt::CTRL + Qt::Key_PageDown}; | ||
250 | collection->setDefaultShortcuts(nextViewAction, nextViewActionKeys); | 211 | collection->setDefaultShortcuts(nextViewAction, nextViewActionKeys); | ||
251 | connect(nextViewAction, &QAction::triggered, this, &Konsole::ViewManager::nextView); | 212 | connect(nextViewAction, &QAction::triggered, this, &Konsole::ViewManager::nextView); | ||
252 | _viewSplitter->addAction(nextViewAction); | 213 | // _viewSplitter->addAction(nextViewAction); | ||
253 | 214 | | |||
254 | const QList<QKeySequence> previousViewActionKeys{Qt::SHIFT + Qt::Key_Left, Qt::CTRL + Qt::Key_PageUp}; | 215 | const QList<QKeySequence> previousViewActionKeys{Qt::SHIFT + Qt::Key_Left, Qt::CTRL + Qt::Key_PageUp}; | ||
255 | collection->setDefaultShortcuts(previousViewAction, previousViewActionKeys); | 216 | collection->setDefaultShortcuts(previousViewAction, previousViewActionKeys); | ||
256 | connect(previousViewAction, &QAction::triggered, this, &Konsole::ViewManager::previousView); | 217 | connect(previousViewAction, &QAction::triggered, this, &Konsole::ViewManager::previousView); | ||
257 | _viewSplitter->addAction(previousViewAction); | 218 | // _viewSplitter->addAction(previousViewAction); | ||
258 | 219 | | |||
259 | collection->setDefaultShortcut(nextContainerAction, Qt::SHIFT + Qt::Key_Tab); | 220 | collection->setDefaultShortcut(nextContainerAction, Qt::SHIFT + Qt::CTRL + Qt::Key_Up); | ||
260 | connect(nextContainerAction, &QAction::triggered, this, &Konsole::ViewManager::nextContainer); | 221 | connect(nextContainerAction, &QAction::triggered, this, &Konsole::ViewManager::focusUp); | ||
261 | _viewSplitter->addAction(nextContainerAction); | 222 | _viewContainer->addAction(nextContainerAction); | ||
223 | | ||||
224 | auto *action = new QAction(QStringLiteral("Focus Down")); | ||||
225 | collection->setDefaultShortcut(action, Qt::SHIFT + Qt::CTRL + Qt::Key_Down); | ||||
226 | connect(action, &QAction::triggered, this, &Konsole::ViewManager::focusDown); | ||||
227 | _viewContainer->addAction(action); | ||||
262 | 228 | | |||
263 | #ifdef Q_OS_MACOS | 229 | #ifdef Q_OS_MACOS | ||
264 | collection->setDefaultShortcut(moveViewLeftAction, | 230 | collection->setDefaultShortcut(moveViewLeftAction, | ||
265 | Konsole::ACCEL + Qt::SHIFT + Qt::Key_BracketLeft); | 231 | Konsole::ACCEL + Qt::SHIFT + Qt::Key_BracketLeft); | ||
266 | #else | 232 | #else | ||
267 | collection->setDefaultShortcut(moveViewLeftAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_Left); | 233 | collection->setDefaultShortcut(moveViewLeftAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_Left); | ||
268 | #endif | 234 | #endif | ||
269 | connect(moveViewLeftAction, &QAction::triggered, this, | 235 | connect(moveViewLeftAction, &QAction::triggered, this, | ||
270 | &Konsole::ViewManager::moveActiveViewLeft); | 236 | &Konsole::ViewManager::focusLeft); | ||
271 | _viewSplitter->addAction(moveViewLeftAction); | 237 | // _viewSplitter->addAction(moveViewLeftAction); | ||
272 | 238 | | |||
273 | #ifdef Q_OS_MACOS | 239 | #ifdef Q_OS_MACOS | ||
274 | collection->setDefaultShortcut(moveViewRightAction, | 240 | collection->setDefaultShortcut(moveViewRightAction, | ||
275 | Konsole::ACCEL + Qt::SHIFT + Qt::Key_BracketRight); | 241 | Konsole::ACCEL + Qt::SHIFT + Qt::Key_BracketRight); | ||
276 | #else | 242 | #else | ||
277 | collection->setDefaultShortcut(moveViewRightAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_Right); | 243 | collection->setDefaultShortcut(moveViewRightAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_Right); | ||
278 | #endif | 244 | #endif | ||
279 | connect(moveViewRightAction, &QAction::triggered, this, | 245 | connect(moveViewRightAction, &QAction::triggered, this, | ||
280 | &Konsole::ViewManager::moveActiveViewRight); | 246 | &Konsole::ViewManager::focusRight); | ||
281 | _viewSplitter->addAction(moveViewRightAction); | 247 | // _viewSplitter->addAction(moveViewRightAction); | ||
282 | 248 | | |||
283 | connect(lastViewAction, &QAction::triggered, this, &Konsole::ViewManager::lastView); | 249 | connect(lastViewAction, &QAction::triggered, this, &Konsole::ViewManager::lastView); | ||
284 | _viewSplitter->addAction(lastViewAction); | 250 | // _viewSplitter->addAction(lastViewAction); | ||
285 | 251 | | |||
286 | collection->setDefaultShortcut(lastUsedViewAction, Qt::CTRL + Qt::Key_Tab); | 252 | collection->setDefaultShortcut(lastUsedViewAction, Qt::CTRL + Qt::Key_Tab); | ||
287 | connect(lastUsedViewAction, &QAction::triggered, this, &Konsole::ViewManager::lastUsedView); | 253 | connect(lastUsedViewAction, &QAction::triggered, this, &Konsole::ViewManager::lastUsedView); | ||
288 | _viewSplitter->addAction(lastUsedViewAction); | 254 | // _viewSplitter->addAction(lastUsedViewAction); | ||
289 | 255 | | |||
290 | collection->setDefaultShortcut(lastUsedViewReverseAction, Qt::CTRL + Qt::SHIFT + Qt::Key_Tab); | 256 | collection->setDefaultShortcut(lastUsedViewReverseAction, Qt::CTRL + Qt::SHIFT + Qt::Key_Tab); | ||
291 | connect(lastUsedViewReverseAction, &QAction::triggered, this, &Konsole::ViewManager::lastUsedViewReverse); | 257 | connect(lastUsedViewReverseAction, &QAction::triggered, this, &Konsole::ViewManager::lastUsedViewReverse); | ||
292 | _viewSplitter->addAction(lastUsedViewReverseAction); | 258 | // _viewSplitter->addAction(lastUsedViewReverseAction); | ||
293 | } | 259 | } | ||
294 | 260 | | |||
295 | void ViewManager::switchToView(int index) | 261 | void ViewManager::switchToView(int index) | ||
296 | { | 262 | { | ||
297 | _viewSplitter->activeContainer()->setCurrentIndex(index); | 263 | _viewContainer->setCurrentIndex(index); | ||
298 | } | 264 | } | ||
299 | 265 | | |||
300 | void ViewManager::updateDetachViewState() | 266 | void ViewManager::updateDetachViewState() | ||
301 | { | 267 | { | ||
302 | Q_ASSERT(_actionCollection); | 268 | Q_ASSERT(_actionCollection); | ||
303 | if (_actionCollection == nullptr) { | 269 | if (_actionCollection == nullptr) { | ||
304 | return; | 270 | return; | ||
305 | } | 271 | } | ||
306 | 272 | | |||
273 | #if 0 | ||||
307 | const bool splitView = _viewSplitter->containers().count() >= 2; | 274 | const bool splitView = _viewSplitter->containers().count() >= 2; | ||
maciejn: There is a method ViewSplitter::getTerminalDisplays() which is a lot more complicated than this. | |||||
tcanabrava: nice catch. that's really easy to remove. | |||||
308 | auto activeContainer = _viewSplitter->activeContainer(); | 275 | auto activeContainer = _viewSplitter->activeContainer(); | ||
309 | const bool shouldEnable = splitView | 276 | const bool shouldEnable = splitView | ||
310 | || ((activeContainer != nullptr) | 277 | || ((activeContainer != nullptr) | ||
311 | && activeContainer->count() >= 2); | 278 | && activeContainer->count() >= 2); | ||
312 | 279 | | |||
313 | QAction *detachAction = _actionCollection->action(QStringLiteral("detach-view")); | 280 | QAction *detachAction = _actionCollection->action(QStringLiteral("detach-view")); | ||
314 | 281 | | |||
315 | if ((detachAction != nullptr) && shouldEnable != detachAction->isEnabled()) { | 282 | if ((detachAction != nullptr) && shouldEnable != detachAction->isEnabled()) { | ||
316 | detachAction->setEnabled(shouldEnable); | 283 | detachAction->setEnabled(shouldEnable); | ||
317 | } | 284 | } | ||
285 | #endif | ||||
286 | } | ||||
287 | | ||||
288 | void ViewManager::focusUp() | ||||
289 | { | ||||
290 | _viewContainer->activeViewSplitter()->focusUp(); | ||||
291 | } | ||||
292 | | ||||
293 | void ViewManager::focusDown() | ||||
294 | { | ||||
295 | _viewContainer->activeViewSplitter()->focusDown(); | ||||
296 | } | ||||
297 | | ||||
298 | void ViewManager::focusLeft() | ||||
299 | { | ||||
300 | _viewContainer->activeViewSplitter()->focusLeft(); | ||||
301 | } | ||||
302 | | ||||
303 | void ViewManager::focusRight() | ||||
304 | { | ||||
305 | _viewContainer->activeViewSplitter()->focusRight(); | ||||
318 | } | 306 | } | ||
319 | 307 | | |||
320 | void ViewManager::moveActiveViewLeft() | 308 | void ViewManager::moveActiveViewLeft() | ||
321 | { | 309 | { | ||
322 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 310 | _viewContainer->moveActiveView(TabbedViewContainer::MoveViewLeft); | ||
323 | Q_ASSERT(container); | | |||
324 | container->moveActiveView(TabbedViewContainer::MoveViewLeft); | | |||
325 | } | 311 | } | ||
326 | 312 | | |||
327 | void ViewManager::moveActiveViewRight() | 313 | void ViewManager::moveActiveViewRight() | ||
328 | { | 314 | { | ||
329 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 315 | _viewContainer->moveActiveView(TabbedViewContainer::MoveViewRight); | ||
330 | Q_ASSERT(container); | | |||
331 | container->moveActiveView(TabbedViewContainer::MoveViewRight); | | |||
332 | } | 316 | } | ||
333 | 317 | | |||
334 | void ViewManager::nextContainer() | 318 | void ViewManager::nextContainer() | ||
335 | { | 319 | { | ||
336 | _viewSplitter->activateNextContainer(); | 320 | // _viewSplitter->activateNextContainer(); | ||
hindenburg: ? | |||||
there's no notion of 'nextContainer' anymore, so I commented that out. I need to see if the call is userfull at all or remove. tcanabrava: there's no notion of 'nextContainer' anymore, so I commented that out. I need to see if the… | |||||
337 | } | 321 | } | ||
338 | 322 | | |||
339 | void ViewManager::nextView() | 323 | void ViewManager::nextView() | ||
340 | { | 324 | { | ||
341 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 325 | _viewContainer->activateNextView(); | ||
342 | Q_ASSERT(container); | | |||
343 | container->activateNextView(); | | |||
344 | } | 326 | } | ||
345 | 327 | | |||
346 | void ViewManager::previousView() | 328 | void ViewManager::previousView() | ||
347 | { | 329 | { | ||
348 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 330 | _viewContainer->activatePreviousView(); | ||
349 | Q_ASSERT(container); | | |||
350 | container->activatePreviousView(); | | |||
351 | } | 331 | } | ||
352 | 332 | | |||
353 | void ViewManager::lastView() | 333 | void ViewManager::lastView() | ||
354 | { | 334 | { | ||
355 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 335 | _viewContainer->activateLastView(); | ||
356 | Q_ASSERT(container); | | |||
357 | container->activateLastView(); | | |||
358 | } | 336 | } | ||
359 | 337 | | |||
360 | void ViewManager::lastUsedView() | 338 | void ViewManager::lastUsedView() | ||
361 | { | 339 | { | ||
362 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 340 | _viewContainer->activateLastUsedView(false); | ||
363 | Q_ASSERT(container); | | |||
364 | container->activateLastUsedView(false); | | |||
365 | } | 341 | } | ||
366 | 342 | | |||
367 | void ViewManager::lastUsedViewReverse() | 343 | void ViewManager::lastUsedViewReverse() | ||
368 | { | 344 | { | ||
369 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 345 | _viewContainer->activateLastUsedView(true); | ||
370 | Q_ASSERT(container); | | |||
371 | container->activateLastUsedView(true); | | |||
372 | } | 346 | } | ||
373 | 347 | | |||
374 | void ViewManager::detachActiveView() | 348 | void ViewManager::detachActiveView() | ||
375 | { | 349 | { | ||
350 | //TODO: Disable Detach temporarely. | ||||
351 | #if 0 | ||||
376 | // find the currently active view and remove it from its container | 352 | // find the currently active view and remove it from its container | ||
377 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 353 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | ||
378 | detachView(container, container->currentWidget()); | 354 | detachView(container, container->currentWidget()); | ||
355 | #endif | ||||
379 | } | 356 | } | ||
380 | 357 | | |||
381 | void ViewManager::detachView(TabbedViewContainer *container, QWidget *view) | 358 | void ViewManager::detachView(TabbedViewContainer *container, QWidget *view) | ||
382 | { | 359 | { | ||
383 | #if !defined(ENABLE_DETACHING) | 360 | #if !defined(ENABLE_DETACHING) | ||
384 | return; | 361 | return; | ||
385 | #endif | 362 | #endif | ||
386 | 363 | | |||
Show All 14 Lines | |||||
401 | 378 | | |||
402 | // remove the view from this window | 379 | // remove the view from this window | ||
403 | container->removeView(viewToDetach); | 380 | container->removeView(viewToDetach); | ||
404 | viewToDetach->deleteLater(); | 381 | viewToDetach->deleteLater(); | ||
405 | 382 | | |||
406 | // if the container from which the view was removed is now empty then it can be deleted, | 383 | // if the container from which the view was removed is now empty then it can be deleted, | ||
407 | // unless it is the only container in the window, in which case it is left empty | 384 | // unless it is the only container in the window, in which case it is left empty | ||
408 | // so that there is always an active container | 385 | // so that there is always an active container | ||
386 | //TODO: Verify if this is correct. | ||||
387 | #if 0 | ||||
409 | if (_viewSplitter->containers().count() > 1 | 388 | if (_viewSplitter->containers().count() > 1 | ||
410 | && container->count() == 0) { | 389 | && container->count() == 0) { | ||
411 | removeContainer(container); | 390 | removeContainer(container); | ||
412 | } | 391 | } | ||
392 | #endif | ||||
413 | } | 393 | } | ||
414 | 394 | | |||
415 | void ViewManager::sessionFinished() | 395 | void ViewManager::sessionFinished() | ||
416 | { | 396 | { | ||
417 | // if this slot is called after the view manager's main widget | 397 | // if this slot is called after the view manager's main widget | ||
418 | // has been destroyed, do nothing | 398 | // has been destroyed, do nothing | ||
419 | if (_viewSplitter.isNull()) { | 399 | if (_viewContainer.isNull()) { | ||
420 | return; | 400 | return; | ||
421 | } | 401 | } | ||
422 | 402 | | |||
423 | auto *session = qobject_cast<Session *>(sender()); | 403 | auto *session = qobject_cast<Session *>(sender()); | ||
424 | Q_ASSERT(session); | 404 | Q_ASSERT(session); | ||
425 | 405 | | |||
426 | // close attached views | 406 | auto view = _sessionMap.key(session); | ||
427 | QList<TerminalDisplay *> children = _viewSplitter->findChildren<TerminalDisplay *>(); | | |||
428 | | ||||
429 | foreach (TerminalDisplay *view, children) { | | |||
430 | if (_sessionMap[view] == session) { | | |||
431 | _sessionMap.remove(view); | 407 | _sessionMap.remove(view); | ||
432 | view->deleteLater(); | 408 | view->deleteLater(); | ||
433 | } | | |||
434 | } | | |||
435 | 409 | | |||
436 | // Only remove the controller from factory() if it's actually controlling | 410 | // Only remove the controller from factory() if it's actually controlling | ||
437 | // the session from the sender. | 411 | // the session from the sender. | ||
438 | // This fixes BUG: 348478 - messed up menus after a detached tab is closed | 412 | // This fixes BUG: 348478 - messed up menus after a detached tab is closed | ||
439 | if ((!_pluggedController.isNull()) && (_pluggedController->session() == session)) { | 413 | if ((!_pluggedController.isNull()) && (_pluggedController->session() == session)) { | ||
440 | // This is needed to remove this controller from factory() in | 414 | // This is needed to remove this controller from factory() in | ||
441 | // order to prevent BUG: 185466 - disappearing menu popup | 415 | // order to prevent BUG: 185466 - disappearing menu popup | ||
442 | emit unplugController(_pluggedController); | 416 | emit unplugController(_pluggedController); | ||
443 | } | 417 | } | ||
418 | | ||||
419 | focusAnotherTerminal(view); | ||||
444 | } | 420 | } | ||
445 | 421 | | |||
422 | void ViewManager::focusAnotherTerminal(TerminalDisplay *lostFocus) | ||||
423 | { | ||||
424 | auto viewSplitter = _viewContainer->activeViewSplitter(); | ||||
425 | auto terminalDisplays = viewSplitter->findChildren<TerminalDisplay*>(); | ||||
426 | for (auto terminalDisplay : terminalDisplays) { | ||||
427 | if (terminalDisplay != lostFocus) { | ||||
428 | terminalDisplay->setFocus(Qt::OtherFocusReason); | ||||
429 | return; | ||||
430 | } | ||||
431 | } | ||||
432 | } | ||||
446 | void ViewManager::viewActivated(QWidget *view) | 433 | void ViewManager::viewActivated(QWidget *view) | ||
447 | { | 434 | { | ||
448 | Q_ASSERT(view != nullptr); | 435 | Q_ASSERT(view != nullptr); | ||
449 | 436 | | |||
450 | // focus the activated view, this will cause the SessionController | 437 | // focus the activated view, this will cause the SessionController | ||
451 | // to notify the world that the view has been focused and the appropriate UI | 438 | // to notify the world that the view has been focused and the appropriate UI | ||
452 | // actions will be plugged in. | 439 | // actions will be plugged in. | ||
453 | view->setFocus(Qt::OtherFocusReason); | 440 | view->setFocus(Qt::OtherFocusReason); | ||
454 | } | 441 | } | ||
455 | 442 | | |||
456 | void ViewManager::splitLeftRight() | 443 | void ViewManager::splitLeftRight() | ||
457 | { | 444 | { | ||
458 | splitView(Qt::Horizontal); | 445 | splitView(Qt::Horizontal); | ||
459 | } | 446 | } | ||
460 | 447 | | |||
461 | void ViewManager::splitTopBottom() | 448 | void ViewManager::splitTopBottom() | ||
462 | { | 449 | { | ||
463 | splitView(Qt::Vertical); | 450 | splitView(Qt::Vertical); | ||
464 | } | 451 | } | ||
465 | 452 | | |||
466 | void ViewManager::splitView(Qt::Orientation orientation) | 453 | void ViewManager::splitView(Qt::Orientation orientation) | ||
467 | { | 454 | { | ||
468 | TabbedViewContainer *container = createContainer(); | 455 | auto viewSplitter = qobject_cast<ViewSplitter*>(_viewContainer->currentWidget()); | ||
469 | 456 | | |||
470 | if (_viewSplitter->activeContainer()->count()) { | | |||
471 | // get the currently applied profile and use it to create the new tab. | 457 | // get the currently applied profile and use it to create the new tab. | ||
472 | auto *activeContainer= _viewSplitter->activeContainer(); | 458 | auto *currentDisplay = viewSplitter->findChild<TerminalDisplay*>(); | ||
473 | auto *currentDisplay = qobject_cast<TerminalDisplay*>(activeContainer->currentWidget()); | | |||
474 | auto profile = SessionManager::instance()->sessionProfile(_sessionMap[currentDisplay]); | 459 | auto profile = SessionManager::instance()->sessionProfile(_sessionMap[currentDisplay]); | ||
475 | 460 | | |||
476 | // Create a new session with the selected profile. | 461 | // Create a new session with the selected profile. | ||
477 | auto *session = SessionManager::instance()->createSession(profile); | 462 | auto *session = SessionManager::instance()->createSession(profile); | ||
478 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | 463 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | ||
479 | 464 | | |||
480 | createView(session, container, 0); | 465 | auto terminalDisplay = createView(session); | ||
481 | } | | |||
482 | 466 | | |||
483 | _viewSplitter->addContainer(container, orientation); | 467 | viewSplitter->addTerminalDisplay(terminalDisplay, orientation); | ||
484 | emit splitViewToggle(_viewSplitter->containers().count() > 0); | 468 | emit splitViewToggle(viewSplitter->count() > 0); | ||
485 | 469 | | |||
486 | // focus the new container | 470 | // focus the new container | ||
487 | container->currentWidget()->setFocus(); | 471 | terminalDisplay->setFocus(); | ||
488 | | ||||
489 | // ensure that the active view is focused after the split / unsplit | | |||
490 | TabbedViewContainer *activeContainer = _viewSplitter->activeContainer(); | | |||
491 | QWidget *activeView = activeContainer != nullptr ? activeContainer->currentWidget() : nullptr; | | |||
492 | | ||||
493 | if (activeView != nullptr) { | | |||
494 | activeView->setFocus(Qt::OtherFocusReason); | | |||
495 | } | | |||
496 | } | 472 | } | ||
497 | 473 | | |||
498 | void ViewManager::removeContainer(TabbedViewContainer *container) | 474 | void ViewManager::removeContainer(TabbedViewContainer *container) | ||
499 | { | 475 | { | ||
476 | qDebug() << "Remove Container Called"; | ||||
477 | #if 0 | ||||
500 | // remove session map entries for views in this container | 478 | // remove session map entries for views in this container | ||
501 | for(int i = 0, end = container->count(); i < end; i++) { | 479 | for(int i = 0, end = container->count(); i < end; i++) { | ||
502 | auto view = container->widget(i); | 480 | auto view = container->widget(i); | ||
503 | auto *display = qobject_cast<TerminalDisplay *>(view); | 481 | auto *display = qobject_cast<TerminalDisplay *>(view); | ||
504 | Q_ASSERT(display); | 482 | Q_ASSERT(display); | ||
505 | _sessionMap.remove(display); | 483 | _sessionMap.remove(display); | ||
506 | } | 484 | } | ||
507 | 485 | | |||
508 | _viewSplitter->removeContainer(container); | 486 | _viewSplitter->removeContainer(container); | ||
509 | container->deleteLater(); | 487 | container->deleteLater(); | ||
510 | 488 | | |||
511 | emit splitViewToggle(_viewSplitter->containers().count() > 1); | 489 | emit splitViewToggle(_viewSplitter->containers().count() > 1); | ||
490 | #endif | ||||
512 | } | 491 | } | ||
513 | 492 | | |||
514 | void ViewManager::expandActiveContainer() | 493 | void ViewManager::expandActiveContainer() | ||
515 | { | 494 | { | ||
516 | _viewSplitter->adjustContainerSize(_viewSplitter->activeContainer(), 10); | 495 | auto activeSplitter = _viewContainer->activeViewSplitter(); | ||
496 | auto activeTerminalDisplay = activeSplitter->activeTerminalDisplay(); | ||||
497 | activeSplitter->adjustTerminalDisplaySize(activeTerminalDisplay, 10); | ||||
517 | } | 498 | } | ||
518 | 499 | | |||
519 | void ViewManager::shrinkActiveContainer() | 500 | void ViewManager::shrinkActiveContainer() | ||
520 | { | 501 | { | ||
521 | _viewSplitter->adjustContainerSize(_viewSplitter->activeContainer(), -10); | 502 | auto activeSplitter = _viewContainer->activeViewSplitter(); | ||
522 | } | 503 | auto activeTerminalDisplay = activeSplitter->activeTerminalDisplay(); | ||
523 | 504 | activeSplitter->adjustTerminalDisplaySize(activeTerminalDisplay, -10); | |||
524 | void ViewManager::closeActiveContainer() | | |||
525 | { | | |||
526 | // only do something if there is more than one container active | | |||
527 | if (_viewSplitter->containers().count() > 1) { | | |||
528 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | | |||
529 | | ||||
530 | removeContainer(container); | | |||
531 | | ||||
532 | // focus next container so that user can continue typing | | |||
533 | // without having to manually focus it themselves | | |||
534 | nextContainer(); | | |||
535 | } | | |||
536 | } | | |||
537 | | ||||
538 | void ViewManager::closeOtherContainers() | | |||
539 | { | | |||
540 | TabbedViewContainer *active = _viewSplitter->activeContainer(); | | |||
541 | | ||||
542 | foreach (TabbedViewContainer *container, _viewSplitter->containers()) { | | |||
543 | if (container != active) { | | |||
544 | removeContainer(container); | | |||
545 | } | | |||
546 | } | | |||
547 | } | 505 | } | ||
548 | 506 | | |||
549 | SessionController *ViewManager::createController(Session *session, TerminalDisplay *view) | 507 | SessionController *ViewManager::createController(Session *session, TerminalDisplay *view) | ||
550 | { | 508 | { | ||
551 | // create a new controller for the session, and ensure that this view manager | 509 | // create a new controller for the session, and ensure that this view manager | ||
552 | // is notified when the view gains the focus | 510 | // is notified when the view gains the focus | ||
553 | auto controller = new SessionController(session, view, this); | 511 | auto controller = new SessionController(session, view, this); | ||
554 | connect(controller, &Konsole::SessionController::focused, this, | 512 | connect(controller, &Konsole::SessionController::focused, this, | ||
Show All 16 Lines | |||||
571 | } | 529 | } | ||
572 | 530 | | |||
573 | void ViewManager::controllerChanged(SessionController *controller) | 531 | void ViewManager::controllerChanged(SessionController *controller) | ||
574 | { | 532 | { | ||
575 | if (controller == _pluggedController) { | 533 | if (controller == _pluggedController) { | ||
576 | return; | 534 | return; | ||
577 | } | 535 | } | ||
578 | 536 | | |||
579 | _viewSplitter->setFocusProxy(controller->view()); | 537 | //TODO: Verify This. | ||
538 | // _viewSplitter->setFocusProxy(controller->view()); | ||||
580 | 539 | | |||
anthonyfieroni: This should stay, i think. | |||||
this should actually be removed, the current way to deal with the focus is working without the proxies, also, there's no _viewSplitter anymore. tcanabrava: this should actually be removed, the current way to deal with the focus is working without the… | |||||
581 | _pluggedController = controller; | 540 | _pluggedController = controller; | ||
582 | emit activeViewChanged(controller); | 541 | emit activeViewChanged(controller); | ||
583 | } | 542 | } | ||
584 | 543 | | |||
585 | SessionController *ViewManager::activeViewController() const | 544 | SessionController *ViewManager::activeViewController() const | ||
586 | { | 545 | { | ||
587 | return _pluggedController; | 546 | return _pluggedController; | ||
588 | } | 547 | } | ||
589 | 548 | | |||
590 | void ViewManager::createView(Session *session, TabbedViewContainer *container, int index) | 549 | TerminalDisplay *ViewManager::createView(Session *session) | ||
591 | { | 550 | { | ||
592 | // notify this view manager when the session finishes so that its view | 551 | // notify this view manager when the session finishes so that its view | ||
593 | // can be deleted | 552 | // can be deleted | ||
594 | // | 553 | // | ||
595 | // Use Qt::UniqueConnection to avoid duplicate connection | 554 | // Use Qt::UniqueConnection to avoid duplicate connection | ||
596 | connect(session, &Konsole::Session::finished, this, &Konsole::ViewManager::sessionFinished, | 555 | connect(session, &Konsole::Session::finished, this, &Konsole::ViewManager::sessionFinished, | ||
597 | Qt::UniqueConnection); | 556 | Qt::UniqueConnection); | ||
598 | 557 | | |||
599 | TerminalDisplay *display = createTerminalDisplay(session); | 558 | TerminalDisplay *display = createTerminalDisplay(session); | ||
600 | const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); | 559 | const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); | ||
601 | applyProfileToView(display, profile); | 560 | applyProfileToView(display, profile); | ||
602 | 561 | | |||
603 | // set initial size | 562 | // set initial size | ||
604 | const QSize &preferredSize = session->preferredSize(); | 563 | const QSize &preferredSize = session->preferredSize(); | ||
605 | 564 | | |||
606 | display->setSize(preferredSize.width(), preferredSize.height()); | 565 | display->setSize(preferredSize.width(), preferredSize.height()); | ||
607 | createController(session, display); | 566 | createController(session, display); | ||
608 | 567 | | |||
609 | _sessionMap[display] = session; | 568 | _sessionMap[display] = session; | ||
610 | container->addView(display, index); | | |||
611 | session->addView(display); | 569 | session->addView(display); | ||
612 | 570 | | |||
613 | // tell the session whether it has a light or dark background | 571 | // tell the session whether it has a light or dark background | ||
614 | session->setDarkBackground(colorSchemeForProfile(profile)->hasDarkBackground()); | 572 | session->setDarkBackground(colorSchemeForProfile(profile)->hasDarkBackground()); | ||
615 | container->setCurrentWidget(display); | | |||
616 | display->setFocus(Qt::OtherFocusReason); | 573 | display->setFocus(Qt::OtherFocusReason); | ||
617 | | ||||
618 | updateDetachViewState(); | 574 | updateDetachViewState(); | ||
619 | } | 575 | return display; | ||
620 | | ||||
621 | void ViewManager::createView(TabbedViewContainer *tabWidget, Session *session) | | |||
622 | { | | |||
623 | const int index = _newTabBehavior == PutNewTabAfterCurrentTab ? | | |||
624 | _viewSplitter->activeContainer()->currentIndex() + 1 : -1; | | |||
625 | | ||||
626 | createView(session, tabWidget, index); | | |||
627 | } | 576 | } | ||
628 | 577 | | |||
629 | TabbedViewContainer *ViewManager::createContainer() | 578 | TabbedViewContainer *ViewManager::createContainer() | ||
630 | { | 579 | { | ||
631 | 580 | auto *container = new TabbedViewContainer(this, nullptr); | |||
632 | auto *container = new TabbedViewContainer(this, _viewSplitter); | | |||
633 | container->setNavigationVisibility(_navigationVisibility); | 581 | container->setNavigationVisibility(_navigationVisibility); | ||
634 | //TODO: Fix Detaching. | 582 | //TODO: Fix Detaching. | ||
635 | connect(container, &TabbedViewContainer::detachTab, this, &ViewManager::detachView); | 583 | connect(container, &TabbedViewContainer::detachTab, this, &ViewManager::detachView); | ||
636 | 584 | | |||
637 | // connect signals and slots | 585 | // connect signals and slots | ||
638 | connect(container, &Konsole::TabbedViewContainer::viewAdded, this, | 586 | connect(container, &Konsole::TabbedViewContainer::viewAdded, this, | ||
639 | [this, container]() { | 587 | [this, container]() { | ||
640 | containerViewsChanged(container); | 588 | containerViewsChanged(container); | ||
Show All 15 Lines | |||||
656 | connect(container, &Konsole::TabbedViewContainer::activeViewChanged, this, | 604 | connect(container, &Konsole::TabbedViewContainer::activeViewChanged, this, | ||
657 | &Konsole::ViewManager::viewActivated); | 605 | &Konsole::ViewManager::viewActivated); | ||
658 | 606 | | |||
659 | return container; | 607 | return container; | ||
660 | } | 608 | } | ||
661 | 609 | | |||
662 | void ViewManager::containerMoveViewRequest(int index, int id) | 610 | void ViewManager::containerMoveViewRequest(int index, int id) | ||
663 | { | 611 | { | ||
612 | Q_UNUSED(index); | ||||
613 | | ||||
664 | auto *container = qobject_cast<TabbedViewContainer *>(sender()); | 614 | auto *container = qobject_cast<TabbedViewContainer *>(sender()); | ||
665 | auto *controller = qobject_cast<SessionController *>(ViewProperties::propertiesById(id)); | 615 | auto *controller = qobject_cast<SessionController *>(ViewProperties::propertiesById(id)); | ||
666 | Q_ASSERT(container); | 616 | Q_ASSERT(container); | ||
667 | Q_ASSERT(controller); | 617 | Q_ASSERT(controller); | ||
668 | 618 | | |||
669 | createView(controller->session(), container, index); | 619 | createView(controller->session()); | ||
670 | controller->session()->refresh(); | 620 | controller->session()->refresh(); | ||
671 | container->currentWidget()->setFocus(); | 621 | container->currentWidget()->setFocus(); | ||
672 | } | 622 | } | ||
673 | 623 | | |||
674 | void ViewManager::setNavigationMethod(NavigationMethod method) | 624 | void ViewManager::setNavigationMethod(NavigationMethod method) | ||
675 | { | 625 | { | ||
676 | Q_ASSERT(_actionCollection); | 626 | Q_ASSERT(_actionCollection); | ||
677 | if (_actionCollection == nullptr) { | 627 | if (_actionCollection == nullptr) { | ||
Show All 34 Lines | |||||
712 | } | 662 | } | ||
713 | 663 | | |||
714 | ViewManager::NavigationMethod ViewManager::navigationMethod() const | 664 | ViewManager::NavigationMethod ViewManager::navigationMethod() const | ||
715 | { | 665 | { | ||
716 | return _navigationMethod; | 666 | return _navigationMethod; | ||
717 | } | 667 | } | ||
718 | 668 | | |||
719 | void ViewManager::containerViewsChanged(TabbedViewContainer *container) | 669 | void ViewManager::containerViewsChanged(TabbedViewContainer *container) | ||
720 | { | 670 | { | ||
721 | if ((!_viewSplitter.isNull()) && container == _viewSplitter->activeContainer()) { | 671 | // TODO: Verify that this is right. | ||
hindenburg: container not used | |||||
722 | emit viewPropertiesChanged(viewProperties()); | 672 | emit viewPropertiesChanged(viewProperties()); | ||
723 | } | 673 | } | ||
724 | } | | |||
725 | 674 | | |||
726 | void ViewManager::viewDestroyed(QWidget *view) | 675 | void ViewManager::viewDestroyed(QWidget *view) | ||
727 | { | 676 | { | ||
677 | qDebug() << "TerminalDisplay destroyed"; | ||||
728 | // Note: the received QWidget has already been destroyed, so | 678 | // Note: the received QWidget has already been destroyed, so | ||
729 | // using dynamic_cast<> or qobject_cast<> does not work here | 679 | // using dynamic_cast<> or qobject_cast<> does not work here | ||
730 | // We only need the pointer address to look it up below | 680 | // We only need the pointer address to look it up below | ||
731 | auto *display = reinterpret_cast<TerminalDisplay *>(view); | 681 | auto *display = reinterpret_cast<TerminalDisplay *>(view); | ||
732 | 682 | | |||
733 | // 1. detach view from session | 683 | // 1. detach view from session | ||
734 | // 2. if the session has no views left, close it | 684 | // 2. if the session has no views left, close it | ||
735 | Session *session = _sessionMap[ display ]; | 685 | Session *session = _sessionMap[ display ]; | ||
736 | _sessionMap.remove(display); | 686 | _sessionMap.remove(display); | ||
737 | if (session != nullptr) { | 687 | if (session != nullptr) { | ||
738 | if (session->views().count() == 0) { | 688 | if (session->views().count() == 0) { | ||
739 | session->close(); | 689 | session->close(); | ||
740 | } | 690 | } | ||
741 | } | 691 | } | ||
742 | //we only update the focus if the splitter is still alive | 692 | //we only update the focus if the splitter is still alive | ||
693 | // TODO: Verify. | ||||
694 | #if 0 | ||||
743 | if (!_viewSplitter.isNull()) { | 695 | if (!_viewSplitter.isNull()) { | ||
744 | updateDetachViewState(); | 696 | updateDetachViewState(); | ||
745 | } | 697 | } | ||
698 | #endif | ||||
746 | // The below causes the menus to be messed up | 699 | // The below causes the menus to be messed up | ||
747 | // Only happens when using the tab bar close button | 700 | // Only happens when using the tab bar close button | ||
748 | // if (_pluggedController) | 701 | // if (_pluggedController) | ||
749 | // emit unplugController(_pluggedController); | 702 | // emit unplugController(_pluggedController); | ||
703 | qDebug() << "End of view destroyed"; | ||||
750 | } | 704 | } | ||
751 | 705 | | |||
752 | TerminalDisplay *ViewManager::createTerminalDisplay(Session *session) | 706 | TerminalDisplay *ViewManager::createTerminalDisplay(Session *session) | ||
753 | { | 707 | { | ||
754 | auto display = new TerminalDisplay(nullptr); | 708 | auto display = new TerminalDisplay(nullptr); | ||
755 | display->setRandomSeed(session->sessionId() * 31); | 709 | display->setRandomSeed(session->sessionId() * 31); | ||
756 | 710 | | |||
757 | return display; | 711 | return display; | ||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | 815 | while (iter.hasNext()) { | |||
869 | } | 823 | } | ||
870 | } | 824 | } | ||
871 | } | 825 | } | ||
872 | 826 | | |||
873 | QList<ViewProperties *> ViewManager::viewProperties() const | 827 | QList<ViewProperties *> ViewManager::viewProperties() const | ||
874 | { | 828 | { | ||
875 | QList<ViewProperties *> list; | 829 | QList<ViewProperties *> list; | ||
876 | 830 | | |||
877 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 831 | TabbedViewContainer *container = _viewContainer; | ||
878 | if (container == nullptr) { | 832 | if (container == nullptr) { | ||
879 | return {}; | 833 | return {}; | ||
880 | } | 834 | } | ||
881 | 835 | | |||
882 | list.reserve(container->count()); | 836 | auto terminalContainers = _viewContainer->findChildren<TerminalDisplay*>(); | ||
837 | list.reserve(terminalContainers.size()); | ||||
883 | 838 | | |||
884 | for(int i = 0, end = container->count(); i < end; i++) { | 839 | for(auto terminalDisplay : _viewContainer->findChildren<TerminalDisplay*>()) { | ||
885 | auto view = container->terminalAt(i); | 840 | list.append(terminalDisplay->sessionController()); | ||
886 | ViewProperties *properties = view->sessionController(); | | |||
887 | Q_ASSERT(properties); | | |||
888 | list << properties; | | |||
889 | } | 841 | } | ||
890 | 842 | | |||
891 | return list; | 843 | return list; | ||
892 | } | 844 | } | ||
893 | 845 | | |||
894 | void ViewManager::saveSessions(KConfigGroup &group) | 846 | void ViewManager::saveSessions(KConfigGroup &group) | ||
895 | { | 847 | { | ||
896 | // find all unique session restore IDs | 848 | // find all unique session restore IDs | ||
897 | QList<int> ids; | 849 | QList<int> ids; | ||
898 | QSet<Session *> unique; | 850 | QSet<Session *> unique; | ||
899 | int tab = 1; | 851 | int tab = 1; | ||
900 | 852 | | |||
901 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 853 | TabbedViewContainer *container = _viewContainer; | ||
902 | 854 | | |||
903 | // first: sessions in the active container, preserving the order | 855 | // first: sessions in the active container, preserving the order | ||
904 | Q_ASSERT(container); | 856 | Q_ASSERT(container); | ||
905 | if (container == nullptr) { | 857 | if (container == nullptr) { | ||
906 | return; | 858 | return; | ||
907 | } | 859 | } | ||
908 | ids.reserve(container->count()); | 860 | ids.reserve(container->count()); | ||
909 | 861 | | |||
862 | //TODO: Handle sessions | ||||
863 | #if 0 | ||||
hindenburg: I need to test session restores w/ splits. | |||||
910 | auto *activeview = qobject_cast<TerminalDisplay *>(container->currentWidget()); | 864 | auto *activeview = qobject_cast<TerminalDisplay *>(container->currentWidget()); | ||
911 | for (int i = 0, end = container->count(); i < end; i++) { | 865 | for (int i = 0, end = container->count(); i < end; i++) { | ||
912 | auto *view = qobject_cast<TerminalDisplay *>(container->widget(i)); | 866 | auto *view = qobject_cast<TerminalDisplay *>(container->widget(i)); | ||
913 | Q_ASSERT(view); | 867 | Q_ASSERT(view); | ||
914 | 868 | | |||
915 | Session *session = _sessionMap[view]; | 869 | Session *session = _sessionMap[view]; | ||
916 | ids << SessionManager::instance()->getRestoreId(session); | 870 | ids << SessionManager::instance()->getRestoreId(session); | ||
917 | unique.insert(session); | 871 | unique.insert(session); | ||
918 | if (view == activeview) { | 872 | if (view == activeview) { | ||
919 | group.writeEntry("Active", tab); | 873 | group.writeEntry("Active", tab); | ||
920 | } | 874 | } | ||
921 | tab++; | 875 | tab++; | ||
922 | } | 876 | } | ||
877 | #endif | ||||
923 | 878 | | |||
924 | // second: all other sessions, in random order | 879 | // second: all other sessions, in random order | ||
925 | // we don't want to have sessions restored that are not connected | 880 | // we don't want to have sessions restored that are not connected | ||
926 | foreach (Session *session, _sessionMap) { | 881 | foreach (Session *session, _sessionMap) { | ||
927 | if (!unique.contains(session)) { | 882 | if (!unique.contains(session)) { | ||
928 | ids << SessionManager::instance()->getRestoreId(session); | 883 | ids << SessionManager::instance()->getRestoreId(session); | ||
929 | unique.insert(session); | 884 | unique.insert(session); | ||
930 | } | 885 | } | ||
931 | } | 886 | } | ||
932 | 887 | | |||
933 | group.writeEntry("Sessions", ids); | 888 | group.writeEntry("Sessions", ids); | ||
934 | } | 889 | } | ||
935 | 890 | | |||
936 | TabbedViewContainer *ViewManager::activeContainer() | 891 | TabbedViewContainer *ViewManager::activeContainer() | ||
937 | { | 892 | { | ||
938 | return _viewSplitter->activeContainer(); | 893 | return _viewContainer; | ||
939 | } | 894 | } | ||
940 | 895 | | |||
941 | void ViewManager::restoreSessions(const KConfigGroup &group) | 896 | void ViewManager::restoreSessions(const KConfigGroup &group) | ||
942 | { | 897 | { | ||
943 | QList<int> ids = group.readEntry("Sessions", QList<int>()); | 898 | QList<int> ids = group.readEntry("Sessions", QList<int>()); | ||
944 | int activeTab = group.readEntry("Active", 0); | 899 | int activeTab = group.readEntry("Active", 0); | ||
945 | TerminalDisplay *display = nullptr; | 900 | TerminalDisplay *display = nullptr; | ||
946 | 901 | | |||
947 | int tab = 1; | 902 | int tab = 1; | ||
948 | foreach (int id, ids) { | 903 | foreach (int id, ids) { | ||
949 | Session *session = SessionManager::instance()->idToSession(id); | 904 | Session *session = SessionManager::instance()->idToSession(id); | ||
950 | 905 | | |||
951 | if (session == nullptr) { | 906 | if (session == nullptr) { | ||
952 | qWarning() << "Unable to load session with id" << id; | 907 | qWarning() << "Unable to load session with id" << id; | ||
953 | // Force a creation of a default session below | 908 | // Force a creation of a default session below | ||
954 | ids.clear(); | 909 | ids.clear(); | ||
955 | break; | 910 | break; | ||
956 | } | 911 | } | ||
957 | 912 | | |||
958 | createView(activeContainer(), session); | 913 | createView(session); | ||
959 | if (!session->isRunning()) { | 914 | if (!session->isRunning()) { | ||
960 | session->run(); | 915 | session->run(); | ||
961 | } | 916 | } | ||
962 | if (tab++ == activeTab) { | 917 | if (tab++ == activeTab) { | ||
963 | display = qobject_cast<TerminalDisplay *>(activeView()); | 918 | display = qobject_cast<TerminalDisplay *>(activeView()); | ||
964 | } | 919 | } | ||
965 | } | 920 | } | ||
966 | 921 | | |||
967 | if (display != nullptr) { | 922 | if (display != nullptr) { | ||
968 | _viewSplitter->activeContainer()->setCurrentWidget(display); | 923 | activeContainer()->setCurrentWidget(display); | ||
969 | display->setFocus(Qt::OtherFocusReason); | 924 | display->setFocus(Qt::OtherFocusReason); | ||
970 | } | 925 | } | ||
971 | 926 | | |||
972 | if (ids.isEmpty()) { // Session file is unusable, start default Profile | 927 | if (ids.isEmpty()) { // Session file is unusable, start default Profile | ||
973 | Profile::Ptr profile = ProfileManager::instance()->defaultProfile(); | 928 | Profile::Ptr profile = ProfileManager::instance()->defaultProfile(); | ||
974 | Session *session = SessionManager::instance()->createSession(profile); | 929 | Session *session = SessionManager::instance()->createSession(profile); | ||
975 | createView(activeContainer(), session); | 930 | createView(session); | ||
976 | if (!session->isRunning()) { | 931 | if (!session->isRunning()) { | ||
977 | session->run(); | 932 | session->run(); | ||
978 | } | 933 | } | ||
979 | } | 934 | } | ||
980 | } | 935 | } | ||
981 | 936 | | |||
982 | int ViewManager::sessionCount() | 937 | int ViewManager::sessionCount() | ||
983 | { | 938 | { | ||
Show All 23 Lines | 955 | { | |||
1007 | return -1; | 962 | return -1; | ||
1008 | } | 963 | } | ||
1009 | 964 | | |||
1010 | void ViewManager::setCurrentSession(int sessionId) | 965 | void ViewManager::setCurrentSession(int sessionId) | ||
1011 | { | 966 | { | ||
1012 | QHash<TerminalDisplay *, Session *>::const_iterator i; | 967 | QHash<TerminalDisplay *, Session *>::const_iterator i; | ||
1013 | for (i = _sessionMap.constBegin(); i != _sessionMap.constEnd(); ++i) { | 968 | for (i = _sessionMap.constBegin(); i != _sessionMap.constEnd(); ++i) { | ||
1014 | if (i.value()->sessionId() == sessionId) { | 969 | if (i.value()->sessionId() == sessionId) { | ||
1015 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 970 | TabbedViewContainer *container = activeContainer(); | ||
1016 | if (container != nullptr) { | 971 | if (container != nullptr) { | ||
1017 | container->setCurrentWidget(i.key()); | 972 | container->setCurrentWidget(i.key()); | ||
1018 | } | 973 | } | ||
1019 | } | 974 | } | ||
1020 | } | 975 | } | ||
1021 | } | 976 | } | ||
1022 | 977 | | |||
1023 | int ViewManager::newSession() | 978 | int ViewManager::newSession() | ||
1024 | { | 979 | { | ||
1025 | Profile::Ptr profile = ProfileManager::instance()->defaultProfile(); | 980 | Profile::Ptr profile = ProfileManager::instance()->defaultProfile(); | ||
1026 | Session *session = SessionManager::instance()->createSession(profile); | 981 | Session *session = SessionManager::instance()->createSession(profile); | ||
1027 | 982 | | |||
1028 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | 983 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | ||
1029 | 984 | | |||
1030 | createView(activeContainer(), session); | 985 | createView(session); | ||
1031 | session->run(); | 986 | session->run(); | ||
1032 | 987 | | |||
1033 | return session->sessionId(); | 988 | return session->sessionId(); | ||
1034 | } | 989 | } | ||
1035 | 990 | | |||
1036 | int ViewManager::newSession(const QString &profile) | 991 | int ViewManager::newSession(const QString &profile) | ||
1037 | { | 992 | { | ||
1038 | const QList<Profile::Ptr> profilelist = ProfileManager::instance()->allProfiles(); | 993 | const QList<Profile::Ptr> profilelist = ProfileManager::instance()->allProfiles(); | ||
1039 | Profile::Ptr profileptr = ProfileManager::instance()->defaultProfile(); | 994 | Profile::Ptr profileptr = ProfileManager::instance()->defaultProfile(); | ||
1040 | 995 | | |||
1041 | for (const auto &i : profilelist) { | 996 | for (const auto &i : profilelist) { | ||
1042 | if (i->name() == profile) { | 997 | if (i->name() == profile) { | ||
1043 | profileptr = i; | 998 | profileptr = i; | ||
1044 | break; | 999 | break; | ||
1045 | } | 1000 | } | ||
1046 | } | 1001 | } | ||
1047 | 1002 | | |||
1048 | Session *session = SessionManager::instance()->createSession(profileptr); | 1003 | Session *session = SessionManager::instance()->createSession(profileptr); | ||
1049 | 1004 | | |||
1050 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | 1005 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | ||
1051 | 1006 | | |||
1052 | createView(activeContainer(), session); | 1007 | createView(session); | ||
1053 | session->run(); | 1008 | session->run(); | ||
1054 | 1009 | | |||
1055 | return session->sessionId(); | 1010 | return session->sessionId(); | ||
1056 | } | 1011 | } | ||
1057 | 1012 | | |||
1058 | int ViewManager::newSession(const QString &profile, const QString &directory) | 1013 | int ViewManager::newSession(const QString &profile, const QString &directory) | ||
1059 | { | 1014 | { | ||
1060 | const QList<Profile::Ptr> profilelist = ProfileManager::instance()->allProfiles(); | 1015 | const QList<Profile::Ptr> profilelist = ProfileManager::instance()->allProfiles(); | ||
1061 | Profile::Ptr profileptr = ProfileManager::instance()->defaultProfile(); | 1016 | Profile::Ptr profileptr = ProfileManager::instance()->defaultProfile(); | ||
1062 | 1017 | | |||
1063 | for (const auto &i : profilelist) { | 1018 | for (const auto &i : profilelist) { | ||
1064 | if (i->name() == profile) { | 1019 | if (i->name() == profile) { | ||
1065 | profileptr = i; | 1020 | profileptr = i; | ||
1066 | break; | 1021 | break; | ||
1067 | } | 1022 | } | ||
1068 | } | 1023 | } | ||
1069 | 1024 | | |||
1070 | Session *session = SessionManager::instance()->createSession(profileptr); | 1025 | Session *session = SessionManager::instance()->createSession(profileptr); | ||
1071 | session->setInitialWorkingDirectory(directory); | 1026 | session->setInitialWorkingDirectory(directory); | ||
1072 | 1027 | | |||
1073 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | 1028 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | ||
1074 | 1029 | | |||
1075 | createView(activeContainer(), session); | 1030 | createView(session); | ||
1076 | session->run(); | 1031 | session->run(); | ||
1077 | 1032 | | |||
1078 | return session->sessionId(); | 1033 | return session->sessionId(); | ||
1079 | } | 1034 | } | ||
1080 | 1035 | | |||
1081 | QString ViewManager::defaultProfile() | 1036 | QString ViewManager::defaultProfile() | ||
1082 | { | 1037 | { | ||
1083 | return ProfileManager::instance()->defaultProfile()->name(); | 1038 | return ProfileManager::instance()->defaultProfile()->name(); | ||
Show All 21 Lines | |||||
1105 | 1060 | | |||
1106 | void ViewManager::moveSessionRight() | 1061 | void ViewManager::moveSessionRight() | ||
1107 | { | 1062 | { | ||
1108 | moveActiveViewRight(); | 1063 | moveActiveViewRight(); | ||
1109 | } | 1064 | } | ||
1110 | 1065 | | |||
1111 | void ViewManager::setTabWidthToText(bool setTabWidthToText) | 1066 | void ViewManager::setTabWidthToText(bool setTabWidthToText) | ||
1112 | { | 1067 | { | ||
1113 | for(auto container : _viewSplitter->containers()) { | 1068 | _viewContainer->tabBar()->setExpanding(!setTabWidthToText); | ||
1114 | container->tabBar()->setExpanding(!setTabWidthToText); | 1069 | _viewContainer->tabBar()->update(); | ||
1115 | container->tabBar()->update(); | | |||
1116 | } | | |||
1117 | } | 1070 | } | ||
1118 | 1071 | | |||
1119 | void ViewManager::setNavigationVisibility(NavigationVisibility navigationVisibility) { | 1072 | void ViewManager::setNavigationVisibility(NavigationVisibility navigationVisibility) { | ||
1120 | if (_navigationVisibility != navigationVisibility) { | 1073 | if (_navigationVisibility != navigationVisibility) { | ||
1121 | _navigationVisibility = navigationVisibility; | 1074 | _navigationVisibility = navigationVisibility; | ||
1122 | for(auto *container : _viewSplitter->containers()) { | 1075 | _viewContainer->setNavigationVisibility(navigationVisibility); | ||
1123 | container->setNavigationVisibility(navigationVisibility); | | |||
1124 | } | | |||
1125 | } | 1076 | } | ||
1126 | } | 1077 | } | ||
1127 | 1078 | | |||
1128 | void ViewManager::setNavigationBehavior(int behavior) | 1079 | void ViewManager::setNavigationBehavior(int behavior) | ||
1129 | { | 1080 | { | ||
1130 | _newTabBehavior = static_cast<NewTabBehavior>(behavior); | 1081 | _newTabBehavior = static_cast<NewTabBehavior>(behavior); | ||
1131 | } | 1082 | } |
There is a method ViewSplitter::getTerminalDisplays() which is a lot more complicated than this. It should probably be simplified to this and used here or removed entirely.