Improve file dialog and command line behavior

This commit is contained in:
No Time To Play 2022-12-12 15:20:18 +00:00
parent d43c9c6029
commit 7e549ed2ea
2 changed files with 19 additions and 2 deletions

View File

@ -8,8 +8,13 @@ Ported to Tcl/Tk.
* Application icon
* Full screen toggle
* Ability to name new files on the command line
* Console support (only in Tcl/Tk version)
### Changed
* File dialogs now set a suitable initial directory.
### Fixed
* Font size key combos were reversed.

View File

@ -44,7 +44,7 @@ else:
about_text = """
A two-pane outliner
Version 2.1a (11 December 2022)
Version 2.1b (12 December 2022)
MIT License
"""
@ -281,6 +281,12 @@ def save_file(full_path):
showerror("Error saving file", str(e), parent=top)
return False
def file_dir():
if outline_filename != None:
return os.path.dirname(outline_filename)
else:
return "."
def all_item_ids(item = ""):
"Return a flat list of item IDs present in the tree."
items = []
@ -374,6 +380,7 @@ def handle_open():
return
choice = askopenfilename(
title="Open existing outline",
initialdir=file_dir(),
filetypes=file_types,
parent=top)
if len(choice) == 0:
@ -397,6 +404,7 @@ def handle_saveas():
choice = asksaveasfilename(
title="Save outline as...",
initialdir=file_dir(),
filetypes=file_types,
parent=top)
if len(choice) == 0:
@ -940,7 +948,11 @@ if top.tk.call('tk', 'windowingsystem') == 'x11':
if len(sys.argv) < 2:
pass
elif not os.path.exists(sys.argv[1]):
outline_filename = os.path.abspath(sys.argv[1])
fn = os.path.basename(outline_filename)
top.title(fn + " | Scrunch Edit")
elif load_file(sys.argv[1]):
outline_filename = sys.argv[1]
outline_filename = os.path.abspath(sys.argv[1])
top.mainloop()