2025-10-16 17:41:42 +00:00
# include <Mw/Milsko.h>
2025-10-17 10:37:34 +00:00
# include "../external/stb_ds.h"
2025-10-16 18:45:45 +00:00
typedef struct filechooser {
2025-10-19 05:23:44 +00:00
char * path ;
char * * history ;
int history_seek ;
2025-11-26 17:01:08 +00:00
int dir_only ;
2025-10-18 10:51:42 +00:00
2025-10-18 10:48:01 +00:00
MwDirectoryEntry * * entries ;
2025-10-18 10:50:57 +00:00
MwDirectoryEntry * * sorted_entries ;
2025-10-18 10:48:01 +00:00
2025-10-16 18:45:45 +00:00
MwWidget nav ;
MwWidget files ;
MwWidget addr ;
MwWidget addr_back ;
MwWidget addr_fwd ;
MwWidget addr_up ;
MwWidget filename_label ;
MwWidget filename ;
MwWidget okay ;
MwWidget cancel ;
MwLLPixmap dir ;
MwLLPixmap file ;
MwLLPixmap back ;
MwLLPixmap forward ;
MwLLPixmap up ;
2025-10-16 18:59:58 +00:00
MwLLPixmap computer ;
2025-10-16 18:45:45 +00:00
} filechooser_t ;
2025-10-19 05:23:44 +00:00
static void scan ( MwWidget handle , const char * path , int record ) ;
2025-10-18 12:51:41 +00:00
2025-10-16 18:45:45 +00:00
static void destroy ( MwWidget handle ) {
filechooser_t * fc = handle - > opaque ;
2025-10-18 10:51:42 +00:00
int i ;
2025-10-18 10:48:01 +00:00
2025-10-19 05:23:44 +00:00
for ( i = 0 ; i < arrlen ( fc - > history ) ; i + + ) free ( fc - > history [ i ] ) ;
arrfree ( fc - > history ) ;
2025-10-18 10:50:57 +00:00
arrfree ( fc - > sorted_entries ) ;
2025-10-18 10:48:01 +00:00
for ( i = 0 ; i < arrlen ( fc - > entries ) ; i + + ) MwDirectoryFreeEntry ( fc - > entries [ i ] ) ;
arrfree ( fc - > entries ) ;
2025-10-16 18:45:45 +00:00
MwLLDestroyPixmap ( fc - > dir ) ;
MwLLDestroyPixmap ( fc - > file ) ;
2025-10-16 18:59:58 +00:00
MwLLDestroyPixmap ( fc - > back ) ;
MwLLDestroyPixmap ( fc - > forward ) ;
MwLLDestroyPixmap ( fc - > up ) ;
MwLLDestroyPixmap ( fc - > computer ) ;
2025-10-16 18:45:45 +00:00
free ( handle - > opaque ) ;
MwDestroyWidget ( handle ) ;
}
2026-04-22 12:05:49 +09:00
static void MWAPI filecancel ( MwWidget handle , void * user , void * call ) {
2025-10-16 18:45:45 +00:00
( void ) user ;
( void ) call ;
destroy ( handle - > parent ) ;
}
2026-04-22 12:05:49 +09:00
static void MWAPI cancel_window ( MwWidget handle , void * user , void * call ) {
2025-10-17 15:41:30 +00:00
( void ) user ;
( void ) call ;
destroy ( handle ) ;
}
2026-04-22 12:05:49 +09:00
static void MWAPI okay ( MwWidget handle , void * user , void * call ) {
2025-10-16 18:45:45 +00:00
( void ) user ;
( void ) call ;
destroy ( handle - > parent ) ;
}
2026-04-22 12:05:49 +09:00
static void MWAPI msgbox_okay ( MwWidget handle , void * user , void * call ) {
2025-10-18 15:27:13 +00:00
( void ) user ;
( void ) call ;
2026-04-20 02:04:43 +09:00
MwDestroyWidget ( handle - > parent ) ;
2025-10-18 15:27:13 +00:00
}
2026-04-22 12:05:49 +09:00
static void MWAPI files_activate ( MwWidget handle , void * user , void * call ) {
2025-10-18 12:51:41 +00:00
int index = * ( int * ) call ;
filechooser_t * fc = handle - > parent - > opaque ;
( void ) user ;
2025-10-18 14:17:26 +00:00
if ( fc - > sorted_entries [ index - 1 ] - > type = = MwDIRECTORY_DIRECTORY ) {
char * p = MwDirectoryJoin ( fc - > path , fc - > sorted_entries [ index - 1 ] - > name ) ;
2025-10-19 05:23:44 +00:00
scan ( handle - > parent , p , 1 ) ;
2025-10-18 14:17:26 +00:00
free ( p ) ;
} else {
2025-11-26 17:01:08 +00:00
char * p ;
p = MwDirectoryJoin ( fc - > path , fc - > sorted_entries [ MwGetInteger ( fc - > files , MwNvalue ) - 1 ] - > name ) ;
2025-12-01 18:16:17 +00:00
MwDispatchUserHandler ( handle - > parent , fc - > dir_only ? MwNdirectoryChosenHandler : MwNfileChosenHandler , p ) ;
2025-11-26 17:01:08 +00:00
free ( p ) ;
2025-10-18 14:17:26 +00:00
okay ( fc - > okay , NULL , NULL ) ;
}
}
2026-04-22 12:05:49 +09:00
static void MWAPI okay_activate ( MwWidget handle , void * user , void * call ) {
2025-11-26 17:01:08 +00:00
filechooser_t * fc = handle - > parent - > opaque ;
char * t = ( char * ) MwGetText ( fc - > filename , MwNtext ) ;
struct stat s ;
char * p = NULL ;
( void ) user ;
( void ) call ;
if ( t ! = NULL & & t [ 0 ] = = ' / ' ) {
p = MwStringDuplicate ( t ) ;
} else {
p = MwDirectoryJoin ( fc - > path , t ) ;
}
if ( t = = NULL | | strlen ( t ) = = 0 ) {
MwWidget msgbox = MwMessageBox ( handle - > parent , fc - > dir_only ? " You have to type directory! " : " You have to type filename! " , " Error " , MwMB_ICONERROR | MwMB_BUTTONOK ) ;
MwAddUserHandler ( MwMessageBoxGetChild ( msgbox , MwMB_BUTTONOK ) , MwNactivateHandler , msgbox_okay , NULL ) ;
} else if ( stat ( p , & s ) ! = 0 ) {
MwWidget msgbox = MwMessageBox ( handle - > parent , " File does not exist! " , " Error " , MwMB_ICONERROR | MwMB_BUTTONOK ) ;
MwAddUserHandler ( MwMessageBoxGetChild ( msgbox , MwMB_BUTTONOK ) , MwNactivateHandler , msgbox_okay , NULL ) ;
2025-12-15 11:42:09 +09:00
# ifdef _S_IFDIR
} else if ( fc - > dir_only ? ( ( s . st_mode & _S_IFDIR ) ! = _S_IFDIR ) : 0 ) {
# else
2025-11-26 17:01:08 +00:00
} else if ( fc - > dir_only ? ! S_ISDIR ( s . st_mode ) : 0 ) {
2025-12-15 11:42:09 +09:00
# endif
2025-11-26 17:01:08 +00:00
MwWidget msgbox = MwMessageBox ( handle - > parent , " File is not permitted here! " , " Error " , MwMB_ICONERROR | MwMB_BUTTONOK ) ;
MwAddUserHandler ( MwMessageBoxGetChild ( msgbox , MwMB_BUTTONOK ) , MwNactivateHandler , msgbox_okay , NULL ) ;
} else {
2025-12-01 18:30:11 +00:00
MwDispatchUserHandler ( handle - > parent , fc - > dir_only ? MwNdirectoryChosenHandler : MwNfileChosenHandler , p ) ;
2025-11-26 17:01:08 +00:00
okay ( fc - > okay , NULL , NULL ) ;
}
if ( p ! = NULL ) free ( p ) ;
}
2026-04-22 12:05:49 +09:00
static void MWAPI nav_activate ( MwWidget handle , void * user , void * call ) {
2025-10-18 16:31:59 +00:00
int index = * ( int * ) call ;
const char * e = MwListBoxGet ( handle , index ) ;
( void ) user ;
if ( strcmp ( e , " Home " ) = = 0 ) {
2026-04-15 20:21:20 -07:00
# if defined(_WIN32) || defined(CLASSIC_MAC_OS)
2025-10-18 16:31:59 +00:00
# else
struct passwd * p = getpwuid ( getuid ( ) ) ;
2025-10-19 05:23:44 +00:00
scan ( handle - > parent , p - > pw_dir , 1 ) ;
2025-10-18 16:31:59 +00:00
# endif
}
}
2026-04-22 12:05:49 +09:00
static void MWAPI addr_up_activate ( MwWidget handle , void * user , void * call ) {
2025-10-18 14:17:26 +00:00
filechooser_t * fc = handle - > parent - > opaque ;
char * p = MwDirectoryJoin ( fc - > path , " .. " ) ;
( void ) user ;
( void ) call ;
2025-10-19 05:23:44 +00:00
scan ( handle - > parent , p , 1 ) ;
2025-10-18 14:17:26 +00:00
free ( p ) ;
2025-10-18 12:51:41 +00:00
}
2026-04-22 12:05:49 +09:00
static void MWAPI addr_back_activate ( MwWidget handle , void * user , void * call ) {
2025-10-19 05:23:44 +00:00
filechooser_t * fc = handle - > parent - > opaque ;
( void ) user ;
( void ) call ;
if ( fc - > history_seek > 1 ) {
fc - > history_seek - = 2 ;
scan ( handle - > parent , fc - > history [ fc - > history_seek ] , 0 ) ;
fc - > history_seek + + ;
}
}
2026-04-22 12:05:49 +09:00
static void MWAPI addr_fwd_activate ( MwWidget handle , void * user , void * call ) {
2025-10-19 05:23:44 +00:00
filechooser_t * fc = handle - > parent - > opaque ;
( void ) user ;
( void ) call ;
if ( fc - > history_seek < arrlen ( fc - > history ) ) {
scan ( handle - > parent , fc - > history [ fc - > history_seek + + ] , 0 ) ;
}
}
2026-04-22 12:05:49 +09:00
static void MWAPI addr_activate ( MwWidget handle , void * user , void * call ) {
2025-10-18 14:37:26 +00:00
( void ) user ;
( void ) call ;
2025-10-19 05:23:44 +00:00
scan ( handle - > parent , MwGetText ( handle , MwNtext ) , 1 ) ;
2025-10-18 14:37:26 +00:00
}
2025-10-16 18:45:45 +00:00
static void layout ( MwWidget handle ) {
filechooser_t * fc = handle - > opaque ;
int w = MwGetInteger ( handle , MwNwidth ) ;
int h = MwGetInteger ( handle , MwNheight ) ;
int wx , wy , ww , wh ;
wx = 5 ;
wy = 5 + 24 + 5 ;
ww = 160 ;
wh = h - 10 - 24 - 5 - 24 - 5 - 24 - 5 ;
if ( fc - > nav = = NULL ) {
2026-04-18 19:21:50 +09:00
int index ;
2025-10-22 17:30:57 +00:00
2025-10-16 18:59:58 +00:00
fc - > nav = MwVaCreateWidget ( MwListBoxClass , " nav " , handle , wx , wy , ww , wh ,
MwNleftPadding , 16 ,
NULL ) ;
2025-10-22 17:30:57 +00:00
2026-04-18 19:40:28 +09:00
index = MwListBoxSet ( fc - > nav , - 1 , 0 , " Home " ) ;
2026-04-18 19:21:50 +09:00
MwListBoxSetIcon ( fc - > nav , index , fc - > computer ) ;
MwAddUserHandler ( fc - > nav , MwNlistBoxActivateHandler , nav_activate , NULL ) ;
2025-10-16 18:45:45 +00:00
} else {
MwVaApply ( fc - > nav ,
MwNx , wx ,
MwNy , wy ,
MwNwidth , ww ,
MwNheight , wh ,
NULL ) ;
}
wx = 5 + 160 + 5 ;
wy = 5 + 24 + 5 ;
ww = w - 5 - 160 - 5 - 5 ;
wh = h - 10 - 24 - 5 - 24 - 5 - 24 - 5 ;
if ( fc - > files = = NULL ) {
fc - > files = MwVaCreateWidget ( MwListBoxClass , " files " , handle , wx , wy , ww , wh ,
MwNhasHeading , 1 ,
2025-10-16 18:59:58 +00:00
MwNleftPadding , 16 ,
2025-10-16 18:45:45 +00:00
NULL ) ;
2026-04-17 01:36:34 +09:00
MwAddUserHandler ( fc - > files , MwNlistBoxActivateHandler , files_activate , NULL ) ;
2025-10-16 18:45:45 +00:00
} else {
MwVaApply ( fc - > files ,
MwNx , wx ,
MwNy , wy ,
MwNwidth , ww ,
MwNheight , wh ,
NULL ) ;
}
wx = 5 + ( ( 24 + 5 ) * 3 ) ;
wy = 5 ;
ww = w - 10 - ( ( 24 + 5 ) * 3 ) ;
wh = 24 ;
if ( fc - > addr = = NULL ) {
fc - > addr = MwCreateWidget ( MwEntryClass , " addr " , handle , wx , wy , ww , wh ) ;
2025-10-18 14:37:26 +00:00
MwAddUserHandler ( fc - > addr , MwNactivateHandler , addr_activate , NULL ) ;
2025-10-16 18:45:45 +00:00
} else {
MwVaApply ( fc - > addr ,
MwNx , wx ,
MwNy , wy ,
MwNwidth , ww ,
MwNheight , wh ,
NULL ) ;
}
wx = 5 ;
wy = 5 ;
ww = 24 ;
wh = 24 ;
if ( fc - > addr_back = = NULL ) {
fc - > addr_back = MwVaCreateWidget ( MwButtonClass , " addr_back " , handle , wx , wy , ww , wh ,
MwNpixmap , fc - > back ,
NULL ) ;
2025-10-19 05:23:44 +00:00
MwAddUserHandler ( fc - > addr_back , MwNactivateHandler , addr_back_activate , NULL ) ;
2025-10-16 18:45:45 +00:00
} else {
MwVaApply ( fc - > addr_back ,
MwNx , wx ,
MwNy , wy ,
MwNwidth , ww ,
MwNheight , wh ,
NULL ) ;
}
wx = 5 + 24 + 5 ;
wy = 5 ;
ww = 24 ;
wh = 24 ;
if ( fc - > addr_fwd = = NULL ) {
fc - > addr_fwd = MwVaCreateWidget ( MwButtonClass , " addr_fwd " , handle , wx , wy , ww , wh ,
MwNpixmap , fc - > forward ,
NULL ) ;
2025-10-19 05:23:44 +00:00
MwAddUserHandler ( fc - > addr_fwd , MwNactivateHandler , addr_fwd_activate , NULL ) ;
2025-10-16 18:45:45 +00:00
} else {
MwVaApply ( fc - > addr_fwd ,
MwNx , wx ,
MwNy , wy ,
MwNwidth , ww ,
MwNheight , wh ,
NULL ) ;
}
wx = 5 + 24 + 5 + 24 + 5 ;
wy = 5 ;
ww = 24 ;
wh = 24 ;
if ( fc - > addr_up = = NULL ) {
fc - > addr_up = MwVaCreateWidget ( MwButtonClass , " addr_up " , handle , wx , wy , ww , wh ,
MwNpixmap , fc - > up ,
NULL ) ;
2025-10-18 14:17:26 +00:00
MwAddUserHandler ( fc - > addr_up , MwNactivateHandler , addr_up_activate , NULL ) ;
2025-10-16 18:45:45 +00:00
} else {
MwVaApply ( fc - > addr_up ,
MwNx , wx ,
MwNy , wy ,
MwNwidth , ww ,
MwNheight , wh ,
NULL ) ;
}
wx = 5 + ( ( 24 + 5 ) * 3 ) ;
wy = h - 5 - 24 - 5 - 24 ;
ww = w - 10 - ( ( 24 + 5 ) * 3 ) ;
wh = 24 ;
if ( fc - > filename = = NULL ) {
fc - > filename = MwCreateWidget ( MwEntryClass , " filename " , handle , wx , wy , ww , wh ) ;
2025-11-26 17:01:08 +00:00
MwAddUserHandler ( fc - > filename , MwNactivateHandler , okay_activate , NULL ) ;
2025-10-16 18:45:45 +00:00
} else {
MwVaApply ( fc - > filename ,
MwNx , wx ,
MwNy , wy ,
MwNwidth , ww ,
MwNheight , wh ,
NULL ) ;
}
wx = 5 ;
wy = h - 5 - 24 - 5 - 24 ;
ww = ( ( 24 + 5 ) * 3 ) ;
wh = 24 ;
if ( fc - > filename_label = = NULL ) {
fc - > filename_label = MwVaCreateWidget ( MwLabelClass , " filename_label " , handle , wx , wy , ww , wh ,
2025-11-26 17:01:08 +00:00
MwNtext , fc - > dir_only ? " Directory: " : " Filename: " ,
2025-10-16 18:45:45 +00:00
NULL ) ;
} else {
MwVaApply ( fc - > filename_label ,
MwNx , wx ,
MwNy , wy ,
MwNwidth , ww ,
MwNheight , wh ,
NULL ) ;
}
wx = w - 5 - 24 * 3 - 5 - 24 * 3 ;
wy = h - 5 - 24 ;
ww = 24 * 3 ;
wh = 24 ;
if ( fc - > okay = = NULL ) {
fc - > okay = MwVaCreateWidget ( MwButtonClass , " ok " , handle , wx , wy , ww , wh ,
MwNtext , " Okay " ,
NULL ) ;
2025-11-26 17:01:08 +00:00
MwAddUserHandler ( fc - > okay , MwNactivateHandler , okay_activate , NULL ) ;
2025-10-16 18:45:45 +00:00
} else {
MwVaApply ( fc - > okay ,
MwNx , wx ,
MwNy , wy ,
MwNwidth , ww ,
MwNheight , wh ,
NULL ) ;
}
wx = w - 5 - 24 * 3 ;
wy = h - 5 - 24 ;
ww = 24 * 3 ;
wh = 24 ;
if ( fc - > cancel = = NULL ) {
fc - > cancel = MwVaCreateWidget ( MwButtonClass , " cancel " , handle , wx , wy , ww , wh ,
MwNtext , " Cancel " ,
NULL ) ;
2026-04-15 21:41:16 -07:00
MwAddUserHandler ( fc - > cancel , MwNactivateHandler , filecancel , NULL ) ;
2025-10-16 18:45:45 +00:00
} else {
MwVaApply ( fc - > cancel ,
MwNx , wx ,
MwNy , wy ,
MwNwidth , ww ,
MwNheight , wh ,
NULL ) ;
}
}
2026-04-22 12:05:49 +09:00
static void MWAPI resize ( MwWidget handle , void * user , void * call ) {
2025-10-16 18:45:45 +00:00
( void ) user ;
( void ) call ;
layout ( handle ) ;
}
2025-10-17 13:12:49 +00:00
static int qsort_files ( const void * a , const void * b ) {
2025-10-17 10:37:34 +00:00
MwDirectoryEntry * aent = * ( MwDirectoryEntry * * ) a ;
MwDirectoryEntry * bent = * ( MwDirectoryEntry * * ) b ;
return strcmp ( aent - > name , bent - > name ) ;
}
2025-10-19 05:23:44 +00:00
static void scan ( MwWidget handle , const char * path , int record ) {
2026-04-18 19:21:50 +09:00
filechooser_t * fc = handle - > opaque ;
void * dir = MwDirectoryOpen ( path ) ;
int i ;
int index ;
2025-10-18 10:48:01 +00:00
2025-10-17 13:12:49 +00:00
if ( dir ! = NULL ) {
2025-10-17 10:37:34 +00:00
MwDirectoryEntry * entry ;
2025-10-18 15:27:13 +00:00
arrfree ( fc - > sorted_entries ) ;
for ( i = 0 ; i < arrlen ( fc - > entries ) ; i + + ) MwDirectoryFreeEntry ( fc - > entries [ i ] ) ;
arrfree ( fc - > entries ) ;
2025-10-18 10:48:01 +00:00
while ( ( entry = MwDirectoryRead ( dir ) ) ! = NULL ) arrput ( fc - > entries , entry ) ;
2025-10-17 10:37:34 +00:00
MwDirectoryClose ( dir ) ;
2025-10-18 10:48:01 +00:00
qsort ( fc - > entries , arrlen ( fc - > entries ) , sizeof ( MwDirectoryEntry * ) , qsort_files ) ;
2025-10-19 05:23:44 +00:00
if ( record ) {
2025-11-20 09:26:18 +00:00
char * str = MwStringDuplicate ( path ) ;
2025-10-19 05:23:44 +00:00
while ( arrlen ( fc - > history ) > fc - > history_seek ) {
free ( fc - > history [ fc - > history_seek ] ) ;
arrdel ( fc - > history , fc - > history_seek ) ;
}
arrins ( fc - > history , fc - > history_seek , str ) ;
fc - > history_seek + + ;
}
2025-10-18 14:37:26 +00:00
} else {
2025-10-18 15:27:13 +00:00
MwWidget msgbox = MwMessageBox ( handle , " Directory does not exist! " , " Error " , MwMB_ICONERROR | MwMB_BUTTONOK ) ;
MwAddUserHandler ( MwMessageBoxGetChild ( msgbox , MwMB_BUTTONOK ) , MwNactivateHandler , msgbox_okay , NULL ) ;
return ;
2025-10-17 10:37:34 +00:00
}
2025-10-16 18:45:45 +00:00
2025-10-18 10:48:01 +00:00
if ( fc - > path ! = NULL ) free ( fc - > path ) ;
2025-11-20 09:26:18 +00:00
fc - > path = MwStringDuplicate ( path ) ;
2025-10-18 10:48:01 +00:00
2025-10-17 00:16:02 +00:00
MwVaApply ( fc - > addr ,
MwNtext , path ,
NULL ) ;
2025-11-26 17:01:08 +00:00
if ( fc - > dir_only ) {
MwVaApply ( fc - > filename ,
MwNtext , path ,
NULL ) ;
} else {
MwVaApply ( fc - > filename ,
MwNtext , " " ,
NULL ) ;
}
2025-10-16 18:45:45 +00:00
MwListBoxReset ( fc - > files ) ;
2025-10-17 13:12:49 +00:00
MwListBoxSetWidth ( fc - > files , 0 , - 128 - 96 ) ;
2025-10-16 18:45:45 +00:00
MwListBoxSetWidth ( fc - > files , 1 , 128 ) ;
MwListBoxSetWidth ( fc - > files , 2 , 0 ) ;
2025-10-17 10:37:34 +00:00
2026-04-18 19:40:28 +09:00
index = MwListBoxSet ( fc - > files , - 1 , 0 , " Name " ) ;
MwListBoxSet ( fc - > files , index , - 1 , " Date modified " ) ;
MwListBoxSet ( fc - > files , index , - 1 , " Size " ) ;
2025-10-22 17:30:57 +00:00
2025-10-18 10:48:01 +00:00
for ( i = 0 ; i < arrlen ( fc - > entries ) ; i + + ) {
if ( strcmp ( fc - > entries [ i ] - > name , " . " ) = = 0 | | strcmp ( fc - > entries [ i ] - > name , " .. " ) = = 0 ) continue ;
if ( fc - > entries [ i ] - > type = = MwDIRECTORY_DIRECTORY ) {
2025-10-22 17:30:57 +00:00
char date [ 128 ] ;
2025-10-17 19:44:55 +00:00
2025-10-18 10:48:01 +00:00
MwStringTime ( date , fc - > entries [ i ] - > mtime ) ;
2025-10-17 19:44:55 +00:00
2026-04-18 19:40:28 +09:00
index = MwListBoxSet ( fc - > files , - 1 , 0 , fc - > entries [ i ] - > name ) ;
MwListBoxSet ( fc - > files , index , - 1 , date ) ;
MwListBoxSet ( fc - > files , index , - 1 , NULL ) ;
2026-04-18 19:21:50 +09:00
MwListBoxSetIcon ( fc - > files , index , fc - > dir ) ;
2025-10-18 10:50:57 +00:00
arrput ( fc - > sorted_entries , fc - > entries [ i ] ) ;
2025-10-17 10:37:34 +00:00
}
}
2025-10-18 10:48:01 +00:00
for ( i = 0 ; i < arrlen ( fc - > entries ) ; i + + ) {
2025-11-26 17:01:08 +00:00
if ( fc - > entries [ i ] - > type = = MwDIRECTORY_FILE & & ! fc - > dir_only ) {
2025-10-22 17:30:57 +00:00
char date [ 128 ] ;
char size [ 128 ] ;
2025-10-17 13:12:49 +00:00
2025-10-18 10:48:01 +00:00
MwStringTime ( date , fc - > entries [ i ] - > mtime ) ;
MwStringSize ( size , fc - > entries [ i ] - > size ) ;
2025-10-17 13:12:49 +00:00
2026-04-18 19:40:28 +09:00
index = MwListBoxSet ( fc - > files , - 1 , 0 , fc - > entries [ i ] - > name ) ;
MwListBoxSet ( fc - > files , index , - 1 , date ) ;
MwListBoxSet ( fc - > files , index , - 1 , size ) ;
2026-04-18 19:21:50 +09:00
MwListBoxSetIcon ( fc - > files , index , fc - > file ) ;
2025-10-18 10:50:57 +00:00
arrput ( fc - > sorted_entries , fc - > entries [ i ] ) ;
2025-10-17 10:37:34 +00:00
}
}
2025-10-16 18:45:45 +00:00
}
2025-11-26 17:01:08 +00:00
MwWidget MwFileChooserEx ( MwWidget handle , const char * title , int dir ) {
2025-10-16 18:45:45 +00:00
MwWidget window ;
int w , h ;
filechooser_t * fc = malloc ( sizeof ( * fc ) ) ;
2025-10-17 00:16:02 +00:00
char * path ;
2025-10-17 13:12:49 +00:00
MwLLPixmap icon ;
2025-11-14 17:11:16 +00:00
int wx ;
int wy ;
2025-10-16 18:45:45 +00:00
memset ( fc , 0 , sizeof ( * fc ) ) ;
2025-10-16 17:41:42 +00:00
2025-11-14 17:11:16 +00:00
w = 700 ;
h = w * 2 / 3 ;
2025-10-16 18:45:45 +00:00
2025-11-15 15:19:35 +00:00
if ( handle = = NULL ) {
wx = wy = MwDEFAULT ;
} else {
wx = MwGetInteger ( handle , MwNx ) + ( MwGetInteger ( handle , MwNwidth ) - w ) / 2 ;
wy = MwGetInteger ( handle , MwNy ) + ( MwGetInteger ( handle , MwNheight ) - h ) / 2 ;
}
2025-11-14 17:11:16 +00:00
2025-11-15 15:19:35 +00:00
window = MwVaCreateWidget ( MwWindowClass , " filechooser " , NULL , wx , wy , w , h ,
2025-11-14 17:11:16 +00:00
MwNtitle , title ,
NULL ) ;
2025-11-15 15:19:35 +00:00
if ( handle ! = NULL ) MwReparent ( window , handle ) ;
2025-11-14 17:11:16 +00:00
2025-10-19 05:23:44 +00:00
fc - > history_seek = 0 ;
2025-10-24 16:27:10 +00:00
fc - > dir = MwLoadIcon ( window , MwIconDirectory ) ;
fc - > file = MwLoadIcon ( window , MwIconFile ) ;
fc - > back = MwLoadIcon ( window , MwIconBack ) ;
fc - > forward = MwLoadIcon ( window , MwIconForward ) ;
fc - > up = MwLoadIcon ( window , MwIconUp ) ;
fc - > computer = MwLoadIcon ( window , MwIconComputer ) ;
2025-11-26 17:01:08 +00:00
fc - > dir_only = dir ;
2025-10-24 16:27:10 +00:00
icon = MwLoadIcon ( window , MwIconSearch ) ;
2025-10-17 10:50:59 +00:00
MwVaApply ( window ,
2025-10-17 13:12:49 +00:00
MwNiconPixmap , icon ,
NULL ) ;
2025-10-17 10:50:59 +00:00
2025-10-16 18:45:45 +00:00
window - > opaque = fc ;
layout ( window ) ;
MwAddUserHandler ( window , MwNresizeHandler , resize , NULL ) ;
2025-10-17 15:41:30 +00:00
MwAddUserHandler ( window , MwNcloseHandler , cancel_window , NULL ) ;
2025-10-16 18:45:45 +00:00
2025-10-17 00:16:02 +00:00
path = MwDirectoryCurrent ( ) ;
2025-10-19 05:23:44 +00:00
scan ( window , path , 1 ) ;
2025-10-17 00:16:02 +00:00
free ( path ) ;
2025-10-16 17:41:42 +00:00
2025-11-14 12:13:31 +00:00
MwLLBeginStateChange ( window - > lowlevel ) ;
2025-11-14 17:29:30 +00:00
MwLLMakePopup ( window - > lowlevel , handle = = NULL ? NULL : handle - > lowlevel ) ;
2025-11-14 12:13:31 +00:00
MwLLEndStateChange ( window - > lowlevel ) ;
2025-10-16 18:45:45 +00:00
2025-10-16 17:41:42 +00:00
return window ;
}
2025-11-26 17:01:08 +00:00
MwWidget MwFileChooser ( MwWidget handle , const char * title ) {
return MwFileChooserEx ( handle , title , 0 ) ;
}