2018-09-15 23:48:02 +00:00
|
|
|
/*
|
|
|
|
4coder_jump_lister.cpp - Lister for jump buffers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2018-09-17 18:47:06 +00:00
|
|
|
static void
|
2019-06-01 23:58:28 +00:00
|
|
|
activate_jump(Application_Links *app, Heap *heap,
|
2019-04-06 19:40:36 +00:00
|
|
|
View_ID view, struct Lister_State *state,
|
2019-06-01 23:58:28 +00:00
|
|
|
String_Const_u8 text_field, void *user_data, b32 activated_by_mouse){
|
2018-09-17 18:47:06 +00:00
|
|
|
Lister_Activation_Code result_code = ListerActivation_Finished;
|
2019-02-26 23:17:53 +00:00
|
|
|
i32 list_index = (i32)PtrAsInt(user_data);
|
2018-12-17 02:07:49 +00:00
|
|
|
Jump_Lister_Parameters *params = (Jump_Lister_Parameters*)state->lister.data.user_data;
|
2018-09-15 23:48:02 +00:00
|
|
|
Marker_List *list = get_marker_list_for_buffer(params->list_buffer_id);
|
|
|
|
if (list != 0){
|
2019-04-06 19:40:36 +00:00
|
|
|
View_ID target_view = {};
|
2018-09-15 23:48:02 +00:00
|
|
|
switch (params->activation_rule){
|
|
|
|
case JumpListerActivation_OpenInUIView:
|
|
|
|
{
|
2019-04-06 19:40:36 +00:00
|
|
|
target_view = view;
|
2018-09-15 23:48:02 +00:00
|
|
|
result_code = ListerActivation_Finished;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case JumpListerActivation_OpenInTargetViewKeepUI:
|
|
|
|
{
|
2019-04-06 19:40:36 +00:00
|
|
|
target_view = params->target_view_id;;
|
2018-09-15 23:48:02 +00:00
|
|
|
result_code = ListerActivation_Continue;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case JumpListerActivation_OpenInTargetViewCloseUI:
|
|
|
|
{
|
2019-04-06 19:40:36 +00:00
|
|
|
target_view = params->target_view_id;
|
2018-09-15 23:48:02 +00:00
|
|
|
result_code = ListerActivation_Finished;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case JumpListerActivation_OpenInNextViewKeepUI:
|
|
|
|
{
|
2019-04-06 19:40:36 +00:00
|
|
|
target_view = view;
|
|
|
|
target_view = get_next_view_looped_primary_panels(app, target_view, AccessAll);
|
2018-09-15 23:48:02 +00:00
|
|
|
result_code = ListerActivation_Continue;
|
|
|
|
}break;
|
|
|
|
|
|
|
|
case JumpListerActivation_OpenInNextViewCloseUI:
|
|
|
|
{
|
2019-04-06 19:40:36 +00:00
|
|
|
target_view = view;
|
|
|
|
target_view = get_next_view_looped_primary_panels(app, target_view, AccessAll);
|
2018-09-15 23:48:02 +00:00
|
|
|
result_code = ListerActivation_Finished;
|
|
|
|
}break;
|
|
|
|
}
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
ID_Pos_Jump_Location location = {};
|
2018-09-15 23:48:02 +00:00
|
|
|
if (get_jump_from_list(app, list, list_index, &location)){
|
2019-04-04 08:25:16 +00:00
|
|
|
Buffer_ID buffer = {};
|
2018-09-15 23:48:02 +00:00
|
|
|
if (get_jump_buffer(app, &buffer, &location)){
|
2019-04-06 19:40:36 +00:00
|
|
|
view_set_active(app, target_view);
|
|
|
|
jump_to_location(app, target_view, buffer, location);
|
2018-09-15 23:48:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-06-01 23:58:28 +00:00
|
|
|
lister_default(app, heap, view, state, result_code);
|
2018-09-15 23:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-01 23:58:28 +00:00
|
|
|
open_jump_lister(Application_Links *app, Heap *heap, View_ID ui_view, Buffer_ID list_buffer_id, Jump_Lister_Activation_Rule activation_rule, View_ID optional_target_view){
|
2018-09-15 23:48:02 +00:00
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
Marker_List *list = get_or_make_list_for_buffer(app, heap, list_buffer_id);
|
2018-09-15 23:48:02 +00:00
|
|
|
if (list != 0){
|
2019-02-26 23:17:53 +00:00
|
|
|
i32 estimated_string_space_size = 0;
|
2018-09-15 23:48:02 +00:00
|
|
|
view_end_ui_mode(app, ui_view);
|
2019-06-01 23:58:28 +00:00
|
|
|
Arena *scratch = context_get_arena(app);
|
|
|
|
Temp_Memory temp = begin_temp(scratch);
|
2019-02-26 23:17:53 +00:00
|
|
|
i32 option_count = list->jump_count;
|
2018-09-15 23:48:02 +00:00
|
|
|
Lister_Option *options = push_array(scratch, Lister_Option, option_count);
|
|
|
|
Managed_Object stored_jumps = list->jump_array;
|
2019-02-26 23:17:53 +00:00
|
|
|
for (i32 i = 0; i < option_count; i += 1){
|
2018-11-20 08:18:54 +00:00
|
|
|
Sticky_Jump_Stored stored = {};
|
2018-09-15 23:48:02 +00:00
|
|
|
managed_object_load_data(app, stored_jumps, i, 1, &stored);
|
2019-06-02 03:07:57 +00:00
|
|
|
String_Const_u8 line = push_buffer_line(app, scratch, list_buffer_id, stored.list_line);
|
2018-12-10 01:31:30 +00:00
|
|
|
options[i].string = line;
|
|
|
|
memset(&options[i].status, 0, sizeof(options[i].status));
|
2018-09-15 23:48:02 +00:00
|
|
|
options[i].user_data = IntAsPtr(i);
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 aligned_size = ((i32)line.size) + 1 + 7;
|
2018-09-15 23:48:02 +00:00
|
|
|
aligned_size = aligned_size - aligned_size%8;
|
|
|
|
estimated_string_space_size += aligned_size;
|
|
|
|
}
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
Jump_Lister_Parameters jump_lister_params = {};
|
2018-09-15 23:48:02 +00:00
|
|
|
jump_lister_params.list_buffer_id = list_buffer_id;
|
|
|
|
jump_lister_params.activation_rule = activation_rule;
|
|
|
|
if (optional_target_view != 0){
|
2019-04-06 19:40:36 +00:00
|
|
|
jump_lister_params.target_view_id = optional_target_view;
|
2018-09-15 23:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
begin_integrated_lister__basic_list(app, "Jump:", activate_jump,
|
|
|
|
&jump_lister_params, sizeof(jump_lister_params),
|
|
|
|
options, option_count,
|
|
|
|
estimated_string_space_size,
|
|
|
|
ui_view);
|
2019-06-01 23:58:28 +00:00
|
|
|
end_temp(temp);
|
2018-09-15 23:48:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CUSTOM_COMMAND_SIG(view_jump_list_with_lister)
|
|
|
|
CUSTOM_DOC("When executed on a buffer with jumps, creates a persistent lister for all the jumps")
|
|
|
|
{
|
2019-06-19 02:31:59 +00:00
|
|
|
View_ID view = get_active_view(app, AccessAll);
|
|
|
|
Buffer_ID buffer = view_get_buffer(app, view, AccessAll);
|
2019-06-01 23:58:28 +00:00
|
|
|
open_jump_lister(app, &global_heap, view, buffer, JumpListerActivation_OpenInNextViewKeepUI, 0);
|
2018-09-15 23:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|