JXFileDocument::JXFileDocument
	(
	JXDirector*			supervisor,
	const JCharacter*	fileName,
	const JBoolean		onDisk,
	const JBoolean		wantBackupFile,
	const JCharacter*	defaultFileNameSuffix
	)
	:
	JXDocument(supervisor),
	itsFileSuffix(defaultFileNameSuffix),
	itsSaveBeforeClosePrompt(JGetString("SaveBeforeClosePrompt::JXFileDocument")),
	itsSaveNewFilePrompt(JGetString("SaveNewFilePrompt::JXFileDocument")),
	itsOKToRevertPrompt(JGetString("OKToRevertPrompt::JXFileDocument"))
{
	itsAllocateTitleSpaceFlag     = kJFalse;
	itsWantBackupFileFlag         = wantBackupFile;
	itsWantNewBackupEveryOpenFlag = kJTrue;
	itsAutosaveBeforeCloseFlag    = kJFalse;
	itsCSF                        = JGetChooseSaveFile();
	itsNeedSafetySaveFlag         = kJFalse;
	itsSafetySaveFileName         = NULL;

	FileChanged(fileName, onDisk);
}
int
main
	(
	int		argc,
	char*	argv[]
	)
{
	ParseTextOptions(argc, argv);

	SymcirApp* app = new SymcirApp(&argc, argv);
	assert( app != NULL );

	JString inputFileName;
	ParseXOptions(argc, argv, &inputFileName);

	if (!inputFileName.IsEmpty() ||
		(JGetChooseSaveFile())->ChooseFile("Netlist to analyze:", NULL, &inputFileName))
		{
		SCCircuitDocument* mainDir = new SCCircuitDocument(app, inputFileName);
		assert( mainDir != NULL );

		mainDir->Activate();
		app->Run();
		}

	return 0;
}
void
CMEditPrefsDialog::ChooseDebugger
	(
	const JCharacter*	name,
	JXInputField*		input
	)
{
	const JCharacter* map[] =
		{
		"name", name
		};
	const JString prompt = JGetString("ChooseDebuggerPrompt::CMEditPrefsDialog", map, sizeof(map));

	JString fullName;
	if ((JGetChooseSaveFile())->ChooseFile(prompt, "", &fullName))
		{
		JString text = input->GetText();
		JIndex i;
		if (text.LocateSubstring(" ", &i))
			{
			text.ReplaceSubstring(1, i-1, fullName);
			}
		else
			{
			text = fullName;
			}
		input->SetText(text);
		}
}
JBoolean
JXPathInput::ChoosePath
	(
	const JCharacter* prompt,
	const JCharacter* instr
	)
{
	JString origPath = GetTextForChoosePath();
	JString newPath;
	if ((itsRequireWriteFlag &&
		 (JGetChooseSaveFile())->ChooseRWPath(prompt, instr, origPath, &newPath)) ||
		(!itsRequireWriteFlag &&
		 (JGetChooseSaveFile())->ChooseRPath(prompt, instr, origPath, &newPath)))
		{
		SetText(newPath);
		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}
int
main
	(
	int argc,
	char** argv
	)
{
	JInitCore();

	JChooseSaveFile* csf = JGetChooseSaveFile();

	JString resultStr;

	if (csf->ChooseFile("Name of file:", NULL, &resultStr))
		{
		std::cout << resultStr << std::endl;
		JWaitForReturn();
		}

	if (csf->ChooseFile("Name of file:", "Please select a file...", &resultStr))
		{
		std::cout << resultStr << std::endl;
		JWaitForReturn();
		}

	if (csf->ChooseRPath("", "Please select a directory...", NULL, &resultStr))
		{
		std::cout << resultStr << std::endl;
		JWaitForReturn();
		}

	if (csf->ChooseRWPath("", "Please select a writable directory:", NULL, &resultStr))
		{
		std::cout << resultStr << std::endl;
		JWaitForReturn();
		}

	if (csf->SaveFile("Save file as:", NULL, "junk", &resultStr))
		{
		std::cout << resultStr << std::endl;
		JWaitForReturn();
		}

	if (csf->SaveFile("Save file as:", "Please save the file...", "more junk", &resultStr))
		{
		std::cout << resultStr << std::endl;
		JWaitForReturn();
		}

	return 0;
}
void
SCCircuitDocument::OpenSomething
	(
	const JCharacter* fileName
	)
{
	JString fullName;
	if (fileName != NULL && fileName[0] != '\0')
		{
		if (JFileExists(fileName))
			{
			fullName = fileName;
			}
		else
			{
			return;
			}
		}
	else if (!(JGetChooseSaveFile())->ChooseFile("File to open:", NULL, &fullName))
		{
		return;
		}

	std::ifstream input(fullName);
	const FileStatus status = CanReadFile(input);
	JXFileDocument* doc;
	if (status == kFileReadable &&
		!(JXGetDocumentManager())->FileDocumentIsOpen(fullName, &doc) &&
		OKToClose())
		{
		CloseAllWindows();
		FileChanged(fullName, kJTrue);
		ReadFile(input);
		}
	else if (status == kNeedNewerVersion)
		{
		(JGetUserNotification())->ReportError(
			"This notebook was created by a newer version of Symcir.  "
			"You need the newest version in order to open it.");
		}
	else if (status == kNotMyFile && OKToClose())
		{
		input.close();
		CloseAllWindows();
		ReadNetlist(fullName);
		}
}
void
GXDataDocument::HandleFileMenu
	(
	const JIndex index
	)
{
	if (index == kNewCmd)
		{
		(GLGetApplication())->NewFile();
		}
	else if (index == kOpenCmd)
		{
		JString filename;
		if (JGetChooseSaveFile()->ChooseFile("Select Data File", "", &filename))
			{
			(GLGetApplication())->OpenFile(filename);
			}
		}
	else if (index == kSaveCmd)
		{
		SaveInCurrentFile();
		}
	else if (index == kSaveAsCmd)
		{
		SaveInNewFile();
		}
	else if (index == kPageSetupCmd)
		{
		itsPrinter->BeginUserPageSetup();
		}
	else if (index == kPrintCmd && itsTable->EndEditing())
		{
		itsPrinter->BeginUserPrintSetup();
		}
	else if (index == kCloseCmd)
		{
		Close();
		}

	else if (index == kQuitCmd)
		{
		(GLGetApplication())->Quit();
		}
}
int
main
	(
	int argc,
	char** argv
	)
{
	JInitCore();

	JString fileName;
	if (!(JGetChooseSaveFile())->SaveFile("Save file as:", NULL, "junk", &fileName))
		{
		return 0;
		}

	ofstream file0(fileName);
	file0 << "0123456789";
	file0.close();		// force write to disk
	fstream file1(fileName, kJTextFile);
	cout << "Length of file (10): " << JGetFStreamLength(file1) << endl;

	fstream* file2 = JSetFStreamLength(fileName, file1, 20, kJTextFile);
	cout << "Old fstream open? (0) " << (file1.rdbuf())->is_open() << endl;
	cout << "Length of file (20): " << JGetFStreamLength(*file2) << endl;

	fstream* file3 = JSetFStreamLength(fileName, *file2, 5, kJTextFile);
	cout << "Old fstream open? (0) " << (file2->rdbuf())->is_open() << endl;
	cout << "Length of file (5): " << JGetFStreamLength(*file3) << endl;

	file3->close();

	ofstream file4(fileName);
	file4.close();

	file1.open(fileName, kJTextFile);
	cout << "default open of ofstream should erase file" << endl;
	cout << "Length of file (0): " << JGetFStreamLength(file1) << endl;
	file1.close();

	remove(fileName);

	return 0;
}
Example #9
0
JBoolean
JXFileInput::SaveFile
	(
	const JCharacter* prompt,
	const JCharacter* instr
	)
{
	const JString origName = GetTextForChooseFile();
	JString newName;
	if ((JGetChooseSaveFile())->SaveFile(prompt, instr, origName, &newName))
		{
		SetText(newName);
		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}
void
CBFileNameDisplay::HandleUnfocusEvent()
{
	JXFileInput::HandleUnfocusEvent();

	JBoolean saved = kJFalse;

	JString fullName;
	if (itsUnfocusAction != kCancel &&
		JExpandHomeDirShortcut(GetText(), &fullName))
		{
		if (JIsRelativePath(fullName) &&
			!(JGetChooseSaveFile())->SaveFile("Save file as:", "", fullName, &fullName))
			{
			fullName.Clear();
			}

		if (!fullName.IsEmpty() &&
			!JSameDirEntry(fullName, itsOrigFile) &&
			itsDoc->SaveInNewFile(fullName))
			{
			saved = kJTrue;

			JBoolean onDisk;
			fullName = itsDoc->GetFullName(&onDisk);
			SetText(fullName);

			if (itsUnfocusAction == kRename)
				{
				CBCleanUpAfterRename(itsOrigFile, fullName);
				}
			}
		}

	if (!saved)
		{
		SetText(itsOrigFile);
		}

	UpdateDisplay(kJFalse);			// take control of text style
	itsDragSource->ProvideDirectSave(NULL);
}
void
CBSearchTextDialog::SaveFileSet()
	const
{
	JString newName;
	if ((JGetChooseSaveFile())->SaveFile("Save file set as:", "",
										 itsFileSetName, &newName))
		{
		itsFileSetName = newName;

		std::ofstream output(itsFileSetName);
		const JPtrArray<JString>& fullNameList = itsFileList->GetFullNameList();
		const JSize fileCount = fullNameList.GetElementCount();
		for (JIndex i=1; i<=fileCount; i++)
			{
			(fullNameList.NthElement(i))->Print(output);
			output << '\n';
			}
		}
}
JBoolean
JXDocumentManager::FindFile
	(
	const JCharacter*	fileName,
	const JCharacter*	currPath,
	JString*			newFileName,
	const JBoolean		askUser
	)
	const
{
	// if the file exists, we are done

	if (JFileExists(fileName))
		{
		*newFileName = fileName;
		return kJTrue;
		}

	// search the directory tree below currPath

	JString path, name, newPath;
	JSplitPathAndName(fileName, &path, &name);

	if (JSearchSubdirs(currPath, name, kJTrue, kJTrue, &newPath))
		{
		*newFileName = newPath + name;
		return kJTrue;
		}

	// check for known case of move/rename

	if (SearchFileMap(fileName, newFileName))
		{
		return kJTrue;
		}

	// ask the user to find it

	if (askUser)
		{
		JString instrMsg = "Unable to locate ";
		instrMsg += fileName;
		instrMsg += "\n\nPlease find it.";

		while ((JGetChooseSaveFile())->ChooseFile("New name of file:", instrMsg, newFileName))
			{
			JString newPath, newName;
			JSplitPathAndName(*newFileName, &newPath, &newName);
			if (newName != name)
				{
				JString warnMsg = name;
				warnMsg += " was requested.\n\nYou selected ";
				warnMsg += newName;
				warnMsg += ".\n\nAre you sure that this is correct?";
				if (!(JGetUserNotification())->AskUserNo(warnMsg))
					{
					continue;
					}
				}

			JString trueName;
			const JBoolean ok = JGetTrueName(*newFileName, &trueName);
			assert( ok );

			FileMap map;
			map.oldName = new JString(fileName);
			assert( map.oldName != NULL );
			map.newName = new JString(trueName);
			assert( map.newName != NULL );
			itsFileMap->AppendElement(map);

			*newFileName = trueName;
			return kJTrue;
			}
		}

	newFileName->Clear();
	return kJFalse;
}