Undo/Redo in dialogs

Next
 From:  ttype (STRUBE)
7286.1 
Hi Michael,

I am working on a small script console, because I wanted colors and stuff: https://github.com/thetumbledtype/moi3d-scripts-other/blob/master/ScriptConsole.js


To make a long story short: Can I make Ctrl+Z and Ctrl+Y work in a dialog at all? While Ctrl+A, Ctrl+C, Ctrl+V and Ctrl+X seem to work most of the time, undo and redo do not work at all (in any dialog).
Attachments:

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Max Smirnov (SMIRNOV)
7286.2 In reply to 7286.1 
Try this
code:
moi.command.registerCommandSpecificShortcutKey( "Ctrl+Z" );
moi.ui.commandDialog.waitForEvent();
e  = moi.ui.commandDialog.event;
if ( e == 'Ctrl+Z' ) DoSomething();
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
7286.3 In reply to 7286.1 
Hi Strube - it's built into MoI's keyboard input processing that when it sees that an edit control has focus, it makes Ctrl+C, Ctrl+V, Ctrl+X and Ctrl+A execute text editing functions in that edit control rather than processing them as regular MoI command shortcuts.

But right now that does not include Ctrl+Y and Ctrl+Z mostly because MoI does not have any multi-line textarea input in any of its regular UI currently, so it just had not come up before. For v4 I could modify this to additionally look if the edit control is a multi-line control or maybe if it's marked with a particular attribute and then also have those keys handled in a similar way.

For now the only way that I can see is to have an event loop like Max shows above where you could register a command specific shortcut key and have it handled by the script itself since it will generate a UI event once it is registered. Then you could call document.execCommand( 'undo' ); to make the text edit do an undo. This may be difficult to use well though since you have to be in a modal type of event loop to do it, you won't be able to do it in a modeless dialog.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  ttype (STRUBE)
7286.4 In reply to 7286.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();
    }
}
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Message 7286.5 deleted 3 Mar 2015 by STRUBE

Previous
 From:  ttype (STRUBE)
7286.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

EDITED: 3 Mar 2015 by STRUBE

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All