Test for debug vs release

2010-03-20 Thread BareFeet
Hi all,

OK, I'm missing something obvious here.

How can I test whether my program is running in debug or release? I'd like to 
wrap a bunch of log file writes in an if statement so it only bothers if I'm 
debugging?

How can I detect debug at compile time? (eg #if ISDEBUGGING)

How can I detect at runtime?

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSForegroundColorAttributeName without AppKit

2010-03-01 Thread BareFeet
Thanks Graham for your reply:

 I have some working code for adding attributes to a string. I'd like to 
 modify it so it will work without needing AppKit. I can get it all going 
 except the NSForegroundColorAttributeName constant which seems to only exist 
 in AppKit.
 
 If you log the actual value of that constant, it's simply @NSColor.

Unfortunately it seems that using the @NSColor key as part of an 
NSAttributedString also requires AppKit. Put another way, I can't see any way 
to draw multi-colored text in a wrapping text field without using AppKit.

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSForegroundColorAttributeName without AppKit

2010-02-19 Thread BareFeet
Hi all,

I have some working code for adding attributes to a string. I'd like to modify 
it so it will work without needing AppKit. I can get it all going except the 
NSForegroundColorAttributeName constant which seems to only exist in AppKit.

Here's an example:

NSColor* tokenColor = [NSColor red];
NSDictionary* tokenAttributesDict = [NSDictionary 
dictionaryWithObject:tokenColor forKey:NSForegroundColorAttributeName];
NSRange tokenRange = NSMakeRange(startCharN, [token length]);
[tokenizedAttributedString addAttributes:tokenAttributesDict range:tokenRange];

Is there an alternative to NSForegroundColorAttributeName I can use without 
needing AppKit?

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Binding to an accessor that is only valid for subclass

2010-02-02 Thread BareFeet
Hi All,

 You can also uncheck the Raises For Not Applicable Keys in the bindings 
 inspector pain in Interface Builder for your text fields.
 
 Thanks for the tip. Once I read it, it seemed like the logical solution. 
 However, it doesn't seem to make any difference.

After some further investigation, turning off Raises For Not Applicable Keys 
does actually work and solves my problem. Hooray! :-)

It wasn't making any difference previously because my model key path was 
something like parsedDictionary.subValue. Even with Raises For Not Applicable 
Keys disabled, I still got an error like:

HIToolbox: ignoring exception '[TopClass 0x100488c30 
addObserver:NSKeyValueObservance 0x10048c1a0 
forKeyPath:@parsedDictionary.subValue options:0x100 context:0x0] was sent to 
an object that is not KVC-compliant for the parsedDictionary property.' that 
raised inside Carbon event dispatch

So I added a routine to my code for the SubClass:

- (NSString*) subValue
{
return [parsedDictionary objectForKey:@subValue];
}

and changed the bindings in IB for the text field to simply have the model key 
path: subValue

Thanks again to John and Jerry for replying.

Thanks,
Tom
BareFeet

 --
Comparison of SQLite GUI tools:
http://www.tandb.com.au/sqlite/compare/?ml

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Binding to an accessor that is only valid for subclass (was: Node hierarchy with subclasses)

2010-02-01 Thread BareFeet
 On Jan 29, 2010, at 9:38 AM, Jerry Krinock wrote:
 
 
 The problem is that when a subclass A is selected, the UI elements bound to 
 subclass B no longer have valid bindings so generate an error. How can I 
 solve this?
 
 You can also uncheck the Raises For Not Applicable Keys in the bindings 
 inspector pain in Interface Builder for your text fields.

Thanks for the tip. Once I read it, it seemed like the logical solution. 
However, it doesn't seem to make any difference. All I could find in the 
documentation about that checkbox/attribute was:

NSRaisesForNotApplicableKeysBindingOption
An NSNumber object containing a Boolean value that specifies if an exception is 
raised when the binding is bound to a key that is not applicable—for example 
when an object is not key-value coding compliant for a key.


To recall, I have something like this:

@interface TopClass : NSObject
{
// some ivars
}

// some accessors

@end

@interface SubClass : TopClass
{
NSString* subValue;
}

- (NSString) subValue;

@end

I have an NSTreeController that contains a list of TopClass and SubClass items. 
The user selects an item in that list.

I have a text field in Interface Builder whose value is bound (ie via bindings) 
to the subValue accessor, ie: NSTreeController - selection.subValue

Obviously, the subValue accessor is only valid if the currently selected item 
is a SubClass object. If the user selects a TopClass item, it throws an 
exception. How can I prevent this?

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Hiding tab view items

2010-01-28 Thread BareFeet
Hi all,

I am just following up on my previous queries about how to show a hierarchy of 
Nodes in the left pane (like iTunes or Disk Utility) and have the available tab 
view items on the right change according to the type of node that the user 
selects.

Thanks to Volker, Kyle, Nathan and Idiot Savant for earlier replies. I think 
I understand now how to retain tab view items so they can be removed and 
reinserted.

I managed to set up my tab view to remove and reinsert particular tab views 
according to what Node is selected, by using the NSOutlineView delegate method. 
I first retain all the tab view items in the awakeFromNib handler. The example 
below checks whether the selected nodeType is table. It then removes or 
inserts the tab view item with the identifier Table in the tab view.

This seems to work OK so far. If I've goofed anywhere, please let me know, via 
the mail list.

@interface MyController : NSObject
{
IBOutlet NSTabView* tabView;
IBOutlet NSTreeController* nodeTreeController;
NSArray* retainedTabViewItems;
}

@end

@implementation MyController

- (void) awakeFromNib
{
retainedTabViewItems = [tabView tabViewItems];
[retainedTabViewItems retain];
}

- (void) dealloc
{
[retainedTabViewItems release];
[super dealloc];
}

- (void) outlineViewSelectionDidChange:(NSNotification*)notification
{
NSString* nodeType = [nodeTreeController 
valueForKeyPath:@selection.type];
NSInteger visibleTabViewItemIndex = [tabView 
indexOfTabViewItemWithIdentifier:@Table];
NSTabViewItem* retainedTabViewItem = nil;
for (int tabViewItemIndex = 0; tabViewItemIndex  [retainedTabViewItems 
count]; tabViewItemIndex++)
{
retainedTabViewItem = [retainedTabViewItems 
objectAtIndex:tabViewItemIndex];
NSString* retainedTabViewItemIdentifier = [retainedTabViewItem 
identifier];
if ([retainedTabViewItemIdentifier isEqualToString:@Table]) 
break;
}
BOOL tabViewItemShouldShow = [nodeType isEqualToString:@table];
BOOL tabViewItemDoesShow = visibleTabViewItemIndex != NSNotFound;
if (tabViewItemShouldShow  !tabViewItemDoesShow)
{
[tabView insertTabViewItem:retainedTabViewItem atIndex:3];
}
else if (!tabViewItemShouldShow  tabViewItemDoesShow)
{
[tabView removeTabViewItem:retainedTabViewItem];
}
}

// other code omitted

@end


 
From: BareFeet list.develo...@tandb.com.au
Date: 21 October 2009 6:02:21 PM AEDT
To: Cocoa Dev Cocoa-dev@lists.apple.com
Subject: Re: Hiding tab view items

