Changeset View
Changeset View
Standalone View
Standalone View
src/SessionController.cpp
Show First 20 Lines • Show All 157 Lines • ▼ Show 20 Line(s) | 121 | { | |||
---|---|---|---|---|---|
158 | 158 | | |||
159 | // move view to newest output when keystrokes occur | 159 | // move view to newest output when keystrokes occur | ||
160 | connect(_view.data(), &Konsole::TerminalDisplay::keyPressedSignal, this, &Konsole::SessionController::trackOutput); | 160 | connect(_view.data(), &Konsole::TerminalDisplay::keyPressedSignal, this, &Konsole::SessionController::trackOutput); | ||
161 | 161 | | |||
162 | // listen to activity / silence notifications from session | 162 | // listen to activity / silence notifications from session | ||
163 | connect(_session.data(), &Konsole::Session::stateChanged, this, &Konsole::SessionController::sessionStateChanged); | 163 | connect(_session.data(), &Konsole::Session::stateChanged, this, &Konsole::SessionController::sessionStateChanged); | ||
164 | // listen to title and icon changes | 164 | // listen to title and icon changes | ||
165 | connect(_session.data(), &Konsole::Session::titleChanged, this, &Konsole::SessionController::sessionTitleChanged); | 165 | connect(_session.data(), &Konsole::Session::titleChanged, this, &Konsole::SessionController::sessionTitleChanged); | ||
166 | connect(_session.data(), &Konsole::Session::readOnlyChanged, this, &Konsole::SessionController::sessionReadOnlyChanged); | ||||
166 | 167 | | |||
167 | connect(this, &Konsole::SessionController::tabRenamedByUser, _session, &Konsole::Session::tabRenamedByUser); | 168 | connect(this, &Konsole::SessionController::tabRenamedByUser, _session, &Konsole::Session::tabRenamedByUser); | ||
168 | 169 | | |||
169 | connect(_session.data() , &Konsole::Session::currentDirectoryChanged , this , &Konsole::SessionController::currentDirectoryChanged); | 170 | connect(_session.data() , &Konsole::Session::currentDirectoryChanged , this , &Konsole::SessionController::currentDirectoryChanged); | ||
170 | 171 | | |||
171 | // listen for color changes | 172 | // listen for color changes | ||
172 | connect(_session.data(), &Konsole::Session::changeBackgroundColorRequest, _view.data(), &Konsole::TerminalDisplay::setBackgroundColor); | 173 | connect(_session.data(), &Konsole::Session::changeBackgroundColorRequest, _view.data(), &Konsole::TerminalDisplay::setBackgroundColor); | ||
173 | connect(_session.data(), &Konsole::Session::changeForegroundColorRequest, _view.data(), &Konsole::TerminalDisplay::setForegroundColor); | 174 | connect(_session.data(), &Konsole::Session::changeForegroundColorRequest, _view.data(), &Konsole::TerminalDisplay::setForegroundColor); | ||
▲ Show 20 Lines • Show All 285 Lines • ▼ Show 20 Line(s) | 458 | { | |||
459 | _session->reportBackgroundColor(c); | 460 | _session->reportBackgroundColor(c); | ||
460 | } | 461 | } | ||
461 | 462 | | |||
462 | void SessionController::toggleReadOnly() | 463 | void SessionController::toggleReadOnly() | ||
463 | { | 464 | { | ||
464 | QAction *action = qobject_cast<QAction*>(sender()); | 465 | QAction *action = qobject_cast<QAction*>(sender()); | ||
465 | if (action != nullptr) { | 466 | if (action != nullptr) { | ||
466 | bool readonly = !isReadOnly(); | 467 | bool readonly = !isReadOnly(); | ||
467 | updateReadOnlyActionState(action, readonly); | | |||
468 | _session->setReadOnly(readonly); | 468 | _session->setReadOnly(readonly); | ||
469 | } | 469 | } | ||
470 | } | 470 | } | ||
471 | 471 | | |||
472 | bool SessionController::eventFilter(QObject* watched , QEvent* event) | 472 | bool SessionController::eventFilter(QObject* watched , QEvent* event) | ||
473 | { | 473 | { | ||
474 | if (event->type() == QEvent::FocusIn && watched == _view) { | 474 | if (event->type() == QEvent::FocusIn && watched == _view) { | ||
475 | // notify the world that the view associated with this session has been focused | 475 | // notify the world that the view associated with this session has been focused | ||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Line(s) | 610 | #endif | |||
630 | action = collection->addAction(QStringLiteral("edit-current-profile"), this, SLOT(editCurrentProfile())); | 630 | action = collection->addAction(QStringLiteral("edit-current-profile"), this, SLOT(editCurrentProfile())); | ||
631 | action->setText(i18n("Edit Current Profile...")); | 631 | action->setText(i18n("Edit Current Profile...")); | ||
632 | action->setIcon(QIcon::fromTheme(QStringLiteral("document-properties"))); | 632 | action->setIcon(QIcon::fromTheme(QStringLiteral("document-properties"))); | ||
633 | 633 | | |||
634 | _switchProfileMenu = new KActionMenu(i18n("Switch Profile"), this); | 634 | _switchProfileMenu = new KActionMenu(i18n("Switch Profile"), this); | ||
635 | collection->addAction(QStringLiteral("switch-profile"), _switchProfileMenu); | 635 | collection->addAction(QStringLiteral("switch-profile"), _switchProfileMenu); | ||
636 | connect(_switchProfileMenu->menu(), &QMenu::aboutToShow, this, &Konsole::SessionController::prepareSwitchProfileMenu); | 636 | connect(_switchProfileMenu->menu(), &QMenu::aboutToShow, this, &Konsole::SessionController::prepareSwitchProfileMenu); | ||
637 | 637 | | |||
638 | // Read-only | | |||
639 | action = collection->addAction(QStringLiteral("view-readonly"), this, SLOT(toggleReadOnly())); | | |||
640 | action->setText(i18nc("@item:inmenu A read only (locked) session", "Read-only")); | | |||
641 | action->setCheckable(true); | | |||
642 | updateReadOnlyActionState(action, isReadOnly()); | | |||
643 | | ||||
644 | // History | 638 | // History | ||
645 | _findAction = KStandardAction::find(this, SLOT(searchBarEvent()), collection); | 639 | _findAction = KStandardAction::find(this, SLOT(searchBarEvent()), collection); | ||
646 | collection->setDefaultShortcut(_findAction, QKeySequence()); | 640 | collection->setDefaultShortcut(_findAction, QKeySequence()); | ||
647 | 641 | | |||
648 | _findNextAction = KStandardAction::findNext(this, SLOT(findNextInHistory()), collection); | 642 | _findNextAction = KStandardAction::findNext(this, SLOT(findNextInHistory()), collection); | ||
649 | collection->setDefaultShortcut(_findNextAction, QKeySequence()); | 643 | collection->setDefaultShortcut(_findNextAction, QKeySequence()); | ||
650 | _findNextAction->setEnabled(false); | 644 | _findNextAction->setEnabled(false); | ||
651 | 645 | | |||
652 | _findPreviousAction = KStandardAction::findPrev(this, SLOT(findPreviousInHistory()), collection); | 646 | _findPreviousAction = KStandardAction::findPrev(this, SLOT(findPreviousInHistory()), collection); | ||
653 | collection->setDefaultShortcut(_findPreviousAction, QKeySequence()); | 647 | collection->setDefaultShortcut(_findPreviousAction, QKeySequence()); | ||
654 | _findPreviousAction->setEnabled(false); | 648 | _findPreviousAction->setEnabled(false); | ||
655 | 649 | | |||
656 | // Character Encoding | 650 | // Character Encoding | ||
657 | _codecAction = new KCodecAction(i18n("Set &Encoding"), this); | 651 | _codecAction = new KCodecAction(i18n("Set &Encoding"), this); | ||
658 | _codecAction->setIcon(QIcon::fromTheme(QStringLiteral("character-set"))); | 652 | _codecAction->setIcon(QIcon::fromTheme(QStringLiteral("character-set"))); | ||
659 | collection->addAction(QStringLiteral("set-encoding"), _codecAction); | 653 | collection->addAction(QStringLiteral("set-encoding"), _codecAction); | ||
660 | connect(_codecAction->menu(), &QMenu::aboutToShow, this, &Konsole::SessionController::updateCodecAction); | 654 | connect(_codecAction->menu(), &QMenu::aboutToShow, this, &Konsole::SessionController::updateCodecAction); | ||
661 | connect(_codecAction, static_cast<void(KCodecAction::*)(QTextCodec*)>(&KCodecAction::triggered), this, &Konsole::SessionController::changeCodec); | 655 | connect(_codecAction, static_cast<void(KCodecAction::*)(QTextCodec*)>(&KCodecAction::triggered), this, &Konsole::SessionController::changeCodec); | ||
656 | | ||||
657 | // Read-only | ||||
658 | action = collection->addAction(QStringLiteral("view-readonly"), this, SLOT(toggleReadOnly())); | ||||
659 | action->setText(i18nc("@item:inmenu A read only (locked) session", "Read-only")); | ||||
660 | action->setCheckable(true); | ||||
661 | updateReadOnlyActionStates(); | ||||
662 | } | 662 | } | ||
663 | 663 | | |||
664 | void SessionController::setupExtraActions() | 664 | void SessionController::setupExtraActions() | ||
665 | { | 665 | { | ||
666 | KActionCollection* collection = actionCollection(); | 666 | KActionCollection* collection = actionCollection(); | ||
667 | 667 | | |||
668 | // Rename Session | 668 | // Rename Session | ||
669 | QAction* action = collection->addAction(QStringLiteral("rename-session"), this, SLOT(renameSession())); | 669 | QAction* action = collection->addAction(QStringLiteral("rename-session"), this, SLOT(renameSession())); | ||
▲ Show 20 Lines • Show All 868 Lines • ▼ Show 20 Line(s) | 1533 | { | |||
1538 | } else { | 1538 | } else { | ||
1539 | if (!_keepIconUntilInteraction) { | 1539 | if (!_keepIconUntilInteraction) { | ||
1540 | // Not in Master Mode: use normal icon | 1540 | // Not in Master Mode: use normal icon | ||
1541 | setIcon(_sessionIcon); | 1541 | setIcon(_sessionIcon); | ||
1542 | } | 1542 | } | ||
1543 | } | 1543 | } | ||
1544 | } | 1544 | } | ||
1545 | 1545 | | |||
1546 | void SessionController::updateReadOnlyActionState(QAction *action, bool readonly) | 1546 | void SessionController::updateReadOnlyActionStates() | ||
1547 | { | 1547 | { | ||
1548 | action->setIcon(QIcon::fromTheme(readonly ? QStringLiteral("object-locked") : QStringLiteral("object-unlocked"))); | 1548 | bool readonly = isReadOnly(); | ||
1549 | action->setChecked(readonly); | 1549 | QAction *readonlyAction = actionCollection()->action(QStringLiteral("view-readonly")); | ||
1550 | Q_ASSERT(readonlyAction != nullptr); | ||||
1551 | readonlyAction->setIcon(QIcon::fromTheme(readonly ? QStringLiteral("object-locked") : QStringLiteral("object-unlocked"))); | ||||
1552 | readonlyAction->setChecked(readonly); | ||||
1550 | 1553 | | |||
1551 | QAction *editAction = actionCollection()->action(QStringLiteral("edit_paste")); | 1554 | auto updateActionState = [this, readonly](const QString &name) { | ||
1552 | if (editAction != nullptr) { | 1555 | QAction *action = actionCollection()->action(name); | ||
1553 | editAction->setEnabled(!readonly); | 1556 | if (action != nullptr) { | ||
1557 | action->setEnabled(!readonly); | ||||
1554 | } | 1558 | } | ||
1559 | }; | ||||
1560 | | ||||
1561 | updateActionState(QStringLiteral("edit_paste")); | ||||
1562 | updateActionState(QStringLiteral("clear-history")); | ||||
1563 | updateActionState(QStringLiteral("clear-history-and-reset")); | ||||
1564 | updateActionState(QStringLiteral("edit-current-profile")); | ||||
1565 | updateActionState(QStringLiteral("switch-profile")); | ||||
1566 | updateActionState(QStringLiteral("adjust-history")); | ||||
1567 | updateActionState(QStringLiteral("send-signal")); | ||||
1568 | updateActionState(QStringLiteral("zmodem-upload")); | ||||
1569 | | ||||
1570 | _codecAction->setEnabled(!readonly); | ||||
1555 | 1571 | | |||
1556 | // Without the timer, when detaching a tab while the message widget is visible, | 1572 | // Without the timer, when detaching a tab while the message widget is visible, | ||
1557 | // the size of the terminal becomes really small... | 1573 | // the size of the terminal becomes really small... | ||
1558 | QTimer::singleShot(0, this, [this, readonly]() { | 1574 | QTimer::singleShot(0, this, [this, readonly]() { | ||
1559 | _view->updateReadOnlyState(readonly); | 1575 | _view->updateReadOnlyState(readonly); | ||
1560 | }); | 1576 | }); | ||
1561 | } | 1577 | } | ||
1562 | 1578 | | |||
Show All 22 Lines | 1585 | { | |||
1585 | if (title.isEmpty()) { | 1601 | if (title.isEmpty()) { | ||
1586 | title = _session->title(Session::NameRole); | 1602 | title = _session->title(Session::NameRole); | ||
1587 | } | 1603 | } | ||
1588 | 1604 | | |||
1589 | setTitle(title); | 1605 | setTitle(title); | ||
1590 | emit rawTitleChanged(); | 1606 | emit rawTitleChanged(); | ||
1591 | } | 1607 | } | ||
1592 | 1608 | | |||
1609 | void SessionController::sessionReadOnlyChanged() { | ||||
1610 | // Trigger icon update | ||||
1611 | sessionTitleChanged(); | ||||
1612 | | ||||
1613 | updateReadOnlyActionStates(); | ||||
1614 | | ||||
1615 | // Update all views | ||||
1616 | for (TerminalDisplay* view : session()->views()) { | ||||
1617 | if (view != _view.data()) { | ||||
1618 | view->updateReadOnlyState(isReadOnly()); | ||||
1619 | } | ||||
1620 | } | ||||
1621 | } | ||||
1622 | | ||||
1593 | void SessionController::showDisplayContextMenu(const QPoint& position) | 1623 | void SessionController::showDisplayContextMenu(const QPoint& position) | ||
1594 | { | 1624 | { | ||
1595 | // needed to make sure the popup menu is available, even if a hosting | 1625 | // needed to make sure the popup menu is available, even if a hosting | ||
1596 | // application did not merge our GUI. | 1626 | // application did not merge our GUI. | ||
1597 | if (factory() == nullptr) { | 1627 | if (factory() == nullptr) { | ||
1598 | if (clientBuilder() == nullptr) { | 1628 | if (clientBuilder() == nullptr) { | ||
1599 | setClientBuilder(new KXMLGUIBuilder(_view)); | 1629 | setClientBuilder(new KXMLGUIBuilder(_view)); | ||
1600 | } | 1630 | } | ||
1601 | 1631 | | |||
1602 | auto factory = new KXMLGUIFactory(clientBuilder(), this); | 1632 | auto factory = new KXMLGUIFactory(clientBuilder(), this); | ||
1603 | factory->addClient(this); | 1633 | factory->addClient(this); | ||
1604 | ////qDebug() << "Created xmlgui factory" << factory; | 1634 | ////qDebug() << "Created xmlgui factory" << factory; | ||
1605 | } | 1635 | } | ||
1606 | 1636 | | |||
1607 | QPointer<QMenu> popup = qobject_cast<QMenu*>(factory()->container(QStringLiteral("session-popup-menu"), this)); | 1637 | QPointer<QMenu> popup = qobject_cast<QMenu*>(factory()->container(QStringLiteral("session-popup-menu"), this)); | ||
1608 | if (popup != nullptr) { | 1638 | if (popup != nullptr) { | ||
1639 | updateReadOnlyActionStates(); | ||||
1640 | | ||||
1609 | // prepend content-specific actions such as "Open Link", "Copy Email Address" etc. | 1641 | // prepend content-specific actions such as "Open Link", "Copy Email Address" etc. | ||
1610 | QList<QAction*> contentActions = _view->filterActions(position); | 1642 | QList<QAction*> contentActions = _view->filterActions(position); | ||
1611 | auto contentSeparator = new QAction(popup); | 1643 | auto contentSeparator = new QAction(popup); | ||
1612 | contentSeparator->setSeparator(true); | 1644 | contentSeparator->setSeparator(true); | ||
1613 | contentActions << contentSeparator; | 1645 | contentActions << contentSeparator; | ||
1614 | popup->insertActions(popup->actions().value(0, nullptr), contentActions); | 1646 | popup->insertActions(popup->actions().value(0, nullptr), contentActions); | ||
1615 | 1647 | | |||
1616 | // always update this submenu before showing the context menu, | 1648 | // always update this submenu before showing the context menu, | ||
▲ Show 20 Lines • Show All 479 Lines • Show Last 20 Lines |