/* * This object contains the various functions for the interface */ var ScholarPane = new function() { var collectionsView; var itemsView; var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); //Privileged methods this.onLoad = onLoad; this.onUnload = onUnload; this.toggleDisplay = toggleDisplay; this.fullScreen = fullScreen; this.newItem = newItem; this.newCollection = newCollection; this.onCollectionSelected = onCollectionSelected; this.itemSelected = itemSelected; this.deleteSelectedItem = deleteSelectedItem; this.deleteSelectedCollection = deleteSelectedCollection; this.renameSelectedCollection = renameSelectedCollection; this.search = search; this.getCollectionsView = getCollectionsView; this.getItemsView = getItemsView; this.buildCollectionContextMenu = buildCollectionContextMenu; this.buildItemContextMenu = buildItemContextMenu; this.openNoteWindow = openNoteWindow; /* * Called when the window is open */ function onLoad() { //Initialize collections view collectionsView = new Scholar.CollectionTreeView(); document.getElementById('collections-tree').view = collectionsView; if(Scholar.Prefs.get("scholarPaneOnTop")) { var oldPane = document.getElementById('scholar-pane'); var oldSplitter = document.getElementById('scholar-splitter'); var appContent = document.getElementById('appcontent'); var newPane = document.createElement('hbox'); newPane.setAttribute('id','scholar-pane'); newPane.setAttribute('collapsed',true); newPane.setAttribute('flex','1'); while(oldPane.hasChildNodes()) newPane.appendChild(oldPane.firstChild); appContent.removeChild(oldPane); appContent.insertBefore(newPane, document.getElementById('content')); var newSplitter = document.createElement('splitter'); newSplitter.setAttribute('id','scholar-splitter'); newSplitter.setAttribute('collapsed',true); newSplitter.setAttribute('resizebefore','closest'); newSplitter.setAttribute('resizeafter','closest'); appContent.removeChild(oldSplitter); appContent.insertBefore(newSplitter, document.getElementById('content')); } //Create the add menu with each item type var addMenu = document.getElementById('tb-add').firstChild; var itemTypes = Scholar.ItemTypes.getTypes(); for(var i = 0; i 0 && confirm(Scholar.getString('pane.items.delete'))) itemsView.deleteSelection(); } function deleteSelectedCollection() { if(collectionsView.selection.count > 0 && confirm(Scholar.getString('pane.collections.delete'))) collectionsView.deleteSelection(); } function renameSelectedCollection() { if(collectionsView.selection.count > 0) { collection = collectionsView._getItemAtRow(collectionsView.selection.currentIndex); var newName = prompt(Scholar.getString('pane.collections.rename'),collection.getName()); if(newName) collection.ref.rename(newName); } } function search() { if(itemsView) { searchVal = document.getElementById('tb-search').value; itemsView.searchText(searchVal); //do something about granularity //document.getElementById('scholar-search-options').getElementsByAttribute('checked','true')[0].label document.getElementById('scholar-search-options').hidden = searchVal == ""; } } function getCollectionsView() { return collectionsView; } function getItemsView() { return itemsView; } function buildCollectionContextMenu() { var menu = document.getElementById('scholar-collectionmenu'); if(collectionsView.selection.count == 1 && !collectionsView._getItemAtRow(collectionsView.selection.currentIndex).isLibrary()) { menu.childNodes[2].removeAttribute('disabled'); menu.childNodes[3].removeAttribute('disabled'); } else { menu.childNodes[2].setAttribute('disabled', true); menu.childNodes[3].setAttribute('disabled', true); } } function buildItemContextMenu() { var menu = document.getElementById('scholar-itemmenu'); if(itemsView && itemsView.selection.count > 0) menu.childNodes[2].removeAttribute('disabled'); else menu.childNodes[2].setAttribute('disabled', true); if(itemsView && itemsView.selection.count > 1) menu.childNodes[2].setAttribute('label', Scholar.getString('pane.items.menu.remove.multiple')); else menu.childNodes[2].setAttribute('label', Scholar.getString('pane.items.menu.remove')); } function openNoteWindow(id) { window.open('chrome://scholar/content/note.xul?id='+id,'','chrome,resizable,centerscreen'); } } window.addEventListener("load", function(e) { ScholarPane.onLoad(e); }, false); window.addEventListener("unload", function(e) { ScholarPane.onUnload(e); }, false);