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

This forum is user-to-user based and not regularly monitored by IDM.
Please see the note at the top of this page on how to contact IDM.

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

Postby JoernH » Thu Jan 26, 2012 9:59 am

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
User avatar
JoernH
Basic User
Basic User
 
Posts: 15
Joined: Tue Mar 10, 2009 10:41 am
Location: Belgium

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

Postby Mofi » Thu Jan 26, 2012 10:30 am

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3936
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

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

Postby JoernH » Thu Jan 26, 2012 10:38 am

Dear Mofi,

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

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

Kind regards

JoernH
User avatar
JoernH
Basic User
Basic User
 
Posts: 15
Joined: Tue Mar 10, 2009 10:41 am
Location: Belgium

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

Postby Mofi » Fri Jan 27, 2012 2:03 am

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();
   }
}
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3936
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

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

Postby JoernH » Fri Jan 27, 2012 2:38 am

Awesome Mofi !

Thanx 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
User avatar
JoernH
Basic User
Basic User
 
Posts: 15
Joined: Tue Mar 10, 2009 10:41 am
Location: Belgium


Return to UltraEdit General Discussion