1- import libjuci , os
1+ import libjuci , gi , os
2+ gi .require_version ('Gtk' , '3.0' )
3+ from gi .repository import Gtk , Gio
24
3- favorite = "/home/zalox/projects" # change to your favorite project
4- favorite_file = "/home/zalox/.juci/plugins/gtkplugin.py"
5+ from libjuci import beta
6+
7+ favorite = os .environ ['HOME' ]
8+ plugin = os .environ ['HOME' ]
9+ favorite_file = os .environ ['HOME' ]
10+
11+ def add_menu (position , label , items ) :
12+ plugin_menu = beta .get_menu_from_name ("plugin_menu" )
13+ if not plugin_menu :
14+ libjuci .terminal .println ("plugin_menu menu does not exist" )
15+ return
16+ sub_menu = Gio .Menu .new ()
17+ i = 0
18+ app = beta .get_gtk_application ()
19+ for item in items :
20+ sub_menu .insert (i , item ["label" ], "app." + item ["action" ])
21+ i = i + 1
22+ python_action = Gio .SimpleAction .new (item ["action" ], None )
23+ python_action .connect ("activate" , item ["method" ])
24+ app .add_action (python_action )
25+ app .add_accelerator (item ["accel" ], "app." + item ["action" ], None )
26+
27+ if plugin_menu .get_n_items () >= position :
28+ plugin_menu .remove (position )
29+
30+ plugin_menu .insert_submenu (position , label , sub_menu )
531
632def init () :
7- append_project = """
8- [
9- {
10- "label": "_Plugins",
11- "menu_elements": [
33+ items = [
34+ {
35+ "label" : "Open plugin folder" ,
36+ "action" : "open_plugin_folder" ,
37+ "accel" : "<primary>p" ,
38+ "method" : open_plugin_folder
39+ },
40+ {
41+ "label" : "Open favorite folder" ,
42+ "action" : "open_favorite_folder" ,
43+ "accel" : "<primary>j" ,
44+ "method" : open_favorite_folder
45+ },
1246 {
13- "label":"_Tools",
14- "menu_elements": [
15- {
16- "label":"Open favorite folder",
17- "keybinding":"<primary>j",
18- "action":"tools.open_favorite_folder"
19- },
20- {
21- "label":"Open plugins folder",
22- "keybinding":"<primary>p",
23- "action":"tools.open_plugin_folder"
24- },
25- {
26- "label":"Open plugins folder",
27- "keybinding":"<primary>i",
28- "action":"tools.open_favorite_file"
29- }
30- ]
47+ "label" : "Open favorite file" ,
48+ "action" : "open_favorite_file" ,
49+ "accel" : "<primary><shift>j" ,
50+ "method" : open_favorite_file
3151 }
32- ]
33- }
34- ]
35- """
36- libjuci .add_menu_element (append_project )
52+ ]
53+ add_menu (0 , "_Tools" , items )
3754
38- def open_favorite_folder () :
55+ def open_favorite_folder (action , param ) :
3956 libjuci .directories .open (favorite )
4057
41- def open_favorite_file () :
58+ def open_favorite_file (action , param ) :
4259 libjuci .directories .open (favorite_file )
4360
44- def open_plugin_folder () :
45- folder = libjuci .get_juci_home ()
46- folder += "/plugins" # may break windows
47- libjuci .directories .open (folder )
61+ def open_plugin_folder (action , param ) :
62+ libjuci .directories .open (plugin )
4863
49- init ()
64+ init ()
0 commit comments