Changeset View
Changeset View
Standalone View
Standalone View
src/ViewManager.cpp
Show First 20 Lines • Show All 380 Lines • ▼ Show 20 Line(s) | 380 | if (_terminalDisplayHistory.count() <= 1) { | |||
---|---|---|---|---|---|
381 | return; | 381 | return; | ||
382 | } | 382 | } | ||
383 | 383 | | |||
384 | switchToTerminalDisplay(_terminalDisplayHistory.at(1)); | 384 | switchToTerminalDisplay(_terminalDisplayHistory.at(1)); | ||
385 | } | 385 | } | ||
386 | 386 | | |||
387 | void ViewManager::detachActiveView() | 387 | void ViewManager::detachActiveView() | ||
388 | { | 388 | { | ||
389 | //TODO: Disable Detach temporarely. | | |||
390 | #if 0 | | |||
391 | // find the currently active view and remove it from its container | 389 | // find the currently active view and remove it from its container | ||
392 | TabbedViewContainer *container = _viewSplitter->activeContainer(); | 390 | TabbedViewContainer *container = _viewContainer; | ||
393 | detachView(container, container->currentWidget()); | 391 | detachView(container, container->activeViewSplitter()->activeTerminalDisplay()); | ||
392 | } | ||||
393 | | ||||
394 | void ViewManager::detachTab(TabbedViewContainer *container) | ||||
395 | { | ||||
396 | #if !defined(ENABLE_DETACHING) | ||||
397 | return; | ||||
394 | #endif | 398 | #endif | ||
399 | auto splitter = container->activeViewSplitter()->getToplevelSplitter(); | ||||
400 | emit tabDetached(splitter); | ||||
401 | auto terminals = splitter->getTerminalDisplays(); | ||||
402 | foreach(TerminalDisplay* terminal, terminals) { | ||||
403 | auto session = _sessionMap[terminal]; | ||||
404 | if (session != nullptr) { | ||||
405 | disconnect(session, &Konsole::Session::finished, this, &Konsole::ViewManager::sessionFinished); | ||||
406 | container->disconnectTerminalDisplay(terminal); | ||||
407 | } | ||||
408 | _sessionMap.remove(terminal); | ||||
409 | } | ||||
410 | removeContainer(container); | ||||
395 | } | 411 | } | ||
396 | 412 | | |||
397 | void ViewManager::detachView(TabbedViewContainer *container, QWidget *view) | 413 | void ViewManager::detachView(TabbedViewContainer *container, QWidget *view) | ||
398 | { | 414 | { | ||
399 | #if !defined(ENABLE_DETACHING) | 415 | #if !defined(ENABLE_DETACHING) | ||
400 | return; | 416 | return; | ||
401 | #endif | 417 | #endif | ||
402 | 418 | | |||
403 | auto *viewToDetach = qobject_cast<TerminalDisplay *>(view); | 419 | auto *viewToDetach = qobject_cast<TerminalDisplay *>(view); | ||
404 | 420 | | |||
405 | if (viewToDetach == nullptr) { | 421 | if (viewToDetach == nullptr) { | ||
406 | return; | 422 | return; | ||
407 | } | 423 | } | ||
408 | 424 | | |||
409 | // BR390736 - some instances are sending invalid session to viewDetached() | 425 | // BR390736 - some instances are sending invalid session to viewDetached() | ||
410 | Session *sessionToDetach = _sessionMap[viewToDetach]; | 426 | Session *sessionToDetach = _sessionMap[viewToDetach]; | ||
411 | if (sessionToDetach == nullptr) { | 427 | if (sessionToDetach == nullptr) { | ||
412 | return; | 428 | return; | ||
413 | } | 429 | } | ||
430 | | ||||
431 | disconnect(sessionToDetach, &Konsole::Session::finished, this, &Konsole::ViewManager::sessionFinished); | ||||
432 | | ||||
414 | emit viewDetached(sessionToDetach); | 433 | emit viewDetached(sessionToDetach); | ||
415 | 434 | | |||
416 | _sessionMap.remove(viewToDetach); | 435 | _sessionMap.remove(viewToDetach); | ||
417 | 436 | | |||
418 | // remove the view from this window | 437 | // remove the view from this window | ||
419 | container->removeView(viewToDetach); | 438 | container->removeView(viewToDetach); | ||
420 | viewToDetach->deleteLater(); | 439 | viewToDetach->deleteLater(); | ||
421 | 440 | | |||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Line(s) | 601 | { | |||
593 | emit activeViewChanged(controller); | 612 | emit activeViewChanged(controller); | ||
594 | } | 613 | } | ||
595 | 614 | | |||
596 | SessionController *ViewManager::activeViewController() const | 615 | SessionController *ViewManager::activeViewController() const | ||
597 | { | 616 | { | ||
598 | return _pluggedController; | 617 | return _pluggedController; | ||
599 | } | 618 | } | ||
600 | 619 | | |||
620 | void ViewManager::attachView(TerminalDisplay *terminal) | ||||
621 | { | ||||
622 | auto session = terminal->sessionController()->session().data(); | ||||
623 | connect(session, &Konsole::Session::finished, this, &Konsole::ViewManager::sessionFinished, | ||||
624 | Qt::UniqueConnection); | ||||
625 | _sessionMap[terminal] = session; | ||||
626 | updateDetachViewState(); | ||||
627 | if (_terminalDisplayHistory.isEmpty()) { | ||||
628 | _terminalDisplayHistory.append(terminal); | ||||
629 | } | ||||
630 | } | ||||
631 | | ||||
601 | TerminalDisplay *ViewManager::createView(Session *session) | 632 | TerminalDisplay *ViewManager::createView(Session *session) | ||
602 | { | 633 | { | ||
603 | // notify this view manager when the session finishes so that its view | 634 | // notify this view manager when the session finishes so that its view | ||
604 | // can be deleted | 635 | // can be deleted | ||
605 | // | 636 | // | ||
606 | // Use Qt::UniqueConnection to avoid duplicate connection | 637 | // Use Qt::UniqueConnection to avoid duplicate connection | ||
607 | connect(session, &Konsole::Session::finished, this, &Konsole::ViewManager::sessionFinished, | 638 | connect(session, &Konsole::Session::finished, this, &Konsole::ViewManager::sessionFinished, | ||
608 | Qt::UniqueConnection); | 639 | Qt::UniqueConnection); | ||
609 | | ||||
610 | TerminalDisplay *display = createTerminalDisplay(session); | 640 | TerminalDisplay *display = createTerminalDisplay(session); | ||
641 | | ||||
611 | const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); | 642 | const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); | ||
612 | applyProfileToView(display, profile); | 643 | applyProfileToView(display, profile); | ||
613 | 644 | | |||
614 | // set initial size | 645 | // set initial size | ||
615 | const QSize &preferredSize = session->preferredSize(); | 646 | const QSize &preferredSize = session->preferredSize(); | ||
616 | 647 | | |||
617 | display->setSize(preferredSize.width(), preferredSize.height()); | 648 | display->setSize(preferredSize.width(), preferredSize.height()); | ||
618 | createController(session, display); | 649 | createController(session, display); | ||
619 | 650 | | |||
620 | _sessionMap[display] = session; | 651 | _sessionMap[display] = session; | ||
621 | session->addView(display); | 652 | session->addView(display); | ||
622 | 653 | | |||
623 | // tell the session whether it has a light or dark background | 654 | // tell the session whether it has a light or dark background | ||
624 | session->setDarkBackground(colorSchemeForProfile(profile)->hasDarkBackground()); | 655 | session->setDarkBackground(colorSchemeForProfile(profile)->hasDarkBackground()); | ||
625 | display->setFocus(Qt::OtherFocusReason); | 656 | display->setFocus(Qt::OtherFocusReason); | ||
626 | updateDetachViewState(); | 657 | updateDetachViewState(); | ||
627 | 658 | | |||
628 | _terminalDisplayHistory.append(display); | 659 | _terminalDisplayHistory.append(display); | ||
629 | | ||||
630 | return display; | 660 | return display; | ||
631 | } | 661 | } | ||
632 | 662 | | |||
633 | TabbedViewContainer *ViewManager::createContainer() | 663 | TabbedViewContainer *ViewManager::createContainer() | ||
634 | { | 664 | { | ||
635 | auto *container = new TabbedViewContainer(this, nullptr); | 665 | auto *container = new TabbedViewContainer(this, nullptr); | ||
636 | container->setNavigationVisibility(_navigationVisibility); | 666 | container->setNavigationVisibility(_navigationVisibility); | ||
637 | //TODO: Fix Detaching. | 667 | //TODO: Fix Detaching. | ||
638 | connect(container, &TabbedViewContainer::detachTab, this, &ViewManager::detachView); | 668 | connect(container, &TabbedViewContainer::detachTab, this, &ViewManager::detachTab); | ||
639 | 669 | | |||
640 | // connect signals and slots | 670 | // connect signals and slots | ||
641 | connect(container, &Konsole::TabbedViewContainer::viewAdded, this, | 671 | connect(container, &Konsole::TabbedViewContainer::viewAdded, this, | ||
642 | [this, container]() { | 672 | [this, container]() { | ||
643 | containerViewsChanged(container); | 673 | containerViewsChanged(container); | ||
644 | }); | 674 | }); | ||
645 | 675 | | |||
646 | connect(container, &Konsole::TabbedViewContainer::viewRemoved, this, | 676 | connect(container, &Konsole::TabbedViewContainer::viewRemoved, this, | ||
▲ Show 20 Lines • Show All 520 Lines • Show Last 20 Lines |