Commit 5c144ced authored by Alexander.Trofimov's avatar Alexander.Trofimov

Добавил выделение для PopUpSelector-а.

Добавил применение при click и dblClick
Добавил смену выделения.

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@55385 954022d7-b5bf-4e40-9824-e11837661b57
parent b2fe8be1
...@@ -2865,16 +2865,6 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS"; ...@@ -2865,16 +2865,6 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
this.wb.restoreFocus(); this.wb.restoreFocus();
}, },
// /**
// * Устанавливает текст в ячейке или в редакторе ячейки
// * @param {String} v новый текст
// * @param {Number} pos позиция текста в редакторе (для редактора ячейки)
// * @param {Number} len длина замещаемого текста (для редактора ячейки)
// */
// asc_setCellValue: function (v, pos, len) {
// this.wb.setCellValue(v, pos, len);
// }, - не используется (и не стоит так делать)
asc_setCellFormat: function (format) { asc_setCellFormat: function (format) {
this.wb.getWorksheet().setSelectionInfo("format", format); this.wb.getWorksheet().setSelectionInfo("format", format);
this.wb.restoreFocus(); this.wb.restoreFocus();
...@@ -3723,7 +3713,6 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS"; ...@@ -3723,7 +3713,6 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
prot["asc_setCellTextColor"] = prot.asc_setCellTextColor; prot["asc_setCellTextColor"] = prot.asc_setCellTextColor;
prot["asc_setCellBackgroundColor"] = prot.asc_setCellBackgroundColor; prot["asc_setCellBackgroundColor"] = prot.asc_setCellBackgroundColor;
prot["asc_setCellBorders"] = prot.asc_setCellBorders; prot["asc_setCellBorders"] = prot.asc_setCellBorders;
//prot["asc_setCellValue"] = prot.asc_setCellValue; - не используется (и не стоит так делать)
prot["asc_setCellFormat"] = prot.asc_setCellFormat; prot["asc_setCellFormat"] = prot.asc_setCellFormat;
prot["asc_setCellAngle"] = prot.asc_setCellAngle; prot["asc_setCellAngle"] = prot.asc_setCellAngle;
prot["asc_setCellStyle"] = prot.asc_setCellStyle; prot["asc_setCellStyle"] = prot.asc_setCellStyle;
......
...@@ -158,5 +158,8 @@ ...@@ -158,5 +158,8 @@
white-space: nowrap; white-space: nowrap;
} }
#apiPopUpList li:hover { #apiPopUpList li:hover {
background-color: rgba(105, 119, 62, 0.2); background-color: #D8DADC;
}
#apiPopUpList li.selected {
background-color: #7d858c;
} }
\ No newline at end of file
...@@ -227,9 +227,10 @@ ...@@ -227,9 +227,10 @@
t.input.addEventListener("drop" , function (e) {e.preventDefault(); return false;} , false); t.input.addEventListener("drop" , function (e) {e.preventDefault(); return false;} , false);
} }
this.fKeyDown = function () { this.fKeyDown = function (event) {
t._keyDownFormulaSelector.apply(t, arguments); if (t.handlers.trigger("popUpSelectorKeyDown", event))
return t._onWindowKeyDown.apply(t, arguments); return t._onWindowKeyDown(event);
return false;
}; };
this.fKeyPress = function () {return t._onWindowKeyPress.apply(t, arguments);}; this.fKeyPress = function () {return t._onWindowKeyPress.apply(t, arguments);};
this.fKeyUp = function () {return t._onWindowKeyUp.apply(t, arguments);}; this.fKeyUp = function () {return t._onWindowKeyUp.apply(t, arguments);};
......
...@@ -803,6 +803,9 @@ ...@@ -803,6 +803,9 @@
case 38: // up case 38: // up
stop(); // Отключим стандартную обработку браузера нажатия up stop(); // Отключим стандартную обработку браузера нажатия up
if (!t.handlers.trigger("popUpSelectorKeyDown", event))
return t.__retval;
dr = event.ctrlKey ? -1.5 : -1; // Движение стрелками (влево-вправо, вверх-вниз) dr = event.ctrlKey ? -1.5 : -1; // Движение стрелками (влево-вправо, вверх-вниз)
break; break;
...@@ -818,6 +821,8 @@ ...@@ -818,6 +821,8 @@
t.handlers.trigger("showAutoComplete"); t.handlers.trigger("showAutoComplete");
return t.__retval; return t.__retval;
} }
if (!t.handlers.trigger("popUpSelectorKeyDown", event))
return t.__retval;
dr = event.ctrlKey ? +1.5 : +1; // Движение стрелками (влево-вправо, вверх-вниз) dr = event.ctrlKey ? +1.5 : +1; // Движение стрелками (влево-вправо, вверх-вниз)
break; break;
......
...@@ -11,18 +11,29 @@ ...@@ -11,18 +11,29 @@
* @param {undefined} undefined * @param {undefined} undefined
*/ */
function($, window, undefined) { function($, window, undefined) {
function PopUpSelector(element) { var asc = window["Asc"];
var asc_HL = asc.HandlersList;
function PopUpSelector(element, handlers) {
this.handlers = new asc_HL(handlers);
this.element = element; this.element = element;
this.selector = null; this.selector = null;
this.selectorStyle = null; this.selectorStyle = null;
this.selectorList = null; this.selectorList = null;
this.selectElement = null;
this.isFormula = false;
this.isVisible = false; this.isVisible = false;
this.fMouseDown = null;
this.fMouseDblClick = null;
this._init(); this._init();
return this; return this;
} }
PopUpSelector.prototype._init = function () { PopUpSelector.prototype._init = function () {
var t = this;
if (null != this.element) { if (null != this.element) {
this.selector = document.createElement("div"); this.selector = document.createElement("div");
this.selectorStyle = this.selector.style; this.selectorStyle = this.selector.style;
...@@ -31,6 +42,9 @@ ...@@ -31,6 +42,9 @@
this.element.appendChild(this.selector); this.element.appendChild(this.selector);
this.selectorList = document.getElementById("apiPopUpList"); this.selectorList = document.getElementById("apiPopUpList");
this.fMouseDown = function (event) {t._onMouseDown(event);};
this.fMouseDblClick = function (event) {t._onMouseDblClick(event);};
} }
}; };
PopUpSelector.prototype.show = function (isFormula, arrItems, cellRect) { PopUpSelector.prototype.show = function (isFormula, arrItems, cellRect) {
...@@ -40,25 +54,25 @@ ...@@ -40,25 +54,25 @@
this.selectorStyle.display = "block"; this.selectorStyle.display = "block";
this.isVisible = true; this.isVisible = true;
} }
this.isFormula = isFormula;
var item; var item;
for (var i = 0; i < arrItems.length; ++i) { for (var i = 0; i < arrItems.length; ++i) {
item = document.createElement("li"); item = document.createElement("li");
if (isFormula) { if (this.isFormula) {
if (0 === i) {
this.selectElement = item;
item.className = "selected";
}
item.innerHTML = arrItems[i].name; item.innerHTML = arrItems[i].name;
item.setAttribute("title", arrItems[i].arg); item.setAttribute("title", arrItems[i].arg);
} else } else
item.innerHTML = arrItems[i]; item.innerHTML = arrItems[i];
/* if (item.addEventListener) {
item.ondblclick = function(e) { item.addEventListener("mousedown" , this.fMouseDown , false);
if ( e && (e.button === 0) ) { item.addEventListener("dblclick" , this.fMouseDblClick , false);
var formulaName = this.innerText || this.textContent; }
var insertText = formulaName.substring(_this.input.value.length - 1) + "(";
_this._addChars(insertText);
_this._removeFormulaSelector();
}
}*/
this.selectorList.appendChild(item); this.selectorList.appendChild(item);
} }
...@@ -91,6 +105,64 @@ ...@@ -91,6 +105,64 @@
}; };
PopUpSelector.prototype._clearList = function () { PopUpSelector.prototype._clearList = function () {
this.selectorList.innerHTML = ""; this.selectorList.innerHTML = "";
this.selectElement = null;
this.isFormula = false;
};
PopUpSelector.prototype.onKeyDown = function (event) {
var retVal = false;
switch (event.which) {
case 9: // Tab
break;
case 13: // "enter"
break;
case 27: // Esc
this.hide();
break;
case 38: // Up
if (this.isFormula)
this._onChangeSelection(this.selectElement.previousSibling);
break;
case 40: // Down
if (this.isFormula)
this._onChangeSelection(this.selectElement.nextSibling);
break;
default:
retVal = true;
}
return retVal;
};
PopUpSelector.prototype._onMouseDown = function (event) {
var element = (event.target || event.srcElement);
if (this.isFormula) {
this._onChangeSelection(element);
} else {
this.hide();
this.handlers.trigger("insert", element.innerHTML);
}
};
PopUpSelector.prototype._onMouseDblClick = function (event) {
if (!this.isVisible)
return;
if (!this.isFormula) {
this._onMouseDown(event);
return;
}
var elementVal = (event.target || event.srcElement).innerHTML + "(";
this.hide();
this.handlers.trigger("insert", elementVal);
};
PopUpSelector.prototype._onChangeSelection = function (newElement) {
if (null === newElement)
return;
if (null !== this.selectElement)
this.selectElement.className = "";
this.selectElement = newElement;
this.selectElement.className = "selected";
}; };
/* /*
......
...@@ -87,6 +87,8 @@ ...@@ -87,6 +87,8 @@
this.popUpSelector = null; this.popUpSelector = null;
this.formulasList = null; // Список всех формул this.formulasList = null; // Список всех формул
this.lastFormulaPos = -1; // Последняя позиция формулы
this.lastFormulaName = ""; // Последний кусок формулы
this._lockDraw = false; this._lockDraw = false;
...@@ -261,7 +263,8 @@ ...@@ -261,7 +263,8 @@
"moveFrozenAnchorHandleDone": function () {self._onMoveFrozenAnchorHandleDone.apply(self, arguments);}, "moveFrozenAnchorHandleDone": function () {self._onMoveFrozenAnchorHandleDone.apply(self, arguments);},
// AutoComplete // AutoComplete
"showAutoComplete": function () {self._onShowAutoComplete.apply(self, arguments);} "showAutoComplete": function () {self._onShowAutoComplete.apply(self, arguments);},
"popUpSelectorKeyDown": function (event) {return self._onPopUpSelectorKeyDown(event);}
}); });
this.model.handlers.add("cleanCellCache", function (wsId, range, canChangeColWidth, bLockDraw) { this.model.handlers.add("cleanCellCache", function (wsId, range, canChangeColWidth, bLockDraw) {
...@@ -416,13 +419,16 @@ ...@@ -416,13 +419,16 @@
self.handlers.trigger("asc_onCanRedoChanged", bCanRedo); self.handlers.trigger("asc_onCanRedoChanged", bCanRedo);
}, },
"applyCloseEvent" : function () {self.controller._onWindowKeyDown.apply(self.controller, arguments);}, "applyCloseEvent" : function () {self.controller._onWindowKeyDown.apply(self.controller, arguments);},
"isViewerMode" : function () {return self.controller.settings.isViewerMode;} "isViewerMode" : function () {return self.controller.settings.isViewerMode;},
"popUpSelectorKeyDown" : function (event) {return self._onPopUpSelectorKeyDown(event);}
}, },
/*settings*/{ /*settings*/{
font: this.defaultFont font: this.defaultFont
}); });
this.popUpSelector = new asc_PS(this.element); this.popUpSelector = new asc_PS(this.element, /*handlers*/{
"insert" : function () {self._onPopUpSelectorInsert.apply(self, arguments);}
});
} }
this.clipboard.Api = this.Api; this.clipboard.Api = this.Api;
...@@ -1347,14 +1353,31 @@ ...@@ -1347,14 +1353,31 @@
} }
} }
} }
if (0 < arrResult.length) if (0 < arrResult.length) {
this.popUpSelector.show(true, arrResult, this.getWorksheet().getActiveCellCoord()); this.popUpSelector.show(true, arrResult, this.getWorksheet().getActiveCellCoord());
else this.lastFormulaPos = formulaPos;
this.lastFormulaName = formulaName;
}
else {
this.popUpSelector.hide(); this.popUpSelector.hide();
this.lastFormulaPos = -1;
this.lastFormulaName = "";
}
};
WorkbookView.prototype._onPopUpSelectorKeyDown = function (event) {
if (!this.popUpSelector.getVisible())
return true;
return this.popUpSelector.onKeyDown(event);
};
WorkbookView.prototype._onPopUpSelectorInsert = function (value) {
if (this.controller.isCellEditMode)
this.cellEditor.replaceText(this.lastFormulaPos, this.lastFormulaName.length, value);
else
this.getWorksheet().setSelectionInfo("value", value, /*onlyActive*/true);
}; };
// Вставка формулы в редактор // Вставка формулы в редактор
WorkbookView.prototype.insertFormulaInEditor = function (functionName, autoComplet) { WorkbookView.prototype.insertFormulaInEditor = function (functionName, autoComplete) {
var t = this; var t = this;
var ws = this.getWorksheet(); var ws = this.getWorksheet();
...@@ -1368,8 +1391,8 @@ ...@@ -1368,8 +1391,8 @@
// Он закрыт // Он закрыт
var cellRange = null; var cellRange = null;
// Если нужно сделать автозаполнение формулы, то ищем ячейки) // Если нужно сделать автозаполнение формулы, то ищем ячейки)
if (autoComplet) { if (autoComplete) {
cellRange = ws.autoCompletFormula(functionName); cellRange = ws.autoCompleteFormula(functionName);
} }
if (cellRange) { if (cellRange) {
if (cellRange.notEditCell) { if (cellRange.notEditCell) {
...@@ -1646,15 +1669,6 @@ ...@@ -1646,15 +1669,6 @@
return printPagesData; return printPagesData;
}; };
// не используется
// WorkbookView.prototype.setCellValue = function (v, pos, len) {
// if (!this.controller.isCellEditMode) {
// this.getWorksheet().setSelectionInfo("value", v, /*onlyActive*/true);
// } else {
// this.cellEditor.replaceText(pos, len, v);
// }
// };
WorkbookView.prototype._initCommentsToSave = function () { WorkbookView.prototype._initCommentsToSave = function () {
for (var wsKey in this.wsViews) for (var wsKey in this.wsViews)
{ {
......
...@@ -752,7 +752,7 @@ ...@@ -752,7 +752,7 @@
}; };
// Автодополняет формулу диапазоном, если это возможно // Автодополняет формулу диапазоном, если это возможно
WorksheetView.prototype.autoCompletFormula = function (functionName) { WorksheetView.prototype.autoCompleteFormula = function (functionName) {
var t = this; var t = this;
this.activeRange.normalize(); this.activeRange.normalize();
var ar = this.activeRange; var ar = this.activeRange;
...@@ -906,7 +906,7 @@ ...@@ -906,7 +906,7 @@
} }
} }
var onAutoCompletFormula = function (isSuccess) { var onAutoCompleteFormula = function (isSuccess) {
if (false === isSuccess) if (false === isSuccess)
return; return;
...@@ -921,7 +921,7 @@ ...@@ -921,7 +921,7 @@
}; };
// Можно ли применять автоформулу // Можно ли применять автоформулу
this._isLockedCells (changedRange, /*subType*/null, onAutoCompletFormula); this._isLockedCells (changedRange, /*subType*/null, onAutoCompleteFormula);
result.notEditCell = true; result.notEditCell = true;
return result; return result;
......
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