Replace some nsIWindowMediator getService() calls with Services.wm

This commit is contained in:
Dan Stillman 2018-02-27 14:13:35 -05:00
parent b0d9a9c82e
commit 68879a0ffc
3 changed files with 9 additions and 27 deletions

View File

@ -2188,9 +2188,7 @@ Zotero.CollectionTreeView.prototype.drop = Zotero.Promise.coroutine(function* (r
} }
*/ */
let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] let lastWin = Services.wm.getMostRecentWindow("navigator:browser");
.getService(Components.interfaces.nsIWindowMediator);
let lastWin = wm.getMostRecentWindow("navigator:browser");
lastWin.openDialog('chrome://zotero/content/merge.xul', '', 'chrome,modal,centerscreen', io); lastWin.openDialog('chrome://zotero/content/merge.xul', '', 'chrome,modal,centerscreen', io);
yield Zotero.DB.executeTransaction(function* () { yield Zotero.DB.executeTransaction(function* () {
@ -2244,9 +2242,7 @@ Zotero.CollectionTreeView.prototype.drop = Zotero.Promise.coroutine(function* (r
var url = data[i]; var url = data[i];
if (url.indexOf('file:///') == 0) { if (url.indexOf('file:///') == 0) {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] let win = Services.wm.getMostRecentWindow("navigator:browser");
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
// If dragging currently loaded page, only convert to // If dragging currently loaded page, only convert to
// file if not an HTML document // file if not an HTML document
if (win.content.location.href != url || if (win.content.location.href != url ||
@ -2264,9 +2260,7 @@ Zotero.CollectionTreeView.prototype.drop = Zotero.Promise.coroutine(function* (r
// Still string, so remote URL // Still string, so remote URL
if (typeof file == 'string') { if (typeof file == 'string') {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] let win = Services.wm.getMostRecentWindow("navigator:browser");
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack', null, row); // TODO: don't do this win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack', null, row); // TODO: don't do this
continue; continue;
} }

View File

@ -3211,9 +3211,7 @@ Zotero.ItemTreeView.prototype.drop = Zotero.Promise.coroutine(function* (row, or
else if (dataType == 'text/x-moz-url' || dataType == 'application/x-moz-file') { else if (dataType == 'text/x-moz-url' || dataType == 'application/x-moz-file') {
// Disallow drop into read-only libraries // Disallow drop into read-only libraries
if (!collectionTreeRow.editable) { if (!collectionTreeRow.editable) {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] let win = Services.wm.getMostRecentWindow("navigator:browser");
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
win.ZoteroPane.displayCannotEditLibraryMessage(); win.ZoteroPane.displayCannotEditLibraryMessage();
return; return;
} }
@ -3256,9 +3254,7 @@ Zotero.ItemTreeView.prototype.drop = Zotero.Promise.coroutine(function* (row, or
if (dataType == 'text/x-moz-url') { if (dataType == 'text/x-moz-url') {
var url = data[i]; var url = data[i];
if (url.indexOf('file:///') == 0) { if (url.indexOf('file:///') == 0) {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] let win = Services.wm.getMostRecentWindow("navigator:browser");
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
// If dragging currently loaded page, only convert to // If dragging currently loaded page, only convert to
// file if not an HTML document // file if not an HTML document
if (win.content.location.href != url || if (win.content.location.href != url ||
@ -3278,9 +3274,7 @@ Zotero.ItemTreeView.prototype.drop = Zotero.Promise.coroutine(function* (row, or
if (typeof file == 'string') { if (typeof file == 'string') {
if (parentItemID) { if (parentItemID) {
if (!collectionTreeRow.filesEditable) { if (!collectionTreeRow.filesEditable) {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] let win = Services.wm.getMostRecentWindow("navigator:browser");
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
win.ZoteroPane.displayCannotEditLibraryFilesMessage(); win.ZoteroPane.displayCannotEditLibraryFilesMessage();
return; return;
} }
@ -3295,9 +3289,7 @@ Zotero.ItemTreeView.prototype.drop = Zotero.Promise.coroutine(function* (row, or
}); });
} }
else { else {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] let win = Services.wm.getMostRecentWindow("navigator:browser");
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack'); // TODO: don't do this win.ZoteroPane.addItemFromURL(url, 'temporaryPDFHack'); // TODO: don't do this
} }
continue; continue;
@ -3318,9 +3310,7 @@ Zotero.ItemTreeView.prototype.drop = Zotero.Promise.coroutine(function* (row, or
} }
else { else {
if (file.leafName.endsWith(".lnk")) { if (file.leafName.endsWith(".lnk")) {
let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] let win = Services.wm.getMostRecentWindow("navigator:browser");
.getService(Components.interfaces.nsIWindowMediator);
let win = wm.getMostRecentWindow("navigator:browser");
win.ZoteroPane.displayCannotAddShortcutMessage(file.path); win.ZoteroPane.displayCannotAddShortcutMessage(file.path);
continue; continue;
} }

View File

@ -3310,9 +3310,7 @@ var ZoteroPane = new function()
else if (openInNewTab || !window.loadURI || uris.length > 1) { else if (openInNewTab || !window.loadURI || uris.length > 1) {
// if no gBrowser, find it // if no gBrowser, find it
if(!gBrowser) { if(!gBrowser) {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
.getService(Components.interfaces.nsIWindowMediator);
var browserWindow = wm.getMostRecentWindow("navigator:browser");
var gBrowser = browserWindow.gBrowser; var gBrowser = browserWindow.gBrowser;
} }