GrafX2 2.9.3227
The ultimate 256-color painting program
filesel.c File Reference
#include <assert.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <ctype.h>
#include <wctype.h>
#include <sys/types.h>
#include "const.h"
#include "struct.h"
#include "global.h"
#include "misc.h"
#include "osdep.h"
#include "errors.h"
#include "io.h"
#include "windows.h"
#include "screen.h"
#include "loadsave.h"
#include "mountlist.h"
#include "engine.h"
#include "readline.h"
#include "input.h"
#include "help.h"
#include "unicode.h"
#include "filesel.h"
#include "fileseltools.h"
+ Include dependency graph for filesel.c:

Data Structures

struct  Read_dir_pdata
 

Macros

#define NORMAL_FILE_COLOR   MC_Light
 
#define NORMAL_DIRECTORY_COLOR   MC_Dark
 
#define NORMAL_BACKGROUND_COLOR   MC_Black
 
#define SELECTED_FILE_COLOR   MC_White
 
#define SELECTED_DIRECTORY_COLOR   MC_Light
 
#define SELECTED_BACKGROUND_COLOR   MC_Dark
 
#define FILENAME_COMPARE   strcmp
 
#define FILENAME_COMPARE_UNICODE   Unicode_strcmp
 
#define MAX_QUICKSEARCH_LEN   50
 

Functions

static void Recount_files (T_Fileselector *list)
 Update T_Fileselector::Nb_files T_Fileselector::Nb_directories T_Fileselector::Nb_elements counts. More...
 
void Free_fileselector_list (T_Fileselector *list)
 This function free all item in the list, but not the list itself. More...
 
int Check_extension (const char *filename_ext, const char *filter)
 Checks if a file has the requested file extension. More...
 
static void Read_dir_callback (void *pdata, const char *file_name, const word *unicode_name, byte is_file, byte is_directory, byte is_hidden)
 
void Read_list_of_files (T_Fileselector *list, byte selected_format)
 
void Read_list_of_drives (T_Fileselector *list, byte name_length)
 
void Sort_list_of_files (T_Fileselector *list)
 Sort a file/directory list. More...
 
T_Fileselector_itemGet_item_by_index (T_Fileselector *list, unsigned short index)
 Fast access to a list item. More...
 
void Display_file_list (T_Fileselector *list, short offset_first, short selector_offset)
 Display of the file/directory list items. More...
 
static void Get_selected_item (T_Fileselector *list, T_Selector_settings *selector, enum FSOBJECT_TYPE *type)
 Get the label of a list item. More...
 
void Selector_scroll_down (short *offset_first, short *selector_offset)
 
void Selector_scroll_up (short *offset_first, short *selector_offset)
 
void Selector_page_down (short *offset_first, short *selector_offset, short lines)
 
void Selector_page_up (short *offset_first, short *selector_offset, short lines)
 
void Selector_end (short *offset_first, short *selector_offset)
 
void Selector_home (short *offset_first, short *selector_offset)
 
short Compute_click_offset_in_fileselector (void)
 
static void Display_bookmark (T_Dropdown_button *Button, int bookmark_number)
 
static void Print_current_directory (void)
 Shows Selector->Directory on 37 chars. More...
 
void Print_filename_in_fileselector (void)
 
static void Prepare_and_display_filelist (short Position, short offset, T_Scroller_button *button, int setfilename)
 Displays the file list with sliders, etc. More...
 
static void Reload_list_of_files (byte filter, T_Scroller_button *button)
 
void Scroll_fileselector (T_Scroller_button *file_scroller)
 
short Find_file_in_fileselector (T_Fileselector *list, const char *fname)
 Look for a file name in a file selector list. More...
 
static void Highlight_file (short index)
 Set the position and index of the file list according to the selected index. More...
 
static short Find_filename_match (const T_Fileselector *list, const word *fname)
 Find the item best matching the searched filename. More...
 
void Reset_quicksearch (void)
 Reset the current quicksearch string. More...
 
static short Quicksearch (const T_Fileselector *selector)
 Select the item based on what the user type. More...
 
void Locate_list_item (T_List_button *list, short selected_item)
 
int Quicksearch_list (T_List_button *list, T_Fileselector *selector)
 
byte Button_Load_or_Save (T_Selector_settings *settings, byte load, T_IO_Context *context)
 Launch the Load/Save dialog (file selector) More...
 

Variables

static byte New_preview_is_needed
 true if the preview timer need to be restarted More...
 
static T_Fileselector Filelist
 
static T_Selector_settingsSelector
 Selector settings to use, for all functions called by Load_or_save. More...
 
