Question

As part of a Mac application I am working on, the user fills out a screen full of stuff and then presses a 'process' button. There are edits performed and if everything passes the edit, a couple of minute process is performed which either end ok or not. I would like to have that process spit out a series of status and processing messages into a separate scrolling window so that if something goes bad, the user can go back through the log and see if anything shows up there.

What would be the best objects and methods for me to review and use for this type of processing?

Added 11/24/2011

As per the first suggestion, I created a second XIB, created a NSWindowController to match and put it all together as some prep work. When the button in pressed in the app delegate, I have this thing do the following:

- (IBAction)runButtonPressed:(id)sender {

RunResultWindow *wc;

wc = [[RunResultWindow alloc] initWithWindowNibName:@"RunResultWindow"];

[wc showWindow:self];

}

RunResultWindow is the name of the XIB and the NSWindowController class that controls it. I also added a finish button and wired that up with the intention of having the results of the process fill up the text window and then hang there until the user presses 'done' or 'finish' or whatever I wind up calling the button.

It actually shows the window when I press the button on the main window but when the code for the button finishes, the window vanishes. Clearly I am leaving out (an important) step.

Once I get the window then I can add the text view etc.... and get that working. What I would like is for the new Window to get focus and then close out when the user presses the 'done' button.

Additionally, I got the window for the window controller from the window method (it returned an address) and tried a couple of window focus methods in the windowDidLoad method of the NSWindowController but no dice.

Thanks again for whatever info I can get on this.

Added 11/25/2011

Duh. Maybe if I make the class instance an ivar instead of embedding it in the button method it will work and, lo, it did. Le Oops.

Était-ce utile?

La solution

Sounds like you want to drop a NSTextView into a window where one can select & scroll the text but not edit the contents.

You can insert text as easily as using the insertText: method.

Autres conseils

So... The NSTextView and insertText combination worked out somewhat ok but I don't' think it is the final answer. First, my understanding is that insertText is really only meant for user input and not background 'system' input to a NXTextStorage object. I'm not sure why but that's fine so I'll avoid it. There are other options. I did find the beginEdit and endEdit methods and it works pretty much about the same way though I have some more work to do on some detail delegate methods.

The part that doesn't work so well is getting the NSScrollView in the window to update on demand. I do the beginEdit and endEdit stuff and am able to update the NSTextStorage object properly. I can do this multiple times in the same method (a test button on the window containing the scroll view). I can tell that because print-object in debug shows me what I'm expecting at the right times. However, I'd like to be able to show an updated NSScrollView multiple times during the court of the windowDidLoad method. The scroll view updates properly when the button push method ends.

Here is some sample code. I do mix insertText and the begin/end edit methods in here but it was more of a test thing than any code I would use for real....

(IBAction)FinishButtonPush:(id)sender {

    NSString *teststring;
    teststring = [NSString stringWithString: @"show"];
    [RunResultWindowTextView setString:teststring];
    teststring = [NSString stringWithString: @"show show"];
    [RunResultWindowTextView setString:teststring];
    teststring = [NSString stringWithString: @"show show show show"];
    [RunResultWindowTextView setString:teststring];
    [RunResultWindowTextView insertText:@"123"];
    NSTextStorage *tempTextStorage;

    tempTextStorage = [RunResultWindowTextView textStorage];

    [tempTextStorage beginEditing];
    [tempTextStorage replaceCharactersInRange:NSMakeRange(5,13)
                            withString:@"Hello to you!"];
    [tempTextStorage endEditing];

    [tempTextStorage beginEditing];
    [tempTextStorage replaceCharactersInRange:NSMakeRange(10,13)
                            withString:@"second change"];
    [tempTextStorage endEditing];

    [RunResultWindowTextView insertText:@"xxx123"];
    [RunResultWindowTextView insertText:@"xxx123567"];
}

Even though the NSTextStorage object is updated properly, the scroll view only updates when the method completes. My understanding is that processEdit is called automatically during endEdit. I added processEdit in there just to see and all I got was either abends or no change depending on where I put the command.

This got deleted and I'm not sure why. If you're going to gong the post, please let me know why you did so. Can't improve my post unless I have an idea what was wrong with it....

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top