項目を列挙するAPI
git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5697 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
parent
3af4c5a8f1
commit
535c7b9f3e
@ -2,52 +2,62 @@
|
|||||||
UI Operations Global Undo History Manager
|
UI Operations Global Undo History Manager
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
var OH = window['piro.sakura.ne.jp'].operationHistory;
|
||||||
|
|
||||||
// window specific history
|
// window specific history
|
||||||
window['piro.sakura.ne.jp'].operationHistory.addEntry(
|
OH.addEntry(
|
||||||
'MyAddonFeature',
|
'MyAddonFeature',
|
||||||
{ label : 'Change tabbar position',
|
{ label : 'Change tabbar position',
|
||||||
onUndo : function() { ... },
|
onUndo : function() { ... },
|
||||||
onRedo : function() { ... } },
|
onRedo : function() { ... } },
|
||||||
window
|
window
|
||||||
);
|
);
|
||||||
window['piro.sakura.ne.jp'].operationHistory.undo('MyAddonFeature', window);
|
OH.undo('MyAddonFeature', window);
|
||||||
window['piro.sakura.ne.jp'].operationHistory.redo('MyAddonFeature', window);
|
OH.redo('MyAddonFeature', window);
|
||||||
|
|
||||||
// global history (not associated to window)
|
// global history (not associated to window)
|
||||||
window['piro.sakura.ne.jp'].operationHistory.addEntry(
|
OH.addEntry(
|
||||||
'MyAddonFeature',
|
'MyAddonFeature',
|
||||||
{ ... }
|
{ ... }
|
||||||
);
|
);
|
||||||
window['piro.sakura.ne.jp'].operationHistory.undo('MyAddonFeature');
|
OH.undo('MyAddonFeature');
|
||||||
|
|
||||||
// anonymous, window specific
|
// anonymous, window specific
|
||||||
window['piro.sakura.ne.jp'].operationHistory.addEntry({ ... }, window);
|
OH.addEntry({ ... }, window);
|
||||||
window['piro.sakura.ne.jp'].operationHistory.undo(window);
|
OH.undo(window);
|
||||||
|
|
||||||
// anonymous, global
|
// anonymous, global
|
||||||
window['piro.sakura.ne.jp'].operationHistory.addEntry({ ... });
|
OH.addEntry({ ... });
|
||||||
window['piro.sakura.ne.jp'].operationHistory.undo();
|
OH.undo();
|
||||||
|
|
||||||
// When you want to use "window" object in the global history,
|
// When you want to use "window" object in the global history,
|
||||||
// you should use the ID string instead of the "window" object
|
// you should use the ID string instead of the "window" object
|
||||||
// to reduce memory leak. For example...
|
// to reduce memory leak. For example...
|
||||||
var id = window['piro.sakura.ne.jp'].operationHistory.getWindowId(targetWindow);
|
var id = OH.getWindowId(targetWindow);
|
||||||
window['piro.sakura.ne.jp'].operationHistory.addEntry({
|
OH.addEntry({
|
||||||
onUndo : function() {
|
onUndo : function() {
|
||||||
// "this" in undo/redo functions refers the operationHistory service itself.
|
// "this" in undo/redo functions refers the operationHistory service itself.
|
||||||
var w = window['piro.sakura.ne.jp'].operationHistory.getWindowById(id);
|
var w = OH.getWindowById(id);
|
||||||
w.MyAddonService.undoSomething();
|
w.MyAddonService.undoSomething();
|
||||||
},
|
},
|
||||||
onRedo : ...
|
onRedo : ...
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// enumerate history entries
|
||||||
|
var history = OH.getHistory('MyAddonFeature', window); // options are same to undo/redo
|
||||||
|
OH.entries.forEach(function(aEntry, aIndex) {
|
||||||
|
var item = MyService.appendItem(aEntry.label);
|
||||||
|
if (aIndex == history.index)
|
||||||
|
item.setAttribute('checked', true);
|
||||||
|
});
|
||||||
|
|
||||||
lisence: The MIT License, Copyright (c) 2009-2010 SHIMODA "Piro" Hiroshi
|
lisence: The MIT License, Copyright (c) 2009-2010 SHIMODA "Piro" Hiroshi
|
||||||
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
|
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
|
||||||
original:
|
original:
|
||||||
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/operationHistory.js
|
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/operationHistory.js
|
||||||
*/
|
*/
|
||||||
(function() {
|
(function() {
|
||||||
const currentRevision = 2;
|
const currentRevision = 3;
|
||||||
|
|
||||||
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
|
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
|
||||||
|
|
||||||
@ -91,6 +101,12 @@
|
|||||||
history.index = entries.length-1;
|
history.index = entries.length-1;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getHistory : function()
|
||||||
|
{
|
||||||
|
var options = this._getOptionsFromArguments(arguments);
|
||||||
|
return options.history;
|
||||||
|
},
|
||||||
|
|
||||||
undo : function()
|
undo : function()
|
||||||
{
|
{
|
||||||
var options = this._getOptionsFromArguments(arguments);
|
var options = this._getOptionsFromArguments(arguments);
|
||||||
@ -240,7 +256,7 @@
|
|||||||
|
|
||||||
_getOptionsFromArguments : function(aArguments)
|
_getOptionsFromArguments : function(aArguments)
|
||||||
{
|
{
|
||||||
var w, name, data;
|
var w = null, name, data = null;
|
||||||
Array.slice(aArguments).some(function(aArg) {
|
Array.slice(aArguments).some(function(aArg) {
|
||||||
if (aArg instanceof Ci.nsIDOMWindow)
|
if (aArg instanceof Ci.nsIDOMWindow)
|
||||||
w = aArg;
|
w = aArg;
|
||||||
@ -255,9 +271,12 @@
|
|||||||
if (!name)
|
if (!name)
|
||||||
name = w ? 'window' : 'global' ;
|
name = w ? 'window' : 'global' ;
|
||||||
|
|
||||||
var windowId = this.getWindowId(window);
|
var tableName = encodeURIComponent(name);
|
||||||
|
|
||||||
|
var windowId = w ? this.getWindowId(window) : null ;
|
||||||
|
if (windowId)
|
||||||
|
tableName += '::'+windowId;
|
||||||
|
|
||||||
var tableName = w ? encodeURIComponent(name)+'::'+windowId : encodeURIComponent(name) ;
|
|
||||||
if (!(tableName in this._tables)) {
|
if (!(tableName in this._tables)) {
|
||||||
this._tables[tableName] = {
|
this._tables[tableName] = {
|
||||||
entries : [],
|
entries : [],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user