From 59872d0b386153b170d00d04981859c1b44b19fb Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Tue, 21 Nov 2017 16:47:40 -0500 Subject: [PATCH] mkdir working (at least on windows) --- 4coder_base_commands.cpp | 31 +++++++++++++++++++++++++++++++ 4coder_default_include.cpp | 3 +++ 4ed_api_implementation.cpp | 8 ++++---- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/4coder_base_commands.cpp b/4coder_base_commands.cpp index 61ebb6db..5faacc45 100644 --- a/4coder_base_commands.cpp +++ b/4coder_base_commands.cpp @@ -1126,6 +1126,37 @@ CUSTOM_DOC("Queries the user for a new name and renames the file of the current } } +CUSTOM_COMMAND_SIG(make_directory_query) +CUSTOM_DOC("Queries the user for a name and creates a new directory with the given name.") +{ + char hot_space[2048]; + int32_t hot_length = directory_get_hot(app, hot_space, sizeof(hot_space)); + if (hot_length < sizeof(hot_space)){ + String hot = make_string(hot_space, hot_length); + + // Query the user + Query_Bar bar; + + char prompt_space[4096]; + bar.prompt = make_fixed_width_string(prompt_space); + append(&bar.prompt, "Make directory at '"); + append(&bar.prompt, hot); + append(&bar.prompt, "': "); + + char name_space[4096]; + bar.string = make_fixed_width_string(name_space); + if (!query_user_string(app, &bar)) return; + if (bar.string.size == 0) return; + + char cmd_space[4096]; + String cmd = make_fixed_width_string(cmd_space); + append(&cmd, "mkdir "); + if (append_checked(&cmd, bar.string)){ + exec_system_command(app, 0, buffer_identifier(0), hot.str, hot.size, cmd.str, cmd.size, 0); + } + } +} + // // cmdid wrappers // diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index d8df7af0..20b910cb 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -725,6 +725,9 @@ CUSTOM_DOC("Execute a 'long form' command.") else if (match_ss(bar.string, make_lit_string("rename file"))){ rename_file_query(app); } + else if (match_ss(bar.string, make_lit_string("mkdir"))){ + make_directory_query(app); + } else{ print_message(app, literal("unrecognized command\n")); } diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index d31855b2..cc0069af 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -2604,10 +2604,10 @@ DOC_SEE(Theme_Color) API_EXPORT int32_t Directory_Get_Hot(Application_Links *app, char *out, int32_t capacity) /* -DOC_PARAM(out, This parameter provides a character buffer that receives the 4coder 'hot directory'.) -DOC_PARAM(capacity, This parameter specifies the maximum size to be output to the out buffer.) -DOC_RETURN(This call returns the size of the string written into the buffer.) -DOC(4coder has a concept of a 'hot directory' which is the directory most recently accessed in the GUI. Whenever the GUI is opened it shows the hot directory. In the future this will be deprecated and eliminated in favor of more flexible directories controlled on the custom side.) +DOC_PARAM(out, On success this character buffer is filled with the 4coder 'hot directory'.) +DOC_PARAM(capacity, Specifies the capacity in bytes of the of the out buffer.) +DOC(4coder has a concept of a 'hot directory' which is the directory most recently accessed in the GUI. Whenever the GUI is opened it shows the hot directory. In the future this will be deprecated and eliminated in favor of more flexible hot directories created and controlled in the custom layer.) +DOC_RETURN(This call returns the length of the hot directory string whether or not it was successfully copied into the output buffer. The call is successful if and only if capacity is greater than or the return size.) DOC_SEE(directory_set_hot) */{ Command_Data *cmd = (Command_Data*)app->cmd_context;