Skip to content

Commit 0d1ccd7

Browse files
committed
switch to partner file command - quick way to switch from .h to .c, or similar
1 parent 4ddb4d0 commit 0d1ccd7

File tree

8 files changed

+56
-3
lines changed

8 files changed

+56
-3
lines changed

src/df/core/df_core.mdesk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ DF_CoreCmdTable:// | | |
221221
{Reload 0 Entity File 0 0 0 0 0 1 FileOutline "reload" "Reload" "Reloads a loaded file." "code,source,file,reload" }
222222
{ReloadActive 0 Null Nil 0 0 0 0 0 0 FileOutline "reload_active" "Reload Active File" "Reloads the active file." "code,source,file,reload" }
223223
{Switch 0 Entity File 0 0 0 0 0 1 FileOutline "switch" "Switch" "Switches to a loaded file." "code,source,file" }
224+
{SwitchToPartnerFile 0 Null Nil 0 0 0 0 0 0 FileOutline "switch_to_partner_file" "Switch To Partner File" "Switches to the focused file's partner; or from header to implementation or vice versa." "code,source,file" }
224225

225226
//- rjf: override file links
226227
{SetFileOverrideLinkSrc 1 Null Nil 0 0 0 0 0 0 Null "set_file_override_link_src" "Set File Override Link Source" "Sets the source path for an override file link." "" }

