void OpMenuSave::Do(OpDescriptor* pOpDesc) { //First get the selected document Document* pdocToSave=Document::GetSelected(); CCamDoc* pccamdocToSave = pdocToSave->GetOilDoc(); if (pdocToSave==NULL || pccamdocToSave==NULL) { ERROR2RAW("No default document!"); return; } //And we'll need a pointer to the application Application* pCamelot = GetApplication(); CTemplateManager& TemplateManager( pCamelot->GetTemplateManager() ); //And put the default templates path in the dialog PathName pathToPutInDialog = TemplateManager.GetTemplatesPath(); FileUtil::RecursiveCreateDirectory( pathToPutInDialog.GetPath() ); //Now create the dialog SaveTemplateDialog dialogToDisplay(pathToPutInDialog); //And show it if (dialogToDisplay.ShowModal() == wxID_OK) { //Then get the path they specified, using this amazingly bad, confusing and //undocumented file dialog code //The "CString" reference should ideally go in Winoil PathName pathToSaveTo; dialogToDisplay.GetChosenFileName(&pathToSaveTo); wxString cstrPathToSaveTo=pathToSaveTo.GetPath(FALSE); dialogToDisplay.AppendExtension(&cstrPathToSaveTo); String_256 strPathToSaveTo=cstrPathToSaveTo; pathToSaveTo=strPathToSaveTo; // Create the save file. CCDiskFile file(pathToSaveTo, ios::out | ios::binary | ios::trunc); // First find the filter. Filter *pFilter = FindFilter ( FILTERID_NATIVE ); // Tell it to save attributes. pFilter->SetSaveAttributes ( TRUE ); // Then save the image to the file. Save ( pFilter, &file ); //Now, if we should make that path the default path if (SaveTemplateDialog::m_fUseAsDefault) { if (pdocToSave->IsAnimated()) { CTemplateManager::SetDefaultAnimationTemplate( strPathToSaveTo ); } else { CTemplateManager::SetDefaultDrawingTemplate( strPathToSaveTo ); } } if (SaveTemplateDialog::m_fDefaultTemplatesFolder) { String_256 strDefaultPath = pathToSaveTo.GetLocation( TRUE ); CTemplateManager::SetTemplatesPath( strDefaultPath ); } } // Finished the operation End(); }