webglade

JavaScript library to dynamically create XUL GUI from Glade XML files
git clone https://logand.com/git/webglade.git/
Log | Files | Refs | README | LICENSE

DocOpenManager.js (4306B)


      1 /**
      2  *
      3  * Mantain the list of all open document and display the list in the windows menu
      4  * bar.
      5  *
      6  * @fileName DocOpenManager.js
      7  * @$LastChangedDate: 2004-06-02 13:40:33 +0200 (Wed, 02 Jun 2004) $
      8  * @author Fabio Serra <faser@faser.net>
      9  * @copyright Fabio Serra (The Initial Developer of the Original Code)
     10  * @license Mozilla Public License Version 1.1
     11  *
     12 */
     13 
     14 /**
     15  * Construct a new DocOpenManager object
     16  * @class This class is used to record the list of all opened documents and to
     17  * display it in the window menubar
     18  * @final
     19  * @constructor
     20  * @return A new DocOpenManager object
     21  *
     22 */
     23 function DocOpenManager() {
     24 	//references to the windows pop-up
     25 	this.winMenu = document.getElementById("windows-menu");
     26 	// THL this.winPopup = document.getElementById("windows-popup");
     27 	this.winPopup = document.getElementById("windows-menu_menu");
     28 	//List all opened document - LIFO
     29 	this.docOpened = new Array();
     30 	this.docCounter = 0;
     31 }
     32 
     33 /**
     34  * Add a new document to the list
     35  * @param {XMDManager} XMDManager
     36 */
     37 DocOpenManager.prototype.addDoc = function(XMDManager) {
     38 
     39 	this.docOpened[this.docCounter] = XMDManager;
     40 	var name = XMDManager.name;
     41 	if(name == "") {
     42 		name = "Document " + (this.docCounter + 1);
     43 	}
     44 	var id = "windows_doc_" + this.docCounter;
     45 	var newItem = '<menuitem id="'+ id +'" doccounter="'+ this.docCounter +'" type="radio" name="openDocuments" checked="false" label="'+ name +'" oncommand="loadDoc('+ this.docCounter +')"/>';
     46 	innerXML(this.winPopup,newItem,true);
     47 	this.checkDoc(this.docCounter);
     48 
     49 	this.docCounter++;
     50 }
     51 
     52 /**
     53  * Rename the currently loaded document
     54  * @param {string} newName
     55  * @return void
     56 */
     57 DocOpenManager.prototype.renameCurrentDoc = function(newName) {
     58 	var docCounter = this.getCurrentDocCounter();
     59 	var el = document.getElementById("windows_doc_"+docCounter);
     60 	el.setAttribute("label",newName);
     61 }
     62 
     63 /**
     64  * Remove the document from the window menubar list
     65  * @param {int} docCounter The current index of the document
     66  * @return void
     67 */
     68 DocOpenManager.prototype.removeDoc = function(docCounter) {
     69 	this.docOpened[docCounter] = null;
     70 	var elRemoved = document.getElementById("windows_doc_"+docCounter);
     71 	this.winPopup.removeChild(elRemoved);
     72 }
     73 
     74 /**
     75  * Check the corresponding menuitem
     76  * @param {int} docCounter
     77  * @return void
     78 */
     79 DocOpenManager.prototype.checkDoc = function(docCounter) {
     80 	var el = document.getElementById("windows_doc_"+docCounter);
     81 	var elOld = this.winMenu.getElementsByTagName("menuitem");
     82 	for(var i=0;i<elOld.length;i++) {
     83 		elOld[i].setAttribute("checked","false");
     84 	}
     85 	el.setAttribute("checked","true");
     86 }
     87 
     88 /**
     89  * Get the checked menuitem
     90  * @return the checked element or false
     91 */
     92 DocOpenManager.prototype.getCheckedItem = function() {
     93 //selectedItem and selectIndex doesn't work
     94 	var el = this.winMenu.getElementsByTagName("menuitem");
     95 	var checked = false;
     96 	for(var i=0;i<el.length;i++) {
     97 		checked = el[i].getAttribute("checked");
     98 		if(checked == "true") {
     99 			return el[i];
    100 		}
    101 	}
    102 	return false;
    103 
    104 }
    105 
    106 /**
    107  * Return the current document index
    108  * @type int
    109 */
    110 DocOpenManager.prototype.getCurrentDocCounter = function() {
    111 	var el = this.getCheckedItem();
    112 	var docCounter = el.getAttribute("doccounter");
    113 	return docCounter;
    114 }
    115 
    116 /**
    117  * Get a selected XMDManager
    118  * @return the reference to the selected XMDManager
    119  * @param {int} docCounter
    120  * @return the XMDManager or false
    121 */
    122 DocOpenManager.prototype.getDocument = function(docCounter){
    123 	if(this.docOpened[docCounter]) {
    124 		return this.docOpened[docCounter];
    125 	} else {
    126 		return false;
    127 	}
    128 }
    129 
    130 /**
    131  * Get the current XMDManager
    132  * @return the XMDManager or false
    133 */
    134 DocOpenManager.prototype.getCurrentDocument = function () {
    135 	//selectedItem doesn't works !???
    136 	var el = this.getCheckedItem();
    137 	if(el) {
    138 		var theDoc = this.getDocument(el.getAttribute("doccounter"));
    139 		return theDoc;
    140 	}else{
    141 		return false;
    142 	}
    143 }
    144 
    145 /**
    146  * Retrieve the name of the current document as stated in the menuitem
    147  * @return the string name or false
    148 */
    149 DocOpenManager.prototype.getCurrentDocumentName = function () {
    150 	//selectedItem doesn't works ???
    151 	var el = this.getCheckedItem();
    152 	if(el) {
    153 		return el.getAttribute("label");
    154 	}else{
    155 		return false;
    156 	}
    157 }