This seems like a common requirement, so I keep thinking I must be missing 
something simple.

For an example of similar functionality, look at Disk Utility. The user can 
navigate through a tree of nested disks and partition nodes in the left view. 
The right view shows a tab view that changes its tab items depending on what 
tree node is selected on the left. For instance, if you select a disk, you see 
the tab view items: First Aid, Erase, Partition, RAID and Restore. But if you 
select a partition, the Partition tab view item disappears.

Since there is no hidden/visible property for tab view items, it seems that I 
have to dynamically delete and create tab view items

snip

 
From: BareFeet list.develo...@tandb.com.au
Date: 13 October 2009 1:53:03 AM AEDT
To: Cocoa Dev Cocoa-dev@lists.apple.com
Subject: Hiding tab view items

Hi all,

I have a hierarchical list of objects, like the typical iTunes or XCode left 
pane. When the user selects a node in this hierarchy, I display detail of that 
node in the pane on the right. This right pane is divided into tab view items. 
Only some of the tab view items are relevant to each type of node, so I'd like 
to hide the tab view items that are not relevant. How can I do this?

In Interface Builder, I can't see any hidden property of tab view item. There 
is a hidden property for the sub-view of a tab view item, but this doesn't 
hide the tab view item itself, so is misleading to the user (ie they can click 
on it, only to see a blank view).

snip

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Node hierarchy with subclasses

2010-01-28 Thread BareFeet
Hi All,

Summary:

I have an NSTreeController driven hierarchy of Nodes in my window's left 
pane. I'd like to subclass Node into a few subclasses. Each subclass in the 
model shows its own tab view item(s) in the view (right half of the document 
window). The tab view item contains UI elements (eg text fields), each of which 
is bound (via bindings) to a property of that subclass.

The problem is that when a subclass A is selected, the UI elements bound to 
subclass B no longer have valid bindings so generate an error. How can I solve 
this?

Example:

As described before, I have my Node tree in the left pane and different tab 
view items showing on the right according to what Node is selected.

I'd like to subclass Node according to type. If this was iTunes, for example, I 
might have subclasses like MoviesNode, PlayListNode etc as subclasses of the 
general Node class used in the tree. MoviesNode would have methods particular 
to showing the list of Movies which are not relevant for all Nodes, etc. For 
instance, I might have a width method that returns the width of a movie as an 
integer. I could display this value by creating a text field bound (ie via 
bindings) to the NSTreeController's selection.width model key path. If I show 
this text field in the Movies tab view item it works fine as long as I have 
selected a MoviesNode, but if I select a different subclass of Node (eg 
playlist) or no Node is selected (such as when the nib awakens), there is no 
width property, so it generates an error, similar to:

HIToolbox: ignoring exception '[Node 0x1001db8e0 
addObserver:NSKeyValueObservance 0x1004aeea0 forKeyPath:@width 
options:0x100 context:0x0] was sent to an object that is not KVC-compliant for 
the width property.' that raised inside Carbon event dispatch

I have tried to code the removal of the Movies tab containing the text field 
bound to the width property, but the error occurs before awakeFromNib is called 
and in the init method it's too early (since there's nothing yet loaded to 
remove).

It seems to me to be a common UI layout to have a Node tree on the left and 
various UI elements on the right appearing according to what Node is selected. 
But how can I do this using bindings?

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Global in NSApplication

2010-01-27 Thread BareFeet
On 27/01/2010, at 5:02 PM, Graham Cox wrote:

 The singleton pattern Jens suggested is simpler. I can't think of any simpler 
 way:
 
 + (Debug*)sharedDebug
 {
static Debug* s_debug = nil;
 
if( s_debug == nil )
s_debug = [[self alloc] init];
 
return s_debug;
 }
 
 
 Then whenever you need the debug object, just call:
 
 [Debug sharedDebug];
 
 The first time it's needed it will be created.

Thanks Graham and Jens. That does appear to be a simpler way to do it and seems 
to be working fine for me :-)

Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Global in NSApplication

2010-01-26 Thread BareFeet
Hi all,

I've created a Debug class in my app, which contains an instance variable and 
several methods. I want to add this to my application but can't see how.

I can add it to MyDocument class like this:

- (id)init
{
self = [super init];
if (self) {
// other stuff
debug = [Debug new];
}
return self;
}

- (void) dealloc
{
// other stuff
[debug release];
[super dealloc];
}

But I want a global instance for the application as a whole. How do I do this? 
Do I have to subclass NSApplication just to create a global variable?

I want to be able to call it from any class in my app, such as:

[[NSApp debug] myMethod];

Please reply to the list.

Thanks,
Tom
BareFeet

 --
Comparison of SQLite GUI tools:
http://www.tandb.com.au/sqlite/compare/?ml

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Global in NSApplication

2010-01-26 Thread BareFeet
Yes, I'm familiar with categories, but didn't mention it because it's  
so similar to subclassing.


I just wanted to check if there's a simpler way. I guess not.

Thanks,
Tom
BareFeet
Sent from my iPhone

On 27/01/2010, at 1:17 PM, Murat Konar mu...@pixar.com wrote:

Read up on categories. Then make the instance of your Debug class a  
static variable in your category implementation file, and use a  
method you added to NSApplication via your category to return it.


http://en.wikipedia.org/wiki/Objective-C#Categories

_murat


On Jan 26, 2010, at 6:05 PM, BareFeet wrote:


Hi all,

I've created a Debug class in my app, which contains an instance  
variable and several methods. I want to add this to my application  
but can't see how.


I can add it to MyDocument class like this:

- (id)init
{
 self = [super init];
 if (self) {
  // other stuff
 debug = [Debug new];
 }
 return self;
}

- (void) dealloc
{
  // other stuff
  [debug release];
  [super dealloc];
}

But I want a global instance for the application as a whole. How do  
I do this? Do I have to subclass NSApplication just to create a  
global variable?


I want to be able to call it from any class in my app, such as:

[[NSApp debug] myMethod];

Please reply to the list.

Thanks,
Tom
BareFeet

--
Comparison of SQLite GUI tools:
http://www.tandb.com.au/sqlite/compare/?ml


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Hiding tab view items

2009-10-21 Thread BareFeet
This seems like a common requirement, so I keep thinking I must be  
missing something simple.


For an example of similar functionality, look at Disk Utility. The  
user can navigate through a tree of nested disks and partition nodes  
in the left view. The right view shows a tab view that changes its tab  
items depending on what tree node is selected on the left. For  
instance, if you select a disk, you see the tab view items: First Aid,  
Erase, Partition, RAID and Restore. But if you select a partition, the  
Partition tab view item disappears.


Since there is no hidden/visible property for tab view items, it seems  
that I have to dynamically delete and create tab view items, which is  
prohibitively complicated since those tab view items also contain  
other objects which must therefore also be dynamically created and  
deleted.


At the moment, I've set up my tab view as tabless (ie the actual tabs  
don't show). Instead of tabs, I've created several segmented controls,  
one showing each desired set of segments. I've created a small second  
tabless tab view where each tab just contains one of the segmented  
controls. When the user selects a tree node (in the left pane),  
bindings switches to the tab containing the desired segmented control.  
When the user clicks on a segment, bindings then switches to the tab  
view corresponding to that segment.


