discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Library, Bundle or ...


From: Richard Frith-Macdonald
Subject: Re: Library, Bundle or ...
Date: Mon, 8 Jan 2007 19:52:30 +0000


On 8 Jan 2007, at 19:10, Philippe Roussel wrote:

On Sat, Jan 06, 2007 at 06:43:19AM +0000, Richard Frith-Macdonald wrote:
If your widgets have no resources (eg image files), you can first
build a library, but if they use resource files you should probably
start by building a bundle.  In fact it's probably good to build a
bundle even if there are no resource files used ... as a bundle does
not have to be linked into applications at compile time in order to
be usable.

After working on it a bit, I still don't get it. If I build my widgets
in a library, I just have to add

Agenda_LIBRARIES_DEPEND_UPON += -lAgendaWidgets

to my application GNUMakefile to use the widget, using a Gorm model or
not. But if I put my widgets in a bundle, I have to load the bundle
manually with code like this (I think)

NSBundle *bundle;
Class MonthView;

bundle = [NSBundle
bundleWithPath:@"/opt/gnustep/Local/Library/Bundles/ AgendaWidget.bundle"];
MonthView = [bundle principalClass];

How am I (or another developer reusing the widget) supposed to know
where is the bundle ?

The main advantage of a bundle is that you can include resources with it (image files etc) and easily move around the whole bundle to wherever you want it. (You also don't have to load it into your appplication unless you actually use it). The issue of locating resource files is resolved ... because they are inside the bundle and the NSBundle class provides standard methods for finding them. That means that all your application needs to do is locate the bundle which could be either inside your application (The NSBundle API helps you find them) or in a standard shared location if the bundle is to be shared by more than one application.

eg.
for a application local bundle ...

bundle = [NSBundle bundleWithPath: [[NSBundle mainBundle] pathForResource: @"AgendaWidget" ofType: @"bundle"]];

or to search all standard bundle locations ...

NSEnumerator *enumerator = [NSSearchPathForDirectoriesinDomains (NSLibraryDirectory, NSAllDomainsMask, YES) objectEnumerator];
NSString        *path;
while (bundle == nil && (path = [enumerator nextObject]) != nil)
  {
bundle = [NSBundle bundleWithPath: [path stringByAppendingPathComponent: @"Bundles/AgendaWidget.bundle"]];
  }

Same question goes for a Gorm palette.

A palette is unrelated to locating the library/bundle, as you don't load it into your application. Your application uses a library or bundle to get the code, and Gorm uses the palette when you design/ build the application user interface. To load a palette into Gorm you just click the 'Tools' menu item, then 'Load palette', then select the palette you wish to use in the open panel. Alternatively, you can set a list of palettes (full paths to the palettes) in the user defaults as an array keyed on 'USER_PALETTES' and Gorm will load these automatically at startup.

In short,
I don't see the advantages of a bundle in this case. May I'm confused...

Well, it depends on your code ... what I wrote in response to your original email was:

If your widgets have no resources (eg image files), you can first build a library, but if they use resource files you should probably start by building a bundle.

ie a bundle is best if you have other resources associated with the code, but a library is simpler if you don't. If you don't have any resource files, and are unlikely to ever add any, then using a library is the way to go.
If you do have resource files, make a bundle.

Developers should be able to handle either case easily.







reply via email to

[Prev in Thread] Current Thread [Next in Thread]