Skip to content

Commit 4b8e0d9

Browse files
committed
App: add up btn
[skip ci]
1 parent f6c3d4b commit 4b8e0d9

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

scripts/gdrive_app.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ def init_ui(self):
300300
self.fwd_btn.setIcon(get_icon(OutlineIcon.ARROW_RIGHT))
301301
self.fwd_btn.clicked.connect(self.go_forward)
302302

303+
self.up_btn = QPushButton()
304+
self.up_btn.setIcon(get_icon(OutlineIcon.ARROW_UP))
305+
self.up_btn.clicked.connect(self.go_up)
306+
303307
self.address_bar = QLineEdit()
304308
self.address_bar.returnPressed.connect(self.on_address_bar_return)
305309

@@ -314,6 +318,7 @@ def init_ui(self):
314318

315319
top_bar.addWidget(self.back_btn)
316320
top_bar.addWidget(self.fwd_btn)
321+
top_bar.addWidget(self.up_btn)
317322
top_bar.addWidget(self.address_bar)
318323

319324
right_layout.addLayout(top_bar)
@@ -434,9 +439,33 @@ def _load_from_history(self, folder_id: str, name: str, highlight_fileid: str |
434439
self.load_folder(folder_id, name, add_history=False, highlight_fileid=highlight_fileid)
435440
self.update_nav_buttons()
436441

442+
def go_up(self):
443+
if self.current_folder_id in ["my_drive", "shared_with_me"]:
444+
return
445+
446+
current_item = self.gcache.get_item(self.current_folder_id)
447+
if not current_item:
448+
return
449+
450+
parent_id = current_item.get('parent_id')
451+
if not parent_id:
452+
# Shared with me root items have parent_id IS NULL in gcache
453+
self.load_root("shared_with_me", highlight_fileid=self.current_folder_id)
454+
return
455+
456+
if len(parent_id) == 19:
457+
# My Drive root items have parent_id length 19 in gcache
458+
self.load_root("my_drive", highlight_fileid=self.current_folder_id)
459+
return
460+
461+
parent_item = self.gcache.get_item(parent_id)
462+
if parent_item:
463+
self.load_folder(parent_id, parent_item['name'], highlight_fileid=self.current_folder_id)
464+
437465
def update_nav_buttons(self):
438466
self.back_btn.setEnabled(self.history_index > 0)
439467
self.fwd_btn.setEnabled(self.history_index < len(self.history) - 1)
468+
self.up_btn.setEnabled(self.current_folder_id not in ["my_drive", "shared_with_me"])
440469

441470
def on_nav_clicked(self, item: QListWidgetItem):
442471
root_type = item.data(Qt.UserRole)

0 commit comments

Comments
 (0)