user selects tree node
 - bindings selects small tab view item which contains just the  
desired segmented control

user selects segment in segmented control
 - bindings selects large tab view item which contains all the  
necessary objects


This works and requires almost no code (just bindings), so it's  
relatively neat. But it seems silly to have to create a second tab  
view just to switch between different segment controls.


Any other insights?

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Hiding tab view items

2009-10-21 Thread BareFeet

Thanks for the reply, Kyle.


 [tabView removeTabViewItem:oldItem]


But isn't that going to destroy the tab item, the view it contains,  
and everything in that view? Can I get it back when that tab view item  
is valid again, or do I have to programmatically create all the objects?


Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Hiding tab view items

2009-10-18 Thread BareFeet

there a different roots to success


Thanks for the input.

a) roll your own Tabs instead of Segmented cell in combination with  
a tabless NSTabView


Do you mean use a segmented control with a tabless NSTabView, where  
each segmented cell is linked to a tab view?


I have set that up, but can't see a way to hide a segmented cell. I  
can turn off the enabled flag (in Interface Builder of via the  
accessor method), but there doesn't appear to be a hidden flag. I  
thought I might be able to set the width to zero, but the  
documentation says:



setWidth:forSegment:

The width of the segment, measured in points. Specify the value 0  
if you want the segment to be sized to fit the available space  
automatically.


So I guess I'll have to build the segmented control dynamically from  
scratch each time I want to hide a segmented cell, just leaving out  
that cell in the rebuild.



b) Add/remove tab items on demand


That sounds similar to above. However, I feel more comfortable  
rebuilding just a segmented cell than trying to delete and rebuild a  
whole view.


Seems messy either way though.

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Binding hidden attribute

2009-10-12 Thread BareFeet

On 12/10/2009, at 11:57 PM, Paul Bruneau wrote:

Yes, I have recently learned how to do this for my under development  
app.


The tricky part in your case (and mine) is because your ivar is  
not an ivar but a derived value returned by a method, you need to  
tell the KVO system that. Here is my method:



+ (NSSet *)keyPathsForValuesAffectingSchemaIsHidden;
{
   return [NSSet setWithObjects:@query, @source, nil];
}


Ooh, that looks complex, but worth noting, thanks.

I realise now tat your answer makes sense as a requirement if the  
type in model object changes, otherwise there's nothing to trigger  
the re-evaluation of the schemaIsHidden ivar. But in my situation, the  
type is set when the object is created and never changes for that  
object. So I don't actually need to handle KVO to that degree.


After further investigation, it seems that my approach works for my  
situation, in so far as the schemaIsHidden value (returned by an  
accessor method or stored in an ivar) is correct for the object's  
type. The problem appears to be that the tab view item is not hiding  
as I hoped it would. I'll repost this as a different question.


Thank you greatly for your response. It helped me realise my faulty  
assumptions and better identify the problems.


Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Hiding tab view items

2009-10-12 Thread BareFeet

Hi all,

I have a hierarchical list of objects, like the typical iTunes or  
XCode left pane. When the user selects a node in this hierarchy, I  
display detail of that node in the pane on the right. This right pane  
is divided into tab view items. Only some of the tab view items are  
relevant to each type of node, so I'd like to hide the tab view items  
that are not relevant. How can I do this?


In interface builder, I can't see any hidden property of tab view  
item. There is a hidden property for the sub-view of a tab view  
item, but this doesn't hide the tab view item itself, so is misleading  
to the user (ie they can click on it, only to see a blank view).


I tried using a segmented control, instead, using bindings to link it  
to the tab view (now tabless). But segmented control cells also seem  
to lack a hidden property.


Any ideas?

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Binding to values which aren't there

2009-10-11 Thread BareFeet

On 10/10/2009, at 9:17 AM, A B wrote:

Long-held habits regarding best practices regarding relational  
integrity are making me reluctant to stick a parentPerson ivar in  
each Note object, otherwise the solution would be simple: Just  
create another property which has code in the getter that calls back  
to the parent object (the structure of which would then have to be  
known to the Note object) for the birthday, does the necessary math  
and then returns the result.


Why not create the parentPerson ivar the Note object? Since you want  
the Note to access a property of the parent Person, this seems logical  
to me and, as you said, makes the solution simple.


Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Binding hidden attribute

2009-10-11 Thread BareFeet

OK, let me put this another way:

Has anyone successfully bound the hidden attribute of an Interface  
object, so that it hides and shows when the ivar changes? If so, how?


Thanks,
Tom
BareFeet

 
From: BareFeet list.develo...@tandb.com.au
Date: 9 October 2009 12:18:38 AM AEDT
To: Cocoa Dev Cocoa-dev@lists.apple.com
Subject: Binding hidden attribute

Hi all,

I'm trying to hide a tab view item according to the value returned an  
accessor in my model.


My accessor simply returns YES or NO, as per:

- (BOOL) schemaIsHidden {
	return ([type isEqualToString: @query] || [type isEqualToString:  
@source]);

}

In interface builder, in my document nib, I selected the view  
belonging to my Schema tab view item, set its Hidden attribute to:


Bind to: My Array Controller
Controller key:  selection
Model Key Path:  schemaIsHidden

It compiles OK, but when I run it, I get an error in the log:

Cannot create attributed string from object null of class NSNull

What does this mean?

Do I have the correct class (BOOL) returned by my accessor?

My other bindings to this same model and controller work fine.

Thanks,
Tom
BareFeet
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Binding hidden attribute

2009-10-08 Thread BareFeet

Hi all,

I'm trying to hide a tab view item according to the value returned an  
accessor in my model.


My accessor simply returns YES or NO, as per:

- (BOOL) schemaIsHidden {
	return ([type isEqualToString: @query] || [type isEqualToString:  
@source]);

}

In interface builder, in my document nib, I selected the view  
belonging to my Schema tab view item, set its Hidden attribute to:


Bind to: My Array Controller
Controller key:  selection
Model Key Path:  schemaIsHidden

It compiles OK, but when I run it, I get an error in the log:

Cannot create attributed string from object null of class NSNull

What does this mean?

Do I have the correct class (BOOL) returned by my accessor?

My other bindings to this same model and controller work fine.

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: reading (parsing) CSV (or Excel) data

2009-10-01 Thread BareFeet

On 02/10/2009, at 10:22 AM, Jens Alfke wrote:

If the data's not too huge, you can read the file into an NSString,  
break that into lines (there are some NSString methods for this, but  
I don't remember their names), and then on each line call [line  
componentsSeparatedByString: @,] to get the values in an NSArray.


That won't work. CSV can contain commas and newlines within items if  
encapsulated in quotes.


The values will be strings not numbers, but you can call -intValue  
or -doubleValue on each one to convert it.


Yes, CSV doesn't specify types, just strings, so any interpretation  
you make on types is after the actual CSV import.


I found this method (the one under the heading General CSV), which  
works fine, caters for delimiters within quotes, escaped quotes etc:


http://macresearch.org/cocoa-scientists-part-xxvi-parsing-csv-data

Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSArrayController addObject or insertObject:atArrangedObjectIndex:

2009-09-22 Thread BareFeet

Hi all,

