[Zope-CVS] CVS: Packages/Moztop/moztop/content/Explorer - Explorer.js:1.1 ExplorerOverlay.xul:1.1

Paul Everitt paul@zope.com
Sat, 25 Jan 2003 12:44:05 -0500


Update of /cvs-repository/Packages/Moztop/moztop/content/Explorer
In directory cvs.zope.org:/tmp/cvs-serv32357/Explorer

Added Files:
	Explorer.js ExplorerOverlay.xul 
Log Message:
Made the move to using rdf files in the profile dir, courtesy of 
the snippet from ScottR.  This means:

  o A new dir "Explorer" to replace Inspector, since we 
  don't have tabs in the left side now

  o No connection made on startup yet (more repair later)

  o For now, you have to manually copy Data/moztop*rdf to 
  your profile dir, because 5 hours of fighting jslib 
  ended in defeat.

Since the URN structure has changed and the id of the 
element with the datasources has changed, more work 
has to be done to get it operational.



=== Added File Packages/Moztop/moztop/content/Explorer/Explorer.js ===
/*****************************************************************************
*
* Copyright (c) 2002, 2003 Zope Corporation and Contributors.
* All Rights Reserved.
*
* This software is subject to the provisions of the Zope Public License,
* Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
* WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
******************************************************************************
Explorer library; here to manage Content Object Tree.

$Id: Explorer.js,v 1.1 2003/01/25 17:44:02 paul Exp $

******************************************************************************/

// Using jslib "include", import some io utilities
include('chrome://moztop/content/jslib/io/io.js');
include('chrome://moztop/content/jslib/io/filesystem.js');


/* XML-RPC client setup. */
function getClient() {
    return Components.classes['@mozilla.org/xml-rpc/client;1']
        .createInstance(Components.interfaces.nsIXmlRpcClient);
}

var xmlRpcClient;
function getXmlRpc() {
    if (!xmlRpcClient) xmlRpcClient = getClient();
    return xmlRpcClient;
}

var Listener = {
    onResult: function(client, ctxt, result) {
        result = result.QueryInterface(
	    Components.interfaces.nsISupportsCString);
	alert(result.toString());
    },

    onFault: function(client, ctxt, fault) {
        alert('Fault! ' + fault + '\n');
    },

    onError: function(client, ctxt, status, errorMsg) {
        alert('Error! <(' + status.toString(16) + ') ' + errorMsg + '>\n');
    }
};

/* Send the Add request via XML-RPC and handle the result. */
function add(parent, obj_type, obj_name) {
    var xmlRpc = getXmlRpc();
    xmlRpc.init(XMLRPC_BASE + parent);
    var type = xmlRpc.createType(xmlRpc.STRING, {});
    type.data = obj_type;
    var name = xmlRpc.createType(xmlRpc.STRING, {});
    name.data = obj_name;
    xmlRpc.asyncCall(Listener, null, 'createAndAdd', [type, name], 2);
} 

/* Add a content object to the folder that is selected in the tree. */
function addContentObject() {
    var type = document.getElementById("field_obj_type").selectedItem.label;
    var name = document.getElementById("field_obj_name").value;
    var tree = document.getElementById("navigationtree");
    var parent = getContainerPath()

    add(parent, type, name);
}

/* Delete a content object from the folder that is selected in the tree. */
function deleteContentObject() {
    var obj_name = getObjectName();
    var parent = getContainerPath();

    var xmlRpc = getXmlRpc();
    xmlRpc.init(XMLRPC_BASE + parent);
    var name = xmlRpc.createType(xmlRpc.STRING, {});
    name.data = obj_name;
    xmlRpc.asyncCall(Listener, null, 'deleteObject', [name], 1);
}

/* Rename a content object in the folder that is selected in the tree. */
function renameContentObject() {
    var new_name = document.getElementById("field_obj_name").value;
    var old_name = getObjectName();
    var parent = getContainerPath();

    rename(parent, old_name, new_name);
}

function rename(parent, old_name, new_name) {
    var xmlRpc = getXmlRpc();
    xmlRpc.init(XMLRPC_BASE + parent);
    var oldName = xmlRpc.createType(xmlRpc.STRING, {});
    oldName.data = old_name;
    var newName = xmlRpc.createType(xmlRpc.STRING, {});
    newName.data = new_name;
    xmlRpc.asyncCall(Listener, null, 'renameObject', [oldName, newName], 2);
}

function cutContentObject() {
    var obj_name = getObjectName();
    var path = getContainerPath();

    alert('Called cutContentObject for ' + obj_name + ' on ' + path +'.');
}

function copyContentObject() {
    var obj_name = getObjectName();
    var parent = getContainerPath();

    var xmlRpc = getXmlRpc();
    xmlRpc.init(XMLRPC_BASE + parent);
    var name = xmlRpc.createType(xmlRpc.STRING, {});
    name.data = obj_name;
    xmlRpc.asyncCall(Listener, null, 'copyObject', [name], 1);

}

