forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenLibraryContextMenu.uc.xul
148 lines (127 loc) · 4.84 KB
/
openLibraryContextMenu.uc.xul
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?xml version="1.0" encoding="UTF-8"?>
<overlay id="openLibraryContextMenuOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<!--
// ==UserScript==
// @name openLibraryContextMenu.uc.xul
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description ブックマークのコンテキストメニューからLibraryを開く
// @include main
// @include chrome://browser/content/bookmarks/bookmarksPanel.xul
// @compatibility Firefox 3.0 3.5 3.6a1 3.7a1pre
// @author Alice0775
// @version 2009/08/17 01:55 見えるようにスクロール
// @version 2009/08/17 01:40 ブックマークのコンテキストメニューからLibraryを開く
// ==/UserScript==
-->
<script type="application/javascript" xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
var openLibraryContextMenu = {
node: null,
organizer:null,
get ios() {
return Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
},
get bmsvc() {
return Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
.getService(Components.interfaces.nsINavBookmarksService);
},
showOrganizer : function () {
var view = PlacesUIUtils.getViewForNode(document.popupNode);
this.node = view.selectedNode;
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
this.organizer = wm.getMostRecentWindow("Places:Organizer");
if (!this.organizer) {
this.organizer = openDialog("chrome://browser/content/places/places.xul",
"", "chrome,toolbar=yes,dialog=no,resizable");
this.organizer.addEventListener("load", this, false);
} else {
this.selectNode(this.node);
}
},
getParentFolderByItemId: function(aNode){
var parentFolderId = null;
var itemType = PlacesUtils.nodeIsFolder(aNode) ||
PlacesUtils.nodeIsTagQuery(aNode) ? "folder" : "bookmark";
var concreteId = PlacesUtils.getConcreteItemId(aNode);
var isRootItem = PlacesUtils.isRootItem(concreteId);
var itemId = aNode.itemId;
if (isRootItem || PlacesUtils.nodeIsTagQuery(aNode)) {
// If this is a root or the Tags query we use the concrete itemId to catch
// the correct title for the node.
itemId = concreteId;
}
//if (PlacesUtils.nodeIsBookmark(aNode)) {
parentFolderId = this.bmsvc.getFolderIdForItem(itemId);
//}
return parentFolderId;
},
selectNode: function(aNode) {
var itemType = PlacesUtils.nodeIsFolder(aNode) ||
PlacesUtils.nodeIsTagQuery(aNode) ? "folder" : "bookmark";
var concreteId = PlacesUtils.getConcreteItemId(aNode);
var isRootItem = PlacesUtils.isRootItem(concreteId);
var itemId = aNode.itemId;
if (isRootItem || PlacesUtils.nodeIsTagQuery(aNode)) {
// If this is a root or the Tags query we use the concrete itemId to catch
// the correct title for the node.
itemId = concreteId;
}
var isFolder = PlacesUtils.nodeIsFolder(aNode);
if (isFolder) {
this.selectLeftPane([itemId]);
} else if (PlacesUtils.nodeIsQuery(aNode)) {
var folderId = aNode.parent.itemId;
if (folderId){
this.selectLeftPane([folderId]);
}
this.selectRightPane([itemId]);
} else {
var folderId = this.getParentFolderByItemId(aNode);
if (folderId){
this.selectLeftPane([folderId]);
}
this.selectRightPane([itemId]);
}
setTimeout(function(self){
self.organizer.window.focus();
}, 1, this);
},
selectRightPane: function(rightPaneItemIds) {
var places = this.organizer.document.getElementById("placeContent");
places.selectItems(rightPaneItemIds, true);
var tbo = places.treeBoxObject;
tbo.ensureRowIsVisible(places.currentIndex);
},
selectLeftPane: function(leftPaneItemIds) {
var places = this.organizer.document.getElementById("placesList");
places.selectItems(leftPaneItemIds, true);
var tbo = places.treeBoxObject;
tbo.ensureRowIsVisible(places.currentIndex);
},
selectOnLoad: function() {
setTimeout(function(self){
self.selectNode(self.node);
}, 1, this);
this.organizer.removeEventListener("load", this, false);
},
handleEvent: function(event){
switch (event.type){
case 'load':
this.selectOnLoad(event);
break;
}
}
}
]]></script>
<!-- Firefox Bookmark Context Menu -->
<popup id="placesContext">
<menuitem id="placesContext_manageFolder" insertafter="placesContext_openLinks:tabs"
label="Organize Bookmark"
oncommand="openLibraryContextMenu.showOrganizer();"
selectiontype="single"
selection="bookmark|folder|query|livemark/feedURI"
accesskey="k;"
/>
</popup>
</overlay>