📄 zgv.c
字号:
} tagview_mode=0; if(sgres>=2) { if(load_single_file(curent,0)==0) pic_incr=0; } else if(load_single_file(curent,1)==0) pic_incr=0; if(sgres==3) gifdir[curent].marked=1; if(pic_incr!=PIC_INCR_RELOAD_KLUDGE) curent+=pic_incr; if(curent>gifdirsiz) curent--,pic_incr=0; if(curent<1 || gifdir[curent].isdir) curent++,pic_incr=0; oldstart=startfrom; fix_startfrom(curent,&startfrom); if(sgres<2 || pic_incr==0) { oldent=-1; restore_mouse_pos_with_size(fs_scrnwide,fs_scrnhigh); redrawall(curent,startfrom); } else { /* if we're *not* redrawing the selector, restore given * current (viewer) screen's size. */ restore_mouse_pos(); } } while(pic_incr); /* make sure we fix mouse pos for selector screen */ restore_mouse_pos_with_size(fs_scrnwide,fs_scrnhigh); break; case '\t': /* tab */ if(load_tagged_files()) /* rets non-zero if needs redraw */ redrawall(curent,startfrom); break; case ':': /* give full filename, for you nethack fans :-) */ case ';': /* (also allow semicolon, might as well) */ file_details(gifdir[curent].name,0,0,NULL); break; case 'W': if(cfg.stupid_gnu_verbosity) { gnu_warranty_help(zgv_ttyfd); redrawall(curent,startfrom); } break; case 'x': case RK_ESC: quit=1; } /* end of switch(key) */ oldstart=startfrom; fix_startfrom(curent,&startfrom); if(startfrom!=oldstart) { showbar(oldent,0,oldstart); showgifdir(oldstart,1,0,0); showgifdir(startfrom,0,0,0); showbar(curent,1,startfrom); } else if(oldent!=-1 && (curent!=oldent || markchange)) { showbar(oldent,0,startfrom); showbar(curent,1,startfrom); } }}void fix_startfrom(int curent,int *startfromp){int startfrom=*startfromp;while(curent<startfrom) startfrom-=YSIZ;while(fwinxpos(curent-startfrom+1)+BARWIDTH>XENDPOS) startfrom+=YSIZ;if(startfrom<1) startfrom=1;*startfromp=startfrom;}/* returns non-zero if we need to update the screen */int rename_file(int curent,int startfrom){static char prompt[256];char *dest;struct stat sbuf;char *tn_src,*tn_dst;snprintf(prompt,sizeof(prompt),"Rename %s to what?",gifdir[curent].name);dest=cm_getline(zgv_ttyfd,prompt, idx_light,idx_dark,idx_black,idx_medium);if(dest==NULL || *dest==0) return(0);/* refuse anything with path elements in */if(strchr(dest,'/')) { msgbox(zgv_ttyfd,"File must remain in current directory", MSGBOXTYPE_OK, idx_light,idx_dark,idx_black); return(0); }/* refuse the renaming if it would blast an existing file */if(stat(dest,&sbuf)!=-1) { msgbox(zgv_ttyfd,"File already exists", MSGBOXTYPE_OK,idx_light,idx_dark,idx_black); return(0); }if(rename(gifdir[curent].name,dest)==-1) { msgbox(zgv_ttyfd,"Couldn't rename file", MSGBOXTYPE_OK,idx_light,idx_dark,idx_black); return(0); }/* if it worked, rename the entry in gifdir[] and try renaming any * thumbnail. (XXX doesn't yet try to rename any ~/.xvpics/_foo_bar/baz one.) */tn_src=tn_dst=NULL;/* ".xvpics/" is 8 chars */if((tn_src=malloc(8+strlen(gifdir[curent].name)+1))==NULL || (tn_dst=malloc(8+strlen(dest)+1))==NULL) { write_gifdir_name(curent,dest); /* do the name copy */ if(tn_src) free(tn_src); return(1); /* not a big deal failing to rename thumbnail */ }strcpy(tn_src,".xvpics/");strcat(tn_src,gifdir[curent].name);strcpy(tn_dst,".xvpics/");strcat(tn_dst,dest);rename(tn_src,tn_dst); /* don't much care if it works or not */free(tn_dst);free(tn_src);write_gifdir_name(curent,dest); /* finally, do the name copy */return(1);}/* save old contents of area to put right-button menu on, and draw it. */static void draw_rb_menu(){int fs256=(fs_vgamode!=G640x480x16);int f;rbm_xysize(filesel_menu_data,&rb_save_width,&rb_save_height);if((rb_save=malloc(rb_save_width*rb_save_height))==NULL) return;if(fs256) { /* use vgagl */ gl_setcontextvga(fs_vgamode); gl_getbox(fs_scrnwide-rb_save_width,0, rb_save_width,rb_save_height,rb_save); }else { /* 16-colour, use vga_getscansegment */ unsigned char *ptr=rb_save; int y; for(y=0;y<rb_save_height;y++,ptr+=rb_save_width) vga_getscansegment(ptr,640-rb_save_width,y,rb_save_width); }/* grey out (make non-active) any ones we shouldn't allow. * this is nasty, but decl of filesel_menu_data notes that there's * a nasty thing here, so it should be ok. */for(f=2;f<6;f++) filesel_menu_data[f].active=0;if(fs_vgamode!=G640x480x16) { f=2; filesel_menu_data[f++].active= (vga_hasmode(G640x480x256) && cfg.mode_allowed[G640x480x256]); filesel_menu_data[f++].active= (vga_hasmode(G800x600x256) && cfg.mode_allowed[G800x600x256]); filesel_menu_data[f++].active= (vga_hasmode(G1024x768x256) && cfg.mode_allowed[G1024x768x256]); filesel_menu_data[f++].active= (vga_hasmode(G1280x1024x256) && cfg.mode_allowed[G1280x1024x256]); }/* only other one which matters is grey/colour, which only means * anything when using 16-col file selector with thumbnails on. */rbm_set_active_flag(filesel_menu_data,"grey/colour", (!fs256 && cfg.xvpic_index));/* now draw the thing */rbm_draw(filesel_menu_data,idx_light,idx_medium,idx_dark,idx_black);}/* restore old contents of area with right-button menu on. */static void undraw_rb_menu(){if(rb_save==NULL) return; /* ran out of memory, can't do much! */if(fs_vgamode!=G640x480x16) { /* use vgagl again */ gl_putbox(fs_scrnwide-rb_save_width,0, rb_save_width,rb_save_height,rb_save); }else { /* 16-colour */ unsigned char *ptr=rb_save; int y; for(y=0;y<rb_save_height;y++,ptr+=rb_save_width) vga_drawscansegment(ptr,640-rb_save_width,y,rb_save_width); }free(rb_save);}/* possibly have a mouse event to deal with for right-button menu. * uses pointer to key to fake keys to do stuff, and returns * 1 if we should stay in rb menu mode, else 0. */static int rb_menu_event(int *keyp){/* important to read both, even if not using both */int mleft=is_end_click_left(),mright=is_end_click_right();int key;if(!mleft) return(1);if(rb_ignore_first_left_click) { rb_ignore_first_left_click=0; return(1); }key=mright; /* a kludge to keep gcc -Wall quiet *//* get faked key for filesel_menu_data, or zero if none */*keyp=0;key=rbm_mousepos_to_key(filesel_menu_data,mouse_getx(),mouse_gety());if(key!=-1) /* -1 means quit menu with no key */ *keyp=key;return((key==0)); /* 1 if didn't match any, else 0 */}/* add new pastpos[0], shifting down all the rest of the entries. */void new_pastpos(int curent,int startfrom){struct stat sbuf;int f;if(cfg.forgetoldpos) return;for(f=MPPOSSIZ-1;f>0;f--) { pastpos[f].dev =pastpos[f-1].dev; pastpos[f].inode =pastpos[f-1].inode; pastpos[f].curent =pastpos[f-1].curent; pastpos[f].startfrom=pastpos[f-1].startfrom; }if(stat(".",&sbuf)==-1) return;pastpos[0].dev =sbuf.st_dev;pastpos[0].inode =sbuf.st_ino;pastpos[0].curent =curent;pastpos[0].startfrom=startfrom;}/* return curent from pastpos[] entry matching current directory, * or if none match return 1. */void get_pastpos(int *curentp,int *startfromp){struct stat sbuf;int f;*curentp=*startfromp=1;if(cfg.forgetoldpos || stat(".",&sbuf)==-1) return;for(f=0;f<MPPOSSIZ;f++) if(pastpos[f].inode==sbuf.st_ino && pastpos[f].dev==sbuf.st_dev) { *curentp=pastpos[f].curent; *startfromp=pastpos[f].startfrom; return; }}/* loads/views one file. caller must do the restore_mouse_pos. */int load_single_file(int curent,int do_howfar){int tmp;if(do_howfar) inithowfar(HOWFAR_LOADING_MSG);vga_runinbackground(1);/* save context for possible abort */if(setjmp(setjmpbuf)) { /* if we get here, someone aborted loading a file. */ if(!tagview_mode || (tagview_mode && do_howfar)) { wait_for_foreground(); msgbox(zgv_ttyfd,"File view aborted",MSGBOXTYPE_OK, idx_light,idx_dark,idx_black); } return(0); }else { if((tmp=readpicture(gifdir[curent].name, do_howfar?showhowfar:smallhowfar,1, 0,NULL,NULL))!=_PIC_OK) { wait_for_foreground(); if(tagview_mode) screenon(); showerrmessage(tmp); return(0); } }return(1);}/* returns non-zero if we need to redraw the selector */int load_tagged_files(void){/* are f and dohf *really* endangered by the possible longjmp back to * load_single_file()? Still, playing it safe... */static int f,dohf;int t,ent;for(f=1,t=0;f<=gifdirsiz;f++) if(gifdir[f].marked) t++;if(t==0) { msgbox(zgv_ttyfd,"No files tagged",MSGBOXTYPE_OK, idx_light,idx_dark,idx_black); return(0); }/* vgadisp.c sets tagview_mode==0 if esc is pressed */tagview_mode=1;dohf=1;/* we do our own mouse pos save, in case showgif() isn't run */save_mouse_pos();do { if(!make_slideshow_idx_array()) { /* this will only happen if memory is VERY tight, as it's quite * a small array... */ msgbox(zgv_ttyfd,"Out of memory", MSGBOXTYPE_OK,idx_light,idx_dark,idx_black); return(!msgbox_draw_ok); } if(cfg.shuffleslideshow) shuffle_slideshow_idx(); for(f=0;f<slideshow_idx_size && tagview_mode;f++) { ent=slideshow_idx[f]; if(permissiondenied(gifdir[ent].name)) { msgbox(zgv_ttyfd,"Permission denied or file not found", MSGBOXTYPE_OK,idx_light,idx_dark,idx_black); free(slideshow_idx); return(!msgbox_draw_ok); } if(load_single_file(ent,dohf)==0) break; dohf=0; /* restore mouse pos ready for it to be saved again */ restore_mouse_pos(); } free(slideshow_idx); }while(cfg.loop && sgres!=1);/* make sure we fix mouse pos for selector screen */restore_mouse_pos_with_size(fs_scrnwide,fs_scrnhigh);return(1); /* need redraw */}void delete_gifdir_element(int n){if(n<1 || n>gifdirsiz) return;/* if not last, need to move further elements up */if(n<gifdirsiz) memmove(gifdir+n,gifdir+n+1, sizeof(struct gifdir_tag)*(gifdirsiz-n));gifdirsiz--;}void copymovedel_file_or_tagged_files(int curent,int remove_from_array, int no_dir_prompt, int (*func_ptr)(char *,char *), char *msg_action,char *msg_acting, char *msg_acted,char *msg_howfar){static char buf[256]; /* must be static to survive longjmp */static int fakemark,fakegone; /* same here */static char *msg_action_sav; /* and here, I think *//* gcc -Wall wants the next two non-auto, too, but in reality they don't * actually have to be. */static int t; static char *dest;int f,done;struct stat sbuf;msg_action_sav=msg_action;fakemark=fakegone=0;dest=NULL;t=tagged_count();if(t==0 && gifdir[curent].isdir) { msgbox(zgv_ttyfd,"No files tagged and cursor not on a file",MSGBOXTYPE_OK, idx_light,idx_dark,idx_black); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -