From 4d96fa7aba7be35800d61d8bed89d3f6c3ef9329 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 13 Jan 2014 16:17:34 +0100 Subject: Core: Merge Find and Locator into Core plugin Change-Id: I7053310272235d854c9f409670ff52a10a7add8b Reviewed-by: Christian Kandeler Reviewed-by: Orgad Shaneh Reviewed-by: Eike Ziller --- src/plugins/bazaar/bazaar.qbs | 3 - src/plugins/bazaar/bazaar_dependencies.pri | 1 - src/plugins/bazaar/bazaarplugin.cpp | 5 +- src/plugins/bazaar/bazaarplugin.h | 7 +- src/plugins/bineditor/bineditor.qbs | 1 - src/plugins/bineditor/bineditor_dependencies.pri | 1 - src/plugins/bineditor/bineditorplugin.cpp | 39 +- src/plugins/bookmarks/bookmarks.qbs | 2 - src/plugins/clangcodemodel/clangsymbolsearcher.cpp | 4 +- src/plugins/clangcodemodel/clangsymbolsearcher.h | 2 +- src/plugins/clearcase/clearcase.qbs | 2 - src/plugins/clearcase/clearcase_dependencies.pri | 1 - src/plugins/clearcase/clearcaseplugin.cpp | 4 +- src/plugins/clearcase/clearcaseplugin.h | 4 +- .../cmakeprojectmanager/cmakelocatorfilter.cpp | 8 +- .../cmakeprojectmanager/cmakelocatorfilter.h | 8 +- .../cmakeprojectmanager/cmakeprojectmanager.qbs | 1 - .../cmakeprojectmanager_dependencies.pri | 1 - src/plugins/coreplugin/coreplugin.cpp | 14 + src/plugins/coreplugin/coreplugin.h | 6 + src/plugins/coreplugin/coreplugin.pro | 5 +- src/plugins/coreplugin/coreplugin.qbs | 87 +++ src/plugins/coreplugin/find/basetextfind.cpp | 427 +++++++++++ src/plugins/coreplugin/find/basetextfind.h | 91 +++ .../coreplugin/find/currentdocumentfind.cpp | 259 +++++++ src/plugins/coreplugin/find/currentdocumentfind.h | 93 +++ src/plugins/coreplugin/find/find.pri | 42 ++ src/plugins/coreplugin/find/find.qrc | 10 + src/plugins/coreplugin/find/finddialog.ui | 209 ++++++ src/plugins/coreplugin/find/findplugin.cpp | 394 +++++++++++ src/plugins/coreplugin/find/findplugin.h | 108 +++ src/plugins/coreplugin/find/findtoolbar.cpp | 779 +++++++++++++++++++++ src/plugins/coreplugin/find/findtoolbar.h | 149 ++++ src/plugins/coreplugin/find/findtoolwindow.cpp | 264 +++++++ src/plugins/coreplugin/find/findtoolwindow.h | 87 +++ src/plugins/coreplugin/find/findwidget.ui | 292 ++++++++ src/plugins/coreplugin/find/ifindfilter.cpp | 285 ++++++++ src/plugins/coreplugin/find/ifindfilter.h | 75 ++ src/plugins/coreplugin/find/ifindsupport.cpp | 121 ++++ src/plugins/coreplugin/find/ifindsupport.h | 80 +++ src/plugins/coreplugin/find/images/all.png | Bin 0 -> 108 bytes .../coreplugin/find/images/casesensitively.png | Bin 0 -> 153 bytes src/plugins/coreplugin/find/images/empty.png | Bin 0 -> 75 bytes src/plugins/coreplugin/find/images/expand.png | Bin 0 -> 931 bytes src/plugins/coreplugin/find/images/next.png | Bin 0 -> 109 bytes .../coreplugin/find/images/preservecase.png | Bin 0 -> 196 bytes src/plugins/coreplugin/find/images/previous.png | Bin 0 -> 103 bytes src/plugins/coreplugin/find/images/regexp.png | Bin 0 -> 152 bytes src/plugins/coreplugin/find/images/replace_all.png | Bin 0 -> 934 bytes src/plugins/coreplugin/find/images/wholewords.png | Bin 0 -> 146 bytes src/plugins/coreplugin/find/images/wordandcase.png | Bin 0 -> 198 bytes .../coreplugin/find/images/wrapindicator.png | Bin 0 -> 1949 bytes src/plugins/coreplugin/find/searchresultcolor.h | 20 + .../find/searchresulttreeitemdelegate.cpp | 224 ++++++ .../coreplugin/find/searchresulttreeitemdelegate.h | 55 ++ .../coreplugin/find/searchresulttreeitemroles.h | 56 ++ .../coreplugin/find/searchresulttreeitems.cpp | 145 ++++ .../coreplugin/find/searchresulttreeitems.h | 82 +++ .../coreplugin/find/searchresulttreemodel.cpp | 504 +++++++++++++ .../coreplugin/find/searchresulttreemodel.h | 99 +++ .../coreplugin/find/searchresulttreeview.cpp | 109 +++ src/plugins/coreplugin/find/searchresulttreeview.h | 73 ++ src/plugins/coreplugin/find/searchresultwidget.cpp | 495 +++++++++++++ src/plugins/coreplugin/find/searchresultwidget.h | 146 ++++ src/plugins/coreplugin/find/searchresultwindow.cpp | 715 +++++++++++++++++++ src/plugins/coreplugin/find/searchresultwindow.h | 198 ++++++ src/plugins/coreplugin/find/textfindconstants.h | 84 +++ src/plugins/coreplugin/find/treeviewfind.cpp | 277 ++++++++ src/plugins/coreplugin/find/treeviewfind.h | 75 ++ src/plugins/coreplugin/locator/basefilefilter.cpp | 126 ++++ src/plugins/coreplugin/locator/basefilefilter.h | 66 ++ src/plugins/coreplugin/locator/commandlocator.cpp | 109 +++ src/plugins/coreplugin/locator/commandlocator.h | 63 ++ src/plugins/coreplugin/locator/directoryfilter.cpp | 204 ++++++ src/plugins/coreplugin/locator/directoryfilter.h | 75 ++ src/plugins/coreplugin/locator/directoryfilter.ui | 195 ++++++ src/plugins/coreplugin/locator/executefilter.cpp | 188 +++++ src/plugins/coreplugin/locator/executefilter.h | 83 +++ .../coreplugin/locator/filesystemfilter.cpp | 187 +++++ src/plugins/coreplugin/locator/filesystemfilter.h | 67 ++ src/plugins/coreplugin/locator/filesystemfilter.ui | 111 +++ src/plugins/coreplugin/locator/ilocatorfilter.cpp | 208 ++++++ src/plugins/coreplugin/locator/ilocatorfilter.h | 167 +++++ src/plugins/coreplugin/locator/images/locator.png | Bin 0 -> 767 bytes src/plugins/coreplugin/locator/images/reload.png | Bin 0 -> 735 bytes src/plugins/coreplugin/locator/locator.pri | 46 ++ src/plugins/coreplugin/locator/locator.qrc | 6 + src/plugins/coreplugin/locator/locator_test.cpp | 173 +++++ src/plugins/coreplugin/locator/locatorconstants.h | 44 ++ .../coreplugin/locator/locatorfiltersfilter.cpp | 95 +++ .../coreplugin/locator/locatorfiltersfilter.h | 69 ++ .../coreplugin/locator/locatorfiltertest.cpp | 88 +++ src/plugins/coreplugin/locator/locatorfiltertest.h | 95 +++ src/plugins/coreplugin/locator/locatormanager.cpp | 58 ++ src/plugins/coreplugin/locator/locatormanager.h | 54 ++ src/plugins/coreplugin/locator/locatorplugin.cpp | 261 +++++++ src/plugins/coreplugin/locator/locatorplugin.h | 134 ++++ .../coreplugin/locator/locatorsearchutils.cpp | 65 ++ .../coreplugin/locator/locatorsearchutils.h | 46 ++ src/plugins/coreplugin/locator/locatorwidget.cpp | 590 ++++++++++++++++ src/plugins/coreplugin/locator/locatorwidget.h | 107 +++ .../coreplugin/locator/opendocumentsfilter.cpp | 114 +++ .../coreplugin/locator/opendocumentsfilter.h | 64 ++ src/plugins/coreplugin/locator/settingspage.cpp | 210 ++++++ src/plugins/coreplugin/locator/settingspage.h | 89 +++ src/plugins/coreplugin/locator/settingspage.ui | 121 ++++ .../coreplugin/progressmanager/progressmanager.cpp | 2 +- src/plugins/cppeditor/cppquickfixes.cpp | 6 +- src/plugins/cpptools/builtinindexingsupport.cpp | 12 +- src/plugins/cpptools/cppclassesfilter.cpp | 4 +- src/plugins/cpptools/cppclassesfilter.h | 2 +- src/plugins/cpptools/cppcurrentdocumentfilter.cpp | 10 +- src/plugins/cpptools/cppcurrentdocumentfilter.h | 8 +- src/plugins/cpptools/cppfindreferences.cpp | 52 +- src/plugins/cpptools/cppfindreferences.h | 14 +- src/plugins/cpptools/cppfunctionsfilter.cpp | 4 +- src/plugins/cpptools/cppfunctionsfilter.h | 2 +- src/plugins/cpptools/cppindexingsupport.h | 8 +- src/plugins/cpptools/cpplocatorfilter.cpp | 18 +- src/plugins/cpptools/cpplocatorfilter.h | 10 +- src/plugins/cpptools/cpplocatorfilter_test.cpp | 4 +- src/plugins/cpptools/cpptools.qbs | 2 - src/plugins/cpptools/cpptools_dependencies.pri | 4 +- src/plugins/cpptools/symbolsearcher_test.cpp | 6 +- src/plugins/cpptools/symbolsfindfilter.cpp | 52 +- src/plugins/cpptools/symbolsfindfilter.h | 18 +- src/plugins/cvs/cvs.qbs | 2 - src/plugins/cvs/cvs_dependencies.pri | 1 - src/plugins/cvs/cvsplugin.cpp | 4 +- src/plugins/cvs/cvsplugin.h | 4 +- src/plugins/debugger/basewindow.cpp | 4 +- src/plugins/debugger/debugger.qbs | 1 - src/plugins/debugger/debugger_dependencies.pri | 1 - src/plugins/debugger/logwindow.cpp | 6 +- src/plugins/diffeditor/diffeditor.qbs | 1 - src/plugins/fakevim/fakevim.qbs | 1 - src/plugins/fakevim/fakevim_dependencies.pri | 3 +- src/plugins/fakevim/fakevimplugin.cpp | 29 +- src/plugins/find/Find.pluginspec.in | 3 +- src/plugins/find/basetextfind.cpp | 427 ----------- src/plugins/find/basetextfind.h | 92 --- src/plugins/find/currentdocumentfind.cpp | 259 ------- src/plugins/find/currentdocumentfind.h | 93 --- src/plugins/find/find.pro | 37 +- src/plugins/find/find.qbs | 39 +- src/plugins/find/find.qrc | 10 - src/plugins/find/find_dependencies.pri | 6 +- src/plugins/find/find_global.h | 40 -- src/plugins/find/finddialog.ui | 209 ------ src/plugins/find/findplugin.cpp | 398 +---------- src/plugins/find/findplugin.h | 109 --- src/plugins/find/findtoolbar.cpp | 778 -------------------- src/plugins/find/findtoolbar.h | 151 ---- src/plugins/find/findtoolwindow.cpp | 264 ------- src/plugins/find/findtoolwindow.h | 87 --- src/plugins/find/findwidget.ui | 292 -------- src/plugins/find/ifindfilter.cpp | 285 -------- src/plugins/find/ifindfilter.h | 76 -- src/plugins/find/ifindsupport.cpp | 121 ---- src/plugins/find/ifindsupport.h | 81 --- src/plugins/find/images/all.png | Bin 108 -> 0 bytes src/plugins/find/images/casesensitively.png | Bin 153 -> 0 bytes src/plugins/find/images/empty.png | Bin 75 -> 0 bytes src/plugins/find/images/expand.png | Bin 931 -> 0 bytes src/plugins/find/images/next.png | Bin 109 -> 0 bytes src/plugins/find/images/preservecase.png | Bin 196 -> 0 bytes src/plugins/find/images/previous.png | Bin 103 -> 0 bytes src/plugins/find/images/regexp.png | Bin 152 -> 0 bytes src/plugins/find/images/replace_all.png | Bin 934 -> 0 bytes src/plugins/find/images/wholewords.png | Bin 146 -> 0 bytes src/plugins/find/images/wordandcase.png | Bin 198 -> 0 bytes src/plugins/find/images/wrapindicator.png | Bin 1949 -> 0 bytes src/plugins/find/searchresultcolor.h | 20 - src/plugins/find/searchresulttreeitemdelegate.cpp | 224 ------ src/plugins/find/searchresulttreeitemdelegate.h | 55 -- src/plugins/find/searchresulttreeitemroles.h | 56 -- src/plugins/find/searchresulttreeitems.cpp | 145 ---- src/plugins/find/searchresulttreeitems.h | 82 --- src/plugins/find/searchresulttreemodel.cpp | 504 ------------- src/plugins/find/searchresulttreemodel.h | 99 --- src/plugins/find/searchresulttreeview.cpp | 109 --- src/plugins/find/searchresulttreeview.h | 73 -- src/plugins/find/searchresultwidget.cpp | 494 ------------- src/plugins/find/searchresultwidget.h | 146 ---- src/plugins/find/searchresultwindow.cpp | 714 ------------------- src/plugins/find/searchresultwindow.h | 197 ------ src/plugins/find/textfindconstants.h | 84 --- src/plugins/find/treeviewfind.cpp | 277 -------- src/plugins/find/treeviewfind.h | 75 -- .../genericprojectmanager.qbs | 2 - src/plugins/git/gerrit/gerritplugin.cpp | 4 +- src/plugins/git/gerrit/gerritplugin.h | 5 +- src/plugins/git/git.qbs | 2 - src/plugins/git/git_dependencies.pri | 1 - src/plugins/git/gitplugin.cpp | 4 +- src/plugins/git/gitplugin.h | 6 +- src/plugins/help/centralwidget.cpp | 2 +- src/plugins/help/centralwidget.h | 4 +- src/plugins/help/help.qbs | 2 - src/plugins/help/help_dependencies.pri | 4 +- src/plugins/help/helpfindsupport.cpp | 33 +- src/plugins/help/helpfindsupport.h | 22 +- src/plugins/help/helpindexfilter.cpp | 10 +- src/plugins/help/helpindexfilter.h | 8 +- src/plugins/help/helpplugin.cpp | 6 +- src/plugins/help/helpviewer.h | 4 +- src/plugins/help/helpviewer_qtb.cpp | 7 +- src/plugins/help/helpviewer_qwv.cpp | 8 +- src/plugins/help/remotehelpfilter.cpp | 8 +- src/plugins/help/remotehelpfilter.h | 8 +- src/plugins/locator/Locator.pluginspec.in | 3 +- src/plugins/locator/basefilefilter.cpp | 126 ---- src/plugins/locator/basefilefilter.h | 67 -- src/plugins/locator/commandlocator.cpp | 109 --- src/plugins/locator/commandlocator.h | 65 -- src/plugins/locator/directoryfilter.cpp | 204 ------ src/plugins/locator/directoryfilter.h | 75 -- src/plugins/locator/directoryfilter.ui | 195 ------ src/plugins/locator/executefilter.cpp | 188 ----- src/plugins/locator/executefilter.h | 83 --- src/plugins/locator/filesystemfilter.cpp | 187 ----- src/plugins/locator/filesystemfilter.h | 67 -- src/plugins/locator/filesystemfilter.ui | 111 --- src/plugins/locator/ilocatorfilter.cpp | 208 ------ src/plugins/locator/ilocatorfilter.h | 169 ----- src/plugins/locator/images/locator.png | Bin 767 -> 0 bytes src/plugins/locator/images/reload.png | Bin 735 -> 0 bytes src/plugins/locator/locator.pro | 41 +- src/plugins/locator/locator.qbs | 51 +- src/plugins/locator/locator.qrc | 6 - src/plugins/locator/locator_dependencies.pri | 3 +- src/plugins/locator/locator_global.h | 41 -- src/plugins/locator/locator_test.cpp | 173 ----- src/plugins/locator/locatorconstants.h | 44 -- src/plugins/locator/locatorfiltersfilter.cpp | 95 --- src/plugins/locator/locatorfiltersfilter.h | 69 -- src/plugins/locator/locatorfiltertest.cpp | 88 --- src/plugins/locator/locatorfiltertest.h | 96 --- src/plugins/locator/locatormanager.cpp | 58 -- src/plugins/locator/locatormanager.h | 54 -- src/plugins/locator/locatorplugin.cpp | 268 +------ src/plugins/locator/locatorplugin.h | 138 ---- src/plugins/locator/locatorsearchutils.cpp | 65 -- src/plugins/locator/locatorsearchutils.h | 47 -- src/plugins/locator/locatorwidget.cpp | 594 ---------------- src/plugins/locator/locatorwidget.h | 107 --- src/plugins/locator/opendocumentsfilter.cpp | 114 --- src/plugins/locator/opendocumentsfilter.h | 64 -- src/plugins/locator/settingspage.cpp | 210 ------ src/plugins/locator/settingspage.h | 89 --- src/plugins/locator/settingspage.ui | 121 ---- src/plugins/macros/findmacrohandler.cpp | 47 +- src/plugins/macros/findmacrohandler.h | 12 +- src/plugins/macros/macrolocatorfilter.cpp | 12 +- src/plugins/macros/macrolocatorfilter.h | 8 +- src/plugins/macros/macros.qbs | 2 - src/plugins/macros/macros_dependencies.pri | 2 - src/plugins/macros/macrotextfind.cpp | 22 +- src/plugins/macros/macrotextfind.h | 32 +- src/plugins/mercurial/mercurial.qbs | 2 - src/plugins/mercurial/mercurial_dependencies.pri | 1 - src/plugins/mercurial/mercurialplugin.cpp | 4 +- src/plugins/mercurial/mercurialplugin.h | 4 +- src/plugins/perforce/perforce.qbs | 2 - src/plugins/perforce/perforce_dependencies.pri | 1 - src/plugins/perforce/perforceplugin.cpp | 4 +- src/plugins/perforce/perforceplugin.h | 4 +- src/plugins/projectexplorer/allprojectsfilter.cpp | 1 - src/plugins/projectexplorer/allprojectsfilter.h | 4 +- src/plugins/projectexplorer/allprojectsfind.cpp | 1 - src/plugins/projectexplorer/appoutputpane.cpp | 4 +- .../projectexplorer/compileoutputwindow.cpp | 4 +- .../projectexplorer/currentprojectfilter.cpp | 1 - src/plugins/projectexplorer/currentprojectfilter.h | 4 +- src/plugins/projectexplorer/currentprojectfind.cpp | 3 +- .../projectexplorer/foldernavigationwidget.cpp | 2 +- src/plugins/projectexplorer/projectexplorer.qbs | 2 - .../projectexplorer_dependencies.pri | 2 - src/plugins/qmljseditor/qmljseditor.qbs | 1 - .../qmljseditor/qmljseditor_dependencies.pri | 1 - src/plugins/qmljseditor/qmljsfindreferences.cpp | 26 +- src/plugins/qmljseditor/qmljsfindreferences.h | 10 +- src/plugins/qmljstools/qmlconsolepane.cpp | 4 +- src/plugins/qmljstools/qmljsfunctionfilter.cpp | 16 +- src/plugins/qmljstools/qmljsfunctionfilter.h | 8 +- src/plugins/qmljstools/qmljstools.qbs | 1 - src/plugins/qmljstools/qmljstools_dependencies.pri | 2 - src/plugins/resourceeditor/resourceeditor.qbs | 1 - .../resourceeditor/resourceeditor_dependencies.pri | 1 - src/plugins/resourceeditor/resourceeditorw.cpp | 4 +- src/plugins/subversion/subversion.qbs | 2 - src/plugins/subversion/subversion_dependencies.pri | 1 - src/plugins/subversion/subversionplugin.cpp | 4 +- src/plugins/subversion/subversionplugin.h | 7 +- src/plugins/tasklist/tasklist.qbs | 2 - src/plugins/texteditor/basefilefind.cpp | 67 +- src/plugins/texteditor/basefilefind.h | 32 +- src/plugins/texteditor/basefilefind_p.h | 4 +- src/plugins/texteditor/basetexteditor.cpp | 18 +- src/plugins/texteditor/basetexteditor.h | 4 +- src/plugins/texteditor/basetexteditor_p.h | 2 +- src/plugins/texteditor/findincurrentfile.cpp | 1 - src/plugins/texteditor/findinfiles.cpp | 8 +- src/plugins/texteditor/findinfiles.h | 2 +- src/plugins/texteditor/findinopenfiles.cpp | 1 - src/plugins/texteditor/linenumberfilter.cpp | 9 +- src/plugins/texteditor/linenumberfilter.h | 8 +- src/plugins/texteditor/texteditor.qbs | 7 - src/plugins/texteditor/texteditor_dependencies.pri | 2 - src/plugins/texteditor/texteditoractionhandler.cpp | 4 +- src/plugins/texteditor/texteditorplugin.cpp | 2 +- src/plugins/texteditor/texteditorplugin.h | 4 +- src/plugins/vcsbase/vcsbase.qbs | 1 - src/plugins/vcsbase/vcsbase_dependencies.pri | 1 - src/plugins/vcsbase/vcsbasesubmiteditor.cpp | 4 +- 315 files changed, 12076 insertions(+), 12238 deletions(-) create mode 100644 src/plugins/coreplugin/find/basetextfind.cpp create mode 100644 src/plugins/coreplugin/find/basetextfind.h create mode 100644 src/plugins/coreplugin/find/currentdocumentfind.cpp create mode 100644 src/plugins/coreplugin/find/currentdocumentfind.h create mode 100644 src/plugins/coreplugin/find/find.pri create mode 100644 src/plugins/coreplugin/find/find.qrc create mode 100644 src/plugins/coreplugin/find/finddialog.ui create mode 100644 src/plugins/coreplugin/find/findplugin.cpp create mode 100644 src/plugins/coreplugin/find/findplugin.h create mode 100644 src/plugins/coreplugin/find/findtoolbar.cpp create mode 100644 src/plugins/coreplugin/find/findtoolbar.h create mode 100644 src/plugins/coreplugin/find/findtoolwindow.cpp create mode 100644 src/plugins/coreplugin/find/findtoolwindow.h create mode 100644 src/plugins/coreplugin/find/findwidget.ui create mode 100644 src/plugins/coreplugin/find/ifindfilter.cpp create mode 100644 src/plugins/coreplugin/find/ifindfilter.h create mode 100644 src/plugins/coreplugin/find/ifindsupport.cpp create mode 100644 src/plugins/coreplugin/find/ifindsupport.h create mode 100644 src/plugins/coreplugin/find/images/all.png create mode 100644 src/plugins/coreplugin/find/images/casesensitively.png create mode 100644 src/plugins/coreplugin/find/images/empty.png create mode 100644 src/plugins/coreplugin/find/images/expand.png create mode 100644 src/plugins/coreplugin/find/images/next.png create mode 100644 src/plugins/coreplugin/find/images/preservecase.png create mode 100644 src/plugins/coreplugin/find/images/previous.png create mode 100644 src/plugins/coreplugin/find/images/regexp.png create mode 100644 src/plugins/coreplugin/find/images/replace_all.png create mode 100644 src/plugins/coreplugin/find/images/wholewords.png create mode 100644 src/plugins/coreplugin/find/images/wordandcase.png create mode 100644 src/plugins/coreplugin/find/images/wrapindicator.png create mode 100644 src/plugins/coreplugin/find/searchresultcolor.h create mode 100644 src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp create mode 100644 src/plugins/coreplugin/find/searchresulttreeitemdelegate.h create mode 100644 src/plugins/coreplugin/find/searchresulttreeitemroles.h create mode 100644 src/plugins/coreplugin/find/searchresulttreeitems.cpp create mode 100644 src/plugins/coreplugin/find/searchresulttreeitems.h create mode 100644 src/plugins/coreplugin/find/searchresulttreemodel.cpp create mode 100644 src/plugins/coreplugin/find/searchresulttreemodel.h create mode 100644 src/plugins/coreplugin/find/searchresulttreeview.cpp create mode 100644 src/plugins/coreplugin/find/searchresulttreeview.h create mode 100644 src/plugins/coreplugin/find/searchresultwidget.cpp create mode 100644 src/plugins/coreplugin/find/searchresultwidget.h create mode 100644 src/plugins/coreplugin/find/searchresultwindow.cpp create mode 100644 src/plugins/coreplugin/find/searchresultwindow.h create mode 100644 src/plugins/coreplugin/find/textfindconstants.h create mode 100644 src/plugins/coreplugin/find/treeviewfind.cpp create mode 100644 src/plugins/coreplugin/find/treeviewfind.h create mode 100644 src/plugins/coreplugin/locator/basefilefilter.cpp create mode 100644 src/plugins/coreplugin/locator/basefilefilter.h create mode 100644 src/plugins/coreplugin/locator/commandlocator.cpp create mode 100644 src/plugins/coreplugin/locator/commandlocator.h create mode 100644 src/plugins/coreplugin/locator/directoryfilter.cpp create mode 100644 src/plugins/coreplugin/locator/directoryfilter.h create mode 100644 src/plugins/coreplugin/locator/directoryfilter.ui create mode 100644 src/plugins/coreplugin/locator/executefilter.cpp create mode 100644 src/plugins/coreplugin/locator/executefilter.h create mode 100644 src/plugins/coreplugin/locator/filesystemfilter.cpp create mode 100644 src/plugins/coreplugin/locator/filesystemfilter.h create mode 100644 src/plugins/coreplugin/locator/filesystemfilter.ui create mode 100644 src/plugins/coreplugin/locator/ilocatorfilter.cpp create mode 100644 src/plugins/coreplugin/locator/ilocatorfilter.h create mode 100644 src/plugins/coreplugin/locator/images/locator.png create mode 100644 src/plugins/coreplugin/locator/images/reload.png create mode 100644 src/plugins/coreplugin/locator/locator.pri create mode 100644 src/plugins/coreplugin/locator/locator.qrc create mode 100644 src/plugins/coreplugin/locator/locator_test.cpp create mode 100644 src/plugins/coreplugin/locator/locatorconstants.h create mode 100644 src/plugins/coreplugin/locator/locatorfiltersfilter.cpp create mode 100644 src/plugins/coreplugin/locator/locatorfiltersfilter.h create mode 100644 src/plugins/coreplugin/locator/locatorfiltertest.cpp create mode 100644 src/plugins/coreplugin/locator/locatorfiltertest.h create mode 100644 src/plugins/coreplugin/locator/locatormanager.cpp create mode 100644 src/plugins/coreplugin/locator/locatormanager.h create mode 100644 src/plugins/coreplugin/locator/locatorplugin.cpp create mode 100644 src/plugins/coreplugin/locator/locatorplugin.h create mode 100644 src/plugins/coreplugin/locator/locatorsearchutils.cpp create mode 100644 src/plugins/coreplugin/locator/locatorsearchutils.h create mode 100644 src/plugins/coreplugin/locator/locatorwidget.cpp create mode 100644 src/plugins/coreplugin/locator/locatorwidget.h create mode 100644 src/plugins/coreplugin/locator/opendocumentsfilter.cpp create mode 100644 src/plugins/coreplugin/locator/opendocumentsfilter.h create mode 100644 src/plugins/coreplugin/locator/settingspage.cpp create mode 100644 src/plugins/coreplugin/locator/settingspage.h create mode 100644 src/plugins/coreplugin/locator/settingspage.ui delete mode 100644 src/plugins/find/basetextfind.cpp delete mode 100644 src/plugins/find/basetextfind.h delete mode 100644 src/plugins/find/currentdocumentfind.cpp delete mode 100644 src/plugins/find/currentdocumentfind.h delete mode 100644 src/plugins/find/find.qrc delete mode 100644 src/plugins/find/find_global.h delete mode 100644 src/plugins/find/finddialog.ui delete mode 100644 src/plugins/find/findplugin.h delete mode 100644 src/plugins/find/findtoolbar.cpp delete mode 100644 src/plugins/find/findtoolbar.h delete mode 100644 src/plugins/find/findtoolwindow.cpp delete mode 100644 src/plugins/find/findtoolwindow.h delete mode 100644 src/plugins/find/findwidget.ui delete mode 100644 src/plugins/find/ifindfilter.cpp delete mode 100644 src/plugins/find/ifindfilter.h delete mode 100644 src/plugins/find/ifindsupport.cpp delete mode 100644 src/plugins/find/ifindsupport.h delete mode 100644 src/plugins/find/images/all.png delete mode 100644 src/plugins/find/images/casesensitively.png delete mode 100644 src/plugins/find/images/empty.png delete mode 100644 src/plugins/find/images/expand.png delete mode 100644 src/plugins/find/images/next.png delete mode 100644 src/plugins/find/images/preservecase.png delete mode 100644 src/plugins/find/images/previous.png delete mode 100644 src/plugins/find/images/regexp.png delete mode 100644 src/plugins/find/images/replace_all.png delete mode 100644 src/plugins/find/images/wholewords.png delete mode 100644 src/plugins/find/images/wordandcase.png delete mode 100644 src/plugins/find/images/wrapindicator.png delete mode 100644 src/plugins/find/searchresultcolor.h delete mode 100644 src/plugins/find/searchresulttreeitemdelegate.cpp delete mode 100644 src/plugins/find/searchresulttreeitemdelegate.h delete mode 100644 src/plugins/find/searchresulttreeitemroles.h delete mode 100644 src/plugins/find/searchresulttreeitems.cpp delete mode 100644 src/plugins/find/searchresulttreeitems.h delete mode 100644 src/plugins/find/searchresulttreemodel.cpp delete mode 100644 src/plugins/find/searchresulttreemodel.h delete mode 100644 src/plugins/find/searchresulttreeview.cpp delete mode 100644 src/plugins/find/searchresulttreeview.h delete mode 100644 src/plugins/find/searchresultwidget.cpp delete mode 100644 src/plugins/find/searchresultwidget.h delete mode 100644 src/plugins/find/searchresultwindow.cpp delete mode 100644 src/plugins/find/searchresultwindow.h delete mode 100644 src/plugins/find/textfindconstants.h delete mode 100644 src/plugins/find/treeviewfind.cpp delete mode 100644 src/plugins/find/treeviewfind.h delete mode 100644 src/plugins/locator/basefilefilter.cpp delete mode 100644 src/plugins/locator/basefilefilter.h delete mode 100644 src/plugins/locator/commandlocator.cpp delete mode 100644 src/plugins/locator/commandlocator.h delete mode 100644 src/plugins/locator/directoryfilter.cpp delete mode 100644 src/plugins/locator/directoryfilter.h delete mode 100644 src/plugins/locator/directoryfilter.ui delete mode 100644 src/plugins/locator/executefilter.cpp delete mode 100644 src/plugins/locator/executefilter.h delete mode 100644 src/plugins/locator/filesystemfilter.cpp delete mode 100644 src/plugins/locator/filesystemfilter.h delete mode 100644 src/plugins/locator/filesystemfilter.ui delete mode 100644 src/plugins/locator/ilocatorfilter.cpp delete mode 100644 src/plugins/locator/ilocatorfilter.h delete mode 100644 src/plugins/locator/images/locator.png delete mode 100644 src/plugins/locator/images/reload.png delete mode 100644 src/plugins/locator/locator.qrc delete mode 100644 src/plugins/locator/locator_global.h delete mode 100644 src/plugins/locator/locator_test.cpp delete mode 100644 src/plugins/locator/locatorconstants.h delete mode 100644 src/plugins/locator/locatorfiltersfilter.cpp delete mode 100644 src/plugins/locator/locatorfiltersfilter.h delete mode 100644 src/plugins/locator/locatorfiltertest.cpp delete mode 100644 src/plugins/locator/locatorfiltertest.h delete mode 100644 src/plugins/locator/locatormanager.cpp delete mode 100644 src/plugins/locator/locatormanager.h delete mode 100644 src/plugins/locator/locatorplugin.h delete mode 100644 src/plugins/locator/locatorsearchutils.cpp delete mode 100644 src/plugins/locator/locatorsearchutils.h delete mode 100644 src/plugins/locator/locatorwidget.cpp delete mode 100644 src/plugins/locator/locatorwidget.h delete mode 100644 src/plugins/locator/opendocumentsfilter.cpp delete mode 100644 src/plugins/locator/opendocumentsfilter.h delete mode 100644 src/plugins/locator/settingspage.cpp delete mode 100644 src/plugins/locator/settingspage.h delete mode 100644 src/plugins/locator/settingspage.ui (limited to 'src') diff --git a/src/plugins/bazaar/bazaar.qbs b/src/plugins/bazaar/bazaar.qbs index 54cbc804f06..7ecf5b8b0ff 100644 --- a/src/plugins/bazaar/bazaar.qbs +++ b/src/plugins/bazaar/bazaar.qbs @@ -8,10 +8,7 @@ QtcPlugin { Depends { name: "Qt.widgets" } Depends { name: "Core" } Depends { name: "TextEditor" } - Depends { name: "Find" } Depends { name: "VcsBase" } - Depends { name: "Locator" } - files: [ "annotationhighlighter.cpp", diff --git a/src/plugins/bazaar/bazaar_dependencies.pri b/src/plugins/bazaar/bazaar_dependencies.pri index a7c268a0d78..1009c58f690 100644 --- a/src/plugins/bazaar/bazaar_dependencies.pri +++ b/src/plugins/bazaar/bazaar_dependencies.pri @@ -2,7 +2,6 @@ QTC_PLUGIN_NAME = Bazaar QTC_LIB_DEPENDS += \ utils QTC_PLUGIN_DEPENDS += \ - locator \ texteditor \ coreplugin \ vcsbase diff --git a/src/plugins/bazaar/bazaarplugin.cpp b/src/plugins/bazaar/bazaarplugin.cpp index cf79874a2fc..9479fb74969 100644 --- a/src/plugins/bazaar/bazaarplugin.cpp +++ b/src/plugins/bazaar/bazaarplugin.cpp @@ -48,8 +48,7 @@ #include #include #include - -#include +#include #include #include @@ -149,7 +148,7 @@ bool BazaarPlugin::initialize(const QStringList &arguments, QString *errorMessag addAutoReleasedObject(new CloneWizard); const QString prefix = QLatin1String("bzr"); - m_commandLocator = new Locator::CommandLocator("Bazaar", prefix, prefix); + m_commandLocator = new Core::CommandLocator("Bazaar", prefix, prefix); addAutoReleasedObject(m_commandLocator); createMenu(); diff --git a/src/plugins/bazaar/bazaarplugin.h b/src/plugins/bazaar/bazaarplugin.h index 382ea438e4d..7a2ee3c1814 100644 --- a/src/plugins/bazaar/bazaarplugin.h +++ b/src/plugins/bazaar/bazaarplugin.h @@ -42,6 +42,7 @@ QT_END_NAMESPACE namespace Core { class ActionManager; class ActionContainer; +class CommandLocator; class Id; class IVersionControl; class IEditorFactory; @@ -56,10 +57,6 @@ namespace VcsBase { class VcsBaseSubmitEditor; } -namespace Locator { -class CommandLocator; -} - namespace Bazaar { namespace Internal { @@ -132,7 +129,7 @@ private: OptionsPage *m_optionsPage; BazaarClient *m_client; - Locator::CommandLocator *m_commandLocator; + Core::CommandLocator *m_commandLocator; Core::ActionContainer *m_bazaarContainer; QList m_repositoryActionList; diff --git a/src/plugins/bineditor/bineditor.qbs b/src/plugins/bineditor/bineditor.qbs index f18676ea80e..a63bcc183fb 100644 --- a/src/plugins/bineditor/bineditor.qbs +++ b/src/plugins/bineditor/bineditor.qbs @@ -8,7 +8,6 @@ QtcPlugin { Depends { name: "Qt.widgets" } Depends { name: "Core" } Depends { name: "TextEditor" } - Depends { name: "Find" } files: [ "bineditor.cpp", diff --git a/src/plugins/bineditor/bineditor_dependencies.pri b/src/plugins/bineditor/bineditor_dependencies.pri index cbc6861ca1f..825c980e927 100644 --- a/src/plugins/bineditor/bineditor_dependencies.pri +++ b/src/plugins/bineditor/bineditor_dependencies.pri @@ -2,6 +2,5 @@ QTC_PLUGIN_NAME = BinEditor QTC_LIB_DEPENDS += \ utils QTC_PLUGIN_DEPENDS += \ - find \ texteditor \ coreplugin diff --git a/src/plugins/bineditor/bineditorplugin.cpp b/src/plugins/bineditor/bineditorplugin.cpp index f2f57d47fab..62a233706ee 100644 --- a/src/plugins/bineditor/bineditorplugin.cpp +++ b/src/plugins/bineditor/bineditorplugin.cpp @@ -53,18 +53,19 @@ #include #include #include +#include #include #include #include -#include #include #include +using namespace Core; using namespace BINEditor; using namespace BINEditor::Internal; -class BinEditorFind : public Find::IFindSupport +class BinEditorFind : public Core::IFindSupport { Q_OBJECT @@ -80,9 +81,9 @@ public: QString currentFindString() const { return QString(); } QString completedFindString() const { return QString(); } - Find::FindFlags supportedFindFlags() const + Core::FindFlags supportedFindFlags() const { - return Find::FindBackward | Find::FindCaseSensitively; + return FindBackward | FindCaseSensitively; } void resetIncrementalSearch() @@ -91,9 +92,9 @@ public: m_incrementalWrappedState = false; } - virtual void highlightAll(const QString &txt, Find::FindFlags findFlags) + virtual void highlightAll(const QString &txt, Core::FindFlags findFlags) { - m_widget->highlightSearchResults(txt.toLatin1(), Find::textDocumentFlagsForFindFlags(findFlags)); + m_widget->highlightSearchResults(txt.toLatin1(), textDocumentFlagsForFindFlags(findFlags)); } void clearResults() @@ -101,7 +102,7 @@ public: m_widget->highlightSearchResults(QByteArray()); } - int find(const QByteArray &pattern, int pos, Find::FindFlags findFlags, bool *wrapped) + int find(const QByteArray &pattern, int pos, Core::FindFlags findFlags, bool *wrapped) { if (wrapped) *wrapped = false; @@ -110,10 +111,10 @@ public: return pos; } - int res = m_widget->find(pattern, pos, Find::textDocumentFlagsForFindFlags(findFlags)); + int res = m_widget->find(pattern, pos, textDocumentFlagsForFindFlags(findFlags)); if (res < 0) { - pos = (findFlags & Find::FindBackward) ? -1 : 0; - res = m_widget->find(pattern, pos, Find::textDocumentFlagsForFindFlags(findFlags)); + pos = (findFlags & FindBackward) ? -1 : 0; + res = m_widget->find(pattern, pos, textDocumentFlagsForFindFlags(findFlags)); if (res < 0) return res; if (wrapped) @@ -122,7 +123,7 @@ public: return res; } - Result findIncremental(const QString &txt, Find::FindFlags findFlags) { + Result findIncremental(const QString &txt, Core::FindFlags findFlags) { QByteArray pattern = txt.toLatin1(); if (pattern != m_lastPattern) resetIncrementalSearch(); // Because we don't search for nibbles. @@ -140,13 +141,13 @@ public: Result result; if (found >= 0) { result = Found; - m_widget->highlightSearchResults(pattern, Find::textDocumentFlagsForFindFlags(findFlags)); + m_widget->highlightSearchResults(pattern, textDocumentFlagsForFindFlags(findFlags)); m_contPos = -1; } else { if (found == -2) { result = NotYetFound; m_contPos += - findFlags & Find::FindBackward + findFlags & FindBackward ? -BinEditorWidget::SearchStride : BinEditorWidget::SearchStride; } else { result = NotFound; @@ -157,12 +158,12 @@ public: return result; } - Result findStep(const QString &txt, Find::FindFlags findFlags) { + Result findStep(const QString &txt, Core::FindFlags findFlags) { QByteArray pattern = txt.toLatin1(); bool wasReset = (m_incrementalStartPos < 0); if (m_contPos == -1) { m_contPos = m_widget->cursorPosition(); - if (findFlags & Find::FindBackward) + if (findFlags & FindBackward) m_contPos = m_widget->selectionStart()-1; } bool wrapped; @@ -175,10 +176,10 @@ public: m_incrementalStartPos = found; m_contPos = -1; if (wasReset) - m_widget->highlightSearchResults(pattern, Find::textDocumentFlagsForFindFlags(findFlags)); + m_widget->highlightSearchResults(pattern, textDocumentFlagsForFindFlags(findFlags)); } else if (found == -2) { result = NotYetFound; - m_contPos += findFlags & Find::FindBackward + m_contPos += findFlags & FindBackward ? -BinEditorWidget::SearchStride : BinEditorWidget::SearchStride; } else { result = NotFound; @@ -213,7 +214,7 @@ public: ~BinEditorDocument() {} QString mimeType() const { - return QLatin1String(Constants::C_BINEDITOR_MIMETYPE); + return QLatin1String(BINEditor::Constants::C_BINEDITOR_MIMETYPE); } bool setContents(const QByteArray &contents) @@ -340,7 +341,7 @@ public: m_widget = widget; m_file = new BinEditorDocument(m_widget); m_context.add(Core::Constants::K_DEFAULT_BINARY_EDITOR_ID); - m_context.add(Constants::C_BINEDITOR); + m_context.add(BINEditor::Constants::C_BINEDITOR); m_addressEdit = new QLineEdit; QRegExpValidator * const addressValidator = new QRegExpValidator(QRegExp(QLatin1String("[0-9a-fA-F]{1,16}")), diff --git a/src/plugins/bookmarks/bookmarks.qbs b/src/plugins/bookmarks/bookmarks.qbs index 4264356767f..b92b06d0724 100644 --- a/src/plugins/bookmarks/bookmarks.qbs +++ b/src/plugins/bookmarks/bookmarks.qbs @@ -9,8 +9,6 @@ QtcPlugin { Depends { name: "Core" } Depends { name: "ProjectExplorer" } Depends { name: "TextEditor" } - Depends { name: "Find" } - Depends { name: "Locator" } files: [ "bookmark.cpp", diff --git a/src/plugins/clangcodemodel/clangsymbolsearcher.cpp b/src/plugins/clangcodemodel/clangsymbolsearcher.cpp index 5032439b889..d603a745f2e 100644 --- a/src/plugins/clangcodemodel/clangsymbolsearcher.cpp +++ b/src/plugins/clangcodemodel/clangsymbolsearcher.cpp @@ -68,7 +68,7 @@ void ClangSymbolSearcher::search(const QLinkedList &allSymbols) ? Qt::CaseSensitive : Qt::CaseInsensitive)); const int chunkSize = 10; - QVector resultItems; + QVector resultItems; resultItems.reserve(100); m_future->setProgressRange(0, allSymbols.size() % chunkSize); @@ -138,7 +138,7 @@ void ClangSymbolSearcher::search(const QLinkedList &allSymbols) info.line = s.m_location.line(); info.column = s.m_location.column() - 1; - Find::SearchResultItem item; + Core::SearchResultItem item; item.path << s.m_qualification; item.text = s.m_name; item.icon = info.icon; diff --git a/src/plugins/clangcodemodel/clangsymbolsearcher.h b/src/plugins/clangcodemodel/clangsymbolsearcher.h index d316133bb9c..ff59e211c43 100644 --- a/src/plugins/clangcodemodel/clangsymbolsearcher.h +++ b/src/plugins/clangcodemodel/clangsymbolsearcher.h @@ -47,7 +47,7 @@ class ClangSymbolSearcher: public CppTools::SymbolSearcher Q_OBJECT typedef CppTools::SymbolSearcher::Parameters Parameters; - typedef Find::SearchResultItem SearchResultItem; + typedef Core::SearchResultItem SearchResultItem; public: ClangSymbolSearcher(ClangIndexer *indexer, const Parameters ¶meters, QSet fileNames, QObject *parent = 0); diff --git a/src/plugins/clearcase/clearcase.qbs b/src/plugins/clearcase/clearcase.qbs index 72edcc26b88..8389ef56737 100644 --- a/src/plugins/clearcase/clearcase.qbs +++ b/src/plugins/clearcase/clearcase.qbs @@ -12,9 +12,7 @@ QtcPlugin { Depends { name: "Core" } Depends { name: "TextEditor" } Depends { name: "ProjectExplorer" } - Depends { name: "Find" } Depends { name: "VcsBase" } - Depends { name: "Locator" } files: [ "activityselector.cpp", diff --git a/src/plugins/clearcase/clearcase_dependencies.pri b/src/plugins/clearcase/clearcase_dependencies.pri index 3b39e2730eb..52d7309af5c 100644 --- a/src/plugins/clearcase/clearcase_dependencies.pri +++ b/src/plugins/clearcase/clearcase_dependencies.pri @@ -2,7 +2,6 @@ QTC_PLUGIN_NAME = ClearCase QTC_LIB_DEPENDS += \ utils QTC_PLUGIN_DEPENDS += \ - locator \ projectexplorer \ texteditor \ coreplugin \ diff --git a/src/plugins/clearcase/clearcaseplugin.cpp b/src/plugins/clearcase/clearcaseplugin.cpp index a625609e152..43ba106d254 100644 --- a/src/plugins/clearcase/clearcaseplugin.cpp +++ b/src/plugins/clearcase/clearcaseplugin.cpp @@ -52,7 +52,7 @@ #include #include #include -#include +#include #include #include #include @@ -471,7 +471,7 @@ bool ClearCasePlugin::initialize(const QStringList & /*arguments */, QString *er const QString description = QLatin1String("ClearCase"); const QString prefix = QLatin1String("cc"); // register cc prefix in Locator - m_commandLocator = new Locator::CommandLocator("cc", description, prefix); + m_commandLocator = new Core::CommandLocator("cc", description, prefix); addAutoReleasedObject(m_commandLocator); //register actions diff --git a/src/plugins/clearcase/clearcaseplugin.h b/src/plugins/clearcase/clearcaseplugin.h index 3dcd4be5eaf..2b47de944f2 100644 --- a/src/plugins/clearcase/clearcaseplugin.h +++ b/src/plugins/clearcase/clearcaseplugin.h @@ -54,13 +54,13 @@ class QTextCodec; QT_END_NAMESPACE namespace Core { +class CommandLocator; class IVersionControl; class IEditor; } // namespace Core namespace Utils { class ParameterAction; } namespace VcsBase { class VcsBaseSubmitEditor; } -namespace Locator { class CommandLocator; } namespace ProjectExplorer { class Project; } namespace ClearCase { @@ -277,7 +277,7 @@ private: QString m_activity; QString m_diffPrefix; - Locator::CommandLocator *m_commandLocator; + Core::CommandLocator *m_commandLocator; Utils::ParameterAction *m_checkOutAction; Utils::ParameterAction *m_checkInCurrentAction; Utils::ParameterAction *m_undoCheckOutAction; diff --git a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp index 39ac8bc91dd..6e498b317c7 100644 --- a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp @@ -64,17 +64,17 @@ CMakeLocatorFilter::~CMakeLocatorFilter() } -QList CMakeLocatorFilter::matchesFor(QFutureInterface &future, const QString &entry) +QList CMakeLocatorFilter::matchesFor(QFutureInterface &future, const QString &entry) { Q_UNUSED(future) - QList result; + QList result; foreach (Project *p, SessionManager::projects()) { CMakeProject *cmakeProject = qobject_cast(p); if (cmakeProject) { foreach (const CMakeBuildTarget &ct, cmakeProject->buildTargets()) { if (ct.title.contains(entry)) { - Locator::FilterEntry entry(this, ct.title, cmakeProject->projectFilePath()); + Core::LocatorFilterEntry entry(this, ct.title, cmakeProject->projectFilePath()); entry.extraInfo = FileUtils::shortNativePath( FileName::fromString(cmakeProject->projectFilePath())); result.append(entry); @@ -86,7 +86,7 @@ QList CMakeLocatorFilter::matchesFor(QFutureInterface +#include #include namespace CMakeProjectManager { namespace Internal { -class CMakeLocatorFilter : public Locator::ILocatorFilter +class CMakeLocatorFilter : public Core::ILocatorFilter { Q_OBJECT @@ -45,8 +45,8 @@ public: CMakeLocatorFilter(); ~CMakeLocatorFilter(); - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(Locator::FilterEntry selection) const; + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(Core::LocatorFilterEntry selection) const; void refresh(QFutureInterface &future); private slots: diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs index 42eafccae7a..9232f5d60af 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.qbs @@ -9,7 +9,6 @@ QtcPlugin { Depends { name: "Core" } Depends { name: "CppTools" } Depends { name: "CPlusPlus" } - Depends { name: "Locator" } Depends { name: "ProjectExplorer" } Depends { name: "TextEditor" } Depends { name: "QtSupport" } diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager_dependencies.pri b/src/plugins/cmakeprojectmanager/cmakeprojectmanager_dependencies.pri index 7ae1e8c822c..25940e72600 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager_dependencies.pri +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager_dependencies.pri @@ -1,7 +1,6 @@ QTC_PLUGIN_NAME = CMakeProjectManager QTC_PLUGIN_DEPENDS += \ coreplugin \ - locator \ projectexplorer \ cpptools \ texteditor \ diff --git a/src/plugins/coreplugin/coreplugin.cpp b/src/plugins/coreplugin/coreplugin.cpp index c6869dd1756..e16a4e7f96a 100644 --- a/src/plugins/coreplugin/coreplugin.cpp +++ b/src/plugins/coreplugin/coreplugin.cpp @@ -35,8 +35,11 @@ #include "mimedatabase.h" #include "modemanager.h" #include "infobar.h" + #include #include +#include +#include #include @@ -51,10 +54,15 @@ CorePlugin::CorePlugin() : m_editMode(0), m_designMode(0) { qRegisterMetaType(); m_mainWindow = new MainWindow; + m_findPlugin = new FindPlugin; + m_locatorPlugin = new LocatorPlugin; } CorePlugin::~CorePlugin() { + delete m_findPlugin; + delete m_locatorPlugin; + if (m_editMode) { removeObject(m_editMode); delete m_editMode; @@ -98,6 +106,9 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage) // Make sure we respect the process's umask when creating new files Utils::SaveFile::initializeUmask(); + m_findPlugin->initialize(arguments, errorMessage); + m_locatorPlugin->initialize(this, arguments, errorMessage); + return success; } @@ -107,11 +118,14 @@ void CorePlugin::extensionsInitialized() if (m_designMode->designModeIsRequired()) addObject(m_designMode); m_mainWindow->extensionsInitialized(); + m_findPlugin->extensionsInitialized(); + m_locatorPlugin->extensionsInitialized(); } bool CorePlugin::delayedInitialize() { HelpManager::setupHelpManager(); + m_locatorPlugin->delayedInitialize(); return true; } diff --git a/src/plugins/coreplugin/coreplugin.h b/src/plugins/coreplugin/coreplugin.h index 9855c39ebaf..fd6d1ad6624 100644 --- a/src/plugins/coreplugin/coreplugin.h +++ b/src/plugins/coreplugin/coreplugin.h @@ -33,11 +33,15 @@ #include namespace Core { + class DesignMode; +class FindPlugin; + namespace Internal { class EditMode; class MainWindow; +class LocatorPlugin; class CorePlugin : public ExtensionSystem::IPlugin { @@ -69,6 +73,8 @@ private: MainWindow *m_mainWindow; EditMode *m_editMode; DesignMode *m_designMode; + FindPlugin *m_findPlugin; + LocatorPlugin *m_locatorPlugin; }; } // namespace Internal diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index 10b4087a432..3b68f06f263 100644 --- a/src/plugins/coreplugin/coreplugin.pro +++ b/src/plugins/coreplugin/coreplugin.pro @@ -206,11 +206,14 @@ FORMS += dialogs/newdialog.ui \ mimetypesettingspage.ui \ mimetypemagicdialog.ui \ removefiledialog.ui \ - dialogs/addtovcsdialog.ui + dialogs/addtovcsdialog.ui RESOURCES += core.qrc \ fancyactionbar.qrc +include(find/find.pri) +include(locator/locator.pri) + win32 { SOURCES += progressmanager/progressmanager_win.cpp greaterThan(QT_MAJOR_VERSION, 4): QT += gui-private # Uses QPlatformNativeInterface. diff --git a/src/plugins/coreplugin/coreplugin.qbs b/src/plugins/coreplugin/coreplugin.qbs index b7b6c93b38e..a18785cdd3a 100644 --- a/src/plugins/coreplugin/coreplugin.qbs +++ b/src/plugins/coreplugin/coreplugin.qbs @@ -1,4 +1,5 @@ import qbs.base 1.0 +import qbs.FileInfo import QtcPlugin QtcPlugin { @@ -183,6 +184,92 @@ QtcPlugin { files: [ "testdatadir.cpp", "testdatadir.h", + "locator/locatorfiltertest.cpp", + "locator/locatorfiltertest.h", + "locator/locator_test.cpp" + ] + + cpp.defines: outer.concat(['SRCDIR="' + FileInfo.path(filePath) + '"']) + } + + Group { + name: "Find" + prefix: "find/" + files: [ + "basetextfind.cpp", + "basetextfind.h", + "currentdocumentfind.cpp", + "currentdocumentfind.h", + "find.qrc", + "finddialog.ui", + "findplugin.cpp", + "findplugin.h", + "findtoolbar.cpp", + "findtoolbar.h", + "findtoolwindow.cpp", + "findtoolwindow.h", + "findwidget.ui", + "ifindfilter.cpp", + "ifindfilter.h", + "ifindsupport.cpp", + "ifindsupport.h", + "searchresultcolor.h", + "searchresulttreeitemdelegate.cpp", + "searchresulttreeitemdelegate.h", + "searchresulttreeitemroles.h", + "searchresulttreeitems.cpp", + "searchresulttreeitems.h", + "searchresulttreemodel.cpp", + "searchresulttreemodel.h", + "searchresulttreeview.cpp", + "searchresulttreeview.h", + "searchresultwidget.cpp", + "searchresultwidget.h", + "searchresultwindow.cpp", + "searchresultwindow.h", + "textfindconstants.h", + "treeviewfind.cpp", + "treeviewfind.h", + ] + } + + Group { + name: "Locator" + prefix: "locator/" + files: [ + "basefilefilter.cpp", + "basefilefilter.h", + "commandlocator.cpp", + "commandlocator.h", + "directoryfilter.cpp", + "directoryfilter.h", + "directoryfilter.ui", + "executefilter.cpp", + "executefilter.h", + "filesystemfilter.cpp", + "filesystemfilter.h", + "filesystemfilter.ui", + "ilocatorfilter.cpp", + "ilocatorfilter.h", + "locator.qrc", + "locatorconstants.h", + "locatorfiltersfilter.cpp", + "locatorfiltersfilter.h", + "locatormanager.cpp", + "locatormanager.h", + "locatorplugin.cpp", + "locatorplugin.h", + "locatorsearchutils.cpp", + "locatorsearchutils.h", + "locatorwidget.cpp", + "locatorwidget.h", + "opendocumentsfilter.cpp", + "opendocumentsfilter.h", + "settingspage.cpp", + "settingspage.h", + "settingspage.ui", + "images/locator.png", + "images/reload.png", ] } diff --git a/src/plugins/coreplugin/find/basetextfind.cpp b/src/plugins/coreplugin/find/basetextfind.cpp new file mode 100644 index 00000000000..70fdef51bd5 --- /dev/null +++ b/src/plugins/coreplugin/find/basetextfind.cpp @@ -0,0 +1,427 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "basetextfind.h" + +#include +#include + +#include + +#include +#include +#include + +namespace Core { + +struct BaseTextFindPrivate +{ + explicit BaseTextFindPrivate(QPlainTextEdit *editor); + explicit BaseTextFindPrivate(QTextEdit *editor); + + QPointer m_editor; + QPointer m_plaineditor; + QPointer m_widget; + QTextCursor m_findScopeStart; + QTextCursor m_findScopeEnd; + int m_findScopeVerticalBlockSelectionFirstColumn; + int m_findScopeVerticalBlockSelectionLastColumn; + int m_incrementalStartPos; + bool m_incrementalWrappedState; +}; + +BaseTextFindPrivate::BaseTextFindPrivate(QTextEdit *editor) + : m_editor(editor) + , m_widget(editor) + , m_findScopeVerticalBlockSelectionFirstColumn(-1) + , m_findScopeVerticalBlockSelectionLastColumn(-1) + , m_incrementalStartPos(-1) + , m_incrementalWrappedState(false) +{ +} + +BaseTextFindPrivate::BaseTextFindPrivate(QPlainTextEdit *editor) + : m_plaineditor(editor) + , m_widget(editor) + , m_findScopeVerticalBlockSelectionFirstColumn(-1) + , m_findScopeVerticalBlockSelectionLastColumn(-1) + , m_incrementalStartPos(-1) + , m_incrementalWrappedState(false) +{ +} + +BaseTextFind::BaseTextFind(QTextEdit *editor) + : d(new BaseTextFindPrivate(editor)) +{ +} + + +BaseTextFind::BaseTextFind(QPlainTextEdit *editor) + : d(new BaseTextFindPrivate(editor)) +{ +} + +BaseTextFind::~BaseTextFind() +{ + delete d; +} + +QTextCursor BaseTextFind::textCursor() const +{ + QTC_ASSERT(d->m_editor || d->m_plaineditor, return QTextCursor()); + return d->m_editor ? d->m_editor->textCursor() : d->m_plaineditor->textCursor(); +} + +void BaseTextFind::setTextCursor(const QTextCursor &cursor) +{ + QTC_ASSERT(d->m_editor || d->m_plaineditor, return); + d->m_editor ? d->m_editor->setTextCursor(cursor) : d->m_plaineditor->setTextCursor(cursor); +} + +QTextDocument *BaseTextFind::document() const +{ + QTC_ASSERT(d->m_editor || d->m_plaineditor, return 0); + return d->m_editor ? d->m_editor->document() : d->m_plaineditor->document(); +} + +bool BaseTextFind::isReadOnly() const +{ + QTC_ASSERT(d->m_editor || d->m_plaineditor, return true); + return d->m_editor ? d->m_editor->isReadOnly() : d->m_plaineditor->isReadOnly(); +} + +bool BaseTextFind::supportsReplace() const +{ + return !isReadOnly(); +} + +FindFlags BaseTextFind::supportedFindFlags() const +{ + return FindBackward | FindCaseSensitively | FindRegularExpression + | FindWholeWords | FindPreserveCase; +} + +void BaseTextFind::resetIncrementalSearch() +{ + d->m_incrementalStartPos = -1; + d->m_incrementalWrappedState = false; +} + +void BaseTextFind::clearResults() +{ + emit highlightAll(QString(), 0); +} + +QString BaseTextFind::currentFindString() const +{ + QTextCursor cursor = textCursor(); + if (cursor.hasSelection() && cursor.block() != cursor.document()->findBlock(cursor.anchor())) + return QString(); // multi block selection + + if (cursor.hasSelection()) + return cursor.selectedText(); + + if (!cursor.atBlockEnd() && !cursor.hasSelection()) { + cursor.movePosition(QTextCursor::StartOfWord); + cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); + QString s = cursor.selectedText(); + foreach (QChar c, s) { + if (!c.isLetterOrNumber() && c != QLatin1Char('_')) { + s.clear(); + break; + } + } + return s; + } + + return QString(); +} + +QString BaseTextFind::completedFindString() const +{ + QTextCursor cursor = textCursor(); + cursor.setPosition(textCursor().selectionStart()); + cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); + return cursor.selectedText(); +} + +IFindSupport::Result BaseTextFind::findIncremental(const QString &txt, FindFlags findFlags) +{ + QTextCursor cursor = textCursor(); + if (d->m_incrementalStartPos < 0) + d->m_incrementalStartPos = cursor.selectionStart(); + cursor.setPosition(d->m_incrementalStartPos); + bool wrapped = false; + bool found = find(txt, findFlags, cursor, &wrapped); + if (wrapped != d->m_incrementalWrappedState && found) { + d->m_incrementalWrappedState = wrapped; + showWrapIndicator(d->m_widget); + } + if (found) + emit highlightAll(txt, findFlags); + else + emit highlightAll(QString(), 0); + return found ? Found : NotFound; +} + +IFindSupport::Result BaseTextFind::findStep(const QString &txt, FindFlags findFlags) +{ + bool wrapped = false; + bool found = find(txt, findFlags, textCursor(), &wrapped); + if (wrapped) + showWrapIndicator(d->m_widget); + if (found) { + d->m_incrementalStartPos = textCursor().selectionStart(); + d->m_incrementalWrappedState = false; + } + return found ? Found : NotFound; +} + +void BaseTextFind::replace(const QString &before, const QString &after, FindFlags findFlags) +{ + QTextCursor cursor = replaceInternal(before, after, findFlags); + setTextCursor(cursor); +} + +QTextCursor BaseTextFind::replaceInternal(const QString &before, const QString &after, + FindFlags findFlags) +{ + QTextCursor cursor = textCursor(); + bool usesRegExp = (findFlags & FindRegularExpression); + bool preserveCase = (findFlags & FindPreserveCase); + QRegExp regexp(before, + (findFlags & FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive, + usesRegExp ? QRegExp::RegExp : QRegExp::FixedString); + + if (regexp.exactMatch(cursor.selectedText())) { + QString realAfter; + if (usesRegExp) + realAfter = Utils::expandRegExpReplacement(after, regexp.capturedTexts()); + else if (preserveCase) + realAfter = Utils::matchCaseReplacement(cursor.selectedText(), after); + else + realAfter = after; + int start = cursor.selectionStart(); + cursor.insertText(realAfter); + if ((findFlags & FindBackward) != 0) + cursor.setPosition(start); + } + return cursor; +} + +bool BaseTextFind::replaceStep(const QString &before, const QString &after, FindFlags findFlags) +{ + QTextCursor cursor = replaceInternal(before, after, findFlags); + bool wrapped = false; + bool found = find(before, findFlags, cursor, &wrapped); + if (wrapped) + showWrapIndicator(d->m_widget); + return found; +} + +int BaseTextFind::replaceAll(const QString &before, const QString &after, FindFlags findFlags) +{ + QTextCursor editCursor = textCursor(); + if (!d->m_findScopeStart.isNull()) + editCursor.setPosition(d->m_findScopeStart.position()); + else + editCursor.movePosition(QTextCursor::Start); + editCursor.beginEditBlock(); + int count = 0; + bool usesRegExp = (findFlags & FindRegularExpression); + bool preserveCase = (findFlags & FindPreserveCase); + QRegExp regexp(before); + regexp.setPatternSyntax(usesRegExp ? QRegExp::RegExp : QRegExp::FixedString); + regexp.setCaseSensitivity((findFlags & FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive); + QTextCursor found = findOne(regexp, editCursor, textDocumentFlagsForFindFlags(findFlags)); + bool first = true; + while (!found.isNull() && inScope(found.selectionStart(), found.selectionEnd())) { + if (found == editCursor && !first) { + if (editCursor.atEnd()) + break; + // If the newly found QTextCursor is the same as recently edit one we have to move on, + // otherwise we would run into an endless loop for some regular expressions + // like ^ or \b. + QTextCursor newPosCursor = editCursor; + newPosCursor.movePosition(findFlags & FindBackward ? + QTextCursor::PreviousCharacter : + QTextCursor::NextCharacter); + found = findOne(regexp, newPosCursor, textDocumentFlagsForFindFlags(findFlags)); + continue; + } + if (first) + first = false; + ++count; + editCursor.setPosition(found.selectionStart()); + editCursor.setPosition(found.selectionEnd(), QTextCursor::KeepAnchor); + regexp.exactMatch(found.selectedText()); + + QString realAfter; + if (usesRegExp) + realAfter = Utils::expandRegExpReplacement(after, regexp.capturedTexts()); + else if (preserveCase) + realAfter = Utils::matchCaseReplacement(found.selectedText(), after); + else + realAfter = after; + editCursor.insertText(realAfter); + found = findOne(regexp, editCursor, textDocumentFlagsForFindFlags(findFlags)); + } + editCursor.endEditBlock(); + return count; +} + +bool BaseTextFind::find(const QString &txt, FindFlags findFlags, + QTextCursor start, bool *wrapped) +{ + if (txt.isEmpty()) { + setTextCursor(start); + return true; + } + QRegExp regexp(txt); + regexp.setPatternSyntax((findFlags & FindRegularExpression) ? QRegExp::RegExp : QRegExp::FixedString); + regexp.setCaseSensitivity((findFlags & FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive); + QTextCursor found = findOne(regexp, start, textDocumentFlagsForFindFlags(findFlags)); + if (wrapped) + *wrapped = false; + + if (!d->m_findScopeStart.isNull()) { + + // scoped + if (found.isNull() || !inScope(found.selectionStart(), found.selectionEnd())) { + if ((findFlags & FindBackward) == 0) + start.setPosition(d->m_findScopeStart.position()); + else + start.setPosition(d->m_findScopeEnd.position()); + found = findOne(regexp, start, textDocumentFlagsForFindFlags(findFlags)); + if (found.isNull() || !inScope(found.selectionStart(), found.selectionEnd())) + return false; + if (wrapped) + *wrapped = true; + } + } else { + + // entire document + if (found.isNull()) { + if ((findFlags & FindBackward) == 0) + start.movePosition(QTextCursor::Start); + else + start.movePosition(QTextCursor::End); + found = findOne(regexp, start, textDocumentFlagsForFindFlags(findFlags)); + if (found.isNull()) + return false; + if (wrapped) + *wrapped = true; + } + } + if (!found.isNull()) + setTextCursor(found); + return true; +} + + +// helper function. Works just like QTextDocument::find() but supports vertical block selection +QTextCursor BaseTextFind::findOne(const QRegExp &expr, const QTextCursor &from, QTextDocument::FindFlags options) const +{ + QTextCursor candidate = document()->find(expr, from, options); + if (candidate.isNull()) + return candidate; + + if (d->m_findScopeVerticalBlockSelectionFirstColumn < 0) + return candidate; + forever { + if (!inScope(candidate.selectionStart(), candidate.selectionEnd())) + return candidate; + bool inVerticalFindScope = false; + QMetaObject::invokeMethod(d->m_plaineditor, "inFindScope", Qt::DirectConnection, + Q_RETURN_ARG(bool, inVerticalFindScope), + Q_ARG(QTextCursor, candidate)); + if (inVerticalFindScope) + return candidate; + + QTextCursor newCandidate = document()->find(expr, candidate, options); + if (newCandidate == candidate) { + // When searching for regular expressions that match "zero length" strings (like ^ or \b) + // we need to move away from the match before searching for the next one. + candidate.movePosition(options & QTextDocument::FindBackward + ? QTextCursor::PreviousCharacter + : QTextCursor::NextCharacter); + candidate = document()->find(expr, candidate, options); + } else { + candidate = newCandidate; + } + } + return candidate; +} + +bool BaseTextFind::inScope(int startPosition, int endPosition) const +{ + if (d->m_findScopeStart.isNull()) + return true; + return (d->m_findScopeStart.position() <= startPosition + && d->m_findScopeEnd.position() >= endPosition); +} + +void BaseTextFind::defineFindScope() +{ + QTextCursor cursor = textCursor(); + if (cursor.hasSelection() && cursor.block() != cursor.document()->findBlock(cursor.anchor())) { + d->m_findScopeStart = QTextCursor(document()->docHandle(), qMax(0, cursor.selectionStart())); + d->m_findScopeEnd = QTextCursor(document()->docHandle(), cursor.selectionEnd()); + d->m_findScopeVerticalBlockSelectionFirstColumn = -1; + d->m_findScopeVerticalBlockSelectionLastColumn = -1; + + if (d->m_plaineditor && d->m_plaineditor->metaObject()->indexOfProperty("verticalBlockSelectionFirstColumn") >= 0) { + d->m_findScopeVerticalBlockSelectionFirstColumn + = d->m_plaineditor->property("verticalBlockSelectionFirstColumn").toInt(); + d->m_findScopeVerticalBlockSelectionLastColumn + = d->m_plaineditor->property("verticalBlockSelectionLastColumn").toInt(); + } + + emit findScopeChanged(d->m_findScopeStart, d->m_findScopeEnd, + d->m_findScopeVerticalBlockSelectionFirstColumn, + d->m_findScopeVerticalBlockSelectionLastColumn); + cursor.setPosition(d->m_findScopeStart.position()); + setTextCursor(cursor); + } else { + clearFindScope(); + } +} + +void BaseTextFind::clearFindScope() +{ + d->m_findScopeStart = QTextCursor(); + d->m_findScopeEnd = QTextCursor(); + d->m_findScopeVerticalBlockSelectionFirstColumn = -1; + d->m_findScopeVerticalBlockSelectionLastColumn = -1; + emit findScopeChanged(d->m_findScopeStart, d->m_findScopeEnd, + d->m_findScopeVerticalBlockSelectionFirstColumn, + d->m_findScopeVerticalBlockSelectionLastColumn); +} + +} // namespace Core diff --git a/src/plugins/coreplugin/find/basetextfind.h b/src/plugins/coreplugin/find/basetextfind.h new file mode 100644 index 00000000000..1d1d54d9ef1 --- /dev/null +++ b/src/plugins/coreplugin/find/basetextfind.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef BASETEXTFIND_H +#define BASETEXTFIND_H + +#include "ifindsupport.h" + +QT_BEGIN_NAMESPACE +class QPlainTextEdit; +class QTextEdit; +class QTextCursor; +QT_END_NAMESPACE + +namespace Core { +struct BaseTextFindPrivate; + +class CORE_EXPORT BaseTextFind : public IFindSupport +{ + Q_OBJECT + +public: + explicit BaseTextFind(QPlainTextEdit *editor); + explicit BaseTextFind(QTextEdit *editor); + virtual ~BaseTextFind(); + + bool supportsReplace() const; + FindFlags supportedFindFlags() const; + void resetIncrementalSearch(); + void clearResults(); + QString currentFindString() const; + QString completedFindString() const; + + Result findIncremental(const QString &txt, FindFlags findFlags); + Result findStep(const QString &txt, FindFlags findFlags); + void replace(const QString &before, const QString &after, FindFlags findFlags); + bool replaceStep(const QString &before, const QString &after, FindFlags findFlags); + int replaceAll(const QString &before, const QString &after, FindFlags findFlags); + + void defineFindScope(); + void clearFindScope(); + +signals: + void highlightAll(const QString &txt, Core::FindFlags findFlags); + void findScopeChanged(const QTextCursor &start, const QTextCursor &end, + int verticalBlockSelectionFirstColumn, + int verticalBlockSelectionLastColumn); + +private: + bool find(const QString &txt, FindFlags findFlags, QTextCursor start, bool *wrapped); + QTextCursor replaceInternal(const QString &before, const QString &after, FindFlags findFlags); + + QTextCursor textCursor() const; + void setTextCursor(const QTextCursor&); + QTextDocument *document() const; + bool isReadOnly() const; + bool inScope(int startPosition, int endPosition) const; + QTextCursor findOne(const QRegExp &expr, const QTextCursor &from, QTextDocument::FindFlags options) const; + + BaseTextFindPrivate *d; +}; + +} // namespace Core + +#endif // BASETEXTFIND_H diff --git a/src/plugins/coreplugin/find/currentdocumentfind.cpp b/src/plugins/coreplugin/find/currentdocumentfind.cpp new file mode 100644 index 00000000000..854a391003b --- /dev/null +++ b/src/plugins/coreplugin/find/currentdocumentfind.cpp @@ -0,0 +1,259 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "currentdocumentfind.h" + +#include +#include +#include + +#include +#include +#include + +using namespace Core; +using namespace Core; +using namespace Core::Internal; + +CurrentDocumentFind::CurrentDocumentFind() + : m_currentFind(0) +{ + connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), + this, SLOT(updateCandidateFindFilter(QWidget*,QWidget*))); +} + +void CurrentDocumentFind::removeConnections() +{ + disconnect(qApp, 0, this, 0); + removeFindSupportConnections(); +} + +void CurrentDocumentFind::resetIncrementalSearch() +{ + QTC_ASSERT(m_currentFind, return); + m_currentFind->resetIncrementalSearch(); +} + +void CurrentDocumentFind::clearResults() +{ + QTC_ASSERT(m_currentFind, return); + m_currentFind->clearResults(); +} + +bool CurrentDocumentFind::isEnabled() const +{ + return m_currentFind && (!m_currentWidget || m_currentWidget->isVisible()); +} + +bool CurrentDocumentFind::candidateIsEnabled() const +{ + return (m_candidateFind != 0); +} + +bool CurrentDocumentFind::supportsReplace() const +{ + QTC_ASSERT(m_currentFind, return false); + return m_currentFind->supportsReplace(); +} + +FindFlags CurrentDocumentFind::supportedFindFlags() const +{ + QTC_ASSERT(m_currentFind, return 0); + return m_currentFind->supportedFindFlags(); +} + +QString CurrentDocumentFind::currentFindString() const +{ + QTC_ASSERT(m_currentFind, return QString()); + return m_currentFind->currentFindString(); +} + +QString CurrentDocumentFind::completedFindString() const +{ + QTC_ASSERT(m_currentFind, return QString()); + return m_currentFind->completedFindString(); +} + +void CurrentDocumentFind::highlightAll(const QString &txt, FindFlags findFlags) +{ + QTC_ASSERT(m_currentFind, return); + m_currentFind->highlightAll(txt, findFlags); +} + +IFindSupport::Result CurrentDocumentFind::findIncremental(const QString &txt, FindFlags findFlags) +{ + QTC_ASSERT(m_currentFind, return IFindSupport::NotFound); + return m_currentFind->findIncremental(txt, findFlags); +} + +IFindSupport::Result CurrentDocumentFind::findStep(const QString &txt, FindFlags findFlags) +{ + QTC_ASSERT(m_currentFind, return IFindSupport::NotFound); + return m_currentFind->findStep(txt, findFlags); +} + +void CurrentDocumentFind::replace(const QString &before, const QString &after, FindFlags findFlags) +{ + QTC_ASSERT(m_currentFind, return); + m_currentFind->replace(before, after, findFlags); +} + +bool CurrentDocumentFind::replaceStep(const QString &before, const QString &after, FindFlags findFlags) +{ + QTC_ASSERT(m_currentFind, return false); + return m_currentFind->replaceStep(before, after, findFlags); +} + +int CurrentDocumentFind::replaceAll(const QString &before, const QString &after, FindFlags findFlags) +{ + QTC_ASSERT(m_currentFind, return 0); + return m_currentFind->replaceAll(before, after, findFlags); +} + +void CurrentDocumentFind::defineFindScope() +{ + QTC_ASSERT(m_currentFind, return); + m_currentFind->defineFindScope(); +} + +void CurrentDocumentFind::clearFindScope() +{ + QTC_ASSERT(m_currentFind, return); + m_currentFind->clearFindScope(); +} + +void CurrentDocumentFind::updateCandidateFindFilter(QWidget *old, QWidget *now) +{ + Q_UNUSED(old) + QWidget *candidate = now; + QPointer impl = 0; + while (!impl && candidate) { + impl = Aggregation::query(candidate); + if (!impl) + candidate = candidate->parentWidget(); + } + if (m_candidateWidget) + disconnect(Aggregation::Aggregate::parentAggregate(m_candidateWidget), SIGNAL(changed()), + this, SLOT(candidateAggregationChanged())); + m_candidateWidget = candidate; + m_candidateFind = impl; + if (m_candidateWidget) + connect(Aggregation::Aggregate::parentAggregate(m_candidateWidget), SIGNAL(changed()), + this, SLOT(candidateAggregationChanged())); + emit candidateChanged(); +} + +void CurrentDocumentFind::acceptCandidate() +{ + if (!m_candidateFind || m_candidateFind == m_currentFind) + return; + removeFindSupportConnections(); + if (m_currentFind) + m_currentFind->clearResults(); + + if (m_currentWidget) + disconnect(Aggregation::Aggregate::parentAggregate(m_currentWidget), SIGNAL(changed()), + this, SLOT(aggregationChanged())); + m_currentWidget = m_candidateWidget; + connect(Aggregation::Aggregate::parentAggregate(m_currentWidget), SIGNAL(changed()), + this, SLOT(aggregationChanged())); + + m_currentFind = m_candidateFind; + if (m_currentFind) { + connect(m_currentFind, SIGNAL(changed()), this, SIGNAL(changed())); + connect(m_currentFind, SIGNAL(destroyed(QObject*)), SLOT(clearFindSupport())); + } + if (m_currentWidget) + m_currentWidget->installEventFilter(this); + emit changed(); +} + +void CurrentDocumentFind::removeFindSupportConnections() +{ + if (m_currentFind) { + disconnect(m_currentFind, SIGNAL(changed()), this, SIGNAL(changed())); + disconnect(m_currentFind, SIGNAL(destroyed(QObject*)), this, SLOT(clearFindSupport())); + } + if (m_currentWidget) + m_currentWidget->removeEventFilter(this); +} + +void CurrentDocumentFind::clearFindSupport() +{ + removeFindSupportConnections(); + m_currentWidget = 0; + m_currentFind = 0; + emit changed(); +} + +bool CurrentDocumentFind::setFocusToCurrentFindSupport() +{ + if (m_currentFind && m_currentWidget) { + QWidget *w = m_currentWidget->focusWidget(); + if (!w) + w = m_currentWidget; + w->setFocus(); + return true; + } + return false; +} + +bool CurrentDocumentFind::eventFilter(QObject *obj, QEvent *event) +{ + if (m_currentWidget && obj == m_currentWidget) { + if (event->type() == QEvent::Hide || event->type() == QEvent::Show) + emit changed(); + } + return QObject::eventFilter(obj, event); +} + +void CurrentDocumentFind::aggregationChanged() +{ + if (m_currentWidget) { + QPointer currentFind = Aggregation::query(m_currentWidget); + if (currentFind != m_currentFind) { + // There's a change in the find support + if (currentFind) { + m_candidateWidget = m_currentWidget; + m_candidateFind = currentFind; + acceptCandidate(); + } else { + clearFindSupport(); + } + } + } +} + +void CurrentDocumentFind::candidateAggregationChanged() +{ + if (m_candidateWidget && m_candidateWidget != m_currentWidget) { + m_candidateFind = Aggregation::query(m_candidateWidget); + emit candidateChanged(); + } +} diff --git a/src/plugins/coreplugin/find/currentdocumentfind.h b/src/plugins/coreplugin/find/currentdocumentfind.h new file mode 100644 index 00000000000..2b428e05839 --- /dev/null +++ b/src/plugins/coreplugin/find/currentdocumentfind.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CURRENTDOCUMENTFIND_H +#define CURRENTDOCUMENTFIND_H + +#include "ifindsupport.h" + +#include + +namespace Core { +namespace Internal { + +class CurrentDocumentFind : public QObject +{ + Q_OBJECT + +public: + CurrentDocumentFind(); + + void resetIncrementalSearch(); + void clearResults(); + bool supportsReplace() const; + FindFlags supportedFindFlags() const; + QString currentFindString() const; + QString completedFindString() const; + + bool isEnabled() const; + bool candidateIsEnabled() const; + void highlightAll(const QString &txt, FindFlags findFlags); + IFindSupport::Result findIncremental(const QString &txt, FindFlags findFlags); + IFindSupport::Result findStep(const QString &txt, FindFlags findFlags); + void replace(const QString &before, const QString &after, FindFlags findFlags); + bool replaceStep(const QString &before, const QString &after, FindFlags findFlags); + int replaceAll(const QString &before, const QString &after, FindFlags findFlags); + void defineFindScope(); + void clearFindScope(); + void acceptCandidate(); + + void removeConnections(); + bool setFocusToCurrentFindSupport(); + + bool eventFilter(QObject *obj, QEvent *event); + +signals: + void changed(); + void candidateChanged(); + +private slots: + void updateCandidateFindFilter(QWidget *old, QWidget *now); + void clearFindSupport(); + void aggregationChanged(); + void candidateAggregationChanged(); + +private: + void removeFindSupportConnections(); + + QPointer m_currentFind; + QPointer m_currentWidget; + QPointer m_candidateFind; + QPointer m_candidateWidget; +}; + +} // namespace Internal +} // namespace Core + +#endif // CURRENTDOCUMENTFIND_H diff --git a/src/plugins/coreplugin/find/find.pri b/src/plugins/coreplugin/find/find.pri new file mode 100644 index 00000000000..c7e8c836bc9 --- /dev/null +++ b/src/plugins/coreplugin/find/find.pri @@ -0,0 +1,42 @@ +HEADERS += \ + $$PWD/findtoolwindow.h \ + $$PWD/textfindconstants.h \ + $$PWD/ifindsupport.h \ + $$PWD/ifindfilter.h \ + $$PWD/currentdocumentfind.h \ + $$PWD/basetextfind.h \ + $$PWD/findtoolbar.h \ + $$PWD/findplugin.h \ + $$PWD/searchresultcolor.h \ + $$PWD/searchresulttreeitemdelegate.h \ + $$PWD/searchresulttreeitemroles.h \ + $$PWD/searchresulttreeitems.h \ + $$PWD/searchresulttreemodel.h \ + $$PWD/searchresulttreeview.h \ + $$PWD/searchresultwindow.h \ + $$PWD/searchresultwidget.h \ + $$PWD/treeviewfind.h + +SOURCES += \ + $$PWD/findtoolwindow.cpp \ + $$PWD/currentdocumentfind.cpp \ + $$PWD/basetextfind.cpp \ + $$PWD/findtoolbar.cpp \ + $$PWD/findplugin.cpp \ + $$PWD/searchresulttreeitemdelegate.cpp \ + $$PWD/searchresulttreeitems.cpp \ + $$PWD/searchresulttreemodel.cpp \ + $$PWD/searchresulttreeview.cpp \ + $$PWD/searchresultwindow.cpp \ + $$PWD/ifindfilter.cpp \ + $$PWD/ifindsupport.cpp \ + $$PWD/searchresultwidget.cpp \ + $$PWD/treeviewfind.cpp + +FORMS += \ + $$PWD/findwidget.ui \ + $$PWD/finddialog.ui + +RESOURCES += \ + $$PWD/find.qrc + diff --git a/src/plugins/coreplugin/find/find.qrc b/src/plugins/coreplugin/find/find.qrc new file mode 100644 index 00000000000..0c4e1281012 --- /dev/null +++ b/src/plugins/coreplugin/find/find.qrc @@ -0,0 +1,10 @@ + + + images/casesensitively.png + images/wholewords.png + images/regexp.png + images/expand.png + images/wrapindicator.png + images/preservecase.png + + diff --git a/src/plugins/coreplugin/find/finddialog.ui b/src/plugins/coreplugin/find/finddialog.ui new file mode 100644 index 00000000000..19d41c938cf --- /dev/null +++ b/src/plugins/coreplugin/find/finddialog.ui @@ -0,0 +1,209 @@ + + + Core::Internal::FindDialog + + + + 0 + 0 + 673 + 240 + + + + + 680 + 16777215 + + + + + QLayout::SetFixedSize + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &Search + + + true + + + + + + + Search && &Replace + + + + + + + + + Sear&ch for: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + searchTerm + + + + + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + + + + + Case sensiti&ve + + + + + + + Whole words o&nly + + + + + + + Use re&gular expressions + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 80 + 0 + + + + Sco&pe: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + filterList + + + + + + + + + + + 0 + 10 + + + + + + + + + Utils::FancyLineEdit + QLineEdit +
utils/fancylineedit.h
+
+ + Utils::FilterLineEdit + Utils::FancyLineEdit +
utils/filterlineedit.h
+
+
+ + filterList + searchTerm + matchCase + wholeWords + regExp + + + +
diff --git a/src/plugins/coreplugin/find/findplugin.cpp b/src/plugins/coreplugin/find/findplugin.cpp new file mode 100644 index 00000000000..ebb9f4b1835 --- /dev/null +++ b/src/plugins/coreplugin/find/findplugin.cpp @@ -0,0 +1,394 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "findplugin.h" + +#include "currentdocumentfind.h" +#include "findtoolbar.h" +#include "findtoolwindow.h" +#include "searchresultwindow.h" +#include "ifindfilter.h" + +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include + +#include +#include + +/*! + \namespace Core::Internal + \internal +*/ +/*! + \namespace Core::Internal::ItemDataRoles + \internal +*/ + +Q_DECLARE_METATYPE(Core::IFindFilter*) + +namespace { + const int MAX_COMPLETIONS = 50; +} + +namespace Core { + +class FindPluginPrivate { +public: + explicit FindPluginPrivate(FindPlugin *q); + + //variables + static FindPlugin *m_instance; + + QHash m_filterActions; + + Internal::CurrentDocumentFind *m_currentDocumentFind; + Internal::FindToolBar *m_findToolBar; + Internal::FindToolWindow *m_findDialog; + SearchResultWindow *m_searchResultWindow; + FindFlags m_findFlags; + QStringListModel *m_findCompletionModel; + QStringListModel *m_replaceCompletionModel; + QStringList m_findCompletions; + QStringList m_replaceCompletions; + QAction *m_openFindDialog; +}; + +FindPluginPrivate::FindPluginPrivate(FindPlugin *q) : + m_currentDocumentFind(0), m_findToolBar(0), m_findDialog(0), + m_findCompletionModel(new QStringListModel(q)), + m_replaceCompletionModel(new QStringListModel(q)) +{ +} + +FindPlugin *FindPluginPrivate::m_instance = 0; + +FindPlugin::FindPlugin() : d(new FindPluginPrivate(this)) +{ + QTC_ASSERT(!FindPluginPrivate::m_instance, return); + FindPluginPrivate::m_instance = this; +} + +FindPlugin::~FindPlugin() +{ + FindPluginPrivate::m_instance = 0; + delete d->m_currentDocumentFind; + delete d->m_findToolBar; + delete d->m_findDialog; + ExtensionSystem::PluginManager::removeObject(d->m_searchResultWindow); + delete d->m_searchResultWindow; + delete d; +} + +FindPlugin *FindPlugin::instance() +{ + return FindPluginPrivate::m_instance; +} + +void FindPlugin::initialize(const QStringList &, QString *) +{ + setupMenu(); + + d->m_currentDocumentFind = new Internal::CurrentDocumentFind; + + d->m_findToolBar = new Internal::FindToolBar(this, d->m_currentDocumentFind); + d->m_findDialog = new Internal::FindToolWindow(this); + d->m_searchResultWindow = new SearchResultWindow(d->m_findDialog); + ExtensionSystem::PluginManager::addObject(d->m_searchResultWindow); +} + +void FindPlugin::extensionsInitialized() +{ + setupFilterMenuItems(); + readSettings(); +} + +void FindPlugin::aboutToShutdown() +{ + d->m_findToolBar->setVisible(false); + d->m_findToolBar->setParent(0); + d->m_currentDocumentFind->removeConnections(); + writeSettings(); +} + +void FindPlugin::filterChanged() +{ + IFindFilter *changedFilter = qobject_cast(sender()); + QAction *action = d->m_filterActions.value(changedFilter); + QTC_ASSERT(changedFilter, return); + QTC_ASSERT(action, return); + action->setEnabled(changedFilter->isEnabled()); + bool haveEnabledFilters = false; + foreach (const IFindFilter *filter, d->m_filterActions.keys()) { + if (filter->isEnabled()) { + haveEnabledFilters = true; + break; + } + } + d->m_openFindDialog->setEnabled(haveEnabledFilters); +} + +void FindPlugin::openFindFilter() +{ + QAction *action = qobject_cast(sender()); + QTC_ASSERT(action, return); + IFindFilter *filter = action->data().value(); + openFindDialog(filter); +} + +void FindPlugin::openFindDialog(IFindFilter *filter) +{ + if (d->m_currentDocumentFind->candidateIsEnabled()) + d->m_currentDocumentFind->acceptCandidate(); + const QString currentFindString = + d->m_currentDocumentFind->isEnabled() ? + d->m_currentDocumentFind->currentFindString() : QString(); + if (!currentFindString.isEmpty()) + d->m_findDialog->setFindText(currentFindString); + d->m_findDialog->setCurrentFilter(filter); + SearchResultWindow::instance()->openNewSearchPanel(); +} + +void FindPlugin::setupMenu() +{ + Core::ActionContainer *medit = Core::ActionManager::actionContainer(Core::Constants::M_EDIT); + Core::ActionContainer *mfind = Core::ActionManager::createMenu(Constants::M_FIND); + medit->addMenu(mfind, Core::Constants::G_EDIT_FIND); + mfind->menu()->setTitle(tr("&Find/Replace")); + mfind->appendGroup(Constants::G_FIND_CURRENTDOCUMENT); + mfind->appendGroup(Constants::G_FIND_FILTERS); + mfind->appendGroup(Constants::G_FIND_FLAGS); + mfind->appendGroup(Constants::G_FIND_ACTIONS); + Core::Context globalcontext(Core::Constants::C_GLOBAL); + Core::Command *cmd; + mfind->addSeparator(globalcontext, Constants::G_FIND_FLAGS); + mfind->addSeparator(globalcontext, Constants::G_FIND_ACTIONS); + + Core::ActionContainer *mfindadvanced = Core::ActionManager::createMenu(Constants::M_FIND_ADVANCED); + mfindadvanced->menu()->setTitle(tr("Advanced Find")); + mfind->addMenu(mfindadvanced, Constants::G_FIND_FILTERS); + d->m_openFindDialog = new QAction(tr("Open Advanced Find..."), this); + d->m_openFindDialog->setIconText(tr("Advanced...")); + cmd = Core::ActionManager::registerAction(d->m_openFindDialog, Constants::ADVANCED_FIND, globalcontext); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F"))); + mfindadvanced->addAction(cmd); + connect(d->m_openFindDialog, SIGNAL(triggered()), this, SLOT(openFindFilter())); +} + +void FindPlugin::setupFilterMenuItems() +{ + QList findInterfaces = + ExtensionSystem::PluginManager::getObjects(); + Core::Command *cmd; + Core::Context globalcontext(Core::Constants::C_GLOBAL); + + Core::ActionContainer *mfindadvanced = Core::ActionManager::actionContainer(Constants::M_FIND_ADVANCED); + d->m_filterActions.clear(); + bool haveEnabledFilters = false; + const Core::Id base("FindFilter."); + foreach (IFindFilter *filter, findInterfaces) { + QAction *action = new QAction(QLatin1String(" ") + filter->displayName(), this); + bool isEnabled = filter->isEnabled(); + if (isEnabled) + haveEnabledFilters = true; + action->setEnabled(isEnabled); + action->setData(qVariantFromValue(filter)); + cmd = Core::ActionManager::registerAction(action, + base.withSuffix(filter->id()), globalcontext); + cmd->setDefaultKeySequence(filter->defaultShortcut()); + mfindadvanced->addAction(cmd); + d->m_filterActions.insert(filter, action); + connect(action, SIGNAL(triggered(bool)), this, SLOT(openFindFilter())); + connect(filter, SIGNAL(enabledChanged(bool)), this, SLOT(filterChanged())); + } + d->m_findDialog->setFindFilters(findInterfaces); + d->m_openFindDialog->setEnabled(haveEnabledFilters); +} + +FindFlags FindPlugin::findFlags() const +{ + return d->m_findFlags; +} + +void FindPlugin::setCaseSensitive(bool sensitive) +{ + setFindFlag(FindCaseSensitively, sensitive); +} + +void FindPlugin::setWholeWord(bool wholeOnly) +{ + setFindFlag(FindWholeWords, wholeOnly); +} + +void FindPlugin::setBackward(bool backward) +{ + setFindFlag(FindBackward, backward); +} + +void FindPlugin::setRegularExpression(bool regExp) +{ + setFindFlag(FindRegularExpression, regExp); +} + +void FindPlugin::setPreserveCase(bool preserveCase) +{ + setFindFlag(FindPreserveCase, preserveCase); +} + +void FindPlugin::setFindFlag(FindFlag flag, bool enabled) +{ + bool hasFlag = hasFindFlag(flag); + if ((hasFlag && enabled) || (!hasFlag && !enabled)) + return; + if (enabled) + d->m_findFlags |= flag; + else + d->m_findFlags &= ~flag; + if (flag != FindBackward) + emit findFlagsChanged(); +} + +bool FindPlugin::hasFindFlag(FindFlag flag) +{ + return d->m_findFlags & flag; +} + +void FindPlugin::writeSettings() +{ + QSettings *settings = Core::ICore::settings(); + settings->beginGroup(QLatin1String("Find")); + settings->setValue(QLatin1String("Backward"), hasFindFlag(FindBackward)); + settings->setValue(QLatin1String("CaseSensitively"), hasFindFlag(FindCaseSensitively)); + settings->setValue(QLatin1String("WholeWords"), hasFindFlag(FindWholeWords)); + settings->setValue(QLatin1String("RegularExpression"), hasFindFlag(FindRegularExpression)); + settings->setValue(QLatin1String("PreserveCase"), hasFindFlag(FindPreserveCase)); + settings->setValue(QLatin1String("FindStrings"), d->m_findCompletions); + settings->setValue(QLatin1String("ReplaceStrings"), d->m_replaceCompletions); + settings->endGroup(); + d->m_findToolBar->writeSettings(); + d->m_findDialog->writeSettings(); + d->m_searchResultWindow->writeSettings(); +} + +void FindPlugin::readSettings() +{ + QSettings *settings = Core::ICore::settings(); + settings->beginGroup(QLatin1String("Find")); + bool block = blockSignals(true); + setBackward(settings->value(QLatin1String("Backward"), false).toBool()); + setCaseSensitive(settings->value(QLatin1String("CaseSensitively"), false).toBool()); + setWholeWord(settings->value(QLatin1String("WholeWords"), false).toBool()); + setRegularExpression(settings->value(QLatin1String("RegularExpression"), false).toBool()); + setPreserveCase(settings->value(QLatin1String("PreserveCase"), false).toBool()); + blockSignals(block); + d->m_findCompletions = settings->value(QLatin1String("FindStrings")).toStringList(); + d->m_replaceCompletions = settings->value(QLatin1String("ReplaceStrings")).toStringList(); + d->m_findCompletionModel->setStringList(d->m_findCompletions); + d->m_replaceCompletionModel->setStringList(d->m_replaceCompletions); + settings->endGroup(); + d->m_findToolBar->readSettings(); + d->m_findDialog->readSettings(); + emit findFlagsChanged(); // would have been done in the setXXX methods above +} + +void FindPlugin::updateFindCompletion(const QString &text) +{ + updateCompletion(text, d->m_findCompletions, d->m_findCompletionModel); +} + +void FindPlugin::updateReplaceCompletion(const QString &text) +{ + updateCompletion(text, d->m_replaceCompletions, d->m_replaceCompletionModel); +} + +void FindPlugin::updateCompletion(const QString &text, QStringList &completions, QStringListModel *model) +{ + if (text.isEmpty()) + return; + completions.removeAll(text); + completions.prepend(text); + while (completions.size() > MAX_COMPLETIONS) + completions.removeLast(); + model->setStringList(completions); +} + +void FindPlugin::setUseFakeVim(bool on) +{ + if (d->m_findToolBar) + d->m_findToolBar->setUseFakeVim(on); +} + +void FindPlugin::openFindToolBar(FindDirection direction) +{ + if (d->m_findToolBar) { + d->m_findToolBar->setBackward(direction == FindBackwardDirection); + d->m_findToolBar->openFindToolBar(); + } +} + +QStringListModel *FindPlugin::findCompletionModel() const +{ + return d->m_findCompletionModel; +} + +QStringListModel *FindPlugin::replaceCompletionModel() const +{ + return d->m_replaceCompletionModel; +} + +QKeySequence IFindFilter::defaultShortcut() const +{ + return QKeySequence(); +} + +// declared in textfindconstants.h +QTextDocument::FindFlags textDocumentFlagsForFindFlags(FindFlags flags) +{ + QTextDocument::FindFlags textDocFlags; + if (flags & FindBackward) + textDocFlags |= QTextDocument::FindBackward; + if (flags & FindCaseSensitively) + textDocFlags |= QTextDocument::FindCaseSensitively; + if (flags & FindWholeWords) + textDocFlags |= QTextDocument::FindWholeWords; + return textDocFlags; +} + +} // namespace Core diff --git a/src/plugins/coreplugin/find/findplugin.h b/src/plugins/coreplugin/find/findplugin.h new file mode 100644 index 00000000000..0c8298052fc --- /dev/null +++ b/src/plugins/coreplugin/find/findplugin.h @@ -0,0 +1,108 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef FINDPLUGIN_H +#define FINDPLUGIN_H + +#include "textfindconstants.h" + +#include + +QT_BEGIN_NAMESPACE +class QStringListModel; +QT_END_NAMESPACE + +namespace Core { +class IFindFilter; +class FindPluginPrivate; + +namespace Internal { +class CorePlugin; +class FindToolBar; +class CurrentDocumentFind; +} // namespace Internal + +class CORE_EXPORT FindPlugin : public QObject +{ + Q_OBJECT + +public: + FindPlugin(); + virtual ~FindPlugin(); + + static FindPlugin *instance(); + + enum FindDirection { + FindForwardDirection, + FindBackwardDirection + }; + + Core::FindFlags findFlags() const; + bool hasFindFlag(Core::FindFlag flag); + void updateFindCompletion(const QString &text); + void updateReplaceCompletion(const QString &text); + QStringListModel *findCompletionModel() const; + QStringListModel *replaceCompletionModel() const; + void setUseFakeVim(bool on); + void openFindToolBar(FindDirection direction); + void openFindDialog(IFindFilter *filter); + + void initialize(const QStringList &, QString *); + void extensionsInitialized(); + void aboutToShutdown(); + +public slots: + void setCaseSensitive(bool sensitive); + void setWholeWord(bool wholeOnly); + void setBackward(bool backward); + void setRegularExpression(bool regExp); + void setPreserveCase(bool preserveCase); + +signals: + void findFlagsChanged(); + +private slots: + void filterChanged(); + void openFindFilter(); + +private: + void setFindFlag(Core::FindFlag flag, bool enabled); + void updateCompletion(const QString &text, QStringList &completions, QStringListModel *model); + void setupMenu(); + void setupFilterMenuItems(); + void writeSettings(); + void readSettings(); + + //variables + FindPluginPrivate *d; +}; + +} // namespace Core + +#endif // FINDPLUGIN_H diff --git a/src/plugins/coreplugin/find/findtoolbar.cpp b/src/plugins/coreplugin/find/findtoolbar.cpp new file mode 100644 index 00000000000..e686c3fd481 --- /dev/null +++ b/src/plugins/coreplugin/find/findtoolbar.cpp @@ -0,0 +1,779 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "findtoolbar.h" +#include "ifindfilter.h" +#include "findplugin.h" + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +Q_DECLARE_METATYPE(QStringList) +Q_DECLARE_METATYPE(Core::IFindFilter*) + +using namespace Core; +using namespace Core::Internal; + +FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumentFind) + : m_plugin(plugin), + m_currentDocumentFind(currentDocumentFind), + m_findCompleter(new QCompleter(this)), + m_replaceCompleter(new QCompleter(this)), + m_enterFindStringAction(0), + m_findNextAction(0), + m_findPreviousAction(0), + m_replaceAction(0), + m_replaceNextAction(0), + m_replacePreviousAction(0), + m_findIncrementalTimer(this), m_findStepTimer(this), + m_useFakeVim(false), + m_eventFiltersInstalled(false) +{ + //setup ui + m_ui.setupUi(this); + // compensate for a vertically expanding spacer below the label + m_ui.replaceLabel->setMinimumHeight(m_ui.replaceEdit->sizeHint().height()); + delete m_ui.replaceButtonsWidget->layout(); + Utils::FlowLayout *flowlayout = new Utils::FlowLayout(m_ui.replaceButtonsWidget, 0, 3, 3); + flowlayout->addWidget(m_ui.replaceButton); + flowlayout->addWidget(m_ui.replaceNextButton); + flowlayout->addWidget(m_ui.replaceAllButton); + m_ui.replaceButtonsWidget->setLayout(flowlayout); + setFocusProxy(m_ui.findEdit); + setProperty("topBorder", true); + setSingleRow(false); + m_ui.findEdit->setAttribute(Qt::WA_MacShowFocusRect, false); + m_ui.replaceEdit->setAttribute(Qt::WA_MacShowFocusRect, false); + + connect(m_ui.findEdit, SIGNAL(editingFinished()), this, SLOT(invokeResetIncrementalSearch())); + + m_ui.close->setIcon(QIcon(QLatin1String(Core::Constants::ICON_CLOSE_DOCUMENT))); + connect(m_ui.close, SIGNAL(clicked()), this, SLOT(hideAndResetFocus())); + + m_findCompleter->setModel(m_plugin->findCompletionModel()); + m_replaceCompleter->setModel(m_plugin->replaceCompletionModel()); + m_ui.findEdit->setSpecialCompleter(m_findCompleter); + m_ui.replaceEdit->setSpecialCompleter(m_replaceCompleter); + + QMenu *lineEditMenu = new QMenu(m_ui.findEdit); + m_ui.findEdit->setButtonMenu(Utils::FancyLineEdit::Left, lineEditMenu); + m_ui.findEdit->setButtonVisible(Utils::FancyLineEdit::Left, true); + m_ui.findEdit->setPlaceholderText(QString()); + m_ui.replaceEdit->setPlaceholderText(QString()); + + connect(m_ui.findEdit, SIGNAL(textChanged(QString)), this, SLOT(invokeFindIncremental())); + + // invoke{Find,Replace}Helper change the completion model. QueuedConnection is used to perform these + // changes only after the completer's activated() signal is handled (QTCREATORBUG-8408) + connect(m_ui.findEdit, SIGNAL(returnPressed()), this, SLOT(invokeFindEnter()), Qt::QueuedConnection); + connect(m_ui.replaceEdit, SIGNAL(returnPressed()), this, SLOT(invokeReplaceEnter()), Qt::QueuedConnection); + + QAction *shiftEnterAction = new QAction(m_ui.findEdit); + shiftEnterAction->setShortcut(QKeySequence(tr("Shift+Enter"))); + shiftEnterAction->setShortcutContext(Qt::WidgetShortcut); + connect(shiftEnterAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious())); + m_ui.findEdit->addAction(shiftEnterAction); + QAction *shiftReturnAction = new QAction(m_ui.findEdit); + shiftReturnAction->setShortcut(QKeySequence(tr("Shift+Return"))); + shiftReturnAction->setShortcutContext(Qt::WidgetShortcut); + connect(shiftReturnAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious())); + m_ui.findEdit->addAction(shiftReturnAction); + + QAction *shiftEnterReplaceAction = new QAction(m_ui.replaceEdit); + shiftEnterReplaceAction->setShortcut(QKeySequence(tr("Shift+Enter"))); + shiftEnterReplaceAction->setShortcutContext(Qt::WidgetShortcut); + connect(shiftEnterReplaceAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious())); + m_ui.replaceEdit->addAction(shiftEnterReplaceAction); + QAction *shiftReturnReplaceAction = new QAction(m_ui.replaceEdit); + shiftReturnReplaceAction->setShortcut(QKeySequence(tr("Shift+Return"))); + shiftReturnReplaceAction->setShortcutContext(Qt::WidgetShortcut); + connect(shiftReturnReplaceAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious())); + m_ui.replaceEdit->addAction(shiftReturnReplaceAction); + + // need to make sure QStringList is registered as metatype + QMetaTypeId::qt_metatype_id(); + + // register actions + Core::Context globalcontext(Core::Constants::C_GLOBAL); + Core::ActionContainer *mfind = Core::ActionManager::actionContainer(Constants::M_FIND); + Core::Command *cmd; + + m_ui.advancedButton->setDefaultAction(Core::ActionManager::command(Constants::ADVANCED_FIND)->action()); + + QIcon icon = QIcon::fromTheme(QLatin1String("edit-find-replace")); + m_findInDocumentAction = new QAction(icon, tr("Find/Replace"), this); + cmd = Core::ActionManager::registerAction(m_findInDocumentAction, Constants::FIND_IN_DOCUMENT, globalcontext); + cmd->setDefaultKeySequence(QKeySequence::Find); + mfind->addAction(cmd, Constants::G_FIND_CURRENTDOCUMENT); + connect(m_findInDocumentAction, SIGNAL(triggered()), this, SLOT(openFind())); + + if (QApplication::clipboard()->supportsFindBuffer()) { + m_enterFindStringAction = new QAction(tr("Enter Find String"), this); + cmd = Core::ActionManager::registerAction(m_enterFindStringAction, "Find.EnterFindString", globalcontext); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+E"))); + mfind->addAction(cmd, Constants::G_FIND_ACTIONS); + connect(m_enterFindStringAction, SIGNAL(triggered()), this, SLOT(putSelectionToFindClipboard())); + connect(QApplication::clipboard(), SIGNAL(findBufferChanged()), this, SLOT(updateFromFindClipboard())); + } + + m_findNextAction = new QAction(tr("Find Next"), this); + cmd = Core::ActionManager::registerAction(m_findNextAction, Constants::FIND_NEXT, globalcontext); + cmd->setDefaultKeySequence(QKeySequence::FindNext); + mfind->addAction(cmd, Constants::G_FIND_ACTIONS); + connect(m_findNextAction, SIGNAL(triggered()), this, SLOT(invokeFindNext())); + m_ui.findNextButton->setDefaultAction(cmd->action()); + + m_findPreviousAction = new QAction(tr("Find Previous"), this); + cmd = Core::ActionManager::registerAction(m_findPreviousAction, Constants::FIND_PREVIOUS, globalcontext); + cmd->setDefaultKeySequence(QKeySequence::FindPrevious); + mfind->addAction(cmd, Constants::G_FIND_ACTIONS); + connect(m_findPreviousAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious())); + m_ui.findPreviousButton->setDefaultAction(cmd->action()); + + m_findNextSelectedAction = new QAction(tr("Find Next (Selected)"), this); + cmd = Core::ActionManager::registerAction(m_findNextSelectedAction, Constants::FIND_NEXT_SELECTED, globalcontext); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+F3"))); + mfind->addAction(cmd, Constants::G_FIND_ACTIONS); + connect(m_findNextSelectedAction, SIGNAL(triggered()), this, SLOT(findNextSelected())); + + m_findPreviousSelectedAction = new QAction(tr("Find Previous (Selected)"), this); + cmd = Core::ActionManager::registerAction(m_findPreviousSelectedAction, Constants::FIND_PREV_SELECTED, globalcontext); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F3"))); + mfind->addAction(cmd, Constants::G_FIND_ACTIONS); + connect(m_findPreviousSelectedAction, SIGNAL(triggered()), this, SLOT(findPreviousSelected())); + + m_replaceAction = new QAction(tr("Replace"), this); + cmd = Core::ActionManager::registerAction(m_replaceAction, Constants::REPLACE, globalcontext); + cmd->setDefaultKeySequence(QKeySequence()); + mfind->addAction(cmd, Constants::G_FIND_ACTIONS); + connect(m_replaceAction, SIGNAL(triggered()), this, SLOT(invokeReplace())); + m_ui.replaceButton->setDefaultAction(cmd->action()); + + m_replaceNextAction = new QAction(tr("Replace && Find"), this); + m_replaceNextAction->setIconText(tr("Replace && Find")); // work around bug in Qt that kills ampersands in tool button + cmd = Core::ActionManager::registerAction(m_replaceNextAction, Constants::REPLACE_NEXT, globalcontext); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+="))); + mfind->addAction(cmd, Constants::G_FIND_ACTIONS); + connect(m_replaceNextAction, SIGNAL(triggered()), this, SLOT(invokeReplaceNext())); + m_ui.replaceNextButton->setDefaultAction(cmd->action()); + + m_replacePreviousAction = new QAction(tr("Replace && Find Previous"), this); + cmd = Core::ActionManager::registerAction(m_replacePreviousAction, Constants::REPLACE_PREVIOUS, globalcontext); + // shortcut removed, clashes with Ctrl++ on many keyboard layouts + //cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+="))); + mfind->addAction(cmd, Constants::G_FIND_ACTIONS); + connect(m_replacePreviousAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious())); + + m_replaceAllAction = new QAction(tr("Replace All"), this); + cmd = Core::ActionManager::registerAction(m_replaceAllAction, Constants::REPLACE_ALL, globalcontext); + mfind->addAction(cmd, Constants::G_FIND_ACTIONS); + connect(m_replaceAllAction, SIGNAL(triggered()), this, SLOT(invokeReplaceAll())); + m_ui.replaceAllButton->setDefaultAction(cmd->action()); + + m_caseSensitiveAction = new QAction(tr("Case Sensitive"), this); + m_caseSensitiveAction->setIcon(QIcon(QLatin1String(":/find/images/casesensitively.png"))); + m_caseSensitiveAction->setCheckable(true); + m_caseSensitiveAction->setChecked(false); + cmd = Core::ActionManager::registerAction(m_caseSensitiveAction, Constants::CASE_SENSITIVE, globalcontext); + mfind->addAction(cmd, Constants::G_FIND_FLAGS); + connect(m_caseSensitiveAction, SIGNAL(triggered(bool)), this, SLOT(setCaseSensitive(bool))); + lineEditMenu->addAction(m_caseSensitiveAction); + + m_wholeWordAction = new QAction(tr("Whole Words Only"), this); + m_wholeWordAction->setIcon(QIcon(QLatin1String(":/find/images/wholewords.png"))); + m_wholeWordAction->setCheckable(true); + m_wholeWordAction->setChecked(false); + cmd = Core::ActionManager::registerAction(m_wholeWordAction, Constants::WHOLE_WORDS, globalcontext); + mfind->addAction(cmd, Constants::G_FIND_FLAGS); + connect(m_wholeWordAction, SIGNAL(triggered(bool)), this, SLOT(setWholeWord(bool))); + lineEditMenu->addAction(m_wholeWordAction); + + m_regularExpressionAction = new QAction(tr("Use Regular Expressions"), this); + m_regularExpressionAction->setIcon(QIcon(QLatin1String(":/find/images/regexp.png"))); + m_regularExpressionAction->setCheckable(true); + m_regularExpressionAction->setChecked(false); + cmd = Core::ActionManager::registerAction(m_regularExpressionAction, Constants::REGULAR_EXPRESSIONS, globalcontext); + mfind->addAction(cmd, Constants::G_FIND_FLAGS); + connect(m_regularExpressionAction, SIGNAL(triggered(bool)), this, SLOT(setRegularExpressions(bool))); + lineEditMenu->addAction(m_regularExpressionAction); + + m_preserveCaseAction = new QAction(tr("Preserve Case when Replacing"), this); + m_preserveCaseAction->setIcon(QPixmap(QLatin1String(":/find/images/preservecase.png"))); + m_preserveCaseAction->setCheckable(true); + m_preserveCaseAction->setChecked(false); + cmd = Core::ActionManager::registerAction(m_preserveCaseAction, Constants::PRESERVE_CASE, globalcontext); + mfind->addAction(cmd, Constants::G_FIND_FLAGS); + connect(m_preserveCaseAction, SIGNAL(triggered(bool)), this, SLOT(setPreserveCase(bool))); + lineEditMenu->addAction(m_preserveCaseAction); + + connect(m_currentDocumentFind, SIGNAL(candidateChanged()), this, SLOT(adaptToCandidate())); + connect(m_currentDocumentFind, SIGNAL(changed()), this, SLOT(updateToolBar())); + updateToolBar(); + + m_findIncrementalTimer.setSingleShot(true); + m_findStepTimer.setSingleShot(true); + connect(&m_findIncrementalTimer, SIGNAL(timeout()), + this, SLOT(invokeFindIncremental())); + connect(&m_findStepTimer, SIGNAL(timeout()), this, SLOT(invokeFindStep())); +} + +FindToolBar::~FindToolBar() +{ +} + +void FindToolBar::installEventFilters() +{ + if (!m_eventFiltersInstalled) { + m_findCompleter->popup()->installEventFilter(this); + m_ui.findEdit->installEventFilter(this); + m_ui.replaceEdit->installEventFilter(this); + this->installEventFilter(this); + m_eventFiltersInstalled = true; + } +} + +bool FindToolBar::shouldSetFocusOnKeyEvent(QKeyEvent *event) +{ + return event->key() == Qt::Key_Escape && !event->modifiers() + && !m_findCompleter->popup()->isVisible() + && !m_replaceCompleter->popup()->isVisible() + && m_currentDocumentFind->isEnabled(); +} + +bool FindToolBar::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *ke = static_cast(event); + if (ke->key() == Qt::Key_Down) { + if (obj == m_ui.findEdit) { + if (m_ui.findEdit->text().isEmpty()) + m_findCompleter->setCompletionPrefix(QString()); + m_findCompleter->complete(); + } else if (obj == m_ui.replaceEdit) { + if (m_ui.replaceEdit->text().isEmpty()) + m_replaceCompleter->setCompletionPrefix(QString()); + m_replaceCompleter->complete(); + } + } + } + + if ((obj == m_ui.findEdit || obj == m_findCompleter->popup()) + && event->type() == QEvent::KeyPress) { + QKeyEvent *ke = static_cast(event); + if (ke->key() == Qt::Key_Space && (ke->modifiers() & Utils::HostOsInfo::controlModifier())) { + QString completedText = m_currentDocumentFind->completedFindString(); + if (!completedText.isEmpty()) { + setFindText(completedText); + ke->accept(); + return true; + } + } + } else if (obj == this && event->type() == QEvent::ShortcutOverride) { + QKeyEvent *ke = static_cast(event); + if (shouldSetFocusOnKeyEvent(ke)) { + event->accept(); + return true; + } else if (ke->key() == Qt::Key_Space && (ke->modifiers() & Utils::HostOsInfo::controlModifier())) { + event->accept(); + return true; + } + } else if (obj == this && event->type() == QEvent::Hide) { + invokeClearResults(); + if (m_currentDocumentFind->isEnabled()) + m_currentDocumentFind->clearFindScope(); + } + return Utils::StyledBar::eventFilter(obj, event); +} + +void FindToolBar::keyPressEvent(QKeyEvent *event) +{ + if (shouldSetFocusOnKeyEvent(event)) { + if (setFocusToCurrentFindSupport()) + event->accept(); + return; + } + return Utils::StyledBar::keyPressEvent(event); +} + +void FindToolBar::adaptToCandidate() +{ + updateFindAction(); + if (findToolBarPlaceHolder() == Core::FindToolBarPlaceHolder::getCurrent()) + m_currentDocumentFind->acceptCandidate(); +} + +void FindToolBar::updateFindAction() +{ + bool enabled = m_currentDocumentFind->candidateIsEnabled(); + m_findInDocumentAction->setEnabled(enabled); + m_findNextSelectedAction->setEnabled(enabled); + m_findPreviousSelectedAction->setEnabled(enabled); +} + +void FindToolBar::updateToolBar() +{ + bool enabled = m_currentDocumentFind->isEnabled(); + bool replaceEnabled = enabled && m_currentDocumentFind->supportsReplace(); + m_findNextAction->setEnabled(enabled); + m_findPreviousAction->setEnabled(enabled); + + m_replaceAction->setEnabled(replaceEnabled); + m_replaceNextAction->setEnabled(replaceEnabled); + m_replacePreviousAction->setEnabled(replaceEnabled); + m_replaceAllAction->setEnabled(replaceEnabled); + + m_caseSensitiveAction->setEnabled(enabled); + m_wholeWordAction->setEnabled(enabled); + m_regularExpressionAction->setEnabled(enabled); + m_preserveCaseAction->setEnabled(replaceEnabled && !hasFindFlag(FindRegularExpression)); + if (QApplication::clipboard()->supportsFindBuffer()) + m_enterFindStringAction->setEnabled(enabled); + bool replaceFocus = m_ui.replaceEdit->hasFocus(); + m_ui.findEdit->setEnabled(enabled); + m_ui.findLabel->setEnabled(enabled); + + m_ui.replaceEdit->setEnabled(replaceEnabled); + m_ui.replaceLabel->setEnabled(replaceEnabled); + m_ui.replaceEdit->setVisible(replaceEnabled); + m_ui.replaceLabel->setVisible(replaceEnabled); + m_ui.replaceButtonsWidget->setVisible(replaceEnabled); + m_ui.advancedButton->setVisible(replaceEnabled); + layout()->invalidate(); + + if (!replaceEnabled && enabled && replaceFocus) + m_ui.findEdit->setFocus(); + updateIcons(); + updateFlagMenus(); +} + +void FindToolBar::invokeFindEnter() +{ + if (m_currentDocumentFind->isEnabled()) { + if (m_useFakeVim) + setFocusToCurrentFindSupport(); + else + invokeFindNext(); + } +} + +void FindToolBar::invokeReplaceEnter() +{ + if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) + invokeReplaceNext(); +} + +void FindToolBar::invokeClearResults() +{ + if (m_currentDocumentFind->isEnabled()) + m_currentDocumentFind->clearResults(); +} + + +void FindToolBar::invokeFindNext() +{ + setFindFlag(FindBackward, false); + invokeFindStep(); +} + +void FindToolBar::invokeFindPrevious() +{ + setFindFlag(FindBackward, true); + invokeFindStep(); +} + +QString FindToolBar::getFindText() +{ + return m_ui.findEdit->text(); +} + +QString FindToolBar::getReplaceText() +{ + return m_ui.replaceEdit->text(); +} + +void FindToolBar::setFindText(const QString &text) +{ + disconnect(m_ui.findEdit, SIGNAL(textChanged(QString)), this, SLOT(invokeFindIncremental())); + if (hasFindFlag(FindRegularExpression)) + m_ui.findEdit->setText(QRegExp::escape(text)); + else + m_ui.findEdit->setText(text); + connect(m_ui.findEdit, SIGNAL(textChanged(QString)), this, SLOT(invokeFindIncremental())); +} + +void FindToolBar::selectFindText() +{ + m_ui.findEdit->selectAll(); +} + +void FindToolBar::invokeFindStep() +{ + m_findStepTimer.stop(); + m_findIncrementalTimer.stop(); + if (m_currentDocumentFind->isEnabled()) { + m_plugin->updateFindCompletion(getFindText()); + IFindSupport::Result result = + m_currentDocumentFind->findStep(getFindText(), effectiveFindFlags()); + if (result == IFindSupport::NotYetFound) + m_findStepTimer.start(50); + } +} + +void FindToolBar::invokeFindIncremental() +{ + m_findIncrementalTimer.stop(); + m_findStepTimer.stop(); + if (m_currentDocumentFind->isEnabled()) { + QString text = getFindText(); + IFindSupport::Result result = + m_currentDocumentFind->findIncremental(text, effectiveFindFlags()); + if (result == IFindSupport::NotYetFound) + m_findIncrementalTimer.start(50); + if (text.isEmpty()) + m_currentDocumentFind->clearResults(); + } +} + +void FindToolBar::invokeReplace() +{ + setFindFlag(FindBackward, false); + if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) { + m_plugin->updateFindCompletion(getFindText()); + m_plugin->updateReplaceCompletion(getReplaceText()); + m_currentDocumentFind->replace(getFindText(), getReplaceText(), effectiveFindFlags()); + } +} + +void FindToolBar::invokeReplaceNext() +{ + setFindFlag(FindBackward, false); + invokeReplaceStep(); +} + +void FindToolBar::invokeReplacePrevious() +{ + setFindFlag(FindBackward, true); + invokeReplaceStep(); +} + +void FindToolBar::invokeReplaceStep() +{ + if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) { + m_plugin->updateFindCompletion(getFindText()); + m_plugin->updateReplaceCompletion(getReplaceText()); + m_currentDocumentFind->replaceStep(getFindText(), getReplaceText(), effectiveFindFlags()); + } +} + +void FindToolBar::invokeReplaceAll() +{ + m_plugin->updateFindCompletion(getFindText()); + m_plugin->updateReplaceCompletion(getReplaceText()); + if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) + m_currentDocumentFind->replaceAll(getFindText(), getReplaceText(), effectiveFindFlags()); +} + +void FindToolBar::invokeResetIncrementalSearch() +{ + m_findIncrementalTimer.stop(); + m_findStepTimer.stop(); + if (m_currentDocumentFind->isEnabled()) + m_currentDocumentFind->resetIncrementalSearch(); +} + + +void FindToolBar::putSelectionToFindClipboard() +{ + const QString text = m_currentDocumentFind->currentFindString(); + QApplication::clipboard()->setText(text, QClipboard::FindBuffer); + setFindText(text); +} + + +void FindToolBar::updateFromFindClipboard() +{ + if (QApplication::clipboard()->supportsFindBuffer()) { + const bool blocks = m_ui.findEdit->blockSignals(true); + setFindText(QApplication::clipboard()->text(QClipboard::FindBuffer)); + m_ui.findEdit->blockSignals(blocks); + } +} + +void FindToolBar::findFlagsChanged() +{ + updateIcons(); + updateFlagMenus(); + invokeClearResults(); + if (isVisible()) + m_currentDocumentFind->highlightAll(getFindText(), effectiveFindFlags()); +} + +void FindToolBar::updateIcons() +{ + FindFlags effectiveFlags = effectiveFindFlags(); + bool casesensitive = effectiveFlags & FindCaseSensitively; + bool wholewords = effectiveFlags & FindWholeWords; + bool regexp = effectiveFlags & FindRegularExpression; + bool preserveCase = effectiveFlags & FindPreserveCase; + if (!casesensitive && !wholewords && !regexp && !preserveCase) { + QPixmap pixmap(17, 17); + pixmap.fill(Qt::transparent); + QPainter painter(&pixmap); + const QPixmap mag = QPixmap(QLatin1String(Core::Constants::ICON_MAGNIFIER)); + painter.drawPixmap(0, (pixmap.height() - mag.height()) / 2, mag); + m_ui.findEdit->setButtonPixmap(Utils::FancyLineEdit::Left, pixmap); + } else { + m_ui.findEdit->setButtonPixmap(Utils::FancyLineEdit::Left, + IFindFilter::pixmapForFindFlags(effectiveFlags)); + } +} + +FindFlags FindToolBar::effectiveFindFlags() +{ + FindFlags supportedFlags; + bool supportsReplace = true; + if (m_currentDocumentFind->isEnabled()) { + supportedFlags = m_currentDocumentFind->supportedFindFlags(); + supportsReplace = m_currentDocumentFind->supportsReplace(); + } else { + supportedFlags = (FindFlags)0xFFFFFF; + } + if (!supportsReplace || m_findFlags & FindRegularExpression) + supportedFlags &= ~FindPreserveCase; + return supportedFlags & m_findFlags; +} + +void FindToolBar::updateFlagMenus() +{ + bool wholeOnly = ((m_findFlags & FindWholeWords)); + bool sensitive = ((m_findFlags & FindCaseSensitively)); + bool regexp = ((m_findFlags & FindRegularExpression)); + bool preserveCase = ((m_findFlags & FindPreserveCase)); + if (m_wholeWordAction->isChecked() != wholeOnly) + m_wholeWordAction->setChecked(wholeOnly); + if (m_caseSensitiveAction->isChecked() != sensitive) + m_caseSensitiveAction->setChecked(sensitive); + if (m_regularExpressionAction->isChecked() != regexp) + m_regularExpressionAction->setChecked(regexp); + if (m_preserveCaseAction->isChecked() != preserveCase) + m_preserveCaseAction->setChecked(preserveCase); + FindFlags supportedFlags; + if (m_currentDocumentFind->isEnabled()) + supportedFlags = m_currentDocumentFind->supportedFindFlags(); + m_wholeWordAction->setEnabled(supportedFlags & FindWholeWords); + m_caseSensitiveAction->setEnabled(supportedFlags & FindCaseSensitively); + m_regularExpressionAction->setEnabled(supportedFlags & FindRegularExpression); + bool replaceEnabled = m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace(); + m_preserveCaseAction->setEnabled((supportedFlags & FindPreserveCase) && !regexp && replaceEnabled); +} + +bool FindToolBar::setFocusToCurrentFindSupport() +{ + return m_currentDocumentFind->setFocusToCurrentFindSupport(); +} + +void FindToolBar::hideAndResetFocus() +{ + m_currentDocumentFind->setFocusToCurrentFindSupport(); + hide(); +} + +Core::FindToolBarPlaceHolder *FindToolBar::findToolBarPlaceHolder() const +{ + QList placeholders = ExtensionSystem::PluginManager::getObjects(); + QWidget *candidate = QApplication::focusWidget(); + while (candidate) { + foreach (Core::FindToolBarPlaceHolder *ph, placeholders) { + if (ph->owner() == candidate) + return ph; + } + candidate = candidate->parentWidget(); + } + return 0; +} + +void FindToolBar::openFind(bool focus) +{ + setBackward(false); + openFindToolBar(focus); +} + +void FindToolBar::openFindToolBar(bool focus) +{ + installEventFilters(); + if (!m_currentDocumentFind->candidateIsEnabled()) + return; + Core::FindToolBarPlaceHolder *holder = findToolBarPlaceHolder(); + if (!holder) + return; + Core::FindToolBarPlaceHolder *previousHolder = Core::FindToolBarPlaceHolder::getCurrent(); + if (previousHolder) + previousHolder->setWidget(0); + Core::FindToolBarPlaceHolder::setCurrent(holder); + m_currentDocumentFind->acceptCandidate(); + holder->setWidget(this); + holder->setVisible(true); + setVisible(true); + if (focus) + setFocus(); + QString text = m_currentDocumentFind->currentFindString(); + if (!text.isEmpty()) + setFindText(text); + m_currentDocumentFind->defineFindScope(); + m_currentDocumentFind->highlightAll(getFindText(), effectiveFindFlags()); + if (focus) + selectFindText(); +} + +void FindToolBar::findNextSelected() +{ + openFind(false); + invokeFindNext(); +} + +void FindToolBar::findPreviousSelected() +{ + openFind(false); + invokeFindPrevious(); +} + +bool FindToolBar::focusNextPrevChild(bool next) +{ + // close tab order change + if (next && m_ui.replaceAllButton->hasFocus()) + m_ui.findEdit->setFocus(Qt::TabFocusReason); + else if (!next && m_ui.findEdit->hasFocus()) + m_ui.replaceAllButton->setFocus(Qt::TabFocusReason); + else + return Utils::StyledBar::focusNextPrevChild(next); + return true; +} + +void FindToolBar::writeSettings() +{ + QSettings *settings = Core::ICore::settings(); + settings->beginGroup(QLatin1String("Find")); + settings->beginGroup(QLatin1String("FindToolBar")); + settings->setValue(QLatin1String("Backward"), QVariant((m_findFlags & FindBackward) != 0)); + settings->setValue(QLatin1String("CaseSensitively"), QVariant((m_findFlags & FindCaseSensitively) != 0)); + settings->setValue(QLatin1String("WholeWords"), QVariant((m_findFlags & FindWholeWords) != 0)); + settings->setValue(QLatin1String("RegularExpression"), QVariant((m_findFlags & FindRegularExpression) != 0)); + settings->setValue(QLatin1String("PreserveCase"), QVariant((m_findFlags & FindPreserveCase) != 0)); + settings->endGroup(); + settings->endGroup(); +} + +void FindToolBar::readSettings() +{ + QSettings *settings = Core::ICore::settings(); + settings->beginGroup(QLatin1String("Find")); + settings->beginGroup(QLatin1String("FindToolBar")); + FindFlags flags; + if (settings->value(QLatin1String("Backward"), false).toBool()) + flags |= FindBackward; + if (settings->value(QLatin1String("CaseSensitively"), false).toBool()) + flags |= FindCaseSensitively; + if (settings->value(QLatin1String("WholeWords"), false).toBool()) + flags |= FindWholeWords; + if (settings->value(QLatin1String("RegularExpression"), false).toBool()) + flags |= FindRegularExpression; + if (settings->value(QLatin1String("PreserveCase"), false).toBool()) + flags |= FindPreserveCase; + settings->endGroup(); + settings->endGroup(); + m_findFlags = flags; + findFlagsChanged(); +} + +void FindToolBar::setUseFakeVim(bool on) +{ + m_useFakeVim = on; +} + +void FindToolBar::setFindFlag(FindFlag flag, bool enabled) +{ + bool hasFlag = hasFindFlag(flag); + if ((hasFlag && enabled) || (!hasFlag && !enabled)) + return; + if (enabled) + m_findFlags |= flag; + else + m_findFlags &= ~flag; + if (flag != FindBackward) + findFlagsChanged(); +} + +bool FindToolBar::hasFindFlag(FindFlag flag) +{ + return m_findFlags & flag; +} + +void FindToolBar::setCaseSensitive(bool sensitive) +{ + setFindFlag(FindCaseSensitively, sensitive); +} + +void FindToolBar::setWholeWord(bool wholeOnly) +{ + setFindFlag(FindWholeWords, wholeOnly); +} + +void FindToolBar::setRegularExpressions(bool regexp) +{ + setFindFlag(FindRegularExpression, regexp); +} + +void FindToolBar::setPreserveCase(bool preserveCase) +{ + setFindFlag(FindPreserveCase, preserveCase); +} + +void FindToolBar::setBackward(bool backward) +{ + setFindFlag(FindBackward, backward); +} diff --git a/src/plugins/coreplugin/find/findtoolbar.h b/src/plugins/coreplugin/find/findtoolbar.h new file mode 100644 index 00000000000..fb90dfbf1f7 --- /dev/null +++ b/src/plugins/coreplugin/find/findtoolbar.h @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef FINDTOOLBAR_H +#define FINDTOOLBAR_H + +#include "ui_findwidget.h" +#include "currentdocumentfind.h" + +#include + +#include + +namespace Core { + +class FindToolBarPlaceHolder; +class FindPlugin; + +namespace Internal { + +class FindToolBar : public Utils::StyledBar +{ + Q_OBJECT + +public: + explicit FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumentFind); + ~FindToolBar(); + + void readSettings(); + void writeSettings(); + + void openFindToolBar(bool focus = true); + void setUseFakeVim(bool on); + +public slots: + void setBackward(bool backward); + +private slots: + void invokeFindNext(); + void invokeFindPrevious(); + void invokeFindStep(); + void invokeReplace(); + void invokeReplaceNext(); + void invokeReplacePrevious(); + void invokeReplaceStep(); + void invokeReplaceAll(); + void invokeResetIncrementalSearch(); + + void invokeFindIncremental(); + void invokeFindEnter(); + void invokeReplaceEnter(); + void putSelectionToFindClipboard(); + void updateFromFindClipboard(); + + void hideAndResetFocus(); + void openFind(bool focus = true); + void findNextSelected(); + void findPreviousSelected(); + void updateFindAction(); + void updateToolBar(); + void findFlagsChanged(); + + void setCaseSensitive(bool sensitive); + void setWholeWord(bool wholeOnly); + void setRegularExpressions(bool regexp); + void setPreserveCase(bool preserveCase); + + void adaptToCandidate(); + +protected: + bool focusNextPrevChild(bool next); + void keyPressEvent(QKeyEvent *event); + +private: + void installEventFilters(); + void invokeClearResults(); + bool setFocusToCurrentFindSupport(); + void setFindFlag(FindFlag flag, bool enabled); + bool hasFindFlag(FindFlag flag); + FindFlags effectiveFindFlags(); + Core::FindToolBarPlaceHolder *findToolBarPlaceHolder() const; + + bool eventFilter(QObject *obj, QEvent *event); + void setFindText(const QString &text); + QString getFindText(); + QString getReplaceText(); + void selectFindText(); + void updateIcons(); + void updateFlagMenus(); + + bool shouldSetFocusOnKeyEvent(QKeyEvent *event); + + FindPlugin *m_plugin; + CurrentDocumentFind *m_currentDocumentFind; + Ui::FindWidget m_ui; + QCompleter *m_findCompleter; + QCompleter *m_replaceCompleter; + QAction *m_findInDocumentAction; + QAction *m_findNextSelectedAction; + QAction *m_findPreviousSelectedAction; + QAction *m_enterFindStringAction; + QAction *m_findNextAction; + QAction *m_findPreviousAction; + QAction *m_replaceAction; + QAction *m_replaceNextAction; + QAction *m_replacePreviousAction; + QAction *m_replaceAllAction; + QAction *m_caseSensitiveAction; + QAction *m_wholeWordAction; + QAction *m_regularExpressionAction; + QAction *m_preserveCaseAction; + FindFlags m_findFlags; + + QTimer m_findIncrementalTimer; + QTimer m_findStepTimer; + bool m_useFakeVim; + bool m_eventFiltersInstalled; +}; + +} // namespace Internal +} // namespace Core + +#endif // FINDTOOLBAR_H diff --git a/src/plugins/coreplugin/find/findtoolwindow.cpp b/src/plugins/coreplugin/find/findtoolwindow.cpp new file mode 100644 index 00000000000..66521dc32b2 --- /dev/null +++ b/src/plugins/coreplugin/find/findtoolwindow.cpp @@ -0,0 +1,264 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "findtoolwindow.h" +#include "ifindfilter.h" +#include "findplugin.h" + +#include + +#include +#include +#include +#include +#include + +using namespace Core; +using namespace Core::Internal; + +static FindToolWindow *m_instance = 0; + +FindToolWindow::FindToolWindow(FindPlugin *plugin, QWidget *parent) + : QWidget(parent), + m_plugin(plugin), + m_findCompleter(new QCompleter(this)), + m_currentFilter(0), + m_configWidget(0) +{ + m_instance = this; + m_ui.setupUi(this); + m_ui.searchTerm->setPlaceholderText(QString()); + setFocusProxy(m_ui.searchTerm); + + connect(m_ui.searchButton, SIGNAL(clicked()), this, SLOT(search())); + connect(m_ui.replaceButton, SIGNAL(clicked()), this, SLOT(replace())); + connect(m_ui.matchCase, SIGNAL(toggled(bool)), m_plugin, SLOT(setCaseSensitive(bool))); + connect(m_ui.wholeWords, SIGNAL(toggled(bool)), m_plugin, SLOT(setWholeWord(bool))); + connect(m_ui.regExp, SIGNAL(toggled(bool)), m_plugin, SLOT(setRegularExpression(bool))); + connect(m_ui.filterList, SIGNAL(activated(int)), this, SLOT(setCurrentFilter(int))); + connect(m_ui.searchTerm, SIGNAL(textChanged(QString)), this, SLOT(updateButtonStates())); + + m_findCompleter->setModel(m_plugin->findCompletionModel()); + m_ui.searchTerm->setSpecialCompleter(m_findCompleter); + m_ui.searchTerm->installEventFilter(this); + QVBoxLayout *layout = new QVBoxLayout; + layout->setMargin(0); + layout->setSpacing(0); + m_ui.configWidget->setLayout(layout); + updateButtonStates(); + + connect(m_plugin, SIGNAL(findFlagsChanged()), this, SLOT(updateFindFlags())); +} + +FindToolWindow::~FindToolWindow() +{ + qDeleteAll(m_configWidgets); +} + +FindToolWindow *FindToolWindow::instance() +{ + return m_instance; +} + +bool FindToolWindow::event(QEvent *event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent *ke = static_cast(event); + if ((ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) + && (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::KeypadModifier)) { + ke->accept(); + search(); + return true; + } + } + return QWidget::event(event); +} + +bool FindToolWindow::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == m_ui.searchTerm && event->type() == QEvent::KeyPress) { + QKeyEvent *ke = static_cast(event); + if (ke->key() == Qt::Key_Down) { + if (m_ui.searchTerm->text().isEmpty()) + m_findCompleter->setCompletionPrefix(QString()); + m_findCompleter->complete(); + } + } + return QWidget::eventFilter(obj, event); +} + +void FindToolWindow::updateButtonStates() +{ + bool filterEnabled = m_currentFilter && m_currentFilter->isEnabled(); + bool enabled = !m_ui.searchTerm->text().isEmpty() && filterEnabled; + m_ui.searchButton->setEnabled(enabled); + m_ui.replaceButton->setEnabled(m_currentFilter + && m_currentFilter->isReplaceSupported() && enabled); + if (m_configWidget) + m_configWidget->setEnabled(filterEnabled); + + m_ui.matchCase->setEnabled(filterEnabled + && (m_currentFilter->supportedFindFlags() & FindCaseSensitively)); + m_ui.wholeWords->setEnabled(filterEnabled + && (m_currentFilter->supportedFindFlags() & FindWholeWords)); + m_ui.regExp->setEnabled(filterEnabled + && (m_currentFilter->supportedFindFlags() & FindRegularExpression)); + m_ui.searchTerm->setEnabled(filterEnabled); +} + +void FindToolWindow::updateFindFlags() +{ + m_ui.matchCase->setChecked(m_plugin->hasFindFlag(FindCaseSensitively)); + m_ui.wholeWords->setChecked(m_plugin->hasFindFlag(FindWholeWords)); + m_ui.regExp->setChecked(m_plugin->hasFindFlag(FindRegularExpression)); +} + + +void FindToolWindow::setFindFilters(const QList &filters) +{ + qDeleteAll(m_configWidgets); + m_configWidgets.clear(); + m_filters = filters; + m_ui.filterList->clear(); + QStringList names; + foreach (IFindFilter *filter, filters) { + names << filter->displayName(); + m_configWidgets.append(filter->createConfigWidget()); + } + m_ui.filterList->addItems(names); + if (m_filters.size() > 0) + setCurrentFilter(0); +} + +void FindToolWindow::setFindText(const QString &text) +{ + m_ui.searchTerm->setText(text); +} + +void FindToolWindow::setCurrentFilter(IFindFilter *filter) +{ + if (!filter) + filter = m_currentFilter; + int index = m_filters.indexOf(filter); + if (index >= 0) + setCurrentFilter(index); + updateFindFlags(); + m_ui.searchTerm->setFocus(); + m_ui.searchTerm->selectAll(); +} + +void FindToolWindow::setCurrentFilter(int index) +{ + m_ui.filterList->setCurrentIndex(index); + for (int i = 0; i < m_configWidgets.size(); ++i) { + QWidget *configWidget = m_configWidgets.at(i); + if (i == index) { + m_configWidget = configWidget; + if (m_currentFilter) + disconnect(m_currentFilter, SIGNAL(enabledChanged(bool)), this, SLOT(updateButtonStates())); + m_currentFilter = m_filters.at(i); + connect(m_currentFilter, SIGNAL(enabledChanged(bool)), this, SLOT(updateButtonStates())); + updateButtonStates(); + if (m_configWidget) + m_ui.configWidget->layout()->addWidget(m_configWidget); + } else { + if (configWidget) + configWidget->setParent(0); + } + } + QWidget *w = m_ui.configWidget; + while (w) { + QScrollArea *sa = qobject_cast(w); + if (sa) { + sa->updateGeometry(); + break; + } + w = w->parentWidget(); + } + for (w = m_configWidget ? m_configWidget : m_ui.configWidget; w; w = w->parentWidget()) { + if (w->layout()) + w->layout()->activate(); + } +} + +void FindToolWindow::acceptAndGetParameters(QString *term, IFindFilter **filter) +{ + if (filter) + *filter = 0; + m_plugin->updateFindCompletion(m_ui.searchTerm->text()); + int index = m_ui.filterList->currentIndex(); + QString searchTerm = m_ui.searchTerm->text(); + if (term) + *term = searchTerm; + if (searchTerm.isEmpty() || index < 0) + return; + if (filter) + *filter = m_filters.at(index); +} + +void FindToolWindow::search() +{ + QString term; + IFindFilter *filter; + acceptAndGetParameters(&term, &filter); + if (filter) + filter->findAll(term, m_plugin->findFlags()); +} + +void FindToolWindow::replace() +{ + QString term; + IFindFilter *filter; + acceptAndGetParameters(&term, &filter); + filter->replaceAll(term, m_plugin->findFlags()); +} + +void FindToolWindow::writeSettings() +{ + QSettings *settings = Core::ICore::settings(); + settings->beginGroup(QLatin1String("Find")); + settings->setValue(QLatin1String("CurrentFilter"), m_currentFilter ? m_currentFilter->id() : QString()); + foreach (IFindFilter *filter, m_filters) + filter->writeSettings(settings); + settings->endGroup(); +} + +void FindToolWindow::readSettings() +{ + QSettings *settings = Core::ICore::settings(); + settings->beginGroup(QLatin1String("Find")); + const QString currentFilter = settings->value(QLatin1String("CurrentFilter")).toString(); + for (int i = 0; i < m_filters.size(); ++i) { + IFindFilter *filter = m_filters.at(i); + filter->readSettings(settings); + if (filter->id() == currentFilter) + setCurrentFilter(i); + } + settings->endGroup(); +} diff --git a/src/plugins/coreplugin/find/findtoolwindow.h b/src/plugins/coreplugin/find/findtoolwindow.h new file mode 100644 index 00000000000..e78d0075ecd --- /dev/null +++ b/src/plugins/coreplugin/find/findtoolwindow.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef FINDTOOLWINDOW_H +#define FINDTOOLWINDOW_H + +#include "ui_finddialog.h" +#include "findplugin.h" + +#include + +QT_FORWARD_DECLARE_CLASS(QCompleter) + +namespace Core { +class IFindFilter; + +namespace Internal { + +class FindToolWindow : public QWidget +{ + Q_OBJECT + +public: + explicit FindToolWindow(FindPlugin *plugin, QWidget *parent = 0); + ~FindToolWindow(); + static FindToolWindow *instance(); + + void setFindFilters(const QList &filters); + + void setFindText(const QString &text); + void setCurrentFilter(IFindFilter *filter); + void readSettings(); + void writeSettings(); + +protected: + bool event(QEvent *event); + bool eventFilter(QObject *obj, QEvent *event); + +private slots: + void search(); + void replace(); + void setCurrentFilter(int index); + void updateButtonStates(); + void updateFindFlags(); + +private: + void acceptAndGetParameters(QString *term, IFindFilter **filter); + + Ui::FindDialog m_ui; + FindPlugin *m_plugin; + QList m_filters; + QCompleter *m_findCompleter; + QWidgetList m_configWidgets; + IFindFilter *m_currentFilter; + QWidget *m_configWidget; +}; + +} // namespace Internal +} // namespace Core + +#endif // FINDTOOLWINDOW_H diff --git a/src/plugins/coreplugin/find/findwidget.ui b/src/plugins/coreplugin/find/findwidget.ui new file mode 100644 index 00000000000..4472102781f --- /dev/null +++ b/src/plugins/coreplugin/find/findwidget.ui @@ -0,0 +1,292 @@ + + + Core::Internal::FindWidget + + + + 0 + 0 + 681 + 88 + + + + Find + + + + 5 + + + 2 + + + 0 + + + 2 + + + 3 + + + 0 + + + + + Find: + + + + + + + + 100 + 0 + + + + + + + + + 3 + + + 0 + + + + + Qt::NoFocus + + + Qt::LeftArrow + + + + + + + + + + Qt::NoFocus + + + Qt::RightArrow + + + + + + + Qt::Horizontal + + + + 40 + 0 + + + + + + + + ... + + + + + + + + + + 0 + + + + + Replace with: + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + + 0 + + + + + + 100 + 0 + + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + + 3 + + + 0 + + + + + + 0 + 0 + + + + + 3 + + + 0 + + + + + Qt::NoFocus + + + Replace + + + Qt::ToolButtonTextOnly + + + Qt::LeftArrow + + + + + + + + + + Qt::NoFocus + + + Replace && Find + + + Qt::ToolButtonTextOnly + + + Qt::RightArrow + + + + + + + + + + Replace All + + + Qt::ToolButtonTextOnly + + + + + + + + + + 0 + + + + + Advanced... + + + Qt::ToolButtonTextOnly + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + + + + + Utils::FancyLineEdit + QLineEdit +
utils/fancylineedit.h
+
+ + Utils::FilterLineEdit + Utils::FancyLineEdit +
utils/filterlineedit.h
+
+
+ + findEdit + replaceEdit + close + replaceAllButton + + + +
diff --git a/src/plugins/coreplugin/find/ifindfilter.cpp b/src/plugins/coreplugin/find/ifindfilter.cpp new file mode 100644 index 00000000000..c9fda43f2a4 --- /dev/null +++ b/src/plugins/coreplugin/find/ifindfilter.cpp @@ -0,0 +1,285 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ifindfilter.h" + +#include +#include + +/*! + \class Find::IFindFilter + \brief The IFindFilter class is the base class for find implementations + that are invoked by selecting \gui Edit > \gui {Find/Replace} > + \gui {Advanced Find}. + + Implementations of this class add an additional \gui Scope to the \gui {Advanced + Find} dialog. That can be any search that requires the user to provide + a text based search term (potentially with find flags like + searching case sensitively or using regular expressions). Existing + scopes are \gui {All Projects} that searches from all files in all projects + and \gui {Files on File System} where the user provides a directory and file + patterns to search. + + To make your find scope available to the user, you need to implement this + class, and register an instance of your subclass in the plugin manager. + + A common way to present the search results to the user, is to use the + shared \gui{Search Results} panel. + + If you want to implement a find filter that is doing a file based text + search, you should use Find::BaseFileFind, which already implements all + the details for this kind of search, only requiring you to provide an + iterator over the file names of the files that should be searched. + + If you want to implement a more specialized find filter, you need to: + \list + \li Start your search in a separate thread + \li Make this known to the Core::ProgressManager, for a progress bar + and the ability to cancel the search + \li Interface with the shared \gui{Search Results} panel, to show + the search results, handle the event that the user click on one + of the search result items, and possible handle a global replace + of all or some of the search result items. + \endlist + + Luckily QtConcurrent and the search result panel provide the frameworks + that make it relatively easy to implement, + while ensuring a common way for the user. + + The common pattern is roughly this: + + Implement the actual search within a QtConcurrent based function, that is + a function that takes a \c{QFutureInterface &future} + as the first parameter and the other information needed for the search + as additional parameters. It should set useful progress information + on the QFutureInterface, regularly check for \c{future.isPaused()} + and \c{future.isCanceled()}, and report the search results + (possibly in chunks) via \c{future.reportResult}. + + In the find filter's find/replaceAll function, get the shared + \gui{Search Results} window, initiate a new search and connect the + signals for handling selection of results and the replace action + (see the Core::SearchResultWindow class for details). + Start your search implementation via the corresponding QtConcurrent + functions. Add the returned QFuture object to the Core::ProgressManager. + Use a QFutureWatcher on the returned QFuture object to receive a signal + when your search implementation reports search results, and add these + to the shared \gui{Search Results} window. +*/ + +/*! + \fn IFindFilter::~IFindFilter() + \internal +*/ + +/*! + \fn QString IFindFilter::id() const + Returns the unique string identifier for this find filter. + + Usually should be something like "MyPlugin.MyFindFilter". +*/ + +/*! + \fn QString IFindFilter::displayName() const + Returns the name of the find filter or scope as presented to the user. + + This is the name that appears in the scope selection combo box, for example. + Always return a translatable string (that is, use tr() for the return value). +*/ + +/*! + \fn bool IFindFilter::isEnabled() const + Returns whether the user should be able to select this find filter + at the moment. + + This is used for the \gui {Current Projects} scope, for example. If the user + has not + opened a project, the scope is disabled. + + \sa changed() +*/ + +/*! + \fn QKeySequence IFindFilter::defaultShortcut() const + Returns the shortcut that can be used to open the advanced find + dialog with this filter or scope preselected. + + Usually return an empty shortcut here, the user can still choose and + assign a specific shortcut to this find scope via the preferences. +*/ + +/*! + \fn bool IFindFilter::isReplaceSupported() const + Returns whether the find filter supports search and replace. + + The default value is false, override this function to return \c true, if + your find filter supports global search and replace. +*/ + +/*! + \fn void IFindFilter::findAll(const QString &txt, Core::FindFlags findFlags) + This function is called when the user selected this find scope and + initiated a search. + + You should start a thread which actually performs the search for \a txt + using the given \a findFlags + (add it to Core::ProgressManager for a progress bar!) and presents the + search results to the user (using the \gui{Search Results} output pane). + For more information, see the descriptions of this class, + Core::ProgressManager, and Core::SearchResultWindow. + + \sa replaceAll() + \sa Core::ProgressManager + \sa Core::SearchResultWindow +*/ + +/*! + \fn void IFindFilter::replaceAll(const QString &txt, Core::FindFlags findFlags) + Override this function if you want to support search and replace. + + This function is called when the user selected this find scope and + initiated a search and replace. + The default implementation does nothing. + + You should start a thread which actually performs the search for \a txt + using the given \a findFlags + (add it to Core::ProgressManager for a progress bar!) and presents the + search results to the user (using the \gui{Search Results} output pane). + For more information see the descriptions of this class, + Core::ProgressManager, and Core::SearchResultWindow. + + \sa findAll() + \sa Core::ProgressManager + \sa Core::SearchResultWindow +*/ + +/*! + \fn QWidget *IFindFilter::createConfigWidget() + Returns a widget that contains additional controls for options + for this find filter. + + The widget will be shown below the common options in the \gui {Advanced Find} + dialog. It will be reparented and deleted by the find plugin. +*/ + +/*! + \fn void IFindFilter::writeSettings(QSettings *settings) + Called at shutdown to write the state of the additional options + for this find filter to the \a settings. +*/ + +/*! + \fn void IFindFilter::readSettings(QSettings *settings) + Called at startup to read the state of the additional options + for this find filter from the \a settings. +*/ + +/*! + \fn void IFindFilter::enabledChanged(bool enabled) + + Signals that the enabled state of this find filter has changed. +*/ + +/*! + \fn Core::FindFlags BaseTextFind::supportedFindFlags() const + Returns the find flags, like whole words or regular expressions, + that this find filter supports. + + Depending on the returned value, the default find option widgets are + enabled or disabled. + The default is Find::FindCaseSensitively, Find::FindRegularExpression + and Find::FindWholeWords +*/ + +namespace Core { + +FindFlags IFindFilter::supportedFindFlags() const +{ + return FindCaseSensitively + | FindRegularExpression | FindWholeWords; +} + +QPixmap IFindFilter::pixmapForFindFlags(FindFlags flags) +{ + static const QPixmap casesensitiveIcon = QPixmap(QLatin1String(":/find/images/casesensitively.png")); + static const QPixmap regexpIcon = QPixmap(QLatin1String(":/find/images/regexp.png")); + static const QPixmap wholewordsIcon = QPixmap(QLatin1String(":/find/images/wholewords.png")); + static const QPixmap preservecaseIcon = QPixmap(QLatin1String(":/find/images/preservecase.png")); + bool casesensitive = flags & FindCaseSensitively; + bool wholewords = flags & FindWholeWords; + bool regexp = flags & FindRegularExpression; + bool preservecase = flags & FindPreserveCase; + int width = 0; + if (casesensitive) width += 6; + if (wholewords) width += 6; + if (regexp) width += 6; + if (preservecase) width += 6; + if (width > 0) --width; + QPixmap pixmap(width, 17); + pixmap.fill(Qt::transparent); + QPainter painter(&pixmap); + int x = 0; + + if (casesensitive) { + painter.drawPixmap(x - 6, 0, casesensitiveIcon); + x += 6; + } + if (wholewords) { + painter.drawPixmap(x - 6, 0, wholewordsIcon); + x += 6; + } + if (regexp) { + painter.drawPixmap(x - 6, 0, regexpIcon); + x += 6; + } + if (preservecase) + painter.drawPixmap(x - 6, 0, preservecaseIcon); + return pixmap; +} + +QString IFindFilter::descriptionForFindFlags(FindFlags flags) +{ + QStringList flagStrings; + if (flags & FindCaseSensitively) + flagStrings.append(tr("Case sensitive")); + if (flags & FindWholeWords) + flagStrings.append(tr("Whole words")); + if (flags & FindRegularExpression) + flagStrings.append(tr("Regular expressions")); + if (flags & FindPreserveCase) + flagStrings.append(tr("Preserve case")); + QString description = tr("Flags: %1"); + if (flagStrings.isEmpty()) + description = description.arg(tr("None")); + else + description = description.arg(flagStrings.join(tr(", "))); + return description; +} + +} // namespace Core diff --git a/src/plugins/coreplugin/find/ifindfilter.h b/src/plugins/coreplugin/find/ifindfilter.h new file mode 100644 index 00000000000..00bb66a04ec --- /dev/null +++ b/src/plugins/coreplugin/find/ifindfilter.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef IFINDFILTER_H +#define IFINDFILTER_H + +#include "textfindconstants.h" + +QT_BEGIN_NAMESPACE +class QWidget; +class QSettings; +class QKeySequence; +class Pixmap; +QT_END_NAMESPACE + +namespace Core { + +class CORE_EXPORT IFindFilter : public QObject +{ + Q_OBJECT +public: + + virtual ~IFindFilter() {} + + virtual QString id() const = 0; + virtual QString displayName() const = 0; + /// + virtual bool isEnabled() const = 0; + virtual QKeySequence defaultShortcut() const; + virtual bool isReplaceSupported() const { return false; } + virtual FindFlags supportedFindFlags() const; + + virtual void findAll(const QString &txt, FindFlags findFlags) = 0; + virtual void replaceAll(const QString &txt, FindFlags findFlags) + { Q_UNUSED(txt) Q_UNUSED(findFlags) } + + virtual QWidget *createConfigWidget() { return 0; } + virtual void writeSettings(QSettings *settings) { Q_UNUSED(settings) } + virtual void readSettings(QSettings *settings) { Q_UNUSED(settings) } + + static QPixmap pixmapForFindFlags(FindFlags flags); + static QString descriptionForFindFlags(FindFlags flags); +signals: + void enabledChanged(bool enabled); +}; + +} // namespace Core + +#endif // IFINDFILTER_H diff --git a/src/plugins/coreplugin/find/ifindsupport.cpp b/src/plugins/coreplugin/find/ifindsupport.cpp new file mode 100644 index 00000000000..f057352de63 --- /dev/null +++ b/src/plugins/coreplugin/find/ifindsupport.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ifindsupport.h" + +#include +#include +#include +#include +#include + +namespace Core { +namespace Internal { + +class WrapIndicator : public QWidget +{ + Q_OBJECT + Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity USER true) + +public: + WrapIndicator(QWidget *parent = 0) + : QWidget(parent), + m_opacity(1.0) + { + if (parent) + setGeometry(QRect(parent->rect().center() - QPoint(25, 25), + parent->rect().center() + QPoint(25, 25))); + } + + qreal opacity() const { return m_opacity; } + void setOpacity(qreal value) { m_opacity = value; update(); } + + void run() + { + show(); + QTimer::singleShot(300, this, SLOT(runInternal())); + } + +protected: + void paintEvent(QPaintEvent *) + { + static QPixmap foreground(QLatin1String(":/find/images/wrapindicator.png")); + QPainter p(this); + p.setOpacity(m_opacity); + p.drawPixmap(rect(), foreground); + } + +private slots: + void runInternal() + { + QPropertyAnimation *anim = new QPropertyAnimation(this, "opacity", this); + anim->setDuration(200); + anim->setEndValue(0.); + connect(anim, SIGNAL(finished()), this, SLOT(deleteLater())); + anim->start(QAbstractAnimation::DeleteWhenStopped); + } + +private: + qreal m_opacity; +}; + +} // Internal +} // Find + +using namespace Core; + +void IFindSupport::replace(const QString &before, const QString &after, FindFlags findFlags) +{ + Q_UNUSED(before) + Q_UNUSED(after) + Q_UNUSED(findFlags) +} + +bool IFindSupport::replaceStep(const QString &before, const QString &after, FindFlags findFlags) +{ + Q_UNUSED(before) + Q_UNUSED(after) + Q_UNUSED(findFlags) + return false; +} + +int IFindSupport::replaceAll(const QString &before, const QString &after, FindFlags findFlags) +{ + Q_UNUSED(before) + Q_UNUSED(after) + Q_UNUSED(findFlags) + return 0; +} + +void IFindSupport::showWrapIndicator(QWidget *parent) +{ + (new Internal::WrapIndicator(parent))->run(); +} + +#include "ifindsupport.moc" diff --git a/src/plugins/coreplugin/find/ifindsupport.h b/src/plugins/coreplugin/find/ifindsupport.h new file mode 100644 index 00000000000..041de57fddd --- /dev/null +++ b/src/plugins/coreplugin/find/ifindsupport.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef IFINDSUPPORT_H +#define IFINDSUPPORT_H + +#include "textfindconstants.h" + +#include +#include + +namespace Core { + +class CORE_EXPORT IFindSupport : public QObject +{ + Q_OBJECT + +public: + enum Result { Found, NotFound, NotYetFound }; + + IFindSupport() : QObject(0) {} + virtual ~IFindSupport() {} + + virtual bool supportsReplace() const = 0; + virtual FindFlags supportedFindFlags() const = 0; + virtual void resetIncrementalSearch() = 0; + virtual void clearResults() = 0; + virtual QString currentFindString() const = 0; + virtual QString completedFindString() const = 0; + + virtual void highlightAll(const QString &txt, FindFlags findFlags); + virtual Result findIncremental(const QString &txt, FindFlags findFlags) = 0; + virtual Result findStep(const QString &txt, FindFlags findFlags) = 0; + virtual void replace(const QString &before, const QString &after, + FindFlags findFlags); + virtual bool replaceStep(const QString &before, const QString &after, + FindFlags findFlags); + virtual int replaceAll(const QString &before, const QString &after, + FindFlags findFlags); + + virtual void defineFindScope(){} + virtual void clearFindScope(){} + + static void showWrapIndicator(QWidget *parent); + +signals: + void changed(); +}; + +inline void IFindSupport::highlightAll(const QString &, FindFlags) {} + +} // namespace Core + +#endif // IFINDSUPPORT_H diff --git a/src/plugins/coreplugin/find/images/all.png b/src/plugins/coreplugin/find/images/all.png new file mode 100644 index 00000000000..f5c1c1f767d Binary files /dev/null and b/src/plugins/coreplugin/find/images/all.png differ diff --git a/src/plugins/coreplugin/find/images/casesensitively.png b/src/plugins/coreplugin/find/images/casesensitively.png new file mode 100644 index 00000000000..029b41faa4d Binary files /dev/null and b/src/plugins/coreplugin/find/images/casesensitively.png differ diff --git a/src/plugins/coreplugin/find/images/empty.png b/src/plugins/coreplugin/find/images/empty.png new file mode 100644 index 00000000000..f02154247c2 Binary files /dev/null and b/src/plugins/coreplugin/find/images/empty.png differ diff --git a/src/plugins/coreplugin/find/images/expand.png b/src/plugins/coreplugin/find/images/expand.png new file mode 100644 index 00000000000..48fcb9b703b Binary files /dev/null and b/src/plugins/coreplugin/find/images/expand.png differ diff --git a/src/plugins/coreplugin/find/images/next.png b/src/plugins/coreplugin/find/images/next.png new file mode 100644 index 00000000000..1844929119b Binary files /dev/null and b/src/plugins/coreplugin/find/images/next.png differ diff --git a/src/plugins/coreplugin/find/images/preservecase.png b/src/plugins/coreplugin/find/images/preservecase.png new file mode 100644 index 00000000000..4869aabd719 Binary files /dev/null and b/src/plugins/coreplugin/find/images/preservecase.png differ diff --git a/src/plugins/coreplugin/find/images/previous.png b/src/plugins/coreplugin/find/images/previous.png new file mode 100644 index 00000000000..4fe50af9a87 Binary files /dev/null and b/src/plugins/coreplugin/find/images/previous.png differ diff --git a/src/plugins/coreplugin/find/images/regexp.png b/src/plugins/coreplugin/find/images/regexp.png new file mode 100644 index 00000000000..be8a5cc48cb Binary files /dev/null and b/src/plugins/coreplugin/find/images/regexp.png differ diff --git a/src/plugins/coreplugin/find/images/replace_all.png b/src/plugins/coreplugin/find/images/replace_all.png new file mode 100644 index 00000000000..d2298a8aade Binary files /dev/null and b/src/plugins/coreplugin/find/images/replace_all.png differ diff --git a/src/plugins/coreplugin/find/images/wholewords.png b/src/plugins/coreplugin/find/images/wholewords.png new file mode 100644 index 00000000000..0ffcecd963c Binary files /dev/null and b/src/plugins/coreplugin/find/images/wholewords.png differ diff --git a/src/plugins/coreplugin/find/images/wordandcase.png b/src/plugins/coreplugin/find/images/wordandcase.png new file mode 100644 index 00000000000..34c0ac31908 Binary files /dev/null and b/src/plugins/coreplugin/find/images/wordandcase.png differ diff --git a/src/plugins/coreplugin/find/images/wrapindicator.png b/src/plugins/coreplugin/find/images/wrapindicator.png new file mode 100644 index 00000000000..a4f8ddf4177 Binary files /dev/null and b/src/plugins/coreplugin/find/images/wrapindicator.png differ diff --git a/src/plugins/coreplugin/find/searchresultcolor.h b/src/plugins/coreplugin/find/searchresultcolor.h new file mode 100644 index 00000000000..0547f077490 --- /dev/null +++ b/src/plugins/coreplugin/find/searchresultcolor.h @@ -0,0 +1,20 @@ +#ifndef SEARCHRESULTCOLOR_H +#define SEARCHRESULTCOLOR_H + +#include + +namespace Core { +namespace Internal { + +class SearchResultColor{ +public: + QColor textBackground; + QColor textForeground; + QColor highlightBackground; + QColor highlightForeground; +}; + +} // namespace Internal +} // namespace Core + +#endif // SEARCHRESULTCOLOR_H diff --git a/src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp b/src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp new file mode 100644 index 00000000000..949a298f62b --- /dev/null +++ b/src/plugins/coreplugin/find/searchresulttreeitemdelegate.cpp @@ -0,0 +1,224 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "searchresulttreeitemdelegate.h" +#include "searchresulttreeitemroles.h" + +#include +#include + +#include +#include + +using namespace Core::Internal; + +SearchResultTreeItemDelegate::SearchResultTreeItemDelegate(QObject *parent) + : QItemDelegate(parent) +{ +} + +void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + static const int iconSize = 16; + + painter->save(); + + QStyleOptionViewItemV3 opt = setOptions(index, option); + painter->setFont(opt.font); + + QItemDelegate::drawBackground(painter, opt, index); + + // ---- do the layout + QRect checkRect; + QRect pixmapRect; + QRect textRect; + + // check mark + bool checkable = (index.model()->flags(index) & Qt::ItemIsUserCheckable); + Qt::CheckState checkState = Qt::Unchecked; + if (checkable) { + QVariant checkStateData = index.data(Qt::CheckStateRole); + checkState = static_cast(checkStateData.toInt()); +#if QT_VERSION >= 0x050000 + checkRect = doCheck(opt, opt.rect, checkStateData); +#else // Qt4 + checkRect = check(opt, opt.rect, checkStateData); +#endif + } + + // icon + QIcon icon = index.model()->data(index, ItemDataRoles::ResultIconRole).value(); + if (!icon.isNull()) + pixmapRect = QRect(0, 0, iconSize, iconSize); + + // text + textRect = opt.rect.adjusted(0, 0, checkRect.width() + pixmapRect.width(), 0); + + // do layout + doLayout(opt, &checkRect, &pixmapRect, &textRect, false); + + // ---- draw the items + // icon + if (!icon.isNull()) + QItemDelegate::drawDecoration(painter, opt, pixmapRect, icon.pixmap(iconSize)); + + // line numbers + int lineNumberAreaWidth = drawLineNumber(painter, opt, textRect, index); + textRect.adjust(lineNumberAreaWidth, 0, 0, 0); + + // text and focus/selection + drawText(painter, opt, textRect, index); + QItemDelegate::drawFocus(painter, opt, opt.rect); + + // check mark + if (checkable) + QItemDelegate::drawCheck(painter, opt, checkRect, checkState); + + painter->restore(); +} + +// returns the width of the line number area +int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyleOptionViewItemV3 &option, + const QRect &rect, + const QModelIndex &index) const +{ + static const int lineNumberAreaHorizontalPadding = 4; + int lineNumber = index.model()->data(index, ItemDataRoles::ResultLineNumberRole).toInt(); + if (lineNumber < 1) + return 0; + const bool isSelected = option.state & QStyle::State_Selected; + QString lineText = QString::number(lineNumber); + int minimumLineNumberDigits = qMax((int)m_minimumLineNumberDigits, lineText.count()); + int fontWidth = painter->fontMetrics().width(QString(minimumLineNumberDigits, QLatin1Char('0'))); + int lineNumberAreaWidth = lineNumberAreaHorizontalPadding + fontWidth + lineNumberAreaHorizontalPadding; + QRect lineNumberAreaRect(rect); + lineNumberAreaRect.setWidth(lineNumberAreaWidth); + + QPalette::ColorGroup cg = QPalette::Normal; + if (!(option.state & QStyle::State_Active)) + cg = QPalette::Inactive; + else if (!(option.state & QStyle::State_Enabled)) + cg = QPalette::Disabled; + + painter->fillRect(lineNumberAreaRect, QBrush(isSelected ? + option.palette.brush(cg, QPalette::Highlight) : + option.palette.color(cg, QPalette::Base).darker(111))); + + QStyleOptionViewItemV3 opt = option; + opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; + opt.palette.setColor(cg, QPalette::Text, Qt::darkGray); + + const QStyle *style = QApplication::style(); + const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1; + + const QRect rowRect = lineNumberAreaRect.adjusted(-textMargin, 0, textMargin-lineNumberAreaHorizontalPadding, 0); + QItemDelegate::drawDisplay(painter, opt, rowRect, lineText); + + return lineNumberAreaWidth; +} + +void SearchResultTreeItemDelegate::drawText(QPainter *painter, + const QStyleOptionViewItem &option, + const QRect &rect, + const QModelIndex &index) const +{ + QString text = index.model()->data(index, Qt::DisplayRole).toString(); + // show number of subresults in displayString + if (index.model()->hasChildren(index)) { + text += QLatin1String(" (") + + QString::number(index.model()->rowCount(index)) + + QLatin1Char(')'); + } + + const int searchTermStart = index.model()->data(index, ItemDataRoles::SearchTermStartRole).toInt(); + int searchTermLength = index.model()->data(index, ItemDataRoles::SearchTermLengthRole).toInt(); + if (searchTermStart < 0 || searchTermStart >= text.length() || searchTermLength < 1) { + QItemDelegate::drawDisplay(painter, option, rect, text); + return; + } + // clip searchTermLength to end of line + searchTermLength = qMin(searchTermLength, text.length() - searchTermStart); + const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; + int searchTermStartPixels = painter->fontMetrics().width(text.left(searchTermStart)); + int searchTermLengthPixels = painter->fontMetrics().width(text.mid(searchTermStart, searchTermLength)); + + // rects + QRect beforeHighlightRect(rect); + beforeHighlightRect.setRight(beforeHighlightRect.left() + searchTermStartPixels); + + QRect resultHighlightRect(rect); + resultHighlightRect.setLeft(beforeHighlightRect.right()); + resultHighlightRect.setRight(resultHighlightRect.left() + searchTermLengthPixels); + + QRect afterHighlightRect(rect); + afterHighlightRect.setLeft(resultHighlightRect.right()); + + // paint all highlight backgrounds + // qitemdelegate has problems with painting background when highlighted + // (highlighted background at wrong position because text is offset with textMargin) + // so we duplicate a lot here, see qitemdelegate for reference + bool isSelected = option.state & QStyle::State_Selected; + QPalette::ColorGroup cg = option.state & QStyle::State_Enabled + ? QPalette::Normal : QPalette::Disabled; + if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) + cg = QPalette::Inactive; + QStyleOptionViewItem baseOption = option; + baseOption.state &= ~QStyle::State_Selected; + if (isSelected) { + painter->fillRect(beforeHighlightRect.adjusted(textMargin, 0, textMargin, 0), + option.palette.brush(cg, QPalette::Highlight)); + painter->fillRect(afterHighlightRect.adjusted(textMargin, 0, textMargin, 0), + option.palette.brush(cg, QPalette::Highlight)); + } + const QColor highlightBackground = + index.model()->data(index, ItemDataRoles::ResultHighlightBackgroundColor).value(); + painter->fillRect(resultHighlightRect.adjusted(textMargin, 0, textMargin - 1, 0), QBrush(highlightBackground)); + + // Text before the highlighting + QStyleOptionViewItem noHighlightOpt = baseOption; + noHighlightOpt.rect = beforeHighlightRect; + noHighlightOpt.textElideMode = Qt::ElideNone; + if (isSelected) + noHighlightOpt.palette.setColor(QPalette::Text, noHighlightOpt.palette.color(cg, QPalette::HighlightedText)); + QItemDelegate::drawDisplay(painter, noHighlightOpt, + beforeHighlightRect, text.mid(0, searchTermStart)); + + // Highlight text + QStyleOptionViewItem highlightOpt = noHighlightOpt; + const QColor highlightForeground = + index.model()->data(index, ItemDataRoles::ResultHighlightForegroundColor).value(); + highlightOpt.palette.setColor(QPalette::Text, highlightForeground); + QItemDelegate::drawDisplay(painter, highlightOpt, resultHighlightRect, + text.mid(searchTermStart, searchTermLength)); + + // Text after the Highlight + noHighlightOpt.rect = afterHighlightRect; + QItemDelegate::drawDisplay(painter, noHighlightOpt, afterHighlightRect, + text.mid(searchTermStart + searchTermLength)); +} diff --git a/src/plugins/coreplugin/find/searchresulttreeitemdelegate.h b/src/plugins/coreplugin/find/searchresulttreeitemdelegate.h new file mode 100644 index 00000000000..af46024ede5 --- /dev/null +++ b/src/plugins/coreplugin/find/searchresulttreeitemdelegate.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef SEARCHRESULTTREEITEMDELEGATE_H +#define SEARCHRESULTTREEITEMDELEGATE_H + +#include + +namespace Core { +namespace Internal { + +class SearchResultTreeItemDelegate: public QItemDelegate +{ +public: + SearchResultTreeItemDelegate(QObject *parent = 0); + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + +private: + int drawLineNumber(QPainter *painter, const QStyleOptionViewItemV3 &option, const QRect &rect, const QModelIndex &index) const; + void drawText(QPainter *painter, const QStyleOptionViewItem &option, + const QRect &rect, const QModelIndex &index) const; + + static const int m_minimumLineNumberDigits = 6; +}; + +} // namespace Internal +} // namespace Core + +#endif // SEARCHRESULTTREEITEMDELEGATE_H diff --git a/src/plugins/coreplugin/find/searchresulttreeitemroles.h b/src/plugins/coreplugin/find/searchresulttreeitemroles.h new file mode 100644 index 00000000000..bd771d7c6a9 --- /dev/null +++ b/src/plugins/coreplugin/find/searchresulttreeitemroles.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef SEARCHRESULTTREEITEMROLES_H +#define SEARCHRESULTTREEITEMROLES_H + +#include + +namespace Core { +namespace Internal { +namespace ItemDataRoles { + +enum Roles +{ + ResultItemRole = Qt::UserRole, + ResultLineRole, + ResultLineNumberRole, + ResultIconRole, + ResultHighlightBackgroundColor, + ResultHighlightForegroundColor, + SearchTermStartRole, + SearchTermLengthRole, + IsGeneratedRole +}; + +} // namespace Internal +} // namespace Core +} // namespace ItemDataRoles + +#endif // SEARCHRESULTTREEITEMROLES_H diff --git a/src/plugins/coreplugin/find/searchresulttreeitems.cpp b/src/plugins/coreplugin/find/searchresulttreeitems.cpp new file mode 100644 index 00000000000..d9f941bd02d --- /dev/null +++ b/src/plugins/coreplugin/find/searchresulttreeitems.cpp @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "searchresulttreeitems.h" + +namespace Core { +namespace Internal { + +SearchResultTreeItem::SearchResultTreeItem(const SearchResultItem &item, + SearchResultTreeItem *parent) + : item(item), + m_parent(parent), + m_isUserCheckable(false), + m_isGenerated(false), + m_checkState(Qt::Unchecked) +{ +} + +SearchResultTreeItem::~SearchResultTreeItem() +{ + clearChildren(); +} + +bool SearchResultTreeItem::isLeaf() const +{ + return childrenCount() == 0 && parent() != 0; +} + +bool SearchResultTreeItem::isUserCheckable() const +{ + return m_isUserCheckable; +} + +void SearchResultTreeItem::setIsUserCheckable(bool isUserCheckable) +{ + m_isUserCheckable = isUserCheckable; +} + +Qt::CheckState SearchResultTreeItem::checkState() const +{ + return m_checkState; +} + +void SearchResultTreeItem::setCheckState(Qt::CheckState checkState) +{ + m_checkState = checkState; +} + +void SearchResultTreeItem::clearChildren() +{ + qDeleteAll(m_children); + m_children.clear(); +} + +int SearchResultTreeItem::childrenCount() const +{ + return m_children.count(); +} + +int SearchResultTreeItem::rowOfItem() const +{ + return (m_parent ? m_parent->m_children.indexOf(const_cast(this)):0); +} + +SearchResultTreeItem* SearchResultTreeItem::childAt(int index) const +{ + return m_children.at(index); +} + +SearchResultTreeItem *SearchResultTreeItem::parent() const +{ + return m_parent; +} + +static bool lessThanByText(SearchResultTreeItem *a, const QString &b) +{ + return a->item.text < b; +} + +int SearchResultTreeItem::insertionIndex(const QString &text, SearchResultTreeItem **existingItem) const +{ + QList::const_iterator insertionPosition = + qLowerBound(m_children.begin(), m_children.end(), text, lessThanByText); + if (existingItem) { + if (insertionPosition != m_children.end() && (*insertionPosition)->item.text == text) + (*existingItem) = (*insertionPosition); + else + *existingItem = 0; + } + return insertionPosition - m_children.begin(); +} + +int SearchResultTreeItem::insertionIndex(const SearchResultItem &item, SearchResultTreeItem **existingItem) const +{ + return insertionIndex(item.text, existingItem); +} + +void SearchResultTreeItem::insertChild(int index, SearchResultTreeItem *child) +{ + m_children.insert(index, child); +} + +void SearchResultTreeItem::insertChild(int index, const SearchResultItem &item) +{ + SearchResultTreeItem *child = new SearchResultTreeItem(item, this); + if (isUserCheckable()) { + child->setIsUserCheckable(true); + child->setCheckState(Qt::Checked); + } + insertChild(index, child); +} + +void SearchResultTreeItem::appendChild(const SearchResultItem &item) +{ + insertChild(m_children.count(), item); +} + +} // namespace Internal +} // namespace Core diff --git a/src/plugins/coreplugin/find/searchresulttreeitems.h b/src/plugins/coreplugin/find/searchresulttreeitems.h new file mode 100644 index 00000000000..3f41818ee1e --- /dev/null +++ b/src/plugins/coreplugin/find/searchresulttreeitems.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef SEARCHRESULTTREEITEMS_H +#define SEARCHRESULTTREEITEMS_H + +#include "searchresultwindow.h" + +#include +#include + +namespace Core { +namespace Internal { + +class SearchResultTreeItem +{ +public: + explicit SearchResultTreeItem(const SearchResultItem &item = SearchResultItem(), + SearchResultTreeItem *parent = NULL); + virtual ~SearchResultTreeItem(); + + bool isLeaf() const; + SearchResultTreeItem *parent() const; + SearchResultTreeItem *childAt(int index) const; + int insertionIndex(const QString &text, SearchResultTreeItem **existingItem) const; + int insertionIndex(const SearchResultItem &item, SearchResultTreeItem **existingItem) const; + void insertChild(int index, SearchResultTreeItem *child); + void insertChild(int index, const SearchResultItem &item); + void appendChild(const SearchResultItem &item); + int childrenCount() const; + int rowOfItem() const; + void clearChildren(); + + bool isUserCheckable() const; + void setIsUserCheckable(bool isUserCheckable); + + Qt::CheckState checkState() const; + void setCheckState(Qt::CheckState checkState); + + bool isGenerated() const { return m_isGenerated; } + void setGenerated(bool value) { m_isGenerated = value; } + + SearchResultItem item; + +private: + SearchResultTreeItem *m_parent; + QList m_children; + bool m_isUserCheckable; + bool m_isGenerated; + Qt::CheckState m_checkState; +}; + +} // namespace Internal +} // namespace Core + +#endif // SEARCHRESULTTREEITEMS_H diff --git a/src/plugins/coreplugin/find/searchresulttreemodel.cpp b/src/plugins/coreplugin/find/searchresulttreemodel.cpp new file mode 100644 index 00000000000..7aafe033bbf --- /dev/null +++ b/src/plugins/coreplugin/find/searchresulttreemodel.cpp @@ -0,0 +1,504 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "searchresulttreemodel.h" +#include "searchresulttreeitems.h" +#include "searchresulttreeitemroles.h" + +#include +#include +#include +#include + +using namespace Core; +using namespace Core::Internal; + +SearchResultTreeModel::SearchResultTreeModel(QObject *parent) + : QAbstractItemModel(parent) + , m_currentParent(0) + , m_showReplaceUI(false) + , m_editorFontIsUsed(false) +{ + m_rootItem = new SearchResultTreeItem; + m_textEditorFont = QFont(QLatin1String("Courier")); +} + +SearchResultTreeModel::~SearchResultTreeModel() +{ + delete m_rootItem; +} + +void SearchResultTreeModel::setShowReplaceUI(bool show) +{ + m_showReplaceUI = show; +} + +void SearchResultTreeModel::setTextEditorFont(const QFont &font, const SearchResultColor color) +{ + layoutAboutToBeChanged(); + m_textEditorFont = font; + m_color = color; + layoutChanged(); +} + +Qt::ItemFlags SearchResultTreeModel::flags(const QModelIndex &idx) const +{ + Qt::ItemFlags flags = QAbstractItemModel::flags(idx); + + if (idx.isValid()) { + if (const SearchResultTreeItem *item = treeItemAtIndex(idx)) { + if (item->isUserCheckable()) + flags |= Qt::ItemIsUserCheckable; + } + } + + return flags; +} + +QModelIndex SearchResultTreeModel::index(int row, int column, + const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + const SearchResultTreeItem *parentItem; + + if (!parent.isValid()) + parentItem = m_rootItem; + else + parentItem = treeItemAtIndex(parent); + + const SearchResultTreeItem *childItem = parentItem->childAt(row); + if (childItem) + return createIndex(row, column, (void *)childItem); + else + return QModelIndex(); +} + +QModelIndex SearchResultTreeModel::index(SearchResultTreeItem *item) const +{ + return createIndex(item->rowOfItem(), 0, (void *)item); +} + +QModelIndex SearchResultTreeModel::parent(const QModelIndex &idx) const +{ + if (!idx.isValid()) + return QModelIndex(); + + const SearchResultTreeItem *childItem = treeItemAtIndex(idx); + const SearchResultTreeItem *parentItem = childItem->parent(); + + if (parentItem == m_rootItem) + return QModelIndex(); + + return createIndex(parentItem->rowOfItem(), 0, (void *)parentItem); +} + +int SearchResultTreeModel::rowCount(const QModelIndex &parent) const +{ + if (parent.column() > 0) + return 0; + + const SearchResultTreeItem *parentItem; + + if (!parent.isValid()) + parentItem = m_rootItem; + else + parentItem = treeItemAtIndex(parent); + + return parentItem->childrenCount(); +} + +int SearchResultTreeModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent) + return 1; +} + +SearchResultTreeItem *SearchResultTreeModel::treeItemAtIndex(const QModelIndex &idx) const +{ + return static_cast(idx.internalPointer()); +} + +QVariant SearchResultTreeModel::data(const QModelIndex &idx, int role) const +{ + if (!idx.isValid()) + return QVariant(); + + QVariant result; + + if (role == Qt::SizeHintRole) { + int height = QApplication::fontMetrics().height(); + if (m_editorFontIsUsed) { + const int editorFontHeight = QFontMetrics(m_textEditorFont).height(); + height = qMax(height, editorFontHeight); + } + result = QSize(0, height); + } else { + result = data(treeItemAtIndex(idx), role); + } + + return result; +} + +bool SearchResultTreeModel::setData(const QModelIndex &idx, const QVariant &value, int role) +{ + if (role == Qt::CheckStateRole) { + Qt::CheckState checkState = static_cast(value.toInt()); + return setCheckState(idx, checkState); + } + return QAbstractItemModel::setData(idx, value, role); +} + +bool SearchResultTreeModel::setCheckState(const QModelIndex &idx, Qt::CheckState checkState, bool firstCall) +{ + SearchResultTreeItem *item = treeItemAtIndex(idx); + if (item->checkState() == checkState) + return false; + item->setCheckState(checkState); + if (firstCall) { + emit dataChanged(idx, idx); + // check parents + SearchResultTreeItem *currentItem = item; + QModelIndex currentIndex = idx; + while (SearchResultTreeItem *parent = currentItem->parent()) { + if (parent->isUserCheckable()) { + bool hasChecked = false; + bool hasUnchecked = false; + for (int i = 0; i < parent->childrenCount(); ++i) { + SearchResultTreeItem *child = parent->childAt(i); + if (!child->isUserCheckable()) + continue; + if (child->checkState() == Qt::Checked) + hasChecked = true; + else if (child->checkState() == Qt::Unchecked) + hasUnchecked = true; + else if (child->checkState() == Qt::PartiallyChecked) + hasChecked = hasUnchecked = true; + } + if (hasChecked && hasUnchecked) + parent->setCheckState(Qt::PartiallyChecked); + else if (hasChecked) + parent->setCheckState(Qt::Checked); + else + parent->setCheckState(Qt::Unchecked); + emit dataChanged(idx.parent(), idx.parent()); + } + currentItem = parent; + currentIndex = idx.parent(); + } + } + // check children + if (int children = item->childrenCount()) { + for (int i = 0; i < children; ++i) { + setCheckState(idx.child(i, 0), checkState, false); + } + emit dataChanged(idx.child(0, 0), idx.child(children-1, 0)); + } + return true; +} + +void setDataInternal(const QModelIndex &index, const QVariant &value, int role); + +QVariant SearchResultTreeModel::data(const SearchResultTreeItem *row, int role) const +{ + QVariant result; + + switch (role) + { + case Qt::CheckStateRole: + if (row->isUserCheckable()) + result = row->checkState(); + break; + case Qt::ToolTipRole: + result = row->item.text.trimmed(); + break; + case Qt::FontRole: + if (row->item.useTextEditorFont) + result = m_textEditorFont; + else + result = QVariant(); + break; + case Qt::TextColorRole: + result = m_color.textForeground; + break; + case Qt::BackgroundRole: + result = m_color.textBackground; + break; + case ItemDataRoles::ResultLineRole: + case Qt::DisplayRole: + result = row->item.text; + break; + case ItemDataRoles::ResultItemRole: + result = qVariantFromValue(row->item); + break; + case ItemDataRoles::ResultLineNumberRole: + result = row->item.lineNumber; + break; + case ItemDataRoles::ResultIconRole: + result = row->item.icon; + break; + case ItemDataRoles::ResultHighlightBackgroundColor: + result = m_color.highlightBackground; + break; + case ItemDataRoles::ResultHighlightForegroundColor: + result = m_color.highlightForeground; + break; + case ItemDataRoles::SearchTermStartRole: + result = row->item.textMarkPos; + break; + case ItemDataRoles::SearchTermLengthRole: + result = row->item.textMarkLength; + break; + case ItemDataRoles::IsGeneratedRole: + result = row->isGenerated(); + break; + default: + result = QVariant(); + break; + } + + return result; +} + +QVariant SearchResultTreeModel::headerData(int section, Qt::Orientation orientation, + int role) const +{ + Q_UNUSED(section) + Q_UNUSED(orientation) + Q_UNUSED(role) + return QVariant(); +} + +/** + * Makes sure that the nodes for a specific path exist and sets + * m_currentParent to the last final + */ +QSet SearchResultTreeModel::addPath(const QStringList &path) +{ + QSet pathNodes; + SearchResultTreeItem *currentItem = m_rootItem; + QModelIndex currentItemIndex = QModelIndex(); + SearchResultTreeItem *partItem = 0; + QStringList currentPath; + foreach (const QString &part, path) { + const int insertionIndex = currentItem->insertionIndex(part, &partItem); + if (!partItem) { + SearchResultItem item; + item.path = currentPath; + item.text = part; + partItem = new SearchResultTreeItem(item, currentItem); + if (m_showReplaceUI) { + partItem->setIsUserCheckable(true); + partItem->setCheckState(Qt::Checked); + } + partItem->setGenerated(true); + beginInsertRows(currentItemIndex, insertionIndex, insertionIndex); + currentItem->insertChild(insertionIndex, partItem); + endInsertRows(); + } + pathNodes << partItem; + currentItemIndex = index(insertionIndex, 0, currentItemIndex); + currentItem = partItem; + currentPath << part; + } + + m_currentParent = currentItem; + m_currentPath = currentPath; + m_currentIndex = currentItemIndex; + return pathNodes; +} + +void SearchResultTreeModel::addResultsToCurrentParent(const QList &items, SearchResult::AddMode mode) +{ + if (!m_currentParent) + return; + + if (mode == SearchResult::AddOrdered) { + // this is the mode for e.g. text search + beginInsertRows(m_currentIndex, m_currentParent->childrenCount(), m_currentParent->childrenCount() + items.count()); + foreach (const SearchResultItem &item, items) { + m_currentParent->appendChild(item); + } + endInsertRows(); + } else if (mode == SearchResult::AddSorted) { + foreach (const SearchResultItem &item, items) { + SearchResultTreeItem *existingItem; + const int insertionIndex = m_currentParent->insertionIndex(item, &existingItem); + if (existingItem) { + existingItem->setGenerated(false); + existingItem->item = item; + QModelIndex itemIndex = m_currentIndex.child(insertionIndex, 0); + dataChanged(itemIndex, itemIndex); + } else { + beginInsertRows(m_currentIndex, insertionIndex, insertionIndex); + m_currentParent->insertChild(insertionIndex, item); + endInsertRows(); + } + } + } + dataChanged(m_currentIndex, m_currentIndex); // Make sure that the number after the file name gets updated +} + +static bool lessThanByPath(const SearchResultItem &a, const SearchResultItem &b) +{ + if (a.path.size() < b.path.size()) + return true; + if (a.path.size() > b.path.size()) + return false; + for (int i = 0; i < a.path.size(); ++i) { + if (a.path.at(i) < b.path.at(i)) + return true; + if (a.path.at(i) > b.path.at(i)) + return false; + } + return false; +} + +/** + * Adds the search result to the list of results, creating nodes for the path when + * necessary. + */ +QList SearchResultTreeModel::addResults(const QList &items, SearchResult::AddMode mode) +{ + QSet pathNodes; + QList sortedItems = items; + qStableSort(sortedItems.begin(), sortedItems.end(), lessThanByPath); + QList itemSet; + foreach (const SearchResultItem &item, sortedItems) { + m_editorFontIsUsed |= item.useTextEditorFont; + if (!m_currentParent || (m_currentPath != item.path)) { + // first add all the items from before + if (!itemSet.isEmpty()) { + addResultsToCurrentParent(itemSet, mode); + itemSet.clear(); + } + // switch parent + pathNodes += addPath(item.path); + } + itemSet << item; + } + if (!itemSet.isEmpty()) { + addResultsToCurrentParent(itemSet, mode); + itemSet.clear(); + } + QList pathIndices; + foreach (SearchResultTreeItem *item, pathNodes) + pathIndices << index(item); + return pathIndices; +} + +void SearchResultTreeModel::clear() +{ + beginResetModel(); + m_currentParent = NULL; + m_rootItem->clearChildren(); + m_editorFontIsUsed = false; + endResetModel(); +} + +QModelIndex SearchResultTreeModel::nextIndex(const QModelIndex &idx, bool *wrapped) const +{ + if (wrapped) + *wrapped = false; + // pathological + if (!idx.isValid()) + return index(0, 0); + + if (rowCount(idx) > 0) { + // node with children + return idx.child(0, 0); + } + // leaf node + QModelIndex nextIndex; + QModelIndex current = idx; + while (!nextIndex.isValid()) { + int row = current.row(); + current = current.parent(); + if (row + 1 < rowCount(current)) { + // Same parent has another child + nextIndex = index(row + 1, 0, current); + } else { + // go up one parent + if (!current.isValid()) { + // we start from the beginning + if (wrapped) + *wrapped = true; + nextIndex = index(0, 0); + } + } + } + return nextIndex; +} + +QModelIndex SearchResultTreeModel::next(const QModelIndex &idx, bool includeGenerated, bool *wrapped) const +{ + QModelIndex value = idx; + do { + value = nextIndex(value, wrapped); + } while (value != idx && !includeGenerated && treeItemAtIndex(value)->isGenerated()); + return value; +} + +QModelIndex SearchResultTreeModel::prevIndex(const QModelIndex &idx, bool *wrapped) const +{ + if (wrapped) + *wrapped = false; + QModelIndex current = idx; + bool checkForChildren = true; + if (current.isValid()) { + int row = current.row(); + if (row > 0) { + current = index(row - 1, 0, current.parent()); + } else { + current = current.parent(); + checkForChildren = !current.isValid(); + if (checkForChildren && wrapped) { + // we start from the end + *wrapped = true; + } + } + } + if (checkForChildren) { + // traverse down the hierarchy + while (int rc = rowCount(current)) { + current = index(rc - 1, 0, current); + } + } + return current; +} + +QModelIndex SearchResultTreeModel::prev(const QModelIndex &idx, bool includeGenerated, bool *wrapped) const +{ + QModelIndex value = idx; + do { + value = prevIndex(value, wrapped); + } while (value != idx && !includeGenerated && treeItemAtIndex(value)->isGenerated()); + return value; +} diff --git a/src/plugins/coreplugin/find/searchresulttreemodel.h b/src/plugins/coreplugin/find/searchresulttreemodel.h new file mode 100644 index 00000000000..36ca6d94ac1 --- /dev/null +++ b/src/plugins/coreplugin/find/searchresulttreemodel.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef SEARCHRESULTTREEMODEL_H +#define SEARCHRESULTTREEMODEL_H + +#include "searchresultwindow.h" +#include "searchresultcolor.h" + +#include +#include + +namespace Core { +namespace Internal { + +class SearchResultTreeItem; + +class SearchResultTreeModel : public QAbstractItemModel +{ + Q_OBJECT + +public: + SearchResultTreeModel(QObject *parent = 0); + ~SearchResultTreeModel(); + + void setShowReplaceUI(bool show); + void setTextEditorFont(const QFont &font, const SearchResultColor color); + + Qt::ItemFlags flags(const QModelIndex &index) const; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &child) const; + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + QVariant headerData(int section, Qt::Orientation orientation, int role) const; + + QModelIndex next(const QModelIndex &idx, bool includeGenerated = false, bool *wrapped = 0) const; + QModelIndex prev(const QModelIndex &idx, bool includeGenerated = false, bool *wrapped = 0) const; + + QList addResults(const QList &items, SearchResult::AddMode mode); + +signals: + void jumpToSearchResult(const QString &fileName, int lineNumber, + int searchTermStart, int searchTermLength); + +public slots: + void clear(); + +private: + QModelIndex index(SearchResultTreeItem *item) const; + void addResultsToCurrentParent(const QList &items, SearchResult::AddMode mode); + QSet addPath(const QStringList &path); + QVariant data(const SearchResultTreeItem *row, int role) const; + bool setCheckState(const QModelIndex &idx, Qt::CheckState checkState, bool firstCall = true); + QModelIndex nextIndex(const QModelIndex &idx, bool *wrapped = 0) const; + QModelIndex prevIndex(const QModelIndex &idx, bool *wrapped = 0) const; + SearchResultTreeItem *treeItemAtIndex(const QModelIndex &idx) const; + + SearchResultTreeItem *m_rootItem; + SearchResultTreeItem *m_currentParent; + SearchResultColor m_color; + QModelIndex m_currentIndex; + QStringList m_currentPath; // the path that belongs to the current parent + QFont m_textEditorFont; + bool m_showReplaceUI; + bool m_editorFontIsUsed; +}; + +} // namespace Internal +} // namespace Core + +#endif // SEARCHRESULTTREEMODEL_H diff --git a/src/plugins/coreplugin/find/searchresulttreeview.cpp b/src/plugins/coreplugin/find/searchresulttreeview.cpp new file mode 100644 index 00000000000..d48efabd976 --- /dev/null +++ b/src/plugins/coreplugin/find/searchresulttreeview.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "searchresulttreeview.h" +#include "searchresulttreeitemroles.h" +#include "searchresulttreemodel.h" +#include "searchresulttreeitemdelegate.h" + +#include +#include + +namespace Core { +namespace Internal { + +SearchResultTreeView::SearchResultTreeView(QWidget *parent) + : QTreeView(parent) + , m_model(new SearchResultTreeModel(this)) + , m_autoExpandResults(false) +{ + setModel(m_model); + setItemDelegate(new SearchResultTreeItemDelegate(this)); + setIndentation(14); + setUniformRowHeights(true); + setExpandsOnDoubleClick(true); + header()->hide(); + + connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(emitJumpToSearchResult(QModelIndex))); +} + +void SearchResultTreeView::setAutoExpandResults(bool expand) +{ + m_autoExpandResults = expand; +} + +void SearchResultTreeView::setTextEditorFont(const QFont &font, const SearchResultColor color) +{ + m_model->setTextEditorFont(font, color); + + QPalette p = palette(); + p.setColor(QPalette::Base, color.textBackground); + setPalette(p); +} + +void SearchResultTreeView::clear() +{ + m_model->clear(); +} + +void SearchResultTreeView::addResults(const QList &items, SearchResult::AddMode mode) +{ + QList addedParents = m_model->addResults(items, mode); + if (m_autoExpandResults && !addedParents.isEmpty()) { + foreach (const QModelIndex &index, addedParents) + setExpanded(index, true); + } +} + +void SearchResultTreeView::emitJumpToSearchResult(const QModelIndex &index) +{ + if (model()->data(index, ItemDataRoles::IsGeneratedRole).toBool()) + return; + SearchResultItem item = model()->data(index, ItemDataRoles::ResultItemRole).value(); + + emit jumpToSearchResult(item); +} + +void SearchResultTreeView::keyPressEvent(QKeyEvent *e) +{ + if (!e->modifiers() && e->key() == Qt::Key_Return) { + emit activated(currentIndex()); + e->accept(); + return; + } + QTreeView::keyPressEvent(e); +} + +SearchResultTreeModel *SearchResultTreeView::model() const +{ + return m_model; +} + +} // namespace Internal +} // namespace Core diff --git a/src/plugins/coreplugin/find/searchresulttreeview.h b/src/plugins/coreplugin/find/searchresulttreeview.h new file mode 100644 index 00000000000..b5dcd792d38 --- /dev/null +++ b/src/plugins/coreplugin/find/searchresulttreeview.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef SEARCHRESULTTREEVIEW_H +#define SEARCHRESULTTREEVIEW_H + +#include "searchresultwindow.h" + +#include + +namespace Core { +namespace Internal { + +class SearchResultTreeModel; +class SearchResultColor; + +class SearchResultTreeView : public QTreeView +{ + Q_OBJECT + +public: + explicit SearchResultTreeView(QWidget *parent = 0); + + void setAutoExpandResults(bool expand); + void setTextEditorFont(const QFont &font, const SearchResultColor color); + + SearchResultTreeModel *model() const; + void addResults(const QList &items, SearchResult::AddMode mode); + +signals: + void jumpToSearchResult(const SearchResultItem &item); + +public slots: + void clear(); + void emitJumpToSearchResult(const QModelIndex &index); + +protected: + void keyPressEvent(QKeyEvent *e); + + SearchResultTreeModel *m_model; + bool m_autoExpandResults; +}; + +} // namespace Internal +} // namespace Core + +#endif // SEARCHRESULTTREEVIEW_H diff --git a/src/plugins/coreplugin/find/searchresultwidget.cpp b/src/plugins/coreplugin/find/searchresultwidget.cpp new file mode 100644 index 00000000000..6539cebdadd --- /dev/null +++ b/src/plugins/coreplugin/find/searchresultwidget.cpp @@ -0,0 +1,495 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "searchresultwidget.h" +#include "searchresulttreeview.h" +#include "searchresulttreemodel.h" +#include "searchresulttreeitems.h" +#include "searchresulttreeitemroles.h" + +#include "findplugin.h" +#include "treeviewfind.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static const int SEARCHRESULT_WARNING_LIMIT = 200000; +static const char SIZE_WARNING_ID[] = "sizeWarningLabel"; + +namespace Core { +namespace Internal { + +class WideEnoughLineEdit : public QLineEdit { + Q_OBJECT +public: + WideEnoughLineEdit(QWidget *parent):QLineEdit(parent){ + connect(this, SIGNAL(textChanged(QString)), + this, SLOT(updateGeometry())); + } + ~WideEnoughLineEdit(){} + QSize sizeHint() const { + QSize sh = QLineEdit::minimumSizeHint(); + sh.rwidth() += qMax(25 * fontMetrics().width(QLatin1Char('x')), + fontMetrics().width(text())); + return sh; + } +public slots: + void updateGeometry() { QLineEdit::updateGeometry(); } +}; + +} // namespace Internal +} // namespace Core + +using namespace Core; +using namespace Core::Internal; + +SearchResultWidget::SearchResultWidget(QWidget *parent) : + QWidget(parent), + m_count(0), + m_isShowingReplaceUI(false), + m_searchAgainSupported(false) +{ + QVBoxLayout *layout = new QVBoxLayout(this); + layout->setMargin(0); + layout->setSpacing(0); + setLayout(layout); + + QFrame *topWidget = new QFrame; + QPalette pal = topWidget->palette(); + pal.setColor(QPalette::Window, QColor(255, 255, 225)); + pal.setColor(QPalette::WindowText, Qt::black); + topWidget->setPalette(pal); + topWidget->setFrameStyle(QFrame::Panel | QFrame::Raised); + topWidget->setLineWidth(1); + topWidget->setAutoFillBackground(true); + QHBoxLayout *topLayout = new QHBoxLayout(topWidget); + topLayout->setMargin(2); + topWidget->setLayout(topLayout); + layout->addWidget(topWidget); + + m_messageWidget = new QFrame; + pal.setColor(QPalette::Window, QColor(255, 255, 225)); + pal.setColor(QPalette::WindowText, Qt::red); + m_messageWidget->setPalette(pal); + m_messageWidget->setFrameStyle(QFrame::Panel | QFrame::Raised); + m_messageWidget->setLineWidth(1); + m_messageWidget->setAutoFillBackground(true); + QHBoxLayout *messageLayout = new QHBoxLayout(m_messageWidget); + messageLayout->setMargin(2); + m_messageWidget->setLayout(messageLayout); + QLabel *messageLabel = new QLabel(tr("Search was canceled.")); + messageLabel->setPalette(pal); + messageLayout->addWidget(messageLabel); + layout->addWidget(m_messageWidget); + m_messageWidget->setVisible(false); + + m_searchResultTreeView = new Internal::SearchResultTreeView(this); + m_searchResultTreeView->setFrameStyle(QFrame::NoFrame); + m_searchResultTreeView->setAttribute(Qt::WA_MacShowFocusRect, false); + Aggregation::Aggregate * agg = new Aggregation::Aggregate; + agg->add(m_searchResultTreeView); + agg->add(new TreeViewFind(m_searchResultTreeView, + ItemDataRoles::ResultLineRole)); + layout->addWidget(m_searchResultTreeView); + + m_infoBarDisplay.setTarget(layout, 2); + m_infoBarDisplay.setInfoBar(&m_infoBar); + + m_descriptionContainer = new QWidget(topWidget); + QHBoxLayout *descriptionLayout = new QHBoxLayout(m_descriptionContainer); + m_descriptionContainer->setLayout(descriptionLayout); + descriptionLayout->setMargin(0); + m_descriptionContainer->setMinimumWidth(200); + m_descriptionContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); + m_label = new QLabel(m_descriptionContainer); + m_label->setVisible(false); + m_searchTerm = new QLabel(m_descriptionContainer); + m_searchTerm->setVisible(false); + descriptionLayout->addWidget(m_label); + descriptionLayout->addWidget(m_searchTerm); + m_cancelButton = new QToolButton(topWidget); + m_cancelButton->setText(tr("Cancel")); + m_cancelButton->setToolButtonStyle(Qt::ToolButtonTextOnly); + connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); + m_searchAgainButton = new QToolButton(topWidget); + m_searchAgainButton->setToolTip(tr("Repeat the search with same parameters")); + m_searchAgainButton->setText(tr("Search again")); + m_searchAgainButton->setToolButtonStyle(Qt::ToolButtonTextOnly); + m_searchAgainButton->setVisible(false); + connect(m_searchAgainButton, SIGNAL(clicked()), this, SLOT(searchAgain())); + + m_replaceLabel = new QLabel(tr("Replace with:"), topWidget); + m_replaceTextEdit = new WideEnoughLineEdit(topWidget); + m_replaceTextEdit->setMinimumWidth(120); + m_replaceTextEdit->setEnabled(false); + m_replaceTextEdit->setTabOrder(m_replaceTextEdit, m_searchResultTreeView); + m_replaceButton = new QToolButton(topWidget); + m_replaceButton->setToolTip(tr("Replace all occurrences")); + m_replaceButton->setText(tr("Replace")); + m_replaceButton->setToolButtonStyle(Qt::ToolButtonTextOnly); + m_replaceButton->setEnabled(false); + m_preserveCaseCheck = new QCheckBox(topWidget); + m_preserveCaseCheck->setText(tr("Preserve case")); + m_preserveCaseCheck->setEnabled(false); + + if (FindPlugin * plugin = FindPlugin::instance()) { + m_preserveCaseCheck->setChecked(plugin->hasFindFlag(FindPreserveCase)); + connect(m_preserveCaseCheck, SIGNAL(clicked(bool)), plugin, SLOT(setPreserveCase(bool))); + } + + m_matchesFoundLabel = new QLabel(topWidget); + updateMatchesFoundLabel(); + + topLayout->addWidget(m_descriptionContainer); + topLayout->addWidget(m_cancelButton); + topLayout->addWidget(m_searchAgainButton); + topLayout->addWidget(m_replaceLabel); + topLayout->addWidget(m_replaceTextEdit); + topLayout->addWidget(m_replaceButton); + topLayout->addWidget(m_preserveCaseCheck); + topLayout->addStretch(2); + topLayout->addWidget(m_matchesFoundLabel); + topWidget->setMinimumHeight(m_cancelButton->sizeHint().height() + + topLayout->contentsMargins().top() + topLayout->contentsMargins().bottom() + + topWidget->lineWidth()); + setShowReplaceUI(false); + + connect(m_searchResultTreeView, SIGNAL(jumpToSearchResult(SearchResultItem)), + this, SLOT(handleJumpToSearchResult(SearchResultItem))); + connect(m_replaceTextEdit, SIGNAL(returnPressed()), this, SLOT(handleReplaceButton())); + connect(m_replaceButton, SIGNAL(clicked()), this, SLOT(handleReplaceButton())); +} + +SearchResultWidget::~SearchResultWidget() +{ + if (m_infoBar.containsInfo(Core::Id(SIZE_WARNING_ID))) + cancelAfterSizeWarning(); +} + +void SearchResultWidget::setInfo(const QString &label, const QString &toolTip, const QString &term) +{ + m_label->setText(label); + m_label->setVisible(!label.isEmpty()); + m_descriptionContainer->setToolTip(toolTip); + m_searchTerm->setText(term); + m_searchTerm->setVisible(!term.isEmpty()); +} + +void SearchResultWidget::addResult(const QString &fileName, int lineNumber, const QString &rowText, + int searchTermStart, int searchTermLength, const QVariant &userData) +{ + SearchResultItem item; + item.path = QStringList() << QDir::toNativeSeparators(fileName); + item.lineNumber = lineNumber; + item.text = rowText; + item.textMarkPos = searchTermStart; + item.textMarkLength = searchTermLength; + item.useTextEditorFont = true; + item.userData = userData; + addResults(QList() << item, SearchResult::AddOrdered); +} + +void SearchResultWidget::addResults(const QList &items, SearchResult::AddMode mode) +{ + bool firstItems = (m_count == 0); + m_count += items.size(); + m_searchResultTreeView->addResults(items, mode); + updateMatchesFoundLabel(); + if (firstItems) { + if (!m_dontAskAgainGroup.isEmpty()) { + Core::Id undoWarningId = Core::Id("warninglabel/").withSuffix(m_dontAskAgainGroup); + if (m_infoBar.canInfoBeAdded(undoWarningId)) { + Core::InfoBarEntry info(undoWarningId, tr("This change cannot be undone."), + Core::InfoBarEntry::GlobalSuppressionEnabled); + m_infoBar.addInfo(info); + } + } + + m_replaceTextEdit->setEnabled(true); + // We didn't have an item before, set the focus to the search widget or replace text edit + if (m_isShowingReplaceUI) { + m_replaceTextEdit->setFocus(); + m_replaceTextEdit->selectAll(); + } else { + m_searchResultTreeView->setFocus(); + } + m_searchResultTreeView->selectionModel()->select(m_searchResultTreeView->model()->index(0, 0, QModelIndex()), QItemSelectionModel::Select); + emit navigateStateChanged(); + } else if (m_count <= SEARCHRESULT_WARNING_LIMIT) { + return; + } else { + Core::Id sizeWarningId(SIZE_WARNING_ID); + if (!m_infoBar.canInfoBeAdded(sizeWarningId)) + return; + emit paused(true); + Core::InfoBarEntry info(sizeWarningId, + tr("The search resulted in more than %n items, do you still want to continue?", + 0, SEARCHRESULT_WARNING_LIMIT)); + info.setCancelButtonInfo(tr("Cancel"), this, SLOT(cancelAfterSizeWarning())); + info.setCustomButtonInfo(tr("Continue"), this, SLOT(continueAfterSizeWarning())); + m_infoBar.addInfo(info); + emit requestPopup(false/*no focus*/); + } +} + + + +int SearchResultWidget::count() const +{ + return m_count; +} + +QString SearchResultWidget::dontAskAgainGroup() const +{ + return m_dontAskAgainGroup; +} + +void SearchResultWidget::setDontAskAgainGroup(const QString &group) +{ + m_dontAskAgainGroup = group; +} + + +void SearchResultWidget::setTextToReplace(const QString &textToReplace) +{ + m_replaceTextEdit->setText(textToReplace); +} + +QString SearchResultWidget::textToReplace() const +{ + return m_replaceTextEdit->text(); +} + +void SearchResultWidget::setShowReplaceUI(bool visible) +{ + m_searchResultTreeView->model()->setShowReplaceUI(visible); + m_replaceLabel->setVisible(visible); + m_replaceTextEdit->setVisible(visible); + m_replaceButton->setVisible(visible); + m_preserveCaseCheck->setVisible(visible); + m_isShowingReplaceUI = visible; +} + +bool SearchResultWidget::hasFocusInternally() const +{ + return m_searchResultTreeView->hasFocus() || (m_isShowingReplaceUI && m_replaceTextEdit->hasFocus()); +} + +void SearchResultWidget::setFocusInternally() +{ + if (m_count > 0) { + if (m_isShowingReplaceUI) { + if (!focusWidget() || focusWidget() == m_replaceTextEdit) { + m_replaceTextEdit->setFocus(); + m_replaceTextEdit->selectAll(); + } else { + m_searchResultTreeView->setFocus(); + } + } else { + m_searchResultTreeView->setFocus(); + } + } +} + +bool SearchResultWidget::canFocusInternally() const +{ + return m_count > 0; +} + +void SearchResultWidget::notifyVisibilityChanged(bool visible) +{ + emit visibilityChanged(visible); +} + +void SearchResultWidget::setTextEditorFont(const QFont &font, const SearchResultColor color) +{ + m_searchResultTreeView->setTextEditorFont(font, color); +} + +void SearchResultWidget::setAutoExpandResults(bool expand) +{ + m_searchResultTreeView->setAutoExpandResults(expand); +} + +void SearchResultWidget::expandAll() +{ + m_searchResultTreeView->expandAll(); +} + +void SearchResultWidget::collapseAll() +{ + m_searchResultTreeView->collapseAll(); +} + +void SearchResultWidget::goToNext() +{ + if (m_count == 0) + return; + QModelIndex idx = m_searchResultTreeView->model()->next(m_searchResultTreeView->currentIndex()); + if (idx.isValid()) { + m_searchResultTreeView->setCurrentIndex(idx); + m_searchResultTreeView->emitJumpToSearchResult(idx); + } +} + +void SearchResultWidget::goToPrevious() +{ + if (!m_searchResultTreeView->model()->rowCount()) + return; + QModelIndex idx = m_searchResultTreeView->model()->prev(m_searchResultTreeView->currentIndex()); + if (idx.isValid()) { + m_searchResultTreeView->setCurrentIndex(idx); + m_searchResultTreeView->emitJumpToSearchResult(idx); + } +} + +void SearchResultWidget::restart() +{ + m_replaceTextEdit->setEnabled(false); + m_replaceButton->setEnabled(false); + m_searchResultTreeView->clear(); + m_count = 0; + Core::Id sizeWarningId(SIZE_WARNING_ID); + m_infoBar.removeInfo(sizeWarningId); + m_infoBar.enableInfo(sizeWarningId); + m_cancelButton->setVisible(true); + m_searchAgainButton->setVisible(false); + m_messageWidget->setVisible(false); + updateMatchesFoundLabel(); + emit restarted(); +} + +void SearchResultWidget::setSearchAgainSupported(bool supported) +{ + m_searchAgainSupported = supported; + m_searchAgainButton->setVisible(supported && !m_cancelButton->isVisible()); +} + +void SearchResultWidget::setSearchAgainEnabled(bool enabled) +{ + m_searchAgainButton->setEnabled(enabled); +} + +void SearchResultWidget::finishSearch(bool canceled) +{ + Core::Id sizeWarningId(SIZE_WARNING_ID); + m_infoBar.removeInfo(sizeWarningId); + m_infoBar.enableInfo(sizeWarningId); + m_replaceTextEdit->setEnabled(m_count > 0); + m_replaceButton->setEnabled(m_count > 0); + m_preserveCaseCheck->setEnabled(m_count > 0); + m_cancelButton->setVisible(false); + m_messageWidget->setVisible(canceled); + m_searchAgainButton->setVisible(m_searchAgainSupported); +} + +void SearchResultWidget::sendRequestPopup() +{ + emit requestPopup(true/*focus*/); +} + +void SearchResultWidget::continueAfterSizeWarning() +{ + m_infoBar.suppressInfo(Core::Id(SIZE_WARNING_ID)); + emit paused(false); +} + +void SearchResultWidget::cancelAfterSizeWarning() +{ + m_infoBar.suppressInfo(Core::Id(SIZE_WARNING_ID)); + emit cancelled(); + emit paused(false); +} + +void SearchResultWidget::handleJumpToSearchResult(const SearchResultItem &item) +{ + emit activated(item); +} + +void SearchResultWidget::handleReplaceButton() +{ + // check if button is actually enabled, because this is also triggered + // by pressing return in replace line edit + if (m_replaceButton->isEnabled()) { + m_infoBar.clear(); + emit replaceButtonClicked(m_replaceTextEdit->text(), checkedItems(), m_preserveCaseCheck->isChecked()); + } +} + +void SearchResultWidget::cancel() +{ + m_cancelButton->setVisible(false); + if (m_infoBar.containsInfo(Core::Id(SIZE_WARNING_ID))) + cancelAfterSizeWarning(); + else + emit cancelled(); +} + +void SearchResultWidget::searchAgain() +{ + emit searchAgainRequested(); +} + +QList SearchResultWidget::checkedItems() const +{ + QList result; + Internal::SearchResultTreeModel *model = m_searchResultTreeView->model(); + const int fileCount = model->rowCount(QModelIndex()); + for (int i = 0; i < fileCount; ++i) { + QModelIndex fileIndex = model->index(i, 0, QModelIndex()); + Internal::SearchResultTreeItem *fileItem = static_cast(fileIndex.internalPointer()); + Q_ASSERT(fileItem != 0); + for (int rowIndex = 0; rowIndex < fileItem->childrenCount(); ++rowIndex) { + QModelIndex textIndex = model->index(rowIndex, 0, fileIndex); + Internal::SearchResultTreeItem *rowItem = static_cast(textIndex.internalPointer()); + if (rowItem->checkState()) + result << rowItem->item; + } + } + return result; +} + +void SearchResultWidget::updateMatchesFoundLabel() +{ + if (m_count == 0) + m_matchesFoundLabel->setText(tr("No matches found.")); + else + m_matchesFoundLabel->setText(tr("%n matches found.", 0, m_count)); +} + +#include "searchresultwidget.moc" diff --git a/src/plugins/coreplugin/find/searchresultwidget.h b/src/plugins/coreplugin/find/searchresultwidget.h new file mode 100644 index 00000000000..e9f64b4164e --- /dev/null +++ b/src/plugins/coreplugin/find/searchresultwidget.h @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef SEARCHRESULTWIDGET_H +#define SEARCHRESULTWIDGET_H + +#include "searchresultwindow.h" + +#include + +#include + +QT_BEGIN_NAMESPACE +class QFrame; +class QLabel; +class QLineEdit; +class QToolButton; +class QCheckBox; +QT_END_NAMESPACE + +namespace Core { +namespace Internal { + +class SearchResultTreeView; +class SearchResultColor; + +class SearchResultWidget : public QWidget +{ + Q_OBJECT +public: + explicit SearchResultWidget(QWidget *parent = 0); + ~SearchResultWidget(); + + void setInfo(const QString &label, const QString &toolTip, const QString &term); + + void addResult(const QString &fileName, int lineNumber, const QString &lineText, + int searchTermStart, int searchTermLength, const QVariant &userData = QVariant()); + void addResults(const QList &items, SearchResult::AddMode mode); + + int count() const; + + QString dontAskAgainGroup() const; + void setDontAskAgainGroup(const QString &group); + + void setTextToReplace(const QString &textToReplace); + QString textToReplace() const; + void setShowReplaceUI(bool visible); + + bool hasFocusInternally() const; + void setFocusInternally(); + bool canFocusInternally() const; + + void notifyVisibilityChanged(bool visible); + + void setTextEditorFont(const QFont &font, const SearchResultColor color); + + void setAutoExpandResults(bool expand); + void expandAll(); + void collapseAll(); + + void goToNext(); + void goToPrevious(); + + void restart(); + + void setSearchAgainSupported(bool supported); + void setSearchAgainEnabled(bool enabled); + +public slots: + void finishSearch(bool canceled); + void sendRequestPopup(); + +signals: + void activated(const Core::SearchResultItem &item); + void replaceButtonClicked(const QString &replaceText, const QList &checkedItems, bool preserveCase); + void searchAgainRequested(); + void cancelled(); + void paused(bool paused); + void restarted(); + void visibilityChanged(bool visible); + void requestPopup(bool focus); + + void navigateStateChanged(); + +private slots: + void continueAfterSizeWarning(); + void cancelAfterSizeWarning(); + void handleJumpToSearchResult(const SearchResultItem &item); + void handleReplaceButton(); + void cancel(); + void searchAgain(); + +private: + QList checkedItems() const; + void updateMatchesFoundLabel(); + + SearchResultTreeView *m_searchResultTreeView; + int m_count; + QString m_dontAskAgainGroup; + QFrame *m_messageWidget; + Core::InfoBar m_infoBar; + Core::InfoBarDisplay m_infoBarDisplay; + bool m_isShowingReplaceUI; + QLabel *m_replaceLabel; + QLineEdit *m_replaceTextEdit; + QToolButton *m_replaceButton; + QToolButton *m_searchAgainButton; + QCheckBox *m_preserveCaseCheck; + bool m_searchAgainSupported; + QWidget *m_descriptionContainer; + QLabel *m_label; + QLabel *m_searchTerm; + QToolButton *m_cancelButton; + QLabel *m_matchesFoundLabel; +}; + +} // Internal +} // Find + +#endif // SEARCHRESULTWIDGET_H diff --git a/src/plugins/coreplugin/find/searchresultwindow.cpp b/src/plugins/coreplugin/find/searchresultwindow.cpp new file mode 100644 index 00000000000..dd4f87475f2 --- /dev/null +++ b/src/plugins/coreplugin/find/searchresultwindow.cpp @@ -0,0 +1,715 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "searchresultwindow.h" +#include "searchresultwidget.h" +#include "searchresultcolor.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +static const char SETTINGSKEYSECTIONNAME[] = "SearchResults"; +static const char SETTINGSKEYEXPANDRESULTS[] = "ExpandResults"; +static const int MAX_SEARCH_HISTORY = 12; + +namespace Core { + +namespace Internal { + + class InternalScrollArea : public QScrollArea + { + Q_OBJECT + public: + explicit InternalScrollArea(QWidget *parent) + : QScrollArea(parent) + { + setFrameStyle(QFrame::NoFrame); + setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + } + + QSize sizeHint() const + { + if (widget()) + return widget()->size(); + return QScrollArea::sizeHint(); + } + }; + + class SearchResultWindowPrivate : public QObject + { + Q_OBJECT + public: + SearchResultWindowPrivate(SearchResultWindow *window); + bool isSearchVisible() const; + int visibleSearchIndex() const; + void setCurrentIndex(int index, bool focus); + + FindPlugin *m_plugin; + SearchResultWindow *q; + QList m_searchResultWidgets; + QToolButton *m_expandCollapseButton; + QAction *m_expandCollapseAction; + static const bool m_initiallyExpand = false; + QWidget *m_spacer; + QComboBox *m_recentSearchesBox; + QStackedWidget *m_widget; + QList m_searchResults; + int m_currentIndex; + QFont m_font; + SearchResultColor m_color; + + public slots: + void setCurrentIndex(int index); + void moveWidgetToTop(); + void popupRequested(bool focus); + }; + + SearchResultWindowPrivate::SearchResultWindowPrivate(SearchResultWindow *window) + : q(window) + { + } + + bool SearchResultWindowPrivate::isSearchVisible() const + { + return m_currentIndex > 0; + } + + int SearchResultWindowPrivate::visibleSearchIndex() const + { + return m_currentIndex - 1; + } + + void SearchResultWindowPrivate::setCurrentIndex(int index, bool focus) + { + if (isSearchVisible()) + m_searchResultWidgets.at(visibleSearchIndex())->notifyVisibilityChanged(false); + m_currentIndex = index; + m_widget->setCurrentIndex(index); + m_recentSearchesBox->setCurrentIndex(index); + if (!isSearchVisible()) { + if (focus) + m_widget->currentWidget()->setFocus(); + m_expandCollapseButton->setEnabled(false); + } else { + if (focus) + m_searchResultWidgets.at(visibleSearchIndex())->setFocusInternally(); + m_searchResultWidgets.at(visibleSearchIndex())->notifyVisibilityChanged(true); + m_expandCollapseButton->setEnabled(true); + } + q->navigateStateChanged(); + } + + void SearchResultWindowPrivate::setCurrentIndex(int index) + { + setCurrentIndex(index, true/*focus*/); + } + + void SearchResultWindowPrivate::moveWidgetToTop() + { + SearchResultWidget *widget = qobject_cast(sender()); + QTC_ASSERT(widget, return); + int index = m_searchResultWidgets.indexOf(widget); + if (index == 0) + return; // nothing to do + int internalIndex = index + 1/*account for "new search" entry*/; + QString searchEntry = m_recentSearchesBox->itemText(internalIndex); + + m_searchResultWidgets.removeAt(index); + m_widget->removeWidget(widget); + m_recentSearchesBox->removeItem(internalIndex); + SearchResult *result = m_searchResults.takeAt(index); + + m_searchResultWidgets.prepend(widget); + m_widget->insertWidget(1, widget); + m_recentSearchesBox->insertItem(1, searchEntry); + m_searchResults.prepend(result); + + // adapt the current index + if (index == visibleSearchIndex()) { + // was visible, so we switch + // this is the default case + m_currentIndex = 1; + m_widget->setCurrentIndex(1); + m_recentSearchesBox->setCurrentIndex(1); + } else if (visibleSearchIndex() < index) { + // academical case where the widget moved before the current widget + // only our internal book keeping needed + ++m_currentIndex; + } + } + + void SearchResultWindowPrivate::popupRequested(bool focus) + { + SearchResultWidget *widget = qobject_cast(sender()); + QTC_ASSERT(widget, return); + int internalIndex = m_searchResultWidgets.indexOf(widget) + 1/*account for "new search" entry*/; + setCurrentIndex(internalIndex, focus); + q->popup(focus ? Core::IOutputPane::ModeSwitch | Core::IOutputPane::WithFocus + : Core::IOutputPane::NoModeSwitch); + } +} + +using namespace Core::Internal; + +/*! + \enum Core::SearchResultWindow::SearchMode + This enum type specifies whether a search should show the replace UI or not: + + \value SearchOnly + The search does not support replace. + \value SearchAndReplace + The search supports replace, so show the UI for it. +*/ + +/*! + \class Core::SearchResult + \brief The SearchResult class reports user interaction, such as the + activation of a search result item. + + Whenever a new search is initiated via startNewSearch, an instance of this + class is returned to provide the initiator with the hooks for handling user + interaction. +*/ + +/*! + \fn void SearchResult::activated(const Core::SearchResultItem &item) + Indicates that the user activated the search result \a item by + double-clicking it, for example. +*/ + +/*! + \fn void SearchResult::replaceButtonClicked(const QString &replaceText, const QList &checkedItems, bool preserveCase) + Indicates that the user initiated a text replace by selecting + \gui {Replace All}, for example. + + The signal reports the text to use for replacement in \a replaceText, + and the list of search result items that were selected by the user + in \a checkedItems. + The handler of this signal should apply the replace only on the selected + items. +*/ + +/*! + \class Core::SearchResultWindow + \brief The SearchResultWindow class is the implementation of a commonly + shared \gui{Search Results} output pane. Use it to show search results + to a user. + + Whenever you want to show the user a list of search results, or want + to present UI for a global search and replace, use the single instance + of this class. + + Except for being an implementation of a output pane, the + SearchResultWindow has a few functions and one enum that allows other + plugins to show their search results and hook into the user actions for + selecting an entry and performing a global replace. + + Whenever you start a search, call startNewSearch(SearchMode) to initialize + the \gui {Search Results} output pane. The parameter determines if the GUI for + replacing should be shown. + The function returns a SearchResult object that is your + hook into the signals from user interaction for this search. + When you produce search results, call addResults or addResult to add them + to the \gui {Search Results} output pane. + After the search has finished call finishSearch to inform the + \gui {Search Results} output pane about it. + + You will get activated signals via your SearchResult instance when + the user selects a search result item, and, if you started the search + with the SearchAndReplace option, the replaceButtonClicked signal + when the user requests a replace. +*/ + +/*! + \fn QString SearchResultWindow::displayName() const + \internal +*/ + +SearchResultWindow *SearchResultWindow::m_instance = 0; + +/*! + \internal +*/ +SearchResultWindow::SearchResultWindow(QWidget *newSearchPanel) + : d(new SearchResultWindowPrivate(this)) +{ + m_instance = this; + + d->m_spacer = new QWidget; + d->m_spacer->setMinimumWidth(30); + d->m_recentSearchesBox = new QComboBox; + d->m_recentSearchesBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); + d->m_recentSearchesBox->addItem(tr("New Search")); + connect(d->m_recentSearchesBox, SIGNAL(activated(int)), d, SLOT(setCurrentIndex(int))); + + d->m_widget = new QStackedWidget; + d->m_widget->setWindowTitle(displayName()); + + InternalScrollArea *newSearchArea = new InternalScrollArea(d->m_widget); + newSearchArea->setWidget(newSearchPanel); + newSearchArea->setFocusProxy(newSearchPanel); + d->m_widget->addWidget(newSearchArea); + d->m_currentIndex = 0; + + d->m_expandCollapseButton = new QToolButton(d->m_widget); + d->m_expandCollapseButton->setAutoRaise(true); + + d->m_expandCollapseAction = new QAction(tr("Expand All"), this); + d->m_expandCollapseAction->setCheckable(true); + d->m_expandCollapseAction->setIcon(QIcon(QLatin1String(":/find/images/expand.png"))); + Core::Command *cmd = Core::ActionManager::registerAction( + d->m_expandCollapseAction, "Find.ExpandAll", + Core::Context(Core::Constants::C_GLOBAL)); + cmd->setAttribute(Core::Command::CA_UpdateText); + d->m_expandCollapseButton->setDefaultAction(cmd->action()); + + connect(d->m_expandCollapseAction, SIGNAL(toggled(bool)), this, SLOT(handleExpandCollapseToolButton(bool))); + readSettings(); +} + +/*! + \internal +*/ +SearchResultWindow::~SearchResultWindow() +{ + qDeleteAll(d->m_searchResults); + delete d->m_widget; + d->m_widget = 0; + delete d; +} + +/*! + Returns the single shared instance of the \gui {Search Results} output pane. +*/ +SearchResultWindow *SearchResultWindow::instance() +{ + return m_instance; +} + +/*! + \internal +*/ +void SearchResultWindow::visibilityChanged(bool visible) +{ + if (d->isSearchVisible()) + d->m_searchResultWidgets.at(d->visibleSearchIndex())->notifyVisibilityChanged(visible); +} + +/*! + \internal +*/ +QWidget *SearchResultWindow::outputWidget(QWidget *) +{ + return d->m_widget; +} + +/*! + \internal +*/ +QList SearchResultWindow::toolBarWidgets() const +{ + return QList() << d->m_expandCollapseButton << d->m_spacer << d->m_recentSearchesBox; +} + +/*! + Tells the \gui {Search Results} output pane to start a new search. + + The \a label should be a string that shortly describes the type of the + search, that is, the search filter and possibly the most relevant search + option, followed by a colon ':'. For example: \c {Project 'myproject':} + The \a searchTerm is shown after the colon. + The \a toolTip should elaborate on the search parameters, like file patterns that are searched and + find flags. + If \a cfgGroup is not empty, it will be used for storing the "do not ask again" + setting of a "this change cannot be undone" warning (which is implicitly requested + by passing a non-empty group). + Returns a SearchResult object that is used for signaling user interaction + with the results of this search. + The search result window owns the returned SearchResult + and might delete it any time, even while the search is running + (for example, when the user clears the \gui {Search Results} pane, or when + the user opens so many other searches + that this search falls out of the history). + +*/ +SearchResult *SearchResultWindow::startNewSearch(const QString &label, + const QString &toolTip, + const QString &searchTerm, + SearchMode searchOrSearchAndReplace, + const QString &cfgGroup) +{ + if (d->m_searchResults.size() >= MAX_SEARCH_HISTORY) { + d->m_searchResultWidgets.last()->notifyVisibilityChanged(false); + // widget first, because that might send interesting signals to SearchResult + delete d->m_searchResultWidgets.takeLast(); + delete d->m_searchResults.takeLast(); + d->m_recentSearchesBox->removeItem(d->m_recentSearchesBox->count()-1); + if (d->m_currentIndex >= d->m_recentSearchesBox->count()) { + // temporarily set the index to the last existing + d->m_currentIndex = d->m_recentSearchesBox->count() - 1; + } + } + Internal::SearchResultWidget *widget = new Internal::SearchResultWidget; + d->m_searchResultWidgets.prepend(widget); + d->m_widget->insertWidget(1, widget); + connect(widget, SIGNAL(navigateStateChanged()), this, SLOT(navigateStateChanged())); + connect(widget, SIGNAL(restarted()), d, SLOT(moveWidgetToTop())); + connect(widget, SIGNAL(requestPopup(bool)), d, SLOT(popupRequested(bool))); + widget->setTextEditorFont(d->m_font, d->m_color); + widget->setShowReplaceUI(searchOrSearchAndReplace != SearchOnly); + widget->setAutoExpandResults(d->m_expandCollapseAction->isChecked()); + widget->setInfo(label, toolTip, searchTerm); + if (searchOrSearchAndReplace == SearchAndReplace) + widget->setDontAskAgainGroup(cfgGroup); + SearchResult *result = new SearchResult(widget); + d->m_searchResults.prepend(result); + d->m_recentSearchesBox->insertItem(1, tr("%1 %2").arg(label, searchTerm)); + if (d->m_currentIndex > 0) + ++d->m_currentIndex; // so setCurrentIndex still knows about the right "currentIndex" and its widget + d->setCurrentIndex(1); + return result; +} + +/*! + Clears the current contents of the \gui {Search Results} output pane. +*/ +void SearchResultWindow::clearContents() +{ + for (int i = d->m_recentSearchesBox->count() - 1; i > 0 /* don't want i==0 */; --i) + d->m_recentSearchesBox->removeItem(i); + foreach (Internal::SearchResultWidget *widget, d->m_searchResultWidgets) + widget->notifyVisibilityChanged(false); + qDeleteAll(d->m_searchResultWidgets); + d->m_searchResultWidgets.clear(); + qDeleteAll(d->m_searchResults); + d->m_searchResults.clear(); + + d->m_currentIndex = 0; + d->m_widget->currentWidget()->setFocus(); + d->m_expandCollapseButton->setEnabled(false); + navigateStateChanged(); +} + +/*! + \internal +*/ +bool SearchResultWindow::hasFocus() const +{ + return d->m_widget->focusWidget() && d->m_widget->focusWidget()->hasFocus(); +} + +/*! + \internal +*/ +bool SearchResultWindow::canFocus() const +{ + if (d->isSearchVisible()) + return d->m_searchResultWidgets.at(d->visibleSearchIndex())->canFocusInternally(); + return true; +} + +/*! + \internal +*/ +void SearchResultWindow::setFocus() +{ + if (!d->isSearchVisible()) + d->m_widget->currentWidget()->setFocus(); + else + d->m_searchResultWidgets.at(d->visibleSearchIndex())->setFocusInternally(); +} + +/*! + \internal +*/ +void SearchResultWindow::setTextEditorFont(const QFont &font, + const QColor &textForegroundColor, + const QColor &textBackgroundColor, + const QColor &highlightForegroundColor, + const QColor &highlightBackgroundColor) +{ + d->m_font = font; + Internal::SearchResultColor color; + color.textBackground = textBackgroundColor; + color.textForeground = textForegroundColor; + color.highlightBackground = highlightBackgroundColor.isValid() + ? highlightBackgroundColor + : textBackgroundColor; + color.highlightForeground = highlightForegroundColor.isValid() + ? highlightForegroundColor + : textForegroundColor; + d->m_color = color; + foreach (Internal::SearchResultWidget *widget, d->m_searchResultWidgets) + widget->setTextEditorFont(font, color); +} + +void SearchResultWindow::openNewSearchPanel() +{ + d->setCurrentIndex(0); + popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus | IOutputPane::EnsureSizeHint); +} + +/*! + \internal +*/ +void SearchResultWindow::handleExpandCollapseToolButton(bool checked) +{ + if (!d->isSearchVisible()) + return; + d->m_searchResultWidgets.at(d->visibleSearchIndex())->setAutoExpandResults(checked); + if (checked) { + d->m_expandCollapseAction->setText(tr("Collapse All")); + d->m_searchResultWidgets.at(d->visibleSearchIndex())->expandAll(); + } else { + d->m_expandCollapseAction->setText(tr("Expand All")); + d->m_searchResultWidgets.at(d->visibleSearchIndex())->collapseAll(); + } +} + +/*! + \internal +*/ +void SearchResultWindow::readSettings() +{ + QSettings *s = Core::ICore::settings(); + s->beginGroup(QLatin1String(SETTINGSKEYSECTIONNAME)); + d->m_expandCollapseAction->setChecked(s->value(QLatin1String(SETTINGSKEYEXPANDRESULTS), d->m_initiallyExpand).toBool()); + s->endGroup(); +} + +/*! + \internal +*/ +void SearchResultWindow::writeSettings() +{ + QSettings *s = Core::ICore::settings(); + s->beginGroup(QLatin1String(SETTINGSKEYSECTIONNAME)); + s->setValue(QLatin1String(SETTINGSKEYEXPANDRESULTS), d->m_expandCollapseAction->isChecked()); + s->endGroup(); +} + +/*! + \internal +*/ +int SearchResultWindow::priorityInStatusBar() const +{ + return 80; +} + +/*! + \internal +*/ +bool SearchResultWindow::canNext() const +{ + if (d->isSearchVisible()) + return d->m_searchResultWidgets.at(d->visibleSearchIndex())->count() > 0; + return false; +} + +/*! + \internal +*/ +bool SearchResultWindow::canPrevious() const +{ + return canNext(); +} + +/*! + \internal +*/ +void SearchResultWindow::goToNext() +{ + int index = d->m_widget->currentIndex(); + if (index != 0) + d->m_searchResultWidgets.at(index-1)->goToNext(); +} + +/*! + \internal +*/ +void SearchResultWindow::goToPrev() +{ + int index = d->m_widget->currentIndex(); + if (index != 0) + d->m_searchResultWidgets.at(index-1)->goToPrevious(); +} + +/*! + \internal +*/ +bool SearchResultWindow::canNavigate() const +{ + return true; +} + +/*! + \internal +*/ +SearchResult::SearchResult(SearchResultWidget *widget) + : m_widget(widget) +{ + connect(widget, SIGNAL(activated(Core::SearchResultItem)), + this, SIGNAL(activated(Core::SearchResultItem))); + connect(widget, SIGNAL(replaceButtonClicked(QString,QList,bool)), + this, SIGNAL(replaceButtonClicked(QString,QList,bool))); + connect(widget, SIGNAL(cancelled()), + this, SIGNAL(cancelled())); + connect(widget, SIGNAL(paused(bool)), + this, SIGNAL(paused(bool))); + connect(widget, SIGNAL(visibilityChanged(bool)), + this, SIGNAL(visibilityChanged(bool))); + connect(widget, SIGNAL(searchAgainRequested()), + this, SIGNAL(searchAgainRequested())); +} + +/*! + Attaches some random \a data to this search, that you can use later. + + \sa userData() +*/ +void SearchResult::setUserData(const QVariant &data) +{ + m_userData = data; +} + +/*! + Returns the data that was attached to this search by calling + setUserData(). + + \sa setUserData() +*/ +QVariant SearchResult::userData() const +{ + return m_userData; +} + +/*! + Returns the text that should replace the text in search results. +*/ +QString SearchResult::textToReplace() const +{ + return m_widget->textToReplace(); +} + +int SearchResult::count() const +{ + return m_widget->count(); +} + +void SearchResult::setSearchAgainSupported(bool supported) +{ + m_widget->setSearchAgainSupported(supported); +} + +/*! + Adds a single result line to the \gui {Search Results} output pane. + + \a fileName, \a lineNumber, and \a lineText are shown on the result line. + \a searchTermStart and \a searchTermLength specify the region that + should be visually marked (string position and length in \a lineText). + You can attach arbitrary \a userData to the search result, which can + be used, for example, when reacting to the signals of the search results + for your search. + + \sa addResults() +*/ +void SearchResult::addResult(const QString &fileName, int lineNumber, const QString &lineText, + int searchTermStart, int searchTermLength, const QVariant &userData) +{ + m_widget->addResult(fileName, lineNumber, lineText, + searchTermStart, searchTermLength, userData); + emit countChanged(m_widget->count()); +} + +/*! + Adds the search result \a items to the \gui {Search Results} output pane. + + \sa addResult() +*/ +void SearchResult::addResults(const QList &items, AddMode mode) +{ + m_widget->addResults(items, mode); + emit countChanged(m_widget->count()); +} + +/*! + Notifies the \gui {Search Results} output pane that the current search + has finished, and the UI should reflect that. +*/ +void SearchResult::finishSearch(bool canceled) +{ + m_widget->finishSearch(canceled); +} + +/*! + Sets the value in the UI element that allows the user to type + the text that should replace text in search results to \a textToReplace. +*/ +void SearchResult::setTextToReplace(const QString &textToReplace) +{ + m_widget->setTextToReplace(textToReplace); +} + +/*! + * Removes all search results. + */ +void SearchResult::restart() +{ + m_widget->restart(); +} + +void SearchResult::setSearchAgainEnabled(bool enabled) +{ + m_widget->setSearchAgainEnabled(enabled); +} + +/*! + * Opens the \gui {Search Results} output pane with this search. + */ +void SearchResult::popup() +{ + m_widget->sendRequestPopup(); +} + +} // namespace Core + +#include "searchresultwindow.moc" diff --git a/src/plugins/coreplugin/find/searchresultwindow.h b/src/plugins/coreplugin/find/searchresultwindow.h new file mode 100644 index 00000000000..c13b9ce32f9 --- /dev/null +++ b/src/plugins/coreplugin/find/searchresultwindow.h @@ -0,0 +1,198 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef SEARCHRESULTWINDOW_H +#define SEARCHRESULTWINDOW_H + +#include + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QFont; +QT_END_NAMESPACE + +namespace Core { +namespace Internal { + class SearchResultTreeView; + class SearchResultWindowPrivate; + class SearchResultWidget; +} +class FindPlugin; +class SearchResultWindow; + +class CORE_EXPORT SearchResultItem +{ +public: + SearchResultItem() + : textMarkPos(-1), + textMarkLength(0), + lineNumber(-1), + useTextEditorFont(false) + { + } + + SearchResultItem(const SearchResultItem &other) + : path(other.path), + text(other.text), + textMarkPos(other.textMarkPos), + textMarkLength(other.textMarkLength), + icon(other.icon), + lineNumber(other.lineNumber), + useTextEditorFont(other.useTextEditorFont), + userData(other.userData) + { + } + + QStringList path; // hierarchy to the parent item of this item + QString text; // text to show for the item itself + int textMarkPos; // 0-based starting position for a mark (-1 for no mark) + int textMarkLength; // length of the mark (0 for no mark) + QIcon icon; // icon to show in front of the item (by be null icon to hide) + int lineNumber; // (0 or -1 for no line number) + bool useTextEditorFont; + QVariant userData; // user data for identification of the item +}; + +class CORE_EXPORT SearchResult : public QObject +{ + Q_OBJECT + +public: + enum AddMode { + AddSorted, + AddOrdered + }; + + void setUserData(const QVariant &data); + QVariant userData() const; + QString textToReplace() const; + int count() const; + void setSearchAgainSupported(bool supported); + +public slots: + void addResult(const QString &fileName, int lineNumber, const QString &lineText, + int searchTermStart, int searchTermLength, const QVariant &userData = QVariant()); + void addResults(const QList &items, AddMode mode); + void finishSearch(bool canceled); + void setTextToReplace(const QString &textToReplace); + void restart(); + void setSearchAgainEnabled(bool enabled); + void popup(); + +signals: + void activated(const Core::SearchResultItem &item); + void replaceButtonClicked(const QString &replaceText, const QList &checkedItems, bool preserveCase); + void cancelled(); + void paused(bool paused); + void visibilityChanged(bool visible); + void countChanged(int count); + void searchAgainRequested(); + void requestEnabledCheck(); + +private: + SearchResult(Internal::SearchResultWidget *widget); + friend class SearchResultWindow; // for the constructor + +private: + Internal::SearchResultWidget *m_widget; + QVariant m_userData; +}; + +class CORE_EXPORT SearchResultWindow : public Core::IOutputPane +{ + Q_OBJECT + +public: + enum SearchMode { + SearchOnly, + SearchAndReplace + }; + + + SearchResultWindow(QWidget *newSearchPanel); + virtual ~SearchResultWindow(); + static SearchResultWindow *instance(); + + QWidget *outputWidget(QWidget *); + QList toolBarWidgets() const; + + QString displayName() const { return tr("Search Results"); } + int priorityInStatusBar() const; + void visibilityChanged(bool visible); + bool hasFocus() const; + bool canFocus() const; + void setFocus(); + + bool canNext() const; + bool canPrevious() const; + void goToNext(); + void goToPrev(); + bool canNavigate() const; + + void setTextEditorFont(const QFont &font, + const QColor &textForegroundColor, + const QColor &textBackgroundColor, + const QColor &highlightForegroundColor, + const QColor &highlightBackgroundColor); + void openNewSearchPanel(); + + // The search result window owns the returned SearchResult + // and might delete it any time, even while the search is running + // (e.g. when the user clears the search result pane, or if the user opens so many other searches + // that this search falls out of the history). + SearchResult *startNewSearch(const QString &label, + const QString &toolTip, + const QString &searchTerm, + SearchMode searchOrSearchAndReplace = SearchOnly, + const QString &cfgGroup = QString()); + +public slots: + void clearContents(); + +private slots: + void handleExpandCollapseToolButton(bool checked); + +public: // Used by plugin, do not use + void writeSettings(); + +private: + void readSettings(); + + Internal::SearchResultWindowPrivate *d; + static SearchResultWindow *m_instance; +}; + +} // namespace Core + +Q_DECLARE_METATYPE(Core::SearchResultItem) + +#endif // SEARCHRESULTWINDOW_H diff --git a/src/plugins/coreplugin/find/textfindconstants.h b/src/plugins/coreplugin/find/textfindconstants.h new file mode 100644 index 00000000000..53292327b30 --- /dev/null +++ b/src/plugins/coreplugin/find/textfindconstants.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef TEXTFINDCONSTANTS_H +#define TEXTFINDCONSTANTS_H + +#include + +#include +#include +#include + +namespace Core { +namespace Constants { + +const char M_FIND[] = "Find.FindMenu"; +const char M_FIND_ADVANCED[] = "Find.FindAdvancedMenu"; +const char G_FIND_CURRENTDOCUMENT[] = "Find.FindMenu.CurrentDocument"; +const char G_FIND_FILTERS[] = "Find.FindMenu.Filters"; +const char G_FIND_FLAGS[] = "Find.FindMenu.Flags"; +const char G_FIND_ACTIONS[] = "Find.FindMenu.Actions"; + +const char ADVANCED_FIND[] = "Find.Dialog"; +const char FIND_IN_DOCUMENT[] = "Find.FindInCurrentDocument"; +const char FIND_NEXT_SELECTED[]= "Find.FindNextSelected"; +const char FIND_PREV_SELECTED[]= "Find.FindPreviousSelected"; +const char FIND_NEXT[] = "Find.FindNext"; +const char FIND_PREVIOUS[] = "Find.FindPrevious"; +const char REPLACE[] = "Find.Replace"; +const char REPLACE_NEXT[] = "Find.ReplaceNext"; +const char REPLACE_PREVIOUS[] = "Find.ReplacePrevious"; +const char REPLACE_ALL[] = "Find.ReplaceAll"; +const char CASE_SENSITIVE[] = "Find.CaseSensitive"; +const char WHOLE_WORDS[] = "Find.WholeWords"; +const char REGULAR_EXPRESSIONS[] = "Find.RegularExpressions"; +const char PRESERVE_CASE[] = "Find.PreserveCase"; +const char TASK_SEARCH[] = "Find.Task.Search"; + +} // namespace Constants + +enum FindFlag { + FindBackward = 0x01, + FindCaseSensitively = 0x02, + FindWholeWords = 0x04, + FindRegularExpression = 0x08, + FindPreserveCase = 0x10 +}; +Q_DECLARE_FLAGS(FindFlags, FindFlag) + +// defined in findplugin.cpp +QTextDocument::FindFlags CORE_EXPORT textDocumentFlagsForFindFlags(FindFlags flags); + +} // namespace Core + +Q_DECLARE_OPERATORS_FOR_FLAGS(Core::FindFlags) +Q_DECLARE_METATYPE(Core::FindFlags) + +#endif // TEXTFINDCONSTANTS_H diff --git a/src/plugins/coreplugin/find/treeviewfind.cpp b/src/plugins/coreplugin/find/treeviewfind.cpp new file mode 100644 index 00000000000..6a1c9375571 --- /dev/null +++ b/src/plugins/coreplugin/find/treeviewfind.cpp @@ -0,0 +1,277 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "treeviewfind.h" + +#include +#include +#include + +namespace Core { + +class ItemModelFindPrivate +{ +public: + explicit ItemModelFindPrivate(QTreeView *view, int role) + : m_view(view) + , m_incrementalWrappedState(false), + m_role(role) + { + } + + QTreeView *m_view; + QModelIndex m_incrementalFindStart; + bool m_incrementalWrappedState; + int m_role; +}; + +TreeViewFind::TreeViewFind(QTreeView *view, int role) + : d(new ItemModelFindPrivate(view, role)) +{ +} + +TreeViewFind::~TreeViewFind() +{ + delete d; +} + +bool TreeViewFind::supportsReplace() const +{ + return false; +} + +FindFlags TreeViewFind::supportedFindFlags() const +{ + return FindBackward | FindCaseSensitively | FindRegularExpression | FindWholeWords; +} + +void TreeViewFind::resetIncrementalSearch() +{ + d->m_incrementalFindStart = QModelIndex(); + d->m_incrementalWrappedState = false; +} + +void TreeViewFind::clearResults() +{ +} + +QString TreeViewFind::currentFindString() const +{ + return QString(); +} + +QString TreeViewFind::completedFindString() const +{ + return QString(); +} + +void TreeViewFind::highlightAll(const QString &/*txt*/, FindFlags /*findFlags*/) +{ +} + +IFindSupport::Result TreeViewFind::findIncremental(const QString &txt, FindFlags findFlags) +{ + if (!d->m_incrementalFindStart.isValid()) { + d->m_incrementalFindStart = d->m_view->currentIndex(); + d->m_incrementalWrappedState = false; + } + d->m_view->setCurrentIndex(d->m_incrementalFindStart); + bool wrapped = false; + IFindSupport::Result result = find(txt, findFlags, true/*startFromCurrent*/, + &wrapped); + if (wrapped != d->m_incrementalWrappedState) { + d->m_incrementalWrappedState = wrapped; + showWrapIndicator(d->m_view); + } + return result; +} + +IFindSupport::Result TreeViewFind::findStep(const QString &txt, FindFlags findFlags) +{ + bool wrapped = false; + IFindSupport::Result result = find(txt, findFlags, false/*startFromNext*/, + &wrapped); + if (wrapped) + showWrapIndicator(d->m_view); + if (result == IFindSupport::Found) { + d->m_incrementalFindStart = d->m_view->currentIndex(); + d->m_incrementalWrappedState = false; + } + return result; +} + +IFindSupport::Result TreeViewFind::find(const QString &searchTxt, + FindFlags findFlags, + bool startFromCurrentIndex, + bool *wrapped) +{ + if (wrapped) + *wrapped = false; + if (searchTxt.isEmpty()) + return IFindSupport::NotFound; + + QTextDocument::FindFlags flags = textDocumentFlagsForFindFlags(findFlags); + QModelIndex resultIndex; + QModelIndex currentIndex = d->m_view->currentIndex(); + QModelIndex index = currentIndex; + int currentRow = currentIndex.row(); + + bool backward = (flags & QTextDocument::FindBackward); + if (wrapped) + *wrapped = false; + bool anyWrapped = false; + bool stepWrapped = false; + if (!startFromCurrentIndex) + index = followingIndex(index, backward, &stepWrapped); + else + currentRow = -1; + do { + anyWrapped |= stepWrapped; // update wrapped state if we actually stepped to next/prev item + if (index.isValid()) { + const QString &text = d->m_view->model()->data( + index, d->m_role).toString(); + if (findFlags & FindRegularExpression) { + bool sensitive = (findFlags & FindCaseSensitively); + QRegExp searchExpr = QRegExp(searchTxt, + (sensitive ? Qt::CaseSensitive : + Qt::CaseInsensitive)); + if (searchExpr.indexIn(text) != -1 + && d->m_view->model()->flags(index) & Qt::ItemIsSelectable + && (index.row() != currentRow || index.parent() != currentIndex.parent())) + resultIndex = index; + } else { + QTextDocument doc(text); + if (!doc.find(searchTxt, 0, + flags & (FindCaseSensitively | FindWholeWords)).isNull() + && d->m_view->model()->flags(index) & Qt::ItemIsSelectable + && (index.row() != currentRow || index.parent() != currentIndex.parent())) + resultIndex = index; + } + } + index = followingIndex(index, backward, &stepWrapped); + } while (!resultIndex.isValid() && index.isValid() && index != currentIndex); + + if (resultIndex.isValid()) { + d->m_view->setCurrentIndex(resultIndex); + d->m_view->scrollTo(resultIndex); + if (resultIndex.parent().isValid()) + d->m_view->expand(resultIndex.parent()); + if (wrapped) + *wrapped = anyWrapped; + return IFindSupport::Found; + } + return IFindSupport::NotFound; +} + +QModelIndex TreeViewFind::nextIndex(const QModelIndex &idx, bool *wrapped) const +{ + if (wrapped) + *wrapped = false; + QAbstractItemModel *model = d->m_view->model(); + // pathological + if (!idx.isValid()) + return model->index(0, 0); + + // same parent has more columns, go to next column + if (idx.column() + 1 < model->columnCount(idx.parent())) + return model->index(idx.row(), idx.column() + 1, idx.parent()); + + // tree views have their children attached to first column + // make sure we are at first column + QModelIndex current = model->index(idx.row(), 0, idx.parent()); + + // check for children + if (model->rowCount(current) > 0) + return current.child(0, 0); + + // no more children, go up and look for parent with more children + QModelIndex nextIndex; + while (!nextIndex.isValid()) { + int row = current.row(); + current = current.parent(); + + if (row + 1 < model->rowCount(current)) { + // Same parent has another child + nextIndex = model->index(row + 1, 0, current); + } else { + // go up one parent + if (!current.isValid()) { + // we start from the beginning + if (wrapped) + *wrapped = true; + nextIndex = model->index(0, 0); + } + } + } + return nextIndex; +} + +QModelIndex TreeViewFind::prevIndex(const QModelIndex &idx, bool *wrapped) const +{ + if (wrapped) + *wrapped = false; + QAbstractItemModel *model = d->m_view->model(); + // if same parent has earlier columns, just move there + if (idx.column() > 0) + return model->index(idx.row(), idx.column() - 1, idx.parent()); + + QModelIndex current = idx; + bool checkForChildren = true; + if (current.isValid()) { + int row = current.row(); + if (row > 0) { + current = model->index(row - 1, 0, current.parent()); + } else { + current = current.parent(); + checkForChildren = !current.isValid(); + if (checkForChildren && wrapped) { + // we start from the end + *wrapped = true; + } + } + } + if (checkForChildren) { + // traverse down the hierarchy + while (int rc = model->rowCount(current)) { + current = model->index(rc - 1, 0, current); + } + } + // set to last column + current = model->index(current.row(), model->columnCount(current.parent()) - 1, current.parent()); + return current; +} + +QModelIndex TreeViewFind::followingIndex(const QModelIndex &idx, bool backward, bool *wrapped) +{ + if (backward) + return prevIndex(idx, wrapped); + return nextIndex(idx, wrapped); +} + +} // namespace Core diff --git a/src/plugins/coreplugin/find/treeviewfind.h b/src/plugins/coreplugin/find/treeviewfind.h new file mode 100644 index 00000000000..06842d2b795 --- /dev/null +++ b/src/plugins/coreplugin/find/treeviewfind.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef TREEVIEWFIND_H +#define TREEVIEWFIND_H + +#include "ifindsupport.h" + +QT_BEGIN_NAMESPACE +class QTreeView; +class QModelIndex; +QT_END_NAMESPACE + +namespace Core { +class ItemModelFindPrivate; + +class CORE_EXPORT TreeViewFind : public IFindSupport +{ + Q_OBJECT +public: + explicit TreeViewFind(QTreeView *view, int role = Qt::DisplayRole); + virtual ~TreeViewFind(); + + bool supportsReplace() const; + FindFlags supportedFindFlags() const; + void resetIncrementalSearch(); + void clearResults(); + QString currentFindString() const; + QString completedFindString() const; + + virtual void highlightAll(const QString &txt, FindFlags findFlags); + Result findIncremental(const QString &txt, FindFlags findFlags); + Result findStep(const QString &txt, FindFlags findFlags); + +private: + Result find(const QString &txt, FindFlags findFlags, + bool startFromCurrentIndex, bool *wrapped); + QModelIndex nextIndex(const QModelIndex &idx, bool *wrapped) const; + QModelIndex prevIndex(const QModelIndex &idx, bool *wrapped) const; + QModelIndex followingIndex(const QModelIndex &idx, bool backward, + bool *wrapped); + +private: + ItemModelFindPrivate *d; +}; + +} // namespace Core + +#endif // TREEVIEWFIND_H diff --git a/src/plugins/coreplugin/locator/basefilefilter.cpp b/src/plugins/coreplugin/locator/basefilefilter.cpp new file mode 100644 index 00000000000..920f5b570db --- /dev/null +++ b/src/plugins/coreplugin/locator/basefilefilter.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "basefilefilter.h" + +#include +#include + +#include +#include + +using namespace Core; +using namespace Core; +using namespace Utils; + +BaseFileFilter::BaseFileFilter() + : m_forceNewSearchList(false) +{ +} + +QList BaseFileFilter::matchesFor(QFutureInterface &future, const QString &origEntry) +{ + updateFiles(); + QList betterEntries; + QList goodEntries; + QString needle = trimWildcards(origEntry); + const QString lineNoSuffix = EditorManager::splitLineNumber(&needle); + QStringMatcher matcher(needle, Qt::CaseInsensitive); + const QChar asterisk = QLatin1Char('*'); + QRegExp regexp(asterisk + needle+ asterisk, Qt::CaseInsensitive, QRegExp::Wildcard); + if (!regexp.isValid()) + return betterEntries; + const QChar pathSeparator = QDir::separator(); + const bool hasPathSeparator = needle.contains(pathSeparator); + const bool hasWildcard = needle.contains(asterisk) || needle.contains(QLatin1Char('?')); + QStringList searchListPaths; + QStringList searchListNames; + const bool containsPreviousEntry = !m_previousEntry.isEmpty() + && needle.contains(m_previousEntry); + const bool pathSeparatorAdded = !m_previousEntry.contains(pathSeparator) + && needle.contains(pathSeparator); + if (!m_forceNewSearchList && containsPreviousEntry && !pathSeparatorAdded) { + searchListPaths = m_previousResultPaths; + searchListNames = m_previousResultNames; + } else { + searchListPaths = m_files; + searchListNames = m_fileNames; + } + m_previousResultPaths.clear(); + m_previousResultNames.clear(); + m_forceNewSearchList = false; + m_previousEntry = needle; + const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(needle); + QStringListIterator paths(searchListPaths); + QStringListIterator names(searchListNames); + while (paths.hasNext() && names.hasNext()) { + if (future.isCanceled()) + break; + + QString path = paths.next(); + QString name = names.next(); + QString matchText = hasPathSeparator ? path : name; + if ((hasWildcard && regexp.exactMatch(matchText)) + || (!hasWildcard && matcher.indexIn(matchText) != -1)) { + QFileInfo fi(path); + LocatorFilterEntry entry(this, fi.fileName(), QString(path + lineNoSuffix)); + entry.extraInfo = FileUtils::shortNativePath(FileName(fi)); + entry.fileName = path; + if (matchText.startsWith(needle, caseSensitivityForPrefix)) + betterEntries.append(entry); + else + goodEntries.append(entry); + m_previousResultPaths.append(path); + m_previousResultNames.append(name); + } + } + + betterEntries.append(goodEntries); + return betterEntries; +} + +void BaseFileFilter::accept(Core::LocatorFilterEntry selection) const +{ + EditorManager::openEditor(selection.internalData.toString(), Id(), + EditorManager::CanContainLineNumber); +} + +void BaseFileFilter::generateFileNames() +{ + m_fileNames.clear(); + foreach (const QString &fileName, m_files) { + QFileInfo fi(fileName); + m_fileNames.append(fi.fileName()); + } + m_forceNewSearchList = true; +} + +void BaseFileFilter::updateFiles() +{ +} diff --git a/src/plugins/coreplugin/locator/basefilefilter.h b/src/plugins/coreplugin/locator/basefilefilter.h new file mode 100644 index 00000000000..44102b30e4e --- /dev/null +++ b/src/plugins/coreplugin/locator/basefilefilter.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef BASEFILEFILTER_H +#define BASEFILEFILTER_H + +#include "ilocatorfilter.h" + +#include + +namespace Core { + +class CORE_EXPORT BaseFileFilter : public Core::ILocatorFilter +{ + Q_OBJECT + +public: + BaseFileFilter(); + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(Core::LocatorFilterEntry selection) const; + +protected: + virtual void updateFiles(); + void generateFileNames(); + + inline QStringList &files() { return m_files; } + inline const QStringList &files() const { return m_files; } + +private: + QStringList m_files; + QStringList m_fileNames; + QStringList m_previousResultPaths; + QStringList m_previousResultNames; + bool m_forceNewSearchList; + QString m_previousEntry; +}; + +} // namespace Core + +#endif // BASEFILEFILTER_H diff --git a/src/plugins/coreplugin/locator/commandlocator.cpp b/src/plugins/coreplugin/locator/commandlocator.cpp new file mode 100644 index 00000000000..13b4ec14859 --- /dev/null +++ b/src/plugins/coreplugin/locator/commandlocator.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "commandlocator.h" + +#include + +#include + +#include + +namespace Core { + +struct CommandLocatorPrivate +{ + QList commands; +}; + +CommandLocator::CommandLocator(Core::Id id, + const QString &displayName, + const QString &shortCutString, + QObject *parent) : + Core::ILocatorFilter(parent), + d(new CommandLocatorPrivate) +{ + setId(id); + setDisplayName(displayName); + setShortcutString(shortCutString); +} + +CommandLocator::~CommandLocator() +{ + delete d; +} + +void CommandLocator::appendCommand(Core::Command *cmd) +{ + d->commands.push_back(cmd); +} + +QList CommandLocator::matchesFor(QFutureInterface &future, const QString &entry) +{ + QList goodEntries; + QList betterEntries; + // Get active, enabled actions matching text, store in list. + // Reference via index in extraInfo. + const QChar ampersand = QLatin1Char('&'); + const Qt::CaseSensitivity caseSensitivity_ = caseSensitivity(entry); + const int count = d->commands.size(); + for (int i = 0; i < count; i++) { + if (future.isCanceled()) + break; + if (d->commands.at(i)->isActive()) { + if (QAction *action = d->commands.at(i)->action()) + if (action->isEnabled()) { + QString text = action->text(); + text.remove(ampersand); + if (text.startsWith(entry, caseSensitivity_)) + betterEntries.append(LocatorFilterEntry(this, text, QVariant(i))); + else if (text.contains(entry, caseSensitivity_)) + goodEntries.append(LocatorFilterEntry(this, text, QVariant(i))); + } + } + } + betterEntries.append(goodEntries); + return betterEntries; +} + +void CommandLocator::accept(Core::LocatorFilterEntry entry) const +{ + // Retrieve action via index. + const int index = entry.internalData.toInt(); + QTC_ASSERT(index >= 0 && index < d->commands.size(), return); + QAction *action = d->commands.at(index)->action(); + QTC_ASSERT(action->isEnabled(), return); + action->trigger(); +} + +void CommandLocator::refresh(QFutureInterface &) +{ +} + +} // namespace Core diff --git a/src/plugins/coreplugin/locator/commandlocator.h b/src/plugins/coreplugin/locator/commandlocator.h new file mode 100644 index 00000000000..d62f5bdfd4e --- /dev/null +++ b/src/plugins/coreplugin/locator/commandlocator.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef COMMANDLOCATOR_H +#define COMMANDLOCATOR_H + +#include "ilocatorfilter.h" + +namespace Core { + +/* Command locators: Provides completion for a set of + * Core::Command's by sub-string of their action's text. */ +class Command; +struct CommandLocatorPrivate; + +class CORE_EXPORT CommandLocator : public Core::ILocatorFilter +{ + Q_OBJECT + +public: + CommandLocator(Core::Id id, const QString &displayName, + const QString &shortCutString, QObject *parent = 0); + ~CommandLocator(); + + void appendCommand(Core::Command *cmd); + + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(LocatorFilterEntry selection) const; + void refresh(QFutureInterface &future); + +private: + CommandLocatorPrivate *d; +}; + +} // namespace Core + +#endif // COMMANDLOCATOR_H diff --git a/src/plugins/coreplugin/locator/directoryfilter.cpp b/src/plugins/coreplugin/locator/directoryfilter.cpp new file mode 100644 index 00000000000..dd7639cfe47 --- /dev/null +++ b/src/plugins/coreplugin/locator/directoryfilter.cpp @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "directoryfilter.h" + +#include +#include + +using namespace Core; +using namespace Core::Internal; + +DirectoryFilter::DirectoryFilter() + : m_name(tr("Generic Directory Filter")), + m_dialog(0) +{ + setId(Core::Id::fromString(m_name)); + setIncludedByDefault(true); + setDisplayName(m_name); + + m_filters.append(QLatin1String("*.h")); + m_filters.append(QLatin1String("*.cpp")); + m_filters.append(QLatin1String("*.ui")); + m_filters.append(QLatin1String("*.qrc")); +} + +QByteArray DirectoryFilter::saveState() const +{ + QMutexLocker locker(&m_lock); + QByteArray value; + QDataStream out(&value, QIODevice::WriteOnly); + out << m_name; + out << m_directories; + out << m_filters; + out << shortcutString(); + out << isIncludedByDefault(); + out << files(); + return value; +} + +bool DirectoryFilter::restoreState(const QByteArray &state) +{ + QMutexLocker locker(&m_lock); + + QString shortcut; + bool defaultFilter; + + QDataStream in(state); + in >> m_name; + in >> m_directories; + in >> m_filters; + in >> shortcut; + in >> defaultFilter; + in >> files(); + + setShortcutString(shortcut); + setIncludedByDefault(defaultFilter); + + generateFileNames(); + return true; +} + +bool DirectoryFilter::openConfigDialog(QWidget *parent, bool &needsRefresh) +{ + bool success = false; + QDialog dialog(parent); + m_dialog = &dialog; + m_ui.setupUi(&dialog); + dialog.setWindowTitle(tr("Filter Configuration")); + connect(m_ui.addButton, SIGNAL(clicked()), + this, SLOT(addDirectory()), Qt::DirectConnection); + connect(m_ui.editButton, SIGNAL(clicked()), + this, SLOT(editDirectory()), Qt::DirectConnection); + connect(m_ui.removeButton, SIGNAL(clicked()), + this, SLOT(removeDirectory()), Qt::DirectConnection); + connect(m_ui.directoryList, SIGNAL(itemSelectionChanged()), + this, SLOT(updateOptionButtons()), Qt::DirectConnection); + m_ui.nameEdit->setText(m_name); + m_ui.nameEdit->selectAll(); + m_ui.directoryList->clear(); + m_ui.directoryList->addItems(m_directories); + m_ui.fileTypeEdit->setText(m_filters.join(QString(QLatin1Char(',')))); + m_ui.shortcutEdit->setText(shortcutString()); + m_ui.defaultFlag->setChecked(!isIncludedByDefault()); + updateOptionButtons(); + if (dialog.exec() == QDialog::Accepted) { + QMutexLocker locker(&m_lock); + bool directoriesChanged = false; + QStringList oldDirectories = m_directories; + QStringList oldFilters = m_filters; + m_name = m_ui.nameEdit->text().trimmed(); + m_directories.clear(); + int oldCount = oldDirectories.count(); + int newCount = m_ui.directoryList->count(); + if (oldCount != newCount) + directoriesChanged = true; + for (int i = 0; i < newCount; ++i) { + m_directories.append(m_ui.directoryList->item(i)->text()); + if (!directoriesChanged && m_directories.at(i) != oldDirectories.at(i)) + directoriesChanged = true; + } + m_filters = m_ui.fileTypeEdit->text().trimmed().split(QLatin1Char(',')); + setShortcutString(m_ui.shortcutEdit->text().trimmed()); + setIncludedByDefault(!m_ui.defaultFlag->isChecked()); + if (directoriesChanged || oldFilters != m_filters) + needsRefresh = true; + success = true; + } + return success; +} + +void DirectoryFilter::addDirectory() +{ + QString dir = QFileDialog::getExistingDirectory(m_dialog, tr("Select Directory")); + if (!dir.isEmpty()) + m_ui.directoryList->addItem(dir); +} + +void DirectoryFilter::editDirectory() +{ + if (m_ui.directoryList->selectedItems().count() < 1) + return; + QListWidgetItem *currentItem = m_ui.directoryList->selectedItems().at(0); + QString dir = QFileDialog::getExistingDirectory(m_dialog, tr("Select Directory"), + currentItem->text()); + if (!dir.isEmpty()) + currentItem->setText(dir); +} + +void DirectoryFilter::removeDirectory() +{ + if (m_ui.directoryList->selectedItems().count() < 1) + return; + QListWidgetItem *currentItem = m_ui.directoryList->selectedItems().at(0); + delete m_ui.directoryList->takeItem(m_ui.directoryList->row(currentItem)); +} + +void DirectoryFilter::updateOptionButtons() +{ + bool haveSelectedItem = (m_ui.directoryList->selectedItems().count() > 0); + m_ui.editButton->setEnabled(haveSelectedItem); + m_ui.removeButton->setEnabled(haveSelectedItem); +} + +void DirectoryFilter::refresh(QFutureInterface &future) +{ + QStringList directories; + { + QMutexLocker locker(&m_lock); + if (m_directories.count() < 1) { + files().clear(); + generateFileNames(); + future.setProgressRange(0, 1); + future.setProgressValueAndText(1, tr("%1 filter update: 0 files").arg(m_name)); + return; + } + directories = m_directories; + } + Utils::SubDirFileIterator it(directories, m_filters); + future.setProgressRange(0, it.maxProgress()); + QStringList filesFound; + while (!future.isCanceled() && it.hasNext()) { + filesFound << it.next(); + if (future.isProgressUpdateNeeded() + || future.progressValue() == 0 /*workaround for regression in Qt*/) { + future.setProgressValueAndText(it.currentProgress(), + tr("%1 filter update: %n files", 0, filesFound.size()).arg(m_name)); + } + } + + if (!future.isCanceled()) { + QMutexLocker locker(&m_lock); + files() = filesFound; + generateFileNames(); + future.setProgressValue(it.maxProgress()); + } else { + future.setProgressValueAndText(it.currentProgress(), tr("%1 filter update: canceled").arg(m_name)); + } +} diff --git a/src/plugins/coreplugin/locator/directoryfilter.h b/src/plugins/coreplugin/locator/directoryfilter.h new file mode 100644 index 00000000000..67e97a6e30b --- /dev/null +++ b/src/plugins/coreplugin/locator/directoryfilter.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef DIRECTORYFILTER_H +#define DIRECTORYFILTER_H + +#include "ui_directoryfilter.h" +#include "basefilefilter.h" + +#include +#include +#include +#include + +namespace Core { +namespace Internal { + +class DirectoryFilter : public BaseFileFilter +{ + Q_OBJECT + +public: + DirectoryFilter(); + QByteArray saveState() const; + bool restoreState(const QByteArray &state); + bool openConfigDialog(QWidget *parent, bool &needsRefresh); + void refresh(QFutureInterface &future); + +private slots: + void addDirectory(); + void editDirectory(); + void removeDirectory(); + void updateOptionButtons(); + +private: + QString m_name; + QStringList m_directories; + QStringList m_filters; + // Our config dialog, uses in addDirectory and editDirectory + // to give their dialogs the right parent + QDialog *m_dialog; + Ui::DirectoryFilterOptions m_ui; + mutable QMutex m_lock; +}; + +} // namespace Internal +} // namespace Core + +#endif // DIRECTORYFILTER_H diff --git a/src/plugins/coreplugin/locator/directoryfilter.ui b/src/plugins/coreplugin/locator/directoryfilter.ui new file mode 100644 index 00000000000..051f7c5104e --- /dev/null +++ b/src/plugins/coreplugin/locator/directoryfilter.ui @@ -0,0 +1,195 @@ + + + Core::Internal::DirectoryFilterOptions + + + + 0 + 0 + 393 + 275 + + + + + + + + + Name: + + + + + + + + + + File types: + + + + + + + Specify file name filters, separated by comma. Filters may contain wildcards. + + + + + + + Prefix: + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Specify a short word/abbreviation that can be used to restrict completions to files from this directory tree. +To do this, you type this shortcut and a space in the Locator entry field, and then the word to search for. + + + + + + + Limit to prefix + + + false + + + + + + + + + Add + + + + + + + Edit + + + + + + + Remove + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Directories: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + 1 + 0 + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + Core::Internal::DirectoryFilterOptions + accept() + + + 353 + 174 + + + 390 + 152 + + + + + buttonBox + rejected() + Core::Internal::DirectoryFilterOptions + reject() + + + 280 + 176 + + + 391 + 141 + + + + + diff --git a/src/plugins/coreplugin/locator/executefilter.cpp b/src/plugins/coreplugin/locator/executefilter.cpp new file mode 100644 index 00000000000..6c2e5f83bd5 --- /dev/null +++ b/src/plugins/coreplugin/locator/executefilter.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "executefilter.h" + +#include +#include +#include + +#include + +using namespace Core; +using namespace Core; +using namespace Core::Internal; + +ExecuteFilter::ExecuteFilter() +{ + setId("Execute custom commands"); + setDisplayName(tr("Execute Custom Commands")); + setShortcutString(QString(QLatin1Char('!'))); + setIncludedByDefault(false); + + m_process = new Utils::QtcProcess(this); + m_process->setEnvironment(Utils::Environment::systemEnvironment()); + connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), this, + SLOT(finished(int,QProcess::ExitStatus))); + connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandardOutput())); + connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStandardError())); + + m_runTimer.setSingleShot(true); + connect(&m_runTimer, SIGNAL(timeout()), this, SLOT(runHeadCommand())); +} + +QList ExecuteFilter::matchesFor(QFutureInterface &future, + const QString &entry) +{ + QList value; + if (!entry.isEmpty()) // avoid empty entry + value.append(LocatorFilterEntry(this, entry, QVariant())); + QList others; + const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry); + foreach (const QString &i, m_commandHistory) { + if (future.isCanceled()) + break; + if (i == entry) // avoid repeated entry + continue; + if (i.startsWith(entry, caseSensitivityForPrefix)) + value.append(LocatorFilterEntry(this, i, QVariant())); + else + others.append(LocatorFilterEntry(this, i, QVariant())); + } + value.append(others); + return value; +} + +void ExecuteFilter::accept(LocatorFilterEntry selection) const +{ + ExecuteFilter *p = const_cast(this); + + const QString value = selection.displayName.trimmed(); + const int index = m_commandHistory.indexOf(value); + if (index != -1 && index != 0) + p->m_commandHistory.removeAt(index); + if (index != 0) + p->m_commandHistory.prepend(value); + + bool found; + QString workingDirectory = Core::VariableManager::value("CurrentDocument:Path", &found); + if (!found || workingDirectory.isEmpty()) + workingDirectory = Core::VariableManager::value("CurrentProject:Path", &found); + + ExecuteData d; + d.workingDirectory = workingDirectory; + const int pos = value.indexOf(QLatin1Char(' ')); + if (pos == -1) { + d.executable = value; + } else { + d.executable = value.left(pos); + d.arguments = value.right(value.length() - pos - 1); + } + + if (m_process->state() != QProcess::NotRunning) { + const QString info(tr("Previous command is still running ('%1').\nDo you want to kill it?") + .arg(p->headCommand())); + int r = QMessageBox::question(0, tr("Kill Previous Process?"), info, + QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, + QMessageBox::Yes); + if (r == QMessageBox::Yes) + m_process->kill(); + if (r != QMessageBox::Cancel) + p->m_taskQueue.enqueue(d); + return; + } + + p->m_taskQueue.enqueue(d); + p->runHeadCommand(); +} + +void ExecuteFilter::finished(int exitCode, QProcess::ExitStatus status) +{ + const QString commandName = headCommand(); + QString message; + if (status == QProcess::NormalExit && exitCode == 0) + message = tr("Command '%1' finished.").arg(commandName); + else + message = tr("Command '%1' failed.").arg(commandName); + MessageManager::write(message); + + m_taskQueue.dequeue(); + if (!m_taskQueue.isEmpty()) + m_runTimer.start(500); +} + +void ExecuteFilter::readStandardOutput() +{ + QByteArray data = m_process->readAllStandardOutput(); + MessageManager::write(QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(), + &m_stdoutState)); +} + +void ExecuteFilter::readStandardError() +{ + static QTextCodec::ConverterState state; + QByteArray data = m_process->readAllStandardError(); + MessageManager::write(QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(), + &m_stderrState)); +} + +void ExecuteFilter::runHeadCommand() +{ + if (!m_taskQueue.isEmpty()) { + const ExecuteData &d = m_taskQueue.head(); + const QString fullPath = Utils::Environment::systemEnvironment().searchInPath(d.executable); + if (fullPath.isEmpty()) { + MessageManager::write(tr("Could not find executable for '%1'").arg(d.executable)); + m_taskQueue.dequeue(); + runHeadCommand(); + return; + } + MessageManager::write(tr("Starting command '%1'").arg(headCommand())); + m_process->setWorkingDirectory(d.workingDirectory); + m_process->setCommand(fullPath, d.arguments); + m_process->start(); + m_process->closeWriteChannel(); + if (!m_process->waitForStarted(1000)) { + MessageManager::write(tr("Could not start process: %1").arg(m_process->errorString())); + m_taskQueue.dequeue(); + runHeadCommand(); + } + } +} + +QString ExecuteFilter::headCommand() const +{ + if (m_taskQueue.isEmpty()) + return QString(); + const ExecuteData &data = m_taskQueue.head(); + if (data.arguments.isEmpty()) + return data.executable; + else + return data.executable + QLatin1Char(' ') + data.arguments; +} diff --git a/src/plugins/coreplugin/locator/executefilter.h b/src/plugins/coreplugin/locator/executefilter.h new file mode 100644 index 00000000000..719d8514c85 --- /dev/null +++ b/src/plugins/coreplugin/locator/executefilter.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef EXECUTEFILTER_H +#define EXECUTEFILTER_H + +#include "ilocatorfilter.h" + +#include + +#include +#include +#include +#include + +namespace Core { +namespace Internal { + +class ExecuteFilter : public Core::ILocatorFilter +{ + Q_OBJECT + struct ExecuteData + { + QString executable; + QString arguments; + QString workingDirectory; + }; + +public: + ExecuteFilter(); + QList matchesFor(QFutureInterface &future, + const QString &entry); + void accept(Core::LocatorFilterEntry selection) const; + void refresh(QFutureInterface &) {} + +private slots: + void finished(int exitCode, QProcess::ExitStatus status); + void readStandardOutput(); + void readStandardError(); + void runHeadCommand(); + +private: + QString headCommand() const; + +private: + QQueue m_taskQueue; + QStringList m_commandHistory; + Utils::QtcProcess *m_process; + QTimer m_runTimer; + QTextCodec::ConverterState m_stdoutState; + QTextCodec::ConverterState m_stderrState; +}; + +} // namespace Internal +} // namespace Core + +#endif // EXECUTEFILTER_H diff --git a/src/plugins/coreplugin/locator/filesystemfilter.cpp b/src/plugins/coreplugin/locator/filesystemfilter.cpp new file mode 100644 index 00000000000..84b05cfd5e9 --- /dev/null +++ b/src/plugins/coreplugin/locator/filesystemfilter.cpp @@ -0,0 +1,187 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "filesystemfilter.h" +#include "locatorwidget.h" +#include +#include + +#include + +using namespace Core; +using namespace Core; +using namespace Core::Internal; + +namespace { + +QList *categorize(const QString &entry, const QString &candidate, + Qt::CaseSensitivity caseSensitivity, + QList *betterEntries, QList *goodEntries) +{ + if (entry.isEmpty() || candidate.startsWith(entry, caseSensitivity)) + return betterEntries; + else if (candidate.contains(entry, caseSensitivity)) + return goodEntries; + return 0; +} + +} // anynoumous namespace + +FileSystemFilter::FileSystemFilter(LocatorWidget *locatorWidget) + : m_locatorWidget(locatorWidget), m_includeHidden(true) +{ + setId("Files in file system"); + setDisplayName(tr("Files in File System")); + setShortcutString(QString(QLatin1Char('f'))); + setIncludedByDefault(false); +} + +QList FileSystemFilter::matchesFor(QFutureInterface &future, const QString &entry) +{ + QList goodEntries; + QList betterEntries; + QFileInfo entryInfo(entry); + QString name = entryInfo.fileName(); + QString directory = entryInfo.path(); + QString filePath = entryInfo.filePath(); + if (entryInfo.isRelative()) { + if (filePath.startsWith(QLatin1String("~/"))) { + directory.replace(0, 1, QDir::homePath()); + } else { + IDocument *document= EditorManager::currentDocument(); + if (document && !document->filePath().isEmpty()) { + QFileInfo info(document->filePath()); + directory.prepend(info.absolutePath() + QLatin1Char('/')); + } + } + } + QDir dirInfo(directory); + QDir::Filters dirFilter = QDir::Dirs|QDir::Drives|QDir::NoDot; + QDir::Filters fileFilter = QDir::Files; + if (m_includeHidden) { + dirFilter |= QDir::Hidden; + fileFilter |= QDir::Hidden; + } + const Qt::CaseSensitivity caseSensitivity_ = caseSensitivity(entry); + QStringList dirs = dirInfo.entryList(dirFilter, + QDir::Name|QDir::IgnoreCase|QDir::LocaleAware); + QStringList files = dirInfo.entryList(fileFilter, + QDir::Name|QDir::IgnoreCase|QDir::LocaleAware); + foreach (const QString &dir, dirs) { + if (future.isCanceled()) + break; + if (QList *category = categorize(name, dir, caseSensitivity_, &betterEntries, + &goodEntries)) { + const QString fullPath = dirInfo.filePath(dir); + LocatorFilterEntry filterEntry(this, dir, QVariant()); + filterEntry.fileName = fullPath; + category->append(filterEntry); + } + } + // file names can match with +linenumber or :linenumber + name = entry; + const QString lineNoSuffix = EditorManager::splitLineNumber(&name); + name = QFileInfo(name).fileName(); + foreach (const QString &file, files) { + if (future.isCanceled()) + break; + if (QList *category = categorize(name, file, caseSensitivity_, &betterEntries, + &goodEntries)) { + const QString fullPath = dirInfo.filePath(file); + LocatorFilterEntry filterEntry(this, file, QString(fullPath + lineNoSuffix)); + filterEntry.fileName = fullPath; + category->append(filterEntry); + } + } + betterEntries.append(goodEntries); + return betterEntries; +} + +void FileSystemFilter::accept(LocatorFilterEntry selection) const +{ + QString fileName = selection.fileName; + QFileInfo info(fileName); + if (info.isDir()) { + QString value = shortcutString(); + value += QLatin1Char(' '); + value += QDir::toNativeSeparators(info.absoluteFilePath() + QLatin1Char('/')); + m_locatorWidget->show(value, value.length()); + return; + } + EditorManager::openEditor(selection.internalData.toString(), Id(), + EditorManager::CanContainLineNumber); +} + +bool FileSystemFilter::openConfigDialog(QWidget *parent, bool &needsRefresh) +{ + Q_UNUSED(needsRefresh) + Ui::FileSystemFilterOptions ui; + QDialog dialog(parent); + ui.setupUi(&dialog); + + ui.hiddenFilesFlag->setChecked(m_includeHidden); + ui.limitCheck->setChecked(!isIncludedByDefault()); + ui.shortcutEdit->setText(shortcutString()); + + if (dialog.exec() == QDialog::Accepted) { + m_includeHidden = ui.hiddenFilesFlag->isChecked(); + setShortcutString(ui.shortcutEdit->text().trimmed()); + setIncludedByDefault(!ui.limitCheck->isChecked()); + return true; + } + return false; +} + +QByteArray FileSystemFilter::saveState() const +{ + QByteArray value; + QDataStream out(&value, QIODevice::WriteOnly); + out << m_includeHidden; + out << shortcutString(); + out << isIncludedByDefault(); + return value; +} + +bool FileSystemFilter::restoreState(const QByteArray &state) +{ + QDataStream in(state); + in >> m_includeHidden; + + // An attempt to prevent setting this on old configuration + if (!in.atEnd()) { + QString shortcut; + bool defaultFilter; + in >> shortcut; + in >> defaultFilter; + setShortcutString(shortcut); + setIncludedByDefault(defaultFilter); + } + + return true; +} diff --git a/src/plugins/coreplugin/locator/filesystemfilter.h b/src/plugins/coreplugin/locator/filesystemfilter.h new file mode 100644 index 00000000000..a6f0283065c --- /dev/null +++ b/src/plugins/coreplugin/locator/filesystemfilter.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef FILESYSTEMFILTER_H +#define FILESYSTEMFILTER_H + +#include "ilocatorfilter.h" +#include "ui_filesystemfilter.h" + +#include +#include +#include +#include + +namespace Core { +namespace Internal { + +class LocatorWidget; + +class FileSystemFilter : public Core::ILocatorFilter +{ + Q_OBJECT + +public: + explicit FileSystemFilter(LocatorWidget *locatorWidget); + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(Core::LocatorFilterEntry selection) const; + QByteArray saveState() const; + bool restoreState(const QByteArray &state); + bool openConfigDialog(QWidget *parent, bool &needsRefresh); + void refresh(QFutureInterface &) {} + +private: + LocatorWidget *m_locatorWidget; + bool m_includeHidden; +}; + +} // namespace Internal +} // namespace Core + +#endif // FILESYSTEMFILTER_H diff --git a/src/plugins/coreplugin/locator/filesystemfilter.ui b/src/plugins/coreplugin/locator/filesystemfilter.ui new file mode 100644 index 00000000000..b6a8944c708 --- /dev/null +++ b/src/plugins/coreplugin/locator/filesystemfilter.ui @@ -0,0 +1,111 @@ + + + Core::Internal::FileSystemFilterOptions + + + + 0 + 0 + 360 + 131 + + + + Add Filter Configuration + + + + + + Prefix: + + + shortcutEdit + + + + + + + + + + Limit to prefix + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + Include hidden files + + + + + + + Filter: + + + + + + + + + buttonBox + accepted() + Core::Internal::FileSystemFilterOptions + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Core::Internal::FileSystemFilterOptions + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/plugins/coreplugin/locator/ilocatorfilter.cpp b/src/plugins/coreplugin/locator/ilocatorfilter.cpp new file mode 100644 index 00000000000..ea91197cc66 --- /dev/null +++ b/src/plugins/coreplugin/locator/ilocatorfilter.cpp @@ -0,0 +1,208 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "ilocatorfilter.h" + +#include +#include +#include +#include +#include +#include + +using namespace Core; + +ILocatorFilter::ILocatorFilter(QObject *parent): + QObject(parent), + m_priority(Medium), + m_includedByDefault(false), + m_hidden(false), + m_enabled(true), + m_isConfigurable(true) +{ +} + +QString ILocatorFilter::shortcutString() const +{ + return m_shortcut; +} + +void ILocatorFilter::setShortcutString(const QString &shortcut) +{ + m_shortcut = shortcut; +} + +QByteArray ILocatorFilter::saveState() const +{ + QByteArray value; + QDataStream out(&value, QIODevice::WriteOnly); + out << shortcutString(); + out << isIncludedByDefault(); + return value; +} + +bool ILocatorFilter::restoreState(const QByteArray &state) +{ + QString shortcut; + bool defaultFilter; + + QDataStream in(state); + in >> shortcut; + in >> defaultFilter; + + setShortcutString(shortcut); + setIncludedByDefault(defaultFilter); + return true; +} + +bool ILocatorFilter::openConfigDialog(QWidget *parent, bool &needsRefresh) +{ + Q_UNUSED(needsRefresh) + + QDialog dialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint); + dialog.setWindowTitle(tr("Filter Configuration")); + + QVBoxLayout *vlayout = new QVBoxLayout(&dialog); + QHBoxLayout *hlayout = new QHBoxLayout; + QLineEdit *shortcutEdit = new QLineEdit(shortcutString()); + QCheckBox *limitCheck = new QCheckBox(tr("Limit to prefix")); + limitCheck->setChecked(!isIncludedByDefault()); + + hlayout->addWidget(new QLabel(tr("Prefix:"))); + hlayout->addWidget(shortcutEdit); + hlayout->addWidget(limitCheck); + + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel); + connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject())); + + vlayout->addLayout(hlayout); + vlayout->addStretch(); + vlayout->addWidget(buttonBox); + + if (dialog.exec() == QDialog::Accepted) { + setShortcutString(shortcutEdit->text().trimmed()); + setIncludedByDefault(!limitCheck->isChecked()); + return true; + } + + return false; +} + +QString ILocatorFilter::trimWildcards(const QString &str) +{ + if (str.isEmpty()) + return str; + int first = 0, last = str.size() - 1; + const QChar asterisk = QLatin1Char('*'); + const QChar question = QLatin1Char('?'); + while (first < str.size() && (str.at(first) == asterisk || str.at(first) == question)) + ++first; + while (last >= 0 && (str.at(last) == asterisk || str.at(last) == question)) + --last; + if (first > last) + return QString(); + return str.mid(first, last - first + 1); +} + +Qt::CaseSensitivity ILocatorFilter::caseSensitivity(const QString &str) +{ + return str == str.toLower() ? Qt::CaseInsensitive : Qt::CaseSensitive; +} + +bool ILocatorFilter::isConfigurable() const +{ + return m_isConfigurable; +} + +bool ILocatorFilter::isIncludedByDefault() const +{ + return m_includedByDefault; +} + +void ILocatorFilter::setIncludedByDefault(bool includedByDefault) +{ + m_includedByDefault = includedByDefault; +} + +bool ILocatorFilter::isHidden() const +{ + return m_hidden; +} + +void ILocatorFilter::setHidden(bool hidden) +{ + m_hidden = hidden; +} + +bool ILocatorFilter::isEnabled() const +{ + return m_enabled; +} + +Core::Id ILocatorFilter::id() const +{ + return m_id; +} + +QString ILocatorFilter::displayName() const +{ + return m_displayName; +} + +ILocatorFilter::Priority ILocatorFilter::priority() const +{ + return m_priority; +} + +void ILocatorFilter::setEnabled(bool enabled) +{ + m_enabled = enabled; +} + +void ILocatorFilter::setId(Core::Id id) +{ + m_id = id; +} + +void ILocatorFilter::setPriority(Priority priority) +{ + m_priority = priority; +} + +void ILocatorFilter::setDisplayName(const QString &displayString) +{ + m_displayName = displayString; +} + +void ILocatorFilter::setConfigurable(bool configurable) +{ + m_isConfigurable = configurable; +} diff --git a/src/plugins/coreplugin/locator/ilocatorfilter.h b/src/plugins/coreplugin/locator/ilocatorfilter.h new file mode 100644 index 00000000000..3c6e213fa02 --- /dev/null +++ b/src/plugins/coreplugin/locator/ilocatorfilter.h @@ -0,0 +1,167 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef ILOCATORFILTER_H +#define ILOCATORFILTER_H + +#include + +#include +#include +#include + +namespace Core { + +class ILocatorFilter; + +struct LocatorFilterEntry +{ + LocatorFilterEntry() + : filter(0) + , fileIconResolved(false) + {} + + LocatorFilterEntry(ILocatorFilter *fromFilter, const QString &name, const QVariant &data, + const QIcon &icon = QIcon()) + : filter(fromFilter) + , displayName(name) + , internalData(data) + , displayIcon(icon) + , fileIconResolved(false) + {} + + bool operator==(const LocatorFilterEntry &other) const { + if (internalData.canConvert(QVariant::String)) + return (internalData.toString() == other.internalData.toString()); + return internalData.constData() == other.internalData.constData(); + } + + /* backpointer to creating filter */ + ILocatorFilter *filter; + /* displayed string */ + QString displayName; + /* extra information displayed in light-gray in a second column (optional) */ + QString extraInfo; + /* can be used by the filter to save more information about the entry */ + QVariant internalData; + /* icon to display along with the entry */ + QIcon displayIcon; + /* file name, if the entry is related to a file, is used e.g. for resolving a file icon */ + QString fileName; + /* internal */ + bool fileIconResolved; +}; + +class CORE_EXPORT ILocatorFilter : public QObject +{ + Q_OBJECT + +public: + enum Priority {High = 0, Medium = 1, Low = 2}; + + ILocatorFilter(QObject *parent = 0); + virtual ~ILocatorFilter() {} + + /* Internal Id. */ + Core::Id id() const; + + /* Visible name. */ + QString displayName() const; + + /* Selection list order in case of multiple active filters (high goes on top). */ + Priority priority() const; + + /* String to type to use this filter exclusively. */ + QString shortcutString() const; + + /* List of matches for the given user entry. */ + virtual QList matchesFor(QFutureInterface &future, const QString &entry) = 0; + + /* User has selected the given entry that belongs to this filter. */ + virtual void accept(LocatorFilterEntry selection) const = 0; + + /* Implement to update caches on user request, if that's a long operation. */ + virtual void refresh(QFutureInterface &future) = 0; + + /* Saved state is used to restore the filter at start up. */ + virtual QByteArray saveState() const; + + /* Used to restore the filter at start up. */ + virtual bool restoreState(const QByteArray &state); + + /* User wants to configure this filter (if supported). Use it to pop up a dialog. + * needsRefresh is used as a hint to indicate that refresh should be called. + * The default implementation allows changing the shortcut and whether the filter + * is enabled by default. + */ + virtual bool openConfigDialog(QWidget *parent, bool &needsRefresh); + + /* If there is a configure dialog available for this filter. The default + * implementation returns true. */ + bool isConfigurable() const; + + /* Is this filter used also when the shortcutString is not used? */ + bool isIncludedByDefault() const; + + /* Returns whether the filter should be hidden from configuration and menus. */ + bool isHidden() const; + + /* Returns whether the filter should be enabled and used in menus. */ + bool isEnabled() const; + + static QString trimWildcards(const QString &str); + static Qt::CaseSensitivity caseSensitivity(const QString &str); + +public slots: + /* Enable or disable the filter. */ + void setEnabled(bool enabled); + +protected: + void setShortcutString(const QString &shortcut); + void setIncludedByDefault(bool includedByDefault); + void setHidden(bool hidden); + void setId(Core::Id id); + void setPriority(Priority priority); + void setDisplayName(const QString &displayString); + void setConfigurable(bool configurable); + +private: + Core::Id m_id; + QString m_shortcut; + Priority m_priority; + QString m_displayName; + bool m_includedByDefault; + bool m_hidden; + bool m_enabled; + bool m_isConfigurable; +}; + +} // namespace Core + +#endif // ILOCATORFILTER_H diff --git a/src/plugins/coreplugin/locator/images/locator.png b/src/plugins/coreplugin/locator/images/locator.png new file mode 100644 index 00000000000..000ee1c0185 Binary files /dev/null and b/src/plugins/coreplugin/locator/images/locator.png differ diff --git a/src/plugins/coreplugin/locator/images/reload.png b/src/plugins/coreplugin/locator/images/reload.png new file mode 100644 index 00000000000..b5afefb32bc Binary files /dev/null and b/src/plugins/coreplugin/locator/images/reload.png differ diff --git a/src/plugins/coreplugin/locator/locator.pri b/src/plugins/coreplugin/locator/locator.pri new file mode 100644 index 00000000000..174e1684fee --- /dev/null +++ b/src/plugins/coreplugin/locator/locator.pri @@ -0,0 +1,46 @@ +HEADERS += \ + $$PWD/locatorplugin.h \ + $$PWD/commandlocator.h \ + $$PWD/locatorwidget.h \ + $$PWD/locatorfiltersfilter.h \ + $$PWD/settingspage.h \ + $$PWD/ilocatorfilter.h \ + $$PWD/opendocumentsfilter.h \ + $$PWD/filesystemfilter.h \ + $$PWD/locatorconstants.h \ + $$PWD/directoryfilter.h \ + $$PWD/locatormanager.h \ + $$PWD/basefilefilter.h \ + $$PWD/executefilter.h \ + $$PWD/locatorsearchutils.h + +SOURCES += \ + $$PWD/locatorplugin.cpp \ + $$PWD/commandlocator.cpp \ + $$PWD/locatorwidget.cpp \ + $$PWD/locatorfiltersfilter.cpp \ + $$PWD/opendocumentsfilter.cpp \ + $$PWD/filesystemfilter.cpp \ + $$PWD/settingspage.cpp \ + $$PWD/directoryfilter.cpp \ + $$PWD/locatormanager.cpp \ + $$PWD/basefilefilter.cpp \ + $$PWD/ilocatorfilter.cpp \ + $$PWD/executefilter.cpp \ + $$PWD/locatorsearchutils.cpp + +FORMS += \ + $$PWD/settingspage.ui \ + $$PWD/filesystemfilter.ui \ + $$PWD/directoryfilter.ui + +RESOURCES += \ + $$PWD/locator.qrc + +equals(TEST, 1) { + HEADERS += $$PWD/locatorfiltertest.h + SOURCES += \ + $$PWD/locatorfiltertest.cpp \ + $$PWD/locator_test.cpp + DEFINES += SRCDIR=\\\"$$PWD\\\" +} diff --git a/src/plugins/coreplugin/locator/locator.qrc b/src/plugins/coreplugin/locator/locator.qrc new file mode 100644 index 00000000000..4cd5df4f13d --- /dev/null +++ b/src/plugins/coreplugin/locator/locator.qrc @@ -0,0 +1,6 @@ + + + images/reload.png + images/locator.png + + diff --git a/src/plugins/coreplugin/locator/locator_test.cpp b/src/plugins/coreplugin/locator/locator_test.cpp new file mode 100644 index 00000000000..35640285ece --- /dev/null +++ b/src/plugins/coreplugin/locator/locator_test.cpp @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + +#include "locatorplugin.h" + +#include "basefilefilter.h" +#include "locatorfiltertest.h" + +#include +#include + +#include +#include +#include + +using namespace Core::Tests; + +namespace { + +QTC_DECLARE_MYTESTDATADIR("../../../tests/locators/") + +class MyBaseFileFilter : public Core::BaseFileFilter +{ +public: + MyBaseFileFilter(const QStringList &theFiles) + { + files().clear(); + files().append(theFiles); + BaseFileFilter::generateFileNames(); + } + + void refresh(QFutureInterface &) {} + +protected: + void updateFiles() {} +}; + +inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); } + +class ReferenceData +{ +public: + ReferenceData() {} + ReferenceData(const QString &searchText, const ResultDataList &results) + : searchText(searchText), results(results) {} + + QString searchText; + ResultDataList results; +}; + +} // anonymous namespace + +Q_DECLARE_METATYPE(ReferenceData) +Q_DECLARE_METATYPE(QList) + +void Core::Internal::LocatorPlugin::test_basefilefilter() +{ + QFETCH(QStringList, testFiles); + QFETCH(QList, referenceDataList); + + MyBaseFileFilter filter(testFiles); + BasicLocatorFilterTest test(&filter); + + foreach (const ReferenceData &reference, referenceDataList) { + const QList filterEntries = test.matchesFor(reference.searchText); + const ResultDataList results = ResultData::fromFilterEntryList(filterEntries); +// QTextStream(stdout) << "----" << endl; +// ResultData::printFilterEntries(results); + QCOMPARE(results, reference.results); + } +} + +void Core::Internal::LocatorPlugin::test_basefilefilter_data() +{ + QTest::addColumn("testFiles"); + QTest::addColumn >("referenceDataList"); + + const QChar pathSeparator = QDir::separator(); + const MyTestDataDir testDir(QLatin1String("testdata_basic")); + const QStringList testFiles = QStringList() + << QDir::toNativeSeparators(testDir.file(QLatin1String("file.cpp"))) + << QDir::toNativeSeparators(testDir.file(QLatin1String("main.cpp"))) + << QDir::toNativeSeparators(testDir.file(QLatin1String("subdir/main.cpp"))); + QStringList testFilesShort; + foreach (const QString &file, testFiles) + testFilesShort << Utils::FileUtils::shortNativePath(Utils::FileName::fromString(file)); + + QTest::newRow("BaseFileFilter-EmptyInput") + << testFiles + << (QList() + << ReferenceData( + QString(), + (QList() + << ResultData(_("file.cpp"), testFilesShort.at(0)) + << ResultData(_("main.cpp"), testFilesShort.at(1)) + << ResultData(_("main.cpp"), testFilesShort.at(2)))) + ); + + QTest::newRow("BaseFileFilter-InputIsFileName") + << testFiles + << (QList() + << ReferenceData( + _("main.cpp"), + (QList() + << ResultData(_("main.cpp"), testFilesShort.at(1)) + << ResultData(_("main.cpp"), testFilesShort.at(2)))) + ); + + QTest::newRow("BaseFileFilter-InputIsFilePath") + << testFiles + << (QList() + << ReferenceData( + QString(_("subdir") + pathSeparator + _("main.cpp")), + (QList() + << ResultData(_("main.cpp"), testFilesShort.at(2)))) + ); + + QTest::newRow("BaseFileFilter-InputIsDirIsPath") + << testFiles + << (QList() + << ReferenceData( _("subdir"), QList()) + << ReferenceData( + QString(_("subdir") + pathSeparator + _("main.cpp")), + (QList() + << ResultData(_("main.cpp"), testFilesShort.at(2)))) + ); + + QTest::newRow("BaseFileFilter-InputIsFileNameFilePathFileName") + << testFiles + << (QList() + << ReferenceData( + _("main.cpp"), + (QList() + << ResultData(_("main.cpp"), testFilesShort.at(1)) + << ResultData(_("main.cpp"), testFilesShort.at(2)))) + << ReferenceData( + QString(_("subdir") + pathSeparator + _("main.cpp")), + (QList() + << ResultData(_("main.cpp"), testFilesShort.at(2)))) + << ReferenceData( + _("main.cpp"), + (QList() + << ResultData(_("main.cpp"), testFilesShort.at(1)) + << ResultData(_("main.cpp"), testFilesShort.at(2)))) + ); +} diff --git a/src/plugins/coreplugin/locator/locatorconstants.h b/src/plugins/coreplugin/locator/locatorconstants.h new file mode 100644 index 00000000000..bd39b411d3e --- /dev/null +++ b/src/plugins/coreplugin/locator/locatorconstants.h @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef LOCATORCONSTANTS_H +#define LOCATORCONSTANTS_H + +#include + +namespace Core { +namespace Constants { + +const char FILTER_OPTIONS_PAGE[] = QT_TRANSLATE_NOOP("Locator", "Locator"); +const char TASK_INDEX[] = "Locator.Task.Index"; + +} // namespace Constants +} // namespace Core + +#endif // LOCATORCONSTANTS_H diff --git a/src/plugins/coreplugin/locator/locatorfiltersfilter.cpp b/src/plugins/coreplugin/locator/locatorfiltersfilter.cpp new file mode 100644 index 00000000000..3c52ad72d93 --- /dev/null +++ b/src/plugins/coreplugin/locator/locatorfiltersfilter.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "locatorfiltersfilter.h" +#include "locatorplugin.h" +#include "locatorwidget.h" + +#include + +using namespace Core; +using namespace Core::Internal; + +Q_DECLARE_METATYPE(ILocatorFilter*) + +LocatorFiltersFilter::LocatorFiltersFilter(LocatorPlugin *plugin, + LocatorWidget *locatorWidget): + m_plugin(plugin), + m_locatorWidget(locatorWidget), + m_icon(QIcon(QLatin1String(Core::Constants::ICON_NEXT))) +{ + setId("FiltersFilter"); + setDisplayName(tr("Available filters")); + setIncludedByDefault(true); + setHidden(true); + setPriority(High); + setConfigurable(false); +} + +QList LocatorFiltersFilter::matchesFor(QFutureInterface &future, const QString &entry) +{ + QList entries; + if (!entry.isEmpty()) + return entries; + + QMap uniqueFilters; + foreach (ILocatorFilter *filter, m_plugin->filters()) { + const QString filterId = filter->shortcutString() + QLatin1Char(',') + filter->displayName(); + uniqueFilters.insert(filterId, filter); + } + + foreach (ILocatorFilter *filter, uniqueFilters) { + if (future.isCanceled()) + break; + if (!filter->shortcutString().isEmpty() && !filter->isHidden() && filter->isEnabled()) { + LocatorFilterEntry filterEntry(this, + filter->shortcutString(), + QVariant::fromValue(filter), + m_icon); + filterEntry.extraInfo = filter->displayName(); + entries.append(filterEntry); + } + } + + return entries; +} + +void LocatorFiltersFilter::accept(LocatorFilterEntry selection) const +{ + ILocatorFilter *filter = selection.internalData.value(); + if (filter) + m_locatorWidget->show(filter->shortcutString() + QLatin1Char(' '), + filter->shortcutString().length() + 1); +} + +void LocatorFiltersFilter::refresh(QFutureInterface &future) +{ + Q_UNUSED(future) + // Nothing to refresh +} diff --git a/src/plugins/coreplugin/locator/locatorfiltersfilter.h b/src/plugins/coreplugin/locator/locatorfiltersfilter.h new file mode 100644 index 00000000000..c775c3a824c --- /dev/null +++ b/src/plugins/coreplugin/locator/locatorfiltersfilter.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef LOCATORFILTERSFILTER_H +#define LOCATORFILTERSFILTER_H + +#include "ilocatorfilter.h" + +#include + +namespace Core { +namespace Internal { + +class LocatorPlugin; +class LocatorWidget; + +/*! + This filter provides the user with the list of available Locator filters. + The list is only shown when nothing has been typed yet. + */ +class LocatorFiltersFilter : public ILocatorFilter +{ + Q_OBJECT + +public: + LocatorFiltersFilter(LocatorPlugin *plugin, + LocatorWidget *locatorWidget); + + // ILocatorFilter + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(LocatorFilterEntry selection) const; + void refresh(QFutureInterface &future); + +private: + LocatorPlugin *m_plugin; + LocatorWidget *m_locatorWidget; + QIcon m_icon; +}; + +} // namespace Internal +} // namespace Core + +#endif // LOCATORFILTERSFILTER_H diff --git a/src/plugins/coreplugin/locator/locatorfiltertest.cpp b/src/plugins/coreplugin/locator/locatorfiltertest.cpp new file mode 100644 index 00000000000..1bdf4998e0b --- /dev/null +++ b/src/plugins/coreplugin/locator/locatorfiltertest.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + +#include "locatorfiltertest.h" +#include "locatorsearchutils.h" + +#include + +#include +#include +#include +#include + +using namespace Core; +using namespace Core::Tests; + +BasicLocatorFilterTest::BasicLocatorFilterTest(ILocatorFilter *filter) : m_filter(filter) +{ +} + +QList BasicLocatorFilterTest::matchesFor(const QString &searchText) +{ + doBeforeLocatorRun(); + const QList filters = QList() << m_filter; + QFuture locatorSearch = QtConcurrent::run(Core::Internal::runSearch, + filters, searchText); + locatorSearch.waitForFinished(); + doAfterLocatorRun(); + return locatorSearch.results(); +} + +ResultData::ResultData() +{ +} + +ResultData::ResultData(const QString &textColumn1, const QString &textColumn2) + : textColumn1(textColumn1), textColumn2(textColumn2) +{ +} + +bool ResultData::operator==(const ResultData &other) const +{ + return textColumn1 == other.textColumn1 && textColumn2 == other.textColumn2; +} + +ResultData::ResultDataList ResultData::fromFilterEntryList(const QList &entries) +{ + ResultDataList result; + foreach (const LocatorFilterEntry &entry, entries) + result << ResultData(entry.displayName, entry.extraInfo); + return result; +} + +void ResultData::printFilterEntries(const ResultData::ResultDataList &entries) +{ + QTextStream out(stdout); + foreach (const ResultData entry, entries) { + out << "<< ResultData(_(\"" << entry.textColumn1 << "\"), _(\"" << entry.textColumn2 + << "\"))" << endl; + } +} diff --git a/src/plugins/coreplugin/locator/locatorfiltertest.h b/src/plugins/coreplugin/locator/locatorfiltertest.h new file mode 100644 index 00000000000..6cbf1e115cc --- /dev/null +++ b/src/plugins/coreplugin/locator/locatorfiltertest.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + +#ifndef LOCATORFILTERTEST_H +#define LOCATORFILTERTEST_H + +#include "ilocatorfilter.h" + +#include + +namespace Core { +namespace Tests { + +/// Runs a locator filter for a search text and returns the results. +class CORE_EXPORT BasicLocatorFilterTest +{ +public: + BasicLocatorFilterTest(Core::ILocatorFilter *filter); + + QList matchesFor(const QString &searchText = QString()); + +private: + virtual void doBeforeLocatorRun() {} + virtual void doAfterLocatorRun() {} + + Core::ILocatorFilter *m_filter; +}; + +class CORE_EXPORT ResultData +{ +public: + typedef QList ResultDataList; + + ResultData(); + ResultData(const QString &textColumn1, const QString &textColumn2); + + bool operator==(const ResultData &other) const; + + static ResultDataList fromFilterEntryList(const QList &entries); + + /// For debugging and creating reference data + static void printFilterEntries(const ResultDataList &entries); + + QString textColumn1; + QString textColumn2; +}; + +typedef ResultData::ResultDataList ResultDataList; + +} // namespace Tests +} // namespace Core + +Q_DECLARE_METATYPE(Core::Tests::ResultData) +Q_DECLARE_METATYPE(Core::Tests::ResultDataList) + +QT_BEGIN_NAMESPACE +namespace QTest { + +template<> inline char *toString(const Core::Tests::ResultData &data) +{ + QByteArray ba = "\"" + data.textColumn1.toUtf8() + "\", \"" + data.textColumn2.toUtf8() + "\""; + return qstrdup(ba.data()); +} + +} // namespace QTest +QT_END_NAMESPACE + +#endif // LOCATORFILTERTEST_H diff --git a/src/plugins/coreplugin/locator/locatormanager.cpp b/src/plugins/coreplugin/locator/locatormanager.cpp new file mode 100644 index 00000000000..9cc893f5f65 --- /dev/null +++ b/src/plugins/coreplugin/locator/locatormanager.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "locatormanager.h" +#include "locatorwidget.h" + +#include +#include + +namespace Core { + +static Internal::LocatorWidget *m_locatorWidget = 0; + +LocatorManager::LocatorManager(Internal::LocatorWidget *locatorWidget) + : QObject(locatorWidget) +{ + m_locatorWidget = locatorWidget; +} + +LocatorManager::~LocatorManager() +{ + ExtensionSystem::PluginManager::removeObject(this); +} + +void LocatorManager::show(const QString &text, + int selectionStart, int selectionLength) +{ + QTC_ASSERT(m_locatorWidget, return); + m_locatorWidget->show(text, selectionStart, selectionLength); +} + +} // namespace Internal diff --git a/src/plugins/coreplugin/locator/locatormanager.h b/src/plugins/coreplugin/locator/locatormanager.h new file mode 100644 index 00000000000..67d2106c04d --- /dev/null +++ b/src/plugins/coreplugin/locator/locatormanager.h @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef LOCATORMANAGER_H +#define LOCATORMANAGER_H + +#include + +#include + +namespace Core { + +namespace Internal { class LocatorWidget; } + +class CORE_EXPORT LocatorManager : public QObject +{ + Q_OBJECT + +public: + LocatorManager(Internal::LocatorWidget *locatorWidget); + ~LocatorManager(); + + static void show(const QString &text, int selectionStart = -1, int selectionLength = 0); +}; + +} // namespace Core + +#endif // LOCATORMANAGER_H diff --git a/src/plugins/coreplugin/locator/locatorplugin.cpp b/src/plugins/coreplugin/locator/locatorplugin.cpp new file mode 100644 index 00000000000..085c0071d21 --- /dev/null +++ b/src/plugins/coreplugin/locator/locatorplugin.cpp @@ -0,0 +1,261 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "locatorplugin.h" +#include "locatorconstants.h" +#include "locatorfiltersfilter.h" +#include "locatormanager.h" +#include "locatorwidget.h" +#include "opendocumentsfilter.h" +#include "filesystemfilter.h" +#include "settingspage.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace Core { +namespace Internal { + +namespace { + static bool filterLessThan(const ILocatorFilter *first, const ILocatorFilter *second) + { + if (first->priority() < second->priority()) + return true; + if (first->priority() > second->priority()) + return false; + return first->id().alphabeticallyBefore(second->id()); + } +} + +LocatorPlugin::LocatorPlugin() + : m_settingsInitialized(false) +{ + m_corePlugin = 0; + m_refreshTimer.setSingleShot(false); + connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); +} + +LocatorPlugin::~LocatorPlugin() +{ + m_corePlugin->removeObject(m_openDocumentsFilter); + m_corePlugin->removeObject(m_fileSystemFilter); + m_corePlugin->removeObject(m_executeFilter); + m_corePlugin->removeObject(m_settingsPage); + delete m_openDocumentsFilter; + delete m_fileSystemFilter; + delete m_executeFilter; + delete m_settingsPage; + qDeleteAll(m_customFilters); +} + +void LocatorPlugin::initialize(CorePlugin *corePlugin, const QStringList &, QString *) +{ + m_corePlugin = corePlugin; + + m_settingsPage = new SettingsPage(this); + m_corePlugin->addObject(m_settingsPage); + + m_locatorWidget = new LocatorWidget(this); + m_locatorWidget->setEnabled(false); + StatusBarWidget *view = new StatusBarWidget; + view->setWidget(m_locatorWidget); + view->setContext(Context("LocatorWidget")); + view->setPosition(StatusBarWidget::First); + m_corePlugin->addAutoReleasedObject(view); + + QAction *action = new QAction(m_locatorWidget->windowIcon(), m_locatorWidget->windowTitle(), this); + Command *cmd = ActionManager::registerAction(action, "QtCreator.Locate", + Context(Core::Constants::C_GLOBAL)); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+K"))); + connect(action, SIGNAL(triggered()), this, SLOT(openLocator())); + connect(cmd, SIGNAL(keySequenceChanged()), this, SLOT(updatePlaceholderText())); + updatePlaceholderText(cmd); + + ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS); + mtools->addAction(cmd); + + m_corePlugin->addObject(new LocatorManager(m_locatorWidget)); + + m_openDocumentsFilter = new OpenDocumentsFilter; + m_corePlugin->addObject(m_openDocumentsFilter); + + m_fileSystemFilter = new FileSystemFilter(m_locatorWidget); + m_corePlugin->addObject(m_fileSystemFilter); + + m_executeFilter = new ExecuteFilter(); + m_corePlugin->addObject(m_executeFilter); + + m_corePlugin->addAutoReleasedObject(new LocatorFiltersFilter(this, m_locatorWidget)); +} + +void LocatorPlugin::updatePlaceholderText(Command *command) +{ + if (!command) + command = qobject_cast(sender()); + QTC_ASSERT(command, return); + if (command->keySequence().isEmpty()) + m_locatorWidget->setPlaceholderText(tr("Type to locate")); + else + m_locatorWidget->setPlaceholderText(tr("Type to locate (%1)").arg( + command->keySequence().toString(QKeySequence::NativeText))); +} + +void LocatorPlugin::openLocator() +{ + m_locatorWidget->show(QString()); +} + +void LocatorPlugin::extensionsInitialized() +{ + m_filters = ExtensionSystem::PluginManager::getObjects(); + qSort(m_filters.begin(), m_filters.end(), filterLessThan); + setFilters(m_filters); +} + +bool LocatorPlugin::delayedInitialize() +{ + loadSettings(); + return true; +} + +void LocatorPlugin::loadSettings() +{ + QSettings *qs = ICore::settings(); + + // Backwards compatibility to old settings location + if (qs->contains(QLatin1String("QuickOpen/FiltersFilter"))) { + loadSettingsHelper(qs); + } else { + SettingsDatabase *settings = ICore::settingsDatabase(); + loadSettingsHelper(settings); + } + + qs->remove(QLatin1String("QuickOpen")); + + m_locatorWidget->updateFilterList(); + m_locatorWidget->setEnabled(true); + if (m_refreshTimer.interval() > 0) + m_refreshTimer.start(); + m_settingsInitialized = true; +} + +void LocatorPlugin::saveSettings() +{ + if (m_settingsInitialized) { + SettingsDatabase *s = ICore::settingsDatabase(); + s->beginGroup(QLatin1String("QuickOpen")); + s->remove(QString()); + s->setValue(QLatin1String("RefreshInterval"), refreshInterval()); + foreach (ILocatorFilter *filter, m_filters) { + if (!m_customFilters.contains(filter)) + s->setValue(filter->id().toString(), filter->saveState()); + } + s->beginGroup(QLatin1String("CustomFilters")); + int i = 0; + foreach (ILocatorFilter *filter, m_customFilters) { + s->setValue(QLatin1String("directory") + QString::number(i), + filter->saveState()); + ++i; + } + s->endGroup(); + s->endGroup(); + } +} + +/*! + Return all filters, including the ones created by the user. +*/ +QList LocatorPlugin::filters() +{ + return m_filters; +} + +/*! + This returns a subset of all the filters, that contains only the filters that + have been created by the user at some point (maybe in a previous session). + */ +QList LocatorPlugin::customFilters() +{ + return m_customFilters; +} + +void LocatorPlugin::setFilters(QList f) +{ + m_filters = f; + m_locatorWidget->updateFilterList(); +} + +void LocatorPlugin::setCustomFilters(QList filters) +{ + m_customFilters = filters; +} + +int LocatorPlugin::refreshInterval() +{ + return m_refreshTimer.interval() / 60000; +} + +void LocatorPlugin::setRefreshInterval(int interval) +{ + if (interval < 1) { + m_refreshTimer.stop(); + m_refreshTimer.setInterval(0); + return; + } + m_refreshTimer.setInterval(interval * 60000); + m_refreshTimer.start(); +} + +void LocatorPlugin::refresh(QList filters) +{ + if (filters.isEmpty()) + filters = m_filters; + QFuture task = QtConcurrent::run(&ILocatorFilter::refresh, filters); + FutureProgress *progress = + ProgressManager::addTask(task, tr("Indexing"), Core::Constants::TASK_INDEX); + connect(progress, SIGNAL(finished()), this, SLOT(saveSettings())); +} + +} // namespace Internal +} // namespace Core diff --git a/src/plugins/coreplugin/locator/locatorplugin.h b/src/plugins/coreplugin/locator/locatorplugin.h new file mode 100644 index 00000000000..f0a8a719b2e --- /dev/null +++ b/src/plugins/coreplugin/locator/locatorplugin.h @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef LOCATORPLUGIN_H +#define LOCATORPLUGIN_H + +#include "ilocatorfilter.h" +#include "directoryfilter.h" +#include "executefilter.h" + +#include +#include + +#include +#include + +namespace Core { +namespace Internal { + +class CorePlugin; +class LocatorWidget; +class OpenDocumentsFilter; +class FileSystemFilter; +class SettingsPage; + +class LocatorPlugin : public QObject +{ + Q_OBJECT + +public: + LocatorPlugin(); + ~LocatorPlugin(); + + void initialize(CorePlugin *corePlugin, const QStringList &arguments, QString *errorMessage); + void extensionsInitialized(); + bool delayedInitialize(); + + QList filters(); + QList customFilters(); + void setFilters(QList f); + void setCustomFilters(QList f); + int refreshInterval(); + void setRefreshInterval(int interval); + +public slots: + void refresh(QList filters = QList()); + void saveSettings(); + void openLocator(); + +private slots: + void updatePlaceholderText(Core::Command *command = 0); + +#ifdef WITH_TESTS + void test_basefilefilter(); + void test_basefilefilter_data(); +#endif + +private: + void loadSettings(); + + template + void loadSettingsHelper(S *settings); + + LocatorWidget *m_locatorWidget; + SettingsPage *m_settingsPage; + + bool m_settingsInitialized; + QList m_filters; + QList m_customFilters; + int m_refreshInterval; + QTimer m_refreshTimer; + OpenDocumentsFilter *m_openDocumentsFilter; + FileSystemFilter *m_fileSystemFilter; + ExecuteFilter *m_executeFilter; + CorePlugin *m_corePlugin; +}; + +template +void LocatorPlugin::loadSettingsHelper(S *settings) +{ + settings->beginGroup(QLatin1String("QuickOpen")); + m_refreshTimer.setInterval(settings->value(QLatin1String("RefreshInterval"), 60).toInt() * 60000); + + foreach (ILocatorFilter *filter, m_filters) { + if (settings->contains(filter->id().toString())) { + const QByteArray state = settings->value(filter->id().toString()).toByteArray(); + if (!state.isEmpty()) + filter->restoreState(state); + } + } + settings->beginGroup(QLatin1String("CustomFilters")); + QList customFilters; + const QStringList keys = settings->childKeys(); + foreach (const QString &key, keys) { + ILocatorFilter *filter = new DirectoryFilter; + filter->restoreState(settings->value(key).toByteArray()); + m_filters.append(filter); + customFilters.append(filter); + } + setCustomFilters(customFilters); + settings->endGroup(); + settings->endGroup(); +} + +} // namespace Internal +} // namespace Core + +#endif // LOCATORPLUGIN_H diff --git a/src/plugins/coreplugin/locator/locatorsearchutils.cpp b/src/plugins/coreplugin/locator/locatorsearchutils.cpp new file mode 100644 index 00000000000..189449fc663 --- /dev/null +++ b/src/plugins/coreplugin/locator/locatorsearchutils.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + + +#include "locatorsearchutils.h" + +#include +#include +#include + +namespace Core { + +uint qHash(const Core::LocatorFilterEntry &entry) +{ + if (entry.internalData.canConvert(QVariant::String)) + return QT_PREPEND_NAMESPACE(qHash)(entry.internalData.toString()); + return QT_PREPEND_NAMESPACE(qHash)(entry.internalData.constData()); +} + +} // namespace Core + +void Core::Internal::runSearch(QFutureInterface &entries, + QList filters, QString searchText) +{ + QSet alreadyAdded; + const bool checkDuplicates = (filters.size() > 1); + foreach (ILocatorFilter *filter, filters) { + if (entries.isCanceled()) + break; + + foreach (const LocatorFilterEntry &entry, filter->matchesFor(entries, searchText)) { + if (checkDuplicates && alreadyAdded.contains(entry)) + continue; + entries.reportResult(entry); + if (checkDuplicates) + alreadyAdded.insert(entry); + } + } +} diff --git a/src/plugins/coreplugin/locator/locatorsearchutils.h b/src/plugins/coreplugin/locator/locatorsearchutils.h new file mode 100644 index 00000000000..1abf03a8fd6 --- /dev/null +++ b/src/plugins/coreplugin/locator/locatorsearchutils.h @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef LOCATORSEARCHUTILS_H +#define LOCATORSEARCHUTILS_H + +#include "ilocatorfilter.h" + +namespace Core { +namespace Internal { + +void CORE_EXPORT runSearch(QFutureInterface &entries, + QList filters, + QString searchText); + +} // namespace Internal +} // namespace Core + +#endif // LOCATORSEARCHUTILS_H + diff --git a/src/plugins/coreplugin/locator/locatorwidget.cpp b/src/plugins/coreplugin/locator/locatorwidget.cpp new file mode 100644 index 00000000000..483ebe1a3fb --- /dev/null +++ b/src/plugins/coreplugin/locator/locatorwidget.cpp @@ -0,0 +1,590 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "locatorwidget.h" +#include "locatorplugin.h" +#include "locatorconstants.h" +#include "locatorsearchutils.h" +#include "ilocatorfilter.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +Q_DECLARE_METATYPE(Core::ILocatorFilter*) +Q_DECLARE_METATYPE(Core::LocatorFilterEntry) + +namespace Core { +namespace Internal { + +/* A model to represent the Locator results. */ +class LocatorModel : public QAbstractListModel +{ +public: + LocatorModel(QObject *parent = 0) + : QAbstractListModel(parent) +// , mDisplayCount(64) + {} + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + int columnCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + + void setEntries(const QList &entries); + //void setDisplayCount(int count); + +private: + mutable QList mEntries; + //int mDisplayCount; +}; + +class CompletionList : public QTreeView +{ +public: + CompletionList(QWidget *parent = 0); + + void updatePreferredSize(); + QSize preferredSize() const { return m_preferredSize; } + + void focusOutEvent (QFocusEvent *event) { + if (event->reason() == Qt::ActiveWindowFocusReason) + hide(); + QTreeView::focusOutEvent(event); + } + + void next() { + int index = currentIndex().row(); + ++index; + if (index >= model()->rowCount(QModelIndex())) { + // wrap + index = 0; + } + setCurrentIndex(model()->index(index, 0)); + } + + void previous() { + int index = currentIndex().row(); + --index; + if (index < 0) { + // wrap + index = model()->rowCount(QModelIndex()) - 1; + } + setCurrentIndex(model()->index(index, 0)); + } + +private: + QSize m_preferredSize; +}; + +} // namespace Internal + + +using namespace Core::Internal; + +// =========== LocatorModel =========== + +int LocatorModel::rowCount(const QModelIndex & /* parent */) const +{ + return mEntries.size(); +} + +int LocatorModel::columnCount(const QModelIndex &parent) const +{ + return parent.isValid() ? 0 : 2; +} + +/*! + * When asked for the icon via Qt::DecorationRole, the LocatorModel lazily + * resolves and caches the Greehouse-specific file icon when + * FilterEntry::resolveFileIcon is true. FilterEntry::internalData is assumed + * to be the filename. + */ +QVariant LocatorModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid() || index.row() >= mEntries.size()) + return QVariant(); + + if (role == Qt::DisplayRole) { + if (index.column() == 0) + return mEntries.at(index.row()).displayName; + else if (index.column() == 1) + return mEntries.at(index.row()).extraInfo; + } else if (role == Qt::ToolTipRole) { + if (mEntries.at(index.row()).extraInfo.isEmpty()) + return QVariant(mEntries.at(index.row()).displayName); + else + return QVariant(mEntries.at(index.row()).displayName + + QLatin1String("\n\n") + mEntries.at(index.row()).extraInfo); + } else if (role == Qt::DecorationRole && index.column() == 0) { + LocatorFilterEntry &entry = mEntries[index.row()]; + if (!entry.fileIconResolved && !entry.fileName.isEmpty() && entry.displayIcon.isNull()) { + entry.fileIconResolved = true; + entry.displayIcon = FileIconProvider::icon(entry.fileName); + } + return entry.displayIcon; + } else if (role == Qt::ForegroundRole && index.column() == 1) { + return QColor(Qt::darkGray); + } else if (role == Qt::UserRole) { + return qVariantFromValue(mEntries.at(index.row())); + } + + return QVariant(); +} + +void LocatorModel::setEntries(const QList &entries) +{ + beginResetModel(); + mEntries = entries; + endResetModel(); +} + +// =========== CompletionList =========== + +CompletionList::CompletionList(QWidget *parent) + : QTreeView(parent) +{ + setRootIsDecorated(false); + setUniformRowHeights(true); + setMaximumWidth(900); + header()->hide(); + header()->setStretchLastSection(true); + // This is too slow when done on all results + //header()->setResizeMode(QHeaderView::ResizeToContents); + setWindowFlags(Qt::ToolTip); + if (Utils::HostOsInfo::isMacHost()) { + if (horizontalScrollBar()) + horizontalScrollBar()->setAttribute(Qt::WA_MacMiniSize); + if (verticalScrollBar()) + verticalScrollBar()->setAttribute(Qt::WA_MacMiniSize); + } +} + +void CompletionList::updatePreferredSize() +{ + const QStyleOptionViewItem &option = viewOptions(); + const QSize shint = itemDelegate()->sizeHint(option, model()->index(0, 0)); + + m_preferredSize = QSize(730, shint.height() * 17 + frameWidth() * 2); +} + +// =========== LocatorWidget =========== + +LocatorWidget::LocatorWidget(LocatorPlugin *qop) : + m_locatorPlugin(qop), + m_locatorModel(new LocatorModel(this)), + m_completionList(new CompletionList(this)), + m_filterMenu(new QMenu(this)), + m_refreshAction(new QAction(tr("Refresh"), this)), + m_configureAction(new QAction(tr("Configure..."), this)), + m_fileLineEdit(new Utils::FilterLineEdit), + m_updateRequested(false), + m_acceptRequested(false), + m_possibleToolTipRequest(false) +{ + // Explicitly hide the completion list popup. + m_completionList->hide(); + + setFocusProxy(m_fileLineEdit); + setWindowTitle(tr("Locate...")); + resize(200, 90); + QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(0); + setSizePolicy(sizePolicy); + setMinimumSize(QSize(200, 0)); + + QHBoxLayout *layout = new QHBoxLayout(this); + setLayout(layout); + layout->setMargin(0); + layout->addWidget(m_fileLineEdit); + + setWindowIcon(QIcon(QLatin1String(":/locator/images/locator.png"))); + const QPixmap image = QPixmap(QLatin1String(Core::Constants::ICON_MAGNIFIER)); + m_fileLineEdit->setButtonPixmap(Utils::FancyLineEdit::Left, image); + m_fileLineEdit->setButtonToolTip(Utils::FancyLineEdit::Left, tr("Options")); + m_fileLineEdit->setFocusPolicy(Qt::ClickFocus); + m_fileLineEdit->setButtonVisible(Utils::FancyLineEdit::Left, true); + // We set click focus since otherwise you will always get two popups + m_fileLineEdit->setButtonFocusPolicy(Utils::FancyLineEdit::Left, Qt::ClickFocus); + m_fileLineEdit->setAttribute(Qt::WA_MacShowFocusRect, false); + + m_fileLineEdit->installEventFilter(this); + this->installEventFilter(this); + + m_completionList->setModel(m_locatorModel); + m_completionList->header()->resizeSection(0, 300); + m_completionList->updatePreferredSize(); + m_completionList->resize(m_completionList->preferredSize()); + + m_filterMenu->addAction(m_refreshAction); + m_filterMenu->addAction(m_configureAction); + + m_fileLineEdit->setButtonMenu(Utils::FancyLineEdit::Left, m_filterMenu); + + connect(m_refreshAction, SIGNAL(triggered()), m_locatorPlugin, SLOT(refresh())); + connect(m_configureAction, SIGNAL(triggered()), this, SLOT(showConfigureDialog())); + connect(m_fileLineEdit, SIGNAL(textChanged(QString)), + this, SLOT(showPopup())); + connect(m_completionList, SIGNAL(activated(QModelIndex)), + this, SLOT(scheduleAcceptCurrentEntry())); + + m_entriesWatcher = new QFutureWatcher(this); + connect(m_entriesWatcher, SIGNAL(finished()), SLOT(updateEntries())); + + m_showPopupTimer = new QTimer(this); + m_showPopupTimer->setInterval(100); + m_showPopupTimer->setSingleShot(true); + connect(m_showPopupTimer, SIGNAL(timeout()), SLOT(showPopupNow())); +} + +void LocatorWidget::setPlaceholderText(const QString &text) +{ + m_fileLineEdit->setPlaceholderText(text); +} + +void LocatorWidget::updateFilterList() +{ + typedef QMap IdActionMap; + + m_filterMenu->clear(); + + // update actions and menu + IdActionMap actionCopy = m_filterActionMap; + m_filterActionMap.clear(); + // register new actions, update existent + foreach (ILocatorFilter *filter, m_locatorPlugin->filters()) { + if (filter->shortcutString().isEmpty() || filter->isHidden()) + continue; + Id filterId = filter->id(); + Id locatorId = filterId.withPrefix("Locator."); + QAction *action = 0; + Command *cmd = 0; + if (!actionCopy.contains(filterId)) { + // register new action + action = new QAction(filter->displayName(), this); + cmd = ActionManager::registerAction(action, locatorId, + Context(Core::Constants::C_GLOBAL)); + cmd->setAttribute(Command::CA_UpdateText); + connect(action, SIGNAL(triggered()), this, SLOT(filterSelected())); + action->setData(qVariantFromValue(filter)); + } else { + action = actionCopy.take(filterId); + action->setText(filter->displayName()); + cmd = ActionManager::command(locatorId); + } + m_filterActionMap.insert(filterId, action); + m_filterMenu->addAction(cmd->action()); + } + + // unregister actions that are deleted now + const IdActionMap::Iterator end = actionCopy.end(); + for (IdActionMap::Iterator it = actionCopy.begin(); it != end; ++it) { + ActionManager::unregisterAction(it.value(), it.key().withPrefix("Locator.")); + delete it.value(); + } + + m_filterMenu->addSeparator(); + m_filterMenu->addAction(m_refreshAction); + m_filterMenu->addAction(m_configureAction); +} + +bool LocatorWidget::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == m_fileLineEdit && event->type() == QEvent::KeyPress) { + if (m_possibleToolTipRequest) + m_possibleToolTipRequest = false; + if (QToolTip::isVisible()) + QToolTip::hideText(); + + QKeyEvent *keyEvent = static_cast(event); + switch (keyEvent->key()) { + case Qt::Key_Up: + case Qt::Key_Down: + case Qt::Key_PageUp: + case Qt::Key_PageDown: + showCompletionList(); + QApplication::sendEvent(m_completionList, event); + return true; + case Qt::Key_Enter: + case Qt::Key_Return: + scheduleAcceptCurrentEntry(); + return true; + case Qt::Key_Escape: + m_completionList->hide(); + return true; + case Qt::Key_Tab: + m_completionList->next(); + return true; + case Qt::Key_Backtab: + m_completionList->previous(); + return true; + case Qt::Key_Alt: + if (keyEvent->modifiers() == Qt::AltModifier) { + m_possibleToolTipRequest = true; + return true; + } + break; + default: + break; + } + } else if (obj == m_fileLineEdit && event->type() == QEvent::KeyRelease) { + QKeyEvent *keyEvent = static_cast(event); + if (m_possibleToolTipRequest) { + m_possibleToolTipRequest = false; + if (m_completionList->isVisible() + && (keyEvent->key() == Qt::Key_Alt) + && (keyEvent->modifiers() == Qt::NoModifier)) { + const QModelIndex index = m_completionList->currentIndex(); + if (index.isValid()) { + QToolTip::showText(m_completionList->pos() + m_completionList->visualRect(index).topRight(), + m_locatorModel->data(index, Qt::ToolTipRole).toString()); + return true; + } + } + } + } else if (obj == m_fileLineEdit && event->type() == QEvent::FocusOut) { + QFocusEvent *fev = static_cast(event); + if (fev->reason() != Qt::ActiveWindowFocusReason || !m_completionList->isActiveWindow()) { + m_completionList->hide(); + m_fileLineEdit->clearFocus(); + } + } else if (obj == m_fileLineEdit && event->type() == QEvent::FocusIn) { + showPopupNow(); + } else if (obj == this && event->type() == QEvent::ShortcutOverride) { + QKeyEvent *ke = static_cast(event); + switch (ke->key()) { + case Qt::Key_Escape: + if (!ke->modifiers()) { + event->accept(); + QTimer::singleShot(0, this, SLOT(setFocusToCurrentMode())); + return true; + } + case Qt::Key_Alt: + if (ke->modifiers() == Qt::AltModifier) { + event->accept(); + return true; + } + break; + default: + break; + } + } + return QWidget::eventFilter(obj, event); +} + +void LocatorWidget::setFocusToCurrentMode() +{ + Core::ModeManager::setFocusToCurrentMode(); +} + +void LocatorWidget::showCompletionList() +{ + const int border = m_completionList->frameWidth(); + const QSize size = m_completionList->preferredSize(); + const QRect rect(mapToGlobal(QPoint(-border, -size.height() - border)), size); + m_completionList->setGeometry(rect); + m_completionList->show(); +} + +void LocatorWidget::showPopup() +{ + m_updateRequested = true; + m_showPopupTimer->start(); +} + +void LocatorWidget::showPopupNow() +{ + m_showPopupTimer->stop(); + updateCompletionList(m_fileLineEdit->text()); + showCompletionList(); +} + +QList LocatorWidget::filtersFor(const QString &text, QString &searchText) +{ + QList filters = m_locatorPlugin->filters(); + const int whiteSpace = text.indexOf(QLatin1Char(' ')); + QString prefix; + if (whiteSpace >= 0) + prefix = text.left(whiteSpace); + if (!prefix.isEmpty()) { + prefix = prefix.toLower(); + QList prefixFilters; + foreach (ILocatorFilter *filter, filters) { + if (prefix == filter->shortcutString()) { + searchText = text.mid(whiteSpace+1); + prefixFilters << filter; + } + } + if (!prefixFilters.isEmpty()) + return prefixFilters; + } + searchText = text; + QList activeFilters; + foreach (ILocatorFilter *filter, filters) + if (filter->isIncludedByDefault()) + activeFilters << filter; + return activeFilters; +} + +void LocatorWidget::updateCompletionList(const QString &text) +{ + m_updateRequested = true; + QString searchText; + const QList filters = filtersFor(text, searchText); + + // cancel the old future + m_entriesWatcher->future().cancel(); + m_entriesWatcher->future().waitForFinished(); + + QFuture future = QtConcurrent::run(runSearch, filters, searchText); + m_entriesWatcher->setFuture(future); +} + +void LocatorWidget::updateEntries() +{ + m_updateRequested = false; + if (m_entriesWatcher->future().isCanceled()) { + // reset to usable state + m_acceptRequested = false; + return; + } + + const QList entries = m_entriesWatcher->future().results(); + m_locatorModel->setEntries(entries); + if (m_locatorModel->rowCount() > 0) + m_completionList->setCurrentIndex(m_locatorModel->index(0, 0)); +#if 0 + m_completionList->updatePreferredSize(); +#endif + if (m_acceptRequested) + acceptCurrentEntry(); +} + +void LocatorWidget::scheduleAcceptCurrentEntry() +{ + if (m_updateRequested) { + // don't just accept the selected entry, since the list is not up to date + // accept will be called after the update finished + m_acceptRequested = true; + } else { + acceptCurrentEntry(); + } +} + +void LocatorWidget::acceptCurrentEntry() +{ + m_acceptRequested = false; + if (!m_completionList->isVisible()) + return; + const QModelIndex index = m_completionList->currentIndex(); + if (!index.isValid()) + return; + const LocatorFilterEntry entry = m_locatorModel->data(index, Qt::UserRole).value(); + m_completionList->hide(); + m_fileLineEdit->clearFocus(); + entry.filter->accept(entry); +} + +void LocatorWidget::show(const QString &text, int selectionStart, int selectionLength) +{ + if (!text.isEmpty()) + m_fileLineEdit->setText(text); + if (!m_fileLineEdit->hasFocus()) + m_fileLineEdit->setFocus(); + else + showPopupNow(); + ICore::raiseWindow(ICore::mainWindow()); + + if (selectionStart >= 0) { + m_fileLineEdit->setSelection(selectionStart, selectionLength); + if (selectionLength == 0) // make sure the cursor is at the right position (Mac-vs.-rest difference) + m_fileLineEdit->setCursorPosition(selectionStart); + } else { + m_fileLineEdit->selectAll(); + } +} + +void LocatorWidget::filterSelected() +{ + QString searchText = tr(""); + QAction *action = qobject_cast(sender()); + QTC_ASSERT(action, return); + ILocatorFilter *filter = action->data().value(); + QTC_ASSERT(filter, return); + QString currentText = m_fileLineEdit->text().trimmed(); + // add shortcut string at front or replace existing shortcut string + if (!currentText.isEmpty()) { + searchText = currentText; + foreach (ILocatorFilter *otherfilter, m_locatorPlugin->filters()) { + if (currentText.startsWith(otherfilter->shortcutString() + QLatin1Char(' '))) { + searchText = currentText.mid(otherfilter->shortcutString().length() + 1); + break; + } + } + } + show(filter->shortcutString() + QLatin1Char(' ') + searchText, + filter->shortcutString().length() + 1, + searchText.length()); + updateCompletionList(m_fileLineEdit->text()); + m_fileLineEdit->setFocus(); +} + +void LocatorWidget::showEvent(QShowEvent *event) +{ + QWidget::showEvent(event); +} + +void LocatorWidget::showConfigureDialog() +{ + ICore::showOptionsDialog(Core::Constants::SETTINGS_CATEGORY_CORE, Constants::FILTER_OPTIONS_PAGE); +} + +} // namespace Core diff --git a/src/plugins/coreplugin/locator/locatorwidget.h b/src/plugins/coreplugin/locator/locatorwidget.h new file mode 100644 index 00000000000..5bc150b362a --- /dev/null +++ b/src/plugins/coreplugin/locator/locatorwidget.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef LOCATORWIDGET_H +#define LOCATORWIDGET_H + +#include "locatorplugin.h" + +#include + +QT_BEGIN_NAMESPACE +class QAction; +class QLabel; +class QLineEdit; +class QMenu; +class QTreeView; +QT_END_NAMESPACE + +namespace Utils { + class FilterLineEdit; +} + +namespace Core { +namespace Internal { + +class LocatorModel; +class CompletionList; + +class LocatorWidget + : public QWidget +{ + Q_OBJECT + +public: + explicit LocatorWidget(LocatorPlugin *qop); + + void updateFilterList(); + + void show(const QString &text, int selectionStart = -1, int selectionLength = 0); + + void setPlaceholderText(const QString &text); + +private slots: + void showPopup(); + void showPopupNow(); + void acceptCurrentEntry(); + void filterSelected(); + void showConfigureDialog(); + void updateEntries(); + void scheduleAcceptCurrentEntry(); + void setFocusToCurrentMode(); + +private: + bool eventFilter(QObject *obj, QEvent *event); + + void showEvent(QShowEvent *e); + + void showCompletionList(); + void updateCompletionList(const QString &text); + QList filtersFor(const QString &text, QString &searchText); + + LocatorPlugin *m_locatorPlugin; + LocatorModel *m_locatorModel; + + CompletionList *m_completionList; + QMenu *m_filterMenu; + QAction *m_refreshAction; + QAction *m_configureAction; + Utils::FilterLineEdit *m_fileLineEdit; + QTimer *m_showPopupTimer; + QFutureWatcher *m_entriesWatcher; + QMap m_filterActionMap; + bool m_updateRequested; + bool m_acceptRequested; + bool m_possibleToolTipRequest; +}; + +} // namespace Internal +} // namespace Core + +#endif // LOCATORWIDGET_H diff --git a/src/plugins/coreplugin/locator/opendocumentsfilter.cpp b/src/plugins/coreplugin/locator/opendocumentsfilter.cpp new file mode 100644 index 00000000000..61fb946c0ab --- /dev/null +++ b/src/plugins/coreplugin/locator/opendocumentsfilter.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "opendocumentsfilter.h" + +#include +#include +#include + +#include + +using namespace Core; +using namespace Core; +using namespace Core::Internal; +using namespace Utils; + +OpenDocumentsFilter::OpenDocumentsFilter() +{ + setId("Open documents"); + setDisplayName(tr("Open Documents")); + setShortcutString(QString(QLatin1Char('o'))); + setIncludedByDefault(true); + + connect(EditorManager::instance(), SIGNAL(editorOpened(Core::IEditor*)), + this, SLOT(refreshInternally())); + connect(EditorManager::instance(), SIGNAL(editorsClosed(QList)), + this, SLOT(refreshInternally())); +} + +QList OpenDocumentsFilter::matchesFor(QFutureInterface &future, const QString &entry_) +{ + QList goodEntries; + QList betterEntries; + QString entry = entry_; + const QString lineNoSuffix = EditorManager::splitLineNumber(&entry); + const QChar asterisk = QLatin1Char('*'); + QString pattern = QString(asterisk); + pattern += entry; + pattern += asterisk; + QRegExp regexp(pattern, Qt::CaseInsensitive, QRegExp::Wildcard); + if (!regexp.isValid()) + return goodEntries; + const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry); + foreach (const DocumentModel::Entry &editorEntry, m_editors) { + if (future.isCanceled()) + break; + QString fileName = editorEntry.fileName(); + if (fileName.isEmpty()) + continue; + QString displayName = editorEntry.displayName(); + if (regexp.exactMatch(displayName)) { + QFileInfo fi(fileName); + LocatorFilterEntry fiEntry(this, fi.fileName(), QString(fileName + lineNoSuffix)); + fiEntry.extraInfo = FileUtils::shortNativePath(FileName(fi)); + fiEntry.fileName = fileName; + QList &category = displayName.startsWith(entry, caseSensitivityForPrefix) + ? betterEntries : goodEntries; + category.append(fiEntry); + } + } + betterEntries.append(goodEntries); + return betterEntries; +} + +void OpenDocumentsFilter::refreshInternally() +{ + m_editors.clear(); + foreach (DocumentModel::Entry *e, EditorManager::documentModel()->documents()) { + DocumentModel::Entry entry; + // create copy with only the information relevant to use + // to avoid model deleting entries behind our back + entry.m_displayName = e->displayName(); + entry.m_fileName = e->fileName(); + m_editors.append(entry); + } +} + +void OpenDocumentsFilter::refresh(QFutureInterface &future) +{ + Q_UNUSED(future) + QMetaObject::invokeMethod(this, "refreshInternally", Qt::BlockingQueuedConnection); +} + +void OpenDocumentsFilter::accept(LocatorFilterEntry selection) const +{ + EditorManager::openEditor(selection.internalData.toString(), Id(), + EditorManager::CanContainLineNumber); +} diff --git a/src/plugins/coreplugin/locator/opendocumentsfilter.h b/src/plugins/coreplugin/locator/opendocumentsfilter.h new file mode 100644 index 00000000000..b16ca7144b9 --- /dev/null +++ b/src/plugins/coreplugin/locator/opendocumentsfilter.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef OPENDOCUMENTSFILTER_H +#define OPENDOCUMENTSFILTER_H + +#include "ilocatorfilter.h" + +#include + +#include +#include +#include + +namespace Core { +namespace Internal { + +class OpenDocumentsFilter : public Core::ILocatorFilter +{ + Q_OBJECT + +public: + OpenDocumentsFilter(); + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(Core::LocatorFilterEntry selection) const; + void refresh(QFutureInterface &future); + +public slots: + void refreshInternally(); + +private: + QList m_editors; +}; + +} // namespace Internal +} // namespace Core + +#endif // OPENDOCUMENTSFILTER_H diff --git a/src/plugins/coreplugin/locator/settingspage.cpp b/src/plugins/coreplugin/locator/settingspage.cpp new file mode 100644 index 00000000000..abdec8be5d8 --- /dev/null +++ b/src/plugins/coreplugin/locator/settingspage.cpp @@ -0,0 +1,210 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "settingspage.h" +#include "locatorconstants.h" + +#include "locatorplugin.h" +#include "ilocatorfilter.h" +#include "directoryfilter.h" + +#include +#include + +#include + +Q_DECLARE_METATYPE(Core::ILocatorFilter*) + +using namespace Core; +using namespace Core::Internal; + +SettingsPage::SettingsPage(LocatorPlugin *plugin) + : m_plugin(plugin), m_widget(0) +{ + setId(Constants::FILTER_OPTIONS_PAGE); + setDisplayName(QCoreApplication::translate("Locator", Core::Constants::FILTER_OPTIONS_PAGE)); + setCategory(Core::Constants::SETTINGS_CATEGORY_CORE); + setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::SETTINGS_TR_CATEGORY_CORE)); + setCategoryIcon(QLatin1String(Core::Constants::SETTINGS_CATEGORY_CORE_ICON)); +} + +QWidget *SettingsPage::widget() +{ + if (!m_widget) { + m_widget = new QWidget; + m_ui.setupUi(m_widget); + m_ui.refreshInterval->setToolTip(m_ui.refreshIntervalLabel->toolTip()); + connect(m_ui.filterList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(updateButtonStates())); + connect(m_ui.filterList, SIGNAL(itemActivated(QListWidgetItem*)), + this, SLOT(configureFilter(QListWidgetItem*))); + connect(m_ui.editButton, SIGNAL(clicked()), + this, SLOT(configureFilter())); + connect(m_ui.addButton, SIGNAL(clicked()), + this, SLOT(addCustomFilter())); + connect(m_ui.removeButton, SIGNAL(clicked()), + this, SLOT(removeCustomFilter())); + + m_ui.refreshInterval->setValue(m_plugin->refreshInterval()); + m_filters = m_plugin->filters(); + m_customFilters = m_plugin->customFilters(); + saveFilterStates(); + updateFilterList(); + } + return m_widget; +} + +void SettingsPage::apply() +{ + // Delete removed filters and clear added filters + qDeleteAll(m_removedFilters); + m_removedFilters.clear(); + m_addedFilters.clear(); + + // Pass the new configuration on to the plugin + m_plugin->setFilters(m_filters); + m_plugin->setCustomFilters(m_customFilters); + m_plugin->setRefreshInterval(m_ui.refreshInterval->value()); + requestRefresh(); + m_plugin->saveSettings(); + saveFilterStates(); +} + +void SettingsPage::finish() +{ + // If settings were applied, this shouldn't change anything. Otherwise it + // makes sure the filter states aren't changed permanently. + restoreFilterStates(); + + // Delete added filters and clear removed filters + qDeleteAll(m_addedFilters); + m_addedFilters.clear(); + m_removedFilters.clear(); + + // Further cleanup + m_filters.clear(); + m_customFilters.clear(); + m_refreshFilters.clear(); + delete m_widget; +} + +void SettingsPage::requestRefresh() +{ + if (!m_refreshFilters.isEmpty()) + m_plugin->refresh(m_refreshFilters); +} + +void SettingsPage::saveFilterStates() +{ + m_filterStates.clear(); + foreach (ILocatorFilter *filter, m_filters) + m_filterStates.insert(filter, filter->saveState()); +} + +void SettingsPage::restoreFilterStates() +{ + foreach (ILocatorFilter *filter, m_filterStates.keys()) + filter->restoreState(m_filterStates.value(filter)); +} + +void SettingsPage::updateFilterList() +{ + m_ui.filterList->clear(); + foreach (ILocatorFilter *filter, m_filters) { + if (filter->isHidden()) + continue; + + QString title; + if (filter->isIncludedByDefault()) + title = filter->displayName(); + else + title = tr("%1 (prefix: %2)").arg(filter->displayName()).arg(filter->shortcutString()); + QListWidgetItem *item = new QListWidgetItem(title); + item->setData(Qt::UserRole, qVariantFromValue(filter)); + m_ui.filterList->addItem(item); + } + if (m_ui.filterList->count() > 0) + m_ui.filterList->setCurrentRow(0); +} + +void SettingsPage::updateButtonStates() +{ + QListWidgetItem *item = m_ui.filterList->currentItem(); + ILocatorFilter *filter = (item ? item->data(Qt::UserRole).value() : 0); + m_ui.editButton->setEnabled(filter && filter->isConfigurable()); + m_ui.removeButton->setEnabled(filter && m_customFilters.contains(filter)); +} + +void SettingsPage::configureFilter(QListWidgetItem *item) +{ + if (!item) + item = m_ui.filterList->currentItem(); + QTC_ASSERT(item, return); + ILocatorFilter *filter = item->data(Qt::UserRole).value(); + QTC_ASSERT(filter, return); + + if (!filter->isConfigurable()) + return; + bool needsRefresh = false; + filter->openConfigDialog(m_widget, needsRefresh); + if (needsRefresh && !m_refreshFilters.contains(filter)) + m_refreshFilters.append(filter); + updateFilterList(); +} + +void SettingsPage::addCustomFilter() +{ + ILocatorFilter *filter = new DirectoryFilter; + bool needsRefresh = false; + if (filter->openConfigDialog(m_widget, needsRefresh)) { + m_filters.append(filter); + m_addedFilters.append(filter); + m_customFilters.append(filter); + m_refreshFilters.append(filter); + updateFilterList(); + } +} + +void SettingsPage::removeCustomFilter() +{ + QListWidgetItem *item = m_ui.filterList->currentItem(); + QTC_ASSERT(item, return); + ILocatorFilter *filter = item->data(Qt::UserRole).value(); + QTC_ASSERT(m_customFilters.contains(filter), return); + m_filters.removeAll(filter); + m_customFilters.removeAll(filter); + m_refreshFilters.removeAll(filter); + if (m_addedFilters.contains(filter)) { + m_addedFilters.removeAll(filter); + delete filter; + } else { + m_removedFilters.append(filter); + } + updateFilterList(); +} diff --git a/src/plugins/coreplugin/locator/settingspage.h b/src/plugins/coreplugin/locator/settingspage.h new file mode 100644 index 00000000000..86ddb9d1a5e --- /dev/null +++ b/src/plugins/coreplugin/locator/settingspage.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef SETTINGSPAGE_H +#define SETTINGSPAGE_H + +#include "ui_settingspage.h" + +#include + +#include +#include + +QT_BEGIN_NAMESPACE +class QListWidgetItem; +QT_END_NAMESPACE + +namespace Core { + +class ILocatorFilter; + +namespace Internal { + +class LocatorPlugin; + +class SettingsPage : public Core::IOptionsPage +{ + Q_OBJECT + +public: + explicit SettingsPage(LocatorPlugin *plugin); + + QWidget *widget(); + void apply(); + void finish(); + +private slots: + void updateButtonStates(); + void configureFilter(QListWidgetItem *item = 0); + void addCustomFilter(); + void removeCustomFilter(); + +private: + void updateFilterList(); + void saveFilterStates(); + void restoreFilterStates(); + void requestRefresh(); + + Ui::LocatorSettingsWidget m_ui; + LocatorPlugin *m_plugin; + QPointer m_widget; + QList m_filters; + QList m_addedFilters; + QList m_removedFilters; + QList m_customFilters; + QList m_refreshFilters; + QHash m_filterStates; +}; + +} // namespace Internal +} // namespace Core + +#endif // SETTINGSPAGE_H diff --git a/src/plugins/coreplugin/locator/settingspage.ui b/src/plugins/coreplugin/locator/settingspage.ui new file mode 100644 index 00000000000..797b650269f --- /dev/null +++ b/src/plugins/coreplugin/locator/settingspage.ui @@ -0,0 +1,121 @@ + + + Core::Internal::LocatorSettingsWidget + + + + 0 + 0 + 367 + 242 + + + + Configure Filters + + + + + + + + + + + + + + + Add + + + + + + + false + + + Remove + + + + + + + false + + + Edit + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Locator filters that do not update their cached data immediately, such as the custom directory filters, update it after this time interval. + + + Refresh interval: + + + + + + + true + + + QAbstractSpinBox::PlusMinus + + + min + + + 320 + + + 5 + + + 60 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + diff --git a/src/plugins/coreplugin/progressmanager/progressmanager.cpp b/src/plugins/coreplugin/progressmanager/progressmanager.cpp index 89818a6d317..5180a374114 100644 --- a/src/plugins/coreplugin/progressmanager/progressmanager.cpp +++ b/src/plugins/coreplugin/progressmanager/progressmanager.cpp @@ -129,7 +129,7 @@ using namespace Core::Internal; \c QFuture object. This is what you want to give the ProgressManager in the addTask() function. - Have a look at e.g Locator::ILocatorFilter. Locator filters implement + Have a look at e.g Core::ILocatorFilter. Locator filters implement a function \c refresh which takes a \c QFutureInterface object as a parameter. These functions look something like: \code diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index e2fd697ce2b..e61d14b30df 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -1934,10 +1934,10 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa } // find a include file through the locator - QFutureInterface dummyInterface; - QList matches = classesFilter->matchesFor(dummyInterface, className); + QFutureInterface dummyInterface; + QList matches = classesFilter->matchesFor(dummyInterface, className); bool classExists = false; - foreach (const Locator::FilterEntry &entry, matches) { + foreach (const Core::LocatorFilterEntry &entry, matches) { const ModelItemInfo info = entry.internalData.value(); if (info.symbolName != className) continue; diff --git a/src/plugins/cpptools/builtinindexingsupport.cpp b/src/plugins/cpptools/builtinindexingsupport.cpp index faec76d150e..0e7542a2d77 100644 --- a/src/plugins/cpptools/builtinindexingsupport.cpp +++ b/src/plugins/cpptools/builtinindexingsupport.cpp @@ -92,7 +92,7 @@ public: ~BuiltinSymbolSearcher() {} - void runSearch(QFutureInterface &future) + void runSearch(QFutureInterface &future) { future.setProgressRange(0, m_snapshot.size()); future.setProgressValue(0); @@ -102,11 +102,11 @@ public: search.setSymbolsToSearchFor(m_parameters.types); CPlusPlus::Snapshot::const_iterator it = m_snapshot.begin(); - QString findString = (m_parameters.flags & Find::FindRegularExpression + QString findString = (m_parameters.flags & Core::FindRegularExpression ? m_parameters.text : QRegExp::escape(m_parameters.text)); - if (m_parameters.flags & Find::FindWholeWords) + if (m_parameters.flags & Core::FindWholeWords) findString = QString::fromLatin1("\\b%1\\b").arg(findString); - QRegExp matcher(findString, (m_parameters.flags & Find::FindCaseSensitively + QRegExp matcher(findString, (m_parameters.flags & Core::FindCaseSensitively ? Qt::CaseSensitive : Qt::CaseInsensitive)); while (it != m_snapshot.end()) { if (future.isPaused()) @@ -114,7 +114,7 @@ public: if (future.isCanceled()) break; if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->fileName())) { - QVector resultItems; + QVector resultItems; QList modelInfos = search(it.value()); foreach (const ModelItemInfo &info, modelInfos) { int index = matcher.indexIn(info.symbolName); @@ -130,7 +130,7 @@ public: info.symbolType); } - Find::SearchResultItem item; + Core::SearchResultItem item; item.path = scope.split(QLatin1String("::"), QString::SkipEmptyParts); item.text = text; item.textMarkPos = -1; diff --git a/src/plugins/cpptools/cppclassesfilter.cpp b/src/plugins/cpptools/cppclassesfilter.cpp index 5809e015201..a32ec4a562f 100644 --- a/src/plugins/cpptools/cppclassesfilter.cpp +++ b/src/plugins/cpptools/cppclassesfilter.cpp @@ -50,10 +50,10 @@ QList > CppClassesFilter::itemsToMatchUserInputAg return QList >() << m_data->classes(); } -Locator::FilterEntry CppClassesFilter::filterEntryFromModelItemInfo(const ModelItemInfo &info) +Core::LocatorFilterEntry CppClassesFilter::filterEntryFromModelItemInfo(const ModelItemInfo &info) { const QVariant id = qVariantFromValue(info); - Locator::FilterEntry filterEntry(this, info.symbolName, id, info.icon); + Core::LocatorFilterEntry filterEntry(this, info.symbolName, id, info.icon); filterEntry.extraInfo = info.symbolScope.isEmpty() ? info.shortNativeFilePath() : info.symbolScope; diff --git a/src/plugins/cpptools/cppclassesfilter.h b/src/plugins/cpptools/cppclassesfilter.h index ceb02b8e7d0..40888d6c336 100644 --- a/src/plugins/cpptools/cppclassesfilter.h +++ b/src/plugins/cpptools/cppclassesfilter.h @@ -46,7 +46,7 @@ public: private: QList > itemsToMatchUserInputAgainst() const; - Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info); + Core::LocatorFilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info); }; } // namespace CppTools diff --git a/src/plugins/cpptools/cppcurrentdocumentfilter.cpp b/src/plugins/cpptools/cppcurrentdocumentfilter.cpp index 2febb844c6b..fb5567d47c5 100644 --- a/src/plugins/cpptools/cppcurrentdocumentfilter.cpp +++ b/src/plugins/cpptools/cppcurrentdocumentfilter.cpp @@ -57,11 +57,11 @@ CppCurrentDocumentFilter::CppCurrentDocumentFilter(CppModelManager *manager) this, SLOT(onEditorAboutToClose(Core::IEditor*))); } -QList CppCurrentDocumentFilter::matchesFor(QFutureInterface &future, const QString & origEntry) +QList CppCurrentDocumentFilter::matchesFor(QFutureInterface &future, const QString & origEntry) { QString entry = trimWildcards(origEntry); - QList goodEntries; - QList betterEntries; + QList goodEntries; + QList betterEntries; QStringMatcher matcher(entry, Qt::CaseInsensitive); const QChar asterisk = QLatin1Char('*'); QRegExp regexp(asterisk + entry + asterisk, Qt::CaseInsensitive, QRegExp::Wildcard); @@ -102,7 +102,7 @@ QList CppCurrentDocumentFilter::matchesFor(QFutureInterfac if (info.unqualifiedNameAndScope(matchString, &name, &extraInfo)) name += info.symbolType; } - Locator::FilterEntry filterEntry(this, name, id, info.icon); + Core::LocatorFilterEntry filterEntry(this, name, id, info.icon); filterEntry.extraInfo = extraInfo; if (matchString.startsWith(entry, caseSensitivityForPrefix)) @@ -118,7 +118,7 @@ QList CppCurrentDocumentFilter::matchesFor(QFutureInterfac return betterEntries; } -void CppCurrentDocumentFilter::accept(Locator::FilterEntry selection) const +void CppCurrentDocumentFilter::accept(Core::LocatorFilterEntry selection) const { ModelItemInfo info = qvariant_cast(selection.internalData); Core::EditorManager::openEditorAt(info.fileName, info.line, info.column); diff --git a/src/plugins/cpptools/cppcurrentdocumentfilter.h b/src/plugins/cpptools/cppcurrentdocumentfilter.h index 5e2bb390d6b..b181bc40bf4 100644 --- a/src/plugins/cpptools/cppcurrentdocumentfilter.h +++ b/src/plugins/cpptools/cppcurrentdocumentfilter.h @@ -31,7 +31,7 @@ #include "searchsymbols.h" -#include +#include namespace Core { class IEditor; } @@ -40,7 +40,7 @@ namespace Internal { class CppModelManager; -class CppCurrentDocumentFilter : public Locator::ILocatorFilter +class CppCurrentDocumentFilter : public Core::ILocatorFilter { Q_OBJECT @@ -48,8 +48,8 @@ public: explicit CppCurrentDocumentFilter(CppModelManager *manager); ~CppCurrentDocumentFilter() {} - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(Locator::FilterEntry selection) const; + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(Core::LocatorFilterEntry selection) const; void refresh(QFutureInterface &future); private slots: diff --git a/src/plugins/cpptools/cppfindreferences.cpp b/src/plugins/cpptools/cppfindreferences.cpp index 0cce94007c3..8f846a90c21 100644 --- a/src/plugins/cpptools/cppfindreferences.cpp +++ b/src/plugins/cpptools/cppfindreferences.cpp @@ -325,15 +325,15 @@ void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol, bool replace) { Overview overview; - Find::SearchResult *search = Find::SearchResultWindow::instance()->startNewSearch(tr("C++ Usages:"), + Core::SearchResult *search = Core::SearchResultWindow::instance()->startNewSearch(tr("C++ Usages:"), QString(), overview.prettyName(context.fullyQualifiedName(symbol)), - replace ? Find::SearchResultWindow::SearchAndReplace - : Find::SearchResultWindow::SearchOnly, + replace ? Core::SearchResultWindow::SearchAndReplace + : Core::SearchResultWindow::SearchOnly, QLatin1String("CppEditor")); search->setTextToReplace(replacement); - connect(search, SIGNAL(replaceButtonClicked(QString,QList,bool)), - SLOT(onReplaceButtonClicked(QString,QList,bool))); + connect(search, SIGNAL(replaceButtonClicked(QString,QList,bool)), + SLOT(onReplaceButtonClicked(QString,QList,bool))); connect(search, SIGNAL(paused(bool)), this, SLOT(setPaused(bool))); search->setSearchAgainSupported(true); connect(search, SIGNAL(searchAgainRequested()), this, SLOT(searchAgain())); @@ -354,7 +354,7 @@ void CppFindReferences::renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus: } } -void CppFindReferences::findAll_helper(Find::SearchResult *search, CPlusPlus::Symbol *symbol, +void CppFindReferences::findAll_helper(Core::SearchResult *search, CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) { if (!(symbol && symbol->identifier())) { @@ -362,10 +362,10 @@ void CppFindReferences::findAll_helper(Find::SearchResult *search, CPlusPlus::Sy return; } connect(search, SIGNAL(cancelled()), this, SLOT(cancel())); - connect(search, SIGNAL(activated(Find::SearchResultItem)), - this, SLOT(openEditor(Find::SearchResultItem))); + connect(search, SIGNAL(activated(Core::SearchResultItem)), + this, SLOT(openEditor(Core::SearchResultItem))); - Find::SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus); + Core::SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus); const CppModelManagerInterface::WorkingCopy workingCopy = m_modelManager->workingCopy(); QFuture result; result = QtConcurrent::run(&find_helper, workingCopy, context, this, symbol); @@ -378,19 +378,19 @@ void CppFindReferences::findAll_helper(Find::SearchResult *search, CPlusPlus::Sy } void CppFindReferences::onReplaceButtonClicked(const QString &text, - const QList &items, + const QList &items, bool preserveCase) { const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase); if (!fileNames.isEmpty()) { m_modelManager->updateSourceFiles(fileNames); - Find::SearchResultWindow::instance()->hide(); + Core::SearchResultWindow::instance()->hide(); } } void CppFindReferences::searchAgain() { - Find::SearchResult *search = qobject_cast(sender()); + Core::SearchResult *search = qobject_cast(sender()); CppFindReferencesParameters parameters = search->userData().value(); Snapshot snapshot = CppModelManagerInterface::instance()->snapshot(); search->restart(); @@ -470,7 +470,7 @@ CPlusPlus::Symbol *CppFindReferences::findSymbol(const CppFindReferencesParamete void CppFindReferences::displayResults(int first, int last) { QFutureWatcher *watcher = static_cast *>(sender()); - Find::SearchResult *search = m_watchers.value(watcher); + Core::SearchResult *search = m_watchers.value(watcher); if (!search) { // search was deleted while it was running watcher->cancel(); @@ -489,7 +489,7 @@ void CppFindReferences::displayResults(int first, int last) void CppFindReferences::searchFinished() { QFutureWatcher *watcher = static_cast *>(sender()); - Find::SearchResult *search = m_watchers.value(watcher); + Core::SearchResult *search = m_watchers.value(watcher); if (search) search->finishSearch(watcher->isCanceled()); m_watchers.remove(watcher); @@ -498,7 +498,7 @@ void CppFindReferences::searchFinished() void CppFindReferences::cancel() { - Find::SearchResult *search = qobject_cast(sender()); + Core::SearchResult *search = qobject_cast(sender()); QTC_ASSERT(search, return); QFutureWatcher *watcher = m_watchers.key(search); QTC_ASSERT(watcher, return); @@ -507,7 +507,7 @@ void CppFindReferences::cancel() void CppFindReferences::setPaused(bool paused) { - Find::SearchResult *search = qobject_cast(sender()); + Core::SearchResult *search = qobject_cast(sender()); QTC_ASSERT(search, return); QFutureWatcher *watcher = m_watchers.key(search); QTC_ASSERT(watcher, return); @@ -515,7 +515,7 @@ void CppFindReferences::setPaused(bool paused) watcher->setPaused(paused); } -void CppFindReferences::openEditor(const Find::SearchResultItem &item) +void CppFindReferences::openEditor(const Core::SearchResultItem &item) { if (item.path.size() > 0) { EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()), @@ -634,22 +634,22 @@ void CppFindReferences::findMacroUses(const Macro ¯o) void CppFindReferences::findMacroUses(const Macro ¯o, const QString &replacement, bool replace) { - Find::SearchResult *search = Find::SearchResultWindow::instance()->startNewSearch( + Core::SearchResult *search = Core::SearchResultWindow::instance()->startNewSearch( tr("C++ Macro Usages:"), QString(), QString::fromUtf8(macro.name()), - replace ? Find::SearchResultWindow::SearchAndReplace - : Find::SearchResultWindow::SearchOnly, + replace ? Core::SearchResultWindow::SearchAndReplace + : Core::SearchResultWindow::SearchOnly, QLatin1String("CppEditor")); search->setTextToReplace(replacement); - connect(search, SIGNAL(replaceButtonClicked(QString,QList,bool)), - SLOT(onReplaceButtonClicked(QString,QList,bool))); + connect(search, SIGNAL(replaceButtonClicked(QString,QList,bool)), + SLOT(onReplaceButtonClicked(QString,QList,bool))); - Find::SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus); + Core::SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus); - connect(search, SIGNAL(activated(Find::SearchResultItem)), - this, SLOT(openEditor(Find::SearchResultItem))); + connect(search, SIGNAL(activated(Core::SearchResultItem)), + this, SLOT(openEditor(Core::SearchResultItem))); connect(search, SIGNAL(cancelled()), this, SLOT(cancel())); connect(search, SIGNAL(paused(bool)), this, SLOT(setPaused(bool))); @@ -714,7 +714,7 @@ void CppFindReferences::setDependencyTable(const CPlusPlus::DependencyTable &new m_deps = newTable; } -void CppFindReferences::createWatcher(const QFuture &future, Find::SearchResult *search) +void CppFindReferences::createWatcher(const QFuture &future, Core::SearchResult *search) { QFutureWatcher *watcher = new QFutureWatcher(); watcher->setPendingResultsLimit(1); diff --git a/src/plugins/cpptools/cppfindreferences.h b/src/plugins/cpptools/cppfindreferences.h index 3b8863d0b0f..200907ed118 100644 --- a/src/plugins/cpptools/cppfindreferences.h +++ b/src/plugins/cpptools/cppfindreferences.h @@ -41,10 +41,10 @@ QT_FORWARD_DECLARE_CLASS(QTimer) -namespace Find { +namespace Core { class SearchResultItem; class SearchResult; -} // namespace Find +} // namespace Core namespace CppTools { class CppModelManagerInterface; @@ -86,8 +86,8 @@ private slots: void searchFinished(); void cancel(); void setPaused(bool paused); - void openEditor(const Find::SearchResultItem &item); - void onReplaceButtonClicked(const QString &text, const QList &items, bool preserveCase); + void openEditor(const Core::SearchResultItem &item); + void onReplaceButtonClicked(const QString &text, const QList &items, bool preserveCase); void searchAgain(); private: @@ -95,17 +95,17 @@ private: const QString &replacement, bool replace); void findMacroUses(const CPlusPlus::Macro ¯o, const QString &replacement, bool replace); - void findAll_helper(Find::SearchResult *search, CPlusPlus::Symbol *symbol, + void findAll_helper(Core::SearchResult *search, CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context); CPlusPlus::DependencyTable dependencyTable() const; void setDependencyTable(const CPlusPlus::DependencyTable &newTable); - void createWatcher(const QFuture &future, Find::SearchResult *search); + void createWatcher(const QFuture &future, Core::SearchResult *search); CPlusPlus::Symbol *findSymbol(const CppFindReferencesParameters ¶meters, const CPlusPlus::Snapshot &snapshot, CPlusPlus::LookupContext *context); private: QPointer m_modelManager; - QMap *, QPointer > m_watchers; + QMap *, QPointer > m_watchers; mutable QMutex m_depsLock; CPlusPlus::DependencyTable m_deps; diff --git a/src/plugins/cpptools/cppfunctionsfilter.cpp b/src/plugins/cpptools/cppfunctionsfilter.cpp index 400d19c1e6c..1f17402763d 100644 --- a/src/plugins/cpptools/cppfunctionsfilter.cpp +++ b/src/plugins/cpptools/cppfunctionsfilter.cpp @@ -49,7 +49,7 @@ QList > CppFunctionsFilter::itemsToMatchUserInput return QList >() << m_data->functions(); } -Locator::FilterEntry CppFunctionsFilter::filterEntryFromModelItemInfo(const CppTools::ModelItemInfo &info) +Core::LocatorFilterEntry CppFunctionsFilter::filterEntryFromModelItemInfo(const CppTools::ModelItemInfo &info) { const QVariant id = qVariantFromValue(info); @@ -59,7 +59,7 @@ Locator::FilterEntry CppFunctionsFilter::filterEntryFromModelItemInfo(const CppT if (extraInfo.isEmpty()) extraInfo = info.shortNativeFilePath(); - Locator::FilterEntry filterEntry(this, name + info.symbolType, id, info.icon); + Core::LocatorFilterEntry filterEntry(this, name + info.symbolType, id, info.icon); filterEntry.extraInfo = extraInfo; return filterEntry; diff --git a/src/plugins/cpptools/cppfunctionsfilter.h b/src/plugins/cpptools/cppfunctionsfilter.h index a3aa7d3c092..5926f645cd7 100644 --- a/src/plugins/cpptools/cppfunctionsfilter.h +++ b/src/plugins/cpptools/cppfunctionsfilter.h @@ -46,7 +46,7 @@ public: private: QList > itemsToMatchUserInputAgainst() const; - Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info); + Core::LocatorFilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info); }; } // namespace Internal diff --git a/src/plugins/cpptools/cppindexingsupport.h b/src/plugins/cpptools/cppindexingsupport.h index 00cb80f5d40..bd50dfc6361 100644 --- a/src/plugins/cpptools/cppindexingsupport.h +++ b/src/plugins/cpptools/cppindexingsupport.h @@ -34,8 +34,8 @@ #include "cppmodelmanagerinterface.h" -#include -#include +#include +#include #include #include @@ -64,7 +64,7 @@ public: struct Parameters { QString text; - Find::FindFlags flags; + Core::FindFlags flags; SymbolTypes types; SearchScope scope; }; @@ -73,7 +73,7 @@ public: public: SymbolSearcher(QObject *parent = 0); virtual ~SymbolSearcher() = 0; - virtual void runSearch(QFutureInterface &future) = 0; + virtual void runSearch(QFutureInterface &future) = 0; }; diff --git a/src/plugins/cpptools/cpplocatorfilter.cpp b/src/plugins/cpptools/cpplocatorfilter.cpp index 5680d36dc06..e4286e13ee1 100644 --- a/src/plugins/cpptools/cpplocatorfilter.cpp +++ b/src/plugins/cpptools/cpplocatorfilter.cpp @@ -47,10 +47,10 @@ CppLocatorFilter::~CppLocatorFilter() { } -Locator::FilterEntry CppLocatorFilter::filterEntryFromModelItemInfo(const CppTools::ModelItemInfo &info) +Core::LocatorFilterEntry CppLocatorFilter::filterEntryFromModelItemInfo(const CppTools::ModelItemInfo &info) { const QVariant id = qVariantFromValue(info); - Locator::FilterEntry filterEntry(this, info.scopedSymbolName(), id, info.icon); + Core::LocatorFilterEntry filterEntry(this, info.scopedSymbolName(), id, info.icon); filterEntry.extraInfo = info.type == ModelItemInfo::Class || info.type == ModelItemInfo::Enum ? info.shortNativeFilePath() : info.symbolType; @@ -71,17 +71,17 @@ QList > CppLocatorFilter::itemsToMatchUserInputAg << m_data->enums(); } -static bool compareLexigraphically(const Locator::FilterEntry &a, - const Locator::FilterEntry &b) +static bool compareLexigraphically(const Core::LocatorFilterEntry &a, + const Core::LocatorFilterEntry &b) { return a.displayName < b.displayName; } -QList CppLocatorFilter::matchesFor(QFutureInterface &future, const QString &origEntry) +QList CppLocatorFilter::matchesFor(QFutureInterface &future, const QString &origEntry) { QString entry = trimWildcards(origEntry); - QList goodEntries; - QList betterEntries; + QList goodEntries; + QList betterEntries; const QChar asterisk = QLatin1Char('*'); QStringMatcher matcher(entry, Qt::CaseInsensitive); QRegExp regexp(asterisk + entry+ asterisk, Qt::CaseInsensitive, QRegExp::Wildcard); @@ -99,7 +99,7 @@ QList CppLocatorFilter::matchesFor(QFutureInterface CppLocatorFilter::matchesFor(QFutureInterface(selection.internalData); Core::EditorManager::openEditorAt(info.fileName, info.line, info.column); diff --git a/src/plugins/cpptools/cpplocatorfilter.h b/src/plugins/cpptools/cpplocatorfilter.h index c1702410372..aba6fe4a275 100644 --- a/src/plugins/cpptools/cpplocatorfilter.h +++ b/src/plugins/cpptools/cpplocatorfilter.h @@ -33,14 +33,14 @@ #include "cpplocatordata.h" #include "searchsymbols.h" -#include +#include namespace CppTools { namespace Internal { class CppModelManager; -class CppLocatorFilter : public Locator::ILocatorFilter +class CppLocatorFilter : public Core::ILocatorFilter { Q_OBJECT @@ -48,13 +48,13 @@ public: CppLocatorFilter(CppLocatorData *locatorData); ~CppLocatorFilter(); - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(Locator::FilterEntry selection) const; + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(Core::LocatorFilterEntry selection) const; void refresh(QFutureInterface &future); private: virtual QList > itemsToMatchUserInputAgainst() const; - virtual Locator::FilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info); + virtual Core::LocatorFilterEntry filterEntryFromModelItemInfo(const ModelItemInfo &info); protected: CppLocatorData *m_data; diff --git a/src/plugins/cpptools/cpplocatorfilter_test.cpp b/src/plugins/cpptools/cpplocatorfilter_test.cpp index 5a0bb04654e..175ba94ea8d 100644 --- a/src/plugins/cpptools/cpplocatorfilter_test.cpp +++ b/src/plugins/cpptools/cpplocatorfilter_test.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include @@ -50,8 +50,6 @@ using namespace Core; using namespace Core::Tests; using namespace CppTools::Internal; using namespace ExtensionSystem; -using namespace Locator; -using namespace Locator::Tests; using namespace Utils; Q_DECLARE_METATYPE(ILocatorFilter *) diff --git a/src/plugins/cpptools/cpptools.qbs b/src/plugins/cpptools/cpptools.qbs index 18cf784cb83..ddbc4feace3 100644 --- a/src/plugins/cpptools/cpptools.qbs +++ b/src/plugins/cpptools/cpptools.qbs @@ -8,10 +8,8 @@ QtcPlugin { Depends { name: "Qt.widgets" } Depends { name: "Core" } - Depends { name: "Find" } Depends { name: "TextEditor" } Depends { name: "ProjectExplorer" } - Depends { name: "Locator" } Depends { name: "CPlusPlus" } Depends { name: "LanguageUtils" } diff --git a/src/plugins/cpptools/cpptools_dependencies.pri b/src/plugins/cpptools/cpptools_dependencies.pri index 15f93ba8376..82a3b3fdf7e 100644 --- a/src/plugins/cpptools/cpptools_dependencies.pri +++ b/src/plugins/cpptools/cpptools_dependencies.pri @@ -5,6 +5,4 @@ QTC_LIB_DEPENDS += \ QTC_PLUGIN_DEPENDS += \ coreplugin \ projectexplorer \ - texteditor \ - locator \ - find + texteditor diff --git a/src/plugins/cpptools/symbolsearcher_test.cpp b/src/plugins/cpptools/symbolsearcher_test.cpp index 5056b942631..9c128b26300 100644 --- a/src/plugins/cpptools/symbolsearcher_test.cpp +++ b/src/plugins/cpptools/symbolsearcher_test.cpp @@ -62,10 +62,10 @@ public: return m_symbolName == other.m_symbolName && m_scope == other.m_scope; } - static ResultDataList fromSearchResultList(const QList &entries) + static ResultDataList fromSearchResultList(const QList &entries) { ResultDataList result; - foreach (const Find::SearchResultItem &entry, entries) + foreach (const Core::SearchResultItem &entry, entries) result << ResultData(entry.text, entry.path.join(QLatin1String("::"))); return result; } @@ -108,7 +108,7 @@ public: CppIndexingSupport *indexingSupport = m_modelManager->indexingSupport(); SymbolSearcher *symbolSearcher = indexingSupport->createSymbolSearcher(searchParameters, QSet() << testFile); - QFuture search + QFuture search = QtConcurrent::run(&SymbolSearcher::runSearch, symbolSearcher); search.waitForFinished(); ResultDataList results = ResultData::fromSearchResultList(search.results()); diff --git a/src/plugins/cpptools/symbolsfindfilter.cpp b/src/plugins/cpptools/symbolsfindfilter.cpp index adfdbc21912..6150c01bec6 100644 --- a/src/plugins/cpptools/symbolsfindfilter.cpp +++ b/src/plugins/cpptools/symbolsfindfilter.cpp @@ -84,35 +84,35 @@ bool SymbolsFindFilter::isEnabled() const void SymbolsFindFilter::cancel() { - Find::SearchResult *search = qobject_cast(sender()); + Core::SearchResult *search = qobject_cast(sender()); QTC_ASSERT(search, return); - QFutureWatcher *watcher = m_watchers.key(search); + QFutureWatcher *watcher = m_watchers.key(search); QTC_ASSERT(watcher, return); watcher->cancel(); } void SymbolsFindFilter::setPaused(bool paused) { - Find::SearchResult *search = qobject_cast(sender()); + Core::SearchResult *search = qobject_cast(sender()); QTC_ASSERT(search, return); - QFutureWatcher *watcher = m_watchers.key(search); + QFutureWatcher *watcher = m_watchers.key(search); QTC_ASSERT(watcher, return); if (!paused || watcher->isRunning()) // guard against pausing when the search is finished watcher->setPaused(paused); } -Find::FindFlags SymbolsFindFilter::supportedFindFlags() const +Core::FindFlags SymbolsFindFilter::supportedFindFlags() const { - return Find::FindCaseSensitively | Find::FindRegularExpression | Find::FindWholeWords; + return Core::FindCaseSensitively | Core::FindRegularExpression | Core::FindWholeWords; } -void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags) +void SymbolsFindFilter::findAll(const QString &txt, Core::FindFlags findFlags) { - Find::SearchResultWindow *window = Find::SearchResultWindow::instance(); - Find::SearchResult *search = window->startNewSearch(label(), toolTip(findFlags), txt); + Core::SearchResultWindow *window = Core::SearchResultWindow::instance(); + Core::SearchResult *search = window->startNewSearch(label(), toolTip(findFlags), txt); search->setSearchAgainSupported(true); - connect(search, SIGNAL(activated(Find::SearchResultItem)), - this, SLOT(openEditor(Find::SearchResultItem))); + connect(search, SIGNAL(activated(Core::SearchResultItem)), + this, SLOT(openEditor(Core::SearchResultItem))); connect(search, SIGNAL(cancelled()), this, SLOT(cancel())); connect(search, SIGNAL(paused(bool)), this, SLOT(setPaused(bool))); connect(search, SIGNAL(searchAgainRequested()), this, SLOT(searchAgain())); @@ -128,7 +128,7 @@ void SymbolsFindFilter::findAll(const QString &txt, Find::FindFlags findFlags) startSearch(search); } -void SymbolsFindFilter::startSearch(Find::SearchResult *search) +void SymbolsFindFilter::startSearch(Core::SearchResult *search) { SymbolSearcher::Parameters parameters = search->userData().value(); QSet projectFileNames; @@ -137,7 +137,7 @@ void SymbolsFindFilter::startSearch(Find::SearchResult *search) projectFileNames += project->files(ProjectExplorer::Project::AllFiles).toSet(); } - QFutureWatcher *watcher = new QFutureWatcher(); + QFutureWatcher *watcher = new QFutureWatcher(); m_watchers.insert(watcher, search); connect(watcher, SIGNAL(finished()), this, SLOT(finish())); @@ -148,38 +148,38 @@ void SymbolsFindFilter::startSearch(Find::SearchResult *search) symbolSearcher, SLOT(deleteLater())); watcher->setFuture(QtConcurrent::run(&SymbolSearcher::runSearch, symbolSearcher)); FutureProgress *progress = ProgressManager::addTask(watcher->future(), tr("Searching"), - Find::Constants::TASK_SEARCH); + Core::Constants::TASK_SEARCH); connect(progress, SIGNAL(clicked()), search, SLOT(popup())); } void SymbolsFindFilter::addResults(int begin, int end) { - QFutureWatcher *watcher = - static_cast *>(sender()); - Find::SearchResult *search = m_watchers.value(watcher); + QFutureWatcher *watcher = + static_cast *>(sender()); + Core::SearchResult *search = m_watchers.value(watcher); if (!search) { // search was removed from search history while the search is running watcher->cancel(); return; } - QList items; + QList items; for (int i = begin; i < end; ++i) items << watcher->resultAt(i); - search->addResults(items, Find::SearchResult::AddSorted); + search->addResults(items, Core::SearchResult::AddSorted); } void SymbolsFindFilter::finish() { - QFutureWatcher *watcher = - static_cast *>(sender()); - Find::SearchResult *search = m_watchers.value(watcher); + QFutureWatcher *watcher = + static_cast *>(sender()); + Core::SearchResult *search = m_watchers.value(watcher); if (search) search->finishSearch(watcher->isCanceled()); m_watchers.remove(watcher); watcher->deleteLater(); } -void SymbolsFindFilter::openEditor(const Find::SearchResultItem &item) +void SymbolsFindFilter::openEditor(const Core::SearchResultItem &item) { if (!item.userData.canConvert()) return; @@ -229,7 +229,7 @@ void SymbolsFindFilter::onAllTasksFinished(Core::Id type) void SymbolsFindFilter::searchAgain() { - Find::SearchResult *search = qobject_cast(sender()); + Core::SearchResult *search = qobject_cast(sender()); QTC_ASSERT(search, return); search->restart(); startSearch(search); @@ -240,7 +240,7 @@ QString SymbolsFindFilter::label() const return tr("C++ Symbols:"); } -QString SymbolsFindFilter::toolTip(Find::FindFlags findFlags) const +QString SymbolsFindFilter::toolTip(Core::FindFlags findFlags) const { QStringList types; if (m_symbolsToSearch & SymbolSearcher::Classes) @@ -254,7 +254,7 @@ QString SymbolsFindFilter::toolTip(Find::FindFlags findFlags) const return tr("Scope: %1\nTypes: %2\nFlags: %3") .arg(searchScope() == SymbolSearcher::SearchGlobal ? tr("All") : tr("Projects")) .arg(types.join(tr(", "))) - .arg(Find::IFindFilter::descriptionForFindFlags(findFlags)); + .arg(Core::IFindFilter::descriptionForFindFlags(findFlags)); } // #pragma mark -- SymbolsFindFilterConfigWidget diff --git a/src/plugins/cpptools/symbolsfindfilter.h b/src/plugins/cpptools/symbolsfindfilter.h index 998b58dba3e..6dc550763ef 100644 --- a/src/plugins/cpptools/symbolsfindfilter.h +++ b/src/plugins/cpptools/symbolsfindfilter.h @@ -32,7 +32,7 @@ #include "searchsymbols.h" -#include +#include #include #include @@ -45,7 +45,7 @@ namespace Internal { class CppModelManager; -class SymbolsFindFilter : public Find::IFindFilter +class SymbolsFindFilter : public Core::IFindFilter { Q_OBJECT @@ -58,9 +58,9 @@ public: QString id() const; QString displayName() const; bool isEnabled() const; - Find::FindFlags supportedFindFlags() const; + Core::FindFlags supportedFindFlags() const; - void findAll(const QString &txt, Find::FindFlags findFlags); + void findAll(const QString &txt, Core::FindFlags findFlags); QWidget *createConfigWidget(); void writeSettings(QSettings *settings); @@ -76,7 +76,7 @@ signals: void symbolsToSearchChanged(); private slots: - void openEditor(const Find::SearchResultItem &item); + void openEditor(const Core::SearchResultItem &item); void addResults(int begin, int end); void finish(); @@ -88,13 +88,13 @@ private slots: private: QString label() const; - QString toolTip(Find::FindFlags findFlags) const; - void startSearch(Find::SearchResult *search); + QString toolTip(Core::FindFlags findFlags) const; + void startSearch(Core::SearchResult *search); CppModelManager *m_manager; bool m_enabled; - QMap *, QPointer > m_watchers; - QPointer m_currentSearch; + QMap *, QPointer > m_watchers; + QPointer m_currentSearch; SearchSymbols::SymbolTypes m_symbolsToSearch; SearchScope m_scope; }; diff --git a/src/plugins/cvs/cvs.qbs b/src/plugins/cvs/cvs.qbs index a1021cfc6e7..810ae1211bc 100644 --- a/src/plugins/cvs/cvs.qbs +++ b/src/plugins/cvs/cvs.qbs @@ -8,9 +8,7 @@ QtcPlugin { Depends { name: "Qt.widgets" } Depends { name: "Core" } Depends { name: "TextEditor" } - Depends { name: "Find" } Depends { name: "VcsBase" } - Depends { name: "Locator" } files: [ "annotationhighlighter.cpp", diff --git a/src/plugins/cvs/cvs_dependencies.pri b/src/plugins/cvs/cvs_dependencies.pri index a10e575988c..8761cf6570a 100644 --- a/src/plugins/cvs/cvs_dependencies.pri +++ b/src/plugins/cvs/cvs_dependencies.pri @@ -2,7 +2,6 @@ QTC_PLUGIN_NAME = CVS QTC_LIB_DEPENDS += \ utils QTC_PLUGIN_DEPENDS += \ - locator \ texteditor \ coreplugin \ vcsbase diff --git a/src/plugins/cvs/cvsplugin.cpp b/src/plugins/cvs/cvsplugin.cpp index 28a06acda81..9e85e9b7bfe 100644 --- a/src/plugins/cvs/cvsplugin.cpp +++ b/src/plugins/cvs/cvsplugin.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -56,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -251,7 +251,7 @@ bool CvsPlugin::initialize(const QStringList &arguments, QString *errorMessage) addAutoReleasedObject(new CheckoutWizard); const QString prefix = QLatin1String("cvs"); - m_commandLocator = new Locator::CommandLocator("CVS", prefix, prefix); + m_commandLocator = new Core::CommandLocator("CVS", prefix, prefix); addAutoReleasedObject(m_commandLocator); // Register actions diff --git a/src/plugins/cvs/cvsplugin.h b/src/plugins/cvs/cvsplugin.h index cccd7af7ba7..bc725da7685 100644 --- a/src/plugins/cvs/cvsplugin.h +++ b/src/plugins/cvs/cvsplugin.h @@ -42,13 +42,13 @@ class QTextCodec; QT_END_NAMESPACE namespace Core { +class CommandLocator; class IEditorFactory; class IVersionControl; } namespace Utils { class ParameterAction; } namespace VcsBase { class VcsBaseSubmitEditor; } -namespace Locator { class CommandLocator; } namespace Cvs { namespace Internal { @@ -171,7 +171,7 @@ private: QString m_commitMessageFileName; QString m_commitRepository; - Locator::CommandLocator *m_commandLocator; + Core::CommandLocator *m_commandLocator; Utils::ParameterAction *m_addAction; Utils::ParameterAction *m_deleteAction; Utils::ParameterAction *m_revertAction; diff --git a/src/plugins/debugger/basewindow.cpp b/src/plugins/debugger/basewindow.cpp index b2757de790c..3da6a8aa7f3 100644 --- a/src/plugins/debugger/basewindow.cpp +++ b/src/plugins/debugger/basewindow.cpp @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include @@ -69,7 +69,7 @@ BaseWindow::BaseWindow(QTreeView *treeView, QWidget *parent) Aggregation::Aggregate *agg = new Aggregation::Aggregate; agg->add(m_treeView); - agg->add(new Find::TreeViewFind(m_treeView)); + agg->add(new Core::TreeViewFind(m_treeView)); } } // namespace Internal diff --git a/src/plugins/debugger/debugger.qbs b/src/plugins/debugger/debugger.qbs index 290929db46d..16927cb79ba 100644 --- a/src/plugins/debugger/debugger.qbs +++ b/src/plugins/debugger/debugger.qbs @@ -8,7 +8,6 @@ QtcPlugin { Depends { name: "Qt"; submodules: ["widgets", "network", "script"] } Depends { name: "Core" } Depends { name: "CppTools" } - Depends { name: "Find" } Depends { name: "ProjectExplorer" } Depends { name: "TextEditor" } Depends { name: "CPlusPlus" } diff --git a/src/plugins/debugger/debugger_dependencies.pri b/src/plugins/debugger/debugger_dependencies.pri index 369a4fc2525..d537fa70d5f 100644 --- a/src/plugins/debugger/debugger_dependencies.pri +++ b/src/plugins/debugger/debugger_dependencies.pri @@ -8,7 +8,6 @@ QTC_LIB_DEPENDS += \ QTC_PLUGIN_DEPENDS += \ coreplugin \ cpptools \ - find \ projectexplorer \ texteditor QTC_PLUGIN_RECOMMENDS += \ diff --git a/src/plugins/debugger/logwindow.cpp b/src/plugins/debugger/logwindow.cpp index 6ad66dbbdd3..74a3f3f525c 100644 --- a/src/plugins/debugger/logwindow.cpp +++ b/src/plugins/debugger/logwindow.cpp @@ -48,7 +48,7 @@ #include #include #include -#include +#include #include #include @@ -408,11 +408,11 @@ LogWindow::LogWindow(QWidget *parent) Aggregation::Aggregate *aggregate = new Aggregation::Aggregate; aggregate->add(m_combinedText); - aggregate->add(new Find::BaseTextFind(m_combinedText)); + aggregate->add(new Core::BaseTextFind(m_combinedText)); aggregate = new Aggregation::Aggregate; aggregate->add(m_inputText); - aggregate->add(new Find::BaseTextFind(m_inputText)); + aggregate->add(new Core::BaseTextFind(m_inputText)); connect(m_inputText, SIGNAL(statusMessageRequested(QString,int)), SIGNAL(statusMessageRequested(QString,int))); diff --git a/src/plugins/diffeditor/diffeditor.qbs b/src/plugins/diffeditor/diffeditor.qbs index 69ef2c01dca..622267fbb5c 100644 --- a/src/plugins/diffeditor/diffeditor.qbs +++ b/src/plugins/diffeditor/diffeditor.qbs @@ -8,7 +8,6 @@ QtcPlugin { Depends { name: "Qt.widgets" } Depends { name: "Core" } Depends { name: "TextEditor" } - Depends { name: "Find" } files: [ diff --git a/src/plugins/fakevim/fakevim.qbs b/src/plugins/fakevim/fakevim.qbs index 4864bc0b501..5ac7938928e 100644 --- a/src/plugins/fakevim/fakevim.qbs +++ b/src/plugins/fakevim/fakevim.qbs @@ -7,7 +7,6 @@ QtcPlugin { Depends { name: "Core" } Depends { name: "TextEditor" } - Depends { name: "Find" } Depends { name: "Qt.widgets" } files: [ diff --git a/src/plugins/fakevim/fakevim_dependencies.pri b/src/plugins/fakevim/fakevim_dependencies.pri index abb8f31a74a..51a82fc372b 100644 --- a/src/plugins/fakevim/fakevim_dependencies.pri +++ b/src/plugins/fakevim/fakevim_dependencies.pri @@ -1,5 +1,4 @@ QTC_PLUGIN_NAME = FakeVim QTC_PLUGIN_DEPENDS += \ coreplugin \ - texteditor \ - find + texteditor diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index d0af40cd7dc..ed48448b385 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -42,6 +42,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -68,10 +71,6 @@ #include #include -#include -#include -#include - #include #include #include @@ -1401,20 +1400,20 @@ void FakeVimPluginPrivate::keepOnlyWindow() void FakeVimPluginPrivate::find(bool reverse) { - if (Find::FindPlugin *plugin = Find::FindPlugin::instance()) { + if (FindPlugin *plugin = FindPlugin::instance()) { plugin->setUseFakeVim(true); plugin->openFindToolBar(reverse - ? Find::FindPlugin::FindBackwardDirection - : Find::FindPlugin::FindForwardDirection); + ? FindPlugin::FindBackwardDirection + : FindPlugin::FindForwardDirection); } } void FakeVimPluginPrivate::findNext(bool reverse) { if (reverse) - triggerAction(Find::Constants::FIND_PREVIOUS); + triggerAction(Core::Constants::FIND_PREVIOUS); else - triggerAction(Find::Constants::FIND_NEXT); + triggerAction(Core::Constants::FIND_NEXT); } void FakeVimPluginPrivate::foldToggle(int depth) @@ -1686,8 +1685,8 @@ void FakeVimPluginPrivate::setUseFakeVim(const QVariant &value) { //qDebug() << "SET USE FAKEVIM" << value; bool on = value.toBool(); - if (Find::FindPlugin::instance()) - Find::FindPlugin::instance()->setUseFakeVim(on); + if (Core::FindPlugin::instance()) + Core::FindPlugin::instance()->setUseFakeVim(on); setUseFakeVimInternal(on); } @@ -1821,10 +1820,10 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd) showSettingsDialog(); } else if (cmd.args == _("ic") || cmd.args == _("ignorecase")) { // :set nc - setActionChecked(Find::Constants::CASE_SENSITIVE, false); + setActionChecked(Core::Constants::CASE_SENSITIVE, false); } else if (cmd.args == _("noic") || cmd.args == _("noignorecase")) { // :set noic - setActionChecked(Find::Constants::CASE_SENSITIVE, true); + setActionChecked(Core::Constants::CASE_SENSITIVE, true); } *handled = false; // Let the handler see it as well. } else if (cmd.matches(_("n"), _("next"))) { @@ -1990,9 +1989,9 @@ void FakeVimPluginPrivate::highlightMatches(const QString &needle) { foreach (IEditor *editor, EditorManager::visibleEditors()) { QWidget *w = editor->widget(); - Find::IFindSupport *find = Aggregation::query(w); + Core::IFindSupport *find = Aggregation::query(w); if (find != 0) - find->highlightAll(needle, Find::FindRegularExpression | Find::FindCaseSensitively); + find->highlightAll(needle, FindRegularExpression | FindCaseSensitively); } } diff --git a/src/plugins/find/Find.pluginspec.in b/src/plugins/find/Find.pluginspec.in index f670aa2f555..8af87eb2e56 100644 --- a/src/plugins/find/Find.pluginspec.in +++ b/src/plugins/find/Find.pluginspec.in @@ -1,4 +1,4 @@ - + Digia Plc (C) 2014 Digia Plc @@ -13,5 +13,4 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General Qt Creator Provides the find widget and the hooks for find implementations. http://www.qt-project.org - $$dependencyList diff --git a/src/plugins/find/basetextfind.cpp b/src/plugins/find/basetextfind.cpp deleted file mode 100644 index 7fa257cfa4b..00000000000 --- a/src/plugins/find/basetextfind.cpp +++ /dev/null @@ -1,427 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "basetextfind.h" - -#include -#include - -#include - -#include -#include -#include - -namespace Find { - -struct BaseTextFindPrivate -{ - explicit BaseTextFindPrivate(QPlainTextEdit *editor); - explicit BaseTextFindPrivate(QTextEdit *editor); - - QPointer m_editor; - QPointer m_plaineditor; - QPointer m_widget; - QTextCursor m_findScopeStart; - QTextCursor m_findScopeEnd; - int m_findScopeVerticalBlockSelectionFirstColumn; - int m_findScopeVerticalBlockSelectionLastColumn; - int m_incrementalStartPos; - bool m_incrementalWrappedState; -}; - -BaseTextFindPrivate::BaseTextFindPrivate(QTextEdit *editor) - : m_editor(editor) - , m_widget(editor) - , m_findScopeVerticalBlockSelectionFirstColumn(-1) - , m_findScopeVerticalBlockSelectionLastColumn(-1) - , m_incrementalStartPos(-1) - , m_incrementalWrappedState(false) -{ -} - -BaseTextFindPrivate::BaseTextFindPrivate(QPlainTextEdit *editor) - : m_plaineditor(editor) - , m_widget(editor) - , m_findScopeVerticalBlockSelectionFirstColumn(-1) - , m_findScopeVerticalBlockSelectionLastColumn(-1) - , m_incrementalStartPos(-1) - , m_incrementalWrappedState(false) -{ -} - -BaseTextFind::BaseTextFind(QTextEdit *editor) - : d(new BaseTextFindPrivate(editor)) -{ -} - - -BaseTextFind::BaseTextFind(QPlainTextEdit *editor) - : d(new BaseTextFindPrivate(editor)) -{ -} - -BaseTextFind::~BaseTextFind() -{ - delete d; -} - -QTextCursor BaseTextFind::textCursor() const -{ - QTC_ASSERT(d->m_editor || d->m_plaineditor, return QTextCursor()); - return d->m_editor ? d->m_editor->textCursor() : d->m_plaineditor->textCursor(); -} - -void BaseTextFind::setTextCursor(const QTextCursor &cursor) -{ - QTC_ASSERT(d->m_editor || d->m_plaineditor, return); - d->m_editor ? d->m_editor->setTextCursor(cursor) : d->m_plaineditor->setTextCursor(cursor); -} - -QTextDocument *BaseTextFind::document() const -{ - QTC_ASSERT(d->m_editor || d->m_plaineditor, return 0); - return d->m_editor ? d->m_editor->document() : d->m_plaineditor->document(); -} - -bool BaseTextFind::isReadOnly() const -{ - QTC_ASSERT(d->m_editor || d->m_plaineditor, return true); - return d->m_editor ? d->m_editor->isReadOnly() : d->m_plaineditor->isReadOnly(); -} - -bool BaseTextFind::supportsReplace() const -{ - return !isReadOnly(); -} - -FindFlags BaseTextFind::supportedFindFlags() const -{ - return FindBackward | FindCaseSensitively | FindRegularExpression - | FindWholeWords | FindPreserveCase; -} - -void BaseTextFind::resetIncrementalSearch() -{ - d->m_incrementalStartPos = -1; - d->m_incrementalWrappedState = false; -} - -void BaseTextFind::clearResults() -{ - emit highlightAll(QString(), 0); -} - -QString BaseTextFind::currentFindString() const -{ - QTextCursor cursor = textCursor(); - if (cursor.hasSelection() && cursor.block() != cursor.document()->findBlock(cursor.anchor())) - return QString(); // multi block selection - - if (cursor.hasSelection()) - return cursor.selectedText(); - - if (!cursor.atBlockEnd() && !cursor.hasSelection()) { - cursor.movePosition(QTextCursor::StartOfWord); - cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); - QString s = cursor.selectedText(); - foreach (QChar c, s) { - if (!c.isLetterOrNumber() && c != QLatin1Char('_')) { - s.clear(); - break; - } - } - return s; - } - - return QString(); -} - -QString BaseTextFind::completedFindString() const -{ - QTextCursor cursor = textCursor(); - cursor.setPosition(textCursor().selectionStart()); - cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); - return cursor.selectedText(); -} - -IFindSupport::Result BaseTextFind::findIncremental(const QString &txt, FindFlags findFlags) -{ - QTextCursor cursor = textCursor(); - if (d->m_incrementalStartPos < 0) - d->m_incrementalStartPos = cursor.selectionStart(); - cursor.setPosition(d->m_incrementalStartPos); - bool wrapped = false; - bool found = find(txt, findFlags, cursor, &wrapped); - if (wrapped != d->m_incrementalWrappedState && found) { - d->m_incrementalWrappedState = wrapped; - showWrapIndicator(d->m_widget); - } - if (found) - emit highlightAll(txt, findFlags); - else - emit highlightAll(QString(), 0); - return found ? Found : NotFound; -} - -IFindSupport::Result BaseTextFind::findStep(const QString &txt, FindFlags findFlags) -{ - bool wrapped = false; - bool found = find(txt, findFlags, textCursor(), &wrapped); - if (wrapped) - showWrapIndicator(d->m_widget); - if (found) { - d->m_incrementalStartPos = textCursor().selectionStart(); - d->m_incrementalWrappedState = false; - } - return found ? Found : NotFound; -} - -void BaseTextFind::replace(const QString &before, const QString &after, FindFlags findFlags) -{ - QTextCursor cursor = replaceInternal(before, after, findFlags); - setTextCursor(cursor); -} - -QTextCursor BaseTextFind::replaceInternal(const QString &before, const QString &after, - FindFlags findFlags) -{ - QTextCursor cursor = textCursor(); - bool usesRegExp = (findFlags & FindRegularExpression); - bool preserveCase = (findFlags & FindPreserveCase); - QRegExp regexp(before, - (findFlags & FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive, - usesRegExp ? QRegExp::RegExp : QRegExp::FixedString); - - if (regexp.exactMatch(cursor.selectedText())) { - QString realAfter; - if (usesRegExp) - realAfter = Utils::expandRegExpReplacement(after, regexp.capturedTexts()); - else if (preserveCase) - realAfter = Utils::matchCaseReplacement(cursor.selectedText(), after); - else - realAfter = after; - int start = cursor.selectionStart(); - cursor.insertText(realAfter); - if ((findFlags & FindBackward) != 0) - cursor.setPosition(start); - } - return cursor; -} - -bool BaseTextFind::replaceStep(const QString &before, const QString &after, FindFlags findFlags) -{ - QTextCursor cursor = replaceInternal(before, after, findFlags); - bool wrapped = false; - bool found = find(before, findFlags, cursor, &wrapped); - if (wrapped) - showWrapIndicator(d->m_widget); - return found; -} - -int BaseTextFind::replaceAll(const QString &before, const QString &after, FindFlags findFlags) -{ - QTextCursor editCursor = textCursor(); - if (!d->m_findScopeStart.isNull()) - editCursor.setPosition(d->m_findScopeStart.position()); - else - editCursor.movePosition(QTextCursor::Start); - editCursor.beginEditBlock(); - int count = 0; - bool usesRegExp = (findFlags & FindRegularExpression); - bool preserveCase = (findFlags & FindPreserveCase); - QRegExp regexp(before); - regexp.setPatternSyntax(usesRegExp ? QRegExp::RegExp : QRegExp::FixedString); - regexp.setCaseSensitivity((findFlags & FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive); - QTextCursor found = findOne(regexp, editCursor, textDocumentFlagsForFindFlags(findFlags)); - bool first = true; - while (!found.isNull() && inScope(found.selectionStart(), found.selectionEnd())) { - if (found == editCursor && !first) { - if (editCursor.atEnd()) - break; - // If the newly found QTextCursor is the same as recently edit one we have to move on, - // otherwise we would run into an endless loop for some regular expressions - // like ^ or \b. - QTextCursor newPosCursor = editCursor; - newPosCursor.movePosition(findFlags & FindBackward ? - QTextCursor::PreviousCharacter : - QTextCursor::NextCharacter); - found = findOne(regexp, newPosCursor, textDocumentFlagsForFindFlags(findFlags)); - continue; - } - if (first) - first = false; - ++count; - editCursor.setPosition(found.selectionStart()); - editCursor.setPosition(found.selectionEnd(), QTextCursor::KeepAnchor); - regexp.exactMatch(found.selectedText()); - - QString realAfter; - if (usesRegExp) - realAfter = Utils::expandRegExpReplacement(after, regexp.capturedTexts()); - else if (preserveCase) - realAfter = Utils::matchCaseReplacement(found.selectedText(), after); - else - realAfter = after; - editCursor.insertText(realAfter); - found = findOne(regexp, editCursor, textDocumentFlagsForFindFlags(findFlags)); - } - editCursor.endEditBlock(); - return count; -} - -bool BaseTextFind::find(const QString &txt, FindFlags findFlags, - QTextCursor start, bool *wrapped) -{ - if (txt.isEmpty()) { - setTextCursor(start); - return true; - } - QRegExp regexp(txt); - regexp.setPatternSyntax((findFlags & FindRegularExpression) ? QRegExp::RegExp : QRegExp::FixedString); - regexp.setCaseSensitivity((findFlags & FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive); - QTextCursor found = findOne(regexp, start, textDocumentFlagsForFindFlags(findFlags)); - if (wrapped) - *wrapped = false; - - if (!d->m_findScopeStart.isNull()) { - - // scoped - if (found.isNull() || !inScope(found.selectionStart(), found.selectionEnd())) { - if ((findFlags & FindBackward) == 0) - start.setPosition(d->m_findScopeStart.position()); - else - start.setPosition(d->m_findScopeEnd.position()); - found = findOne(regexp, start, textDocumentFlagsForFindFlags(findFlags)); - if (found.isNull() || !inScope(found.selectionStart(), found.selectionEnd())) - return false; - if (wrapped) - *wrapped = true; - } - } else { - - // entire document - if (found.isNull()) { - if ((findFlags & FindBackward) == 0) - start.movePosition(QTextCursor::Start); - else - start.movePosition(QTextCursor::End); - found = findOne(regexp, start, textDocumentFlagsForFindFlags(findFlags)); - if (found.isNull()) - return false; - if (wrapped) - *wrapped = true; - } - } - if (!found.isNull()) - setTextCursor(found); - return true; -} - - -// helper function. Works just like QTextDocument::find() but supports vertical block selection -QTextCursor BaseTextFind::findOne(const QRegExp &expr, const QTextCursor &from, QTextDocument::FindFlags options) const -{ - QTextCursor candidate = document()->find(expr, from, options); - if (candidate.isNull()) - return candidate; - - if (d->m_findScopeVerticalBlockSelectionFirstColumn < 0) - return candidate; - forever { - if (!inScope(candidate.selectionStart(), candidate.selectionEnd())) - return candidate; - bool inVerticalFindScope = false; - QMetaObject::invokeMethod(d->m_plaineditor, "inFindScope", Qt::DirectConnection, - Q_RETURN_ARG(bool, inVerticalFindScope), - Q_ARG(QTextCursor, candidate)); - if (inVerticalFindScope) - return candidate; - - QTextCursor newCandidate = document()->find(expr, candidate, options); - if (newCandidate == candidate) { - // When searching for regular expressions that match "zero length" strings (like ^ or \b) - // we need to move away from the match before searching for the next one. - candidate.movePosition(options & QTextDocument::FindBackward - ? QTextCursor::PreviousCharacter - : QTextCursor::NextCharacter); - candidate = document()->find(expr, candidate, options); - } else { - candidate = newCandidate; - } - } - return candidate; -} - -bool BaseTextFind::inScope(int startPosition, int endPosition) const -{ - if (d->m_findScopeStart.isNull()) - return true; - return (d->m_findScopeStart.position() <= startPosition - && d->m_findScopeEnd.position() >= endPosition); -} - -void BaseTextFind::defineFindScope() -{ - QTextCursor cursor = textCursor(); - if (cursor.hasSelection() && cursor.block() != cursor.document()->findBlock(cursor.anchor())) { - d->m_findScopeStart = QTextCursor(document()->docHandle(), qMax(0, cursor.selectionStart())); - d->m_findScopeEnd = QTextCursor(document()->docHandle(), cursor.selectionEnd()); - d->m_findScopeVerticalBlockSelectionFirstColumn = -1; - d->m_findScopeVerticalBlockSelectionLastColumn = -1; - - if (d->m_plaineditor && d->m_plaineditor->metaObject()->indexOfProperty("verticalBlockSelectionFirstColumn") >= 0) { - d->m_findScopeVerticalBlockSelectionFirstColumn - = d->m_plaineditor->property("verticalBlockSelectionFirstColumn").toInt(); - d->m_findScopeVerticalBlockSelectionLastColumn - = d->m_plaineditor->property("verticalBlockSelectionLastColumn").toInt(); - } - - emit findScopeChanged(d->m_findScopeStart, d->m_findScopeEnd, - d->m_findScopeVerticalBlockSelectionFirstColumn, - d->m_findScopeVerticalBlockSelectionLastColumn); - cursor.setPosition(d->m_findScopeStart.position()); - setTextCursor(cursor); - } else { - clearFindScope(); - } -} - -void BaseTextFind::clearFindScope() -{ - d->m_findScopeStart = QTextCursor(); - d->m_findScopeEnd = QTextCursor(); - d->m_findScopeVerticalBlockSelectionFirstColumn = -1; - d->m_findScopeVerticalBlockSelectionLastColumn = -1; - emit findScopeChanged(d->m_findScopeStart, d->m_findScopeEnd, - d->m_findScopeVerticalBlockSelectionFirstColumn, - d->m_findScopeVerticalBlockSelectionLastColumn); -} - -} // namespace Find diff --git a/src/plugins/find/basetextfind.h b/src/plugins/find/basetextfind.h deleted file mode 100644 index b5769223020..00000000000 --- a/src/plugins/find/basetextfind.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef BASETEXTFIND_H -#define BASETEXTFIND_H - -#include "find_global.h" -#include "ifindsupport.h" - -QT_BEGIN_NAMESPACE -class QPlainTextEdit; -class QTextEdit; -class QTextCursor; -QT_END_NAMESPACE - -namespace Find { -struct BaseTextFindPrivate; - -class FIND_EXPORT BaseTextFind : public IFindSupport -{ - Q_OBJECT - -public: - explicit BaseTextFind(QPlainTextEdit *editor); - explicit BaseTextFind(QTextEdit *editor); - virtual ~BaseTextFind(); - - bool supportsReplace() const; - FindFlags supportedFindFlags() const; - void resetIncrementalSearch(); - void clearResults(); - QString currentFindString() const; - QString completedFindString() const; - - Result findIncremental(const QString &txt, FindFlags findFlags); - Result findStep(const QString &txt, FindFlags findFlags); - void replace(const QString &before, const QString &after, FindFlags findFlags); - bool replaceStep(const QString &before, const QString &after, FindFlags findFlags); - int replaceAll(const QString &before, const QString &after, FindFlags findFlags); - - void defineFindScope(); - void clearFindScope(); - -signals: - void highlightAll(const QString &txt, Find::FindFlags findFlags); - void findScopeChanged(const QTextCursor &start, const QTextCursor &end, - int verticalBlockSelectionFirstColumn, - int verticalBlockSelectionLastColumn); - -private: - bool find(const QString &txt, FindFlags findFlags, QTextCursor start, bool *wrapped); - QTextCursor replaceInternal(const QString &before, const QString &after, FindFlags findFlags); - - QTextCursor textCursor() const; - void setTextCursor(const QTextCursor&); - QTextDocument *document() const; - bool isReadOnly() const; - bool inScope(int startPosition, int endPosition) const; - QTextCursor findOne(const QRegExp &expr, const QTextCursor &from, QTextDocument::FindFlags options) const; - - BaseTextFindPrivate *d; -}; - -} // namespace Find - -#endif // BASETEXTFIND_H diff --git a/src/plugins/find/currentdocumentfind.cpp b/src/plugins/find/currentdocumentfind.cpp deleted file mode 100644 index 48723e15351..00000000000 --- a/src/plugins/find/currentdocumentfind.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "currentdocumentfind.h" - -#include -#include -#include - -#include -#include -#include - -using namespace Core; -using namespace Find; -using namespace Find::Internal; - -CurrentDocumentFind::CurrentDocumentFind() - : m_currentFind(0) -{ - connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), - this, SLOT(updateCandidateFindFilter(QWidget*,QWidget*))); -} - -void CurrentDocumentFind::removeConnections() -{ - disconnect(qApp, 0, this, 0); - removeFindSupportConnections(); -} - -void CurrentDocumentFind::resetIncrementalSearch() -{ - QTC_ASSERT(m_currentFind, return); - m_currentFind->resetIncrementalSearch(); -} - -void CurrentDocumentFind::clearResults() -{ - QTC_ASSERT(m_currentFind, return); - m_currentFind->clearResults(); -} - -bool CurrentDocumentFind::isEnabled() const -{ - return m_currentFind && (!m_currentWidget || m_currentWidget->isVisible()); -} - -bool CurrentDocumentFind::candidateIsEnabled() const -{ - return (m_candidateFind != 0); -} - -bool CurrentDocumentFind::supportsReplace() const -{ - QTC_ASSERT(m_currentFind, return false); - return m_currentFind->supportsReplace(); -} - -FindFlags CurrentDocumentFind::supportedFindFlags() const -{ - QTC_ASSERT(m_currentFind, return 0); - return m_currentFind->supportedFindFlags(); -} - -QString CurrentDocumentFind::currentFindString() const -{ - QTC_ASSERT(m_currentFind, return QString()); - return m_currentFind->currentFindString(); -} - -QString CurrentDocumentFind::completedFindString() const -{ - QTC_ASSERT(m_currentFind, return QString()); - return m_currentFind->completedFindString(); -} - -void CurrentDocumentFind::highlightAll(const QString &txt, FindFlags findFlags) -{ - QTC_ASSERT(m_currentFind, return); - m_currentFind->highlightAll(txt, findFlags); -} - -IFindSupport::Result CurrentDocumentFind::findIncremental(const QString &txt, FindFlags findFlags) -{ - QTC_ASSERT(m_currentFind, return IFindSupport::NotFound); - return m_currentFind->findIncremental(txt, findFlags); -} - -IFindSupport::Result CurrentDocumentFind::findStep(const QString &txt, FindFlags findFlags) -{ - QTC_ASSERT(m_currentFind, return IFindSupport::NotFound); - return m_currentFind->findStep(txt, findFlags); -} - -void CurrentDocumentFind::replace(const QString &before, const QString &after, FindFlags findFlags) -{ - QTC_ASSERT(m_currentFind, return); - m_currentFind->replace(before, after, findFlags); -} - -bool CurrentDocumentFind::replaceStep(const QString &before, const QString &after, FindFlags findFlags) -{ - QTC_ASSERT(m_currentFind, return false); - return m_currentFind->replaceStep(before, after, findFlags); -} - -int CurrentDocumentFind::replaceAll(const QString &before, const QString &after, FindFlags findFlags) -{ - QTC_ASSERT(m_currentFind, return 0); - return m_currentFind->replaceAll(before, after, findFlags); -} - -void CurrentDocumentFind::defineFindScope() -{ - QTC_ASSERT(m_currentFind, return); - m_currentFind->defineFindScope(); -} - -void CurrentDocumentFind::clearFindScope() -{ - QTC_ASSERT(m_currentFind, return); - m_currentFind->clearFindScope(); -} - -void CurrentDocumentFind::updateCandidateFindFilter(QWidget *old, QWidget *now) -{ - Q_UNUSED(old) - QWidget *candidate = now; - QPointer impl = 0; - while (!impl && candidate) { - impl = Aggregation::query(candidate); - if (!impl) - candidate = candidate->parentWidget(); - } - if (m_candidateWidget) - disconnect(Aggregation::Aggregate::parentAggregate(m_candidateWidget), SIGNAL(changed()), - this, SLOT(candidateAggregationChanged())); - m_candidateWidget = candidate; - m_candidateFind = impl; - if (m_candidateWidget) - connect(Aggregation::Aggregate::parentAggregate(m_candidateWidget), SIGNAL(changed()), - this, SLOT(candidateAggregationChanged())); - emit candidateChanged(); -} - -void CurrentDocumentFind::acceptCandidate() -{ - if (!m_candidateFind || m_candidateFind == m_currentFind) - return; - removeFindSupportConnections(); - if (m_currentFind) - m_currentFind->clearResults(); - - if (m_currentWidget) - disconnect(Aggregation::Aggregate::parentAggregate(m_currentWidget), SIGNAL(changed()), - this, SLOT(aggregationChanged())); - m_currentWidget = m_candidateWidget; - connect(Aggregation::Aggregate::parentAggregate(m_currentWidget), SIGNAL(changed()), - this, SLOT(aggregationChanged())); - - m_currentFind = m_candidateFind; - if (m_currentFind) { - connect(m_currentFind, SIGNAL(changed()), this, SIGNAL(changed())); - connect(m_currentFind, SIGNAL(destroyed(QObject*)), SLOT(clearFindSupport())); - } - if (m_currentWidget) - m_currentWidget->installEventFilter(this); - emit changed(); -} - -void CurrentDocumentFind::removeFindSupportConnections() -{ - if (m_currentFind) { - disconnect(m_currentFind, SIGNAL(changed()), this, SIGNAL(changed())); - disconnect(m_currentFind, SIGNAL(destroyed(QObject*)), this, SLOT(clearFindSupport())); - } - if (m_currentWidget) - m_currentWidget->removeEventFilter(this); -} - -void CurrentDocumentFind::clearFindSupport() -{ - removeFindSupportConnections(); - m_currentWidget = 0; - m_currentFind = 0; - emit changed(); -} - -bool CurrentDocumentFind::setFocusToCurrentFindSupport() -{ - if (m_currentFind && m_currentWidget) { - QWidget *w = m_currentWidget->focusWidget(); - if (!w) - w = m_currentWidget; - w->setFocus(); - return true; - } - return false; -} - -bool CurrentDocumentFind::eventFilter(QObject *obj, QEvent *event) -{ - if (m_currentWidget && obj == m_currentWidget) { - if (event->type() == QEvent::Hide || event->type() == QEvent::Show) - emit changed(); - } - return QObject::eventFilter(obj, event); -} - -void CurrentDocumentFind::aggregationChanged() -{ - if (m_currentWidget) { - QPointer currentFind = Aggregation::query(m_currentWidget); - if (currentFind != m_currentFind) { - // There's a change in the find support - if (currentFind) { - m_candidateWidget = m_currentWidget; - m_candidateFind = currentFind; - acceptCandidate(); - } else { - clearFindSupport(); - } - } - } -} - -void CurrentDocumentFind::candidateAggregationChanged() -{ - if (m_candidateWidget && m_candidateWidget != m_currentWidget) { - m_candidateFind = Aggregation::query(m_candidateWidget); - emit candidateChanged(); - } -} diff --git a/src/plugins/find/currentdocumentfind.h b/src/plugins/find/currentdocumentfind.h deleted file mode 100644 index 2c79ab36aef..00000000000 --- a/src/plugins/find/currentdocumentfind.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef CURRENTDOCUMENTFIND_H -#define CURRENTDOCUMENTFIND_H - -#include "ifindsupport.h" - -#include - -namespace Find { -namespace Internal { - -class CurrentDocumentFind : public QObject -{ - Q_OBJECT - -public: - CurrentDocumentFind(); - - void resetIncrementalSearch(); - void clearResults(); - bool supportsReplace() const; - FindFlags supportedFindFlags() const; - QString currentFindString() const; - QString completedFindString() const; - - bool isEnabled() const; - bool candidateIsEnabled() const; - void highlightAll(const QString &txt, FindFlags findFlags); - IFindSupport::Result findIncremental(const QString &txt, FindFlags findFlags); - IFindSupport::Result findStep(const QString &txt, FindFlags findFlags); - void replace(const QString &before, const QString &after, FindFlags findFlags); - bool replaceStep(const QString &before, const QString &after, FindFlags findFlags); - int replaceAll(const QString &before, const QString &after, FindFlags findFlags); - void defineFindScope(); - void clearFindScope(); - void acceptCandidate(); - - void removeConnections(); - bool setFocusToCurrentFindSupport(); - - bool eventFilter(QObject *obj, QEvent *event); - -signals: - void changed(); - void candidateChanged(); - -private slots: - void updateCandidateFindFilter(QWidget *old, QWidget *now); - void clearFindSupport(); - void aggregationChanged(); - void candidateAggregationChanged(); - -private: - void removeFindSupportConnections(); - - QPointer m_currentFind; - QPointer m_currentWidget; - QPointer m_candidateFind; - QPointer m_candidateWidget; -}; - -} // namespace Internal -} // namespace Find - -#endif // CURRENTDOCUMENTFIND_H diff --git a/src/plugins/find/find.pro b/src/plugins/find/find.pro index 8666b26bdea..a7d911be0d5 100644 --- a/src/plugins/find/find.pro +++ b/src/plugins/find/find.pro @@ -1,38 +1,3 @@ include(../../qtcreatorplugin.pri) DEFINES += FIND_LIBRARY -HEADERS += findtoolwindow.h \ - textfindconstants.h \ - ifindsupport.h \ - ifindfilter.h \ - currentdocumentfind.h \ - basetextfind.h \ - find_global.h \ - findtoolbar.h \ - findplugin.h \ - searchresultcolor.h \ - searchresulttreeitemdelegate.h \ - searchresulttreeitemroles.h \ - searchresulttreeitems.h \ - searchresulttreemodel.h \ - searchresulttreeview.h \ - searchresultwindow.h \ - searchresultwidget.h \ - treeviewfind.h -SOURCES += findtoolwindow.cpp \ - currentdocumentfind.cpp \ - basetextfind.cpp \ - findtoolbar.cpp \ - findplugin.cpp \ - searchresulttreeitemdelegate.cpp \ - searchresulttreeitems.cpp \ - searchresulttreemodel.cpp \ - searchresulttreeview.cpp \ - searchresultwindow.cpp \ - ifindfilter.cpp \ - ifindsupport.cpp \ - searchresultwidget.cpp \ - treeviewfind.cpp -FORMS += findwidget.ui \ - finddialog.ui -RESOURCES += find.qrc - +SOURCES += findplugin.cpp diff --git a/src/plugins/find/find.qbs b/src/plugins/find/find.qbs index 0b4a08986bc..e0acdc006f2 100644 --- a/src/plugins/find/find.qbs +++ b/src/plugins/find/find.qbs @@ -5,44 +5,7 @@ import QtcPlugin QtcPlugin { name: "Find" - Depends { name: "Qt"; submodules: ["widgets", "xml", "network", "script"] } Depends { name: "Core" } - files: [ - "basetextfind.cpp", - "basetextfind.h", - "currentdocumentfind.cpp", - "currentdocumentfind.h", - "find.qrc", - "find_global.h", - "finddialog.ui", - "findplugin.cpp", - "findplugin.h", - "findtoolbar.cpp", - "findtoolbar.h", - "findtoolwindow.cpp", - "findtoolwindow.h", - "findwidget.ui", - "ifindfilter.cpp", - "ifindfilter.h", - "ifindsupport.cpp", - "ifindsupport.h", - "searchresultcolor.h", - "searchresulttreeitemdelegate.cpp", - "searchresulttreeitemdelegate.h", - "searchresulttreeitemroles.h", - "searchresulttreeitems.cpp", - "searchresulttreeitems.h", - "searchresulttreemodel.cpp", - "searchresulttreemodel.h", - "searchresulttreeview.cpp", - "searchresulttreeview.h", - "searchresultwidget.cpp", - "searchresultwidget.h", - "searchresultwindow.cpp", - "searchresultwindow.h", - "textfindconstants.h", - "treeviewfind.cpp", - "treeviewfind.h", - ] + files: [ "findplugin.cpp" ] } diff --git a/src/plugins/find/find.qrc b/src/plugins/find/find.qrc deleted file mode 100644 index 0c4e1281012..00000000000 --- a/src/plugins/find/find.qrc +++ /dev/null @@ -1,10 +0,0 @@ - - - images/casesensitively.png - images/wholewords.png - images/regexp.png - images/expand.png - images/wrapindicator.png - images/preservecase.png - - diff --git a/src/plugins/find/find_dependencies.pri b/src/plugins/find/find_dependencies.pri index 52291a8aab4..39a0b86f75e 100644 --- a/src/plugins/find/find_dependencies.pri +++ b/src/plugins/find/find_dependencies.pri @@ -1,5 +1,3 @@ QTC_PLUGIN_NAME = Find -QTC_LIB_DEPENDS += \ - utils -QTC_PLUGIN_DEPENDS += \ - coreplugin +QTC_LIB_DEPENDS += +QTC_PLUGIN_DEPENDS += diff --git a/src/plugins/find/find_global.h b/src/plugins/find/find_global.h deleted file mode 100644 index 68d06d5145b..00000000000 --- a/src/plugins/find/find_global.h +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ -#ifndef FIND_GLOBAL_H -#define FIND_GLOBAL_H - -#include - -#if defined(FIND_LIBRARY) -# define FIND_EXPORT Q_DECL_EXPORT -#else -# define FIND_EXPORT Q_DECL_IMPORT -#endif - -#endif // FIND_GLOBAL_H diff --git a/src/plugins/find/finddialog.ui b/src/plugins/find/finddialog.ui deleted file mode 100644 index c7eddf9dadc..00000000000 --- a/src/plugins/find/finddialog.ui +++ /dev/null @@ -1,209 +0,0 @@ - - - Find::Internal::FindDialog - - - - 0 - 0 - 673 - 240 - - - - - 680 - 16777215 - - - - - QLayout::SetFixedSize - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - &Search - - - true - - - - - - - Search && &Replace - - - - - - - - - Sear&ch for: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - searchTerm - - - - - - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 0 - - - - - Case sensiti&ve - - - - - - - Whole words o&nly - - - - - - - Use re&gular expressions - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 0 - 0 - - - - - 80 - 0 - - - - Sco&pe: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - filterList - - - - - - - - - - - 0 - 10 - - - - - - - - - Utils::FancyLineEdit - QLineEdit -
utils/fancylineedit.h
-
- - Utils::FilterLineEdit - Utils::FancyLineEdit -
utils/filterlineedit.h
-
-
- - filterList - searchTerm - matchCase - wholeWords - regExp - - - -
diff --git a/src/plugins/find/findplugin.cpp b/src/plugins/find/findplugin.cpp index be9196e209d..a4428b657fd 100644 --- a/src/plugins/find/findplugin.cpp +++ b/src/plugins/find/findplugin.cpp @@ -1,398 +1,2 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ -#include "findplugin.h" - -#include "currentdocumentfind.h" -#include "findtoolbar.h" -#include "findtoolwindow.h" -#include "searchresultwindow.h" -#include "ifindfilter.h" - -#include -#include -#include -#include -#include - -#include - -#include - -#include -#include -#include - -#include -#include - -/*! - \namespace Find - The Find namespace provides everything that has to do with search term based searches. -*/ - -/*! - \namespace Find::Internal - \internal -*/ -/*! - \namespace Find::Internal::ItemDataRoles - \internal -*/ - -Q_DECLARE_METATYPE(Find::IFindFilter*) - -namespace { - const int MAX_COMPLETIONS = 50; -} - -namespace Find { - -class FindPluginPrivate { -public: - explicit FindPluginPrivate(FindPlugin *q); - - //variables - static FindPlugin *m_instance; - - QHash m_filterActions; - - Internal::CurrentDocumentFind *m_currentDocumentFind; - Internal::FindToolBar *m_findToolBar; - Internal::FindToolWindow *m_findDialog; - FindFlags m_findFlags; - QStringListModel *m_findCompletionModel; - QStringListModel *m_replaceCompletionModel; - QStringList m_findCompletions; - QStringList m_replaceCompletions; - QAction *m_openFindDialog; -}; - -FindPluginPrivate::FindPluginPrivate(FindPlugin *q) : - m_currentDocumentFind(0), m_findToolBar(0), m_findDialog(0), - m_findCompletionModel(new QStringListModel(q)), - m_replaceCompletionModel(new QStringListModel(q)) -{ -} - -FindPlugin *FindPluginPrivate::m_instance = 0; - -FindPlugin::FindPlugin() : d(new FindPluginPrivate(this)) -{ - QTC_ASSERT(!FindPluginPrivate::m_instance, return); - FindPluginPrivate::m_instance = this; -} - -FindPlugin::~FindPlugin() -{ - FindPluginPrivate::m_instance = 0; - delete d->m_currentDocumentFind; - delete d->m_findToolBar; - delete d->m_findDialog; - delete d; -} - -FindPlugin *FindPlugin::instance() -{ - return FindPluginPrivate::m_instance; -} - -bool FindPlugin::initialize(const QStringList &, QString *) -{ - setupMenu(); - - d->m_currentDocumentFind = new Internal::CurrentDocumentFind; - - d->m_findToolBar = new Internal::FindToolBar(this, d->m_currentDocumentFind); - d->m_findDialog = new Internal::FindToolWindow(this); - SearchResultWindow *searchResultWindow = new SearchResultWindow(d->m_findDialog); - addAutoReleasedObject(searchResultWindow); - return true; -} - -void FindPlugin::extensionsInitialized() -{ - setupFilterMenuItems(); - readSettings(); -} - -ExtensionSystem::IPlugin::ShutdownFlag FindPlugin::aboutToShutdown() -{ - d->m_findToolBar->setVisible(false); - d->m_findToolBar->setParent(0); - d->m_currentDocumentFind->removeConnections(); - writeSettings(); - return SynchronousShutdown; -} - -void FindPlugin::filterChanged() -{ - IFindFilter *changedFilter = qobject_cast(sender()); - QAction *action = d->m_filterActions.value(changedFilter); - QTC_ASSERT(changedFilter, return); - QTC_ASSERT(action, return); - action->setEnabled(changedFilter->isEnabled()); - bool haveEnabledFilters = false; - foreach (const IFindFilter *filter, d->m_filterActions.keys()) { - if (filter->isEnabled()) { - haveEnabledFilters = true; - break; - } - } - d->m_openFindDialog->setEnabled(haveEnabledFilters); -} - -void FindPlugin::openFindFilter() -{ - QAction *action = qobject_cast(sender()); - QTC_ASSERT(action, return); - IFindFilter *filter = action->data().value(); - openFindDialog(filter); -} - -void FindPlugin::openFindDialog(IFindFilter *filter) -{ - if (d->m_currentDocumentFind->candidateIsEnabled()) - d->m_currentDocumentFind->acceptCandidate(); - const QString currentFindString = - d->m_currentDocumentFind->isEnabled() ? - d->m_currentDocumentFind->currentFindString() : QString(); - if (!currentFindString.isEmpty()) - d->m_findDialog->setFindText(currentFindString); - d->m_findDialog->setCurrentFilter(filter); - SearchResultWindow::instance()->openNewSearchPanel(); -} - -void FindPlugin::setupMenu() -{ - Core::ActionContainer *medit = Core::ActionManager::actionContainer(Core::Constants::M_EDIT); - Core::ActionContainer *mfind = Core::ActionManager::createMenu(Constants::M_FIND); - medit->addMenu(mfind, Core::Constants::G_EDIT_FIND); - mfind->menu()->setTitle(tr("&Find/Replace")); - mfind->appendGroup(Constants::G_FIND_CURRENTDOCUMENT); - mfind->appendGroup(Constants::G_FIND_FILTERS); - mfind->appendGroup(Constants::G_FIND_FLAGS); - mfind->appendGroup(Constants::G_FIND_ACTIONS); - Core::Context globalcontext(Core::Constants::C_GLOBAL); - Core::Command *cmd; - mfind->addSeparator(globalcontext, Constants::G_FIND_FLAGS); - mfind->addSeparator(globalcontext, Constants::G_FIND_ACTIONS); - - Core::ActionContainer *mfindadvanced = Core::ActionManager::createMenu(Constants::M_FIND_ADVANCED); - mfindadvanced->menu()->setTitle(tr("Advanced Find")); - mfind->addMenu(mfindadvanced, Constants::G_FIND_FILTERS); - d->m_openFindDialog = new QAction(tr("Open Advanced Find..."), this); - d->m_openFindDialog->setIconText(tr("Advanced...")); - cmd = Core::ActionManager::registerAction(d->m_openFindDialog, Constants::ADVANCED_FIND, globalcontext); - cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F"))); - mfindadvanced->addAction(cmd); - connect(d->m_openFindDialog, SIGNAL(triggered()), this, SLOT(openFindFilter())); -} - -void FindPlugin::setupFilterMenuItems() -{ - QList findInterfaces = - ExtensionSystem::PluginManager::getObjects(); - Core::Command *cmd; - Core::Context globalcontext(Core::Constants::C_GLOBAL); - - Core::ActionContainer *mfindadvanced = Core::ActionManager::actionContainer(Constants::M_FIND_ADVANCED); - d->m_filterActions.clear(); - bool haveEnabledFilters = false; - const Core::Id base("FindFilter."); - foreach (IFindFilter *filter, findInterfaces) { - QAction *action = new QAction(QLatin1String(" ") + filter->displayName(), this); - bool isEnabled = filter->isEnabled(); - if (isEnabled) - haveEnabledFilters = true; - action->setEnabled(isEnabled); - action->setData(qVariantFromValue(filter)); - cmd = Core::ActionManager::registerAction(action, - base.withSuffix(filter->id()), globalcontext); - cmd->setDefaultKeySequence(filter->defaultShortcut()); - mfindadvanced->addAction(cmd); - d->m_filterActions.insert(filter, action); - connect(action, SIGNAL(triggered(bool)), this, SLOT(openFindFilter())); - connect(filter, SIGNAL(enabledChanged(bool)), this, SLOT(filterChanged())); - } - d->m_findDialog->setFindFilters(findInterfaces); - d->m_openFindDialog->setEnabled(haveEnabledFilters); -} - -FindFlags FindPlugin::findFlags() const -{ - return d->m_findFlags; -} - -void FindPlugin::setCaseSensitive(bool sensitive) -{ - setFindFlag(FindCaseSensitively, sensitive); -} - -void FindPlugin::setWholeWord(bool wholeOnly) -{ - setFindFlag(FindWholeWords, wholeOnly); -} - -void FindPlugin::setBackward(bool backward) -{ - setFindFlag(FindBackward, backward); -} - -void FindPlugin::setRegularExpression(bool regExp) -{ - setFindFlag(FindRegularExpression, regExp); -} - -void FindPlugin::setPreserveCase(bool preserveCase) -{ - setFindFlag(FindPreserveCase, preserveCase); -} - -void FindPlugin::setFindFlag(FindFlag flag, bool enabled) -{ - bool hasFlag = hasFindFlag(flag); - if ((hasFlag && enabled) || (!hasFlag && !enabled)) - return; - if (enabled) - d->m_findFlags |= flag; - else - d->m_findFlags &= ~flag; - if (flag != FindBackward) - emit findFlagsChanged(); -} - -bool FindPlugin::hasFindFlag(FindFlag flag) -{ - return d->m_findFlags & flag; -} - -void FindPlugin::writeSettings() -{ - QSettings *settings = Core::ICore::settings(); - settings->beginGroup(QLatin1String("Find")); - settings->setValue(QLatin1String("Backward"), hasFindFlag(FindBackward)); - settings->setValue(QLatin1String("CaseSensitively"), hasFindFlag(FindCaseSensitively)); - settings->setValue(QLatin1String("WholeWords"), hasFindFlag(FindWholeWords)); - settings->setValue(QLatin1String("RegularExpression"), hasFindFlag(FindRegularExpression)); - settings->setValue(QLatin1String("PreserveCase"), hasFindFlag(FindPreserveCase)); - settings->setValue(QLatin1String("FindStrings"), d->m_findCompletions); - settings->setValue(QLatin1String("ReplaceStrings"), d->m_replaceCompletions); - settings->endGroup(); - d->m_findToolBar->writeSettings(); - d->m_findDialog->writeSettings(); -} - -void FindPlugin::readSettings() -{ - QSettings *settings = Core::ICore::settings(); - settings->beginGroup(QLatin1String("Find")); - bool block = blockSignals(true); - setBackward(settings->value(QLatin1String("Backward"), false).toBool()); - setCaseSensitive(settings->value(QLatin1String("CaseSensitively"), false).toBool()); - setWholeWord(settings->value(QLatin1String("WholeWords"), false).toBool()); - setRegularExpression(settings->value(QLatin1String("RegularExpression"), false).toBool()); - setPreserveCase(settings->value(QLatin1String("PreserveCase"), false).toBool()); - blockSignals(block); - d->m_findCompletions = settings->value(QLatin1String("FindStrings")).toStringList(); - d->m_replaceCompletions = settings->value(QLatin1String("ReplaceStrings")).toStringList(); - d->m_findCompletionModel->setStringList(d->m_findCompletions); - d->m_replaceCompletionModel->setStringList(d->m_replaceCompletions); - settings->endGroup(); - d->m_findToolBar->readSettings(); - d->m_findDialog->readSettings(); - emit findFlagsChanged(); // would have been done in the setXXX methods above -} - -void FindPlugin::updateFindCompletion(const QString &text) -{ - updateCompletion(text, d->m_findCompletions, d->m_findCompletionModel); -} - -void FindPlugin::updateReplaceCompletion(const QString &text) -{ - updateCompletion(text, d->m_replaceCompletions, d->m_replaceCompletionModel); -} - -void FindPlugin::updateCompletion(const QString &text, QStringList &completions, QStringListModel *model) -{ - if (text.isEmpty()) - return; - completions.removeAll(text); - completions.prepend(text); - while (completions.size() > MAX_COMPLETIONS) - completions.removeLast(); - model->setStringList(completions); -} - -void FindPlugin::setUseFakeVim(bool on) -{ - if (d->m_findToolBar) - d->m_findToolBar->setUseFakeVim(on); -} - -void FindPlugin::openFindToolBar(FindDirection direction) -{ - if (d->m_findToolBar) { - d->m_findToolBar->setBackward(direction == FindBackwardDirection); - d->m_findToolBar->openFindToolBar(); - } -} - -QStringListModel *FindPlugin::findCompletionModel() const -{ - return d->m_findCompletionModel; -} - -QStringListModel *FindPlugin::replaceCompletionModel() const -{ - return d->m_replaceCompletionModel; -} - -QKeySequence IFindFilter::defaultShortcut() const -{ - return QKeySequence(); -} - -} // namespace Find - -// declared in textfindconstants.h -QTextDocument::FindFlags Find::textDocumentFlagsForFindFlags(Find::FindFlags flags) -{ - QTextDocument::FindFlags textDocFlags; - if (flags & FindBackward) - textDocFlags |= QTextDocument::FindBackward; - if (flags & Find::FindCaseSensitively) - textDocFlags |= QTextDocument::FindCaseSensitively; - if (flags & Find::FindWholeWords) - textDocFlags |= QTextDocument::FindWholeWords; - return textDocFlags; -} - -Q_EXPORT_PLUGIN(Find::FindPlugin) +void dummyFindPlugin () {} diff --git a/src/plugins/find/findplugin.h b/src/plugins/find/findplugin.h deleted file mode 100644 index 872ae87ea22..00000000000 --- a/src/plugins/find/findplugin.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef FINDPLUGIN_H -#define FINDPLUGIN_H - -#include "find_global.h" -#include "textfindconstants.h" - -#include - -QT_BEGIN_NAMESPACE -class QStringListModel; -QT_END_NAMESPACE - -namespace Find { -class IFindFilter; -class FindPluginPrivate; - -namespace Internal { -class FindToolBar; -class CurrentDocumentFind; -} // namespace Internal - -class FIND_EXPORT FindPlugin : public ExtensionSystem::IPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Find.json") - -public: - FindPlugin(); - virtual ~FindPlugin(); - static FindPlugin *instance(); - - enum FindDirection { - FindForwardDirection, - FindBackwardDirection - }; - - // IPlugin - bool initialize(const QStringList &arguments, QString *errorMessage); - void extensionsInitialized(); - ShutdownFlag aboutToShutdown(); - - FindFlags findFlags() const; - bool hasFindFlag(FindFlag flag); - void updateFindCompletion(const QString &text); - void updateReplaceCompletion(const QString &text); - QStringListModel *findCompletionModel() const; - QStringListModel *replaceCompletionModel() const; - void setUseFakeVim(bool on); - void openFindToolBar(FindDirection direction); - void openFindDialog(IFindFilter *filter); - -public slots: - void setCaseSensitive(bool sensitive); - void setWholeWord(bool wholeOnly); - void setBackward(bool backward); - void setRegularExpression(bool regExp); - void setPreserveCase(bool preserveCase); - -signals: - void findFlagsChanged(); - -private slots: - void filterChanged(); - void openFindFilter(); - -private: - void setFindFlag(FindFlag flag, bool enabled); - void updateCompletion(const QString &text, QStringList &completions, QStringListModel *model); - void setupMenu(); - void setupFilterMenuItems(); - void writeSettings(); - void readSettings(); - - //variables - FindPluginPrivate *d; -}; - -} // namespace Find - -#endif // FINDPLUGIN_H diff --git a/src/plugins/find/findtoolbar.cpp b/src/plugins/find/findtoolbar.cpp deleted file mode 100644 index bfb9158d849..00000000000 --- a/src/plugins/find/findtoolbar.cpp +++ /dev/null @@ -1,778 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "findtoolbar.h" -#include "findplugin.h" -#include "ifindfilter.h" - -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -Q_DECLARE_METATYPE(QStringList) -Q_DECLARE_METATYPE(Find::IFindFilter*) - -using namespace Find; -using namespace Find::Internal; - -FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumentFind) - : m_plugin(plugin), - m_currentDocumentFind(currentDocumentFind), - m_findCompleter(new QCompleter(this)), - m_replaceCompleter(new QCompleter(this)), - m_enterFindStringAction(0), - m_findNextAction(0), - m_findPreviousAction(0), - m_replaceAction(0), - m_replaceNextAction(0), - m_replacePreviousAction(0), - m_findIncrementalTimer(this), m_findStepTimer(this), - m_useFakeVim(false), - m_eventFiltersInstalled(false) -{ - //setup ui - m_ui.setupUi(this); - // compensate for a vertically expanding spacer below the label - m_ui.replaceLabel->setMinimumHeight(m_ui.replaceEdit->sizeHint().height()); - delete m_ui.replaceButtonsWidget->layout(); - Utils::FlowLayout *flowlayout = new Utils::FlowLayout(m_ui.replaceButtonsWidget, 0, 3, 3); - flowlayout->addWidget(m_ui.replaceButton); - flowlayout->addWidget(m_ui.replaceNextButton); - flowlayout->addWidget(m_ui.replaceAllButton); - m_ui.replaceButtonsWidget->setLayout(flowlayout); - setFocusProxy(m_ui.findEdit); - setProperty("topBorder", true); - setSingleRow(false); - m_ui.findEdit->setAttribute(Qt::WA_MacShowFocusRect, false); - m_ui.replaceEdit->setAttribute(Qt::WA_MacShowFocusRect, false); - - connect(m_ui.findEdit, SIGNAL(editingFinished()), this, SLOT(invokeResetIncrementalSearch())); - - m_ui.close->setIcon(QIcon(QLatin1String(Core::Constants::ICON_CLOSE_DOCUMENT))); - connect(m_ui.close, SIGNAL(clicked()), this, SLOT(hideAndResetFocus())); - - m_findCompleter->setModel(m_plugin->findCompletionModel()); - m_replaceCompleter->setModel(m_plugin->replaceCompletionModel()); - m_ui.findEdit->setSpecialCompleter(m_findCompleter); - m_ui.replaceEdit->setSpecialCompleter(m_replaceCompleter); - - QMenu *lineEditMenu = new QMenu(m_ui.findEdit); - m_ui.findEdit->setButtonMenu(Utils::FancyLineEdit::Left, lineEditMenu); - m_ui.findEdit->setButtonVisible(Utils::FancyLineEdit::Left, true); - m_ui.findEdit->setPlaceholderText(QString()); - m_ui.replaceEdit->setPlaceholderText(QString()); - - connect(m_ui.findEdit, SIGNAL(textChanged(QString)), this, SLOT(invokeFindIncremental())); - - // invoke{Find,Replace}Helper change the completion model. QueuedConnection is used to perform these - // changes only after the completer's activated() signal is handled (QTCREATORBUG-8408) - connect(m_ui.findEdit, SIGNAL(returnPressed()), this, SLOT(invokeFindEnter()), Qt::QueuedConnection); - connect(m_ui.replaceEdit, SIGNAL(returnPressed()), this, SLOT(invokeReplaceEnter()), Qt::QueuedConnection); - - QAction *shiftEnterAction = new QAction(m_ui.findEdit); - shiftEnterAction->setShortcut(QKeySequence(tr("Shift+Enter"))); - shiftEnterAction->setShortcutContext(Qt::WidgetShortcut); - connect(shiftEnterAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious())); - m_ui.findEdit->addAction(shiftEnterAction); - QAction *shiftReturnAction = new QAction(m_ui.findEdit); - shiftReturnAction->setShortcut(QKeySequence(tr("Shift+Return"))); - shiftReturnAction->setShortcutContext(Qt::WidgetShortcut); - connect(shiftReturnAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious())); - m_ui.findEdit->addAction(shiftReturnAction); - - QAction *shiftEnterReplaceAction = new QAction(m_ui.replaceEdit); - shiftEnterReplaceAction->setShortcut(QKeySequence(tr("Shift+Enter"))); - shiftEnterReplaceAction->setShortcutContext(Qt::WidgetShortcut); - connect(shiftEnterReplaceAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious())); - m_ui.replaceEdit->addAction(shiftEnterReplaceAction); - QAction *shiftReturnReplaceAction = new QAction(m_ui.replaceEdit); - shiftReturnReplaceAction->setShortcut(QKeySequence(tr("Shift+Return"))); - shiftReturnReplaceAction->setShortcutContext(Qt::WidgetShortcut); - connect(shiftReturnReplaceAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious())); - m_ui.replaceEdit->addAction(shiftReturnReplaceAction); - - // need to make sure QStringList is registered as metatype - QMetaTypeId::qt_metatype_id(); - - // register actions - Core::Context globalcontext(Core::Constants::C_GLOBAL); - Core::ActionContainer *mfind = Core::ActionManager::actionContainer(Constants::M_FIND); - Core::Command *cmd; - - m_ui.advancedButton->setDefaultAction(Core::ActionManager::command(Constants::ADVANCED_FIND)->action()); - - QIcon icon = QIcon::fromTheme(QLatin1String("edit-find-replace")); - m_findInDocumentAction = new QAction(icon, tr("Find/Replace"), this); - cmd = Core::ActionManager::registerAction(m_findInDocumentAction, Constants::FIND_IN_DOCUMENT, globalcontext); - cmd->setDefaultKeySequence(QKeySequence::Find); - mfind->addAction(cmd, Constants::G_FIND_CURRENTDOCUMENT); - connect(m_findInDocumentAction, SIGNAL(triggered()), this, SLOT(openFind())); - - if (QApplication::clipboard()->supportsFindBuffer()) { - m_enterFindStringAction = new QAction(tr("Enter Find String"), this); - cmd = Core::ActionManager::registerAction(m_enterFindStringAction, "Find.EnterFindString", globalcontext); - cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+E"))); - mfind->addAction(cmd, Constants::G_FIND_ACTIONS); - connect(m_enterFindStringAction, SIGNAL(triggered()), this, SLOT(putSelectionToFindClipboard())); - connect(QApplication::clipboard(), SIGNAL(findBufferChanged()), this, SLOT(updateFromFindClipboard())); - } - - m_findNextAction = new QAction(tr("Find Next"), this); - cmd = Core::ActionManager::registerAction(m_findNextAction, Constants::FIND_NEXT, globalcontext); - cmd->setDefaultKeySequence(QKeySequence::FindNext); - mfind->addAction(cmd, Constants::G_FIND_ACTIONS); - connect(m_findNextAction, SIGNAL(triggered()), this, SLOT(invokeFindNext())); - m_ui.findNextButton->setDefaultAction(cmd->action()); - - m_findPreviousAction = new QAction(tr("Find Previous"), this); - cmd = Core::ActionManager::registerAction(m_findPreviousAction, Constants::FIND_PREVIOUS, globalcontext); - cmd->setDefaultKeySequence(QKeySequence::FindPrevious); - mfind->addAction(cmd, Constants::G_FIND_ACTIONS); - connect(m_findPreviousAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious())); - m_ui.findPreviousButton->setDefaultAction(cmd->action()); - - m_findNextSelectedAction = new QAction(tr("Find Next (Selected)"), this); - cmd = Core::ActionManager::registerAction(m_findNextSelectedAction, Constants::FIND_NEXT_SELECTED, globalcontext); - cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+F3"))); - mfind->addAction(cmd, Constants::G_FIND_ACTIONS); - connect(m_findNextSelectedAction, SIGNAL(triggered()), this, SLOT(findNextSelected())); - - m_findPreviousSelectedAction = new QAction(tr("Find Previous (Selected)"), this); - cmd = Core::ActionManager::registerAction(m_findPreviousSelectedAction, Constants::FIND_PREV_SELECTED, globalcontext); - cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F3"))); - mfind->addAction(cmd, Constants::G_FIND_ACTIONS); - connect(m_findPreviousSelectedAction, SIGNAL(triggered()), this, SLOT(findPreviousSelected())); - - m_replaceAction = new QAction(tr("Replace"), this); - cmd = Core::ActionManager::registerAction(m_replaceAction, Constants::REPLACE, globalcontext); - cmd->setDefaultKeySequence(QKeySequence()); - mfind->addAction(cmd, Constants::G_FIND_ACTIONS); - connect(m_replaceAction, SIGNAL(triggered()), this, SLOT(invokeReplace())); - m_ui.replaceButton->setDefaultAction(cmd->action()); - - m_replaceNextAction = new QAction(tr("Replace && Find"), this); - m_replaceNextAction->setIconText(tr("Replace && Find")); // work around bug in Qt that kills ampersands in tool button - cmd = Core::ActionManager::registerAction(m_replaceNextAction, Constants::REPLACE_NEXT, globalcontext); - cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+="))); - mfind->addAction(cmd, Constants::G_FIND_ACTIONS); - connect(m_replaceNextAction, SIGNAL(triggered()), this, SLOT(invokeReplaceNext())); - m_ui.replaceNextButton->setDefaultAction(cmd->action()); - - m_replacePreviousAction = new QAction(tr("Replace && Find Previous"), this); - cmd = Core::ActionManager::registerAction(m_replacePreviousAction, Constants::REPLACE_PREVIOUS, globalcontext); - // shortcut removed, clashes with Ctrl++ on many keyboard layouts - //cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+="))); - mfind->addAction(cmd, Constants::G_FIND_ACTIONS); - connect(m_replacePreviousAction, SIGNAL(triggered()), this, SLOT(invokeReplacePrevious())); - - m_replaceAllAction = new QAction(tr("Replace All"), this); - cmd = Core::ActionManager::registerAction(m_replaceAllAction, Constants::REPLACE_ALL, globalcontext); - mfind->addAction(cmd, Constants::G_FIND_ACTIONS); - connect(m_replaceAllAction, SIGNAL(triggered()), this, SLOT(invokeReplaceAll())); - m_ui.replaceAllButton->setDefaultAction(cmd->action()); - - m_caseSensitiveAction = new QAction(tr("Case Sensitive"), this); - m_caseSensitiveAction->setIcon(QIcon(QLatin1String(":/find/images/casesensitively.png"))); - m_caseSensitiveAction->setCheckable(true); - m_caseSensitiveAction->setChecked(false); - cmd = Core::ActionManager::registerAction(m_caseSensitiveAction, Constants::CASE_SENSITIVE, globalcontext); - mfind->addAction(cmd, Constants::G_FIND_FLAGS); - connect(m_caseSensitiveAction, SIGNAL(triggered(bool)), this, SLOT(setCaseSensitive(bool))); - lineEditMenu->addAction(m_caseSensitiveAction); - - m_wholeWordAction = new QAction(tr("Whole Words Only"), this); - m_wholeWordAction->setIcon(QIcon(QLatin1String(":/find/images/wholewords.png"))); - m_wholeWordAction->setCheckable(true); - m_wholeWordAction->setChecked(false); - cmd = Core::ActionManager::registerAction(m_wholeWordAction, Constants::WHOLE_WORDS, globalcontext); - mfind->addAction(cmd, Constants::G_FIND_FLAGS); - connect(m_wholeWordAction, SIGNAL(triggered(bool)), this, SLOT(setWholeWord(bool))); - lineEditMenu->addAction(m_wholeWordAction); - - m_regularExpressionAction = new QAction(tr("Use Regular Expressions"), this); - m_regularExpressionAction->setIcon(QIcon(QLatin1String(":/find/images/regexp.png"))); - m_regularExpressionAction->setCheckable(true); - m_regularExpressionAction->setChecked(false); - cmd = Core::ActionManager::registerAction(m_regularExpressionAction, Constants::REGULAR_EXPRESSIONS, globalcontext); - mfind->addAction(cmd, Constants::G_FIND_FLAGS); - connect(m_regularExpressionAction, SIGNAL(triggered(bool)), this, SLOT(setRegularExpressions(bool))); - lineEditMenu->addAction(m_regularExpressionAction); - - m_preserveCaseAction = new QAction(tr("Preserve Case when Replacing"), this); - m_preserveCaseAction->setIcon(QPixmap(QLatin1String(":/find/images/preservecase.png"))); - m_preserveCaseAction->setCheckable(true); - m_preserveCaseAction->setChecked(false); - cmd = Core::ActionManager::registerAction(m_preserveCaseAction, Constants::PRESERVE_CASE, globalcontext); - mfind->addAction(cmd, Constants::G_FIND_FLAGS); - connect(m_preserveCaseAction, SIGNAL(triggered(bool)), this, SLOT(setPreserveCase(bool))); - lineEditMenu->addAction(m_preserveCaseAction); - - connect(m_currentDocumentFind, SIGNAL(candidateChanged()), this, SLOT(adaptToCandidate())); - connect(m_currentDocumentFind, SIGNAL(changed()), this, SLOT(updateToolBar())); - updateToolBar(); - - m_findIncrementalTimer.setSingleShot(true); - m_findStepTimer.setSingleShot(true); - connect(&m_findIncrementalTimer, SIGNAL(timeout()), - this, SLOT(invokeFindIncremental())); - connect(&m_findStepTimer, SIGNAL(timeout()), this, SLOT(invokeFindStep())); -} - -FindToolBar::~FindToolBar() -{ -} - -void FindToolBar::installEventFilters() -{ - if (!m_eventFiltersInstalled) { - m_findCompleter->popup()->installEventFilter(this); - m_ui.findEdit->installEventFilter(this); - m_ui.replaceEdit->installEventFilter(this); - this->installEventFilter(this); - m_eventFiltersInstalled = true; - } -} - -bool FindToolBar::shouldSetFocusOnKeyEvent(QKeyEvent *event) -{ - return event->key() == Qt::Key_Escape && !event->modifiers() - && !m_findCompleter->popup()->isVisible() - && !m_replaceCompleter->popup()->isVisible() - && m_currentDocumentFind->isEnabled(); -} - -bool FindToolBar::eventFilter(QObject *obj, QEvent *event) -{ - if (event->type() == QEvent::KeyPress) { - QKeyEvent *ke = static_cast(event); - if (ke->key() == Qt::Key_Down) { - if (obj == m_ui.findEdit) { - if (m_ui.findEdit->text().isEmpty()) - m_findCompleter->setCompletionPrefix(QString()); - m_findCompleter->complete(); - } else if (obj == m_ui.replaceEdit) { - if (m_ui.replaceEdit->text().isEmpty()) - m_replaceCompleter->setCompletionPrefix(QString()); - m_replaceCompleter->complete(); - } - } - } - - if ((obj == m_ui.findEdit || obj == m_findCompleter->popup()) - && event->type() == QEvent::KeyPress) { - QKeyEvent *ke = static_cast(event); - if (ke->key() == Qt::Key_Space && (ke->modifiers() & Utils::HostOsInfo::controlModifier())) { - QString completedText = m_currentDocumentFind->completedFindString(); - if (!completedText.isEmpty()) { - setFindText(completedText); - ke->accept(); - return true; - } - } - } else if (obj == this && event->type() == QEvent::ShortcutOverride) { - QKeyEvent *ke = static_cast(event); - if (shouldSetFocusOnKeyEvent(ke)) { - event->accept(); - return true; - } else if (ke->key() == Qt::Key_Space && (ke->modifiers() & Utils::HostOsInfo::controlModifier())) { - event->accept(); - return true; - } - } else if (obj == this && event->type() == QEvent::Hide) { - invokeClearResults(); - if (m_currentDocumentFind->isEnabled()) - m_currentDocumentFind->clearFindScope(); - } - return Utils::StyledBar::eventFilter(obj, event); -} - -void FindToolBar::keyPressEvent(QKeyEvent *event) -{ - if (shouldSetFocusOnKeyEvent(event)) { - if (setFocusToCurrentFindSupport()) - event->accept(); - return; - } - return Utils::StyledBar::keyPressEvent(event); -} - -void FindToolBar::adaptToCandidate() -{ - updateFindAction(); - if (findToolBarPlaceHolder() == Core::FindToolBarPlaceHolder::getCurrent()) - m_currentDocumentFind->acceptCandidate(); -} - -void FindToolBar::updateFindAction() -{ - bool enabled = m_currentDocumentFind->candidateIsEnabled(); - m_findInDocumentAction->setEnabled(enabled); - m_findNextSelectedAction->setEnabled(enabled); - m_findPreviousSelectedAction->setEnabled(enabled); -} - -void FindToolBar::updateToolBar() -{ - bool enabled = m_currentDocumentFind->isEnabled(); - bool replaceEnabled = enabled && m_currentDocumentFind->supportsReplace(); - m_findNextAction->setEnabled(enabled); - m_findPreviousAction->setEnabled(enabled); - - m_replaceAction->setEnabled(replaceEnabled); - m_replaceNextAction->setEnabled(replaceEnabled); - m_replacePreviousAction->setEnabled(replaceEnabled); - m_replaceAllAction->setEnabled(replaceEnabled); - - m_caseSensitiveAction->setEnabled(enabled); - m_wholeWordAction->setEnabled(enabled); - m_regularExpressionAction->setEnabled(enabled); - m_preserveCaseAction->setEnabled(replaceEnabled && !hasFindFlag(FindRegularExpression)); - if (QApplication::clipboard()->supportsFindBuffer()) - m_enterFindStringAction->setEnabled(enabled); - bool replaceFocus = m_ui.replaceEdit->hasFocus(); - m_ui.findEdit->setEnabled(enabled); - m_ui.findLabel->setEnabled(enabled); - - m_ui.replaceEdit->setEnabled(replaceEnabled); - m_ui.replaceLabel->setEnabled(replaceEnabled); - m_ui.replaceEdit->setVisible(replaceEnabled); - m_ui.replaceLabel->setVisible(replaceEnabled); - m_ui.replaceButtonsWidget->setVisible(replaceEnabled); - m_ui.advancedButton->setVisible(replaceEnabled); - layout()->invalidate(); - - if (!replaceEnabled && enabled && replaceFocus) - m_ui.findEdit->setFocus(); - updateIcons(); - updateFlagMenus(); -} - -void FindToolBar::invokeFindEnter() -{ - if (m_currentDocumentFind->isEnabled()) { - if (m_useFakeVim) - setFocusToCurrentFindSupport(); - else - invokeFindNext(); - } -} - -void FindToolBar::invokeReplaceEnter() -{ - if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) - invokeReplaceNext(); -} - -void FindToolBar::invokeClearResults() -{ - if (m_currentDocumentFind->isEnabled()) - m_currentDocumentFind->clearResults(); -} - - -void FindToolBar::invokeFindNext() -{ - setFindFlag(FindBackward, false); - invokeFindStep(); -} - -void FindToolBar::invokeFindPrevious() -{ - setFindFlag(FindBackward, true); - invokeFindStep(); -} - -QString FindToolBar::getFindText() -{ - return m_ui.findEdit->text(); -} - -QString FindToolBar::getReplaceText() -{ - return m_ui.replaceEdit->text(); -} - -void FindToolBar::setFindText(const QString &text) -{ - disconnect(m_ui.findEdit, SIGNAL(textChanged(QString)), this, SLOT(invokeFindIncremental())); - if (hasFindFlag(FindRegularExpression)) - m_ui.findEdit->setText(QRegExp::escape(text)); - else - m_ui.findEdit->setText(text); - connect(m_ui.findEdit, SIGNAL(textChanged(QString)), this, SLOT(invokeFindIncremental())); -} - -void FindToolBar::selectFindText() -{ - m_ui.findEdit->selectAll(); -} - -void FindToolBar::invokeFindStep() -{ - m_findStepTimer.stop(); - m_findIncrementalTimer.stop(); - if (m_currentDocumentFind->isEnabled()) { - m_plugin->updateFindCompletion(getFindText()); - IFindSupport::Result result = - m_currentDocumentFind->findStep(getFindText(), effectiveFindFlags()); - if (result == IFindSupport::NotYetFound) - m_findStepTimer.start(50); - } -} - -void FindToolBar::invokeFindIncremental() -{ - m_findIncrementalTimer.stop(); - m_findStepTimer.stop(); - if (m_currentDocumentFind->isEnabled()) { - QString text = getFindText(); - IFindSupport::Result result = - m_currentDocumentFind->findIncremental(text, effectiveFindFlags()); - if (result == IFindSupport::NotYetFound) - m_findIncrementalTimer.start(50); - if (text.isEmpty()) - m_currentDocumentFind->clearResults(); - } -} - -void FindToolBar::invokeReplace() -{ - setFindFlag(FindBackward, false); - if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) { - m_plugin->updateFindCompletion(getFindText()); - m_plugin->updateReplaceCompletion(getReplaceText()); - m_currentDocumentFind->replace(getFindText(), getReplaceText(), effectiveFindFlags()); - } -} - -void FindToolBar::invokeReplaceNext() -{ - setFindFlag(FindBackward, false); - invokeReplaceStep(); -} - -void FindToolBar::invokeReplacePrevious() -{ - setFindFlag(FindBackward, true); - invokeReplaceStep(); -} - -void FindToolBar::invokeReplaceStep() -{ - if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) { - m_plugin->updateFindCompletion(getFindText()); - m_plugin->updateReplaceCompletion(getReplaceText()); - m_currentDocumentFind->replaceStep(getFindText(), getReplaceText(), effectiveFindFlags()); - } -} - -void FindToolBar::invokeReplaceAll() -{ - m_plugin->updateFindCompletion(getFindText()); - m_plugin->updateReplaceCompletion(getReplaceText()); - if (m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace()) - m_currentDocumentFind->replaceAll(getFindText(), getReplaceText(), effectiveFindFlags()); -} - -void FindToolBar::invokeResetIncrementalSearch() -{ - m_findIncrementalTimer.stop(); - m_findStepTimer.stop(); - if (m_currentDocumentFind->isEnabled()) - m_currentDocumentFind->resetIncrementalSearch(); -} - - -void FindToolBar::putSelectionToFindClipboard() -{ - const QString text = m_currentDocumentFind->currentFindString(); - QApplication::clipboard()->setText(text, QClipboard::FindBuffer); - setFindText(text); -} - - -void FindToolBar::updateFromFindClipboard() -{ - if (QApplication::clipboard()->supportsFindBuffer()) { - const bool blocks = m_ui.findEdit->blockSignals(true); - setFindText(QApplication::clipboard()->text(QClipboard::FindBuffer)); - m_ui.findEdit->blockSignals(blocks); - } -} - -void FindToolBar::findFlagsChanged() -{ - updateIcons(); - updateFlagMenus(); - invokeClearResults(); - if (isVisible()) - m_currentDocumentFind->highlightAll(getFindText(), effectiveFindFlags()); -} - -void FindToolBar::updateIcons() -{ - FindFlags effectiveFlags = effectiveFindFlags(); - bool casesensitive = effectiveFlags & FindCaseSensitively; - bool wholewords = effectiveFlags & FindWholeWords; - bool regexp = effectiveFlags & FindRegularExpression; - bool preserveCase = effectiveFlags & FindPreserveCase; - if (!casesensitive && !wholewords && !regexp && !preserveCase) { - QPixmap pixmap(17, 17); - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - const QPixmap mag = QPixmap(QLatin1String(Core::Constants::ICON_MAGNIFIER)); - painter.drawPixmap(0, (pixmap.height() - mag.height()) / 2, mag); - m_ui.findEdit->setButtonPixmap(Utils::FancyLineEdit::Left, pixmap); - } else { - m_ui.findEdit->setButtonPixmap(Utils::FancyLineEdit::Left, - IFindFilter::pixmapForFindFlags(effectiveFlags)); - } -} - -FindFlags FindToolBar::effectiveFindFlags() -{ - FindFlags supportedFlags; - bool supportsReplace = true; - if (m_currentDocumentFind->isEnabled()) { - supportedFlags = m_currentDocumentFind->supportedFindFlags(); - supportsReplace = m_currentDocumentFind->supportsReplace(); - } else { - supportedFlags = (FindFlags)0xFFFFFF; - } - if (!supportsReplace || m_findFlags & FindRegularExpression) - supportedFlags &= ~FindPreserveCase; - return supportedFlags & m_findFlags; -} - -void FindToolBar::updateFlagMenus() -{ - bool wholeOnly = ((m_findFlags & FindWholeWords)); - bool sensitive = ((m_findFlags & FindCaseSensitively)); - bool regexp = ((m_findFlags & FindRegularExpression)); - bool preserveCase = ((m_findFlags & FindPreserveCase)); - if (m_wholeWordAction->isChecked() != wholeOnly) - m_wholeWordAction->setChecked(wholeOnly); - if (m_caseSensitiveAction->isChecked() != sensitive) - m_caseSensitiveAction->setChecked(sensitive); - if (m_regularExpressionAction->isChecked() != regexp) - m_regularExpressionAction->setChecked(regexp); - if (m_preserveCaseAction->isChecked() != preserveCase) - m_preserveCaseAction->setChecked(preserveCase); - FindFlags supportedFlags; - if (m_currentDocumentFind->isEnabled()) - supportedFlags = m_currentDocumentFind->supportedFindFlags(); - m_wholeWordAction->setEnabled(supportedFlags & FindWholeWords); - m_caseSensitiveAction->setEnabled(supportedFlags & FindCaseSensitively); - m_regularExpressionAction->setEnabled(supportedFlags & FindRegularExpression); - bool replaceEnabled = m_currentDocumentFind->isEnabled() && m_currentDocumentFind->supportsReplace(); - m_preserveCaseAction->setEnabled((supportedFlags & FindPreserveCase) && !regexp && replaceEnabled); -} - -bool FindToolBar::setFocusToCurrentFindSupport() -{ - return m_currentDocumentFind->setFocusToCurrentFindSupport(); -} - -void FindToolBar::hideAndResetFocus() -{ - m_currentDocumentFind->setFocusToCurrentFindSupport(); - hide(); -} - -Core::FindToolBarPlaceHolder *FindToolBar::findToolBarPlaceHolder() const -{ - QList placeholders = ExtensionSystem::PluginManager::getObjects(); - QWidget *candidate = QApplication::focusWidget(); - while (candidate) { - foreach (Core::FindToolBarPlaceHolder *ph, placeholders) { - if (ph->owner() == candidate) - return ph; - } - candidate = candidate->parentWidget(); - } - return 0; -} - -void FindToolBar::openFind(bool focus) -{ - setBackward(false); - openFindToolBar(focus); -} - -void FindToolBar::openFindToolBar(bool focus) -{ - installEventFilters(); - if (!m_currentDocumentFind->candidateIsEnabled()) - return; - Core::FindToolBarPlaceHolder *holder = findToolBarPlaceHolder(); - if (!holder) - return; - Core::FindToolBarPlaceHolder *previousHolder = Core::FindToolBarPlaceHolder::getCurrent(); - if (previousHolder) - previousHolder->setWidget(0); - Core::FindToolBarPlaceHolder::setCurrent(holder); - m_currentDocumentFind->acceptCandidate(); - holder->setWidget(this); - holder->setVisible(true); - setVisible(true); - if (focus) - setFocus(); - QString text = m_currentDocumentFind->currentFindString(); - if (!text.isEmpty()) - setFindText(text); - m_currentDocumentFind->defineFindScope(); - m_currentDocumentFind->highlightAll(getFindText(), effectiveFindFlags()); - if (focus) - selectFindText(); -} - -void FindToolBar::findNextSelected() -{ - openFind(false); - invokeFindNext(); -} - -void FindToolBar::findPreviousSelected() -{ - openFind(false); - invokeFindPrevious(); -} - -bool FindToolBar::focusNextPrevChild(bool next) -{ - // close tab order change - if (next && m_ui.replaceAllButton->hasFocus()) - m_ui.findEdit->setFocus(Qt::TabFocusReason); - else if (!next && m_ui.findEdit->hasFocus()) - m_ui.replaceAllButton->setFocus(Qt::TabFocusReason); - else - return Utils::StyledBar::focusNextPrevChild(next); - return true; -} - -void FindToolBar::writeSettings() -{ - QSettings *settings = Core::ICore::settings(); - settings->beginGroup(QLatin1String("Find")); - settings->beginGroup(QLatin1String("FindToolBar")); - settings->setValue(QLatin1String("Backward"), QVariant((m_findFlags & FindBackward) != 0)); - settings->setValue(QLatin1String("CaseSensitively"), QVariant((m_findFlags & FindCaseSensitively) != 0)); - settings->setValue(QLatin1String("WholeWords"), QVariant((m_findFlags & FindWholeWords) != 0)); - settings->setValue(QLatin1String("RegularExpression"), QVariant((m_findFlags & FindRegularExpression) != 0)); - settings->setValue(QLatin1String("PreserveCase"), QVariant((m_findFlags & FindPreserveCase) != 0)); - settings->endGroup(); - settings->endGroup(); -} - -void FindToolBar::readSettings() -{ - QSettings *settings = Core::ICore::settings(); - settings->beginGroup(QLatin1String("Find")); - settings->beginGroup(QLatin1String("FindToolBar")); - FindFlags flags; - if (settings->value(QLatin1String("Backward"), false).toBool()) - flags |= FindBackward; - if (settings->value(QLatin1String("CaseSensitively"), false).toBool()) - flags |= FindCaseSensitively; - if (settings->value(QLatin1String("WholeWords"), false).toBool()) - flags |= FindWholeWords; - if (settings->value(QLatin1String("RegularExpression"), false).toBool()) - flags |= FindRegularExpression; - if (settings->value(QLatin1String("PreserveCase"), false).toBool()) - flags |= FindPreserveCase; - settings->endGroup(); - settings->endGroup(); - m_findFlags = flags; - findFlagsChanged(); -} - -void FindToolBar::setUseFakeVim(bool on) -{ - m_useFakeVim = on; -} - -void FindToolBar::setFindFlag(FindFlag flag, bool enabled) -{ - bool hasFlag = hasFindFlag(flag); - if ((hasFlag && enabled) || (!hasFlag && !enabled)) - return; - if (enabled) - m_findFlags |= flag; - else - m_findFlags &= ~flag; - if (flag != FindBackward) - findFlagsChanged(); -} - -bool FindToolBar::hasFindFlag(FindFlag flag) -{ - return m_findFlags & flag; -} - -void FindToolBar::setCaseSensitive(bool sensitive) -{ - setFindFlag(FindCaseSensitively, sensitive); -} - -void FindToolBar::setWholeWord(bool wholeOnly) -{ - setFindFlag(FindWholeWords, wholeOnly); -} - -void FindToolBar::setRegularExpressions(bool regexp) -{ - setFindFlag(FindRegularExpression, regexp); -} - -void FindToolBar::setPreserveCase(bool preserveCase) -{ - setFindFlag(FindPreserveCase, preserveCase); -} - -void FindToolBar::setBackward(bool backward) -{ - setFindFlag(FindBackward, backward); -} diff --git a/src/plugins/find/findtoolbar.h b/src/plugins/find/findtoolbar.h deleted file mode 100644 index a5e2fcade7f..00000000000 --- a/src/plugins/find/findtoolbar.h +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef FINDTOOLBAR_H -#define FINDTOOLBAR_H - -#include "ui_findwidget.h" -#include "currentdocumentfind.h" - -#include - -#include - -namespace Core { -class FindToolBarPlaceHolder; -} - -namespace Find { -class FindPlugin; - -namespace Internal { - -class FindToolBar : public Utils::StyledBar -{ - Q_OBJECT - -public: - explicit FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumentFind); - ~FindToolBar(); - - void readSettings(); - void writeSettings(); - - void openFindToolBar(bool focus = true); - void setUseFakeVim(bool on); - -public slots: - void setBackward(bool backward); - -private slots: - void invokeFindNext(); - void invokeFindPrevious(); - void invokeFindStep(); - void invokeReplace(); - void invokeReplaceNext(); - void invokeReplacePrevious(); - void invokeReplaceStep(); - void invokeReplaceAll(); - void invokeResetIncrementalSearch(); - - void invokeFindIncremental(); - void invokeFindEnter(); - void invokeReplaceEnter(); - void putSelectionToFindClipboard(); - void updateFromFindClipboard(); - - void hideAndResetFocus(); - void openFind(bool focus = true); - void findNextSelected(); - void findPreviousSelected(); - void updateFindAction(); - void updateToolBar(); - void findFlagsChanged(); - - void setCaseSensitive(bool sensitive); - void setWholeWord(bool wholeOnly); - void setRegularExpressions(bool regexp); - void setPreserveCase(bool preserveCase); - - void adaptToCandidate(); - -protected: - bool focusNextPrevChild(bool next); - void keyPressEvent(QKeyEvent *event); - -private: - void installEventFilters(); - void invokeClearResults(); - bool setFocusToCurrentFindSupport(); - void setFindFlag(FindFlag flag, bool enabled); - bool hasFindFlag(FindFlag flag); - FindFlags effectiveFindFlags(); - Core::FindToolBarPlaceHolder *findToolBarPlaceHolder() const; - - bool eventFilter(QObject *obj, QEvent *event); - void setFindText(const QString &text); - QString getFindText(); - QString getReplaceText(); - void selectFindText(); - void updateIcons(); - void updateFlagMenus(); - - bool shouldSetFocusOnKeyEvent(QKeyEvent *event); - - FindPlugin *m_plugin; - CurrentDocumentFind *m_currentDocumentFind; - Ui::FindWidget m_ui; - QCompleter *m_findCompleter; - QCompleter *m_replaceCompleter; - QAction *m_findInDocumentAction; - QAction *m_findNextSelectedAction; - QAction *m_findPreviousSelectedAction; - QAction *m_enterFindStringAction; - QAction *m_findNextAction; - QAction *m_findPreviousAction; - QAction *m_replaceAction; - QAction *m_replaceNextAction; - QAction *m_replacePreviousAction; - QAction *m_replaceAllAction; - QAction *m_caseSensitiveAction; - QAction *m_wholeWordAction; - QAction *m_regularExpressionAction; - QAction *m_preserveCaseAction; - FindFlags m_findFlags; - - QTimer m_findIncrementalTimer; - QTimer m_findStepTimer; - bool m_useFakeVim; - bool m_eventFiltersInstalled; -}; - -} // namespace Internal -} // namespace Find - -#endif // FINDTOOLBAR_H diff --git a/src/plugins/find/findtoolwindow.cpp b/src/plugins/find/findtoolwindow.cpp deleted file mode 100644 index 77b48d28662..00000000000 --- a/src/plugins/find/findtoolwindow.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "findtoolwindow.h" -#include "ifindfilter.h" -#include "findplugin.h" - -#include - -#include -#include -#include -#include -#include - -using namespace Find; -using namespace Find::Internal; - -static FindToolWindow *m_instance = 0; - -FindToolWindow::FindToolWindow(FindPlugin *plugin, QWidget *parent) - : QWidget(parent), - m_plugin(plugin), - m_findCompleter(new QCompleter(this)), - m_currentFilter(0), - m_configWidget(0) -{ - m_instance = this; - m_ui.setupUi(this); - m_ui.searchTerm->setPlaceholderText(QString()); - setFocusProxy(m_ui.searchTerm); - - connect(m_ui.searchButton, SIGNAL(clicked()), this, SLOT(search())); - connect(m_ui.replaceButton, SIGNAL(clicked()), this, SLOT(replace())); - connect(m_ui.matchCase, SIGNAL(toggled(bool)), m_plugin, SLOT(setCaseSensitive(bool))); - connect(m_ui.wholeWords, SIGNAL(toggled(bool)), m_plugin, SLOT(setWholeWord(bool))); - connect(m_ui.regExp, SIGNAL(toggled(bool)), m_plugin, SLOT(setRegularExpression(bool))); - connect(m_ui.filterList, SIGNAL(activated(int)), this, SLOT(setCurrentFilter(int))); - connect(m_ui.searchTerm, SIGNAL(textChanged(QString)), this, SLOT(updateButtonStates())); - - m_findCompleter->setModel(m_plugin->findCompletionModel()); - m_ui.searchTerm->setSpecialCompleter(m_findCompleter); - m_ui.searchTerm->installEventFilter(this); - QVBoxLayout *layout = new QVBoxLayout; - layout->setMargin(0); - layout->setSpacing(0); - m_ui.configWidget->setLayout(layout); - updateButtonStates(); - - connect(m_plugin, SIGNAL(findFlagsChanged()), this, SLOT(updateFindFlags())); -} - -FindToolWindow::~FindToolWindow() -{ - qDeleteAll(m_configWidgets); -} - -FindToolWindow *FindToolWindow::instance() -{ - return m_instance; -} - -bool FindToolWindow::event(QEvent *event) -{ - if (event->type() == QEvent::KeyPress) { - QKeyEvent *ke = static_cast(event); - if ((ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) - && (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::KeypadModifier)) { - ke->accept(); - search(); - return true; - } - } - return QWidget::event(event); -} - -bool FindToolWindow::eventFilter(QObject *obj, QEvent *event) -{ - if (obj == m_ui.searchTerm && event->type() == QEvent::KeyPress) { - QKeyEvent *ke = static_cast(event); - if (ke->key() == Qt::Key_Down) { - if (m_ui.searchTerm->text().isEmpty()) - m_findCompleter->setCompletionPrefix(QString()); - m_findCompleter->complete(); - } - } - return QWidget::eventFilter(obj, event); -} - -void FindToolWindow::updateButtonStates() -{ - bool filterEnabled = m_currentFilter && m_currentFilter->isEnabled(); - bool enabled = !m_ui.searchTerm->text().isEmpty() && filterEnabled; - m_ui.searchButton->setEnabled(enabled); - m_ui.replaceButton->setEnabled(m_currentFilter - && m_currentFilter->isReplaceSupported() && enabled); - if (m_configWidget) - m_configWidget->setEnabled(filterEnabled); - - m_ui.matchCase->setEnabled(filterEnabled - && (m_currentFilter->supportedFindFlags() & FindCaseSensitively)); - m_ui.wholeWords->setEnabled(filterEnabled - && (m_currentFilter->supportedFindFlags() & FindWholeWords)); - m_ui.regExp->setEnabled(filterEnabled - && (m_currentFilter->supportedFindFlags() & FindRegularExpression)); - m_ui.searchTerm->setEnabled(filterEnabled); -} - -void FindToolWindow::updateFindFlags() -{ - m_ui.matchCase->setChecked(m_plugin->hasFindFlag(FindCaseSensitively)); - m_ui.wholeWords->setChecked(m_plugin->hasFindFlag(FindWholeWords)); - m_ui.regExp->setChecked(m_plugin->hasFindFlag(FindRegularExpression)); -} - - -void FindToolWindow::setFindFilters(const QList &filters) -{ - qDeleteAll(m_configWidgets); - m_configWidgets.clear(); - m_filters = filters; - m_ui.filterList->clear(); - QStringList names; - foreach (IFindFilter *filter, filters) { - names << filter->displayName(); - m_configWidgets.append(filter->createConfigWidget()); - } - m_ui.filterList->addItems(names); - if (m_filters.size() > 0) - setCurrentFilter(0); -} - -void FindToolWindow::setFindText(const QString &text) -{ - m_ui.searchTerm->setText(text); -} - -void FindToolWindow::setCurrentFilter(IFindFilter *filter) -{ - if (!filter) - filter = m_currentFilter; - int index = m_filters.indexOf(filter); - if (index >= 0) - setCurrentFilter(index); - updateFindFlags(); - m_ui.searchTerm->setFocus(); - m_ui.searchTerm->selectAll(); -} - -void FindToolWindow::setCurrentFilter(int index) -{ - m_ui.filterList->setCurrentIndex(index); - for (int i = 0; i < m_configWidgets.size(); ++i) { - QWidget *configWidget = m_configWidgets.at(i); - if (i == index) { - m_configWidget = configWidget; - if (m_currentFilter) - disconnect(m_currentFilter, SIGNAL(enabledChanged(bool)), this, SLOT(updateButtonStates())); - m_currentFilter = m_filters.at(i); - connect(m_currentFilter, SIGNAL(enabledChanged(bool)), this, SLOT(updateButtonStates())); - updateButtonStates(); - if (m_configWidget) - m_ui.configWidget->layout()->addWidget(m_configWidget); - } else { - if (configWidget) - configWidget->setParent(0); - } - } - QWidget *w = m_ui.configWidget; - while (w) { - QScrollArea *sa = qobject_cast(w); - if (sa) { - sa->updateGeometry(); - break; - } - w = w->parentWidget(); - } - for (w = m_configWidget ? m_configWidget : m_ui.configWidget; w; w = w->parentWidget()) { - if (w->layout()) - w->layout()->activate(); - } -} - -void FindToolWindow::acceptAndGetParameters(QString *term, IFindFilter **filter) -{ - if (filter) - *filter = 0; - m_plugin->updateFindCompletion(m_ui.searchTerm->text()); - int index = m_ui.filterList->currentIndex(); - QString searchTerm = m_ui.searchTerm->text(); - if (term) - *term = searchTerm; - if (searchTerm.isEmpty() || index < 0) - return; - if (filter) - *filter = m_filters.at(index); -} - -void FindToolWindow::search() -{ - QString term; - IFindFilter *filter; - acceptAndGetParameters(&term, &filter); - if (filter) - filter->findAll(term, m_plugin->findFlags()); -} - -void FindToolWindow::replace() -{ - QString term; - IFindFilter *filter; - acceptAndGetParameters(&term, &filter); - filter->replaceAll(term, m_plugin->findFlags()); -} - -void FindToolWindow::writeSettings() -{ - QSettings *settings = Core::ICore::settings(); - settings->beginGroup(QLatin1String("Find")); - settings->setValue(QLatin1String("CurrentFilter"), m_currentFilter ? m_currentFilter->id() : QString()); - foreach (IFindFilter *filter, m_filters) - filter->writeSettings(settings); - settings->endGroup(); -} - -void FindToolWindow::readSettings() -{ - QSettings *settings = Core::ICore::settings(); - settings->beginGroup(QLatin1String("Find")); - const QString currentFilter = settings->value(QLatin1String("CurrentFilter")).toString(); - for (int i = 0; i < m_filters.size(); ++i) { - IFindFilter *filter = m_filters.at(i); - filter->readSettings(settings); - if (filter->id() == currentFilter) - setCurrentFilter(i); - } - settings->endGroup(); -} diff --git a/src/plugins/find/findtoolwindow.h b/src/plugins/find/findtoolwindow.h deleted file mode 100644 index 49cb5211cb0..00000000000 --- a/src/plugins/find/findtoolwindow.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef FINDTOOLWINDOW_H -#define FINDTOOLWINDOW_H - -#include "ui_finddialog.h" - -#include - -QT_FORWARD_DECLARE_CLASS(QCompleter) - -namespace Find { -class FindPlugin; -class IFindFilter; - -namespace Internal { - -class FindToolWindow : public QWidget -{ - Q_OBJECT - -public: - explicit FindToolWindow(FindPlugin *plugin, QWidget *parent = 0); - ~FindToolWindow(); - static FindToolWindow *instance(); - - void setFindFilters(const QList &filters); - - void setFindText(const QString &text); - void setCurrentFilter(IFindFilter *filter); - void readSettings(); - void writeSettings(); - -protected: - bool event(QEvent *event); - bool eventFilter(QObject *obj, QEvent *event); - -private slots: - void search(); - void replace(); - void setCurrentFilter(int index); - void updateButtonStates(); - void updateFindFlags(); - -private: - void acceptAndGetParameters(QString *term, IFindFilter **filter); - - Ui::FindDialog m_ui; - FindPlugin *m_plugin; - QList m_filters; - QCompleter *m_findCompleter; - QWidgetList m_configWidgets; - IFindFilter *m_currentFilter; - QWidget *m_configWidget; -}; - -} // namespace Internal -} // namespace Find - -#endif // FINDTOOLWINDOW_H diff --git a/src/plugins/find/findwidget.ui b/src/plugins/find/findwidget.ui deleted file mode 100644 index 7ff9c28f0f2..00000000000 --- a/src/plugins/find/findwidget.ui +++ /dev/null @@ -1,292 +0,0 @@ - - - Find::Internal::FindWidget - - - - 0 - 0 - 681 - 88 - - - - Find - - - - 5 - - - 2 - - - 0 - - - 2 - - - 3 - - - 0 - - - - - Find: - - - - - - - - 100 - 0 - - - - - - - - - 3 - - - 0 - - - - - Qt::NoFocus - - - Qt::LeftArrow - - - - - - - - - - Qt::NoFocus - - - Qt::RightArrow - - - - - - - Qt::Horizontal - - - - 40 - 0 - - - - - - - - ... - - - - - - - - - - 0 - - - - - Replace with: - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - - - 0 - - - - - - 100 - 0 - - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - - - 3 - - - 0 - - - - - - 0 - 0 - - - - - 3 - - - 0 - - - - - Qt::NoFocus - - - Replace - - - Qt::ToolButtonTextOnly - - - Qt::LeftArrow - - - - - - - - - - Qt::NoFocus - - - Replace && Find - - - Qt::ToolButtonTextOnly - - - Qt::RightArrow - - - - - - - - - - Replace All - - - Qt::ToolButtonTextOnly - - - - - - - - - - 0 - - - - - Advanced... - - - Qt::ToolButtonTextOnly - - - - - - - Qt::Vertical - - - - 0 - 0 - - - - - - - - - - - - - Utils::FancyLineEdit - QLineEdit -
utils/fancylineedit.h
-
- - Utils::FilterLineEdit - Utils::FancyLineEdit -
utils/filterlineedit.h
-
-
- - findEdit - replaceEdit - close - replaceAllButton - - - -
diff --git a/src/plugins/find/ifindfilter.cpp b/src/plugins/find/ifindfilter.cpp deleted file mode 100644 index bcd8e8d2c4f..00000000000 --- a/src/plugins/find/ifindfilter.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "ifindfilter.h" - -#include -#include - -/*! - \class Find::IFindFilter - \brief The IFindFilter class is the base class for find implementations - that are invoked by selecting \gui Edit > \gui {Find/Replace} > - \gui {Advanced Find}. - - Implementations of this class add an additional \gui Scope to the \gui {Advanced - Find} dialog. That can be any search that requires the user to provide - a text based search term (potentially with find flags like - searching case sensitively or using regular expressions). Existing - scopes are \gui {All Projects} that searches from all files in all projects - and \gui {Files on File System} where the user provides a directory and file - patterns to search. - - To make your find scope available to the user, you need to implement this - class, and register an instance of your subclass in the plugin manager. - - A common way to present the search results to the user, is to use the - shared \gui{Search Results} panel. - - If you want to implement a find filter that is doing a file based text - search, you should use Find::BaseFileFind, which already implements all - the details for this kind of search, only requiring you to provide an - iterator over the file names of the files that should be searched. - - If you want to implement a more specialized find filter, you need to: - \list - \li Start your search in a separate thread - \li Make this known to the Core::ProgressManager, for a progress bar - and the ability to cancel the search - \li Interface with the shared \gui{Search Results} panel, to show - the search results, handle the event that the user click on one - of the search result items, and possible handle a global replace - of all or some of the search result items. - \endlist - - Luckily QtConcurrent and the search result panel provide the frameworks - that make it relatively easy to implement, - while ensuring a common way for the user. - - The common pattern is roughly this: - - Implement the actual search within a QtConcurrent based function, that is - a function that takes a \c{QFutureInterface &future} - as the first parameter and the other information needed for the search - as additional parameters. It should set useful progress information - on the QFutureInterface, regularly check for \c{future.isPaused()} - and \c{future.isCanceled()}, and report the search results - (possibly in chunks) via \c{future.reportResult}. - - In the find filter's find/replaceAll function, get the shared - \gui{Search Results} window, initiate a new search and connect the - signals for handling selection of results and the replace action - (see the Find::SearchResultWindow class for details). - Start your search implementation via the corresponding QtConcurrent - functions. Add the returned QFuture object to the Core::ProgressManager. - Use a QFutureWatcher on the returned QFuture object to receive a signal - when your search implementation reports search results, and add these - to the shared \gui{Search Results} window. -*/ - -/*! - \fn IFindFilter::~IFindFilter() - \internal -*/ - -/*! - \fn QString IFindFilter::id() const - Returns the unique string identifier for this find filter. - - Usually should be something like "MyPlugin.MyFindFilter". -*/ - -/*! - \fn QString IFindFilter::displayName() const - Returns the name of the find filter or scope as presented to the user. - - This is the name that appears in the scope selection combo box, for example. - Always return a translatable string (that is, use tr() for the return value). -*/ - -/*! - \fn bool IFindFilter::isEnabled() const - Returns whether the user should be able to select this find filter - at the moment. - - This is used for the \gui {Current Projects} scope, for example. If the user - has not - opened a project, the scope is disabled. - - \sa changed() -*/ - -/*! - \fn QKeySequence IFindFilter::defaultShortcut() const - Returns the shortcut that can be used to open the advanced find - dialog with this filter or scope preselected. - - Usually return an empty shortcut here, the user can still choose and - assign a specific shortcut to this find scope via the preferences. -*/ - -/*! - \fn bool IFindFilter::isReplaceSupported() const - Returns whether the find filter supports search and replace. - - The default value is false, override this function to return \c true, if - your find filter supports global search and replace. -*/ - -/*! - \fn void IFindFilter::findAll(const QString &txt, Find::FindFlags findFlags) - This function is called when the user selected this find scope and - initiated a search. - - You should start a thread which actually performs the search for \a txt - using the given \a findFlags - (add it to Core::ProgressManager for a progress bar!) and presents the - search results to the user (using the \gui{Search Results} output pane). - For more information, see the descriptions of this class, - Core::ProgressManager, and Find::SearchResultWindow. - - \sa replaceAll() - \sa Core::ProgressManager - \sa Find::SearchResultWindow -*/ - -/*! - \fn void IFindFilter::replaceAll(const QString &txt, Find::FindFlags findFlags) - Override this function if you want to support search and replace. - - This function is called when the user selected this find scope and - initiated a search and replace. - The default implementation does nothing. - - You should start a thread which actually performs the search for \a txt - using the given \a findFlags - (add it to Core::ProgressManager for a progress bar!) and presents the - search results to the user (using the \gui{Search Results} output pane). - For more information see the descriptions of this class, - Core::ProgressManager, and Find::SearchResultWindow. - - \sa findAll() - \sa Core::ProgressManager - \sa Find::SearchResultWindow -*/ - -/*! - \fn QWidget *IFindFilter::createConfigWidget() - Returns a widget that contains additional controls for options - for this find filter. - - The widget will be shown below the common options in the \gui {Advanced Find} - dialog. It will be reparented and deleted by the find plugin. -*/ - -/*! - \fn void IFindFilter::writeSettings(QSettings *settings) - Called at shutdown to write the state of the additional options - for this find filter to the \a settings. -*/ - -/*! - \fn void IFindFilter::readSettings(QSettings *settings) - Called at startup to read the state of the additional options - for this find filter from the \a settings. -*/ - -/*! - \fn void IFindFilter::enabledChanged(bool enabled) - - Signals that the enabled state of this find filter has changed. -*/ - -/*! - \fn Find::FindFlags BaseTextFind::supportedFindFlags() const - Returns the find flags, like whole words or regular expressions, - that this find filter supports. - - Depending on the returned value, the default find option widgets are - enabled or disabled. - The default is Find::FindCaseSensitively, Find::FindRegularExpression - and Find::FindWholeWords -*/ - -namespace Find { - -FindFlags IFindFilter::supportedFindFlags() const -{ - return FindCaseSensitively - | FindRegularExpression | FindWholeWords; -} - -QPixmap IFindFilter::pixmapForFindFlags(FindFlags flags) -{ - static const QPixmap casesensitiveIcon = QPixmap(QLatin1String(":/find/images/casesensitively.png")); - static const QPixmap regexpIcon = QPixmap(QLatin1String(":/find/images/regexp.png")); - static const QPixmap wholewordsIcon = QPixmap(QLatin1String(":/find/images/wholewords.png")); - static const QPixmap preservecaseIcon = QPixmap(QLatin1String(":/find/images/preservecase.png")); - bool casesensitive = flags & FindCaseSensitively; - bool wholewords = flags & FindWholeWords; - bool regexp = flags & FindRegularExpression; - bool preservecase = flags & FindPreserveCase; - int width = 0; - if (casesensitive) width += 6; - if (wholewords) width += 6; - if (regexp) width += 6; - if (preservecase) width += 6; - if (width > 0) --width; - QPixmap pixmap(width, 17); - pixmap.fill(Qt::transparent); - QPainter painter(&pixmap); - int x = 0; - - if (casesensitive) { - painter.drawPixmap(x - 6, 0, casesensitiveIcon); - x += 6; - } - if (wholewords) { - painter.drawPixmap(x - 6, 0, wholewordsIcon); - x += 6; - } - if (regexp) { - painter.drawPixmap(x - 6, 0, regexpIcon); - x += 6; - } - if (preservecase) - painter.drawPixmap(x - 6, 0, preservecaseIcon); - return pixmap; -} - -QString IFindFilter::descriptionForFindFlags(FindFlags flags) -{ - QStringList flagStrings; - if (flags & FindCaseSensitively) - flagStrings.append(tr("Case sensitive")); - if (flags & FindWholeWords) - flagStrings.append(tr("Whole words")); - if (flags & FindRegularExpression) - flagStrings.append(tr("Regular expressions")); - if (flags & FindPreserveCase) - flagStrings.append(tr("Preserve case")); - QString description = tr("Flags: %1"); - if (flagStrings.isEmpty()) - description = description.arg(tr("None")); - else - description = description.arg(flagStrings.join(tr(", "))); - return description; -} - -} // namespace Find diff --git a/src/plugins/find/ifindfilter.h b/src/plugins/find/ifindfilter.h deleted file mode 100644 index 378762c04d9..00000000000 --- a/src/plugins/find/ifindfilter.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef IFINDFILTER_H -#define IFINDFILTER_H - -#include "find_global.h" -#include "textfindconstants.h" - -QT_BEGIN_NAMESPACE -class QWidget; -class QSettings; -class QKeySequence; -class Pixmap; -QT_END_NAMESPACE - -namespace Find { - -class FIND_EXPORT IFindFilter : public QObject -{ - Q_OBJECT -public: - - virtual ~IFindFilter() {} - - virtual QString id() const = 0; - virtual QString displayName() const = 0; - /// - virtual bool isEnabled() const = 0; - virtual QKeySequence defaultShortcut() const; - virtual bool isReplaceSupported() const { return false; } - virtual FindFlags supportedFindFlags() const; - - virtual void findAll(const QString &txt, FindFlags findFlags) = 0; - virtual void replaceAll(const QString &txt, FindFlags findFlags) - { Q_UNUSED(txt) Q_UNUSED(findFlags) } - - virtual QWidget *createConfigWidget() { return 0; } - virtual void writeSettings(QSettings *settings) { Q_UNUSED(settings) } - virtual void readSettings(QSettings *settings) { Q_UNUSED(settings) } - - static QPixmap pixmapForFindFlags(FindFlags flags); - static QString descriptionForFindFlags(FindFlags flags); -signals: - void enabledChanged(bool enabled); -}; - -} // namespace Find - -#endif // IFINDFILTER_H diff --git a/src/plugins/find/ifindsupport.cpp b/src/plugins/find/ifindsupport.cpp deleted file mode 100644 index a001fc08660..00000000000 --- a/src/plugins/find/ifindsupport.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "ifindsupport.h" - -#include -#include -#include -#include -#include - -namespace Find { -namespace Internal { - -class WrapIndicator : public QWidget -{ - Q_OBJECT - Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity USER true) - -public: - WrapIndicator(QWidget *parent = 0) - : QWidget(parent), - m_opacity(1.0) - { - if (parent) - setGeometry(QRect(parent->rect().center() - QPoint(25, 25), - parent->rect().center() + QPoint(25, 25))); - } - - qreal opacity() const { return m_opacity; } - void setOpacity(qreal value) { m_opacity = value; update(); } - - void run() - { - show(); - QTimer::singleShot(300, this, SLOT(runInternal())); - } - -protected: - void paintEvent(QPaintEvent *) - { - static QPixmap foreground(QLatin1String(":/find/images/wrapindicator.png")); - QPainter p(this); - p.setOpacity(m_opacity); - p.drawPixmap(rect(), foreground); - } - -private slots: - void runInternal() - { - QPropertyAnimation *anim = new QPropertyAnimation(this, "opacity", this); - anim->setDuration(200); - anim->setEndValue(0.); - connect(anim, SIGNAL(finished()), this, SLOT(deleteLater())); - anim->start(QAbstractAnimation::DeleteWhenStopped); - } - -private: - qreal m_opacity; -}; - -} // Internal -} // Find - -using namespace Find; - -void IFindSupport::replace(const QString &before, const QString &after, FindFlags findFlags) -{ - Q_UNUSED(before) - Q_UNUSED(after) - Q_UNUSED(findFlags) -} - -bool IFindSupport::replaceStep(const QString &before, const QString &after, FindFlags findFlags) -{ - Q_UNUSED(before) - Q_UNUSED(after) - Q_UNUSED(findFlags) - return false; -} - -int IFindSupport::replaceAll(const QString &before, const QString &after, FindFlags findFlags) -{ - Q_UNUSED(before) - Q_UNUSED(after) - Q_UNUSED(findFlags) - return 0; -} - -void IFindSupport::showWrapIndicator(QWidget *parent) -{ - (new Internal::WrapIndicator(parent))->run(); -} - -#include "ifindsupport.moc" diff --git a/src/plugins/find/ifindsupport.h b/src/plugins/find/ifindsupport.h deleted file mode 100644 index d5b80023670..00000000000 --- a/src/plugins/find/ifindsupport.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef IFINDSUPPORT_H -#define IFINDSUPPORT_H - -#include "find_global.h" -#include "textfindconstants.h" - -#include -#include - -namespace Find { - -class FIND_EXPORT IFindSupport : public QObject -{ - Q_OBJECT - -public: - enum Result { Found, NotFound, NotYetFound }; - - IFindSupport() : QObject(0) {} - virtual ~IFindSupport() {} - - virtual bool supportsReplace() const = 0; - virtual FindFlags supportedFindFlags() const = 0; - virtual void resetIncrementalSearch() = 0; - virtual void clearResults() = 0; - virtual QString currentFindString() const = 0; - virtual QString completedFindString() const = 0; - - virtual void highlightAll(const QString &txt, FindFlags findFlags); - virtual Result findIncremental(const QString &txt, FindFlags findFlags) = 0; - virtual Result findStep(const QString &txt, FindFlags findFlags) = 0; - virtual void replace(const QString &before, const QString &after, - FindFlags findFlags); - virtual bool replaceStep(const QString &before, const QString &after, - FindFlags findFlags); - virtual int replaceAll(const QString &before, const QString &after, - FindFlags findFlags); - - virtual void defineFindScope(){} - virtual void clearFindScope(){} - - static void showWrapIndicator(QWidget *parent); - -signals: - void changed(); -}; - -inline void IFindSupport::highlightAll(const QString &, FindFlags) {} - -} // namespace Find - -#endif // IFINDSUPPORT_H diff --git a/src/plugins/find/images/all.png b/src/plugins/find/images/all.png deleted file mode 100644 index f5c1c1f767d..00000000000 Binary files a/src/plugins/find/images/all.png and /dev/null differ diff --git a/src/plugins/find/images/casesensitively.png b/src/plugins/find/images/casesensitively.png deleted file mode 100644 index 029b41faa4d..00000000000 Binary files a/src/plugins/find/images/casesensitively.png and /dev/null differ diff --git a/src/plugins/find/images/empty.png b/src/plugins/find/images/empty.png deleted file mode 100644 index f02154247c2..00000000000 Binary files a/src/plugins/find/images/empty.png and /dev/null differ diff --git a/src/plugins/find/images/expand.png b/src/plugins/find/images/expand.png deleted file mode 100644 index 48fcb9b703b..00000000000 Binary files a/src/plugins/find/images/expand.png and /dev/null differ diff --git a/src/plugins/find/images/next.png b/src/plugins/find/images/next.png deleted file mode 100644 index 1844929119b..00000000000 Binary files a/src/plugins/find/images/next.png and /dev/null differ diff --git a/src/plugins/find/images/preservecase.png b/src/plugins/find/images/preservecase.png deleted file mode 100644 index 4869aabd719..00000000000 Binary files a/src/plugins/find/images/preservecase.png and /dev/null differ diff --git a/src/plugins/find/images/previous.png b/src/plugins/find/images/previous.png deleted file mode 100644 index 4fe50af9a87..00000000000 Binary files a/src/plugins/find/images/previous.png and /dev/null differ diff --git a/src/plugins/find/images/regexp.png b/src/plugins/find/images/regexp.png deleted file mode 100644 index be8a5cc48cb..00000000000 Binary files a/src/plugins/find/images/regexp.png and /dev/null differ diff --git a/src/plugins/find/images/replace_all.png b/src/plugins/find/images/replace_all.png deleted file mode 100644 index d2298a8aade..00000000000 Binary files a/src/plugins/find/images/replace_all.png and /dev/null differ diff --git a/src/plugins/find/images/wholewords.png b/src/plugins/find/images/wholewords.png deleted file mode 100644 index 0ffcecd963c..00000000000 Binary files a/src/plugins/find/images/wholewords.png and /dev/null differ diff --git a/src/plugins/find/images/wordandcase.png b/src/plugins/find/images/wordandcase.png deleted file mode 100644 index 34c0ac31908..00000000000 Binary files a/src/plugins/find/images/wordandcase.png and /dev/null differ diff --git a/src/plugins/find/images/wrapindicator.png b/src/plugins/find/images/wrapindicator.png deleted file mode 100644 index a4f8ddf4177..00000000000 Binary files a/src/plugins/find/images/wrapindicator.png and /dev/null differ diff --git a/src/plugins/find/searchresultcolor.h b/src/plugins/find/searchresultcolor.h deleted file mode 100644 index fab3e06bb28..00000000000 --- a/src/plugins/find/searchresultcolor.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SEARCHRESULTCOLOR_H -#define SEARCHRESULTCOLOR_H - -#include - -namespace Find { -namespace Internal { - -class SearchResultColor{ -public: - QColor textBackground; - QColor textForeground; - QColor highlightBackground; - QColor highlightForeground; -}; - -} // namespace Internal -} // namespace Find - -#endif // SEARCHRESULTCOLOR_H diff --git a/src/plugins/find/searchresulttreeitemdelegate.cpp b/src/plugins/find/searchresulttreeitemdelegate.cpp deleted file mode 100644 index 3f9e9b20981..00000000000 --- a/src/plugins/find/searchresulttreeitemdelegate.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "searchresulttreeitemdelegate.h" -#include "searchresulttreeitemroles.h" - -#include -#include - -#include -#include - -using namespace Find::Internal; - -SearchResultTreeItemDelegate::SearchResultTreeItemDelegate(QObject *parent) - : QItemDelegate(parent) -{ -} - -void SearchResultTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - static const int iconSize = 16; - - painter->save(); - - QStyleOptionViewItemV3 opt = setOptions(index, option); - painter->setFont(opt.font); - - QItemDelegate::drawBackground(painter, opt, index); - - // ---- do the layout - QRect checkRect; - QRect pixmapRect; - QRect textRect; - - // check mark - bool checkable = (index.model()->flags(index) & Qt::ItemIsUserCheckable); - Qt::CheckState checkState = Qt::Unchecked; - if (checkable) { - QVariant checkStateData = index.data(Qt::CheckStateRole); - checkState = static_cast(checkStateData.toInt()); -#if QT_VERSION >= 0x050000 - checkRect = doCheck(opt, opt.rect, checkStateData); -#else // Qt4 - checkRect = check(opt, opt.rect, checkStateData); -#endif - } - - // icon - QIcon icon = index.model()->data(index, ItemDataRoles::ResultIconRole).value(); - if (!icon.isNull()) - pixmapRect = QRect(0, 0, iconSize, iconSize); - - // text - textRect = opt.rect.adjusted(0, 0, checkRect.width() + pixmapRect.width(), 0); - - // do layout - doLayout(opt, &checkRect, &pixmapRect, &textRect, false); - - // ---- draw the items - // icon - if (!icon.isNull()) - QItemDelegate::drawDecoration(painter, opt, pixmapRect, icon.pixmap(iconSize)); - - // line numbers - int lineNumberAreaWidth = drawLineNumber(painter, opt, textRect, index); - textRect.adjust(lineNumberAreaWidth, 0, 0, 0); - - // text and focus/selection - drawText(painter, opt, textRect, index); - QItemDelegate::drawFocus(painter, opt, opt.rect); - - // check mark - if (checkable) - QItemDelegate::drawCheck(painter, opt, checkRect, checkState); - - painter->restore(); -} - -// returns the width of the line number area -int SearchResultTreeItemDelegate::drawLineNumber(QPainter *painter, const QStyleOptionViewItemV3 &option, - const QRect &rect, - const QModelIndex &index) const -{ - static const int lineNumberAreaHorizontalPadding = 4; - int lineNumber = index.model()->data(index, ItemDataRoles::ResultLineNumberRole).toInt(); - if (lineNumber < 1) - return 0; - const bool isSelected = option.state & QStyle::State_Selected; - QString lineText = QString::number(lineNumber); - int minimumLineNumberDigits = qMax((int)m_minimumLineNumberDigits, lineText.count()); - int fontWidth = painter->fontMetrics().width(QString(minimumLineNumberDigits, QLatin1Char('0'))); - int lineNumberAreaWidth = lineNumberAreaHorizontalPadding + fontWidth + lineNumberAreaHorizontalPadding; - QRect lineNumberAreaRect(rect); - lineNumberAreaRect.setWidth(lineNumberAreaWidth); - - QPalette::ColorGroup cg = QPalette::Normal; - if (!(option.state & QStyle::State_Active)) - cg = QPalette::Inactive; - else if (!(option.state & QStyle::State_Enabled)) - cg = QPalette::Disabled; - - painter->fillRect(lineNumberAreaRect, QBrush(isSelected ? - option.palette.brush(cg, QPalette::Highlight) : - option.palette.color(cg, QPalette::Base).darker(111))); - - QStyleOptionViewItemV3 opt = option; - opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; - opt.palette.setColor(cg, QPalette::Text, Qt::darkGray); - - const QStyle *style = QApplication::style(); - const int textMargin = style->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, 0) + 1; - - const QRect rowRect = lineNumberAreaRect.adjusted(-textMargin, 0, textMargin-lineNumberAreaHorizontalPadding, 0); - QItemDelegate::drawDisplay(painter, opt, rowRect, lineText); - - return lineNumberAreaWidth; -} - -void SearchResultTreeItemDelegate::drawText(QPainter *painter, - const QStyleOptionViewItem &option, - const QRect &rect, - const QModelIndex &index) const -{ - QString text = index.model()->data(index, Qt::DisplayRole).toString(); - // show number of subresults in displayString - if (index.model()->hasChildren(index)) { - text += QLatin1String(" (") - + QString::number(index.model()->rowCount(index)) - + QLatin1Char(')'); - } - - const int searchTermStart = index.model()->data(index, ItemDataRoles::SearchTermStartRole).toInt(); - int searchTermLength = index.model()->data(index, ItemDataRoles::SearchTermLengthRole).toInt(); - if (searchTermStart < 0 || searchTermStart >= text.length() || searchTermLength < 1) { - QItemDelegate::drawDisplay(painter, option, rect, text); - return; - } - // clip searchTermLength to end of line - searchTermLength = qMin(searchTermLength, text.length() - searchTermStart); - const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; - int searchTermStartPixels = painter->fontMetrics().width(text.left(searchTermStart)); - int searchTermLengthPixels = painter->fontMetrics().width(text.mid(searchTermStart, searchTermLength)); - - // rects - QRect beforeHighlightRect(rect); - beforeHighlightRect.setRight(beforeHighlightRect.left() + searchTermStartPixels); - - QRect resultHighlightRect(rect); - resultHighlightRect.setLeft(beforeHighlightRect.right()); - resultHighlightRect.setRight(resultHighlightRect.left() + searchTermLengthPixels); - - QRect afterHighlightRect(rect); - afterHighlightRect.setLeft(resultHighlightRect.right()); - - // paint all highlight backgrounds - // qitemdelegate has problems with painting background when highlighted - // (highlighted background at wrong position because text is offset with textMargin) - // so we duplicate a lot here, see qitemdelegate for reference - bool isSelected = option.state & QStyle::State_Selected; - QPalette::ColorGroup cg = option.state & QStyle::State_Enabled - ? QPalette::Normal : QPalette::Disabled; - if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) - cg = QPalette::Inactive; - QStyleOptionViewItem baseOption = option; - baseOption.state &= ~QStyle::State_Selected; - if (isSelected) { - painter->fillRect(beforeHighlightRect.adjusted(textMargin, 0, textMargin, 0), - option.palette.brush(cg, QPalette::Highlight)); - painter->fillRect(afterHighlightRect.adjusted(textMargin, 0, textMargin, 0), - option.palette.brush(cg, QPalette::Highlight)); - } - const QColor highlightBackground = - index.model()->data(index, ItemDataRoles::ResultHighlightBackgroundColor).value(); - painter->fillRect(resultHighlightRect.adjusted(textMargin, 0, textMargin - 1, 0), QBrush(highlightBackground)); - - // Text before the highlighting - QStyleOptionViewItem noHighlightOpt = baseOption; - noHighlightOpt.rect = beforeHighlightRect; - noHighlightOpt.textElideMode = Qt::ElideNone; - if (isSelected) - noHighlightOpt.palette.setColor(QPalette::Text, noHighlightOpt.palette.color(cg, QPalette::HighlightedText)); - QItemDelegate::drawDisplay(painter, noHighlightOpt, - beforeHighlightRect, text.mid(0, searchTermStart)); - - // Highlight text - QStyleOptionViewItem highlightOpt = noHighlightOpt; - const QColor highlightForeground = - index.model()->data(index, ItemDataRoles::ResultHighlightForegroundColor).value(); - highlightOpt.palette.setColor(QPalette::Text, highlightForeground); - QItemDelegate::drawDisplay(painter, highlightOpt, resultHighlightRect, - text.mid(searchTermStart, searchTermLength)); - - // Text after the Highlight - noHighlightOpt.rect = afterHighlightRect; - QItemDelegate::drawDisplay(painter, noHighlightOpt, afterHighlightRect, - text.mid(searchTermStart + searchTermLength)); -} diff --git a/src/plugins/find/searchresulttreeitemdelegate.h b/src/plugins/find/searchresulttreeitemdelegate.h deleted file mode 100644 index e91882bd79d..00000000000 --- a/src/plugins/find/searchresulttreeitemdelegate.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef SEARCHRESULTTREEITEMDELEGATE_H -#define SEARCHRESULTTREEITEMDELEGATE_H - -#include - -namespace Find { -namespace Internal { - -class SearchResultTreeItemDelegate: public QItemDelegate -{ -public: - SearchResultTreeItemDelegate(QObject *parent = 0); - void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; - -private: - int drawLineNumber(QPainter *painter, const QStyleOptionViewItemV3 &option, const QRect &rect, const QModelIndex &index) const; - void drawText(QPainter *painter, const QStyleOptionViewItem &option, - const QRect &rect, const QModelIndex &index) const; - - static const int m_minimumLineNumberDigits = 6; -}; - -} // namespace Internal -} // namespace Find - -#endif // SEARCHRESULTTREEITEMDELEGATE_H diff --git a/src/plugins/find/searchresulttreeitemroles.h b/src/plugins/find/searchresulttreeitemroles.h deleted file mode 100644 index 80cda671ca3..00000000000 --- a/src/plugins/find/searchresulttreeitemroles.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef SEARCHRESULTTREEITEMROLES_H -#define SEARCHRESULTTREEITEMROLES_H - -#include - -namespace Find { -namespace Internal { -namespace ItemDataRoles { - -enum Roles -{ - ResultItemRole = Qt::UserRole, - ResultLineRole, - ResultLineNumberRole, - ResultIconRole, - ResultHighlightBackgroundColor, - ResultHighlightForegroundColor, - SearchTermStartRole, - SearchTermLengthRole, - IsGeneratedRole -}; - -} // namespace Internal -} // namespace Find -} // namespace ItemDataRoles - -#endif // SEARCHRESULTTREEITEMROLES_H diff --git a/src/plugins/find/searchresulttreeitems.cpp b/src/plugins/find/searchresulttreeitems.cpp deleted file mode 100644 index a49e4d03e16..00000000000 --- a/src/plugins/find/searchresulttreeitems.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "searchresulttreeitems.h" - -namespace Find { -namespace Internal { - -SearchResultTreeItem::SearchResultTreeItem(const SearchResultItem &item, - SearchResultTreeItem *parent) - : item(item), - m_parent(parent), - m_isUserCheckable(false), - m_isGenerated(false), - m_checkState(Qt::Unchecked) -{ -} - -SearchResultTreeItem::~SearchResultTreeItem() -{ - clearChildren(); -} - -bool SearchResultTreeItem::isLeaf() const -{ - return childrenCount() == 0 && parent() != 0; -} - -bool SearchResultTreeItem::isUserCheckable() const -{ - return m_isUserCheckable; -} - -void SearchResultTreeItem::setIsUserCheckable(bool isUserCheckable) -{ - m_isUserCheckable = isUserCheckable; -} - -Qt::CheckState SearchResultTreeItem::checkState() const -{ - return m_checkState; -} - -void SearchResultTreeItem::setCheckState(Qt::CheckState checkState) -{ - m_checkState = checkState; -} - -void SearchResultTreeItem::clearChildren() -{ - qDeleteAll(m_children); - m_children.clear(); -} - -int SearchResultTreeItem::childrenCount() const -{ - return m_children.count(); -} - -int SearchResultTreeItem::rowOfItem() const -{ - return (m_parent ? m_parent->m_children.indexOf(const_cast(this)):0); -} - -SearchResultTreeItem* SearchResultTreeItem::childAt(int index) const -{ - return m_children.at(index); -} - -SearchResultTreeItem *SearchResultTreeItem::parent() const -{ - return m_parent; -} - -static bool lessThanByText(SearchResultTreeItem *a, const QString &b) -{ - return a->item.text < b; -} - -int SearchResultTreeItem::insertionIndex(const QString &text, SearchResultTreeItem **existingItem) const -{ - QList::const_iterator insertionPosition = - qLowerBound(m_children.begin(), m_children.end(), text, lessThanByText); - if (existingItem) { - if (insertionPosition != m_children.end() && (*insertionPosition)->item.text == text) - (*existingItem) = (*insertionPosition); - else - *existingItem = 0; - } - return insertionPosition - m_children.begin(); -} - -int SearchResultTreeItem::insertionIndex(const SearchResultItem &item, SearchResultTreeItem **existingItem) const -{ - return insertionIndex(item.text, existingItem); -} - -void SearchResultTreeItem::insertChild(int index, SearchResultTreeItem *child) -{ - m_children.insert(index, child); -} - -void SearchResultTreeItem::insertChild(int index, const SearchResultItem &item) -{ - SearchResultTreeItem *child = new SearchResultTreeItem(item, this); - if (isUserCheckable()) { - child->setIsUserCheckable(true); - child->setCheckState(Qt::Checked); - } - insertChild(index, child); -} - -void SearchResultTreeItem::appendChild(const SearchResultItem &item) -{ - insertChild(m_children.count(), item); -} - -} // namespace Internal -} // namespace Find diff --git a/src/plugins/find/searchresulttreeitems.h b/src/plugins/find/searchresulttreeitems.h deleted file mode 100644 index e64c93e7598..00000000000 --- a/src/plugins/find/searchresulttreeitems.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef SEARCHRESULTTREEITEMS_H -#define SEARCHRESULTTREEITEMS_H - -#include "searchresultwindow.h" - -#include -#include - -namespace Find { -namespace Internal { - -class SearchResultTreeItem -{ -public: - explicit SearchResultTreeItem(const SearchResultItem &item = SearchResultItem(), - SearchResultTreeItem *parent = NULL); - virtual ~SearchResultTreeItem(); - - bool isLeaf() const; - SearchResultTreeItem *parent() const; - SearchResultTreeItem *childAt(int index) const; - int insertionIndex(const QString &text, SearchResultTreeItem **existingItem) const; - int insertionIndex(const SearchResultItem &item, SearchResultTreeItem **existingItem) const; - void insertChild(int index, SearchResultTreeItem *child); - void insertChild(int index, const SearchResultItem &item); - void appendChild(const SearchResultItem &item); - int childrenCount() const; - int rowOfItem() const; - void clearChildren(); - - bool isUserCheckable() const; - void setIsUserCheckable(bool isUserCheckable); - - Qt::CheckState checkState() const; - void setCheckState(Qt::CheckState checkState); - - bool isGenerated() const { return m_isGenerated; } - void setGenerated(bool value) { m_isGenerated = value; } - - SearchResultItem item; - -private: - SearchResultTreeItem *m_parent; - QList m_children; - bool m_isUserCheckable; - bool m_isGenerated; - Qt::CheckState m_checkState; -}; - -} // namespace Internal -} // namespace Find - -#endif // SEARCHRESULTTREEITEMS_H diff --git a/src/plugins/find/searchresulttreemodel.cpp b/src/plugins/find/searchresulttreemodel.cpp deleted file mode 100644 index feca87cc39d..00000000000 --- a/src/plugins/find/searchresulttreemodel.cpp +++ /dev/null @@ -1,504 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "searchresulttreemodel.h" -#include "searchresulttreeitems.h" -#include "searchresulttreeitemroles.h" - -#include -#include -#include -#include - -using namespace Find; -using namespace Find::Internal; - -SearchResultTreeModel::SearchResultTreeModel(QObject *parent) - : QAbstractItemModel(parent) - , m_currentParent(0) - , m_showReplaceUI(false) - , m_editorFontIsUsed(false) -{ - m_rootItem = new SearchResultTreeItem; - m_textEditorFont = QFont(QLatin1String("Courier")); -} - -SearchResultTreeModel::~SearchResultTreeModel() -{ - delete m_rootItem; -} - -void SearchResultTreeModel::setShowReplaceUI(bool show) -{ - m_showReplaceUI = show; -} - -void SearchResultTreeModel::setTextEditorFont(const QFont &font, const SearchResultColor color) -{ - layoutAboutToBeChanged(); - m_textEditorFont = font; - m_color = color; - layoutChanged(); -} - -Qt::ItemFlags SearchResultTreeModel::flags(const QModelIndex &idx) const -{ - Qt::ItemFlags flags = QAbstractItemModel::flags(idx); - - if (idx.isValid()) { - if (const SearchResultTreeItem *item = treeItemAtIndex(idx)) { - if (item->isUserCheckable()) - flags |= Qt::ItemIsUserCheckable; - } - } - - return flags; -} - -QModelIndex SearchResultTreeModel::index(int row, int column, - const QModelIndex &parent) const -{ - if (!hasIndex(row, column, parent)) - return QModelIndex(); - - const SearchResultTreeItem *parentItem; - - if (!parent.isValid()) - parentItem = m_rootItem; - else - parentItem = treeItemAtIndex(parent); - - const SearchResultTreeItem *childItem = parentItem->childAt(row); - if (childItem) - return createIndex(row, column, (void *)childItem); - else - return QModelIndex(); -} - -QModelIndex SearchResultTreeModel::index(SearchResultTreeItem *item) const -{ - return createIndex(item->rowOfItem(), 0, (void *)item); -} - -QModelIndex SearchResultTreeModel::parent(const QModelIndex &idx) const -{ - if (!idx.isValid()) - return QModelIndex(); - - const SearchResultTreeItem *childItem = treeItemAtIndex(idx); - const SearchResultTreeItem *parentItem = childItem->parent(); - - if (parentItem == m_rootItem) - return QModelIndex(); - - return createIndex(parentItem->rowOfItem(), 0, (void *)parentItem); -} - -int SearchResultTreeModel::rowCount(const QModelIndex &parent) const -{ - if (parent.column() > 0) - return 0; - - const SearchResultTreeItem *parentItem; - - if (!parent.isValid()) - parentItem = m_rootItem; - else - parentItem = treeItemAtIndex(parent); - - return parentItem->childrenCount(); -} - -int SearchResultTreeModel::columnCount(const QModelIndex &parent) const -{ - Q_UNUSED(parent) - return 1; -} - -SearchResultTreeItem *SearchResultTreeModel::treeItemAtIndex(const QModelIndex &idx) const -{ - return static_cast(idx.internalPointer()); -} - -QVariant SearchResultTreeModel::data(const QModelIndex &idx, int role) const -{ - if (!idx.isValid()) - return QVariant(); - - QVariant result; - - if (role == Qt::SizeHintRole) { - int height = QApplication::fontMetrics().height(); - if (m_editorFontIsUsed) { - const int editorFontHeight = QFontMetrics(m_textEditorFont).height(); - height = qMax(height, editorFontHeight); - } - result = QSize(0, height); - } else { - result = data(treeItemAtIndex(idx), role); - } - - return result; -} - -bool SearchResultTreeModel::setData(const QModelIndex &idx, const QVariant &value, int role) -{ - if (role == Qt::CheckStateRole) { - Qt::CheckState checkState = static_cast(value.toInt()); - return setCheckState(idx, checkState); - } - return QAbstractItemModel::setData(idx, value, role); -} - -bool SearchResultTreeModel::setCheckState(const QModelIndex &idx, Qt::CheckState checkState, bool firstCall) -{ - SearchResultTreeItem *item = treeItemAtIndex(idx); - if (item->checkState() == checkState) - return false; - item->setCheckState(checkState); - if (firstCall) { - emit dataChanged(idx, idx); - // check parents - SearchResultTreeItem *currentItem = item; - QModelIndex currentIndex = idx; - while (SearchResultTreeItem *parent = currentItem->parent()) { - if (parent->isUserCheckable()) { - bool hasChecked = false; - bool hasUnchecked = false; - for (int i = 0; i < parent->childrenCount(); ++i) { - SearchResultTreeItem *child = parent->childAt(i); - if (!child->isUserCheckable()) - continue; - if (child->checkState() == Qt::Checked) - hasChecked = true; - else if (child->checkState() == Qt::Unchecked) - hasUnchecked = true; - else if (child->checkState() == Qt::PartiallyChecked) - hasChecked = hasUnchecked = true; - } - if (hasChecked && hasUnchecked) - parent->setCheckState(Qt::PartiallyChecked); - else if (hasChecked) - parent->setCheckState(Qt::Checked); - else - parent->setCheckState(Qt::Unchecked); - emit dataChanged(idx.parent(), idx.parent()); - } - currentItem = parent; - currentIndex = idx.parent(); - } - } - // check children - if (int children = item->childrenCount()) { - for (int i = 0; i < children; ++i) { - setCheckState(idx.child(i, 0), checkState, false); - } - emit dataChanged(idx.child(0, 0), idx.child(children-1, 0)); - } - return true; -} - -void setDataInternal(const QModelIndex &index, const QVariant &value, int role); - -QVariant SearchResultTreeModel::data(const SearchResultTreeItem *row, int role) const -{ - QVariant result; - - switch (role) - { - case Qt::CheckStateRole: - if (row->isUserCheckable()) - result = row->checkState(); - break; - case Qt::ToolTipRole: - result = row->item.text.trimmed(); - break; - case Qt::FontRole: - if (row->item.useTextEditorFont) - result = m_textEditorFont; - else - result = QVariant(); - break; - case Qt::TextColorRole: - result = m_color.textForeground; - break; - case Qt::BackgroundRole: - result = m_color.textBackground; - break; - case ItemDataRoles::ResultLineRole: - case Qt::DisplayRole: - result = row->item.text; - break; - case ItemDataRoles::ResultItemRole: - result = qVariantFromValue(row->item); - break; - case ItemDataRoles::ResultLineNumberRole: - result = row->item.lineNumber; - break; - case ItemDataRoles::ResultIconRole: - result = row->item.icon; - break; - case ItemDataRoles::ResultHighlightBackgroundColor: - result = m_color.highlightBackground; - break; - case ItemDataRoles::ResultHighlightForegroundColor: - result = m_color.highlightForeground; - break; - case ItemDataRoles::SearchTermStartRole: - result = row->item.textMarkPos; - break; - case ItemDataRoles::SearchTermLengthRole: - result = row->item.textMarkLength; - break; - case ItemDataRoles::IsGeneratedRole: - result = row->isGenerated(); - break; - default: - result = QVariant(); - break; - } - - return result; -} - -QVariant SearchResultTreeModel::headerData(int section, Qt::Orientation orientation, - int role) const -{ - Q_UNUSED(section) - Q_UNUSED(orientation) - Q_UNUSED(role) - return QVariant(); -} - -/** - * Makes sure that the nodes for a specific path exist and sets - * m_currentParent to the last final - */ -QSet SearchResultTreeModel::addPath(const QStringList &path) -{ - QSet pathNodes; - SearchResultTreeItem *currentItem = m_rootItem; - QModelIndex currentItemIndex = QModelIndex(); - SearchResultTreeItem *partItem = 0; - QStringList currentPath; - foreach (const QString &part, path) { - const int insertionIndex = currentItem->insertionIndex(part, &partItem); - if (!partItem) { - SearchResultItem item; - item.path = currentPath; - item.text = part; - partItem = new SearchResultTreeItem(item, currentItem); - if (m_showReplaceUI) { - partItem->setIsUserCheckable(true); - partItem->setCheckState(Qt::Checked); - } - partItem->setGenerated(true); - beginInsertRows(currentItemIndex, insertionIndex, insertionIndex); - currentItem->insertChild(insertionIndex, partItem); - endInsertRows(); - } - pathNodes << partItem; - currentItemIndex = index(insertionIndex, 0, currentItemIndex); - currentItem = partItem; - currentPath << part; - } - - m_currentParent = currentItem; - m_currentPath = currentPath; - m_currentIndex = currentItemIndex; - return pathNodes; -} - -void SearchResultTreeModel::addResultsToCurrentParent(const QList &items, SearchResult::AddMode mode) -{ - if (!m_currentParent) - return; - - if (mode == SearchResult::AddOrdered) { - // this is the mode for e.g. text search - beginInsertRows(m_currentIndex, m_currentParent->childrenCount(), m_currentParent->childrenCount() + items.count()); - foreach (const SearchResultItem &item, items) { - m_currentParent->appendChild(item); - } - endInsertRows(); - } else if (mode == SearchResult::AddSorted) { - foreach (const SearchResultItem &item, items) { - SearchResultTreeItem *existingItem; - const int insertionIndex = m_currentParent->insertionIndex(item, &existingItem); - if (existingItem) { - existingItem->setGenerated(false); - existingItem->item = item; - QModelIndex itemIndex = m_currentIndex.child(insertionIndex, 0); - dataChanged(itemIndex, itemIndex); - } else { - beginInsertRows(m_currentIndex, insertionIndex, insertionIndex); - m_currentParent->insertChild(insertionIndex, item); - endInsertRows(); - } - } - } - dataChanged(m_currentIndex, m_currentIndex); // Make sure that the number after the file name gets updated -} - -static bool lessThanByPath(const SearchResultItem &a, const SearchResultItem &b) -{ - if (a.path.size() < b.path.size()) - return true; - if (a.path.size() > b.path.size()) - return false; - for (int i = 0; i < a.path.size(); ++i) { - if (a.path.at(i) < b.path.at(i)) - return true; - if (a.path.at(i) > b.path.at(i)) - return false; - } - return false; -} - -/** - * Adds the search result to the list of results, creating nodes for the path when - * necessary. - */ -QList SearchResultTreeModel::addResults(const QList &items, SearchResult::AddMode mode) -{ - QSet pathNodes; - QList sortedItems = items; - qStableSort(sortedItems.begin(), sortedItems.end(), lessThanByPath); - QList itemSet; - foreach (const SearchResultItem &item, sortedItems) { - m_editorFontIsUsed |= item.useTextEditorFont; - if (!m_currentParent || (m_currentPath != item.path)) { - // first add all the items from before - if (!itemSet.isEmpty()) { - addResultsToCurrentParent(itemSet, mode); - itemSet.clear(); - } - // switch parent - pathNodes += addPath(item.path); - } - itemSet << item; - } - if (!itemSet.isEmpty()) { - addResultsToCurrentParent(itemSet, mode); - itemSet.clear(); - } - QList pathIndices; - foreach (SearchResultTreeItem *item, pathNodes) - pathIndices << index(item); - return pathIndices; -} - -void SearchResultTreeModel::clear() -{ - beginResetModel(); - m_currentParent = NULL; - m_rootItem->clearChildren(); - m_editorFontIsUsed = false; - endResetModel(); -} - -QModelIndex SearchResultTreeModel::nextIndex(const QModelIndex &idx, bool *wrapped) const -{ - if (wrapped) - *wrapped = false; - // pathological - if (!idx.isValid()) - return index(0, 0); - - if (rowCount(idx) > 0) { - // node with children - return idx.child(0, 0); - } - // leaf node - QModelIndex nextIndex; - QModelIndex current = idx; - while (!nextIndex.isValid()) { - int row = current.row(); - current = current.parent(); - if (row + 1 < rowCount(current)) { - // Same parent has another child - nextIndex = index(row + 1, 0, current); - } else { - // go up one parent - if (!current.isValid()) { - // we start from the beginning - if (wrapped) - *wrapped = true; - nextIndex = index(0, 0); - } - } - } - return nextIndex; -} - -QModelIndex SearchResultTreeModel::next(const QModelIndex &idx, bool includeGenerated, bool *wrapped) const -{ - QModelIndex value = idx; - do { - value = nextIndex(value, wrapped); - } while (value != idx && !includeGenerated && treeItemAtIndex(value)->isGenerated()); - return value; -} - -QModelIndex SearchResultTreeModel::prevIndex(const QModelIndex &idx, bool *wrapped) const -{ - if (wrapped) - *wrapped = false; - QModelIndex current = idx; - bool checkForChildren = true; - if (current.isValid()) { - int row = current.row(); - if (row > 0) { - current = index(row - 1, 0, current.parent()); - } else { - current = current.parent(); - checkForChildren = !current.isValid(); - if (checkForChildren && wrapped) { - // we start from the end - *wrapped = true; - } - } - } - if (checkForChildren) { - // traverse down the hierarchy - while (int rc = rowCount(current)) { - current = index(rc - 1, 0, current); - } - } - return current; -} - -QModelIndex SearchResultTreeModel::prev(const QModelIndex &idx, bool includeGenerated, bool *wrapped) const -{ - QModelIndex value = idx; - do { - value = prevIndex(value, wrapped); - } while (value != idx && !includeGenerated && treeItemAtIndex(value)->isGenerated()); - return value; -} diff --git a/src/plugins/find/searchresulttreemodel.h b/src/plugins/find/searchresulttreemodel.h deleted file mode 100644 index ad45c6f4b62..00000000000 --- a/src/plugins/find/searchresulttreemodel.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef SEARCHRESULTTREEMODEL_H -#define SEARCHRESULTTREEMODEL_H - -#include "searchresultwindow.h" -#include "searchresultcolor.h" - -#include -#include - -namespace Find { -namespace Internal { - -class SearchResultTreeItem; - -class SearchResultTreeModel : public QAbstractItemModel -{ - Q_OBJECT - -public: - SearchResultTreeModel(QObject *parent = 0); - ~SearchResultTreeModel(); - - void setShowReplaceUI(bool show); - void setTextEditorFont(const QFont &font, const SearchResultColor color); - - Qt::ItemFlags flags(const QModelIndex &index) const; - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; - QModelIndex parent(const QModelIndex &child) const; - int rowCount(const QModelIndex &parent = QModelIndex()) const; - int columnCount(const QModelIndex &parent = QModelIndex()) const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - - QModelIndex next(const QModelIndex &idx, bool includeGenerated = false, bool *wrapped = 0) const; - QModelIndex prev(const QModelIndex &idx, bool includeGenerated = false, bool *wrapped = 0) const; - - QList addResults(const QList &items, SearchResult::AddMode mode); - -signals: - void jumpToSearchResult(const QString &fileName, int lineNumber, - int searchTermStart, int searchTermLength); - -public slots: - void clear(); - -private: - QModelIndex index(SearchResultTreeItem *item) const; - void addResultsToCurrentParent(const QList &items, SearchResult::AddMode mode); - QSet addPath(const QStringList &path); - QVariant data(const SearchResultTreeItem *row, int role) const; - bool setCheckState(const QModelIndex &idx, Qt::CheckState checkState, bool firstCall = true); - QModelIndex nextIndex(const QModelIndex &idx, bool *wrapped = 0) const; - QModelIndex prevIndex(const QModelIndex &idx, bool *wrapped = 0) const; - SearchResultTreeItem *treeItemAtIndex(const QModelIndex &idx) const; - - SearchResultTreeItem *m_rootItem; - SearchResultTreeItem *m_currentParent; - SearchResultColor m_color; - QModelIndex m_currentIndex; - QStringList m_currentPath; // the path that belongs to the current parent - QFont m_textEditorFont; - bool m_showReplaceUI; - bool m_editorFontIsUsed; -}; - -} // namespace Internal -} // namespace Find - -#endif // SEARCHRESULTTREEMODEL_H diff --git a/src/plugins/find/searchresulttreeview.cpp b/src/plugins/find/searchresulttreeview.cpp deleted file mode 100644 index 8b96176264e..00000000000 --- a/src/plugins/find/searchresulttreeview.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "searchresulttreeview.h" -#include "searchresulttreeitemroles.h" -#include "searchresulttreemodel.h" -#include "searchresulttreeitemdelegate.h" - -#include -#include - -namespace Find { -namespace Internal { - -SearchResultTreeView::SearchResultTreeView(QWidget *parent) - : QTreeView(parent) - , m_model(new SearchResultTreeModel(this)) - , m_autoExpandResults(false) -{ - setModel(m_model); - setItemDelegate(new SearchResultTreeItemDelegate(this)); - setIndentation(14); - setUniformRowHeights(true); - setExpandsOnDoubleClick(true); - header()->hide(); - - connect(this, SIGNAL(activated(QModelIndex)), this, SLOT(emitJumpToSearchResult(QModelIndex))); -} - -void SearchResultTreeView::setAutoExpandResults(bool expand) -{ - m_autoExpandResults = expand; -} - -void SearchResultTreeView::setTextEditorFont(const QFont &font, const SearchResultColor color) -{ - m_model->setTextEditorFont(font, color); - - QPalette p = palette(); - p.setColor(QPalette::Base, color.textBackground); - setPalette(p); -} - -void SearchResultTreeView::clear() -{ - m_model->clear(); -} - -void SearchResultTreeView::addResults(const QList &items, SearchResult::AddMode mode) -{ - QList addedParents = m_model->addResults(items, mode); - if (m_autoExpandResults && !addedParents.isEmpty()) { - foreach (const QModelIndex &index, addedParents) - setExpanded(index, true); - } -} - -void SearchResultTreeView::emitJumpToSearchResult(const QModelIndex &index) -{ - if (model()->data(index, ItemDataRoles::IsGeneratedRole).toBool()) - return; - SearchResultItem item = model()->data(index, ItemDataRoles::ResultItemRole).value(); - - emit jumpToSearchResult(item); -} - -void SearchResultTreeView::keyPressEvent(QKeyEvent *e) -{ - if (!e->modifiers() && e->key() == Qt::Key_Return) { - emit activated(currentIndex()); - e->accept(); - return; - } - QTreeView::keyPressEvent(e); -} - -SearchResultTreeModel *SearchResultTreeView::model() const -{ - return m_model; -} - -} // namespace Internal -} // namespace Find diff --git a/src/plugins/find/searchresulttreeview.h b/src/plugins/find/searchresulttreeview.h deleted file mode 100644 index ecf290c90df..00000000000 --- a/src/plugins/find/searchresulttreeview.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef SEARCHRESULTTREEVIEW_H -#define SEARCHRESULTTREEVIEW_H - -#include "searchresultwindow.h" - -#include - -namespace Find { -namespace Internal { - -class SearchResultTreeModel; -class SearchResultColor; - -class SearchResultTreeView : public QTreeView -{ - Q_OBJECT - -public: - explicit SearchResultTreeView(QWidget *parent = 0); - - void setAutoExpandResults(bool expand); - void setTextEditorFont(const QFont &font, const SearchResultColor color); - - SearchResultTreeModel *model() const; - void addResults(const QList &items, SearchResult::AddMode mode); - -signals: - void jumpToSearchResult(const SearchResultItem &item); - -public slots: - void clear(); - void emitJumpToSearchResult(const QModelIndex &index); - -protected: - void keyPressEvent(QKeyEvent *e); - - SearchResultTreeModel *m_model; - bool m_autoExpandResults; -}; - -} // namespace Internal -} // namespace Find - -#endif // SEARCHRESULTTREEVIEW_H diff --git a/src/plugins/find/searchresultwidget.cpp b/src/plugins/find/searchresultwidget.cpp deleted file mode 100644 index bbdfe3d1386..00000000000 --- a/src/plugins/find/searchresultwidget.cpp +++ /dev/null @@ -1,494 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "searchresultwidget.h" -#include "searchresulttreeview.h" -#include "searchresulttreemodel.h" -#include "searchresulttreeitems.h" -#include "searchresulttreeitemroles.h" - -#include "findplugin.h" -#include "treeviewfind.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -static const int SEARCHRESULT_WARNING_LIMIT = 200000; -static const char SIZE_WARNING_ID[] = "sizeWarningLabel"; - -namespace Find { -namespace Internal { - -class WideEnoughLineEdit : public QLineEdit { - Q_OBJECT -public: - WideEnoughLineEdit(QWidget *parent):QLineEdit(parent){ - connect(this, SIGNAL(textChanged(QString)), - this, SLOT(updateGeometry())); - } - ~WideEnoughLineEdit(){} - QSize sizeHint() const { - QSize sh = QLineEdit::minimumSizeHint(); - sh.rwidth() += qMax(25 * fontMetrics().width(QLatin1Char('x')), - fontMetrics().width(text())); - return sh; - } -public slots: - void updateGeometry() { QLineEdit::updateGeometry(); } -}; - -} // Internal -} // Find - -using namespace Find; -using namespace Find::Internal; - -SearchResultWidget::SearchResultWidget(QWidget *parent) : - QWidget(parent), - m_count(0), - m_isShowingReplaceUI(false), - m_searchAgainSupported(false) -{ - QVBoxLayout *layout = new QVBoxLayout(this); - layout->setMargin(0); - layout->setSpacing(0); - setLayout(layout); - - QFrame *topWidget = new QFrame; - QPalette pal = topWidget->palette(); - pal.setColor(QPalette::Window, QColor(255, 255, 225)); - pal.setColor(QPalette::WindowText, Qt::black); - topWidget->setPalette(pal); - topWidget->setFrameStyle(QFrame::Panel | QFrame::Raised); - topWidget->setLineWidth(1); - topWidget->setAutoFillBackground(true); - QHBoxLayout *topLayout = new QHBoxLayout(topWidget); - topLayout->setMargin(2); - topWidget->setLayout(topLayout); - layout->addWidget(topWidget); - - m_messageWidget = new QFrame; - pal.setColor(QPalette::Window, QColor(255, 255, 225)); - pal.setColor(QPalette::WindowText, Qt::red); - m_messageWidget->setPalette(pal); - m_messageWidget->setFrameStyle(QFrame::Panel | QFrame::Raised); - m_messageWidget->setLineWidth(1); - m_messageWidget->setAutoFillBackground(true); - QHBoxLayout *messageLayout = new QHBoxLayout(m_messageWidget); - messageLayout->setMargin(2); - m_messageWidget->setLayout(messageLayout); - QLabel *messageLabel = new QLabel(tr("Search was canceled.")); - messageLabel->setPalette(pal); - messageLayout->addWidget(messageLabel); - layout->addWidget(m_messageWidget); - m_messageWidget->setVisible(false); - - m_searchResultTreeView = new Internal::SearchResultTreeView(this); - m_searchResultTreeView->setFrameStyle(QFrame::NoFrame); - m_searchResultTreeView->setAttribute(Qt::WA_MacShowFocusRect, false); - Aggregation::Aggregate * agg = new Aggregation::Aggregate; - agg->add(m_searchResultTreeView); - agg->add(new TreeViewFind(m_searchResultTreeView, - ItemDataRoles::ResultLineRole)); - layout->addWidget(m_searchResultTreeView); - - m_infoBarDisplay.setTarget(layout, 2); - m_infoBarDisplay.setInfoBar(&m_infoBar); - - m_descriptionContainer = new QWidget(topWidget); - QHBoxLayout *descriptionLayout = new QHBoxLayout(m_descriptionContainer); - m_descriptionContainer->setLayout(descriptionLayout); - descriptionLayout->setMargin(0); - m_descriptionContainer->setMinimumWidth(200); - m_descriptionContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); - m_label = new QLabel(m_descriptionContainer); - m_label->setVisible(false); - m_searchTerm = new QLabel(m_descriptionContainer); - m_searchTerm->setVisible(false); - descriptionLayout->addWidget(m_label); - descriptionLayout->addWidget(m_searchTerm); - m_cancelButton = new QToolButton(topWidget); - m_cancelButton->setText(tr("Cancel")); - m_cancelButton->setToolButtonStyle(Qt::ToolButtonTextOnly); - connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); - m_searchAgainButton = new QToolButton(topWidget); - m_searchAgainButton->setToolTip(tr("Repeat the search with same parameters")); - m_searchAgainButton->setText(tr("Search again")); - m_searchAgainButton->setToolButtonStyle(Qt::ToolButtonTextOnly); - m_searchAgainButton->setVisible(false); - connect(m_searchAgainButton, SIGNAL(clicked()), this, SLOT(searchAgain())); - - m_replaceLabel = new QLabel(tr("Replace with:"), topWidget); - m_replaceTextEdit = new WideEnoughLineEdit(topWidget); - m_replaceTextEdit->setMinimumWidth(120); - m_replaceTextEdit->setEnabled(false); - m_replaceTextEdit->setTabOrder(m_replaceTextEdit, m_searchResultTreeView); - m_replaceButton = new QToolButton(topWidget); - m_replaceButton->setToolTip(tr("Replace all occurrences")); - m_replaceButton->setText(tr("Replace")); - m_replaceButton->setToolButtonStyle(Qt::ToolButtonTextOnly); - m_replaceButton->setEnabled(false); - m_preserveCaseCheck = new QCheckBox(topWidget); - m_preserveCaseCheck->setText(tr("Preserve case")); - m_preserveCaseCheck->setEnabled(false); - - if (FindPlugin * plugin = FindPlugin::instance()) { - m_preserveCaseCheck->setChecked(plugin->hasFindFlag(FindPreserveCase)); - connect(m_preserveCaseCheck, SIGNAL(clicked(bool)), plugin, SLOT(setPreserveCase(bool))); - } - - m_matchesFoundLabel = new QLabel(topWidget); - updateMatchesFoundLabel(); - - topLayout->addWidget(m_descriptionContainer); - topLayout->addWidget(m_cancelButton); - topLayout->addWidget(m_searchAgainButton); - topLayout->addWidget(m_replaceLabel); - topLayout->addWidget(m_replaceTextEdit); - topLayout->addWidget(m_replaceButton); - topLayout->addWidget(m_preserveCaseCheck); - topLayout->addStretch(2); - topLayout->addWidget(m_matchesFoundLabel); - topWidget->setMinimumHeight(m_cancelButton->sizeHint().height() - + topLayout->contentsMargins().top() + topLayout->contentsMargins().bottom() - + topWidget->lineWidth()); - setShowReplaceUI(false); - - connect(m_searchResultTreeView, SIGNAL(jumpToSearchResult(SearchResultItem)), - this, SLOT(handleJumpToSearchResult(SearchResultItem))); - connect(m_replaceTextEdit, SIGNAL(returnPressed()), this, SLOT(handleReplaceButton())); - connect(m_replaceButton, SIGNAL(clicked()), this, SLOT(handleReplaceButton())); -} - -SearchResultWidget::~SearchResultWidget() -{ - if (m_infoBar.containsInfo(Core::Id(SIZE_WARNING_ID))) - cancelAfterSizeWarning(); -} - -void SearchResultWidget::setInfo(const QString &label, const QString &toolTip, const QString &term) -{ - m_label->setText(label); - m_label->setVisible(!label.isEmpty()); - m_descriptionContainer->setToolTip(toolTip); - m_searchTerm->setText(term); - m_searchTerm->setVisible(!term.isEmpty()); -} - -void SearchResultWidget::addResult(const QString &fileName, int lineNumber, const QString &rowText, - int searchTermStart, int searchTermLength, const QVariant &userData) -{ - SearchResultItem item; - item.path = QStringList() << QDir::toNativeSeparators(fileName); - item.lineNumber = lineNumber; - item.text = rowText; - item.textMarkPos = searchTermStart; - item.textMarkLength = searchTermLength; - item.useTextEditorFont = true; - item.userData = userData; - addResults(QList() << item, SearchResult::AddOrdered); -} - -void SearchResultWidget::addResults(const QList &items, SearchResult::AddMode mode) -{ - bool firstItems = (m_count == 0); - m_count += items.size(); - m_searchResultTreeView->addResults(items, mode); - updateMatchesFoundLabel(); - if (firstItems) { - if (!m_dontAskAgainGroup.isEmpty()) { - Core::Id undoWarningId = Core::Id("warninglabel/").withSuffix(m_dontAskAgainGroup); - if (m_infoBar.canInfoBeAdded(undoWarningId)) { - Core::InfoBarEntry info(undoWarningId, tr("This change cannot be undone."), - Core::InfoBarEntry::GlobalSuppressionEnabled); - m_infoBar.addInfo(info); - } - } - - m_replaceTextEdit->setEnabled(true); - // We didn't have an item before, set the focus to the search widget or replace text edit - if (m_isShowingReplaceUI) { - m_replaceTextEdit->setFocus(); - m_replaceTextEdit->selectAll(); - } else { - m_searchResultTreeView->setFocus(); - } - m_searchResultTreeView->selectionModel()->select(m_searchResultTreeView->model()->index(0, 0, QModelIndex()), QItemSelectionModel::Select); - emit navigateStateChanged(); - } else if (m_count <= SEARCHRESULT_WARNING_LIMIT) { - return; - } else { - Core::Id sizeWarningId(SIZE_WARNING_ID); - if (!m_infoBar.canInfoBeAdded(sizeWarningId)) - return; - emit paused(true); - Core::InfoBarEntry info(sizeWarningId, - tr("The search resulted in more than %n items, do you still want to continue?", - 0, SEARCHRESULT_WARNING_LIMIT)); - info.setCancelButtonInfo(tr("Cancel"), this, SLOT(cancelAfterSizeWarning())); - info.setCustomButtonInfo(tr("Continue"), this, SLOT(continueAfterSizeWarning())); - m_infoBar.addInfo(info); - emit requestPopup(false/*no focus*/); - } -} - - - -int SearchResultWidget::count() const -{ - return m_count; -} - -QString SearchResultWidget::dontAskAgainGroup() const -{ - return m_dontAskAgainGroup; -} - -void SearchResultWidget::setDontAskAgainGroup(const QString &group) -{ - m_dontAskAgainGroup = group; -} - - -void SearchResultWidget::setTextToReplace(const QString &textToReplace) -{ - m_replaceTextEdit->setText(textToReplace); -} - -QString SearchResultWidget::textToReplace() const -{ - return m_replaceTextEdit->text(); -} - -void SearchResultWidget::setShowReplaceUI(bool visible) -{ - m_searchResultTreeView->model()->setShowReplaceUI(visible); - m_replaceLabel->setVisible(visible); - m_replaceTextEdit->setVisible(visible); - m_replaceButton->setVisible(visible); - m_preserveCaseCheck->setVisible(visible); - m_isShowingReplaceUI = visible; -} - -bool SearchResultWidget::hasFocusInternally() const -{ - return m_searchResultTreeView->hasFocus() || (m_isShowingReplaceUI && m_replaceTextEdit->hasFocus()); -} - -void SearchResultWidget::setFocusInternally() -{ - if (m_count > 0) { - if (m_isShowingReplaceUI) { - if (!focusWidget() || focusWidget() == m_replaceTextEdit) { - m_replaceTextEdit->setFocus(); - m_replaceTextEdit->selectAll(); - } else { - m_searchResultTreeView->setFocus(); - } - } else { - m_searchResultTreeView->setFocus(); - } - } -} - -bool SearchResultWidget::canFocusInternally() const -{ - return m_count > 0; -} - -void SearchResultWidget::notifyVisibilityChanged(bool visible) -{ - emit visibilityChanged(visible); -} - -void SearchResultWidget::setTextEditorFont(const QFont &font, const SearchResultColor color) -{ - m_searchResultTreeView->setTextEditorFont(font, color); -} - -void SearchResultWidget::setAutoExpandResults(bool expand) -{ - m_searchResultTreeView->setAutoExpandResults(expand); -} - -void SearchResultWidget::expandAll() -{ - m_searchResultTreeView->expandAll(); -} - -void SearchResultWidget::collapseAll() -{ - m_searchResultTreeView->collapseAll(); -} - -void SearchResultWidget::goToNext() -{ - if (m_count == 0) - return; - QModelIndex idx = m_searchResultTreeView->model()->next(m_searchResultTreeView->currentIndex()); - if (idx.isValid()) { - m_searchResultTreeView->setCurrentIndex(idx); - m_searchResultTreeView->emitJumpToSearchResult(idx); - } -} - -void SearchResultWidget::goToPrevious() -{ - if (!m_searchResultTreeView->model()->rowCount()) - return; - QModelIndex idx = m_searchResultTreeView->model()->prev(m_searchResultTreeView->currentIndex()); - if (idx.isValid()) { - m_searchResultTreeView->setCurrentIndex(idx); - m_searchResultTreeView->emitJumpToSearchResult(idx); - } -} - -void SearchResultWidget::restart() -{ - m_replaceTextEdit->setEnabled(false); - m_replaceButton->setEnabled(false); - m_searchResultTreeView->clear(); - m_count = 0; - Core::Id sizeWarningId(SIZE_WARNING_ID); - m_infoBar.removeInfo(sizeWarningId); - m_infoBar.enableInfo(sizeWarningId); - m_cancelButton->setVisible(true); - m_searchAgainButton->setVisible(false); - m_messageWidget->setVisible(false); - updateMatchesFoundLabel(); - emit restarted(); -} - -void SearchResultWidget::setSearchAgainSupported(bool supported) -{ - m_searchAgainSupported = supported; - m_searchAgainButton->setVisible(supported && !m_cancelButton->isVisible()); -} - -void SearchResultWidget::setSearchAgainEnabled(bool enabled) -{ - m_searchAgainButton->setEnabled(enabled); -} - -void SearchResultWidget::finishSearch(bool canceled) -{ - Core::Id sizeWarningId(SIZE_WARNING_ID); - m_infoBar.removeInfo(sizeWarningId); - m_infoBar.enableInfo(sizeWarningId); - m_replaceTextEdit->setEnabled(m_count > 0); - m_replaceButton->setEnabled(m_count > 0); - m_preserveCaseCheck->setEnabled(m_count > 0); - m_cancelButton->setVisible(false); - m_messageWidget->setVisible(canceled); - m_searchAgainButton->setVisible(m_searchAgainSupported); -} - -void SearchResultWidget::sendRequestPopup() -{ - emit requestPopup(true/*focus*/); -} - -void SearchResultWidget::continueAfterSizeWarning() -{ - m_infoBar.suppressInfo(Core::Id(SIZE_WARNING_ID)); - emit paused(false); -} - -void SearchResultWidget::cancelAfterSizeWarning() -{ - m_infoBar.suppressInfo(Core::Id(SIZE_WARNING_ID)); - emit cancelled(); - emit paused(false); -} - -void SearchResultWidget::handleJumpToSearchResult(const SearchResultItem &item) -{ - emit activated(item); -} - -void SearchResultWidget::handleReplaceButton() -{ - // check if button is actually enabled, because this is also triggered - // by pressing return in replace line edit - if (m_replaceButton->isEnabled()) { - m_infoBar.clear(); - emit replaceButtonClicked(m_replaceTextEdit->text(), checkedItems(), m_preserveCaseCheck->isChecked()); - } -} - -void SearchResultWidget::cancel() -{ - m_cancelButton->setVisible(false); - if (m_infoBar.containsInfo(Core::Id(SIZE_WARNING_ID))) - cancelAfterSizeWarning(); - else - emit cancelled(); -} - -void SearchResultWidget::searchAgain() -{ - emit searchAgainRequested(); -} - -QList SearchResultWidget::checkedItems() const -{ - QList result; - Internal::SearchResultTreeModel *model = m_searchResultTreeView->model(); - const int fileCount = model->rowCount(QModelIndex()); - for (int i = 0; i < fileCount; ++i) { - QModelIndex fileIndex = model->index(i, 0, QModelIndex()); - Internal::SearchResultTreeItem *fileItem = static_cast(fileIndex.internalPointer()); - Q_ASSERT(fileItem != 0); - for (int rowIndex = 0; rowIndex < fileItem->childrenCount(); ++rowIndex) { - QModelIndex textIndex = model->index(rowIndex, 0, fileIndex); - Internal::SearchResultTreeItem *rowItem = static_cast(textIndex.internalPointer()); - if (rowItem->checkState()) - result << rowItem->item; - } - } - return result; -} - -void SearchResultWidget::updateMatchesFoundLabel() -{ - if (m_count == 0) - m_matchesFoundLabel->setText(tr("No matches found.")); - else - m_matchesFoundLabel->setText(tr("%n matches found.", 0, m_count)); -} - -#include "searchresultwidget.moc" diff --git a/src/plugins/find/searchresultwidget.h b/src/plugins/find/searchresultwidget.h deleted file mode 100644 index 76ec7da9350..00000000000 --- a/src/plugins/find/searchresultwidget.h +++ /dev/null @@ -1,146 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef SEARCHRESULTWIDGET_H -#define SEARCHRESULTWIDGET_H - -#include "searchresultwindow.h" - -#include - -#include - -QT_BEGIN_NAMESPACE -class QFrame; -class QLabel; -class QLineEdit; -class QToolButton; -class QCheckBox; -QT_END_NAMESPACE - -namespace Find { -namespace Internal { - -class SearchResultTreeView; -class SearchResultColor; - -class SearchResultWidget : public QWidget -{ - Q_OBJECT -public: - explicit SearchResultWidget(QWidget *parent = 0); - ~SearchResultWidget(); - - void setInfo(const QString &label, const QString &toolTip, const QString &term); - - void addResult(const QString &fileName, int lineNumber, const QString &lineText, - int searchTermStart, int searchTermLength, const QVariant &userData = QVariant()); - void addResults(const QList &items, SearchResult::AddMode mode); - - int count() const; - - QString dontAskAgainGroup() const; - void setDontAskAgainGroup(const QString &group); - - void setTextToReplace(const QString &textToReplace); - QString textToReplace() const; - void setShowReplaceUI(bool visible); - - bool hasFocusInternally() const; - void setFocusInternally(); - bool canFocusInternally() const; - - void notifyVisibilityChanged(bool visible); - - void setTextEditorFont(const QFont &font, const SearchResultColor color); - - void setAutoExpandResults(bool expand); - void expandAll(); - void collapseAll(); - - void goToNext(); - void goToPrevious(); - - void restart(); - - void setSearchAgainSupported(bool supported); - void setSearchAgainEnabled(bool enabled); - -public slots: - void finishSearch(bool canceled); - void sendRequestPopup(); - -signals: - void activated(const Find::SearchResultItem &item); - void replaceButtonClicked(const QString &replaceText, const QList &checkedItems, bool preserveCase); - void searchAgainRequested(); - void cancelled(); - void paused(bool paused); - void restarted(); - void visibilityChanged(bool visible); - void requestPopup(bool focus); - - void navigateStateChanged(); - -private slots: - void continueAfterSizeWarning(); - void cancelAfterSizeWarning(); - void handleJumpToSearchResult(const SearchResultItem &item); - void handleReplaceButton(); - void cancel(); - void searchAgain(); - -private: - QList checkedItems() const; - void updateMatchesFoundLabel(); - - SearchResultTreeView *m_searchResultTreeView; - int m_count; - QString m_dontAskAgainGroup; - QFrame *m_messageWidget; - Core::InfoBar m_infoBar; - Core::InfoBarDisplay m_infoBarDisplay; - bool m_isShowingReplaceUI; - QLabel *m_replaceLabel; - QLineEdit *m_replaceTextEdit; - QToolButton *m_replaceButton; - QToolButton *m_searchAgainButton; - QCheckBox *m_preserveCaseCheck; - bool m_searchAgainSupported; - QWidget *m_descriptionContainer; - QLabel *m_label; - QLabel *m_searchTerm; - QToolButton *m_cancelButton; - QLabel *m_matchesFoundLabel; -}; - -} // Internal -} // Find - -#endif // SEARCHRESULTWIDGET_H diff --git a/src/plugins/find/searchresultwindow.cpp b/src/plugins/find/searchresultwindow.cpp deleted file mode 100644 index a5dce4791db..00000000000 --- a/src/plugins/find/searchresultwindow.cpp +++ /dev/null @@ -1,714 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "searchresultwindow.h" -#include "searchresultwidget.h" -#include "searchresultcolor.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -static const char SETTINGSKEYSECTIONNAME[] = "SearchResults"; -static const char SETTINGSKEYEXPANDRESULTS[] = "ExpandResults"; -static const int MAX_SEARCH_HISTORY = 12; - -namespace Find { - -namespace Internal { - - class InternalScrollArea : public QScrollArea - { - Q_OBJECT - public: - explicit InternalScrollArea(QWidget *parent) - : QScrollArea(parent) - { - setFrameStyle(QFrame::NoFrame); - setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); - } - - QSize sizeHint() const - { - if (widget()) - return widget()->size(); - return QScrollArea::sizeHint(); - } - }; - - class SearchResultWindowPrivate : public QObject - { - Q_OBJECT - public: - SearchResultWindowPrivate(SearchResultWindow *window); - bool isSearchVisible() const; - int visibleSearchIndex() const; - void setCurrentIndex(int index, bool focus); - - SearchResultWindow *q; - QList m_searchResultWidgets; - QToolButton *m_expandCollapseButton; - QAction *m_expandCollapseAction; - static const bool m_initiallyExpand = false; - QWidget *m_spacer; - QComboBox *m_recentSearchesBox; - QStackedWidget *m_widget; - QList m_searchResults; - int m_currentIndex; - QFont m_font; - SearchResultColor m_color; - - public slots: - void setCurrentIndex(int index); - void moveWidgetToTop(); - void popupRequested(bool focus); - }; - - SearchResultWindowPrivate::SearchResultWindowPrivate(SearchResultWindow *window) - : q(window) - { - } - - bool SearchResultWindowPrivate::isSearchVisible() const - { - return m_currentIndex > 0; - } - - int SearchResultWindowPrivate::visibleSearchIndex() const - { - return m_currentIndex - 1; - } - - void SearchResultWindowPrivate::setCurrentIndex(int index, bool focus) - { - if (isSearchVisible()) - m_searchResultWidgets.at(visibleSearchIndex())->notifyVisibilityChanged(false); - m_currentIndex = index; - m_widget->setCurrentIndex(index); - m_recentSearchesBox->setCurrentIndex(index); - if (!isSearchVisible()) { - if (focus) - m_widget->currentWidget()->setFocus(); - m_expandCollapseButton->setEnabled(false); - } else { - if (focus) - m_searchResultWidgets.at(visibleSearchIndex())->setFocusInternally(); - m_searchResultWidgets.at(visibleSearchIndex())->notifyVisibilityChanged(true); - m_expandCollapseButton->setEnabled(true); - } - q->navigateStateChanged(); - } - - void SearchResultWindowPrivate::setCurrentIndex(int index) - { - setCurrentIndex(index, true/*focus*/); - } - - void SearchResultWindowPrivate::moveWidgetToTop() - { - SearchResultWidget *widget = qobject_cast(sender()); - QTC_ASSERT(widget, return); - int index = m_searchResultWidgets.indexOf(widget); - if (index == 0) - return; // nothing to do - int internalIndex = index + 1/*account for "new search" entry*/; - QString searchEntry = m_recentSearchesBox->itemText(internalIndex); - - m_searchResultWidgets.removeAt(index); - m_widget->removeWidget(widget); - m_recentSearchesBox->removeItem(internalIndex); - SearchResult *result = m_searchResults.takeAt(index); - - m_searchResultWidgets.prepend(widget); - m_widget->insertWidget(1, widget); - m_recentSearchesBox->insertItem(1, searchEntry); - m_searchResults.prepend(result); - - // adapt the current index - if (index == visibleSearchIndex()) { - // was visible, so we switch - // this is the default case - m_currentIndex = 1; - m_widget->setCurrentIndex(1); - m_recentSearchesBox->setCurrentIndex(1); - } else if (visibleSearchIndex() < index) { - // academical case where the widget moved before the current widget - // only our internal book keeping needed - ++m_currentIndex; - } - } - - void SearchResultWindowPrivate::popupRequested(bool focus) - { - SearchResultWidget *widget = qobject_cast(sender()); - QTC_ASSERT(widget, return); - int internalIndex = m_searchResultWidgets.indexOf(widget) + 1/*account for "new search" entry*/; - setCurrentIndex(internalIndex, focus); - q->popup(focus ? Core::IOutputPane::ModeSwitch | Core::IOutputPane::WithFocus - : Core::IOutputPane::NoModeSwitch); - } -} - -using namespace Find::Internal; - -/*! - \enum Find::SearchResultWindow::SearchMode - This enum type specifies whether a search should show the replace UI or not: - - \value SearchOnly - The search does not support replace. - \value SearchAndReplace - The search supports replace, so show the UI for it. -*/ - -/*! - \class Find::SearchResult - \brief The SearchResult class reports user interaction, such as the - activation of a search result item. - - Whenever a new search is initiated via startNewSearch, an instance of this - class is returned to provide the initiator with the hooks for handling user - interaction. -*/ - -/*! - \fn void SearchResult::activated(const Find::SearchResultItem &item) - Indicates that the user activated the search result \a item by - double-clicking it, for example. -*/ - -/*! - \fn void SearchResult::replaceButtonClicked(const QString &replaceText, const QList &checkedItems, bool preserveCase) - Indicates that the user initiated a text replace by selecting - \gui {Replace All}, for example. - - The signal reports the text to use for replacement in \a replaceText, - and the list of search result items that were selected by the user - in \a checkedItems. - The handler of this signal should apply the replace only on the selected - items. -*/ - -/*! - \class Find::SearchResultWindow - \brief The SearchResultWindow class is the implementation of a commonly - shared \gui{Search Results} output pane. Use it to show search results - to a user. - - Whenever you want to show the user a list of search results, or want - to present UI for a global search and replace, use the single instance - of this class. - - Except for being an implementation of a output pane, the - SearchResultWindow has a few functions and one enum that allows other - plugins to show their search results and hook into the user actions for - selecting an entry and performing a global replace. - - Whenever you start a search, call startNewSearch(SearchMode) to initialize - the \gui {Search Results} output pane. The parameter determines if the GUI for - replacing should be shown. - The function returns a SearchResult object that is your - hook into the signals from user interaction for this search. - When you produce search results, call addResults or addResult to add them - to the \gui {Search Results} output pane. - After the search has finished call finishSearch to inform the - \gui {Search Results} output pane about it. - - You will get activated signals via your SearchResult instance when - the user selects a search result item, and, if you started the search - with the SearchAndReplace option, the replaceButtonClicked signal - when the user requests a replace. -*/ - -/*! - \fn QString SearchResultWindow::displayName() const - \internal -*/ - -SearchResultWindow *SearchResultWindow::m_instance = 0; - -/*! - \internal -*/ -SearchResultWindow::SearchResultWindow(QWidget *newSearchPanel) - : d(new SearchResultWindowPrivate(this)) -{ - m_instance = this; - d->m_spacer = new QWidget; - d->m_spacer->setMinimumWidth(30); - d->m_recentSearchesBox = new QComboBox; - d->m_recentSearchesBox->setSizeAdjustPolicy(QComboBox::AdjustToContents); - d->m_recentSearchesBox->addItem(tr("New Search")); - connect(d->m_recentSearchesBox, SIGNAL(activated(int)), d, SLOT(setCurrentIndex(int))); - - d->m_widget = new QStackedWidget; - d->m_widget->setWindowTitle(displayName()); - - InternalScrollArea *newSearchArea = new InternalScrollArea(d->m_widget); - newSearchArea->setWidget(newSearchPanel); - newSearchArea->setFocusProxy(newSearchPanel); - d->m_widget->addWidget(newSearchArea); - d->m_currentIndex = 0; - - d->m_expandCollapseButton = new QToolButton(d->m_widget); - d->m_expandCollapseButton->setAutoRaise(true); - - d->m_expandCollapseAction = new QAction(tr("Expand All"), this); - d->m_expandCollapseAction->setCheckable(true); - d->m_expandCollapseAction->setIcon(QIcon(QLatin1String(":/find/images/expand.png"))); - Core::Command *cmd = Core::ActionManager::registerAction( - d->m_expandCollapseAction, "Find.ExpandAll", - Core::Context(Core::Constants::C_GLOBAL)); - cmd->setAttribute(Core::Command::CA_UpdateText); - d->m_expandCollapseButton->setDefaultAction(cmd->action()); - - connect(d->m_expandCollapseAction, SIGNAL(toggled(bool)), this, SLOT(handleExpandCollapseToolButton(bool))); - readSettings(); -} - -/*! - \internal -*/ -SearchResultWindow::~SearchResultWindow() -{ - writeSettings(); - qDeleteAll(d->m_searchResults); - delete d->m_widget; - d->m_widget = 0; - delete d; -} - -/*! - Returns the single shared instance of the \gui {Search Results} output pane. -*/ -SearchResultWindow *SearchResultWindow::instance() -{ - return m_instance; -} - -/*! - \internal -*/ -void SearchResultWindow::visibilityChanged(bool visible) -{ - if (d->isSearchVisible()) - d->m_searchResultWidgets.at(d->visibleSearchIndex())->notifyVisibilityChanged(visible); -} - -/*! - \internal -*/ -QWidget *SearchResultWindow::outputWidget(QWidget *) -{ - return d->m_widget; -} - -/*! - \internal -*/ -QList SearchResultWindow::toolBarWidgets() const -{ - return QList() << d->m_expandCollapseButton << d->m_spacer << d->m_recentSearchesBox; -} - -/*! - Tells the \gui {Search Results} output pane to start a new search. - - The \a label should be a string that shortly describes the type of the - search, that is, the search filter and possibly the most relevant search - option, followed by a colon ':'. For example: \c {Project 'myproject':} - The \a searchTerm is shown after the colon. - The \a toolTip should elaborate on the search parameters, like file patterns that are searched and - find flags. - If \a cfgGroup is not empty, it will be used for storing the "do not ask again" - setting of a "this change cannot be undone" warning (which is implicitly requested - by passing a non-empty group). - Returns a SearchResult object that is used for signaling user interaction - with the results of this search. - The search result window owns the returned SearchResult - and might delete it any time, even while the search is running - (for example, when the user clears the \gui {Search Results} pane, or when - the user opens so many other searches - that this search falls out of the history). - -*/ -SearchResult *SearchResultWindow::startNewSearch(const QString &label, - const QString &toolTip, - const QString &searchTerm, - SearchMode searchOrSearchAndReplace, - const QString &cfgGroup) -{ - if (d->m_searchResults.size() >= MAX_SEARCH_HISTORY) { - d->m_searchResultWidgets.last()->notifyVisibilityChanged(false); - // widget first, because that might send interesting signals to SearchResult - delete d->m_searchResultWidgets.takeLast(); - delete d->m_searchResults.takeLast(); - d->m_recentSearchesBox->removeItem(d->m_recentSearchesBox->count()-1); - if (d->m_currentIndex >= d->m_recentSearchesBox->count()) { - // temporarily set the index to the last existing - d->m_currentIndex = d->m_recentSearchesBox->count() - 1; - } - } - Internal::SearchResultWidget *widget = new Internal::SearchResultWidget; - d->m_searchResultWidgets.prepend(widget); - d->m_widget->insertWidget(1, widget); - connect(widget, SIGNAL(navigateStateChanged()), this, SLOT(navigateStateChanged())); - connect(widget, SIGNAL(restarted()), d, SLOT(moveWidgetToTop())); - connect(widget, SIGNAL(requestPopup(bool)), d, SLOT(popupRequested(bool))); - widget->setTextEditorFont(d->m_font, d->m_color); - widget->setShowReplaceUI(searchOrSearchAndReplace != SearchOnly); - widget->setAutoExpandResults(d->m_expandCollapseAction->isChecked()); - widget->setInfo(label, toolTip, searchTerm); - if (searchOrSearchAndReplace == SearchAndReplace) - widget->setDontAskAgainGroup(cfgGroup); - SearchResult *result = new SearchResult(widget); - d->m_searchResults.prepend(result); - d->m_recentSearchesBox->insertItem(1, tr("%1 %2").arg(label, searchTerm)); - if (d->m_currentIndex > 0) - ++d->m_currentIndex; // so setCurrentIndex still knows about the right "currentIndex" and its widget - d->setCurrentIndex(1); - return result; -} - -/*! - Clears the current contents of the \gui {Search Results} output pane. -*/ -void SearchResultWindow::clearContents() -{ - for (int i = d->m_recentSearchesBox->count() - 1; i > 0 /* don't want i==0 */; --i) - d->m_recentSearchesBox->removeItem(i); - foreach (Internal::SearchResultWidget *widget, d->m_searchResultWidgets) - widget->notifyVisibilityChanged(false); - qDeleteAll(d->m_searchResultWidgets); - d->m_searchResultWidgets.clear(); - qDeleteAll(d->m_searchResults); - d->m_searchResults.clear(); - - d->m_currentIndex = 0; - d->m_widget->currentWidget()->setFocus(); - d->m_expandCollapseButton->setEnabled(false); - navigateStateChanged(); -} - -/*! - \internal -*/ -bool SearchResultWindow::hasFocus() const -{ - return d->m_widget->focusWidget() && d->m_widget->focusWidget()->hasFocus(); -} - -/*! - \internal -*/ -bool SearchResultWindow::canFocus() const -{ - if (d->isSearchVisible()) - return d->m_searchResultWidgets.at(d->visibleSearchIndex())->canFocusInternally(); - return true; -} - -/*! - \internal -*/ -void SearchResultWindow::setFocus() -{ - if (!d->isSearchVisible()) - d->m_widget->currentWidget()->setFocus(); - else - d->m_searchResultWidgets.at(d->visibleSearchIndex())->setFocusInternally(); -} - -/*! - \internal -*/ -void SearchResultWindow::setTextEditorFont(const QFont &font, - const QColor &textForegroundColor, - const QColor &textBackgroundColor, - const QColor &highlightForegroundColor, - const QColor &highlightBackgroundColor) -{ - d->m_font = font; - Internal::SearchResultColor color; - color.textBackground = textBackgroundColor; - color.textForeground = textForegroundColor; - color.highlightBackground = highlightBackgroundColor.isValid() - ? highlightBackgroundColor - : textBackgroundColor; - color.highlightForeground = highlightForegroundColor.isValid() - ? highlightForegroundColor - : textForegroundColor; - d->m_color = color; - foreach (Internal::SearchResultWidget *widget, d->m_searchResultWidgets) - widget->setTextEditorFont(font, color); -} - -void SearchResultWindow::openNewSearchPanel() -{ - d->setCurrentIndex(0); - popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus | IOutputPane::EnsureSizeHint); -} - -/*! - \internal -*/ -void SearchResultWindow::handleExpandCollapseToolButton(bool checked) -{ - if (!d->isSearchVisible()) - return; - d->m_searchResultWidgets.at(d->visibleSearchIndex())->setAutoExpandResults(checked); - if (checked) { - d->m_expandCollapseAction->setText(tr("Collapse All")); - d->m_searchResultWidgets.at(d->visibleSearchIndex())->expandAll(); - } else { - d->m_expandCollapseAction->setText(tr("Expand All")); - d->m_searchResultWidgets.at(d->visibleSearchIndex())->collapseAll(); - } -} - -/*! - \internal -*/ -void SearchResultWindow::readSettings() -{ - QSettings *s = Core::ICore::settings(); - s->beginGroup(QLatin1String(SETTINGSKEYSECTIONNAME)); - d->m_expandCollapseAction->setChecked(s->value(QLatin1String(SETTINGSKEYEXPANDRESULTS), d->m_initiallyExpand).toBool()); - s->endGroup(); -} - -/*! - \internal -*/ -void SearchResultWindow::writeSettings() -{ - QSettings *s = Core::ICore::settings(); - s->beginGroup(QLatin1String(SETTINGSKEYSECTIONNAME)); - s->setValue(QLatin1String(SETTINGSKEYEXPANDRESULTS), d->m_expandCollapseAction->isChecked()); - s->endGroup(); -} - -/*! - \internal -*/ -int SearchResultWindow::priorityInStatusBar() const -{ - return 80; -} - -/*! - \internal -*/ -bool SearchResultWindow::canNext() const -{ - if (d->isSearchVisible()) - return d->m_searchResultWidgets.at(d->visibleSearchIndex())->count() > 0; - return false; -} - -/*! - \internal -*/ -bool SearchResultWindow::canPrevious() const -{ - return canNext(); -} - -/*! - \internal -*/ -void SearchResultWindow::goToNext() -{ - int index = d->m_widget->currentIndex(); - if (index != 0) - d->m_searchResultWidgets.at(index-1)->goToNext(); -} - -/*! - \internal -*/ -void SearchResultWindow::goToPrev() -{ - int index = d->m_widget->currentIndex(); - if (index != 0) - d->m_searchResultWidgets.at(index-1)->goToPrevious(); -} - -/*! - \internal -*/ -bool SearchResultWindow::canNavigate() const -{ - return true; -} - -/*! - \internal -*/ -SearchResult::SearchResult(SearchResultWidget *widget) - : m_widget(widget) -{ - connect(widget, SIGNAL(activated(Find::SearchResultItem)), - this, SIGNAL(activated(Find::SearchResultItem))); - connect(widget, SIGNAL(replaceButtonClicked(QString,QList,bool)), - this, SIGNAL(replaceButtonClicked(QString,QList,bool))); - connect(widget, SIGNAL(cancelled()), - this, SIGNAL(cancelled())); - connect(widget, SIGNAL(paused(bool)), - this, SIGNAL(paused(bool))); - connect(widget, SIGNAL(visibilityChanged(bool)), - this, SIGNAL(visibilityChanged(bool))); - connect(widget, SIGNAL(searchAgainRequested()), - this, SIGNAL(searchAgainRequested())); -} - -/*! - Attaches some random \a data to this search, that you can use later. - - \sa userData() -*/ -void SearchResult::setUserData(const QVariant &data) -{ - m_userData = data; -} - -/*! - Returns the data that was attached to this search by calling - setUserData(). - - \sa setUserData() -*/ -QVariant SearchResult::userData() const -{ - return m_userData; -} - -/*! - Returns the text that should replace the text in search results. -*/ -QString SearchResult::textToReplace() const -{ - return m_widget->textToReplace(); -} - -int SearchResult::count() const -{ - return m_widget->count(); -} - -void SearchResult::setSearchAgainSupported(bool supported) -{ - m_widget->setSearchAgainSupported(supported); -} - -/*! - Adds a single result line to the \gui {Search Results} output pane. - - \a fileName, \a lineNumber, and \a lineText are shown on the result line. - \a searchTermStart and \a searchTermLength specify the region that - should be visually marked (string position and length in \a lineText). - You can attach arbitrary \a userData to the search result, which can - be used, for example, when reacting to the signals of the search results - for your search. - - \sa addResults() -*/ -void SearchResult::addResult(const QString &fileName, int lineNumber, const QString &lineText, - int searchTermStart, int searchTermLength, const QVariant &userData) -{ - m_widget->addResult(fileName, lineNumber, lineText, - searchTermStart, searchTermLength, userData); - emit countChanged(m_widget->count()); -} - -/*! - Adds the search result \a items to the \gui {Search Results} output pane. - - \sa addResult() -*/ -void SearchResult::addResults(const QList &items, AddMode mode) -{ - m_widget->addResults(items, mode); - emit countChanged(m_widget->count()); -} - -/*! - Notifies the \gui {Search Results} output pane that the current search - has finished, and the UI should reflect that. -*/ -void SearchResult::finishSearch(bool canceled) -{ - m_widget->finishSearch(canceled); -} - -/*! - Sets the value in the UI element that allows the user to type - the text that should replace text in search results to \a textToReplace. -*/ -void SearchResult::setTextToReplace(const QString &textToReplace) -{ - m_widget->setTextToReplace(textToReplace); -} - -/*! - * Removes all search results. - */ -void SearchResult::restart() -{ - m_widget->restart(); -} - -void SearchResult::setSearchAgainEnabled(bool enabled) -{ - m_widget->setSearchAgainEnabled(enabled); -} - -/*! - * Opens the \gui {Search Results} output pane with this search. - */ -void SearchResult::popup() -{ - m_widget->sendRequestPopup(); -} - -} // namespace Find - -#include "searchresultwindow.moc" diff --git a/src/plugins/find/searchresultwindow.h b/src/plugins/find/searchresultwindow.h deleted file mode 100644 index 8c7f052c01f..00000000000 --- a/src/plugins/find/searchresultwindow.h +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef SEARCHRESULTWINDOW_H -#define SEARCHRESULTWINDOW_H - -#include "find_global.h" - -#include - -#include -#include -#include - -QT_BEGIN_NAMESPACE -class QFont; -QT_END_NAMESPACE - -namespace Find { -namespace Internal { - class SearchResultTreeView; - class SearchResultWindowPrivate; - class SearchResultWidget; -} -class SearchResultWindow; - -class FIND_EXPORT SearchResultItem -{ -public: - SearchResultItem() - : textMarkPos(-1), - textMarkLength(0), - lineNumber(-1), - useTextEditorFont(false) - { - } - - SearchResultItem(const SearchResultItem &other) - : path(other.path), - text(other.text), - textMarkPos(other.textMarkPos), - textMarkLength(other.textMarkLength), - icon(other.icon), - lineNumber(other.lineNumber), - useTextEditorFont(other.useTextEditorFont), - userData(other.userData) - { - } - - QStringList path; // hierarchy to the parent item of this item - QString text; // text to show for the item itself - int textMarkPos; // 0-based starting position for a mark (-1 for no mark) - int textMarkLength; // length of the mark (0 for no mark) - QIcon icon; // icon to show in front of the item (by be null icon to hide) - int lineNumber; // (0 or -1 for no line number) - bool useTextEditorFont; - QVariant userData; // user data for identification of the item -}; - -class FIND_EXPORT SearchResult : public QObject -{ - Q_OBJECT - -public: - enum AddMode { - AddSorted, - AddOrdered - }; - - void setUserData(const QVariant &data); - QVariant userData() const; - QString textToReplace() const; - int count() const; - void setSearchAgainSupported(bool supported); - -public slots: - void addResult(const QString &fileName, int lineNumber, const QString &lineText, - int searchTermStart, int searchTermLength, const QVariant &userData = QVariant()); - void addResults(const QList &items, AddMode mode); - void finishSearch(bool canceled); - void setTextToReplace(const QString &textToReplace); - void restart(); - void setSearchAgainEnabled(bool enabled); - void popup(); - -signals: - void activated(const Find::SearchResultItem &item); - void replaceButtonClicked(const QString &replaceText, const QList &checkedItems, bool preserveCase); - void cancelled(); - void paused(bool paused); - void visibilityChanged(bool visible); - void countChanged(int count); - void searchAgainRequested(); - void requestEnabledCheck(); - -private: - SearchResult(Internal::SearchResultWidget *widget); - friend class SearchResultWindow; // for the constructor - -private: - Internal::SearchResultWidget *m_widget; - QVariant m_userData; -}; - -class FIND_EXPORT SearchResultWindow : public Core::IOutputPane -{ - Q_OBJECT - -public: - enum SearchMode { - SearchOnly, - SearchAndReplace - }; - - - SearchResultWindow(QWidget *newSearchPanel); - virtual ~SearchResultWindow(); - static SearchResultWindow *instance(); - - QWidget *outputWidget(QWidget *); - QList toolBarWidgets() const; - - QString displayName() const { return tr("Search Results"); } - int priorityInStatusBar() const; - void visibilityChanged(bool visible); - bool hasFocus() const; - bool canFocus() const; - void setFocus(); - - bool canNext() const; - bool canPrevious() const; - void goToNext(); - void goToPrev(); - bool canNavigate() const; - - void setTextEditorFont(const QFont &font, - const QColor &textForegroundColor, - const QColor &textBackgroundColor, - const QColor &highlightForegroundColor, - const QColor &highlightBackgroundColor); - void openNewSearchPanel(); - - // The search result window owns the returned SearchResult - // and might delete it any time, even while the search is running - // (e.g. when the user clears the search result pane, or if the user opens so many other searches - // that this search falls out of the history). - SearchResult *startNewSearch(const QString &label, - const QString &toolTip, - const QString &searchTerm, - SearchMode searchOrSearchAndReplace = SearchOnly, - const QString &cfgGroup = QString()); - -public slots: - void clearContents(); - -private slots: - void handleExpandCollapseToolButton(bool checked); - -private: - void readSettings(); - void writeSettings(); - - Internal::SearchResultWindowPrivate *d; - static SearchResultWindow *m_instance; -}; - -} // namespace Find - -Q_DECLARE_METATYPE(Find::SearchResultItem) - -#endif // SEARCHRESULTWINDOW_H diff --git a/src/plugins/find/textfindconstants.h b/src/plugins/find/textfindconstants.h deleted file mode 100644 index 0100df7d2d3..00000000000 --- a/src/plugins/find/textfindconstants.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef TEXTFINDCONSTANTS_H -#define TEXTFINDCONSTANTS_H - -#include "find_global.h" - -#include -#include -#include - -namespace Find { -namespace Constants { - -const char M_FIND[] = "Find.FindMenu"; -const char M_FIND_ADVANCED[] = "Find.FindAdvancedMenu"; -const char G_FIND_CURRENTDOCUMENT[] = "Find.FindMenu.CurrentDocument"; -const char G_FIND_FILTERS[] = "Find.FindMenu.Filters"; -const char G_FIND_FLAGS[] = "Find.FindMenu.Flags"; -const char G_FIND_ACTIONS[] = "Find.FindMenu.Actions"; - -const char ADVANCED_FIND[] = "Find.Dialog"; -const char FIND_IN_DOCUMENT[] = "Find.FindInCurrentDocument"; -const char FIND_NEXT_SELECTED[]= "Find.FindNextSelected"; -const char FIND_PREV_SELECTED[]= "Find.FindPreviousSelected"; -const char FIND_NEXT[] = "Find.FindNext"; -const char FIND_PREVIOUS[] = "Find.FindPrevious"; -const char REPLACE[] = "Find.Replace"; -const char REPLACE_NEXT[] = "Find.ReplaceNext"; -const char REPLACE_PREVIOUS[] = "Find.ReplacePrevious"; -const char REPLACE_ALL[] = "Find.ReplaceAll"; -const char CASE_SENSITIVE[] = "Find.CaseSensitive"; -const char WHOLE_WORDS[] = "Find.WholeWords"; -const char REGULAR_EXPRESSIONS[] = "Find.RegularExpressions"; -const char PRESERVE_CASE[] = "Find.PreserveCase"; -const char TASK_SEARCH[] = "Find.Task.Search"; - -} // namespace Constants - -enum FindFlag { - FindBackward = 0x01, - FindCaseSensitively = 0x02, - FindWholeWords = 0x04, - FindRegularExpression = 0x08, - FindPreserveCase = 0x10 -}; -Q_DECLARE_FLAGS(FindFlags, FindFlag) - -// defined in findplugin.cpp -QTextDocument::FindFlags FIND_EXPORT textDocumentFlagsForFindFlags(FindFlags flags); - -} // namespace Find - -Q_DECLARE_OPERATORS_FOR_FLAGS(Find::FindFlags) -Q_DECLARE_METATYPE(Find::FindFlags) - -#endif // TEXTFINDCONSTANTS_H diff --git a/src/plugins/find/treeviewfind.cpp b/src/plugins/find/treeviewfind.cpp deleted file mode 100644 index 24ac4e7e374..00000000000 --- a/src/plugins/find/treeviewfind.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "treeviewfind.h" - -#include -#include -#include - -namespace Find { - -class ItemModelFindPrivate -{ -public: - explicit ItemModelFindPrivate(QTreeView *view, int role) - : m_view(view) - , m_incrementalWrappedState(false), - m_role(role) - { - } - - QTreeView *m_view; - QModelIndex m_incrementalFindStart; - bool m_incrementalWrappedState; - int m_role; -}; - -TreeViewFind::TreeViewFind(QTreeView *view, int role) - : d(new ItemModelFindPrivate(view, role)) -{ -} - -TreeViewFind::~TreeViewFind() -{ - delete d; -} - -bool TreeViewFind::supportsReplace() const -{ - return false; -} - -FindFlags TreeViewFind::supportedFindFlags() const -{ - return FindBackward | FindCaseSensitively | FindRegularExpression | FindWholeWords; -} - -void TreeViewFind::resetIncrementalSearch() -{ - d->m_incrementalFindStart = QModelIndex(); - d->m_incrementalWrappedState = false; -} - -void TreeViewFind::clearResults() -{ -} - -QString TreeViewFind::currentFindString() const -{ - return QString(); -} - -QString TreeViewFind::completedFindString() const -{ - return QString(); -} - -void TreeViewFind::highlightAll(const QString &/*txt*/, FindFlags /*findFlags*/) -{ -} - -IFindSupport::Result TreeViewFind::findIncremental(const QString &txt, FindFlags findFlags) -{ - if (!d->m_incrementalFindStart.isValid()) { - d->m_incrementalFindStart = d->m_view->currentIndex(); - d->m_incrementalWrappedState = false; - } - d->m_view->setCurrentIndex(d->m_incrementalFindStart); - bool wrapped = false; - IFindSupport::Result result = find(txt, findFlags, true/*startFromCurrent*/, - &wrapped); - if (wrapped != d->m_incrementalWrappedState) { - d->m_incrementalWrappedState = wrapped; - showWrapIndicator(d->m_view); - } - return result; -} - -IFindSupport::Result TreeViewFind::findStep(const QString &txt, FindFlags findFlags) -{ - bool wrapped = false; - IFindSupport::Result result = find(txt, findFlags, false/*startFromNext*/, - &wrapped); - if (wrapped) - showWrapIndicator(d->m_view); - if (result == IFindSupport::Found) { - d->m_incrementalFindStart = d->m_view->currentIndex(); - d->m_incrementalWrappedState = false; - } - return result; -} - -IFindSupport::Result TreeViewFind::find(const QString &searchTxt, - FindFlags findFlags, - bool startFromCurrentIndex, - bool *wrapped) -{ - if (wrapped) - *wrapped = false; - if (searchTxt.isEmpty()) - return IFindSupport::NotFound; - - QTextDocument::FindFlags flags = textDocumentFlagsForFindFlags(findFlags); - QModelIndex resultIndex; - QModelIndex currentIndex = d->m_view->currentIndex(); - QModelIndex index = currentIndex; - int currentRow = currentIndex.row(); - - bool backward = (flags & QTextDocument::FindBackward); - if (wrapped) - *wrapped = false; - bool anyWrapped = false; - bool stepWrapped = false; - if (!startFromCurrentIndex) - index = followingIndex(index, backward, &stepWrapped); - else - currentRow = -1; - do { - anyWrapped |= stepWrapped; // update wrapped state if we actually stepped to next/prev item - if (index.isValid()) { - const QString &text = d->m_view->model()->data( - index, d->m_role).toString(); - if (findFlags & FindRegularExpression) { - bool sensitive = (findFlags & FindCaseSensitively); - QRegExp searchExpr = QRegExp(searchTxt, - (sensitive ? Qt::CaseSensitive : - Qt::CaseInsensitive)); - if (searchExpr.indexIn(text) != -1 - && d->m_view->model()->flags(index) & Qt::ItemIsSelectable - && (index.row() != currentRow || index.parent() != currentIndex.parent())) - resultIndex = index; - } else { - QTextDocument doc(text); - if (!doc.find(searchTxt, 0, - flags & (FindCaseSensitively | FindWholeWords)).isNull() - && d->m_view->model()->flags(index) & Qt::ItemIsSelectable - && (index.row() != currentRow || index.parent() != currentIndex.parent())) - resultIndex = index; - } - } - index = followingIndex(index, backward, &stepWrapped); - } while (!resultIndex.isValid() && index.isValid() && index != currentIndex); - - if (resultIndex.isValid()) { - d->m_view->setCurrentIndex(resultIndex); - d->m_view->scrollTo(resultIndex); - if (resultIndex.parent().isValid()) - d->m_view->expand(resultIndex.parent()); - if (wrapped) - *wrapped = anyWrapped; - return IFindSupport::Found; - } - return IFindSupport::NotFound; -} - -QModelIndex TreeViewFind::nextIndex(const QModelIndex &idx, bool *wrapped) const -{ - if (wrapped) - *wrapped = false; - QAbstractItemModel *model = d->m_view->model(); - // pathological - if (!idx.isValid()) - return model->index(0, 0); - - // same parent has more columns, go to next column - if (idx.column() + 1 < model->columnCount(idx.parent())) - return model->index(idx.row(), idx.column() + 1, idx.parent()); - - // tree views have their children attached to first column - // make sure we are at first column - QModelIndex current = model->index(idx.row(), 0, idx.parent()); - - // check for children - if (model->rowCount(current) > 0) - return current.child(0, 0); - - // no more children, go up and look for parent with more children - QModelIndex nextIndex; - while (!nextIndex.isValid()) { - int row = current.row(); - current = current.parent(); - - if (row + 1 < model->rowCount(current)) { - // Same parent has another child - nextIndex = model->index(row + 1, 0, current); - } else { - // go up one parent - if (!current.isValid()) { - // we start from the beginning - if (wrapped) - *wrapped = true; - nextIndex = model->index(0, 0); - } - } - } - return nextIndex; -} - -QModelIndex TreeViewFind::prevIndex(const QModelIndex &idx, bool *wrapped) const -{ - if (wrapped) - *wrapped = false; - QAbstractItemModel *model = d->m_view->model(); - // if same parent has earlier columns, just move there - if (idx.column() > 0) - return model->index(idx.row(), idx.column() - 1, idx.parent()); - - QModelIndex current = idx; - bool checkForChildren = true; - if (current.isValid()) { - int row = current.row(); - if (row > 0) { - current = model->index(row - 1, 0, current.parent()); - } else { - current = current.parent(); - checkForChildren = !current.isValid(); - if (checkForChildren && wrapped) { - // we start from the end - *wrapped = true; - } - } - } - if (checkForChildren) { - // traverse down the hierarchy - while (int rc = model->rowCount(current)) { - current = model->index(rc - 1, 0, current); - } - } - // set to last column - current = model->index(current.row(), model->columnCount(current.parent()) - 1, current.parent()); - return current; -} - -QModelIndex TreeViewFind::followingIndex(const QModelIndex &idx, bool backward, bool *wrapped) -{ - if (backward) - return prevIndex(idx, wrapped); - return nextIndex(idx, wrapped); -} - -} // namespace Find diff --git a/src/plugins/find/treeviewfind.h b/src/plugins/find/treeviewfind.h deleted file mode 100644 index b7ac19468f9..00000000000 --- a/src/plugins/find/treeviewfind.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef TREEVIEWFIND_H -#define TREEVIEWFIND_H - -#include "ifindsupport.h" - -QT_BEGIN_NAMESPACE -class QTreeView; -class QModelIndex; -QT_END_NAMESPACE - -namespace Find { -class ItemModelFindPrivate; - -class FIND_EXPORT TreeViewFind : public IFindSupport -{ - Q_OBJECT -public: - explicit TreeViewFind(QTreeView *view, int role = Qt::DisplayRole); - virtual ~TreeViewFind(); - - bool supportsReplace() const; - FindFlags supportedFindFlags() const; - void resetIncrementalSearch(); - void clearResults(); - QString currentFindString() const; - QString completedFindString() const; - - virtual void highlightAll(const QString &txt, FindFlags findFlags); - Result findIncremental(const QString &txt, FindFlags findFlags); - Result findStep(const QString &txt, FindFlags findFlags); - -private: - Result find(const QString &txt, FindFlags findFlags, - bool startFromCurrentIndex, bool *wrapped); - QModelIndex nextIndex(const QModelIndex &idx, bool *wrapped) const; - QModelIndex prevIndex(const QModelIndex &idx, bool *wrapped) const; - QModelIndex followingIndex(const QModelIndex &idx, bool backward, - bool *wrapped); - -private: - ItemModelFindPrivate *d; -}; - -} // namespace Find - -#endif // TREEVIEWFIND_H diff --git a/src/plugins/genericprojectmanager/genericprojectmanager.qbs b/src/plugins/genericprojectmanager/genericprojectmanager.qbs index 707264924ea..72729967a37 100644 --- a/src/plugins/genericprojectmanager/genericprojectmanager.qbs +++ b/src/plugins/genericprojectmanager/genericprojectmanager.qbs @@ -11,8 +11,6 @@ QtcPlugin { Depends { name: "CppTools" } Depends { name: "TextEditor" } Depends { name: "ProjectExplorer" } - Depends { name: "Find" } - Depends { name: "Locator" } Depends { name: "QtSupport" } files: [ diff --git a/src/plugins/git/gerrit/gerritplugin.cpp b/src/plugins/git/gerrit/gerritplugin.cpp index 2acbc32fce1..733808a80eb 100644 --- a/src/plugins/git/gerrit/gerritplugin.cpp +++ b/src/plugins/git/gerrit/gerritplugin.cpp @@ -51,7 +51,7 @@ #include #include #include -#include +#include #include @@ -302,7 +302,7 @@ void GerritPlugin::updateActions(bool hasTopLevel) m_pushToGerritPair.first->setEnabled(hasTopLevel); } -void GerritPlugin::addToLocator(Locator::CommandLocator *locator) +void GerritPlugin::addToLocator(Core::CommandLocator *locator) { locator->appendCommand(m_gerritCommand); locator->appendCommand(m_pushToGerritPair.second); diff --git a/src/plugins/git/gerrit/gerritplugin.h b/src/plugins/git/gerrit/gerritplugin.h index cefa726d35a..1d7217d9c4c 100644 --- a/src/plugins/git/gerrit/gerritplugin.h +++ b/src/plugins/git/gerrit/gerritplugin.h @@ -42,10 +42,9 @@ QT_END_NAMESPACE namespace Core { class ActionContainer; class Command; +class CommandLocator; } -namespace Locator { class CommandLocator; } - namespace Gerrit { namespace Internal { @@ -66,7 +65,7 @@ public: static QString gitBinary(); static QString branch(const QString &repository); - void addToLocator(Locator::CommandLocator *locator); + void addToLocator(Core::CommandLocator *locator); void push(const QString &topLevel); public slots: diff --git a/src/plugins/git/git.qbs b/src/plugins/git/git.qbs index dd4e2e02055..bff95c4aca0 100644 --- a/src/plugins/git/git.qbs +++ b/src/plugins/git/git.qbs @@ -8,10 +8,8 @@ QtcPlugin { Depends { name: "Qt"; submodules: ["widgets", "network"] } Depends { name: "Core" } Depends { name: "TextEditor" } - Depends { name: "Find" } Depends { name: "VcsBase" } Depends { name: "DiffEditor" } - Depends { name: "Locator" } files: [ "annotationhighlighter.cpp", diff --git a/src/plugins/git/git_dependencies.pri b/src/plugins/git/git_dependencies.pri index 6e7123f2474..e78d2e2e5d7 100644 --- a/src/plugins/git/git_dependencies.pri +++ b/src/plugins/git/git_dependencies.pri @@ -2,7 +2,6 @@ QTC_PLUGIN_NAME = Git QTC_LIB_DEPENDS += \ utils QTC_PLUGIN_DEPENDS += \ - locator \ texteditor \ coreplugin \ vcsbase \ diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index a3b75828ea1..be1b7400197 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -71,7 +71,7 @@ #include #include #include -#include +#include #include #include @@ -298,7 +298,7 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) addAutoReleasedObject(new Gitorious::Internal::GitoriousCloneWizard); const QString prefix = QLatin1String("git"); - m_commandLocator = new Locator::CommandLocator("Git", prefix, prefix); + m_commandLocator = new Core::CommandLocator("Git", prefix, prefix); addAutoReleasedObject(m_commandLocator); //register actions diff --git a/src/plugins/git/gitplugin.h b/src/plugins/git/gitplugin.h index 4ebb2e48c39..27e3292630f 100644 --- a/src/plugins/git/gitplugin.h +++ b/src/plugins/git/gitplugin.h @@ -49,6 +49,7 @@ namespace Core { class IEditor; class IEditorFactory; class Command; +class CommandLocator; class Context; class ActionManager; class ActionContainer; @@ -56,9 +57,6 @@ class ActionContainer; namespace Utils { class ParameterAction; } -namespace Locator { - class CommandLocator; -} namespace Gerrit { namespace Internal { class GerritPlugin; @@ -206,7 +204,7 @@ private: void updateVersionWarning(); static GitPlugin *m_instance; - Locator::CommandLocator *m_commandLocator; + Core::CommandLocator *m_commandLocator; QAction *m_submitCurrentAction; QAction *m_diffSelectedFilesAction; diff --git a/src/plugins/help/centralwidget.cpp b/src/plugins/help/centralwidget.cpp index b99ba69487e..7480831ed98 100644 --- a/src/plugins/help/centralwidget.cpp +++ b/src/plugins/help/centralwidget.cpp @@ -152,7 +152,7 @@ void CentralWidget::setCurrentPage(HelpViewer *page) m_stackedWidget->setCurrentWidget(page); } -bool CentralWidget::find(const QString &txt, Find::FindFlags flags, +bool CentralWidget::find(const QString &txt, Core::FindFlags flags, bool incremental, bool *wrapped) { return currentHelpViewer()->findText(txt, flags, incremental, false, wrapped); diff --git a/src/plugins/help/centralwidget.h b/src/plugins/help/centralwidget.h index a260eb2326e..be8d5abf011 100644 --- a/src/plugins/help/centralwidget.h +++ b/src/plugins/help/centralwidget.h @@ -30,7 +30,7 @@ #ifndef CENTRALWIDGET_H #define CENTRALWIDGET_H -#include +#include #include @@ -68,7 +68,7 @@ public: int currentIndex() const; void setCurrentPage(HelpViewer *page); - bool find(const QString &txt, Find::FindFlags findFlags, + bool find(const QString &txt, Core::FindFlags findFlags, bool incremental, bool *wrapped = 0); public slots: diff --git a/src/plugins/help/help.qbs b/src/plugins/help/help.qbs index b4c8b62f377..1761d5359c4 100644 --- a/src/plugins/help/help.qbs +++ b/src/plugins/help/help.qbs @@ -12,8 +12,6 @@ QtcPlugin { } Depends { name: "Core" } - Depends { name: "Find" } - Depends { name: "Locator" } Depends { name: "app_version_header" } cpp.defines: base.concat(["QT_CLUCENE_SUPPORT"]) diff --git a/src/plugins/help/help_dependencies.pri b/src/plugins/help/help_dependencies.pri index 058256c5790..df048080748 100644 --- a/src/plugins/help/help_dependencies.pri +++ b/src/plugins/help/help_dependencies.pri @@ -1,5 +1,3 @@ QTC_PLUGIN_NAME = Help QTC_PLUGIN_DEPENDS += \ - coreplugin \ - find \ - locator + coreplugin diff --git a/src/plugins/help/helpfindsupport.cpp b/src/plugins/help/helpfindsupport.cpp index 16efef0b003..b971fb1d9ff 100644 --- a/src/plugins/help/helpfindsupport.cpp +++ b/src/plugins/help/helpfindsupport.cpp @@ -32,6 +32,7 @@ #include +using namespace Core; using namespace Help::Internal; HelpFindSupport::HelpFindSupport(CentralWidget *centralWidget) @@ -43,9 +44,9 @@ HelpFindSupport::~HelpFindSupport() { } -Find::FindFlags HelpFindSupport::supportedFindFlags() const +Core::FindFlags HelpFindSupport::supportedFindFlags() const { - return Find::FindBackward | Find::FindCaseSensitively; + return FindBackward | FindCaseSensitively; } QString HelpFindSupport::currentFindString() const @@ -62,20 +63,20 @@ QString HelpFindSupport::completedFindString() const return QString(); } -Find::IFindSupport::Result HelpFindSupport::findIncremental(const QString &txt, - Find::FindFlags findFlags) +Core::IFindSupport::Result HelpFindSupport::findIncremental(const QString &txt, + Core::FindFlags findFlags) { - findFlags &= ~Find::FindBackward; + findFlags &= ~FindBackward; return find(txt, findFlags, true) ? Found : NotFound; } -Find::IFindSupport::Result HelpFindSupport::findStep(const QString &txt, - Find::FindFlags findFlags) +Core::IFindSupport::Result HelpFindSupport::findStep(const QString &txt, + Core::FindFlags findFlags) { return find(txt, findFlags, false) ? Found : NotFound; } -bool HelpFindSupport::find(const QString &txt, Find::FindFlags findFlags, bool incremental) +bool HelpFindSupport::find(const QString &txt, Core::FindFlags findFlags, bool incremental) { QTC_ASSERT(m_centralWidget, return false); bool wrapped = false; @@ -92,9 +93,9 @@ HelpViewerFindSupport::HelpViewerFindSupport(HelpViewer *viewer) { } -Find::FindFlags HelpViewerFindSupport::supportedFindFlags() const +Core::FindFlags HelpViewerFindSupport::supportedFindFlags() const { - return Find::FindBackward | Find::FindCaseSensitively; + return FindBackward | FindCaseSensitively; } QString HelpViewerFindSupport::currentFindString() const @@ -103,23 +104,23 @@ QString HelpViewerFindSupport::currentFindString() const return m_viewer->selectedText(); } -Find::IFindSupport::Result HelpViewerFindSupport::findIncremental(const QString &txt, - Find::FindFlags findFlags) +Core::IFindSupport::Result HelpViewerFindSupport::findIncremental(const QString &txt, + Core::FindFlags findFlags) { QTC_ASSERT(m_viewer, return NotFound); - findFlags &= ~Find::FindBackward; + findFlags &= ~FindBackward; return find(txt, findFlags, true) ? Found : NotFound; } -Find::IFindSupport::Result HelpViewerFindSupport::findStep(const QString &txt, - Find::FindFlags findFlags) +Core::IFindSupport::Result HelpViewerFindSupport::findStep(const QString &txt, + Core::FindFlags findFlags) { QTC_ASSERT(m_viewer, return NotFound); return find(txt, findFlags, false) ? Found : NotFound; } bool HelpViewerFindSupport::find(const QString &txt, - Find::FindFlags findFlags, bool incremental) + Core::FindFlags findFlags, bool incremental) { QTC_ASSERT(m_viewer, return false); bool wrapped = false; diff --git a/src/plugins/help/helpfindsupport.h b/src/plugins/help/helpfindsupport.h index fce9eaf45e6..c67a0a18d9a 100644 --- a/src/plugins/help/helpfindsupport.h +++ b/src/plugins/help/helpfindsupport.h @@ -32,14 +32,14 @@ #include "centralwidget.h" -#include +#include namespace Help { namespace Internal { class HelpViewer; -class HelpFindSupport : public Find::IFindSupport +class HelpFindSupport : public Core::IFindSupport { Q_OBJECT @@ -48,40 +48,40 @@ public: ~HelpFindSupport(); bool supportsReplace() const { return false; } - Find::FindFlags supportedFindFlags() const; + Core::FindFlags supportedFindFlags() const; void resetIncrementalSearch() {} void clearResults() {} QString currentFindString() const; QString completedFindString() const; - Result findIncremental(const QString &txt, Find::FindFlags findFlags); - Result findStep(const QString &txt, Find::FindFlags findFlags); + Result findIncremental(const QString &txt, Core::FindFlags findFlags); + Result findStep(const QString &txt, Core::FindFlags findFlags); private: - bool find(const QString &ttf, Find::FindFlags findFlags, bool incremental); + bool find(const QString &ttf, Core::FindFlags findFlags, bool incremental); CentralWidget *m_centralWidget; }; -class HelpViewerFindSupport : public Find::IFindSupport +class HelpViewerFindSupport : public Core::IFindSupport { Q_OBJECT public: HelpViewerFindSupport(HelpViewer *viewer); bool supportsReplace() const { return false; } - Find::FindFlags supportedFindFlags() const; + Core::FindFlags supportedFindFlags() const; void resetIncrementalSearch() {} void clearResults() {} QString currentFindString() const; QString completedFindString() const { return QString(); } - Result findIncremental(const QString &txt, Find::FindFlags findFlags); - Result findStep(const QString &txt, Find::FindFlags findFlags); + Result findIncremental(const QString &txt, Core::FindFlags findFlags); + Result findStep(const QString &txt, Core::FindFlags findFlags); private: - bool find(const QString &ttf, Find::FindFlags findFlags, bool incremental); + bool find(const QString &ttf, Core::FindFlags findFlags, bool incremental); HelpViewer *m_viewer; }; diff --git a/src/plugins/help/helpindexfilter.cpp b/src/plugins/help/helpindexfilter.cpp index e964e9c428c..ebd04c3954c 100644 --- a/src/plugins/help/helpindexfilter.cpp +++ b/src/plugins/help/helpindexfilter.cpp @@ -39,7 +39,7 @@ #include -using namespace Locator; +using namespace Core; using namespace Help; using namespace Help::Internal; @@ -59,7 +59,7 @@ HelpIndexFilter::~HelpIndexFilter() { } -QList HelpIndexFilter::matchesFor(QFutureInterface &future, const QString &entry) +QList HelpIndexFilter::matchesFor(QFutureInterface &future, const QString &entry) { QStringList keywords; if (entry.length() < 2) @@ -67,17 +67,17 @@ QList HelpIndexFilter::matchesFor(QFutureInterface entries; + QList entries; foreach (const QString &keyword, keywords) { if (future.isCanceled()) break; - entries.append(FilterEntry(this, keyword, QVariant(), m_icon)); + entries.append(LocatorFilterEntry(this, keyword, QVariant(), m_icon)); } return entries; } -void HelpIndexFilter::accept(FilterEntry selection) const +void HelpIndexFilter::accept(LocatorFilterEntry selection) const { const QString &key = selection.displayName; const QMap &links = Core::HelpManager::linksForKeyword(key); diff --git a/src/plugins/help/helpindexfilter.h b/src/plugins/help/helpindexfilter.h index bf26413dac6..ae0e4bf7f4a 100644 --- a/src/plugins/help/helpindexfilter.h +++ b/src/plugins/help/helpindexfilter.h @@ -30,14 +30,14 @@ #ifndef HELPINDEXFILTER_H #define HELPINDEXFILTER_H -#include +#include #include namespace Help { namespace Internal { -class HelpIndexFilter : public Locator::ILocatorFilter +class HelpIndexFilter : public Core::ILocatorFilter { Q_OBJECT @@ -46,8 +46,8 @@ public: ~HelpIndexFilter(); // ILocatorFilter - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(Locator::FilterEntry selection) const; + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(Core::LocatorFilterEntry selection) const; void refresh(QFutureInterface &future); signals: diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 33ab67a5bd7..e75d4860e89 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -65,7 +65,7 @@ #include #include #include -#include +#include #include #include #include @@ -1227,8 +1227,8 @@ void HelpPlugin::slotReportBug() void HelpPlugin::openFindToolBar() { - if (Find::FindPlugin::instance()) - Find::FindPlugin::instance()->openFindToolBar(Find::FindPlugin::FindForwardDirection); + if (FindPlugin::instance()) + FindPlugin::instance()->openFindToolBar(FindPlugin::FindForwardDirection); } void HelpPlugin::onSideBarVisibilityChanged() diff --git a/src/plugins/help/helpviewer.h b/src/plugins/help/helpviewer.h index 1355684b1dd..8a877c317b0 100644 --- a/src/plugins/help/helpviewer.h +++ b/src/plugins/help/helpviewer.h @@ -30,7 +30,7 @@ #ifndef HELPVIEWER_H #define HELPVIEWER_H -#include +#include #include #include @@ -82,7 +82,7 @@ public: bool isForwardAvailable() const; bool isBackwardAvailable() const; - bool findText(const QString &text, Find::FindFlags flags, + bool findText(const QString &text, Core::FindFlags flags, bool incremental, bool fromSearch, bool *wrapped = 0); static bool isLocalUrl(const QUrl &url); diff --git a/src/plugins/help/helpviewer_qtb.cpp b/src/plugins/help/helpviewer_qtb.cpp index e643ccc1588..b43a9c2fa97 100644 --- a/src/plugins/help/helpviewer_qtb.cpp +++ b/src/plugins/help/helpviewer_qtb.cpp @@ -45,7 +45,6 @@ #include -using namespace Find; using namespace Help; using namespace Help::Internal; @@ -194,7 +193,7 @@ bool HelpViewer::isBackwardAvailable() const return QTextBrowser::isBackwardAvailable(); } -bool HelpViewer::findText(const QString &text, Find::FindFlags flags, +bool HelpViewer::findText(const QString &text, Core::FindFlags flags, bool incremental, bool fromSearch, bool *wrapped) { if (wrapped) @@ -208,10 +207,10 @@ bool HelpViewer::findText(const QString &text, Find::FindFlags flags, if (incremental) cursor.setPosition(position); - QTextDocument::FindFlags f = Find::textDocumentFlagsForFindFlags(flags); + QTextDocument::FindFlags f = Core::textDocumentFlagsForFindFlags(flags); QTextCursor found = doc->find(text, cursor, f); if (found.isNull()) { - if ((flags & Find::FindBackward) == 0) + if ((flags & Core::FindBackward) == 0) cursor.movePosition(QTextCursor::Start); else cursor.movePosition(QTextCursor::End); diff --git a/src/plugins/help/helpviewer_qwv.cpp b/src/plugins/help/helpviewer_qwv.cpp index f0f44bc66f2..d8301084a8c 100644 --- a/src/plugins/help/helpviewer_qwv.cpp +++ b/src/plugins/help/helpviewer_qwv.cpp @@ -58,7 +58,7 @@ #include -using namespace Find; +using namespace Core; using namespace Help; using namespace Help::Internal; @@ -412,7 +412,7 @@ bool HelpViewer::isBackwardAvailable() const return pageAction(QWebPage::Back)->isEnabled(); } -bool HelpViewer::findText(const QString &text, Find::FindFlags flags, +bool HelpViewer::findText(const QString &text, Core::FindFlags flags, bool incremental, bool fromSearch, bool *wrapped) { Q_UNUSED(incremental); @@ -420,9 +420,9 @@ bool HelpViewer::findText(const QString &text, Find::FindFlags flags, if (wrapped) *wrapped = false; QWebPage::FindFlags options; - if (flags & Find::FindBackward) + if (flags & Core::FindBackward) options |= QWebPage::FindBackward; - if (flags & Find::FindCaseSensitively) + if (flags & Core::FindCaseSensitively) options |= QWebPage::FindCaseSensitively; bool found = QWebView::findText(text, options); diff --git a/src/plugins/help/remotehelpfilter.cpp b/src/plugins/help/remotehelpfilter.cpp index 130f196f1b8..4d09abde98a 100644 --- a/src/plugins/help/remotehelpfilter.cpp +++ b/src/plugins/help/remotehelpfilter.cpp @@ -96,20 +96,20 @@ RemoteHelpFilter::~RemoteHelpFilter() { } -QList RemoteHelpFilter::matchesFor(QFutureInterface &future, const QString &pattern) +QList RemoteHelpFilter::matchesFor(QFutureInterface &future, const QString &pattern) { - QList entries; + QList entries; foreach (const QString &url, m_remoteUrls) { if (future.isCanceled()) break; - entries.append(Locator::FilterEntry(this, url.arg(pattern), QVariant(), + entries.append(Core::LocatorFilterEntry(this, url.arg(pattern), QVariant(), m_icon)); } return entries; } -void RemoteHelpFilter::accept(Locator::FilterEntry selection) const +void RemoteHelpFilter::accept(Core::LocatorFilterEntry selection) const { const QString &url = selection.displayName; if (!url.isEmpty()) diff --git a/src/plugins/help/remotehelpfilter.h b/src/plugins/help/remotehelpfilter.h index a070a0f3fb4..958deb1cbd2 100644 --- a/src/plugins/help/remotehelpfilter.h +++ b/src/plugins/help/remotehelpfilter.h @@ -32,14 +32,14 @@ #include "ui_remotehelpfilter.h" -#include +#include #include namespace Help { namespace Internal { -class RemoteHelpFilter : public Locator::ILocatorFilter +class RemoteHelpFilter : public Core::ILocatorFilter { Q_OBJECT public: @@ -47,8 +47,8 @@ public: ~RemoteHelpFilter(); // ILocatorFilter - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(Locator::FilterEntry selection) const; + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(Core::LocatorFilterEntry selection) const; void refresh(QFutureInterface &future); QByteArray saveState() const; bool restoreState(const QByteArray &state); diff --git a/src/plugins/locator/Locator.pluginspec.in b/src/plugins/locator/Locator.pluginspec.in index ecd6d22c95a..a67f7977e9f 100644 --- a/src/plugins/locator/Locator.pluginspec.in +++ b/src/plugins/locator/Locator.pluginspec.in @@ -1,4 +1,4 @@ - + Digia Plc (C) 2014 Digia Plc @@ -13,5 +13,4 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General Qt Creator Provides the Locator widget and the hooks for Locator filter implementations. http://www.qt-project.org - $$dependencyList diff --git a/src/plugins/locator/basefilefilter.cpp b/src/plugins/locator/basefilefilter.cpp deleted file mode 100644 index c802014f1e8..00000000000 --- a/src/plugins/locator/basefilefilter.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "basefilefilter.h" - -#include -#include - -#include -#include - -using namespace Core; -using namespace Locator; -using namespace Utils; - -BaseFileFilter::BaseFileFilter() - : m_forceNewSearchList(false) -{ -} - -QList BaseFileFilter::matchesFor(QFutureInterface &future, const QString &origEntry) -{ - updateFiles(); - QList betterEntries; - QList goodEntries; - QString needle = trimWildcards(origEntry); - const QString lineNoSuffix = EditorManager::splitLineNumber(&needle); - QStringMatcher matcher(needle, Qt::CaseInsensitive); - const QChar asterisk = QLatin1Char('*'); - QRegExp regexp(asterisk + needle+ asterisk, Qt::CaseInsensitive, QRegExp::Wildcard); - if (!regexp.isValid()) - return betterEntries; - const QChar pathSeparator = QDir::separator(); - const bool hasPathSeparator = needle.contains(pathSeparator); - const bool hasWildcard = needle.contains(asterisk) || needle.contains(QLatin1Char('?')); - QStringList searchListPaths; - QStringList searchListNames; - const bool containsPreviousEntry = !m_previousEntry.isEmpty() - && needle.contains(m_previousEntry); - const bool pathSeparatorAdded = !m_previousEntry.contains(pathSeparator) - && needle.contains(pathSeparator); - if (!m_forceNewSearchList && containsPreviousEntry && !pathSeparatorAdded) { - searchListPaths = m_previousResultPaths; - searchListNames = m_previousResultNames; - } else { - searchListPaths = m_files; - searchListNames = m_fileNames; - } - m_previousResultPaths.clear(); - m_previousResultNames.clear(); - m_forceNewSearchList = false; - m_previousEntry = needle; - const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(needle); - QStringListIterator paths(searchListPaths); - QStringListIterator names(searchListNames); - while (paths.hasNext() && names.hasNext()) { - if (future.isCanceled()) - break; - - QString path = paths.next(); - QString name = names.next(); - QString matchText = hasPathSeparator ? path : name; - if ((hasWildcard && regexp.exactMatch(matchText)) - || (!hasWildcard && matcher.indexIn(matchText) != -1)) { - QFileInfo fi(path); - FilterEntry entry(this, fi.fileName(), QString(path + lineNoSuffix)); - entry.extraInfo = FileUtils::shortNativePath(FileName(fi)); - entry.fileName = path; - if (matchText.startsWith(needle, caseSensitivityForPrefix)) - betterEntries.append(entry); - else - goodEntries.append(entry); - m_previousResultPaths.append(path); - m_previousResultNames.append(name); - } - } - - betterEntries.append(goodEntries); - return betterEntries; -} - -void BaseFileFilter::accept(Locator::FilterEntry selection) const -{ - EditorManager::openEditor(selection.internalData.toString(), Id(), - EditorManager::CanContainLineNumber); -} - -void BaseFileFilter::generateFileNames() -{ - m_fileNames.clear(); - foreach (const QString &fileName, m_files) { - QFileInfo fi(fileName); - m_fileNames.append(fi.fileName()); - } - m_forceNewSearchList = true; -} - -void BaseFileFilter::updateFiles() -{ -} diff --git a/src/plugins/locator/basefilefilter.h b/src/plugins/locator/basefilefilter.h deleted file mode 100644 index 7e7c7fe7860..00000000000 --- a/src/plugins/locator/basefilefilter.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef BASEFILEFILTER_H -#define BASEFILEFILTER_H - -#include "locator_global.h" -#include "ilocatorfilter.h" - -#include - -namespace Locator { - -class LOCATOR_EXPORT BaseFileFilter : public Locator::ILocatorFilter -{ - Q_OBJECT - -public: - BaseFileFilter(); - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(Locator::FilterEntry selection) const; - -protected: - virtual void updateFiles(); - void generateFileNames(); - - inline QStringList &files() { return m_files; } - inline const QStringList &files() const { return m_files; } - -private: - QStringList m_files; - QStringList m_fileNames; - QStringList m_previousResultPaths; - QStringList m_previousResultNames; - bool m_forceNewSearchList; - QString m_previousEntry; -}; - -} // namespace Locator - -#endif // BASEFILEFILTER_H diff --git a/src/plugins/locator/commandlocator.cpp b/src/plugins/locator/commandlocator.cpp deleted file mode 100644 index bf9e2eed8b9..00000000000 --- a/src/plugins/locator/commandlocator.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "commandlocator.h" - -#include - -#include - -#include - -namespace Locator { - -struct CommandLocatorPrivate -{ - QList commands; -}; - -CommandLocator::CommandLocator(Core::Id id, - const QString &displayName, - const QString &shortCutString, - QObject *parent) : - Locator::ILocatorFilter(parent), - d(new CommandLocatorPrivate) -{ - setId(id); - setDisplayName(displayName); - setShortcutString(shortCutString); -} - -CommandLocator::~CommandLocator() -{ - delete d; -} - -void CommandLocator::appendCommand(Core::Command *cmd) -{ - d->commands.push_back(cmd); -} - -QList CommandLocator::matchesFor(QFutureInterface &future, const QString &entry) -{ - QList goodEntries; - QList betterEntries; - // Get active, enabled actions matching text, store in list. - // Reference via index in extraInfo. - const QChar ampersand = QLatin1Char('&'); - const Qt::CaseSensitivity caseSensitivity_ = caseSensitivity(entry); - const int count = d->commands.size(); - for (int i = 0; i < count; i++) { - if (future.isCanceled()) - break; - if (d->commands.at(i)->isActive()) { - if (QAction *action = d->commands.at(i)->action()) - if (action->isEnabled()) { - QString text = action->text(); - text.remove(ampersand); - if (text.startsWith(entry, caseSensitivity_)) - betterEntries.append(FilterEntry(this, text, QVariant(i))); - else if (text.contains(entry, caseSensitivity_)) - goodEntries.append(FilterEntry(this, text, QVariant(i))); - } - } - } - betterEntries.append(goodEntries); - return betterEntries; -} - -void CommandLocator::accept(Locator::FilterEntry entry) const -{ - // Retrieve action via index. - const int index = entry.internalData.toInt(); - QTC_ASSERT(index >= 0 && index < d->commands.size(), return); - QAction *action = d->commands.at(index)->action(); - QTC_ASSERT(action->isEnabled(), return); - action->trigger(); -} - -void CommandLocator::refresh(QFutureInterface &) -{ -} - -} // namespace Locator diff --git a/src/plugins/locator/commandlocator.h b/src/plugins/locator/commandlocator.h deleted file mode 100644 index 3943c492825..00000000000 --- a/src/plugins/locator/commandlocator.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef COMMANDLOCATOR_H -#define COMMANDLOCATOR_H - -#include "locator_global.h" -#include "ilocatorfilter.h" - -namespace Core { class Command; } - -namespace Locator { -/* Command locators: Provides completion for a set of - * Core::Command's by sub-string of their action's text. */ - -struct CommandLocatorPrivate; - -class LOCATOR_EXPORT CommandLocator : public Locator::ILocatorFilter -{ - Q_OBJECT - -public: - CommandLocator(Core::Id id, const QString &displayName, - const QString &shortCutString, QObject *parent = 0); - ~CommandLocator(); - - void appendCommand(Core::Command *cmd); - - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(FilterEntry selection) const; - void refresh(QFutureInterface &future); - -private: - CommandLocatorPrivate *d; -}; - -} // namespace Locator - -#endif // COMMANDLOCATOR_H diff --git a/src/plugins/locator/directoryfilter.cpp b/src/plugins/locator/directoryfilter.cpp deleted file mode 100644 index f920c3de621..00000000000 --- a/src/plugins/locator/directoryfilter.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "directoryfilter.h" - -#include -#include - -using namespace Locator; -using namespace Locator::Internal; - -DirectoryFilter::DirectoryFilter() - : m_name(tr("Generic Directory Filter")), - m_dialog(0) -{ - setId(Core::Id::fromString(m_name)); - setIncludedByDefault(true); - setDisplayName(m_name); - - m_filters.append(QLatin1String("*.h")); - m_filters.append(QLatin1String("*.cpp")); - m_filters.append(QLatin1String("*.ui")); - m_filters.append(QLatin1String("*.qrc")); -} - -QByteArray DirectoryFilter::saveState() const -{ - QMutexLocker locker(&m_lock); - QByteArray value; - QDataStream out(&value, QIODevice::WriteOnly); - out << m_name; - out << m_directories; - out << m_filters; - out << shortcutString(); - out << isIncludedByDefault(); - out << files(); - return value; -} - -bool DirectoryFilter::restoreState(const QByteArray &state) -{ - QMutexLocker locker(&m_lock); - - QString shortcut; - bool defaultFilter; - - QDataStream in(state); - in >> m_name; - in >> m_directories; - in >> m_filters; - in >> shortcut; - in >> defaultFilter; - in >> files(); - - setShortcutString(shortcut); - setIncludedByDefault(defaultFilter); - - generateFileNames(); - return true; -} - -bool DirectoryFilter::openConfigDialog(QWidget *parent, bool &needsRefresh) -{ - bool success = false; - QDialog dialog(parent); - m_dialog = &dialog; - m_ui.setupUi(&dialog); - dialog.setWindowTitle(tr("Filter Configuration")); - connect(m_ui.addButton, SIGNAL(clicked()), - this, SLOT(addDirectory()), Qt::DirectConnection); - connect(m_ui.editButton, SIGNAL(clicked()), - this, SLOT(editDirectory()), Qt::DirectConnection); - connect(m_ui.removeButton, SIGNAL(clicked()), - this, SLOT(removeDirectory()), Qt::DirectConnection); - connect(m_ui.directoryList, SIGNAL(itemSelectionChanged()), - this, SLOT(updateOptionButtons()), Qt::DirectConnection); - m_ui.nameEdit->setText(m_name); - m_ui.nameEdit->selectAll(); - m_ui.directoryList->clear(); - m_ui.directoryList->addItems(m_directories); - m_ui.fileTypeEdit->setText(m_filters.join(QString(QLatin1Char(',')))); - m_ui.shortcutEdit->setText(shortcutString()); - m_ui.defaultFlag->setChecked(!isIncludedByDefault()); - updateOptionButtons(); - if (dialog.exec() == QDialog::Accepted) { - QMutexLocker locker(&m_lock); - bool directoriesChanged = false; - QStringList oldDirectories = m_directories; - QStringList oldFilters = m_filters; - m_name = m_ui.nameEdit->text().trimmed(); - m_directories.clear(); - int oldCount = oldDirectories.count(); - int newCount = m_ui.directoryList->count(); - if (oldCount != newCount) - directoriesChanged = true; - for (int i = 0; i < newCount; ++i) { - m_directories.append(m_ui.directoryList->item(i)->text()); - if (!directoriesChanged && m_directories.at(i) != oldDirectories.at(i)) - directoriesChanged = true; - } - m_filters = m_ui.fileTypeEdit->text().trimmed().split(QLatin1Char(',')); - setShortcutString(m_ui.shortcutEdit->text().trimmed()); - setIncludedByDefault(!m_ui.defaultFlag->isChecked()); - if (directoriesChanged || oldFilters != m_filters) - needsRefresh = true; - success = true; - } - return success; -} - -void DirectoryFilter::addDirectory() -{ - QString dir = QFileDialog::getExistingDirectory(m_dialog, tr("Select Directory")); - if (!dir.isEmpty()) - m_ui.directoryList->addItem(dir); -} - -void DirectoryFilter::editDirectory() -{ - if (m_ui.directoryList->selectedItems().count() < 1) - return; - QListWidgetItem *currentItem = m_ui.directoryList->selectedItems().at(0); - QString dir = QFileDialog::getExistingDirectory(m_dialog, tr("Select Directory"), - currentItem->text()); - if (!dir.isEmpty()) - currentItem->setText(dir); -} - -void DirectoryFilter::removeDirectory() -{ - if (m_ui.directoryList->selectedItems().count() < 1) - return; - QListWidgetItem *currentItem = m_ui.directoryList->selectedItems().at(0); - delete m_ui.directoryList->takeItem(m_ui.directoryList->row(currentItem)); -} - -void DirectoryFilter::updateOptionButtons() -{ - bool haveSelectedItem = (m_ui.directoryList->selectedItems().count() > 0); - m_ui.editButton->setEnabled(haveSelectedItem); - m_ui.removeButton->setEnabled(haveSelectedItem); -} - -void DirectoryFilter::refresh(QFutureInterface &future) -{ - QStringList directories; - { - QMutexLocker locker(&m_lock); - if (m_directories.count() < 1) { - files().clear(); - generateFileNames(); - future.setProgressRange(0, 1); - future.setProgressValueAndText(1, tr("%1 filter update: 0 files").arg(m_name)); - return; - } - directories = m_directories; - } - Utils::SubDirFileIterator it(directories, m_filters); - future.setProgressRange(0, it.maxProgress()); - QStringList filesFound; - while (!future.isCanceled() && it.hasNext()) { - filesFound << it.next(); - if (future.isProgressUpdateNeeded() - || future.progressValue() == 0 /*workaround for regression in Qt*/) { - future.setProgressValueAndText(it.currentProgress(), - tr("%1 filter update: %n files", 0, filesFound.size()).arg(m_name)); - } - } - - if (!future.isCanceled()) { - QMutexLocker locker(&m_lock); - files() = filesFound; - generateFileNames(); - future.setProgressValue(it.maxProgress()); - } else { - future.setProgressValueAndText(it.currentProgress(), tr("%1 filter update: canceled").arg(m_name)); - } -} diff --git a/src/plugins/locator/directoryfilter.h b/src/plugins/locator/directoryfilter.h deleted file mode 100644 index 021a5167923..00000000000 --- a/src/plugins/locator/directoryfilter.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef DIRECTORYFILTER_H -#define DIRECTORYFILTER_H - -#include "ui_directoryfilter.h" -#include "basefilefilter.h" - -#include -#include -#include -#include - -namespace Locator { -namespace Internal { - -class DirectoryFilter : public BaseFileFilter -{ - Q_OBJECT - -public: - DirectoryFilter(); - QByteArray saveState() const; - bool restoreState(const QByteArray &state); - bool openConfigDialog(QWidget *parent, bool &needsRefresh); - void refresh(QFutureInterface &future); - -private slots: - void addDirectory(); - void editDirectory(); - void removeDirectory(); - void updateOptionButtons(); - -private: - QString m_name; - QStringList m_directories; - QStringList m_filters; - // Our config dialog, uses in addDirectory and editDirectory - // to give their dialogs the right parent - QDialog *m_dialog; - Ui::DirectoryFilterOptions m_ui; - mutable QMutex m_lock; -}; - -} // namespace Internal -} // namespace Locator - -#endif // DIRECTORYFILTER_H diff --git a/src/plugins/locator/directoryfilter.ui b/src/plugins/locator/directoryfilter.ui deleted file mode 100644 index d2b954ace19..00000000000 --- a/src/plugins/locator/directoryfilter.ui +++ /dev/null @@ -1,195 +0,0 @@ - - - Locator::Internal::DirectoryFilterOptions - - - - 0 - 0 - 393 - 275 - - - - - - - - - Name: - - - - - - - - - - File types: - - - - - - - Specify file name filters, separated by comma. Filters may contain wildcards. - - - - - - - Prefix: - - - - - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - Specify a short word/abbreviation that can be used to restrict completions to files from this directory tree. -To do this, you type this shortcut and a space in the Locator entry field, and then the word to search for. - - - - - - - Limit to prefix - - - false - - - - - - - - - Add - - - - - - - Edit - - - - - - - Remove - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Directories: - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - 1 - 0 - - - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - buttonBox - accepted() - Locator::Internal::DirectoryFilterOptions - accept() - - - 353 - 174 - - - 390 - 152 - - - - - buttonBox - rejected() - Locator::Internal::DirectoryFilterOptions - reject() - - - 280 - 176 - - - 391 - 141 - - - - - diff --git a/src/plugins/locator/executefilter.cpp b/src/plugins/locator/executefilter.cpp deleted file mode 100644 index 4f7cc7404e9..00000000000 --- a/src/plugins/locator/executefilter.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "executefilter.h" - -#include -#include -#include - -#include - -using namespace Core; -using namespace Locator; -using namespace Locator::Internal; - -ExecuteFilter::ExecuteFilter() -{ - setId("Execute custom commands"); - setDisplayName(tr("Execute Custom Commands")); - setShortcutString(QString(QLatin1Char('!'))); - setIncludedByDefault(false); - - m_process = new Utils::QtcProcess(this); - m_process->setEnvironment(Utils::Environment::systemEnvironment()); - connect(m_process, SIGNAL(finished(int,QProcess::ExitStatus)), this, - SLOT(finished(int,QProcess::ExitStatus))); - connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandardOutput())); - connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStandardError())); - - m_runTimer.setSingleShot(true); - connect(&m_runTimer, SIGNAL(timeout()), this, SLOT(runHeadCommand())); -} - -QList ExecuteFilter::matchesFor(QFutureInterface &future, - const QString &entry) -{ - QList value; - if (!entry.isEmpty()) // avoid empty entry - value.append(FilterEntry(this, entry, QVariant())); - QList others; - const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry); - foreach (const QString &i, m_commandHistory) { - if (future.isCanceled()) - break; - if (i == entry) // avoid repeated entry - continue; - if (i.startsWith(entry, caseSensitivityForPrefix)) - value.append(FilterEntry(this, i, QVariant())); - else - others.append(FilterEntry(this, i, QVariant())); - } - value.append(others); - return value; -} - -void ExecuteFilter::accept(FilterEntry selection) const -{ - ExecuteFilter *p = const_cast(this); - - const QString value = selection.displayName.trimmed(); - const int index = m_commandHistory.indexOf(value); - if (index != -1 && index != 0) - p->m_commandHistory.removeAt(index); - if (index != 0) - p->m_commandHistory.prepend(value); - - bool found; - QString workingDirectory = Core::VariableManager::value("CurrentDocument:Path", &found); - if (!found || workingDirectory.isEmpty()) - workingDirectory = Core::VariableManager::value("CurrentProject:Path", &found); - - ExecuteData d; - d.workingDirectory = workingDirectory; - const int pos = value.indexOf(QLatin1Char(' ')); - if (pos == -1) { - d.executable = value; - } else { - d.executable = value.left(pos); - d.arguments = value.right(value.length() - pos - 1); - } - - if (m_process->state() != QProcess::NotRunning) { - const QString info(tr("Previous command is still running ('%1').\nDo you want to kill it?") - .arg(p->headCommand())); - int r = QMessageBox::question(0, tr("Kill Previous Process?"), info, - QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, - QMessageBox::Yes); - if (r == QMessageBox::Yes) - m_process->kill(); - if (r != QMessageBox::Cancel) - p->m_taskQueue.enqueue(d); - return; - } - - p->m_taskQueue.enqueue(d); - p->runHeadCommand(); -} - -void ExecuteFilter::finished(int exitCode, QProcess::ExitStatus status) -{ - const QString commandName = headCommand(); - QString message; - if (status == QProcess::NormalExit && exitCode == 0) - message = tr("Command '%1' finished.").arg(commandName); - else - message = tr("Command '%1' failed.").arg(commandName); - MessageManager::write(message); - - m_taskQueue.dequeue(); - if (!m_taskQueue.isEmpty()) - m_runTimer.start(500); -} - -void ExecuteFilter::readStandardOutput() -{ - QByteArray data = m_process->readAllStandardOutput(); - MessageManager::write(QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(), - &m_stdoutState)); -} - -void ExecuteFilter::readStandardError() -{ - static QTextCodec::ConverterState state; - QByteArray data = m_process->readAllStandardError(); - MessageManager::write(QTextCodec::codecForLocale()->toUnicode(data.constData(), data.size(), - &m_stderrState)); -} - -void ExecuteFilter::runHeadCommand() -{ - if (!m_taskQueue.isEmpty()) { - const ExecuteData &d = m_taskQueue.head(); - const QString fullPath = Utils::Environment::systemEnvironment().searchInPath(d.executable); - if (fullPath.isEmpty()) { - MessageManager::write(tr("Could not find executable for '%1'").arg(d.executable)); - m_taskQueue.dequeue(); - runHeadCommand(); - return; - } - MessageManager::write(tr("Starting command '%1'").arg(headCommand())); - m_process->setWorkingDirectory(d.workingDirectory); - m_process->setCommand(fullPath, d.arguments); - m_process->start(); - m_process->closeWriteChannel(); - if (!m_process->waitForStarted(1000)) { - MessageManager::write(tr("Could not start process: %1").arg(m_process->errorString())); - m_taskQueue.dequeue(); - runHeadCommand(); - } - } -} - -QString ExecuteFilter::headCommand() const -{ - if (m_taskQueue.isEmpty()) - return QString(); - const ExecuteData &data = m_taskQueue.head(); - if (data.arguments.isEmpty()) - return data.executable; - else - return data.executable + QLatin1Char(' ') + data.arguments; -} diff --git a/src/plugins/locator/executefilter.h b/src/plugins/locator/executefilter.h deleted file mode 100644 index 9d2f0e946ca..00000000000 --- a/src/plugins/locator/executefilter.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef EXECUTEFILTER_H -#define EXECUTEFILTER_H - -#include "ilocatorfilter.h" - -#include - -#include -#include -#include -#include - -namespace Locator { -namespace Internal { - -class ExecuteFilter : public Locator::ILocatorFilter -{ - Q_OBJECT - struct ExecuteData - { - QString executable; - QString arguments; - QString workingDirectory; - }; - -public: - ExecuteFilter(); - QList matchesFor(QFutureInterface &future, - const QString &entry); - void accept(Locator::FilterEntry selection) const; - void refresh(QFutureInterface &) {} - -private slots: - void finished(int exitCode, QProcess::ExitStatus status); - void readStandardOutput(); - void readStandardError(); - void runHeadCommand(); - -private: - QString headCommand() const; - -private: - QQueue m_taskQueue; - QStringList m_commandHistory; - Utils::QtcProcess *m_process; - QTimer m_runTimer; - QTextCodec::ConverterState m_stdoutState; - QTextCodec::ConverterState m_stderrState; -}; - -} // namespace Internal -} // namespace Locator - -#endif // EXECUTEFILTER_H diff --git a/src/plugins/locator/filesystemfilter.cpp b/src/plugins/locator/filesystemfilter.cpp deleted file mode 100644 index b5a11399641..00000000000 --- a/src/plugins/locator/filesystemfilter.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "filesystemfilter.h" -#include "locatorwidget.h" -#include -#include - -#include - -using namespace Core; -using namespace Locator; -using namespace Locator::Internal; - -namespace { - -QList *categorize(const QString &entry, const QString &candidate, - Qt::CaseSensitivity caseSensitivity, - QList *betterEntries, QList *goodEntries) -{ - if (entry.isEmpty() || candidate.startsWith(entry, caseSensitivity)) - return betterEntries; - else if (candidate.contains(entry, caseSensitivity)) - return goodEntries; - return 0; -} - -} // anynoumous namespace - -FileSystemFilter::FileSystemFilter(LocatorWidget *locatorWidget) - : m_locatorWidget(locatorWidget), m_includeHidden(true) -{ - setId("Files in file system"); - setDisplayName(tr("Files in File System")); - setShortcutString(QString(QLatin1Char('f'))); - setIncludedByDefault(false); -} - -QList FileSystemFilter::matchesFor(QFutureInterface &future, const QString &entry) -{ - QList goodEntries; - QList betterEntries; - QFileInfo entryInfo(entry); - QString name = entryInfo.fileName(); - QString directory = entryInfo.path(); - QString filePath = entryInfo.filePath(); - if (entryInfo.isRelative()) { - if (filePath.startsWith(QLatin1String("~/"))) { - directory.replace(0, 1, QDir::homePath()); - } else { - IDocument *document= EditorManager::currentDocument(); - if (document && !document->filePath().isEmpty()) { - QFileInfo info(document->filePath()); - directory.prepend(info.absolutePath() + QLatin1Char('/')); - } - } - } - QDir dirInfo(directory); - QDir::Filters dirFilter = QDir::Dirs|QDir::Drives|QDir::NoDot; - QDir::Filters fileFilter = QDir::Files; - if (m_includeHidden) { - dirFilter |= QDir::Hidden; - fileFilter |= QDir::Hidden; - } - const Qt::CaseSensitivity caseSensitivity_ = caseSensitivity(entry); - QStringList dirs = dirInfo.entryList(dirFilter, - QDir::Name|QDir::IgnoreCase|QDir::LocaleAware); - QStringList files = dirInfo.entryList(fileFilter, - QDir::Name|QDir::IgnoreCase|QDir::LocaleAware); - foreach (const QString &dir, dirs) { - if (future.isCanceled()) - break; - if (QList *category = categorize(name, dir, caseSensitivity_, &betterEntries, - &goodEntries)) { - const QString fullPath = dirInfo.filePath(dir); - FilterEntry filterEntry(this, dir, QVariant()); - filterEntry.fileName = fullPath; - category->append(filterEntry); - } - } - // file names can match with +linenumber or :linenumber - name = entry; - const QString lineNoSuffix = EditorManager::splitLineNumber(&name); - name = QFileInfo(name).fileName(); - foreach (const QString &file, files) { - if (future.isCanceled()) - break; - if (QList *category = categorize(name, file, caseSensitivity_, &betterEntries, - &goodEntries)) { - const QString fullPath = dirInfo.filePath(file); - FilterEntry filterEntry(this, file, QString(fullPath + lineNoSuffix)); - filterEntry.fileName = fullPath; - category->append(filterEntry); - } - } - betterEntries.append(goodEntries); - return betterEntries; -} - -void FileSystemFilter::accept(FilterEntry selection) const -{ - QString fileName = selection.fileName; - QFileInfo info(fileName); - if (info.isDir()) { - QString value = shortcutString(); - value += QLatin1Char(' '); - value += QDir::toNativeSeparators(info.absoluteFilePath() + QLatin1Char('/')); - m_locatorWidget->show(value, value.length()); - return; - } - EditorManager::openEditor(selection.internalData.toString(), Id(), - EditorManager::CanContainLineNumber); -} - -bool FileSystemFilter::openConfigDialog(QWidget *parent, bool &needsRefresh) -{ - Q_UNUSED(needsRefresh) - Ui::FileSystemFilterOptions ui; - QDialog dialog(parent); - ui.setupUi(&dialog); - - ui.hiddenFilesFlag->setChecked(m_includeHidden); - ui.limitCheck->setChecked(!isIncludedByDefault()); - ui.shortcutEdit->setText(shortcutString()); - - if (dialog.exec() == QDialog::Accepted) { - m_includeHidden = ui.hiddenFilesFlag->isChecked(); - setShortcutString(ui.shortcutEdit->text().trimmed()); - setIncludedByDefault(!ui.limitCheck->isChecked()); - return true; - } - return false; -} - -QByteArray FileSystemFilter::saveState() const -{ - QByteArray value; - QDataStream out(&value, QIODevice::WriteOnly); - out << m_includeHidden; - out << shortcutString(); - out << isIncludedByDefault(); - return value; -} - -bool FileSystemFilter::restoreState(const QByteArray &state) -{ - QDataStream in(state); - in >> m_includeHidden; - - // An attempt to prevent setting this on old configuration - if (!in.atEnd()) { - QString shortcut; - bool defaultFilter; - in >> shortcut; - in >> defaultFilter; - setShortcutString(shortcut); - setIncludedByDefault(defaultFilter); - } - - return true; -} diff --git a/src/plugins/locator/filesystemfilter.h b/src/plugins/locator/filesystemfilter.h deleted file mode 100644 index 9708dca4897..00000000000 --- a/src/plugins/locator/filesystemfilter.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef FILESYSTEMFILTER_H -#define FILESYSTEMFILTER_H - -#include "ilocatorfilter.h" -#include "ui_filesystemfilter.h" - -#include -#include -#include -#include - -namespace Locator { -namespace Internal { - -class LocatorWidget; - -class FileSystemFilter : public Locator::ILocatorFilter -{ - Q_OBJECT - -public: - explicit FileSystemFilter(LocatorWidget *locatorWidget); - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(Locator::FilterEntry selection) const; - QByteArray saveState() const; - bool restoreState(const QByteArray &state); - bool openConfigDialog(QWidget *parent, bool &needsRefresh); - void refresh(QFutureInterface &) {} - -private: - LocatorWidget *m_locatorWidget; - bool m_includeHidden; -}; - -} // namespace Internal -} // namespace Locator - -#endif // FILESYSTEMFILTER_H diff --git a/src/plugins/locator/filesystemfilter.ui b/src/plugins/locator/filesystemfilter.ui deleted file mode 100644 index 8fa9a0af01e..00000000000 --- a/src/plugins/locator/filesystemfilter.ui +++ /dev/null @@ -1,111 +0,0 @@ - - - Locator::Internal::FileSystemFilterOptions - - - - 0 - 0 - 360 - 131 - - - - Add Filter Configuration - - - - - - Prefix: - - - shortcutEdit - - - - - - - - - - Limit to prefix - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - Qt::Vertical - - - - 20 - 20 - - - - - - - - Include hidden files - - - - - - - Filter: - - - - - - - - - buttonBox - accepted() - Locator::Internal::FileSystemFilterOptions - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - Locator::Internal::FileSystemFilterOptions - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/src/plugins/locator/ilocatorfilter.cpp b/src/plugins/locator/ilocatorfilter.cpp deleted file mode 100644 index 70e8374c3ba..00000000000 --- a/src/plugins/locator/ilocatorfilter.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "ilocatorfilter.h" - -#include -#include -#include -#include -#include -#include - -using namespace Locator; - -ILocatorFilter::ILocatorFilter(QObject *parent): - QObject(parent), - m_priority(Medium), - m_includedByDefault(false), - m_hidden(false), - m_enabled(true), - m_isConfigurable(true) -{ -} - -QString ILocatorFilter::shortcutString() const -{ - return m_shortcut; -} - -void ILocatorFilter::setShortcutString(const QString &shortcut) -{ - m_shortcut = shortcut; -} - -QByteArray ILocatorFilter::saveState() const -{ - QByteArray value; - QDataStream out(&value, QIODevice::WriteOnly); - out << shortcutString(); - out << isIncludedByDefault(); - return value; -} - -bool ILocatorFilter::restoreState(const QByteArray &state) -{ - QString shortcut; - bool defaultFilter; - - QDataStream in(state); - in >> shortcut; - in >> defaultFilter; - - setShortcutString(shortcut); - setIncludedByDefault(defaultFilter); - return true; -} - -bool ILocatorFilter::openConfigDialog(QWidget *parent, bool &needsRefresh) -{ - Q_UNUSED(needsRefresh) - - QDialog dialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint); - dialog.setWindowTitle(tr("Filter Configuration")); - - QVBoxLayout *vlayout = new QVBoxLayout(&dialog); - QHBoxLayout *hlayout = new QHBoxLayout; - QLineEdit *shortcutEdit = new QLineEdit(shortcutString()); - QCheckBox *limitCheck = new QCheckBox(tr("Limit to prefix")); - limitCheck->setChecked(!isIncludedByDefault()); - - hlayout->addWidget(new QLabel(tr("Prefix:"))); - hlayout->addWidget(shortcutEdit); - hlayout->addWidget(limitCheck); - - QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | - QDialogButtonBox::Cancel); - connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept())); - connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject())); - - vlayout->addLayout(hlayout); - vlayout->addStretch(); - vlayout->addWidget(buttonBox); - - if (dialog.exec() == QDialog::Accepted) { - setShortcutString(shortcutEdit->text().trimmed()); - setIncludedByDefault(!limitCheck->isChecked()); - return true; - } - - return false; -} - -QString ILocatorFilter::trimWildcards(const QString &str) -{ - if (str.isEmpty()) - return str; - int first = 0, last = str.size() - 1; - const QChar asterisk = QLatin1Char('*'); - const QChar question = QLatin1Char('?'); - while (first < str.size() && (str.at(first) == asterisk || str.at(first) == question)) - ++first; - while (last >= 0 && (str.at(last) == asterisk || str.at(last) == question)) - --last; - if (first > last) - return QString(); - return str.mid(first, last - first + 1); -} - -Qt::CaseSensitivity ILocatorFilter::caseSensitivity(const QString &str) -{ - return str == str.toLower() ? Qt::CaseInsensitive : Qt::CaseSensitive; -} - -bool ILocatorFilter::isConfigurable() const -{ - return m_isConfigurable; -} - -bool ILocatorFilter::isIncludedByDefault() const -{ - return m_includedByDefault; -} - -void ILocatorFilter::setIncludedByDefault(bool includedByDefault) -{ - m_includedByDefault = includedByDefault; -} - -bool ILocatorFilter::isHidden() const -{ - return m_hidden; -} - -void ILocatorFilter::setHidden(bool hidden) -{ - m_hidden = hidden; -} - -bool ILocatorFilter::isEnabled() const -{ - return m_enabled; -} - -Core::Id ILocatorFilter::id() const -{ - return m_id; -} - -QString ILocatorFilter::displayName() const -{ - return m_displayName; -} - -ILocatorFilter::Priority ILocatorFilter::priority() const -{ - return m_priority; -} - -void ILocatorFilter::setEnabled(bool enabled) -{ - m_enabled = enabled; -} - -void ILocatorFilter::setId(Core::Id id) -{ - m_id = id; -} - -void ILocatorFilter::setPriority(Priority priority) -{ - m_priority = priority; -} - -void ILocatorFilter::setDisplayName(const QString &displayString) -{ - m_displayName = displayString; -} - -void ILocatorFilter::setConfigurable(bool configurable) -{ - m_isConfigurable = configurable; -} diff --git a/src/plugins/locator/ilocatorfilter.h b/src/plugins/locator/ilocatorfilter.h deleted file mode 100644 index b3ca3039fc3..00000000000 --- a/src/plugins/locator/ilocatorfilter.h +++ /dev/null @@ -1,169 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef ILOCATORFILTER_H -#define ILOCATORFILTER_H - -#include "locator_global.h" - -#include - -#include -#include -#include - -namespace Locator { - -class ILocatorFilter; - -struct FilterEntry -{ - FilterEntry() - : filter(0) - , fileIconResolved(false) - {} - - FilterEntry(ILocatorFilter *fromFilter, const QString &name, const QVariant &data, - const QIcon &icon = QIcon()) - : filter(fromFilter) - , displayName(name) - , internalData(data) - , displayIcon(icon) - , fileIconResolved(false) - {} - - bool operator==(const FilterEntry &other) const { - if (internalData.canConvert(QVariant::String)) - return (internalData.toString() == other.internalData.toString()); - return internalData.constData() == other.internalData.constData(); - } - - /* backpointer to creating filter */ - ILocatorFilter *filter; - /* displayed string */ - QString displayName; - /* extra information displayed in light-gray in a second column (optional) */ - QString extraInfo; - /* can be used by the filter to save more information about the entry */ - QVariant internalData; - /* icon to display along with the entry */ - QIcon displayIcon; - /* file name, if the entry is related to a file, is used e.g. for resolving a file icon */ - QString fileName; - /* internal */ - bool fileIconResolved; -}; - -class LOCATOR_EXPORT ILocatorFilter : public QObject -{ - Q_OBJECT - -public: - enum Priority {High = 0, Medium = 1, Low = 2}; - - ILocatorFilter(QObject *parent = 0); - virtual ~ILocatorFilter() {} - - /* Internal Id. */ - Core::Id id() const; - - /* Visible name. */ - QString displayName() const; - - /* Selection list order in case of multiple active filters (high goes on top). */ - Priority priority() const; - - /* String to type to use this filter exclusively. */ - QString shortcutString() const; - - /* List of matches for the given user entry. */ - virtual QList matchesFor(QFutureInterface &future, const QString &entry) = 0; - - /* User has selected the given entry that belongs to this filter. */ - virtual void accept(FilterEntry selection) const = 0; - - /* Implement to update caches on user request, if that's a long operation. */ - virtual void refresh(QFutureInterface &future) = 0; - - /* Saved state is used to restore the filter at start up. */ - virtual QByteArray saveState() const; - - /* Used to restore the filter at start up. */ - virtual bool restoreState(const QByteArray &state); - - /* User wants to configure this filter (if supported). Use it to pop up a dialog. - * needsRefresh is used as a hint to indicate that refresh should be called. - * The default implementation allows changing the shortcut and whether the filter - * is enabled by default. - */ - virtual bool openConfigDialog(QWidget *parent, bool &needsRefresh); - - /* If there is a configure dialog available for this filter. The default - * implementation returns true. */ - bool isConfigurable() const; - - /* Is this filter used also when the shortcutString is not used? */ - bool isIncludedByDefault() const; - - /* Returns whether the filter should be hidden from configuration and menus. */ - bool isHidden() const; - - /* Returns whether the filter should be enabled and used in menus. */ - bool isEnabled() const; - - static QString trimWildcards(const QString &str); - static Qt::CaseSensitivity caseSensitivity(const QString &str); - -public slots: - /* Enable or disable the filter. */ - void setEnabled(bool enabled); - -protected: - void setShortcutString(const QString &shortcut); - void setIncludedByDefault(bool includedByDefault); - void setHidden(bool hidden); - void setId(Core::Id id); - void setPriority(Priority priority); - void setDisplayName(const QString &displayString); - void setConfigurable(bool configurable); - -private: - Core::Id m_id; - QString m_shortcut; - Priority m_priority; - QString m_displayName; - bool m_includedByDefault; - bool m_hidden; - bool m_enabled; - bool m_isConfigurable; -}; - -} // namespace Locator - -#endif // ILOCATORFILTER_H diff --git a/src/plugins/locator/images/locator.png b/src/plugins/locator/images/locator.png deleted file mode 100644 index 000ee1c0185..00000000000 Binary files a/src/plugins/locator/images/locator.png and /dev/null differ diff --git a/src/plugins/locator/images/reload.png b/src/plugins/locator/images/reload.png deleted file mode 100644 index b5afefb32bc..00000000000 Binary files a/src/plugins/locator/images/reload.png and /dev/null differ diff --git a/src/plugins/locator/locator.pro b/src/plugins/locator/locator.pro index 69c237599b2..a293b5ae63a 100644 --- a/src/plugins/locator/locator.pro +++ b/src/plugins/locator/locator.pro @@ -1,43 +1,4 @@ DEFINES += LOCATOR_LIBRARY include(../../qtcreatorplugin.pri) -HEADERS += locatorplugin.h \ - commandlocator.h \ - locatorwidget.h \ - locatorfiltersfilter.h \ - settingspage.h \ - ilocatorfilter.h \ - opendocumentsfilter.h \ - filesystemfilter.h \ - locatorconstants.h \ - directoryfilter.h \ - locatormanager.h \ - basefilefilter.h \ - locator_global.h \ - executefilter.h \ - locatorsearchutils.h -SOURCES += locatorplugin.cpp \ - commandlocator.cpp \ - locatorwidget.cpp \ - locatorfiltersfilter.cpp \ - opendocumentsfilter.cpp \ - filesystemfilter.cpp \ - settingspage.cpp \ - directoryfilter.cpp \ - locatormanager.cpp \ - basefilefilter.cpp \ - ilocatorfilter.cpp \ - executefilter.cpp \ - locatorsearchutils.cpp -FORMS += settingspage.ui \ - filesystemfilter.ui \ - directoryfilter.ui -RESOURCES += locator.qrc - -equals(TEST, 1) { - HEADERS += locatorfiltertest.h - SOURCES += \ - locatorfiltertest.cpp \ - locator_test.cpp - DEFINES += SRCDIR=\\\"$$PWD\\\" -} +SOURCES += locatorplugin.cpp diff --git a/src/plugins/locator/locator.qbs b/src/plugins/locator/locator.qbs index 0e06a3b4341..b32738a9f72 100644 --- a/src/plugins/locator/locator.qbs +++ b/src/plugins/locator/locator.qbs @@ -5,56 +5,7 @@ import QtcPlugin QtcPlugin { name: "Locator" - - Depends { name: "Qt"; submodules: ["widgets", "xml", "network", "script"] } Depends { name: "Core" } - files: [ - "basefilefilter.cpp", - "basefilefilter.h", - "commandlocator.cpp", - "commandlocator.h", - "directoryfilter.cpp", - "directoryfilter.h", - "directoryfilter.ui", - "executefilter.cpp", - "executefilter.h", - "filesystemfilter.cpp", - "filesystemfilter.h", - "filesystemfilter.ui", - "ilocatorfilter.cpp", - "ilocatorfilter.h", - "locator.qrc", - "locator_global.h", - "locatorconstants.h", - "locatorfiltersfilter.cpp", - "locatorfiltersfilter.h", - "locatormanager.cpp", - "locatormanager.h", - "locatorplugin.cpp", - "locatorplugin.h", - "locatorsearchutils.cpp", - "locatorsearchutils.h", - "locatorwidget.cpp", - "locatorwidget.h", - "opendocumentsfilter.cpp", - "opendocumentsfilter.h", - "settingspage.cpp", - "settingspage.h", - "settingspage.ui", - "images/locator.png", - "images/reload.png", - ] - - Group { - name: "Tests" - condition: project.testsEnabled - files: [ - "locatorfiltertest.cpp", - "locatorfiltertest.h", - "locator_test.cpp" - ] - - cpp.defines: outer.concat(['SRCDIR="' + FileInfo.path(filePath) + '"']) - } + files: [ "locatorplugin.cpp" ] } diff --git a/src/plugins/locator/locator.qrc b/src/plugins/locator/locator.qrc deleted file mode 100644 index 4cd5df4f13d..00000000000 --- a/src/plugins/locator/locator.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - images/reload.png - images/locator.png - - diff --git a/src/plugins/locator/locator_dependencies.pri b/src/plugins/locator/locator_dependencies.pri index 899b5554a6c..bb53d187025 100644 --- a/src/plugins/locator/locator_dependencies.pri +++ b/src/plugins/locator/locator_dependencies.pri @@ -1,3 +1,2 @@ QTC_PLUGIN_NAME = Locator -QTC_PLUGIN_DEPENDS += \ - coreplugin +QTC_PLUGIN_DEPENDS += diff --git a/src/plugins/locator/locator_global.h b/src/plugins/locator/locator_global.h deleted file mode 100644 index 751f7c17b5c..00000000000 --- a/src/plugins/locator/locator_global.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef LOCATOR_GLOBAL_H -#define LOCATOR_GLOBAL_H - -#include - -#if defined(LOCATOR_LIBRARY) -# define LOCATOR_EXPORT Q_DECL_EXPORT -#else -# define LOCATOR_EXPORT Q_DECL_IMPORT -#endif - -#endif // LOCATOR_GLOBAL_H diff --git a/src/plugins/locator/locator_test.cpp b/src/plugins/locator/locator_test.cpp deleted file mode 100644 index ea68c53c125..00000000000 --- a/src/plugins/locator/locator_test.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - - -#include "locatorplugin.h" - -#include "basefilefilter.h" -#include "locatorfiltertest.h" - -#include -#include - -#include -#include -#include - -using namespace Locator::Tests; - -namespace { - -QTC_DECLARE_MYTESTDATADIR("../../../tests/locators/") - -class MyBaseFileFilter : public Locator::BaseFileFilter -{ -public: - MyBaseFileFilter(const QStringList &theFiles) - { - files().clear(); - files().append(theFiles); - BaseFileFilter::generateFileNames(); - } - - void refresh(QFutureInterface &) {} - -protected: - void updateFiles() {} -}; - -inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); } - -class ReferenceData -{ -public: - ReferenceData() {} - ReferenceData(const QString &searchText, const ResultDataList &results) - : searchText(searchText), results(results) {} - - QString searchText; - ResultDataList results; -}; - -} // anonymous namespace - -Q_DECLARE_METATYPE(ReferenceData) -Q_DECLARE_METATYPE(QList) - -void Locator::Internal::LocatorPlugin::test_basefilefilter() -{ - QFETCH(QStringList, testFiles); - QFETCH(QList, referenceDataList); - - MyBaseFileFilter filter(testFiles); - BasicLocatorFilterTest test(&filter); - - foreach (const ReferenceData &reference, referenceDataList) { - const QList filterEntries = test.matchesFor(reference.searchText); - const ResultDataList results = ResultData::fromFilterEntryList(filterEntries); -// QTextStream(stdout) << "----" << endl; -// ResultData::printFilterEntries(results); - QCOMPARE(results, reference.results); - } -} - -void Locator::Internal::LocatorPlugin::test_basefilefilter_data() -{ - QTest::addColumn("testFiles"); - QTest::addColumn >("referenceDataList"); - - const QChar pathSeparator = QDir::separator(); - const MyTestDataDir testDir(QLatin1String("testdata_basic")); - const QStringList testFiles = QStringList() - << QDir::toNativeSeparators(testDir.file(QLatin1String("file.cpp"))) - << QDir::toNativeSeparators(testDir.file(QLatin1String("main.cpp"))) - << QDir::toNativeSeparators(testDir.file(QLatin1String("subdir/main.cpp"))); - QStringList testFilesShort; - foreach (const QString &file, testFiles) - testFilesShort << Utils::FileUtils::shortNativePath(Utils::FileName::fromString(file)); - - QTest::newRow("BaseFileFilter-EmptyInput") - << testFiles - << (QList() - << ReferenceData( - QString(), - (QList() - << ResultData(_("file.cpp"), testFilesShort.at(0)) - << ResultData(_("main.cpp"), testFilesShort.at(1)) - << ResultData(_("main.cpp"), testFilesShort.at(2)))) - ); - - QTest::newRow("BaseFileFilter-InputIsFileName") - << testFiles - << (QList() - << ReferenceData( - _("main.cpp"), - (QList() - << ResultData(_("main.cpp"), testFilesShort.at(1)) - << ResultData(_("main.cpp"), testFilesShort.at(2)))) - ); - - QTest::newRow("BaseFileFilter-InputIsFilePath") - << testFiles - << (QList() - << ReferenceData( - QString(_("subdir") + pathSeparator + _("main.cpp")), - (QList() - << ResultData(_("main.cpp"), testFilesShort.at(2)))) - ); - - QTest::newRow("BaseFileFilter-InputIsDirIsPath") - << testFiles - << (QList() - << ReferenceData( _("subdir"), QList()) - << ReferenceData( - QString(_("subdir") + pathSeparator + _("main.cpp")), - (QList() - << ResultData(_("main.cpp"), testFilesShort.at(2)))) - ); - - QTest::newRow("BaseFileFilter-InputIsFileNameFilePathFileName") - << testFiles - << (QList() - << ReferenceData( - _("main.cpp"), - (QList() - << ResultData(_("main.cpp"), testFilesShort.at(1)) - << ResultData(_("main.cpp"), testFilesShort.at(2)))) - << ReferenceData( - QString(_("subdir") + pathSeparator + _("main.cpp")), - (QList() - << ResultData(_("main.cpp"), testFilesShort.at(2)))) - << ReferenceData( - _("main.cpp"), - (QList() - << ResultData(_("main.cpp"), testFilesShort.at(1)) - << ResultData(_("main.cpp"), testFilesShort.at(2)))) - ); -} diff --git a/src/plugins/locator/locatorconstants.h b/src/plugins/locator/locatorconstants.h deleted file mode 100644 index 71bca5f0af0..00000000000 --- a/src/plugins/locator/locatorconstants.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef LOCATORCONSTANTS_H -#define LOCATORCONSTANTS_H - -#include - -namespace Locator { -namespace Constants { - -const char FILTER_OPTIONS_PAGE[] = QT_TRANSLATE_NOOP("Locator", "Locator"); -const char TASK_INDEX[] = "Locator.Task.Index"; - -} // namespace Constants -} // namespace Locator - -#endif // LOCATORCONSTANTS_H diff --git a/src/plugins/locator/locatorfiltersfilter.cpp b/src/plugins/locator/locatorfiltersfilter.cpp deleted file mode 100644 index ff69e2a3fe3..00000000000 --- a/src/plugins/locator/locatorfiltersfilter.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "locatorfiltersfilter.h" -#include "locatorplugin.h" -#include "locatorwidget.h" - -#include - -using namespace Locator; -using namespace Locator::Internal; - -Q_DECLARE_METATYPE(ILocatorFilter*) - -LocatorFiltersFilter::LocatorFiltersFilter(LocatorPlugin *plugin, - LocatorWidget *locatorWidget): - m_plugin(plugin), - m_locatorWidget(locatorWidget), - m_icon(QIcon(QLatin1String(Core::Constants::ICON_NEXT))) -{ - setId("FiltersFilter"); - setDisplayName(tr("Available filters")); - setIncludedByDefault(true); - setHidden(true); - setPriority(High); - setConfigurable(false); -} - -QList LocatorFiltersFilter::matchesFor(QFutureInterface &future, const QString &entry) -{ - QList entries; - if (!entry.isEmpty()) - return entries; - - QMap uniqueFilters; - foreach (ILocatorFilter *filter, m_plugin->filters()) { - const QString filterId = filter->shortcutString() + QLatin1Char(',') + filter->displayName(); - uniqueFilters.insert(filterId, filter); - } - - foreach (ILocatorFilter *filter, uniqueFilters) { - if (future.isCanceled()) - break; - if (!filter->shortcutString().isEmpty() && !filter->isHidden() && filter->isEnabled()) { - FilterEntry filterEntry(this, - filter->shortcutString(), - QVariant::fromValue(filter), - m_icon); - filterEntry.extraInfo = filter->displayName(); - entries.append(filterEntry); - } - } - - return entries; -} - -void LocatorFiltersFilter::accept(FilterEntry selection) const -{ - ILocatorFilter *filter = selection.internalData.value(); - if (filter) - m_locatorWidget->show(filter->shortcutString() + QLatin1Char(' '), - filter->shortcutString().length() + 1); -} - -void LocatorFiltersFilter::refresh(QFutureInterface &future) -{ - Q_UNUSED(future) - // Nothing to refresh -} diff --git a/src/plugins/locator/locatorfiltersfilter.h b/src/plugins/locator/locatorfiltersfilter.h deleted file mode 100644 index 8fb7bab8e39..00000000000 --- a/src/plugins/locator/locatorfiltersfilter.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef LOCATORFILTERSFILTER_H -#define LOCATORFILTERSFILTER_H - -#include "ilocatorfilter.h" - -#include - -namespace Locator { -namespace Internal { - -class LocatorPlugin; -class LocatorWidget; - -/*! - This filter provides the user with the list of available Locator filters. - The list is only shown when nothing has been typed yet. - */ -class LocatorFiltersFilter : public ILocatorFilter -{ - Q_OBJECT - -public: - LocatorFiltersFilter(LocatorPlugin *plugin, - LocatorWidget *locatorWidget); - - // ILocatorFilter - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(FilterEntry selection) const; - void refresh(QFutureInterface &future); - -private: - LocatorPlugin *m_plugin; - LocatorWidget *m_locatorWidget; - QIcon m_icon; -}; - -} // namespace Internal -} // namespace Locator - -#endif // LOCATORFILTERSFILTER_H diff --git a/src/plugins/locator/locatorfiltertest.cpp b/src/plugins/locator/locatorfiltertest.cpp deleted file mode 100644 index db5c63e4cf4..00000000000 --- a/src/plugins/locator/locatorfiltertest.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - - -#include "locatorfiltertest.h" -#include "locatorsearchutils.h" - -#include - -#include -#include -#include -#include - -using namespace Locator; -using namespace Locator::Tests; - -BasicLocatorFilterTest::BasicLocatorFilterTest(ILocatorFilter *filter) : m_filter(filter) -{ -} - -QList BasicLocatorFilterTest::matchesFor(const QString &searchText) -{ - doBeforeLocatorRun(); - const QList filters = QList() << m_filter; - QFuture locatorSearch = QtConcurrent::run(Locator::Internal::runSearch, - filters, searchText); - locatorSearch.waitForFinished(); - doAfterLocatorRun(); - return locatorSearch.results(); -} - -ResultData::ResultData() -{ -} - -ResultData::ResultData(const QString &textColumn1, const QString &textColumn2) - : textColumn1(textColumn1), textColumn2(textColumn2) -{ -} - -bool ResultData::operator==(const ResultData &other) const -{ - return textColumn1 == other.textColumn1 && textColumn2 == other.textColumn2; -} - -ResultData::ResultDataList ResultData::fromFilterEntryList(const QList &entries) -{ - ResultDataList result; - foreach (const FilterEntry &entry, entries) - result << ResultData(entry.displayName, entry.extraInfo); - return result; -} - -void ResultData::printFilterEntries(const ResultData::ResultDataList &entries) -{ - QTextStream out(stdout); - foreach (const ResultData entry, entries) { - out << "<< ResultData(_(\"" << entry.textColumn1 << "\"), _(\"" << entry.textColumn2 - << "\"))" << endl; - } -} diff --git a/src/plugins/locator/locatorfiltertest.h b/src/plugins/locator/locatorfiltertest.h deleted file mode 100644 index 84217808b81..00000000000 --- a/src/plugins/locator/locatorfiltertest.h +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - - -#ifndef LOCATORFILTERTEST_H -#define LOCATORFILTERTEST_H - -#include "locator_global.h" -#include "ilocatorfilter.h" - -#include - -namespace Locator { -namespace Tests { - -/// Runs a locator filter for a search text and returns the results. -class LOCATOR_EXPORT BasicLocatorFilterTest -{ -public: - BasicLocatorFilterTest(Locator::ILocatorFilter *filter); - - QList matchesFor(const QString &searchText = QString()); - -private: - virtual void doBeforeLocatorRun() {} - virtual void doAfterLocatorRun() {} - - Locator::ILocatorFilter *m_filter; -}; - -class LOCATOR_EXPORT ResultData -{ -public: - typedef QList ResultDataList; - - ResultData(); - ResultData(const QString &textColumn1, const QString &textColumn2); - - bool operator==(const ResultData &other) const; - - static ResultDataList fromFilterEntryList(const QList &entries); - - /// For debugging and creating reference data - static void printFilterEntries(const ResultDataList &entries); - - QString textColumn1; - QString textColumn2; -}; - -typedef ResultData::ResultDataList ResultDataList; - -} // namespace Tests -} // namespace Locator - -Q_DECLARE_METATYPE(Locator::Tests::ResultData) -Q_DECLARE_METATYPE(Locator::Tests::ResultDataList) - -QT_BEGIN_NAMESPACE -namespace QTest { - -template<> inline char *toString(const Locator::Tests::ResultData &data) -{ - QByteArray ba = "\"" + data.textColumn1.toUtf8() + "\", \"" + data.textColumn2.toUtf8() + "\""; - return qstrdup(ba.data()); -} - -} // namespace QTest -QT_END_NAMESPACE - -#endif // LOCATORFILTERTEST_H diff --git a/src/plugins/locator/locatormanager.cpp b/src/plugins/locator/locatormanager.cpp deleted file mode 100644 index 279cecaaae6..00000000000 --- a/src/plugins/locator/locatormanager.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "locatormanager.h" -#include "locatorwidget.h" - -#include -#include - -namespace Locator { - -static Internal::LocatorWidget *m_locatorWidget = 0; - -LocatorManager::LocatorManager(Internal::LocatorWidget *locatorWidget) - : QObject(locatorWidget) -{ - m_locatorWidget = locatorWidget; -} - -LocatorManager::~LocatorManager() -{ - ExtensionSystem::PluginManager::removeObject(this); -} - -void LocatorManager::show(const QString &text, - int selectionStart, int selectionLength) -{ - QTC_ASSERT(m_locatorWidget, return); - m_locatorWidget->show(text, selectionStart, selectionLength); -} - -} // namespace Internal diff --git a/src/plugins/locator/locatormanager.h b/src/plugins/locator/locatormanager.h deleted file mode 100644 index 9affcf8e611..00000000000 --- a/src/plugins/locator/locatormanager.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef LOCATORMANAGER_H -#define LOCATORMANAGER_H - -#include "locator_global.h" - -#include - -namespace Locator { - -namespace Internal { class LocatorWidget; } - -class LOCATOR_EXPORT LocatorManager : public QObject -{ - Q_OBJECT - -public: - LocatorManager(Internal::LocatorWidget *locatorWidget); - ~LocatorManager(); - - static void show(const QString &text, int selectionStart = -1, int selectionLength = 0); -}; - -} // namespace Locator - -#endif // LOCATORMANAGER_H diff --git a/src/plugins/locator/locatorplugin.cpp b/src/plugins/locator/locatorplugin.cpp index 4348254135e..802cedd7c5e 100644 --- a/src/plugins/locator/locatorplugin.cpp +++ b/src/plugins/locator/locatorplugin.cpp @@ -1,268 +1,2 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ -#include "locatorplugin.h" -#include "locatorconstants.h" -#include "locatorfiltersfilter.h" -#include "locatormanager.h" -#include "locatorwidget.h" -#include "opendocumentsfilter.h" -#include "filesystemfilter.h" -#include "settingspage.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -/*! - \namespace Locator - The Locator namespace provides the hooks for Locator content. -*/ -/*! - \namespace Locator::Internal - \internal -*/ - -using namespace Core; -using namespace Locator; -using namespace Locator::Internal; - -namespace { - static bool filterLessThan(const ILocatorFilter *first, const ILocatorFilter *second) - { - if (first->priority() < second->priority()) - return true; - if (first->priority() > second->priority()) - return false; - return first->id().alphabeticallyBefore(second->id()); - } -} - -LocatorPlugin::LocatorPlugin() - : m_settingsInitialized(false) -{ - m_refreshTimer.setSingleShot(false); - connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); -} - -LocatorPlugin::~LocatorPlugin() -{ - removeObject(m_openDocumentsFilter); - removeObject(m_fileSystemFilter); - removeObject(m_executeFilter); - removeObject(m_settingsPage); - delete m_openDocumentsFilter; - delete m_fileSystemFilter; - delete m_executeFilter; - delete m_settingsPage; - qDeleteAll(m_customFilters); -} - -bool LocatorPlugin::initialize(const QStringList &, QString *) -{ - m_settingsPage = new SettingsPage(this); - addObject(m_settingsPage); - - m_locatorWidget = new LocatorWidget(this); - m_locatorWidget->setEnabled(false); - StatusBarWidget *view = new StatusBarWidget; - view->setWidget(m_locatorWidget); - view->setContext(Context("LocatorWidget")); - view->setPosition(StatusBarWidget::First); - addAutoReleasedObject(view); - - QAction *action = new QAction(m_locatorWidget->windowIcon(), m_locatorWidget->windowTitle(), this); - Command *cmd = ActionManager::registerAction(action, "QtCreator.Locate", - Context(Core::Constants::C_GLOBAL)); - cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+K"))); - connect(action, SIGNAL(triggered()), this, SLOT(openLocator())); - connect(cmd, SIGNAL(keySequenceChanged()), this, SLOT(updatePlaceholderText())); - updatePlaceholderText(cmd); - - ActionContainer *mtools = ActionManager::actionContainer(Core::Constants::M_TOOLS); - mtools->addAction(cmd); - - addObject(new LocatorManager(m_locatorWidget)); - - m_openDocumentsFilter = new OpenDocumentsFilter; - addObject(m_openDocumentsFilter); - - m_fileSystemFilter = new FileSystemFilter(m_locatorWidget); - addObject(m_fileSystemFilter); - - m_executeFilter = new ExecuteFilter(); - addObject(m_executeFilter); - - addAutoReleasedObject(new LocatorFiltersFilter(this, m_locatorWidget)); - - return true; -} - -void LocatorPlugin::updatePlaceholderText(Command *command) -{ - if (!command) - command = qobject_cast(sender()); - QTC_ASSERT(command, return); - if (command->keySequence().isEmpty()) - m_locatorWidget->setPlaceholderText(tr("Type to locate")); - else - m_locatorWidget->setPlaceholderText(tr("Type to locate (%1)").arg( - command->keySequence().toString(QKeySequence::NativeText))); -} - -void LocatorPlugin::openLocator() -{ - m_locatorWidget->show(QString()); -} - -void LocatorPlugin::extensionsInitialized() -{ - m_filters = ExtensionSystem::PluginManager::getObjects(); - qSort(m_filters.begin(), m_filters.end(), filterLessThan); - setFilters(m_filters); -} - -bool LocatorPlugin::delayedInitialize() -{ - loadSettings(); - return true; -} - -void LocatorPlugin::loadSettings() -{ - QSettings *qs = ICore::settings(); - - // Backwards compatibility to old settings location - if (qs->contains(QLatin1String("QuickOpen/FiltersFilter"))) { - loadSettingsHelper(qs); - } else { - SettingsDatabase *settings = ICore::settingsDatabase(); - loadSettingsHelper(settings); - } - - qs->remove(QLatin1String("QuickOpen")); - - m_locatorWidget->updateFilterList(); - m_locatorWidget->setEnabled(true); - if (m_refreshTimer.interval() > 0) - m_refreshTimer.start(); - m_settingsInitialized = true; -} - -void LocatorPlugin::saveSettings() -{ - if (m_settingsInitialized) { - SettingsDatabase *s = ICore::settingsDatabase(); - s->beginGroup(QLatin1String("QuickOpen")); - s->remove(QString()); - s->setValue(QLatin1String("RefreshInterval"), refreshInterval()); - foreach (ILocatorFilter *filter, m_filters) { - if (!m_customFilters.contains(filter)) - s->setValue(filter->id().toString(), filter->saveState()); - } - s->beginGroup(QLatin1String("CustomFilters")); - int i = 0; - foreach (ILocatorFilter *filter, m_customFilters) { - s->setValue(QLatin1String("directory") + QString::number(i), - filter->saveState()); - ++i; - } - s->endGroup(); - s->endGroup(); - } -} - -/*! - Return all filters, including the ones created by the user. -*/ -QList LocatorPlugin::filters() -{ - return m_filters; -} - -/*! - This returns a subset of all the filters, that contains only the filters that - have been created by the user at some point (maybe in a previous session). - */ -QList LocatorPlugin::customFilters() -{ - return m_customFilters; -} - -void LocatorPlugin::setFilters(QList f) -{ - m_filters = f; - m_locatorWidget->updateFilterList(); -} - -void LocatorPlugin::setCustomFilters(QList filters) -{ - m_customFilters = filters; -} - -int LocatorPlugin::refreshInterval() -{ - return m_refreshTimer.interval() / 60000; -} - -void LocatorPlugin::setRefreshInterval(int interval) -{ - if (interval < 1) { - m_refreshTimer.stop(); - m_refreshTimer.setInterval(0); - return; - } - m_refreshTimer.setInterval(interval * 60000); - m_refreshTimer.start(); -} - -void LocatorPlugin::refresh(QList filters) -{ - if (filters.isEmpty()) - filters = m_filters; - QFuture task = QtConcurrent::run(&ILocatorFilter::refresh, filters); - FutureProgress *progress = - ProgressManager::addTask(task, tr("Indexing"), Locator::Constants::TASK_INDEX); - connect(progress, SIGNAL(finished()), this, SLOT(saveSettings())); -} - -Q_EXPORT_PLUGIN(LocatorPlugin) +void dummyLocatorPlugin () {} diff --git a/src/plugins/locator/locatorplugin.h b/src/plugins/locator/locatorplugin.h deleted file mode 100644 index f9268e12f15..00000000000 --- a/src/plugins/locator/locatorplugin.h +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef LOCATORPLUGIN_H -#define LOCATORPLUGIN_H - -#include "ilocatorfilter.h" -#include "directoryfilter.h" -#include "executefilter.h" - -#include -#include - -#include -#include - -#if QT_VERSION >= 0x050000 -# include -#endif - -namespace Locator { -namespace Internal { - -class LocatorWidget; -class OpenDocumentsFilter; -class FileSystemFilter; -class SettingsPage; -class LocatorPlugin; - -class LocatorPlugin : public ExtensionSystem::IPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Locator.json") - -public: - LocatorPlugin(); - ~LocatorPlugin(); - - bool initialize(const QStringList &arguments, QString *errorMessage); - void extensionsInitialized(); - bool delayedInitialize(); - - QList filters(); - QList customFilters(); - void setFilters(QList f); - void setCustomFilters(QList f); - int refreshInterval(); - void setRefreshInterval(int interval); - -public slots: - void refresh(QList filters = QList()); - void saveSettings(); - void openLocator(); - -private slots: - void updatePlaceholderText(Core::Command *command = 0); - -#ifdef WITH_TESTS - void test_basefilefilter(); - void test_basefilefilter_data(); -#endif - -private: - void loadSettings(); - - template - void loadSettingsHelper(S *settings); - - LocatorWidget *m_locatorWidget; - SettingsPage *m_settingsPage; - - bool m_settingsInitialized; - QList m_filters; - QList m_customFilters; - int m_refreshInterval; - QTimer m_refreshTimer; - OpenDocumentsFilter *m_openDocumentsFilter; - FileSystemFilter *m_fileSystemFilter; - ExecuteFilter *m_executeFilter; -}; - -template -void LocatorPlugin::loadSettingsHelper(S *settings) -{ - settings->beginGroup(QLatin1String("QuickOpen")); - m_refreshTimer.setInterval(settings->value(QLatin1String("RefreshInterval"), 60).toInt() * 60000); - - foreach (ILocatorFilter *filter, m_filters) { - if (settings->contains(filter->id().toString())) { - const QByteArray state = settings->value(filter->id().toString()).toByteArray(); - if (!state.isEmpty()) - filter->restoreState(state); - } - } - settings->beginGroup(QLatin1String("CustomFilters")); - QList customFilters; - const QStringList keys = settings->childKeys(); - foreach (const QString &key, keys) { - ILocatorFilter *filter = new DirectoryFilter; - filter->restoreState(settings->value(key).toByteArray()); - m_filters.append(filter); - customFilters.append(filter); - } - setCustomFilters(customFilters); - settings->endGroup(); - settings->endGroup(); -} - -} // namespace Internal -} // namespace Locator - -#endif // LOCATORPLUGIN_H diff --git a/src/plugins/locator/locatorsearchutils.cpp b/src/plugins/locator/locatorsearchutils.cpp deleted file mode 100644 index 51c37f31c01..00000000000 --- a/src/plugins/locator/locatorsearchutils.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - - -#include "locatorsearchutils.h" - -#include -#include -#include - -namespace Locator { - -uint qHash(const Locator::FilterEntry &entry) -{ - if (entry.internalData.canConvert(QVariant::String)) - return QT_PREPEND_NAMESPACE(qHash)(entry.internalData.toString()); - return QT_PREPEND_NAMESPACE(qHash)(entry.internalData.constData()); -} - -} // namespace Locator - -void Locator::Internal::runSearch(QFutureInterface &entries, - QList filters, QString searchText) -{ - QSet alreadyAdded; - const bool checkDuplicates = (filters.size() > 1); - foreach (ILocatorFilter *filter, filters) { - if (entries.isCanceled()) - break; - - foreach (const FilterEntry &entry, filter->matchesFor(entries, searchText)) { - if (checkDuplicates && alreadyAdded.contains(entry)) - continue; - entries.reportResult(entry); - if (checkDuplicates) - alreadyAdded.insert(entry); - } - } -} diff --git a/src/plugins/locator/locatorsearchutils.h b/src/plugins/locator/locatorsearchutils.h deleted file mode 100644 index 59d90cdda3b..00000000000 --- a/src/plugins/locator/locatorsearchutils.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef LOCATORSEARCHUTILS_H -#define LOCATORSEARCHUTILS_H - -#include "locator_global.h" -#include "ilocatorfilter.h" - -namespace Locator { -namespace Internal { - -void LOCATOR_EXPORT runSearch(QFutureInterface &entries, - QList filters, - QString searchText); - -} // namespace Internal -} // namespace Locator - -#endif // LOCATORSEARCHUTILS_H - diff --git a/src/plugins/locator/locatorwidget.cpp b/src/plugins/locator/locatorwidget.cpp deleted file mode 100644 index d592b459a1e..00000000000 --- a/src/plugins/locator/locatorwidget.cpp +++ /dev/null @@ -1,594 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "locatorwidget.h" -#include "locatorplugin.h" -#include "locatorconstants.h" -#include "locatorsearchutils.h" -#include "ilocatorfilter.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -Q_DECLARE_METATYPE(Locator::ILocatorFilter*) -Q_DECLARE_METATYPE(Locator::FilterEntry) - -using namespace Core; - -namespace Locator { -namespace Internal { - -/* A model to represent the Locator results. */ -class LocatorModel : public QAbstractListModel -{ -public: - LocatorModel(QObject *parent = 0) - : QAbstractListModel(parent) -// , mDisplayCount(64) - {} - - int rowCount(const QModelIndex &parent = QModelIndex()) const; - int columnCount(const QModelIndex &parent = QModelIndex()) const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - - void setEntries(const QList &entries); - //void setDisplayCount(int count); - -private: - mutable QList mEntries; - //int mDisplayCount; -}; - -class CompletionList : public QTreeView -{ -public: - CompletionList(QWidget *parent = 0); - - void updatePreferredSize(); - QSize preferredSize() const { return m_preferredSize; } - - void focusOutEvent (QFocusEvent *event) { - if (event->reason() == Qt::ActiveWindowFocusReason) - hide(); - QTreeView::focusOutEvent(event); - } - - void next() { - int index = currentIndex().row(); - ++index; - if (index >= model()->rowCount(QModelIndex())) { - // wrap - index = 0; - } - setCurrentIndex(model()->index(index, 0)); - } - - void previous() { - int index = currentIndex().row(); - --index; - if (index < 0) { - // wrap - index = model()->rowCount(QModelIndex()) - 1; - } - setCurrentIndex(model()->index(index, 0)); - } - -private: - QSize m_preferredSize; -}; - -} // namespace Internal - - - -} // namespace Locator - -using namespace Locator; -using namespace Locator::Internal; - -// =========== LocatorModel =========== - -int LocatorModel::rowCount(const QModelIndex & /* parent */) const -{ - return mEntries.size(); -} - -int LocatorModel::columnCount(const QModelIndex &parent) const -{ - return parent.isValid() ? 0 : 2; -} - -/*! - * When asked for the icon via Qt::DecorationRole, the LocatorModel lazily - * resolves and caches the Greehouse-specific file icon when - * FilterEntry::resolveFileIcon is true. FilterEntry::internalData is assumed - * to be the filename. - */ -QVariant LocatorModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid() || index.row() >= mEntries.size()) - return QVariant(); - - if (role == Qt::DisplayRole) { - if (index.column() == 0) - return mEntries.at(index.row()).displayName; - else if (index.column() == 1) - return mEntries.at(index.row()).extraInfo; - } else if (role == Qt::ToolTipRole) { - if (mEntries.at(index.row()).extraInfo.isEmpty()) - return QVariant(mEntries.at(index.row()).displayName); - else - return QVariant(mEntries.at(index.row()).displayName - + QLatin1String("\n\n") + mEntries.at(index.row()).extraInfo); - } else if (role == Qt::DecorationRole && index.column() == 0) { - FilterEntry &entry = mEntries[index.row()]; - if (!entry.fileIconResolved && !entry.fileName.isEmpty() && entry.displayIcon.isNull()) { - entry.fileIconResolved = true; - entry.displayIcon = FileIconProvider::icon(entry.fileName); - } - return entry.displayIcon; - } else if (role == Qt::ForegroundRole && index.column() == 1) { - return QColor(Qt::darkGray); - } else if (role == Qt::UserRole) { - return qVariantFromValue(mEntries.at(index.row())); - } - - return QVariant(); -} - -void LocatorModel::setEntries(const QList &entries) -{ - beginResetModel(); - mEntries = entries; - endResetModel(); -} - -// =========== CompletionList =========== - -CompletionList::CompletionList(QWidget *parent) - : QTreeView(parent) -{ - setRootIsDecorated(false); - setUniformRowHeights(true); - setMaximumWidth(900); - header()->hide(); - header()->setStretchLastSection(true); - // This is too slow when done on all results - //header()->setResizeMode(QHeaderView::ResizeToContents); - setWindowFlags(Qt::ToolTip); - if (Utils::HostOsInfo::isMacHost()) { - if (horizontalScrollBar()) - horizontalScrollBar()->setAttribute(Qt::WA_MacMiniSize); - if (verticalScrollBar()) - verticalScrollBar()->setAttribute(Qt::WA_MacMiniSize); - } -} - -void CompletionList::updatePreferredSize() -{ - const QStyleOptionViewItem &option = viewOptions(); - const QSize shint = itemDelegate()->sizeHint(option, model()->index(0, 0)); - - m_preferredSize = QSize(730, shint.height() * 17 + frameWidth() * 2); -} - -// =========== LocatorWidget =========== - -LocatorWidget::LocatorWidget(LocatorPlugin *qop) : - m_locatorPlugin(qop), - m_locatorModel(new LocatorModel(this)), - m_completionList(new CompletionList(this)), - m_filterMenu(new QMenu(this)), - m_refreshAction(new QAction(tr("Refresh"), this)), - m_configureAction(new QAction(tr("Configure..."), this)), - m_fileLineEdit(new Utils::FilterLineEdit), - m_updateRequested(false), - m_acceptRequested(false), - m_possibleToolTipRequest(false) -{ - // Explicitly hide the completion list popup. - m_completionList->hide(); - - setFocusProxy(m_fileLineEdit); - setWindowTitle(tr("Locate...")); - resize(200, 90); - QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); - sizePolicy.setHorizontalStretch(0); - sizePolicy.setVerticalStretch(0); - setSizePolicy(sizePolicy); - setMinimumSize(QSize(200, 0)); - - QHBoxLayout *layout = new QHBoxLayout(this); - setLayout(layout); - layout->setMargin(0); - layout->addWidget(m_fileLineEdit); - - setWindowIcon(QIcon(QLatin1String(":/locator/images/locator.png"))); - const QPixmap image = QPixmap(QLatin1String(Core::Constants::ICON_MAGNIFIER)); - m_fileLineEdit->setButtonPixmap(Utils::FancyLineEdit::Left, image); - m_fileLineEdit->setButtonToolTip(Utils::FancyLineEdit::Left, tr("Options")); - m_fileLineEdit->setFocusPolicy(Qt::ClickFocus); - m_fileLineEdit->setButtonVisible(Utils::FancyLineEdit::Left, true); - // We set click focus since otherwise you will always get two popups - m_fileLineEdit->setButtonFocusPolicy(Utils::FancyLineEdit::Left, Qt::ClickFocus); - m_fileLineEdit->setAttribute(Qt::WA_MacShowFocusRect, false); - - m_fileLineEdit->installEventFilter(this); - this->installEventFilter(this); - - m_completionList->setModel(m_locatorModel); - m_completionList->header()->resizeSection(0, 300); - m_completionList->updatePreferredSize(); - m_completionList->resize(m_completionList->preferredSize()); - - m_filterMenu->addAction(m_refreshAction); - m_filterMenu->addAction(m_configureAction); - - m_fileLineEdit->setButtonMenu(Utils::FancyLineEdit::Left, m_filterMenu); - - connect(m_refreshAction, SIGNAL(triggered()), m_locatorPlugin, SLOT(refresh())); - connect(m_configureAction, SIGNAL(triggered()), this, SLOT(showConfigureDialog())); - connect(m_fileLineEdit, SIGNAL(textChanged(QString)), - this, SLOT(showPopup())); - connect(m_completionList, SIGNAL(activated(QModelIndex)), - this, SLOT(scheduleAcceptCurrentEntry())); - - m_entriesWatcher = new QFutureWatcher(this); - connect(m_entriesWatcher, SIGNAL(finished()), SLOT(updateEntries())); - - m_showPopupTimer = new QTimer(this); - m_showPopupTimer->setInterval(100); - m_showPopupTimer->setSingleShot(true); - connect(m_showPopupTimer, SIGNAL(timeout()), SLOT(showPopupNow())); -} - -void LocatorWidget::setPlaceholderText(const QString &text) -{ - m_fileLineEdit->setPlaceholderText(text); -} - -void LocatorWidget::updateFilterList() -{ - typedef QMap IdActionMap; - - m_filterMenu->clear(); - - // update actions and menu - IdActionMap actionCopy = m_filterActionMap; - m_filterActionMap.clear(); - // register new actions, update existent - foreach (ILocatorFilter *filter, m_locatorPlugin->filters()) { - if (filter->shortcutString().isEmpty() || filter->isHidden()) - continue; - Id filterId = filter->id(); - Id locatorId = filterId.withPrefix("Locator."); - QAction *action = 0; - Command *cmd = 0; - if (!actionCopy.contains(filterId)) { - // register new action - action = new QAction(filter->displayName(), this); - cmd = ActionManager::registerAction(action, locatorId, - Context(Core::Constants::C_GLOBAL)); - cmd->setAttribute(Command::CA_UpdateText); - connect(action, SIGNAL(triggered()), this, SLOT(filterSelected())); - action->setData(qVariantFromValue(filter)); - } else { - action = actionCopy.take(filterId); - action->setText(filter->displayName()); - cmd = ActionManager::command(locatorId); - } - m_filterActionMap.insert(filterId, action); - m_filterMenu->addAction(cmd->action()); - } - - // unregister actions that are deleted now - const IdActionMap::Iterator end = actionCopy.end(); - for (IdActionMap::Iterator it = actionCopy.begin(); it != end; ++it) { - ActionManager::unregisterAction(it.value(), it.key().withPrefix("Locator.")); - delete it.value(); - } - - m_filterMenu->addSeparator(); - m_filterMenu->addAction(m_refreshAction); - m_filterMenu->addAction(m_configureAction); -} - -bool LocatorWidget::eventFilter(QObject *obj, QEvent *event) -{ - if (obj == m_fileLineEdit && event->type() == QEvent::KeyPress) { - if (m_possibleToolTipRequest) - m_possibleToolTipRequest = false; - if (QToolTip::isVisible()) - QToolTip::hideText(); - - QKeyEvent *keyEvent = static_cast(event); - switch (keyEvent->key()) { - case Qt::Key_Up: - case Qt::Key_Down: - case Qt::Key_PageUp: - case Qt::Key_PageDown: - showCompletionList(); - QApplication::sendEvent(m_completionList, event); - return true; - case Qt::Key_Enter: - case Qt::Key_Return: - scheduleAcceptCurrentEntry(); - return true; - case Qt::Key_Escape: - m_completionList->hide(); - return true; - case Qt::Key_Tab: - m_completionList->next(); - return true; - case Qt::Key_Backtab: - m_completionList->previous(); - return true; - case Qt::Key_Alt: - if (keyEvent->modifiers() == Qt::AltModifier) { - m_possibleToolTipRequest = true; - return true; - } - break; - default: - break; - } - } else if (obj == m_fileLineEdit && event->type() == QEvent::KeyRelease) { - QKeyEvent *keyEvent = static_cast(event); - if (m_possibleToolTipRequest) { - m_possibleToolTipRequest = false; - if (m_completionList->isVisible() - && (keyEvent->key() == Qt::Key_Alt) - && (keyEvent->modifiers() == Qt::NoModifier)) { - const QModelIndex index = m_completionList->currentIndex(); - if (index.isValid()) { - QToolTip::showText(m_completionList->pos() + m_completionList->visualRect(index).topRight(), - m_locatorModel->data(index, Qt::ToolTipRole).toString()); - return true; - } - } - } - } else if (obj == m_fileLineEdit && event->type() == QEvent::FocusOut) { - QFocusEvent *fev = static_cast(event); - if (fev->reason() != Qt::ActiveWindowFocusReason || !m_completionList->isActiveWindow()) { - m_completionList->hide(); - m_fileLineEdit->clearFocus(); - } - } else if (obj == m_fileLineEdit && event->type() == QEvent::FocusIn) { - showPopupNow(); - } else if (obj == this && event->type() == QEvent::ShortcutOverride) { - QKeyEvent *ke = static_cast(event); - switch (ke->key()) { - case Qt::Key_Escape: - if (!ke->modifiers()) { - event->accept(); - QTimer::singleShot(0, this, SLOT(setFocusToCurrentMode())); - return true; - } - case Qt::Key_Alt: - if (ke->modifiers() == Qt::AltModifier) { - event->accept(); - return true; - } - break; - default: - break; - } - } - return QWidget::eventFilter(obj, event); -} - -void LocatorWidget::setFocusToCurrentMode() -{ - Core::ModeManager::setFocusToCurrentMode(); -} - -void LocatorWidget::showCompletionList() -{ - const int border = m_completionList->frameWidth(); - const QSize size = m_completionList->preferredSize(); - const QRect rect(mapToGlobal(QPoint(-border, -size.height() - border)), size); - m_completionList->setGeometry(rect); - m_completionList->show(); -} - -void LocatorWidget::showPopup() -{ - m_updateRequested = true; - m_showPopupTimer->start(); -} - -void LocatorWidget::showPopupNow() -{ - m_showPopupTimer->stop(); - updateCompletionList(m_fileLineEdit->text()); - showCompletionList(); -} - -QList LocatorWidget::filtersFor(const QString &text, QString &searchText) -{ - QList filters = m_locatorPlugin->filters(); - const int whiteSpace = text.indexOf(QLatin1Char(' ')); - QString prefix; - if (whiteSpace >= 0) - prefix = text.left(whiteSpace); - if (!prefix.isEmpty()) { - prefix = prefix.toLower(); - QList prefixFilters; - foreach (ILocatorFilter *filter, filters) { - if (prefix == filter->shortcutString()) { - searchText = text.mid(whiteSpace+1); - prefixFilters << filter; - } - } - if (!prefixFilters.isEmpty()) - return prefixFilters; - } - searchText = text; - QList activeFilters; - foreach (ILocatorFilter *filter, filters) - if (filter->isIncludedByDefault()) - activeFilters << filter; - return activeFilters; -} - -void LocatorWidget::updateCompletionList(const QString &text) -{ - m_updateRequested = true; - QString searchText; - const QList filters = filtersFor(text, searchText); - - // cancel the old future - m_entriesWatcher->future().cancel(); - m_entriesWatcher->future().waitForFinished(); - - QFuture future = QtConcurrent::run(runSearch, filters, searchText); - m_entriesWatcher->setFuture(future); -} - -void LocatorWidget::updateEntries() -{ - m_updateRequested = false; - if (m_entriesWatcher->future().isCanceled()) { - // reset to usable state - m_acceptRequested = false; - return; - } - - const QList entries = m_entriesWatcher->future().results(); - m_locatorModel->setEntries(entries); - if (m_locatorModel->rowCount() > 0) - m_completionList->setCurrentIndex(m_locatorModel->index(0, 0)); -#if 0 - m_completionList->updatePreferredSize(); -#endif - if (m_acceptRequested) - acceptCurrentEntry(); -} - -void LocatorWidget::scheduleAcceptCurrentEntry() -{ - if (m_updateRequested) { - // don't just accept the selected entry, since the list is not up to date - // accept will be called after the update finished - m_acceptRequested = true; - } else { - acceptCurrentEntry(); - } -} - -void LocatorWidget::acceptCurrentEntry() -{ - m_acceptRequested = false; - if (!m_completionList->isVisible()) - return; - const QModelIndex index = m_completionList->currentIndex(); - if (!index.isValid()) - return; - const FilterEntry entry = m_locatorModel->data(index, Qt::UserRole).value(); - m_completionList->hide(); - m_fileLineEdit->clearFocus(); - entry.filter->accept(entry); -} - -void LocatorWidget::show(const QString &text, int selectionStart, int selectionLength) -{ - if (!text.isEmpty()) - m_fileLineEdit->setText(text); - if (!m_fileLineEdit->hasFocus()) - m_fileLineEdit->setFocus(); - else - showPopupNow(); - ICore::raiseWindow(ICore::mainWindow()); - - if (selectionStart >= 0) { - m_fileLineEdit->setSelection(selectionStart, selectionLength); - if (selectionLength == 0) // make sure the cursor is at the right position (Mac-vs.-rest difference) - m_fileLineEdit->setCursorPosition(selectionStart); - } else { - m_fileLineEdit->selectAll(); - } -} - -void LocatorWidget::filterSelected() -{ - QString searchText = tr(""); - QAction *action = qobject_cast(sender()); - QTC_ASSERT(action, return); - ILocatorFilter *filter = action->data().value(); - QTC_ASSERT(filter, return); - QString currentText = m_fileLineEdit->text().trimmed(); - // add shortcut string at front or replace existing shortcut string - if (!currentText.isEmpty()) { - searchText = currentText; - foreach (ILocatorFilter *otherfilter, m_locatorPlugin->filters()) { - if (currentText.startsWith(otherfilter->shortcutString() + QLatin1Char(' '))) { - searchText = currentText.mid(otherfilter->shortcutString().length() + 1); - break; - } - } - } - show(filter->shortcutString() + QLatin1Char(' ') + searchText, - filter->shortcutString().length() + 1, - searchText.length()); - updateCompletionList(m_fileLineEdit->text()); - m_fileLineEdit->setFocus(); -} - -void LocatorWidget::showEvent(QShowEvent *event) -{ - QWidget::showEvent(event); -} - -void LocatorWidget::showConfigureDialog() -{ - ICore::showOptionsDialog(Core::Constants::SETTINGS_CATEGORY_CORE, Constants::FILTER_OPTIONS_PAGE); -} diff --git a/src/plugins/locator/locatorwidget.h b/src/plugins/locator/locatorwidget.h deleted file mode 100644 index aefa335a10f..00000000000 --- a/src/plugins/locator/locatorwidget.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef LOCATORWIDGET_H -#define LOCATORWIDGET_H - -#include "locatorplugin.h" - -#include - -QT_BEGIN_NAMESPACE -class QAction; -class QLabel; -class QLineEdit; -class QMenu; -class QTreeView; -QT_END_NAMESPACE - -namespace Utils { - class FilterLineEdit; -} - -namespace Locator { -namespace Internal { - -class LocatorModel; -class CompletionList; - -class LocatorWidget - : public QWidget -{ - Q_OBJECT - -public: - explicit LocatorWidget(LocatorPlugin *qop); - - void updateFilterList(); - - void show(const QString &text, int selectionStart = -1, int selectionLength = 0); - - void setPlaceholderText(const QString &text); - -private slots: - void showPopup(); - void showPopupNow(); - void acceptCurrentEntry(); - void filterSelected(); - void showConfigureDialog(); - void updateEntries(); - void scheduleAcceptCurrentEntry(); - void setFocusToCurrentMode(); - -private: - bool eventFilter(QObject *obj, QEvent *event); - - void showEvent(QShowEvent *e); - - void showCompletionList(); - void updateCompletionList(const QString &text); - QList filtersFor(const QString &text, QString &searchText); - - LocatorPlugin *m_locatorPlugin; - LocatorModel *m_locatorModel; - - CompletionList *m_completionList; - QMenu *m_filterMenu; - QAction *m_refreshAction; - QAction *m_configureAction; - Utils::FilterLineEdit *m_fileLineEdit; - QTimer *m_showPopupTimer; - QFutureWatcher *m_entriesWatcher; - QMap m_filterActionMap; - bool m_updateRequested; - bool m_acceptRequested; - bool m_possibleToolTipRequest; -}; - -} // namespace Internal -} // namespace Locator - -#endif // LOCATORWIDGET_H diff --git a/src/plugins/locator/opendocumentsfilter.cpp b/src/plugins/locator/opendocumentsfilter.cpp deleted file mode 100644 index f0e4549590e..00000000000 --- a/src/plugins/locator/opendocumentsfilter.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "opendocumentsfilter.h" - -#include -#include -#include - -#include - -using namespace Core; -using namespace Locator; -using namespace Locator::Internal; -using namespace Utils; - -OpenDocumentsFilter::OpenDocumentsFilter() -{ - setId("Open documents"); - setDisplayName(tr("Open Documents")); - setShortcutString(QString(QLatin1Char('o'))); - setIncludedByDefault(true); - - connect(EditorManager::instance(), SIGNAL(editorOpened(Core::IEditor*)), - this, SLOT(refreshInternally())); - connect(EditorManager::instance(), SIGNAL(editorsClosed(QList)), - this, SLOT(refreshInternally())); -} - -QList OpenDocumentsFilter::matchesFor(QFutureInterface &future, const QString &entry_) -{ - QList goodEntries; - QList betterEntries; - QString entry = entry_; - const QString lineNoSuffix = EditorManager::splitLineNumber(&entry); - const QChar asterisk = QLatin1Char('*'); - QString pattern = QString(asterisk); - pattern += entry; - pattern += asterisk; - QRegExp regexp(pattern, Qt::CaseInsensitive, QRegExp::Wildcard); - if (!regexp.isValid()) - return goodEntries; - const Qt::CaseSensitivity caseSensitivityForPrefix = caseSensitivity(entry); - foreach (const DocumentModel::Entry &editorEntry, m_editors) { - if (future.isCanceled()) - break; - QString fileName = editorEntry.fileName(); - if (fileName.isEmpty()) - continue; - QString displayName = editorEntry.displayName(); - if (regexp.exactMatch(displayName)) { - QFileInfo fi(fileName); - FilterEntry fiEntry(this, fi.fileName(), QString(fileName + lineNoSuffix)); - fiEntry.extraInfo = FileUtils::shortNativePath(FileName(fi)); - fiEntry.fileName = fileName; - QList &category = displayName.startsWith(entry, caseSensitivityForPrefix) - ? betterEntries : goodEntries; - category.append(fiEntry); - } - } - betterEntries.append(goodEntries); - return betterEntries; -} - -void OpenDocumentsFilter::refreshInternally() -{ - m_editors.clear(); - foreach (DocumentModel::Entry *e, EditorManager::documentModel()->documents()) { - DocumentModel::Entry entry; - // create copy with only the information relevant to use - // to avoid model deleting entries behind our back - entry.m_displayName = e->displayName(); - entry.m_fileName = e->fileName(); - m_editors.append(entry); - } -} - -void OpenDocumentsFilter::refresh(QFutureInterface &future) -{ - Q_UNUSED(future) - QMetaObject::invokeMethod(this, "refreshInternally", Qt::BlockingQueuedConnection); -} - -void OpenDocumentsFilter::accept(FilterEntry selection) const -{ - EditorManager::openEditor(selection.internalData.toString(), Id(), - EditorManager::CanContainLineNumber); -} diff --git a/src/plugins/locator/opendocumentsfilter.h b/src/plugins/locator/opendocumentsfilter.h deleted file mode 100644 index e567d5b291e..00000000000 --- a/src/plugins/locator/opendocumentsfilter.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef OPENDOCUMENTSFILTER_H -#define OPENDOCUMENTSFILTER_H - -#include "ilocatorfilter.h" - -#include - -#include -#include -#include - -namespace Locator { -namespace Internal { - -class OpenDocumentsFilter : public Locator::ILocatorFilter -{ - Q_OBJECT - -public: - OpenDocumentsFilter(); - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(Locator::FilterEntry selection) const; - void refresh(QFutureInterface &future); - -public slots: - void refreshInternally(); - -private: - QList m_editors; -}; - -} // namespace Internal -} // namespace Locator - -#endif // OPENDOCUMENTSFILTER_H diff --git a/src/plugins/locator/settingspage.cpp b/src/plugins/locator/settingspage.cpp deleted file mode 100644 index 2feec8d9a38..00000000000 --- a/src/plugins/locator/settingspage.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "settingspage.h" -#include "locatorconstants.h" - -#include "locatorplugin.h" -#include "ilocatorfilter.h" -#include "directoryfilter.h" - -#include -#include - -#include - -Q_DECLARE_METATYPE(Locator::ILocatorFilter*) - -using namespace Locator; -using namespace Locator::Internal; - -SettingsPage::SettingsPage(LocatorPlugin *plugin) - : m_plugin(plugin), m_widget(0) -{ - setId(Constants::FILTER_OPTIONS_PAGE); - setDisplayName(QCoreApplication::translate("Locator", Locator::Constants::FILTER_OPTIONS_PAGE)); - setCategory(Core::Constants::SETTINGS_CATEGORY_CORE); - setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::SETTINGS_TR_CATEGORY_CORE)); - setCategoryIcon(QLatin1String(Core::Constants::SETTINGS_CATEGORY_CORE_ICON)); -} - -QWidget *SettingsPage::widget() -{ - if (!m_widget) { - m_widget = new QWidget; - m_ui.setupUi(m_widget); - m_ui.refreshInterval->setToolTip(m_ui.refreshIntervalLabel->toolTip()); - connect(m_ui.filterList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), - this, SLOT(updateButtonStates())); - connect(m_ui.filterList, SIGNAL(itemActivated(QListWidgetItem*)), - this, SLOT(configureFilter(QListWidgetItem*))); - connect(m_ui.editButton, SIGNAL(clicked()), - this, SLOT(configureFilter())); - connect(m_ui.addButton, SIGNAL(clicked()), - this, SLOT(addCustomFilter())); - connect(m_ui.removeButton, SIGNAL(clicked()), - this, SLOT(removeCustomFilter())); - - m_ui.refreshInterval->setValue(m_plugin->refreshInterval()); - m_filters = m_plugin->filters(); - m_customFilters = m_plugin->customFilters(); - saveFilterStates(); - updateFilterList(); - } - return m_widget; -} - -void SettingsPage::apply() -{ - // Delete removed filters and clear added filters - qDeleteAll(m_removedFilters); - m_removedFilters.clear(); - m_addedFilters.clear(); - - // Pass the new configuration on to the plugin - m_plugin->setFilters(m_filters); - m_plugin->setCustomFilters(m_customFilters); - m_plugin->setRefreshInterval(m_ui.refreshInterval->value()); - requestRefresh(); - m_plugin->saveSettings(); - saveFilterStates(); -} - -void SettingsPage::finish() -{ - // If settings were applied, this shouldn't change anything. Otherwise it - // makes sure the filter states aren't changed permanently. - restoreFilterStates(); - - // Delete added filters and clear removed filters - qDeleteAll(m_addedFilters); - m_addedFilters.clear(); - m_removedFilters.clear(); - - // Further cleanup - m_filters.clear(); - m_customFilters.clear(); - m_refreshFilters.clear(); - delete m_widget; -} - -void SettingsPage::requestRefresh() -{ - if (!m_refreshFilters.isEmpty()) - m_plugin->refresh(m_refreshFilters); -} - -void SettingsPage::saveFilterStates() -{ - m_filterStates.clear(); - foreach (ILocatorFilter *filter, m_filters) - m_filterStates.insert(filter, filter->saveState()); -} - -void SettingsPage::restoreFilterStates() -{ - foreach (ILocatorFilter *filter, m_filterStates.keys()) - filter->restoreState(m_filterStates.value(filter)); -} - -void SettingsPage::updateFilterList() -{ - m_ui.filterList->clear(); - foreach (ILocatorFilter *filter, m_filters) { - if (filter->isHidden()) - continue; - - QString title; - if (filter->isIncludedByDefault()) - title = filter->displayName(); - else - title = tr("%1 (prefix: %2)").arg(filter->displayName()).arg(filter->shortcutString()); - QListWidgetItem *item = new QListWidgetItem(title); - item->setData(Qt::UserRole, qVariantFromValue(filter)); - m_ui.filterList->addItem(item); - } - if (m_ui.filterList->count() > 0) - m_ui.filterList->setCurrentRow(0); -} - -void SettingsPage::updateButtonStates() -{ - QListWidgetItem *item = m_ui.filterList->currentItem(); - ILocatorFilter *filter = (item ? item->data(Qt::UserRole).value() : 0); - m_ui.editButton->setEnabled(filter && filter->isConfigurable()); - m_ui.removeButton->setEnabled(filter && m_customFilters.contains(filter)); -} - -void SettingsPage::configureFilter(QListWidgetItem *item) -{ - if (!item) - item = m_ui.filterList->currentItem(); - QTC_ASSERT(item, return); - ILocatorFilter *filter = item->data(Qt::UserRole).value(); - QTC_ASSERT(filter, return); - - if (!filter->isConfigurable()) - return; - bool needsRefresh = false; - filter->openConfigDialog(m_widget, needsRefresh); - if (needsRefresh && !m_refreshFilters.contains(filter)) - m_refreshFilters.append(filter); - updateFilterList(); -} - -void SettingsPage::addCustomFilter() -{ - ILocatorFilter *filter = new DirectoryFilter; - bool needsRefresh = false; - if (filter->openConfigDialog(m_widget, needsRefresh)) { - m_filters.append(filter); - m_addedFilters.append(filter); - m_customFilters.append(filter); - m_refreshFilters.append(filter); - updateFilterList(); - } -} - -void SettingsPage::removeCustomFilter() -{ - QListWidgetItem *item = m_ui.filterList->currentItem(); - QTC_ASSERT(item, return); - ILocatorFilter *filter = item->data(Qt::UserRole).value(); - QTC_ASSERT(m_customFilters.contains(filter), return); - m_filters.removeAll(filter); - m_customFilters.removeAll(filter); - m_refreshFilters.removeAll(filter); - if (m_addedFilters.contains(filter)) { - m_addedFilters.removeAll(filter); - delete filter; - } else { - m_removedFilters.append(filter); - } - updateFilterList(); -} diff --git a/src/plugins/locator/settingspage.h b/src/plugins/locator/settingspage.h deleted file mode 100644 index 2042d9aec61..00000000000 --- a/src/plugins/locator/settingspage.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef SETTINGSPAGE_H -#define SETTINGSPAGE_H - -#include "ui_settingspage.h" - -#include - -#include -#include - -QT_BEGIN_NAMESPACE -class QListWidgetItem; -QT_END_NAMESPACE - -namespace Locator { - -class ILocatorFilter; - -namespace Internal { - -class LocatorPlugin; - -class SettingsPage : public Core::IOptionsPage -{ - Q_OBJECT - -public: - explicit SettingsPage(LocatorPlugin *plugin); - - QWidget *widget(); - void apply(); - void finish(); - -private slots: - void updateButtonStates(); - void configureFilter(QListWidgetItem *item = 0); - void addCustomFilter(); - void removeCustomFilter(); - -private: - void updateFilterList(); - void saveFilterStates(); - void restoreFilterStates(); - void requestRefresh(); - - Ui::SettingsWidget m_ui; - LocatorPlugin *m_plugin; - QPointer m_widget; - QList m_filters; - QList m_addedFilters; - QList m_removedFilters; - QList m_customFilters; - QList m_refreshFilters; - QHash m_filterStates; -}; - -} // namespace Internal -} // namespace Locator - -#endif // SETTINGSPAGE_H diff --git a/src/plugins/locator/settingspage.ui b/src/plugins/locator/settingspage.ui deleted file mode 100644 index e600ca1cedd..00000000000 --- a/src/plugins/locator/settingspage.ui +++ /dev/null @@ -1,121 +0,0 @@ - - - Locator::Internal::SettingsWidget - - - - 0 - 0 - 367 - 242 - - - - Configure Filters - - - - - - - - - - - - - - - Add - - - - - - - false - - - Remove - - - - - - - false - - - Edit - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Locator filters that do not update their cached data immediately, such as the custom directory filters, update it after this time interval. - - - Refresh interval: - - - - - - - true - - - QAbstractSpinBox::PlusMinus - - - min - - - 320 - - - 5 - - - 60 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - diff --git a/src/plugins/macros/findmacrohandler.cpp b/src/plugins/macros/findmacrohandler.cpp index 4fe95088819..be7824019ae 100644 --- a/src/plugins/macros/findmacrohandler.cpp +++ b/src/plugins/macros/findmacrohandler.cpp @@ -32,11 +32,10 @@ #include "macro.h" #include "macrotextfind.h" -#include - #include #include #include +#include #include @@ -79,32 +78,32 @@ bool FindMacroHandler::executeEvent(const MacroEvent ¯oEvent) if (!aggregate) return false; - Find::IFindSupport *currentFind = aggregate->component(); + Core::IFindSupport *currentFind = aggregate->component(); if (!currentFind) return false; switch (macroEvent.value(TYPE).toInt()) { case FINDINCREMENTAL: currentFind->findIncremental(macroEvent.value(BEFORE).toString(), - (Find::FindFlags)macroEvent.value(FLAGS).toInt()); + (Core::FindFlags)macroEvent.value(FLAGS).toInt()); break; case FINDSTEP: currentFind->findStep(macroEvent.value(BEFORE).toString(), - (Find::FindFlags)macroEvent.value(FLAGS).toInt()); + (Core::FindFlags)macroEvent.value(FLAGS).toInt()); break; case REPLACE: currentFind->replace(macroEvent.value(BEFORE).toString(), macroEvent.value(AFTER).toString(), - (Find::FindFlags)macroEvent.value(FLAGS).toInt()); + (Core::FindFlags)macroEvent.value(FLAGS).toInt()); case REPLACESTEP: currentFind->replaceStep(macroEvent.value(BEFORE).toString(), macroEvent.value(AFTER).toString(), - (Find::FindFlags)macroEvent.value(FLAGS).toInt()); + (Core::FindFlags)macroEvent.value(FLAGS).toInt()); break; case REPLACEALL: currentFind->replaceAll(macroEvent.value(BEFORE).toString(), macroEvent.value(AFTER).toString(), - (Find::FindFlags)macroEvent.value(FLAGS).toInt()); + (Core::FindFlags)macroEvent.value(FLAGS).toInt()); break; case RESET: currentFind->resetIncrementalSearch(); @@ -113,7 +112,7 @@ bool FindMacroHandler::executeEvent(const MacroEvent ¯oEvent) return true; } -void FindMacroHandler::findIncremental(const QString &txt, Find::FindFlags findFlags) +void FindMacroHandler::findIncremental(const QString &txt, Core::FindFlags findFlags) { if (!isRecording()) return; @@ -125,7 +124,7 @@ void FindMacroHandler::findIncremental(const QString &txt, Find::FindFlags findF addMacroEvent(e); } -void FindMacroHandler::findStep(const QString &txt, Find::FindFlags findFlags) +void FindMacroHandler::findStep(const QString &txt, Core::FindFlags findFlags) { if (!isRecording()) return; @@ -137,7 +136,7 @@ void FindMacroHandler::findStep(const QString &txt, Find::FindFlags findFlags) addMacroEvent(e); } -void FindMacroHandler::replace(const QString &before, const QString &after, Find::FindFlags findFlags) +void FindMacroHandler::replace(const QString &before, const QString &after, Core::FindFlags findFlags) { if (!isRecording()) return; @@ -150,7 +149,7 @@ void FindMacroHandler::replace(const QString &before, const QString &after, Find addMacroEvent(e); } -void FindMacroHandler::replaceStep(const QString &before, const QString &after, Find::FindFlags findFlags) +void FindMacroHandler::replaceStep(const QString &before, const QString &after, Core::FindFlags findFlags) { if (!isRecording()) return; @@ -163,7 +162,7 @@ void FindMacroHandler::replaceStep(const QString &before, const QString &after, addMacroEvent(e); } -void FindMacroHandler::replaceAll(const QString &before, const QString &after, Find::FindFlags findFlags) +void FindMacroHandler::replaceAll(const QString &before, const QString &after, Core::FindFlags findFlags) { if (!isRecording()) return; @@ -194,7 +193,7 @@ void FindMacroHandler::changeEditor(Core::IEditor *editor) Aggregation::Aggregate *aggregate = Aggregation::Aggregate::parentAggregate(editor->widget()); if (aggregate) { - Find::IFindSupport *currentFind = aggregate->component(); + Core::IFindSupport *currentFind = aggregate->component(); if (currentFind) { MacroTextFind *macroFind = qobject_cast(currentFind); if (macroFind) @@ -205,18 +204,18 @@ void FindMacroHandler::changeEditor(Core::IEditor *editor) aggregate->add(macroFind); // Connect all signals - connect(macroFind, SIGNAL(allReplaced(QString,QString,Find::FindFlags)), - this, SLOT(replaceAll(QString,QString,Find::FindFlags))); - connect(macroFind, SIGNAL(incrementalFound(QString,Find::FindFlags)), - this, SLOT(findIncremental(QString,Find::FindFlags))); + connect(macroFind, SIGNAL(allReplaced(QString,QString,Core::FindFlags)), + this, SLOT(replaceAll(QString,QString,Core::FindFlags))); + connect(macroFind, SIGNAL(incrementalFound(QString,Core::FindFlags)), + this, SLOT(findIncremental(QString,Core::FindFlags))); connect(macroFind, SIGNAL(incrementalSearchReseted()), this, SLOT(resetIncrementalSearch())); - connect(macroFind, SIGNAL(replaced(QString,QString,Find::FindFlags)), - this, SLOT(replace(QString,QString,Find::FindFlags))); - connect(macroFind, SIGNAL(stepFound(QString,Find::FindFlags)), - this, SLOT(findStep(QString,Find::FindFlags))); - connect(macroFind, SIGNAL(stepReplaced(QString,QString,Find::FindFlags)), - this, SLOT(replaceStep(QString,QString,Find::FindFlags))); + connect(macroFind, SIGNAL(replaced(QString,QString,Core::FindFlags)), + this, SLOT(replace(QString,QString,Core::FindFlags))); + connect(macroFind, SIGNAL(stepFound(QString,Core::FindFlags)), + this, SLOT(findStep(QString,Core::FindFlags))); + connect(macroFind, SIGNAL(stepReplaced(QString,QString,Core::FindFlags)), + this, SLOT(replaceStep(QString,QString,Core::FindFlags))); } } } diff --git a/src/plugins/macros/findmacrohandler.h b/src/plugins/macros/findmacrohandler.h index 7f35f1adfd4..33a68e5766d 100644 --- a/src/plugins/macros/findmacrohandler.h +++ b/src/plugins/macros/findmacrohandler.h @@ -32,7 +32,7 @@ #include "imacrohandler.h" -#include +#include namespace Core { class IEditor; @@ -54,11 +54,11 @@ public: bool executeEvent(const MacroEvent ¯oEvent); public slots: - void findIncremental(const QString &txt, Find::FindFlags findFlags); - void findStep(const QString &txt, Find::FindFlags findFlags); - void replace(const QString &before, const QString &after, Find::FindFlags findFlags); - void replaceStep(const QString &before, const QString &after, Find::FindFlags findFlags); - void replaceAll(const QString &before, const QString &after, Find::FindFlags findFlags); + void findIncremental(const QString &txt, Core::FindFlags findFlags); + void findStep(const QString &txt, Core::FindFlags findFlags); + void replace(const QString &before, const QString &after, Core::FindFlags findFlags); + void replaceStep(const QString &before, const QString &after, Core::FindFlags findFlags); + void replaceAll(const QString &before, const QString &after, Core::FindFlags findFlags); void resetIncrementalSearch(); private slots: diff --git a/src/plugins/macros/macrolocatorfilter.cpp b/src/plugins/macros/macrolocatorfilter.cpp index e1cd889445d..e63f1f090ed 100644 --- a/src/plugins/macros/macrolocatorfilter.cpp +++ b/src/plugins/macros/macrolocatorfilter.cpp @@ -52,11 +52,11 @@ MacroLocatorFilter::~MacroLocatorFilter() { } -QList MacroLocatorFilter::matchesFor(QFutureInterface &future, const QString &entry) +QList MacroLocatorFilter::matchesFor(QFutureInterface &future, const QString &entry) { Q_UNUSED(future) - QList goodEntries; - QList betterEntries; + QList goodEntries; + QList betterEntries; const Qt::CaseSensitivity caseSensitivity_ = caseSensitivity(entry); @@ -67,7 +67,7 @@ QList MacroLocatorFilter::matchesFor(QFutureInterface *category = 0; + QList *category = 0; if (name.startsWith(entry, caseSensitivity_)) category = &betterEntries; else if (name.contains(entry, caseSensitivity_)) @@ -75,7 +75,7 @@ QList MacroLocatorFilter::matchesFor(QFutureInterfacedescription(); category->append(entry); } @@ -84,7 +84,7 @@ QList MacroLocatorFilter::matchesFor(QFutureInterface +#include #include @@ -40,7 +40,7 @@ class MacroManager; namespace Internal { -class MacroLocatorFilter : public Locator::ILocatorFilter +class MacroLocatorFilter : public Core::ILocatorFilter { Q_OBJECT @@ -48,8 +48,8 @@ public: MacroLocatorFilter(); ~MacroLocatorFilter(); - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(Locator::FilterEntry selection) const; + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(Core::LocatorFilterEntry selection) const; void refresh(QFutureInterface &future); private: diff --git a/src/plugins/macros/macros.qbs b/src/plugins/macros/macros.qbs index b9e90960a06..f6dac5cb8f3 100644 --- a/src/plugins/macros/macros.qbs +++ b/src/plugins/macros/macros.qbs @@ -7,8 +7,6 @@ QtcPlugin { Depends { name: "Qt.widgets" } Depends { name: "Core" } - Depends { name: "Locator" } - Depends { name: "Find" } Depends { name: "TextEditor" } Depends { name: "app_version_header" } diff --git a/src/plugins/macros/macros_dependencies.pri b/src/plugins/macros/macros_dependencies.pri index 3ae94328b31..e7850c9d526 100644 --- a/src/plugins/macros/macros_dependencies.pri +++ b/src/plugins/macros/macros_dependencies.pri @@ -1,6 +1,4 @@ QTC_PLUGIN_NAME = Macros QTC_PLUGIN_DEPENDS += \ coreplugin \ - locator \ - find \ texteditor diff --git a/src/plugins/macros/macrotextfind.cpp b/src/plugins/macros/macrotextfind.cpp index b56a81cdd33..1aeef19113c 100644 --- a/src/plugins/macros/macrotextfind.cpp +++ b/src/plugins/macros/macrotextfind.cpp @@ -34,8 +34,8 @@ using namespace Macros; using namespace Macros::Internal; -MacroTextFind::MacroTextFind(Find::IFindSupport *currentFind): - Find::IFindSupport(), +MacroTextFind::MacroTextFind(Core::IFindSupport *currentFind): + Core::IFindSupport(), m_currentFind(currentFind) { } @@ -46,7 +46,7 @@ bool MacroTextFind::supportsReplace() const return m_currentFind->supportsReplace(); } -Find::FindFlags MacroTextFind::supportedFindFlags() const +Core::FindFlags MacroTextFind::supportedFindFlags() const { QTC_ASSERT(m_currentFind, return 0); return m_currentFind->supportedFindFlags(); @@ -77,38 +77,38 @@ QString MacroTextFind::completedFindString() const return m_currentFind->completedFindString(); } -void MacroTextFind::highlightAll(const QString &txt, Find::FindFlags findFlags) +void MacroTextFind::highlightAll(const QString &txt, Core::FindFlags findFlags) { QTC_ASSERT(m_currentFind, return); m_currentFind->highlightAll(txt, findFlags); } -Find::IFindSupport::Result MacroTextFind::findIncremental(const QString &txt, Find::FindFlags findFlags) +Core::IFindSupport::Result MacroTextFind::findIncremental(const QString &txt, Core::FindFlags findFlags) { QTC_ASSERT(m_currentFind, return IFindSupport::NotFound); - Find::IFindSupport::Result result = m_currentFind->findIncremental(txt, findFlags); + Core::IFindSupport::Result result = m_currentFind->findIncremental(txt, findFlags); if (result == Found) emit incrementalFound(txt, findFlags); return result; } -Find::IFindSupport::Result MacroTextFind::findStep(const QString &txt, Find::FindFlags findFlags) +Core::IFindSupport::Result MacroTextFind::findStep(const QString &txt, Core::FindFlags findFlags) { QTC_ASSERT(m_currentFind, return IFindSupport::NotFound); - Find::IFindSupport::Result result = m_currentFind->findStep(txt, findFlags); + Core::IFindSupport::Result result = m_currentFind->findStep(txt, findFlags); if (result == Found) emit stepFound(txt, findFlags); return result; } -void MacroTextFind::replace(const QString &before, const QString &after, Find::FindFlags findFlags) +void MacroTextFind::replace(const QString &before, const QString &after, Core::FindFlags findFlags) { QTC_ASSERT(m_currentFind, return); m_currentFind->replace(before, after, findFlags); emit replaced(before, after, findFlags); } -bool MacroTextFind::replaceStep(const QString &before, const QString &after, Find::FindFlags findFlags) +bool MacroTextFind::replaceStep(const QString &before, const QString &after, Core::FindFlags findFlags) { QTC_ASSERT(m_currentFind, return false); bool result = m_currentFind->replaceStep(before, after, findFlags); @@ -116,7 +116,7 @@ bool MacroTextFind::replaceStep(const QString &before, const QString &after, Fin return result; } -int MacroTextFind::replaceAll(const QString &before, const QString &after, Find::FindFlags findFlags) +int MacroTextFind::replaceAll(const QString &before, const QString &after, Core::FindFlags findFlags) { QTC_ASSERT(m_currentFind, return 0); int result = m_currentFind->replaceAll(before, after, findFlags); diff --git a/src/plugins/macros/macrotextfind.h b/src/plugins/macros/macrotextfind.h index f2e6fecb66e..f703664dfdd 100644 --- a/src/plugins/macros/macrotextfind.h +++ b/src/plugins/macros/macrotextfind.h @@ -30,50 +30,50 @@ #ifndef MACROSPLUGIN_MACROTEXTFIND_H #define MACROSPLUGIN_MACROTEXTFIND_H -#include +#include #include namespace Macros { namespace Internal { -class MacroTextFind : public Find::IFindSupport +class MacroTextFind : public Core::IFindSupport { Q_OBJECT public: - MacroTextFind(Find::IFindSupport *currentFind); + MacroTextFind(Core::IFindSupport *currentFind); bool supportsReplace() const; - Find::FindFlags supportedFindFlags() const; + Core::FindFlags supportedFindFlags() const; void resetIncrementalSearch(); void clearResults(); QString currentFindString() const; QString completedFindString() const; - void highlightAll(const QString &txt, Find::FindFlags findFlags); - Find::IFindSupport::Result findIncremental(const QString &txt, Find::FindFlags findFlags); - Find::IFindSupport::Result findStep(const QString &txt, Find::FindFlags findFlags); - void replace(const QString &before, const QString &after, Find::FindFlags findFlags); - bool replaceStep(const QString &before, const QString &after, Find::FindFlags findFlags); - int replaceAll(const QString &before, const QString &after, Find::FindFlags findFlags); + void highlightAll(const QString &txt, Core::FindFlags findFlags); + Core::IFindSupport::Result findIncremental(const QString &txt, Core::FindFlags findFlags); + Core::IFindSupport::Result findStep(const QString &txt, Core::FindFlags findFlags); + void replace(const QString &before, const QString &after, Core::FindFlags findFlags); + bool replaceStep(const QString &before, const QString &after, Core::FindFlags findFlags); + int replaceAll(const QString &before, const QString &after, Core::FindFlags findFlags); void defineFindScope(); void clearFindScope(); signals: void incrementalSearchReseted(); - void incrementalFound(const QString &txt, Find::FindFlags findFlags); - void stepFound(const QString &txt, Find::FindFlags findFlags); + void incrementalFound(const QString &txt, Core::FindFlags findFlags); + void stepFound(const QString &txt, Core::FindFlags findFlags); void replaced(const QString &before, const QString &after, - Find::FindFlags findFlags); + Core::FindFlags findFlags); void stepReplaced(const QString &before, const QString &after, - Find::FindFlags findFlags); + Core::FindFlags findFlags); void allReplaced(const QString &before, const QString &after, - Find::FindFlags findFlags); + Core::FindFlags findFlags); private: - QPointer m_currentFind; + QPointer m_currentFind; }; } // namespace Internal diff --git a/src/plugins/mercurial/mercurial.qbs b/src/plugins/mercurial/mercurial.qbs index 80611787e7e..e6fec9fbedc 100644 --- a/src/plugins/mercurial/mercurial.qbs +++ b/src/plugins/mercurial/mercurial.qbs @@ -8,9 +8,7 @@ QtcPlugin { Depends { name: "Qt.widgets" } Depends { name: "Core" } Depends { name: "TextEditor" } - Depends { name: "Find" } Depends { name: "VcsBase" } - Depends { name: "Locator" } files: [ "annotationhighlighter.cpp", diff --git a/src/plugins/mercurial/mercurial_dependencies.pri b/src/plugins/mercurial/mercurial_dependencies.pri index 8de4e4595d4..de8a0df27ac 100644 --- a/src/plugins/mercurial/mercurial_dependencies.pri +++ b/src/plugins/mercurial/mercurial_dependencies.pri @@ -2,7 +2,6 @@ QTC_PLUGIN_NAME = Mercurial QTC_LIB_DEPENDS += \ utils QTC_PLUGIN_DEPENDS += \ - locator \ texteditor \ coreplugin \ vcsbase diff --git a/src/plugins/mercurial/mercurialplugin.cpp b/src/plugins/mercurial/mercurialplugin.cpp index 8814c4f0eba..eac981f3b38 100644 --- a/src/plugins/mercurial/mercurialplugin.cpp +++ b/src/plugins/mercurial/mercurialplugin.cpp @@ -49,7 +49,7 @@ #include #include -#include +#include #include #include @@ -152,7 +152,7 @@ bool MercurialPlugin::initialize(const QStringList & /* arguments */, QString * addAutoReleasedObject(new CloneWizard); const QString prefix = QLatin1String("hg"); - m_commandLocator = new Locator::CommandLocator("Mercurial", prefix, prefix); + m_commandLocator = new Core::CommandLocator("Mercurial", prefix, prefix); addAutoReleasedObject(m_commandLocator); createMenu(); diff --git a/src/plugins/mercurial/mercurialplugin.h b/src/plugins/mercurial/mercurialplugin.h index 7c5ab3d2031..12676a99315 100644 --- a/src/plugins/mercurial/mercurialplugin.h +++ b/src/plugins/mercurial/mercurialplugin.h @@ -43,6 +43,7 @@ QT_END_NAMESPACE namespace Core { class ActionContainer; class ActionManager; +class CommandLocator; class ICore; class Id; class IEditor; @@ -50,7 +51,6 @@ class IEditor; namespace Utils { class ParameterAction; } namespace VcsBase { class VcsBaseSubmitEditor; } -namespace Locator { class CommandLocator; } namespace Mercurial { namespace Internal { @@ -143,7 +143,7 @@ private: MercurialClient *m_client; Core::ICore *core; - Locator::CommandLocator *m_commandLocator; + Core::CommandLocator *m_commandLocator; Core::ActionContainer *mercurialContainer; QList m_repositoryActionList; diff --git a/src/plugins/perforce/perforce.qbs b/src/plugins/perforce/perforce.qbs index 9bc46fcee5c..155da2891f0 100644 --- a/src/plugins/perforce/perforce.qbs +++ b/src/plugins/perforce/perforce.qbs @@ -8,9 +8,7 @@ QtcPlugin { Depends { name: "Qt.widgets" } Depends { name: "Core" } Depends { name: "TextEditor" } - Depends { name: "Find" } Depends { name: "VcsBase" } - Depends { name: "Locator" } files: [ "annotationhighlighter.cpp", diff --git a/src/plugins/perforce/perforce_dependencies.pri b/src/plugins/perforce/perforce_dependencies.pri index 7e46fc79903..dca91be311c 100644 --- a/src/plugins/perforce/perforce_dependencies.pri +++ b/src/plugins/perforce/perforce_dependencies.pri @@ -2,7 +2,6 @@ QTC_PLUGIN_NAME = Perforce QTC_LIB_DEPENDS += \ utils QTC_PLUGIN_DEPENDS += \ - locator \ texteditor \ coreplugin \ vcsbase diff --git a/src/plugins/perforce/perforceplugin.cpp b/src/plugins/perforce/perforceplugin.cpp index 99693b74ebb..cad43e661fa 100644 --- a/src/plugins/perforce/perforceplugin.cpp +++ b/src/plugins/perforce/perforceplugin.cpp @@ -48,7 +48,7 @@ #include #include #include -#include +#include #include #include #include @@ -226,7 +226,7 @@ bool PerforcePlugin::initialize(const QStringList & /* arguments */, QString *er addAutoReleasedObject(new PerforceEditorFactory(editorParameters + i, this, describeSlot)); const QString prefix = QLatin1String("p4"); - m_commandLocator = new Locator::CommandLocator("Perforce", prefix, prefix); + m_commandLocator = new Core::CommandLocator("Perforce", prefix, prefix); addAutoReleasedObject(m_commandLocator); Core::ActionContainer *mtools = diff --git a/src/plugins/perforce/perforceplugin.h b/src/plugins/perforce/perforceplugin.h index 7337181b223..9b6b48ca4de 100644 --- a/src/plugins/perforce/perforceplugin.h +++ b/src/plugins/perforce/perforceplugin.h @@ -53,7 +53,7 @@ namespace Utils { class TempFileSaver; } -namespace Locator { +namespace Core { class CommandLocator; } @@ -203,7 +203,7 @@ private: static PerforceVersionControl *perforceVersionControl(); - Locator::CommandLocator *m_commandLocator; + Core::CommandLocator *m_commandLocator; Utils::ParameterAction *m_editAction; Utils::ParameterAction *m_addAction; Utils::ParameterAction *m_deleteAction; diff --git a/src/plugins/projectexplorer/allprojectsfilter.cpp b/src/plugins/projectexplorer/allprojectsfilter.cpp index 0c45806127d..fe1e30b875b 100644 --- a/src/plugins/projectexplorer/allprojectsfilter.cpp +++ b/src/plugins/projectexplorer/allprojectsfilter.cpp @@ -33,7 +33,6 @@ #include "project.h" using namespace Core; -using namespace Locator; using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; diff --git a/src/plugins/projectexplorer/allprojectsfilter.h b/src/plugins/projectexplorer/allprojectsfilter.h index 38dae1ae148..0e5b79b5617 100644 --- a/src/plugins/projectexplorer/allprojectsfilter.h +++ b/src/plugins/projectexplorer/allprojectsfilter.h @@ -30,14 +30,14 @@ #ifndef ALLPROJECTSFILTER_H #define ALLPROJECTSFILTER_H -#include +#include #include namespace ProjectExplorer { namespace Internal { -class AllProjectsFilter : public Locator::BaseFileFilter +class AllProjectsFilter : public Core::BaseFileFilter { Q_OBJECT diff --git a/src/plugins/projectexplorer/allprojectsfind.cpp b/src/plugins/projectexplorer/allprojectsfind.cpp index cc93ff2af2b..d248fd454c2 100644 --- a/src/plugins/projectexplorer/allprojectsfind.cpp +++ b/src/plugins/projectexplorer/allprojectsfind.cpp @@ -43,7 +43,6 @@ #include #include -using namespace Find; using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; using namespace TextEditor; diff --git a/src/plugins/projectexplorer/appoutputpane.cpp b/src/plugins/projectexplorer/appoutputpane.cpp index 6765d81689b..38a0858fece 100644 --- a/src/plugins/projectexplorer/appoutputpane.cpp +++ b/src/plugins/projectexplorer/appoutputpane.cpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include #include @@ -331,7 +331,7 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc) ow->setMaxLineCount(ProjectExplorerPlugin::projectExplorerSettings().maxAppOutputLines); Aggregation::Aggregate *agg = new Aggregation::Aggregate; agg->add(ow); - agg->add(new Find::BaseTextFind(ow)); + agg->add(new Core::BaseTextFind(ow)); m_runControlTabs.push_back(RunControlTab(rc, ow)); m_tabWidget->addTab(ow, rc->displayName()); if (debug) diff --git a/src/plugins/projectexplorer/compileoutputwindow.cpp b/src/plugins/projectexplorer/compileoutputwindow.cpp index 539ad34f45b..75df27230c6 100644 --- a/src/plugins/projectexplorer/compileoutputwindow.cpp +++ b/src/plugins/projectexplorer/compileoutputwindow.cpp @@ -36,7 +36,7 @@ #include "taskhub.h" #include -#include +#include #include #include #include @@ -127,7 +127,7 @@ CompileOutputWindow::CompileOutputWindow(BuildManager * /*bm*/, QAction *cancelB Aggregation::Aggregate *agg = new Aggregation::Aggregate; agg->add(m_outputWindow); - agg->add(new Find::BaseTextFind(m_outputWindow)); + agg->add(new Core::BaseTextFind(m_outputWindow)); qRegisterMetaType("QTextCharFormat"); diff --git a/src/plugins/projectexplorer/currentprojectfilter.cpp b/src/plugins/projectexplorer/currentprojectfilter.cpp index 0d05f8ff910..dabee908b71 100644 --- a/src/plugins/projectexplorer/currentprojectfilter.cpp +++ b/src/plugins/projectexplorer/currentprojectfilter.cpp @@ -34,7 +34,6 @@ #include using namespace Core; -using namespace Locator; using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; diff --git a/src/plugins/projectexplorer/currentprojectfilter.h b/src/plugins/projectexplorer/currentprojectfilter.h index f932b5aa207..25fe85a8acc 100644 --- a/src/plugins/projectexplorer/currentprojectfilter.h +++ b/src/plugins/projectexplorer/currentprojectfilter.h @@ -30,7 +30,7 @@ #ifndef CURRENTPROJECTFILTER_H #define CURRENTPROJECTFILTER_H -#include +#include #include @@ -40,7 +40,7 @@ class Project; namespace Internal { -class CurrentProjectFilter : public Locator::BaseFileFilter +class CurrentProjectFilter : public Core::BaseFileFilter { Q_OBJECT diff --git a/src/plugins/projectexplorer/currentprojectfind.cpp b/src/plugins/projectexplorer/currentprojectfind.cpp index c0b89a8bfba..8b7fce47782 100644 --- a/src/plugins/projectexplorer/currentprojectfind.cpp +++ b/src/plugins/projectexplorer/currentprojectfind.cpp @@ -39,7 +39,6 @@ #include #include -using namespace Find; using namespace ProjectExplorer; using namespace ProjectExplorer::Internal; using namespace TextEditor; @@ -103,7 +102,7 @@ void CurrentProjectFind::handleProjectChanged() void CurrentProjectFind::recheckEnabled() { - SearchResult *search = qobject_cast(sender()); + Core::SearchResult *search = qobject_cast(sender()); if (!search) return; QString projectFile = getAdditionalParameters(search).toString(); diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp index 4e836e0cd48..1ca24358ed4 100644 --- a/src/plugins/projectexplorer/foldernavigationwidget.cpp +++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp @@ -38,8 +38,8 @@ #include #include #include +#include -#include #include #include diff --git a/src/plugins/projectexplorer/projectexplorer.qbs b/src/plugins/projectexplorer/projectexplorer.qbs index 1a10feb66d6..5f8abc5ae1e 100644 --- a/src/plugins/projectexplorer/projectexplorer.qbs +++ b/src/plugins/projectexplorer/projectexplorer.qbs @@ -9,8 +9,6 @@ QtcPlugin { Depends { name: "Qt"; submodules: ["widgets", "xml", "network", "script"] } Depends { name: "Qt.quick"; condition: QtcFunctions.versionIsAtLeast(Qt.core.version, "5.1"); } Depends { name: "Core" } - Depends { name: "Locator" } - Depends { name: "Find" } Depends { name: "TextEditor" } Depends { name: "QtcSsh" } diff --git a/src/plugins/projectexplorer/projectexplorer_dependencies.pri b/src/plugins/projectexplorer/projectexplorer_dependencies.pri index f970e87607c..ab0a5facc4e 100644 --- a/src/plugins/projectexplorer/projectexplorer_dependencies.pri +++ b/src/plugins/projectexplorer/projectexplorer_dependencies.pri @@ -3,8 +3,6 @@ QTC_LIB_DEPENDS += \ ssh \ utils QTC_PLUGIN_DEPENDS += \ - locator \ - find \ coreplugin \ texteditor QT *= network diff --git a/src/plugins/qmljseditor/qmljseditor.qbs b/src/plugins/qmljseditor/qmljseditor.qbs index 7284d2a3422..0ebd66d2a74 100644 --- a/src/plugins/qmljseditor/qmljseditor.qbs +++ b/src/plugins/qmljseditor/qmljseditor.qbs @@ -12,7 +12,6 @@ QtcPlugin { Depends { name: "QmlJSTools" } Depends { name: "QmlJS" } Depends { name: "LanguageUtils" } - Depends { name: "Find" } Depends { name: "QmlEditorWidgets" } Depends { name: "CPlusPlus" } diff --git a/src/plugins/qmljseditor/qmljseditor_dependencies.pri b/src/plugins/qmljseditor/qmljseditor_dependencies.pri index 481638aa2a9..56134f03348 100644 --- a/src/plugins/qmljseditor/qmljseditor_dependencies.pri +++ b/src/plugins/qmljseditor/qmljseditor_dependencies.pri @@ -4,7 +4,6 @@ QTC_LIB_DEPENDS += \ qmleditorwidgets QTC_PLUGIN_DEPENDS += \ coreplugin \ - find \ texteditor \ projectexplorer \ qmljstools diff --git a/src/plugins/qmljseditor/qmljsfindreferences.cpp b/src/plugins/qmljseditor/qmljsfindreferences.cpp index 7dc4179aa2c..f4162da0c7e 100644 --- a/src/plugins/qmljseditor/qmljsfindreferences.cpp +++ b/src/plugins/qmljseditor/qmljsfindreferences.cpp @@ -30,7 +30,7 @@ #include "qmljsfindreferences.h" #include -#include +#include #include #include #include @@ -925,20 +925,20 @@ void FindReferences::displayResults(int first, int last) const QString label = tr("QML/JS Usages:"); if (replacement.isEmpty()) { - m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch( - label, QString(), symbolName, Find::SearchResultWindow::SearchOnly); + m_currentSearch = Core::SearchResultWindow::instance()->startNewSearch( + label, QString(), symbolName, Core::SearchResultWindow::SearchOnly); } else { - m_currentSearch = Find::SearchResultWindow::instance()->startNewSearch( - label, QString(), symbolName, Find::SearchResultWindow::SearchAndReplace); + m_currentSearch = Core::SearchResultWindow::instance()->startNewSearch( + label, QString(), symbolName, Core::SearchResultWindow::SearchAndReplace); m_currentSearch->setTextToReplace(replacement); - connect(m_currentSearch, SIGNAL(replaceButtonClicked(QString,QList,bool)), - SLOT(onReplaceButtonClicked(QString,QList,bool))); + connect(m_currentSearch, SIGNAL(replaceButtonClicked(QString,QList,bool)), + SLOT(onReplaceButtonClicked(QString,QList,bool))); } - connect(m_currentSearch, SIGNAL(activated(Find::SearchResultItem)), - this, SLOT(openEditor(Find::SearchResultItem))); + connect(m_currentSearch, SIGNAL(activated(Core::SearchResultItem)), + this, SLOT(openEditor(Core::SearchResultItem))); connect(m_currentSearch, SIGNAL(cancelled()), this, SLOT(cancel())); connect(m_currentSearch, SIGNAL(paused(bool)), this, SLOT(setPaused(bool))); - Find::SearchResultWindow::instance()->popup(IOutputPane::Flags(IOutputPane::ModeSwitch | IOutputPane::WithFocus)); + Core::SearchResultWindow::instance()->popup(IOutputPane::Flags(IOutputPane::ModeSwitch | IOutputPane::WithFocus)); FutureProgress *progress = ProgressManager::addTask( m_watcher.future(), tr("Searching"), @@ -981,7 +981,7 @@ void FindReferences::setPaused(bool paused) m_watcher.setPaused(paused); } -void FindReferences::openEditor(const Find::SearchResultItem &item) +void FindReferences::openEditor(const Core::SearchResultItem &item) { if (item.path.size() > 0) { EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()), @@ -991,7 +991,7 @@ void FindReferences::openEditor(const Find::SearchResultItem &item) } } -void FindReferences::onReplaceButtonClicked(const QString &text, const QList &items, bool preserveCase) +void FindReferences::onReplaceButtonClicked(const QString &text, const QList &items, bool preserveCase) { const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase); @@ -1011,5 +1011,5 @@ void FindReferences::onReplaceButtonClicked(const QString &text, const QListupdateSourceFiles(changedUnsavedEditors, false); - Find::SearchResultWindow::instance()->hide(); + Core::SearchResultWindow::instance()->hide(); } diff --git a/src/plugins/qmljseditor/qmljsfindreferences.h b/src/plugins/qmljseditor/qmljsfindreferences.h index f4d3dc6c55c..a9fcd38de9a 100644 --- a/src/plugins/qmljseditor/qmljsfindreferences.h +++ b/src/plugins/qmljseditor/qmljsfindreferences.h @@ -40,10 +40,10 @@ QT_FORWARD_DECLARE_CLASS(QTimer) -namespace Find { +namespace Core { class SearchResultItem; class SearchResult; -} // namespace Find +} // namespace Core namespace QmlJSEditor { @@ -85,11 +85,11 @@ private Q_SLOTS: void searchFinished(); void cancel(); void setPaused(bool paused); - void openEditor(const Find::SearchResultItem &item); - void onReplaceButtonClicked(const QString &text, const QList &items, bool preserveCase); + void openEditor(const Core::SearchResultItem &item); + void onReplaceButtonClicked(const QString &text, const QList &items, bool preserveCase); private: - QPointer m_currentSearch; + QPointer m_currentSearch; QFutureWatcher m_watcher; }; diff --git a/src/plugins/qmljstools/qmlconsolepane.cpp b/src/plugins/qmljstools/qmlconsolepane.cpp index c55ecdfd31c..6f5c0f26d2f 100644 --- a/src/plugins/qmljstools/qmlconsolepane.cpp +++ b/src/plugins/qmljstools/qmlconsolepane.cpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include @@ -95,7 +95,7 @@ QmlConsolePane::QmlConsolePane(QObject *parent) Aggregation::Aggregate *aggregate = new Aggregation::Aggregate(); aggregate->add(m_consoleView); - aggregate->add(new Find::TreeViewFind(m_consoleView)); + aggregate->add(new Core::TreeViewFind(m_consoleView)); vbox->addWidget(m_consoleView); vbox->addWidget(new Core::FindToolBarPlaceHolder(m_consoleWidget)); diff --git a/src/plugins/qmljstools/qmljsfunctionfilter.cpp b/src/plugins/qmljstools/qmljsfunctionfilter.cpp index 9da8cc3c683..32e709b5627 100644 --- a/src/plugins/qmljstools/qmljsfunctionfilter.cpp +++ b/src/plugins/qmljstools/qmljsfunctionfilter.cpp @@ -39,7 +39,7 @@ using namespace QmlJSTools::Internal; Q_DECLARE_METATYPE(LocatorData::Entry) FunctionFilter::FunctionFilter(LocatorData *data, QObject *parent) - : Locator::ILocatorFilter(parent) + : Core::ILocatorFilter(parent) , m_data(data) { setId("Functions"); @@ -55,17 +55,17 @@ void FunctionFilter::refresh(QFutureInterface &) { } -static bool compareLexigraphically(const Locator::FilterEntry &a, - const Locator::FilterEntry &b) +static bool compareLexigraphically(const Core::LocatorFilterEntry &a, + const Core::LocatorFilterEntry &b) { return a.displayName < b.displayName; } -QList FunctionFilter::matchesFor(QFutureInterface &future, const QString &origEntry) +QList FunctionFilter::matchesFor(QFutureInterface &future, const QString &origEntry) { QString entry = trimWildcards(origEntry); - QList goodEntries; - QList betterEntries; + QList goodEntries; + QList betterEntries; const QChar asterisk = QLatin1Char('*'); QStringMatcher matcher(entry, Qt::CaseInsensitive); QRegExp regexp(asterisk + entry+ asterisk, Qt::CaseInsensitive, QRegExp::Wildcard); @@ -89,7 +89,7 @@ QList FunctionFilter::matchesFor(QFutureInterface FunctionFilter::matchesFor(QFutureInterface(selection.internalData); Core::EditorManager::openEditorAt(entry.fileName, entry.line, entry.column); diff --git a/src/plugins/qmljstools/qmljsfunctionfilter.h b/src/plugins/qmljstools/qmljsfunctionfilter.h index ee7d468c1d8..5728a46c6cf 100644 --- a/src/plugins/qmljstools/qmljsfunctionfilter.h +++ b/src/plugins/qmljstools/qmljsfunctionfilter.h @@ -30,14 +30,14 @@ #ifndef QMLJSFUNCTIONFILTER_H #define QMLJSFUNCTIONFILTER_H -#include +#include namespace QmlJSTools { namespace Internal { class LocatorData; -class FunctionFilter : public Locator::ILocatorFilter +class FunctionFilter : public Core::ILocatorFilter { Q_OBJECT @@ -45,8 +45,8 @@ public: explicit FunctionFilter(LocatorData *data, QObject *parent = 0); ~FunctionFilter(); - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(Locator::FilterEntry selection) const; + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(Core::LocatorFilterEntry selection) const; void refresh(QFutureInterface &future); private: diff --git a/src/plugins/qmljstools/qmljstools.qbs b/src/plugins/qmljstools/qmljstools.qbs index 629cef4a153..ffbd0624322 100644 --- a/src/plugins/qmljstools/qmljstools.qbs +++ b/src/plugins/qmljstools/qmljstools.qbs @@ -12,7 +12,6 @@ QtcPlugin { Depends { name: "QmlJS" } Depends { name: "ProjectExplorer" } Depends { name: "TextEditor" } - Depends { name: "Locator" } Depends { name: "QmlDebug" } Depends { name: "QtSupport" } diff --git a/src/plugins/qmljstools/qmljstools_dependencies.pri b/src/plugins/qmljstools/qmljstools_dependencies.pri index 2dd8e9b1c66..198ce543edd 100644 --- a/src/plugins/qmljstools/qmljstools_dependencies.pri +++ b/src/plugins/qmljstools/qmljstools_dependencies.pri @@ -5,8 +5,6 @@ QTC_LIB_DEPENDS += \ qmljs QTC_PLUGIN_DEPENDS += \ coreplugin \ - find \ - locator \ projectexplorer \ qtsupport \ texteditor \ diff --git a/src/plugins/resourceeditor/resourceeditor.qbs b/src/plugins/resourceeditor/resourceeditor.qbs index bac08834000..193c9b75133 100644 --- a/src/plugins/resourceeditor/resourceeditor.qbs +++ b/src/plugins/resourceeditor/resourceeditor.qbs @@ -6,7 +6,6 @@ QtcPlugin { name: "ResourceEditor" Depends { name: "Core" } - Depends { name: "Find" } Depends { name: "Qt"; submodules: ["widgets", "xml"] } Group { diff --git a/src/plugins/resourceeditor/resourceeditor_dependencies.pri b/src/plugins/resourceeditor/resourceeditor_dependencies.pri index 753971d6dbe..8a82e801cfc 100644 --- a/src/plugins/resourceeditor/resourceeditor_dependencies.pri +++ b/src/plugins/resourceeditor/resourceeditor_dependencies.pri @@ -3,4 +3,3 @@ QTC_LIB_DEPENDS += \ utils QTC_PLUGIN_DEPENDS += \ coreplugin \ - find diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp index ada5cdc8f24..36ce8a14a1f 100644 --- a/src/plugins/resourceeditor/resourceeditorw.cpp +++ b/src/plugins/resourceeditor/resourceeditorw.cpp @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include #include @@ -97,7 +97,7 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context, Aggregation::Aggregate * agg = new Aggregation::Aggregate; agg->add(m_resourceEditor->treeView()); - agg->add(new Find::TreeViewFind(m_resourceEditor->treeView())); + agg->add(new Core::TreeViewFind(m_resourceEditor->treeView())); m_resourceEditor->setResourceDragEnabled(true); m_contextMenu->addAction(tr("Open File"), this, SLOT(openCurrentFile())); diff --git a/src/plugins/subversion/subversion.qbs b/src/plugins/subversion/subversion.qbs index 6c3c48286f0..b92fff54f35 100644 --- a/src/plugins/subversion/subversion.qbs +++ b/src/plugins/subversion/subversion.qbs @@ -8,9 +8,7 @@ QtcPlugin { Depends { name: "Qt.widgets" } Depends { name: "Core" } Depends { name: "TextEditor" } - Depends { name: "Find" } Depends { name: "VcsBase" } - Depends { name: "Locator" } files: [ "annotationhighlighter.cpp", diff --git a/src/plugins/subversion/subversion_dependencies.pri b/src/plugins/subversion/subversion_dependencies.pri index 297af991b6d..87e1a57ad59 100644 --- a/src/plugins/subversion/subversion_dependencies.pri +++ b/src/plugins/subversion/subversion_dependencies.pri @@ -2,7 +2,6 @@ QTC_PLUGIN_NAME = Subversion QTC_LIB_DEPENDS += \ utils QTC_PLUGIN_DEPENDS += \ - locator \ texteditor \ coreplugin \ vcsbase diff --git a/src/plugins/subversion/subversionplugin.cpp b/src/plugins/subversion/subversionplugin.cpp index cc068dd144a..e6faebde04a 100644 --- a/src/plugins/subversion/subversionplugin.cpp +++ b/src/plugins/subversion/subversionplugin.cpp @@ -59,7 +59,7 @@ #include #include -#include +#include #include @@ -267,7 +267,7 @@ bool SubversionPlugin::initialize(const QStringList & /*arguments */, QString *e addAutoReleasedObject(new CheckoutWizard); const QString prefix = QLatin1String("svn"); - m_commandLocator = new Locator::CommandLocator("Subversion", prefix, prefix); + m_commandLocator = new Core::CommandLocator("Subversion", prefix, prefix); addAutoReleasedObject(m_commandLocator); //register actions diff --git a/src/plugins/subversion/subversionplugin.h b/src/plugins/subversion/subversionplugin.h index 77a1a6c7860..14e818156d8 100644 --- a/src/plugins/subversion/subversionplugin.h +++ b/src/plugins/subversion/subversionplugin.h @@ -42,6 +42,7 @@ class QTextCodec; QT_END_NAMESPACE namespace Core { + class CommandLocator; class IVersionControl; class IEditor; } @@ -53,10 +54,6 @@ namespace VcsBase { class VcsBaseSubmitEditor; } -namespace Locator { - class CommandLocator; -} - namespace Subversion { namespace Internal { @@ -170,7 +167,7 @@ private: QString m_commitMessageFileName; QString m_commitRepository; - Locator::CommandLocator *m_commandLocator; + Core::CommandLocator *m_commandLocator; Utils::ParameterAction *m_addAction; Utils::ParameterAction *m_deleteAction; Utils::ParameterAction *m_revertAction; diff --git a/src/plugins/tasklist/tasklist.qbs b/src/plugins/tasklist/tasklist.qbs index 8374262e75b..ef105ea216c 100644 --- a/src/plugins/tasklist/tasklist.qbs +++ b/src/plugins/tasklist/tasklist.qbs @@ -8,8 +8,6 @@ QtcPlugin { Depends { name: "Qt.widgets" } Depends { name: "Core" } Depends { name: "ProjectExplorer" } - Depends { name: "Find" } - Depends { name: "Locator" } Depends { name: "TextEditor" } files: [ diff --git a/src/plugins/texteditor/basefilefind.cpp b/src/plugins/texteditor/basefilefind.cpp index cb5d71fdd26..d6ad2f18abc 100644 --- a/src/plugins/texteditor/basefilefind.cpp +++ b/src/plugins/texteditor/basefilefind.cpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include #include @@ -56,27 +56,26 @@ namespace TextEditor { namespace Internal { -class BaseFileFindPrivate { + +class BaseFileFindPrivate +{ public: BaseFileFindPrivate() : m_resultLabel(0), m_filterCombo(0) {} - QMap *, QPointer > m_watchers; - QPointer m_currentFindSupport; + QMap *, QPointer > m_watchers; + QPointer m_currentFindSupport; QLabel *m_resultLabel; QStringListModel m_filterStrings; QString m_filterSetting; QPointer m_filterCombo; }; + } // namespace Internal -} // namespace TextEditor -using namespace Core; +using namespace Internal; using namespace Utils; -using namespace Find; -using namespace TextEditor; -using namespace TextEditor::Internal; - +using namespace Core; BaseFileFind::BaseFileFind() : d(new BaseFileFindPrivate) { @@ -125,14 +124,14 @@ QStringList BaseFileFind::fileNameFilters() const return filters; } -void BaseFileFind::runNewSearch(const QString &txt, Find::FindFlags findFlags, +void BaseFileFind::runNewSearch(const QString &txt, Core::FindFlags findFlags, SearchResultWindow::SearchMode searchMode) { d->m_currentFindSupport = 0; if (d->m_filterCombo) updateComboEntries(d->m_filterCombo, true); - SearchResult *search = Find::SearchResultWindow::instance()->startNewSearch(label(), - toolTip().arg(Find::IFindFilter::descriptionForFindFlags(findFlags)), + SearchResult *search = Core::SearchResultWindow::instance()->startNewSearch(label(), + toolTip().arg(Core::IFindFilter::descriptionForFindFlags(findFlags)), txt, searchMode, QString::fromLatin1("TextEditor")); search->setTextToReplace(txt); search->setSearchAgainSupported(true); @@ -142,10 +141,10 @@ void BaseFileFind::runNewSearch(const QString &txt, Find::FindFlags findFlags, parameters.nameFilters = fileNameFilters(); parameters.additionalParameters = additionalParameters(); search->setUserData(qVariantFromValue(parameters)); - connect(search, SIGNAL(activated(Find::SearchResultItem)), this, SLOT(openEditor(Find::SearchResultItem))); + connect(search, SIGNAL(activated(Core::SearchResultItem)), this, SLOT(openEditor(Core::SearchResultItem))); if (searchMode == SearchResultWindow::SearchAndReplace) { - connect(search, SIGNAL(replaceButtonClicked(QString,QList,bool)), - this, SLOT(doReplace(QString,QList,bool))); + connect(search, SIGNAL(replaceButtonClicked(QString,QList,bool)), + this, SLOT(doReplace(QString,QList,bool))); } connect(search, SIGNAL(visibilityChanged(bool)), this, SLOT(hideHighlightAll(bool))); connect(search, SIGNAL(cancelled()), this, SLOT(cancel())); @@ -157,20 +156,20 @@ void BaseFileFind::runNewSearch(const QString &txt, Find::FindFlags findFlags, runSearch(search); } -void BaseFileFind::runSearch(Find::SearchResult *search) +void BaseFileFind::runSearch(Core::SearchResult *search) { FileFindParameters parameters = search->userData().value(); CountingLabel *label = new CountingLabel; connect(search, SIGNAL(countChanged(int)), label, SLOT(updateCount(int))); CountingLabel *statusLabel = new CountingLabel; connect(search, SIGNAL(countChanged(int)), statusLabel, SLOT(updateCount(int))); - Find::SearchResultWindow::instance()->popup(IOutputPane::Flags(IOutputPane::ModeSwitch|IOutputPane::WithFocus)); + Core::SearchResultWindow::instance()->popup(IOutputPane::Flags(IOutputPane::ModeSwitch|IOutputPane::WithFocus)); QFutureWatcher *watcher = new QFutureWatcher(); d->m_watchers.insert(watcher, search); watcher->setPendingResultsLimit(1); connect(watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int))); connect(watcher, SIGNAL(finished()), this, SLOT(searchFinished())); - if (parameters.flags & Find::FindRegularExpression) { + if (parameters.flags & FindRegularExpression) { watcher->setFuture(Utils::findInFilesRegExp(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), @@ -188,24 +187,24 @@ void BaseFileFind::runSearch(Find::SearchResult *search) connect(progress, SIGNAL(clicked()), search, SLOT(popup())); } -void BaseFileFind::findAll(const QString &txt, Find::FindFlags findFlags) +void BaseFileFind::findAll(const QString &txt, Core::FindFlags findFlags) { runNewSearch(txt, findFlags, SearchResultWindow::SearchOnly); } -void BaseFileFind::replaceAll(const QString &txt, Find::FindFlags findFlags) +void BaseFileFind::replaceAll(const QString &txt, Core::FindFlags findFlags) { runNewSearch(txt, findFlags, SearchResultWindow::SearchAndReplace); } void BaseFileFind::doReplace(const QString &text, - const QList &items, + const QList &items, bool preserveCase) { QStringList files = replaceAll(text, items, preserveCase); if (!files.isEmpty()) { DocumentManager::notifyFilesChangedInternally(files); - Find::SearchResultWindow::instance()->hide(); + Core::SearchResultWindow::instance()->hide(); } } @@ -219,9 +218,9 @@ void BaseFileFind::displayResult(int index) { return; } Utils::FileSearchResultList results = watcher->resultAt(index); - QList items; + QList items; foreach (const Utils::FileSearchResult &result, results) { - Find::SearchResultItem item; + Core::SearchResultItem item; item.path = QStringList() << QDir::toNativeSeparators(result.fileName); item.lineNumber = result.lineNumber; item.text = result.matchingLine; @@ -231,7 +230,7 @@ void BaseFileFind::displayResult(int index) { item.userData = result.regexpCapturedTexts; items << item; } - search->addResults(items, Find::SearchResult::AddOrdered); + search->addResults(items, Core::SearchResult::AddOrdered); } void BaseFileFind::searchFinished() @@ -304,7 +303,7 @@ void BaseFileFind::updateComboEntries(QComboBox *combo, bool onTop) } } -void BaseFileFind::openEditor(const Find::SearchResultItem &item) +void BaseFileFind::openEditor(const Core::SearchResultItem &item) { SearchResult *result = qobject_cast(sender()); IEditor *openedEditor = 0; @@ -352,7 +351,7 @@ void BaseFileFind::recheckEnabled() } QStringList BaseFileFind::replaceAll(const QString &text, - const QList &items, + const QList &items, bool preserveCase) { if (items.isEmpty()) @@ -360,12 +359,12 @@ QStringList BaseFileFind::replaceAll(const QString &text, RefactoringChanges refactoring; - QHash > changes; - foreach (const Find::SearchResultItem &item, items) + QHash > changes; + foreach (const Core::SearchResultItem &item, items) changes[QDir::fromNativeSeparators(item.path.first())].append(item); // Checking for files without write permissions - QHashIterator > it(changes); + QHashIterator > it(changes); QSet roFiles; while (it.hasNext()) { it.next(); @@ -386,12 +385,12 @@ QStringList BaseFileFind::replaceAll(const QString &text, while (it.hasNext()) { it.next(); const QString fileName = it.key(); - const QList changeItems = it.value(); + const QList changeItems = it.value(); ChangeSet changeSet; RefactoringFilePtr file = refactoring.file(fileName); QSet > processed; - foreach (const Find::SearchResultItem &item, changeItems) { + foreach (const Core::SearchResultItem &item, changeItems) { const QPair &p = qMakePair(item.lineNumber, item.textMarkPos); if (processed.contains(p)) continue; @@ -441,3 +440,5 @@ void CountingLabel::updateCount(int count) { setText(tr("%1 found").arg(count)); } + +} // namespace TextEditor diff --git a/src/plugins/texteditor/basefilefind.h b/src/plugins/texteditor/basefilefind.h index e1d72b73247..f7f14662d52 100644 --- a/src/plugins/texteditor/basefilefind.h +++ b/src/plugins/texteditor/basefilefind.h @@ -32,8 +32,8 @@ #include "texteditor_global.h" -#include -#include +#include +#include QT_BEGIN_NAMESPACE class QLabel; @@ -41,18 +41,18 @@ class QComboBox; QT_END_NAMESPACE namespace Utils { class FileIterator; } -namespace Find { +namespace Core { class SearchResult; class SearchResultItem; class IFindSupport; -} // namespace Find +} // namespace Core namespace TextEditor { namespace Internal { class BaseFileFindPrivate; } // namespace Internal -class TEXTEDITOR_EXPORT BaseFileFind : public Find::IFindFilter +class TEXTEDITOR_EXPORT BaseFileFind : public Core::IFindFilter { Q_OBJECT @@ -62,21 +62,21 @@ public: bool isEnabled() const; bool isReplaceSupported() const { return true; } - void findAll(const QString &txt, Find::FindFlags findFlags); - void replaceAll(const QString &txt, Find::FindFlags findFlags); + void findAll(const QString &txt, Core::FindFlags findFlags); + void replaceAll(const QString &txt, Core::FindFlags findFlags); /* returns the list of unique files that were passed in items */ static QStringList replaceAll(const QString &txt, - const QList &items, + const QList &items, bool preserveCase = false); protected: virtual Utils::FileIterator *files(const QStringList &nameFilters, const QVariant &additionalParameters) const = 0; virtual QVariant additionalParameters() const = 0; - QVariant getAdditionalParameters(Find::SearchResult *search); - virtual QString label() const = 0; // see Find::SearchResultWindow::startNewSearch - virtual QString toolTip() const = 0; // see Find::SearchResultWindow::startNewSearch, + QVariant getAdditionalParameters(Core::SearchResult *search); + virtual QString label() const = 0; // see Core::SearchResultWindow::startNewSearch + virtual QString toolTip() const = 0; // see Core::SearchResultWindow::startNewSearch, // add %1 placeholder where the find flags should be put void writeCommonSettings(QSettings *settings); @@ -91,18 +91,18 @@ private slots: void searchFinished(); void cancel(); void setPaused(bool paused); - void openEditor(const Find::SearchResultItem &item); + void openEditor(const Core::SearchResultItem &item); void doReplace(const QString &txt, - const QList &items, + const QList &items, bool preserveCase); void hideHighlightAll(bool visible); void searchAgain(); void recheckEnabled(); private: - void runNewSearch(const QString &txt, Find::FindFlags findFlags, - Find::SearchResultWindow::SearchMode searchMode); - void runSearch(Find::SearchResult *search); + void runNewSearch(const QString &txt, Core::FindFlags findFlags, + Core::SearchResultWindow::SearchMode searchMode); + void runSearch(Core::SearchResult *search); Internal::BaseFileFindPrivate *d; }; diff --git a/src/plugins/texteditor/basefilefind_p.h b/src/plugins/texteditor/basefilefind_p.h index 8234a924d64..8622771c299 100644 --- a/src/plugins/texteditor/basefilefind_p.h +++ b/src/plugins/texteditor/basefilefind_p.h @@ -30,7 +30,7 @@ #ifndef BASEFILEFIND_P_H #define BASEFILEFIND_P_H -#include +#include #include #include @@ -52,7 +52,7 @@ class FileFindParameters { public: QString text; - Find::FindFlags flags; + Core::FindFlags flags; QStringList nameFilters; QVariant additionalParameters; }; diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index c374fa1775f..dbed95f3caf 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -57,7 +57,7 @@ #include #include #include -#include +#include #include #include #include @@ -104,6 +104,7 @@ \internal */ +using namespace Core; using namespace Utils; namespace TextEditor { @@ -2670,7 +2671,7 @@ void BaseTextEditorWidgetPrivate::highlightSearchResults(const QTextBlock &block l = m_searchExpr.matchedLength(); if (l == 0) break; - if ((m_findFlags & Find::FindWholeWords) + if ((m_findFlags & Core::FindWholeWords) && ((idx && text.at(idx-1).isLetterOrNumber()) || (idx + l < text.length() && text.at(idx + l).isLetterOrNumber()))) continue; @@ -4847,19 +4848,19 @@ void BaseTextEditorWidget::markBlocksAsChanged(QList blockNumbers) } -void BaseTextEditorWidget::highlightSearchResults(const QString &txt, Find::FindFlags findFlags) +void BaseTextEditorWidget::highlightSearchResults(const QString &txt, Core::FindFlags findFlags) { QString pattern = txt; // highlighting single characters only if you're searching for whole words - if (pattern.size() < 2 && !(findFlags & Find::FindWholeWords)) + if (pattern.size() < 2 && !(findFlags & FindWholeWords)) pattern.clear(); if (d->m_searchExpr.pattern() == pattern) return; d->m_searchExpr.setPattern(pattern); - d->m_searchExpr.setPatternSyntax((findFlags & Find::FindRegularExpression) ? + d->m_searchExpr.setPatternSyntax((findFlags & FindRegularExpression) ? QRegExp::RegExp : QRegExp::FixedString); - d->m_searchExpr.setCaseSensitivity((findFlags & Find::FindCaseSensitively) ? + d->m_searchExpr.setCaseSensitivity((findFlags & FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive); d->m_findFlags = findFlags; @@ -6128,11 +6129,10 @@ BaseTextEditor::BaseTextEditor(BaseTextEditorWidget *editor) : m_editorWidget(editor) { setWidget(m_editorWidget); - using namespace Find; Aggregation::Aggregate *aggregate = new Aggregation::Aggregate; BaseTextFind *baseTextFind = new BaseTextFind(editor); - connect(baseTextFind, SIGNAL(highlightAll(QString,Find::FindFlags)), - editor, SLOT(highlightSearchResults(QString,Find::FindFlags))); + connect(baseTextFind, SIGNAL(highlightAll(QString,Core::FindFlags)), + editor, SLOT(highlightSearchResults(QString,Core::FindFlags))); connect(baseTextFind, SIGNAL(findScopeChanged(QTextCursor,QTextCursor,int,int)), editor, SLOT(setFindScope(QTextCursor,QTextCursor,int,int))); aggregate->add(baseTextFind); diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index be0dbae9184..4f8d97288d8 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -35,7 +35,7 @@ #include "codeassist/assistenums.h" #include -#include +#include #include #include @@ -366,7 +366,7 @@ private slots: void editorContentsChange(int position, int charsRemoved, int charsAdded); void documentAboutToBeReloaded(); void documentReloadFinished(bool success); - void highlightSearchResults(const QString &txt, Find::FindFlags findFlags); + void highlightSearchResults(const QString &txt, Core::FindFlags findFlags); void setFindScope(const QTextCursor &start, const QTextCursor &end, int, int); bool inFindScope(const QTextCursor &cursor); bool inFindScope(int selectionStart, int selectionEnd); diff --git a/src/plugins/texteditor/basetexteditor_p.h b/src/plugins/texteditor/basetexteditor_p.h index 8d476bab311..9d9c85d12d5 100644 --- a/src/plugins/texteditor/basetexteditor_p.h +++ b/src/plugins/texteditor/basetexteditor_p.h @@ -185,7 +185,7 @@ public: QTextCharFormat m_ifdefedOutFormat; QRegExp m_searchExpr; - Find::FindFlags m_findFlags; + Core::FindFlags m_findFlags; QTextCharFormat m_searchResultFormat; QTextCharFormat m_searchScopeFormat; QTextCharFormat m_currentLineFormat; diff --git a/src/plugins/texteditor/findincurrentfile.cpp b/src/plugins/texteditor/findincurrentfile.cpp index c8a93106da6..def758770cb 100644 --- a/src/plugins/texteditor/findincurrentfile.cpp +++ b/src/plugins/texteditor/findincurrentfile.cpp @@ -37,7 +37,6 @@ #include -using namespace Find; using namespace TextEditor; using namespace TextEditor::Internal; diff --git a/src/plugins/texteditor/findinfiles.cpp b/src/plugins/texteditor/findinfiles.cpp index 9fc036e60aa..bfc56b7f248 100644 --- a/src/plugins/texteditor/findinfiles.cpp +++ b/src/plugins/texteditor/findinfiles.cpp @@ -30,7 +30,7 @@ #include "findinfiles.h" #include -#include +#include #include #include #include @@ -44,7 +44,7 @@ #include #include -using namespace Find; +using namespace Core; using namespace TextEditor; static FindInFiles *m_instance = 0; @@ -72,7 +72,7 @@ QString FindInFiles::displayName() const return tr("Files on File System"); } -void FindInFiles::findAll(const QString &txt, Find::FindFlags findFlags) +void FindInFiles::findAll(const QString &txt, Core::FindFlags findFlags) { updateComboEntries(m_directory, true); BaseFileFind::findAll(txt, findFlags); @@ -195,5 +195,5 @@ void FindInFiles::findOnFileSystem(const QString &path) const QFileInfo fi(path); const QString folder = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath(); m_instance->setDirectory(folder); - Find::FindPlugin::instance()->openFindDialog(m_instance); + FindPlugin::instance()->openFindDialog(m_instance); } diff --git a/src/plugins/texteditor/findinfiles.h b/src/plugins/texteditor/findinfiles.h index 0038dd75bfb..6f9cac5b5f7 100644 --- a/src/plugins/texteditor/findinfiles.h +++ b/src/plugins/texteditor/findinfiles.h @@ -50,7 +50,7 @@ public: QString id() const; QString displayName() const; - void findAll(const QString &txt, Find::FindFlags findFlags); + void findAll(const QString &txt, Core::FindFlags findFlags); QWidget *createConfigWidget(); void writeSettings(QSettings *settings); void readSettings(QSettings *settings); diff --git a/src/plugins/texteditor/findinopenfiles.cpp b/src/plugins/texteditor/findinopenfiles.cpp index dec1e278a80..f3fd8620814 100644 --- a/src/plugins/texteditor/findinopenfiles.cpp +++ b/src/plugins/texteditor/findinopenfiles.cpp @@ -37,7 +37,6 @@ #include -using namespace Find; using namespace TextEditor; using namespace TextEditor::Internal; diff --git a/src/plugins/texteditor/linenumberfilter.cpp b/src/plugins/texteditor/linenumberfilter.cpp index 21e9576bfe7..a97af5dbdad 100644 --- a/src/plugins/texteditor/linenumberfilter.cpp +++ b/src/plugins/texteditor/linenumberfilter.cpp @@ -43,7 +43,6 @@ typedef QPair LineColumn; Q_DECLARE_METATYPE(LineColumn) using namespace Core; -using namespace Locator; using namespace TextEditor; using namespace TextEditor::Internal; @@ -57,9 +56,9 @@ LineNumberFilter::LineNumberFilter(QObject *parent) setIncludedByDefault(true); } -QList LineNumberFilter::matchesFor(QFutureInterface &, const QString &entry) +QList LineNumberFilter::matchesFor(QFutureInterface &, const QString &entry) { - QList value; + QList value; QStringList lineAndColumn = entry.split(QLatin1Char(':')); int sectionCount = lineAndColumn.size(); int line = 0; @@ -82,12 +81,12 @@ QList LineNumberFilter::matchesFor(QFutureInterface +#include #include #include @@ -42,15 +42,15 @@ class ITextEditor; namespace Internal { -class LineNumberFilter : public Locator::ILocatorFilter +class LineNumberFilter : public Core::ILocatorFilter { Q_OBJECT public: explicit LineNumberFilter(QObject *parent = 0); - QList matchesFor(QFutureInterface &future, const QString &entry); - void accept(Locator::FilterEntry selection) const; + QList matchesFor(QFutureInterface &future, const QString &entry); + void accept(Core::LocatorFilterEntry selection) const; void refresh(QFutureInterface &) {} private: diff --git a/src/plugins/texteditor/texteditor.qbs b/src/plugins/texteditor/texteditor.qbs index 5cb8d7c1c60..f6472f7a18d 100644 --- a/src/plugins/texteditor/texteditor.qbs +++ b/src/plugins/texteditor/texteditor.qbs @@ -7,8 +7,6 @@ QtcPlugin { Depends { name: "Qt"; submodules: ["widgets", "xml", "network", "script", "printsupport"] } Depends { name: "Core" } - Depends { name: "Find" } - Depends { name: "Locator" } cpp.includePaths: base.concat([path]) // Needed for the highlighterengine autotest. @@ -267,9 +265,4 @@ QtcPlugin { "snippetssettingspage.ui", ] } - - Export { - Depends { name: "Find" } - Depends { name: "Locator" } - } } diff --git a/src/plugins/texteditor/texteditor_dependencies.pri b/src/plugins/texteditor/texteditor_dependencies.pri index 0d4d168776e..389caeeaa66 100644 --- a/src/plugins/texteditor/texteditor_dependencies.pri +++ b/src/plugins/texteditor/texteditor_dependencies.pri @@ -2,6 +2,4 @@ QTC_PLUGIN_NAME = TextEditor QTC_LIB_DEPENDS += \ utils QTC_PLUGIN_DEPENDS += \ - find \ - locator \ coreplugin diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index cef93738e9f..7e5f9d45dc4 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -35,7 +35,7 @@ #include "texteditorconstants.h" #include "texteditorplugin.h" -#include +#include #include #include #include @@ -425,7 +425,7 @@ void TextEditorActionHandler::gotoAction() locatorString += QLatin1Char(' '); const int selectionStart = locatorString.size(); locatorString += tr(":"); - Locator::LocatorManager::show(locatorString, selectionStart, locatorString.size() - selectionStart); + Core::LocatorManager::show(locatorString, selectionStart, locatorString.size() - selectionStart); } void TextEditorActionHandler::printAction() diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp index fb1b52bf7f6..7265ecb215f 100644 --- a/src/plugins/texteditor/texteditorplugin.cpp +++ b/src/plugins/texteditor/texteditorplugin.cpp @@ -210,7 +210,7 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe void TextEditorPlugin::extensionsInitialized() { - m_searchResultWindow = Find::SearchResultWindow::instance(); + m_searchResultWindow = Core::SearchResultWindow::instance(); m_outlineFactory->setWidgetFactories(ExtensionSystem::PluginManager::getObjects()); diff --git a/src/plugins/texteditor/texteditorplugin.h b/src/plugins/texteditor/texteditorplugin.h index 81110efbd0d..3fd323b156f 100644 --- a/src/plugins/texteditor/texteditorplugin.h +++ b/src/plugins/texteditor/texteditorplugin.h @@ -32,7 +32,7 @@ #include -namespace Find { +namespace Core { class SearchResultWindow; } @@ -85,7 +85,7 @@ private: TextEditorSettings *m_settings; PlainTextEditorFactory *m_editorFactory; LineNumberFilter *m_lineNumberFilter; - Find::SearchResultWindow *m_searchResultWindow; + Core::SearchResultWindow *m_searchResultWindow; OutlineFactory *m_outlineFactory; BaseTextMarkRegistry *m_baseTextMarkRegistry; }; diff --git a/src/plugins/vcsbase/vcsbase.qbs b/src/plugins/vcsbase/vcsbase.qbs index ff0b5ce8e8b..1abc87493eb 100644 --- a/src/plugins/vcsbase/vcsbase.qbs +++ b/src/plugins/vcsbase/vcsbase.qbs @@ -8,7 +8,6 @@ QtcPlugin { Depends { name: "Core" } Depends { name: "TextEditor" } Depends { name: "ProjectExplorer" } - Depends { name: "Find" } Depends { name: "Qt.widgets" } Depends { name: "CppTools" } Depends { name: "CPlusPlus" } diff --git a/src/plugins/vcsbase/vcsbase_dependencies.pri b/src/plugins/vcsbase/vcsbase_dependencies.pri index c089267094c..7126e57c9f3 100644 --- a/src/plugins/vcsbase/vcsbase_dependencies.pri +++ b/src/plugins/vcsbase/vcsbase_dependencies.pri @@ -3,5 +3,4 @@ QTC_PLUGIN_DEPENDS += \ coreplugin \ texteditor \ projectexplorer \ - find \ cpptools diff --git a/src/plugins/vcsbase/vcsbasesubmiteditor.cpp b/src/plugins/vcsbase/vcsbasesubmiteditor.cpp index 069b867ad11..3aafe9398fe 100644 --- a/src/plugins/vcsbase/vcsbasesubmiteditor.cpp +++ b/src/plugins/vcsbase/vcsbasesubmiteditor.cpp @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include @@ -241,7 +241,7 @@ VcsBaseSubmitEditor::VcsBaseSubmitEditor(const VcsBaseSubmitEditorParameters *pa this, SLOT(slotRefreshCommitData()), Qt::QueuedConnection); Aggregation::Aggregate *aggregate = new Aggregation::Aggregate; - aggregate->add(new Find::BaseTextFind(descriptionEdit)); + aggregate->add(new Core::BaseTextFind(descriptionEdit)); aggregate->add(this); } -- cgit v1.2.3