14 Replies Latest reply on Mar 1, 2017 2:56 AM by K.Daube

    Put focus on insertion point..

    Klaus Göbel Level 3

      I'm trying to put the focus on the insertion point after inserting text from a palette without mouseclick.

      I just want to continue writing at that point.

       

      Things I've already tested:

      - scrollToText

      - oDoc.IsInFront = 1

      - oDoc.TextSelection = tRange

       

      Has anybody solved this problem?

       

      var w = new Window ("palette","INSERT");
          w.Button = w.add("button",undefined,"Go")
          w.Button.onClick = Insert;
          w.show()
      
      function Insert()
      {
      var oDoc = app.ActiveDoc
      var textLoc = oDoc.TextSelection.beg;  
      oDoc.AddText (textLoc, "Test");  
      }
      
        • 1. Re: Put focus on insertion point..
          K.Daube Level 1

          Klaus,

          I have a function DisplayMarker which might give a hint:

          function DisplayMarker (oDoc, oCurrentMarker) {
          //          Select marker to visualize the location of the current marker
          //          (Text Symbols must be on to see it)
          var myTextRange, oTextLoc1, oTextLoc2;
          
            if (oCurrentMarker.ObjectValid()) {
              oTextLoc1 = oCurrentMarker.TextLoc;
              oTextLoc2 = oCurrentMarker.TextLoc;
            } else {
              alert ("DisplayMarker:\nPgm error: oCurrentMarker not defined.", DisplayMarker.name, true);
              return false;
            }
            oTextLoc2.offset = oTextLoc2.offset+1;                  // offset2 = offset1 is given by oTextLoc 
            myTextRange  = new TextRange(oTextLoc1,oTextLoc2);      // define a TextRange    
            oDoc.TextSelection = myTextRange;              // if you want to select the marker  
            oDoc.ScrollToText(myTextRange);                // requires a TextRange. NOT a location  
          } //--- end DisplayMarker
          

          It works fine.

          • 2. Re: Put focus on insertion point..
            Klaus Göbel Level 3

            Hi Klaus,

            thanks a lot for your suggestions.

             

            The problem is, to put the focus on the document, when working with a palette-window.

            In my little script above, when you click "Go", the text is inserted at the insertion point.

            What I want to do then is, just to write in the document, without clicking with the mouse to the insertion point.

            Things I've already tested:

            - scrollToText

            - oDoc.IsInFront = 1

            - oDoc.TextSelection = tRange

            I've also tested Shift - F7: no success.

            • 3. Re: Put focus on insertion point..
              K.Daube Level 1

              Now I understand: I also had no success in doing this.

              I needed to resort to "documentation change"...

              function SetFocusToDoc (oDoc) { //=== Set focus back to document after invoking panel =============
              // Comment  Since the panels are per definition 'in front' they can not be influenced to give 
              //          focus back to the document. The user must click into the document to get it in focus
              //          to be able to enter another shortcut. Of course the focus of the panel is left also
              //          when reaching for the menu.
              //          HENCE THIS FUNCTION IS NOT USED …
              // Reference Klaus Göbel at https://forums.adobe.com/thread/2240541
              var oTextRange, fcode = [];
              
                oTextRange = oDoc.TextSelection;
                oDoc.ScrollToText (oTextRange);
                oDoc.IsInFront = 0;                            // method Klaus Göbel -> no effect
                oDoc.IsInFront = 1;
                fcode[0] = FCodes.FOCUS_INPUT_DOC;  // <Definition \x620> new idea - no effect
                  Fcodes(fcode);
              } //--- end SetFocusToDoc
              

               

              This seems to be a panel quirk

              1 person found this helpful
              • 4. Re: Put focus on insertion point..
                Klaus Göbel Level 3

                Hi Klaus,

                thanks a lot, pointing to that solution. I'll try to work it out and give you a feedback.

                 

                oDoc.IsInFront = 0;         
                oDoc.IsInFront = 1;  
                
                

                 

                Doing that workes only if at least 2 dokuments are open.

                Ergo: It doesn't work.

                • 5. Re: Put focus on insertion point..
                  Wiedenmaier Level 3

                  Klaus,

                  I think there are two changes to get this done as ES has no window handling mechanism.

                   

                  1. implement an FDK Client, which gives you access to the windows, then you'll be able to active the active document window

                  2. find a workaround with any function that could activate current active doc window.

                   

                  Point 1, I think it's too much overhead for this. As "IsInFront" works when two documents are open but not if only one is opened, following thoughts

                   

                  1. try

                  Assign an invalid doc to app.ActiveDoc

                   

                  var doc = app.ActiveDoc

                  app.ActiveDoc = app.ActiveDoc.NextDocumentInSession

                  app.ActiveDoc = doc;

                   

                  2. try

                  Minimize active doc and maximize it again

                  app.ActiveDoc.IsIconified = true;

                  app.ActiveDoc.IsIconified = false ;

                   

                  or perhaps

                   

                  app.ActiveDoc.IsOnScreen = false;

                  app.ActiveDoc.IsOnScreen = true;

                   

                  or a combination of IsOnScreen and IsInFront

                   

                   

                  3. try

                  Call something like Redisplay/Reformatting

                   

                  4. try

                  keep an hidden (empty) document. Make it visible, make it the activeDoc and than switch back to your document and hide your dummy again.

                   

                  Sorry, not nice but perhaps could help

                   

                  Markus

                  • 6. Re: Put focus on insertion point..
                    Klaus Göbel Level 3

                    Hi Markus,

                    thanks a lot for your suggestions.

                    None of them works. The only way seems to be fcode[0] = FCodes.FOCUS_INPUT_DOC;

                    But there is absolutely no effect. So maybe it's a bug.

                     

                    All other things only cause flickering.

                    • 7. Re: Put focus on insertion point..
                      Wiedenmaier Level 3

                      Hi Klaus,

                       

                      I woudn't call it a bug. Bug is such a hard word :-)

                       

                      I think, this all is due to a missing window messaging queue support within ExtendScript. Perhaps @AdobeTCS could bring some C-features like "BringWindowToFront" up to ExtendScript.

                       

                      Window focus is on your ES Dialog, and you can't change this Focus without messaging queue support.

                       

                      So I think the only way to make this work in a stable way is an FDK Client which implements a callback to FA_NoteCallClient and implements this window handling.

                       

                      Sorry

                      Markus

                      • 8. Re: Put focus on insertion point..
                        Russ Ward Level 4

                        Hi Klaus G.,

                         

                        Any time I need to force a document to the front (that is, "brute force"), I call Open() on it again. Did you try that? Maybe something like:

                         

                        SimpleOpen(oDoc.Name, false);

                         

                        Russ

                        • 9. Re: Put focus on insertion point..
                          Klaus Göbel Level 3

                          Hi Russ,

                          thanks for your advice.

                          In my case, the document already is open and on top of all other documents or it is the only open document.

                          But the palette-dialog overlaps it.

                          I have a (palette-)script, that inserts words by pressing a button. I want that the user can continue writing without having to "aim"  with the mouse without closing the dialog.

                          • 10. Re: Put focus on insertion point..
                            Russ Ward Level 4

                            Hi Klaus,

                             

                            I understand that. I have found that an "open" command on an open document tends to force it to the front, when other options fail. Did you try it?

                             

                            Russ

                            • 11. Re: Put focus on insertion point..
                              Klaus Göbel Level 3

                              Hi Russ,

                              I've just tried. It only flickers.

                               

                              Klaus

                              • 12. Re: Put focus on insertion point..
                                Russ Ward Level 4

                                Confound it! I thought I had the answer. Thanks for trying.

                                • 13. Re: Put focus on insertion point..
                                  Wiedenmaier Level 3

                                  just another idea:

                                   

                                  try to set active property of your palette to false and after that try one of suggestions above.

                                  Would start with SimpleOpen, as Russ suggested.

                                   

                                  Markus

                                  • 14. Re: Put focus on insertion point..
                                    K.Daube Level 1

                                    Following Markus' last advice I can place the text:

                                    #target framemaker
                                    var w = new Window ("palette","INSERT");  
                                            w.Button = w.add("button",undefined,"Go")  
                                            w.Button.onClick = Insert;  
                                            w.show()  
                                    
                                    function Insert()  {  
                                        var oDoc = app.ActiveDoc  
                                        var textLoc = oDoc.TextSelection.beg; 
                                        w.active = false;   // Markus' suggestion 
                                        oDoc.AddText (textLoc, "Test");    
                                    }
                                    

                                    So, does this work in a real-world script also?