wshanks / Zutilo

Zotero plugin providing some additional editing features
Other
1.53k stars 72 forks source link

Add "Zutilo Preferences" to menu #64

Closed gracile-fr closed 7 years ago

gracile-fr commented 7 years ago

Because, in Zotero 5.0, "the Actions (gear icon) menu has been removed from the toolbar, as all options are now available in menus. "Zutilo Preferences" is added after "Zotero Preferences" which is under "Edit" on Mac OS / Linux and under "Tools" on Windows. See #61

wshanks commented 7 years ago

Thanks! I merged your new function into the old so that it is more clear that it is a 4 vs. 5 issue and I can remove the version 4 only code at a later time.

jlegewie commented 7 years ago

I am using Zutilo 2.0.2 with Zotero 5.0.3.beta and don't see any Zutilo Preferences in the menu bar. I am also asking because I haven't figured this out for zotfile. Zotero preferences are now under the zotero menu on Mac OS but I have problems placing the zotfile preferences there.

wshanks commented 7 years ago

Yeah, sorry (especially to @gracile-fr who is responsible for most of the work), I have been negligent about putting out a new version. The changes discussed here were merged after the last release of Zutilo. I will try to generate a new release tonight if I have time. The main hold up has been that I wanted to automate the release process more, but I haven't had time to do that.

jlegewie commented 7 years ago

Can you point at the relevant commit for this?

wshanks commented 7 years ago

Sorry I didn't have time to do the release tonight. The commits are just the ones above:

https://github.com/willsALMANJ/Zutilo/pull/64/commits/226af439a45861a87ae8efaaf4371116f6104391 https://github.com/willsALMANJ/Zutilo/pull/64/commits/d1e1e23a90192b9a656faca496d0f64e19d8b314

I haven't had a chance to test yet to see if the menu still works in Zotero 5.0. It woorked several months ago. @gracile-fr could possibly add more since gracile submitted PR's for both ZotFile and Zutilo about this.

wshanks commented 7 years ago

I just tested and the current master for Zutilo puts the "Zutilo Preferences" menu item below Zotero's "Preferences" menu item in the global menu bar. @gracile-fr and I found that the particular menu these menu items appear in is OS-dependent (see #61) -- "Edit" on Linux (and probably macOS) and "Tools" on Windows. It seems that the OS-independent id for the menu is menu_preferences, so make sure you are using that. Maybe ZotFile is putting the preferences menu item under Tools which works for Windows but not macOS?

wshanks commented 7 years ago

