Changeset 393

Show
Ignore:
Timestamp:
2007-06-27 08:55:55 (19 months ago)
Author:
martinkou
Message:

Ported the basic undo/redo logic from IE to Gecko

Location:
FCKeditor/trunk/editor/_source
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/trunk/editor/_source/commandclasses/fck_othercommands.js

    r347 r393  
    231231FCKUndoCommand.prototype.Execute = function() 
    232232{ 
    233         if ( FCKBrowserInfo.IsIE ) 
    234                 FCKUndo.Undo() ; 
    235         else 
    236                 FCK.ExecuteNamedCommand( 'Undo' ) ; 
     233        FCKUndo.Undo() ; 
    237234} 
    238235 
    239236FCKUndoCommand.prototype.GetState = function() 
    240237{ 
    241         if ( FCKBrowserInfo.IsIE ) 
    242                 return ( FCKUndo.CheckUndoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ; 
    243         else 
    244                 return FCK.GetNamedCommandState( 'Undo' ) ; 
     238        return ( FCKUndo.CheckUndoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ; 
    245239} 
    246240 
     
    253247FCKRedoCommand.prototype.Execute = function() 
    254248{ 
    255         if ( FCKBrowserInfo.IsIE ) 
    256                 FCKUndo.Redo() ; 
    257         else 
    258                 FCK.ExecuteNamedCommand( 'Redo' ) ; 
     249        FCKUndo.Redo() ; 
    259250} 
    260251 
    261252FCKRedoCommand.prototype.GetState = function() 
    262253{ 
    263         if ( FCKBrowserInfo.IsIE ) 
    264                 return ( FCKUndo.CheckRedoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ; 
    265         else 
    266                 return FCK.GetNamedCommandState( 'Redo' ) ; 
     254        return ( FCKUndo.CheckRedoState() ? FCK_TRISTATE_OFF : FCK_TRISTATE_DISABLED ) ; 
    267255} 
    268256 
  • FCKeditor/trunk/editor/_source/internals/fck_gecko.js

    r341 r393  
    2626FCK.Description = "FCKeditor for Gecko Browsers" ; 
    2727 
     28FCK._KeyDownUndo = function() 
     29{ 
     30        if ( !FCKUndo.Typing ) 
     31        { 
     32                FCKUndo.SaveUndoStep() ; 
     33                FCKUndo.Typing = true ; 
     34                FCK.Events.FireEvent( "OnSelectionChange" ) ; 
     35        } 
     36 
     37        FCKUndo.TypesCount++ ; 
     38 
     39        if ( FCKUndo.TypesCount > FCKUndo.MaxTypes ) 
     40        { 
     41                FCKUndo.TypesCount = 0 ; 
     42                FCKUndo.SaveUndoStep() ; 
     43        } 
     44} 
     45 
     46FCK._KeyDownListener = function( evt ) 
     47{ 
     48        if ( FCK.EditorWindow ) 
     49        { 
     50                if ( !( evt.keyCode >= 16 && evt.keyCode <= 18 ) ) 
     51                        FCK._KeyDownUndo(); 
     52        } 
     53        return true; 
     54} 
     55 
    2856FCK.InitializeBehaviors = function() 
    2957{ 
     
    5987        } 
    6088        this.EditorDocument.addEventListener( 'dblclick', this._DblClickListener, true ) ; 
     89 
     90        // Record changes for the undo system when there are key down events. 
     91        this.EditorDocument.addEventListener( 'keydown', this._KeyDownListener, false ) ; 
    6192 
    6293        // Reset the context menu. 
  • FCKeditor/trunk/editor/_source/internals/fckundo_gecko.js

    r132 r393  
    2424var FCKUndo = new Object() ; 
    2525 
     26FCKUndo.SavedData = new Array() ; 
     27FCKUndo.CurrentIndex = -1 ; 
     28FCKUndo.TypesCount = FCKUndo.MaxTypes = 25 ; 
     29FCKUndo.Typing = false; 
     30 
    2631FCKUndo.SaveUndoStep = function() 
    27 {} 
     32{ 
     33        if ( FCK.EditMode != FCK_EDITMODE_WYSIWYG ) 
     34                return ; 
     35 
     36        // Shrink the array to the current level. 
     37        FCKUndo.SavedData = FCKUndo.SavedData.slice( 0, FCKUndo.CurrentIndex + 1 ) ; 
     38 
     39        // Get the Actual HTML. 
     40        var sHtml = FCK.EditorDocument.body.innerHTML ; 
     41 
     42        // Cancel operation if the new step is identical to the previous one. 
     43        if ( FCKUndo.CurrentIndex >= 0 && sHtml == FCKUndo.SavedData[ FCKUndo.CurrentIndex ][0] ) 
     44                return ; 
     45 
     46        // If we reach the Maximun number of undo levels, we must remove the first 
     47        // entry of the list shifting all elements. 
     48        if ( FCKUndo.CurrentIndex + 1 >= FCKConfig.MaxUndoLevels ) 
     49                FCKUndo.SavedData.shift() ; 
     50        else 
     51                FCKUndo.CurrentIndex++ ; 
     52 
     53        // Get the actual selection. 
     54        // TODO: How to handle this in Gecko? 
     55 
     56        // Save the new level in front of the actual position. 
     57        FCKUndo.SavedData[ FCKUndo.CurrentIndex ] = [ sHtml, null ] ; 
     58 
     59        FCK.Events.FireEvent( "OnSelectionChange" ) ; 
     60} 
     61 
     62FCKUndo.CheckUndoState = function() 
     63{ 
     64        return ( FCKUndo.Typing || FCKUndo.CurrentIndex > 0 ) ; 
     65} 
     66 
     67FCKUndo.CheckRedoState = function() 
     68{ 
     69        return ( !FCKUndo.Typing && FCKUndo.CurrentIndex < ( FCKUndo.SavedData.length - 1 ) ) ; 
     70} 
     71 
     72FCKUndo.Undo = function() 
     73{ 
     74        if ( FCKUndo.CheckUndoState() ) 
     75        { 
     76                // If it is the first step. 
     77                if ( FCKUndo.CurrentIndex == ( FCKUndo.SavedData.length - 1 ) ) 
     78                { 
     79                        // Save the actual state for a possible "Redo" call. 
     80                        FCKUndo.SaveUndoStep() ; 
     81                } 
     82 
     83                // Go a step back. 
     84                FCKUndo._ApplyUndoLevel( --FCKUndo.CurrentIndex ) ; 
     85 
     86                FCK.Events.FireEvent( "OnSelectionChange" ) ; 
     87        } 
     88} 
     89 
     90FCKUndo.Redo = function() 
     91{ 
     92        if ( FCKUndo.CheckRedoState() ) 
     93        { 
     94                // Go a step forward. 
     95                FCKUndo._ApplyUndoLevel( ++FCKUndo.CurrentIndex ) ; 
     96 
     97                FCK.Events.FireEvent( "OnSelectionChange" ) ; 
     98        } 
     99} 
     100 
     101FCKUndo._ApplyUndoLevel = function(level) 
     102{ 
     103        var oData = FCKUndo.SavedData[ level ] ; 
     104 
     105        if ( !oData ) 
     106                return ; 
     107 
     108        // Update the editor contents with that step data. 
     109        FCK.EditorDocument.body.innerHTML = oData[0] ; 
     110 
     111        // TODO: Restore selection in Gecko 
     112 
     113        FCKUndo.TypesCount = 0 ; 
     114        FCKUndo.Typing = false ; 
     115}