Skip navigation.
 
mlBuilding Text System by hand - View Displays Nothing
FROM : Michael Hanna
DATE : Tue Nov 02 01:45:19 2004

Hello,

I'm building the text system by hand for my app like it's set up in 
Figure 4 of:

file:///Developer/ADC%20Reference%20Library/documentation/Cocoa/
Conceptual/TextArchitecture/Concepts/CommonConfigs.html

so that the two NSTextViews are viewing the same document. They are 
inside an NSSplitView. The NSTextViews and the NSSplitView are archived 
in the MyDocument.nib.

in the MyDocument -init method I have:

       
       myDocumentTextStorage = [[NSTextStorage alloc] init];
       myDocumentString = [[[NSMutableAttributedString alloc] init] retain];
       
       myTopLayoutManager = [[NSLayoutManager alloc] init];
       [myDocumentTextStorage addLayoutManager:myTopLayoutManager];
       [myTopLayoutManager release];
       
       myBottomLayoutManager = [[NSLayoutManager alloc] init];
       [myDocumentTextStorage addLayoutManager:myBottomLayoutManager];
       [myBottomLayoutManager release];


inside my awakeFromNib I use replaceTextContainer to have the 
NSTextViews conform to my hand-built text-system:

- (void)awakeFromNib {
   
   NSRect topTextViewFrame = [myTopTextView frame];
   NSRect bottomTextViewFrame = [myBottomTextView frame];
   
   // create the NSTextContainers now, now that the textviews are 
referenceable
   
   myTopTextContainer = [[NSTextContainer alloc] 
initWithContainerSize:topTextViewFrame.size];
   [myTopLayoutManager addTextContainer:myTopTextContainer];
   [myTopTextContainer release];
   
   myBottomTextContainer = [[NSTextContainer alloc] 
initWithContainerSize:bottomTextViewFrame.size];
   [myBottomLayoutManager addTextContainer:myBottomTextContainer];
   [myBottomTextContainer release];
   
   [myTopTextView replaceTextContainer:myTopTextContainer];
   [myBottomTextView replaceTextContainer:myBottomTextContainer];

       ......
}

the user opens a file using initWithPath:

- (void)openVisualFilePanelDidEnd:(NSOpenPanel *)openPanel
           returnCode:(int)returnCode
           contextInfo:(void *)x
{
   NSMutableAttributedString *theString;
   if(returnCode == NSOKButton) {
       [prompter setVisualPromptPath:[openPanel filename]];
       [self updateChangeCount:NSChangeDone];
       theString = [[NSMutableAttributedString alloc] 
initWithPath:[openPanel filename] documentAttributes:nil];
       
       [self setDocumentString:theString];
       [self updateUI];
       [theString release];
               
   }
}


inside setDocumentString I go:

   [myDocumentTextStorage setAttributedString:theString];

I am certain by this time the NSMutableAttributedString is set to the 
NSTextStorage because I set a breakpoint and typed 'po 
myDocumentTextStorage' to see its contents(the string is there)

finally in updateUI I sent setNeedsDisplay to all the Views...but it 
still comes up blank.

   
   [myTopTextView setNeedsDisplay:YES];
   [myBottomTextView setNeedsDisplay:YES];
   [mySplitView setNeedsDisplay:YES];


any ideas why the views are blank? I used 
file:///Developer/ADC%20Reference%20Library/documentation/Cocoa/
Conceptual/TextArchitecture/Tasks/AssembleSysByHand.html

to help me with this whole task.

best regards,
Michael

Related mailsAuthorDate
No related mails found.