4
4
from fileListApp import FileListApp # Assuming this is your custom module
5
5
from open import Open # Assuming this is your custom module
6
6
from PIL import Image , ImageTk
7
+ from model import Model
8
+ from texture import Texture
9
+ from map import Map
7
10
8
11
class File :
9
12
"""
@@ -112,6 +115,7 @@ def display_files(self):
112
115
113
116
# Bind double-click event to open the selected file
114
117
self .tree .bind ("<Double-Button-1>" , self .open_file )
118
+ self .tree .bind ("<Button-3>" , self .show_context_menu )
115
119
116
120
self .fileList = FileListApp (self .sdk , self .main_root )
117
121
@@ -189,14 +193,12 @@ def load_thumbnail(self, file_path, parent=""):
189
193
".smd" : "txt.png" ,
190
194
".cfg" : "txt.png" ,
191
195
".sln" : "Visual_Studio.png" ,
192
- ".vpk" : "fileexplorer.png" ,
193
196
".wav" : "audio.png" ,
194
197
".mp3" : "audio.png" ,
195
198
".bik" : "video.png" ,
196
199
".bat" : "terminal.png"
197
200
}
198
201
199
- #ext = os.path.splitext(file_path)[1]
200
202
file_name , file_extension = os .path .splitext (file_path )
201
203
202
204
if file_extension in file_icons :
@@ -217,3 +219,58 @@ def load_thumbnail(self, file_path, parent=""):
217
219
except Exception as e :
218
220
print ("Error loading thumbnail:" , e )
219
221
return None
222
+
223
+ def show_context_menu (self , event ):
224
+ """
225
+ Show the context menu on right-click.
226
+ """
227
+ selected_item = self .tree .identify_row (event .y )
228
+
229
+ if selected_item :
230
+ self .tree .selection_set (selected_item )
231
+
232
+ filename = self .tree .item (selected_item , 'text' )
233
+ print (filename )
234
+
235
+ parent_item = self .tree .parent (selected_item )
236
+
237
+ file_path_parts = [filename ]
238
+
239
+ while parent_item :
240
+ item_text = self .tree .item (parent_item , "text" )
241
+ file_path_parts .append (item_text )
242
+ parent_item = self .tree .parent (parent_item )
243
+
244
+ file_path_parts .reverse ()
245
+ file_path = os .path .join (self .sdk .parent_folder , * file_path_parts )
246
+
247
+ print (file_path )
248
+
249
+ self .context_menu = tk .Menu (self .tree , tearoff = 0 )
250
+
251
+ file_extension = os .path .splitext (filename )[1 ]
252
+
253
+ if file_extension == ".qc" :
254
+ model = Model (self .sdk )
255
+ self .context_menu .add_command (label = "Compile Model" , command = lambda : model .build_model (file_path ))
256
+ elif file_extension == ".tga" :
257
+ texture = Texture (self .sdk )
258
+ self .context_menu .add_command (label = "Compile Texture" , command = lambda : texture .build_texture (file_path ))
259
+ elif file_extension == ".vmf" :
260
+ map = Map (self .sdk )
261
+ self .context_menu .add_command (label = "Compile Map" , command = lambda : map .build_map (file_path ))
262
+
263
+ self .context_menu .add_command (label = "Delete" , command = lambda : self .delete_file (file_path , selected_item ))
264
+
265
+ self .context_menu .post (event .x_root , event .y_root )
266
+
267
+ def delete_file (self , file_path , tree_item ):
268
+ """
269
+ Delete the specified file and update the Treeview.
270
+ """
271
+ try :
272
+ os .remove (file_path )
273
+ self .tree .delete (tree_item )
274
+ print (f"Deleted: { file_path } " )
275
+ except Exception as e :
276
+ print (f"Error deleting file: { e } " )
0 commit comments