Bug 803831 - GCLI Command to open Profile Directory. r=jwalker

This commit is contained in:
Gabriel Luong 2014-06-15 22:57:00 -04:00
parent fee35a641c
commit 2265f9a900
5 changed files with 150 additions and 0 deletions

View File

@ -14,6 +14,7 @@ const commandModules = [
"gcli/commands/cmd",
"gcli/commands/cookie",
"gcli/commands/csscoverage",
"gcli/commands/folder",
"gcli/commands/inject",
"gcli/commands/jsb",
"gcli/commands/listen",

View File

@ -50,6 +50,7 @@ support-files =
browser_cmd_csscoverage_sheetB.css
browser_cmd_csscoverage_sheetC.css
browser_cmd_csscoverage_sheetD.css
[browser_cmd_folder.js]
[browser_cmd_inject.js]
support-files =
browser_cmd_inject.html

View File

@ -0,0 +1,58 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that the folder commands works as they should
const TEST_URI = "data:text/html;charset=utf-8,cmd-folder";
function test() {
helpers.addTabWithToolbar(TEST_URI, function(options) {
return helpers.audit(options, [
{
setup: 'folder',
check: {
input: 'folder',
hints: ' open',
markup: 'IIIIII',
status: 'ERROR'
},
},
{
setup: 'folder open',
check: {
input: 'folder open',
hints: ' [path]',
markup: 'VVVVVVVVVVV',
status: 'VALID'
}
},
{
setup: 'folder open ~',
check: {
input: 'folder open ~',
hints: '',
markup: 'VVVVVVVVVVVVV',
status: 'VALID'
}
},
{
setup: 'folder openprofile',
check: {
input: 'folder openprofile',
hints: '',
markup: 'VVVVVVVVVVVVVVVVVV',
status: 'VALID'
}
},
{
setup: 'folder openprofile WRONG',
check: {
input: 'folder openprofile WRONG',
hints: '',
markup: 'VVVVVVVVVVVVVVVVVVVEEEEE',
status: 'ERROR'
}
}
]);
}).then(finish, helpers.handleError);
}

View File

@ -1400,3 +1400,20 @@ injectManual2=Inject common libraries into the content of the page which can als
injectLibraryDesc=Select the library to inject or enter a valid script URI to inject
injectLoaded=%1$S loaded
injectFailed=Failed to load %1$S - Invalid URI
# LOCALIZATION NOTE (folderDesc, folderOpenDesc, folderOpenDir,
# folderOpenProfileDesc) These strings describe the 'folder' commands and
# all available parameters.
folderDesc=Open folders
folderOpenDesc=Open folder path
folderOpenDir=Directory Path
folderOpenProfileDesc=Open profile directory
# LOCALIZATION NOTE (folderInvalidPath) A string displayed as the result
# of the 'folder open' command with an invalid folder path.
folderInvalidPath=Please enter a valid path
# LOCALIZATION NOTE (folderOpenDirResult) A very short string used to
# describe the result of the 'folder open' command.
# The argument (%1$S) is the folder path.
folderOpenDirResult=Opened %1$S

View File

@ -0,0 +1,73 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { Cc, Ci, Cu, CC } = require("chrome");
const { Services } = require("resource://gre/modules/Services.jsm");
const gcli = require("gcli/index");
const dirService = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties);
function showFolder(aPath) {
let nsLocalFile = CC("@mozilla.org/file/local;1", "nsILocalFile",
"initWithPath");
try {
let file = new nsLocalFile(aPath);
if (file.exists()) {
file.reveal();
return gcli.lookupFormat("folderOpenDirResult", [aPath]);
} else {
return gcli.lookup("folderInvalidPath");
}
} catch (e) {
return gcli.lookup("folderInvalidPath");
}
}
exports.items = [
{
name: "folder",
description: gcli.lookup("folderDesc")
},
{
name: "folder open",
description: gcli.lookup("folderOpenDesc"),
params: [
{
name: "path",
type: { name: "string", allowBlank: true },
defaultValue: "~",
description: gcli.lookup("folderOpenDir")
}
],
returnType: "string",
exec: function(args, context) {
let dirName = args.path;
// replaces ~ with the home directory path in unix and windows
if (dirName.indexOf("~") == 0) {
let homeDirFile = dirService.get("Home", Ci.nsIFile);
let homeDir = homeDirFile.path;
dirName = dirName.substr(1);
dirName = homeDir + dirName;
}
return showFolder(dirName);
}
},
{
name: "folder openprofile",
description: gcli.lookup("folderOpenProfileDesc"),
returnType: "string",
exec: function(args, context) {
// Get the profile directory.
let currProfD = Services.dirsvc.get("ProfD", Ci.nsIFile);
let profileDir = currProfD.path;
return showFolder(profileDir);
}
}
];