Page 1 of 1

Creating a module for use by widgets?

Posted: Thu Sep 24, 2015 5:17 am
by trevordevore
I have a number of UI widgets now. I would like to move common handlers to a separate module. I want the handlers defined in the module to be accessible to widgets the <use> it. I don't want it in the message path of LCS. I tried the following code in an .lcb file as I thought a <module> would accomplish what I want:

Code: Select all

module com.livecode.extensions.xyz.uicontrol

use com.livecode.canvas
use com.livecode.engine

public handler AdjustColorForEnabledState(in pColor as Color, in pEnabled as Boolean) returns Color
   if pEnabled then
		set the alpha of pColor to 1
	else
		set the alpha of pColor to 0.5
	end if
end handler

end module
When trying to <Test> with the Extension Builder I get the following error:

Code: Select all

12:13 AM: Fetching metadata from /Users/xyz/lc-modules/UIControl/manifest.xml
12:13 AM: Error: couldn't retrieve extension type from manifest /Users/xyz/lc-modules/UIControl/manifest.xml
12:13 AM: Error: Could not compile module /Users/xyz/lc-modules/UIControl
Is there a way to accomplish what I'm after? If so, what is the correct way?

Re: Creating a module for use by widgets?

Posted: Thu Sep 24, 2015 9:36 am
by livecodeali
Hi Trevor,

Funnily enough, I just did this for our widgets:
https://github.com/livecode/livecode-ide/pull/511

and uncovered the fact that modules when compiled don't output a type field to the manifest.
That's what's causing the bug.

This https://github.com/livecode/livecode-ide/pull/511 works around it, but I think the proper fix is to have modules declare themselves to be of module type.

Re: Creating a module for use by widgets?

Posted: Thu Sep 24, 2015 10:18 am
by livecodeali
Ok, here is the correct fix.

https://github.com/livecode/livecode/pull/2918

If your module identifier has three components, you will have still have an issue with the IDE thinking the module is builtin and therefore not trying to load it. I will try to fix that asap.

Re: Creating a module for use by widgets?

Posted: Thu Sep 24, 2015 4:07 pm
by trevordevore
Thanks @livecodeali. It works!

One other question - right now it seems that if I want to change my shared module I have to uninstall it, quit LiveCode, make my code changes, relaunch LiveCode, and then reinstall it. Is there an easier way?

Re: Creating a module for use by widgets?

Posted: Sat Sep 26, 2015 5:08 pm
by livecodeali
Hmm, good question. I suspect because your other loaded modules have references to it, there currently isn't a way of doing that. I presume you've tried doing this via the extension builder without restarting and it said "Error: module with that name already loaded" or something similar?

Re: Creating a module for use by widgets?

Posted: Sat Sep 26, 2015 9:13 pm
by trevordevore
I don't get any errors from the Extensions Builder. It appears as if everything worked but my changes don't show up. I just tested again and I don't have to go through the uninstall step. But I do have to restart.