One Submenu for many plugins
-
Hi,
I Need some help.
I wish to create the same submenu for some plugins.AS exemple:
Plugin A
Plugin B
Plugin CFor something like that:
[pre:f9u5ni7z]Plugins
-> Sub1
-> sub11
-> Plugin A
-> plugin B
-> Function Y
-> Function Z
-> sub12
-> plugin C[/pre:f9u5ni7z]I tried something like that:
plugin A:
sub_1 = UI.menu( 'plugin' ).add_submenu( 'Sub1' )
sub_11 = sub_1.add_submenu( 'sub11')
sub_11.add_item("plugin A") {A}plugin B:
sub_1 = UI.menu( 'plugin' ).add_submenu( 'Sub1' )
sub_11 = sub_1.add_submenu( 'sub11')
Sub_Plug = sub_11.add_submenu( 'plugin B')
Sub_Plug.add_item("Function Y") {Y}
Sub_Plug.add_item("Function Z") {Z}plugin
sub_1 = UI.menu( 'plugin' ).add_submenu( 'Sub 1' )
sub_12 = sub_1.add_submenu( 'sub12')
sub_11.add_item("plugin C") {C}And it gives:
[pre:f9u5ni7z]Plugins
-> Sub1
-> sub11
-> plugin A
-> Sub1
-> sub11
-> plugin B
-> Function Y
-> Function Z
-> Sub1
-> sub12
-> plugin C[/pre:f9u5ni7z]How can I do to fix this ?
Thank you for the help and sorry for my bad english.
Have a good day. -
Adding a 2nd level submenu:
"Plugins/Kherv/pluginC/plugin_c.rb"
module Kherv module PluginC require('Kherv/kherv_menu.rb') include(Kherv;;Menu) if SUBMENU['Sub 1/Sub 1.1'] @sub = SUBMENU['Sub 1/Sub 1.1'] else @sub = SUBMENU['Sub 1/Sub 1.1']= SUBMENU['Sub 1'].add_submenu('Sub 1.1') end @sub.add_item('Item C') { # code here } end # submodule for PluginC end
-
Only create menu "Sub1" ONCE.
(1) Write all your plugins so they are wrapped within YOUR toplevel module.
"Plugins/Kherv/kherv_menu.rb"
module Kherv module Menu # this is a "mixin" module TOPMENU ||= UI.menu('Plugins').add_submenu('Kherv') SUBMENU ||= {} # Hash to hold submenu references # hash keys can be menu paths like; "Kherv/Tools/Text" end end
"Plugins/Kherv/pluginA/plugin_a.rb"
module Kherv module PluginA require('Kherv/kherv_menu.rb') include(Kherv;;Menu) if SUBMENU['Sub 1'] @sub = SUBMENU['Sub 1'] else @sub = SUBMENU['Sub 1']= TOPMENU.add_submenu('Sub 1') end @sub.add_item('Item A') { # code here } end # submodule for PluginA end
"Plugins/Kherv/pluginB/plugin_b.rb"
module Kherv module PluginB require('Kherv/kherv_menu.rb') include(Kherv;;Menu) if SUBMENU['Sub 1'] @sub = SUBMENU['Sub 1'] else @sub = SUBMENU['Sub 1']= TOPMENU.add_submenu('Sub 1') end @sub.add_item('Item B') { # code here } end # submodule for PluginB end
-
Although this should work.. because of current API bugs. It will not.
See thread: http://sketchucation.com/forums/viewtopic.php?f=180&t=49912&p=449979#p449362
Advertisement