src/df/core/generated/df_core.meta.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[] =
8585
{ str8_lit_comp("reload"), str8_lit_comp("Reloads a loaded file."), str8_lit_comp("code,source,file,reload"), str8_lit_comp("Reload"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Entity, DF_EntityKind_File, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*1)}, DF_IconKind_FileOutline},
8686
{ str8_lit_comp("reload_active"), str8_lit_comp("Reloads the active file."), str8_lit_comp("code,source,file,reload"), str8_lit_comp("Reload Active File"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_FileOutline},
8787
{ str8_lit_comp("switch"), str8_lit_comp("Switches to a loaded file."), str8_lit_comp("code,source,file"), str8_lit_comp("Switch"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Entity, DF_EntityKind_File, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*1)}, DF_IconKind_FileOutline},
88+
{ str8_lit_comp("switch_to_partner_file"), str8_lit_comp("Switches to the focused file's partner; or from header to implementation or vice versa."), str8_lit_comp("code,source,file"), str8_lit_comp("Switch To Partner File"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_FileOutline},
8889
{ str8_lit_comp("set_file_override_link_src"), str8_lit_comp("Sets the source path for an override file link."), str8_lit_comp(""), str8_lit_comp("Set File Override Link Source"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null},
8990
{ str8_lit_comp("set_file_override_link_dst"), str8_lit_comp("Sets the destination path for an override file link."), str8_lit_comp(""), str8_lit_comp("Set File Override Link Destination"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null},
9091
{ str8_lit_comp("set_file_replacement_path"), str8_lit_comp("Sets the path which should be used as the replacement for the passed file."), str8_lit_comp(""), str8_lit_comp("Set File Replacement Path"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null},

src/df/core/generated/df_core.meta.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ DF_CoreCmdKind_Open,
135135
DF_CoreCmdKind_Reload,
136136
DF_CoreCmdKind_ReloadActive,
137137
DF_CoreCmdKind_Switch,
138+
DF_CoreCmdKind_SwitchToPartnerFile,
138139
DF_CoreCmdKind_SetFileOverrideLinkSrc,
139140
DF_CoreCmdKind_SetFileOverrideLinkDst,
140141
DF_CoreCmdKind_SetFileReplacementPath,

src/df/gfx/df_gfx.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,47 @@ df_window_update_and_render(Arena *arena, OS_EventList *events, DF_Window *ws, D
18651865
df_cmd_list_push(arena, cmds, &p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_PendingEntity));
18661866
}
18671867
}break;
1868+
case DF_CoreCmdKind_SwitchToPartnerFile:
1869+
{
1870+
DF_Panel *panel = df_panel_from_handle(params.panel);
1871+
DF_View *view = df_view_from_handle(panel->selected_tab_view);
1872+
DF_Entity *entity = df_entity_from_handle(view->entity);
1873+
DF_GfxViewKind view_kind = df_gfx_view_kind_from_string(view->spec->info.name);
1874+
if(view_kind == DF_GfxViewKind_Code && entity->kind == DF_EntityKind_File)
1875+
{
1876+
String8 file_full_path = df_full_path_from_entity(scratch.arena, entity);
1877+
String8 file_folder = str8_chop_last_slash(file_full_path);
1878+
String8 file_name = str8_chop_last_dot(entity->name);
1879+
String8 file_ext = str8_skip_last_dot(entity->name);
1880+
String8 partner_ext_candidates[] =
1881+
{
1882+
str8_lit_comp("h"),
1883+
str8_lit_comp("hpp"),
1884+
str8_lit_comp("hxx"),
1885+
str8_lit_comp("c"),
1886+
str8_lit_comp("cc"),
1887+
str8_lit_comp("cxx"),
1888+
str8_lit_comp("cpp"),
1889+
};
1890+
for(U64 idx = 0; idx < ArrayCount(partner_ext_candidates); idx += 1)
1891+
{
1892+
if(!str8_match(partner_ext_candidates[idx], file_ext, StringMatchFlag_CaseInsensitive))
1893+
{
1894+
String8 candidate = push_str8f(scratch.arena, "%S.%S", file_name, partner_ext_candidates[idx]);
1895+
String8 candidate_path = push_str8f(scratch.arena, "%S/%S", file_folder, candidate);
1896+
FileProperties candidate_props = os_properties_from_file_path(candidate_path);
1897+
if(candidate_props.modified != 0)
1898+
{
1899+
DF_Entity *candidate = df_entity_from_path(candidate_path, DF_EntityFromPathFlag_OpenAsNeeded);
1900+
DF_CmdParams p = df_cmd_params_from_panel(ws, panel);
1901+
p.entity = df_handle_from_entity(candidate);
1902+
df_cmd_list_push(arena, cmds, &p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_Switch));
1903+
break;
1904+
}
1905+
}
1906+
}
1907+
}
1908+
}break;
18681909

18691910
//- rjf: directional movement & text controls
18701911
//

src/df/gfx/df_gfx.mdesk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ DF_DefaultBindingTable:
8383
{ "open" O ctrl 0 0 }
8484
{ "reload_active" R ctrl shift 0 }
8585
{ "switch" I ctrl 0 0 }
86+
{ "switch_to_partner_file" O 0 0 alt }
8687

8788
//- rjf: setting config paths
8889
{ "load_user" O ctrl shift alt }

src/df/gfx/generated/df_gfx.meta.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ DF_StringBindingPair df_g_default_binding_table[] =
940940
{str8_lit_comp("open"), {OS_Key_O, 0 |OS_EventFlag_Ctrl }},
941941
{str8_lit_comp("reload_active"), {OS_Key_R, 0 |OS_EventFlag_Ctrl |OS_EventFlag_Shift }},
942942
{str8_lit_comp("switch"), {OS_Key_I, 0 |OS_EventFlag_Ctrl }},
943+
{str8_lit_comp("switch_to_partner_file"), {OS_Key_O, 0 |OS_EventFlag_Alt}},
943944
{str8_lit_comp("load_user"), {OS_Key_O, 0 |OS_EventFlag_Ctrl |OS_EventFlag_Shift |OS_EventFlag_Alt}},
944945
{str8_lit_comp("load_profile"), {OS_Key_O, 0 |OS_EventFlag_Ctrl |OS_EventFlag_Alt}},
945946
{str8_lit_comp("move_left"), {OS_Key_Left, 0 }},

src/raddbg/raddbg.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,14 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data)
325325
for(OS_Event *ev = leftover_events.first, *next = 0; ev != 0; ev = next)
326326
{
327327
next = ev->next;
328-
if(ev->timestamp_us+1000000 < os_now_microseconds())
328+
if(ev->timestamp_us+1000000 < os_now_microseconds() ||
329+
ev->kind == OS_EventKind_Text ||
330+
(ev->kind == OS_EventKind_Press && ev->key != OS_Key_LeftMouseButton) ||
331+
(ev->kind == OS_EventKind_Press && ev->key != OS_Key_RightMouseButton) ||
332+
(ev->kind == OS_EventKind_Press && ev->key != OS_Key_MiddleMouseButton) ||
333+
(ev->kind == OS_EventKind_Release && ev->key != OS_Key_LeftMouseButton) ||
334+
(ev->kind == OS_EventKind_Release && ev->key != OS_Key_RightMouseButton) ||
335+
(ev->kind == OS_EventKind_Release && ev->key != OS_Key_MiddleMouseButton))
329336
{
330337
os_eat_event(&leftover_events, ev);
331338
}

src/raddbg/raddbg.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// [ ] drag/drop tab cleanup
1111
// [ ] target/breakpoint/watch-pin reordering
1212
// [ ] watch window reordering
13-
// [ ] query views, cleanup & floating - maybe merge "applies to view" vs. not
13+
// [x] query views, cleanup & floating - maybe merge "applies to view" vs. not
1414
// [ ] standard way to filter
1515
// [ ] visualize remapped files (via path map)
1616
// [ ] hovering truncated string for a short time -> tooltip with full wrapped
@@ -34,7 +34,7 @@
3434
//
3535
// [ ] it would be nice to have "show in explorer" for right click on source
3636
// file tab (opens explorer & selects the file)
37-
// [ ] it would be nice if Alt+o in source file would switch between .h and
37+
// [x] it would be nice if Alt+o in source file would switch between .h and
3838
// .c/cpp file (just look for same name in same folder)
3939
//
4040
// [ ] what's up with decimal number coloring where every group of 3 are in

0 commit comments

Comments
 (0)