Disabling UI with a command element

Talk about code development, features, specific bugs, enhancements, patches, and similar 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 bugs, git, the repositories, 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. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

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.
User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4981
Joined: 2015-12-09, 15:45
Contact:

Disabling UI with a command element

Unread 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."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35630
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: Disabling UI with a command element

Unread post by Moonchild » 2020-05-08, 07:28

Why aren't you disabling them from the window load event, instead?
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4981
Joined: 2015-12-09, 15:45
Contact:

Re: Disabling UI with a command element

Unread 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."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35630
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: Disabling UI with a command element

Unread 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.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

Locked