'Ask user to save file if modified'

def save_if_changed(self, cancelable=False, index=None):

    if (index is None):
        indexes = list(range(self.get_stack_count()))
    else:
        indexes = [index]
    buttons = (QMessageBox.Yes | QMessageBox.No)
    if cancelable:
        buttons |= QMessageBox.Cancel
    unsaved_nb = 0
    for index in indexes:
        if self.data[index].editor.document().isModified():
            unsaved_nb += 1
    if (not unsaved_nb):
        return True
    if (unsaved_nb > 1):
        buttons |= (QMessageBox.YesAll | QMessageBox.NoAll)
    yes_all = False
    for index in indexes:
        self.set_stack_index(index)
        finfo = self.data[index]
        if ((finfo.filename == self.tempfile_path) or yes_all):
            if (not self.save()):
                return False
        elif finfo.editor.document().isModified():
            self.msgbox = QMessageBox(QMessageBox.Question, self.title, (_('<b>%s</b>    has    been    modified.<br>Do    you    want    to    save    changes?') % osp.basename(finfo.filename)), buttons, parent=self)
            answer = self.msgbox.exec_()
            if (answer == QMessageBox.Yes):
                if (not self.save()):
                    return False
            elif (answer == QMessageBox.YesAll):
                if (not self.save()):
                    return False
                yes_all = True
            elif (answer == QMessageBox.NoAll):
                return True
            elif (answer == QMessageBox.Cancel):
                return False
    return True
