4 * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "bcfilebox.h"
24 #include "bclistboxitem.h"
25 #include "bcnewfolder.h"
28 #include "bcresources.h"
29 #include "bcsignals.h"
32 #include "condition.h"
33 #include "filesystem.h"
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,
53 this->filebox = filebox;
56 int BC_FileBoxRecent::handle_event()
58 BC_ListBoxItem *selection = get_selection(0, 0);
59 if( selection != 0 ) {
60 char *path = selection->get_text();
61 filebox->submit_dir(path);
76 BC_FileBoxListBox::BC_FileBoxListBox(int x, int y, BC_FileBox *filebox)
77 : BC_ListBox(x, y, filebox->get_listbox_w(), filebox->get_listbox_h(y),
78 filebox->get_display_mode(), filebox->list_column,
79 filebox->column_titles, filebox->column_width,
80 filebox->columns, 0, 0,
81 filebox->select_multiple ? LISTBOX_MULTIPLE : LISTBOX_SINGLE,
84 this->filebox = filebox;
85 set_sort_column(filebox->sort_column);
86 set_sort_order(filebox->sort_order);
87 set_allow_drag_column(1);
90 BC_FileBoxListBox::~BC_FileBoxListBox()
94 int BC_FileBoxListBox::handle_event()
96 filebox->submit_file(filebox->textbox->get_text());
100 int BC_FileBoxListBox::selection_changed()
102 BC_ListBoxItem *item = get_selection(
103 filebox->column_of_type(FILEBOX_NAME), 0);
106 char path[BCTEXTLEN];
107 strcpy(path, item->get_text());
108 filebox->textbox->update(path);
109 filebox->fs->extract_dir(filebox->directory, path);
110 filebox->fs->extract_name(filebox->filename, path);
111 filebox->fs->complete_path(path);
112 strcpy(filebox->current_path, path);
113 strcpy(filebox->submitted_path, path);
118 int BC_FileBoxListBox::column_resize_event()
120 for(int i = 0; i < filebox->columns; i++)
121 BC_WindowBase::get_resources()->filebox_columnwidth[i] =
122 filebox->column_width[i] =
127 int BC_FileBoxListBox::sort_order_event()
129 get_resources()->filebox_sortcolumn = filebox->sort_column = get_sort_column();
130 get_resources()->filebox_sortorder = filebox->sort_order = get_sort_order();
131 filebox->refresh(-1);
135 int BC_FileBoxListBox::move_column_event()
137 filebox->move_column(get_from_column(), get_to_column());
141 int BC_FileBoxListBox::evaluate_query(char *string)
143 // Search name column
144 ArrayList<BC_ListBoxItem*> *column =
145 &filebox->list_column[filebox->column_of_type(FILEBOX_NAME)];
146 // Get current selection
147 int current_selection = get_selection_number(0, 0);
149 // Get best score in remaining items
150 int lowest_score = 0x7fffffff;
152 if(current_selection < 0) current_selection = 0;
153 // for(int i = current_selection + 1; i < column->size(); i++)
154 for(int i = current_selection; i < column->size(); i++)
156 int len1 = strlen(string);
157 int len2 = strlen(column->get(i)->get_text());
158 int current_score = strncasecmp(string,
159 column->get(i)->get_text(),
161 //printf(" %d i=%d %d %s %s\n", __LINE__, i, current_score, string, column->get(i)->get_text());
163 if(abs(current_score) < lowest_score)
165 lowest_score = abs(current_score);
177 BC_FileBoxTextBox::BC_FileBoxTextBox(int x, int y, BC_FileBox *filebox)
178 : BC_TextBox(x, y, filebox->get_w() - 20, 1,
179 filebox->want_directory ? filebox->directory : filebox->filename)
181 this->filebox = filebox;
184 BC_FileBoxTextBox::~BC_FileBoxTextBox()
191 int BC_FileBoxTextBox::handle_event()
194 if(get_keypress() != RETURN)
196 result = calculate_suggestions(&filebox->list_column[0]);
204 BC_FileBoxDirectoryText::BC_FileBoxDirectoryText(int x, int y, BC_FileBox *filebox)
205 : BC_TextBox(x, y, filebox->get_w() - 40, 1, filebox->fs->get_current_dir())
207 this->filebox = filebox;
210 int BC_FileBoxDirectoryText::handle_event()
212 const char *path = get_text();
213 if( !filebox->fs->is_dir(path) ) return 0;
214 const char *cp = path;
216 if( cp > path && *--cp != '/' ) return 0;
217 char *file_path = FileSystem::basepath(path);
218 char *dir_path = FileSystem::basepath(filebox->directory);
219 int ret = !strcmp(file_path, dir_path) ? 0 : 1;
221 strcpy(filebox->directory, file_path);
222 filebox->update_history();
223 filebox->fs->change_dir(file_path);
235 BC_FileBoxFilterText::BC_FileBoxFilterText(int x, int y, BC_FileBox *filebox)
236 : BC_TextBox(x, y, filebox->get_w() - 50, 1, filebox->get_resources()->filebox_filter)
238 this->filebox = filebox;
241 int BC_FileBoxFilterText::handle_event()
243 filebox->update_filter(get_text());
250 BC_FileBoxFilterMenu::BC_FileBoxFilterMenu(int x, int y, BC_FileBox *filebox)
253 filebox->get_w() - 30,
256 &filebox->filter_list,
263 this->filebox = filebox;
264 set_tooltip(_("Change the filter"));
267 int BC_FileBoxFilterMenu::handle_event()
269 filebox->filter_text->update(
270 get_selection(filebox->column_of_type(FILEBOX_NAME), 0)->get_text());
271 filebox->update_filter(
272 get_selection(filebox->column_of_type(FILEBOX_NAME), 0)->get_text());
285 BC_FileBoxCancel::BC_FileBoxCancel(BC_FileBox *filebox)
286 : BC_CancelButton(filebox)
288 this->filebox = filebox;
289 set_tooltip(_("Cancel the operation"));
292 BC_FileBoxCancel::~BC_FileBoxCancel()
296 int BC_FileBoxCancel::handle_event()
298 // filebox->submit_file(filebox->textbox->get_text());
299 filebox->newfolder_thread->interrupt();
300 filebox->set_done(1);
310 BC_FileBoxUseThis::BC_FileBoxUseThis(BC_FileBox *filebox)
311 : BC_Button(filebox->get_w() / 2 -
312 BC_WindowBase::get_resources()->usethis_button_images[0]->get_w() / 2,
313 filebox->ok_button->get_y(),
314 BC_WindowBase::get_resources()->usethis_button_images)
316 this->filebox = filebox;
317 set_tooltip(_("Submit the directory"));
320 BC_FileBoxUseThis::~BC_FileBoxUseThis()
324 int BC_FileBoxUseThis::handle_event()
326 // printf("BC_FileBoxUseThis::handle_event %d '%s'\n",
328 // filebox->textbox->get_text());
329 filebox->submit_file(filebox->textbox->get_text(), 1);
337 BC_FileBoxOK::BC_FileBoxOK(BC_FileBox *filebox)
338 : BC_OKButton(filebox,
339 !filebox->want_directory ?
340 BC_WindowBase::get_resources()->ok_images :
341 BC_WindowBase::get_resources()->filebox_descend_images)
343 this->filebox = filebox;
344 if(filebox->want_directory)
345 set_tooltip(_("Descend directory"));
347 set_tooltip(_("Submit the file"));
350 BC_FileBoxOK::~BC_FileBoxOK()
354 int BC_FileBoxOK::handle_event()
356 //printf("BC_FileBoxOK::handle_event %d\n", __LINE__);
357 const char *path = filebox->textbox->get_text();
358 if( *path ) filebox->submit_file(path);
363 BC_FileBoxText::BC_FileBoxText(int x, int y, BC_FileBox *filebox)
364 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_text_images)
366 this->filebox = filebox;
367 set_tooltip(_("Display text"));
369 int BC_FileBoxText::handle_event()
371 filebox->create_listbox(filebox->listbox->get_x(), filebox->listbox->get_y(), LISTBOX_TEXT);
372 filebox->listbox->show_window(1);
377 BC_FileBoxIcons::BC_FileBoxIcons(int x, int y, BC_FileBox *filebox)
378 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_icons_images)
380 this->filebox = filebox;
381 set_tooltip(_("Display icons"));
383 int BC_FileBoxIcons::handle_event()
385 filebox->create_listbox(filebox->listbox->get_x(), filebox->listbox->get_y(), LISTBOX_ICONS);
386 filebox->listbox->show_window(1);
391 BC_FileBoxNewfolder::BC_FileBoxNewfolder(int x, int y, BC_FileBox *filebox)
392 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_newfolder_images)
394 this->filebox = filebox;
395 set_tooltip(_("Create new folder"));
397 int BC_FileBoxNewfolder::handle_event()
399 filebox->newfolder_thread->start_new_folder();
404 BC_FileBoxRename::BC_FileBoxRename(int x, int y, BC_FileBox *filebox)
405 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_rename_images)
407 this->filebox = filebox;
408 set_tooltip(_("Rename file"));
410 int BC_FileBoxRename::handle_event()
412 filebox->rename_thread->start_rename();
416 BC_FileBoxUpdir::BC_FileBoxUpdir(int x, int y, BC_FileBox *filebox)
417 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_updir_images)
419 this->filebox = filebox;
420 set_tooltip(_("Up a directory"));
422 int BC_FileBoxUpdir::handle_event()
424 // Need a temp so submit_file can expand it
425 sprintf(string, "..");
426 filebox->submit_file(string);
430 BC_FileBoxDelete::BC_FileBoxDelete(int x, int y, BC_FileBox *filebox)
431 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_delete_images)
433 this->filebox = filebox;
434 set_tooltip(_("Delete files"));
436 int BC_FileBoxDelete::handle_event()
438 filebox->unlock_window();
439 filebox->delete_thread->start();
440 filebox->lock_window("BC_FileBoxDelete::handle_event");
444 BC_FileBoxReload::BC_FileBoxReload(int x, int y, BC_FileBox *filebox)
445 : BC_Button(x, y, BC_WindowBase::get_resources()->filebox_reload_images)
447 this->filebox = filebox;
448 set_tooltip(_("Refresh"));
450 int BC_FileBoxReload::handle_event()
465 BC_FileBox::BC_FileBox(int x, int y, const char *init_path,
466 const char *title, const char *caption, int show_all_files,
467 int want_directory, int multiple_files, int h_padding)
468 : BC_Window(title, x, y,
469 BC_WindowBase::get_resources()->filebox_w,
470 BC_WindowBase::get_resources()->filebox_h,
474 // if(want_directory)
476 // fs->set_want_directory();
477 // columns = DIRBOX_COLUMNS;
478 // columns = FILEBOX_COLUMNS;
482 columns = FILEBOX_COLUMNS;
485 list_column = new ArrayList<BC_ListBoxItem*>[columns];
486 column_type = new int[columns];
487 column_width = new int[columns];
493 strcpy(this->caption, caption);
494 strcpy(this->current_path, init_path);
495 strcpy(this->submitted_path, init_path);
496 select_multiple = multiple_files;
497 this->want_directory = want_directory;
498 if(show_all_files) fs->set_show_all();
499 fs->complete_path(this->current_path);
500 strcpy(this->submitted_path, this->current_path);
501 fs->extract_dir(directory, this->current_path);
502 fs->extract_name(filename, this->current_path);
504 // printf("BC_FileBox::BC_FileBox %d '%s' '%s' '%s'\n",
506 // this->submitted_path,
510 // if(want_directory)
512 // for(int i = 0; i < columns; i++)
514 // column_type[i] = get_resources()->dirbox_columntype[i];
515 // column_width[i] = get_resources()->dirbox_columnwidth[i];
516 // column_titles[i] = BC_FileBox::columntype_to_text(column_type[i]);
518 // sort_column = get_resources()->dirbox_sortcolumn;
519 // sort_order = get_resources()->dirbox_sortorder;
523 for(int i = 0; i < columns; i++)
525 column_type[i] = get_resources()->filebox_columntype[i];
526 column_width[i] = get_resources()->filebox_columnwidth[i];
527 column_titles[i] = (char*)BC_FileBox::columntype_to_text(column_type[i]);
529 sort_column = get_resources()->filebox_sortcolumn;
530 sort_order = get_resources()->filebox_sortorder;
535 // Test if current directory exists
536 if(!fs->is_dir(directory))
538 sprintf(directory, "~");
539 fs->complete_path(directory);
540 strcpy(current_path,directory);
543 fs->set_current_dir(directory);
547 h_padding = BC_WindowBase::get_resources()->ok_images[0]->get_h() -
550 this->h_padding = h_padding;
551 delete_thread = new BC_DeleteThread(this);
555 BC_FileBox::~BC_FileBox()
557 // this has to be destroyed before tables, because it can call for an update!
558 delete newfolder_thread;
561 for(int i = 0; i < TOTAL_ICONS; i++)
563 filter_list.remove_all_objects();
564 delete [] list_column;
565 delete [] column_type;
566 delete [] column_width;
567 delete delete_thread;
568 delete rename_thread;
569 recent_dirs.remove_all_objects();
572 void BC_FileBox::create_objects()
575 BC_Resources *resources = BC_WindowBase::get_resources();
576 int directory_title_margin = MAX(20,
577 resources->filebox_text_images[0]->get_h());
579 // Directories aren't filtered in FileSystem so skip this
582 filter_list.append(new BC_ListBoxItem("*"));
583 filter_list.append(new BC_ListBoxItem("[*.mkv]"));
584 filter_list.append(new BC_ListBoxItem("[*.mp4]"));
585 filter_list.append(new BC_ListBoxItem("[*.mp2][*.mp3][*.wav]"));
586 filter_list.append(new BC_ListBoxItem("[*.avi][*.mpg][*.m2v][*.m1v][*.mov]"));
587 filter_list.append(new BC_ListBoxItem("*.xml"));
588 fs->set_filter(get_resources()->filebox_filter);
594 add_subwindow(ok_button = new BC_FileBoxOK(this));
596 add_subwindow(usethis_button = new BC_FileBoxUseThis(this));
597 add_subwindow(cancel_button = new BC_FileBoxCancel(this));
599 add_subwindow(new BC_Title(x, y, caption));
601 x = get_w() - resources->filebox_icons_images[0]->get_w() - 10;
603 add_subwindow(icon_button = new BC_FileBoxIcons(x, y, this));
604 x -= resources->filebox_text_images[0]->get_w() + 5;
606 add_subwindow(text_button = new BC_FileBoxText(x, y, this));
607 x -= resources->filebox_newfolder_images[0]->get_w() + 5;
609 add_subwindow(folder_button = new BC_FileBoxNewfolder(x, y, this));
610 x -= resources->filebox_delete_images[0]->get_w() + 5;
612 add_subwindow(rename_button = new BC_FileBoxRename(x, y, this));
613 x -= resources->filebox_delete_images[0]->get_w() + 5;
615 add_subwindow(delete_button = new BC_FileBoxDelete(x, y, this));
616 x -= resources->filebox_reload_images[0]->get_w() + 5;
618 add_subwindow(reload_button = new BC_FileBoxReload(x, y, this));
619 x -= resources->filebox_updir_images[0]->get_w() + 5;
621 add_subwindow(updir_button = new BC_FileBoxUpdir(x, y, this));
624 y += directory_title_margin + 3;
626 add_subwindow(recent_popup = new BC_FileBoxRecent(this, x, y));
627 add_subwindow(directory_title = new BC_FileBoxDirectoryText(x, y, this));
628 directory_title->reposition_window(x, y, get_w() - recent_popup->get_w() - 20, 1);
629 x += directory_title->get_w() + 8;
630 recent_popup->reposition_window(x, y, directory_title->get_w(), 200);
633 y += directory_title->get_h() + 5;
635 int newest_id = 0, newest = -1;
636 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++) {
637 if( !resources->filebox_history[i].path[0] ) continue;
638 if( resources->filebox_history[i].id > newest_id ) {
639 newest_id = resources->filebox_history[i].id;
644 strcpy(directory, resources->filebox_history[newest].path);
645 fs->change_dir(directory, 0);
646 strcpy(directory, fs->get_current_dir());
647 directory_title->update(fs->get_current_dir());
649 fs->set_sort_order(sort_order);
650 fs->set_sort_field(column_type[sort_column]);
651 fs->update(directory);
653 // Create recent dir list
658 create_listbox(x, y, get_display_mode());
659 y += listbox->get_h() + 10;
660 add_subwindow(textbox = new BC_FileBoxTextBox(x, y, this));
661 y += textbox->get_h() + 10;
663 if(!want_directory) {
664 add_subwindow(filter_text = new BC_FileBoxFilterText(x, y, this));
665 add_subwindow(filter_popup =
666 new BC_FileBoxFilterMenu(x + filter_text->get_w(), y, this));;
669 // listbox has to be active because refresh might be called from newfolder_thread
671 newfolder_thread = new BC_NewFolderThread(this);
673 rename_thread = new BC_RenameThread(this);
679 int BC_FileBox::get_listbox_w()
684 int BC_FileBox::get_listbox_h(int y)
686 int result = get_h() -
690 result -= BC_WindowBase::get_resources()->dirbox_margin;
692 result -= BC_WindowBase::get_resources()->filebox_margin;
697 int BC_FileBox::create_icons()
699 for(int i = 0; i < TOTAL_ICONS; i++)
701 icons[i] = new BC_Pixmap(this,
702 BC_WindowBase::get_resources()->type_to_icon[i],
708 int BC_FileBox::resize_event(int w, int h)
710 draw_background(0, 0, w, h);
713 // OK button handles resize event itself
714 // ok_button->reposition_window(ok_button->get_x(),
715 // h - (get_h() - ok_button->get_y()));
716 // cancel_button->reposition_window(w - (get_w() - cancel_button->get_x()),
717 // h - (get_h() - cancel_button->get_y()));
719 usethis_button->reposition_window(w / 2 - 50,
720 h - (get_h() - usethis_button->get_y()));
723 if(filter_popup) filter_popup->reposition_window(w - (get_w() - filter_popup->get_x()),
724 h - (get_h() - filter_popup->get_y()),
729 if(filter_text) filter_text->reposition_window(filter_text->get_x(),
730 h - (get_h() - filter_text->get_y()),
731 w - (get_w() - filter_text->get_w()),
733 directory_title->reposition_window(
734 directory_title->get_x(),
735 directory_title->get_y(),
736 get_w() - recent_popup->get_w() - 20,
738 recent_popup->reposition_window(
739 directory_title->get_x() + directory_title->get_w() + 8,
740 directory_title->get_y(),
741 directory_title->get_w() + recent_popup->get_w(),
742 recent_popup->get_h());
743 textbox->reposition_window(textbox->get_x(),
744 h - (get_h() - textbox->get_y()),
745 w - (get_w() - textbox->get_w()),
747 listbox->reposition_window(listbox->get_x(),
749 w - (get_w() - listbox->get_w()),
750 h - (get_h() - listbox->get_h()),
752 int dx = w - get_w();
753 icon_button->reposition_window(icon_button->get_x()+dx, icon_button->get_y());
754 text_button->reposition_window(text_button->get_x()+dx, text_button->get_y());
755 folder_button->reposition_window(folder_button->get_x()+dx, folder_button->get_y());
756 rename_button->reposition_window(rename_button->get_x()+dx, rename_button->get_y());
757 reload_button->reposition_window(reload_button->get_x()+dx, reload_button->get_y());
758 delete_button->reposition_window(delete_button->get_x()+dx, delete_button->get_y());
759 updir_button->reposition_window(updir_button->get_x()+dx, updir_button->get_y());
761 get_resources()->filebox_w = get_w();
762 get_resources()->filebox_h = get_h();
767 int BC_FileBox::keypress_event()
769 switch(get_keypress())
772 if(ctrl_down()) set_done(1);
779 int BC_FileBox::close_event()
785 int BC_FileBox::handle_event()
790 int BC_FileBox::extract_extension(char *out, const char *in)
794 while( --i>=0 && in[i]!='.' );
795 if( i >= 0 ) strcpy(out, &in[++i]);
799 int BC_FileBox::create_tables()
802 char string[BCTEXTLEN];
803 BC_ListBoxItem *new_item;
805 fs->set_sort_order(sort_order);
806 fs->set_sort_field(column_type[sort_column]);
808 for(int i = 0; i < fs->total_files(); i++)
810 FileItem *file_item = fs->get_entry(i);
811 int is_dir = file_item->is_dir;
812 BC_Pixmap* icon = get_icon(file_item->name, is_dir);
815 new_item = new BC_ListBoxItem(file_item->name,
817 is_dir ? get_resources()->directory_color : get_resources()->file_color);
818 if(is_dir) new_item->set_searchable(0);
819 list_column[column_of_type(FILEBOX_NAME)].append(new_item);
822 // if(!want_directory)
826 sprintf(string, "%jd", file_item->size);
827 new_item = new BC_ListBoxItem(string, get_resources()->file_color);
831 new_item = new BC_ListBoxItem("", get_resources()->directory_color);
834 list_column[column_of_type(FILEBOX_SIZE)].append(new_item);
840 static const char *month_text[13] = { "Nul",
841 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
842 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
846 month_text[file_item->month],
849 new_item = new BC_ListBoxItem(string, get_resources()->file_color);
853 new_item = new BC_ListBoxItem("", get_resources()->directory_color);
856 list_column[column_of_type(FILEBOX_DATE)].append(new_item);
859 // if(!want_directory)
862 extract_extension(string, file_item->name);
863 new_item = new BC_ListBoxItem(string, get_resources()->file_color);
866 new_item = new BC_ListBoxItem("", get_resources()->directory_color);
868 list_column[column_of_type(FILEBOX_EXTENSION)].append(new_item);
875 int BC_FileBox::delete_tables()
877 for(int j = 0; j < columns; j++)
879 list_column[j].remove_all_objects();
884 BC_Pixmap* BC_FileBox::get_icon(char *path, int is_dir)
886 char *suffix = strrchr(path, '.');
887 int icon_type = ICON_UNKNOWN;
889 if(is_dir) return icons[ICON_FOLDER];
896 for(int i = 0; i < TOTAL_SUFFIXES; i++)
898 if(!strcasecmp(suffix, BC_WindowBase::get_resources()->suffix_to_type[i].suffix))
900 icon_type = BC_WindowBase::get_resources()->suffix_to_type[i].icon_type;
907 return icons[icon_type];
910 const char* BC_FileBox::columntype_to_text(int type)
913 case FILEBOX_NAME: return FILEBOX_NAME_TEXT;
914 case FILEBOX_SIZE: return FILEBOX_SIZE_TEXT;
915 case FILEBOX_DATE: return FILEBOX_DATE_TEXT;
916 case FILEBOX_EXTENSION: return FILEBOX_EXTENSION_TEXT;
921 int BC_FileBox::column_of_type(int type)
923 for(int i = 0; i < columns; i++)
924 if(column_type[i] == type) return i;
930 int BC_FileBox::refresh(int reset)
932 fs->set_sort_order(sort_order);
933 fs->set_sort_field(column_type[sort_column]);
939 listbox->set_master_column(column_of_type(FILEBOX_NAME), 0);
940 listbox->update(list_column, column_titles, column_width, columns,
941 reset>0 ? 0 : listbox->get_xposition(),
942 reset>0 ? 0 : listbox->get_yposition(),
947 int BC_FileBox::update_filter(const char *filter)
949 fs->set_filter(filter);
952 strcpy(get_resources()->filebox_filter, filter);
958 void BC_FileBox::move_column(int src, int dst)
962 ArrayList<BC_ListBoxItem*> *new_columns =
963 new ArrayList<BC_ListBoxItem*>[columns];
964 int *new_types = new int[columns];
965 int *new_widths = new int[columns];
967 // Fill in remaining columns with consecutive data
968 for(int out_column = 0, in_column = 0;
969 out_column < columns;
973 // Copy destination column from src column
974 if(out_column == dst)
976 for(int i = 0; i < list_column[src].total; i++)
978 new_columns[out_column].append(list_column[src].values[i]);
980 new_types[out_column] = column_type[src];
981 new_widths[out_column] = column_width[src];
986 // Skip source column
987 if(in_column == src) in_column++;
988 for(int i = 0; i < list_column[src].total; i++)
990 new_columns[out_column].append(list_column[in_column].values[i]);
992 new_types[out_column] = column_type[in_column];
993 new_widths[out_column] = column_width[in_column];
998 delete [] list_column;
999 delete [] column_type;
1000 delete [] column_width;
1001 list_column = new_columns;
1002 column_type = new_types;
1003 column_width = new_widths;
1005 for(int i = 0; i < columns; i++)
1007 get_resources()->filebox_columntype[i] = column_type[i];
1008 get_resources()->filebox_columnwidth[i] = column_width[i];
1009 column_titles[i] = (char*)BC_FileBox::columntype_to_text(column_type[i]);
1017 int BC_FileBox::submit_dir(char *dir)
1019 strcpy(directory, dir);
1020 fs->join_names(current_path, directory, filename);
1022 // printf("BC_FileBox::submit_dir %d '%s' '%s' '%s'\n",
1027 strcpy(submitted_path, current_path);
1028 fs->change_dir(dir, 0);
1030 directory_title->update(fs->get_current_dir());
1032 textbox->update(fs->get_current_dir());
1034 textbox->update(filename);
1035 listbox->reset_query();
1039 int BC_FileBox::submit_file(const char *path, int use_this)
1041 // Deactivate textbox to hide suggestions
1042 textbox->deactivate();
1044 // If file wanted, take the current directory as the desired file.
1045 // If directory wanted, ignore it.
1046 if(!path[0] && !want_directory)
1048 // save complete path
1049 strcpy(this->current_path, directory);
1050 // save complete path
1051 strcpy(this->submitted_path, directory);
1053 // Zero out filename
1059 // is a directory, change directories
1060 if(fs->is_dir(path) && !use_this)
1062 fs->change_dir(path, 0);
1064 directory_title->update(fs->get_current_dir());
1065 strcpy(this->current_path, fs->get_current_dir());
1066 strcpy(this->submitted_path, fs->get_current_dir());
1067 strcpy(this->directory, fs->get_current_dir());
1071 textbox->update(fs->get_current_dir());
1073 textbox->update("");
1074 listbox->reset_query();
1078 // Is a file or desired directory. Quit the operation.
1080 char path2[BCTEXTLEN];
1081 strcpy(path2, path);
1083 // save directory for defaults
1084 fs->extract_dir(directory, path2);
1086 // Just take the directory
1090 strcpy(path2, directory);
1093 // Take the complete path
1095 fs->extract_name(filename, path2); // save filename
1098 fs->complete_path(path2);
1099 strcpy(this->current_path, path2); // save complete path
1100 strcpy(this->submitted_path, path2); // save complete path
1102 newfolder_thread->interrupt();
1109 void BC_FileBox::update_history()
1111 // Look for path already in history
1112 BC_Resources *resources = get_resources();
1113 char path[BCTEXTLEN];
1114 strcpy(path, directory);
1115 // enfore one trailing slash
1118 while( cp > path && *(cp-1) == '/' ) --cp;
1119 *cp++ = '/'; *cp = 0;
1121 // int new_slot = FILEBOX_HISTORY_SIZE - 1;
1123 for(int i = FILEBOX_HISTORY_SIZE - 1; i >= 0; i--)
1125 if(resources->filebox_history[i].path[0] &&
1126 !strcmp(resources->filebox_history[i].path, path))
1128 // Got matching path.
1130 resources->filebox_history[i].id = resources->get_filebox_id();
1133 // // Shift down from this point.
1136 // strcpy(resources->filebox_history[i],
1137 // resources->filebox_history[i - 1]);
1138 // if(resources->filebox_history[i][0]) new_slot--;
1144 // if(resources->filebox_history[i][0])
1150 // Remove oldest entry if full
1151 if(resources->filebox_history[FILEBOX_HISTORY_SIZE - 1].path[0])
1153 int oldest_id = 0x7fffffff;
1155 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++)
1157 if(resources->filebox_history[i].path[0] &&
1158 resources->filebox_history[i].id < oldest_id)
1160 oldest_id = resources->filebox_history[i].id;
1165 for(int i = oldest; i < FILEBOX_HISTORY_SIZE - 1; i++)
1167 strcpy(resources->filebox_history[i].path,
1168 resources->filebox_history[i + 1].path);
1169 resources->filebox_history[i].id =
1170 resources->filebox_history[i + 1].id;
1175 strcpy(resources->filebox_history[FILEBOX_HISTORY_SIZE - 1].path, path);
1176 resources->filebox_history[FILEBOX_HISTORY_SIZE - 1].id = resources->get_filebox_id();
1183 for(int i = 1; i < FILEBOX_HISTORY_SIZE; i++)
1185 if( (resources->filebox_history[i - 1].path[0] &&
1186 resources->filebox_history[i].path[0] &&
1187 strcasecmp(resources->filebox_history[i - 1].path,
1188 resources->filebox_history[i].path) > 0) ||
1189 (resources->filebox_history[i - 1].path[0] == 0 &&
1190 resources->filebox_history[i].path[0]) )
1193 char temp[BCTEXTLEN];
1195 strcpy(temp, resources->filebox_history[i - 1].path);
1196 id_temp = resources->filebox_history[i - 1].id;
1197 strcpy(resources->filebox_history[i - 1].path,
1198 resources->filebox_history[i].path);
1199 resources->filebox_history[i - 1].id =
1200 resources->filebox_history[i].id;
1201 strcpy(resources->filebox_history[i].path, temp);
1202 resources->filebox_history[i].id = id_temp;
1209 // for(int i = FILEBOX_HISTORY_SIZE - 1; i > 0; i--)
1211 // strcpy(resources->filebox_history[i],
1212 // resources->filebox_history[i - 1]);
1217 // strcpy(resources->filebox_history[new_slot], path);
1220 recent_popup->update(&recent_dirs, 0, 0, 1);
1223 void BC_FileBox::create_history()
1225 BC_Resources *resources = get_resources();
1226 recent_dirs.remove_all_objects();
1227 for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++) {
1228 if(resources->filebox_history[i].path[0]) {
1229 recent_dirs.append(new BC_ListBoxItem(resources->filebox_history[i].path));
1235 int BC_FileBox::get_display_mode()
1237 return top_level->get_resources()->filebox_mode;
1240 void BC_FileBox::create_listbox(int x, int y, int mode)
1242 if(listbox && listbox->get_display_mode() != mode)
1246 top_level->get_resources()->filebox_mode = mode;
1250 add_subwindow(listbox = new BC_FileBoxListBox(x, y, this));
1253 char* BC_FileBox::get_path(int selection)
1257 return get_submitted_path();
1261 BC_ListBoxItem *item = listbox->get_selection(
1262 column_of_type(FILEBOX_NAME), selection - 1);
1265 fs->join_names(string, directory, item->get_text());
1272 char* BC_FileBox::get_submitted_path()
1274 return submitted_path;
1277 char* BC_FileBox::get_current_path()
1279 //printf("BC_FileBox::get_current_path 1 %s\n", current_path);
1280 return current_path;
1283 char* BC_FileBox::get_newfolder_title()
1285 char *letter2 = strchr(title, ':');
1286 new_folder_title[0] = 0;
1289 memcpy(new_folder_title, title, letter2 - title);
1290 new_folder_title[letter2 - title] = 0;
1293 strcat(new_folder_title, _(": New folder"));
1295 return new_folder_title;
1298 char* BC_FileBox::get_rename_title()
1300 char *letter2 = strchr(title, ':');
1301 new_folder_title[0] = 0;
1304 memcpy(new_folder_title, title, letter2 - title);
1305 new_folder_title[letter2 - title] = 0;
1308 strcat(new_folder_title, _(": Rename"));
1310 return new_folder_title;
1313 char* BC_FileBox::get_delete_title()
1315 char *letter2 = strchr(title, ':');
1316 new_folder_title[0] = 0;
1319 memcpy(new_folder_title, title, letter2 - title);
1320 new_folder_title[letter2 - title] = 0;
1323 strcat(new_folder_title, _(": Delete"));
1325 return new_folder_title;
1328 void BC_FileBox::delete_files()
1330 // Starting at 1 causes it to ignore what's in the textbox.
1334 while((path = get_path(i)))
1336 // Not directory. Remove it.
1337 if(!fs.is_dir(path))
1339 //printf("BC_FileBox::delete_files: removing \"%s\"\n", path);
1347 BC_Button* BC_FileBox::get_ok_button()
1352 BC_Button* BC_FileBox::get_cancel_button()
1354 return cancel_button;