Re : An OutlineView with Finder Editing Behavior
Re : An OutlineView with Finder Editing Behavior
- Subject: Re : An OutlineView with Finder Editing Behavior
- From: email@hidden
- Date: Fri, 28 Oct 2005 15:42:45 +0100
Thanks for your help !
I'll try this ASAP.
"so you've probably created your own text editor and passed it as "editor"
argument, and you've probably passed self (your outline view) as the
delegate. So, in your delegate you should implement -textDidChange: method,
which will receive notifications posted by your editor and resize the
editor. Something like this:"
No I didn't create my own text editor.... I've subclassed NSTextFieldCell to
be able to put image and text in the cell. So this method take care of
selecting just the text part (as in Apple sample).
So this method is automaticaly called. No need to pass any argument.
How can I do this ? How can I create a text editor ?
I think I have to make a subclass of NSTextField and use this subclasse as
text editor ?
Make my outline delegate of it and that's all ?
And in TextDidChange, calling selectWithFrame:inView:editor:delegate:... ?
About all tips for save and reload etc, etc, ok. I think i've understood and
I thank you for all theses tips.
See you !
Guillaume
-----Message d'origine-----
De : Dragan Milic [mailto:email@hidden]
Envoyé : vendredi 28 octobre 2005 12:56
À : Cocoa-dev Mailing List
Cc : email@hidden
Objet : Re: An OutlineView with Finder Editing Behavior
Well,
You can't get all of these out of the box.
* When user validate, if text is longer than column, put some "..." char.
This one is easy. On Tiger, you just call setLineBreakMode: of your
dataCell, passing it NSLineBreakByTruncattingMiddle/Head/Tail (if you want
"..." chars in the middle/beginning/end of the cell). If you want to support
previous versions of OS as well, you'll need a workaround in your
NSTextFieldCell subclass (you've already subclassed it, since it can draw
images). So, it'd look something like this:
in "YourCellSubclassCell.h"
@interface YourCellSubclassCell : NSTextFieldCell
{
...
NSLineBreakMode _MALineBreakMode;
...
}
...
- (NSLineBreakMode)lineBreakMode;
- (void)setLineBreakMode:(NSLineBreakMode)mode;
...
@end
in "YourCellSubclassCell.h"
@implementation MAImageAndTextFieldCell
...
- (NSLineBreakMode)lineBreakMode
{
if (OS_Version < 10.4) { // check the archive to see how to do this
return _MALineBreakMode;
}
else {
return [super lineBreakMode];
}
}
- (void)setLineBreakMode:(NSLineBreakMode)mode
{
if (OS_Version < 10.4) { // check the archive to see how to do this
_MALineBreakMode = mode;
}
else {
[super setLineBreakMode:mode];
}
}
...
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
...
if ((OS_Version < 10.4) && ([[self stringValue] length] > 0)) {
NSMutableDictionary *tempAttributes = [NSMutableDictionary
dictionaryWithDictionary:
[[self attributedStringValue] attributesAtIndex:0
effectiveRange:NULL]];
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]
init];
[style setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]];
[style setLineBreakMode:[self lineBreakMode]];
NSColor *color = (([self isHighlighted] && [[controlView window]
isKeyWindow]) ?
[NSColor alternateSelectedControlTextColor] : [self
textColor]);
[tempAttributes setObject:style
forKey:NSParagraphStyleAttributeName];
[tempAttributes setObject:color
forKey:NSForegroundColorAttributeName];
[style release];
NSMutableAttributedString *newAttributedString =
[[NSMutableAttributedString alloc]
initWithAttributedString:[self attributedStringValue]];
[newAttributedString setAttributes:tempAttributes range:
NSMakeRange(0, [newAttributedString length])];
[self setAttributedStringValue:newAttributedString];
[newAttributedString release];
}
...
[super drawInteriorWithFrame:cellFrame inView:controlView];
}
I'm using this regularly and it works.
* When selecting, bound as large as actual text,
* When user enter car, bound width auto-resize,
* When input text reach end of column, break line,
You're not far from the solution. Now, I've never implemented this, but this
guideline should work. You can't rely on NSTableView's
-editColumn:row:withEvent:select: method, since it will create editing field
of the same size as the cell. But, you're already using NSCell's
-selectWithFrame:inView:editor:delegate:start:length method, so you've
probably created your own text editor and passed it as "editor" argument,
and you've probably passed self (your outline view) as the delegate. So, in
your delegate you should implement -textDidChange: method, which will
receive notifications posted by your editor and resize the editor. Something
like this:
- (void)textDidChange:(NSNotification *)notification
{
id editor = [notification object];
...
[editor resizeSomehow]
...
}
When resizing the editor you can use -sizeToFit method, but it wont be of
much help. When starting editing a cell, you also have to remember an index
of its column, so later while resizing your editor you can check whether
you've reached that column's width and if so, stop resizing the editor
horizontally and resize it vertically by one line. Also note that if your
new editing string in the editor is narrower (less characters) then the old
string value of the cell, your editor will shrink and expose cell string
which lies beneath the editor (remember, editor is just placed on top of the
cell, the cell is still drawn beneath it with the old string value). So when
starting editing you'll also have to remember cell's current string value,
then set its string value to @"" (empty string), edit, and when finish
editing set the cell's string value to new string, if editing was accepted
by data source method -outlineView:setObjectValue:forTableColumn:byItem, or
set it to saved old value, if editing was rejected.
Hope this helps.
Milke
On 28.10.2005. at 10:50, email@hidden wrote:
Hi,
I've got an NSOutlineView with Image & Text (same classes than
NSDrag&DropOutlineView from Apple Samples).
I'de like to have the same behaviour than the finder when editing :
* When selecting, bound as large as actual text,
* When user enter car, bound width auto-resize,
* When input text reach end of column, break line,
* When user validate, if text is longer than column, put some "..." char.
I've tried several method but no success.
In SelectWithFrame..., I find a way to draw a rect just around the text at
editing begining.
But I can't make it autoresize when user enter text.
Thanks for help !
Guillaume
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden