// modified from doccore.cpp BOOL CBonfireDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace) // Save the document data to a file // lpszPathName = path name where to save document file // if lpszPathName is NULL then the user will be prompted (SaveAs) // note: lpszPathName can be different than 'm_strPathName' // if 'bReplace' is TRUE will change file name if successful (SaveAs) // if 'bReplace' is FALSE will not change path name (SaveCopyAs) { CString newName = lpszPathName; if (newName.IsEmpty()) { CDocTemplate* pTemplate = GetDocTemplate(); ASSERT(pTemplate != NULL); newName = m_strPathName; if (bReplace && newName.IsEmpty()) { newName = m_strTitle; // check for dubious filename int iBad = newName.FindOneOf(_T(" #%;/\\")); if (iBad != -1) newName.ReleaseBuffer(iBad); // append the default suffix if there is one CString strExt; if (pTemplate->GetDocString(strExt, CDocTemplate::filterExt) && !strExt.IsEmpty()) { ASSERT(strExt[0] == '.'); newName += strExt; } } if (SaveFileDialog(AfxGetMainWnd(),newName,newName,NULL, GetFileFilter(FILTER_FILES),6,GetDefExt(FILTER_FILES)) <= 0) return FALSE; // don't even attempt to save } CWaitCursor wait; if (!OnSaveDocument(newName)) { if (lpszPathName == NULL) { // be sure to delete the file TRY { CFile::Remove(newName); } CATCH_ALL(e) { TRACE0("Warning: failed to delete file after failed SaveAs.\n"); do { e->Delete(); } while (0); //DELETE_EXCEPTION(e); } END_CATCH_ALL } return FALSE; }
void Frame::OnOpen(wxCommandEvent& event) { if (!m_task) return; try { wxFileDialog dlg(this, wxT("Open"), wxEmptyString, wxEmptyString, GetFileFilter(), wxFD_OPEN); if (dlg.ShowModal() == wxID_OK) { OpenFile(dlg.GetPath().ToStdString()); } } catch (Exception& e) { ExceptionDlg dlg(this, e); dlg.ShowModal(); } }
void Frame::OnSaveAs(wxCommandEvent& event) { if (!m_task) return; try { wxFileDialog dlg(this, wxT("Save"), wxEmptyString, wxEmptyString, GetFileFilter(), wxFD_SAVE); if (dlg.ShowModal() == wxID_OK) { std::string fixed = FileHelper::GetFilenameAddTag(dlg.GetPath().ToStdString(), m_filetag, "json"); EditedFileStack::Instance()->SetBottom(fixed); m_task->Store(fixed.c_str()); } } catch (Exception& e) { ExceptionDlg dlg(this, e); dlg.ShowModal(); } }
void DlgController::SelectFile (SourceType type) { FileGetter browser; browser.SetFilter (GetFileFilter (type)); if (browser.GetExistingFile (_hWnd, "Select a source file")) { char const * path = browser.GetPath (); _currentDir.Change (browser.GetDirectory ()); ListCurrentDir (); _editFile.SetText (browser.GetFileName ()); _painter.SetSource (type, path); } else { _wave.UnCheck (); _image.UnCheck (); _mike.Check (); _painter.SetSource (SRC_MIKE); } ReInit (); }
void Frame::OnSaveAs(wxCommandEvent& event) { if (!m_task) return; try { std::string filter = GetFileFilter(); std::string png_filter = "PNG files (*.png)|*.png"; filter += "|" + png_filter; wxFileDialog dlg(this, wxT("Save"), wxEmptyString, wxEmptyString, filter, wxFD_SAVE); if (dlg.ShowModal() == wxID_OK) { std::string filename = dlg.GetPath(); std::string ext = ee::FileHelper::GetExtension(filename); if (ext == "png") { SaveAsPNG(filename); } else { SaveAsJson(filename); } } } catch (ee::Exception& e) { ee::ExceptionDlg dlg(this, e); dlg.ShowModal(); } }
BOOL CToolsHelper::PrepareCmdline(const USERTOOL& tool, const USERTOOLARGS& args, CString& sToolPath, CString& sCmdline) { // do necessary substitutions CToolsCmdlineParser tcp(tool.sCmdline); CString sTasklist(args.sTasklist); if (tcp.HasTasklistArgument()) { // allow for no loaded file if (!FileMisc::FileExists(sTasklist)) { CPreferences prefs; CFileOpenDialog dialog(IDS_SELECTTASKLIST_TITLE, GetDefaultFileExt(), NULL, EOFN_DEFAULTOPEN, GetFileFilter()); if (dialog.DoModal(&prefs) != IDOK) return FALSE; sTasklist = dialog.GetPathName(); } CString sDrive, sPath, sFName, sExt; FileMisc::SplitPath(sTasklist, &sDrive, &sPath, &sFName, &sExt); tcp.ReplaceArgument(CLAT_PATHNAME, sTasklist); tcp.ReplaceArgument(CLAT_FOLDER, sDrive + sPath); tcp.ReplaceArgument(CLAT_FILENAME, sFName + sExt); tcp.ReplaceArgument(CLAT_FILETITLE, sFName); } tcp.ReplaceArgument(CLAT_TODOLIST, FileMisc::GetAppFilePath()); tcp.ReplaceArgument(CLAT_SELTASKID, args.sTaskIDs); tcp.ReplaceArgument(CLAT_SELTASKTITLE, args.sTaskTitle); tcp.ReplaceArgument(CLAT_SELTASKEXTID, args.sTaskExtID); tcp.ReplaceArgument(CLAT_SELTASKCOMMENTS, args.sTaskComments); tcp.ReplaceArgument(CLAT_SELTASKFILELINK, args.sTaskFileLink); tcp.ReplaceArgument(CLAT_SELTASKALLOCBY, args.sTaskAllocBy); tcp.ReplaceArgument(CLAT_SELTASKALLOCTO, args.sTaskAllocTo); CCLArgArray aCustomArgs; int nArg = tcp.GetCustomAttributeArguments(aCustomArgs); while (nArg--) { CString sAttribID(aCustomArgs[nArg].sName), sValue; args.mapTaskCustData.Lookup(sAttribID, sValue); tcp.ReplaceArgument(aCustomArgs[nArg].sPlaceHolder, sValue); } if (tcp.IsUserInputRequired()) { CToolsUserInputDlg dialog(tcp); if (dialog.DoModal(tool.sToolName) != IDOK) return FALSE; // process the results CCLArgArray aArgs; int nArg = tcp.GetUserArguments(aArgs); while (nArg--) { CString sResult(dialog.GetResult(aArgs[nArg].sName)); tcp.ReplaceArgument(aArgs[nArg].sName, sResult); } } sCmdline = tcp.GetCmdLine(); sToolPath = GetToolPath(tool); return TRUE; }