Editing and processing content of text field in an attached panel

Hi All,

I have practically exhausted my thoughts on this problem so I decided to post this topic here for your kind help.

I have an attached panel to the main window that has a text field which contains a default name as string. Now, I want to have the chance to edit the text field in this panel and then process it accordingly before the application goes back and fetch the other items to process.

My problem is this: the panel displays the default name, ready to be edited, but then it goes on to the next item without giving a chance for the text field to be edited and have the edited name processed by another handler.

I have put in delays but they do not seem to do anything. What is the best approach to solve this problem? I have tried delay and timeout, and ignoring-considering application responses…but I can’t seem to get a good fix.

Here’s a snippet of my code for your kind perusal and analyses to see how I can accomplish what I want to do:

property display_itemPanel: 1
property editingIsDone: false
property asLongAsPossible: 3600
property noMore: 0

global the_item, fileNameOnly

on show_itemNamePanel(the_item, fileNameOnly)
	set editingIsDone to false
	if itemPanel is missing value then
		load nib "myPrefPanel"
		set itemPanel to "individual_panel"
	end if
      if display_itemPanel is equal to 1 then
		display panel window itemPanel attached to window "settingsPanel"
		set the content of text field "user_prefName" of window itemPanel to fileNameOnly
	end if
      --I want to edit the text field in the above panel and come up with an edited filename to be processed by the handler below (work_withItem)
	if editingIsDone is false then
		delay asLongAsPossible
      --when "OK" button in the panel is clicked (presumably after edting the text field), then set editingIsDone to true and zero the delay and perform the required tasks below
		set the content of text field "user_prefName" of window itemPanel to editedfilename
		--handler below processes the new filename (edited) for the_item
		my work_withItem (the_item, editedfileName)
		delay noMore
	end if
end show_itemNamePanel

And many thanks for your generous assistance.

archseed :frowning:

What do you mean by this? How is it “going on” and where is it going to? The text field should obviously be editable, and once you display a panel, it just sits there until you close it. You should be able to edit your text, get it’s value, modify the input, etc… all before the panel closes or any other changes are made. The only way for it to go away is if you allow the panel to close somewhere in your code.

I don’t understand what the delays and the “editingIsDone” are for, but it seems like you’re not quite up to speed as to how panel’s are implemented and how they work when attached to windows. If my assumptions are correct, you’re looking for something like this conceptual model…

Hope this gets you somewhere. Seems like you’re going about it all the wrong way. A panel is just another window, so work with it the same as with any other window. Then when you’re done with it, just send it a “close panel…” message and carry on.



Many thanks, jobu. On almost every problem that I have, you’re always there to get me thinking.

I will try the conceptual model that you posted. And yes, I honestly admit, I haven’t been working that far along on the attached panel and really need a lot more mental “exercise” on this stuff.

In retrospect, I believe that I should have posted my problem a little differently. Actually, the panel stays open as I did not issue a “close panel” command. The trouble is the text field editing does not get registered. I think the problem likes in reworking the codes to get the text field edited and processed.

Thanks just the same. And I hope this message sends you into a nice slumber if you’re still wide awake yet… :smiley:

archseed :slight_smile:

Side note: It looks like you’re using display panel, which is depreciated; You should use display instead.

See also: Panel Suite


To evaluate text as it changes I usually use the “on changed” handler of the object. Whenever the text in the text field changes, it calls the handler, allowing you to update the enabled status of your “OK” button…

on changed theObject
	if name of theObject is "user_prefName" then
		set proposedName to content of theObject
		set enabled of button "OK" of (window of theObject) to (validateName(proposedName))
	end if
end changed

to validateName(proposedName)
	--> if proposedName is acceptable (Test the name with your validation code here)
		return true
	--> end if
	return false
end validateName



I got the edited text in the attached panel to be accepted and processed by the application so that is not a problem anymore.

The problem that I should have clearly explained from the outset is this:

My application is a droplist that processes a number of dropped items (either items in folder or multiple items dragged into its icon). I could make the attached panel display the default entries into its text field but if I do not put a delay after the panel shows, the program simply zips through to the next item in the dropped items.

While the delay works, it is not an ideal solution because after editing is complete and processed, the application waits until the delay is completed before it displays again. Moreover, the delay simply suspends the panel for a certain amount of time, then cancels out and goes to the next item even if editing is not yet done. Not a very nifty solution, indeed!

I’ve tried setting a boolean test condition but it does not seem to suspend the panel action - even used state of some buttons in the panel to signal that the editing is still active and that the panel would have to wait. No dice!

Any further suggestions? I am really lost on this.

Would appreciate your thoughts on this problem while I sweep through this forum for some possibly related posts.

Many thanks.

archseed :slight_smile:

Hi All,

After some experimentations, I got this thing to work in this manner:

1). I put a global boolean flag (“freeze_theProcess”) and set it to true inside the handler that displays the attached panel with an editable text field;

2). Then, inside that handler I put a repeat loop that cycles through with a delay of 1 if the boolean flag remains true. When boolean flag becomes false (set to false in the “on end editing theObject” handler) the panel closes and the program exits the display panel handler to process the edited text field.

So far, it has worked like a charm (am crossing my fingers right now :D). My only problem is trapping the error that occurs after the last item is read and edited. I will get to that eventually.

archseed :):slight_smile: