File lister now handles .. in directory names
This commit is contained in:
parent
15a2cb080e
commit
6491a88d8a
|
@ -15,17 +15,23 @@ struct file_view_state
|
|||
input_command* FileView_Commands = 0;
|
||||
s32 FileView_CommandsCount = 0;
|
||||
|
||||
// TODO(pjs): 2 - On Change Dir function
|
||||
// - clears the memory arena
|
||||
// - enumerates the new directory in the memory arena
|
||||
|
||||
internal void
|
||||
FileViewUpdateWorkingDirectory(gs_const_string WorkingDirectory, file_view_state* State, context Context)
|
||||
{
|
||||
ClearArena(&State->FileNamesArena);
|
||||
|
||||
gs_const_string SanitizedDirectory = WorkingDirectory;
|
||||
|
||||
u32 LastSlashIndex = FindLast(SanitizedDirectory, '\\');
|
||||
gs_const_string LastDir = Substring(SanitizedDirectory, LastSlashIndex + 1, SanitizedDirectory.Length);
|
||||
if (StringsEqual(LastDir, ConstString("..")))
|
||||
{
|
||||
u32 SecondLastSlashIndex = FindLast(SanitizedDirectory, LastSlashIndex - 1, '\\');
|
||||
SanitizedDirectory = Substring(SanitizedDirectory, 0, SecondLastSlashIndex);
|
||||
}
|
||||
|
||||
State->WorkingDirectory = PushString(&State->FileNamesArena, WorkingDirectory.Length + 2);
|
||||
PrintF(&State->WorkingDirectory, "%S", WorkingDirectory);
|
||||
PrintF(&State->WorkingDirectory, "%S", SanitizedDirectory);
|
||||
if (State->WorkingDirectory.Str[State->WorkingDirectory.Length - 1] != '\\')
|
||||
{
|
||||
AppendPrintF(&State->WorkingDirectory, "\\");
|
||||
|
@ -80,7 +86,18 @@ FileView_Render(panel Panel, rect2 PanelBounds, render_command_buffer* RenderBuf
|
|||
gs_file_info File = FileViewState->FileNames.Values[i];
|
||||
gs_string PathString = PushString(State->Transient, File.Path.Length);
|
||||
PrintF(&PathString, "%S", File.Path);
|
||||
ui_LayoutDrawString(&State->Interface, &Layout, PathString, State->Interface.Style.TextColor);
|
||||
if (ui_LayoutListButton(&State->Interface, &Layout, PathString, i))
|
||||
{
|
||||
if (File.IsDirectory)
|
||||
{
|
||||
FileViewUpdateWorkingDirectory(File.Path, FileViewState, Context);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO(pjs): Select the file
|
||||
}
|
||||
}
|
||||
//ui_LayoutDrawString(&State->Interface, &Layout, PathString, State->Interface.Style.TextColor);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1366,7 +1366,7 @@ CharArrayLength (char* CS)
|
|||
internal bool
|
||||
IsNullTerminated(gs_const_string String)
|
||||
{
|
||||
return (String.Str[String.Length - 1] != 0);
|
||||
return (String.Str[String.Length] == 0);
|
||||
}
|
||||
internal bool
|
||||
IsNullTerminated(gs_string String)
|
||||
|
@ -1455,13 +1455,21 @@ FindFirst(gs_const_string String, char C)
|
|||
{
|
||||
return FindFirst(String, 0, C);
|
||||
}
|
||||
|
||||
internal u64
|
||||
FindLast(gs_const_string String, char C)
|
||||
FindLast(gs_const_string String, u64 StartIndex, char C)
|
||||
{
|
||||
s64 Result = String.Length - 1;
|
||||
s64 Result = StartIndex;
|
||||
for(; Result >= 0 && C != String.Str[Result]; Result--);
|
||||
return (u64)Result;
|
||||
}
|
||||
|
||||
internal u64
|
||||
FindLast(gs_const_string String, char C)
|
||||
{
|
||||
return FindLast(String, String.Length - 1, C);
|
||||
}
|
||||
|
||||
internal u64
|
||||
FindFirstFromSet(gs_const_string String, char* SetArray)
|
||||
{
|
||||
|
@ -2968,14 +2976,19 @@ CreateFileHandler(file_handler_get_file_info* GetFileInfo,
|
|||
internal gs_const_string
|
||||
GetNullTerminatedPath(gs_file_handler FileHandler, gs_const_string Path)
|
||||
{
|
||||
gs_const_string NullTermPath = Path;
|
||||
if (!IsNullTerminated(NullTermPath))
|
||||
gs_const_string Result = {};
|
||||
if (!IsNullTerminated(Path))
|
||||
{
|
||||
AssertMessage("need to allocate a new string, Path to it, and null terminate");
|
||||
// TODO(Peter): Probably want to have some sort of temp memory,
|
||||
// or be passing in a thread context, etc.
|
||||
gs_string NullTermPath = PushString(FileHandler.Transient, Path.Length + 1);
|
||||
PrintF(&NullTermPath, "%S", Path);
|
||||
NullTerminate(&NullTermPath);
|
||||
Result = NullTermPath.ConstString;
|
||||
}
|
||||
return NullTermPath;
|
||||
else
|
||||
{
|
||||
Result = Path;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
internal gs_file_info
|
||||
|
|
Loading…
Reference in New Issue