File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ """Contextual menu for Explorer
2
+
3
+ This script provides a contextual menu for
4
+ file or directory to open
5
+ explorer in this directory.
6
+
7
+ """
8
+
9
+ import os
10
+ import GPS
11
+ import os_utils
12
+ from gs_utils import interactive
13
+ import subprocess
14
+
15
+
16
+ def can_execute (context ):
17
+ """A filter to only allow this action for project or files view"""
18
+ return (
19
+ context .file () is not None or context .directory () is not None
20
+ ) and context .module_name in ["Files_View" , "Project_Explorer_Project" ]
21
+
22
+
23
+ @interactive (
24
+ name = "Locate in Explorer" ,
25
+ contextual = "Open explorer" ,
26
+ filter = can_execute
27
+ )
28
+ def on_activate ():
29
+ gps = os .environ .copy ()
30
+ sys = os .environ .copy ()
31
+ for k in gps .keys ():
32
+ if k .startswith ("GPS_STARTUP_" ):
33
+ if gps [k ] != "_ABSENT_VARIABLE_" :
34
+ sys [k [12 :]] = gps [k ]
35
+
36
+ path = GPS .current_context ().directory ()
37
+
38
+ if path is None :
39
+ if GPS .current_context ().file () is not None :
40
+ path = GPS .current_context ().file ().path
41
+ else :
42
+ path = '.'
43
+
44
+ if os .name == "nt" :
45
+ e = 'explorer.exe'
46
+ path = '"' + path + '"'
47
+ else :
48
+ e = 'xdg-open'
49
+
50
+ try :
51
+ subprocess .call ([e , path ], env = sys )
52
+ except Exception as ex :
53
+ GPS .Console ().write (print (ex ))
You can’t perform that action at this time.
0 commit comments