JColorIndex JXFileInput::GetTextColor ( const JCharacter* fileName, const JCharacter* basePath, const JBoolean requireRead, const JBoolean requireWrite, const JBoolean requireExec, const JColormap* colormap ) { if (JStringEmpty(fileName)) { return colormap->GetBlackColor(); } JString fullName; if ((!JIsRelativePath(fileName) || !JStringEmpty(basePath)) && JConvertToAbsolutePath(fileName, basePath, &fullName) && (!requireRead || JFileReadable(fullName)) && (!requireWrite || JFileWritable(fullName)) && (!requireExec || JFileExecutable(fullName))) { return colormap->GetBlackColor(); } else { return colormap->GetRedColor(); } }
JBoolean JXFileInput::InputValid() { if (itsAllowInvalidFileFlag) { return kJTrue; } else if (!JXInputField::InputValid()) { return kJFalse; } const JString& text = GetText(); if (text.IsEmpty()) { return JNegate(IsRequired()); } JString fullName; const JCharacter* errID = NULL; if (JIsRelativePath(text) && !HasBasePath()) { errID = kNoRelPathID; RecalcAll(kJTrue); } else if (!JConvertToAbsolutePath(text, itsBasePath, &fullName) || !JFileExists(fullName)) { errID = kDoesNotExistID; } else if (itsRequireReadFlag && !JFileReadable(fullName)) { errID = kUnreadableID; } else if (itsRequireWriteFlag && !JFileWritable(fullName)) { errID = kUnwritableID; } else if (itsRequireExecFlag && !JFileExecutable(fullName)) { errID = kCannotExecID; } if (JStringEmpty(errID)) { return kJTrue; } else { (JGetUserNotification())->ReportError(JGetString(errID)); return kJFalse; } }
JBoolean JXFileInput::GetFile ( JString* fullName ) const { const JString& text = GetText(); return JI2B(!text.IsEmpty() && (!JIsRelativePath(text) || HasBasePath()) && JConvertToAbsolutePath(text, itsBasePath, fullName) && JFileExists(*fullName) && (!itsRequireReadFlag || JFileReadable(*fullName)) && (!itsRequireWriteFlag || JFileWritable(*fullName)) && (!itsRequireExecFlag || JFileExecutable(*fullName))); }
void JEditVCS ( const JCharacter* fullName ) { if (JFileExists(fullName) && !JFileWritable(fullName)) { JString path, name; JSplitPathAndName(fullName, &path, &name); JString vcsDir = JCombinePathAndName(path, kCVSDirName); if (JDirectoryExists(vcsDir)) { const JString cmd = "cd " + path + "; cvs edit " + name; system(cmd); } } }
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; } }
void ParseOptions ( const JSize argc, char* argv[], JString* fileName, JBoolean* printInfo, int* transparentColor, LaceOption* interlace, JBoolean* padColormap, JBoolean* blend, JFloat* alpha, JRGB* alphaColor, JString* blendOutput ) { if (argc == 1) { PrintHelp(); exit(0); } fileName->Clear(); *printInfo = kJFalse; *transparentColor = kTransparentColorNotSet; *interlace = kIgnoreInterlace; *padColormap = kJFalse; *blend = kJFalse; JIndex index = 1; while (index < argc) { if (strcmp(argv[index], "-h") == 0 || strcmp(argv[index], "--help") == 0) { PrintHelp(); exit(0); } else if (strcmp(argv[index], "-v") == 0 || strcmp(argv[index], "--version") == 0) { PrintVersion(); exit(0); } else if (strcmp(argv[index], "-i") == 0) { *printInfo = kJTrue; } else if (strcmp(argv[index], "-t") == 0) { JCheckForValues(1, &index, argc, argv); if (strcmp(argv[index], "none") == 0) { *transparentColor = kNoTransparentColor; } else if ('0' <= argv[index][0] && argv[index][0] <= '9') { *transparentColor = atoi(argv[index]); } else { cerr << argv[0] << ": -t requires a number or none" << endl; exit(1); } } else if (strcmp(argv[index], "-l") == 0) { JCheckForValues(1, &index, argc, argv); if (strcmp(argv[index], "on") == 0) { *interlace = kTurnInterlaceOn; } else if (strcmp(argv[index], "off") == 0) { *interlace = kTurnInterlaceOff; } else { cerr << argv[0] << ": -l requires either on or off" << endl; exit(1); } } else if (strcmp(argv[index], "-p") == 0) { *padColormap = kJTrue; } else if (strcmp(argv[index], "-b") == 0) { JCheckForValues(5, &index, argc, argv); *blend = kJTrue; *alpha = atof(argv[index]); alphaColor->red = atoi(argv[index+1]); alphaColor->green = atoi(argv[index+2]); alphaColor->blue = atoi(argv[index+3]); *blendOutput = argv[index+4]; index += 4; } else if (argv[index][0] == '-') { cerr << argv[0] << ": unknown option " << argv[index] << endl; exit(1); } else if (fileName->IsEmpty()) { if (!JFileReadable(argv[index])) { cerr << argv[0] << ": file is unreadable" << endl; exit(1); } if (!JFileWritable(argv[index])) { cerr << argv[0] << ": file is unwriteable" << endl; exit(1); } *fileName = argv[index]; } else { cerr << argv[0] << ": too many parameters" << endl; exit(1); } index++; } if (fileName->IsEmpty()) { cerr << argv[0] << ": no input file specified" << endl; exit(1); } if (argc == 2) { *printInfo = kJTrue; } }
void JXFileInput::AdjustStylesBeforeRecalc ( const JString& buffer, JRunArray<Font>* styles, JIndexRange* recalcRange, JIndexRange* redrawRange, const JBoolean deletion ) { const JColormap* colormap = GetColormap(); const JSize totalLength = buffer.GetLength(); JString fullName = buffer; if ((JIsRelativePath(buffer) && !HasBasePath()) || !JExpandHomeDirShortcut(buffer, &fullName)) { fullName.Clear(); } // Last clause because if JConvertToAbsolutePath() succeeds, we don't // want to further modify fullName. else if (JIsRelativePath(buffer) && !JConvertToAbsolutePath(buffer, itsBasePath, &fullName)) { if (HasBasePath()) { fullName = JCombinePathAndName(itsBasePath, buffer); } else { fullName.Clear(); } } JSize errLength; if (fullName.IsEmpty()) { errLength = totalLength; } else if (!JFileExists(fullName) || (itsRequireReadFlag && !JFileReadable(fullName)) || (itsRequireWriteFlag && !JFileWritable(fullName)) || (itsRequireExecFlag && !JFileExecutable(fullName))) { const JString closestDir = JGetClosestDirectory(fullName, kJFalse); if (fullName.BeginsWith(closestDir)) { errLength = fullName.GetLength() - closestDir.GetLength(); } else { errLength = totalLength; } } else { errLength = 0; } if (errLength > 0 && buffer.EndsWith(kThisDirSuffix)) { errLength++; // trailing . is trimmed } Font f = styles->GetFirstElement(); styles->RemoveAll(); if (errLength >= totalLength) { f.style.color = colormap->GetRedColor(); styles->AppendElements(f, totalLength); } else { f.style.color = colormap->GetBlackColor(); styles->AppendElements(f, totalLength - errLength); if (errLength > 0) { f.style.color = colormap->GetRedColor(); styles->AppendElements(f, errLength); } } *redrawRange += JIndexRange(1, totalLength); }