Get Active Document's Index

Get Active Document's Index

14
Basic UserBasic User
14

    Apr 12, 2007#1

    How can I access the active document's index number? I can set the active document by using UltraEdit[x].setActive(); but how can I get the index of the currently active document?

    Thanks.

    262
    MasterMaster
    262

      Apr 13, 2007#2

      Include this function that I have written. It should be called in the start of your script before any ...setActive is performed

      Code: Select all

      UltraEdit.activeDocument.write("Active document has index="+getActiveDocumentIndex());
      
      /* Find the tab index of the active document */
      function getActiveDocumentIndex() {
      	var tabindex = -1; /* start value */
      
      	for (var i = 0; i < UltraEdit.document.length; i++)
      	{
      		if (UltraEdit.activeDocument.path==UltraEdit.document[i].path) {
      			tabindex = i;
      			break;
      		}
      	}
      	return tabindex;
      }
      
      Edit 2010-03-02: In UE version 16.00 a new property was added to the scripting environment: var docIx = UltraEdit.activeDocumentIdx; (See more UE 16.00 scripting enhancements...).

      14
      Basic UserBasic User
      14

        Apr 13, 2007#3

        I knew it was an array when I saw the example script using the .length property. I didn't remember seeing anything in the docs that actually said that .document is an array object, but I did go back and find that after reading your post.

        262
        MasterMaster
        262

          Jun 16, 2007#4

          I just wanted you to know, that I have sent the feature request below to IDM Support. Cheers ! Jorrasdk
          Jorrasdk wrote:Hi IDM Support

          Feature request: UltraEdit.activeDocumentIdx
          New scripting read only property which returns the tab index of the currently active file.
          Should return -1 if there are no open files in the editor.


          Up to now I have used a function shown below ( getActiveDocumentIndex() ) to find the index of the active document, but it is tedious to always have this function in my script (as we can't include other scripts yet ;-).

          I need UltraEdit.activeDocumentIdx to know which document to return to if I have performed some newFile's or setActive's on other files. It is also nice to create aliases to simplify code like this:

          Code: Select all

          var mySourceDoc = UltraEdit.document[UltraEdit.activeDocumentIdx];
          UltraEdit.newfile();
          var myNewWorkDoc = UltraEdit.document[UltraEdit.activeDocumentIdx];
          mySourceDoc.selectLine();
          myNewWorkDoc.write(mySourceDoc.selection);
          Regards
          jorrasdk
          Edit 2010-03-02: In UE version 16.00 a new property was added to the scripting environment: var docIx = UltraEdit.activeDocumentIdx; (See more UE 16.00 scripting enhancements...).

          6
          NewbieNewbie
          6

            Dec 02, 2008#5

            Hello

            Has anyone had any trouble with UltraEdit.document.length misreporting the number of documents open?

            I am trying to use this function and have been getting:
            An error occurred on line 81:
            if (UltraEdit.activeDocument.path==UltraEdit.document.path) {
            Script failed.

            I have discovered that the reason for this is UltraEdit.document.length is sometimes returning a number one greater than the number of documents open, therefore UltraEdit.document.path is trying to reference a file that isn't there. In my script I am opening and closing several text files - maybe UltraEdit.document.length is getting confused?

            36
            Basic UserBasic User
            36

              Mar 12, 2009#6

              I'm using UltraEdit v14.20.1.1008. UltraEdit.document.length seems to only hold the number of documents if you use open file tabs, which I don't (I use the file tree view instead). It returns 0, even though I have several documents open. Any other ideas about getting the index of the current document in this case?

              Is this something that will be remedied in the next version? Ie. getting an UltraEdit.activeDocumentIndex.

              Edit:
              After a closer look this must be a bug. UltraEdit.document[index] doesn't seem to work at all without having open file tabs, any reference to it results in a script fail. I doubt this is the intended behavior. I'm going to file a bug report on it, or at least ask about the behavior.

              Edit2: The reply from IDM suggests that this is indeed a bug. Hopefully a fix will be out soonish =)

              Edit3: This bug isn't fixed in UE15, I have however made the Open Files a Tab together with File View so it doesn't take any space at least.

              6,603547
              Grand MasterGrand Master
              6,603547

                Nov 01, 2009#7

                I have an update on the issue with document array management not working correct when the open file tabs bar is not enabled. It looks like the problem is fixed with UE v15.20.0.1017. I have not fully tested it, but one of my scripts written for IDM to demonstrate the wrong behavior of document array management when the open file tabs bar is not enabled works now correct and produces the same result as when executing it while the open file tabs bar is visible.
                Best regards from an UC/UE/UES for Windows user from Austria

                36
                Basic UserBasic User
                36

                  Nov 05, 2009#8

                  Yes, it was fixed. I forgot I posted about it, so sorry for not updating this thread. IDM sent me a release to test a few weeks ago, and it was fixed in that one (think it was 1017 as you said, currently on 1021 testing another issue).

                  262
                  MasterMaster
                  262

                    Mar 02, 2010#9

                    In UE version 16.00 a new property was added to the scripting environment: var docIx = UltraEdit.activeDocumentIdx; (See more UE 16.00 scripting enhancements...).