X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fbcfilebox.C;h=80cf3320191f37ec35b4096c7f418485292cb71e;hp=1dc1f308d5739b7c41276ca7923a26bc1caa5025;hb=7e5a0760f40ff787cc3d93cb7768a901ebe52809;hpb=43821d27c5b51c4250a251f20c98878f54deb288 diff --git a/cinelerra-5.1/guicast/bcfilebox.C b/cinelerra-5.1/guicast/bcfilebox.C index 1dc1f308..80cf3320 100644 --- a/cinelerra-5.1/guicast/bcfilebox.C +++ b/cinelerra-5.1/guicast/bcfilebox.C @@ -1,7 +1,7 @@ /* * CINELERRA - * Copyright (C) 1997-2011 Adam Williams + * Copyright (C) 1997-2017 Adam Williams * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -172,8 +172,6 @@ int BC_FileBoxListBox::evaluate_query(char *string) } - - BC_FileBoxTextBox::BC_FileBoxTextBox(int x, int y, BC_FileBox *filebox) : BC_TextBox(x, y, filebox->get_w() - 20, 1, filebox->want_directory ? filebox->directory : filebox->filename) @@ -185,9 +183,6 @@ BC_FileBoxTextBox::~BC_FileBoxTextBox() { } - - - int BC_FileBoxTextBox::handle_event() { int result = 0; @@ -199,8 +194,6 @@ int BC_FileBoxTextBox::handle_event() } - - BC_FileBoxDirectoryText::BC_FileBoxDirectoryText(int x, int y, BC_FileBox *filebox) : BC_TextBox(x, y, filebox->get_w() - 40, 1, filebox->fs->get_current_dir()) { @@ -215,7 +208,7 @@ int BC_FileBoxDirectoryText::handle_event() 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()); + char *dir_path = FileSystem::basepath(filebox->directory); int ret = !strcmp(file_path, dir_path) ? 0 : 1; if( ret ) { strcpy(filebox->directory, file_path); @@ -229,11 +222,8 @@ int BC_FileBoxDirectoryText::handle_event() } - - - BC_FileBoxFilterText::BC_FileBoxFilterText(int x, int y, BC_FileBox *filebox) - : BC_TextBox(x, y, filebox->get_w() - 50, 1, filebox->get_resources()->filebox_filter) + : BC_TextBox(x, y, filebox->get_w() - x - 50, 1, filebox->get_resources()->filebox_filter) { this->filebox = filebox; } @@ -245,20 +235,9 @@ int BC_FileBoxFilterText::handle_event() } - - BC_FileBoxFilterMenu::BC_FileBoxFilterMenu(int x, int y, BC_FileBox *filebox) - : BC_ListBox(x, - y, - filebox->get_w() - 30, - 120, - LISTBOX_TEXT, - &filebox->filter_list, - 0, - 0, - 1, - 0, - 1) + : BC_ListBox(x, y, filebox->get_w() - 30, 120, + LISTBOX_TEXT, &filebox->filter_list, 0, 0, 1, 0, 1) { this->filebox = filebox; set_tooltip(_("Change the filter")); @@ -274,39 +253,30 @@ int BC_FileBoxFilterMenu::handle_event() } - - - - - - - - -BC_FileBoxCancel::BC_FileBoxCancel(BC_FileBox *filebox) - : BC_CancelButton(filebox) +BC_FileBoxSizeFormat::BC_FileBoxSizeFormat(int x, int y, BC_FileBox *file_box) + : BC_Button(x, y, &BC_WindowBase::get_resources()-> + filebox_szfmt_images[3*file_box->size_format]) { - this->filebox = filebox; - set_tooltip(_("Cancel the operation")); + this->file_box = file_box; + set_tooltip(_("Size numeric format")); } - -BC_FileBoxCancel::~BC_FileBoxCancel() +BC_FileBoxSizeFormat::~BC_FileBoxSizeFormat() { } -int BC_FileBoxCancel::handle_event() +int BC_FileBoxSizeFormat::handle_event() { -// filebox->submit_file(filebox->textbox->get_text()); - filebox->newfolder_thread->interrupt(); - filebox->set_done(1); + if( ++file_box->size_format > FILEBOX_SIZE_THOU ) + file_box->size_format = FILEBOX_SIZE_RAW; + BC_WindowBase::get_resources()->filebox_size_format = file_box->size_format; + set_images(&BC_WindowBase::get_resources()-> + filebox_szfmt_images[3*file_box->size_format]); + draw_face(0); + file_box->refresh(0); return 1; } - - - - - BC_FileBoxUseThis::BC_FileBoxUseThis(BC_FileBox *filebox) : BC_Button(filebox->get_w() / 2 - BC_WindowBase::get_resources()->usethis_button_images[0]->get_w() / 2, @@ -331,9 +301,6 @@ int BC_FileBoxUseThis::handle_event() } - - - BC_FileBoxOK::BC_FileBoxOK(BC_FileBox *filebox) : BC_OKButton(filebox, !filebox->want_directory ? @@ -359,6 +326,26 @@ int BC_FileBoxOK::handle_event() return 1; } +BC_FileBoxCancel::BC_FileBoxCancel(BC_FileBox *filebox) + : BC_CancelButton(filebox) +{ + this->filebox = filebox; + set_tooltip(_("Cancel the operation")); +} + +BC_FileBoxCancel::~BC_FileBoxCancel() +{ +} + +int BC_FileBoxCancel::handle_event() +{ +// filebox->submit_file(filebox->textbox->get_text()); + filebox->newfolder_thread->interrupt(); + filebox->set_done(1); + return 1; +} + + BC_FileBoxText::BC_FileBoxText(int x, int y, BC_FileBox *filebox) : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_text_images) @@ -455,13 +442,6 @@ int BC_FileBoxReload::handle_event() - - - - - - - BC_FileBox::BC_FileBox(int x, int y, const char *init_path, const char *title, const char *caption, int show_all_files, int want_directory, int multiple_files, int h_padding) @@ -486,9 +466,11 @@ BC_FileBox::BC_FileBox(int x, int y, const char *init_path, column_type = new int[columns]; column_width = new int[columns]; + filter_title = 0; filter_text = 0; filter_popup = 0; usethis_button = 0; + size_format = BC_WindowBase::get_resources()->filebox_size_format; strcpy(this->caption, caption); strcpy(this->current_path, init_path); @@ -497,7 +479,7 @@ BC_FileBox::BC_FileBox(int x, int y, const char *init_path, this->want_directory = want_directory; if(show_all_files) fs->set_show_all(); fs->complete_path(this->current_path); - fs->complete_path(this->submitted_path); + strcpy(this->submitted_path, this->current_path); fs->extract_dir(directory, this->current_path); fs->extract_name(filename, this->current_path); @@ -535,16 +517,12 @@ BC_FileBox::BC_FileBox(int x, int y, const char *init_path, // Test if current directory exists if(!fs->is_dir(directory)) { - sprintf(this->current_path, "~"); - fs->complete_path(this->current_path); - fs->set_current_dir(this->current_path); -// fs->update(this->current_path); - strcpy(directory, fs->get_current_dir()); + sprintf(directory, "~"); + fs->complete_path(directory); + strcpy(current_path,directory); filename[0] = 0; } - else - fs->set_current_dir(this->directory); - + fs->set_current_dir(directory); if(h_padding == -1) { @@ -575,33 +553,27 @@ BC_FileBox::~BC_FileBox() void BC_FileBox::create_objects() { + lock_window("BC_FileBox::create_objects"); int x = 10, y = 10; BC_Resources *resources = BC_WindowBase::get_resources(); int directory_title_margin = MAX(20, resources->filebox_text_images[0]->get_h()); -// Create recent dir list - create_history(); - update_history(); - // Directories aren't filtered in FileSystem so skip this if(!want_directory) { filter_list.append(new BC_ListBoxItem("*")); - filter_list.append(new BC_ListBoxItem("[*.mkv]")); - filter_list.append(new BC_ListBoxItem("[*.mp4]")); + filter_list.append(new BC_ListBoxItem("[*.mkv][*.webm]")); + filter_list.append(new BC_ListBoxItem("[*.mp4][*.MP4]")); filter_list.append(new BC_ListBoxItem("[*.mp2][*.mp3][*.wav]")); filter_list.append(new BC_ListBoxItem("[*.avi][*.mpg][*.m2v][*.m1v][*.mov]")); + filter_list.append(new BC_ListBoxItem("[*.jpg][*.JPG][*.png][*.gif][*.tiff]")); filter_list.append(new BC_ListBoxItem("*.xml")); fs->set_filter(get_resources()->filebox_filter); } - fs->set_sort_order(sort_order); - fs->set_sort_field(column_type[sort_column]); - fs->update(directory); - create_icons(); - create_tables(); + create_tables(0); add_subwindow(ok_button = new BC_FileBoxOK(this)); if(want_directory) @@ -631,17 +603,18 @@ void BC_FileBox::create_objects() x -= resources->filebox_updir_images[0]->get_w() + 5; add_subwindow(updir_button = new BC_FileBoxUpdir(x, y, this)); + x -= resources->filebox_szfmt_images[0]->get_w() + 5; + + add_subwindow(szfmt_button = new BC_FileBoxSizeFormat(x, y, this)); x = 10; y += directory_title_margin + 3; add_subwindow(recent_popup = new BC_FileBoxRecent(this, x, y)); add_subwindow(directory_title = new BC_FileBoxDirectoryText(x, y, this)); - directory_title->reposition_window(x, y, - get_w() - recent_popup->get_w() - 20, 1); - recent_popup->reposition_window( - x + directory_title->get_w(), y, - directory_title->get_w(), 200); + directory_title->reposition_window(x, y, get_w() - recent_popup->get_w() - 20, 1); + x += directory_title->get_w() + 8; + recent_popup->reposition_window(x, y, directory_title->get_w(), 200); x = 10; y += directory_title->get_h() + 5; @@ -657,8 +630,16 @@ void BC_FileBox::create_objects() if( newest >= 0 ) { strcpy(directory, resources->filebox_history[newest].path); fs->change_dir(directory, 0); + strcpy(directory, fs->get_current_dir()); directory_title->update(fs->get_current_dir()); } + fs->set_sort_order(sort_order); + fs->set_sort_field(column_type[sort_column]); + fs->update(directory); + +// Create recent dir list + create_history(); + update_history(); listbox = 0; create_listbox(x, y, get_display_mode()); @@ -667,9 +648,11 @@ void BC_FileBox::create_objects() y += textbox->get_h() + 10; if(!want_directory) { - add_subwindow(filter_text = new BC_FileBoxFilterText(x, y, this)); + add_subwindow(filter_title = new BC_Title(x, y, _("Specify filter:"))); + int x1 = x + filter_title->get_w() + 10; + add_subwindow(filter_text = new BC_FileBoxFilterText(x1, y, this)); add_subwindow(filter_popup = - new BC_FileBoxFilterMenu(x + filter_text->get_w(), y, this));; + new BC_FileBoxFilterMenu(x1 + filter_text->get_w(), y, this)); } // listbox has to be active because refresh might be called from newfolder_thread @@ -678,8 +661,9 @@ void BC_FileBox::create_objects() rename_thread = new BC_RenameThread(this); - + refresh(); show_window(); + unlock_window(); } int BC_FileBox::get_listbox_w() @@ -689,9 +673,7 @@ int BC_FileBox::get_listbox_w() int BC_FileBox::get_listbox_h(int y) { - int result = get_h() - - y - - h_padding; + int result = get_h() - y - h_padding - 10; if(want_directory) result -= BC_WindowBase::get_resources()->dirbox_margin; else @@ -731,7 +713,8 @@ int BC_FileBox::resize_event(int w, int h) w - 30, 0); - + if(filter_title) filter_title->reposition_window(filter_title->get_x(), + h - (get_h() - filter_title->get_y())); if(filter_text) filter_text->reposition_window(filter_text->get_x(), h - (get_h() - filter_text->get_y()), w - (get_w() - filter_text->get_w()), @@ -742,7 +725,7 @@ int BC_FileBox::resize_event(int w, int h) get_w() - recent_popup->get_w() - 20, 1); recent_popup->reposition_window( - directory_title->get_x() + directory_title->get_w(), + directory_title->get_x() + directory_title->get_w() + 8, directory_title->get_y(), directory_title->get_w() + recent_popup->get_w(), recent_popup->get_h()); @@ -763,6 +746,7 @@ int BC_FileBox::resize_event(int w, int h) reload_button->reposition_window(reload_button->get_x()+dx, reload_button->get_y()); delete_button->reposition_window(delete_button->get_x()+dx, delete_button->get_y()); updir_button->reposition_window(updir_button->get_x()+dx, updir_button->get_y()); + szfmt_button->reposition_window(szfmt_button->get_x()+dx, szfmt_button->get_y()); set_w(w); set_h(h); get_resources()->filebox_w = get_w(); get_resources()->filebox_h = get_h(); @@ -772,12 +756,19 @@ int BC_FileBox::resize_event(int w, int h) int BC_FileBox::keypress_event() { - switch(get_keypress()) - { - case 'w': - if(ctrl_down()) set_done(1); - return 1; - break; + switch(get_keypress()) { + case 'a': + if( !ctrl_down() ) break; + refresh(0, 1); + return 1; + case 'z': + if( !ctrl_down() ) break; + refresh(0, 0); + return 1; + case 'w': + if( !ctrl_down() ) break; + set_done(1); + return 1; } return 0; } @@ -802,8 +793,22 @@ int BC_FileBox::extract_extension(char *out, const char *in) return 0; } -int BC_FileBox::create_tables() +static inline int64_t ipow(int m, int n) +{ + int64_t v = 1; + for( int64_t vv=m; n>0; vv*=vv,n>>=1 ) if( n & 1 ) v *= vv; + return v; +} +static inline int ilen(int64_t v) { + int len = 1; + while( len<16 && (v/=10)>0 ) ++len; + return len; +} + +int BC_FileBox::create_tables(int select_all) +{ + int preload_textbox = select_all; delete_tables(); char string[BCTEXTLEN]; BC_ListBoxItem *new_item; @@ -829,7 +834,41 @@ int BC_FileBox::create_tables() // { if(!is_dir) { - sprintf(string, "%jd", file_item->size); + if( preload_textbox ) { + preload_textbox = 0; + textbox->update(new_item->get_text()); + } + int64_t size = file_item->size; + if( (size_format == FILEBOX_SIZE_1000 && size >= 1000) || + (size_format == FILEBOX_SIZE_1024 && size >= 1024) ) { + static const char *suffix[] = { "", "K", "M", "G", "T", "P" }; + if( size_format == FILEBOX_SIZE_1024 ) { + static const long double kk = logl(1000.)/logl(1024.); + size = expl(kk*logl((long double)size)) + 0.5; + } + int len = ilen(size), drop = len-3, round = 1; + if( round && drop > 0 ) { //round + size += ipow(10,drop)/2; + len = ilen(size); drop = len-3; + } + size /= ipow(10,drop); + int sfx = (len-1)/3; + int digits = (sfx+1)*3 - len; + int64_t frac = ipow(10,digits); + int mant = size / frac; + int fraction = size - mant*frac; + sfx = *suffix[sfx]; + if( sfx && size_format == FILEBOX_SIZE_1000 ) sfx += 'a'-'A'; + if( digits ) + sprintf(string, "%d.%0*d%c", mant, digits, fraction, sfx); + else + sprintf(string, "%d%c", mant, sfx); + } + else { + sprintf(string, "%jd", size); + if( size_format == FILEBOX_SIZE_THOU ) + Units::punctuate(string); + } new_item = new BC_ListBoxItem(string, get_resources()->file_color); } else @@ -843,15 +882,11 @@ int BC_FileBox::create_tables() // Date entry if(!is_dir || 1) { - static const char *month_text[13] = { "Nul", - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" - }; - sprintf(string, - "%s %d, %d", - month_text[file_item->month], - file_item->day, - file_item->year); + struct tm mod_time; + localtime_r(&file_item->mtime, &mod_time); + sprintf(string, "%04d.%02d.%02d %02d:%02d:%02d", + mod_time.tm_year+1900, mod_time.tm_mon+1, mod_time.tm_mday, + mod_time.tm_hour, mod_time.tm_min, mod_time.tm_sec); new_item = new BC_ListBoxItem(string, get_resources()->file_color); } else @@ -873,6 +908,12 @@ int BC_FileBox::create_tables() } list_column[column_of_type(FILEBOX_EXTENSION)].append(new_item); // } + + if( !is_dir && select_all ) { + int k = list_column[0].size()-1; + for( int j=0; jset_selected(1); + } } return 0; @@ -889,25 +930,13 @@ int BC_FileBox::delete_tables() BC_Pixmap* BC_FileBox::get_icon(char *path, int is_dir) { - char *suffix = strrchr(path, '.'); + if( is_dir ) return icons[ICON_FOLDER]; int icon_type = ICON_UNKNOWN; - - if(is_dir) return icons[ICON_FOLDER]; - - if(suffix) - { - suffix++; - if(*suffix != 0) - { - for(int i = 0; i < TOTAL_SUFFIXES; i++) - { - if(!strcasecmp(suffix, BC_WindowBase::get_resources()->suffix_to_type[i].suffix)) - { - icon_type = BC_WindowBase::get_resources()->suffix_to_type[i].icon_type; - break; - } - } - } + char *suffix = strrchr(path, '.'); + if( suffix && *++suffix ) { + suffix_to_type_t *stp = &BC_WindowBase::get_resources()->suffix_to_type[0]; + while( stp->suffix && strcasecmp(stp->suffix, suffix) ) ++stp; + if( stp->icon_type ) icon_type = stp->icon_type; } return icons[icon_type]; @@ -933,7 +962,7 @@ int BC_FileBox::column_of_type(int type) -int BC_FileBox::refresh(int reset) +int BC_FileBox::refresh(int reset, int select_all) { fs->set_sort_order(sort_order); fs->set_sort_field(column_type[sort_column]); @@ -941,7 +970,7 @@ int BC_FileBox::refresh(int reset) fs->update(0); else fs->update_sort(); - create_tables(); + create_tables(select_all); listbox->set_master_column(column_of_type(FILEBOX_NAME), 0); listbox->update(list_column, column_titles, column_width, columns, reset>0 ? 0 : listbox->get_xposition(), @@ -1044,12 +1073,17 @@ int BC_FileBox::submit_dir(char *dir) int BC_FileBox::submit_file(const char *path, int use_this) { + char path1[BCTEXTLEN]; + strcpy(path1, path); + char *cp = strchr(path1,'\n'); + if( cp ) *cp = 0; + // Deactivate textbox to hide suggestions textbox->deactivate(); // If file wanted, take the current directory as the desired file. // If directory wanted, ignore it. - if(!path[0] && !want_directory) + if(!path1[0] && !want_directory) { // save complete path strcpy(this->current_path, directory); @@ -1063,9 +1097,9 @@ int BC_FileBox::submit_file(const char *path, int use_this) } // is a directory, change directories - if(fs->is_dir(path) && !use_this) + if(fs->is_dir(path1) && !use_this) { - fs->change_dir(path, 0); + fs->change_dir(path1, 0); refresh(1); directory_title->update(fs->get_current_dir()); strcpy(this->current_path, fs->get_current_dir()); @@ -1084,7 +1118,7 @@ int BC_FileBox::submit_file(const char *path, int use_this) // Is a file or desired directory. Quit the operation. { char path2[BCTEXTLEN]; - strcpy(path2, path); + strcpy(path2, path1); // save directory for defaults fs->extract_dir(directory, path2); @@ -1120,7 +1154,7 @@ void BC_FileBox::update_history() strcpy(path, directory); // enfore one trailing slash char *cp = path; - while( *cp ) ++cp; + while( *cp && *cp != '\n' ) ++cp; while( cp > path && *(cp-1) == '/' ) --cp; *cp++ = '/'; *cp = 0;