Ticket #604 (closed enhancement: wontfix)

Opened 5 years ago

Last modified 3 years ago

add cross-platform "ask for filename" function to core

Reported by: EricShulman Owned by: EricShulman
Priority: minor Milestone: 2.7.1
Component: core Version:
Severity: low Keywords:
Cc:

Description (last modified by EricShulman) (diff)

The following cross-platform "ask for filename" functionality is very useful for many plugins (and potentially for future core features). Adding it to the core could greatly reduce the overhead due to having this function defined separately in each plugin:

function askForFilename(msg,path,file,mustExist) {
	if(window.Components)
		var r=mozAskForFilename(msg,path,file,mustExist);
	else if(config.browser.isIE)
		var r=ieAskForFilename(msg,path,file,mustExist);
	else
		var r=prompt(msg,path+file)||""; // fallback
	return r||"";
}

function mozAskForFilename(msg,path,file,mustExist) {
	try {
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		var nsIFilePicker = window.Components.interfaces.nsIFilePicker;
		var picker = Components.classes['@mozilla.org/filepicker;1'].createInstance(nsIFilePicker);
		picker.init(window, msg, ,mustExist?nsiFilePicker.modeOpen:nsIFilePicker.modeSave);
		var thispath = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
		thispath.initWithPath(path);
		picker.displayDirectory=thispath;
		picker.defaultExtension='html';
		picker.defaultString=file;
		picker.appendFilters(nsIFilePicker.filterAll|nsIFilePicker.filterText|nsIFilePicker.filterHTML);
		if (picker.show()!=nsIFilePicker.returnCancel)
			var result=picker.file.persistentDescriptor;
	}
	catch(e) {
		alert('error during local file access: '+e.toString()) }
	}
	return result;
}

function ieAskForFilename(msg,path,file,mustExist) {
	try {
		var s = new ActiveXObject('UserAccounts.CommonDialog');
		s.Filter='All files|*.*|Text files|*.txt|HTML files|*.htm;*.html|';
		s.FilterIndex=3; // default to HTML files;
		s.InitialDir=path;
		s.FileName=file;
		if (s.showOpen())
			var result=s.FileName;
	}
	catch(e) {
		var result=prompt(msg,path+file); } // fallback for pre-XP/IE6
	}
	return result;
}

To support Safari, one or more wrapper functions could be added to TiddlySaver?.jar Java code to support javascript invokation of java file I/O for 'file open' (mustExist=true) and 'file save' (mustExist=false) versions of askForFilename() dialog box.

Change History

Changed 5 years ago by MartinBudden

  • milestone set to 2.5

Changed 5 years ago by EricShulman

  • description modified (diff)

Changed 4 years ago by MartinBudden

  • owner changed from JeremyRuston to EricShulman

Changed 4 years ago by MartinBudden

  • milestone changed from 2.5.1 to 2.5.2

Changed 4 years ago by FND

  • milestone changed from 2.5.3 to 2.6

Changed 3 years ago by MartinBudden

  • status changed from new to closed
  • resolution set to wontfix

No longer a problem, this is fixed as a result of the fix in ticket #1169.

Changed 3 years ago by MartinBudden

  • milestone changed from 2.6.2 to 2.7.1

Milestone 2.6.2 deleted

Note: See TracTickets for help on using tickets.