I have an NSArrayController and am trying to get an add button to  
work, so that it inserts a new DataRow object at the current  
selection, or at the end if no selection.


Here's my code:

- (IBAction) insertDataRow:(id)sender
{
DataRow* newDataRow = [[DataRow new] autorelease];
	[newDataRow setTransactionPending:@insert]; // just a flag in the  
DataRow object
	NSUInteger controllerSelectionIndex = [dataRowsController  
selectionIndex];


if (controllerSelectionIndex == NSNotFound)
{
[dataRowsController addObject:newDataRow];
}
else
{
		[dataRowsController insertObject:newDataRow  
atArrangedObjectIndex:controllerSelectionIndex];

}
}

When it gets to either the addObject or insertObject method, it  
crashes with the error:

Program received signal:  “EXC_BAD_ACCESS”

If I hook up an add button directly to the insert or remove  
received action of the NSArrayController, it works fine. But I need to  
run my own method so I can check and set other variables, such as the  
setTransactionPending property shown above.


Can someone please tell me what I'm doing wrong?

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSArrayController addObject or insertObject:atArrangedObjectIndex:

2009-09-22 Thread BareFeet

On 22/09/2009, at 5:18 PM, Dave Keck wrote:


It looks like dataRowsController is no longer a valid object by the
time -addObject:/-insertObject: is called on it.


Thanks for the reply Dave.

That doesn't seem to be the problem. dataRowsController is hooked up  
via Interface Builder to the NSArrayController. I know it's valid  
because the method in my code [dataRowsController selectionIndex]  
works, as does a test method [dataRowsController content].


I think I've found the problem though.

It seems that the addObject: or insertObject: method call on the  
controller actually calls the getter then the setter for the whole  
array. I had an NSLog in my getter that was actually causing the error:


- (void) setDataRows:(NSMutableArray *)newDataRows
{
NSLog(@setDataRows: count == %@, [newDataRows count]);
[dataRows autorelease];
dataRows = newDataRows;
[dataRows retain];
}

Once I removed the NSLog line (or just the [newDataRows count]  
method), it works fine.


Two followup questions:

1. Why can't I use the array count in the NSlog like that?

2. Does addObject: and insertObject: actually just get the whole  
array, add the extra object, then write the whole array back to the  
instance variable? I thought it would be more efficient than that.


Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Filtering a table view using NSSearchField

2009-09-15 Thread BareFeet

Hi Matt,


I'm trying to filter a NSTableView using the contents of an
NSSearchField. I have an Array Controller and table columns bound to
key paths in the array controller. So for example I have the table
column for name is bound to Array Controller.arrangedObjects.name.


What I want to do now is filter the contents of the table view  
(based on the name column) using text typed into an NSSearchField.


I know this is somehow possible using bindings and predicates, but  
im not sure exactly how to do it.


Download my app Thucydides. It's short and sweet and comes with  
example
source code which exemplifies exactly what you're describing. In  
fact, what

you're describing is just about all it does.


I had a look at your code. As best I can tell, the filtering doesn't  
use Bindings or predicates at all (though the display of the actual  
controller array etc uses bindings). You just change the array (which  
you called found) to only include rows from the complete array  
(which you called urls).


Am I missing something in your code that uses bindings for the search  
field and filtering?


Is there a way to simply bind the search field content to a filter key  
path?


Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSCell setControlSize:NSSmallControlSize doesn't show change

2009-09-13 Thread BareFeet

Hi all,

I'm programmatically building an NSTable. I add columns in a loop and  
am trying to set various attributes. All of it works except  
setControlSize:NSSmallControlSize. When I get the value after setting  
(ie using controlSize), it seems to have changed, but the actual cell/ 
column is still shown in regular size (even after initiating a view  
update). What am I missing?


Sample code:

//  BFTableViewCategory.h

#import Cocoa/Cocoa.h

@interface NSTableView (ExtrasByTom)

- (void) createColumns:(NSArray*)dataColumns;

@end


#import BFTableViewCategory.h

@implementation NSTableView (ExtrasByTom)

- (void) createColumns:(NSArray*)dataColumns {
for (NSString* columnName in columnNames) {
		NSTableColumn* newTableColumn = [[[NSTableColumn alloc]  
initWithIdentifier:columnName] autorelease];

[[newTableColumn headerCell] setStringValue:columnName];
[self addTableColumn:newTableColumn];
[[newTableColumn dataCell] setAlignment:NSRightTextAlignment];
		[[newTableColumn dataCell] setControlSize:NSSmallControlSize]; //  
only thing that doesn't show change

[newTableColumn setWidth:100];
}
}

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Intercepting user changes to table cells using bindings

2009-09-10 Thread BareFeet

Hi all,

I have a table view with columns bound to an NSArrayController. The  
user can edit the values that appear and it's all working fine.


I have a class called DataRow for each row in the table/controller.  
Each DataRow is essentially an NSMutableDictionary with a key for each  
column name. The column names (and therefore dictionary keys) are  
dynamically built according to imported data.


What is the best way to intercept user changes to cells in the table?  
I might want to just record the changes or allow/disallow them.


One way, I figure, is to use this method in my DataRow class:

- (void) setValue:(id)value forKeyPath:(NSString*)keyPath
{
NSLog(@DataRow setValue:forKeyPath:%@, keyPath);
return [super setValue:(id)value forKeyPath:(NSString*)keyPath];
}

This gives the keyPath as: dataRow.The Column Name of the Edited Cell

Is there a built in way to extract the column name (same at the  
dictionary key), or should I just parse out based on the delimiting  
. and hope there are no . in the name?


Or is there a better way altogether to intercept data entry changes?

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Passing variables between .m files

2009-09-10 Thread BareFeet

Hi Aaron,

I have been struggling over this one for a while now, and what  
frustrates me

the most is the feeling that it should be relatively simple to do.

Let's say I have File1.m and File2.m, and I would like to access a  
variable

in File2.m from File1.

My previous programming experience is in Java, so my first  
impression was to

do this (in the File1 implementation file):

File2.outletVariable = varFile1;


I asked a similar question a few days ago, and was helped out by the  
same Graham who answered you. I feel your pain and confusion.


The answer is pretty simple, assuming we're talking about the same  
thing.


I'm assuming you have two classes, depicted in your File1.m and  
File2.m files, and you have an object of each class in your nib file.  
You need to add an outlet in File1.h that you can link to the File2  
object, like this:


// File1.h

@class File2;

@interface File1 : NSObject
{
IBOutlet File2* linkToFile2;
}

Once that is saved in XCode, switch over to Interface Builder, control- 
drag from your File1 object to your File2 object. The popup menu  
should show linkToFile2, select it.


Now you can call any method in File2 from File1. If you want to access  
an instance variable in the File2 object, such as (NSString*)  
myVariable, then you will need to create an accessor method for it in  
File2, such as:


- (NSString*) myVariable
{
return myVariable;
}

Then you can refer to it from File1 via:

[linkToFile2 myVariable];

Hope this helps you as much as Graham helped me. If not, flip back to  
his answers to my question about a week ago.


Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Custom NSActionCell subclass + table column binding

2009-09-10 Thread BareFeet

Hi Florijan,

