var XLog = 3; // 3 = warnings+, 4 = info+, 5 = normal+ ("+" means "and more severe") var LAYOUT_NAME = "Event.Generic.AutoSaveLayout"; //############################################################################## // This addin automatically saves current layout in between, not only when DO // was exited normally. This allows to get back to work after blackout, windows, // computer crash or if DO itself ran into problems and could not be exited // properly (app crash/hang, out of memory situation, bad extension-dll whatever). // // To get the auto saved layout to be loaded automatically when DO restarts, // configure "Open a saved lister layout [LAYOUT_NAME]" in the following prefs // sections. You can also choose the layout LAYOUT_NAME from the menu manually, // after DO restarted, then do not change any of the settings below. // // - Preferences / Launching Opus / From the Desktop // - Preferences / Launching Opus / From the Taskbar icon // - Preferences / Launching Opus / Startup // //############################################################################## //############################################################################## function OnInit(initData){ //uid added via script wizard (do not change after publishing this script) var uid = "54947148-1219-4C26-8D92-C3EDC6B34FDC"; //thread url added via script wizard (required for updating) var url = "https://resource.dopus.com/t/scheduling-save-all-listers/40996/9"; initData.name = "Event.Generic: AutoSaveLayout"; initData.desc = "Automatically save current layout."; initData.copyright = "tb - 2022.04.15"; initData.version = "0.1"; initData.default_enable = true; return false; } //############################################################################## function getTimeStampNow() { return new Date().getTime(); } //############################################################################## function getTimeStampFuture( ) { return getTimeStampNow() + (1000 * 60 * 5); // + 5 mins } //############################################################################## function getTimeStampDelay( ) { return getTimeStampNow() + (1000 * 5); // + 5 secs } // delay saving of layout for some SECONDS //############################################################################## function delayNextSaving() { DOpus.Vars.Set("script.autosave_layout.do_not_save_until", getTimeStampDelay() ); } // disable saving of layout for some MINUTES. // some events will still save layout and then switch handling over to regular // saving, which will always be blocked for some seconds only, to reduce the overall // saving activity to reasonable level. //############################################################################## function disableSavingTemporarily() { DOpus.Vars.Set("script.autosave_layout.do_not_save_until", getTimeStampFuture() ); } //############################################################################## function isSavingDelayed(forced) { var now = getTimeStampNow(); var doNotSaveUntil = -1; if (DOpus.Vars.Exists("script.autosave_layout.do_not_save_until")) doNotSaveUntil = DOpus.Vars.Get("script.autosave_layout.do_not_save_until" ) * 1; var delayed = now < doNotSaveUntil; if (forced || !delayed) { Log("Saving layout YES - delayed ["+delayed+"], forced ["+forced+"]."); return true; } Log("Saving layout NO - delayed ["+delayed+"], forced ["+forced+"]."); return false; } //############################################################################## function saveLayout( forced ) { forced = typeof forced === "undefined" ? false : forced; //test if saving is enabled or forced, saving is disabled temporarily //after a lister opened and/or for some time after DO started up. if (!isSavingDelayed(forced)){ //Log("Auto-saving layout skipped."); return false; } //Log(" Saving layout as ["+LAYOUT_NAME+"].."); var cmd = DOpus.Create.Command(); cmd.RunCommand('Prefs LAYOUTSAVE LAYOUTNAME="'+LAYOUT_NAME+'"'); //cmd.RunCommand("Prefs SETDEFAULTLISTER=quiet"); delayNextSaving(); return true; } //############################################################################## function OnStartup( data ) { //disable saving temporarily disableSavingTemporarily(); } //############################################################################## function OnOpenLister( data ) { //disable saving temporarily, many tabs could open and trigger a layout save. //we could tell quite sure whether the lister was opened because DO started, //and maybe if a layout was loaded or an external folder was "launched" in DO //(Explorer replacement), but we aim to keep things simple this time. //so we just don't care about saving the layout for some time after a lister //opened, auto saving the layout will kick in again, once a tab closed or a //lister closed. //just for reference, some thoughts for more complex handling: //- startup listers could be detected by "startup" datestamp from OnStartup()? //- layout-opened listers could be detected with ".layout" property? //- what about externally launched listers? disableSavingTemporarily(); } //############################################################################## function OnOpenTab( data ) { saveLayout(); } //############################################################################## function OnActivateTab( data ) { saveLayout(); } //############################################################################## function OnActivateLister( data ) { //saving layout if any lister lost focus (another //application or another DO lister got focus). if (!data.active) saveLayout(); } //############################################################################## function OnCloseTab( data ) { //closing a tab always re-enables auto saving of layout saveLayout(true); //just save } //############################################################################## function OnListerResize( data ) { //resizing a lister always re-enables auto saving of layout saveLayout(true); //just save } //############################################################################## function OnListerUIChange( data ) { //ui change always re-enables auto saving of layout saveLayout(true); //just save } //############################################################################## function OnCloseLister( data ) { //closing a lister always re-enables auto saving of layout saveLayout(true); //just save } //############################################################################## function OnShutdown( data ) { saveLayout(true); //just save } //############################################################################## function Log(text, lvl, ind){ //XLog v0.46 (fix missing output for missing "normal" and indent -> Log("text, "", 1); ) var u="undefined",lvs={o:0,x:1,e:2,w:3,i:4,n:5,t:6,d:7,a:8},i=["","X","E","W","I","","","",""],d=DOpus; if (typeof XLog==u){var v=d.Vars; if (v.Exists("XLog") && typeof XLogForce==u) {XLog=v.Get("XLog"); }} if (typeof XLog==u){try{var c=Script.Config;if(typeof c.XLog!=u){XLog=c.XLog;}}catch(e){d.Output("XLog: Early call, log-level=all.",1);XLog=8;}} if (typeof XLog==u){XLog="normal";} if(XLog.paused===undefined){ if(XLog===true) var L=5; else if(!isNaN(parseInt(XLog,10))) var L=XLog*1; else var L=lvs[(""+XLog).toLowerCase().substring(0,1)]; XLog={paused:false,I:0,L:L};} lvl=((typeof lvl==u || lvl == "")?5:lvs[lvl.substring(0,1).toLowerCase()]); if (!(lvl && XLog.L && !XLog.paused && (lvl<=XLog.L))){ return;} var pad = (XLog.I==0?"":new Array(XLog.I+1).join(" ")); if (i[lvl])pad = i[lvl]+(!pad?" ":pad.substring(1)); if (text!="-"){if (d.Version.AtLeast("11.13.1")) d.Output(pad+text,((lvl==1||lvl==2)?1:0)); else d.Output(pad+text);} ind=(ind!==undefined?ind:0);XLog.I+=ind;if(XLog.I<0)throw new Error("XLog indent went sub-zero."); } //############################################################################## function OnAboutScript(data){ //v0.1 var cmd = DOpus.Create.Command(); if (!cmd.Commandlist('s').exists("ScriptWizard")){ if (DOpus.Dlg.Request("The 'ScriptWizard' add-in has not been found.\n\n"+ "Install 'ScriptWizard' from [resource.dopus.com].\nThe add-in enables this dialog and also offers "+ "easy updating of scripts and many more.","Yes, take me there!|Cancel", "No About.. ", data.window)) cmd.RunCommand('http://resource.dopus.com/viewtopic.php?f=35&t=23179');} else cmd.RunCommand('ScriptWizard ABOUT WIN='+data.window+' FILE="'+Script.File+'"'); } //MD5 = "502596bb488ccc12f3d393115deda1d6"; DATE = "2022.04.15 - 11:03:21"