File size: 2,022 Bytes
c02f046
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Kwf.Form.HtmlEditor.UndoRedo = Ext2.extend(Ext2.util.Observable, {
    init: function(cmp){
        this.cmp = cmp;
        this.cmp.afterMethod('createToolbar', this.afterCreateToolbar, this);
        this.cmp.on('initialize', this.onInit, this, {delay:100, single: true});
        this.cmp.afterMethod('updateToolbar', this.updateToolbar, this);
    },
    onInit: function(){
        this.cmp.tinymceEditor.on('Undo Redo AddUndo TypingUndo ClearUndos', (function() {
            this.updateToolbar();
        }).bind(this));
    },
    updateToolbar: function() {
        this.undoAction.setDisabled(!this.cmp.tinymceEditor.undoManager.hasUndo());
        this.redoAction.setDisabled(!this.cmp.tinymceEditor.undoManager.hasRedo());
    },
    afterCreateToolbar: function() {
        this.undoAction = new Ext2.Action({
            handler: function() {
                this.cmp.tinymceEditor.undoManager.undo();
            },
            scope: this,
            disabled: true,
            icon: '/assets/silkicons/arrow_undo.png',
            tooltip: {
                cls: 'x2-html-editor-tip',
                title: trlKwf('Undo (Ctrl+Z)'),
                text: trlKwf('Undo the last action.')
            },
            cls: 'x2-btn-icon',
            clickEvent: 'mousedown',
            tabIndex: -1
        });
        this.redoAction = new Ext2.Action({
            handler: function() {
                this.cmp.tinymceEditor.undoManager.redo();
            },
            scope: this,
            disabled: true,
            icon: '/assets/silkicons/arrow_redo.png',
            tooltip: {
                cls: 'x2-html-editor-tip',
                title: trlKwf('Redo'),
                text: trlKwf('Redo the last action.')
            },
            cls: 'x2-btn-icon',
            clickEvent: 'mousedown',
            tabIndex: -1
        });

        var tb = this.cmp.getToolbar();
        tb.insert(0, this.undoAction);
        tb.insert(1, this.redoAction);
        tb.insert(2, '-');
    }
});