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