Put the search-replace macro into the next stage. The first stage
        is the query stage to ask the user for the string to replace,
        the second stage is to query the string to replace it with,
        and the third allows to replace or skip individual matches,
        or replace them all automatically.

def nextMode(self):
        """
        Put the search-replace macro into the next stage. The first stage
        is the query stage to ask the user for the string to replace,
        the second stage is to query the string to replace it with,
        and the third allows to replace or skip individual matches,
        or replace them all automatically.
        """
        # Terminate the replacement procedure if the no match was found.
        if len(self.matchList) == 0:
            self.qteAbort(QtmacsMessage())
            self.qteMain.qteKillMiniApplet()
            return

        self.queryMode += 1
        if self.queryMode == 1:
            # Disconnect the text-changed slot because no real time
            # highlighting is necessary when entering the replacement
            # string, unlike when entering the string to replace.
            self.qteText.textChanged.disconnect(self.qteTextChanged)

            # Store the string to replace and clear out the query field.
            self.toReplace = self.qteText.toPlainText()
            self.qteText.clear()
            self.qteTextPrefix.setText('mode 1')
        elif self.queryMode == 2:
            # Mode two is to replace or skip individual matches. For
            # this purpose rebind the "n", "!", and <space> keys
            # with the respective macros to facilitate it.
            register = self.qteMain.qteRegisterMacro
            bind = self.qteMain.qteBindKeyWidget

            # Unbind all keys from the input widget.
            self.qteMain.qteUnbindAllFromWidgetObject(self.qteText)

            macroName = register(self.ReplaceAll, replaceMacro=True)
            bind('!', macroName, self.qteText)

            macroName = register(self.ReplaceNext, replaceMacro=True)
            bind('<space>', macroName, self.qteText)

            macroName = register(self.SkipNext, replaceMacro=True)
            bind('n', macroName, self.qteText)

            macroName = register(self.Abort, replaceMacro=True)
            bind('q', macroName, self.qteText)
            bind('<enter>', macroName, self.qteText)

            self.toReplaceWith = self.qteText.toPlainText()
            self.qteTextPrefix.setText('mode 2')
            self.qteText.setText('<space> to replace, <n> to skip, '
                                 '<!> to replace all.')
        else:
            self.qteAbort(QtmacsMessage())
            self.qteMain.qteKillMiniApplet()