General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion How to open a file "Read Only" in XMetal Author 5.5 in Jscript?

  • pszwec

    How to open a file "Read Only" in XMetal Author 5.5 in Jscript?

    Participants 2
    Replies 3
    Last Activity 10 years, 7 months ago

    The current line is  Documents.Open(cfile);

    I thought I could just change it to this ” Documents.Open(cfile, 1);” (based on Jscript open textfile at MSDN 1-read access, 2=write access, 8=read/write access) and it would work.

    Thanks Derek in advance,

    Peter

    Reply

    Derek Read

    Reply to: How to open a file "Read Only" in XMetal Author 5.5 in Jscript?

    Our Open() API does not support a parameter that lets you set a file's read-only attribute. If you pass a number as the second parameter that is interpreted as the view to open the document in. See your copy of the Programmers Guide (or [url=http://na.justsystems.com/webhelp/en/xmetaldeveloper/pg/6.0/pg.html#Open]Documents.Open[/url])

    JScript doesn't have such functionality either. I suspect you might be reading Microsoft's documentation for the File System Object (aka: FSO), so you are close but not quite at the right location.

    To do what you want to do (a bit of guessing here) you would call our Documents.Open() API as documented in the Programmers Guide and then you might make an additional call to FSO. FSO is not the only way to do this, but it is easy to use with JScript. Following is adapted from http://msdn.microsoft.com/en-us/library/5tx15443%28VS.85%29.aspx

    //XMetaL Script Language JScript:
    function setReadOnlyBit(filespec,boolSet) {
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var f = fso.GetFile(filespec);
    if (f.attributes & 1) {
    if(boolSet == false) {
    f.attributes = f.attributes - 1;
    }
    }
    else {
    if(boolSet == true) {
    f.attributes = f.attributes + 1;
    }
    }
    }

    var filepath = "C:\temp\mytestfile.xml";

    //pass true to add the read-only bit
    setReadOnlyBit(filepath,true);
    Application.Alert("read only bit has been set (check before dismissing this dialog)");

    //pass false to remove the read-only bit
    setReadOnlyBit(filepath,false);
    Application.Alert("read only bit has been removed");

    Keep in mind that XMetaL Author will allow you to open files with this bit set. It is up to the customizer to decide what the product's behavior should be in this case. With most of the CMS integrations for XMetaL a “read only” file (which may have different meanings in the CMS sense) is allowed to open but the CSS that styles the file is changed to show the entire document with a grey background (or similar indicator) and a call to an API named Selection.ReadOnly is run on the root element so the author does not waste time editing the file (in most CMS systems there is no concept of “Save As”). In your case, if you are storing files on the local file system you might wish to allow users to both open and edit these files. In this case XMetaL Author should ask the author to do a Save As when they try to Save (unless you have overridden those commands by creating your own Save and / or Save As functionality).

    If your goal is to allow multiple users to work on the same files without overwriting changes other people have made you may wish to look at one of the existing integrations we have with various CMS systems. If your budget is low you might also look at SVN or Mercurial.

    Reply

    pszwec

    Reply to: How to open a file "Read Only" in XMetal Author 5.5 in Jscript?

    Thanks, I'll look at this.

    My goal is to let users open a file without being able to change anything. (At least not save changes back) They just want to view a file, maybe cut some text from it. Currently LCS (Kirsten's group) has code in there that updates the element and element even is you just open the file to look.

    Reply

    pszwec

    Reply to: How to open a file "Read Only" in XMetal Author 5.5 in Jscript?

    OK, that works fine. I guess I have to turn the read only bit back off upon file close. IS pressing the X in the upper right run the same code as File, Close? If not, how would I set the read only bit back?

    Thanks

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support