1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#include <stdio.h>
#include <string.h>
#include "m_pd.h"
#include "g_canvas.h"
// tk_chooseDirectory
/*
proc pdtk_folderpanel {target localdir} {
if {$localdir == ""} {
set filename [tk_getSaveFile]
} else {
set filename [tk_getSaveFile -initialdir $localdir]
}
if {$filename != ""} {
pd [concat $target callback [pdtk_enquote $filename] \;]
}
}
*/
t_class *folderpanel_class;
typedef struct _folderpanel
{
t_object x_obj;
t_symbol *x_s;
} t_folderpanel;
static void folderpanel_symbol(t_folderpanel *x, t_symbol *s)
{
char *path = (s && s->s_name) ? s->s_name : "\"\"";
sys_vgui("tof_folderpanel %s \n", x->x_s->s_name);
}
static void folderpanel_bang(t_folderpanel *x)
{
folderpanel_symbol(x, &s_);
}
static void folderpanel_callback(t_folderpanel *x, t_symbol *s)
{
outlet_symbol(x->x_obj.ob_outlet, s);
}
static void folderpanel_free(t_folderpanel *x)
{
pd_unbind(&x->x_obj.ob_pd, x->x_s);
}
static void *folderpanel_new( void)
{
char buf[50];
t_folderpanel *x = (t_folderpanel *)pd_new(folderpanel_class);
sprintf(buf, "d%lx", (t_int)x);
x->x_s = gensym(buf);
pd_bind(&x->x_obj.ob_pd, x->x_s);
outlet_new(&x->x_obj, &s_symbol);
return (x);
}
void folderpanel_setup(void)
{
folderpanel_class = class_new(gensym("folderpanel"),
(t_newmethod)folderpanel_new, (t_method)folderpanel_free,
sizeof(t_folderpanel), 0, 0);
class_addbang(folderpanel_class, folderpanel_bang);
class_addsymbol(folderpanel_class, folderpanel_symbol);
class_addmethod(folderpanel_class, (t_method)folderpanel_callback,
gensym("callback"), A_SYMBOL, 0);
sys_gui("proc tof_folderpanel {target} {\n");
sys_gui(" set path [tk_chooseDirectory] \n");
sys_gui(" if {$path != \"\"} {\n");
sys_gui(" pd [concat $target callback [pdtk_enquote $path]] \\;\n");
sys_gui(" }\n");
sys_gui("}\n");
}
|