Skip to content

Commit e918a29

Browse files
Properly fix discard changes breaking UI
1 parent c969c13 commit e918a29

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

gui.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,21 @@ def open_create_new_project(self) -> None:
428428
self.create_new_project_buttons()
429429
self.new_project_frame.wait_window()
430430

431+
def clear_recent_projects(self) -> None:
432+
"""
433+
Clear the recent projects.
434+
435+
:return: None.
436+
"""
437+
logger.debug("Clearing recent projects...")
438+
if mbox.askokcancel("CircuitPython Project Manager: Confirm",
439+
"Are you sure you want to clear all recent projects?"):
440+
logger.debug("Clearing all recent projects!")
441+
self.save_key("opened_recent", [])
442+
self.update_recent_projects()
443+
else:
444+
logger.debug("User canceled clearing all recent projects!")
445+
431446
def update_recent_projects(self) -> None:
432447
"""
433448
Update the opened recent projects menu.
@@ -445,6 +460,9 @@ def update_recent_projects(self) -> None:
445460
command=lambda path=path: self.open_project(path))
446461
if len(self.recent_projects) == 0:
447462
self.opened_recent_menu.add_command(label="No recent projects!", state=tk.DISABLED)
463+
self.opened_recent_menu.add_separator()
464+
self.opened_recent_menu.add_command(label="Clear recent projects", command=self.clear_recent_projects,
465+
state=tk.DISABLED if len(self.recent_projects) == 0 else tk.NORMAL)
448466

449467
def create_file_menu(self) -> None:
450468
"""
@@ -838,7 +856,7 @@ def discard_modified(self) -> None:
838856
return
839857
try:
840858
logger.debug("Discarding all changes!")
841-
self.make_main_gui()
859+
self.update_main_gui()
842860
except FileNotFoundError:
843861
logger.exception("Uh oh, an exception has occurred!")
844862
self.close_project()
@@ -915,6 +933,7 @@ def update_main_gui(self) -> None:
915933
916934
:return: None.
917935
"""
936+
self.disable_closing = True
918937
self.update_menu_state()
919938
logger.debug("Updating main GUI...")
920939
self.destroy_all_children(widget=self.main_frame)
@@ -926,12 +945,15 @@ def create_main_gui(self) -> None:
926945
927946
:return: None.
928947
"""
948+
logger.debug(f"self.cpypmconfig_path: {repr(self.cpypmconfig_path)}")
929949
if self.cpypmconfig_path is None:
950+
logger.info("No project is open!")
930951
ttk.Label(
931952
master=self.main_frame,
932953
text="No project is open! Use the file menu to create\na new project or open an existing project!"
933954
).grid(row=0, column=0, sticky=tk.NW)
934955
else:
956+
logger.info("Project is open - (re)loading everything!")
935957
logger.debug(f"Parsing {repr(self.cpypmconfig_path)}")
936958
self.cpypmconfig = json.loads(self.cpypmconfig_path.read_text())
937959
self.make_title(self.cpypmconfig["project_name"])
@@ -941,6 +963,7 @@ def create_main_gui(self) -> None:
941963
self.make_file_sync_buttons()
942964
ttk.Separator(master=self.right_frame, orient=tk.HORIZONTAL).grid(row=3, column=0, padx=1, pady=1, sticky=tk.NW + tk.E)
943965
self.make_save_and_sync_buttons()
966+
self.disable_closing = False
944967

945968
def make_main_gui(self, cpypmconfig_path: Path = None) -> None:
946969
"""

0 commit comments

Comments
 (0)