home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
filF9CC53EA258B23D0E47AC2FC84B7FFBA
< prev
next >
Wrap
Text File
|
2010-07-12
|
10KB
|
315 lines
var YaSpellcheckerUserDict = {
get personalDict() {
delete this.personalDict;
this.personalDict = Cc["@mozilla.org/spellchecker/personaldictionary;1"]
.getService().QueryInterface(Ci.mozIPersonalDictionary);
return this.personalDict;
},
get tree() {
delete this.tree;
this.tree = document.getElementById("words-list");
return this.tree;
},
get treechildren() {
delete this.treechildren;
this.treechildren = document.getElementById("words-list-treechildren");
return this.treechildren;
},
init: function() {
this.buildDictList();
this.tree.addEventListener("yaStopEditing", this, false);
this.tree.addEventListener("yaStartEditing", this, false);
this.tree.addEventListener("select", this, false);
},
saveDict: function() {
this.personalDict.save();
document.getElementById("dict-button-save").setAttribute("disabled", "true");
},
onDialogAccept: function() {
this.saveDict();
},
_canceledDialod: false,
onDialogCancel: function() {
if (this._canceledDialod || document.getElementById("dict-button-save").hasAttribute("disabled"))
return true;
this._canceledDialod = true;
let stringBundle = Cc["@mozilla.org/intl/stringbundle;1"].createInstance(Ci.nsIStringBundleService)
.createBundle("chrome://yasearch/locale/spellchecker/spellchecker.properties");
function getLocalizedString(aName) {
return stringBundle.GetStringFromName(aName);
}
let prompter = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
let flags = prompter.BUTTON_POS_2 * prompter.BUTTON_TITLE_IS_STRING +
prompter.BUTTON_POS_1 * prompter.BUTTON_TITLE_IS_STRING +
prompter.BUTTON_POS_0 * prompter.BUTTON_TITLE_IS_STRING +
prompter.BUTTON_POS_2_DEFAULT;
let result = prompter.confirmEx(window,
getLocalizedString("spellcheckerUserDictConfirmTitle"),
getLocalizedString("spellcheckerUserDictConfirmMessage"),
flags,
getLocalizedString("spellcheckerUserDictConfirmButtonCancel"),
getLocalizedString("spellcheckerUserDictConfirmButtonDontSave"),
getLocalizedString("spellcheckerUserDictConfirmButtonSave"),
null, {});
switch (result) {
case 0:
this._canceledDialod = false;
break;
case 2:
this.saveDict();
break;
case 1:
default:
break;
}
return this._canceledDialod;
},
onDialogUnload: function() {
this.tree.removeEventListener("select", this, false);
this.tree.removeEventListener("yaStartEditing", this, false);
this.tree.removeEventListener("yaStopEditing", this, false);
this.personalDict.load();
let openerDocument = window.opener.document;
if (openerDocument) {
let tbSpellcheckerButton = openerDocument.getElementById("yasearch-spellchecker-button");
if (tbSpellcheckerButton && "updatePageDictionary" in tbSpellcheckerButton)
tbSpellcheckerButton.updatePageDictionary();
}
},
onTreeSelect: function() {
let selections = this.getTreeSelections();
let disabled = !selections.length;
document.getElementById("dict-button-remove").setAttribute("disabled", disabled);
document.getElementById("dict-button-edit").setAttribute("disabled", disabled || (this.tree.editingRow != -1));
},
handleEvent: function(aEvent) {
switch (aEvent.type) {
case "select":
this.onTreeSelect();
break;
case "yaStartEditing":
if (this.tree.editingRow != -1)
document.getElementById("info-box").setAttribute("visible", "true");
break;
case "yaStopEditing":
document.getElementById("info-box").setAttribute("visible", "false");
let changedData = aEvent.yaTextChangedData;
if (changedData.shouldAccept && changedData.textBefore != changedData.textAfter) {
if (changedData.textBefore)
this.personalDict.removeWord(changedData.textBefore, null);
if (changedData.textAfter) {
let rowIndex = changedData.row;
let words = changedData.textAfter
.replace(/^\s+/, '').replace(/\s+$/, '').replace(/\s+/g, ' ')
.split(/\s/)
.reverse()
.filter(
function(aWord) {
return aWord && !this.personalDict.check(aWord, null);
}, this
);
if (words.length) {
let word = words.pop();
this.tree.view.setCellText(rowIndex, changedData.column, word);
if (!this.personalDict.check(word, null))
this.personalDict.addWord(word, null);
} else {
this.removeRow(changedData.row);
}
let addedWordsLength = words.length;
words.forEach(function(aWord) {
if (!this.personalDict.check(aWord, null)) {
this.personalDict.addWord(aWord, null);
this.appendTreeItemForWord(aWord, rowIndex + 1);
} else {
addedWordsLength--;
}
}, this);
this.tree.view.selection.rangedSelect(rowIndex, rowIndex + addedWordsLength, false);
}
}
if (!changedData.textAfter || (!changedData.shouldAccept && !changedData.textBefore))
this.removeRow(changedData.row);
else
this.onChange();
this.onTreeSelect();
setTimeout(function(me) {
if (me && "tree" in me) {
let focused = document.commandDispatcher.focusedElement;
if (!focused || (focused instanceof Ci.nsIDOMHTMLInputElement))
if (focused)
focused.blur();
me.tree.focus();
}
}, 5, this);
break;
}
},
onChange: function() {
let saveButton = document.getElementById("dict-button-save");
if (saveButton.hasAttribute("disabled"))
saveButton.removeAttribute("disabled");
},
addRow: function() {
setTimeout(function(me) {
if (me && "_addRow" in me)
me._addRow();
}, 15, this);
},
_addRow: function() {
if (this.tree.editingRow != -1 && !this.tree.inputField.value)
return;
this.tree.stopEditing(true);
this.appendTreeItemForWord("");
let rowIndex = this.treechildren.childNodes.length - 1;
this.editRow(rowIndex);
},
editRow: function(aRowIndex) {
let rowIndex = arguments.length ? aRowIndex : Math.min(this.treechildren.childNodes.length - 1, this.tree.currentIndex);
if (rowIndex < 0)
return;
this.tree.view.selection.select(rowIndex);
this.tree.startEditing(rowIndex, this.tree.columns.getColumnAt(0));
this.onChange();
},
_removeRow: function(aRowIndex) {
let text = this.tree.view.getCellText(aRowIndex, this.tree.columns.getColumnAt(0));
if (text)
this.personalDict.removeWord(text, null);
},
removeRow: function(aRowIndex) {
let rowIndex = arguments.length ? aRowIndex : this.tree.currentIndex;
if (rowIndex < 0 || rowIndex > this.treechildren.childNodes.length - 1)
return;
this._removeRow(rowIndex);
this.treechildren.removeChild(this.treechildren.childNodes[rowIndex]);
this.tree.view.selection.select(rowIndex-1);
this.onChange();
},
removeRows: function() {
let selections = this.getTreeSelections();
let selectionsLen = selections.length;
if (!selectionsLen)
return;
let treechildren = this.treechildren;
let trChildNodes = treechildren.childNodes;
selections.reverse().forEach(function(aSelection) {
this._removeRow(aSelection);
treechildren.removeChild(trChildNodes[aSelection]);
}, this);
this.tree.view.selection.select(Math.min(treechildren.childNodes.length - 1, selections[selectionsLen-1]));
this.onChange();
},
buildDictList: function() {
let wordsArray = [];
let personalEnumerator = this.personalDict.wordList;
while (personalEnumerator.hasMore())
wordsArray.push(personalEnumerator.getNext());
wordsArray.sort().forEach(function(aWord) {
this.appendTreeItemForWord(aWord);
}, this);
},
getTreeSelections: function() {
let selections = [];
let select = this.tree.view.selection;
if (select) {
let childNodesLen = this.treechildren.childNodes.length;
if (childNodesLen) {
let count = select.getRangeCount();
let min = new Object();
let max = new Object();
for (let i = 0; i < count; i++) {
select.getRangeAt(i, min, max);
min = Math.max(0, min.value);
max = Math.min(childNodesLen-1, max.value);
for (let k = min; k <= max; k++) {
selections[selections.length] = k;
}
}
}
}
return selections;
},
appendTreeItemForWord: function(aWord, aIndex) {
let treeItem = document.createElement("treeitem");
let treeRow = document.createElement("treerow");
let treeCell = document.createElement("treecell");
treeCell.setAttribute("label", aWord);
treeRow.appendChild(treeCell);
treeItem.appendChild(treeRow);
if (typeof aIndex == "undefined" || !this.treechildren.childNodes.length)
this.treechildren.appendChild(treeItem);
else
this.treechildren.insertBefore(treeItem, this.treechildren.childNodes[aIndex]);
}
}