Setting text on Cocoa

17 views
Skip to first unread message

Matthew Brush

unread,
Feb 15, 2012, 11:22:44 AM2/15/12
to scintilla...@googlegroups.com
Hi,

I'm having trouble setting the text on a ScintillaView in a
document-based OSX/Cocoa application. I'm using the following code (as a
test) and nothing happens (no text appears in the view):

- (BOOL) readFromData:(NSData *)data ofType:(NSString *)typeName
error:(NSError **)outError
{
BOOL readSuccess = NO;
NSString *fileContents = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];

if (fileContents) {
readSuccess = YES;
[mEditor setString:fileContents];
// testing to see if there is contents (there is)
// NSLog("File contents: %@", fileContents);
// testing to see if any text works (it doesn't)
//[mEditor setString:@"Hello world"];
[fileContents release];
}

return readSuccess;
}

I'm brand new to Cocoa and Objective-C so it's entirely likely I'm
missing something really obvious, but no matter what I try, I can't seem
to make any text appear in the ScintillaView (unless I type it manually).

Any pointers would be greatly appreciated.

Cheers,
Matthew Brush

Mike Lischke

unread,
Feb 15, 2012, 11:23:38 AM2/15/12
to scintilla...@googlegroups.com

Matthew,

> - (BOOL) readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
> {
> BOOL readSuccess = NO;
> NSString *fileContents = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
>
> if (fileContents) {
> readSuccess = YES;
> [mEditor setString:fileContents];
> // testing to see if there is contents (there is)
> // NSLog("File contents: %@", fileContents);
> // testing to see if any text works (it doesn't)
> //[mEditor setString:@"Hello world"];
> [fileContents release];
> }
>
> return readSuccess;
> }
>
> I'm brand new to Cocoa and Objective-C so it's entirely likely I'm missing something really obvious, but no matter what I try, I can't seem to make any text appear in the ScintillaView (unless I type it manually).


That should work fine, provided the file contents contains actually something and the editor is not read-only ([ScintillaView setEditable:]).

Mike
--
www.soft-gems.net

Michael Mullin

unread,
Feb 15, 2012, 1:43:25 PM2/15/12
to scintilla-interest

Matthew Brush

unread,
Feb 16, 2012, 12:03:38 AM2/16/12
to scintilla...@googlegroups.com

Hi,

It turned out that the data/text was OK but the ScintillaView (mEditor)
hadn't been initialized by the time readFromData got called (I was doing
it in awakeFromNib). I was kind of expecting such a programmer error to
blow up in my face like it does with C :)

Thanks for your help (and code).

Cheers,
Matthew Brush

Matthew Brush

unread,
Feb 16, 2012, 12:06:01 AM2/16/12
to scintilla...@googlegroups.com
On 02/15/2012 10:43 AM, Michael Mullin wrote:
> Here's how I do it Matthew
>
> http://bazaar.launchpad.net/~masmullin/codeassistor/trunk/view/head:/src/ui/mac/MyEditor.mm#L311
>

Thanks for the example, it helped. My confusion was with how the
document controller stuff worked and which order the functions got
called in.

Cheers,
Matthew Brush

Reply all
Reply to author
Forward
0 new messages