void paste_clipboard_index(Application_Links* app, int clip_index)
{
View_Summary view = get_active_view(app, AccessOpen);
int32_t len = clipboard_index(app, 0, clip_index, 0, 0);
char *str = 0;
if (len <= app->memory_size)
str = (char*)app->memory;
if (str != 0)
{
clipboard_index(app, 0, clip_index, str, len);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen);
int32_t pos = view.cursor.pos;
buffer_replace_range(app, &buffer, pos, pos, str, len);
view_set_cursor(app, &view, seek_pos(pos + len), true);
Theme_Color paste = {};
paste.tag = Stag_Paste;
get_theme_colors(app, &paste, 1);
view_post_fade(app, &view, 0.667f, pos, pos + len, paste.color);
auto_tab_range(app);
}
}
static void
activate_clipboard_lister(Application_Links *app, Partition *scratch, Heap *heap,
View_Summary *view, Lister_State *state,
String text_field, void *user_data, bool32 activated_by_mouse)
{
lister_default(app, scratch, heap, view, state, ListerActivation_Finished);
int clip_index = (int) PtrAsInt(user_data);
paste_clipboard_index(app, clip_index);
}
CUSTOM_COMMAND_SIG(clipmate_lister)
{
Partition* arena = &global_part;
Temp_Memory temp = begin_temp_memory(arena);
View_Summary view = get_active_view(app, AccessOpen);
view_end_ui_mode(app, &view);
int32_t option_count = clipboard_count(app, 0);
if (option_count > 10)
option_count = 10;
Lister_Option* options = push_array(arena, Lister_Option, option_count);
for (int32_t i = 0; i < option_count; i++)
{
int32_t contents_length = clipboard_index(app, 0, i, 0, 0);
char* str_index = push_array(arena, char, 5);
itoa(i, str_index, 10);
char* clipboard_contents = push_array(arena, char, contents_length);
clipboard_index(app, 0, i, clipboard_contents, contents_length);
options[i].string = make_string(str_index, (int) strlen(str_index));
options[i].status = make_string(clipboard_contents, contents_length);
options[i].user_data = IntAsPtr(i);
}
begin_integrated_lister__basic_list(app, "Clipboard:", activate_clipboard_lister, 0, 0, options, option_count, 0, &view);
end_temp_memory(temp);
}