JEXI development (14) Application Command mode

xiaoxiao2021-03-06  184

Command mode is used to encapsulate users. Define Command interface:

Public interface command {boolean execute (); void unExecute (); string toString ();

TOSTRING () Method Returns the command description to prompt the user in the toolbar's UNDO / REDO.

SLR COMMANDMANAGER is used to create, execute, and revoke commands:

Command cmd = new deleteCommand (...); if (cmd.execute ()) {addtocommandlist (cmd); // add to undo list}

If Execute () returns success, the command is successfully executed, put this command in the list, and you can revoke the command in the future to implement the UNDO function, which requires each command to save before execution Related data to recover in the future.

In order to simprance, we have not implemented unExecute (), the command defined is as follows:

INSERTCOMMAND: Insert a character. DeleteCommand: Delete a character or selection text. SplitCommand: The user is equivalent to dividing the current paragraph into two parts. FormatCommand: Formats Select Chinese.

The above commands can already achieve basic editing functions, as for other commands such as COPY, Paste or the like can be added later, because user operation is packaged by one by one, so it will be extremely easy to expand.

The latest interface:

转载请注明原文地址:https://www.9cbs.com/read-128244.html

New Post(0)