Disabling UI with a command element

Talk about code development, features, specific bugzilla bugs, enhancements, patches, and other highly technical things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific referenced Bugzilla bugs, mercurial, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Most "bug reports" do not belong in this board and should initially be posted in Community Support or other relevant support boards.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
Post Reply
User avatar
moonbat
Board Warrior
Board Warrior
Posts: 1603
Joined: 2015-12-09, 15:45

Disabling UI with a command element

Post by moonbat » 2020-05-08, 02:50

Per the documentation, commands are a special case of broadcaster and should be used with menu items and buttons. My extension has a menu item and a button to open a window, and I want them to be disabled while the window is open.

I'm using a command for both in the overlay like this -

Code: Select all

	<commandset>
		<command id="myCommand" />
	</commandset>
	<menupopup id="menu_ToolsPopup">
		<menuitem id="menu-id" class="menu-iconic"
			label="&menu-label;"
			insertafter="appmenu_addons" command="myCommand" />
	</menupopup>
	<toolbarpalette id="BrowserToolbarPalette">
		<toolbarbutton id="button-id"
			class="toolbarbutton-1 chromeclass-toolbar-additional"
			label="&button.label;"
			command="myCommand" />
	</toolbarpalette>
In the Javascript, I'm doing

Code: Select all

	openWindow: function() {
		var windowtype = "mywindow";
		var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
		var existingWindow = wm.getMostRecentWindow(windowtype);
		var windowref = null;
		if (existingWindow) {
			existingWindow.focus();
		}
		else {
			windowref = window.open("chrome://myextension/content/mywindow.xul", "mywindow",
				  "chrome,width=640,height=480,resizable=yes,dialog,alwaysRaised,centerscreen");
		}
		document.getElementById('myCommand').setAttribute("disabled","true");
		windowref.addEventListener("unload",closeWindow,false);
	},
	closeWindow:function (){
		console.log("Inside window close");
	    document.getElementById('CmdSetPMPlayerOpenWindow').removeAttribute("disabled");
	}
This doesn't work, neither does setting the disabled attribute to true or "true" - the UI elements stay enabled when the window is opened. Is the command set supposed to be used this way? I tried using a separate broadcaster element instead but that didn't work either.

Also, the window close listener is called twice, both when opening and closing, why?
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Linux Mint 20 Xfce x64 on HP i5 laptop with 12 GB RAM, always latest versions of PM & Basilisk unless specified.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 27036
Joined: 2011-08-28, 17:27
Location: 58°2'16"N 14°58'31"E
Contact:

Re: Disabling UI with a command element

Post by Moonchild » 2020-05-08, 07:28

Why aren't you disabling them from the window load event, instead?
"There will be times when the position you advocate, no matter how well framed and supported, will not be accepted by the public simply because you are who you are." -- Merrill Rose
Image

User avatar
moonbat
Board Warrior
Board Warrior
Posts: 1603
Joined: 2015-12-09, 15:45

Re: Disabling UI with a command element

Post by moonbat » 2020-05-08, 08:23

Do you mean the window load for the extension? The openWindow function is the window load handler for the extension's window, triggered by myCommand. So I want to disable the button after it has been clicked to open the window, and enable it again when the window is closed.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Linux Mint 20 Xfce x64 on HP i5 laptop with 12 GB RAM, always latest versions of PM & Basilisk unless specified.

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 27036
Joined: 2011-08-28, 17:27
Location: 58°2'16"N 14°58'31"E
Contact:

Re: Disabling UI with a command element

Post by Moonchild » 2020-05-08, 09:03

What I meant was disabling the button from the window you are opening, in the load handler in the opened window.
And enable it again in the unload handler of the window. So, let the pop-up control the button state.
"There will be times when the position you advocate, no matter how well framed and supported, will not be accepted by the public simply because you are who you are." -- Merrill Rose
Image

Post Reply