125 self.srHistory = { |
125 self.srHistory = { |
126 "search": [], |
126 "search": [], |
127 "replace": [] |
127 "replace": [] |
128 } |
128 } |
129 from .SearchReplaceWidget import SearchReplaceWidget |
129 from .SearchReplaceWidget import SearchReplaceWidget |
130 self.searchDlg = SearchReplaceWidget(False, self, self) |
130 self.__searchWidget = SearchReplaceWidget(False, self, self) |
131 self.replaceDlg = SearchReplaceWidget(True, self, self) |
131 self.__replaceWidget = SearchReplaceWidget(True, self, self) |
132 |
132 |
133 centralWidget = QWidget() |
133 centralWidget = QWidget() |
134 layout = QVBoxLayout() |
134 layout = QVBoxLayout() |
135 layout.setContentsMargins(1, 1, 1, 1) |
135 layout.setContentsMargins(1, 1, 1, 1) |
136 layout.addWidget(self.__textEdit) |
136 layout.addWidget(self.__textEdit) |
137 layout.addWidget(self.searchDlg) |
137 layout.addWidget(self.__searchWidget) |
138 layout.addWidget(self.replaceDlg) |
138 layout.addWidget(self.__replaceWidget) |
139 centralWidget.setLayout(layout) |
139 centralWidget.setLayout(layout) |
140 self.setCentralWidget(centralWidget) |
140 self.setCentralWidget(centralWidget) |
141 self.searchDlg.hide() |
141 self.__searchWidget.hide() |
142 self.replaceDlg.hide() |
142 self.__replaceWidget.hide() |
143 |
143 |
144 self.lexer_ = None |
144 self.lexer_ = None |
145 self.apiLanguage = "" |
145 self.apiLanguage = "" |
146 self.filetype = "" |
146 self.filetype = "" |
147 |
147 |
178 self.__textEdit.setContextMenuPolicy(Qt.CustomContextMenu) |
178 self.__textEdit.setContextMenuPolicy(Qt.CustomContextMenu) |
179 self.__textEdit.customContextMenuRequested.connect( |
179 self.__textEdit.customContextMenuRequested.connect( |
180 self.__contextMenuRequested) |
180 self.__contextMenuRequested) |
181 |
181 |
182 self.__textEdit.selectionChanged.connect( |
182 self.__textEdit.selectionChanged.connect( |
183 self.searchDlg.selectionChanged) |
183 self.__searchWidget.selectionChanged) |
184 self.__textEdit.selectionChanged.connect( |
184 self.__textEdit.selectionChanged.connect( |
185 self.replaceDlg.selectionChanged) |
185 self.__replaceWidget.selectionChanged) |
186 |
186 |
187 self.__setCurrentFile("") |
187 self.__setCurrentFile("") |
188 if filename: |
188 if filename: |
189 self.__loadFile(filename, filetype) |
189 self.__loadFile(filename, filetype) |
190 |
190 |
1952 """<b>Search</b>""" |
1952 """<b>Search</b>""" |
1953 """<p>Search for some text in the current editor. A""" |
1953 """<p>Search for some text in the current editor. A""" |
1954 """ dialog is shown to enter the searchtext and options""" |
1954 """ dialog is shown to enter the searchtext and options""" |
1955 """ for the search.</p>""" |
1955 """ for the search.</p>""" |
1956 )) |
1956 )) |
1957 self.searchAct.triggered.connect(self.__search) |
1957 self.searchAct.triggered.connect(self.showSearchWidget) |
1958 self.searchActions.append(self.searchAct) |
1958 self.searchActions.append(self.searchAct) |
1959 |
1959 |
1960 self.searchNextAct = E5Action( |
1960 self.searchNextAct = E5Action( |
1961 QCoreApplication.translate('ViewManager', 'Search next'), |
1961 QCoreApplication.translate('ViewManager', 'Search next'), |
1962 UI.PixmapCache.getIcon("findNext.png"), |
1962 UI.PixmapCache.getIcon("findNext.png"), |
1972 """<b>Search next</b>""" |
1972 """<b>Search next</b>""" |
1973 """<p>Search the next occurrence of some text in the current""" |
1973 """<p>Search the next occurrence of some text in the current""" |
1974 """ editor. The previously entered searchtext and options are""" |
1974 """ editor. The previously entered searchtext and options are""" |
1975 """ reused.</p>""" |
1975 """ reused.</p>""" |
1976 )) |
1976 )) |
1977 self.searchNextAct.triggered.connect(self.searchDlg.findNext) |
1977 self.searchNextAct.triggered.connect(self.__searchNext) |
1978 self.searchActions.append(self.searchNextAct) |
1978 self.searchActions.append(self.searchNextAct) |
1979 |
1979 |
1980 self.searchPrevAct = E5Action( |
1980 self.searchPrevAct = E5Action( |
1981 QCoreApplication.translate('ViewManager', 'Search previous'), |
1981 QCoreApplication.translate('ViewManager', 'Search previous'), |
1982 UI.PixmapCache.getIcon("findPrev.png"), |
1982 UI.PixmapCache.getIcon("findPrev.png"), |
1992 """<b>Search previous</b>""" |
1992 """<b>Search previous</b>""" |
1993 """<p>Search the previous occurrence of some text in the""" |
1993 """<p>Search the previous occurrence of some text in the""" |
1994 """ current editor. The previously entered searchtext and""" |
1994 """ current editor. The previously entered searchtext and""" |
1995 """ options are reused.</p>""" |
1995 """ options are reused.</p>""" |
1996 )) |
1996 )) |
1997 self.searchPrevAct.triggered.connect(self.searchDlg.findPrev) |
1997 self.searchPrevAct.triggered.connect(self.__searchPrev) |
1998 self.searchActions.append(self.searchPrevAct) |
1998 self.searchActions.append(self.searchPrevAct) |
1999 |
1999 |
2000 self.searchClearMarkersAct = E5Action( |
2000 self.searchClearMarkersAct = E5Action( |
2001 QCoreApplication.translate('ViewManager', |
2001 QCoreApplication.translate('ViewManager', |
2002 'Clear search markers'), |
2002 'Clear search markers'), |
2031 """<b>Replace</b>""" |
2031 """<b>Replace</b>""" |
2032 """<p>Search for some text in the current editor and replace""" |
2032 """<p>Search for some text in the current editor and replace""" |
2033 """ it. A dialog is shown to enter the searchtext, the""" |
2033 """ it. A dialog is shown to enter the searchtext, the""" |
2034 """ replacement text and options for the search and replace.</p>""" |
2034 """ replacement text and options for the search and replace.</p>""" |
2035 )) |
2035 )) |
2036 self.replaceAct.triggered.connect(self.__replace) |
2036 self.replaceAct.triggered.connect(self.showReplaceWidget) |
2037 self.searchActions.append(self.replaceAct) |
2037 self.searchActions.append(self.replaceAct) |
|
2038 |
|
2039 self.replaceAndSearchAct = E5Action( |
|
2040 QCoreApplication.translate( |
|
2041 'ViewManager', 'Replace and Search'), |
|
2042 UI.PixmapCache.getIcon("editReplaceSearch.png"), |
|
2043 QCoreApplication.translate( |
|
2044 'ViewManager', 'Replace and Search'), |
|
2045 QKeySequence(QCoreApplication.translate( |
|
2046 'ViewManager', "Meta+R", "Search|Replace and Search")), |
|
2047 0, |
|
2048 self, 'vm_replace_search') |
|
2049 self.replaceAndSearchAct.setStatusTip(QCoreApplication.translate( |
|
2050 'ViewManager', |
|
2051 'Replace the found text and search the next occurrence')) |
|
2052 self.replaceAndSearchAct.setWhatsThis(QCoreApplication.translate( |
|
2053 'ViewManager', |
|
2054 """<b>Replace and Search</b>""" |
|
2055 """<p>Replace the found occurrence of text in the current""" |
|
2056 """ editor and search for the next one. The previously entered""" |
|
2057 """ search text and options are reused.</p>""" |
|
2058 )) |
|
2059 self.replaceAndSearchAct.triggered.connect( |
|
2060 self.__replaceWidget.replaceSearch) |
|
2061 self.searchActions.append(self.replaceAndSearchAct) |
|
2062 |
|
2063 self.replaceSelectionAct = E5Action( |
|
2064 QCoreApplication.translate( |
|
2065 'ViewManager', 'Replace Occurrence'), |
|
2066 UI.PixmapCache.getIcon("editReplace.png"), |
|
2067 QCoreApplication.translate( |
|
2068 'ViewManager', 'Replace Occurrence'), |
|
2069 QKeySequence(QCoreApplication.translate( |
|
2070 'ViewManager', "Ctrl+Meta+R", "Search|Replace Occurrence")), |
|
2071 0, |
|
2072 self, 'vm_replace_occurrence') |
|
2073 self.replaceSelectionAct.setStatusTip(QCoreApplication.translate( |
|
2074 'ViewManager', 'Replace the found text')) |
|
2075 self.replaceSelectionAct.setWhatsThis(QCoreApplication.translate( |
|
2076 'ViewManager', |
|
2077 """<b>Replace Occurrence</b>""" |
|
2078 """<p>Replace the found occurrence of the search text in the""" |
|
2079 """ current editor.</p>""" |
|
2080 )) |
|
2081 self.replaceSelectionAct.triggered.connect( |
|
2082 self.__replaceWidget.replace) |
|
2083 self.searchActions.append(self.replaceSelectionAct) |
|
2084 |
|
2085 self.replaceAllAct = E5Action( |
|
2086 QCoreApplication.translate( |
|
2087 'ViewManager', 'Replace All'), |
|
2088 UI.PixmapCache.getIcon("editReplaceAll.png"), |
|
2089 QCoreApplication.translate( |
|
2090 'ViewManager', 'Replace All'), |
|
2091 QKeySequence(QCoreApplication.translate( |
|
2092 'ViewManager', "Shift+Meta+R", "Search|Replace All")), |
|
2093 0, |
|
2094 self, 'vm_replace_all') |
|
2095 self.replaceAllAct.setStatusTip(QCoreApplication.translate( |
|
2096 'ViewManager', 'Replace search text occurrences')) |
|
2097 self.replaceAllAct.setWhatsThis(QCoreApplication.translate( |
|
2098 'ViewManager', |
|
2099 """<b>Replace All</b>""" |
|
2100 """<p>Replace all occurrences of the search text in the current""" |
|
2101 """ editor.</p>""" |
|
2102 )) |
|
2103 self.replaceAllAct.triggered.connect( |
|
2104 self.__replaceWidget.replaceAll) |
|
2105 self.searchActions.append(self.replaceAllAct) |
2038 |
2106 |
2039 def __createHelpActions(self): |
2107 def __createHelpActions(self): |
2040 """ |
2108 """ |
2041 Private method to create the Help actions. |
2109 Private method to create the Help actions. |
2042 """ |
2110 """ |
2112 self.editMenu.addAction(self.searchAct) |
2180 self.editMenu.addAction(self.searchAct) |
2113 self.editMenu.addAction(self.searchNextAct) |
2181 self.editMenu.addAction(self.searchNextAct) |
2114 self.editMenu.addAction(self.searchPrevAct) |
2182 self.editMenu.addAction(self.searchPrevAct) |
2115 self.editMenu.addAction(self.searchClearMarkersAct) |
2183 self.editMenu.addAction(self.searchClearMarkersAct) |
2116 self.editMenu.addAction(self.replaceAct) |
2184 self.editMenu.addAction(self.replaceAct) |
|
2185 self.editMenu.addAction(self.replaceAndSearchAct) |
|
2186 self.editMenu.addAction(self.replaceSelectionAct) |
|
2187 self.editMenu.addAction(self.replaceAllAct) |
2117 |
2188 |
2118 self.menuBar().addSeparator() |
2189 self.menuBar().addSeparator() |
2119 |
2190 |
2120 self.helpMenu = self.menuBar().addMenu(self.tr("&Help")) |
2191 self.helpMenu = self.menuBar().addMenu(self.tr("&Help")) |
2121 self.helpMenu.addAction(self.aboutAct) |
2192 self.helpMenu.addAction(self.aboutAct) |
3041 |
3112 |
3042 @return the word at that current position |
3113 @return the word at that current position |
3043 """ |
3114 """ |
3044 line, index = self.__textEdit.getCursorPosition() |
3115 line, index = self.__textEdit.getCursorPosition() |
3045 return self.__getWord(line, index) |
3116 return self.__getWord(line, index) |
3046 |
3117 |
3047 def __search(self): |
3118 def showSearchWidget(self): |
3048 """ |
3119 """ |
3049 Private method to handle the search action. |
3120 Public method to show the search widget. |
3050 """ |
3121 """ |
3051 self.replaceDlg.close() |
3122 self.__replaceWidget.hide() |
3052 self.searchDlg.show(self.textForFind()) |
3123 self.__searchWidget.show() |
|
3124 self.__searchWidget.show(self.textForFind()) |
|
3125 |
|
3126 def __searchNext(self): |
|
3127 """ |
|
3128 Private slot to handle the search next action. |
|
3129 """ |
|
3130 if self.__replaceWidget.isVisible(): |
|
3131 self.__replaceWidget.findNext() |
|
3132 else: |
|
3133 self.__searchWidget.findNext() |
|
3134 |
|
3135 def __searchPrev(self): |
|
3136 """ |
|
3137 Private slot to handle the search previous action. |
|
3138 """ |
|
3139 if self.__replaceWidget.isVisible(): |
|
3140 self.__replaceWidget.findPrev() |
|
3141 else: |
|
3142 self.__searchWidget.findPrev() |
|
3143 |
|
3144 def showReplaceWidget(self): |
|
3145 """ |
|
3146 Public method to show the replace widget. |
|
3147 """ |
|
3148 self.__searchWidget.hide() |
|
3149 self.__replaceWidget.show(self.textForFind()) |
3053 |
3150 |
3054 def __searchClearMarkers(self): |
3151 def __searchClearMarkers(self): |
3055 """ |
3152 """ |
3056 Private method to clear the search markers of the active window. |
3153 Private method to clear the search markers of the active window. |
3057 """ |
3154 """ |
3058 self.clearSearchIndicators() |
3155 self.clearSearchIndicators() |
3059 |
|
3060 def __replace(self): |
|
3061 """ |
|
3062 Private method to handle the replace action. |
|
3063 """ |
|
3064 self.searchDlg.close() |
|
3065 self.replaceDlg.show(self.textForFind()) |
|
3066 |
3156 |
3067 def activeWindow(self): |
3157 def activeWindow(self): |
3068 """ |
3158 """ |
3069 Public method to fulfill the ViewManager interface. |
3159 Public method to fulfill the ViewManager interface. |
3070 |
3160 |