2017-01-29 00:03:23 +00:00
|
|
|
/*
|
|
|
|
4coder_experiments.cpp - Supplies extension bindings to the defaults with experimental new features.
|
|
|
|
*/
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-12 02:15:54 +00:00
|
|
|
// TOP
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2019-09-28 23:29:54 +00:00
|
|
|
// TODO(allen): move all out of experimental
|
|
|
|
|
2017-01-29 00:03:23 +00:00
|
|
|
#include "4coder_default_include.cpp"
|
|
|
|
#include "4coder_miblo_numbers.cpp"
|
2017-01-23 06:19:43 +00:00
|
|
|
|
2016-05-12 02:15:54 +00:00
|
|
|
#define NO_BINDING
|
2016-06-21 14:00:07 +00:00
|
|
|
#include "4coder_default_bindings.cpp"
|
2016-03-24 01:05:28 +00:00
|
|
|
|
2016-05-29 03:12:12 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2017-11-21 18:25:19 +00:00
|
|
|
// NOTE(allen): An experimental mutli-pasting thing
|
2017-01-14 03:01:35 +00:00
|
|
|
|
2017-11-21 18:25:19 +00:00
|
|
|
CUSTOM_COMMAND_SIG(multi_paste){
|
2019-06-01 23:58:28 +00:00
|
|
|
Scratch_Block scratch(app);
|
|
|
|
|
2019-06-19 02:31:59 +00:00
|
|
|
i32 count = clipboard_count(app, 0);
|
2017-11-21 18:25:19 +00:00
|
|
|
if (count > 0){
|
2019-06-19 02:31:59 +00:00
|
|
|
View_ID view = get_active_view(app, AccessOpen);
|
2019-06-20 04:45:58 +00:00
|
|
|
Managed_Scope scope = view_get_managed_scope(app, view);
|
2017-07-10 14:51:19 +00:00
|
|
|
|
2019-09-04 05:31:35 +00:00
|
|
|
Rewrite_Type *rewrite = scope_attachment(app, scope, view_rewrite_loc, Rewrite_Type);
|
|
|
|
if (*rewrite == Rewrite_Paste){
|
|
|
|
Rewrite_Type *next_rewrite = scope_attachment(app, scope, view_next_rewrite_loc, Rewrite_Type);
|
|
|
|
*next_rewrite = Rewrite_Paste;
|
|
|
|
i32 *paste_index_ptr = scope_attachment(app, scope, view_paste_index_loc, i32);
|
|
|
|
i32 paste_index = (*paste_index_ptr) + 1;
|
|
|
|
*paste_index_ptr = paste_index;
|
2017-07-10 14:51:19 +00:00
|
|
|
|
2019-06-19 02:31:59 +00:00
|
|
|
String_Const_u8 string = push_clipboard_index(app, scratch, 0, paste_index);
|
2017-07-10 14:51:19 +00:00
|
|
|
|
2019-06-18 22:56:09 +00:00
|
|
|
String_Const_u8 insert_string = push_u8_stringf(scratch, "\n%.*s", string_expand(string));
|
2019-06-01 23:58:28 +00:00
|
|
|
|
2019-06-19 02:31:59 +00:00
|
|
|
Buffer_ID buffer = view_get_buffer(app, view, AccessOpen);
|
2019-06-20 23:43:27 +00:00
|
|
|
Range_i64 range = get_view_range(app, view);
|
|
|
|
buffer_replace_range(app, buffer, Ii64(range.max), insert_string);
|
2019-06-01 23:58:28 +00:00
|
|
|
view_set_mark(app, view, seek_pos(range.max + 1));
|
2019-09-02 21:32:52 +00:00
|
|
|
view_set_cursor_and_preferred_x(app, view, seek_pos(range.max + insert_string.size));
|
2019-06-01 23:58:28 +00:00
|
|
|
|
|
|
|
Theme_Color paste = {};
|
|
|
|
paste.tag = Stag_Paste;
|
|
|
|
get_theme_colors(app, &paste, 1);
|
2019-06-20 23:43:27 +00:00
|
|
|
view_post_fade(app, view, 0.667f, Ii64(range.max + 1, range.max + insert_string.size), paste.color);
|
2017-06-28 15:15:54 +00:00
|
|
|
}
|
2017-07-10 14:51:19 +00:00
|
|
|
else{
|
2019-06-01 23:58:28 +00:00
|
|
|
paste(app);
|
2017-07-10 14:51:19 +00:00
|
|
|
}
|
2017-01-14 03:01:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-20 23:43:27 +00:00
|
|
|
static Range_i64
|
|
|
|
multi_paste_range(Application_Links *app, View_ID view, Range_i64 range, i32 paste_count, b32 old_to_new){
|
2019-06-01 23:58:28 +00:00
|
|
|
Scratch_Block scratch(app);
|
|
|
|
|
2019-06-20 23:43:27 +00:00
|
|
|
Range_i64 finish_range = range;
|
2017-11-21 18:25:19 +00:00
|
|
|
if (paste_count >= 1){
|
2019-06-19 02:31:59 +00:00
|
|
|
Buffer_ID buffer = view_get_buffer(app, view, AccessOpen);
|
|
|
|
if (buffer != 0){
|
2019-09-02 18:59:36 +00:00
|
|
|
i64 total_size = 0;
|
2019-02-26 23:08:42 +00:00
|
|
|
for (i32 paste_index = 0; paste_index < paste_count; ++paste_index){
|
2019-09-27 23:56:05 +00:00
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
2019-09-02 18:59:36 +00:00
|
|
|
String_Const_u8 string = push_clipboard_index(app, scratch, 0, paste_index);
|
|
|
|
total_size += string.size + 1;
|
2019-09-27 23:56:05 +00:00
|
|
|
end_temp(temp);
|
2017-07-10 14:51:19 +00:00
|
|
|
}
|
2017-11-21 18:25:19 +00:00
|
|
|
total_size -= 1;
|
2017-07-10 14:51:19 +00:00
|
|
|
|
2017-11-21 18:25:19 +00:00
|
|
|
if (total_size <= app->memory_size){
|
2019-02-26 23:08:42 +00:00
|
|
|
i32 first = paste_count - 1;
|
|
|
|
i32 one_past_last = -1;
|
|
|
|
i32 step = -1;
|
2017-11-29 23:00:14 +00:00
|
|
|
if (!old_to_new){
|
|
|
|
first = 0;
|
|
|
|
one_past_last = paste_count;
|
|
|
|
step = 1;
|
|
|
|
}
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
List_String_Const_u8 list = {};
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
for (i32 paste_index = first; paste_index != one_past_last; paste_index += step){
|
2017-11-29 23:00:14 +00:00
|
|
|
if (paste_index != first){
|
2019-06-01 23:58:28 +00:00
|
|
|
string_list_push(scratch, &list, SCu8("\n", 1));
|
|
|
|
}
|
2019-06-19 02:31:59 +00:00
|
|
|
String_Const_u8 string = push_clipboard_index(app, scratch, 0, paste_index);
|
|
|
|
if (string.size > 0){
|
2019-06-01 23:58:28 +00:00
|
|
|
string_list_push(scratch, &list, string);
|
2017-07-10 14:51:19 +00:00
|
|
|
}
|
2017-11-21 18:25:19 +00:00
|
|
|
}
|
2017-07-10 14:51:19 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 flattened = string_list_flatten(scratch, list);
|
|
|
|
|
|
|
|
buffer_replace_range(app, buffer, range, flattened);
|
2019-06-20 23:43:27 +00:00
|
|
|
i64 pos = range.min;
|
2017-11-21 18:25:19 +00:00
|
|
|
finish_range.min = pos;
|
|
|
|
finish_range.max = pos + total_size;
|
|
|
|
view_set_mark(app, view, seek_pos(finish_range.min));
|
2019-09-02 21:32:52 +00:00
|
|
|
view_set_cursor_and_preferred_x(app, view, seek_pos(finish_range.max));
|
2017-07-10 14:51:19 +00:00
|
|
|
|
2017-11-21 18:25:19 +00:00
|
|
|
// TODO(allen): Send this to all views.
|
|
|
|
Theme_Color paste;
|
|
|
|
paste.tag = Stag_Paste;
|
|
|
|
get_theme_colors(app, &paste, 1);
|
2019-06-20 23:43:27 +00:00
|
|
|
view_post_fade(app, view, 0.667f, finish_range, paste.color);
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
2017-11-21 18:25:19 +00:00
|
|
|
}
|
2017-07-10 14:51:19 +00:00
|
|
|
}
|
2017-11-21 18:25:19 +00:00
|
|
|
return(finish_range);
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-29 23:00:14 +00:00
|
|
|
static void
|
2019-02-26 23:08:42 +00:00
|
|
|
multi_paste_interactive_up_down(Application_Links *app, i32 paste_count, i32 clip_count){
|
2019-06-19 02:31:59 +00:00
|
|
|
View_ID view = get_active_view(app, AccessOpen);
|
2019-06-20 23:43:27 +00:00
|
|
|
i64 pos = view_get_cursor_pos(app, view);
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 old_to_new = true;
|
2019-06-20 23:43:27 +00:00
|
|
|
Range_i64 range = multi_paste_range(app, view, Ii64(pos), paste_count, old_to_new);
|
2017-11-29 23:00:14 +00:00
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
Query_Bar bar = {};
|
2019-06-01 23:58:28 +00:00
|
|
|
bar.prompt = string_u8_litexpr("Up and Down to condense and expand paste stages; R to reverse order; Return to finish; Escape to abort.");
|
2017-11-29 23:00:14 +00:00
|
|
|
if (start_query_bar(app, &bar, 0) == 0) return;
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
User_Input in = {};
|
2017-11-29 23:00:14 +00:00
|
|
|
for (;;){
|
|
|
|
in = get_user_input(app, EventOnAnyKey, EventOnEsc);
|
|
|
|
if (in.abort) break;
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
b32 did_modify = false;
|
2017-11-29 23:00:14 +00:00
|
|
|
if (in.key.keycode == key_up){
|
|
|
|
if (paste_count > 1){
|
|
|
|
--paste_count;
|
|
|
|
did_modify = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (in.key.keycode == key_down){
|
|
|
|
if (paste_count < clip_count){
|
|
|
|
++paste_count;
|
|
|
|
did_modify = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (in.key.keycode == 'r' || in.key.keycode == 'R'){
|
|
|
|
old_to_new = !old_to_new;
|
|
|
|
did_modify = true;
|
|
|
|
}
|
|
|
|
else if (in.key.keycode == '\n'){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (did_modify){
|
2019-04-06 21:13:49 +00:00
|
|
|
range = multi_paste_range(app, view, range, paste_count, old_to_new);
|
2017-11-29 23:00:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in.abort){
|
2019-06-19 02:31:59 +00:00
|
|
|
Buffer_ID buffer = view_get_buffer(app, view, AccessOpen);
|
2019-06-01 23:58:28 +00:00
|
|
|
buffer_replace_range(app, buffer, range, SCu8(""));
|
2017-11-29 23:00:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-21 18:25:19 +00:00
|
|
|
CUSTOM_COMMAND_SIG(multi_paste_interactive){
|
2019-06-19 02:31:59 +00:00
|
|
|
i32 clip_count = clipboard_count(app, 0);
|
2017-11-21 18:25:19 +00:00
|
|
|
if (clip_count > 0){
|
2017-11-29 23:00:14 +00:00
|
|
|
multi_paste_interactive_up_down(app, 1, clip_count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CUSTOM_COMMAND_SIG(multi_paste_interactive_quick){
|
2019-06-19 02:31:59 +00:00
|
|
|
i32 clip_count = clipboard_count(app, 0);
|
2017-11-29 23:00:14 +00:00
|
|
|
if (clip_count > 0){
|
2019-06-01 23:58:28 +00:00
|
|
|
u8 string_space[256];
|
2018-11-20 08:18:54 +00:00
|
|
|
Query_Bar bar = {};
|
2019-06-01 23:58:28 +00:00
|
|
|
bar.prompt = string_u8_litexpr("How Many Slots To Paste: ");
|
|
|
|
bar.string = SCu8(string_space, (umem)0);
|
|
|
|
bar.string_capacity = sizeof(string_space);
|
2017-11-29 23:00:14 +00:00
|
|
|
query_user_number(app, &bar);
|
2017-11-21 18:25:19 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 initial_paste_count = (i32)string_to_integer(bar.string, 10);
|
|
|
|
initial_paste_count = clamp(1, initial_paste_count, clip_count);
|
2017-11-29 23:00:14 +00:00
|
|
|
end_query_bar(app, &bar, 0);
|
|
|
|
|
|
|
|
multi_paste_interactive_up_down(app, initial_paste_count, clip_count);
|
2017-01-29 00:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
extern "C" i32
|
|
|
|
get_bindings(void *data, i32 size){
|
2017-07-10 14:51:19 +00:00
|
|
|
Bind_Helper context_ = begin_bind_helper(data, size);
|
|
|
|
Bind_Helper *context = &context_;
|
|
|
|
|
2019-02-24 07:22:16 +00:00
|
|
|
set_hook(context, hook_buffer_viewer_update, default_view_adjust);
|
2017-07-10 14:51:19 +00:00
|
|
|
|
|
|
|
set_start_hook(context, default_start);
|
|
|
|
set_open_file_hook(context, default_file_settings);
|
|
|
|
set_new_file_hook(context, default_new_file);
|
|
|
|
set_save_file_hook(context, default_file_save);
|
|
|
|
set_end_file_hook(context, end_file_close_jump_list);
|
|
|
|
|
|
|
|
set_input_filter(context, default_suppress_mouse_filter);
|
|
|
|
set_command_caller(context, default_command_caller);
|
2018-09-24 22:19:45 +00:00
|
|
|
set_render_caller(context, default_render_caller);
|
2017-07-10 14:51:19 +00:00
|
|
|
|
|
|
|
set_scroll_rule(context, smooth_scroll_rule);
|
2017-11-30 23:25:49 +00:00
|
|
|
set_buffer_name_resolver(context, default_buffer_name_resolution);
|
2019-02-25 23:42:13 +00:00
|
|
|
set_modify_color_table_hook(context, default_modify_color_table);
|
2019-03-25 21:28:15 +00:00
|
|
|
set_get_view_buffer_region_hook(context, default_view_buffer_region);
|
2017-07-10 14:51:19 +00:00
|
|
|
|
|
|
|
default_keys(context);
|
|
|
|
|
|
|
|
// NOTE(allen|a4.0.6): Command maps can be opened more than
|
|
|
|
// once so that you can extend existing maps very easily.
|
|
|
|
// You can also use the helper "restart_map" instead of
|
|
|
|
// begin_map to clear everything that was in the map and
|
|
|
|
// bind new things instead.
|
|
|
|
begin_map(context, mapid_file);
|
2019-09-02 18:59:36 +00:00
|
|
|
//bind(context, key_back, MDFR_ALT|MDFR_CTRL, kill_rect);
|
|
|
|
//bind(context, ' ', MDFR_ALT|MDFR_CTRL, multi_line_edit);
|
2017-07-10 14:51:19 +00:00
|
|
|
|
|
|
|
bind(context, key_page_up, MDFR_ALT, miblo_increment_time_stamp);
|
|
|
|
bind(context, key_page_down, MDFR_ALT, miblo_decrement_time_stamp);
|
|
|
|
|
|
|
|
bind(context, key_home, MDFR_ALT, miblo_increment_time_stamp_minute);
|
|
|
|
bind(context, key_end, MDFR_ALT, miblo_decrement_time_stamp_minute);
|
|
|
|
|
2017-11-29 23:00:14 +00:00
|
|
|
bind(context, 'b', MDFR_CTRL, multi_paste_interactive_quick);
|
2019-07-13 00:43:17 +00:00
|
|
|
bind(context, 'A', MDFR_CTRL, replace_in_all_buffers);
|
2017-07-10 14:51:19 +00:00
|
|
|
end_map(context);
|
|
|
|
|
2019-02-26 23:08:42 +00:00
|
|
|
return(end_bind_helper(context));
|
2016-05-12 02:15:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|