Looking for a more elegant solution for updating an NSTextView

Hello again,

I’m currently working on a script which uses Yummy FTP to transfer/synch files and PHP serverside to use drush to manage and keep my Drupal installs clean and updated. Yummy FTP basically provides me with a nice solution for managing FTP bookmarks in folders (physical folders → easy integration) and also provides basic FTP manipulation, connecting, synching and multithreaded uploads/downloads.

To keep an eye on all the activity, I log a lot to the console via “log thisAndThat” and also to an NSTextView field in the UI. Logging to the console isn’t much of a problem (obviously) but the NSTextView only refreshes its content when again receiving focus after an action has been finished by an app I previously called.

I currently do a bit of a quirky thing to refresh its contents. I’m trying to outline the concept:


someHandler_(sender)
-- do this and that to prepare data

-- Always going thru a lot of items doing a lot of actions which produce log content which are sent to the text view and to the console
repeat with item in listOfItems 

--getting the focus back to my gui/mainwindow
activate

-- Apparently, calling a dialog box makes the parent window refresh it's contents:
display dialog "We're going to start!" buttons {"OK"} default button 1 giving up after 1 with icon note

--start the work
tell application "TheAppIWannaCall"
activate
-- make the app hide
tell application "System Events" to tell process "TheAppIWannaCall" to set visible to false
quit
end tell
end repeat
end someHandler_

This procedure is quite annoying from the usability point of view, all the focus-switching creates distraction. Therefore, does any of you know of a simpler way to achieve the same result, which is basically “have text refresh in a text view at mutiple points during the execution of a handler”?

As always, any inputs are greatly appreciated. :slight_smile:

Best regards,

Oliver

What exactly changes between ‘refreshes’ ?

I created a function which takes the existing log, adds the new chunks and writes it back to the text view. New chunks are immediately written to console.


	on updateStatus(mylog, addition)
		log addition
		set statusLog to mylog & return & addition
		logTextField's setString_(statusLog)
		return statusLog
	end updateStatus

This function is called at many points:


	my updateStatus(statusLog, "[ No Bookmarks found. Check your folders! ]")

“statusLog” is a global variable.

Have you tried this?

logTextField's setNeedsDisplay_(true)

Yes, I tried this too. Did not make any difference.

Maybe, if I execute the actions (shell scripts et al) in a different process, the refreshing might work. But I haven’t yet found out how to do that. :slight_smile:

For now I’ll just rely on the output I send to the console and replace the textView-log with a progress bar. :slight_smile:

Thanks!

G’day

Perhaps if you use the ‘displayIfNeeded()’ method as well. It just worked for me.

Regards

Santa


on Clearmessages()
		Messages's setStringValue_("")
	end Clearmessages
	
	on writeOnlyMessage(thetempMessage)
		my Clearmessages()
		Messages's setStringValue_(thetempMessage)
		Messages's setNeedsDisplay_(true)
		Messages's displayIfNeeded()
	end writeOnlyMessage