コード例 #1
0
    def _onReplaceFileOne(self, replaceText):
        """Do one replacement in the file
        """
        self._widget.updateComboBoxes()

        qpart = core.workspace().currentDocument().qutepart
        regExp = self._widget.getRegExp()

        start, end = qpart.absSelectedPosition

        match = regExp.search(qpart.text, start)

        if match is None:
            match = regExp.search(qpart.text, 0)

        if match is not None:
            replaceTextSubed = substitutions.makeSubstitutions(
                replaceText, match)
            qpart.replaceText(match.start(), len(match.group(0)),
                              replaceTextSubed)
            # move cursor to the end of replaced text
            qpart.absCursorPosition = match.start() + len(replaceTextSubed)
            # move selection to the next item
            self._searchFile(forward=True, incremental=False)
        else:
            self._widget.setState(self._widget.Bad)
コード例 #2
0
ファイル: controller.py プロジェクト: polovik/enki
    def _onReplaceFileOne(self, replaceText):
        """Do one replacement in the file
        """
        self._widget.updateComboBoxes()
        
        document = core.workspace().currentDocument()
        regExp = self._widget.getRegExp()

        start, end = document.absSelection()  # pylint: disable=W0612
        if start is None:
            start = 0
        
        match = regExp.search(document.text(), start)
        
        if match is None:
            match = regExp.search(document.text(), 0)
        
        if match is not None:
            document.goTo(absPos = match.start(), selectionLength = len(match.group(0)))
            replaceTextSubed = substitutions.makeSubstitutions(replaceText, match)
            document.replaceSelectedText(replaceTextSubed)
            document.goTo(absPos = match.start() + len(replaceTextSubed))
            # move selection to the next item
            self._searchFile(forward=True, incremental=False )
        else:
            self._widget.setState(self._widget.Bad)
コード例 #3
0
ファイル: threads.py プロジェクト: adjustive/enki
    def _doReplacements(self, content, matches):
        """Do replacements for one file
        """
        for result in matches[::-1]:  # count from end to begin because we are replacing by offset in content
            replaceTextWithMatches = substitutions.makeSubstitutions(self._replaceText,
                                                                     result.match)
            content = content[:result.match.start()] + replaceTextWithMatches + content[result.match.end():]

        return content
コード例 #4
0
ファイル: threads.py プロジェクト: MagSec-Arts/enki
    def _doReplacements(self, content, matches):
        """Do replacements for one file
        """
        for result in matches[::
                              -1]:  # count from end to begin because we are replacing by offset in content
            replaceTextWithMatches = substitutions.makeSubstitutions(
                self._replaceText, result.match)
            content = content[:result.match.start(
            )] + replaceTextWithMatches + content[result.match.end():]

        return content
コード例 #5
0
ファイル: controller.py プロジェクト: adjustive/enki
    def _onReplaceFileAll(self, replaceText):
        """Do all replacements in the file
        """
        self._widget.updateComboBoxes()

        qpart = core.workspace().currentDocument().qutepart
        regExp = self._widget.getRegExp()

        matches = self._findAllMatches(qpart.text, regExp)
        with qpart:
            for match in matches[::-1]:  # reverse order, because replacement may move indexes
                replaceTextSubed = substitutions.makeSubstitutions(replaceText, match)
                qpart.replaceText(match.start(), len(match.group(0)), replaceTextSubed)

        core.mainWindow().statusBar().showMessage( self.tr( "%d match(es) replaced." % len(matches) ), 3000 )
コード例 #6
0
    def _onReplaceFileAll(self, replaceText):
        """Do all replacements in the file
        """
        self._widget.updateComboBoxes()

        qpart = core.workspace().currentDocument().qutepart
        regExp = self._widget.getRegExp()

        matches = self._findAllMatches(qpart.text, regExp)
        with qpart:
            for match in matches[::
                                 -1]:  # reverse order, because replacement may move indexes
                replaceTextSubed = substitutions.makeSubstitutions(
                    replaceText, match)
                qpart.replaceText(match.start(), len(match.group(0)),
                                  replaceTextSubed)

        core.mainWindow().statusBar().showMessage(
            self.tr("%d match(es) replaced." % len(matches)), 3000)
コード例 #7
0
ファイル: controller.py プロジェクト: polovik/enki
    def _onReplaceFileAll(self, replaceText):
        """Do all replacements in the file
        """
        self._widget.updateComboBoxes()
        
        document = core.workspace().currentDocument()
        regExp = self._widget.getRegExp()

        oldPos = document.absCursorPosition()
        
        document.beginUndoAction()
        
        pos = 0
        count = 0
        match = regExp.search(document.text(), pos)
        while match is not None:
            document.goTo(absPos = match.start(), selectionLength = len(match.group(0)))
            replaceTextSubed = substitutions.makeSubstitutions(replaceText, match)
                
            document.replaceSelectedText(replaceTextSubed)
            
            count += 1
            
            pos = match.start() + len(replaceTextSubed)
            
            if not match.group(0) and not replText:  # avoid freeze when replacing empty with empty
                pos  += 1
            if pos < len(document.text()):
                match = regExp.search(document.text(), pos)
            else:
                match = None

        document.endUndoAction()
        
        if oldPos is not None:
            document.setCursorPosition(absPos = oldPos) # restore cursor position
        core.mainWindow().statusBar().showMessage( self.tr( "%d match(es) replaced." % count ), 3000 )
コード例 #8
0
ファイル: controller.py プロジェクト: adjustive/enki
    def _onReplaceFileOne(self, replaceText):
        """Do one replacement in the file
        """
        self._widget.updateComboBoxes()

        qpart = core.workspace().currentDocument().qutepart
        regExp = self._widget.getRegExp()

        start, end = qpart.absSelectedPosition

        match = regExp.search(qpart.text, start)

        if match is None:
            match = regExp.search(qpart.text, 0)

        if match is not None:
            replaceTextSubed = substitutions.makeSubstitutions(replaceText, match)
            qpart.replaceText(match.start(), len(match.group(0)), replaceTextSubed)
            # move cursor to the end of replaced text
            qpart.absCursorPosition = match.start() + len(replaceTextSubed)
            # move selection to the next item
            self._searchFile(forward=True, incremental=False )
        else:
            self._widget.setState(self._widget.Bad)