def close_tab(self, document): """ Close a document tab. @param document: The document that will be closed. @type document: A Document object. """ if not isinstance(document, Document): raise TypeError("The argument must be a Document object") if not document.is_updated(): dialog = CloseAlertDialog() button_clicked = dialog.run() dialog.destroy() if button_clicked == gtk.RESPONSE_DELETE_EVENT or \ button_clicked == 2: return elif button_clicked == 3: self.save_tab(document) self.remove_from_autosave(document) self.__remove_tab(document) self.emit("close-file", document) if self.get_n_pages() == 0: self.open_tab()
def change_encode(self, document, encode): #TODO: this method isn't use the document passed argument #TODO: what happen if a invalid encoding is passed? """ Change the text encode of a document. @param document: a document to change the encoding @type document: a Document. @param encode: encode name. @type encode: a String. """ page_num = self.get_current_page() if page_num != -1: document = self.get_nth_page(page_num) if document.encode != encode: file_uri = document.file_uri if file_uri != "": if not document.is_updated(): dialog = CloseAlertDialog() dialog.set_markup(constants.MESSAGE_0014) button_clicked = dialog.run() if button_clicked == gtk.RESPONSE_DELETE_EVENT: dialog.destroy() return elif button_clicked == 1: dialog.destroy() elif button_clicked == 2: dialog.destroy() return elif button_clicked == 3: self.save_active_tab(file_uri) dialog.destroy() self.__remove_tab(document) self.open_tab(file_uri, encode) else: self.__remove_tab(document) self.open_tab(file_uri, encode) new_page_num = self.get_current_page() document = self.get_nth_page(new_page_num) self.reorder_child(document, page_num)