'Set directory as working directory'

@Slot(str)
@Slot(str, bool)
@Slot(str, bool, bool)
@Slot(str, bool, bool, bool)
def chdir(self, directory, browsing_history=False, refresh_explorer=True, refresh_console=True):

    if directory:
        directory = osp.abspath(to_text_string(directory))
    if browsing_history:
        directory = self.history[self.histindex]
    elif (directory in self.history):
        self.histindex = self.history.index(directory)
    else:
        if (self.histindex is None):
            self.history = []
        else:
            self.history = self.history[:(self.histindex + 1)]
        self.history.append(directory)
        self.histindex = (len(self.history) - 1)
    os.chdir(directory)
    self.refresh_plugin()
    if refresh_explorer:
        self.set_explorer_cwd.emit(directory)
    if refresh_console:
        self.set_current_console_wd.emit(directory)
    self.refresh_findinfiles.emit()