I linked to the wrong issue at first in the previous comment. I edited it to point to the right place now (#61).

gracile-fr commented 7 years ago

The location of "Zotero Preferences" has changed for Windows, not for MacOS (and we have been wrong from the beginning about it). Windows/Linux : Edit->Preferences MacOS: Zotero menu->Preferences

How does the "Zutilo prefs" menu item behave on MacOS at the moment? I can't test. @jlegewie ?

jlegewie commented 7 years ago

It's under the File menu on Mac OS. It should be under the Zotero menu. I tried to make that happen with zotfile but had problems. I think the Zotero menu is not initialized in XUL but later created or something.

wshanks commented 7 years ago

@gracile-fr I don't think that we were wrong from the beginniing, though maybe I misunderstand what you mean. The thread you link to is only 10 days old whereas we made these changes several months ago. It looks like the change for Windows was merged in a few days ago here: https://github.com/zotero/zotero/issues/1167.

The Preferences menu item was placed in different locations on Windows, macOS, and Linux and now the Windows location was moved to match the Linux one. I think the way we added the Zutilo preferences menu item should be unaffected by all this variation because the Zotero preferences menu item is always called menu_preferenes and Zutilo gets that item by id and then inserts its own preferences menu item into the parent of menu_preferences. I can't check on Windows or macOS right now -- if anyone else can that would be nice.

Zutilo inserts its menu item dynamically, so I'm not sure about what XUL overlay method would work. It seems like it should be menu_FilePopup on macOS: https://github.com/zotero/zotero/blob/52680608023189226502ab11fa2f4e5a93c73b97/chrome/content/zotero-platform/mac/standalone/menuOverlay.xul#L83

jlegewie commented 7 years ago

For macOS: I think the problem is that menu_preferenes is initially paced under the file menu in Zotero and then moved to the Zotero menu. So the problem might be that Zutilo places the menu before the moving happens and therefore ends up in the File menu. But that is just a theory.

wshanks commented 7 years ago

I see. That seems right. There is a comment in the overlay that says they are hidden by nsMenuBarX:

https://github.com/zotero/zotero/blob/9c0befceeb2dfd10154b0cb6498dfd2b8f308b16/chrome/content/zotero-platform/mac/standalone/menuOverlay.xul

and here is nsMenuBarX.mm:

https://dxr.mozilla.org/comm-esr52/source/mozilla/widget/cocoa/nsMenuBarX.mm

Have you made any progress on this so far? I don't have easy access to a Mac so it is hard to test.

Right now, Zutilo loads its chrome at startup (whenever bootstrap.js gets called):

https://github.com/willsALMANJ/Zutilo/blob/791d5d519ba7a81aba15bfbc52fb82f12af4bb02/addon/chrome/content/zutilo/zutilo.jsm#L96

and this also adds an onOpenWindow listener that adds a load event listener.

I'm not sure about the timing of the following:

I guess I could test the timing of some of those but not the preferences moving part. Can you try making a Zotero context menu item that adds the ZotFile preferences menu to see if it finds the right place after the Zotero preferences item has definitely moved to application menu?

Maybe @dstillman has an idea for what to do?

wshanks commented 7 years ago

Actually, the timing might not be that important if the preferences menu item is already moved to the application menu before the addon code runs. The application menu belongs to a hidden window, so a script that modifies the content of the window it is run in will not work. The code needs to search for the hidden main window and add the item there. Something like the prepareWindows() method in zutilo.jsm might work:

   var windows = Services.wm.getEnumerator('navigator:browser');
   while (windows.hasMoreElements()) {
       this.loadWindowChrome(windows.getNext());
   }

If the hidden window is not navigator:browser, then that would be removed so it's just Services.wm.getEnumerator() and loops over all windows. Then the command in place of this.loadWindowChrome() could check for menu_preferences in each window and insert our menu item for any window that has a menu_preferences item. Or we could figure out what type of window the hidden one is instead of navigator:browser.

jlegewie commented 7 years ago

I tried this approach based on your suggestions but it places the zotfile preferences under the File menu on macOS.

var windows = Services.wm.getEnumerator('navigator:browser');
while (windows.hasMoreElements()) {
    var win = windows.getNext();
    var zoteroPrefsItem = win.document.getElementById('menu_preferences');
    if (zoteroPrefsItem === null) break;
    // Add Zotfile preferences item after Zotero preferences menu item
    var zoteroPrefsMenu = zoteroPrefsItem.parentElement;
    if (zoteroPrefsMenu === null) return;
    var zotfileMenuItem = win.document.createElement('menuitem');
    zotfileMenuItem.setAttribute('id', 'zotfile-options');
    zotfileMenuItem.setAttribute('label', Zotero.ZotFile.ZFgetString('menu.preferences'));
    zotfileMenuItem.addEventListener('command', Zotero.ZotFile.openPreferenceWindow);
    zoteroPrefsMenu.insertBefore(zotfileMenuItem, zoteroPrefsItem.nextSibling);
}
wshanks commented 7 years ago

Hmm, okay. That makes me wonder if an addon has the ability to manipulate the application menu.

dstillman commented 7 years ago

That makes me wonder if an addon has the ability to manipulate the application menu.

I would be quite surprised if you could. But it doesn't seem particularly appropriate or necessary on macOS — that's where the application prefs go, but it would be sort of surprising for a plugin to put its prefs there.

wshanks commented 7 years ago

Thanks @dstillman

@jlegewie does Zutilo's preferences menu end up in the File menu as well? I can move the menu wherever seems appropriate, but I don't know how the interface looks different on macOS. It's nice to put it somewhere to save a click, but the preferences are also accessible from the addons manager, so it's not that big of a deal.

jlegewie commented 7 years ago

Yes, Zutilo's preference menu is under the File menu:

screen shot 2017-07-24 at 6 06 18 am

I think the plugin preferences fit better under the Tools menu. That's also consistent with Windows. Maybe with a separator but we shouldn't create two.

screen shot 2017-07-24 at 6 06 29 am
dstillman commented 7 years ago

Yes, Tools would be better.

wshanks commented 7 years ago

Okay, in Zutilo, I can check if the nodeName of the nextSibling of menu_openAddons is menuseparator and if not insert a menu separator and otherwise just insert the Zutilo preference item after the separator that was already there. You'd probably want to do the same in ZotFile.

gracile-fr commented 7 years ago

( @willsALMANJ : Re "I don't think that we were wrong from the beginniing, though maybe I misunderstand what you mean." – I just wanted to say that we didn't know the Zotero Prefs were in the Application menu on MacOS)