// -*- ASCII:EDT -*- // recentDirectories.edt // keeps a list of recently opened directories // (schlicht 20020829) ///////////////////////// //============================================================================= // This macro keeps a list of recently opened directories. It can be used in // addition to the "File | Open" command, or can even replace it. // It requires at least WinEdt 5.3: Requires(20020223); //============================================================================= // INSTALLATION //===================================================== // * Save this file as %b\Macros\recentDirectories.edt. // * Add a new menu entry to the File or the Document menu (or even replace // the "&Open" Command in the File menu) with a "Macro" that is defined as: // [Exe("%b\Macros\recentDirectories.edt");] // (Note: With WinEdt 5.3 and newer, the existing "Command" item will be // automatically converted into a "Macro" item, as long as you don't forget // the square brackets.) // * If you want the directories of all opened files to be automatically added // to the history (strongly recommended), add the following line to the file // %b\Macros\MDIOpen.edt (if you are using a WinEdt Build before 20040504), // resp. to // %b\Local\MDIOpen.edt (if you are using WinEdt Build 20040504) // or to // %b\Local\Events\MDIOpen.edt (if you are using WinEdt Build 20041213 or newer) -- // (if the file %b\Local[\Events]\MDIOpen.edt does not exist, you have to create it) // ------------------------------------------------------------------------------ // Assign("recentDir","add");Exe("%b\Macros\recentDirectories.edt"); // ------------------------------------------------------------------------------ // If you don't do this, directories will only be appended to the history, when // you run this macro. // * Adjust the options below. //============================================================================= // Apart from using this macro as an addition or replacement for "Open...", // you can also use it in the same way for "Save As..." (or any other Command // for which it makes sense). // To do so, define the Macro in the menu entry that calls it as // [Assign("recentDir","Save As..."); Exe("%b\Macros\recentDirectories.edt");] // or // [Assign("recentDir","Open Project..."); Exe("%b\Macros\recentDirectories.edt");] // etc. //============================================================================= //============================================================================= // OPTIONS // ======================================================== // 1. Number of directories to remember: // // -------------------------------------------------------- Assign("recentDir:History","10"); // ======================================================== // ======================================================== // 2. Which path to add to the history? // // %!P = current path // // %p = current file's path // // -------------------------------------------------------- Assign("recentDir:Current","%!P"); //Assign("recentDir:Current","%p"); // ======================================================== // ======================================================== // 3. If you're using multiple projects, you might want // // to have different directory histories for them, too: // // -------------------------------------------------------- Assign("recentDir:Project","%!n"); // different histories for different projects //Assign("recentDir:Project",""); // share one history between projects // ======================================================== // ======================================================== // 4. Here, you can set up to 5 directories which should // // always be present in the list, no matter whether you // // have actually opened a file from them: // // -------------------------------------------------------- Assign("recentDir:Home","%@('HOMEDRIVE');%@('HOMEPATH');"); //Assign("recentDir:Home1","%B\Doc"); //Assign("recentDir:Home2","%$('TeX-Root');\doc"); //Assign("recentDir:Home3","%$('TeX-Local');\doc"); //Assign("recentDir:Home4","another\one"); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // You could also use different Home Directories for // // different projects: Uncomment the next block and // // fill in the blanks: // // -------------------------------------------------------- //// ,- project name ,- project home directory //IfStr("%!n","WinEdt","=","Assign('recentDir:Home1','your\home\directory');"); //IfStr("%!n","", "=","Assign('recentDir:Home1','');"); //// ... etc. // ======================================================== // ======================================================== // 5. Uncomment the next line if you want the // // directories to be sorted alphabetically. Otherwise // // they will be sorted chronologically. // // (Note that the first directory in the list -- i.e., // // the current directory -- will be excluded from // // sorting.) // // -------------------------------------------------------- //Assign("recentDir:Sort","alphabetical"); // ============================================================================= // End Of Options // ============================================================================= // Preparation: // temporarily save the registers, to restore them on exit Assign("tmp0","%!0"); Assign("tmp1","%!1"); Assign("tmp2","%!2"); Assign("tmp3","%!3"); Assign("tmp4","%!4"); Assign("recentDir:Exit",!`> LetReg(0,"");> Loop(!"> Release('recentDir:Home%!0');> IfNum(%!0,4,'=','Stop;','LetRegNum(0,%!0+1);');> ");> LetReg(0,"%$('tmp0');");> LetReg(1,"%$('tmp1');");> LetReg(2,"%$('tmp2');");> LetReg(3,"%$('tmp3');");> LetReg(4,"%$('tmp4');");> Release("recentDir");> `); // Default action (CMD) is "Open...": IfStr("%$('recentDir');","","=",> "Assign('recentDir:Action','Open...');",> "Assign('recentDir:Action','%$(|recentDir|);');"); IfStr("%$('recentDir:Sort');","alphabetical","=",!`> SortLines("%$('%$(|recentDir:Project|);recentDirectories');",1101,0,0);> Assign("%$('recentDir:Project');recentDirectories","%!0");> `); // check whether maximum number of directories reached, // and whether the current and the home directory are already included IfStr("%$('recentDir:Current');","","=","Assign('recentDir:Current','%!P');"); LetRegNum(2,-1); LetRegNum(3,5); LetReg(4,""); Loop(!`> Assign("recentDir:nohome%!4","nohome");> IfFileExists("%$('recentDir:Home%!4');\","","Release('recentDir:Home%!4');");> IfStr("%$('recentDir:Home%!4');","%$('recentDir:Current');","=","Release('recentDir:Home%!4');");> IfStr("%$('recentDir:Home%!4');","","=","Release('recentDir:nohome%!4');LetRegNum(3,%!3-1);");> IfNum(%!4,4,"=","Stop;","LetRegNum(4,%!4+1);");> `); LetReg(0,"%$('%$(|recentDir:Project|);recentDirectories');"); Loop(!`> SetOK(1);> FindInString("%!0","",1,2,1001,%!2);> IfOK(!"> IfNum(%!3+2,'%$(|recentDir:History|);','>',> !'ExtractByIndex(0,''%!0'',0,%!1-1);> Stop;',> !'GetTag(0,4);> LetRegNum(3,%!3+1);> IfStr(''%!4'',''%$(|recentDir:Current|);'',''='',> !''ReplaceInString(|%!0|,||,%!1,%!2,0,0);> LetRegNum(2,|%!2-(%!2-%!1)|);> LetRegNum(3,%!3-1);''> );> LetReg(1,'''');> Loop(!*> IfStr(''%!4'',''%$(|recentDir:Home%!1|);'',''='',> !''LetRegNum(3,%!3-1);> Release(|recentDir:nohome%!1|);''> );> IfNum(%!1,4,''='',''Stop;'',''LetRegNum(1,%!1+1);'');> *);> '> );",> "Stop;"> );> `); // add current directory: Assign("%$(|recentDir:Project|);recentDirectories","/%$('recentDir:Current');/%\%!0"); // add home directory: LetReg(1,''); Loop(!`> IfStr('%$(|recentDir:nohome%!1|);','nohome','=',!'> Assign(''%$(|recentDir:Project|);recentDirectories'',> ''%$(|%$(*recentDir:Project*);recentDirectories|);/%$(|recentDir:Home%!1|);/%\'');> ');> IfNum(%!1,5,'=','Stop;','LetRegNum(1,%!1+1);');> `);> // exit if called by MDIOpen: IfStr("%$('recentDir');","add","=",!"Do('%$(|recentDir:Exit|);');Exit;"); // show history Interface("Recent directories -- %$('recentDir:Action');"); LetRegNum(2,0); LetRegNum(3,0); Loop(!`> SetOK(1);> FindInString("%$('%$(|recentDir:Project|);recentDirectories');","",1,2,1001,%!2);> IfOK(!"> GetTag(0,0);> IfFileExists('%!0\',!'> // trim to fit: GetLength(1,''%!0'');> IfNum(%!1,57,''>'',!''SetOK(1);> FindInString(""%!0"",""\"",4,4,1000,27);> IfNum(%!4,""%!1-24"",""<"",""LetReg(4,|..\..|);"",""LetReg(4,|...|);"");> ReplaceInString(""%!0"",""%!4"",27,%!1-25,0,1);'',''LetReg(1,""%!0"");'');> Item(''%!1'',''SetFolder(""%!0"");'');> LetRegNum(3,%!3+1);> ');> ","Stop;");> `); LetRegNum(4,0); // delete a directory from history: Item("=== Forget a Directory ===",!`> Interface("Forget a Directory");> FindInString("%$('%$(|recentDir:Project|);recentDirectories');","/%$('recentDir:Current');/",1,2,0);> Loop(!"SetOK(1);> FindInString('%$(|%$(*recentDir:Project*);recentDirectories|);','',1,2,1001,%!2);> IfOK(!'GetTag(0,0);> GetLength(1,|%!0|);> IfNum(%!1,57,|>|,!|SetOK(1);> FindInString(""%!0"",""\"",3,3,1000,27);> IfNum(%!3,""%!1-24"",""<"",""LetReg(3,||..\..||);"",""LetReg(3,||...||);"");> ReplaceInString(""%!0"",""%!3"",27,%!1-25,0,1);|,|LetReg(1,""%!0"");|);> LetReg(3,||);> Loop(!|> IfStr(''%!0'',''%$(*recentDir:Home%!3*);'',''='',''LetReg(1,||||);'');> IfNum(%!3,4,''='',''Stop;'',''LetRegNum(3,%!3+1);'');> |);> IfStr(''%!1'','''',''<>'',!''> Item(|%!1|,|LetReg(0,""%!0"");|);> LetRegNum(4,%!4+1);''> );',> 'Stop;');");> IfNum(%!4,0,"=",> !"Prompt('I cannot forget any directories!',2,0);> Exe('%b\Macros\recentDirectories.edt');> Exit;",> !"ShowList(1,1,!'Do(''%?'');',!'Do(''%$(|recentDir:Exit|);'');Exit;',1);");> FindInString("%$('%$(|recentDir:Project|);recentDirectories');","/%!0/",1,2,0);> IfOK(!"ReplaceInString('%$(|%$(*recentDir:Project*);recentDirectories|);','',%!1,%!2+2,0,0);> Assign('%$(|recentDir:Project|);recentDirectories','%!0');");> Exe("%b\Macros\recentDirectories.edt");> Exit;> `); //// Not enabled: //IfStr("%$('recentDir:Sort');","alphabetical","<>",!`> // Item("=== Sort alphabetically ===",!"> // Assign('recentDir:temp','%$(|%$(*recentDir:Project*);recentDirectories|);');> // Assign('recentDir:Sort','alphabetical');> // Exe('%b\Macros\recentDirectories.edt');> // Release('recentDir:Sort');> // Assign('%$(|recentDir:Project|);recentDirectories','%$(|recentDir:temp|);');> // Exit;> // ");> //`); IfNum(%!3,1,">",!"ShowList(1,1,!'Do(''%?'');',!'Do(''%$(|recentDir:Exit|);'');Exit;',1);"); // we have to release the variables *before* the Open/Save As.. dialog // in case the user cancels it: Do("%$('recentDir:Exit');"); CMD("%$('recentDir:Action');"); End; ============================ R Schlicht ============================ $Id: recentDirectories.edt,v 1.10 2004-12-24 04:11:30+01 schlicht Exp schlicht $