static enum FSOBJECT_TYPE Selected_type
 Type of the selected entry in the file selector. More...
 
static word quicksearch_filename [MAX_QUICKSEARCH_LEN+1] = { 0 }
 Current quicksearch string. More...
 

Macro Definition Documentation

◆ NORMAL_FILE_COLOR

#define NORMAL_FILE_COLOR   MC_Light

◆ NORMAL_DIRECTORY_COLOR

#define NORMAL_DIRECTORY_COLOR   MC_Dark

◆ NORMAL_BACKGROUND_COLOR

#define NORMAL_BACKGROUND_COLOR   MC_Black

◆ SELECTED_FILE_COLOR

#define SELECTED_FILE_COLOR   MC_White

◆ SELECTED_DIRECTORY_COLOR

#define SELECTED_DIRECTORY_COLOR   MC_Light

◆ SELECTED_BACKGROUND_COLOR

#define SELECTED_BACKGROUND_COLOR   MC_Dark

◆ FILENAME_COMPARE

#define FILENAME_COMPARE   strcmp

◆ FILENAME_COMPARE_UNICODE

#define FILENAME_COMPARE_UNICODE   Unicode_strcmp

◆ MAX_QUICKSEARCH_LEN

#define MAX_QUICKSEARCH_LEN   50

Function Documentation

◆ Recount_files()

◆ Free_fileselector_list()

void Free_fileselector_list ( T_Fileselector list)

This function free all item in the list, but not the list itself.

Parameters
listthe linked list

References T_Fileselector::First, T_Fileselector_item::Next, NULL, Recount_files(), T_Fileselector_item::Unicode_full_name, and T_Fileselector_item::Unicode_short_name.

Referenced by Button_Load_or_Save(), Button_Skins(), Read_list_of_drives(), and Read_list_of_files().

◆ Check_extension()

int Check_extension ( const char *  filename_ext,
const char *  filter 
)

Checks if a file has the requested file extension.

The extension string can end with a ';' (remainder is ignored). This function allows wildcard '?', and '*' if it's the only character.

References NULL.

Referenced by Read_dir_callback().

◆ Read_dir_callback()

◆ Read_list_of_files()

◆ Read_list_of_drives()

◆ Sort_list_of_files()

void Sort_list_of_files ( T_Fileselector list)

Sort a file/directory list.

The sord is done in that order : Directories first, in alphabetical order, then Files, in alphabetical order.

List counts and index are updated.

Parameters
listthe linked list

References FILENAME_COMPARE, FILENAME_COMPARE_UNICODE, T_Fileselector::First, T_Fileselector_item::Full_name, T_Fileselector_item::Next, NULL, PARENT_DIR, T_Fileselector_item::Previous, Recount_files(), T_Fileselector_item::Type, and T_Fileselector_item::Unicode_full_name.

Referenced by Button_Load_or_Save(), Button_Skins(), and Reload_list_of_files().

◆ Get_item_by_index()

T_Fileselector_item * Get_item_by_index ( T_Fileselector list,
unsigned short  index 
)

Fast access to a list item.

Parameters
listthe linked list
indexthe item index to access
Returns
the item at the index position in the list
NULL in case of error

References T_Fileselector::First, T_Fileselector::Index, T_Fileselector::Nb_elements, T_Fileselector_item::Next, and NULL.

Referenced by Button_Load_or_Save(), Button_Skins(), Display_file_list(), Draw_one_skin_name(), and Get_selected_item().

◆ Display_file_list()

void Display_file_list ( T_Fileselector list,
short  offset_first,
short  selector_offset 
)

◆ Get_selected_item()

static void Get_selected_item ( T_Fileselector list,
T_Selector_settings selector,
enum FSOBJECT_TYPE type 
)
static

Get the label of a list item.

selector->filename and selector->filename_unicode are updated

Parameters
listthe file list
selectorthe current File selector
typeNULL or a pointer to receive the type : 0 = file, 1 = directory, 2 = drive.

References T_Selector_settings::filename, T_Selector_settings::filename_unicode, T_Fileselector_item::Full_name, Get_item_by_index(), T_Fileselector::Nb_elements, NULL, T_Selector_settings::Offset, T_Selector_settings::Position, T_Fileselector_item::Type, T_Fileselector_item::Unicode_full_name, and Unicode_strdup().

Referenced by Button_Load_or_Save(), Prepare_and_display_filelist(), and Scroll_fileselector().

◆ Selector_scroll_down()

void Selector_scroll_down ( short *  offset_first,
short *  selector_offset 
)

◆ Selector_scroll_up()

void Selector_scroll_up ( short *  offset_first,
short *  selector_offset 
)

References Display_file_list(), and Filelist.

Referenced by Button_Load_or_Save().

◆ Selector_page_down()

void Selector_page_down ( short *  offset_first,
short *  selector_offset,
short  lines 
)

◆ Selector_page_up()

void Selector_page_up ( short *  offset_first,
short *  selector_offset,
short  lines 
)

References Display_file_list(), and Filelist.

Referenced by Button_Load_or_Save().

◆ Selector_end()

void Selector_end ( short *  offset_first,
short *  selector_offset 
)

◆ Selector_home()

void Selector_home ( short *  offset_first,
short *  selector_offset 
)

References Display_file_list(), and Filelist.

Referenced by Button_Load_or_Save().

◆ Compute_click_offset_in_fileselector()

short Compute_click_offset_in_fileselector ( void  )

◆ Display_bookmark()

◆ Print_current_directory()

◆ Print_filename_in_fileselector()

◆ Prepare_and_display_filelist()

static void Prepare_and_display_filelist ( short  Position,
short  offset,
T_Scroller_button button,
int  setfilename 
)
static

Displays the file list with sliders, etc.

also optionally updates the current file name (Selector_filename)

Parameters
Positionthe current position in the file list
offsetthe offset of the selected item in the file list
buttonthe scrollbar/slider GUI control
setfilenameoption to update Selector_filename

References Compute_slider_cursor_length(), Display_file_list(), Filelist, Get_selected_item(), MC_Black, T_Scroller_button::Nb_elements, T_Fileselector::Nb_elements, T_Scroller_button::Position, Print_current_directory(), Print_filename_in_fileselector(), Selected_type, Selector, Update_window_area, Window_draw_slider(), and Window_rectangle().

Referenced by Button_Load_or_Save(), and Reload_list_of_files().

◆ Reload_list_of_files()

◆ Scroll_fileselector()

◆ Find_file_in_fileselector()

short Find_file_in_fileselector ( T_Fileselector list,
const char *  fname 
)

Look for a file name in a file selector list.

Parameters
listThe file selector list
fnameThe file name to search for
Returns
the index of the file
-1 if the file name was not found

References T_Fileselector::First, T_Fileselector_item::Full_name, T_Fileselector_item::Next, and NULL.

Referenced by Button_Load_or_Save(), and Button_Skins().

◆ Highlight_file()

static void Highlight_file ( short  index)
static

Set the position and index of the file list according to the selected index.

Parameters
indexindex of selected file

References Filelist, T_Fileselector::Nb_elements, T_Selector_settings::Offset, T_Selector_settings::Position, and Selector.

Referenced by Button_Load_or_Save().

◆ Find_filename_match()

static short Find_filename_match ( const T_Fileselector list,
const word fname 
)
static

Find the item best matching the searched filename.

used by quicksearch

Returns
-1 if not matching name found

References Config, T_Config::Find_file_fast, T_Fileselector::First, T_Fileselector_item::Full_name, T_Fileselector_item::Next, NULL, T_Fileselector_item::Type, and T_Fileselector_item::Unicode_full_name.

Referenced by Quicksearch().

◆ Reset_quicksearch()

void Reset_quicksearch ( void  )

Reset the current quicksearch string.

References quicksearch_filename.

Referenced by Button_Load_or_Save(), and Quicksearch().

◆ Quicksearch()

static short Quicksearch ( const T_Fileselector selector)
static

◆ Locate_list_item()

◆ Quicksearch_list()

◆ Button_Load_or_Save()

byte Button_Load_or_Save ( T_Selector_settings settings,
byte  load,
T_IO_Context context 
)

Launch the Load/Save dialog (file selector)

Parameters
settingsthe settings associated with this file selector
load1 for a load dialog, 0 for a save
contextthe IO context
Returns
0 if the user cancelled the load/save
1 if the user want to load/save a file
Todo:
convert label to unicode before editing

