mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 18:42:27 +01:00
Move marks to storage module.
This commit is contained in:
@@ -790,8 +790,7 @@ liberator.QuickMarks = function () //{{{
|
|||||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
liberator.storage.newObject("quickmarks", true);
|
var qmarks = liberator.storage.newMap("quickmarks", true);
|
||||||
var qmarks = liberator.storage.quickmarks;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////}}}
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
////////////////////// MAPPINGS ////////////////////////////////////////////////
|
////////////////////// MAPPINGS ////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -911,12 +911,13 @@ liberator.Buffer = function () //{{{
|
|||||||
elem.focus();
|
elem.focus();
|
||||||
|
|
||||||
var evt = doc.createEvent("MouseEvents");
|
var evt = doc.createEvent("MouseEvents");
|
||||||
evt.initMouseEvent("mousedown", true, true, view, 1, offsetX, offsetY, 0, 0, /*ctrl*/ newTab, /*event.altKey*/0, /*event.shiftKey*/ newWindow, /*event.metaKey*/ newTab, 0, null);
|
for each (event in ["mousedown", "mouseup", "click"])
|
||||||
elem.dispatchEvent(evt);
|
{
|
||||||
evt.initMouseEvent("mouseup", true, true, view, 1, offsetX, offsetY, 0, 0, /*ctrl*/ newTab, /*event.altKey*/0, /*event.shiftKey*/ newWindow, /*event.metaKey*/ newTab, 0, null);
|
evt.initMouseEvent(event, true, true, view, 1, offsetX, offsetY,
|
||||||
elem.dispatchEvent(evt);
|
0, 0, /*ctrl*/ newTab, /*event.altKey*/0, /*event.shiftKey*/ newWindow,
|
||||||
evt.initMouseEvent("click", true, true, view, 1, offsetX, offsetY, 0, 0, /*ctrl*/ newTab, /*event.altKey*/0, /*event.shiftKey*/ newWindow, /*event.metaKey*/ newTab, 0, null);
|
/*event.metaKey*/ newTab, 0, null);
|
||||||
elem.dispatchEvent(evt);
|
elem.dispatchEvent(evt);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
saveLink: function (elem, skipPrompt)
|
saveLink: function (elem, skipPrompt)
|
||||||
@@ -1423,8 +1424,9 @@ liberator.Marks = function () //{{{
|
|||||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
var localMarks = {};
|
var localMarks = liberator.storage.newMap('local-marks', true);
|
||||||
var urlMarks = {};
|
var urlMarks = liberator.storage.newMap('url-marks', true);
|
||||||
|
|
||||||
var pendingJumps = [];
|
var pendingJumps = [];
|
||||||
var appContent = document.getElementById("appcontent");
|
var appContent = document.getElementById("appcontent");
|
||||||
|
|
||||||
@@ -1437,7 +1439,7 @@ liberator.Marks = function () //{{{
|
|||||||
for (var i = 0, length = pendingJumps.length; i < length; i++)
|
for (var i = 0, length = pendingJumps.length; i < length; i++)
|
||||||
{
|
{
|
||||||
var mark = pendingJumps[i];
|
var mark = pendingJumps[i];
|
||||||
if (win.location.href == mark.location)
|
if (win && win.location.href == mark.location)
|
||||||
{
|
{
|
||||||
win.scrollTo(mark.position.x * win.scrollMaxX, mark.position.y * win.scrollMaxY);
|
win.scrollTo(mark.position.x * win.scrollMaxX, mark.position.y * win.scrollMaxY);
|
||||||
pendingJumps.splice(i, 1);
|
pendingJumps.splice(i, 1);
|
||||||
@@ -1446,19 +1448,27 @@ liberator.Marks = function () //{{{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function markToString(name, mark)
|
||||||
|
{
|
||||||
|
return name + " | " + mark.location +
|
||||||
|
" | (" + mark.position.x + ", " + mark.position.y + ")" +
|
||||||
|
('tab' in mark) ? " | tab: " + liberator.tabs.index(mark.tab) : "";
|
||||||
|
}
|
||||||
|
|
||||||
function removeLocalMark(mark)
|
function removeLocalMark(mark)
|
||||||
{
|
{
|
||||||
if (mark in localMarks)
|
var localmark = localMarks.get(mark);
|
||||||
|
if (localmark)
|
||||||
{
|
{
|
||||||
var win = window.content;
|
var win = window.content;
|
||||||
for (var i = 0; i < localMarks[mark].length; i++)
|
for (var [i,] in Iterator(localmark))
|
||||||
{
|
{
|
||||||
if (localMarks[mark][i].location == win.location.href)
|
if (localmark[i].location == win.location.href)
|
||||||
{
|
{
|
||||||
liberator.log("Deleting local mark: " + mark + " | " + localMarks[mark][i].location + " | (" + localMarks[mark][i].position.x + ", " + localMarks[mark][i].position.y + ") | tab: " + liberator.tabs.index(localMarks[mark][i].tab), 5);
|
liberator.log("Deleting local mark: " + markToString(mark, localmark[i]), 5);
|
||||||
localMarks[mark].splice(i, 1);
|
localmark.splice(i, 1);
|
||||||
if (localMarks[mark].length == 0)
|
if (localmark.length == 0)
|
||||||
delete localMarks[mark];
|
localMarks.remove(mark);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1467,10 +1477,11 @@ liberator.Marks = function () //{{{
|
|||||||
|
|
||||||
function removeURLMark(mark)
|
function removeURLMark(mark)
|
||||||
{
|
{
|
||||||
if (mark in urlMarks)
|
var urlmark = urlMarks.get(mark);
|
||||||
|
if (urlmark)
|
||||||
{
|
{
|
||||||
liberator.log("Deleting URL mark: " + mark + " | " + urlMarks[mark].location + " | (" + urlMarks[mark].position.x + ", " + urlMarks[mark].position.y + ") | tab: " + liberator.tabs.index(urlMarks[mark].tab), 5);
|
liberator.log("Deleting URL mark: " + markToString(mark, urlmark), 5);
|
||||||
delete urlMarks[mark];
|
urlMarks.remove(mark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1491,14 +1502,14 @@ liberator.Marks = function () //{{{
|
|||||||
// local marks
|
// local marks
|
||||||
lmarks = [[[mark, value[i]] for (i in value)
|
lmarks = [[[mark, value[i]] for (i in value)
|
||||||
if (value[i].location == window.content.location.href)]
|
if (value[i].location == window.content.location.href)]
|
||||||
for ([mark, value] in Iterator(localMarks))];
|
for ([mark, value] in localMarks)];
|
||||||
lmarks = Array.concat.apply(Array, lmarks);
|
lmarks = Array.concat.apply(Array, lmarks);
|
||||||
lmarks.sort();
|
lmarks.sort();
|
||||||
|
|
||||||
// URL marks
|
// URL marks
|
||||||
// FIXME: why does umarks.sort() cause a "Component is not available =
|
// FIXME: why does umarks.sort() cause a "Component is not available =
|
||||||
// NS_ERROR_NOT_AVAILABLE" exception when used here?
|
// NS_ERROR_NOT_AVAILABLE" exception when used here?
|
||||||
umarks = [[key, mark] for ([key, mark] in Iterator(urlMarks))];
|
umarks = [[key, mark] for ([key, mark] in urlMarks)];
|
||||||
umarks.sort(function (a, b) a[0].localeCompare(b[0]));
|
umarks.sort(function (a, b) a[0].localeCompare(b[0]));
|
||||||
|
|
||||||
return lmarks.concat(umarks);
|
return lmarks.concat(umarks);
|
||||||
@@ -1635,17 +1646,18 @@ liberator.Marks = function () //{{{
|
|||||||
|
|
||||||
if (isURLMark(mark))
|
if (isURLMark(mark))
|
||||||
{
|
{
|
||||||
liberator.log("Adding URL mark: " + mark + " | " + win.location.href + " | (" + position.x + ", " + position.y + ") | tab: " + liberator.tabs.index(liberator.tabs.getTab()), 5);
|
urlMarks.set(mark, { location: win.location.href, position: position, tab: liberator.tabs.getTab() });
|
||||||
urlMarks[mark] = { location: win.location.href, position: position, tab: liberator.tabs.getTab() };
|
liberator.log("Adding URL mark: " + markToString(mark, urlMarks.get(mark)), 5);
|
||||||
}
|
}
|
||||||
else if (isLocalMark(mark))
|
else if (isLocalMark(mark))
|
||||||
{
|
{
|
||||||
// remove any previous mark of the same name for this location
|
// remove any previous mark of the same name for this location
|
||||||
removeLocalMark(mark);
|
removeLocalMark(mark);
|
||||||
if (!localMarks[mark])
|
if (!localMarks.get(mark))
|
||||||
localMarks[mark] = [];
|
localMarks.set(mark, []);
|
||||||
liberator.log("Adding local mark: " + mark + " | " + win.location.href + " | (" + position.x + ", " + position.y + ")", 5);
|
let vals = { location: win.location.href, position: position };
|
||||||
localMarks[mark].push({ location: win.location.href, position: position });
|
localMarks.get(mark).push(vals);
|
||||||
|
liberator.log("Adding local mark: " + markToString(mark, vals), 5);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1654,18 +1666,18 @@ liberator.Marks = function () //{{{
|
|||||||
if (special)
|
if (special)
|
||||||
{
|
{
|
||||||
// :delmarks! only deletes a-z marks
|
// :delmarks! only deletes a-z marks
|
||||||
for (var mark in localMarks)
|
for (var [mark,] in localMarks)
|
||||||
removeLocalMark(mark);
|
removeLocalMark(mark);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var pattern = new RegExp("[" + filter.replace(/\s+/g, "") + "]");
|
var pattern = new RegExp("[" + filter.replace(/\s+/g, "") + "]");
|
||||||
for (var mark in urlMarks)
|
for (var [mark,] in urlMarks)
|
||||||
{
|
{
|
||||||
if (pattern.test(mark))
|
if (pattern.test(mark))
|
||||||
removeURLMark(mark);
|
removeURLMark(mark);
|
||||||
}
|
}
|
||||||
for (var mark in localMarks)
|
for (var [mark,] in localMarks)
|
||||||
{
|
{
|
||||||
if (pattern.test(mark))
|
if (pattern.test(mark))
|
||||||
removeLocalMark(mark);
|
removeLocalMark(mark);
|
||||||
@@ -1679,10 +1691,10 @@ liberator.Marks = function () //{{{
|
|||||||
|
|
||||||
if (isURLMark(mark))
|
if (isURLMark(mark))
|
||||||
{
|
{
|
||||||
var slice = urlMarks[mark];
|
var slice = urlMarks.get(mark);
|
||||||
if (slice && slice.tab && slice.tab.linkedBrowser)
|
if (slice && slice.tab && slice.tab.linkedBrowser)
|
||||||
{
|
{
|
||||||
if (!slice.tab.parentNode)
|
if (slice.tab.parentNode != getBrowser().tabContainer)
|
||||||
{
|
{
|
||||||
pendingJumps.push(slice);
|
pendingJumps.push(slice);
|
||||||
// NOTE: this obviously won't work on generated pages using
|
// NOTE: this obviously won't work on generated pages using
|
||||||
@@ -1701,7 +1713,7 @@ liberator.Marks = function () //{{{
|
|||||||
win.location.href = slice.location;
|
win.location.href = slice.location;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
liberator.log("Jumping to URL mark: " + mark + " | " + slice.location + " | (" + slice.position.x + ", " + slice.position.y + ") | tab: " + liberator.tabs.index(slice.tab), 5);
|
liberator.log("Jumping to URL mark: " + markToString(mark, slice), 5);
|
||||||
win.scrollTo(slice.position.x * win.scrollMaxX, slice.position.y * win.scrollMaxY);
|
win.scrollTo(slice.position.x * win.scrollMaxX, slice.position.y * win.scrollMaxY);
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
@@ -1710,13 +1722,13 @@ liberator.Marks = function () //{{{
|
|||||||
else if (isLocalMark(mark))
|
else if (isLocalMark(mark))
|
||||||
{
|
{
|
||||||
var win = window.content;
|
var win = window.content;
|
||||||
var slice = localMarks[mark] || [];
|
var slice = localMarks.get(mark) || [];
|
||||||
|
|
||||||
for (var i = 0; i < slice.length; i++)
|
for (var i = 0; i < slice.length; i++)
|
||||||
{
|
{
|
||||||
if (win.location.href == slice[i].location)
|
if (win.location.href == slice[i].location)
|
||||||
{
|
{
|
||||||
liberator.log("Jumping to local mark: " + mark + " | " + slice[i].location + " | (" + slice[i].position.x + ", " + slice[i].position.y + ")", 5);
|
liberator.log("Jumping to local mark: " + markToString(mark, slice), 5);
|
||||||
win.scrollTo(slice[i].position.x * win.scrollMaxX, slice[i].position.y * win.scrollMaxY);
|
win.scrollTo(slice[i].position.x * win.scrollMaxX, slice[i].position.y * win.scrollMaxY);
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -255,9 +255,8 @@ liberator.Events = function () //{{{
|
|||||||
var inputBufferLength = 0; // count the number of keys in v.input.buffer (can be different from v.input.buffer.length)
|
var inputBufferLength = 0; // count the number of keys in v.input.buffer (can be different from v.input.buffer.length)
|
||||||
var skipMap = false; // while feeding the keys (stored in v.input.buffer | no map found) - ignore mappings
|
var skipMap = false; // while feeding the keys (stored in v.input.buffer | no map found) - ignore mappings
|
||||||
|
|
||||||
liberator.storage.newObject('macros', false);
|
var macros = liberator.storage.newMap('macros', true);
|
||||||
|
|
||||||
var macros = liberator.storage.macros;
|
|
||||||
var currentMacro = "";
|
var currentMacro = "";
|
||||||
var lastMacro = "";
|
var lastMacro = "";
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ liberator.Options = function () //{{{
|
|||||||
opt.set(opt.value, liberator.options.OPTION_SCOPE_GLOBAL)
|
opt.set(opt.value, liberator.options.OPTION_SCOPE_GLOBAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
liberator.storage.newObject("options", false);
|
liberator.storage.newMap("options", false);
|
||||||
liberator.storage.addObserver("options", optionObserver);
|
liberator.storage.addObserver("options", optionObserver);
|
||||||
|
|
||||||
function storePreference(name, value)
|
function storePreference(name, value)
|
||||||
|
|||||||
@@ -191,20 +191,20 @@ var storage = {
|
|||||||
this.__defineGetter__(key, function () keys[key]);
|
this.__defineGetter__(key, function () keys[key]);
|
||||||
},
|
},
|
||||||
|
|
||||||
newObject: function newObject(key, store)
|
newMap: function newMap(key, store)
|
||||||
{
|
{
|
||||||
// TODO: Add type checking.
|
// TODO: Add type checking.
|
||||||
if (key in keys)
|
if (!(key in keys))
|
||||||
return;
|
|
||||||
this._addKey(key, new ObjectStore(key, store));
|
this._addKey(key, new ObjectStore(key, store));
|
||||||
|
return this[key];
|
||||||
},
|
},
|
||||||
|
|
||||||
newArray: function newArray(key, store)
|
newArray: function newArray(key, store)
|
||||||
{
|
{
|
||||||
// TODO: Add type checking.
|
// TODO: Add type checking.
|
||||||
if (key in keys)
|
if (!(key in keys))
|
||||||
return;
|
|
||||||
this._addKey(key, new ArrayStore(key, store));
|
this._addKey(key, new ArrayStore(key, store));
|
||||||
|
return this[key];
|
||||||
},
|
},
|
||||||
|
|
||||||
addObserver: function addObserver(key, callback)
|
addObserver: function addObserver(key, callback)
|
||||||
|
|||||||
Reference in New Issue
Block a user