I've made an NSActionCell subclass for indicating the priority of an  
object, similar to the rating column in iTunes. The visual aspects  
of it are working fine, as well as displaying the correct priority  
for table rows that have a priority value set.


The problem is setting the new priority when the user clicks on the  
column. I've tried two approaches:


1) Setting the target of the cell to self, and in the action message  
set the objectValue of the cell to the desired priority (which I  
have no problem determining from the location of the mouse click).  
Somehow that does not affect the bound NSManagedObject at all.


If I understand you correctly, you have bound your table column to an  
array controller, and are trying to change the data by changing the  
table column. As far as I understand bindings (which isn't much), you  
aren't supposed to (because it won't work) change the data by  
programmatically adjusting the view (ie the table column cell).


You should instead direct any programmatic changes to the data itself,  
through the controller in a key-value compliant way. Then the view  
will automatically reflect those changes.


I hope this helps. If ou need more detail, I'll try to follow up.

Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSController's class accessing NSDocument methods

2009-09-09 Thread BareFeet

Hi all,

Following up my previous question:

I have a MyDocument/File's Owner, NSOutlineView and bound  
NSTreeController in a nib file. The outline/table shows a list of  
Entities (nothing to do with Cocoa or CoreData) in the current  
document/file. I have successfully set up accessor methods for  
properties of Entity such as name and type. But I'm trying to set up  
another accessor method (dataRows) that depends on the document  
path. I can't see how to access the NSDocument methods from an  
Entity within it. How is it done?



The best solution I've come up with is to create a document property  
in each Entity as it's created, linking back to the MyDocument  
instance that contains it. Then each Entity can refer to the document  
which contains it when needed (eg when running an accessor method such  
as dataRows).


It makes sense to add a container reference as an extra property to an  
object when it's created. But I thought there might have been some  
built in way to do this such as in Interface Builder.


Here's the modified code:

//  Entity.h

#import Cocoa/Cocoa.h

@interface Entity : NSObject
{
}

@property (retain) NSString* type;
@property (retain) NSString* name;
@property (retain) MyDocument* document;
@property (retain) NSMutableArray* dataRows;

@end


//  Entity.m

#import Entity.h
#import MyGenerator.h

@implementation Entity

@synthesize type;
@synthesize name;
@synthesize document;
@synthesize dataRows;

- (void) dealloc
{
[editing release];
[type release];
[name release];
[document release];
[super dealloc];
}

- (NSMutableArray*) dataRows
{
NSString* fileString = [[[self document] fileURL] path];
NSString* selectedEntityName = [self name];
	NSMutableArray* dataRowsArray = [MyGenerator  
dataRowsGivenFilePath:fileString entityName:selectedEntityName];

return dataRowsArray;
}

Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSController's class accessing NSDocument methods

2009-09-07 Thread BareFeet

Hi all,

I have a fairly simple app, with an Entity table and a DataRows table  
(each has a controller), set up using bindings (no Core Data). I've  
set it up so when I select an Entity in the Entities table, the  
DataRows table refreshes by calling my Entity.selection.dataRows  
accessor method.


I have a MyDocument/File's Owner, NSOutlineView and bound  
NSTreeController in a nib file. The outline/table shows a list of  
Entities (nothing to do with Cocoa or CoreData) in the current  
document/file. I have successfully set up accessor methods for  
properties of Entity such as name and type. But I'm trying to set up  
another accessor method (dataRows) that depends on the document path.  
I can't see how to access the NSDocument methods from an Entity within  
it. How is it done?


Here's some code:

//  Entity.h

#import Cocoa/Cocoa.h

@interface Entity : NSObject
{
}

@property (retain) NSString* type;
@property (retain) NSString* name;

@property (retain) NSMutableArray* dataRows;

@end


//  Entity.m

#import Entity.h
#import MyGenerator.h

@implementation Entity

@synthesize type;
@synthesize name;

@synthesize dataRows;

- (NSMutableArray*) dataRows
{
// ***
// I need this next line to instead get the path of the document that
// shares the controller's nib, rather than being hard coded.
// Something like: fileString = [[linkToDocument fileURL] path]
// ***

NSString* fileString = @/Users/tom/Documents/MyFile.sqlitedb;

NSString* selectedEntityName = [self name];
	NSMutableArray* dataRowsArray = [MyGenerator  
dataRowsGivenFilePath:fileString entityName:selectedEntityName];

return dataRowsArray;
}

Thanks in advance,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Binding table columns that change at runtime

2009-09-06 Thread BareFeet

Thanks Brent for your input:

You will probably want to use KVO to observe changes to the array  
holding the list of column names to show.


I'm not sure how to do that. It's probably enough in my case to  
intercept setContent calls to the NSArrayController, changing the  
table columns during that process.



You can subclass NSArrayController.


I ended up doing that. I only had to intercept setContent and add an  
IBOutlet instance variable linked to the NSTableView, so I could set  
up the needed columns based on the newContent:


//  BFArrayController.h

@interface BFArrayController : NSArrayController
{
IBOutlet NSTableView* myTableView;
}

@property (retain) NSTableView* myTableView;

- (void) setContent: (id) newContent;

@end


//  BFArrayController.m

#import BFArrayController.h
#import BFTableViewCategory.h

@implementation BFArrayController

@synthesize myTableView;

- (void) setContent: (id) newContent
{
if ([newContent count]  0)
{
NSArray* columnNameArray = [[newContent objectAtIndex:0] 
allKeys];
[myTableView createColumns:(NSArray*)columnNameArray 
bindTo:self];
}
[super setContent: newContent];
}

@end


And I implemented a new createColumns:bindTo: method as a category for  
NSTableViews:


//  BFTableViewCategory.h

#import Cocoa/Cocoa.h

@interface NSTableView (ExtrasByTom)

- (void) createColumns:(NSArray*)columnNameArray bindTo: 
(NSArrayController*) tableArrayController;


@end


//  BFTableViewCategory.m

#import BFTableViewCategory.h

@implementation NSTableView (ExtrasByTom)

- (void) createColumns:(NSArray*)columnNameArray bindTo: 
(NSArrayController*) tableArrayController

{
// Remove old columns:
	NSMutableArray* oldTableColumns = [NSArray arrayWithArray: [self  
tableColumns]];

for(NSTableColumn* oldTableColumn in oldTableColumns)
[self removeTableColumn:oldTableColumn];

// Add new columns:
for (NSString* columnName in columnNameArray)
{
		NSTableColumn* newTableColumn = [[[NSTableColumn alloc]  
initWithIdentifier:columnName] autorelease];

[[newTableColumn headerCell] setStringValue:columnName];
[self addTableColumn:newTableColumn];
		[newTableColumn bind:@value toObject:tableArrayController  
withKeyPath:[NSString stringWithFormat: @arrangedObjects.%@,  
columnName] options:nil];

}
}
@end

You could go all-out and add support for a new binding or the custom  
controller could just add itself as an observer of the arranged  
objects property of the relevant array controller (the one managing  
the list of column names). Then implement the KVO observation method  
(-observeValueForKeyPath:ofObject:change:context:), where you will  
do the right thing depending on whether a column was added or removed.



