forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inlineEditForBookmarkTitleOnSidebar.uc.js
95 lines (78 loc) · 2.51 KB
/
inlineEditForBookmarkTitleOnSidebar.uc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// ==UserScript==
// @name inlineEditForBookmarkTitleOnSidebar.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description サイドバーにおいてブックマークのタイトルを直接編集できるようにする
// @include chrome://browser/content/bookmarks/bookmarksPanel.xul
// @compatibility Firefox 10-
// @author Alice0775
// @version 2012/02/06 編集終了Enterでブックマークが開かないように
// @version 2012/02/06
// @note ツリーの左端をF2またはダブルクリックでブックマークのタイトルの編集開始
// @note ブックマークフォルダはF2でタイトルの編集開始
// ==/UserScript==
var inlineEditForBookmarkTitleOnSidebar = {
get _BTree() {
delete this._BTree
return this._BTree = document.getElementById("bookmarks-view");
},
init: function(){
if (!this._BTree)
return;
var func = SidebarUtils.handleTreeKeyPress.toString();
func = func.replace(
'{',
<><![CDATA[
$&
var tree = aEvent.target.parentNode;
if (tree.editing)
return;
]]></>
);
//Replace function
SidebarUtils.handleTreeKeyPress = new Function(
func.match(/\((.*)\)\s*\{/)[1],
func.replace(/^function\s*.*\s*\(.*\)\s*\{/, '').replace(/}$/, '')
);
this._BTree.setAttribute('editable', true);
this._BTree.addEventListener('keypress', this, false);
window.addEventListener('unload', this, false);
},
uninit: function(){
if (!this._BTree)
return;
this._BTree.removeEventListener('keypress', this, false);
window.removeEventListener('unload', this, false);
this._BTree = null;
},
keypress: function(event) {
if (event.keyCode != KeyEvent.DOM_VK_F2)
return;
var tree = event.target;
if (tree.disabled)
return;
var b = tree.treeBoxObject;
var row = b.view.selection.currentIndex;
var col = tree.columns[0];
if (row == -1)
return;
if (tree.editable)
if (tree.startEditing(row, col))
event.preventDefault();
},
handleEvent: function(event) {
switch (event.type) {
case "keypress":
this.keypress(event);
break;
case "unload":
this.uninit();
break;
}
},
debug: function(aMsg){
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.logStringMessage(aMsg);
}
}
inlineEditForBookmarkTitleOnSidebar.init();