flu_file_chooser.cpp
来自「ncbi源码」· C++ 代码 · 共 2,471 行 · 第 1/5 页
CPP
2,471 行
} cd( FAVORITES_UNIQUE_STRING ); return; }#ifdef WIN32 SHFILEOPSTRUCT fileop; memset( &fileop, 0, sizeof(SHFILEOPSTRUCT) ); fileop.fFlags = FOF_SILENT | FOF_NOERRORUI | FOF_NOCONFIRMATION; if( recycle ) fileop.fFlags |= FOF_ALLOWUNDO; fileop.wFunc = FO_DELETE; fileop.pTo = NULL;#endif for( i = 0; i < g->children(); i++ ) { if( ((Entry*)g->child(i))->selected ) { int result = 0; name = currentDir + ((Entry*)g->child(i))->filename; // if directory, recursively remove if( ((Entry*)g->child(i))->type == ENTRY_DIR ) { // if we are recycling in windows, then the recursive part happens automatically#ifdef WIN32 if( !recycle )#endif { Fl_Group::current(0); Fl_Window *win = new Fl_Window( 200, 100, "Notice" ); Flu_Label *label = new Flu_Label( 30, 30, 150, 30, "Preparing to delete..." ); win->end(); win->show(); Fl::check(); // recursively build a list of all files that will be deleted StringVector files; recursiveScan( name.c_str(), &files ); // delete all the files label->label( "Deleting files..." ); for( unsigned int i = 0; i < files.size(); i++ ) { //printf( "%s\n", files[i].c_str() ); if( ::remove( files[i].c_str() ) != 0 ) { win->hide(); delete win; cd( "./" ); return; } } win->hide(); delete win; Fl::check(); continue; } }#ifdef WIN32 // this moves files to the recycle bin, depending on the value of 'recycle' { int len = name.size(); char *buf = (char*)malloc( len+2 ); strcpy( buf, name.c_str() ); buf[len+1] = '\0'; // have to have 2 '\0' at the end fileop.pFrom = buf; result = SHFileOperation( &fileop ); free( buf ); }#else result = ::remove( name.c_str() );#endif // if remove fails, report an error if( result != 0 ) { fl_alert( "An error ocurred while trying to delete '%s'.", name.c_str() ); cd( "./" ); return; } } } // refresh this directory cd( "./" ); }}void Flu_File_Chooser :: filesystemsCB( const char *path ){ //printf( "filesystems: %s\n", path );#ifdef WIN32 FluSimpleString p = path; if( p == "/Favorites/" ) favoritesCB(); else if( p == "/Desktop/My Computer/" ) myComputerCB(); else if( p == "/Desktop/My Documents/" ) documentsCB(); else if( p == "/Desktop/" ) desktopCB(); // if the path leads off with "/Desktop/My Computer", then strip that part off and cd // to the remaining else if( strstr( path, "/Desktop/My Computer/" ) == path ) { // seach for '(' and if present, extract the drive name and cd to it char *paren = strrchr( path, '(' ); if( paren ) { char drive[] = "A:/"; drive[0] = paren[1]; cd( drive ); } else { cd( path+21 ); } }#else cd( path );#endif}void Flu_File_Chooser :: favoritesCB(){ cd( FAVORITES_UNIQUE_STRING );}void Flu_File_Chooser :: myComputerCB(){ cd( "/" );}void Flu_File_Chooser :: documentsCB(){#ifdef WIN32 FluSimpleString s = userHome + "My Documents"; cd( s.c_str() );#else cd( "/tmp/" );#endif}Flu_File_Chooser :: FileInput :: FileInput( int x, int y, int w, int h, const char *l, Flu_File_Chooser *c ) : Fl_Input( x, y, w, h, l ){ chooser = c;}Flu_File_Chooser :: FileInput :: ~FileInput(){}int Flu_File_Chooser :: FileInput :: handle( int event ){ if( event == FL_KEYDOWN ) { if( Fl::event_key(FL_Tab) ) { chooser->filenameTabCallback = true; FluSimpleString v(value());#ifdef WIN32 // turn "c:" into "c:\" if( v.size() >= 2 ) if( v[1] == ':' && v[2] == '\0' ) { v += "/"; value( v.c_str() ); position( size(), size() ); }#endif chooser->delayedCd = v + "*"; Fl::add_timeout( 0.0f, Flu_File_Chooser::delayedCdCB, chooser ); return 1; } else if( Fl::event_key(FL_Left) ) { if( Fl_Input::position() == 0 ) return 1; else return Fl_Input::handle( event ); } else if( Fl::event_key(FL_Right) ) { if( Fl_Input::position() == (int)strlen(Fl_Input::value()) ) return 1; else return Fl_Input::handle( event ); } else if( Fl::event_key(FL_Up) || Fl::event_key(FL_Down) ) { chooser->getEntryContainer()->take_focus(); if( !chooser->lastSelected ) { if( chooser->getEntryGroup()->children() ) { Flu_File_Chooser::Entry *e = (Flu_File_Chooser::Entry*)chooser->getEntryGroup()->child(0); e->selected = true; chooser->lastSelected = e; e->redraw(); } } return chooser->getEntryContainer()->handle( event ); } } return Fl_Input::handle( event );}Flu_File_Chooser :: PreviewTile :: PreviewTile( int x, int y, int w, int h, Flu_File_Chooser *c ) : Fl_Tile( x, y, w, h ){ chooser = c;}int Flu_File_Chooser :: PreviewTile :: handle( int event ){ // if we're not in preview mode, then the user isn't allowed to resize the tile if( !chooser->previewBtn->value() ) return Fl_Group::handle( event ); if( event == FL_DRAG ) { // the user is probably dragging to resize the columns // update the sizes for each entry chooser->updateEntrySizes(); chooser->redraw(); } return Fl_Tile::handle(event);}Flu_File_Chooser :: PreviewWidgetBase :: PreviewWidgetBase() : Fl_Group( 0, 0, 0, 0 ){}Flu_File_Chooser :: PreviewWidgetBase :: ~PreviewWidgetBase(){}Flu_File_Chooser :: PreviewGroup :: PreviewGroup( int x, int y, int w, int h, Flu_File_Chooser *c ) : Fl_Group( x, y, w, h ){ box( FL_DOWN_BOX ); align( FL_ALIGN_CENTER | FL_ALIGN_CLIP ); labelsize( 60 ); labelfont( FL_HELVETICA ); chooser = c; handled = 0;}void Flu_File_Chooser :: PreviewGroup :: draw(){ if( !chooser->previewBtn->value() ) return; if( file.size() == 0 ) return; FILE *f = fopen( file.c_str(), "rb" ); if( !f ) { label( "" ); Fl_Group::draw(); return; } fclose( f ); if( lastFile != file ) { lastFile = file; handled = 0; PreviewWidgetBase *next; for( int i = chooser->previewHandlers.size()-1; i >= 0; i-- ) { next = chooser->previewHandlers[i]; next->hide(); if( !handled ) { Fl_Group *p = next->parent(); Fl_Group::add( next ); if( next->preview( file.c_str() ) != 0 ) { next->show(); handled = next; } Fl_Group::remove( *next ); if( p ) p->add( next ); } } } if( handled == 0 ) { label( "?" ); Fl_Group::draw(); } else { label( "" ); Fl_Group *p = handled->parent(); Fl_Group::add( handled ); handled->resize( x()+Fl::box_dx(box()), y()+Fl::box_dy(box()), w()-Fl::box_dw(box()), h()-Fl::box_dh(box()) ); Fl_Group::draw(); Fl_Group::remove( *handled ); if( p ) p->add( handled ); }}// adapted from Fl_File_Chooser2.cxx : update_preview()int Flu_File_Chooser :: ImgTxtPreview :: preview( const char *filename ){ Fl_Shared_Image *img, // New image *oldimg; // Old image int pbw, pbh; // Width and height of preview box int w, h; // Width and height of preview image window()->cursor( FL_CURSOR_WAIT ); Fl::check(); img = Fl_Shared_Image::get( filename ); if( img ) { window()->cursor( FL_CURSOR_DEFAULT ); Fl::check(); } oldimg = (Fl_Shared_Image*)image(); if( oldimg ) oldimg->release(); image(0); if( !img ) { // Try reading the first 1k of data for a label... FILE *f = fopen( filename, "rb" ); if( f ) { int bytes = fread( previewTxt, 1, sizeof(previewTxt) - 1, f ); previewTxt[bytes] = '\0'; fclose( f ); } else return 0; window()->cursor( FL_CURSOR_DEFAULT ); Fl::check(); // Scan the buffer for printable chars... unsigned char *ptr; for( ptr = previewTxt; *ptr && (isprint(*ptr) || isspace(*ptr)); ptr++ ) {} if( *ptr || ptr == previewTxt ) { // Non-printable file - can't handle return 0; } else { // Show the first 1k of text... label( (const char*)previewTxt ); align((Fl_Align)(FL_ALIGN_CLIP | FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_TOP)); labelsize( 12 ); labelfont( FL_COURIER ); } } else if( img->w() > 0 && img->h() > 0 ) { pbw = this->w() - 20; pbh = this->h() - 20; pbw = (pbw < 10) ? 10 : pbw; pbh = (pbh < 10) ? 10 : pbh; if( img->w() > pbw || img->h() > pbh ) { w = pbw; h = int(float(w*img->h()) / float(img->w())); if( h > pbh ) { h = pbh; w = int(float(h*img->w()) / float(img->h())); } oldimg = (Fl_Shared_Image *)img->copy(w, h); image((Fl_Image *)oldimg); img->release(); } else image((Fl_Image *)img); align( FL_ALIGN_CLIP ); label(0); } redraw(); return 1;}void Flu_File_Chooser :: previewCB(){ if( previewBtn->value() ) { fileGroup->resize( fileGroup->x(), fileGroup->y(), previewTile->last-fileGroup->x(), fileGroup->h() ); previewGroup->resize( previewTile->last, previewGroup->y(), previewTile->w()-fileGroup->w(), previewGroup->h() ); previewGroup->show(); } else { previewTile->last = previewGroup->x(); fileGroup->resize( fileGroup->x(), fileGroup->y(), previewTile->w(), fileGroup->h() ); previewGroup->resize( previewTile->x()+previewTile->w(), previewGroup->y(), 0, previewGroup->h() ); previewGroup->hide(); } previewGroup->redraw(); previewTile->init_sizes(); //filescroll->parent()->init_sizes(); fileDetailsGroup->parent()->init_sizes(); updateEntrySizes(); redraw();}void Flu_File_Chooser :: sortCB( Fl_Widget *w ){ // if the sort method is already selected, toggle the REVERSE bit if( w == detailNameBtn ) { if( sortMethod & SORT_NAME ) sortMethod ^= SORT_REVERSE; else sortMethod = SORT_NAME; } else if( w == detailSizeBtn ) { if( sortMethod & SORT_SIZE ) sortMethod ^= SORT_REVERSE; else sortMethod = SORT_SIZE; } else if( w == detailDateBtn ) { if( sortMethod & SORT_DATE ) sortMethod ^= SORT_REVERSE; else sortMethod = SORT_DATE; } else if( w == detailTypeBtn ) { if( sortMethod & SORT_TYPE ) sortMethod ^= SORT_REVERSE; else sortMethod = SORT_TYPE; } bool reverse = ( sortMethod & SORT_REVERSE ); detailNameBtn->label( "Name" ); detailSizeBtn->label( "Size" ); detailDateBtn->label( "Date" ); detailTypeBtn->label( "Type" ); switch( sortMethod & ~SORT_REVERSE ) { case SORT_NAME: detailNameBtn->label( reverse?"@-12DnArrow Name":"@-18UpArrow Name" ); break; case SORT_SIZE: detailSizeBtn->label( reverse?"@-12DnArrow Size":"@-18UpArrow Size" ); break; case SORT_DATE: detailDateBtn->label( reverse?"@-12DnArrow Date":"@-18UpArrow Date" ); break; case SORT_TYPE: detailTypeBtn->label( reverse?"@-12DnArrow Type":"@-18UpArrow Type" ); break; } filelist->sort(); filedetails->sort();}Flu_File_Chooser :: CBTile :: CBTile( int x, int y, int w, int h, Flu_File_Chooser *c ) : Fl_Tile( x, y, w, h ){ chooser = c;}int Flu_File_Chooser :: CBTile :: handle( int event ){ if( event == FL_DRAG ) { // the user is probably dragging to resize the columns // update the sizes for each entry chooser->updateEntrySizes(); chooser->redraw(); } return Fl_Tile::handle(event);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?