Script to show/hide certain lines

Script to show/hide certain lines

7
NewbieNewbie
7

    Oct 19, 2015#1

    Hi-
    I have a script that searches for several keywords in a text file and then outputs--to the output window and in a message box--the number of times each keyword was found in the document.
    Now, I want to show the lines that have the keyword found from a script. Is there a way to do this-> https://www.ultraedit.com/support/tutor ... lines.html from a script?

    What I envision is this:
    A user opens a text file, runs my script, and gets a message box saying that the word WARNING was found three times.
    Once the user clicks OK, another message box appears asking them whether they want to see the lines that have WARNING (ideally with the three lines above and the three lines below).

    I know you can do that in KEdit, can this be done in UltraEdit?

    6,681583
    Grand MasterGrand Master
    6,681583

      Oct 20, 2015#2

      There is the command

      Code: Select all

      UltraEdit.activeDocument.hideOrShowLines();
      which results on execution with a block selected in hiding the block with the exception of first line and depending on a configuration setting on last line of the block.

      The configuration setting for showing or hiding last line is Show last line of fold in syntax highlighted files which can be found at Advanced - Configuration - Editor Display - Code Folding.

      So with appropriate scripting code it would be more or less possible to hide all lines with exception of the lines with WARNING and 3 lines above and below. But you have to take also into account on coding this if within those 7 lines there are again lines with WARNING.

      In Find window there is Filter lines option which can be used with a regular expression search to hide all lines except those containing WARNING and the 3 lines above and below. But the filter option is not available in scripts or macros.

      It would be of course also possible to simply copy the blocks of interest into a new file or writing the lines of interest into output window with file name and line number like when using Find with option List lines containing string. With the lines with WARNING with file name with full path and line number in output window, the user could use from within file window Ctrl+Shift+Down and Ctrl+Shift+Up to navigate to the lines in file listed in output window. Getting the lines of interest into output window is most easily done with using Find in Files executed on current file only with results written to output window.

      Here is the small script code demonstrating how to use Find in Files to get all lines with WARNING written to output window.

      Code: Select all

      if (UltraEdit.document.length > 0)  // Is any file opened?
      {
         // Disable writing script execution status to output window.
         UltraEdit.outputWindow.showStatus=false;
         // Clear the output window.
         UltraEdit.outputWindow.clear();
         // Run a Find in Files searching case-sensitive for WARNING on
         // current file only with found lines written to output window.
         UltraEdit.ueReOn();
         UltraEdit.frInFiles.filesToSearch=0;
         UltraEdit.frInFiles.directoryStart="";
         UltraEdit.frInFiles.searchInFilesTypes=UltraEdit.activeDocument.path;
         UltraEdit.frInFiles.displayLinesDoNotMatch=false;
         UltraEdit.frInFiles.openMatchingFiles=false;
         UltraEdit.frInFiles.ignoreHiddenSubs=true;
         UltraEdit.frInFiles.useOutputWindow=true;
         UltraEdit.frInFiles.reverseSearch=false;
         UltraEdit.frInFiles.unicodeSearch=false;
         UltraEdit.frInFiles.useEncoding=false;
         UltraEdit.frInFiles.searchSubs=false;
         UltraEdit.frInFiles.matchCase=true;
         UltraEdit.frInFiles.matchWord=false;
         UltraEdit.frInFiles.regExp=false;
         UltraEdit.frInFiles.find("WARNING");
      }
      
      Best regards from an UC/UE/UES for Windows user from Austria

      7
      NewbieNewbie
      7

        Oct 20, 2015#3

        Thanks, Mofi.

        Yeah, I figured the filter option wasn't available for macros/scripts.

        Is it possible to program message boxes with buttons (like in VBA) so that the user can click on one and then based on the button they chose different parts of the script would run?

        I guess what I am asking is:

        Is it possible to interact with the user beyond the UltraEdit.getstring, getvalue, and messageBox?

        6,681583
        Grand MasterGrand Master
        6,681583

          Oct 20, 2015#4

          rtorres wrote:Is it possible to interact with the user beyond the UltraEdit.getstring, getvalue, and messageBox?
          Available in UE v22.20 are only those 3 commands for user interaction. But take a look on New Dialog: Options() which might offer what you need for your script.
          Best regards from an UC/UE/UES for Windows user from Austria

          7
          NewbieNewbie
          7

            Oct 20, 2015#5

            Thanks! I'll check it out.

              Oct 27, 2015#6

              Okay, so I checked it out, and it gets the job done. This is a major improvement, and I hope IDM people are paying attention.
              I sure hope they incorporate some of this functionality to later versions of UE.

              Thanks for the tip!