How to add undo functionality for a plugin

• Jun 20, 2013 - 20:13

I noticed that I cannot undo the action of my plugin. Is there some code that I have to add?

Thanks for the help,
Ruud


Comments

It seems that there exist curScore.startUndo() and curScore.endUndo() calls in the 1.X version of the framework - at least, I see those defined in the Score object and being used by lots of plugins. It does seem to work, although I've never really experimented to see how well.

In reply to by Ruud Mulder

I have tried to use the undo calls but it does not work. I tried debugging but that gave strange results. First of all, when I had the standard applyToNotesInSelection in a separate file it did not switch to that file but showed me the main file that called it. Secondly, when I stepped it stopped with an error after the first note of the selection (with a blue box) but when I run it applies the function to all selected notes.
Is there anyone with experience on this point? I did this with version 1.3 on Windows XP with a dutch language setting.

Thanks for the help,
Ruud

In reply to by Ruud Mulder

Posting an example you are having trouble with would help. Perhaps I suspect some operations are inherently not undoable. But I know it works for most of the plugins I've worked on - Break Every X Measures, Cue Notes, Explode/Implode, Slash Notation Styles, etc. So maybe look at one of those to see if you are using the calls differently.

Oh, and I have no idea if plugins even support the idea of separating functions into different files, but suspect not, at least for 1.3. I think 2.0 might.

In reply to by Marc Sabatella

Calling a function in another script file does work. It searches first in the folder where the calling script is. It just doesn't show in the debugger. The code I used is below and calls the standard function applyToNotesInSelection that is in the Development/Plugin Development/Howto.
Since the enharmonic shift will be in 2.0 this is now only for my understanding, so it is not necessary to put in a lot of effort.

// shift one note
function shiftUp(note)
{
var newtpc = note.tpc + 12;
if (newtpc <= 33)
{
note.tpc = newtpc;
}
};
function init() {};
function run()
{
curScore.startUndo();
// do the shift for all notes in selection using the standard code snippet
applyToNotesInSelection(shiftUp);
curScore.endUndo();
};
function close() {};

var mscorePlugin =
{
majorVersion: 1,
minorVersion: 1,
menu: 'Plugins.enharmonicShiftUp',
init: init,
run: run,
onClose: close
};

Do you still have an unanswered question? Please log in first to post your question.