Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

ScriptUI : edittext live modifications problem

People's Champ ,
Nov 19, 2009 Nov 19, 2009

Hi,

I set a scriptUI interface.

http://i.imagehost.org/0754/Image_1.png

I have two buttons :

     - one has to add a carriage return on the edittext field

     - one has to add tab.

I am using textselection property of the edittext object.

On Mac it works very fine.

On Windows, it just go crazy. Sometimes, it just ignores the click, other times, it adds the element unexpectingly.

ie tab or carriage return are placed everywhere but where I want it.

What do I do wrong ?

TIA Loic

TOPICS
Scripting
13.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 21, 2011 Mar 21, 2011

If I understand your tests there is no need to send keystroke via AS since you original onEnterKey handler  works for Mac, right? Can you confirm that it works whatever the number  of lines in the EditText and for ID CS3/CS4/CS5? (I think your  workaround is the best for Mac platforms since it also supports modal  dialogs.)

I have not been able to test CS4 or CS5 yet, but can confirm insertion of multiple linebreaks works perfectly for CS3 on Mac. Your code is quite, umm, verbose! Here is a clean and compact version without any dependencies for those of you who just want to add as little as possible to your existing projects. Make sure it gets executed before adding any EditText elements to your windows and you won't need to bother with anything else!

EditText.prototype.onEnterKey = function (event) {      if (this.properties.multiline) {           if ($.os.toLowerCase().indexOf('mac') == 0)                this.textselection = '\n', this.dispatchEvent(new UIEvent('changing')), this.dispatchEvent(new UIEvent('change'));           else if ($.os.toLowerCase().indexOf('win') == 0 && !app.modalState)                app.doScript('set WshShell = CreateObject("WScript.Shell")\nWshShell.SendKeys("^{ENTER}")', ScriptLanguage.VISUAL_BASIC);      } }

The only issue on the Mac is that ScriptUI does not register events when textselection is modified. Thus onChanging never gets triggered and if the only change you made was the linebreak(s) then onChange will not fire either, which is why I am dispatching both events manually. Much better would be if one only had to dispatch onChanging and then could set the change "flag" somehow so that ScriptUI would triggers onChange as normal when the element loses focus... anyone know if something like that is possible?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 22, 2011 Mar 22, 2011

Browsing the forum today I've noticed the syntax for creating event objects seems to have changed with CS4, my code above is for CS3 so will not be fully compatible with newer versions. Is the notify() function still available and using the same syntax in ScriptUI CS4/CS5? If so that might be the most straightforward and compatible solution. I can't quite get it to work properly though, notify("onChange") works as expected (or simply notify() as change is the default event for EditText objects) but despite what the documentation claims notify("onChanging") never fires the changing event handler for me. Any ideas?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2011 Mar 22, 2011

>so that ScriptUI would triggers onChange as normal when the element loses focus

Focus appears to be a big problem in ScriptUI in palettes. For example, your EditText.prototype.onEnterKey works fine in CS5/Windows, but only in dialogs. In palettes, Ctrl+Enter fires up the QuickApply menu. This doesn't answer your question entirely, but I just wanted to point out that there are focus problems in ScriptUI.

Peter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jun 11, 2013 Jun 11, 2013

Hi Marc,

I tried your script but when I press enter the quick apply menu comes up.

AFAIK This is because you use WshShell.SendKeys which does not distinguish between the regular and the number pad enter in order to do this apparently one has to use WshShell.SendInput. So says here.

As I don't know VB one bit (might learn it one day if I get a mac )

Do you have any idea of how to do this?

Thanks

Trevor

P.s.

Did you see my scrollable panel function #6 in http://forums.adobe.com/message/5396270#5396270 you might even find it useful.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 20, 2015 Jun 20, 2015
LATEST

Hi all,

The following example shows that it is possible to load an editText selection in a variable.

// MAC Finder ou WINDOWS Explorer, on autorise le double clic  et on fait passer Photoshop au 1er plan

#target photoshop

app.bringToFront();

var text = "My tailor is very rich !"

var dlgBox=new Window ("dialog",text);

dlgBox.orientation="row";

dlgBox.add ("statictext", undefined,"Name:");

var myText= dlgBox.add("edittext", undefined,text);

myText.characters= 30;

myText.active=true;

var button=dlgBox.add ("button", undefined,"OK");

dlgBox.add ("button", undefined,"Cancel");

dlgBox.show();

button.onClick=selection(myText);

function selection(text)

{

   alert(myText.textselection);

}

Excuse my poor English.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2011 Mar 22, 2011

Mayhem,

>all development has been on CS3 Mac where the hack appears to perform perfectly

You might be in for a surprise when you move to CS4 or 5. The textedit control worked rather well in CS3 (Windows), with Ctrl+Enter and Ctrl+Tab doing a good job inserting new lines and tabs, and staying in focus; the Copy and Paste shortcuts, too, work fine in CS3.

In CS4 it was almost completely broken: Ctrl+Enter stopped working most of the time, I forget what happened to Ctrl+Tab, but most annoyingly, Enter/Ctrl+Enter and Ctrl+Tab were sent to a document or the app instead of to the edittext control; same for the Copy and Paste shorcuts.

In CS5 things have improved but aren't back to the level of CS3.

Peter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines