r860: Merge 2.1:
[cinelerra_cv.git] / guicast / bcfilebox.C
blob7bb3f1f5f30f8e70b91fbc2d0e8be9e31338d705
1 #include "bcdelete.h"
2 #include "bcfilebox.h"
3 #include "bclistboxitem.h"
4 #include "bcnewfolder.h"
5 #include "bcpixmap.h"
6 #include "bcresources.h"
7 #include "bctitle.h"
8 #include "clip.h"
9 #include "condition.h"
10 #include "filesystem.h"
11 #include "language.h"
12 #include "mutex.h"
13 #include <string.h>
14 #include <sys/stat.h>
22 BC_FileBoxRecent::BC_FileBoxRecent(BC_FileBox *filebox, int x, int y)
23  : BC_ListBox(x, 
24         y, 
25         250, 
26         filebox->get_text_height(MEDIUMFONT) * FILEBOX_HISTORY_SIZE + 
27                 BC_ScrollBar::get_span(SCROLL_HORIZ) +
28                 LISTBOX_MARGIN * 2,
29         LISTBOX_TEXT, 
30         &filebox->recent_dirs, 
31         0, 
32         0, 
33         1, 
34         0, 
35         1)
37         this->filebox = filebox;
40 int BC_FileBoxRecent::handle_event()
42         if(get_selection(0, 0) >= 0)
43         {
44                 filebox->submit_dir(get_selection(0, 0)->get_text());
45         }
46         return 1;
59 BC_FileBoxListBox::BC_FileBoxListBox(int x, int y, BC_FileBox *filebox)
60  : BC_ListBox(x, 
61                         y, 
62                         filebox->get_listbox_w(), 
63                         filebox->get_listbox_h(y), 
64                         filebox->get_display_mode(), 
65                         filebox->list_column, 
66                         filebox->column_titles,
67                         filebox->column_width,
68                         filebox->columns,
69                         0,
70                         0,
71                         filebox->select_multiple ? LISTBOX_MULTIPLE : LISTBOX_SINGLE,
72                         ICON_LEFT,
73                         0)
74
75         this->filebox = filebox;
76         set_sort_column(filebox->sort_column);
77         set_sort_order(filebox->sort_order);
78         set_allow_drag_column(1);
81 BC_FileBoxListBox::~BC_FileBoxListBox()
85 int BC_FileBoxListBox::handle_event()
87         filebox->submit_file(filebox->textbox->get_text());
88         return 1;
91 int BC_FileBoxListBox::selection_changed()
93         BC_ListBoxItem *item = get_selection(
94                 filebox->column_of_type(FILEBOX_NAME), 0);
96         if(item)
97         {
98                 char path[BCTEXTLEN];
99                 strcpy(path, item->get_text());
100                 filebox->textbox->update(path);
101                 filebox->fs->extract_dir(filebox->directory, path);
102                 filebox->fs->extract_name(filebox->filename, path);
103                 filebox->fs->complete_path(path);
104                 strcpy(filebox->current_path, path);
105                 strcpy(filebox->submitted_path, path);
106         }
107         return 1;
110 int BC_FileBoxListBox::column_resize_event()
112         for(int i = 0; i < filebox->columns; i++)
113                 BC_WindowBase::get_resources()->filebox_columnwidth[i] = 
114                         filebox->column_width[i] = 
115                         get_column_width(i);
116         return 1;
119 int BC_FileBoxListBox::sort_order_event()
121         get_resources()->filebox_sortcolumn = filebox->sort_column = get_sort_column();
122         get_resources()->filebox_sortorder = filebox->sort_order = get_sort_order();
123         filebox->refresh();
124         return 1;
127 int BC_FileBoxListBox::move_column_event()
129         filebox->move_column(get_from_column(), get_to_column());
130         return 1;
133 int BC_FileBoxListBox::evaluate_query(int list_item, char *string)
135         ArrayList<BC_ListBoxItem*> *column = 
136                 &filebox->list_column[filebox->column_of_type(FILEBOX_NAME)];
137         return(column->values[list_item]->get_color() != get_resources()->directory_color && 
138                 strcmp(string, column->values[list_item]->get_text()) <= 0);
144 BC_FileBoxTextBox::BC_FileBoxTextBox(int x, int y, BC_FileBox *filebox)
145  : BC_TextBox(x, y, filebox->get_w() - 50, 1, filebox->filename)
147         this->filebox = filebox; 
150 BC_FileBoxTextBox::~BC_FileBoxTextBox()
154 int BC_FileBoxTextBox::handle_event()
156 //      filebox->handle_event();
157         return 1;
163 BC_FileBoxDirectoryText::BC_FileBoxDirectoryText(int x, int y, BC_FileBox *filebox)
164  : BC_TextBox(x, y, filebox->get_w() - 40, 1, filebox->fs->get_current_dir())
166         this->filebox = filebox;
169 int BC_FileBoxDirectoryText::handle_event()
171         char *path;
172         path = get_text();
173         // is a directory, change directories
174         if(!filebox->fs->is_dir(path))
175         {
176                 filebox->fs->change_dir(path);
177                 filebox->refresh();
178                 update(strcat(filebox->fs->get_current_dir(),"/"));
179         }
180         return 0;
187 BC_FileBoxFilterText::BC_FileBoxFilterText(int x, int y, BC_FileBox *filebox)
188  : BC_TextBox(x, y, filebox->get_w() - 50, 1, filebox->get_resources()->filebox_filter)
190         this->filebox = filebox;
193 int BC_FileBoxFilterText::handle_event()
195         filebox->update_filter(get_text());
196         return 0;
202 BC_FileBoxFilterMenu::BC_FileBoxFilterMenu(int x, int y, BC_FileBox *filebox)
203  : BC_ListBox(x, 
204         y, 
205         filebox->get_w() - 30, 
206         120, 
207         LISTBOX_TEXT, 
208         &filebox->filter_list, 
209         0, 
210         0, 
211         1, 
212         0, 
213         1)
215         this->filebox = filebox;
216         set_tooltip(_("Change the filter"));
219 int BC_FileBoxFilterMenu::handle_event()
221         filebox->filter_text->update(
222                 get_selection(filebox->column_of_type(FILEBOX_NAME), 0)->get_text());
223         filebox->update_filter(
224                 get_selection(filebox->column_of_type(FILEBOX_NAME), 0)->get_text());
225         return 0;
237 BC_FileBoxCancel::BC_FileBoxCancel(BC_FileBox *filebox)
238  : BC_CancelButton(filebox)
240         this->filebox = filebox;
241         set_tooltip(_("Cancel the operation"));
244 BC_FileBoxCancel::~BC_FileBoxCancel()
248 int BC_FileBoxCancel::handle_event()
250 //      filebox->submit_file(filebox->textbox->get_text());
251         filebox->newfolder_thread->interrupt();
252         filebox->set_done(1);
253         return 1;
262 BC_FileBoxUseThis::BC_FileBoxUseThis(BC_FileBox *filebox)
263  : BC_Button(filebox->get_w() / 2 - 
264                 BC_WindowBase::get_resources()->usethis_button_images[0]->get_w() / 2, 
265         filebox->ok_button->get_y(), 
266         BC_WindowBase::get_resources()->usethis_button_images)
268         this->filebox = filebox; 
269         set_tooltip(_("Submit the directory"));
272 BC_FileBoxUseThis::~BC_FileBoxUseThis()
276 int BC_FileBoxUseThis::handle_event()
278         filebox->submit_file(filebox->textbox->get_text(), 1);
279         return 1;
286 BC_FileBoxOK::BC_FileBoxOK(BC_FileBox *filebox)
287  : BC_OKButton(filebox, 
288         !filebox->want_directory ? 
289                 BC_WindowBase::get_resources()->ok_images :
290                 BC_WindowBase::get_resources()->filebox_descend_images)
292         this->filebox = filebox; 
293         if(filebox->want_directory)
294                 set_tooltip(_("Descend directory"));
295         else
296                 set_tooltip(_("Submit the file"));
299 BC_FileBoxOK::~BC_FileBoxOK()
303 int BC_FileBoxOK::handle_event()
305         filebox->submit_file(filebox->textbox->get_text());
306         return 1;
314 BC_FileBoxText::BC_FileBoxText(int x, int y, BC_FileBox *filebox)
315  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_text_images)
317         this->filebox = filebox; 
318         set_tooltip(_("Display text"));
320 int BC_FileBoxText::handle_event()
322         filebox->create_listbox(filebox->listbox->get_x(), filebox->listbox->get_y(), LISTBOX_TEXT);
323         return 1;
327 BC_FileBoxIcons::BC_FileBoxIcons(int x, int y, BC_FileBox *filebox)
328  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_icons_images)
330         this->filebox = filebox; 
331         set_tooltip(_("Display icons"));
333 int BC_FileBoxIcons::handle_event()
335         filebox->create_listbox(filebox->listbox->get_x(), filebox->listbox->get_y(), LISTBOX_ICONS);
336         return 1;
340 BC_FileBoxNewfolder::BC_FileBoxNewfolder(int x, int y, BC_FileBox *filebox)
341  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_newfolder_images)
343         this->filebox = filebox; 
344         set_tooltip(_("Create new folder"));
346 int BC_FileBoxNewfolder::handle_event()
348         filebox->newfolder_thread->start_new_folder();
349         return 1;
352 BC_FileBoxUpdir::BC_FileBoxUpdir(int x, int y, BC_FileBox *filebox)
353  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_updir_images)
355         this->filebox = filebox; 
356         set_tooltip(_("Up a directory"));
358 int BC_FileBoxUpdir::handle_event()
360 // Need a temp so submit_file can expand it
361         sprintf(string, _(".."));
362         filebox->submit_file(string);
363         return 1;
366 BC_FileBoxDelete::BC_FileBoxDelete(int x, int y, BC_FileBox *filebox)
367  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_delete_images)
369         this->filebox = filebox; 
370         set_tooltip(_("Delete files"));
372 int BC_FileBoxDelete::handle_event()
374         filebox->unlock_window();
375         filebox->delete_thread->start();
376         filebox->lock_window("BC_FileBoxDelete::handle_event");
377         return 1;
380 BC_FileBoxReload::BC_FileBoxReload(int x, int y, BC_FileBox *filebox)
381  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_reload_images)
383         this->filebox = filebox; 
384         set_tooltip(_("Refresh"));
386 int BC_FileBoxReload::handle_event()
388         filebox->refresh();
389         return 1;
401 BC_FileBox::BC_FileBox(int x, 
402                 int y, 
403                 char *init_path,
404                 char *title,
405                 char *caption,
406                 int show_all_files,
407                 int want_directory,
408                 int multiple_files,
409                 int h_padding)
410  : BC_Window(title, 
411         x,
412         y,
413         BC_WindowBase::get_resources()->filebox_w, 
414         BC_WindowBase::get_resources()->filebox_h, 
415         10, 
416         10,
417         1,
418         0,
419         1)
421         fs = new FileSystem;
422 //      if(want_directory)
423 //      {
424 //              fs->set_want_directory();
425 //              columns = DIRBOX_COLUMNS;
426 //              columns = FILEBOX_COLUMNS;
427 //      }
428 //      else
429         {
430                 columns = FILEBOX_COLUMNS;
431         }
433         list_column = new ArrayList<BC_ListBoxItem*>[columns];
434         column_type = new int[columns];
435         column_width = new int[columns];
437         filter_text = 0;
438         filter_popup = 0;
439         usethis_button = 0;
441         strcpy(this->caption, caption);
442         strcpy(this->current_path, init_path);
443         strcpy(this->submitted_path, init_path);
444         select_multiple = multiple_files;
445         this->want_directory = want_directory;
446         if(show_all_files) fs->set_show_all();
447         fs->complete_path(this->current_path);
448         fs->complete_path(this->submitted_path);
449         fs->extract_dir(directory, this->current_path);
450         fs->extract_name(filename, this->current_path);
453 //      if(want_directory)
454 //      {
455 //              for(int i = 0; i < columns; i++)
456 //              {
457 //                      column_type[i] = get_resources()->dirbox_columntype[i];
458 //                      column_width[i] = get_resources()->dirbox_columnwidth[i];
459 //                      column_titles[i] = BC_FileBox::columntype_to_text(column_type[i]);
460 //              }
461 //              sort_column = get_resources()->dirbox_sortcolumn;
462 //              sort_order = get_resources()->dirbox_sortorder;
463 //      }
464 //      else
465         {
466                 for(int i = 0; i < columns; i++)
467                 {
468                         column_type[i] = get_resources()->filebox_columntype[i];
469                         column_width[i] = get_resources()->filebox_columnwidth[i];
470                         column_titles[i] = BC_FileBox::columntype_to_text(column_type[i]);
471                 }
472                 sort_column = get_resources()->filebox_sortcolumn;
473                 sort_order = get_resources()->filebox_sortorder;
474         }
478 // Test directory
479         if(fs->update(directory))
480         {
481                 sprintf(this->current_path, "~");
482                 fs->complete_path(this->current_path);
483                 fs->update(this->current_path);
484                 strcpy(directory, fs->get_current_dir());
485                 sprintf(filename, "");
486         }
489         if(h_padding == -1)
490         {
491                 h_padding = BC_WindowBase::get_resources()->ok_images[0]->get_h() - 
492                         20;
493         }
494         this->h_padding = h_padding;
495         delete_thread = new BC_DeleteThread(this);
498 BC_FileBox::~BC_FileBox()
500 // this has to be destroyed before tables, because it can call for an update!
501         delete newfolder_thread;
502         delete fs;
503         delete_tables();
504         for(int i = 0; i < TOTAL_ICONS; i++)
505                 delete icons[i];
506         filter_list.remove_all_objects();
507         delete [] list_column;
508         delete [] column_type;
509         delete [] column_width;
510         delete delete_thread;
511         recent_dirs.remove_all_objects();
514 int BC_FileBox::create_objects()
516         int x = 10, y = 10;
517         BC_Resources *resources = BC_WindowBase::get_resources();
518         int directory_title_margin = MAX(20,
519                 resources->filebox_text_images[0]->get_h());
521 // Create recent dir list
522         create_history();
524 // Directories aren't filtered in FileSystem so skip this
525         if(!want_directory)
526         {
527                 filter_list.append(new BC_ListBoxItem("*"));
528                 filter_list.append(new BC_ListBoxItem("[*.ifo][*.vob]"));
529                 filter_list.append(new BC_ListBoxItem("[*.mp2][*.mp3][*.wav]"));
530                 filter_list.append(new BC_ListBoxItem("[*.avi][*.mpg][*.m2v][*.m1v][*.mov]"));
531                 filter_list.append(new BC_ListBoxItem("heroine*"));
532                 filter_list.append(new BC_ListBoxItem("*.xml"));
533                 fs->set_filter(get_resources()->filebox_filter);
534         }
536         fs->update(directory);
537         create_icons();
538         create_tables();
540         add_subwindow(ok_button = new BC_FileBoxOK(this));
541         if(want_directory)
542                 add_subwindow(usethis_button = new BC_FileBoxUseThis(this));
543         add_subwindow(cancel_button = new BC_FileBoxCancel(this));
545         add_subwindow(new BC_Title(x, y, caption));
547         x = get_w() - resources->filebox_icons_images[0]->get_w() - 10;
548         add_subwindow(icon_button = new BC_FileBoxIcons(x, y, this));
549         x -= resources->filebox_text_images[0]->get_w() + 5;
550         add_subwindow(text_button = new BC_FileBoxText(x, y, this));
551         x -= resources->filebox_newfolder_images[0]->get_w() + 5;
552         add_subwindow(folder_button = new BC_FileBoxNewfolder(x, y, this));
553         x -= resources->filebox_delete_images[0]->get_w() + 5;
554         add_subwindow(delete_button = new BC_FileBoxDelete(x, y, this));
555         x -= resources->filebox_reload_images[0]->get_w() + 5;
556         add_subwindow(reload_button = new BC_FileBoxReload(x, y, this));
557         x -= resources->filebox_updir_images[0]->get_w() + 5;
558         add_subwindow(updir_button = new BC_FileBoxUpdir(x, y, this));
560         x = 10;
561         y += directory_title_margin + 3;
563         add_subwindow(recent_popup = new BC_FileBoxRecent(this, 
564                 x, 
565                 y));
566         add_subwindow(directory_title = new BC_FileBoxDirectoryText(x, y, this));
567         directory_title->reposition_window(
568                 x,
569                 y,
570                 get_w() - recent_popup->get_w() -  20,
571                 1);
572         recent_popup->reposition_window(
573                 x + directory_title->get_w(),
574                 y,
575                 directory_title->get_w(),
576                 200);
578         x = 10;
579         y += directory_title->get_h() + 5;
580         listbox = 0;
582         create_listbox(x, y, get_display_mode());
583         y += listbox->get_h() + 10;
584         add_subwindow(textbox = new BC_FileBoxTextBox(x, y, this));
585         y += textbox->get_h() + 10;
588         if(!want_directory)
589         {
590                 add_subwindow(filter_text = new BC_FileBoxFilterText(x, y, this));
591                 add_subwindow(filter_popup = 
592                         new BC_FileBoxFilterMenu(x + filter_text->get_w(), y, this));;
593         }
595 // listbox has to be active because refresh might be called from newfolder_thread
596         listbox->activate();
597         newfolder_thread = new BC_NewFolderThread(this);
598         
599         show_window();
600         return 0;
603 int BC_FileBox::get_listbox_w()
605         return get_w() - 20;
608 int BC_FileBox::get_listbox_h(int y)
610         int result = get_h() - 
611                 y - 
612                 h_padding;
613         if(want_directory)
614                 result -= BC_WindowBase::get_resources()->dirbox_margin;
615         else
616                 result -= BC_WindowBase::get_resources()->filebox_margin;
618         return result;
621 int BC_FileBox::create_icons()
623         for(int i = 0; i < TOTAL_ICONS; i++)
624         {
625                 icons[i] = new BC_Pixmap(this, 
626                         BC_WindowBase::get_resources()->type_to_icon[i],
627                         PIXMAP_ALPHA);
628         }
629         return 0;
632 int BC_FileBox::resize_event(int w, int h)
634         draw_background(0, 0, w, h);
635         flash();
637 // OK button handles resize event itself
638 //      ok_button->reposition_window(ok_button->get_x(), 
639 //              h - (get_h() - ok_button->get_y()));
640 //      cancel_button->reposition_window(w - (get_w() - cancel_button->get_x()), 
641 //              h - (get_h() - cancel_button->get_y()));
642         if(usethis_button)
643                 usethis_button->reposition_window(w / 2 - 50, h - (get_h() - usethis_button->get_y()));
646         if(filter_popup) filter_popup->reposition_window(w - (get_w() - filter_popup->get_x()), 
647                 h - (get_h() - filter_popup->get_y()),
648                 w - 30);
651         if(filter_text) filter_text->reposition_window(filter_text->get_x(), 
652                 h - (get_h() - filter_text->get_y()),
653                 w - (get_w() - filter_text->get_w()),
654                 1);
655         directory_title->reposition_window(
656                 directory_title->get_x(),
657                 directory_title->get_y(),
658                 get_w() - recent_popup->get_w() -  20,
659                 1);
660         recent_popup->reposition_window(
661                 directory_title->get_x() + directory_title->get_w(),
662                 directory_title->get_y(),
663                 directory_title->get_w() + recent_popup->get_w(),
664                 recent_popup->get_h());
665         textbox->reposition_window(textbox->get_x(), 
666                 h - (get_h() - textbox->get_y()),
667                 w - (get_w() - textbox->get_w()),
668                 1);
669         listbox->reposition_window(listbox->get_x(),
670                 listbox->get_y(),
671                 w - (get_w() - listbox->get_w()),
672                 h - (get_h() - listbox->get_h()));
673         icon_button->reposition_window(w - (get_w() - icon_button->get_x()), 
674                 icon_button->get_y());
675         text_button->reposition_window(w - (get_w() - text_button->get_x()), 
676                 text_button->get_y());
677         folder_button->reposition_window(w - (get_w() - folder_button->get_x()), 
678                 folder_button->get_y());
679         reload_button->reposition_window(w - (get_w() - reload_button->get_x()),
680                 reload_button->get_y());
681         delete_button->reposition_window(w - (get_w() - delete_button->get_x()),
682                 delete_button->get_y());
683         updir_button->reposition_window(w - (get_w() - updir_button->get_x()), 
684                 updir_button->get_y());
685         set_w(w);
686         set_h(h);
687         get_resources()->filebox_w = get_w();
688         get_resources()->filebox_h = get_h();
689         return 1;
692 int BC_FileBox::keypress_event()
694         switch(get_keypress())
695         {
696                 case 'w':
697                         if(ctrl_down()) set_done(1);
698                         return 1;
699                         break;
700         }
701         return 0;
704 int BC_FileBox::close_event()
706         set_done(1);
707         return 1;
710 int BC_FileBox::handle_event()
712         return 0;
715 int BC_FileBox::extract_extension(char *out, const char *in)
717         int i;
719         for(i = strlen(in)-1; i > 0 && in[i] != '.'; i--)
720           {
721             ;
722           }
723         if(in[i] == '.') {
724           i++;
725           strcpy(out, &in[i]);
726         }
727         else
728           out[0] = '\0';
729         return 0;
732 int BC_FileBox::create_tables()
734         delete_tables();
735         char string[BCTEXTLEN];
736         BC_ListBoxItem *new_item;
738         fs->set_sort_order(sort_order);
739         fs->set_sort_field(column_type[sort_column]);
741 // Directory is entered before this from a random source
742         fs->update(0);
743         for(int i = 0; i < fs->total_files(); i++)
744         {
745                 FileItem *file_item = fs->get_entry(i);
746                 int is_dir = file_item->is_dir;
747                 BC_Pixmap* icon = get_icon(file_item->name, is_dir);
749 // Name entry
750                 new_item = new BC_ListBoxItem(file_item->name,
751                         icon, 
752                         is_dir ? get_resources()->directory_color : get_resources()->file_color);
753                 if(is_dir) new_item->set_searchable(0);
754                 list_column[column_of_type(FILEBOX_NAME)].append(new_item);
755         
756 // Size entry
757 //              if(!want_directory)
758 //              {
759                         if(!is_dir)
760                         {
761                                 sprintf(string, "%lld", file_item->size);
762                                 new_item = new BC_ListBoxItem(string, get_resources()->file_color);
763                         }
764                         else
765                         {
766                                 new_item = new BC_ListBoxItem("", get_resources()->directory_color);
767                         }
769                         list_column[column_of_type(FILEBOX_SIZE)].append(new_item);
770 //              }
772 // Date entry
773                 if(!is_dir || 1)
774                 {
775                         static char *month_text[13] = 
776                         {
777                                 "Null",
778                                 "Jan",
779                                 "Feb",
780                                 "Mar",
781                                 "Apr",
782                                 "May",
783                                 "Jun",
784                                 "Jul",
785                                 "Aug",
786                                 "Sep",
787                                 "Oct",
788                                 "Nov",
789                                 "Dec"
790                         };
791                         sprintf(string, 
792                                 "%s %d, %d", 
793                                 month_text[file_item->month],
794                                 file_item->day,
795                                 file_item->year);
796                         new_item = new BC_ListBoxItem(string, get_resources()->file_color);
797                 }
798                 else
799                 {
800                         new_item = new BC_ListBoxItem("", get_resources()->directory_color);
801                 }
803                 list_column[column_of_type(FILEBOX_DATE)].append(new_item);
805 // Extension entry
806                 if(!want_directory)
807                 {
808                         if(!is_dir)
809                         {
810                                 extract_extension(string, file_item->name);
811                                 new_item = new BC_ListBoxItem(string, get_resources()->file_color);
812                         }
813                         else
814                         {
815                                 new_item = new BC_ListBoxItem("", get_resources()->directory_color);
816                         }
817                         list_column[column_of_type(FILEBOX_EXTENSION)].append(new_item);
818                 }
819         }
821         return 0;
824 int BC_FileBox::delete_tables()
826         for(int j = 0; j < columns; j++)
827         {
828                 list_column[j].remove_all_objects();
829         }
830         return 0;
833 BC_Pixmap* BC_FileBox::get_icon(char *path, int is_dir)
835         char *suffix = strrchr(path, '.');
836         int icon_type = ICON_UNKNOWN;
838         if(is_dir) return icons[ICON_FOLDER];
840         if(suffix)
841         {
842                 suffix++;
843                 if(*suffix != 0)
844                 {
845                         for(int i = 0; i < TOTAL_SUFFIXES; i++)
846                         {
847                                 if(!strcasecmp(suffix, BC_WindowBase::get_resources()->suffix_to_type[i].suffix)) 
848                                 {
849                                         icon_type = BC_WindowBase::get_resources()->suffix_to_type[i].icon_type;
850                                         break;
851                                 }
852                         }
853                 }
854         }
856         return icons[icon_type];
859 char* BC_FileBox::columntype_to_text(int type)
861         switch(type)
862         {
863                 case FILEBOX_NAME:
864                         return FILEBOX_NAME_TEXT;
865                         break;
866                 case FILEBOX_SIZE:
867                         return FILEBOX_SIZE_TEXT;
868                         break;
869                 case FILEBOX_DATE:
870                         return FILEBOX_DATE_TEXT;
871                         break;
872                 case FILEBOX_EXTENSION:
873                         return FILEBOX_EXTENSION_TEXT;
874                         break; 
875         }
876         return "";
879 int BC_FileBox::column_of_type(int type)
881         for(int i = 0; i < columns; i++)
882                 if(column_type[i] == type) return i;
883         return 0;
888 int BC_FileBox::refresh()
890         create_tables();
891         listbox->set_master_column(column_of_type(FILEBOX_NAME), 0);
892         listbox->update(list_column, 
893                 column_titles, 
894                 column_width,
895                 columns, 
896                 0, 
897                 0,
898                 -1, 
899                 1);
901         return 0;
904 int BC_FileBox::update_filter(char *filter)
906         fs->set_filter(filter);
907         fs->update(0);
908         refresh();
909         strcpy(get_resources()->filebox_filter, filter);
911         return 0;
915 void BC_FileBox::move_column(int src, int dst)
917         ArrayList<BC_ListBoxItem*> *new_columns = 
918                 new ArrayList<BC_ListBoxItem*>[columns];
919         int *new_types = new int[columns];
920         int *new_widths = new int[columns];
922 // Fill in remaining columns with consecutive data
923         for(int out_column = 0, in_column = 0; 
924                 out_column < columns; 
925                 out_column++,
926                 in_column++)
927         {
928 // Copy destination column from src column
929                 if(out_column == dst)
930                 {
931                         for(int i = 0; i < list_column[src].total; i++)
932                         {
933                                 new_columns[out_column].append(list_column[src].values[i]);
934                         }
935                         new_types[out_column] = column_type[src];
936                         new_widths[out_column] = column_width[src];
937                         in_column--;
938                 }
939                 else
940                 {
941 // Skip source column
942                         if(in_column == src) in_column++;
943                         for(int i = 0; i < list_column[src].total; i++)
944                         {
945                                 new_columns[out_column].append(list_column[in_column].values[i]);
946                         }
947                         new_types[out_column] = column_type[in_column];
948                         new_widths[out_column] = column_width[in_column];
949                 }
950         }
952 // Swap tables
953         delete [] list_column;
954         delete [] column_type;
955         delete [] column_width;
956         list_column = new_columns;
957         column_type = new_types;
958         column_width = new_widths;
960         for(int i = 0; i < columns; i++)
961         {
962                 get_resources()->filebox_columntype[i] = column_type[i];
963                 get_resources()->filebox_columnwidth[i] = column_width[i];
964                 column_titles[i] = BC_FileBox::columntype_to_text(column_type[i]);
965         }
966         
968         refresh();
972 int BC_FileBox::submit_dir(char *dir)
974         strcpy(directory, dir);
975         fs->join_names(current_path, directory, filename);
976         strcpy(submitted_path, current_path);
977         fs->change_dir(dir);
978         refresh();
979         directory_title->update(fs->get_current_dir());
980         if(want_directory)
981                 textbox->update(fs->get_current_dir());
982         else
983                 textbox->update(filename);
984         listbox->reset_query();
985         return 0;
988 int BC_FileBox::submit_file(char *path, int use_this)
990 // blank.  
991 // If file wanted, take the current directory as the desired file.
992 // If directory wanted, ignore it.
993         if(!path[0] && !want_directory)
994         {
995 // save complete path
996                 strcpy(this->current_path, directory);
997 // save complete path
998                 strcpy(this->submitted_path, directory);
999                 update_history();
1000 // Zero out filename
1001                 filename[0] = 0;
1002                 set_done(0);
1003                 return 0;
1004         }
1006 // is a directory, change directories
1007         if(fs->is_dir(path) && !use_this)
1008         {
1009                 fs->change_dir(path);
1010                 refresh();
1011                 directory_title->update(fs->get_current_dir());
1012                 strcpy(this->current_path, fs->get_current_dir());
1013                 strcpy(this->submitted_path, fs->get_current_dir());
1014                 strcpy(this->directory, fs->get_current_dir());
1015                 filename[0] = 0;
1016                 if(want_directory)
1017                         textbox->update(fs->get_current_dir());
1018                 else
1019                         textbox->update("");
1020                 listbox->reset_query();
1021                 return 1;
1022         }
1023         else
1024 // Is a file or desired directory.  Quit the operation.
1025         {
1026 // save directory for defaults
1027                 fs->extract_dir(directory, path);     
1029 // Just take the directory
1030                 if(want_directory)
1031                 {
1032                         filename[0] = 0;
1033                         strcpy(path, directory);
1034                 }
1035                 else
1036 // Take the complete path
1037                 {
1038                         fs->extract_name(filename, path);     // save filename
1039                 }
1041                 fs->complete_path(path);
1042                 strcpy(this->current_path, path);          // save complete path
1043                 strcpy(this->submitted_path, path);          // save complete path
1044                 update_history();
1045                 newfolder_thread->interrupt();
1046                 set_done(0);
1047                 return 0;
1048         }
1049         return 0;
1052 void BC_FileBox::update_history()
1054 // Look for path already in history
1055         BC_Resources *resources = get_resources();
1056         int new_slot = FILEBOX_HISTORY_SIZE - 1;
1057         for(int i = FILEBOX_HISTORY_SIZE - 1; i >= 0; i--)
1058         {
1059                 if(!strcmp(resources->filebox_history[i], directory))
1060                 {
1061 // Shift down from this point
1062                         while(i > 0)
1063                         {
1064                                 strcpy(resources->filebox_history[i], 
1065                                         resources->filebox_history[i - 1]);
1066                                 if(resources->filebox_history[i][0]) new_slot--;
1067                                 i--;
1068                         }
1069                         break;
1070                 }
1071                 else
1072                         if(resources->filebox_history[i][0])
1073                                 new_slot--;
1074                 else
1075                         break;
1076         }
1078         if(new_slot < 0)
1079         {
1080                 for(int i = FILEBOX_HISTORY_SIZE - 1; i > 0; i--)
1081                 {
1082                         strcpy(resources->filebox_history[i], 
1083                                         resources->filebox_history[i - 1]);
1084                 }
1085                 new_slot = 0;
1086         }
1087         strcpy(resources->filebox_history[new_slot], directory);
1089         create_history();
1090         recent_popup->update(&recent_dirs,
1091                 0,
1092                 0,
1093                 1);
1096 void BC_FileBox::create_history()
1098         BC_Resources *resources = get_resources();
1099         recent_dirs.remove_all_objects();
1100         for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
1101         {
1102                 if(resources->filebox_history[i][0])
1103                 {
1104                         recent_dirs.append(new BC_ListBoxItem(resources->filebox_history[i]));
1105                 }
1106         }
1110 int BC_FileBox::get_display_mode()
1112         return top_level->get_resources()->filebox_mode;
1115 void BC_FileBox::create_listbox(int x, int y, int mode)
1117         if(listbox && listbox->get_display_mode() != mode)
1118         {
1119                 delete listbox;
1120                 listbox = 0;
1121                 top_level->get_resources()->filebox_mode = mode;
1122         }
1124         if(!listbox)
1125                 add_subwindow(listbox = new BC_FileBoxListBox(x, y, this));
1128 char* BC_FileBox::get_path(int selection)
1130         if(selection == 0)
1131         {
1132                 return get_submitted_path();
1133         }
1134         else
1135         {
1136                 BC_ListBoxItem *item = listbox->get_selection(
1137                         column_of_type(FILEBOX_NAME), selection - 1);
1138                 if(item) 
1139                 {
1140                         fs->join_names(string, directory, item->get_text());
1141                         return string;
1142                 }
1143         }
1144         return 0;
1147 char* BC_FileBox::get_submitted_path()
1149         return submitted_path;
1152 char* BC_FileBox::get_current_path()
1154 //printf("BC_FileBox::get_current_path 1 %s\n", current_path);
1155         return current_path;
1158 char* BC_FileBox::get_newfolder_title()
1160         char *letter2 = strchr(title, ':');
1161         new_folder_title[0] = 0;
1162         if(letter2)
1163         {
1164                 memcpy(new_folder_title, title, letter2 - title);
1165                 new_folder_title[letter2 - title] = 0;
1166         }
1168         strcat(new_folder_title, _(": New folder"));
1170         return new_folder_title;
1173 char* BC_FileBox::get_delete_title()
1175         char *letter2 = strchr(title, ':');
1176         new_folder_title[0] = 0;
1177         if(letter2)
1178         {
1179                 memcpy(new_folder_title, title, letter2 - title);
1180                 new_folder_title[letter2 - title] = 0;
1181         }
1183         strcat(new_folder_title, _(": Delete"));
1185         return new_folder_title;
1188 void BC_FileBox::delete_files()
1190 // Starting at 1 causes it to ignore what's in the textbox.
1191         int i = 1;
1192         char *path;
1193         FileSystem fs;
1194         while((path = get_path(i)))
1195         {
1196 // Not directory.  Remove it.
1197                 if(!fs.is_dir(path))
1198                 {
1199 printf("BC_FileBox::delete_files: removing \"%s\"\n", path);
1200                         remove(path);
1201                 }
1202                 i++;
1203         }
1204         refresh();
1207 BC_Button* BC_FileBox::get_ok_button()
1209         return ok_button;
1212 BC_Button* BC_FileBox::get_cancel_button()
1214         return cancel_button;