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 | // associate bookmark menu with current session | 241 | // associate bookmark menu with current session | ||
238 | bookmarkHandler()->setActiveView(controller); | 242 | bookmarkHandler()->setActiveView(controller); | ||
239 | disconnect(bookmarkHandler(), &Konsole::BookmarkHandler::openUrl, nullptr, nullptr); | 243 | disconnect(bookmarkHandler(), &Konsole::BookmarkHandler::openUrl, nullptr, nullptr); | ||
240 | connect(bookmarkHandler(), &Konsole::BookmarkHandler::openUrl, controller, | 244 | connect(bookmarkHandler(), &Konsole::BookmarkHandler::openUrl, controller, | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 312 | { | |||
309 | KActionCollection *collection = actionCollection(); | 313 | KActionCollection *collection = actionCollection(); | ||
310 | 314 | | |||
311 | // File Menu | 315 | // File Menu | ||
312 | _newTabMenuAction = new KActionMenu(QIcon::fromTheme(QStringLiteral("tab-new")), | 316 | _newTabMenuAction = new KActionMenu(QIcon::fromTheme(QStringLiteral("tab-new")), | ||
313 | i18nc("@action:inmenu", "&New Tab"), collection); | 317 | i18nc("@action:inmenu", "&New Tab"), collection); | ||
314 | collection->setDefaultShortcut(_newTabMenuAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_T); | 318 | collection->setDefaultShortcut(_newTabMenuAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_T); | ||
315 | collection->setShortcutsConfigurable(_newTabMenuAction, true); | 319 | collection->setShortcutsConfigurable(_newTabMenuAction, true); | ||
316 | _newTabMenuAction->setAutoRepeat(false); | 320 | _newTabMenuAction->setAutoRepeat(false); | ||
317 | connect(_newTabMenuAction, &KActionMenu::triggered, | 321 | connect(_newTabMenuAction, &KActionMenu::triggered, | ||
318 | this, [this] { newTab(_viewManager->activeContainer());}); | 322 | this, [this] { newTab(); }); | ||
anthonyfieroni: Can you connect like:
```
connect(_newTabMenuAction, &KActionMenu::triggered, this, &MainWindow… | |||||
319 | collection->addAction(QStringLiteral("new-tab"), _newTabMenuAction); | 323 | collection->addAction(QStringLiteral("new-tab"), _newTabMenuAction); | ||
320 | collection->setShortcutsConfigurable(_newTabMenuAction, true); | 324 | collection->setShortcutsConfigurable(_newTabMenuAction, true); | ||
321 | 325 | | |||
322 | QAction* menuAction = collection->addAction(QStringLiteral("clone-tab")); | 326 | QAction* menuAction = collection->addAction(QStringLiteral("clone-tab")); | ||
323 | menuAction->setIcon(QIcon::fromTheme(QStringLiteral("tab-duplicate"))); | 327 | menuAction->setIcon(QIcon::fromTheme(QStringLiteral("tab-duplicate"))); | ||
324 | menuAction->setText(i18nc("@action:inmenu", "&Clone Tab")); | 328 | menuAction->setText(i18nc("@action:inmenu", "&Clone Tab")); | ||
325 | collection->setDefaultShortcut(menuAction, QKeySequence()); | 329 | collection->setDefaultShortcut(menuAction, QKeySequence()); | ||
326 | menuAction->setAutoRepeat(false); | 330 | menuAction->setAutoRepeat(false); | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | |||||
383 | { | 387 | { | ||
384 | return _bookmarkHandler; | 388 | return _bookmarkHandler; | ||
385 | } | 389 | } | ||
386 | 390 | | |||
387 | void MainWindow::setProfileList(ProfileList *list) | 391 | void MainWindow::setProfileList(ProfileList *list) | ||
388 | { | 392 | { | ||
389 | profileListChanged(list->actions()); | 393 | profileListChanged(list->actions()); | ||
390 | 394 | | |||
391 | connect(list, &Konsole::ProfileList::profileSelected, this, | 395 | connect(list, &Konsole::ProfileList::profileSelected, this, | ||
392 | [this](const Profile::Ptr &profile) { newFromProfile(_viewManager->activeContainer(), profile);}); | 396 | [this](const Profile::Ptr &profile) { newFromProfile(profile);}); | ||
Same as above connect(list, &Konsole::ProfileList::profileSelected, this, &MainWindow::newFromProfile); anthonyfieroni: Same as above
```
connect(list, &Konsole::ProfileList::profileSelected, this, &MainWindow… | |||||
393 | 397 | | |||
394 | connect(list, &Konsole::ProfileList::actionsChanged, this, | 398 | connect(list, &Konsole::ProfileList::actionsChanged, this, | ||
395 | &Konsole::MainWindow::profileListChanged); | 399 | &Konsole::MainWindow::profileListChanged); | ||
396 | } | 400 | } | ||
397 | 401 | | |||
398 | void MainWindow::profileListChanged(const QList<QAction *> &sessionActions) | 402 | void MainWindow::profileListChanged(const QList<QAction *> &sessionActions) | ||
399 | { | 403 | { | ||
400 | // If only 1 profile is to be shown in the menu, only display | 404 | // If only 1 profile is to be shown in the menu, only display | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | |||||
453 | } | 457 | } | ||
454 | 458 | | |||
455 | void MainWindow::openUrls(const QList<QUrl> &urls) | 459 | void MainWindow::openUrls(const QList<QUrl> &urls) | ||
456 | { | 460 | { | ||
457 | Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile(); | 461 | Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile(); | ||
458 | 462 | | |||
459 | Q_FOREACH (const auto &url, urls) { | 463 | Q_FOREACH (const auto &url, urls) { | ||
460 | if (url.isLocalFile()) { | 464 | if (url.isLocalFile()) { | ||
461 | createSession(_viewManager->activeContainer(), defaultProfile, url.path()); | 465 | createSession(defaultProfile, url.path()); | ||
462 | } else if (url.scheme() == QLatin1String("ssh")) { | 466 | } else if (url.scheme() == QLatin1String("ssh")) { | ||
463 | createSSHSession(_viewManager->activeContainer(), defaultProfile, url); | 467 | createSSHSession(defaultProfile, url); | ||
464 | } | 468 | } | ||
465 | } | 469 | } | ||
466 | } | 470 | } | ||
467 | 471 | | |||
468 | void MainWindow::newTab(TabbedViewContainer *tabWidget) | 472 | void MainWindow::newTab() | ||
469 | { | 473 | { | ||
470 | Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile(); | 474 | Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile(); | ||
471 | createSession(tabWidget, defaultProfile, activeSessionDir()); | 475 | createSession(defaultProfile, activeSessionDir()); | ||
472 | } | 476 | } | ||
473 | 477 | | |||
474 | void MainWindow::cloneTab() | 478 | void MainWindow::cloneTab() | ||
475 | { | 479 | { | ||
476 | Q_ASSERT(_pluggedController); | 480 | Q_ASSERT(_pluggedController); | ||
477 | 481 | | |||
478 | Session *session = _pluggedController->session(); | 482 | Session *session = _pluggedController->session(); | ||
479 | Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); | 483 | Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); | ||
480 | if (profile) { | 484 | if (profile) { | ||
481 | createSession(_viewManager->activeContainer(), profile, activeSessionDir()); | 485 | createSession(profile, activeSessionDir()); | ||
482 | } else { | 486 | } else { | ||
483 | // something must be wrong: every session should be associated with profile | 487 | // something must be wrong: every session should be associated with profile | ||
484 | Q_ASSERT(false); | 488 | Q_ASSERT(false); | ||
485 | newTab(_viewManager->activeContainer()); | 489 | newTab(); | ||
486 | } | 490 | } | ||
487 | } | 491 | } | ||
488 | 492 | | |||
489 | Session *MainWindow::createSession(TabbedViewContainer *tabWidget, Profile::Ptr profile, const QString &directory) | 493 | Session *MainWindow::createSession(Profile::Ptr profile, const QString &directory) | ||
490 | { | 494 | { | ||
491 | if (!profile) { | 495 | if (!profile) { | ||
492 | profile = ProfileManager::instance()->defaultProfile(); | 496 | profile = ProfileManager::instance()->defaultProfile(); | ||
493 | } | 497 | } | ||
494 | 498 | | |||
495 | Session *session = SessionManager::instance()->createSession(profile); | 499 | Session *session = SessionManager::instance()->createSession(profile); | ||
496 | 500 | | |||
497 | if (!directory.isEmpty() && profile->startInCurrentSessionDir()) { | 501 | if (!directory.isEmpty() && profile->startInCurrentSessionDir()) { | ||
498 | session->setInitialWorkingDirectory(directory); | 502 | session->setInitialWorkingDirectory(directory); | ||
499 | } | 503 | } | ||
500 | 504 | | |||
501 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(_viewManager->managerId())); | 505 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(_viewManager->managerId())); | ||
502 | 506 | | |||
503 | // create view before starting the session process so that the session | 507 | // create view before starting the session process so that the session | ||
504 | // doesn't suffer a change in terminal size right after the session | 508 | // doesn't suffer a change in terminal size right after the session | ||
505 | // starts. Some applications such as GNU Screen and Midnight Commander | 509 | // starts. Some applications such as GNU Screen and Midnight Commander | ||
506 | // don't like this happening | 510 | // don't like this happening | ||
507 | _viewManager->createView(tabWidget, session); | 511 | auto newView = _viewManager->createView(session); | ||
508 | 512 | _viewManager->activeContainer()->addView(newView); | |||
509 | return session; | 513 | return session; | ||
510 | } | 514 | } | ||
511 | 515 | | |||
512 | Session *MainWindow::createSSHSession(TabbedViewContainer *tabWidget, Profile::Ptr profile, const QUrl &url) | 516 | Session *MainWindow::createSSHSession(Profile::Ptr profile, const QUrl &url) | ||
513 | { | 517 | { | ||
514 | if (!profile) { | 518 | if (!profile) { | ||
515 | profile = ProfileManager::instance()->defaultProfile(); | 519 | profile = ProfileManager::instance()->defaultProfile(); | ||
516 | } | 520 | } | ||
517 | 521 | | |||
518 | Session *session = SessionManager::instance()->createSession(profile); | 522 | Session *session = SessionManager::instance()->createSession(profile); | ||
519 | 523 | | |||
520 | QString sshCommand = QStringLiteral("ssh "); | 524 | QString sshCommand = QStringLiteral("ssh "); | ||
521 | if (url.port() > -1) { | 525 | if (url.port() > -1) { | ||
522 | sshCommand += QStringLiteral("-p %1 ").arg(url.port()); | 526 | sshCommand += QStringLiteral("-p %1 ").arg(url.port()); | ||
523 | } | 527 | } | ||
524 | if (!url.userName().isEmpty()) { | 528 | if (!url.userName().isEmpty()) { | ||
525 | sshCommand += (url.userName() + QLatin1Char('@')); | 529 | sshCommand += (url.userName() + QLatin1Char('@')); | ||
526 | } | 530 | } | ||
527 | if (!url.host().isEmpty()) { | 531 | if (!url.host().isEmpty()) { | ||
528 | sshCommand += url.host(); | 532 | sshCommand += url.host(); | ||
529 | } | 533 | } | ||
530 | 534 | | |||
531 | session->sendTextToTerminal(sshCommand, QLatin1Char('\r')); | 535 | session->sendTextToTerminal(sshCommand, QLatin1Char('\r')); | ||
532 | 536 | | |||
533 | // create view before starting the session process so that the session | 537 | // create view before starting the session process so that the session | ||
534 | // doesn't suffer a change in terminal size right after the session | 538 | // doesn't suffer a change in terminal size right after the session | ||
535 | // starts. some applications such as GNU Screen and Midnight Commander | 539 | // starts. some applications such as GNU Screen and Midnight Commander | ||
536 | // don't like this happening | 540 | // don't like this happening | ||
537 | _viewManager->createView(tabWidget, session); | 541 | auto newView = _viewManager->createView(session); | ||
538 | 542 | _viewManager->activeContainer()->addView(newView); | |||
539 | return session; | 543 | return session; | ||
540 | } | 544 | } | ||
541 | 545 | | |||
542 | void MainWindow::setFocus() | 546 | void MainWindow::setFocus() | ||
543 | { | 547 | { | ||
544 | _viewManager->activeView()->setFocus(); | 548 | _viewManager->activeView()->setFocus(); | ||
545 | } | 549 | } | ||
546 | 550 | | |||
▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Line(s) | 706 | foreach (SessionController *controller, SessionController::allControllers()) { | |||
703 | controller->reloadXML(); | 707 | controller->reloadXML(); | ||
704 | if ((controller->factory() != nullptr) && controller != _pluggedController) { | 708 | if ((controller->factory() != nullptr) && controller != _pluggedController) { | ||
705 | syncActiveShortcuts(controller->actionCollection(), _pluggedController->actionCollection()); | 709 | syncActiveShortcuts(controller->actionCollection(), _pluggedController->actionCollection()); | ||
706 | } | 710 | } | ||
707 | } | 711 | } | ||
708 | } | 712 | } | ||
709 | } | 713 | } | ||
710 | 714 | | |||
711 | void MainWindow::newFromProfile(TabbedViewContainer *tabWidget, const Profile::Ptr &profile) | 715 | void MainWindow::newFromProfile(const Profile::Ptr &profile) | ||
712 | { | 716 | { | ||
713 | createSession(tabWidget, profile, activeSessionDir()); | 717 | createSession(profile, activeSessionDir()); | ||
714 | } | 718 | } | ||
715 | 719 | | |||
716 | void MainWindow::showManageProfilesDialog() | 720 | void MainWindow::showManageProfilesDialog() | ||
717 | { | 721 | { | ||
718 | showSettingsDialog(true); | 722 | showSettingsDialog(true); | ||
719 | } | 723 | } | ||
720 | 724 | | |||
721 | void MainWindow::showSettingsDialog(const bool showProfilePage) | 725 | void MainWindow::showSettingsDialog(const bool showProfilePage) | ||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Line(s) | 858 | if (auto action = actionCollection()->action(name)) { | |||
855 | if (action->isEnabled()) { | 859 | if (action->isEnabled()) { | ||
856 | action->trigger(); | 860 | action->trigger(); | ||
857 | } | 861 | } | ||
858 | } | 862 | } | ||
859 | } | 863 | } | ||
860 | 864 | | |||
861 | bool MainWindow::eventFilter(QObject *obj, QEvent *event) | 865 | bool MainWindow::eventFilter(QObject *obj, QEvent *event) | ||
862 | { | 866 | { | ||
863 | if (obj == _pluggedController->view()) { | 867 | if (!_pluggedController.isNull() && obj == _pluggedController->view()) { | ||
864 | switch(event->type()) { | 868 | switch(event->type()) { | ||
865 | case QEvent::MouseButtonPress: | 869 | case QEvent::MouseButtonPress: | ||
866 | case QEvent::MouseButtonDblClick: | 870 | case QEvent::MouseButtonDblClick: | ||
867 | switch(static_cast<QMouseEvent*>(event)->button()) { | 871 | switch(static_cast<QMouseEvent*>(event)->button()) { | ||
868 | case Qt::ForwardButton: | 872 | case Qt::ForwardButton: | ||
869 | triggerAction(QStringLiteral("next-view")); | 873 | triggerAction(QStringLiteral("next-view")); | ||
870 | break; | 874 | break; | ||
871 | case Qt::BackButton: | 875 | case Qt::BackButton: | ||
Show All 19 Lines |
Can you connect like: