void ImageFieldEditor::openCreateHandler(void) { //Have the user select the file to import std::vector<WindowEventProducer::FileDialogFilter> Filters; std::list< const Char8 * > ReadableImageSuff; ImageFileHandler::the()->getSuffixList(ReadableImageSuff, ImageFileType::OSG_READ_SUPPORTED); //Determine all of the readable image filetypes Filters.push_back(WindowEventProducer::FileDialogFilter("All Image filetypes","")); std::string AllImageSuffixes; std::string AllImageSuffixesDesc("All Image filetypes ("); for(std::list<const Char8*>::const_iterator SuffixItor(ReadableImageSuff.begin()) ; SuffixItor != ReadableImageSuff.end() ; ++SuffixItor) { if(ImageFileHandler::the()->getFileType(*SuffixItor)) { if(!AllImageSuffixes.empty()) { AllImageSuffixes += ","; AllImageSuffixesDesc += ", "; } AllImageSuffixes += *SuffixItor; AllImageSuffixesDesc = AllImageSuffixesDesc + "*." + *SuffixItor; Filters.push_back(WindowEventProducer::FileDialogFilter(std::string(ImageFileHandler::the()->getFileType(*SuffixItor)->getMimeType()) + " (*." + *SuffixItor + ")",*SuffixItor)); } } AllImageSuffixesDesc += ")"; Filters[0] = WindowEventProducer::FileDialogFilter(AllImageSuffixesDesc,AllImageSuffixes); Filters.push_back(WindowEventProducer::FileDialogFilter("All (*.*)","*")); std::vector<BoostPath> FilesToOpen; FilesToOpen = getParentWindow()->getParentDrawingSurface()->getEventProducer()->openFileDialog("Import a image file.", Filters, BoostPath("."), false); ImageRefPtr NewImage = NULL; if(FilesToOpen.size() > 0) { //Try loading the file using the ImageFileHandler NewImage = ImageFileHandler::the()->read(FilesToOpen[0].string().c_str()); if(NewImage) { FilePathAttachment::setFilePath(NewImage, FilesToOpen[0]); //Set the value of the field SetFieldValueCommandPtr SetCommand = SetFieldValueCommand::create(getEditingFC(), getEditingFieldId(), boost::lexical_cast<std::string>(NewImage->getId()), getEditingFieldIndex()); getCommandManager()->executeCommand(SetCommand); } } }
std::vector<std::string> FCFileHandlerBase::getSuffixList(UInt32 flags) const { std::vector<std::string> FileTypesResult; for(FileTypeMap::const_iterator MapItor(_SuffixTypeMap.begin()) ; MapItor != _SuffixTypeMap.end() ; ++MapItor) { for(FileTypeVector::const_iterator VecItor(MapItor->second.begin()) ; VecItor != MapItor->second.end() ; ++VecItor) { if((*VecItor)->getFlags() & flags) { std::vector<std::string> Suffixes((*VecItor)->getSuffixList()); for(std::vector<std::string>::const_iterator SuffixItor(Suffixes.begin()) ; SuffixItor<Suffixes.end() ; ++SuffixItor) { FileTypesResult.push_back(*SuffixItor); } } } } return FileTypesResult; }