function pasteContentObject() {
    var path = getContainerPath();

    alert('Called pasteContentObject on ' + path +'.');
}

/* Utility functions */
function getPath() {
    var tree = document.getElementById("navigationtree");
    var index = tree.view.selection.currentIndex;
    var rdf = tree.view.getItemAtIndex(index).resource;
    var path = rdf.Value.replace('urn:explorer:data', '');
    while (path.indexOf(":") > -1)
	path = path.replace(":", "/");

    return path
}

function getContainerPath() {
    var path = getPath()
    var obj_name = getObjectName()
    var container = path.substring(0, path.length-obj_name.length);

    return container
}

function getObjectName() {
    var path = getPath()
    var parts = path.split('/');
    var obj_name = parts[parts.length-1];
    
    return obj_name
}


=== Added File Packages/Moztop/moztop/content/Explorer/ExplorerOverlay.xul ===
<?xml version="1.0"?>

<overlay id="ExplorerOverlay" 
         xmlns:z="http://www.zope.org/rdf/content#"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script src="Explorer.js"/>

<vbox id="explorer">
<tree flex="1" 
    id="navigationtree" ref="urn:moztop:sites" 
    datasources="rdf:null" 
    containment="http://home.netscape.com/NC-rdf#subitems">
  <treecols>
    <treecol id="ResourceNameColumn" label="Name" primary="true" flex="1"/>
    <splitter class="tree-splitter"/>
    <treecol id="TypeColumn" label="Type" flex="1" hidden="true"/>
  </treecols>

   <template>
      <rule>
        <conditions>
          <content uri="?uri" />
          <triple subject="?uri"
                  predicate="http://home.netscape.com/NC-rdf#subitems"
                  object="?subitems" />
          <member container="?subitems" child="?subitem" />
       </conditions>

        <bindings>
            <binding subject="?subitem"
                    predicate="http://www.purl.org/dc/1.1#title"
                    object="?name" />
          <binding subject="?subitem"
                   predicate="http://www.zope.org/rdf/site#resourcetype"
                   object="?resourcetype" />
            <binding subject="?resourcetype"
                    predicate="http://www.purl.org/dc/1.1#title"
                    object="?resourcetypetitle"/>
            <binding subject="?resourcetype"
                    predicate="http://www.zope.org/rdf/site#styleid"
                    object="?styleid"/>
        </bindings>

        <action>
            <treechildren onclick="treechildSelect();" flex="1">
                <treeitem uri="?subitem">
                    <treerow>
                        <treecell properties="zope-?styleid" label="?name"/>
			<treecell label="?resourcetypetitle"/>
                    </treerow>
                </treeitem>
            </treechildren>
        </action>
      </rule>
    </template>
</tree>


<box orient="vertical">
  <box orient="horizontal">
    <menulist id="field_obj_type" label="Type">
      <menupopup>
        <menuitem label="Folder" />
        <menuitem label="File" />
        <menuitem label="Image" />
        <menuitem label="ZPTPage" />
        <menuitem label="DTMLPage" />
        <menuitem label="SQLScript" />
      </menupopup>
    </menulist>
    <textbox id="field_obj_name" value="Name" flex="1" />
  </box>
  <box orient="horizontal">
    <button command="explorer-add:command" label="Add" />
    <button command="explorer-delete:command" label="Delete" />
    <button command="explorer-rename:command" label="Rename" />
    <!--
     XXX lets replace those buttons by icons. They are too wide and boring.

    <button command="explorer-cut:command" label="Cut" />
    <button command="explorer-copy:command" label="Copy" />
    <button command="explorer-paste:command" label="Paste" />
    -->
  </box>
</box>

<commandset id="explorercommands"> 
  <command id="explorer-add:command" 
           oncommand="window.openDialog('Inspector/AddDialog.xul',
           'Add', 'chrome,modal,centerscreen,width=300,height=100');"/> 
  <command id="explorer-delete:command" oncommand="deleteContentObject();"/> 
  <command id="explorer-rename:command" 
           oncommand="window.openDialog('Inspector/RenameDialog.xul',
           'Rename', 'chrome,modal,centerscreen,width=300,height=100');"/> 
  <command id="explorer-cut:command" oncommand="cutContentObject();"/> 
  <command id="explorer-copy:command" oncommand="copyContentObject();"/> 
  <command id="explorer-paste:command" oncommand="pasteContentObject();"/> 
</commandset> 

<popupset>
  <popup id="explorermenu">
    <menuitem label="Add" command="explorer-add:command" />
    <menuitem label="Delete" command="explorer-delete:command" />
    <menuitem label="Rename" command="explorer-rename:command" />
    <menuseparator/>
    <menuitem label="Cut" command="explorer-cut:command" />
    <menuitem label="Copy" command="explorer-copy:command" />
    <menuitem label="Paste" command="explorer-paste:command" />
  </popup>
</popupset>

</vbox>

</overlay>