From 30fb06bce3c76c7f37d8649aa33927f38ed194a9 Mon Sep 17 00:00:00 2001 From: mescalinum Date: Fri, 28 Oct 2011 19:25:27 +0000 Subject: add open menu svn path=/trunk/externals/loaders/tclpd/; revision=15671 --- tcl_class.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tcl_class.c') diff --git a/tcl_class.c b/tcl_class.c index 08fe2e6..596e28d 100644 --- a/tcl_class.c +++ b/tcl_class.c @@ -6,6 +6,7 @@ static hash_table_t* class_table = NULL; static hash_table_t* object_table = NULL; +static hash_table_t* source_table = NULL; #define class_table_add(n, c) hashtable_add(class_table, n, (void*)c) #define class_table_remove(n) hashtable_remove(class_table, n) @@ -32,6 +33,8 @@ t_class* tclpd_class_new(const char* name, int flags) { // is this really necessary given that there is already a 'anything' handler? class_addmethod(c, (t_method)tclpd_loadbang, gensym("loadbang"), A_NULL); + class_addmethod(c, (t_method)tclpd_open, gensym("menu-open"), A_NULL); + char buf[80]; Tcl_Obj* res; int res_i; @@ -80,6 +83,11 @@ t_tcl* tclpd_new(t_symbol* classsym, int ac, t_atom* at) { x->ninlets = 1 /* qlass->c_firstin ??? */; x->x_glist = (t_glist*)canvas_getcurrent(); + x->source_file = (char *)hashtable_get(source_table, name); + if(!x->source_file) { + post("tclpd: missing source file information. open command will not work."); + } + x->classname = Tcl_NewStringObj(name, -1); char so[64]; snprintf(so, 64, "tclpd.%s.x%lx", name, objectSequentialId++); @@ -224,6 +232,13 @@ void tclpd_loadbang(t_tcl* x) { tclpd_inlet_anything(x, 0, gensym("loadbang"), 0, NULL); } +void tclpd_open(t_tcl *x) { + if(!x->source_file) + return; + + sys_vgui("::pd_menucommands::menu_openfile {%s}\n", x->source_file); +} + /* Tcl glue: */ t_proxyinlet* tclpd_add_proxyinlet(t_tcl* x) { @@ -370,3 +385,14 @@ void tclpd_class_namespace_init(const char* classname) { classname, classname, classname); Tcl_Eval(tcl_for_pd, cmd); } + +void source_table_remove(const char *object_name) { + if(!source_table) + source_table = hashtable_new(1 << 7); + hashtable_remove(source_table, object_name); +} + +void source_table_add(const char *object_name, const char *source_file) { + source_table_remove(object_name); + hashtable_add(source_table, object_name, strdup(source_file)); +} -- cgit v1.2.1