MoI discussion forum
MoI discussion forum

Full Version: Undo/Redo in dialogs

Show messages: All  1-3  4-6

From: ttype (STRUBE)
2 Mar 2015   [#4] In reply to [#2]
I've appended this, your example and added just the first line at the beginning of the script inside the body, hoping that that would change MoI's event policy. But either nothing happens or the script console is not opening at all and MoI crashes afterwards on closing.

Codemirror, which I use, btw has its' own undo/redo functionality that works when I assign a shortcut key that is not used by MoI.

code:
moi.command.registerCommandSpecificShortcutKey( "Ctrl+Z" );
while(1) {
    moi.ui.commandDialog.waitForEvent();
    e  = moi.ui.commandDialog.event;
    if ( e == 'Ctrl+Z' ) {
        editor.undo();
    }
}

Message 7286.5 was deleted


From: ttype (STRUBE)
3 Mar 2015   [#6]
I got it!

Because codemirror has its' own undo/redo functionality objects can be added to commandbar like in FullScreen.js and then I simply set up a new shortcut for CTRL+Z and Y that checks if the editor has focus.
code:
var cb = moi.ui.getUIPanel('moi://ui/CommandBar.htm');
cb.consoleDoc = document;
cb.editor = editor;

$(window).unload(function() {
    delete cb.consoleDoc;
    delete cb.editor;
});

code:
var cb = moi.ui.getUIPanel('moi://ui/CommandBar.htm');

if (cb.consoleDoc && cb.consoleDoc.hasFocus()) {
    cb.editor.undo()
} else {
    moi.command.undo();
}

So now there is a small script console with syntax highlighting, line numbers, undo/redo and bracket matching. Still not too much, but it can be found here: https://github.com/thetumbledtype/moi3d-scripts-other/blob/master/ScriptConsole.htm

Show messages: All  1-3  4-6