Changeset View
Changeset View
Standalone View
Standalone View
src/MainWindow.cpp
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
45 | #include <KConfigDialog> | 45 | #include <KConfigDialog> | ||
46 | #include <KIconLoader> | 46 | #include <KIconLoader> | ||
47 | 47 | | |||
48 | // Konsole | 48 | // Konsole | ||
49 | #include "BookmarkHandler.h" | 49 | #include "BookmarkHandler.h" | ||
50 | #include "SessionController.h" | 50 | #include "SessionController.h" | ||
51 | #include "ProfileList.h" | 51 | #include "ProfileList.h" | ||
52 | #include "Session.h" | 52 | #include "Session.h" | ||
53 | #include "ViewContainer.h" | ||||
53 | #include "ViewManager.h" | 54 | #include "ViewManager.h" | ||
54 | #include "SessionManager.h" | 55 | #include "SessionManager.h" | ||
55 | #include "ProfileManager.h" | 56 | #include "ProfileManager.h" | ||
56 | #include "KonsoleSettings.h" | 57 | #include "KonsoleSettings.h" | ||
57 | #include "WindowSystemInfo.h" | 58 | #include "WindowSystemInfo.h" | ||
58 | #include "TerminalDisplay.h" | 59 | #include "TerminalDisplay.h" | ||
59 | #include "settings/FileLocationSettings.h" | 60 | #include "settings/FileLocationSettings.h" | ||
60 | #include "settings/GeneralSettings.h" | 61 | #include "settings/GeneralSettings.h" | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 104 | connect(_viewManager, &Konsole::ViewManager::unplugController, this, | |||
104 | &Konsole::MainWindow::disconnectController); | 105 | &Konsole::MainWindow::disconnectController); | ||
105 | connect(_viewManager, &Konsole::ViewManager::viewPropertiesChanged, | 106 | connect(_viewManager, &Konsole::ViewManager::viewPropertiesChanged, | ||
106 | bookmarkHandler(), &Konsole::BookmarkHandler::setViews); | 107 | bookmarkHandler(), &Konsole::BookmarkHandler::setViews); | ||
107 | connect(_viewManager, &Konsole::ViewManager::blurSettingChanged, | 108 | connect(_viewManager, &Konsole::ViewManager::blurSettingChanged, | ||
108 | this, &Konsole::MainWindow::setBlur); | 109 | this, &Konsole::MainWindow::setBlur); | ||
109 | 110 | | |||
110 | connect(_viewManager, &Konsole::ViewManager::updateWindowIcon, this, | 111 | connect(_viewManager, &Konsole::ViewManager::updateWindowIcon, this, | ||
111 | &Konsole::MainWindow::updateWindowIcon); | 112 | &Konsole::MainWindow::updateWindowIcon); | ||
112 | connect(_viewManager, | 113 | connect(_viewManager, &Konsole::ViewManager::newViewWithProfileRequest, | ||
113 | static_cast<void (ViewManager::*)(Profile::Ptr)>(&Konsole::ViewManager::newViewRequest), | 114 | this, &Konsole::MainWindow::newFromProfile); | ||
114 | this, | 115 | connect(_viewManager, &Konsole::ViewManager::newViewRequest, | ||
115 | &Konsole::MainWindow::newFromProfile); | 116 | this, &Konsole::MainWindow::newTab); | ||
116 | connect(_viewManager, | | |||
117 | static_cast<void (ViewManager::*)()>(&Konsole::ViewManager::newViewRequest), this, | | |||
118 | &Konsole::MainWindow::newTab); | | |||
119 | connect(_viewManager, &Konsole::ViewManager::viewDetached, this, | 117 | connect(_viewManager, &Konsole::ViewManager::viewDetached, this, | ||
120 | &Konsole::MainWindow::viewDetached); | 118 | &Konsole::MainWindow::viewDetached); | ||
121 | 119 | | |||
122 | setCentralWidget(_viewManager->widget()); | 120 | setCentralWidget(_viewManager->widget()); | ||
123 | 121 | | |||
124 | // disable automatically generated accelerators in top-level | 122 | // disable automatically generated accelerators in top-level | ||
125 | // menu items - to avoid conflicting with Alt+[Letter] shortcuts | 123 | // menu items - to avoid conflicting with Alt+[Letter] shortcuts | ||
126 | // in terminal applications | 124 | // in terminal applications | ||
▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Line(s) | 308 | { | |||
311 | KActionCollection *collection = actionCollection(); | 309 | KActionCollection *collection = actionCollection(); | ||
312 | 310 | | |||
313 | // File Menu | 311 | // File Menu | ||
314 | _newTabMenuAction = new KActionMenu(QIcon::fromTheme(QStringLiteral("tab-new")), | 312 | _newTabMenuAction = new KActionMenu(QIcon::fromTheme(QStringLiteral("tab-new")), | ||
315 | i18nc("@action:inmenu", "&New Tab"), collection); | 313 | i18nc("@action:inmenu", "&New Tab"), collection); | ||
316 | collection->setDefaultShortcut(_newTabMenuAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_T); | 314 | collection->setDefaultShortcut(_newTabMenuAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_T); | ||
317 | collection->setShortcutsConfigurable(_newTabMenuAction, true); | 315 | collection->setShortcutsConfigurable(_newTabMenuAction, true); | ||
318 | _newTabMenuAction->setAutoRepeat(false); | 316 | _newTabMenuAction->setAutoRepeat(false); | ||
319 | connect(_newTabMenuAction, &KActionMenu::triggered, this, &Konsole::MainWindow::newTab); | 317 | connect(_newTabMenuAction, &KActionMenu::triggered, | ||
318 | this, [this] { newTab(_viewManager->activeContainer());}); | ||||
320 | collection->addAction(QStringLiteral("new-tab"), _newTabMenuAction); | 319 | collection->addAction(QStringLiteral("new-tab"), _newTabMenuAction); | ||
321 | collection->setShortcutsConfigurable(_newTabMenuAction, true); | 320 | collection->setShortcutsConfigurable(_newTabMenuAction, true); | ||
322 | 321 | | |||
323 | QAction* menuAction = collection->addAction(QStringLiteral("clone-tab")); | 322 | QAction* menuAction = collection->addAction(QStringLiteral("clone-tab")); | ||
324 | menuAction->setIcon(QIcon::fromTheme(QStringLiteral("tab-duplicate"))); | 323 | menuAction->setIcon(QIcon::fromTheme(QStringLiteral("tab-duplicate"))); | ||
325 | menuAction->setText(i18nc("@action:inmenu", "&Clone Tab")); | 324 | menuAction->setText(i18nc("@action:inmenu", "&Clone Tab")); | ||
326 | collection->setDefaultShortcut(menuAction, QKeySequence()); | 325 | collection->setDefaultShortcut(menuAction, QKeySequence()); | ||
327 | menuAction->setAutoRepeat(false); | 326 | menuAction->setAutoRepeat(false); | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 383 | { | |||
385 | return _bookmarkHandler; | 384 | return _bookmarkHandler; | ||
386 | } | 385 | } | ||
387 | 386 | | |||
388 | void MainWindow::setProfileList(ProfileList *list) | 387 | void MainWindow::setProfileList(ProfileList *list) | ||
389 | { | 388 | { | ||
390 | profileListChanged(list->actions()); | 389 | profileListChanged(list->actions()); | ||
391 | 390 | | |||
392 | connect(list, &Konsole::ProfileList::profileSelected, this, | 391 | connect(list, &Konsole::ProfileList::profileSelected, this, | ||
393 | &Konsole::MainWindow::newFromProfile); | 392 | [this](Profile::Ptr profile) { newFromProfile(_viewManager->activeContainer(), profile);}); | ||
394 | 393 | | |||
395 | connect(list, &Konsole::ProfileList::actionsChanged, this, | 394 | connect(list, &Konsole::ProfileList::actionsChanged, this, | ||
396 | &Konsole::MainWindow::profileListChanged); | 395 | &Konsole::MainWindow::profileListChanged); | ||
397 | } | 396 | } | ||
398 | 397 | | |||
399 | void MainWindow::profileListChanged(const QList<QAction *> &sessionActions) | 398 | void MainWindow::profileListChanged(const QList<QAction *> &sessionActions) | ||
400 | { | 399 | { | ||
401 | // If only 1 profile is to be shown in the menu, only display | 400 | // If only 1 profile is to be shown in the menu, only display | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | |||||
454 | } | 453 | } | ||
455 | 454 | | |||
456 | void MainWindow::openUrls(const QList<QUrl> &urls) | 455 | void MainWindow::openUrls(const QList<QUrl> &urls) | ||
457 | { | 456 | { | ||
458 | Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile(); | 457 | Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile(); | ||
459 | 458 | | |||
460 | Q_FOREACH (const auto &url, urls) { | 459 | Q_FOREACH (const auto &url, urls) { | ||
461 | if (url.isLocalFile()) { | 460 | if (url.isLocalFile()) { | ||
462 | createSession(defaultProfile, url.path()); | 461 | createSession(_viewManager->activeContainer(), defaultProfile, url.path()); | ||
463 | } else if (url.scheme() == QLatin1String("ssh")) { | 462 | } else if (url.scheme() == QLatin1String("ssh")) { | ||
464 | createSSHSession(defaultProfile, url); | 463 | createSSHSession(_viewManager->activeContainer(), defaultProfile, url); | ||
465 | } | 464 | } | ||
466 | } | 465 | } | ||
467 | } | 466 | } | ||
468 | 467 | | |||
469 | void MainWindow::newTab() | 468 | void MainWindow::newTab(TabbedViewContainer *tabWidget) | ||
470 | { | 469 | { | ||
471 | Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile(); | 470 | Profile::Ptr defaultProfile = ProfileManager::instance()->defaultProfile(); | ||
472 | createSession(defaultProfile, activeSessionDir()); | 471 | createSession(tabWidget, defaultProfile, activeSessionDir()); | ||
473 | } | 472 | } | ||
474 | 473 | | |||
475 | void MainWindow::cloneTab() | 474 | void MainWindow::cloneTab() | ||
476 | { | 475 | { | ||
477 | Q_ASSERT(_pluggedController); | 476 | Q_ASSERT(_pluggedController); | ||
478 | 477 | | |||
479 | Session *session = _pluggedController->session(); | 478 | Session *session = _pluggedController->session(); | ||
480 | Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); | 479 | Profile::Ptr profile = SessionManager::instance()->sessionProfile(session); | ||
481 | if (profile) { | 480 | if (profile) { | ||
482 | createSession(profile, activeSessionDir()); | 481 | createSession(_viewManager->activeContainer(), profile, activeSessionDir()); | ||
483 | } else { | 482 | } else { | ||
484 | // something must be wrong: every session should be associated with profile | 483 | // something must be wrong: every session should be associated with profile | ||
485 | Q_ASSERT(false); | 484 | Q_ASSERT(false); | ||
486 | newTab(); | 485 | newTab(_viewManager->activeContainer()); | ||
487 | } | 486 | } | ||
488 | } | 487 | } | ||
489 | 488 | | |||
490 | Session *MainWindow::createSession(Profile::Ptr profile, const QString &directory) | 489 | Session *MainWindow::createSession(TabbedViewContainer *tabWidget, Profile::Ptr profile, const QString &directory) | ||
491 | { | 490 | { | ||
492 | if (!profile) { | 491 | if (!profile) { | ||
493 | profile = ProfileManager::instance()->defaultProfile(); | 492 | profile = ProfileManager::instance()->defaultProfile(); | ||
494 | } | 493 | } | ||
495 | 494 | | |||
496 | Session *session = SessionManager::instance()->createSession(profile); | 495 | Session *session = SessionManager::instance()->createSession(profile); | ||
497 | 496 | | |||
498 | if (!directory.isEmpty() && profile->startInCurrentSessionDir()) { | 497 | if (!directory.isEmpty() && profile->startInCurrentSessionDir()) { | ||
499 | session->setInitialWorkingDirectory(directory); | 498 | session->setInitialWorkingDirectory(directory); | ||
500 | } | 499 | } | ||
501 | 500 | | |||
502 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(_viewManager->managerId())); | 501 | session->addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_WINDOW=/Windows/%1").arg(_viewManager->managerId())); | ||
503 | 502 | | |||
504 | // create view before starting the session process so that the session | 503 | // create view before starting the session process so that the session | ||
505 | // doesn't suffer a change in terminal size right after the session | 504 | // doesn't suffer a change in terminal size right after the session | ||
506 | // starts. Some applications such as GNU Screen and Midnight Commander | 505 | // starts. Some applications such as GNU Screen and Midnight Commander | ||
507 | // don't like this happening | 506 | // don't like this happening | ||
508 | _viewManager->createView(session); | 507 | _viewManager->createView(tabWidget, session); | ||
509 | 508 | | |||
510 | return session; | 509 | return session; | ||
511 | } | 510 | } | ||
512 | 511 | | |||
513 | Session *MainWindow::createSSHSession(Profile::Ptr profile, const QUrl &url) | 512 | Session *MainWindow::createSSHSession(TabbedViewContainer *tabWidget, Profile::Ptr profile, const QUrl &url) | ||
514 | { | 513 | { | ||
515 | if (!profile) { | 514 | if (!profile) { | ||
516 | profile = ProfileManager::instance()->defaultProfile(); | 515 | profile = ProfileManager::instance()->defaultProfile(); | ||
517 | } | 516 | } | ||
518 | 517 | | |||
519 | Session *session = SessionManager::instance()->createSession(profile); | 518 | Session *session = SessionManager::instance()->createSession(profile); | ||
520 | 519 | | |||
521 | QString sshCommand = QStringLiteral("ssh "); | 520 | QString sshCommand = QStringLiteral("ssh "); | ||
522 | if (url.port() > -1) { | 521 | if (url.port() > -1) { | ||
523 | sshCommand += QStringLiteral("-p %1 ").arg(url.port()); | 522 | sshCommand += QStringLiteral("-p %1 ").arg(url.port()); | ||
524 | } | 523 | } | ||
525 | if (!url.userName().isEmpty()) { | 524 | if (!url.userName().isEmpty()) { | ||
526 | sshCommand += (url.userName() + QLatin1Char('@')); | 525 | sshCommand += (url.userName() + QLatin1Char('@')); | ||
527 | } | 526 | } | ||
528 | if (!url.host().isEmpty()) { | 527 | if (!url.host().isEmpty()) { | ||
529 | sshCommand += url.host(); | 528 | sshCommand += url.host(); | ||
530 | } | 529 | } | ||
531 | 530 | | |||
532 | session->sendTextToTerminal(sshCommand, QLatin1Char('\r')); | 531 | session->sendTextToTerminal(sshCommand, QLatin1Char('\r')); | ||
533 | 532 | | |||
534 | // create view before starting the session process so that the session | 533 | // create view before starting the session process so that the session | ||
535 | // doesn't suffer a change in terminal size right after the session | 534 | // doesn't suffer a change in terminal size right after the session | ||
536 | // starts. some applications such as GNU Screen and Midnight Commander | 535 | // starts. some applications such as GNU Screen and Midnight Commander | ||
537 | // don't like this happening | 536 | // don't like this happening | ||
538 | _viewManager->createView(session); | 537 | _viewManager->createView(tabWidget, session); | ||
539 | 538 | | |||
540 | return session; | 539 | return session; | ||
541 | } | 540 | } | ||
542 | 541 | | |||
543 | void MainWindow::setFocus() | 542 | void MainWindow::setFocus() | ||
544 | { | 543 | { | ||
545 | _viewManager->activeView()->setFocus(); | 544 | _viewManager->activeView()->setFocus(); | ||
546 | } | 545 | } | ||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Line(s) | 702 | foreach (SessionController *controller, SessionController::allControllers()) { | |||
704 | controller->reloadXML(); | 703 | controller->reloadXML(); | ||
705 | if ((controller->factory() != nullptr) && controller != _pluggedController) { | 704 | if ((controller->factory() != nullptr) && controller != _pluggedController) { | ||
706 | syncActiveShortcuts(controller->actionCollection(), _pluggedController->actionCollection()); | 705 | syncActiveShortcuts(controller->actionCollection(), _pluggedController->actionCollection()); | ||
707 | } | 706 | } | ||
708 | } | 707 | } | ||
709 | } | 708 | } | ||
710 | } | 709 | } | ||
711 | 710 | | |||
712 | void MainWindow::newFromProfile(Profile::Ptr profile) | 711 | void MainWindow::newFromProfile(TabbedViewContainer *tabWidget, Profile::Ptr profile) | ||
713 | { | 712 | { | ||
714 | createSession(profile, activeSessionDir()); | 713 | createSession(tabWidget, profile, activeSessionDir()); | ||
715 | } | 714 | } | ||
716 | 715 | | |||
717 | void MainWindow::showManageProfilesDialog() | 716 | void MainWindow::showManageProfilesDialog() | ||
718 | { | 717 | { | ||
719 | showSettingsDialog(true); | 718 | showSettingsDialog(true); | ||
720 | } | 719 | } | ||
721 | 720 | | |||
722 | void MainWindow::showSettingsDialog(const bool showProfilePage) | 721 | void MainWindow::showSettingsDialog(const bool showProfilePage) | ||
▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines |