Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/projectview.cpp
Show All 17 Lines | |||||
18 | #include <QHeaderView> | 18 | #include <QHeaderView> | ||
19 | #include <QIcon> | 19 | #include <QIcon> | ||
20 | #include <KLocalizedString> | 20 | #include <KLocalizedString> | ||
21 | #include <QList> | 21 | #include <QList> | ||
22 | #include <QMenu> | 22 | #include <QMenu> | ||
23 | #include <QMimeData> | 23 | #include <QMimeData> | ||
24 | #include <QMimeDatabase> | 24 | #include <QMimeDatabase> | ||
25 | #include <QMimeType> | 25 | #include <QMimeType> | ||
26 | #include <QSignalMapper> | | |||
27 | #include <QUrl> | 26 | #include <QUrl> | ||
28 | 27 | | |||
29 | #include <KActionMenu> | 28 | #include <KActionMenu> | ||
30 | #include <KMimeTypeTrader> | 29 | #include <KMimeTypeTrader> | ||
31 | #include <KRun> | 30 | #include <KRun> | ||
32 | 31 | | |||
33 | #include "kileinfo.h" | 32 | #include "kileinfo.h" | ||
34 | #include "documentinfo.h" | 33 | #include "documentinfo.h" | ||
▲ Show 20 Lines • Show All 724 Lines • ▼ Show 20 Line(s) | 755 | if(open) { | |||
759 | item->setURL(projitem->url()); | 758 | item->setURL(projitem->url()); | ||
760 | makeTheConnection(item); | 759 | makeTheConnection(item); | ||
761 | } | 760 | } | ||
762 | 761 | | |||
763 | } | 762 | } | ||
764 | 763 | | |||
765 | void ProjectView::contextMenuEvent(QContextMenuEvent *event) | 764 | void ProjectView::contextMenuEvent(QContextMenuEvent *event) | ||
766 | { | 765 | { | ||
767 | QSignalMapper signalMapper, serviceSignalMapper; | | |||
768 | QMenu popup; | 766 | QMenu popup; | ||
769 | QAction *action = Q_NULLPTR; | 767 | QAction *action = Q_NULLPTR; | ||
770 | 768 | | |||
771 | QTreeWidgetItem* treeWidgetItem = itemAt(event->pos()); | 769 | QTreeWidgetItem* treeWidgetItem = itemAt(event->pos()); | ||
772 | if(!treeWidgetItem) { | 770 | if(!treeWidgetItem) { | ||
773 | return; | 771 | return; | ||
774 | } | 772 | } | ||
775 | 773 | | |||
Show All 10 Lines | |||||
786 | bool isKilePrFile = false; | 784 | bool isKilePrFile = false; | ||
787 | if(projectViewItem->type() != KileType::Project && projectViewItem->projectItem() | 785 | if(projectViewItem->type() != KileType::Project && projectViewItem->projectItem() | ||
788 | && projectViewItem->projectItem()->project()) { | 786 | && projectViewItem->projectItem()->project()) { | ||
789 | isKilePrFile = projectViewItem->projectItem()->project()->url() == projectViewItem->url(); | 787 | isKilePrFile = projectViewItem->projectItem()->project()->url() == projectViewItem->url(); | ||
790 | } | 788 | } | ||
791 | 789 | | |||
792 | if(projectViewItem->type() == KileType::ProjectExtra && !isKilePrFile) { | 790 | if(projectViewItem->type() == KileType::ProjectExtra && !isKilePrFile) { | ||
793 | QMenu *servicesMenu = popup.addMenu(QIcon::fromTheme("fork"), i18n("&Open With")); | 791 | QMenu *servicesMenu = popup.addMenu(QIcon::fromTheme("fork"), i18n("&Open With")); | ||
794 | connect(&serviceSignalMapper, SIGNAL(mapped(int)), this, SLOT(slotRun(int))); | | |||
795 | QMimeDatabase db; | 792 | QMimeDatabase db; | ||
796 | m_offerList = KMimeTypeTrader::self()->query(db.mimeTypeForUrl(projectViewItem->url()).name(), "Application"); | 793 | m_offerList = KMimeTypeTrader::self()->query(db.mimeTypeForUrl(projectViewItem->url()).name(), "Application"); | ||
797 | for (int i = 0; i < m_offerList.count(); ++i) { | 794 | for (int i = 0; i < m_offerList.count(); ++i) { | ||
798 | action = new QAction(servicesMenu); | 795 | action = new QAction(servicesMenu); | ||
799 | action->setIcon(QIcon::fromTheme(m_offerList[i]->icon())); | 796 | action->setIcon(QIcon::fromTheme(m_offerList[i]->icon())); | ||
800 | action->setText(m_offerList[i]->name()); | 797 | action->setText(m_offerList[i]->name()); | ||
801 | connect(action, SIGNAL(triggered()), &serviceSignalMapper, SLOT(map())); | 798 | connect(action, &QAction::triggered, this, [this, i] { slotRun(i + 1); }); | ||
802 | serviceSignalMapper.setMapping(action, i + 1); | | |||
803 | servicesMenu->addAction(action); | 799 | servicesMenu->addAction(action); | ||
804 | } | 800 | } | ||
805 | 801 | | |||
806 | servicesMenu->addSeparator(); | 802 | servicesMenu->addSeparator(); | ||
807 | action = servicesMenu->addAction(i18n("Other..."), &serviceSignalMapper, SLOT(map())); | 803 | servicesMenu->addAction(i18n("Other..."), this, [this] { slotRun(0); }); | ||
808 | serviceSignalMapper.setMapping(action, 0); | | |||
809 | insertsep = true; | 804 | insertsep = true; | ||
810 | } | 805 | } | ||
811 | 806 | | |||
812 | if (projectViewItem->type() == KileType::File || projectViewItem->type() == KileType::ProjectItem) { | 807 | if (projectViewItem->type() == KileType::File || projectViewItem->type() == KileType::ProjectItem) { | ||
813 | if(!m_ki->isOpen(projectViewItem->url())) { | 808 | if(!m_ki->isOpen(projectViewItem->url())) { | ||
814 | action = popup.addAction(QIcon::fromTheme("document-open"), i18n("&Open"), &signalMapper, SLOT(map())); | 809 | popup.addAction(QIcon::fromTheme("document-open"), i18n("&Open"), this, [this] { slotProjectItem(KPV_ID_OPEN); }); | ||
815 | signalMapper.setMapping(action, KPV_ID_OPEN); | | |||
816 | } | 810 | } | ||
817 | else { | 811 | else { | ||
818 | action = popup.addAction(QIcon::fromTheme("document-save"), i18n("&Save"), &signalMapper, SLOT(map())); | 812 | popup.addAction(QIcon::fromTheme("document-save"), i18n("&Save"), this, [this] { slotProjectItem(KPV_ID_SAVE); }); | ||
819 | signalMapper.setMapping(action, KPV_ID_SAVE); | | |||
820 | } | 813 | } | ||
821 | insertsep = true; | 814 | insertsep = true; | ||
822 | } | 815 | } | ||
823 | 816 | | |||
824 | if(projectViewItem->type() == KileType::File) { | 817 | if(projectViewItem->type() == KileType::File) { | ||
825 | if(m_nProjects > 0) { | 818 | if(m_nProjects > 0) { | ||
826 | if(insertsep) { | 819 | if(insertsep) { | ||
827 | popup.addSeparator(); | 820 | popup.addSeparator(); | ||
828 | } | 821 | } | ||
829 | action = popup.addAction(QIcon::fromTheme("project_add"), i18n("&Add to Project"), &signalMapper, SLOT(map())); | 822 | popup.addAction(QIcon::fromTheme("project_add"), i18n("&Add to Project"), this, [this] { slotProjectItem(KPV_ID_ADD); }); | ||
830 | signalMapper.setMapping(action, KPV_ID_ADD); | | |||
831 | insertsep = true; | 823 | insertsep = true; | ||
832 | } | 824 | } | ||
833 | connect(&signalMapper, SIGNAL(mapped(int)), this, SLOT(slotFile(int))); | | |||
834 | } | 825 | } | ||
835 | else if(projectViewItem->type() == KileType::ProjectItem || projectViewItem->type() == KileType::ProjectExtra) { | 826 | else if(projectViewItem->type() == KileType::ProjectItem || projectViewItem->type() == KileType::ProjectExtra) { | ||
836 | KileProjectItem *pi = projectViewItem->projectItem(); | 827 | KileProjectItem *pi = projectViewItem->projectItem(); | ||
837 | if(pi) { | 828 | if(pi) { | ||
838 | if(insertsep) { | 829 | if(insertsep) { | ||
839 | popup.addSeparator(); | 830 | popup.addSeparator(); | ||
840 | } | 831 | } | ||
841 | action = popup.addAction(i18n("&Include in Archive"), &signalMapper, SLOT(map())); | 832 | action = popup.addAction(i18n("&Include in Archive"), this, [this] { slotProjectItem(KPV_ID_INCLUDE); }); | ||
842 | signalMapper.setMapping(action, KPV_ID_INCLUDE); | | |||
843 | action->setCheckable(true); | 833 | action->setCheckable(true); | ||
844 | action->setChecked(pi->archive()); | 834 | action->setChecked(pi->archive()); | ||
845 | insertsep = true; | 835 | insertsep = true; | ||
846 | } | 836 | } | ||
847 | if(!isKilePrFile) { | 837 | if(!isKilePrFile) { | ||
848 | if(insertsep) { | 838 | if(insertsep) { | ||
849 | popup.addSeparator(); | 839 | popup.addSeparator(); | ||
850 | } | 840 | } | ||
851 | action = popup.addAction(QIcon::fromTheme("project_remove"),i18n("&Remove From Project"), &signalMapper, SLOT(map())); | 841 | popup.addAction(QIcon::fromTheme("project_remove"),i18n("&Remove From Project"), this, [this] { slotProjectItem(KPV_ID_REMOVE); }); | ||
852 | signalMapper.setMapping(action, KPV_ID_REMOVE); | | |||
853 | insertsep = true; | 842 | insertsep = true; | ||
854 | } | 843 | } | ||
855 | connect(&signalMapper, SIGNAL(mapped(int)), this, SLOT(slotProjectItem(int))); | | |||
856 | } | 844 | } | ||
857 | else if(projectViewItem->type() == KileType::Project) { | 845 | else if(projectViewItem->type() == KileType::Project) { | ||
858 | if(insertsep) { | 846 | if(insertsep) { | ||
859 | popup.addSeparator(); | 847 | popup.addSeparator(); | ||
860 | } | 848 | } | ||
861 | action = popup.addAction(i18n("A&dd Files..."), &signalMapper, SLOT(map())); | 849 | popup.addAction(i18n("A&dd Files..."), this, [this] { slotProject(KPV_ID_ADDFILES); }); | ||
862 | signalMapper.setMapping(action, KPV_ID_ADDFILES); | | |||
863 | popup.addSeparator(); | 850 | popup.addSeparator(); | ||
864 | action = popup.addAction(i18n("Open All &Project Files"), &signalMapper, SLOT(map())); | 851 | popup.addAction(i18n("Open All &Project Files"), this, [this] { slotProject(KPV_ID_OPENALLFILES); }); | ||
865 | signalMapper.setMapping(action, KPV_ID_OPENALLFILES); | | |||
866 | popup.addSeparator(); | 852 | popup.addSeparator(); | ||
867 | action = popup.addAction(QIcon::fromTheme("view-refresh"),i18n("Refresh Project &Tree"), &signalMapper, SLOT(map())); | 853 | popup.addAction(QIcon::fromTheme("view-refresh"),i18n("Refresh Project &Tree"), this, [this] { slotProject(KPV_ID_BUILDTREE); }); | ||
868 | signalMapper.setMapping(action, KPV_ID_BUILDTREE); | 854 | popup.addAction(QIcon::fromTheme("configure"), i18n("Project &Options"), this, [this] { slotProject(KPV_ID_OPTIONS); }); | ||
869 | action = popup.addAction(QIcon::fromTheme("configure"), i18n("Project &Options"), &signalMapper, SLOT(map())); | 855 | popup.addAction(i18n("&Archive"), this, [this] { slotProject(KPV_ID_ARCHIVE); }); | ||
870 | signalMapper.setMapping(action, KPV_ID_OPTIONS); | | |||
871 | action = popup.addAction(i18n("&Archive"), &signalMapper, SLOT(map())); | | |||
872 | signalMapper.setMapping(action, KPV_ID_ARCHIVE); | | |||
873 | connect(&signalMapper, SIGNAL(mapped(int)), this, SLOT(slotProject(int))); | | |||
874 | insertsep = true; | 856 | insertsep = true; | ||
875 | } | 857 | } | ||
876 | 858 | | |||
877 | if((projectViewItem->type() == KileType::File) || (projectViewItem->type() == KileType::ProjectItem) | 859 | if((projectViewItem->type() == KileType::File) || (projectViewItem->type() == KileType::ProjectItem) | ||
878 | || (projectViewItem->type()== KileType::Project)) { | 860 | || (projectViewItem->type()== KileType::Project)) { | ||
879 | if(insertsep) { | 861 | if(insertsep) { | ||
880 | popup.addSeparator(); | 862 | popup.addSeparator(); | ||
881 | } | 863 | } | ||
882 | action = popup.addAction(QIcon::fromTheme("view-close"), i18n("&Close"), &signalMapper, SLOT(map())); | 864 | if(projectViewItem->type() == KileType::Project) { | ||
883 | signalMapper.setMapping(action, KPV_ID_CLOSE); | 865 | popup.addAction(QIcon::fromTheme("view-close"), i18n("&Close"), this, [this] { slotProject(KPV_ID_CLOSE); }); | ||
866 | } | ||||
867 | else { | ||||
868 | popup.addAction(QIcon::fromTheme("view-close"), i18n("&Close"), this, [this] { slotProjectItem(KPV_ID_CLOSE); }); | ||||
869 | } | ||||
884 | } | 870 | } | ||
885 | 871 | | |||
886 | popup.exec(event->globalPos()); | 872 | popup.exec(event->globalPos()); | ||
887 | m_offerList.clear(); | 873 | m_offerList.clear(); | ||
888 | } | 874 | } | ||
889 | 875 | | |||
890 | void ProjectView::dragEnterEvent(QDragEnterEvent *event) | 876 | void ProjectView::dragEnterEvent(QDragEnterEvent *event) | ||
891 | { | 877 | { | ||
Show All 19 Lines |