📄 iodlg.c
字号:
FILETEXTLINE(o)->filebox->load_list(FILETEXTLINE(o)->filebox,
FILETEXTLINE(o)->filebox->path,
FILETEXTLINE(o)->filebox->file);
};
} else
clear_event(event);
};
if ( event->type & EV_INFO ) { /* info event */
/* filelistbox was reselect */
if ( event->message == MSG_SELECTEDFILELISTBOXITEM &&
event->obj && event->obj == OBJECT(FILEHISTORY(o)->filebox) ) {
p_filelistbox_item rec = (p_filelistbox_item)LISTBOX_ITEM_AT(LISTBOX(event->obj)->list, LISTBOX(event->obj)->current);
if ( rec ) { /* filelistbox current item exist */
if ( rec->info.attrib & FA_DIREC )
TEXTLINE(o)->set_text(TEXTLINE(o), FILEHISTORY(o)->filebox->file);
else {
TEXTLINE(o)->set_text(TEXTLINE(o), rec->info.filename);
FILETEXTLINE(o)->filename = _strdup(rec->info.filename);
};
};
clear_event(event);
};
};
};
////////////////////////////////////////////////////////////////////////////////
/* t_filelistctrl MSG_LSTDIRSELECTED */
void filelistctrl_translate_event ( p_object o, p_event event ) {
view_translate_event ( o, event );
if ( event->type & EV_MESSAGE ) {
p_filelistctrl f = FILELISTCTRL(o);
switch ( event->message ) {
case MSG_PARENTDIR : {
if ( stricmp( f->filebox->path ,"/") ) {
l_text path = f->filebox->path;
l_text parent = io_parentdir(path);
f->filebox->load_list(f->filebox, parent, f->filebox->file);
};
clear_event(event);
}; break;
case MSG_LSTDIRSELECTED : {
if ( f->his ) {
if ( f->his->current == 0 ) {
f->filebox->load_list(f->filebox, _strdup("/"), f->filebox->file);
} else {
p_vdrive vdrv = VirtualDrives->at(VirtualDrives,f->his->current-1);
if ( vdrv ) f->filebox->load_list(f->filebox, set_format_text(NULL,"/%s/",vdrv->drive), f->filebox->file);
};
};
clear_event(event);
}; break;
};
};
};
////////////////////////////////////////////////////////////////////////////////
p_list get_vdrives ( void ) {
p_list p = list_init(_malloc(sizeof(t_list)), &free_listbox_item, 0);
if ( p ) {
p->insert(p, new_listbox_item(TXT_COMPUTER, NULL, 0, NULL));
if ( VirtualDrives && VirtualDrives->last ) {
p_item x = VirtualDrives->first(VirtualDrives);
p_item f = x;
if ( f )
do {
p_vdrive o = ((p_vdrive)(x->rec));
p->insert(p, new_listbox_item(o->drive, IMG_DIR16, 0, NULL));
x = x->next;
} while ( x != f );
};
};
return p;
};
////////////////////////////////////////////////////////////////////////////////
void filelistctrl_setup ( p_object o )
{
p_icobutton b;
t_rect r;
p_filelistctrl ct = FILELISTCTRL(o);
view_setup(o);
r = VIEW(o)->get_local_extent(VIEW(o));
b = icobutton_init(sf_malloc(sizeof(t_icobutton)), rect_assign(220,0,220+r.b.y,r.b.y), ParentDirIcon, "Parent dir", MSG_PARENTDIR, BF_UNDERSEL+BF_NORMAL);
if ( b ) {
OBJECT(b)->set_options(OBJECT(b), VW_OF_IGNORELIM, true);
OBJECT(b)->set_options(OBJECT(b), OB_OF_SELECTABLE, false);
//VIEW(b)->align |= TX_ALIGN_LEFT+TX_ALIGN_FIXEDX;
};
o->insert(o, OBJECT(b));
ct->his = history_init( _malloc(sizeof(t_history)),
rect_assign( 0,0,200,r.b.y ),
get_vdrives() ,
150,
HF_REWRITEUNABLE|LF_SELFLIST);
ct->his->message = MSG_LSTDIRSELECTED;
o->insert(o, OBJECT(ct->his));
/* insert close button to window */
};
/* t_filelistctrl */
////////////////////////////////////////////////////////////////////////////////
p_filelistctrl _filelistctrl_init ( p_filelistctrl o, t_rect r, p_filelistbox filebox )
{
if ( !o ) return NULL;
clear_type(o, sizeof(t_filelistctrl));
view_init(VIEW(o), r);
o->filebox = filebox;
OBJECT(o)->setup = &filelistctrl_setup;
OBJECT(o)->translate_event = &filelistctrl_translate_event;
VIEW(o)->brush.color = color_3d_face;
o->his = NULL;
return o;
};
////////////////////////////////////////////////////////////////////////////////
/* t_filehistory */
p_filehistory _filehistory_init ( p_filehistory o, t_rect r, p_list list, l_int limit, l_int flags, p_filelistbox filebox )
{
if ( !o ) return NULL;
clear_type(o, sizeof(t_filehistory));
history_init(HISTORY(o), r, list, limit, flags);
o->filebox = filebox;
/* object's functions */
/* view's functions */
/* history's functions */
HISTORY(o)->show_box = &filehistory_show_box;
/* filehistory's functions */
/* function calling */
return o;
};
/* t_filetextline */
p_filetextline _filetextline_init ( p_filetextline o, t_rect r, l_int limit, l_int flags, p_filelistbox filebox, p_filehistory filehistory )
{
if ( !o ) return NULL;
clear_type(o, sizeof(t_filetextline));
textline_init(TEXTLINE(o), r, limit, flags);
o->filebox = filebox;
o->filehistory = filehistory;
/* object's functions */
OBJECT(o)->translate_event = &filetextline_translate_event;
/* view's functions */
/* function calling */
return o;
};
/* t_filelistbox */
/*
filelistbox - is used for work with files/directories in listbox
- cols number of columns
- flags flags of listbox + flags of filelistbox
...listbox flags
LF_NONE
LF_UNDERSEL select item whenever is mouse under it
LF_SELECTABLE select more item for copying
...filistbox flags
FL_SAVE main button works as save button
FL_OPEN main button works as open button
FL_DIROPEN main button works as diropen button
- path path to directory, from where is the first output of files
- file name of file, that is as the first in file textline
- atrib file atributions, atrrib of files that may be displayed by
filelistbox. Definitions are defined in _iodir.h and <dir.h>
`FA_RDONLY' Include read-only files in the search
`FA_HIDDEN' Include hidden files in the search
`FA_SYSTEM' Include system files in the search
`FA_LABEL' Include the volume label in the search
`FA_DIREC' Include subdirectories in the search
`FA_ARCH' Include modified files in the search
...in _iodir.h
`FA_LINK' link to file
`FA_LINKDIR' link to dir
`FA_LINKDRIVE' link to drive
`FA_NOTPARENT' not show parent directory ".."
- file_sel
function that is called for all files, when file is focused,
argument is [path to file/filename] of current file.
*/
p_filelistbox _filelistbox_init ( p_filelistbox o, t_rect r, l_int cols, l_int flags, l_text path, l_text file, l_int attrib, void (*file_sel)() )
{
if ( !o ) return NULL;
clear_type(o, sizeof(t_filelistbox));
listbox_init(LISTBOX(o), r, NULL, cols, flags);
o->file = _strdup(file);
o->path = _strdup(path);
o->attrib = attrib;
o->file_sel = file_sel;
/* object's functions */
l_tag_cpy(OBJECT(o)->data_type, DAT_LIST);
OBJECT(o)->setup = &filelistbox_setup;
OBJECT(o)->set_data = &filelistbox_set_data;
OBJECT(o)->get_data = &filelistbox_get_data;
OBJECT(o)->translate_event = &filelistbox_translate_event;
/* view's functions */
VIEW(o)->drag_where = &filelistbox_drag_where;
/* listbox's functions */
LISTBOX(o)->rewrite_item = &filelistbox_rewrite_item;
LISTBOX(o)->get_selected_items = &filelistbox_get_selected_items;
LISTBOX(o)->flags = flags;
/* filelistbox's functions */
o->load_list = &filelistbox_load_list;
o->file_menu = &filelistbox_file_menu;
o->get_file = &filelistbox_get_file;
o->file_handle_ex = &filelistbox_file_handle_ex;
o->file_handle = &filelistbox_file_handle;
o->change_name = &filelistbox_change_name;
o->new_directory = &filelistbox_new_directory;
/* function calling */
return o;
};
/* dialogs */
static t_point fapp_size_minimum ( p_view o )
{
return point_assign(300, 200);
};
l_text _file_dialog ( l_text caption, l_text bname, l_text path, l_text file, p_list hislist, l_int attrib, l_int flags, void (*file_sel)() )
{
l_text endfile = NULL;
p_appwin w;
t_rect r = rect_assign(0, 0, 400, 320);
if ( flags & FL_DIROPEN ) { /* it's dir dialog */
r.b.x -= 30;
r.b.y -= 40;
};
w = appwin_init(_malloc(sizeof(t_appwin)), r, caption, 0, 0, NULL);
if ( w ) {
p_button b = NULL;
p_button c = NULL;
p_filelistctrl h = NULL;
p_filelistbox box = NULL;
p_filehistory d = NULL;
p_filetextline tl = NULL;
p_stattext st_fname = NULL;
p_stattext st_ftype = NULL;
//p_stattext st_links = NULL;
t_rect t;
t_rect f;
t_rect s;
r = t = VIEW(w)->size_limits(VIEW(w));
r.a.x += 10;
r.a.y += 10;
r.b.x -= 10;
r.b.y -= 10;
t = f = r;
VIEW(w)->drag_mode |= DM_DRAGGROW;
VIEW(w)->size_minimum = &fapp_size_minimum;
r = rect_assign(r.a.x, r.a.y+30, t.b.x, r.a.y+190);
box = filelistbox_init(_malloc(sizeof(t_filelistbox)), r, 3, LF_SELECTABLE|flags, path, (l_text)FILELISTBOX_ITEM_FILENAME(hislist, 0), attrib, file_sel);
f = rect_assign(r.a.x, t.a.y, t.a.x+250, t.a.y+20);
h = filelistctrl_init(_malloc(sizeof(t_filelistctrl)), f, box);
r = rect_assign(r.a.x+100, r.b.y+STANDARD_SCROLLBAR_WIDTH+20, r.b.x-STANDARD_HISTORYBUTTON_SIZE-120, r.b.y+STANDARD_SCROLLBAR_WIDTH+40);
r = rect_assign(r.a.x, r.b.y+10, r.b.x, r.b.y+30);
s = rect_assign(r.a.x-100, r.a.y, r.a.x-10, r.b.y);
if ( !(flags & FL_DIROPEN) ) { /* it's file dialog */
st_ftype = stattext_init(_malloc(sizeof(t_stattext)), s, TX_ALIGN_BOTTOM, "%s :", TXT_FILETYPE);
d = filehistory_init(_malloc(sizeof(t_filehistory)), r, hislist, IO_TEXT_LIMIT, HF_REWRITEUNABLE, box);
f = rect_assign(r.a.x, r.a.y-30, r.b.x, r.a.y-10);
s = rect_assign(f.a.x-100, f.a.y, f.a.x-10, f.b.y);
st_fname = stattext_init(_malloc(sizeof(t_stattext)), s, TX_ALIGN_BOTTOM, "%s :", TXT_FILENAME);
tl = filetextline_init(_malloc(sizeof(t_filetextline)), f, IO_TEXT_LIMIT, TF_NONE, box, d);
r = rect_assign(r.b.x+STANDARD_HISTORYBUTTON_SIZE+10, r.a.y, t.b.x, r.b.y);
b = button_init(_malloc(sizeof(t_button)), r, bname, MSG_OK, BF_DEFAULT);
/* button alignment */
if ( b ) VIEW(b)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_RIGHT|TX_ALIGN_FIXEDX|TX_ALIGN_FIXEDY;
} else { /* it's directory dialog */
r = rect_assign(t.a.x, t.b.y-20, t.b.x, t.b.y);
b = button_init(_malloc(sizeof(t_button)), r, bname, MSG_OPENDIR, BF_DEFAULT);
/* button alignment */
if ( b ) VIEW(b)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_RIGHT|TX_ALIGN_FIXEDY;
};
/* window alignment */
VIEW(w)->align = TX_ALIGN_CENTER;
/* filebox alignment */
if ( box ) VIEW(box)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_RIGHT;
/* filehistory alignment */
if ( d ) VIEW(d)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_RIGHT|TX_ALIGN_FIXEDY;
/* filetextline alignment */
if ( tl ) VIEW(tl)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_RIGHT|TX_ALIGN_FIXEDY;
/* filename stattext */
if ( st_fname ) VIEW(st_fname)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_FIXEDX|TX_ALIGN_FIXEDY;
/* filetype stattext */
if ( st_ftype ) VIEW(st_ftype)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_FIXEDX|TX_ALIGN_FIXEDY;
OBJECT(desktop)->insert(OBJECT(desktop), OBJECT(w));
OBJECT(w)->insert(OBJECT(w), OBJECT(h));
OBJECT(w)->insert(OBJECT(w), OBJECT(b));
OBJECT(w)->insert(OBJECT(w), OBJECT(box));
OBJECT(w)->insert(OBJECT(w), OBJECT(tl));
OBJECT(w)->insert(OBJECT(w), OBJECT(d));
OBJECT(w)->insert(OBJECT(w), OBJECT(st_fname));
OBJECT(w)->insert(OBJECT(w), OBJECT(st_ftype));
//OBJECT(w)->insert(OBJECT(w), OBJECT(st_links));
if ( tl ) /* not directory, not line */
TEXTLINE(tl)->set_text(TEXTLINE(tl), file);
if ( desktop->execute_view(desktop, VIEW(w)) == MSG_OK ) {
l_text file1 = box?box->file:NULL;
l_text filename = tl?TEXTLINE(tl)->text:file1;
l_text pathname = box?box->path:NULL;
endfile = io_realpath(pathname, filename);
};
dispose(OBJECT(w));
};
return endfile;
};
void iodlg_init ( void ) {
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -