Commit 13df0633 authored by Sergey.Konovalov's avatar Sergey.Konovalov Committed by Alexander.Trofimov

Bug 25916 - [CoEdit] Лист не отображается как активный при передаче данных...

Bug 25916 - [CoEdit] Лист не отображается как активный при передаче данных второму пользователю после Hide Sheet.
Bug 25654 - Фокус не возвращается на лист книги, восстановленный с помощью redo.
В историю сохраняется sheet для undo и redo, не меняем sheet в совместном редактировании.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@57810 954022d7-b5bf-4e40-9824-e11837661b57
parent ef62fee9
......@@ -367,10 +367,16 @@ CHistory.prototype.UndoRedoEnd = function (Point, oRedoObjectParam, bUndo) {
oState = bUndo ? Point.SelectionState : ((this.Index === this.Points.length - 1) ?
this.LastState : this.Points[this.Index + 1].SelectionState);
// ToDo какое-то не очень решение брать 0-й элемент и у него получать индекс!
var nSheetId = (null !== oState) ? oState[0].worksheetId : Point.nLastSheetId;
if (null !== nSheetId)
this.workbook.handlers.trigger('showWorksheet', nSheetId);
if (this.workbook.bCollaborativeChanges) {
//active может поменяться только при remove, hide листов
this.workbook.handlers.trigger('showWorksheet', this.workbook.getActive());
}
else {
// ToDo какое-то не очень решение брать 0-й элемент и у него получать индекс!
var nSheetId = (null !== oState) ? oState[0].worksheetId : ((this.workbook.bRedoChanges && null != Point.RedoSheetId) ? Point.RedoSheetId : Point.UndoSheetId);
if (null !== nSheetId)
this.workbook.handlers.trigger('showWorksheet', nSheetId);
}
for (i in Point.UpdateRigions)
this.workbook.handlers.trigger("cleanCellCache", i, Point.UpdateRigions[i], false, true);
......@@ -586,18 +592,19 @@ CHistory.prototype.Create_NewPoint = function()
var Items = [];
var UpdateRigions = {};
var Time = new Date().getTime();
var nLastSheetId = null, oSelectionState = this.workbook.handlers.trigger("getSelectionState");
var UndoSheetId = null, oSelectionState = this.workbook.handlers.trigger("getSelectionState");
// ToDo Берем всегда, т.к. в случае с LastState мы можем не попасть на нужный лист и не заселектить нужный диапазон!
var oSelectRange = this.workbook.handlers.trigger("getSelection");
var wsActive = this.workbook.getWorksheet(this.workbook.getActive());
if (wsActive)
nLastSheetId = wsActive.getId();
UndoSheetId = wsActive.getId();
this.CurPoint = {
Items : Items, // Массив изменений, начиная с текущего момента
UpdateRigions : UpdateRigions,
nLastSheetId : nLastSheetId,
UndoSheetId: UndoSheetId,
RedoSheetId: null,
SelectRange : oSelectRange,
SelectRangeRedo : oSelectRange,
Time : Time, // Текущее время
......@@ -652,7 +659,7 @@ CHistory.prototype.Add = function(Class, Type, sheetid, range, Data, LocalChange
Item.LocalChange = LocalChange;
oCurPoint.Items.push( Item );
if(null != range)
if (null != range && null != sheetid)
{
var updateRange = oCurPoint.UpdateRigions[sheetid];
if(null != updateRange)
......@@ -662,7 +669,7 @@ CHistory.prototype.Add = function(Class, Type, sheetid, range, Data, LocalChange
oCurPoint.UpdateRigions[sheetid] = updateRange;
}
if (null != sheetid)
oCurPoint.nLastSheetId = sheetid;
oCurPoint.UndoSheetId = sheetid;
if(1 == oCurPoint.Items.length)
this._sendCanUndoRedo();
};
......@@ -720,6 +727,22 @@ CHistory.prototype.GetSelectionRedo = function()
oRes = this.CurPoint.SelectRangeRedo;
return oRes;
};
CHistory.prototype.SetSheetRedo = function (sheetId) {
if (0 !== this.TurnOffHistory)
return;
if (null == this.CurPoint)
return;
this.CurPoint.RedoSheetId = sheetId;
};
CHistory.prototype.SetSheetUndo = function (sheetId) {
if (0 !== this.TurnOffHistory)
return;
if (null == this.CurPoint)
return;
this.CurPoint.UndoSheetId = sheetId;
};
CHistory.prototype.TurnOff = function()
{
this.TurnOffHistory++;
......
......@@ -2685,7 +2685,7 @@ UndoRedoWorkbook.prototype = {
}
else if(historyitem_Workbook_SheetPositions == Type)
{
var wsActive = this.wb.aWorksheets[this.wb.nActive];
var wsActive = this.wb.getActiveWs();
//делаем вспомогательным map из sheetid
var oTempSheetMap = {};
for(var i = 0, length = Data.positions.length; i < length; ++i)
......@@ -2744,8 +2744,7 @@ UndoRedoWorkbook.prototype = {
if(bEmpty)
break;
}
this.wb._updateWorksheetIndexes();
this.wb.nActive = wsActive.getIndex();
this.wb._updateWorksheetIndexes(wsActive);
}
else if(historyitem_Workbook_ChangeColorScheme == Type)
{
......
......@@ -1284,6 +1284,9 @@ Workbook.prototype.getDefaultSize=function(){
Workbook.prototype.getActive=function(){
return this.nActive;
};
Workbook.prototype.getActiveWs = function () {
return this.getWorksheet(this.nActive);
};
Workbook.prototype.setActive=function(index){
if(index >= 0 && index < this.aWorksheets.length){
this.nActive = index;
......@@ -1321,6 +1324,7 @@ Workbook.prototype.getWorksheetCount=function(){
Workbook.prototype.createWorksheet=function(indexBefore, sName, sId){
History.Create_NewPoint();
History.TurnOff();
var wsActive = this.getActiveWs();
var oNewWorksheet = new Woorksheet(this, this.aWorksheets.length, sId);
if(null != sName)
{
......@@ -1337,11 +1341,12 @@ Workbook.prototype.createWorksheet=function(indexBefore, sName, sId){
this.aWorksheets.push(oNewWorksheet);
}
this.aWorksheetsById[oNewWorksheet.getId()] = oNewWorksheet;
this._updateWorksheetIndexes();
this.setActive(oNewWorksheet.index);
this._updateWorksheetIndexes(wsActive);
History.TurnOn();
this._insertWorksheetFormula(oNewWorksheet.index);
History.Add(g_oUndoRedoWorkbook, historyitem_Workbook_SheetAdd, null, null, new UndoRedoData_SheetAdd(indexBefore, oNewWorksheet.getName(), null, oNewWorksheet.getId()));
History.SetSheetUndo(wsActive.getId());
History.SetSheetRedo(oNewWorksheet.getId());
return oNewWorksheet.index;
};
Workbook.prototype.copyWorksheet=function(index, insertBefore, sName, sId, bFromRedo){
......@@ -1349,6 +1354,7 @@ Workbook.prototype.copyWorksheet=function(index, insertBefore, sName, sId, bFrom
if(index >= 0 && index < this.aWorksheets.length){
History.Create_NewPoint();
History.TurnOff();
var wsActive = this.getActiveWs();
var wsFrom = this.aWorksheets[index];
var newSheet = wsFrom.clone(sId);
if(null != sName)
......@@ -1367,7 +1373,7 @@ Workbook.prototype.copyWorksheet=function(index, insertBefore, sName, sId, bFrom
this.aWorksheets.push(newSheet);
}
this.aWorksheetsById[newSheet.getId()] = newSheet;
this._updateWorksheetIndexes();
this._updateWorksheetIndexes(wsActive);
History.TurnOn();
this._insertWorksheetFormula(insertBefore);
//для формул. создаем копию this.cwf[this.Id] для нового листа.
......@@ -1385,13 +1391,16 @@ Workbook.prototype.copyWorksheet=function(index, insertBefore, sName, sId, bFrom
}
sortDependency(this);
History.Add(g_oUndoRedoWorkbook, historyitem_Workbook_SheetAdd, null, null, new UndoRedoData_SheetAdd(insertBefore, newSheet.getName(), wsFrom.getId(), newSheet.getId()));
History.SetSheetUndo(wsActive.getId());
History.SetSheetRedo(newSheet.getId());
if(!(bFromRedo === true))
{
wsFrom.copyDrawingObjects(newSheet, wsFrom);
}
}
};
Workbook.prototype.insertWorksheet=function(index, sheet, cwf){
Workbook.prototype.insertWorksheet = function (index, sheet, cwf) {
var wsActive = this.getActiveWs();
if(null != index && index >= 0 && index < this.aWorksheets.length){
//помещаем новый sheet перед insertBefore
this.aWorksheets.splice(index, 0, sheet);
......@@ -1401,7 +1410,7 @@ Workbook.prototype.insertWorksheet=function(index, sheet, cwf){
this.aWorksheets.push(sheet);
}
this.aWorksheetsById[sheet.getId()] = sheet;
this._updateWorksheetIndexes();
this._updateWorksheetIndexes(wsActive);
this._insertWorksheetFormula(index);
//восстанавливаем список ячеек с формулами для sheet
this.cwf[sheet.getId()] = cwf;
......@@ -1434,6 +1443,7 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){
indexTo >= 0 && indexTo < this.aWorksheets.length){
History.Create_NewPoint();
History.TurnOff();
var wsActive = this.getActiveWs();
var oWsFrom = this.aWorksheets[indexFrom];
var oWsTo = this.aWorksheets[indexTo];
var tempW = {
......@@ -1474,7 +1484,7 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){
History.TurnOn();
var movedSheet = this.aWorksheets.splice(indexFrom, 1);
this.aWorksheets.splice(indexTo, 0, movedSheet[0]);
this._updateWorksheetIndexes();
this._updateWorksheetIndexes(wsActive);
this._insertWorksheetFormula(tempW.wTI);
......@@ -1483,6 +1493,28 @@ Workbook.prototype.replaceWorksheet=function(indexFrom, indexTo){
unLockDraw(this);
}
};
Workbook.prototype.findSheetNoHidden = function (nIndex) {
var i, ws, oRes = null, bFound = false, countWorksheets = this.getWorksheetCount();
for (i = nIndex; i < countWorksheets; ++i) {
ws = this.getWorksheet(i);
if (false === ws.getHidden()) {
oRes = ws;
bFound = true;
break;
}
}
// Не нашли справа, ищем слева от текущего
if (!bFound) {
for (i = nIndex - 1; i >= 0; --i) {
ws = this.getWorksheet(i);
if (false === ws.getHidden()) {
oRes = ws;
break;
}
}
}
return oRes;
}
Workbook.prototype.removeWorksheet=function(nIndex, outputParams){
//проверяем останется ли хоть один нескрытый sheet
var bEmpty = true;
......@@ -1521,54 +1553,42 @@ Workbook.prototype.removeWorksheet=function(nIndex, outputParams){
}
}
}
//по всем удаленным листам пробегаемся и удаляем из workbook.cwf (cwf - cells with forluma) элементы с названием соответствующего листа.
this.dependencyFormulas.removeNodeBySheetId(removedSheetId);
History.TurnOff();
var nNewActive = this.nActive;
this.aWorksheets.splice(nIndex, 1);
//по всем удаленным листам пробегаемся и удаляем из workbook.cwf (cwf - cells with forluma) элементы с названием соответствующего листа.
var _cwf = this.cwf[removedSheetId];
delete this.cwf[removedSheetId];
delete this.aWorksheetsById[removedSheetId];
var bFind = false;
if(nNewActive < this.aWorksheets.length)
{
for(var i = nNewActive; i < this.aWorksheets.length; ++i)
if(false == this.aWorksheets[i].getHidden())
{
bFind = true;
nNewActive = i;
break;
}
}
if(false == bFind)
{
for(var i = nNewActive - 1; i >= 0; --i)
if(false == this.aWorksheets[i].getHidden())
{
nNewActive = i;
break;
}
var wsActive = this.getActiveWs();
var oVisibleWs = null;
this.aWorksheets.splice(nIndex, 1);
delete this.aWorksheetsById[removedSheetId];
if (nIndex == this.getActive()) {
oVisibleWs = this.findSheetNoHidden(nIndex);
if (null != oVisibleWs)
wsActive = oVisibleWs;
}
History.TurnOn();
History.Add(g_oUndoRedoWorkbook, historyitem_Workbook_SheetRemove, null, null, new UndoRedoData_SheetRemove(nIndex, removedSheetId, removedSheet, _cwf));
if (null != oVisibleWs) {
History.SetSheetUndo(removedSheetId);
History.SetSheetRedo(wsActive.getId());
}
if(null != outputParams)
{
outputParams.sheet = removedSheet;
outputParams.cwf = _cwf;
}
this._updateWorksheetIndexes();
this.nActive = nNewActive;
this._updateWorksheetIndexes(wsActive);
buildRecalc(this);
unLockDraw(this);
return nNewActive;
return wsActive.getIndex();
}
return -1;
};
Workbook.prototype._updateWorksheetIndexes=function(){
Workbook.prototype._updateWorksheetIndexes = function (wsActive) {
for(var i = 0, length = this.aWorksheets.length; i < length; ++i)
this.aWorksheets[i]._setIndex(i);
if (null != wsActive)
this.setActive(wsActive.getIndex());
};
Workbook.prototype.checkUniqueSheetName=function(name){
var workbookSheetCount = this.getWorksheetCount();
......@@ -1795,6 +1815,9 @@ Workbook.prototype.SerializeHistory = function(){
if (historyitem_Workbook_SheetAdd == item.nActionType || historyitem_Workbook_SheetRemove == item.nActionType || historyitem_Workbook_SheetMove == item.nActionType)
bChangeSheetPlace = true;
}
else if (g_oUndoRedoWorksheet === item.oClass && historyitem_Worksheet_Hide === item.nActionType) {
bChangeSheetPlace = true;
}
this._SerializeHistoryBase64(oMemory, item, aPointChangesBase64);
}
if (bChangeSheetPlace) {
......@@ -1874,24 +1897,17 @@ Workbook.prototype.DeserializeHistory = function(aChanges, fCallback){
History.SetSelection(null);
History.SetSelectionRedo(null);
var oHistoryPositions = null;//нужен самый последний historyitem_Workbook_SheetPositions
var oRedoObjectParam = new Asc.RedoObjectParam();
History.UndoRedoPrepare(oRedoObjectParam, false);
for (var i = 0, length = aUndoRedoElems.length; i < length; ++i)
{
var item = aUndoRedoElems[i];
if ((null != item.oClass || (item.oData && typeof item.oData.sChangedObjectId === "string")) && null != item.nActionType) {
if (g_oUndoRedoWorkbook == item.oClass && historyitem_Workbook_SheetPositions == item.nActionType)
oHistoryPositions = item;
else {
// TODO if(g_oUndoRedoGraphicObjects == item.oClass && item.oData.drawingData)
// item.oData.drawingData.bCollaborativeChanges = true;
History.RedoAdd(oRedoObjectParam, item.oClass, item.nActionType, item.nSheetId, item.oRange, item.oData);
}
// TODO if(g_oUndoRedoGraphicObjects == item.oClass && item.oData.drawingData)
// item.oData.drawingData.bCollaborativeChanges = true;
History.RedoAdd(oRedoObjectParam, item.oClass, item.nActionType, item.nSheetId, item.oRange, item.oData);
}
}
if(null != oHistoryPositions)
History.RedoAdd(oRedoObjectParam, oHistoryPositions.oClass, oHistoryPositions.nActionType, oHistoryPositions.nSheetId, oHistoryPositions.oRange, oHistoryPositions.oData);
History.UndoRedoEnd(null, oRedoObjectParam, false);
......@@ -2353,35 +2369,26 @@ Woorksheet.prototype.getHidden=function(){
return false != this.bHidden;
return false;
};
Woorksheet.prototype.setHidden=function(hidden){
if(this.bHidden != hidden)
{
History.Create_NewPoint();
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_Hide, this.getId(), null, new UndoRedoData_FromTo(this.bHidden, hidden));
}
this.bHidden = hidden;
if(true == this.bHidden && this.getIndex() == this.workbook.getActive())
{
//выбираем новый активный
var activeWorksheet = this.getIndex();
var countWorksheets = this.workbook.getWorksheetCount();
// Покажем следующий лист или предыдущий (если больше нет)
var i, ws;
for (i = activeWorksheet + 1; i < countWorksheets; ++i) {
ws = this.workbook.getWorksheet(i);
if (false === ws.getHidden()) {
this.workbook.handlers.trigger("undoRedoHideSheet", i);
return;
}
}
// Не нашли справа, ищем слева от текущего
for (i = activeWorksheet - 1; i >= 0; --i) {
ws = this.workbook.getWorksheet(i);
if (false === ws.getHidden()) {
this.workbook.handlers.trigger("undoRedoHideSheet", i);
return;
}
}
Woorksheet.prototype.setHidden = function (hidden) {
var bOldHidden = this.bHidden, wb = this.workbook, wsActive = wb.getActiveWs(), oVisibleWs = null;
this.bHidden = hidden;
if (true == this.bHidden && this.getIndex() == wsActive.getIndex())
{
oVisibleWs = wb.findSheetNoHidden(this.getIndex());
if (null != oVisibleWs) {
var nNewIndex = oVisibleWs.getIndex();
wb.setActive(nNewIndex);
if (!wb.bUndoChanges && !wb.bRedoChanges)
wb.handlers.trigger("undoRedoHideSheet", nNewIndex);
}
}
if (bOldHidden != hidden) {
History.Create_NewPoint();
History.Add(g_oUndoRedoWorksheet, historyitem_Worksheet_Hide, this.getId(), null, new UndoRedoData_FromTo(bOldHidden, hidden));
if (null != oVisibleWs) {
History.SetSheetUndo(wsActive.getId());
History.SetSheetRedo(oVisibleWs.getId());
}
}
};
Woorksheet.prototype.getSheetViewSettings = function () {
......
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