瀏覽代碼

Implement astl-load-from-file

pull/15/head
10sr 9 年之前
父節點
當前提交
3ea3690bf2
共有 1 個文件被更改,包括 24 次插入1 次删除
  1. +24
    -1
      _keysnail.js

+ 24
- 1
_keysnail.js 查看文件

@@ -271,6 +271,7 @@ var autoSaveTabList = (function(){
function selectDirectory(title){
// open dialog and return nsILocalFile object
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsILocalFile
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFilePicker
// this function blocks.
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"].
@@ -285,6 +286,24 @@ var autoSaveTabList = (function(){
return fp.file;
}

function selectFile(title){
// open dialog and return nsILocalFile object
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsILocalFile
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFilePicker
// this function blocks.
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"].
createInstance(nsIFilePicker);
fp.init(window, title, nsIFilePicker.modeOpen);

// block
var res = fp.show();
if (res !== nsIFilePicker.returnOK) {
return null;
}
return fp.file;
}

function setup(){
// set destination directory
var dstdir = selectDirectory("Select Directory to Save Tab List");
@@ -349,7 +368,9 @@ var autoSaveTabList = (function(){

function openFromFile(){
var file = selectFile();
openFromLFSplittedString(util.readTextFile(file));
if (file) {
openFromLFSplittedString(util.readTextFile(file.path));
}
}

function openFromClipboard(){
@@ -371,11 +392,13 @@ var autoSaveTabList = (function(){
getTabList: getTabList,
saveCurrentList: saveCurrentList,
openFromClipboard: openFromClipboard
openFromFile: openFromFile
};
})();

ext.add("astl-setup", autoSaveTabList.setup, "Auto save tab list - Setup");
ext.add("astl-open-from-clipboard", autoSaveTabList.openFromClipboard, "Auto save tab list - Open tabs from clipboard");
ext.add("astl-open-from-file", autoSaveTabList.openFromFile, "Auto save tab list - Open tabs from local file");
ext.add("astl-save-current", autoSaveTabList.saveCurrentList,
"Auto save tab list - Save current list");



Loading…
取消
儲存