Commit 038831a2 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Добавил в апи функции asc_getCanUndo и asc_getCanRedo

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@57618 954022d7-b5bf-4e40-9824-e11837661b57
parent 1e804d12
...@@ -1154,6 +1154,13 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS"; ...@@ -1154,6 +1154,13 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
return false; return false;
}, },
asc_getCanUndo: function () {
return History.Can_Undo();
},
asc_getCanRedo: function () {
return History.Can_Redo();
},
// Actions and callbacks interface // Actions and callbacks interface
...@@ -3626,6 +3633,8 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS"; ...@@ -3626,6 +3633,8 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
prot["asc_getDocumentName"] = prot.asc_getDocumentName; prot["asc_getDocumentName"] = prot.asc_getDocumentName;
prot["asc_getDocumentFormat"] = prot.asc_getDocumentFormat; prot["asc_getDocumentFormat"] = prot.asc_getDocumentFormat;
prot["asc_isDocumentModified"] = prot.asc_isDocumentModified; prot["asc_isDocumentModified"] = prot.asc_isDocumentModified;
prot["asc_getCanUndo"] = prot.asc_getCanUndo;
prot["asc_getCanRedo"] = prot.asc_getCanRedo;
prot["asc_setAutoSaveGap"] = prot.asc_setAutoSaveGap; prot["asc_setAutoSaveGap"] = prot.asc_setAutoSaveGap;
......
...@@ -186,10 +186,8 @@ function CHistory(workbook) ...@@ -186,10 +186,8 @@ function CHistory(workbook)
this.SavedIndex = null; // Номер точки отката, на которой произошло последнее сохранение this.SavedIndex = null; // Номер точки отката, на которой произошло последнее сохранение
} }
CHistory.prototype = CHistory.prototype.Clear = function()
{ {
Clear : function()
{
this.Index = -1; this.Index = -1;
this.SavePoint = null; this.SavePoint = null;
this.Points.length = 0; this.Points.length = 0;
...@@ -201,28 +199,23 @@ CHistory.prototype = ...@@ -201,28 +199,23 @@ CHistory.prototype =
this.SavedIndex = null; this.SavedIndex = null;
this._sendCanUndoRedo(); this._sendCanUndoRedo();
}, };
Can_Undo : function() /** @returns {boolean} */
{ CHistory.prototype.Can_Undo = function()
if ( (null != this.CurPoint && this.CurPoint.Items.length > 0) || this.Index >= 0 ) {
return true; return ((null != this.CurPoint && this.CurPoint.Items.length > 0) || this.Index >= 0);
};
return false; /** @returns {boolean} */
}, CHistory.prototype.Can_Redo = function()
{
Can_Redo : function() return ((null == this.CurPoint || 0 == this.CurPoint.Items.length) && this.Points.length > 0 && this.Index < this.Points.length - 1);
{ };
if ( (null == this.CurPoint || 0 == this.CurPoint.Items.length) && this.Points.length > 0 && this.Index < this.Points.length - 1 )
return true;
return false;
},
Undo : function() CHistory.prototype.Undo = function()
{ {
// Проверяем можно ли сделать Undo // Проверяем можно ли сделать Undo
if ( true != this.Can_Undo() ) if ( true != this.Can_Undo() )
return null; return;
if (this.Index === this.Points.length - 1) if (this.Index === this.Points.length - 1)
this.LastState = this.workbook.handlers.trigger("getSelectionState"); this.LastState = this.workbook.handlers.trigger("getSelectionState");
...@@ -244,8 +237,8 @@ CHistory.prototype = ...@@ -244,8 +237,8 @@ CHistory.prototype =
this._addRedoObjectParam(oRedoObjectParam, Item); this._addRedoObjectParam(oRedoObjectParam, Item);
} }
this.UndoRedoEnd(Point, oRedoObjectParam, true); this.UndoRedoEnd(Point, oRedoObjectParam, true);
}, };
UndoRedoPrepare : function (oRedoObjectParam, bUndo) { CHistory.prototype.UndoRedoPrepare = function (oRedoObjectParam, bUndo) {
if (this.Is_On()) { if (this.Is_On()) {
oRedoObjectParam.bIsOn = true; oRedoObjectParam.bIsOn = true;
this.TurnOff(); this.TurnOff();
...@@ -257,9 +250,9 @@ CHistory.prototype = ...@@ -257,9 +250,9 @@ CHistory.prototype =
this.workbook.bUndoChanges = true; this.workbook.bUndoChanges = true;
else else
this.workbook.bRedoChanges = true; this.workbook.bRedoChanges = true;
}, };
RedoAdd : function(oRedoObjectParam, Class, Type, sheetid, range, Data, LocalChange) CHistory.prototype.RedoAdd = function(oRedoObjectParam, Class, Type, sheetid, range, Data, LocalChange)
{ {
//todo сделать что-нибудь с Is_On //todo сделать что-нибудь с Is_On
var bNeedOff = false; var bNeedOff = false;
if(false == this.Is_On()) if(false == this.Is_On())
...@@ -297,15 +290,14 @@ CHistory.prototype = ...@@ -297,15 +290,14 @@ CHistory.prototype =
} }
} }
this._addRedoObjectParam(oRedoObjectParam, this.CurPoint.Items[this.CurPoint.Items.length - 1]); this._addRedoObjectParam(oRedoObjectParam, this.CurPoint.Items[this.CurPoint.Items.length - 1]);
}, };
CheckXfrmChanges: function(xfrm)
{
}, CHistory.prototype.CheckXfrmChanges = function(xfrm)
{
};
RedoExecute : function(Point, oRedoObjectParam) CHistory.prototype.RedoExecute = function(Point, oRedoObjectParam)
{ {
// Выполняем все действия в прямом порядке // Выполняем все действия в прямом порядке
for ( var Index = 0; Index < Point.Items.length; Index++ ) for ( var Index = 0; Index < Point.Items.length; Index++ )
{ {
...@@ -334,8 +326,8 @@ CHistory.prototype = ...@@ -334,8 +326,8 @@ CHistory.prototype =
wsViews[i].objectRender.controller.recalculate2(undefined); wsViews[i].objectRender.controller.recalculate2(undefined);
} }
} }
}, };
UndoRedoEnd: function (Point, oRedoObjectParam, bUndo) { CHistory.prototype.UndoRedoEnd = function (Point, oRedoObjectParam, bUndo) {
var wsViews, i, oState; var wsViews, i, oState;
if (!bUndo && null == Point) { if (!bUndo && null == Point) {
this._checkCurPoint(); this._checkCurPoint();
...@@ -435,12 +427,12 @@ CHistory.prototype = ...@@ -435,12 +427,12 @@ CHistory.prototype =
unLockDraw(this.workbook); unLockDraw(this.workbook);
if (oRedoObjectParam.bIsOn) if (oRedoObjectParam.bIsOn)
this.TurnOn(); this.TurnOn();
}, };
Redo : function() CHistory.prototype.Redo = function()
{ {
// Проверяем можно ли сделать Redo // Проверяем можно ли сделать Redo
if ( true != this.Can_Redo() ) if ( true != this.Can_Redo() )
return null; return;
var oRedoObjectParam = new Asc.RedoObjectParam(); var oRedoObjectParam = new Asc.RedoObjectParam();
this.UndoRedoPrepare(oRedoObjectParam, false); this.UndoRedoPrepare(oRedoObjectParam, false);
...@@ -451,8 +443,8 @@ CHistory.prototype = ...@@ -451,8 +443,8 @@ CHistory.prototype =
this.RedoExecute(Point, oRedoObjectParam); this.RedoExecute(Point, oRedoObjectParam);
this.UndoRedoEnd(Point, oRedoObjectParam, false); this.UndoRedoEnd(Point, oRedoObjectParam, false);
}, };
_addRedoObjectParam: function (oRedoObjectParam, Point) { CHistory.prototype._addRedoObjectParam = function (oRedoObjectParam, Point) {
if (g_oUndoRedoWorksheet === Point.Class && historyitem_Worksheet_SetViewSettings === Point.Type) { if (g_oUndoRedoWorksheet === Point.Class && historyitem_Worksheet_SetViewSettings === Point.Type) {
oRedoObjectParam.bIsReInit = true; oRedoObjectParam.bIsReInit = true;
oRedoObjectParam.oOnUpdateSheetViewSettings[Point.SheetId] = Point.SheetId; oRedoObjectParam.oOnUpdateSheetViewSettings[Point.SheetId] = Point.SheetId;
...@@ -469,9 +461,9 @@ CHistory.prototype = ...@@ -469,9 +461,9 @@ CHistory.prototype =
oRedoObjectParam.oOnUpdateTabColor[Point.SheetId] = Point.SheetId; oRedoObjectParam.oOnUpdateTabColor[Point.SheetId] = Point.SheetId;
else if (g_oUndoRedoWorksheet === Point.Class && historyitem_Worksheet_ChangeFrozenCell === Point.Type) else if (g_oUndoRedoWorksheet === Point.Class && historyitem_Worksheet_ChangeFrozenCell === Point.Type)
oRedoObjectParam.oOnUpdateSheetViewSettings[Point.SheetId] = Point.SheetId; oRedoObjectParam.oOnUpdateSheetViewSettings[Point.SheetId] = Point.SheetId;
}, };
Get_RecalcData : function(Point2) CHistory.prototype.Get_RecalcData = function(Point2)
{ {
//if ( this.Index >= 0 ) //if ( this.Index >= 0 )
{ {
//for ( var Pos = this.RecIndex + 1; Pos <= this.Index; Pos++ ) //for ( var Pos = this.RecIndex + 1; Pos <= this.Index; Pos++ )
...@@ -510,20 +502,22 @@ CHistory.prototype = ...@@ -510,20 +502,22 @@ CHistory.prototype =
} }
} }
} }
}, };
Reset_RecalcIndex : function() CHistory.prototype.Reset_RecalcIndex = function()
{ {
this.RecIndex = this.Index; this.RecIndex = this.Index;
}, };
Set_Additional_ExtendDocumentToPos: function() CHistory.prototype.Set_Additional_ExtendDocumentToPos = function()
{}, {
};
Check_UninonLastPoints : function()
{ CHistory.prototype.Check_UninonLastPoints = function()
{
// Не объединяем точки истории, если на предыдущей точке произошло сохранение // Не объединяем точки истории, если на предыдущей точке произошло сохранение
if ( this.Points.length < 2) if ( this.Points.length < 2)
return; return;
...@@ -577,10 +571,10 @@ CHistory.prototype = ...@@ -577,10 +571,10 @@ CHistory.prototype =
this.Index += DiffIndex; this.Index += DiffIndex;
this.RecIndex += Math.max( -1, this.RecIndex + DiffIndex); this.RecIndex += Math.max( -1, this.RecIndex + DiffIndex);
} }
}, };
Create_NewPoint : function() CHistory.prototype.Create_NewPoint = function()
{ {
if ( 0 !== this.TurnOffHistory || 0 !== this.Transaction ) if ( 0 !== this.TurnOffHistory || 0 !== this.Transaction )
return; return;
...@@ -608,13 +602,13 @@ CHistory.prototype = ...@@ -608,13 +602,13 @@ CHistory.prototype =
Time : Time, // Текущее время Time : Time, // Текущее время
SelectionState : oSelectionState SelectionState : oSelectionState
}; };
}, };
// Регистрируем новое изменение: // Регистрируем новое изменение:
// Class - объект, в котором оно произошло // Class - объект, в котором оно произошло
// Data - сами изменения // Data - сами изменения
Add : function(Class, Type, sheetid, range, Data, LocalChange) CHistory.prototype.Add = function(Class, Type, sheetid, range, Data, LocalChange)
{ {
if ( 0 !== this.TurnOffHistory ) if ( 0 !== this.TurnOffHistory )
return; return;
...@@ -670,10 +664,10 @@ CHistory.prototype = ...@@ -670,10 +664,10 @@ CHistory.prototype =
oCurPoint.nLastSheetId = sheetid; oCurPoint.nLastSheetId = sheetid;
if(1 == oCurPoint.Items.length) if(1 == oCurPoint.Items.length)
this._sendCanUndoRedo(); this._sendCanUndoRedo();
}, };
_sendCanUndoRedo : function() CHistory.prototype._sendCanUndoRedo = function()
{ {
this.workbook.handlers.trigger("setCanUndo", this.Can_Undo()); this.workbook.handlers.trigger("setCanUndo", this.Can_Undo());
this.workbook.handlers.trigger("setCanRedo", this.Can_Redo()); this.workbook.handlers.trigger("setCanRedo", this.Can_Redo());
if(this.IsModify != this.Is_Modified()) if(this.IsModify != this.Is_Modified())
...@@ -681,9 +675,9 @@ CHistory.prototype = ...@@ -681,9 +675,9 @@ CHistory.prototype =
this.IsModify = !this.IsModify; this.IsModify = !this.IsModify;
this.workbook.handlers.trigger("setDocumentModified", this.IsModify); this.workbook.handlers.trigger("setDocumentModified", this.IsModify);
} }
}, };
_checkCurPoint : function() CHistory.prototype._checkCurPoint = function()
{ {
if(null != this.CurPoint && this.CurPoint.Items.length > 0) if(null != this.CurPoint && this.CurPoint.Items.length > 0)
{ {
// Создаем новую точку // Создаем новую точку
...@@ -692,69 +686,69 @@ CHistory.prototype = ...@@ -692,69 +686,69 @@ CHistory.prototype =
this.Points.length = this.Index + 1; this.Points.length = this.Index + 1;
this.CurPoint = null; this.CurPoint = null;
} }
}, };
SetSelection : function(range) CHistory.prototype.SetSelection = function(range)
{ {
if ( 0 !== this.TurnOffHistory ) if ( 0 !== this.TurnOffHistory )
return; return;
if ( null == this.CurPoint ) if ( null == this.CurPoint )
return; return;
this.CurPoint.SelectRange = range; this.CurPoint.SelectRange = range;
}, };
SetSelectionRedo : function(range) CHistory.prototype.SetSelectionRedo = function(range)
{ {
if ( 0 !== this.TurnOffHistory ) if ( 0 !== this.TurnOffHistory )
return; return;
if ( null == this.CurPoint ) if ( null == this.CurPoint )
return; return;
this.CurPoint.SelectRangeRedo = range; this.CurPoint.SelectRangeRedo = range;
}, };
GetSelection : function(range) CHistory.prototype.GetSelection = function()
{ {
var oRes = null; var oRes = null;
if(null != this.CurPoint) if(null != this.CurPoint)
oRes = this.CurPoint.SelectRange; oRes = this.CurPoint.SelectRange;
return oRes; return oRes;
}, };
GetSelectionRedo : function(range) CHistory.prototype.GetSelectionRedo = function()
{ {
var oRes = null; var oRes = null;
if(null != this.CurPoint) if(null != this.CurPoint)
oRes = this.CurPoint.SelectRangeRedo; oRes = this.CurPoint.SelectRangeRedo;
return oRes; return oRes;
}, };
TurnOff : function() CHistory.prototype.TurnOff = function()
{ {
this.TurnOffHistory++; this.TurnOffHistory++;
}, };
TurnOn : function() CHistory.prototype.TurnOn = function()
{ {
this.TurnOffHistory--; this.TurnOffHistory--;
if(this.TurnOffHistory < 0) if(this.TurnOffHistory < 0)
this.TurnOffHistory = 0; this.TurnOffHistory = 0;
}, };
StartTransaction : function() CHistory.prototype.StartTransaction = function()
{ {
this.Transaction++; this.Transaction++;
}, };
EndTransaction : function() CHistory.prototype.EndTransaction = function()
{ {
this.Transaction--; this.Transaction--;
if(this.Transaction < 0) if(this.Transaction < 0)
this.Transaction = 0; this.Transaction = 0;
}, };
/** @returns {boolean} */
Is_On : function() CHistory.prototype.Is_On = function()
{ {
return ( 0 === this.TurnOffHistory ? true : false ) ; return (0 === this.TurnOffHistory);
}, };
Save : function() CHistory.prototype.Save = function()
{ {
if(null != this.CurPoint && this.CurPoint.Items.length > 0) if(null != this.CurPoint && this.CurPoint.Items.length > 0)
this.SavePoint = this.CurPoint; this.SavePoint = this.CurPoint;
else if(this.Index >= 0 && this.Index < this.Points.length) else if(this.Index >= 0 && this.Index < this.Points.length)
...@@ -764,13 +758,14 @@ CHistory.prototype = ...@@ -764,13 +758,14 @@ CHistory.prototype =
this.IsModify = !this.IsModify; this.IsModify = !this.IsModify;
this.workbook.handlers.trigger("setDocumentModified", this.IsModify); this.workbook.handlers.trigger("setDocumentModified", this.IsModify);
} }
}, };
Reset_SavedIndex : function() CHistory.prototype.Reset_SavedIndex = function()
{ {
this.SavedIndex = this.Index; this.SavedIndex = this.Index;
}, };
Is_Modified : function() /** @returns {boolean} */
{ CHistory.prototype.Is_Modified = function()
{
if(null != this.CurPoint && this.CurPoint.Items.length > 0) if(null != this.CurPoint && this.CurPoint.Items.length > 0)
{ {
if(null != this.SavePoint) if(null != this.SavePoint)
...@@ -788,13 +783,12 @@ CHistory.prototype = ...@@ -788,13 +783,12 @@ CHistory.prototype =
else if(null != this.SavePoint) else if(null != this.SavePoint)
return true; return true;
return false; return false;
}, };
GetSerializeArray : function() CHistory.prototype.GetSerializeArray = function()
{ {
var aRes = []; var aRes = [];
this._checkCurPoint(); this._checkCurPoint();
var i = 0, t; var i = 0;
var worksheets = Asc["editor"].wbModel.aWorksheets;
if (null != this.SavedIndex) if (null != this.SavedIndex)
i = this.SavedIndex + 1; i = this.SavedIndex + 1;
for(; i <= this.Index; ++i) for(; i <= this.Index; ++i)
...@@ -810,14 +804,13 @@ CHistory.prototype = ...@@ -810,14 +804,13 @@ CHistory.prototype =
aRes.push(aPointChanges); aRes.push(aPointChanges);
} }
return aRes; return aRes;
}, };
//функция, которая перемещает последнее действие на первую позицию(в текущей точке) //функция, которая перемещает последнее действие на первую позицию(в текущей точке)
ChangeActionsEndToStart : function() CHistory.prototype.ChangeActionsEndToStart = function()
{ {
if(null != this.CurPoint && this.CurPoint.Items.length > 0) if(null != this.CurPoint && this.CurPoint.Items.length > 0)
{ {
var endAction = this.CurPoint.Items.pop(); var endAction = this.CurPoint.Items.pop();
this.CurPoint.Items.unshift(endAction); this.CurPoint.Items.unshift(endAction);
} }
}
}; };
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment