Skip to content

Commit

Permalink
Use upcounting filename index when exporting to single file
Browse files Browse the repository at this point in the history
"first_imported_file-01.pdf" instead of suggesting overwriting
"first_imported_file.pdf". Count up one on every export.
Close pdfarranger#758
  • Loading branch information
kbengs committed Dec 5, 2022
1 parent d464bb3 commit d6a1385
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pdfarranger/pdfarranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def __init__(self, *args, **kwargs):
self.export_process = None
self.post_action = None
self.export_file = None
self.export_counter = 1
self.drag_path = None
self.drag_pos = Gtk.IconViewDropPosition.DROP_RIGHT
self.window_width_old = 0
Expand Down Expand Up @@ -958,6 +959,7 @@ def clear_data(self):
self.metadata = {}
self.undomanager.clear()
self.set_export_file(None)
self.export_counter = 1
self.set_unsaved(False)
self.update_statusbar()
malloc_trim()
Expand Down Expand Up @@ -1028,9 +1030,18 @@ def choose_export_pdf_name(self, exportmode):
chooser.set_do_overwrite_confirmation(True)
if len(self.pdfqueue) > 0:
f = self.pdfqueue[0].filename
# could be an image thanks to img2pdf
if f.endswith(".pdf"):
chooser.set_filename(f)
f_dir, basename = os.path.split(f)
if exportmode == 'ALL_TO_SINGLE':
if f.endswith(".pdf"):
chooser.set_filename(f) # Set name to existing file
else:
shortname, ext = os.path.splitext(basename)
if exportmode == 'SELECTED_TO_SINGLE':
f = shortname + "-" + str(self.export_counter).zfill(2) + ext
else: # ALL_TO_MULTIPLE or SELECTED_TO_MULTIPLE
f = basename
if f.endswith(".pdf"):
chooser.set_current_name(f) # Set name to new file
chooser.set_current_folder(self.export_directory)
filter_list = self.__create_filters(['pdf', 'all'])
for f in filter_list[1:]:
Expand All @@ -1041,6 +1052,8 @@ def choose_export_pdf_name(self, exportmode):
chooser.destroy()
if response == Gtk.ResponseType.ACCEPT:
self.save(exportmode, file_out)
if exportmode == 'SELECTED_TO_SINGLE':
self.export_counter += 1
else:
self.post_action = None

Expand Down

0 comments on commit d6a1385

Please sign in to comment.