Working autosave, but need help to finalize it

 From:  Michael Gibson
11150.11 In reply to 11150.10 
Hi Moi3dFan, the problem is your function SetAutosaveTimer() inside SidePane.htm only consists of this:

code:
					function SetAutosaveTimer()
					{
						if ( Autosave == 0 ) clearInterval(AutosaveTimer);
					}


That's only clearing the timer, not setting it up.

The point of making the function is for it to contain the setup code as well. So you need to move the code for setting up the timer into the function.

Something like this (untested, may have typos):

code:
					var AutosaveTimer = false;
					var Autosave = 0;
					var AutosaveIncremental = false;
	
					function SetAutosaveTimer()
					{
						if ( AutosaveTimer ) clearInterval(AutosaveTimer);

						Autosave = moi.command.getOption( 'Autosave', true); // return autosave time (ms) from ini (180000 = 3 min)
						AutosaveIncremental = moi.command.getOption( 'AutosaveIncremental', true); //return AS mode (false)

						AutosaveTimer = setInterval(function() {
							if (AutosaveIncremental) { 
								moi.command.execCommand('IncrementalSave');
							} else { 
								moi.command.execCommand('Save');
							}
						}, Autosave)

					}
					SetAutosaveTimer();


Also since the setup is retrieving the values from moi.ini you need to alter the code in GeneralOptions.htm so it will store the values in moi.ini before it calls moi.ui.sidePane.SetAutosaveTimer(); in addition to doing it in the Shutdown() function.

- Michael