99 QHBoxLayout , QListWidget , QListWidgetItem ,
1010 QPushButton , QLineEdit , QSplitter , QMessageBox ,
1111 QListView , QMenu , QProgressDialog , QCompleter ,
12- QDialog , QLabel )
12+ QDialog , QLabel , QInputDialog )
1313from PySide6 .QtCore import Qt , QSize
1414from PySide6 .QtGui import QIcon , QPixmap , QShortcut , QKeySequence
1515
@@ -405,6 +405,10 @@ def init_ui(self):
405405 self .context_shortcut = QShortcut (QKeySequence ("Shift+F10" ), self )
406406 self .context_shortcut .activated .connect (self .show_file_view_context_menu )
407407
408+ # Shortcut for renaming
409+ self .rename_shortcut = QShortcut (QKeySequence ("F2" ), self )
410+ self .rename_shortcut .activated .connect (self .trigger_rename )
411+
408412 self .file_view .setFocus ()
409413
410414 def apply_icon_overlay (self , pixmap : QPixmap , icon_enum : Any , color : str = None , is_filled : bool = False ) -> QPixmap :
@@ -699,6 +703,7 @@ def on_context_menu(self, pos):
699703 copy_id_action = menu .addAction ("Copy ID" )
700704 copy_link_action = menu .addAction ("Copy URL" )
701705 open_browser_action = menu .addAction ("Open in browser..." )
706+ rename_action = menu .addAction ("Rename..." )
702707 move_file_action = menu .addAction ("Move file..." )
703708
704709 action = menu .exec (self .file_view .viewport ().mapToGlobal (pos ))
@@ -709,9 +714,39 @@ def on_context_menu(self, pos):
709714 QApplication .clipboard ().setText (url )
710715 elif action == open_browser_action :
711716 webbrowser .open (url )
717+ elif action == rename_action :
718+ self .rename_file (file_data )
712719 elif action == move_file_action :
713720 self .move_file (file_data )
714721
722+ def trigger_rename (self ):
723+ if self .file_view .hasFocus ():
724+ item = self .file_view .currentItem ()
725+ if item :
726+ file_data = item .data (Qt .UserRole )
727+ self .rename_file (file_data )
728+
729+ def rename_file (self , file_data : Dict [str , Any ]):
730+ new_name , ok = QInputDialog .getText (
731+ self , "Rename" , "Enter new name:" ,
732+ text = file_data ['name' ]
733+ )
734+ if ok and new_name and new_name != file_data ['name' ]:
735+ try :
736+ # Use a progress dialog for the rename operation as it can be slow
737+ progress = QProgressDialog ("Renaming..." , None , 0 , 0 , self )
738+ progress .setWindowTitle ("Renaming" )
739+ progress .setWindowModality (Qt .WindowModal )
740+ progress .show ()
741+ QApplication .processEvents ()
742+
743+ self .gcache .rename_file (file_data ['id' ], new_name )
744+
745+ progress .close ()
746+ self .refresh ()
747+ except Exception as e :
748+ QMessageBox .critical (self , "Error" , f"Failed to rename file: { e } " )
749+
715750 def move_file (self , file_data : dict [str , Any ]):
716751 dialog = MoveFileDialog (self , self .gcache )
717752 if dialog .exec ():
0 commit comments