aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/flext/source/flattr_ed.cpp
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2004-09-09 04:00:47 +0000
committerThomas Grill <xovo@users.sourceforge.net>2004-09-09 04:00:47 +0000
commit585f6de9b51870f5f8d60e39979eb43fe3d0e3a7 (patch)
tree1e5c8e7e0db045fe9fcbb2817f0b3277842e04e7 /externals/grill/flext/source/flattr_ed.cpp
parentb02b33bcca8f01852bf16ad214e2d509e5e14903 (diff)
""
svn path=/trunk/; revision=2019
Diffstat (limited to 'externals/grill/flext/source/flattr_ed.cpp')
-rw-r--r--externals/grill/flext/source/flattr_ed.cpp178
1 files changed, 94 insertions, 84 deletions
diff --git a/externals/grill/flext/source/flattr_ed.cpp b/externals/grill/flext/source/flattr_ed.cpp
index 8a4b98f5..ff922897 100644
--- a/externals/grill/flext/source/flattr_ed.cpp
+++ b/externals/grill/flext/source/flattr_ed.cpp
@@ -78,72 +78,75 @@ void flext_base::SetAttrEditor(t_classid c)
// generate the script for the property dialog
sys_gui(
- "proc flext_apply {id alen} {\n"
+ "proc flext_escatoms {lst} {\n"
+ "set tmp {}\n"
+ "foreach a $lst {\n"
+ "set a [regsub {\\$} $a \\\\$]\n" // replace $ with \$
+ "set a [regsub {,} $a \\\\,]\n" // replace , with \,
+ "set a [regsub {;} $a \\\\\\;]\n" // replace ; with \;
+ "lappend tmp $a\n"
+ "}\n"
+ "return $tmp\n"
+ "}\n"
+
+ "proc flext_makevalue {id ix} {\n"
// strip "." from the TK id to make a variable name suffix
"set vid [string trimleft $id .]\n"
- // make a list of the attribute values (including save flags)
+ "set var_attr_name [concat [concat var_name_$ix]_$vid ]\n"
+ "set var_attr_init [concat [concat var_init_$ix]_$vid ]\n"
+ "set var_attr_val [concat [concat var_val_$ix]_$vid ]\n"
+ "set var_attr_save [concat [concat var_save_$ix]_$vid ]\n"
+ "set var_attr_type [concat [concat var_type_$ix]_$vid ]\n"
+
+ "global $var_attr_name $var_attr_init $var_attr_val $var_attr_save $var_attr_type\n"
"set lst {}\n"
- "for {set ix 1} {$ix <= $alen} {incr ix} {\n"
- "set var_attr_name [concat [concat var_name_$ix]_$vid ]\n"
- "set var_attr_init [concat [concat var_init_$ix]_$vid ]\n"
- "set var_attr_val [concat [concat var_val_$ix]_$vid ]\n"
- "set var_attr_save [concat [concat var_save_$ix]_$vid ]\n"
- "set var_attr_type [concat [concat var_type_$ix]_$vid ]\n"
-
- "global $var_attr_name $var_attr_init $var_attr_val $var_attr_save $var_attr_type\n"
-
- "if { [expr $$var_attr_type] != 0 } {\n"
- // attribute is puttable
-
- "lappend lst [eval concat $$var_attr_name]\n"
-
- // process current value
- "set tmp [eval concat $$var_attr_val]\n"
- "set len [llength $tmp]\n"
- "if { $len == 1 } {\n"
- // it's an atom
- // if atom starts with $, replace it by # ($ can't be passed by TCL)
- "if { [string index $tmp 0] == \"$\" } {\n"
- "set tmp [string replace $tmp 0 0 #]\n"
- "}\n"
- "lappend lst $tmp\n"
- "} else {\n"
- // it's a list
- "set lst [concat $lst {list} $len $tmp]\n"
- "}\n"
- // process init value
- "set tmp [eval concat $$var_attr_init]\n"
- "set len [llength $tmp]\n"
- "if { $len == 1 } {\n"
- // it's an atom
- // if atom starts with $, replace it by # ($ can't be passed by TCL)
- "if { [string index $tmp 0] == \"$\" } {\n"
- "set tmp [string replace $tmp 0 0 #]\n"
- "}\n"
- "lappend lst $tmp\n"
- "} else {\n"
- // it's a list
- "set lst [concat $lst {list} $len $tmp]\n"
- "}\n"
+ "if { [expr $$var_attr_type] != 0 } {\n"
+ // attribute is puttable
- "lappend lst [eval concat $$var_attr_save]\n"
- "}\n"
+ "lappend lst [eval concat $$var_attr_name]\n"
+
+ // process current value
+ "set tmp [flext_escatoms [eval concat $$var_attr_val]]\n"
+ "set lst [concat $lst [llength $tmp] $tmp]\n"
+
+ // process init value
+ "set tmp [flext_escatoms [eval concat $$var_attr_init]]\n"
+ "set lst [concat $lst [llength $tmp] $tmp]\n"
+
+ "lappend lst [eval concat $$var_attr_save]\n"
"}\n"
- "set cmd [concat $id attributedialog $lst \\;]\n"
- "pd $cmd\n"
+ // return list
+ "return $lst\n"
+ "}\n"
+
+ "proc flext_apply {id ix} {\n"
+ "set lst [flext_makevalue $id $ix]\n"
+ "set lst [eval concat $lst]\n" // remove curly braces from character escaping
+ "pd [concat $id attributedialog $lst \\;]\n"
+ "}\n"
+
+ "proc flext_applyall {id alen} {\n"
+ // make a list of the attribute values (including save flags)
+
+ "set lst {}\n"
+ "for {set ix 1} {$ix <= $alen} {incr ix} {\n"
+ "set lst [concat $lst [flext_makevalue $id $ix]]\n"
+ "}\n"
+ "set lst [eval concat $lst]\n" // remove curly braces from character escaping
+
+ "pd [concat $id attributedialog $lst \\;]\n"
"}\n"
"proc flext_cancel {id} {\n"
- "set cmd [concat $id cancel \\;]\n"
- "pd $cmd\n"
+ "pd [concat $id cancel \\;]\n"
"}\n"
"proc flext_ok {id alen} {\n"
- "flext_apply $id $alen\n"
+ "flext_applyall $id $alen\n"
"flext_cancel $id\n"
"}\n"
@@ -181,7 +184,11 @@ void flext_base::SetAttrEditor(t_classid c)
"proc flext_textcopy {id idtxt var} {\n"
"global $var\n"
- "set $var [eval $idtxt get 0.0 end]\n"
+ "set txt [eval $idtxt get 0.0 end]\n"
+ // strip newline characters
+ "set tmp {}\n"
+ "foreach t $txt { lappend tmp [string trim $t] }\n"
+ "set $var $tmp\n"
"destroy $id\n"
"}\n"
@@ -200,7 +207,15 @@ void flext_base::SetAttrEditor(t_classid c)
"pack $id.w.scroll -side right -fill y\n"
"pack $id.w.text -expand yes -fill both\n"
- "$id.w.text insert 0.0 [expr $$var]\n"
+ // insert text with newlines
+ "set txt [split [expr $$var] ,]\n"
+ "set lines [llength $txt]\n"
+ "for {set ix 0} {$ix < ($lines-1)} {incr ix} {\n"
+ "$id.w.text insert end [string trim [lindex $txt $ix] ]\n"
+ "$id.w.text insert end \" ,\\n\"\n"
+ "}\n"
+ "$id.w.text insert end [string trim [lindex $txt end] ]\n"
+
"$id.w.text mark set insert 0.0\n"
"if { $edit != 0 } then {\n"
@@ -229,7 +244,8 @@ void flext_base::SetAttrEditor(t_classid c)
"grid columnconfigure $id 0 -weight 1\n" // label
"grid columnconfigure $id {1 4} -weight 3\n" // value entry
"grid columnconfigure $id {2 3} -weight 0\n" // copy buttons
- "grid columnconfigure $id {5 6 7} -weight 0\n" // radio buttons
+ "grid columnconfigure $id 5 -weight 1\n" // apply button
+ "grid columnconfigure $id {6 7 8} -weight 0\n" // radio buttons
// "grid rowconfigure $id {0 1 2} -weight 0\n"
@@ -238,6 +254,7 @@ void flext_base::SetAttrEditor(t_classid c)
"label $id.init -text {initial value} -height 2 -font {Helvetica 9 bold}\n"
"label $id.copy -text {copy} -height 2 -font {Helvetica 9 bold}\n"
"label $id.val -text {current value} -height 2 -font {Helvetica 9 bold}\n"
+ "label $id.apply -text {} -height 2 -font {Helvetica 9 bold}\n" // why must this be empty?
"foreach {i txt} {0 {don't\rsave} 1 {do\rinit} 2 {always\rsave} } {\n"
"label $id.b$i -text $txt -height 2 -font {Helvetica 9 bold}\n"
"}\n"
@@ -247,13 +264,14 @@ void flext_base::SetAttrEditor(t_classid c)
"grid config $id.init -column 1 -row $row \n"
"grid config $id.copy -column 2 -columnspan 2 -row $row \n"
"grid config $id.val -column 4 -row $row \n"
- "foreach i {0 1 2} { grid config $id.b$i -column [expr $i + 5] -row $row }\n"
+ "grid config $id.apply -column 5 -row $row \n"
+ "foreach i {0 1 2} { grid config $id.b$i -column [expr $i + 6] -row $row }\n"
// "grid config $id.options -column 3 -row 0 \n"
"incr row\n"
// Separator
"frame $id.sep -relief ridge -bd 1 -height 2\n"
- "grid config $id.sep -column 0 -columnspan 8 -row $row -pady 2 -sticky {snew}\n"
+ "grid config $id.sep -column 0 -columnspan 9 -row $row -pady 2 -sticky {snew}\n"
"incr row\n"
"set ix 1\n"
@@ -322,18 +340,23 @@ void flext_base::SetAttrEditor(t_classid c)
"grid config $id.init-$ix -column 1 -row $row -padx 5 -sticky {ew}\n"
"grid config $id.val-$ix -column 4 -row $row -padx 5 -sticky {ew}\n"
+ // copy buttons
"button $id.b2i-$ix -text {<-} -height 1 -command \" flext_copyval $var_attr_init $var_attr_val \"\n"
"grid config $id.b2i-$ix -column 2 -row $row -sticky {ew}\n"
"button $id.b2c-$ix -text {->} -height 1 -command \" flext_copyval $var_attr_val $var_attr_init \"\n"
"grid config $id.b2c-$ix -column 3 -row $row -sticky {ew}\n"
+ // apply button
+ "button $id.apply-$ix -text {Apply} -height 1 -command \" flext_apply $id $ix \"\n"
+ "grid config $id.apply-$ix -column 5 -row $row -sticky {ew}\n"
+
// "tk_optionMenu $id.opt-$ix $var_attr_save {don't save} {initialize} {always save}\n"
// "grid config $id.opt-$ix -column 5 -row $ix \n"
// radiobuttons
"foreach {i c} {0 black 1 blue 2 red} {\n"
"radiobutton $id.b$i-$ix -value $i -foreground $c -variable $var_attr_save \n"
- "grid config $id.b$i-$ix -column [expr $i + 5] -row $row \n"
+ "grid config $id.b$i-$ix -column [expr $i + 6] -row $row \n"
"}\n"
"} else {\n"
// attribute is gettable only
@@ -361,7 +384,7 @@ void flext_base::SetAttrEditor(t_classid c)
"grid config $id.val-$ix -column 4 -row $row -padx 5 -sticky {ew}\n"
"label $id.readonly-$ix -text \"read-only\"\n"
- "grid config $id.readonly-$ix -column 5 -columnspan 3 -row $row -padx 5 -sticky {ew}\n"
+ "grid config $id.readonly-$ix -column 6 -columnspan 3 -row $row -padx 5 -sticky {ew}\n"
"}\n"
// increase counter
@@ -372,16 +395,16 @@ void flext_base::SetAttrEditor(t_classid c)
// Separator
"frame $id.sep2 -relief ridge -bd 1 -height 2\n"
// "grid rowconfigure $id $row -weight 0\n"
- "grid config $id.sep2 -column 0 -columnspan 8 -row $row -pady 5 -sticky {snew}\n"
+ "grid config $id.sep2 -column 0 -columnspan 9 -row $row -pady 5 -sticky {snew}\n"
"incr row\n"
// Buttons
"frame $id.buttonframe\n"
"pack $id.buttonframe -side bottom -fill x\n"
- "button $id.buttonframe.cancel -text {Cancel} -width 20 -command \" flext_cancel $id \"\n"
- "button $id.buttonframe.apply -text {Apply} -width 20 -command \" flext_apply $id $alen \"\n"
- "button $id.buttonframe.ok -text {OK} -width 20 -command \" flext_ok $id $alen \"\n"
+ "button $id.buttonframe.cancel -text {Leave} -width 20 -command \" flext_cancel $id \"\n"
+ "button $id.buttonframe.apply -text {Apply all} -width 20 -command \" flext_applyall $id $alen \"\n"
+ "button $id.buttonframe.ok -text {Apply & Leave} -width 20 -command \" flext_ok $id $alen \"\n"
"button $id.buttonframe.help -text {Help} -width 10 -command \" flext_help $id \"\n"
"pack $id.buttonframe.cancel -side left -expand 1\n"
@@ -390,12 +413,12 @@ void flext_base::SetAttrEditor(t_classid c)
"pack $id.buttonframe.help -side left -expand 1\n"
// "grid rowconfigure $id $row -weight 0\n"
- "grid config $id.buttonframe -column 0 -columnspan 8 -row $row -pady 5 -sticky {ew}\n"
+ "grid config $id.buttonframe -column 0 -columnspan 9 -row $row -pady 5 -sticky {ew}\n"
// Key bindings
"bind $id {<KeyPress-Escape>} \" flext_cancel $id \"\n"
"bind $id {<KeyPress-Return>} \" flext_ok $id $alen \"\n"
- "bind $id {<Shift-KeyPress-Return>} \" flext_apply $id $alen \"\n"
+ "bind $id {<Shift-KeyPress-Return>} \" flext_applyall $id $alen \"\n"
"}\n"
);
}
@@ -621,10 +644,7 @@ void flext_base::cb_GfxSave(t_gobj *c, t_binbuf *b)
bool flext_base::cb_AttrDialog(flext_base *th,int argc,const t_atom *argv)
{
- int i = 0;
- if(IsSymbol(argv[i]) && GetSymbol(argv[i]) == sym_list) ++i;
-
- for(; i < argc; ) {
+ for(int i = 0; i < argc; ) {
FLEXT_ASSERT(IsSymbol(argv[i]));
// get name
@@ -632,27 +652,17 @@ bool flext_base::cb_AttrDialog(flext_base *th,int argc,const t_atom *argv)
i++;
// get current value
+ FLEXT_ASSERT(CanbeInt(argv[i]));
int ccnt,coffs;
- if(IsSymbol(argv[i]) && GetSymbol(argv[i]) == sym_list) {
- i++;
- FLEXT_ASSERT(CanbeInt(argv[i]));
- ccnt = GetAInt(argv[i]);
- coffs = ++i;
- }
- else
- coffs = i,ccnt = 1;
+ ccnt = GetAInt(argv[i]);
+ coffs = ++i;
i += ccnt;
// get init value
+ FLEXT_ASSERT(CanbeInt(argv[i]));
int icnt,ioffs;
- if(IsSymbol(argv[i]) && GetSymbol(argv[i]) == sym_list) {
- i++;
- FLEXT_ASSERT(CanbeInt(argv[i]));
- icnt = GetAInt(argv[i]);
- ioffs = ++i;
- }
- else
- ioffs = i,icnt = 1;
+ icnt = GetAInt(argv[i]);
+ ioffs = ++i;
i += icnt;
FLEXT_ASSERT(i < argc);