JBoolean JXChooseFileDialog::OKToDeactivate() { if (!JXCSFDialogBase::OKToDeactivate()) { return kJFalse; } else if (Cancelled()) { return kJTrue; } JXPathInput* pathInput = GetPathInput(); if (pathInput->HasFocus()) { GoToItsPath(); return kJFalse; } JXInputField* filterInput = GetFilterInput(); if (filterInput->HasFocus()) { AdjustFilter(); return kJFalse; } JXDirTable* fileBrowser = GetFileBrowser(); if (fileBrowser->GoToSelectedDirectory()) { return kJFalse; } JPtrArray<JDirEntry> entryList(JPtrArrayT::kDeleteAll); if (fileBrowser->GetSelection(&entryList)) { const JSize count = entryList.GetElementCount(); for (JIndex i=1; i<=count; i++) { JDirEntry* entry = entryList.NthElement(i); entry->ForceUpdate(); // check that link hasn't been broken behind our back if (!entry->IsFile()) { (GetDirInfo())->ForceUpdate(); return kJFalse; } } return kJTrue; } else { return kJFalse; } }
JBoolean JXSaveFileDialog::OKToDeactivate() { if (!JXCSFDialogBase::OKToDeactivate()) { return kJFalse; } else if (Cancelled()) { return kJTrue; } JXPathInput* pathInput = GetPathInput(); if (pathInput->HasFocus()) { GoToItsPath(); return kJFalse; } JXInputField* filterInput = GetFilterInput(); if (filterInput->HasFocus()) { AdjustFilter(); return kJFalse; } JXDirTable* fileBrowser = GetFileBrowser(); if (fileBrowser->HasFocus() && fileBrowser->GoToSelectedDirectory()) { return kJFalse; } const JString& fileName = itsFileNameInput->GetText(); if (fileName.IsEmpty()) { (JGetUserNotification())->ReportError("You need to enter a file name."); return kJFalse; } const JString& path = GetPath(); const JString fullName = path + fileName; const JBoolean fileExists = JFileExists(fullName); if (JDirectoryExists(fullName)) { (JGetUserNotification())->ReportError( "This name is already used for a directory."); return kJFalse; } else if (!JDirectoryWritable(path) && !fileExists) { (JGetUserNotification())->ReportError( "You are not allowed to write to this directory."); return kJFalse; } else if (!fileExists) { *itsFileName = fileName; return kJTrue; } else if (!JFileWritable(fullName)) { (JGetUserNotification())->ReportError( "You are not allowed to write to this file."); return kJFalse; } else if ((JGetUserNotification())->AskUserNo("That file already exists. Replace it?")) { *itsFileName = fileName; return kJTrue; } else { return kJFalse; } }