Hmmm, that's interesting. It would be useful to be able to bind the  
array of NSTableColumns used by an NSTableView to some array in the  
model data. Probably a bit beyond me at the moment.


Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Binding table columns that change at runtime

2009-09-04 Thread BareFeet

Hi all,

I'm fairly comfortable with setting up bindings for table columns to  
an NSArrayController. Now I'd like to use bindings where the columns  
change at runtime. Is this possible? I am avoiding using CoreData  
(so I can run on Mac OS X 10.3 ish and upwards).


Picking up on my own post:

I managed to create table columns at runtime and bind them to my array  
controller, using:


[newTableColumn bind:@value toObject:dataRowsController withKeyPath: 
[NSString stringWithFormat: @arrangedObjects.%@, columnName]  
options:nil];


I've appended the full code below. It took me a while to realise that  
in the bind:toObject:withKeyPath:options: method, the withKeyPath:  
parameter concatenates two fields that appear in Interface Builder's  
GUI: Controller Key and Model Key Path.


// Code to add new columns and bind them to the array controller
// Remove old columns:
NSMutableArray* oldTableColumns = [NSArray arrayWithArray:  
[dataRowsTableView tableColumns]];

for (NSTableColumn* oldTableColumn in oldTableColumns)
[dataRowsTableView removeTableColumn:oldTableColumn];

// Add new columns:
NSArray* columnNameArray = [[dataRowsArray objectAtIndex:0] allKeys];
for (NSString* columnName in columnNameArray)
{
	NSTableColumn* newTableColumn = [[[NSTableColumn alloc]  
initWithIdentifier:columnName] autorelease];

[[newTableColumn headerCell] setStringValue:columnName];
[dataRowsTableView addTableColumn:newTableColumn];
	[newTableColumn bind:@value toObject:dataRowsController withKeyPath: 
[NSString stringWithFormat: @arrangedObjects.%@, columnName]  
options:nil];

}

Now I've also bound my dataRowsController to the selection of another  
controller (an NSTreeController). I have a dataRowsArray accessor  
method setup, so the correct array loads. If the table columns are  
already in place (such as by me manually running the code above), the  
data displays perfectly. But I can't see how to trigger my code above  
(that creates and binds table columns) when the selection changes.


Any ideas?

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Binding table columns that change at runtime

2009-09-04 Thread BareFeet

On 05/09/2009, at 3:16 AM, Sean McBride wrote:


On 9/4/09 9:41 AM, BareFeet said:


I'm fairly comfortable with setting up bindings for table columns to
an NSArrayController. Now I'd like to use bindings where the columns
change at runtime. Is this possible? I am avoiding using CoreData (so
I can run on Mac OS X 10.3 ish and upwards).


One way to do this is to create all the columns in IB and bind them  
all

in IB.  Then at runtime, programatically hide columns as needed.


Thanks for the input Sean.

Two problems with that:

1. The columns I'm generating are from input data (any SQLite  
database) so the combination of columns is infinite. I can't create  
infinite columns and hide some.


2. As per my second email I've managed to generate the table columns  
and bind them in code. But now I'm looking for the best way to trigger  
that code when the selection in the boundTo list changes. It would be  
the same dilemma ifI were to hide columns (vs creating them): how do I  
trigger that in bindings?


Thanks,
Tom
BareFeet
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Binding table columns that change at runtime

2009-09-03 Thread BareFeet

Hi all,

I'm fairly comfortable with setting up bindings for table columns to  
an NSArrayController. Now I'd like to use bindings where the columns  
change at runtime. Is this possible? I am avoiding using CoreData (so  
I can run on Mac OS X 10.3 ish and upwards).


Any help appreciated.

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Two controllers in a window, how do I get one to run a function in another?

2009-09-01 Thread BareFeet

Hi again Graham and anyone else interested,

Yes, I've done that, control dragged from MyController to File's  
Owner and selected the_document. For simplicity, I'm just creating  
the_document in MyController (I've no need for MyDocument to refer  
to the_controller).


I still get nil for the_document at runtime.


OK, my antennae are twitching. You're going to have to show your  
code, because it sounds like you're doing something very strange here.


You say you're creating the document in your controller. Huh?


No, I'm not specifically creating the document (ie an instance of  
NSDocument). I'm just creating the_document instance variable, as per  
your code sample. Perhaps my use of the word creating was  
misleading, sorry.


To try to isolate the issue, I created a Refresh button and hooked  
it up to a refresh method in MyController. It just calls init (as  
below). When the program runs and instantiates a document that I open,  
debugging the init call shows the_document as nil. But when I click  
Refresh to call init again, it shows the_document as not nil and  
fileString is assigned correctly etc.


So perhaps it's a problem with the instantiation?

My code is below.

Thanks for your help with this. This is one thorn in a project port  
(from AppleScript Studio) that is otherwise going very well.


Tom

//  MyDocument.h

#import Cocoa/Cocoa.h

@interface MyDocument : NSDocument
{
}
@end


//  MyDocument.m

#import MyDocument.h

@implementation MyDocument
// usual template code
@end


//  MyController.h

#import Cocoa/Cocoa.h

@class MyDocument;

@interface MyController : NSObject
{
IBOutlet MyDocument* the_document;
}

- (IBAction) refresh:(NSButton*)sender;

@end


//  MyController.m

#import MyController.h
#import MyDocument.h

@implementation MyController

- (IBAction) refresh:(NSButton*)sender
{
[self init];
}

- (id) init
{
[super init];
NSString* fileString = [[the_document fileURL] path];
// more code that uses fileString
}

- (void) dealloc
{
[super dealloc];
}

@end

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Two controllers in a window, how do I get one to run a function in another?

2009-09-01 Thread BareFeet

Hi Graham,

To try to isolate the issue, I created a Refresh button and  
hooked it up to a refresh method in MyController. It just calls  
init (as below). When the program runs and instantiates a  
document that I open, debugging the init call shows the_document as  
nil. But when I click Refresh to call init again, it shows  
the_document as not nil and fileString is assigned correctly etc.


So perhaps it's a problem with the instantiation?


The ivar the_document won't be valid until at least -awakeFromNib  
is called. That's the earliest point you can access it.


That did the trick. I moved the code (referring to the_document) to  
run after/in awakeFromNib, rather than in the init method.


I think you're over-thinking this. Is MyController an object in the  
nib?


Yes.


If so, connect the_document to File's Owner and you're done.


Already done.

By the time your document is ready to use, the controller will be  
valid, exist, and be working.


It is working now.

Init time for any of these objects is too early - debugging in there  
won't tell you much because at that time the nib hasn't been fully  
loaded so none of the outlets will have been set.


That was the problem.


If on the other hand you're instantiating MyController in code


Nah, wasn't over-thinking ;-)

Thanks a lot Graham for your time and patience. I really appreciate  
it. As I mentioned, this has been one repeating gap in my knowledge  
(accessing one object's ivars or methods from another in the same  
nib). I had seen the IBOutlet approach mentioned in forums, but  
nothing really laid it out.


Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Two controllers in a window, how do I get one to run a function in another?

2009-08-31 Thread BareFeet

Hi Graham and all,

I also tried to use bindings, which I've made work well for linking  
text views, table columns, even outline view columns, to data in my  
model. But I can't seem to set up bindings to link an instance  
variable in one controller to another controller. So I guess  
bindings are only for linking view objects to model objects, yes?


