def __prompt_for_name(self, title, save_button_text, action, check_name=None): builder = SaveFileBuilder(title, self._get_display_name(), save_button_text, check_name) builder.dialog.set_transient_for(self.widget.get_toplevel()) if self._get_filename() is not None: builder.name_entry.set_text(os.path.basename(self._get_filename())) builder.prompt_for_name(self.notebook.folder, self._get_extension(), action) builder.dialog.destroy()
def __prompt_for_name(self, title, save_button_text, action, check_name=None): builder = SaveFileBuilder(title, self._get_display_name(), save_button_text, self._validate_name, check_name) builder.dialog.set_transient_for(self.widget.get_toplevel()) if self._get_filename() is not None: builder.name_entry.set_text(os.path.basename(self._get_filename())) builder.prompt_for_name(self.notebook.folder, self._get_extension(), action) builder.dialog.destroy()
def on_file_list_rename_file(self, file_list, file): if file.active: # If we have the file open, we need to rename via the editor for editor in self.editors: if editor.file == file: editor.rename() # Reselect the new item in the list new_file = self.notebook.file_for_absolute_path(editor.filename) file_list.select_file(new_file) else: # Otherwise do it directly def check_name(name): return name != "" and name != file.path def do_rename(new_path): old_path = os.path.join(self.notebook.folder, file.path) os.rename(old_path, new_path) self.notebook.refresh() # Reselect the new item in the list new_file = self.notebook.file_for_absolute_path(new_path) file_list.select_file(new_file) if isinstance(file, WorksheetFile): extension = "rws" validate_name = WorksheetEditor.validate_name elif isinstance(file, LibraryFile): extension = "py" validate_name = LibraryEditor.validate_name else: extension = "" validate_name = None title = "Rename '%s'" % file.path builder = SaveFileBuilder(title, file.path, "Rename", validate_name, check_name) builder.dialog.set_transient_for(self.window) builder.name_entry.set_text(file.path) builder.prompt_for_name(self.notebook.folder, extension, do_rename) builder.dialog.destroy()