Script to create fixed width headers with other functions

Script to create fixed width headers with other functions

16
Basic UserBasic User
16

    May 01, 2023#1

    Hi,
    I need the opinion of you experts:

    I have now made the update to UE2023.
    Unfortunately, I do not like the new appearance of the block comment at all (optics!!!).

    I have therefore written a small program that creates script and function headers with fixed (adjustable) width ==> see code

    On execution it is queried whether 1. = script header or 2. = function header.

    Script header:
    Checks if 1st line contains '// @Engine=WebView2': if yes then insert head in line 2.
    Script name is entered automatically (if saved at least once). see '<==' in code.
    Enters the current date (function taken here from the forum). (German format). see '<==' in the code.
    Path without file name is determined and entered.


    Function header:
    is inserted at cursor position. Thus on the 1. line of the function. The line is searched for the function name
    and entered complete with parameter list. see '<==' in the code.
    The parameter list is read and evaluated and for each parameter a separate line is created and the corresponding parameter is entered.
    and the corresponding parameter is entered. see '<==' in the code.
    Enters the current date (function taken here from the forum). (German format). see '<==' in the code.

    Code: Select all

    // ===================================================================================================
    // Scriptname    :  Header mit Datum.js                                                                <==
    // Aufgabe       :                                                                                    
    // Beschreibung  :                                                                                    
    // Author        :  Frank Schulze                                                                     
    // Datum         :  01.05.2023                                                                         <==
    // Pfad          :  G:\Eigene Dateien\UltraEdit\scripts\                                               <==
    // ===================================================================================================
    
    var _ue         = UltraEdit;
    var _thisDoc$    = _ue.activeDocument;
    var _con        = _ue.outputWindow;
    var _selRow$    = "";
    var _date$      = "";
    var _comment$   = "";
    var _result     = 0; 
    var _nCursorPos = 0;
    var _bolFunc    = false;
    
    const _length   = 102;
    
    if (_ue.document.length > 0)                                                    // wenn mind. 1 Datei geöffnet ist 
      {  
      if (_ue.columnMode == true)                                                   // wenn Spaltenmodus aktiv, 
        {
          _result = _ue.getString("Blockmodus aktiv !!!\r\n" +                      // Info und Auswahl 
                                  "(1)     =  auschalten\r\n" +
                                  "(2)     =  Abbrechen",1);
          if (_result == 1)                                                         // wenn '1' (ausschalten) 
            _ue.columnModeOff()                                                     // ausschalten 
          else if (_result == 2)                                                    // wenn '2' (Abbrechen) 
            Stop;                                                                   // Programmende 
        }
    
        _thisDoc$.gotoLine(_thisDoc$.currentLineNum,1);                             // Cursor an den Zeilenanfang setzen und 
        _nCursorPos = _thisDoc$.currentPos;                                         // Position merken 
    
        _result = _ue.getString("(1)     =  Header für Sciptköpfe\r\n" +            // Abfrage 
                                "(2)     =  Header für Funktionen\r\n" +
                                "(Stop)  =  Abbrechen",1);
        if (_result.toLowerCase() == 'stop')                                        // wenn 'Stop' 
          {
            stop;                                                                   // abbrechen 
          }
        else if (_result == 1)                                                      // wenn '1' (Headerkopf) 
          {
            var _Path     = _thisDoc$.path.replace(/(.*[\\\/])(.+).+/, '$1');       // Pfad extrahieren 
            var _FileName = _thisDoc$.path.replace(/^.*[\\\/]/, '');                // Dateinamen extrahieren 
    
            _thisDoc$.top();                                                        // Pos1 der Datei 
            _thisDoc$.findReplace.multiline=true;
            _thisDoc$.findReplace.regExp=true;
            _thisDoc$.findReplace.find('^// *@.*View2');                            // nach WebView2 suchen 
            if (_thisDoc$.isFound())                                                // wenn gefunden 
              {
                _con.write(_thisDoc$.currentLineNum + '');
                if (_thisDoc$.currentLineNum == 1)                                  // in Zeile 1 
                    _thisDoc$.gotoLine(2,1);                                        // dann unterhalb einfügen 
                else
                  _thisDoc$.gotoLine(1,1);                                          // ansonsten in Zeile 1 einfügen 
              }
            else 
                _thisDoc$.gotoLine(1,1);                                            // ansonsten in Zeile 1 einfügen 
    
            _comment$ = "// ";                                                      // obere Kopflinie 
            _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,'=');
            _thisDoc$.write(_comment$);                                             // und ins Dokument eintragen 
    
            _comment$ = "// Scriptname    :  " + _FileName;                         // Scriptname mit <==> Filename 
            _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,' ');
            _thisDoc$.write(_comment$);
    
            _comment$ = "// Aufgabe       :  ";                                     // Aufgabe 
            _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,' ');
            _thisDoc$.write(_comment$);
    
            _comment$ = "// Beschreibung  :  ";                                     // Beschreibung 
            _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,' ');
            _thisDoc$.write(_comment$);
    
            _comment$ = "// Author        :  Frank Schulze";                        // Author 
            _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,' ');
            _thisDoc$.write(_comment$);
    
            _comment$ = "// Datum         :  " + fn_createDate();                   // Datum mit <==> Erstellungsdatum 
            _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,' ');
            _thisDoc$.write(_comment$);
    
            _comment$ = "// Pfad          :  " + _Path;                             // Pfad mit <==> Pfad 
            _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,' ');
            _thisDoc$.write(_comment$);
          }
        else if (_result == 2)                                                      // wenn '2' (Funktionskopf) 
          {
            _thisDoc$.selectLine();                                                 // Zeile markieren 
            _selRow$    = _thisDoc$.selection;                                      // und sichern 
            _thisDoc$.gotoPos(_nCursorPos);                                         // zur alten Pos. zurückkehren (hebt Markierung wieder auf) 
    
            _comment$ = "// ";
            _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,'=');
            _thisDoc$.write(_comment$);
    
            getFuncName(_selRow$);                                                  // <==> erstellt Functionname und event. nötige Parameterabschnitte 
            
            _comment$ = "// Aufgabe       :  ";                                     // Aufgabe 
            _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,' ');
            _thisDoc$.write(_comment$);
     
            if (_bolFunc)                                                           // wenn Funktion, dann Rückgabe berücksichtigen 
              {
                _comment$ = "// Rückgabe      :  ";                                     
                _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,' ');
                _thisDoc$.write(_comment$);
              } ;
     
            _comment$ = "// Author        :  Frank Schulze";
            _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,' ');
            _thisDoc$.write(_comment$);
     
            _comment$ = "// Datum         :  " + fn_createDate();
            _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,' ');
            _thisDoc$.write(_comment$);
         }
         _comment$ = "// ";                                                         // untere Kopflinie 
         _comment$ = fn_fillTrailingChars(_comment$ , _comment$.length, _length,'=');
         _thisDoc$.write(_comment$);
         _thisDoc$.gotoPos(_nCursorPos);
      }
    
    // ===================================================================================================
    // Funktion      :  fn_createDate()                                                                    <==
    // Aufgabe       :                                                                                    
    // Rückgabe      :  fertiges Datum (german)                                                           
    // Author        :  ??                                                                                
    // Datum         :  ??.??.????                                                                        
    // ===================================================================================================
    function fn_createDate() 
      {
        var currentDate = new Date();
        currentDate.setDate(currentDate.getDate());
        var d = currentDate.getDay()
        var dt = currentDate.getDate();
        dt = (dt < 10 ? '0' : '') + dt;
        var m = currentDate.getMonth() + 1;
        m = (m < 10 ? '0' : '') + m;
        var year = currentDate.getFullYear();
        var mn = currentDate.getMinutes();
        mn = (mn < 10 ? '0' : '') + mn;
        var hr = currentDate.getHours();
        hr = (hr < 10 ? '0' : '') + hr;
        var _strDate = dt + "." + m + "." + year;
        return _strDate;
      }
    
    // ===================================================================================================
    // Funktion      :  fn_fillTrailingChars(_comment$, _startCol, _numChars, _char$)                      <==
    // Parameter 1   :  _comment$ =  bisheriger 'Vorstring'                                                <==
    // Parameter 2   :  _startCol =  Startposition (ab Ende des 'Vorstrings')                              <==
    // Parameter 3   :  _numChars =  Anzahl Spalten insgesamt                                              <==
    // Parameter 4   :  _char$    =  Füllzeichen                                                           <==
    // Aufgabe       :  erstellt Kommentarblöcke mit fester einstellbarer Breite                          
    // Rückgabe      :  fertige Kommentarzeile                                                            
    // Author        :  Frank Schulze                                                                     
    // Datum         :  19.04.2023                                                                         <==
    // ===================================================================================================
    function fn_fillTrailingChars(_comment$, _startCol, _numChars, _char$)
      {
        for (_startCol; _startCol < _numChars; _startCol++)                         // Schleife: von akt. Pos. bis max. Spalte 
          {
            _comment$ += _char$;                                                    // mit angegebenen Zeiche auffüllen 
          }
        _comment$ = _comment$ + '\r\n';                                             // zum Schluss noch ein Zeilenende anhängen 
        return _comment$;                                                           // fertigen String an Funktion zurückgeben 
      }
    
    // ===================================================================================================
    // Funktion      :  getFuncName(_Row$)                                                                 <==
    // Parameter 1   :  _Row$ = String mit der akt. Zeile                                                  <==
    // Aufgabe       :                                                                                    
    // Author        :  Frank Schulze                                                                     
    // Datum         :  29.04.2023                                                                         <==
    // ===================================================================================================
    function getFuncName(_Row$)
      {
        const _obj = /(function\W+)(\w+) ?\((.*)\)/.exec(_Row$);                    // prüft, ob ein Funktionsnamen gefunden werden kann 
                                                                                    // und erstellt ein neues Objekt wenn ja 
        var _found$     = "";
        if (_obj == null)                                                           // nicht gefunden ? 
          {
            _found$ = "nicht gefunden !";                                           // Fehlermeldung generieren 
            _con.write(_found$);                                                    // und ausgeben 
          }
        else                                                                        // sonst 
          {
            var _Parameter$ = _obj[3];                                              // Parameterstring sichern 
            _found$ = _obj[0].substring(9,_obj[0].length);                          // gefundenen Funktionsnamen sichern 
            if (_found$.match(/^fn.+/) != null) _bolFunc=true;                      // wenn fn
            _comment$ = "// Funktion      :  " + _found$;
            _comment$ = fn_fillTrailingChars(_comment$, _comment$.length, _length, ' ');
            _thisDoc$.write(_comment$);
            _con.write(_Parameter$ + '+' + _found$);
            if (_Parameter$ != "") prepareParameter(_Parameter$);                   // wenn Parameter vorhanden, <==> 
          }
      }
    
    // ===================================================================================================
    // Funktion      :  prepareParameter(_Parameter$)                                                      <==
    // Parameter 1   :  _Parameter$ =                                                                      <==
    // Aufgabe       :                                                                                    
    // Author        :  Frank Schulze                                                                     
    // Datum         :  30.04.2023                                                                         <==
    // ===================================================================================================
    function prepareParameter(_Parameter$)
      {
        var i           = 0;
        var _ParamList$ = "";
        var _tmpSplit$  = _Parameter$.split(',');                                   // Parameterstring bei vorhandenem Komma teilen 
        var _numParam   = _tmpSplit$.length;                                        // Anz. Parameter ermitteln 
        while (i < _numParam)                                                       // Schleife für Anzahl 
          {
            _ParamList$ = _tmpSplit$[i];
            _ParamList$ += ' = ';
    
            _comment$ = "// Parameter " + (i + 1) + "   :  " + _ParamList$.trim();
            _comment$ = fn_fillTrailingChars(_comment$, _comment$.length, _length, ' ');
            _thisDoc$.write(_comment$);
    
            i++;
          }
      }
    
    What do you think of it ? I would be grateful for any suggestions for optimization.

    But !!! Keep in mind I am a beginner in Javascript.

    Be merciful 🙏

    Greetings Frank

    PS: The german comments in the code could not be translated, sorry!
    (Translated with DeepL)
    Win10 Pro (64bit) 22H2 - UE 2023.2.0.27 64-bit

    6,602547
    Grand MasterGrand Master
    6,602547

      May 01, 2023#2

      Here is an improved version of your script. You can see the differences by comparing your version with this version.

      Code: Select all

      // ===================================================================================================
      // Skriptname    :  Header mit Datum.js                                                                <==
      // Aufgabe       :
      // Beschreibung  :
      // Author        :  Frank Schulze
      // Datum         :  01.05.2023                                                                         <==
      // Pfad          :  G:\Eigene Dateien\UltraEdit\scripts\                                               <==
      // ===================================================================================================
      
      var _ue         = UltraEdit;
      var _thisDoc$   = _ue.activeDocument;
      var _con        = _ue.outputWindow;
      var _selRow$    = "";
      var _date$      = "";
      var _comment$   = [];
      var _bolFunc    = false;
      
      const _length   = 102;
      
      if (_ue.document.length > 0) main();                                            // wenn mind. eine Datei geöffnet ist
      
      function main()
        {
          var result;
          if (_ue.columnMode)                                                         // wenn Spaltenmodus aktiv,
          {
            result = _ue.getValue("Blockmodus aktiv !!!\n0 ... Auschalten\n1 ... Abbrechen",1);   // Info und Auswahl
            if (!result) return;                                                      // wenn ungleich 0 (Abbrechen)
            _ue.columnModeOff();
          }
          var _cUrrentLine = _thisDoc$.currentLineNum;                                // Position merken
      
          result = _ue.getValue("0 ... Header für Skriptköpfe\n1 ... Header für Funktionen\n2 ... Abbrechen",1); // Abfrage
          if (!result)                                                                // wenn 0 (Headerkopf)
            {
              var gotoTop  = false;
              var _Path     = _thisDoc$.path.replace(/(.*[\\\/])(.+).+/, '$1');       // Pfad extrahieren
              var _FileName = _thisDoc$.path.replace(/^.*[\\\/]/, '');                // Dateinamen extrahieren
      
              _ue.perlReOn();
              _thisDoc$.top();                                                        // Pos1 der Datei
              _thisDoc$.findReplace.mode=0;
              _thisDoc$.findReplace.matchCase=true;
              _thisDoc$.findReplace.matchWord=false;
              _thisDoc$.findReplace.regExp=true;
              _thisDoc$.findReplace.searchDown=true;
              _thisDoc$.findReplace.searchInColumn=false;
              if (_thisDoc$.findReplace.find('^// *@.*View2'))                        // nach WebView2 suchen
                {                                                                     // wenn gefunden
                  _con.write(_thisDoc$.currentLineNum.toString(10));
                  if (_thisDoc$.currentLineNum == 1)                                  // in Zeile 1
                    {
                      _thisDoc$.gotoLine(2,1);                                        // dann unterhalb einfügen
                      if (_cUrrentLine < 2) gotoTop = true;
                    }
                  else _thisDoc$.top();                                               // ansonsten in Zeile 1 einfügen
                }
      
              _comment$[0] = "// ";                                                   // obere Kopflinie
              _comment$[0] = fn_fillTrailingChars(_comment$[0], _comment$[0].length, _length,'=');
      
              _comment$[1] = "// Scriptname    :  " + _FileName;                      // Skriptname mit <==> Filename
              _comment$[1] = fn_fillTrailingChars(_comment$[1], _comment$[1].length, _length,' ');
      
              _comment$[2] = "// Aufgabe       :  ";                                  // Aufgabe
              _comment$[2] = fn_fillTrailingChars(_comment$[2], _comment$[2].length, _length,' ');
      
              _comment$[3] = "// Beschreibung  :  ";                                  // Beschreibung
              _comment$[3] = fn_fillTrailingChars(_comment$[3], _comment$[3].length, _length,' ');
      
              _comment$[4] = "// Author        :  Frank Schulze";                     // Author
              _comment$[4] = fn_fillTrailingChars(_comment$[4],_comment$[4].length, _length,' ');
      
              _comment$[5] = "// Datum         :  " + fn_createDate();                // Datum mit <==> Erstellungsdatum
              _comment$[5] = fn_fillTrailingChars(_comment$[5],_comment$[5].length, _length,' ');
      
              _comment$[6] = "// Pfad          :  " + _Path;                          // Pfad mit <==> Pfad
              _comment$[6] = fn_fillTrailingChars(_comment$[6], _comment$[6].length, _length,' ');
      
              _comment$[7] = _comment$[0];
              _thisDoc$.write(_comment$.join(""));
              if (!gotoTop) _cUrrentLine += _comment$.length;
            }
          else if (result == 1)                                                       // wenn 1 (Funktionskopf)
            {
              _thisDoc$.selectLine();                                                 // Zeile markieren
              _selRow$  = _thisDoc$.selection;                                        // und sichern
              _thisDoc$.gotoLine(_cUrrentLine,1);                                     // zur alten Pos. zurückkehren (hebt Markierung wieder auf)
      
              _comment$[0] = "// ";
              _comment$[0] = fn_fillTrailingChars(_comment$[0], _comment$[0].length, _length,'=');
      
              getFuncName(_selRow$);                                                  // <==> erstellt Funktionsname und event. nötige Parameterabschnitte
              var lineIndex = _comment$.length;
      
              _comment$[lineIndex] = "// Aufgabe       :  ";                          // Aufgabe
              _comment$[lineIndex] = fn_fillTrailingChars(_comment$[lineIndex], _comment$[lineIndex].length, _length,' ');
              lineIndex++;
      
              if (_bolFunc)                                                           // wenn Funktion, dann Rückgabe berücksichtigen
                {
                  _comment$[lineIndex] = "// Rückgabe      :  ";
                  _comment$[lineIndex]= fn_fillTrailingChars(_comment$[lineIndex], _comment$[lineIndex].length, _length,' ');
                  lineIndex++;
                }
      
              _comment$[lineIndex] = "// Author        :  Frank Schulze";
              _comment$[lineIndex] = fn_fillTrailingChars(_comment$[lineIndex], _comment$[lineIndex].length, _length,' ');
              lineIndex++;
      
              _comment$[lineIndex] = "// Datum         :  " + fn_createDate();
              _comment$[lineIndex] = fn_fillTrailingChars(_comment$[lineIndex], _comment$[lineIndex].length, _length,' ');
              lineIndex++;
      
              _comment$[lineIndex] = _comment$[0];
              _thisDoc$.write(_comment$.join(""));
              _cUrrentLine += _comment$.length;
            }
          _thisDoc$.gotoLine(_cUrrentLine,1);
        }
      
      // ===================================================================================================
      // Funktion      :  fn_createDate()                                                                    <==
      // Aufgabe       :
      // Rückgabe      :  fertiges Datum (german)
      // Author        :  ??
      // Datum         :  ??.??.????
      // ===================================================================================================
      function fn_createDate()
        {
          var currentDate = new Date();
          currentDate.setDate(currentDate.getDate());
          var d = currentDate.getDay();
          var dt = currentDate.getDate();
          dt = (dt < 10 ? '0' : '') + dt;
          var m = currentDate.getMonth() + 1;
          m = (m < 10 ? '0' : '') + m;
          var year = currentDate.getFullYear();
          var mn = currentDate.getMinutes();
          mn = (mn < 10 ? '0' : '') + mn;
          var hr = currentDate.getHours();
          hr = (hr < 10 ? '0' : '') + hr;
          var _strDate = dt + "." + m + "." + year;
          return _strDate;
        }
      
      // ===================================================================================================
      // Funktion      :  fn_fillTrailingChars(_comment$, _startCol, _numChars, _char$)                      <==
      // Parameter 1   :  _comment$ =  bisheriger 'Vorstring'                                                <==
      // Parameter 2   :  _startCol =  Startposition (ab Ende des 'Vorstrings')                              <==
      // Parameter 3   :  _numChars =  Anzahl Spalten insgesamt                                              <==
      // Parameter 4   :  _char$    =  Füllzeichen                                                           <==
      // Aufgabe       :  erstellt Kommentarblöcke mit fester einstellbarer Breite
      // Rückgabe      :  fertige Kommentarzeile
      // Author        :  Frank Schulze
      // Datum         :  19.04.2023                                                                         <==
      // ===================================================================================================
      function fn_fillTrailingChars(_comment$, _startCol, _numChars, _char$)
        {
          for (_startCol; _startCol < _numChars; _startCol++)                         // Schleife: von akt. Pos. bis max. Spalte
            {
              _comment$ += _char$;                                                    // mit angegebenen Zeichen auffüllen
            }
          _comment$ += '\r\n';                                                        // zum Schluss noch ein Zeilenende anhängen
          return _comment$;                                                           // fertigen String an Funktion zurückgeben
        }
      
      // ===================================================================================================
      // Funktion      :  getFuncName(_Row$)                                                                 <==
      // Parameter 1   :  _Row$ = String mit der akt. Zeile                                                  <==
      // Aufgabe       :
      // Author        :  Frank Schulze
      // Datum         :  29.04.2023                                                                         <==
      // ===================================================================================================
      function getFuncName(_Row$)
        {
          const _obj = /(function\W+)(\w+) ?\((.*)\)/.exec(_Row$);                    // prüft, ob ein Funktionsnamen gefunden werden kann
                                                                                      // und erstellt ein neues Objekt wenn ja
          var _found$     = "";
          var lineIndex = _comment$.length;
          if (_obj === null)                                                          // nicht gefunden ?
            {
              _found$ = "nicht gefunden !";                                           // Fehlermeldung generieren
              _con.write(_found$);                                                    // und ausgeben
            }
          else                                                                        // sonst
            {
              var _Parameter$ = _obj[3];                                              // Parameterstring sichern
              _found$ = _obj[0].substring(9,_obj[0].length);                          // gefundenen Funktionsnamen sichern
              if (_found$.match(/^fn.+/) !== null) _bolFunc=true;                     // wenn fn
              _comment$[lineIndex] = "// Funktion      :  " + _found$;
              _comment$[lineIndex] = fn_fillTrailingChars(_comment$[lineIndex], _comment$[lineIndex].length, _length, ' ');
              _con.write(_Parameter$ + '+' + _found$);
              if (_Parameter$.length) prepareParameter(_Parameter$);                  // wenn Parameter vorhanden, <==>
            }
        }
      
      // ===================================================================================================
      // Funktion      :  prepareParameter(_Parameter$)                                                      <==
      // Parameter 1   :  _Parameter$ =                                                                      <==
      // Aufgabe       :
      // Author        :  Frank Schulze
      // Datum         :  30.04.2023                                                                         <==
      // ===================================================================================================
      function prepareParameter(_Parameter$)
        {
          var lineIndex = _comment$.length;
          var i           = 0;
          var _ParamList$ = "";
          var _tmpSplit$  = _Parameter$.split(',');                                   // Parameterstring bei vorhandenem Komma teilen
          var _numParam   = _tmpSplit$.length;                                        // Anz. Parameter ermitteln
          while (i < _numParam)                                                       // Schleife für Anzahl
            {
              _ParamList$ = _tmpSplit$[i];
              _ParamList$ += ' = ';
      
              _comment$[lineIndex] = "// Parameter " + (i + 1) + "   :  " + _ParamList$.trim();
              _comment$[lineIndex] = fn_fillTrailingChars(_comment$[lineIndex], _comment$[lineIndex].length, _length, ' ');
              lineIndex++;
              i++;
            }
        }
      The main goal was to decrease the number of document writes to one to create just one undo record by using an array of comment lines to add and write all the lines as one block into the active file.

      The second goal was to really set back the caret to initial line after inserting the comment lines. There can be even more optimized and improved but it is already very late now in Austria.

      The script is linted with 0 errors and 0 warnings. JavaScript Lint is embedded in UltraEdit v2023.0.0.41 and should be run on an UltraEdit script for detecting errors and potential problems before running the script.

      Please let me know if you have questions regarding to my changes.
      Best regards from an UC/UE/UES for Windows user from Austria

      16
      Basic UserBasic User
      16

        May 09, 2023#3

        Hi,


        Thanks for your effort.
        Sorry for not getting back to you sooner. Had a lot to do the last few days.

        I have a few questions now:

        Code: Select all

        _con.write(_thisDoc$.currentLineNum.toString(10));
        - Where is the difference to .toString()?

        - I had taken the getString() instead of the getValue() m on purpose, because the default '0' bothers me a bit.
          (0 is not a selection for me, max for cancel). Is it possible to suppress the default?

        - How do I determine the current user?

        The idea to wrap the comment lines in an array is a cool idea !!!


        By the way: WebView2 still doesn't work. Uninstalled it and reinstalled it. Nothing. Very sad.

        greetings
        (Translated with DeepL)
        Win10 Pro (64bit) 22H2 - UE 2023.2.0.27 64-bit

        6,602547
        Grand MasterGrand Master
        6,602547

          May 10, 2023#4

          The value 10 for decimal system is the default of function toString() on function parameter not explicitly specified in the script. It is my coding style to always explicitly specify function parameter values in scripts to see what is really used without reading the documentation of the function and to make the script independent on defaults as defaults might change in future.

          It is not possible to suppress default value 0 of function getValue(). I requested once having the default value 0 pre-selected in the opened dialog window so that the user just has to enter the new value. But this little enhancement request has not yet been implemented in UE/UES. If you prefer for that reason getString(), you can use that function. But please note that the returned value is now a string and not a number. The comparisons should be with strings like result != "0" instead of !result or result == "1" instead of result == 1 for type correct comparisons.

          A user must not sign in on UltraEdit to use it. There is no user name variable available in UltraEdit for that reason. You can configure and run from within the script a user tool which queries the name of the current user from windows registry and outputs the information to standard output which is captured by UltraEdit to the output window and read by the script from the output window.

          You should contact by email the UltraEdit support regarding to the WebView2 usage problem.

          There can be even more optimized for the script to decrease the number of instructions the CPU has to perform for the same result although a script user would not notice a difference on further optimizations. The most important optimizations were writing the lines as one block into the file for recording just one undo step and cause a minimum on window updates and have the caret on correct line after inserting the comment block.
          Best regards from an UC/UE/UES for Windows user from Austria

          16
          Basic UserBasic User
          16

            May 10, 2023#5

            Hi,
            If you prefer for that reason getString(), you can use that function. But please note that the returned value is now a string and not a number. The comparisons should be with strings like result != "0" instead of !result or result == "1" instead of result == 1 for type correct comparisons.
            Thank you, I have taken into account .
            You can configure and run from within the script a user tool which queries the name of the current user from windows registry and outputs the information to standard output which is captured by UltraEdit to the output window and read by the script from the output window.
            Did I mention that I'm just getting into JavaScript? (Not easy when switching from VBA to JavaScript).
            Do you have a basic framework that shows me the way?

            Is it possible to disable the screen refresh for scripts as well, like with macros?
            (Translated with DeepL)
            Win10 Pro (64bit) 22H2 - UE 2023.2.0.27 64-bit

            6,602547
            Grand MasterGrand Master
            6,602547

              May 11, 2023#6

              I don't have a basic framework. I have some smart templates defined for myself for often needed code blocks, but nothing which is designed for general usage.

              There can be opened in UltraEdit with a click on ribbon tab Layout in third group Lists on check box item Tags the Tag List view. Next select the tag group UE/UES Script Commands for inserting UE/UES specific script commands and properties with a double click on an item in this list. into active file at current caret position In toolbar/menu mode with contemporary menus clicking in menu Layout on menu item Tags opens also the Tag List view. This view can be opened in toolbar/menu mode with traditional menus by clicking in menu View in submenu menu Views/lists in submenu Lists on menu item Tag list.

              Please take a look on announcement topic JavaScript tutorial, power tips and more for more JavaScript related staff helping hopefully beginners in writing UltraEdit scripts.

              Please note further that there is JavaScript Lint embedded in UltraEdit. In ribbon mode click on ribbon tab Coding in fourth group Formatting on small down arrow below item JS/CSS and click in popup menu on menu item JavaScript Lint. In toolbar/menu mode with contemporary menus click in menu Coding in submenu JS/CSS on menu item JavaScript Lint to check the active script file with that third-party utility installed together with UltraEdit/UEStudio. The tool can be run on active script file in toolbar/menu mode with traditional menus by clicking in menu Format in submenu JS/CSS on menu item JavaScript Lint.

              There is no configuration setting to disable window updates while the script is running. The available settings are in Advanced - Settings or Configuration - Scripting. There are in general two techniques to avoid window updates on reformatting a file with a script. The first one is loading the entire file contents as string into memory of script interpreter, reformat the file contents in memory of script interpreter using only functions of the JavaScript String object and other JavaScript core functions and finally overwrite the entire file contents with the reformatted data of the string variable in memory of script interpreter. That method can be used only for small files as the amount of memory for script interpreter is small even on several GB of RAM being currently free. The other method is working with maximized document windows as used by most users and avoid document window refreshes by getting the document index of active file, creating a new file becoming the active file with an empty document window taking over entire document window area inside UE/UES main application window, using now all UltraEdit.document commands with the document index of initial active file of which window is behind the new file window and finally close the new file without saving it.
              Best regards from an UC/UE/UES for Windows user from Austria