First, forget bindings... bindings is really an advanced topic, so I  
suggest you'll be better off leaving it alone for now. Bindings are  
mostly designed for handling the view--controller connections.


Actually, as I mentioned, I've had great success with bindings for  
linking view objects to data. I am actually surprised at how bindings  
seems to always be taught as an advanced topic, whereas I think it  
should be introduced much earlier to newbie Cocoa programmers,  
especially since it eliminates so much code, but that's another story.


I just wondered whether bindings could be used to link instance  
variables in two controllers, but I guess not.


In this case you have a controller--controller connection, which  
is likely to be a lot simpler.


You have two controllers. Each controller can have an IBOutlet to  
the other one. Just declare the outlets then wire them up in your  
nib, e.g:


I kinda got that, but missed what exactly to wire up...


// MyController.h

@class MyDocument;

@interface MController : NSObject
{
   IBOutlet MyDocument*the_document;
}

...

@end


...
ahh, now that makes sense. That's what I was missing. I was trying to  
add IBOutlets for instance variables but needed to instead add  
IBOutlets for the class (eg MyDocument). Has this been documented  
anywhere? I couldn't find it. I would have thought it a common  
requirement, or is there a better approach to sharing data between  
controllers in the same nib?


When I try to compile the above, I get an error:

expected specifier-qualifier-list before 'MyDocument'

If I change the MyDocument* to id, it works, but what's the problem?

Once you have added the outlets to your classes, they will be  
visible in IB, so just ctrl-drag from one object to the other and  
choose the outlet to connect it. In the .m files, #import the header  
for the other class:


#import MyDocument.h


Is this really necessary? It compiles without it. I did it anyway.


In your code, you can now do things like this, from your controller:

NSString* file = [the_document fileString];


the_document is showing as value nil. It doesn't seem to be linked to  
the instance of MyDocument. Am I missing something?


Thanks for all your help,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Two controllers in a window, how do I get one to run a function in another?

2009-08-31 Thread BareFeet

Hi Graham and all,

ahh, now that makes sense. That's what I was missing. I was trying  
to add IBOutlets for instance variables but needed to instead add  
IBOutlets for the class (eg MyDocument).


Whaaa? You're probably getting your terminology confused


but the above makes no sense to me. IBOutlets *are* instance  
variables. You don't/can't add an IBOutlet for an instance  
variable. The presence of IBOutlet is merely a marker that allows  
IB to parse the file. If you look up its definition you'll see it  
evaluates to nothing.


Yes, bad terminology, sorry. I know IBOutlets are just a label/marker  
for instance variables which Interface Builder recognises. What I  
meant was that I was trying to add in MyController the IBOutlet label  
for an instance variable in the MyDocument class, but should have  
instead labeled an instance of the MyDocument class itself. I don't  
know if that's any clearer.


You are also not adding an IBOutlet for the class. You are adding an  
instance variable, tagged as an outlet, which will point to the  
MyDocument instance.


Yes, that's what I meant ;-)


When I try to compile the above, I get an error:

expected specifier-qualifier-list before 'MyDocument'

If I change the MyDocument* to id, it works, but what's the  
problem?


Did you include the @class MyDocument; line?


Doh!, no, missed that. Thanks for that.

That's important - it's a forward declaration, which informs the  
compiler that the MyDocument* is merely a pointer, and so it doesn't  
need to know anything else about the class - it has all it needs to  
proceed to lay out this object.


Again, I'd like to see where this is documented, in the context of  
linking controllers. Thanks so much for the tip.


You can use id, which is a bit like void*, an anonymous type that  
will shut the compiler up, but it's better to type things  
specifically where you can do so, and here is one such place.


Yes, I'm familiar with id being like void, used as a non-specific  
pointer etc. I prefer to use specific classes, but just used id  
temporarily to isolate the problem. I've specified the type now that  
the error is gone (thanks to @class).



In your code, you can now do things like this, from your controller:

NSString* file = [the_document fileString];


the_document is showing as value nil. It doesn't seem to be linked  
to the instance of MyDocument. Am I missing something?


Well, have you actually linked it to the instance of MyDocument? If  
these objects exist as part of the nib (which is the simplest  
approach) then you link them together in Interface Builder by ctrl- 
dragging from one to the other. In the case of the document class,  
it's File's Owner in the nib. The other controller would typically  
be dragged in as an NSObject (blue cube icon) and have its class set  
to MyController. IB will display the outlets the_document and  
the_controller and then it's up to you to connect them.


Yes, I've done that, control dragged from MyController to File's Owner  
and selected the_document. For simplicity, I'm just creating  
the_document in MyController (I've no need for MyDocument to refer to  
the_controller).


I still get nil for the_document at runtime.

Any other ideas?

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Two controllers in a window, how do I get one to run a function in another?

2009-08-30 Thread BareFeet

Hi All,

I want to have two NSObjects (controllers) - one for the tableview  
and all the actions that it needs to perform, and one for the web  
view.  I am having difficulty getting the tableview controller to  
tell the webview controller to display a particular page.  And I  
can't find anything about this subject in my Cocoa books or on the  
web.  Am I barking up the wrong tree here?  Should I only have one  
controller per window?


I've read the replies but can't get any approach to work. I must be  
missing something simple.


For example, I have an instance method called fileString in my  
MyDocument class, that returns the path to that document. But how do  
I call it from my MyController? In MyController.m, when I say:


#import MyDocument.h
...
[MyDocument fileString];

I get a runtime error:

+[MyDocument fileString]: unrecognized selector sent to class.

The error makes sense because I am trying to call an instance method  
on a class. But how to I refer to the instance of MyDocument that sits  
in the same nib instance as the MyController that is calling it?


When you stop laughing, can you please lay it out for me.

I also tried to use bindings, which I've made work well for linking  
text views, table columns, even outline view columns, to data in my  
model. But I can't seem to set up bindings to link an instance  
variable in one controller to another controller. So I guess bindings  
are only for linking view objects to model objects, yes?


Thanks,
Tom
BareFeet


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Syntax Coloring?

2009-08-23 Thread BareFeet

Hi Keita,


Hello, I'm writing a code editor and so far, i've been using Flex for
regex-matching the whole document every time the text is changed and
coloring appropriately...


How are you doing this? How did you incorporate Flex or regex-matching?

I approached it using regex to parse the quoted and commented strings  
into single objects, then parse using regex for the language, then  
reinsert the quoted and commented strings. But this was using perl and  
scripting, whereas I now need to port to Cocoa.


I managed to get regex working in Cocoa using RegexKiteLite, but now  
need to move across the rest of my method.


I got this idea from some CocoaBuilders or CocoaDev forum/mailing  
list awhile ago


Do you have a link to the article?

but it's terribly inefficient and slow, especially with large  
documents.


I would hope that there's come Cocoa class for parsing source text  
into tokens etc, but don't know of anything.


Tom

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSString and regular expressions

2009-08-03 Thread BareFeet

Hi All,

RegexKitLite looks promising. It claims to only require you to add  
the .h and .m file to your project and link to the libicucore.dylib  
library.


