// -*- ASCII:EDT -*- // makeMUI.edt // (schlicht 20030714) ///////////////////////// // -------------------------------------------------------------------------------- // The MUI plug-in (http://www.winedt.org/Plugins/mui.php) is a great application // to generate user friendly dialogs. // However, to the macro writer, it is less friendly. If you've once tried it, you // will know that writing the underlying macro code is tiresome and error-prone. // This macro tool facilitates macro programming for the MUI plug-in. // // It will generate all the code you would otherwise write yourself -- including // register releases before, and the framework for evaluating the user's choices // after running the MUI plug-in. // // Find further documentation at the end of the file. // -------------------------------------------------------------------------------- Requires(20030429); // WinEdt 5.4 // This macro might also work with 5.3. I simply don't know. You can try by commenting // the previous line. // ------- // // OPTIONS // // ------- // // set your favourite delimiters here: Assign("makeMUIdelimiter1","`"); // outer Assign("makeMUIdelimiter2",""""); // inner // end lines with the concatenation character ">" ? Assign("makeMUIconcat",""); //Assign("makeMUIconcat",">"); // ================================================================================ // these are MUI's limits: Assign("makeMUIEditBoxLimit","9"); Assign("makeMUICheckBoxLimit","9"); Assign("makeMUIComboBoxLimit","9"); Assign("makeMUIEditBrowseLimit","9"); Assign("makeMUIRadioButtonLimit","5"); // preparation: Assign("makeMUIEditBox","0") Assign("makeMUICheckBox","0"); Assign("makeMUIComboBox","0"); Assign("makeMUIRadioButton","0"); Assign("makeMUIEditBrowse","0"); Release("makeMUIExe"); Release("makeMUIfile"); IfSel(1,"<>",> "Prompt('Select the whole file?',2,2,> 'CMD(''Go To Beginning Of File'');Mark(0);CMD(''Select All'');',> 'Exit;');",> "Mark(0);"); GetSel(0,0); // get title, concatenate options and determine pre-selected option: Assign('makeMUIOption',!`> LetRegNum(7,0);> LetRegNum(8,0);> FormatString("%!1",3,"trimboth");> Assign("makeMUI%$('makeMUItype');%$('makeMUI%$(|makeMUItype|);');title","%!3");> LetReg(1,"");> Loop(!"> SetOK(1);> LetRegNum(6,%!2);> FindInString('%!0','<\(~{>}*\)>',5,2,1001,%!2);> IfOK(!'> GetTag(0,4);> ExtractByIndex(5,""%!4"",0,0);> IfStr(""%!5"","" "",""="",!""> LetRegNum(7,%!7+1);> FormatString(|%!4|,4,|trimboth|);> ExtractByIndex(5,|%!4|,0,0);> IfStr(|%!5|,|!|,|=|,!|ReplaceInString(''%!4'','''',0,0,0,4);LetRegNum(8,%!7);|);> FormatString(|%!4|,4,|trimboth|);> LetReg(1,|%!1%!4|||);> Assign(|makeMUI%$(*makeMUItype*);%$(*makeMUI%$(:makeMUItype:);*);%!7value|,|%!4|);> "",!""LetRegNum(2,%!6);Stop;"");> ','Stop;');> ");> GetLength(6,"%!1");ReplaceInString("%!1","",%!6-1,%!6,0,1);> `); LetRegNum(2,0); LetReg(9,""); Loop(!`> SetOK(1);> FindInString("%!0%\","<\(~{>}*\)>",1,2,1001,%!2);> IfOK(!"> GetTag(0,1);> FormatString('%!1',1,'trimboth');> ExtractByIndex(3,'%!1',0,1);> GetLength(4,'%!3');> IfNum(%!4,1,'=','LetReg(3,''%!3 '');');> // set concatenation IfStr('%!3','>>','=',!'> Assign(""makeMUIconcat"","">"");> LetReg(1,"""");> ');> // delimiters IfStr('%!3','D1','=',!'> ReplaceInString(""%!1"","""",0,1,0,1);> FormatString(""%!1"",1,""trimboth"");> Assign(""makeMUIdelimiter1"",""%!1"");> LetReg(1,"""");> ');> IfStr('%!3','D2','=',!'> ReplaceInString(""%!1"","""",0,1,0,1);> FormatString(""%!1"",1,""trimboth"");> Assign(""makeMUIdelimiter2"",""%!1"");> LetReg(1,"""");> ');> // File IfStr('%!3','F ','=',!'> ReplaceInString(""%!1"","""",0,1,0,1);> FormatString(""%!1"",1,""trimboth"");> Assign(""makeMUIfile"",""%!1"");> LetReg(1,""OpenOutput(%$(|makeMUIdelimiter1|);%!1%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> ');> // Title IfStr('%!3','T ','=',!'> ReplaceInString(""%!1"","""",0,1,0,1);> FormatString(""%!1"",1,""trimboth"");> LetReg(1,""WrL(%$(|makeMUIdelimiter1|);MUITitle(%$(|makeMUIdelimiter2|);%!1%$(|makeMUIdelimiter2|););%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> ');> // Width IfStr('%!3','W ','=',!'> ReplaceInString(""%!1"","""",0,1,0,1);> FormatString(""%!1"",1,""trimboth"");> LetReg(1,""WrL(%$(|makeMUIdelimiter1|);MUIWidth(%$(|makeMUIdelimiter2|);%!1%$(|makeMUIdelimiter2|););%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> ');> // Generic IfStr('%!3','! ','=',!'> ReplaceInString(""%!1"","""",0,1,0,1);> FormatString(""%!1"",1,""trimboth"");> LetReg(1,""WrL(%$(|makeMUIdelimiter1|);%!1%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> ');> // Label IfStr('%!3','L ','=',!'> ReplaceInString(""%!1"","""",0,1,0,1);> FormatString(""%!1"",1,""trimboth"");> IfStr(""%!1"","""",""="",""LetReg(1,'' '');"");> LetReg(1,""WrL(%$(|makeMUIdelimiter1|);MUILabel(%$(|makeMUIdelimiter2|);%!1%$(|makeMUIdelimiter2|););%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> ');> // EditBox IfStr('%!3','E ','=',!'> LetRegNum(4,""%$(|makeMUIEditBox|);+1"");> Assign(""makeMUIEditBox"",""%!4"");> ReplaceInString(""%!1"","""",0,1,0,1);> FormatString(""%!1"",1,""trimboth"");> ExtractByIndex(4,""%!1"",0,0);> IfStr(""%!4"",""!"",""="",""ReplaceInString(''%!1'','''',0,0,0,1);LetReg(8,'',1'');"",""LetReg(8,'''');"");> FormatString(""%!1"",1,""trimboth"");> LetReg(1,""WrL(%$(|makeMUIdelimiter1|);MUIEditBox(%$(|makeMUIdelimiter2|);%!1%$(|makeMUIdelimiter2|);%!8);%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> ');> // CheckBox IfStr('%!3','X ','=',!'> LetRegNum(4,""%$(|makeMUICheckBox|);+1"");> Assign(""makeMUICheckBox"",""%!4"");> ReplaceInString(""%!1"","""",0,1,0,1);> FormatString(""%!1"",1,""trimboth"");> ExtractByIndex(4,""%!1"",0,0);> IfStr(""%!4"",""!"",""="",""ReplaceInString(''%!1'','''',0,0,0,1);LetReg(8,'',1'');"",""LetReg(8,'''');"");> FormatString(""%!1"",1,""trimboth"");> Assign(""makeMUICheckBox%$(|makeMUICheckBox|);value"",""%!1"");> LetReg(1,""WrL(%$(|makeMUIdelimiter1|);MUICheckBox(%$(|makeMUIdelimiter2|);%!1%$(|makeMUIdelimiter2|);%!8);%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> ');> // ComboBox IfStr('%!3','C ','=',!'> LetRegNum(4,""%$(|makeMUIComboBox|);+1"");> Assign(""makeMUIComboBox"",""%!4"");> Assign(""makeMUItype"",""ComboBox"");> ReplaceInString(""%!1"","""",0,1,0,1);> Do(""%$(|makeMUIOption|);"");> FormatString(""%!1"",1,""trimboth"");> IfStr(""%!3"","""",""<>"",!""> LetReg(3,''WrL(%$(|makeMUIdelimiter1|);MUILabel(%$(|makeMUIdelimiter2|);%!3%$(|makeMUIdelimiter2|););%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);%\'');"",""LetReg(3,'''');"");> LetReg(1,""%!3WrL(%$(|makeMUIdelimiter1|);MUIComboBox(%$(|makeMUIdelimiter2|);%!1%$(|makeMUIdelimiter2|);,%!8);%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> ');> // RadioButton IfStr('%!3','R ','=',!'> LetRegNum(4,""%$(|makeMUIRadioButton|);+1"");> Assign(""makeMUIRadioButton"",""%!4"");> Assign(""makeMUItype"",""RadioButton"");> ReplaceInString(""%!1"","""",0,1,0,1);> Do(""%$(|makeMUIOption|);"");> FormatString(""%!1"",1,""trimboth"");> LetReg(1,""WrL(%$(|makeMUIdelimiter1|);MUIRadioButton(%$(|makeMUIdelimiter2|);%!1%$(|makeMUIdelimiter2|);,%!8,%$(|makeMUIdelimiter2|);%!3%$(|makeMUIdelimiter2|););%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> ');> // MUIEditBrowseFile IfStr('%!3','BF','=',!'> LetRegNum(4,""%$(|makeMUIEditBrowse|);+1"");> Assign(""makeMUIEditBrowse"",""%!4"");> ReplaceInString(""%!1"","""",0,1,0,1);> FormatString(""%!1"",1,""trimboth"");> LetReg(1,""WrL(%$(|makeMUIdelimiter1|);MUIEditBrowseFile(%$(|makeMUIdelimiter2|);%!1%$(|makeMUIdelimiter2|);,%$(|makeMUIdelimiter2|);|All files|*.*%$(|makeMUIdelimiter2|);,0/1);%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> ');> // MUIEditBrowseFolder IfStr('%!3','BD','=',!'> LetRegNum(4,""%$(|makeMUIEditBrowse|);+1"");> Assign(""makeMUIEditBrowse"",""%!4"");> ReplaceInString(""%!1"","""",0,1,0,1);> FormatString(""%!1"",1,""trimboth"");> LetReg(1,""WrL(%$(|makeMUIdelimiter1|);MUIEditBrowseFolder(%$(|makeMUIdelimiter2|);%!1%$(|makeMUIdelimiter2|);,00/11);%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> ');> // The End IfStr('%!3','--','=',!'> LetReg(1,""CloseOutput;%$(|makeMUIconcat|);%\WinExe(%$(|makeMUIdelimiter1|);%$(|makeMUIdelimiter1|);,%$(|makeMUIdelimiter1|);%%$(%$(|makeMUIdelimiter2|);MUIexe%$(|makeMUIdelimiter2|);); %$(|makeMUIdelimiter2|);%$(|makeMUIfile|);%$(|makeMUIdelimiter2|);%$(|makeMUIdelimiter1|);,%$(|makeMUIdelimiter1|);%%p%$(|makeMUIdelimiter1|);,%$(|makeMUIdelimiter1|);%$(|makeMUIdelimiter1|);,000100);%$(|makeMUIconcat|);"");> Assign(""makeMUIExe"",""yes"");> ReplaceInString(""%!0"","""",0,%!2,0);> Assign(""makeMUIrest"",""%!0"");> Stop;> ');> IfStr('%!1','','<>',!'LetReg(9,''%!9%!1%\'');');> ","Stop;");> `) // after running MUI Assign("makeMUIaux",!`> LetReg(8,"");> LetRegNum(0,1);> Do("LetRegNum(1,%$('makeMUI%!7'););");> Do("LetRegNum(2,%$('makeMUI%!7Limit'););");> Loop(!"> IfNum(%!0,%!2,'>',!'LetReg(8,''%!8/%_/ => There are more than %!2 %!7 fields!!!%\'');LetRegNum(1,-1);');> IfNum(%!0,%!1,'>','Stop;',> !'LetReg(8,''%!8Release(%$(|makeMUIdelimiter1|);MUI%!7%!0%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);%\'');> IfStr(''%$(|makeMUIIfClause|);'',''normal'',''='',!''> LetRegNum(5,1);> IfStr(""%$(|makeMUI%!7%!0title|);"","""",""="",!""LetReg(3,|%!3%\/%_/ => MUI%!7%!0|);"",> !""LetReg(3,|%!3%\/%_/ => %$(*makeMUI%!7%!0title*);|);"");> Loop(!``> LetReg(3,""%!3%\IfStr(%$(|makeMUIdelimiter1|);%%$(%$(|makeMUIdelimiter2|);MUI%!7%!0%$(|makeMUIdelimiter2|););%$(|makeMUIdelimiter1|);,> %$(|makeMUIdelimiter1|);%$(|makeMUI%!7%!0%!5value|);%$(|makeMUIdelimiter1|);,%$(|makeMUIdelimiter1|);=%$(|makeMUIdelimiter1|);,>%\> %$(|makeMUIdelimiter1|);%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> Release(""makeMUI%!7%!0%!5value"");> LetRegNum(5,%!5+1);> IfStr(""%$(|makeMUI%!7%!0%!5value|);"","""",""="",""Stop;"","""");> ``);> '');> IfStr(''%$(|makeMUIIfClause|);'',''numeric'',''='',!''> LetReg(3,""%!3%\IfNum(%$(|makeMUIdelimiter1|);%%$(%$(|makeMUIdelimiter2|);MUI%!7%!0%$(|makeMUIdelimiter2|););%$(|makeMUIdelimiter1|);,1,> %$(|makeMUIdelimiter1|);=%$(|makeMUIdelimiter1|);, /%_/ => %$(|makeMUI%!7%!0value|); <>%\ %$(|makeMUIdelimiter1|);%$(|makeMUIdelimiter1|);,%$(|makeMUIdelimiter1|);%$(|makeMUIdelimiter1|););%$(|makeMUIconcat|);"");> Release(""makeMUI%!7%!0value"");> '');> IfStr(''%$(|makeMUIIfClause|);'',''none'',''='',!''> Release(""makeMUI%!7%!0%!5value"");> LetReg(3,""%!3%\/%_/ => %%$(|MUI%!7%!0|);%\"");'');> ');> LetRegNum(0,%!0+1);> ");> LetReg(9,"%!8%!9");> LetReg(6,"%!6%!3");> `); // only execute this if "--" was found: IfStr("%$('makeMUIExe');","yes","=",!`> LetReg(3,"");> LetReg(6,"");> Assign('makeMUIIfClause','normal');> LetReg(7,"ComboBox");> Do("%$('makeMUIaux');");> LetReg(7,"RadioButton");> Do("%$('makeMUIaux');");> Assign('makeMUIIfClause','numeric');> LetReg(7,"CheckBox");> Do("%$('makeMUIaux');");> Assign('makeMUIIfClause','none');> LetReg(7,"EditBox");> Do("%$('makeMUIaux');");> LetReg(7,"EditBrowse");> Do("%$('makeMUIaux');");> IfStr("%$('makeMUIfile');","","=","Assign('makeMUIfile','/%_/ => WARNING: No output file specified!%\');","Release('makeMUIfile');");> LetReg(9,"%$('makeMUIfile');IfFileExists(""%%b\Plugins\MUI\mui.exe"",""Assign('MUIexe','%%b\Plugins\MUI\mui.exe');"",>%\> ""IfFileExists('%%B\Plugins\MUI\mui.exe','Assign(''MUIexe'',''%%B\Plugins\MUI\mui.exe'');',>%\> 'Prompt(''You do not have the MUI plug-in installed!%%\Please get it from www.winedt.org.'',3,1);Exit;');"");%$(|makeMUIconcat|);%\> Assign(""MUIOK"",""0"");%$(|makeMUIconcat|);%\%!9IfNum(""%%$('MUIOK');"",0,""="",""Exit;"");%$(|makeMUIconcat|);%!3%\");> `); BeginGroup; SetTracking(0); Ins("%!9"); Ins("%$('makeMUIrest');"); LetRegNum(1,%l); Goto(0); CMD("Next Bullet"); IfNum(%l,%!1,">","Goto(0);"); SetTracking(1); Refresh; EndGroup; End; // -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ You'd write something like the following: ============================================================= // This is the output file, i.e. the MUI input _F_ile: F %b\Macros\macro\makeMUItest.mui // This is the caption (_T_itle) of the MUI window: T Global Options: // This is its _W_idth: W 300 // First, we write a _L_abel: L These are the class options: // This is a _C_ombo box: C Papersize letterpaper (11 x 8.5 inches) legalpaper (14 x 8.5 inches) a3paper (420 x 297 mm) !a4paper (297 x 210 mm) a5paper (210 x 148 mm) // a _R_adio button: R Orientation !portrait landscape // a _X_eck box: X Draft // Finally, "--" marks the end of the MUI block. // (Outcommented for didactic reasons) //-- ============================================================== To get an idea of how it works, I suggest you now select the above block and execute the current macro. Done? OK, so far, so simple, you might say. Now undo it, then uncomment the last line, so that it reads "--", select the block again, and re-run the current macro. ... Quite different, eh? You've just seen the real advantage of this macro. The following abbreviations are defined: ---------------------------------------- F FILE to which the macro will write the MUI input T CAPTION of the MUI dialog W <width> WIDTH of the MUI dialog L <text> LABEL L LABEL, empty (resulting in some more space in the MUI dialog) E <text> EDIT BOX (<text> is optional) E !<text> EDIT BOX, disabled (<text> is optional) X <option> CHECK BOX, not checked X !<option> CHECK BOX, checked C <title> COMBO BOX (<title> is optional) <option> Put each option on a line of its own (preceded by at least one space). !<option> If you precede an option with "!", it will be pre-selected in MUI. R <title> RADIO BUTTON (<title> is optional) !<option> same as COMBO BOX <option> BF <file> FILE BROWSER (<file> is optional) BD <directory> DIRECTORY BROWSER (<directory> is optional) There are more arguments to these two macros, which you will have to specify afterwards (the macro will insert bullets in their place). ! <MUI macro> For all other, unsupported MUI macros. This will simply surround the current string with WrL(" and "); -- End of MUI dialog code This will also generate the preparatory code, and the framework for making sense of the user's options SETTINGS: >> Append all lines with the concatenation character ">" (e.g., when you use the generated code inside a loop) D1 <delimiter> Set outer delimiter (all WinEdt delimiters: "'`|*: ) D2 <delimiter> Set inner delimiter (all MUI delimiters: `'" ) These settings must come before all the rest, of course. You can adjust them at the beginning of this macro, too. ---------------------------------------- Note that all of these abbreviations have to start at the beginning of the line. As you might have noticed when running the example, empty lines will be removed. All other lines (including comments) will be copied verbatim. You can only generate macro code for one MUI dialog at a time. I hope this macro facilitates the creation of MUI macro code, so that more of it can be written, and this great little application can even more be proved to be beneficent for the WinEdt community. // -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ R Schlicht <w.m.l@gmx.net> $Id: makeMUI.edt,v 1.0 2003-07-16 02:50:53+02 schlicht Exp schlicht $