Changeset View
Changeset View
Standalone View
Standalone View
src/MainWindow.cpp
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | 108 | connect(_viewManager, &Konsole::ViewManager::blurSettingChanged, | |||
---|---|---|---|---|---|
109 | this, &Konsole::MainWindow::setBlur); | 109 | this, &Konsole::MainWindow::setBlur); | ||
110 | 110 | | |||
111 | connect(_viewManager, &Konsole::ViewManager::updateWindowIcon, this, | 111 | connect(_viewManager, &Konsole::ViewManager::updateWindowIcon, this, | ||
112 | &Konsole::MainWindow::updateWindowIcon); | 112 | &Konsole::MainWindow::updateWindowIcon); | ||
113 | connect(_viewManager, &Konsole::ViewManager::newViewWithProfileRequest, | 113 | connect(_viewManager, &Konsole::ViewManager::newViewWithProfileRequest, | ||
114 | this, &Konsole::MainWindow::newFromProfile); | 114 | this, &Konsole::MainWindow::newFromProfile); | ||
115 | connect(_viewManager, &Konsole::ViewManager::newViewRequest, | 115 | connect(_viewManager, &Konsole::ViewManager::newViewRequest, | ||
116 | this, &Konsole::MainWindow::newTab); | 116 | this, &Konsole::MainWindow::newTab); | ||
117 | connect(_viewManager, &Konsole::ViewManager::viewDetached, this, | 117 | connect(_viewManager, &Konsole::ViewManager::terminalsDetached, this, | ||
118 | &Konsole::MainWindow::viewDetached); | 118 | &Konsole::MainWindow::terminalsDetached); | ||
119 | 119 | | |||
120 | setCentralWidget(_viewManager->widget()); | 120 | setCentralWidget(_viewManager->widget()); | ||
121 | 121 | | |||
122 | // disable automatically generated accelerators in top-level | 122 | // disable automatically generated accelerators in top-level | ||
123 | // menu items - to avoid conflicting with Alt+[Letter] shortcuts | 123 | // menu items - to avoid conflicting with Alt+[Letter] shortcuts | ||
124 | // in terminal applications | 124 | // in terminal applications | ||
125 | KAcceleratorManager::setNoAccel(menuBar()); | 125 | KAcceleratorManager::setNoAccel(menuBar()); | ||
126 | 126 | | |||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Line(s) | 214 | { | |||
225 | 225 | | |||
226 | // KXmlGuiFactory::removeClient() will try to access actions associated | 226 | // KXmlGuiFactory::removeClient() will try to access actions associated | ||
227 | // with the controller internally, which may not be valid after the controller | 227 | // with the controller internally, which may not be valid after the controller | ||
228 | // itself is no longer valid (after the associated session and or view have | 228 | // itself is no longer valid (after the associated session and or view have | ||
229 | // been destroyed) | 229 | // been destroyed) | ||
230 | if (controller->isValid()) { | 230 | if (controller->isValid()) { | ||
231 | guiFactory()->removeClient(controller); | 231 | guiFactory()->removeClient(controller); | ||
232 | } | 232 | } | ||
233 | | ||||
234 | if (_pluggedController == controller) { | ||||
235 | _pluggedController = nullptr; | ||||
236 | } | ||||
233 | } | 237 | } | ||
234 | 238 | | |||
235 | void MainWindow::activeViewChanged(SessionController *controller) | 239 | void MainWindow::activeViewChanged(SessionController *controller) | ||
236 | { | 240 | { | ||
237 | if (!SessionManager::instance()->sessionProfile(controller->session())) { | 241 | if (!SessionManager::instance()->sessionProfile(controller->session())) { | ||
238 | return; | 242 | return; | ||
239 | } | 243 | } | ||
240 | // associate bookmark menu with current session | 244 | // associate bookmark menu with current session | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | |||||
311 | { | 315 | { | ||
312 | KActionCollection *collection = actionCollection(); | 316 | KActionCollection *collection = actionCollection(); | ||
313 | 317 | | |||
314 | // File Menu | 318 | // File Menu | ||
315 | _newTabMenuAction = new KActionMenu(QIcon::fromTheme(QStringLiteral("tab-new")), | 319 | _newTabMenuAction = new KActionMenu(QIcon::fromTheme(QStringLiteral("tab-new")), | ||
316 | i18nc("@action:inmenu", "&New Tab"), collection); | 320 | i18nc("@action:inmenu", "&New Tab"), collection); | ||
317 | collection->setDefaultShortcut(_newTabMenuAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_T); | 321 | collection->setDefaultShortcut(_newTabMenuAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_T); | ||
318 | collection->setShortcutsConfigurable(_newTabMenuAction, true); | 322 | collection->setShortcutsConfigurable(_newTabMenuAction, true); | ||
319 | _newTabMenuAction->setAutoRepeat(false); | 323 | _newTabMenuAction->setAutoRepeat(false); | ||
320 | connect(_newTabMenuAction, &KActionMenu::triggered, | 324 | connect(_newTabMenuAction, &KActionMenu::triggered, this, &MainWindow::newTab); | ||
anthonyfieroni: Can you connect like:
```
connect(_newTabMenuAction, &KActionMenu::triggered, this, &MainWindow… | |||||
321 | this, [this] { newTab(_viewManager->activeContainer());}); | | |||
322 | collection->addAction(QStringLiteral("new-tab"), _newTabMenuAction); | 325 | collection->addAction(QStringLiteral("new-tab"), _newTabMenuAction); | ||
323 | collection->setShortcutsConfigurable(_newTabMenuAction, true); | 326 | collection->setShortcutsConfigurable(_newTabMenuAction, true); | ||
324 | 327 | | |||
325 | QAction* menuAction = collection->addAction(QStringLiteral("clone-tab")); | 328 | QAction* menuAction = collection->addAction(QStringLiteral("clone-tab")); | ||
326 | menuAction->setIcon(QIcon::fromTheme(QStringLiteral("tab-duplicate"))); | 329 | menuAction->setIcon(QIcon::fromTheme(QStringLiteral("tab-duplicate"))); | ||
327 | menuAction->setText(i18nc("@action:inmenu", "&Clone Tab")); | 330 | menuAction->setText(i18nc("@action:inmenu", "&Clone Tab")); | ||
328 | collection->setDefaultShortcut(menuAction, QKeySequence()); | 331 | collection->setDefaultShortcut(menuAction, QKeySequence()); | ||
329 | menuAction->setAutoRepeat(false); | 332 | menuAction->setAutoRepeat(false); | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | |||||
385 | BookmarkHandler *MainWindow::bookmarkHandler() const | 388 | BookmarkHandler *MainWindow::bookmarkHandler() const | ||
386 | { | 389 | { | ||
387 | return _bookmarkHandler; | 390 | return _bookmarkHandler; | ||
388 | } | 391 | } | ||
389 | 392 | | |||
390 | void MainWindow::setProfileList(ProfileList *list) | 393 | void MainWindow::setProfileList(ProfileList *list) | ||
391 | { | 394 | { | ||
392 | profileListChanged(list->actions()); | 395 | profileListChanged(list->actions()); | ||
393 | 396 | | |||
394 | connect(list, &Konsole::ProfileList::profileSelected, this, | 397 | connect(list, &Konsole::ProfileList::profileSelected, this, &MainWindow::newFromProfile); | ||
Same as above connect(list, &Konsole::ProfileList::profileSelected, this, &MainWindow::newFromProfile); anthonyfieroni: Same as above
```
connect(list, &Konsole::ProfileList::profileSelected, this, &MainWindow… | |||||
395 | [this](const Profile::Ptr &profile) { newFromProfile(_viewManager->activeContainer(), profile);}); | 398 | connect(list, &Konsole::ProfileList::actionsChanged, this, &Konsole::MainWindow::profileListChanged); | ||
396 | | ||||
397 | connect(list, &Konsole::ProfileList::actionsChanged, this, | | |||
398 | &Konsole::MainWindow::profileListChanged); | | |||
399 | } | 399 | } | ||
400 | 400 | | |||
401 | void MainWindow::profileListChanged(const QList<QAction *> &sessionActions) | 401 | void MainWindow::profileListChanged(const QList<QAction *> &sessionActions) | ||
402 | { | 402 | { | ||
403 | // If only 1 profile is to be shown in the menu, only display | 403 | // If only 1 profile is to be shown in the menu, only display | ||
404 | // it if it is the non-default profile. | 404 | // it if it is the non-default profile. | ||
405 | if (sessionActions.size() > 2) { | 405 | if (sessionActions.size() > 2) { | ||
406 | // Update the 'New Tab' KActionMenu | 406 | // Update the 'New Tab' KActionMenu | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
456 | } | 456 | } | ||
457 | 457 | | |||
458 | void MainWindow::openUrls(const QList<QUrl> &urls) | 458 | void MainWindow::openUrls(const QList<QUrl> &urls) | ||
459 | { | 459 | { | ||
460 | Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile(); | 460 | Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile(); | ||
461 | 461 | | |||
462 | for (const auto &url : urls) { | 462 | for (const auto &url : urls) { | ||
463 | if (url.isLocalFile()) { | 463 | if (url.isLocalFile()) { | ||
464 | createSession(_viewManager->activeContainer(), defaultProfile, url.path()); | 464 | createSession(defaultProfile, url.path()); | ||
465 | } else if (url.scheme() == QLatin1String("ssh")) { | 465 | } else if (url.scheme() == QLatin1String("ssh")) { | ||
466 | createSSHSession(_viewManager->activeContainer(), defaultProfile, url); | 466 | createSSHSession(defaultProfile, url); | ||
467 | } | 467 | } | ||
468 | } | 468 | } | ||
469 | } | 469 | } | ||
470 | 470 | | |||
471 | void MainWindow::newTab(TabbedViewContainer *tabWidget) | 471 | void MainWindow::newTab() | ||
472 | { | 472 | { | ||
473 | Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile(); | 473 | Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile(); | ||
474 | createSession(tabWidget, defaultProfile, activeSessionDir()); | 474 | createSession(defaultProfile, activeSessionDir()); | ||
475 | } | 475 | } | ||
476 | 476 | | |||
477 | void MainWindow::cloneTab() | 477 | void MainWindow::cloneTab() | ||
478 | { | 478 | { | ||
479 | Q_ASSERT(_pluggedController); | 479 | Q_ASSERT(_pluggedController); | ||
480 | 480 | | |||
481 | Session *session = _pluggedController->session(); | 481 | Session *session = _pluggedController->session(); | ||
482 | Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); | 482 | Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); | ||
483 | if (profile) { | 483 | if (profile) { | ||
484 | createSession(_viewManager->activeContainer(), profile, activeSessionDir()); | 484 | createSession(profile, activeSessionDir()); | ||
485 | } else { | 485 | } else { | ||
486 | // something must be wrong: every session should be associated with profile | 486 | // something must be wrong: every session should be associated with profile | ||
487 | Q_ASSERT(false); | 487 | Q_ASSERT(false); | ||
488 | newTab(_viewManager->activeContainer()); | 488 | newTab(); | ||
489 | } | 489 | } | ||
490 | } | 490 | } | ||
491 | 491 | | |||
492 | Session *MainWindow::createSession(TabbedViewContainer *tabWidget, Profile::Ptr profile, const QString &directory) | 492 | Session *MainWindow::createSession(Profile::Ptr profile, const QString &directory) | ||
493 | { | 493 | { | ||
494 | if (!profile) { | 494 | if (!profile) { | ||
495 | profile = ProfileManager::instance()->defaultProfile(); | 495 | profile = ProfileManager::instance()->defaultProfile(); | ||
496 | } | 496 | } | ||
497 | 497 | | |||
498 | Session *session = SessionManager::instance()->createSession(profile); | 498 | Session *session = SessionManager::instance()->createSession(profile); | ||
499 | 499 | | |||
500 | if (!directory.isEmpty() && profile->startInCurrentSessionDir()) { | 500 | if (!directory.isEmpty() && profile->startInCurrentSessionDir()) { | ||
501 | session->setInitialWorkingDirectory(directory); | 501 | session->setInitialWorkingDirectory(directory); | ||
502 | } | 502 | } | ||
503 | 503 | | |||
504 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(_viewManager->managerId())); | 504 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(_viewManager->managerId())); | ||
505 | 505 | | |||
506 | // create view before starting the session process so that the session | 506 | // create view before starting the session process so that the session | ||
507 | // doesn't suffer a change in terminal size right after the session | 507 | // doesn't suffer a change in terminal size right after the session | ||
508 | // starts. Some applications such as GNU Screen and Midnight Commander | 508 | // starts. Some applications such as GNU Screen and Midnight Commander | ||
509 | // don't like this happening | 509 | // don't like this happening | ||
510 | _viewManager->createView(tabWidget, session); | 510 | auto newView = _viewManager->createView(session); | ||
511 | 511 | _viewManager->activeContainer()->addView(newView); | |||
512 | return session; | 512 | return session; | ||
513 | } | 513 | } | ||
514 | 514 | | |||
515 | Session *MainWindow::createSSHSession(TabbedViewContainer *tabWidget, Profile::Ptr profile, const QUrl &url) | 515 | Session *MainWindow::createSSHSession(Profile::Ptr profile, const QUrl &url) | ||
516 | { | 516 | { | ||
517 | if (!profile) { | 517 | if (!profile) { | ||
518 | profile = ProfileManager::instance()->defaultProfile(); | 518 | profile = ProfileManager::instance()->defaultProfile(); | ||
519 | } | 519 | } | ||
520 | 520 | | |||
521 | Session *session = SessionManager::instance()->createSession(profile); | 521 | Session *session = SessionManager::instance()->createSession(profile); | ||
522 | 522 | | |||
523 | QString sshCommand = QStringLiteral("ssh "); | 523 | QString sshCommand = QStringLiteral("ssh "); | ||
524 | if (url.port() > -1) { | 524 | if (url.port() > -1) { | ||
525 | sshCommand += QStringLiteral("-p %1 ").arg(url.port()); | 525 | sshCommand += QStringLiteral("-p %1 ").arg(url.port()); | ||
526 | } | 526 | } | ||
527 | if (!url.userName().isEmpty()) { | 527 | if (!url.userName().isEmpty()) { | ||
528 | sshCommand += (url.userName() + QLatin1Char('@')); | 528 | sshCommand += (url.userName() + QLatin1Char('@')); | ||
529 | } | 529 | } | ||
530 | if (!url.host().isEmpty()) { | 530 | if (!url.host().isEmpty()) { | ||
531 | sshCommand += url.host(); | 531 | sshCommand += url.host(); | ||
532 | } | 532 | } | ||
533 | 533 | | |||
534 | session->sendTextToTerminal(sshCommand, QLatin1Char('\r')); | 534 | session->sendTextToTerminal(sshCommand, QLatin1Char('\r')); | ||
535 | 535 | | |||
536 | // create view before starting the session process so that the session | 536 | // create view before starting the session process so that the session | ||
537 | // doesn't suffer a change in terminal size right after the session | 537 | // doesn't suffer a change in terminal size right after the session | ||
538 | // starts. some applications such as GNU Screen and Midnight Commander | 538 | // starts. some applications such as GNU Screen and Midnight Commander | ||
539 | // don't like this happening | 539 | // don't like this happening | ||
540 | _viewManager->createView(tabWidget, session); | 540 | auto newView = _viewManager->createView(session); | ||
541 | 541 | _viewManager->activeContainer()->addView(newView); | |||
542 | return session; | 542 | return session; | ||
543 | } | 543 | } | ||
544 | 544 | | |||
545 | void MainWindow::setFocus() | 545 | void MainWindow::setFocus() | ||
546 | { | 546 | { | ||
547 | _viewManager->activeView()->setFocus(); | 547 | _viewManager->activeView()->setFocus(); | ||
548 | } | 548 | } | ||
549 | 549 | | |||
▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Line(s) | 705 | foreach (SessionController *controller, SessionController::allControllers()) { | |||
706 | controller->reloadXML(); | 706 | controller->reloadXML(); | ||
707 | if ((controller->factory() != nullptr) && controller != _pluggedController) { | 707 | if ((controller->factory() != nullptr) && controller != _pluggedController) { | ||
708 | syncActiveShortcuts(controller->actionCollection(), _pluggedController->actionCollection()); | 708 | syncActiveShortcuts(controller->actionCollection(), _pluggedController->actionCollection()); | ||
709 | } | 709 | } | ||
710 | } | 710 | } | ||
711 | } | 711 | } | ||
712 | } | 712 | } | ||
713 | 713 | | |||
714 | void MainWindow::newFromProfile(TabbedViewContainer *tabWidget, const Profile::Ptr &profile) | 714 | void MainWindow::newFromProfile(const Profile::Ptr &profile) | ||
715 | { | 715 | { | ||
716 | createSession(tabWidget, profile, activeSessionDir()); | 716 | createSession(profile, activeSessionDir()); | ||
717 | } | 717 | } | ||
718 | 718 | | |||
719 | void MainWindow::showManageProfilesDialog() | 719 | void MainWindow::showManageProfilesDialog() | ||
720 | { | 720 | { | ||
721 | showSettingsDialog(true); | 721 | showSettingsDialog(true); | ||
722 | } | 722 | } | ||
723 | 723 | | |||
724 | void MainWindow::showSettingsDialog(const bool showProfilePage) | 724 | void MainWindow::showSettingsDialog(const bool showProfilePage) | ||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Line(s) | 857 | if (auto action = actionCollection()->action(name)) { | |||
858 | if (action->isEnabled()) { | 858 | if (action->isEnabled()) { | ||
859 | action->trigger(); | 859 | action->trigger(); | ||
860 | } | 860 | } | ||
861 | } | 861 | } | ||
862 | } | 862 | } | ||
863 | 863 | | |||
864 | bool MainWindow::eventFilter(QObject *obj, QEvent *event) | 864 | bool MainWindow::eventFilter(QObject *obj, QEvent *event) | ||
865 | { | 865 | { | ||
866 | if (obj == _pluggedController->view()) { | 866 | if (!_pluggedController.isNull() && obj == _pluggedController->view()) { | ||
867 | switch(event->type()) { | 867 | switch(event->type()) { | ||
868 | case QEvent::MouseButtonPress: | 868 | case QEvent::MouseButtonPress: | ||
869 | case QEvent::MouseButtonDblClick: | 869 | case QEvent::MouseButtonDblClick: | ||
870 | switch(static_cast<QMouseEvent*>(event)->button()) { | 870 | switch(static_cast<QMouseEvent*>(event)->button()) { | ||
871 | case Qt::ForwardButton: | 871 | case Qt::ForwardButton: | ||
872 | triggerAction(QStringLiteral("next-view")); | 872 | triggerAction(QStringLiteral("next-view")); | ||
873 | break; | 873 | break; | ||
874 | case Qt::BackButton: | 874 | case Qt::BackButton: | ||
Show All 19 Lines |
Can you connect like: