Skip to content

Commit

Permalink
Merge pull request adobe#8 from minimattapps/chrome-app
Browse files Browse the repository at this point in the history
Added Fullscreen menu item and enabled Quit menu item, also allowed Importing Files and Folders
  • Loading branch information
maks committed Jul 9, 2013
2 parents d567d8a + 62eccd5 commit 8e4c160
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
chrome.app.runtime.onLaunched.addListener(function () {
chrome.app.window.create('index.html', {
'id': 'brackets'
});
}, function (window){
window.maximize();
});

});

}());
2 changes: 1 addition & 1 deletion src/command/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ define(function (require, exports, module) {
var project_cmenu = Menus.registerContextMenu(Menus.ContextMenuIds.PROJECT_MENU);
project_cmenu.addMenuItem(Commands.FILE_NEW);
project_cmenu.addMenuItem(Commands.FILE_NEW_FOLDER);
//project_cmenu.addMenuItem(Commands.FILE_RENAME);
project_cmenu.addMenuItem(Commands.FILE_RENAME);
//project_cmenu.addMenuItem(Commands.FILE_SAVE_AS);
project_cmenu.addMenuItem(Commands.FILE_DELETE);
//project_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_OS);
Expand Down
140 changes: 140 additions & 0 deletions src/extensions/default/ChromeApp/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
/*global define, $, brackets, window */

/** Simple extension that adds a "File > Hello World" menu item */
define(function (require, exports, module) {
"use strict";

var CommandManager = brackets.getModule("command/CommandManager"),
Menus = brackets.getModule("command/Menus");
var ProjectManager = brackets.getModule("project/ProjectManager");

var fullscreen = false;
// Function to run when the menu item is clicked
function handleFullscreen() {
if (fullscreen == false){
chrome.app.window.current().fullscreen();
fullscreen = true;

} else {
chrome.app.window.current().restore();
fullscreen = false;
}
}


// First, register a command - a UI-less object associating an id to a handler

CommandManager.register("Fullscreen", "chromeapp.fullscreen", handleFullscreen);

CommandManager.register("Import Folder", "chromeapp.importfolder", importFolder);
CommandManager.register("Import File", "chromeapp.importfile", importFile);
// Then create a menu item bound to the command
// The label of the menu item is the name we gave the command (see above)
var filemenu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU);
var menu = Menus.getMenu(Menus.AppMenuBar.VIEW_MENU);


// We could also add a key binding at the same time:
var ver = parseInt(window.navigator.appVersion.match(/Chrome\/(\d+)\./)[1], 10);
if (ver != 27){
menu.addMenuItem("chromeapp.fullscreen", "F11");
}
filemenu.addMenuItem("chromeapp.importfolder", "Ctrl-Alt-I");
filemenu.addMenuItem("chromeapp.importfile");


function handleFolderSelect(evt) {
var files = evt.target.files; // FileList object

// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {

var dir = f.webkitRelativePath.substring(0, f.webkitRelativePath.lastIndexOf('/'));
console.log(dir);


brackets.fs.makedir(dir,null,function(error){
console.log("Created Directory");
});



var reader = new FileReader();

// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {

brackets.fs.writeFile(theFile.webkitRelativePath,e.target.result,null,function(error){
console.log("Created Files");
ProjectManager.refreshFileTree();
});

};
})(f);

// Read in the image file as a data URL.
reader.readAsText(f);


}

}

function handleFileSelect(evt) {
var savedir = ProjectManager.getSelectedItem().fullPath;
if (savedir == null){
savedir = "";
} else {
if (ProjectManager.getSelectedItem().isFile){
savedir = savedir.substring(0, savedir.lastIndexOf('/')) + "/";
}
}


var files = evt.target.files; // FileList object

// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {



var reader = new FileReader();

// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {

brackets.fs.writeFile(savedir + theFile.name,e.target.result,null,function(error){
console.log("Created Files");
ProjectManager.refreshFileTree();
});

};
})(f);

// Read in the image file as a data URL.
reader.readAsText(f);


}

}




function importFolder(){
document.getElementById('folderinput').addEventListener('change', handleFolderSelect, false);
document.getElementById("folderinput").click();
}

function importFile(){

document.getElementById('fileinput').addEventListener('change', handleFileSelect, false);
document.getElementById("fileinput").click();
}
});
27 changes: 21 additions & 6 deletions src/file/HTMLIntegration.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,29 @@ define(function (require, exports, module) {
}, errorHandler);
}

function rename(oldPath, newPath, callback) {
// client.move(oldPath, newPath, function (error) {
// callback(mapError(error));
// });

function rename(oldPath, newPath, callback) {
console.log("RENAME: " + oldPath);

var newDirName = newPath.substr(0, newPath.lastIndexOf("/") + 1),
newFileName = newPath.substr(newPath.lastIndexOf("/") + 1);

}
fs.root.getFile(oldPath, {create: false}, function (fileEntry) {
if (newDirName === "/") {
fileEntry.moveTo(fs.root, newFileName, function () {
callback(brackets.fs.NO_ERROR);
}, errorHandler);
} else {

fs.root.getDirectory(newDirName, {create: true}, function (dirEntry) {
fileEntry.moveTo(dirEntry, newFileName, function () {
callback(brackets.fs.NO_ERROR);
}, errorHandler);
}, errorHandler);

}
}, errorHandler);

}

function unlink(path, callback){
console.log("DELETE: " + path);
Expand Down
2 changes: 2 additions & 0 deletions src/htmlContent/main-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
<!-- For more info, see note in brackets.less for class .dummy-text, or issue 76 -->
<div class="dummy-text">x</div>
</div>
<input type="file" id="folderinput" webkitdirectory="" directory="" style="visibility:hidden">
<input type="file" id="fileinput" style="visibility:hidden" multiple>

<!-- Modal Windows -->
<div id="context-menu-bar">
Expand Down
6 changes: 2 additions & 4 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
"manifest_version": 2,
"minimum_chrome_version": "25.0",
"offline_enabled": true,
"app": {
"app": {
"background": {
"scripts": [
"background.js"
]
"scripts": ["background.js"]
}
},
"permissions": [
Expand Down
1 change: 1 addition & 0 deletions src/utils/ExtensionLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ define(function (require, exports, module) {
var basePath = PathUtils.directory(window.location.href) + "extensions/default/",
defaultExtensions = [
"CSSCodeHints",
"ChromeApp",
//"DebugCommands",
"HTMLCodeHints",
"HtmlEntityCodeHints",
Expand Down
6 changes: 6 additions & 0 deletions src/utils/Global.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ define(function (require, exports, module) {
}

if (chrome.runtime) {


//Enable quit function
brackets.app.quit = function(){
window.close();
}
HTMLIntegration.init();
}

Expand Down

0 comments on commit 8e4c160

Please sign in to comment.