refactor: consolidate navigation logic and improve refresh reliability using path data context

This commit is contained in:
Martin Tranberg
2026-04-07 13:21:23 +02:00
parent 0159b91c69
commit 205b1ac241

View File

@@ -1078,24 +1078,21 @@ class SharePointApp(wx.Frame):
if idx < 0 or idx >= len(self.favorites): return
fav = self.favorites[idx]
self.current_path = fav['path']
self.update_path_display()
# Navigate to contents
# Opret navigations-data fra favoritten
data = {
"type": fav['type'],
"id": fav['id'],
"name": fav['name'],
"drive_id": fav['drive_id'],
"path": fav['path']
"path": fav['path'],
"web_url": fav.get('web_url')
}
if fav['type'] == "SITE": self.current_site_id = fav['id']
elif fav['drive_id']: self.current_drive_id = fav['drive_id']
# Vis indholdet og opdater stien
self._navigate_to_item_data(data)
self.list_ctrl.DeleteAllItems()
self.current_items = []
self.set_status(self.get_txt("status_loading_content"))
threading.Thread(target=self._fetch_list_contents_bg, args=(data,), daemon=True).start()
# Forsøg at synkronisere træet asynkront
wx.CallAfter(self._sync_tree_selection_by_path, fav['path'])
def on_favorite_right_click(self, event):
idx = self.fav_list.GetFirstSelected()
@@ -1503,12 +1500,20 @@ class SharePointApp(wx.Frame):
threading.Thread(target=self._fetch_tree_children_bg, args=(selected, data), daemon=True).start()
def _refresh_current_view(self):
# 1. Prøv at bruge den aktuelle navigationskontekst (pålideligt ved Favorites/Breadcrumbs)
if hasattr(self, 'current_path_data') and self.current_path_data:
data = self.current_path_data[-1]
self.set_status(f"Opdaterer '{data['name']}'...")
threading.Thread(target=self._fetch_list_contents_bg, args=(data,), daemon=True).start()
return
# 2. Fallback til Træ-kontrol markering
sel = self.tree_ctrl.GetSelection()
if sel.IsOk():
data = self.tree_item_data.get(sel)
if data:
# Kør i nuværende baggrundstråd hvis muligt, ellers ny
self._fetch_list_contents_bg(data)
self.set_status(f"Opdaterer '{data['name']}'...")
threading.Thread(target=self._fetch_list_contents_bg, args=(data,), daemon=True).start()
def clear_main(self):
self.list_ctrl.DeleteAllItems()