3162 self.__markedText = word |
3162 self.__markedText = word |
3163 |
3163 |
3164 ############################################################################ |
3164 ############################################################################ |
3165 ## Comment handling methods below |
3165 ## Comment handling methods below |
3166 ############################################################################ |
3166 ############################################################################ |
3167 |
3167 |
|
3168 def __isCommentedLine(self, line, commentStr): |
|
3169 """ |
|
3170 Private method to check, if the given line is a comment line as produced |
|
3171 by the configured comment rules. |
|
3172 |
|
3173 @param line text of the line to check (string) |
|
3174 @param commentStr comment string to check against (string) |
|
3175 @return flag indicating a commented line (boolean) |
|
3176 """ |
|
3177 if Preferences.getEditor("CommentColumn0"): |
|
3178 return line.startswith(commentStr) |
|
3179 else: |
|
3180 return line.strip().startswith(commentStr) |
|
3181 |
3168 def toggleCommentBlock(self): |
3182 def toggleCommentBlock(self): |
3169 """ |
3183 """ |
3170 Public slot to toggle the comment of a block. |
3184 Public slot to toggle the comment of a block. |
3171 |
3185 |
3172 If the line of the cursor or the selection is not commented, it will |
3186 If the line of the cursor or the selection is not commented, it will |
3180 line, index = self.getCursorPosition() |
3194 line, index = self.getCursorPosition() |
3181 |
3195 |
3182 # check if line starts with our comment string (i.e. was commented |
3196 # check if line starts with our comment string (i.e. was commented |
3183 # by our comment...() slots |
3197 # by our comment...() slots |
3184 if self.hasSelectedText() and \ |
3198 if self.hasSelectedText() and \ |
3185 self.text(self.getSelection()[0]).strip().startswith(commentStr): |
3199 self.__isCommentedLine(self.text(self.getSelection()[0]), commentStr): |
3186 self.uncommentLineOrSelection() |
3200 self.uncommentLineOrSelection() |
3187 elif not self.text(line).strip().startswith(commentStr): |
3201 elif not self.__isCommentedLine(self.text(line), commentStr): |
3188 # it doesn't, so comment the line or selection |
3202 # it doesn't, so comment the line or selection |
3189 self.commentLineOrSelection() |
3203 self.commentLineOrSelection() |
3190 else: |
3204 else: |
3191 # determine the start of the comment block |
3205 # determine the start of the comment block |
3192 begline = line |
3206 begline = line |
3193 while begline > 0 and \ |
3207 while begline > 0 and \ |
3194 self.text(begline - 1).strip().startswith(commentStr): |
3208 self.__isCommentedLine(self.text(begline - 1), commentStr): |
3195 begline -= 1 |
3209 begline -= 1 |
3196 # determine the end of the comment block |
3210 # determine the end of the comment block |
3197 endline = line |
3211 endline = line |
3198 lines = self.lines() |
3212 lines = self.lines() |
3199 while endline < lines and \ |
3213 while endline < lines and \ |
3200 self.text(endline + 1).strip().startswith(commentStr): |
3214 self.__isCommentedLine(self.text(endline + 1), commentStr): |
3201 endline += 1 |
3215 endline += 1 |
3202 |
3216 |
3203 self.setSelection(begline, 0, endline, self.lineLength(endline)) |
3217 self.setSelection(begline, 0, endline, self.lineLength(endline)) |
3204 self.uncommentLineOrSelection() |
3218 self.uncommentLineOrSelection() |
3205 |
3219 |
3231 commentStr = self.lexer_.commentStr() |
3245 commentStr = self.lexer_.commentStr() |
3232 line, index = self.getCursorPosition() |
3246 line, index = self.getCursorPosition() |
3233 |
3247 |
3234 # check if line starts with our comment string (i.e. was commented |
3248 # check if line starts with our comment string (i.e. was commented |
3235 # by our comment...() slots |
3249 # by our comment...() slots |
3236 if not self.text(line).strip().startswith(commentStr): |
3250 if not self.__isCommentedLine(self.text(line), commentStr): |
3237 return |
3251 return |
3238 |
3252 |
3239 # now remove the comment string |
3253 # now remove the comment string |
3240 self.beginUndoAction() |
3254 self.beginUndoAction() |
3241 if Preferences.getEditor("CommentColumn0"): |
3255 if Preferences.getEditor("CommentColumn0"): |
3299 self.beginUndoAction() |
3313 self.beginUndoAction() |
3300 # iterate over the lines |
3314 # iterate over the lines |
3301 for line in range(lineFrom, endLine + 1): |
3315 for line in range(lineFrom, endLine + 1): |
3302 # check if line starts with our comment string (i.e. was commented |
3316 # check if line starts with our comment string (i.e. was commented |
3303 # by our comment...() slots |
3317 # by our comment...() slots |
3304 if not self.text(line).strip().startswith(commentStr): |
3318 if not self.__isCommentedLine(self.text(line), commentStr): |
3305 continue |
3319 continue |
3306 |
3320 |
3307 if Preferences.getEditor("CommentColumn0"): |
3321 if Preferences.getEditor("CommentColumn0"): |
3308 self.setSelection(line, 0, line, len(commentStr)) |
3322 self.setSelection(line, 0, line, len(commentStr)) |
3309 else: |
3323 else: |