dvb chan tuner api upgrade, slip/ripple handle drag keyfrm fix, load menu tweaks
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / bcfilebox.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2017 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "bcdelete.h"
23 #include "bcfilebox.h"
24 #include "bclistboxitem.h"
25 #include "bcnewfolder.h"
26 #include "bcpixmap.h"
27 #include "bcrename.h"
28 #include "bcresources.h"
29 #include "bcsignals.h"
30 #include "bctitle.h"
31 #include "clip.h"
32 #include "condition.h"
33 #include "filesystem.h"
34 #include "keys.h"
35 #include "language.h"
36 #include "mutex.h"
37 #include <string.h>
38 #include <sys/stat.h>
39
40
41
42
43
44
45
46 BC_FileBoxRecent::BC_FileBoxRecent(BC_FileBox *filebox, int x, int y)
47  : BC_ListBox(x, y, 250,
48                 filebox->get_text_height(MEDIUMFONT) * FILEBOX_HISTORY_SIZE +
49                 BC_ScrollBar::get_span(SCROLL_HORIZ) +
50                 LISTBOX_MARGIN * 2, LISTBOX_TEXT, &filebox->recent_dirs,
51                 0, 0, 1, 0, 1)
52 {
53         this->filebox = filebox;
54         set_tooltip(_("Recent paths"));
55 }
56
57 int BC_FileBoxRecent::handle_event()
58 {
59         BC_ListBoxItem *selection = get_selection(0, 0);
60         if( selection != 0 ) {
61                 char *path = selection->get_text();
62                 filebox->submit_dir(path);
63         }
64         return 1;
65 }
66
67
68
69
70
71
72
73
74
75
76
77 BC_FileBoxListBox::BC_FileBoxListBox(int x, int y, BC_FileBox *filebox)
78  : BC_ListBox(x, y, filebox->get_listbox_w(), filebox->get_listbox_h(y),
79                 filebox->get_display_mode(), filebox->list_column,
80                 filebox->column_titles, filebox->column_width,
81                 filebox->columns, 0, 0,
82                 filebox->select_multiple ? LISTBOX_MULTIPLE : LISTBOX_SINGLE,
83                 ICON_LEFT, 0)
84 {
85         this->filebox = filebox;
86         set_sort_column(filebox->sort_column);
87         set_sort_order(filebox->sort_order);
88         set_allow_drag_column(1);
89 }
90
91 BC_FileBoxListBox::~BC_FileBoxListBox()
92 {
93 }
94
95 int BC_FileBoxListBox::handle_event()
96 {
97         filebox->submit_file(filebox->textbox->get_text());
98         return 1;
99 }
100
101 int BC_FileBoxListBox::selection_changed()
102 {
103         BC_ListBoxItem *item = get_selection(
104                 filebox->column_of_type(FILEBOX_NAME), 0);
105
106         if(item) {
107                 char path[BCTEXTLEN];
108                 strcpy(path, item->get_text());
109                 filebox->textbox->update(path);
110                 filebox->fs->extract_dir(filebox->directory, path);
111                 filebox->fs->extract_name(filebox->filename, path);
112                 filebox->fs->complete_path(path);
113                 strcpy(filebox->current_path, path);
114                 strcpy(filebox->submitted_path, path);
115         }
116         return 1;
117 }
118
119 int BC_FileBoxListBox::column_resize_event()
120 {
121         for(int i = 0; i < filebox->columns; i++)
122                 BC_WindowBase::get_resources()->filebox_columnwidth[i] =
123                         filebox->column_width[i] =
124                         get_column_width(i);
125         return 1;
126 }
127
128 int BC_FileBoxListBox::sort_order_event()
129 {
130         get_resources()->filebox_sortcolumn = filebox->sort_column = get_sort_column();
131         get_resources()->filebox_sortorder = filebox->sort_order = get_sort_order();
132         filebox->refresh(-1);
133         return 1;
134 }
135
136 int BC_FileBoxListBox::move_column_event()
137 {
138         filebox->move_column(get_from_column(), get_to_column());
139         return 1;
140 }
141
142 int BC_FileBoxListBox::evaluate_query(char *string)
143 {
144 // Search name column
145         ArrayList<BC_ListBoxItem*> *column =
146                 &filebox->list_column[filebox->column_of_type(FILEBOX_NAME)];
147 // Get current selection
148         int current_selection = get_selection_number(0, 0);
149
150 // Get best score in remaining items
151         int lowest_score = 0x7fffffff;
152         int best_item = -1;
153         if(current_selection < 0) current_selection = 0;
154 //      for(int i = current_selection + 1; i < column->size(); i++)
155         for(int i = current_selection; i < column->size(); i++)
156         {
157                 int len1 = strlen(string);
158                 int len2 = strlen(column->get(i)->get_text());
159                 int current_score = strncasecmp(string,
160                         column->get(i)->get_text(),
161                         MIN(len1, len2));
162 //printf(" %d i=%d %d %s %s\n", __LINE__, i, current_score, string, column->get(i)->get_text());
163
164                 if(abs(current_score) < lowest_score)
165                 {
166                         lowest_score = abs(current_score);
167                         best_item = i;
168                 }
169         }
170
171
172         return best_item;
173 }
174
175
176 BC_FileBoxTextBox::BC_FileBoxTextBox(int x, int y, BC_FileBox *filebox)
177  : BC_TextBox(x, y, filebox->get_w() - x - 20, 1,
178         filebox->want_directory ?  filebox->directory : filebox->filename)
179 {
180         this->filebox = filebox;
181 }
182
183 BC_FileBoxTextBox::~BC_FileBoxTextBox()
184 {
185 }
186
187 int BC_FileBoxTextBox::handle_event()
188 {
189         int result = 0;
190         if(get_keypress() != RETURN)
191         {
192                 result = calculate_suggestions(&filebox->list_column[0]);
193         }
194         return result;
195 }
196
197
198 BC_FileBoxDirectoryText::BC_FileBoxDirectoryText(int x, int y, int w, BC_FileBox *filebox)
199  : BC_TextBox(x, y, w, 1, filebox->fs->get_current_dir())
200 {
201         this->filebox = filebox;
202 }
203
204 int BC_FileBoxDirectoryText::handle_event()
205 {
206         const char *path = get_text();
207         if( !filebox->fs->is_dir(path) ) return 0;
208         const char *cp = path;
209         while( *cp ) ++cp;
210         if( cp > path && *--cp != '/' ) return 0;
211         char *file_path = FileSystem::basepath(path);
212         char *dir_path = FileSystem::basepath(filebox->directory);
213         int ret = !strcmp(file_path, dir_path) ? 0 : 1;
214         if( ret ) {
215                 strcpy(filebox->directory, file_path);
216                 filebox->update_history();
217                 filebox->fs->change_dir(file_path);
218                 filebox->refresh(1);
219         }
220         delete [] dir_path;
221         delete [] file_path;
222         return ret;
223 }
224
225
226 BC_FileBoxSearchText::BC_FileBoxSearchText(int x, int y, BC_FileBox *filebox)
227  : BC_TextBox(x, y, filebox->get_w() - x - 40, 1, "")
228 {
229         this->filebox = filebox;
230 }
231
232 int BC_FileBoxSearchText::handle_event()
233 {
234         filebox->refresh();
235         return 1;
236 }
237
238
239 BC_FileBoxFilterText::BC_FileBoxFilterText(int x, int y, BC_FileBox *filebox)
240  : BC_TextBox(x, y, filebox->get_w() - x - 50, 1, filebox->get_resources()->filebox_filter)
241 {
242         this->filebox = filebox;
243 }
244
245 int BC_FileBoxFilterText::handle_event()
246 {
247         filebox->update_filter(get_text());
248         return 1;
249 }
250
251
252 BC_FileBoxFilterMenu::BC_FileBoxFilterMenu(int x, int y, BC_FileBox *filebox)
253  : BC_ListBox(x, y, filebox->get_w() - 30, 120,
254         LISTBOX_TEXT, &filebox->filter_list, 0, 0, 1, 0, 1)
255 {
256         this->filebox = filebox;
257         set_tooltip(_("Change the filter"));
258 }
259
260 int BC_FileBoxFilterMenu::handle_event()
261 {
262         filebox->filter_text->update(
263                 get_selection(filebox->column_of_type(FILEBOX_NAME), 0)->get_text());
264         filebox->update_filter(
265                 get_selection(filebox->column_of_type(FILEBOX_NAME), 0)->get_text());
266         return 1;
267 }
268
269
270 BC_FileBoxSizeFormat::BC_FileBoxSizeFormat(int x, int y, BC_FileBox *file_box)
271  : BC_Button(x, y, &BC_WindowBase::get_resources()->
272                 filebox_szfmt_images[3*file_box->size_format])
273 {
274         this->file_box = file_box;
275         set_tooltip(_("Size numeric format"));
276 }
277 BC_FileBoxSizeFormat::~BC_FileBoxSizeFormat()
278 {
279 }
280
281 int BC_FileBoxSizeFormat::handle_event()
282 {
283         if( ++file_box->size_format > FILEBOX_SIZE_THOU )
284                 file_box->size_format = FILEBOX_SIZE_RAW;
285         BC_WindowBase::get_resources()->filebox_size_format = file_box->size_format;
286         set_images(&BC_WindowBase::get_resources()->
287                 filebox_szfmt_images[3*file_box->size_format]);
288         draw_face(0);
289         file_box->refresh(0);
290         return 1;
291 }
292
293
294 BC_FileBoxUseThis::BC_FileBoxUseThis(BC_FileBox *filebox)
295  : BC_Button(filebox->get_w() / 2 -
296                 BC_WindowBase::get_resources()->usethis_button_images[0]->get_w() / 2,
297         filebox->ok_button->get_y(),
298         BC_WindowBase::get_resources()->usethis_button_images)
299 {
300         this->filebox = filebox;
301         set_tooltip(_("Submit the directory"));
302 }
303
304 BC_FileBoxUseThis::~BC_FileBoxUseThis()
305 {
306 }
307
308 int BC_FileBoxUseThis::handle_event()
309 {
310 // printf("BC_FileBoxUseThis::handle_event %d '%s'\n",
311 // __LINE__,
312 // filebox->textbox->get_text());
313         filebox->submit_file(filebox->textbox->get_text(), 1);
314         return 1;
315 }
316
317
318 BC_FileBoxOK::BC_FileBoxOK(BC_FileBox *filebox)
319  : BC_OKButton(filebox,
320         !filebox->want_directory ?
321                 BC_WindowBase::get_resources()->ok_images :
322                 BC_WindowBase::get_resources()->filebox_descend_images)
323 {
324         this->filebox = filebox;
325         if(filebox->want_directory)
326                 set_tooltip(_("Descend directory"));
327         else
328                 set_tooltip(_("Submit the file"));
329 }
330
331 BC_FileBoxOK::~BC_FileBoxOK()
332 {
333 }
334
335 int BC_FileBoxOK::handle_event()
336 {
337 //printf("BC_FileBoxOK::handle_event %d\n", __LINE__);
338         const char *path = filebox->textbox->get_text();
339         if( *path ) filebox->submit_file(path);
340         return 1;
341 }
342
343 BC_FileBoxCancel::BC_FileBoxCancel(BC_FileBox *filebox)
344  : BC_CancelButton(filebox)
345 {
346         this->filebox = filebox;
347         set_tooltip(_("Cancel the operation"));
348 }
349
350 BC_FileBoxCancel::~BC_FileBoxCancel()
351 {
352 }
353
354 int BC_FileBoxCancel::handle_event()
355 {
356 //      filebox->submit_file(filebox->textbox->get_text());
357         filebox->newfolder_thread->interrupt();
358         filebox->set_done(1);
359         return 1;
360 }
361
362
363
364 BC_FileBoxText::BC_FileBoxText(int x, int y, BC_FileBox *filebox)
365  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_text_images)
366 {
367         this->filebox = filebox;
368         set_tooltip(_("Display text"));
369 }
370 int BC_FileBoxText::handle_event()
371 {
372         filebox->create_listbox(filebox->listbox->get_x(), filebox->listbox->get_y(), LISTBOX_TEXT);
373         filebox->listbox->show_window(1);
374         return 1;
375 }
376
377
378 BC_FileBoxIcons::BC_FileBoxIcons(int x, int y, BC_FileBox *filebox)
379  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_icons_images)
380 {
381         this->filebox = filebox;
382         set_tooltip(_("Display icons"));
383 }
384 int BC_FileBoxIcons::handle_event()
385 {
386         filebox->create_listbox(filebox->listbox->get_x(), filebox->listbox->get_y(), LISTBOX_ICONS);
387         filebox->listbox->show_window(1);
388         return 1;
389 }
390
391
392 BC_FileBoxNewfolder::BC_FileBoxNewfolder(int x, int y, BC_FileBox *filebox)
393  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_newfolder_images)
394 {
395         this->filebox = filebox;
396         set_tooltip(_("Create new folder"));
397 }
398 int BC_FileBoxNewfolder::handle_event()
399 {
400         filebox->newfolder_thread->start_new_folder();
401         return 1;
402 }
403
404
405 BC_FileBoxRename::BC_FileBoxRename(int x, int y, BC_FileBox *filebox)
406  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_rename_images)
407 {
408         this->filebox = filebox;
409         set_tooltip(_("Rename file"));
410 }
411 int BC_FileBoxRename::handle_event()
412 {
413         filebox->rename_thread->start_rename();
414         return 1;
415 }
416
417 BC_FileBoxUpdir::BC_FileBoxUpdir(int x, int y, BC_FileBox *filebox)
418  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_updir_images)
419 {
420         this->filebox = filebox;
421         set_tooltip(_("Up a directory"));
422 }
423 int BC_FileBoxUpdir::handle_event()
424 {
425 // Need a temp so submit_file can expand it
426         sprintf(string, "..");
427         filebox->submit_file(string);
428         return 1;
429 }
430
431 BC_FileBoxDelete::BC_FileBoxDelete(int x, int y, BC_FileBox *filebox)
432  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_delete_images)
433 {
434         this->filebox = filebox;
435         set_tooltip(_("Delete files"));
436 }
437 int BC_FileBoxDelete::handle_event()
438 {
439         filebox->unlock_window();
440         filebox->delete_thread->start();
441         filebox->lock_window("BC_FileBoxDelete::handle_event");
442         return 1;
443 }
444
445 BC_FileBoxReload::BC_FileBoxReload(int x, int y, BC_FileBox *filebox)
446  : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_reload_images)
447 {
448         this->filebox = filebox;
449         set_tooltip(_("Refresh"));
450 }
451 int BC_FileBoxReload::handle_event()
452 {
453         filebox->refresh();
454         return 1;
455 }
456
457
458
459 BC_FileBox::BC_FileBox(int x, int y, const char *init_path,
460                 const char *title, const char *caption, int show_all_files,
461                 int want_directory, int multiple_files, int h_padding)
462  : BC_Window(title, x, y,
463         BC_WindowBase::get_resources()->filebox_w,
464         BC_WindowBase::get_resources()->filebox_h,
465         400, 300, 1, 0, 1)
466 {
467         fs = new FileSystem;
468 //      if(want_directory)
469 //      {
470 //              fs->set_want_directory();
471 //              columns = DIRBOX_COLUMNS;
472 //              columns = FILEBOX_COLUMNS;
473 //      }
474 //      else
475         {
476                 columns = FILEBOX_COLUMNS;
477         }
478
479         list_column = new ArrayList<BC_ListBoxItem*>[columns];
480         column_type = new int[columns];
481         column_width = new int[columns];
482
483         filter_title = 0;
484         filter_text = 0;
485         filter_popup = 0;
486         usethis_button = 0;
487         size_format = BC_WindowBase::get_resources()->filebox_size_format;
488
489         strcpy(this->caption, caption);
490         strcpy(this->current_path, init_path);
491         strcpy(this->submitted_path, init_path);
492         select_multiple = multiple_files;
493         this->want_directory = want_directory;
494         if(show_all_files) fs->set_show_all();
495         fs->complete_path(this->current_path);
496         strcpy(this->submitted_path, this->current_path);
497         fs->extract_dir(directory, this->current_path);
498         fs->extract_name(filename, this->current_path);
499
500 // printf("BC_FileBox::BC_FileBox %d '%s' '%s' '%s'\n",
501 // __LINE__,
502 // this->submitted_path,
503 // directory,
504 // filename);
505
506 //      if(want_directory)
507 //      {
508 //              for(int i = 0; i < columns; i++)
509 //              {
510 //                      column_type[i] = get_resources()->dirbox_columntype[i];
511 //                      column_width[i] = get_resources()->dirbox_columnwidth[i];
512 //                      column_titles[i] = BC_FileBox::columntype_to_text(column_type[i]);
513 //              }
514 //              sort_column = get_resources()->dirbox_sortcolumn;
515 //              sort_order = get_resources()->dirbox_sortorder;
516 //      }
517 //      else
518         {
519                 for(int i = 0; i < columns; i++)
520                 {
521                         column_type[i] = get_resources()->filebox_columntype[i];
522                         column_width[i] = get_resources()->filebox_columnwidth[i];
523                         column_titles[i] = (char*)BC_FileBox::columntype_to_text(column_type[i]);
524                 }
525                 sort_column = get_resources()->filebox_sortcolumn;
526                 sort_order = get_resources()->filebox_sortorder;
527         }
528
529
530
531 // Test if current directory exists
532         if(!fs->is_dir(directory))
533         {
534                 sprintf(directory, "~");
535                 fs->complete_path(directory);
536                 strcpy(current_path,directory);
537                 filename[0] = 0;
538         }
539         fs->set_current_dir(directory);
540
541         if(h_padding == -1)
542         {
543                 h_padding = BC_WindowBase::get_resources()->ok_images[0]->get_h() -
544                         20;
545         }
546         this->h_padding = h_padding;
547         delete_thread = new BC_DeleteThread(this);
548         rename_thread = 0;
549 }
550
551 BC_FileBox::~BC_FileBox()
552 {
553 // this has to be destroyed before tables, because it can call for an update!
554         delete newfolder_thread;
555         delete fs;
556         delete_tables();
557         for(int i = 0; i < TOTAL_ICONS; i++)
558                 delete icons[i];
559         filter_list.remove_all_objects();
560         delete [] list_column;
561         delete [] column_type;
562         delete [] column_width;
563         delete delete_thread;
564         delete rename_thread;
565         recent_dirs.remove_all_objects();
566 }
567
568 void BC_FileBox::create_objects()
569 {
570         lock_window("BC_FileBox::create_objects");
571         int x = 10, y = 10;
572         BC_Resources *resources = BC_WindowBase::get_resources();
573         int directory_title_margin = MAX(20,
574                 resources->filebox_text_images[0]->get_h());
575
576 // Directories aren't filtered in FileSystem so skip this
577         if(!want_directory)
578         {
579                 filter_list.append(new BC_ListBoxItem("*"));
580                 filter_list.append(new BC_ListBoxItem("[*.mkv][*.webm]"));
581                 filter_list.append(new BC_ListBoxItem("[*.mp4][*.MP4]"));
582                 filter_list.append(new BC_ListBoxItem("[*.mp2][*.mp3][*.wav]"));
583                 filter_list.append(new BC_ListBoxItem("[*.avi][*.mpg][*.m2v][*.m1v][*.mov]"));
584                 filter_list.append(new BC_ListBoxItem("[*.jpg][*.JPG][*.png][*.gif][*.tiff]"));
585                 filter_list.append(new BC_ListBoxItem("*.xml"));
586                 fs->set_filter(get_resources()->filebox_filter);
587         }
588
589         create_icons();
590         create_tables(0);
591
592         add_subwindow(ok_button = new BC_FileBoxOK(this));
593         if(want_directory)
594                 add_subwindow(usethis_button = new BC_FileBoxUseThis(this));
595         add_subwindow(cancel_button = new BC_FileBoxCancel(this));
596
597         add_subwindow(new BC_Title(x, y, caption));
598
599         x = get_w() - resources->filebox_icons_images[0]->get_w() - 10;
600
601         add_subwindow(icon_button = new BC_FileBoxIcons(x, y, this));
602         x -= resources->filebox_text_images[0]->get_w() + 5;
603
604         add_subwindow(text_button = new BC_FileBoxText(x, y, this));
605         x -= resources->filebox_newfolder_images[0]->get_w() + 5;
606
607         add_subwindow(folder_button = new BC_FileBoxNewfolder(x, y, this));
608         x -= resources->filebox_delete_images[0]->get_w() + 5;
609
610         add_subwindow(rename_button = new BC_FileBoxRename(x, y, this));
611         x -= resources->filebox_delete_images[0]->get_w() + 5;
612
613         add_subwindow(delete_button = new BC_FileBoxDelete(x, y, this));
614         x -= resources->filebox_reload_images[0]->get_w() + 5;
615
616         add_subwindow(reload_button = new BC_FileBoxReload(x, y, this));
617         x -= resources->filebox_updir_images[0]->get_w() + 5;
618
619         add_subwindow(updir_button = new BC_FileBoxUpdir(x, y, this));
620         x -= resources->filebox_szfmt_images[0]->get_w() + 5;
621
622         add_subwindow(szfmt_button = new BC_FileBoxSizeFormat(x, y, this));
623
624         x = 10;
625         y += directory_title_margin + 3;
626
627         add_subwindow(recent_popup = new BC_FileBoxRecent(this, x, y));
628         BC_Title *dir_title;
629         add_subwindow(dir_title = new BC_Title(x, y, _("Directory:")));
630         int x1 = x + dir_title->get_w() + 10, w1 = get_w()-x1 - recent_popup->get_w()-20;
631         add_subwindow(directory_title = new BC_FileBoxDirectoryText(x1, y, w1, this));
632         x1 += directory_title->get_w() + 8;
633         recent_popup->reposition_window(x1, y, directory_title->get_w(), 200);
634
635         x = 10;
636         y += directory_title->get_h() + 5;
637
638         BC_Title *search_title;
639         add_subwindow(search_title = new BC_Title(x, y, _("Search:")));
640         x += search_title->get_w() + 10;
641         add_subwindow(search_text = new BC_FileBoxSearchText(x, y, this));
642
643         x = 10;
644         y += search_text->get_h() + 5;
645
646         int newest_id = 0, newest = -1;
647         for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++) {
648                 if( !resources->filebox_history[i].path[0] ) continue;
649                 if( resources->filebox_history[i].id > newest_id ) {
650                         newest_id = resources->filebox_history[i].id;
651                         newest = i;
652                 }
653         }
654         if( newest >= 0 ) {
655                 strcpy(directory, resources->filebox_history[newest].path);
656                 fs->change_dir(directory, 0);
657                 strcpy(directory, fs->get_current_dir());
658                 directory_title->update(fs->get_current_dir());
659         }
660         fs->set_sort_order(sort_order);
661         fs->set_sort_field(column_type[sort_column]);
662         fs->update(directory);
663
664 // Create recent dir list
665         create_history();
666         update_history();
667
668         listbox = 0;
669         create_listbox(x, y, get_display_mode());
670         y += listbox->get_h() + 10;
671         add_subwindow(file_title = new BC_Title(x, y, _("File:")));
672         x1 = x + file_title->get_w() + 10;
673         add_subwindow(textbox = new BC_FileBoxTextBox(x1, y, this));
674         y += textbox->get_h() + 10;
675
676         if(!want_directory) {
677                 add_subwindow(filter_title = new BC_Title(x, y, _("Specify filter:")));
678                 int x1 = x + filter_title->get_w() + 10;
679                 add_subwindow(filter_text = new BC_FileBoxFilterText(x1, y, this));
680                 add_subwindow(filter_popup =
681                         new BC_FileBoxFilterMenu(x1 + filter_text->get_w(), y, this));
682         }
683
684 // listbox has to be active because refresh might be called from newfolder_thread
685         listbox->activate();
686         newfolder_thread = new BC_NewFolderThread(this);
687
688         rename_thread = new BC_RenameThread(this);
689
690         refresh();
691         show_window();
692         unlock_window();
693 }
694
695 int BC_FileBox::get_listbox_w()
696 {
697         return get_w() - 20;
698 }
699
700 int BC_FileBox::get_listbox_h(int y)
701 {
702         int result = get_h() - y - h_padding - 10;
703         if(want_directory)
704                 result -= BC_WindowBase::get_resources()->dirbox_margin;
705         else
706                 result -= BC_WindowBase::get_resources()->filebox_margin;
707
708         return result;
709 }
710
711 int BC_FileBox::create_icons()
712 {
713         for(int i = 0; i < TOTAL_ICONS; i++)
714         {
715                 icons[i] = new BC_Pixmap(this,
716                         BC_WindowBase::get_resources()->type_to_icon[i],
717                         PIXMAP_ALPHA);
718         }
719         return 0;
720 }
721
722 int BC_FileBox::resize_event(int w, int h)
723 {
724         draw_background(0, 0, w, h);
725         flash(0);
726
727 // OK button handles resize event itself
728 //      ok_button->reposition_window(ok_button->get_x(),
729 //              h - (get_h() - ok_button->get_y()));
730 //      cancel_button->reposition_window(w - (get_w() - cancel_button->get_x()),
731 //              h - (get_h() - cancel_button->get_y()));
732         if(usethis_button)
733                 usethis_button->reposition_window(w / 2 - 50,
734                         h - (get_h() - usethis_button->get_y()));
735
736
737         if(filter_popup) filter_popup->reposition_window(w - (get_w() - filter_popup->get_x()),
738                 h - (get_h() - filter_popup->get_y()),
739                 w - 30,
740                 0);
741
742         if(filter_title) filter_title->reposition_window(filter_title->get_x(),
743                 h - (get_h() - filter_title->get_y()));
744         if(filter_text) filter_text->reposition_window(filter_text->get_x(),
745                 h - (get_h() - filter_text->get_y()),
746                 w - (get_w() - filter_text->get_w()),
747                 1);
748         directory_title->reposition_window(
749                 directory_title->get_x(), directory_title->get_y(),
750                 get_w()-directory_title->get_x() - recent_popup->get_w()-20, 1);
751         recent_popup->reposition_window(
752                 directory_title->get_x() + directory_title->get_w() + 8,
753                 directory_title->get_y(),
754                 directory_title->get_w() + recent_popup->get_w(), 200);
755         search_text->reposition_window(
756                 search_text->get_x(),
757                 search_text->get_y(),
758                 get_w() - search_text->get_x() -  40,
759                 1);
760         file_title->reposition_window(file_title->get_x(),
761                 h - (get_h() - file_title->get_y()));
762         textbox->reposition_window(textbox->get_x(),
763                 h - (get_h() - textbox->get_y()),
764                 w - (get_w() - textbox->get_w()),
765                 1);
766         listbox->reposition_window(listbox->get_x(),
767                 listbox->get_y(),
768                 w - (get_w() - listbox->get_w()),
769                 h - (get_h() - listbox->get_h()),
770                 0);
771         int dx = w - get_w();
772         icon_button->reposition_window(icon_button->get_x()+dx, icon_button->get_y());
773         text_button->reposition_window(text_button->get_x()+dx, text_button->get_y());
774         folder_button->reposition_window(folder_button->get_x()+dx, folder_button->get_y());
775         rename_button->reposition_window(rename_button->get_x()+dx, rename_button->get_y());
776         reload_button->reposition_window(reload_button->get_x()+dx, reload_button->get_y());
777         delete_button->reposition_window(delete_button->get_x()+dx, delete_button->get_y());
778         updir_button->reposition_window(updir_button->get_x()+dx, updir_button->get_y());
779         szfmt_button->reposition_window(szfmt_button->get_x()+dx, szfmt_button->get_y());
780         set_w(w);  set_h(h);
781         get_resources()->filebox_w = get_w();
782         get_resources()->filebox_h = get_h();
783         flush();
784         return 1;
785 }
786
787 int BC_FileBox::keypress_event()
788 {
789         switch(get_keypress()) {
790         case 'a':
791                 if( !ctrl_down() ) break;
792                 refresh(0, 1);
793                 return 1;
794         case 'z':
795                 if( !ctrl_down() ) break;
796                 refresh(0, 0);
797                 return 1;
798         case 'w':
799                 if( !ctrl_down() ) break;
800                 set_done(1);
801                 return 1;
802         }
803         return 0;
804 }
805
806 int BC_FileBox::close_event()
807 {
808         set_done(1);
809         return 1;
810 }
811
812 int BC_FileBox::handle_event()
813 {
814         return 0;
815 }
816
817 int BC_FileBox::extract_extension(char *out, const char *in)
818 {
819         *out = 0;
820         int i = strlen(in);
821         while( --i>=0 && in[i]!='.' );
822         if( i >= 0 ) strcpy(out, &in[++i]);
823         return 0;
824 }
825
826 static inline int64_t ipow(int m, int n)
827 {
828         int64_t v = 1;
829         for( int64_t vv=m; n>0; vv*=vv,n>>=1 ) if( n & 1 ) v *= vv;
830         return v;
831 }
832 static inline int ilen(int64_t v)
833 {
834         int len = 1;
835         while( len<16 && (v/=10)>0 ) ++len;
836         return len;
837 }
838
839 int BC_FileBox::create_tables(int select_all)
840 {
841         int preload_textbox = select_all;
842         delete_tables();
843         char string[BCTEXTLEN];
844         BC_ListBoxItem *new_item;
845
846         fs->set_sort_order(sort_order);
847         fs->set_sort_field(column_type[sort_column]);
848
849         for(int i = 0; i < fs->total_files(); i++)
850         {
851                 FileItem *file_item = fs->get_entry(i);
852                 const char *text = search_text->get_text();
853                 if( text && text[0] && !bstrcasestr(file_item->name, text) )
854                         continue;
855                 int is_dir = file_item->is_dir;
856                 BC_Pixmap* icon = get_icon(file_item->name, is_dir);
857
858 // Name entry
859                 new_item = new BC_ListBoxItem(file_item->name,
860                         icon,
861                         is_dir ? get_resources()->directory_color : get_resources()->file_color);
862                 if(is_dir) new_item->set_searchable(0);
863                 list_column[column_of_type(FILEBOX_NAME)].append(new_item);
864
865 // Size entry
866 //              if(!want_directory)
867 //              {
868                         if(!is_dir)
869                         {
870                                 if( preload_textbox ) {
871                                         preload_textbox = 0;
872                                         textbox->update(new_item->get_text());
873                                 }
874                                 int64_t size = file_item->size;
875                                 if( (size_format == FILEBOX_SIZE_1000 && size >= 1000) ||
876                                     (size_format == FILEBOX_SIZE_1024 && size >= 1024) ) {
877                                         static const char *suffix[] = { "", "K", "M", "G", "T", "P" };
878                                         if( size_format == FILEBOX_SIZE_1024 ) {
879                                                 static const long double kk = logl(1000.)/logl(1024.);
880                                                 size = expl(kk*logl((long double)size)) + 0.5;
881                                         }
882                                         int len = ilen(size), drop = len-3, round = 1;
883                                         if( round && drop > 0 ) { //round
884                                                 size += ipow(10,drop)/2;
885                                                 len = ilen(size);  drop = len-3;
886                                         }
887                                         size /= ipow(10,drop);
888                                         int sfx = (len-1)/3;
889                                         int digits = (sfx+1)*3 - len;
890                                         int64_t frac = ipow(10,digits);
891                                         int mant  = size / frac;
892                                         int fraction = size - mant*frac;
893                                         sfx = *suffix[sfx];
894                                         if( sfx && size_format == FILEBOX_SIZE_1000 ) sfx += 'a'-'A';
895                                         if( digits )
896                                                 sprintf(string, "%d.%0*d%c", mant, digits, fraction, sfx);
897                                         else
898                                                 sprintf(string, "%d%c", mant, sfx);
899                                 }
900                                 else {
901                                         sprintf(string, "%jd", size);
902                                         if( size_format == FILEBOX_SIZE_THOU )
903                                                 Units::punctuate(string);
904                                 }
905                                 new_item = new BC_ListBoxItem(string, get_resources()->file_color);
906                         }
907                         else
908                         {
909                                 new_item = new BC_ListBoxItem("", get_resources()->directory_color);
910                         }
911
912                         list_column[column_of_type(FILEBOX_SIZE)].append(new_item);
913 //              }
914
915 // Date entry
916                 if(!is_dir || 1)
917                 {
918                         struct tm mod_time;
919                         localtime_r(&file_item->mtime, &mod_time);
920                         sprintf(string, "%04d.%02d.%02d  %02d:%02d:%02d",
921                                 mod_time.tm_year+1900, mod_time.tm_mon+1, mod_time.tm_mday,
922                                 mod_time.tm_hour, mod_time.tm_min, mod_time.tm_sec);
923                         new_item = new BC_ListBoxItem(string, get_resources()->file_color);
924                 }
925                 else
926                 {
927                         new_item = new BC_ListBoxItem("", get_resources()->directory_color);
928                 }
929
930                 list_column[column_of_type(FILEBOX_DATE)].append(new_item);
931
932 // Extension entry
933 //              if(!want_directory)
934 //              {
935                         if(!is_dir) {
936                                 extract_extension(string, file_item->name);
937                                 new_item = new BC_ListBoxItem(string, get_resources()->file_color);
938                         }
939                         else {
940                                 new_item = new BC_ListBoxItem("", get_resources()->directory_color);
941                         }
942                         list_column[column_of_type(FILEBOX_EXTENSION)].append(new_item);
943 //              }
944
945                 if( !is_dir && select_all ) {
946                         int k = list_column[0].size()-1;
947                         for( int j=0; j<columns; ++j )
948                                 list_column[j][k]->set_selected(1);
949                 }
950         }
951
952         return 0;
953 }
954
955 int BC_FileBox::delete_tables()
956 {
957         for(int j = 0; j < columns; j++)
958         {
959                 list_column[j].remove_all_objects();
960         }
961         return 0;
962 }
963
964 BC_Pixmap* BC_FileBox::get_icon(char *path, int is_dir)
965 {
966         if( is_dir ) return icons[ICON_FOLDER];
967         int icon_type = ICON_UNKNOWN;
968         char *suffix = strrchr(path, '.');
969         if( suffix && *++suffix ) {
970                 suffix_to_type_t *stp = &BC_WindowBase::get_resources()->suffix_to_type[0];
971                 while( stp->suffix && strcasecmp(stp->suffix, suffix) ) ++stp;
972                 if( stp->icon_type ) icon_type = stp->icon_type;
973         }
974
975         return icons[icon_type];
976 }
977
978 const char* BC_FileBox::columntype_to_text(int type)
979 {
980         switch(type) {
981                 case FILEBOX_NAME: return FILEBOX_NAME_TEXT;
982                 case FILEBOX_SIZE: return FILEBOX_SIZE_TEXT;
983                 case FILEBOX_DATE: return FILEBOX_DATE_TEXT;
984                 case FILEBOX_EXTENSION: return FILEBOX_EXTENSION_TEXT;
985         }
986         return "";
987 }
988
989 int BC_FileBox::column_of_type(int type)
990 {
991         for(int i = 0; i < columns; i++)
992                 if(column_type[i] == type) return i;
993         return 0;
994 }
995
996
997
998 int BC_FileBox::refresh(int reset, int select_all)
999 {
1000         fs->set_sort_order(sort_order);
1001         fs->set_sort_field(column_type[sort_column]);
1002         if( reset >= 0 )
1003                 fs->update(0);
1004         else
1005                 fs->update_sort();
1006         create_tables(select_all);
1007         listbox->set_master_column(column_of_type(FILEBOX_NAME), 0);
1008         listbox->update(list_column, column_titles, column_width, columns,
1009                 reset>0 ? 0 : listbox->get_xposition(),
1010                 reset>0 ? 0 : listbox->get_yposition(),
1011                 -1, 1);
1012         return 0;
1013 }
1014
1015 int BC_FileBox::update_filter(const char *filter)
1016 {
1017         fs->set_filter(filter);
1018 //      fs->update(0);
1019         refresh();
1020         strcpy(get_resources()->filebox_filter, filter);
1021
1022         return 0;
1023 }
1024
1025
1026 void BC_FileBox::move_column(int src, int dst)
1027 {
1028         if(src != dst)
1029         {
1030                 ArrayList<BC_ListBoxItem*> *new_columns =
1031                         new ArrayList<BC_ListBoxItem*>[columns];
1032                 int *new_types = new int[columns];
1033                 int *new_widths = new int[columns];
1034
1035         // Fill in remaining columns with consecutive data
1036                 for(int out_column = 0, in_column = 0;
1037                         out_column < columns;
1038                         out_column++,
1039                         in_column++)
1040                 {
1041         // Copy destination column from src column
1042                         if(out_column == dst)
1043                         {
1044                                 for(int i = 0; i < list_column[src].total; i++)
1045                                 {
1046                                         new_columns[out_column].append(list_column[src].values[i]);
1047                                 }
1048                                 new_types[out_column] = column_type[src];
1049                                 new_widths[out_column] = column_width[src];
1050                                 in_column--;
1051                         }
1052                         else
1053                         {
1054         // Skip source column
1055                                 if(in_column == src) in_column++;
1056                                 for(int i = 0; i < list_column[src].total; i++)
1057                                 {
1058                                         new_columns[out_column].append(list_column[in_column].values[i]);
1059                                 }
1060                                 new_types[out_column] = column_type[in_column];
1061                                 new_widths[out_column] = column_width[in_column];
1062                         }
1063                 }
1064
1065         // Swap tables
1066                 delete [] list_column;
1067                 delete [] column_type;
1068                 delete [] column_width;
1069                 list_column = new_columns;
1070                 column_type = new_types;
1071                 column_width = new_widths;
1072
1073                 for(int i = 0; i < columns; i++)
1074                 {
1075                         get_resources()->filebox_columntype[i] = column_type[i];
1076                         get_resources()->filebox_columnwidth[i] = column_width[i];
1077                         column_titles[i] = (char*)BC_FileBox::columntype_to_text(column_type[i]);
1078                 }
1079         }
1080
1081         refresh();
1082 }
1083
1084
1085 int BC_FileBox::submit_dir(char *dir)
1086 {
1087         strcpy(directory, dir);
1088         fs->join_names(current_path, directory, filename);
1089
1090 // printf("BC_FileBox::submit_dir %d '%s' '%s' '%s'\n",
1091 // __LINE__,
1092 // current_path,
1093 // directory,
1094 // filename);
1095         strcpy(submitted_path, current_path);
1096         fs->change_dir(dir, 0);
1097         refresh(1);
1098         directory_title->update(fs->get_current_dir());
1099         if(want_directory)
1100                 textbox->update(fs->get_current_dir());
1101         else
1102                 textbox->update(filename);
1103         listbox->reset_query();
1104         return 0;
1105 }
1106
1107 int BC_FileBox::submit_file(const char *path, int use_this)
1108 {
1109         char path1[BCTEXTLEN];
1110         strcpy(path1, path);
1111         char *cp = strchr(path1,'\n');
1112         if( cp ) *cp = 0;
1113
1114 // Deactivate textbox to hide suggestions
1115         textbox->deactivate();
1116
1117 // If file wanted, take the current directory as the desired file.
1118 // If directory wanted, ignore it.
1119         if(!path1[0] && !want_directory)
1120         {
1121 // save complete path
1122                 strcpy(this->current_path, directory);
1123 // save complete path
1124                 strcpy(this->submitted_path, directory);
1125                 update_history();
1126 // Zero out filename
1127                 filename[0] = 0;
1128                 set_done(0);
1129                 return 0;
1130         }
1131
1132 // is a directory, change directories
1133         if(fs->is_dir(path1) && !use_this)
1134         {
1135                 fs->change_dir(path1, 0);
1136                 refresh(1);
1137                 directory_title->update(fs->get_current_dir());
1138                 strcpy(this->current_path, fs->get_current_dir());
1139                 strcpy(this->submitted_path, fs->get_current_dir());
1140                 strcpy(this->directory, fs->get_current_dir());
1141                 update_history();
1142                 filename[0] = 0;
1143                 if(want_directory)
1144                         textbox->update(fs->get_current_dir());
1145                 else
1146                         textbox->update("");
1147                 listbox->reset_query();
1148                 return 1;
1149         }
1150         else
1151 // Is a file or desired directory.  Quit the operation.
1152         {
1153                 char path2[BCTEXTLEN];
1154                 strcpy(path2, path1);
1155
1156 // save directory for defaults
1157                 fs->extract_dir(directory, path2);
1158
1159 // Just take the directory
1160                 if(want_directory)
1161                 {
1162                         filename[0] = 0;
1163                         strcpy(path2, directory);
1164                 }
1165                 else
1166 // Take the complete path
1167                 {
1168                         fs->extract_name(filename, path2);     // save filename
1169                 }
1170
1171                 fs->complete_path(path2);
1172                 strcpy(this->current_path, path2);          // save complete path
1173                 strcpy(this->submitted_path, path2);          // save complete path
1174                 update_history();
1175                 newfolder_thread->interrupt();
1176                 set_done(0);
1177                 return 0;
1178         }
1179         return 0;
1180 }
1181
1182 void BC_FileBox::update_history()
1183 {
1184 // Look for path already in history
1185         BC_Resources *resources = get_resources();
1186         char path[BCTEXTLEN];
1187         strcpy(path, directory);
1188 // enfore one trailing slash
1189         char *cp = path;
1190         while( *cp && *cp != '\n' ) ++cp;
1191         while( cp > path && *(cp-1) == '/' ) --cp;
1192         *cp++ = '/';  *cp = 0;
1193
1194 //      int new_slot = FILEBOX_HISTORY_SIZE - 1;
1195
1196         for(int i = FILEBOX_HISTORY_SIZE - 1; i >= 0; i--)
1197         {
1198                 if(resources->filebox_history[i].path[0] &&
1199                         !strcmp(resources->filebox_history[i].path, path))
1200                 {
1201 // Got matching path.
1202 // Update ID.
1203                         resources->filebox_history[i].id = resources->get_filebox_id();
1204                         return;
1205                 }
1206 // // Shift down from this point.
1207 //                      while(i > 0)
1208 //                      {
1209 //                              strcpy(resources->filebox_history[i],
1210 //                                      resources->filebox_history[i - 1]);
1211 //                              if(resources->filebox_history[i][0]) new_slot--;
1212 //                              i--;
1213 //                      }
1214 //                      break;
1215 //              }
1216 //              else
1217 //                      if(resources->filebox_history[i][0])
1218 //                              new_slot--;
1219 //              else
1220 //                      break;
1221         }
1222
1223 // Remove oldest entry if full
1224         if(resources->filebox_history[FILEBOX_HISTORY_SIZE - 1].path[0])
1225         {
1226                 int oldest_id = 0x7fffffff;
1227                 int oldest = 0;
1228                 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
1229                 {
1230                         if(resources->filebox_history[i].path[0] &&
1231                                 resources->filebox_history[i].id < oldest_id)
1232                         {
1233                                 oldest_id = resources->filebox_history[i].id;
1234                                 oldest = i;
1235                         }
1236                 }
1237
1238                 for(int i = oldest; i < FILEBOX_HISTORY_SIZE - 1; i++)
1239                 {
1240                         strcpy(resources->filebox_history[i].path,
1241                                 resources->filebox_history[i + 1].path);
1242                         resources->filebox_history[i].id =
1243                                 resources->filebox_history[i + 1].id;
1244                 }
1245         }
1246
1247 // Create new entry
1248         strcpy(resources->filebox_history[FILEBOX_HISTORY_SIZE - 1].path, path);
1249         resources->filebox_history[FILEBOX_HISTORY_SIZE - 1].id = resources->get_filebox_id();
1250
1251 // Alphabetize
1252         int done = 0;
1253         while(!done)
1254         {
1255                 done = 1;
1256                 for(int i = 1; i < FILEBOX_HISTORY_SIZE; i++)
1257                 {
1258                         if( (resources->filebox_history[i - 1].path[0] &&
1259                                 resources->filebox_history[i].path[0] &&
1260                                 strcasecmp(resources->filebox_history[i - 1].path,
1261                                         resources->filebox_history[i].path) > 0) ||
1262                                 (resources->filebox_history[i - 1].path[0] == 0 &&
1263                                         resources->filebox_history[i].path[0]) )
1264                         {
1265                                 done = 0;
1266                                 char temp[BCTEXTLEN];
1267                                 int id_temp;
1268                                 strcpy(temp, resources->filebox_history[i - 1].path);
1269                                 id_temp = resources->filebox_history[i - 1].id;
1270                                 strcpy(resources->filebox_history[i - 1].path,
1271                                         resources->filebox_history[i].path);
1272                                 resources->filebox_history[i - 1].id =
1273                                         resources->filebox_history[i].id;
1274                                 strcpy(resources->filebox_history[i].path, temp);
1275                                 resources->filebox_history[i].id = id_temp;
1276                         }
1277                 }
1278         }
1279
1280 //      if(new_slot < 0)
1281 //      {
1282 //              for(int i = FILEBOX_HISTORY_SIZE - 1; i > 0; i--)
1283 //              {
1284 //                      strcpy(resources->filebox_history[i],
1285 //                                      resources->filebox_history[i - 1]);
1286 //              }
1287 //              new_slot = 0;
1288 //      }
1289 //
1290 //      strcpy(resources->filebox_history[new_slot], path);
1291
1292         create_history();
1293         recent_popup->update(&recent_dirs, 0, 0, 1);
1294 }
1295
1296 void BC_FileBox::create_history()
1297 {
1298         BC_Resources *resources = get_resources();
1299         recent_dirs.remove_all_objects();
1300         for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++) {
1301                 if(resources->filebox_history[i].path[0]) {
1302                         recent_dirs.append(new BC_ListBoxItem(resources->filebox_history[i].path));
1303                 }
1304         }
1305 }
1306
1307
1308 int BC_FileBox::get_display_mode()
1309 {
1310         return top_level->get_resources()->filebox_mode;
1311 }
1312
1313 void BC_FileBox::create_listbox(int x, int y, int mode)
1314 {
1315         if(listbox && listbox->get_display_mode() != mode)
1316         {
1317                 delete listbox;
1318                 listbox = 0;
1319                 top_level->get_resources()->filebox_mode = mode;
1320         }
1321
1322         if(!listbox)
1323                 add_subwindow(listbox = new BC_FileBoxListBox(x, y, this));
1324 }
1325
1326 char* BC_FileBox::get_path(int selection)
1327 {
1328         if(selection == 0)
1329         {
1330                 return get_submitted_path();
1331         }
1332         else
1333         {
1334                 BC_ListBoxItem *item = listbox->get_selection(
1335                         column_of_type(FILEBOX_NAME), selection - 1);
1336                 if(item)
1337                 {
1338                         fs->join_names(string, directory, item->get_text());
1339                         return string;
1340                 }
1341         }
1342         return 0;
1343 }
1344
1345 char* BC_FileBox::get_submitted_path()
1346 {
1347         return submitted_path;
1348 }
1349
1350 char* BC_FileBox::get_current_path()
1351 {
1352 //printf("BC_FileBox::get_current_path 1 %s\n", current_path);
1353         return current_path;
1354 }
1355
1356 char* BC_FileBox::get_newfolder_title()
1357 {
1358         char *letter2 = strchr(title, ':');
1359         new_folder_title[0] = 0;
1360         if(letter2)
1361         {
1362                 memcpy(new_folder_title, title, letter2 - title);
1363                 new_folder_title[letter2 - title] = 0;
1364         }
1365
1366         strcat(new_folder_title, _(": New folder"));
1367
1368         return new_folder_title;
1369 }
1370
1371 char* BC_FileBox::get_rename_title()
1372 {
1373         char *letter2 = strchr(title, ':');
1374         new_folder_title[0] = 0;
1375         if(letter2)
1376         {
1377                 memcpy(new_folder_title, title, letter2 - title);
1378                 new_folder_title[letter2 - title] = 0;
1379         }
1380
1381         strcat(new_folder_title, _(": Rename"));
1382
1383         return new_folder_title;
1384 }
1385
1386 char* BC_FileBox::get_delete_title()
1387 {
1388         char *letter2 = strchr(title, ':');
1389         new_folder_title[0] = 0;
1390         if(letter2)
1391         {
1392                 memcpy(new_folder_title, title, letter2 - title);
1393                 new_folder_title[letter2 - title] = 0;
1394         }
1395
1396         strcat(new_folder_title, _(": Delete"));
1397
1398         return new_folder_title;
1399 }
1400
1401 void BC_FileBox::delete_files()
1402 {
1403 // Starting at 1 causes it to ignore what's in the textbox.
1404         int i = 1;
1405         char *path;
1406         FileSystem fs;
1407         while((path = get_path(i)))
1408         {
1409 // Not directory.  Remove it.
1410                 if(!fs.is_dir(path))
1411                 {
1412 //printf("BC_FileBox::delete_files: removing \"%s\"\n", path);
1413                         remove(path);
1414                 }
1415                 i++;
1416         }
1417         refresh();
1418 }
1419
1420 BC_Button* BC_FileBox::get_ok_button()
1421 {
1422         return ok_button;
1423 }
1424
1425 BC_Button* BC_FileBox::get_cancel_button()
1426 {
1427         return cancel_button;
1428 }
1429