"XML convert to CR/LFs" disabled for read-only files

"XML convert to CR/LFs" disabled for read-only files

15
Basic UserBasic User
15

    Jan 26, 2012#1

    Dear readers,

    I notice that the function "XML convert to CR/LFs" does not work for read-only files :-(
    The function is disabled.

    While I realize that it cannot be saved ( since it is read-only ) I'd still like to have the possibility to re-organize the XML file to easier read it. Then it is up to me if I save it as a different file, or discard the changes.

    Typical situation is when I fetch an XML file out of a ZIP file. It then is un-packed by the zip-file reader to a temporary location, and is set to read-only.

    Is this just me, or is this a general opinion that it should work ?

    Kind regards

    JoernH

    6,602548
    Grand MasterGrand Master
    6,602548

      Jan 26, 2012#2

      UltraEdit is in my point of view better than MS Word which allows you to edit a file, but on save informs the user that the file is read-only. Then MS Word let you only save the file using Save As. Modifying the read-only file attribute now and try to save the file again does not work in MS Word. Saving an already modified, previously read-only file is not possible anymore.

      The meaning of read-only attribute is that the file can be just read, not modified. Even a temporary modification should not be possible which of course can work at all only when a copy of the file is created as MS Word always makes on opening and usually also UltraEdit, except the file is very large. But even with a temporary copy of the file a modification of the contents should not be possible if source is read-only.

      Simply change the read-only attribute of the file which can be done also from within UltraEdit with command Edit - Read-Only when having configuration setting Change file read-only attribute when changing menu setting enabled, or copy the contents of the read-only file to a new file and run on this file XML convert to CR/LFs. Running the command on a new, unsaved file works, but without proper indentations. Better is to save the new file as Temp.xml and then run the command.

      UltraEdit handles read-only files as all applications should do, the execution of any command which can modify the contents of a read-only file is blocked, even when a user is not happy with that behavior.

      15
      Basic UserBasic User
      15

        Jan 26, 2012#3

        Dear Mofi,

        Well said indeed! I did not think about it in that way  :(
        ... and a nice tip about the "Edit - Read Only" functionality!

        Thanks a bunch (as usual), and enjoy your day :-)

        Kind regards

        JoernH

        6,602548
        Grand MasterGrand Master
        6,602548

          Jan 27, 2012#4

          I want to give you a solution according to my suggestion. Add following script to the list of scripts and assign a hotkey. Whenever you want to execute XML convert to CR/LFs on any file, press the hotkey for the script.

          You should edit the folder path of the temporary XML file(s) to whatever you like.

          The script requires UltraEdit v17.10 or later because of command UltraEdit.activeDocument.isReadOnly().

          Code: Select all

          if (UltraEdit.document.length > 0)
          {
             if (!UltraEdit.activeDocument.isReadOnly())
             {
                UltraEdit.activeDocument.xmlConvertToCRLF();
             }
             else  // The file is read-only. Copy the contents to
             {     // a temporary XML file with next free file name
                   // and then use xmlConvertToCRLF on this file.
                UltraEdit.activeDocument.selectAll();
                UltraEdit.selectClipboard(9);
                UltraEdit.activeDocument.copy();
                // Discard selection by moving caret to top of the read-only
                // file or close the read-only file, whatever you like more.
                UltraEdit.activeDocument.top();
                // UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
                var nNumber = 1;
                do
                {
                   var sTempFile = "C:\\Temp\\Temp" + nNumber.toString() + ".xml";
                   var nIndex = 0;
                   while (nIndex < UltraEdit.document.length)
                   {
                      if (UltraEdit.document[nIndex].path == sTempFile)
                      {
                         nNumber++;
                         break;
                      }
                      else nIndex++:
                   }
                   if (nIndex == UltraEdit.document.length) nNumber = 0;
                }
                while (nNumber);
                UltraEdit.newFile();
                UltraEdit.activeDocument.paste();
                UltraEdit.clearClipboard();
                UltraEdit.selectClipboard(0);
                UltraEdit.activeDocument.top();
                UltraEdit.saveAs(sTempFile);
                UltraEdit.activeDocument.xmlConvertToCRLF();
             }
          }

          15
          Basic UserBasic User
          15

            Jan 27, 2012#5

            Awesome Mofi!

            Thanks a bunch - exactly what I needed.

            You should take an early day off today and go have a beer! Just send the bill my way  :wink:

            Kind regards

            JoernH

            1

              Dec 09, 2013#6

              While it makes sense to me for this command to be disabled for read-only files, the problem I have is that it is always disabled even for files that are not marked read-only.

              I have tried saving the file as a new file on my local drive, and the command is still not available.

              Is there something else I should check?

              6,602548
              Grand MasterGrand Master
              6,602548

                Dec 10, 2013#7

                The command XML Convert to CR/LFs is only available in UltraEdit for Windows prior v17.10 (UEStudio prior v11.10) if the active file is syntax highlighted with a syntax highlighting language containing in the wordfile in first line the language marker XML_LANG.

                So for a file with an extension not being automatically detected as an XML file, it is first necessary to select XML in submenu View as (Highlighting File Type) in menu View with such a version of UE/UES.

                New file extensions for XML syntax highlighting can be added at any time to the wordfile containing the language definition for XML. With active file syntax highlighted already as XML file, open Advanced - Configuration - Editor Display - Syntax Highlighting. The language XML is already preselected. Click on button Open and close the configuration dialog with button Cancel. In the opened wordfile append to end of the first line the other file extensions which are interpreted not case-sensitive.

                It is also possible to configure default highlighting for new, unsaved files and select language XML to be able to use the command XML Convert to CR/LFs on new, unsaved files.

                The command XML Convert to CR/LFs is available for any file since UE for Windows v17.10 and UES v11.10. The user must be aware of not using this command on files which have no XML structure.
                Best regards from an UC/UE/UES for Windows user from Austria