int BC_FileBoxDirectoryText::handle_event()
{
- const char *path;
- path = get_text();
- // is a directory, change directories
- if(filebox->fs->is_dir(path))
- {
- const char *cp = path;
- char dir_path[BCTEXTLEN], *dp = dir_path;
- while( *cp ) *dp++ = *cp++;
- while( dp >= dir_path && *--dp == '/' );
- *++dp = '/'; *++dp = 0;
- if( strcmp(filebox->fs->get_current_dir(), dir_path) ) {
- filebox->fs->change_dir(dir_path);
- filebox->refresh(1);
- }
- update(dir_path);
- return 1;
+ const char *path = get_text();
+ if( !filebox->fs->is_dir(path) ) return 0;
+ const char *cp = path;
+ while( *cp ) ++cp;
+ if( cp > path && *--cp != '/' ) return 0;
+ char *file_path = FileSystem::basepath(path);
+ char *dir_path = FileSystem::basepath(filebox->fs->get_current_dir());
+ int ret = !strcmp(file_path, dir_path) ? 0 : 1;
+ if( ret ) {
+ strcpy(filebox->directory, file_path);
+ filebox->update_history();
+ filebox->fs->change_dir(file_path);
+ filebox->refresh(1);
}
- return 0;
+ delete [] dir_path;
+ delete [] file_path;
+ return ret;
}
: BC_Window(title, x, y,
BC_WindowBase::get_resources()->filebox_w,
BC_WindowBase::get_resources()->filebox_h,
- 10, 10, 1, 0, 1)
+ 400, 300, 1, 0, 1)
{
fs = new FileSystem;
// if(want_directory)
strcpy(directory, fs->get_current_dir());
filename[0] = 0;
}
+ else
+ fs->set_current_dir(this->directory);
if(h_padding == -1)
int BC_FileBox::extract_extension(char *out, const char *in)
{
- int i;
-
- for(i = strlen(in)-1; i > 0 && in[i] != '.'; i--)
- {
- ;
- }
- if(in[i] == '.') {
- i++;
- strcpy(out, &in[i]);
- }
- else
- out[0] = '\0';
+ *out = 0;
+ int i = strlen(in);
+ while( --i>=0 && in[i]!='.' );
+ if( i >= 0 ) strcpy(out, &in[++i]);
return 0;
}
// {
if(!is_dir)
{
- sprintf(string, _LD, file_item->size);
+ sprintf(string, "%jd", file_item->size);
new_item = new BC_ListBoxItem(string, get_resources()->file_color);
}
else
// Extension entry
// if(!want_directory)
// {
- if(!is_dir)
- {
+ if(!is_dir) {
extract_extension(string, file_item->name);
new_item = new BC_ListBoxItem(string, get_resources()->file_color);
}
- else
- {
+ else {
new_item = new BC_ListBoxItem("", get_resources()->directory_color);
}
list_column[column_of_type(FILEBOX_EXTENSION)].append(new_item);