Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add brackets.fs.makedir() and brackets.fs.rename() methods. Implement…

… on mac.
  • Loading branch information...
commit 7bd36d031a1c1533784f4f85a8bd9024139f74d4 1 parent 319a2e5
@gruehle gruehle authored
View
36 appshell/appshell_extensions.cpp
@@ -150,6 +150,42 @@ class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
// Set response args for this function
responseArgs->SetList(2, directoryContents);
+ } else if (message_name == "MakeDir") {
+ // Parameters:
+ // 0: int32 - callback id
+ // 1: string - directory path
+ // 2: number - mode
+ if (argList->GetSize() != 3 ||
+ argList->GetType(1) != VTYPE_STRING ||
+ argList->GetType(2) != VTYPE_INT) {
+ error = ERR_INVALID_PARAMS;
+ }
+
+ if (error == NO_ERROR) {
+ ExtensionString pathname = argList->GetString(1);
+ int32 mode = argList->GetInt(2);
+
+ error = MakeDir(pathname, mode);
+ }
+ // No additional response args for this function
+ } else if (message_name == "Rename") {
+ // Parameters:
+ // 0: int32 - callback id
+ // 1: string - old path
+ // 2: string - new path
+ if (argList->GetSize() != 3 ||
+ argList->GetType(1) != VTYPE_STRING ||
+ argList->GetType(2) != VTYPE_STRING) {
+ error = ERR_INVALID_PARAMS;
+ }
+
+ if (error == NO_ERROR) {
+ ExtensionString oldName = argList->GetString(1);
+ ExtensionString newName = argList->GetString(2);
+
+ error = Rename(oldName, newName);
+ }
+ // No additional response args for this function
} else if (message_name == "GetFileModificationTime") {
// Parameters:
// 0: int32 - callback id
View
30 appshell/appshell_extensions.js
@@ -144,7 +144,35 @@ if (!appshell.app) {
appshell.fs.readdir = function (path, callback) {
var resultString = ReadDir(callback, path);
};
-
+
+ /**
+ * Create a new directory.
+ *
+ * @param {string} path The path of the directory to create.
+ * @param {number} mode The permissions for the directory, in numeric format (ie 0777)
+ * @param {function(err)} callback Asynchronous callback function. The callback gets one argument.
+ *
+ * @return None. This is an asynchronous call that sends all return information to the callback.
+ **/
+ native function MakeDir();
+ appshell.fs.makedir = function (path, mode, callback) {
+ MakeDir(callback, path, mode);
+ };
+
+ /**
+ * Rename a file or directory.
+ *
+ * @param {string} oldPath The old name of the file or directory.
+ * @param {string} newPath The new name of the file or directory.
+ * @param {function(err)} callback Asynchronous callback function. The callback gets one argument.
+ *
+ * @return None. This is an asynchronous call that sends all return information to the callback.
+ **/
+ native function Rename();
+ appshell.fs.rename = function(oldPath, newPath, callback) {
+ Rename(callback, oldPath, newPath);
+ };
+
/**
* Get information for the selected file or directory.
*
View
22 appshell/appshell_extensions_mac.mm
@@ -337,6 +337,28 @@ int32 ReadDir(ExtensionString path, CefRefPtr<CefListValue>& directoryContents)
return ConvertNSErrorCode(error, true);
}
+int32 MakeDir(ExtensionString path, int32 mode)
+{
+ NSError* error = nil;
+ NSString* pathStr = [NSString stringWithUTF8String:path.c_str()];
+
+ // TODO: honor mode
+ [[NSFileManager defaultManager] createDirectoryAtPath:pathStr withIntermediateDirectories:FALSE attributes:nil error:&error];
+
+ return ConvertNSErrorCode(error, false);
+}
+
+int32 Rename(ExtensionString oldName, ExtensionString newName)
+{
+ NSError* error = nil;
+ NSString* oldPathStr = [NSString stringWithUTF8String:oldName.c_str()];
+ NSString* newPathStr = [NSString stringWithUTF8String:newName.c_str()];
+
+ [[NSFileManager defaultManager] moveItemAtPath:oldPathStr toPath:newPathStr error:&error];
+
+ return ConvertNSErrorCode(error, false);
+}
+
int32 GetFileModificationTime(ExtensionString filename, uint32& modtime, bool& isDir)
{
NSString* path = [NSString stringWithUTF8String:filename.c_str()];
View
4 appshell/appshell_extensions_platform.h
@@ -67,6 +67,10 @@ int32 ShowOpenDialog(bool allowMulitpleSelection,
int32 ReadDir(ExtensionString path, CefRefPtr<CefListValue>& directoryContents);
+int32 MakeDir(ExtensionString path, int32 mode);
+
+int32 Rename(ExtensionString oldName, ExtensionString newName);
+
int32 GetFileModificationTime(ExtensionString filename, uint32& modtime, bool& isDir);
int32 ReadFile(ExtensionString filename, ExtensionString encoding, std::string& contents);
Please sign in to comment.
Something went wrong with that request. Please try again.