www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

preferences_general.js (3725B)


      1 /*
      2     ***** BEGIN LICENSE BLOCK *****
      3     
      4     Copyright © 2006–2013 Center for History and New Media
      5                      George Mason University, Fairfax, Virginia, USA
      6                      http://zotero.org
      7     
      8     This file is part of Zotero.
      9     
     10     Zotero is free software: you can redistribute it and/or modify
     11     it under the terms of the GNU Affero General Public License as published by
     12     the Free Software Foundation, either version 3 of the License, or
     13     (at your option) any later version.
     14     
     15     Zotero is distributed in the hope that it will be useful,
     16     but WITHOUT ANY WARRANTY; without even the implied warranty of
     17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18     GNU Affero General Public License for more details.
     19     
     20     You should have received a copy of the GNU Affero General Public License
     21     along with Zotero.  If not, see <http://www.gnu.org/licenses/>.
     22     
     23     ***** END LICENSE BLOCK *****
     24 */
     25 
     26 "use strict";
     27 
     28 Components.utils.import("resource://gre/modules/Services.jsm");
     29 Components.utils.import("resource://gre/modules/osfile.jsm");
     30 
     31 Zotero_Preferences.General = {
     32 	init: function () {
     33 		// JS-based strings
     34 		var checkbox = document.getElementById('launchNonNativeFiles-checkbox');
     35 		if (checkbox) {
     36 			checkbox.label = Zotero.getString(
     37 				'zotero.preferences.launchNonNativeFiles', Zotero.appName
     38 			);
     39 		}
     40 		
     41 		document.getElementById('noteFontSize').value = Zotero.Prefs.get('note.fontSize');
     42 		
     43 		this._updateFileHandlerUI();
     44 	},
     45 	
     46 	//
     47 	// File handlers
     48 	//
     49 	chooseFileHandler: function (type) {
     50 		var pref = this._getFileHandlerPref(type);
     51 		var currentPath = Zotero.Prefs.get(pref);
     52 		
     53 		var nsIFilePicker = Components.interfaces.nsIFilePicker;
     54 		var fp = Components.classes["@mozilla.org/filepicker;1"]
     55 			.createInstance(nsIFilePicker);
     56 		if (currentPath) {
     57 			fp.displayDirectory = Zotero.File.pathToFile(OS.Path.dirname(currentPath));
     58 		}
     59 		fp.init(
     60 			window,
     61 			Zotero.getString('zotero.preferences.chooseApplication'),
     62 			nsIFilePicker.modeOpen
     63 		);
     64 		fp.appendFilters(nsIFilePicker.filterApps);
     65 		if (fp.show() != nsIFilePicker.returnOK) {
     66 			this._updateFileHandlerUI();
     67 			return false;
     68 		}
     69 		var newPath = OS.Path.normalize(fp.file.path);
     70 		this.setFileHandler(type, newPath);
     71 	},
     72 	
     73 	setFileHandler: function (type, handler) {
     74 		var pref = this._getFileHandlerPref(type);
     75 		if (handler) {
     76 			Zotero.Prefs.set(pref, handler);
     77 		}
     78 		else {
     79 			Zotero.Prefs.clear(pref);
     80 		}
     81 		this._updateFileHandlerUI();
     82 	},
     83 	
     84 	_updateFileHandlerUI: function () {
     85 		var handler = Zotero.Prefs.get('fileHandler.pdf');
     86 		var menulist = document.getElementById('fileHandler-pdf');
     87 		var customMenuItem = document.getElementById('fileHandler-custom');
     88 		if (handler) {
     89 			let icon;
     90 			try {
     91 				let fph = Services.io.getProtocolHandler("file")
     92 					.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
     93 				let urlspec = fph.getURLSpecFromFile(Zotero.File.pathToFile(handler));
     94 				icon = "moz-icon://" + urlspec + "?size=16";
     95 			}
     96 			catch (e) {
     97 				Zotero.logError(e);
     98 			}
     99 			
    100 			let handlerFilename = OS.Path.basename(handler);
    101 			if (Zotero.isMac) {
    102 				handlerFilename = handlerFilename.replace(/\.app$/, '');
    103 			}
    104 			customMenuItem.setAttribute('label', handlerFilename);
    105 			if (icon) {
    106 				customMenuItem.className = 'menuitem-iconic';
    107 				customMenuItem.setAttribute('image', icon);
    108 			}
    109 			else {
    110 				customMenuItem.className = '';
    111 			}
    112 			customMenuItem.hidden = false;
    113 			menulist.selectedIndex = 0;
    114 		}
    115 		else {
    116 			customMenuItem.hidden = true;
    117 			menulist.selectedIndex = 1;
    118 		}
    119 	},
    120 	
    121 	_getFileHandlerPref: function (type) {
    122 		if (type != 'pdf') {
    123 			throw new Error(`Unknown file type ${type}`);
    124 		}
    125 		return 'fileHandler.pdf';
    126 	}
    127 }