References Back_color, T_Config::Bookmark_directory, T_Config::Bookmark_label, BUTTON_HELP, BUTTON_LOAD, BUTTON_SAVE, Calculate_relative_path(), Change_directory(), Check_timer(), Close_window(), T_IO_Context::Comment, T_Format::Comment, COMMENT_SIZE, Compute_click_offset_in_fileselector(), Compute_optimal_menu_colors(), Config, Confirmation_box(), CONTEXT_BRUSH, CONTEXT_MAIN_IMAGE, CONTEXT_PALETTE, CONTEXT_PREVIEW_PALETTE, Data_directory, T_Format::Default_extension, DEFAULT_FILEFORMAT, Destroy_context(), T_Selector_settings::Directory, Directory_exists(), T_Selector_settings::Directory_unicode, Display_bookmark(), Display_cursor(), Display_file_list(), Display_menu(), Error, Extract_filename(), T_IO_Context::File_directory, File_exists(), File_formats, T_IO_Context::File_name, T_IO_Context::File_name_unicode, Filelist, T_Selector_settings::filename, FILENAME_COMPARE, T_Selector_settings::filename_unicode, Find_file_in_fileselector(), Find_last_separator(), T_Fileselector::First, T_IO_Context::Format, format, FORMAT_ALL_FILES, FORMAT_CLIPBOARD, T_Selector_settings::Format_filter, Free_fileselector_list(), FSOBJECT_DIR, FSOBJECT_DRIVE, FSOBJECT_FILE, T_Fileselector_item::Full_name, Get_current_directory(), Get_fileformat(), Get_item_by_index(), Get_selected_item(), Get_Unicode_Filename(), GFX2_DEBUG, GFX2_INFO, GFX2_Log(), GFX2_WARNING, Hide_cursor, Highlight_file(), ICON_STAR, Init_chrono(), Init_context_preview(), INPUT_TYPE_FILENAME, INPUT_TYPE_STRING, Is_shortcut(), Key, KEY_BACKSPACE, KEY_DELETE, KEY_DOWN, KEY_END, KEY_ESC, KEY_HOME, KEY_MOUSEWHEELDOWN, KEY_MOUSEWHEELUP, KEY_NONE, KEY_PAGEDOWN, KEY_PAGEUP, KEY_RETURN, KEY_UNKNOWN, KEY_UP, T_Format::Label, LEFT_SIDE, Load, Load_image(), Main, MC_Black, MC_Dark, MC_Light, Menu_factor_Y, Menu_Y_before_window, Mouse_K, NB_BOOKMARKS, T_Fileselector::Nb_directories, T_Fileselector::Nb_elements, Nb_known_formats(), New_preview_is_needed, NULL, T_Selector_settings::Offset, Open_window(), T_Document::palette, T_Format::Palette_only, PARENT_DIR, T_Selector_settings::Position, Position_last_dot(), Position_last_dot_unicode(), Prepare_and_display_filelist(), PREVIEW_HEIGHT, PREVIEW_WIDTH, Print_filename_in_fileselector(), Print_in_window(), Quicksearch(), Quit_is_required, Read_list_of_drives(), Read_list_of_files(), Readline(), Readline_ex(), Readline_ex_unicode(), Reload_list_of_files(), Remove_directory(), Remove_path(), Reset_quicksearch(), RIGHT_SIDE, T_Format::Save, Save, Save_image(), Scroll_fileselector(), Selected_type, Selector, Selector_end(), Selector_home(), Selector_page_down(), Selector_page_up(), Selector_scroll_down(), Selector_scroll_up(), Set_palette(), SHORTCUT_COPY, SHORTCUT_PASTE, Sort_list_of_files(), SPECIAL_LOAD_BRUSH, SPECIAL_SAVE_BRUSH, T_Config::Timer_delay, Timer_state, T_IO_Context::Type, T_Fileselector_item::Type, Unicode_char_strlcat(), Unicode_char_strlcpy(), Unicode_strdup(), Unicode_strlcpy(), Unicode_strlen(), Unselect_button(), Update_window_area, Wait_end_of_click(), Window_attribute2, Window_clicked_button(), Window_display_frame_in(), Window_display_icon_sprite(), Window_dropdown_add_item(), Window_height, Window_help(), Window_pos_Y, Window_rectangle(), Window_set_dropdown_button(), Window_set_input_button(), Window_set_normal_button(), Window_set_scroller_button(), Window_set_special_button(), Window_width, and Windows_open.

Referenced by Load_picture(), and Save_picture().

Variable Documentation

◆ New_preview_is_needed

byte New_preview_is_needed
static

true if the preview timer need to be restarted

Referenced by Button_Load_or_Save(), and Scroll_fileselector().

◆ Filelist

◆ Selector

◆ Selected_type

enum FSOBJECT_TYPE Selected_type
static

Type of the selected entry in the file selector.

Referenced by Button_Load_or_Save(), Prepare_and_display_filelist(), and Scroll_fileselector().

◆ quicksearch_filename

word quicksearch_filename[MAX_QUICKSEARCH_LEN+1] = { 0 }
static

Current quicksearch string.

Referenced by Quicksearch(), and Reset_quicksearch().