Skip to content

Commit

Permalink
Unix: Do not show drive letter in TChDirDialog/TDirListBox
Browse files Browse the repository at this point in the history
See #141.
  • Loading branch information
magiblot committed May 21, 2024
1 parent e5b8d3f commit 545bc7d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
15 changes: 12 additions & 3 deletions source/tvision/tchdrdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ static void trimEndSeparator(char *path)
path[len-1] = EOS;
}

static void getCurrentDir( char *dir )
{
getCurDir( dir );
#if defined( _TV_UNIX )
// Remove drive letter.
memmove(dir, dir + 2, strlen(dir) - 2 + 1);
#endif
}

void TChDirDialog::handleEvent( TEvent& event )
{
TDialog::handleEvent( event );
Expand All @@ -133,15 +142,15 @@ void TChDirDialog::handleEvent( TEvent& event )
switch( event.message.command )
{
case cmRevert:
getCurDir( curDir );
getCurrentDir( curDir );
break;
case cmChangeDir:
{
TDirEntry *p = dirList->list()->at( dirList->focused );
strcpy( curDir, p->dir() );
if( strcmp( curDir, drivesText ) == 0 )
break;
else if( driveValid( curDir[0] ) )
else if( isSeparator( curDir[0] ) || driveValid( curDir[0] ) )
{
int len = strlen( curDir );
if( !isSeparator(curDir[len-1]) )
Expand Down Expand Up @@ -175,7 +184,7 @@ void TChDirDialog::setUpDialog()
if( dirList != 0 )
{
char curDir[MAXPATH];
getCurDir( curDir );
getCurrentDir( curDir );
dirList->newDirectory( curDir );
if( dirInput != 0 )
{
Expand Down
33 changes: 22 additions & 11 deletions source/tvision/tdirlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,35 @@ void TDirListBox::showDirs( TDirCollection *dirs )
strcpy( org, pathDir );

char *curDir = dir;
char *end = dir + 3;
char hold = *end;
*end = EOS; // mark end of drive name
strcpy( name, curDir );
dirs->insert( new TDirEntry( org, name ) );

*end = hold; // restore full path
curDir = end;
char *end;

// Show root directory.
if( (end = strchr( curDir, '\\' )) != 0 )
{
char hold = *(++end);
*end = EOS;
strcpy( name, curDir );
dirs->insert( new TDirEntry( org, dir ) );
*end = hold;
curDir = end;
}
else
return;

// Show directories up to the current one.
while( (end = strchr( curDir, '\\' )) != 0 )
{
*end = EOS;
strncpy( name, curDir, size_t(end-curDir) );
name[size_t(end-curDir)] = EOS;
strcpy( name, curDir );
dirs->insert( new TDirEntry( org - indent, dir ) );
*end = '\\';
curDir = end+1;
curDir = end + 1;
indent += indentSize;
}

cur = dirs->getCount() - 1;

// Show subdirectories.
end = strrchr( dir, '\\' );
char path[MAXPATH];
strncpy( path, dir, size_t(end-dir+1) );
Expand Down Expand Up @@ -198,7 +206,10 @@ void TDirListBox::newDirectory( TStringView str )
{
strnzcpy( dir, str, sizeof(dir) );
TDirCollection *dirs = new TDirCollection( 5, 5 );
#if !defined( _TV_UNIX )
// Add 'Drives' entry.
dirs->insert( new TDirEntry( drives, drives ) );
#endif
if( str == drives )
showDrives( dirs );
else
Expand Down

0 comments on commit 545bc7d

Please sign in to comment.