Changeset View
Changeset View
Standalone View
Standalone View
src/ViewManager.cpp
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 89 | connect(SessionManager::instance(), &Konsole::SessionManager::sessionUpdated, | |||
---|---|---|---|---|---|
90 | this, &Konsole::ViewManager::updateViewsForSession); | 90 | this, &Konsole::ViewManager::updateViewsForSession); | ||
91 | 91 | | |||
92 | //prepare DBus communication | 92 | //prepare DBus communication | ||
93 | new WindowAdaptor(this); | 93 | new WindowAdaptor(this); | ||
94 | 94 | | |||
95 | _managerId = ++lastManagerId; | 95 | _managerId = ++lastManagerId; | ||
96 | QDBusConnection::sessionBus().registerObject(QLatin1String("/Windows/") | 96 | QDBusConnection::sessionBus().registerObject(QLatin1String("/Windows/") | ||
97 | + QString::number(_managerId), this); | 97 | + QString::number(_managerId), this); | ||
98 | | ||||
99 | _viewSplitter->addContainer(createContainer(), Qt::Vertical); | ||||
98 | } | 100 | } | ||
99 | 101 | | |||
100 | ViewManager::~ViewManager() = default; | 102 | ViewManager::~ViewManager() = default; | ||
101 | 103 | | |||
102 | int ViewManager::managerId() const | 104 | int ViewManager::managerId() const | ||
103 | { | 105 | { | ||
104 | return _managerId; | 106 | return _managerId; | ||
105 | } | 107 | } | ||
▲ Show 20 Lines • Show All 354 Lines • ▼ Show 20 Line(s) | |||||
460 | { | 462 | { | ||
461 | splitView(Qt::Vertical); | 463 | splitView(Qt::Vertical); | ||
462 | } | 464 | } | ||
463 | 465 | | |||
464 | void ViewManager::splitView(Qt::Orientation orientation) | 466 | void ViewManager::splitView(Qt::Orientation orientation) | ||
465 | { | 467 | { | ||
466 | TabbedViewContainer *container = createContainer(); | 468 | TabbedViewContainer *container = createContainer(); | ||
467 | 469 | | |||
468 | // iterate over each session which has a view in the current active | 470 | if (_viewSplitter->activeContainer()->count()) { | ||
469 | // container and create a new view for that session in a new container | 471 | // get the currently applied profile and use it to create the new tab. | ||
470 | for(int i = 0, end = _viewSplitter->activeContainer()->count(); i < end; i++) { | 472 | auto *activeContainer= _viewSplitter->activeContainer(); | ||
471 | auto view = _viewSplitter->activeContainer()->widget(i); | 473 | auto *currentDisplay = qobject_cast<TerminalDisplay*>(activeContainer->currentWidget()); | ||
472 | Session *session = _sessionMap[qobject_cast<TerminalDisplay *>(view)]; | 474 | auto profile = SessionManager::instance()->sessionProfile(_sessionMap[currentDisplay]); | ||
473 | TerminalDisplay *display = createTerminalDisplay(session); | | |||
474 | const Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); | | |||
475 | applyProfileToView(display, profile); | | |||
476 | ViewProperties *properties = createController(session, display); | | |||
477 | 475 | | |||
478 | _sessionMap[display] = session; | 476 | // Create a new session with the selected profile. | ||
477 | auto *session = SessionManager::instance()->createSession(profile); | ||||
478 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | ||||
479 | 479 | | |||
480 | container->addView(display, properties); | 480 | createView(session, container, 0); | ||
481 | session->addView(display); | | |||
482 | } | 481 | } | ||
483 | 482 | | |||
484 | _viewSplitter->addContainer(container, orientation); | 483 | _viewSplitter->addContainer(container, orientation); | ||
485 | emit splitViewToggle(_viewSplitter->containers().count() > 0); | 484 | emit splitViewToggle(_viewSplitter->containers().count() > 0); | ||
486 | 485 | | |||
487 | // focus the new container | 486 | // focus the new container | ||
488 | container->currentWidget()->setFocus(); | 487 | container->currentWidget()->setFocus(); | ||
489 | 488 | | |||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Line(s) | 591 | { | |||
617 | if (container == _viewSplitter->activeContainer()) { | 616 | if (container == _viewSplitter->activeContainer()) { | ||
618 | container->setCurrentWidget(display); | 617 | container->setCurrentWidget(display); | ||
619 | display->setFocus(Qt::OtherFocusReason); | 618 | display->setFocus(Qt::OtherFocusReason); | ||
620 | } | 619 | } | ||
621 | 620 | | |||
622 | updateDetachViewState(); | 621 | updateDetachViewState(); | ||
623 | } | 622 | } | ||
624 | 623 | | |||
625 | void ViewManager::createView(Session *session) | 624 | void ViewManager::createView(TabbedViewContainer *tabWidget, Session *session) | ||
626 | { | 625 | { | ||
627 | // create the default container | 626 | const int index = _newTabBehavior == PutNewTabAfterCurrentTab ? | ||
628 | if (_viewSplitter->containers().count() == 0) { | 627 | _viewSplitter->activeContainer()->currentIndex() + 1 : -1; | ||
629 | TabbedViewContainer *container = createContainer(); | | |||
630 | _viewSplitter->addContainer(container, Qt::Vertical); | | |||
631 | emit splitViewToggle(false); | | |||
632 | } | | |||
633 | | ||||
634 | // new tab will be put at the end by default. | | |||
635 | int index = -1; | | |||
636 | | ||||
637 | if (_newTabBehavior == PutNewTabAfterCurrentTab) { | | |||
638 | index = _viewSplitter->activeContainer()->currentIndex() + 1; | | |||
639 | } | | |||
640 | 628 | | |||
641 | // iterate over the view containers owned by this view manager | 629 | createView(session, tabWidget, index); | ||
642 | // and create a new terminal display for the session in each of them, along with | | |||
643 | // a controller for the session/display pair | | |||
644 | foreach (TabbedViewContainer *container, _viewSplitter->containers()) { | | |||
645 | createView(session, container, index); | | |||
646 | } | | |||
647 | } | 630 | } | ||
648 | 631 | | |||
649 | TabbedViewContainer *ViewManager::createContainer() | 632 | TabbedViewContainer *ViewManager::createContainer() | ||
650 | { | 633 | { | ||
651 | 634 | | |||
652 | auto *container = new TabbedViewContainer(this, _viewSplitter); | 635 | auto *container = new TabbedViewContainer(this, _viewSplitter); | ||
653 | container->setNavigationVisibility(_navigationVisibility); | 636 | container->setNavigationVisibility(_navigationVisibility); | ||
654 | //TODO: Fix Detaching. | 637 | //TODO: Fix Detaching. | ||
655 | connect(container, &TabbedViewContainer::detachTab, this, &ViewManager::detachView); | 638 | connect(container, &TabbedViewContainer::detachTab, this, &ViewManager::detachView); | ||
656 | 639 | | |||
657 | // connect signals and slots | 640 | // connect signals and slots | ||
658 | connect(container, &Konsole::TabbedViewContainer::viewAdded, this, | 641 | connect(container, &Konsole::TabbedViewContainer::viewAdded, this, | ||
659 | [this, container]() { | 642 | [this, container]() { | ||
660 | containerViewsChanged(container); | 643 | containerViewsChanged(container); | ||
661 | }); | 644 | }); | ||
662 | 645 | | |||
663 | connect(container, &Konsole::TabbedViewContainer::viewRemoved, this, | 646 | connect(container, &Konsole::TabbedViewContainer::viewRemoved, this, | ||
664 | [this, container]() { | 647 | [this, container]() { | ||
665 | containerViewsChanged(container); | 648 | containerViewsChanged(container); | ||
666 | }); | 649 | }); | ||
667 | 650 | | |||
668 | connect(container, | 651 | connect(container, &TabbedViewContainer::newViewRequest, | ||
669 | static_cast<void (TabbedViewContainer::*)()>(&Konsole::TabbedViewContainer::newViewRequest), this, | 652 | this, &ViewManager::newViewRequest); | ||
670 | static_cast<void (ViewManager::*)()>(&Konsole::ViewManager::newViewRequest)); | 653 | connect(container, &Konsole::TabbedViewContainer::newViewWithProfileRequest, | ||
671 | connect(container, | 654 | this, &Konsole::ViewManager::newViewWithProfileRequest); | ||
672 | static_cast<void (TabbedViewContainer::*)(Profile::Ptr)>(&Konsole::TabbedViewContainer::newViewRequest), | | |||
673 | this, | | |||
674 | static_cast<void (ViewManager::*)(Profile::Ptr)>(&Konsole::ViewManager::newViewRequest)); | | |||
675 | connect(container, &Konsole::TabbedViewContainer::moveViewRequest, this, | 655 | connect(container, &Konsole::TabbedViewContainer::moveViewRequest, this, | ||
676 | &Konsole::ViewManager::containerMoveViewRequest); | 656 | &Konsole::ViewManager::containerMoveViewRequest); | ||
677 | connect(container, &Konsole::TabbedViewContainer::viewRemoved, this, | 657 | connect(container, &Konsole::TabbedViewContainer::viewRemoved, this, | ||
678 | &Konsole::ViewManager::viewDestroyed); | 658 | &Konsole::ViewManager::viewDestroyed); | ||
679 | connect(container, &Konsole::TabbedViewContainer::activeViewChanged, this, | 659 | connect(container, &Konsole::TabbedViewContainer::activeViewChanged, this, | ||
680 | &Konsole::ViewManager::viewActivated); | 660 | &Konsole::ViewManager::viewActivated); | ||
681 | 661 | | |||
682 | return container; | 662 | return container; | ||
683 | } | 663 | } | ||
684 | 664 | | |||
685 | void ViewManager::containerMoveViewRequest(int index, int id, | 665 | void ViewManager::containerMoveViewRequest(int index, int id) | ||
686 | TabbedViewContainer *sourceTabbedContainer) | | |||
687 | { | 666 | { | ||
688 | auto *container = qobject_cast<TabbedViewContainer *>(sender()); | 667 | auto *container = qobject_cast<TabbedViewContainer *>(sender()); | ||
689 | auto *controller = qobject_cast<SessionController *>(ViewProperties::propertiesById(id)); | 668 | auto *controller = qobject_cast<SessionController *>(ViewProperties::propertiesById(id)); | ||
690 | 669 | Q_ASSERT(container); | |||
thsurrel: sourceViewManager is unused now. | |||||
691 | if (controller == nullptr) { | 670 | Q_ASSERT(controller); | ||
692 | return; | | |||
693 | } | | |||
694 | | ||||
695 | // do not move the last tab in a split view. | | |||
696 | if (sourceTabbedContainer != nullptr) { | | |||
697 | QPointer<TabbedViewContainer> sourceContainer = qobject_cast<TabbedViewContainer *>(sourceTabbedContainer); | | |||
698 | | ||||
699 | if (_viewSplitter->containers().contains(sourceContainer)) { | | |||
700 | return; | | |||
701 | } else { | | |||
702 | ViewManager *sourceViewManager = sourceTabbedContainer->connectedViewManager(); | | |||
703 | | ||||
704 | // do not remove the last tab on the window | | |||
705 | if (qobject_cast<ViewSplitter *>(sourceViewManager->widget())->containers().size() > 1) { | | |||
706 | return; | | |||
707 | } | | |||
708 | } | | |||
709 | } | | |||
710 | 671 | | |||
711 | createView(controller->session(), container, index); | 672 | createView(controller->session(), container, index); | ||
712 | controller->session()->refresh(); | 673 | controller->session()->refresh(); | ||
674 | container->currentWidget()->setFocus(); | ||||
713 | } | 675 | } | ||
714 | 676 | | |||
715 | void ViewManager::setNavigationMethod(NavigationMethod method) | 677 | void ViewManager::setNavigationMethod(NavigationMethod method) | ||
716 | { | 678 | { | ||
717 | Q_ASSERT(_actionCollection); | 679 | Q_ASSERT(_actionCollection); | ||
718 | if (_actionCollection == nullptr) { | 680 | if (_actionCollection == nullptr) { | ||
719 | return; | 681 | return; | ||
720 | } | 682 | } | ||
▲ Show 20 Lines • Show All 248 Lines • ▼ Show 20 Line(s) | 930 | if (!unique.contains(session)) { | |||
969 | ids << SessionManager::instance()->getRestoreId(session); | 931 | ids << SessionManager::instance()->getRestoreId(session); | ||
970 | unique.insert(session); | 932 | unique.insert(session); | ||
971 | } | 933 | } | ||
972 | } | 934 | } | ||
973 | 935 | | |||
974 | group.writeEntry("Sessions", ids); | 936 | group.writeEntry("Sessions", ids); | ||
975 | } | 937 | } | ||
976 | 938 | | |||
939 | TabbedViewContainer *ViewManager::activeContainer() | ||||
940 | { | ||||
941 | return _viewSplitter->activeContainer(); | ||||
942 | } | ||||
943 | | ||||
977 | void ViewManager::restoreSessions(const KConfigGroup &group) | 944 | void ViewManager::restoreSessions(const KConfigGroup &group) | ||
978 | { | 945 | { | ||
979 | QList<int> ids = group.readEntry("Sessions", QList<int>()); | 946 | QList<int> ids = group.readEntry("Sessions", QList<int>()); | ||
980 | int activeTab = group.readEntry("Active", 0); | 947 | int activeTab = group.readEntry("Active", 0); | ||
981 | TerminalDisplay *display = nullptr; | 948 | TerminalDisplay *display = nullptr; | ||
982 | 949 | | |||
983 | int tab = 1; | 950 | int tab = 1; | ||
984 | foreach (int id, ids) { | 951 | foreach (int id, ids) { | ||
985 | Session *session = SessionManager::instance()->idToSession(id); | 952 | Session *session = SessionManager::instance()->idToSession(id); | ||
986 | 953 | | |||
987 | if (session == nullptr) { | 954 | if (session == nullptr) { | ||
988 | qWarning() << "Unable to load session with id" << id; | 955 | qWarning() << "Unable to load session with id" << id; | ||
989 | // Force a creation of a default session below | 956 | // Force a creation of a default session below | ||
990 | ids.clear(); | 957 | ids.clear(); | ||
991 | break; | 958 | break; | ||
992 | } | 959 | } | ||
993 | 960 | | |||
994 | createView(session); | 961 | createView(activeContainer(), session); | ||
995 | if (!session->isRunning()) { | 962 | if (!session->isRunning()) { | ||
996 | session->run(); | 963 | session->run(); | ||
997 | } | 964 | } | ||
998 | if (tab++ == activeTab) { | 965 | if (tab++ == activeTab) { | ||
999 | display = qobject_cast<TerminalDisplay *>(activeView()); | 966 | display = qobject_cast<TerminalDisplay *>(activeView()); | ||
1000 | } | 967 | } | ||
1001 | } | 968 | } | ||
1002 | 969 | | |||
1003 | if (display != nullptr) { | 970 | if (display != nullptr) { | ||
1004 | _viewSplitter->activeContainer()->setCurrentWidget(display); | 971 | _viewSplitter->activeContainer()->setCurrentWidget(display); | ||
1005 | display->setFocus(Qt::OtherFocusReason); | 972 | display->setFocus(Qt::OtherFocusReason); | ||
1006 | } | 973 | } | ||
1007 | 974 | | |||
1008 | if (ids.isEmpty()) { // Session file is unusable, start default Profile | 975 | if (ids.isEmpty()) { // Session file is unusable, start default Profile | ||
1009 | Profile::Ptr profile = ProfileManager::instance()->defaultProfile(); | 976 | Profile::Ptr profile = ProfileManager::instance()->defaultProfile(); | ||
1010 | Session *session = SessionManager::instance()->createSession(profile); | 977 | Session *session = SessionManager::instance()->createSession(profile); | ||
1011 | createView(session); | 978 | createView(activeContainer(), session); | ||
1012 | if (!session->isRunning()) { | 979 | if (!session->isRunning()) { | ||
1013 | session->run(); | 980 | session->run(); | ||
1014 | } | 981 | } | ||
1015 | } | 982 | } | ||
1016 | } | 983 | } | ||
1017 | 984 | | |||
1018 | int ViewManager::sessionCount() | 985 | int ViewManager::sessionCount() | ||
1019 | { | 986 | { | ||
Show All 38 Lines | |||||
1058 | 1025 | | |||
1059 | int ViewManager::newSession() | 1026 | int ViewManager::newSession() | ||
1060 | { | 1027 | { | ||
1061 | Profile::Ptr profile = ProfileManager::instance()->defaultProfile(); | 1028 | Profile::Ptr profile = ProfileManager::instance()->defaultProfile(); | ||
1062 | Session *session = SessionManager::instance()->createSession(profile); | 1029 | Session *session = SessionManager::instance()->createSession(profile); | ||
1063 | 1030 | | |||
1064 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | 1031 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | ||
1065 | 1032 | | |||
1066 | createView(session); | 1033 | createView(activeContainer(), session); | ||
1067 | session->run(); | 1034 | session->run(); | ||
1068 | 1035 | | |||
1069 | return session->sessionId(); | 1036 | return session->sessionId(); | ||
1070 | } | 1037 | } | ||
1071 | 1038 | | |||
1072 | int ViewManager::newSession(const QString &profile) | 1039 | int ViewManager::newSession(const QString &profile) | ||
1073 | { | 1040 | { | ||
1074 | const QList<Profile::Ptr> profilelist = ProfileManager::instance()->allProfiles(); | 1041 | const QList<Profile::Ptr> profilelist = ProfileManager::instance()->allProfiles(); | ||
1075 | Profile::Ptr profileptr = ProfileManager::instance()->defaultProfile(); | 1042 | Profile::Ptr profileptr = ProfileManager::instance()->defaultProfile(); | ||
1076 | 1043 | | |||
1077 | for (const auto &i : profilelist) { | 1044 | for (const auto &i : profilelist) { | ||
1078 | if (i->name() == profile) { | 1045 | if (i->name() == profile) { | ||
1079 | profileptr = i; | 1046 | profileptr = i; | ||
1080 | break; | 1047 | break; | ||
1081 | } | 1048 | } | ||
1082 | } | 1049 | } | ||
1083 | 1050 | | |||
1084 | Session *session = SessionManager::instance()->createSession(profileptr); | 1051 | Session *session = SessionManager::instance()->createSession(profileptr); | ||
1085 | 1052 | | |||
1086 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | 1053 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | ||
1087 | 1054 | | |||
1088 | createView(session); | 1055 | createView(activeContainer(), session); | ||
1089 | session->run(); | 1056 | session->run(); | ||
1090 | 1057 | | |||
1091 | return session->sessionId(); | 1058 | return session->sessionId(); | ||
1092 | } | 1059 | } | ||
1093 | 1060 | | |||
1094 | int ViewManager::newSession(const QString &profile, const QString &directory) | 1061 | int ViewManager::newSession(const QString &profile, const QString &directory) | ||
1095 | { | 1062 | { | ||
1096 | const QList<Profile::Ptr> profilelist = ProfileManager::instance()->allProfiles(); | 1063 | const QList<Profile::Ptr> profilelist = ProfileManager::instance()->allProfiles(); | ||
1097 | Profile::Ptr profileptr = ProfileManager::instance()->defaultProfile(); | 1064 | Profile::Ptr profileptr = ProfileManager::instance()->defaultProfile(); | ||
1098 | 1065 | | |||
1099 | for (const auto &i : profilelist) { | 1066 | for (const auto &i : profilelist) { | ||
1100 | if (i->name() == profile) { | 1067 | if (i->name() == profile) { | ||
1101 | profileptr = i; | 1068 | profileptr = i; | ||
1102 | break; | 1069 | break; | ||
1103 | } | 1070 | } | ||
1104 | } | 1071 | } | ||
1105 | 1072 | | |||
1106 | Session *session = SessionManager::instance()->createSession(profileptr); | 1073 | Session *session = SessionManager::instance()->createSession(profileptr); | ||
1107 | session->setInitialWorkingDirectory(directory); | 1074 | session->setInitialWorkingDirectory(directory); | ||
1108 | 1075 | | |||
1109 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | 1076 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(managerId())); | ||
1110 | 1077 | | |||
1111 | createView(session); | 1078 | createView(activeContainer(), session); | ||
1112 | session->run(); | 1079 | session->run(); | ||
1113 | 1080 | | |||
1114 | return session->sessionId(); | 1081 | return session->sessionId(); | ||
1115 | } | 1082 | } | ||
1116 | 1083 | | |||
1117 | QString ViewManager::defaultProfile() | 1084 | QString ViewManager::defaultProfile() | ||
1118 | { | 1085 | { | ||
1119 | return ProfileManager::instance()->defaultProfile()->name(); | 1086 | return ProfileManager::instance()->defaultProfile()->name(); | ||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |
sourceViewManager is unused now.