I managed to incorporate RegexKitLite fairly easily once I found in  
the documentation the steps to link to the libicucore.dylib library.


Thanks for all your comments about ICU vs PCRE. I've thrown a couple  
of fairly involved regexes at it that I've previously used in Perl  
(therefore PCRE) and haven't had to make any adjustments at all.


I've wrapped it in a test Cocoa app that shows capture in an outline  
view, with each group showing as a child item of its capture. It's  
working very well so far. The essence of my use of RegexKitLite here is:


- (IBAction)update:(id)sender
{
NSString * regexString = [regexField string];
NSString * inputString = [inputField string];

	[outputArray release]; // already defined as an instance variable in  
the .h file

NSError * myError = nil;
NSRange myRange = NSMakeRange(0, [inputString length]);
	outputArray = [inputString  
arrayOfCaptureComponentsMatchedByRegex:regexString  
options:RKLNoOptions range:myRange error:myError];

[outputArray retain];
[outputOutline reloadData];
}
@end

I'm new to Cocoa and Objective-C. So please tell me gently of any  
glaring errors above


Now to use it in my real project, I need to port over my routines that  
parsed SQL statements. I have been doing this by:


1. Using regex to replace quoted items (eg bounded by  or ' or a  
comment bounded by /* */ or -- \n) with placeholders.


2. Using regex to parse the SQL (now containing placeholders) into  
desired SQL components


3. Replacing placeholders with original text.

Before I go ahead and port this same method across, is there any built  
in functionality in Cocoa that will facilitate this (or part of it)  
directly?


Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


AGRegex (was: NSString and regular expressions)

2009-08-03 Thread BareFeet

Hi all,

Has anyone got procedure for getting AGRegex to work in their project?

Thanks,
Tom
BareFeet

 
From: BareFeet list.develo...@tandb.com.au
Date: 31 July 2009 9:03:20 AM AEST
To: Cocoa Dev Cocoa-dev@lists.apple.com
Subject: Re: NSString and regular expressions

Hi Rob,


I personally just compile the files directly into my project.

You need AGRegex.h and AGRegex.m but you should only compile the  
following files from the pcre distribution:


pcre_chartables.c
pcre_compile.c
pcre_exec.c
pcre_fullinfo.c
pcre_get.c
pcre_globals.c
pcre_info.c
pcre_ord2utf8.c
pcre_tables.c
pcre_try_flipped.c
pcre_ucp_searchfuncs.c
pcre_valid_utf8.c
pcre_xclass.c


Thanks. I tried that, but get 436 fails during compile, starting with  
pcre.h: No such file or directory.


So I copied pcre.h across to my project too but then get more errors  
starting with pcre_internal.h No such file or directory.


If I add all the header files, I still get compile errors, starting  
with:


pcre_ucp_searchfuncs.c:48:54:
 error: ucptable.c: No such file or directory

So I copied ucptable.c but I get the error:

ucptable.c:4:
 error: expected '=', ',', ';', 'asm' or '__attribute__' before  
'ucp_table'


Can you please clue me in as to how to get AGRegex to work?

Thanks,
Tom
BareFeet

 
From: BareFeet list.develo...@tandb.com.au
Date: 30 July 2009 2:51:59 PM AEST
To: Cocoa-dev cocoa-dev@lists.apple.com
Subject: Re: NSString and regular expressions

Hi Rob  all,

On 28/07/2009, at 11:02 AM, Rob Keniger wrote:

You might want to look at AGRegex which is very compact (one class)  
and which uses PCRE:


http://colloquy.info/project/browser/trunk/Frameworks/AGRegex


Thanks for the tip. Have you been able to get this to work?

Do we add the framework or the AGRegex files (and PCRE folder) to our  
own project? I've tried both and can't get it to work. I can't find  
any instructions in the documentation on adding it correctly to your  
own project.


Thanks,
Tom
BareFeet
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSString and regular expressions

2009-07-30 Thread BareFeet

Hi Rob  all,

On 28/07/2009, at 11:02 AM, Rob Keniger wrote:

You might want to look at AGRegex which is very compact (one class)  
and which uses PCRE:


http://colloquy.info/project/browser/trunk/Frameworks/AGRegex


Thanks for the tip. Have you been able to get this to work?

Do we add the framework or the AGRegex files (and PCRE folder) to our  
own project? I've tried both and can't get it to work. I can't find  
any instructions in the documentation on adding it correctly to your  
own project.


Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSString and regular expressions

2009-07-30 Thread BareFeet

Hi Rob,


I personally just compile the files directly into my project.

You need AGRegex.h and AGRegex.m but you should only compile the  
following files from the pcre distribution:


pcre_chartables.c
pcre_compile.c
pcre_exec.c
pcre_fullinfo.c
pcre_get.c
pcre_globals.c
pcre_info.c
pcre_ord2utf8.c
pcre_tables.c
pcre_try_flipped.c
pcre_ucp_searchfuncs.c
pcre_valid_utf8.c
pcre_xclass.c


Thanks. I tried that, but get 436 fails during compile, starting with  
pcre.h: No such file or directory.


So I copied pcre.h across to my project too but then get more errors  
starting with pcre_internal.h No such file or directory.


If I add all the header files, I still get compile errors, starting  
with:


pcre_ucp_searchfuncs.c:48:54:
  error: ucptable.c: No such file or directory

So I copied ucptable.c but I get the error:

ucptable.c:4:
  error: expected '=', ',', ';', 'asm' or '__attribute__' before  
'ucp_table'


Can you please clue me in as to how to get AGRegex to work?

Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSString and regular expressions

2009-07-30 Thread BareFeet

Hi John and all,

You might want to look at AGRegex which is very compact (one class)  
and which uses PCRE:


http://colloquy.info/project/browser/trunk/Frameworks/AGRegex



Of note, Colloquy appears to have switched to RegexKitLite itself:

http://svn.colloquy.info/project/changeset/4301


I did notice that log entry, but thought it was never acted upon (ie  
they are still using AGRegex).


RegexKitLite looks promising. It claims to only require you to add  
the .h and .m file to your project and link to the libicucore.dylib  
library.


The documentation notes: Warning: Apple does not officially support  
linking to the libicucore.dylib library. In reality, how worried  
should I be about this? I am amazed that Cocoa doesn't provide regex  
itself. Surely Apple must provide or recommend something to do the job.


As quoted earlier:

Unfortunately, RegexKit Lite (the stripped-down version) uses the  
built-in ICU library which uses a syntax quite different to the  
PCRE that most people are used to.


At first glance through the ICU Syntax documentation included with  
RegexKitLite, it appears the same as what I'm used to. At least it  
supports \s for whitespace, \w for words, (?=...) for look ahead. I  
did, however, discover:



Single Quote
Two single quotes represent a single quote, either inside or outside  
single quotes. Text within single quotes is not interpreted in any  
way, except for two adjacent single quotes. It is taken as literal  
text— special characters become non-special. These quoting  
conventions for ICU character classes differ from those of Perl or  
Java. In those environments, single quotes have no special meaning,  
and are treated like any other literal character.


I guess I can deal with that.

Has anyone discovered any other issues (or had successes) dealing with  
ICU syntax in RegexKitLite and RegexKitLite in general?


Thanks,
Tom
BareFeet

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com