Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/kfileitemactions.cpp
Show First 20 Lines • Show All 644 Lines • ▼ Show 20 Line(s) | 622 | if (d->m_mimeTypeList.count() > 1 | |||
---|---|---|---|---|---|
645 | d->m_fileOpenList = d->m_props.items(); | 645 | d->m_fileOpenList = d->m_props.items(); | ||
646 | QObject::connect(runAct, SIGNAL(triggered()), d, SLOT(slotRunPreferredApplications())); | 646 | QObject::connect(runAct, SIGNAL(triggered()), d, SLOT(slotRunPreferredApplications())); | ||
647 | topMenu->addAction(runAct); | 647 | topMenu->addAction(runAct); | ||
648 | } | 648 | } | ||
649 | 649 | | |||
650 | if (!offers.isEmpty()) { | 650 | if (!offers.isEmpty()) { | ||
651 | QMenu *menu = topMenu; | 651 | QMenu *menu = topMenu; | ||
652 | 652 | | |||
653 | if (offers.count() > 1) { // submenu 'open with' | 653 | // Always show the top app inline | ||
654 | QAction *act = d->createAppAction(offers.takeFirst(), true); | ||||
anthonyfieroni: Use offers.takeFirst(), it will get and remove. | |||||
elvisangelaccio: Please use `true` rather than `menu` as 2nd argument | |||||
655 | menu->addAction(act); | ||||
656 | | ||||
anthonyfieroni: Remove. | |||||
657 | // If there are still more apps, show them in a sub-menu | ||||
658 | if (!offers.isEmpty()) { // submenu 'open with' | ||||
654 | menu = new QMenu(i18nc("@title:menu", "&Open With"), topMenu); | 659 | menu = new QMenu(i18nc("@title:menu", "&Open With"), topMenu); | ||
655 | menu->menuAction()->setObjectName(QStringLiteral("openWith_submenu")); // for the unittest | 660 | menu->menuAction()->setObjectName(QStringLiteral("openWith_submenu")); // for the unittest | ||
656 | topMenu->addMenu(menu); | 661 | topMenu->addMenu(menu); | ||
657 | } | | |||
658 | //qDebug() << offers.count() << "offers" << topMenu << menu; | | |||
659 | 662 | | |||
663 | // Add other apps to the sub-menu | ||||
This introduce one more so menu can grow with 6 items which is much. Why not keep same approach, but we can show every time the *preferred* one --------------------------- Open with Gwenview Open with other application -> { submenu if present others, or ... if not } --------------------------- anthonyfieroni: This introduce one more so menu can grow with 6 items which is much. Why not keep same… | |||||
ngraham: Hey, I like that idea! | |||||
660 | KService::List::ConstIterator it = offers.constBegin(); | 664 | KService::List::ConstIterator it = offers.constBegin(); | ||
661 | for (; it != offers.constEnd(); it++) { | 665 | for (; it != offers.constEnd(); it++) { | ||
662 | QAction *act = d->createAppAction(*it, | 666 | QAction *act = d->createAppAction(*it, | ||
663 | // no submenu -> prefix single offer | 667 | // no submenu -> prefix single offer | ||
664 | menu == topMenu); | 668 | menu == topMenu); | ||
665 | menu->addAction(act); | 669 | menu->addAction(act); | ||
666 | } | 670 | } | ||
671 | topMenu->addSeparator(); | ||||
672 | } | ||||
667 | 673 | | |||
668 | QString openWithActionName; | 674 | QString openWithActionName; | ||
669 | if (menu != topMenu) { // submenu | 675 | if (menu != topMenu) { // submenu | ||
670 | menu->addSeparator(); | 676 | menu->addSeparator(); | ||
671 | openWithActionName = i18nc("@action:inmenu Open With", "&Other..."); | 677 | openWithActionName = i18nc("@action:inmenu Open With", "&Other..."); | ||
672 | } else { | 678 | } else { | ||
673 | openWithActionName = i18nc("@title:menu", "&Open With..."); | 679 | openWithActionName = i18nc("@title:menu", "&Open With..."); | ||
674 | } | 680 | } | ||
675 | QAction *openWithAct = new QAction(this); | 681 | QAction *openWithAct = new QAction(this); | ||
676 | openWithAct->setText(openWithActionName); | 682 | openWithAct->setText(openWithActionName); | ||
677 | openWithAct->setObjectName(QStringLiteral("openwith_browse")); // for the unittest | 683 | openWithAct->setObjectName(QStringLiteral("openwith_browse")); // for the unittest | ||
678 | QObject::connect(openWithAct, SIGNAL(triggered()), d, SLOT(slotOpenWithDialog())); | 684 | QObject::connect(openWithAct, SIGNAL(triggered()), d, SLOT(slotOpenWithDialog())); | ||
679 | menu->addAction(openWithAct); | 685 | menu->addAction(openWithAct); | ||
686 | menu->addSeparator(); | ||||
680 | } else { // no app offers -> Open With... | 687 | } else { // no app offers -> Open With... | ||
681 | QAction *act = new QAction(this); | 688 | QAction *act = new QAction(this); | ||
682 | act->setText(i18nc("@title:menu", "&Open With...")); | 689 | act->setText(i18nc("@title:menu", "&Open With...")); | ||
683 | act->setObjectName(QStringLiteral("openwith")); // for the unittest | 690 | act->setObjectName(QStringLiteral("openwith")); // for the unittest | ||
684 | QObject::connect(act, SIGNAL(triggered()), d, SLOT(slotOpenWithDialog())); | 691 | QObject::connect(act, SIGNAL(triggered()), d, SLOT(slotOpenWithDialog())); | ||
685 | topMenu->addAction(act); | 692 | topMenu->addAction(act); | ||
686 | } | 693 | } | ||
687 | 694 | | |||
▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines |
Use offers.takeFirst(), it will get and remove.