JError
JDirInfo::GoTo
	(
	const JCharacter* origDirName
	)
{
	JString dirName;
	if (JStringEmpty(origDirName) ||
		!JConvertToAbsolutePath(origDirName, NULL, &dirName))
		{
		return JBadPath(origDirName);
		}

	if (JSameDirEntry(dirName, *itsCWD))
		{
		Update();
		return JNoError();
		}
	JAppendDirSeparator(&dirName);

	const JString origCWD = *itsCWD;

	*itsCWD = dirName;
	const JError err = BuildInfo();
	if (err.OK())
		{
		Broadcast(PathChanged());
		}
	else
		{
		*itsCWD = origCWD;
		}

	return err;
}
JBoolean
SyGApplication::IsMountPoint
	(
	const JCharacter*	path,
	JMountType*			type
	)
	const
{
	if (!JNameUsed(path))
		{
		return kJFalse;
		}

	UpdateMountPointList();

	const JSize count = itsMountPointList->GetElementCount();
	for (JIndex i=1; i<=count; i++)
		{
		const JMountPoint info = itsMountPointList->GetElement(i);
		if (JSameDirEntry(path, *(info.path)))
			{
			if (type != NULL)
				{
				*type = info.type;
				}
			return kJTrue;
			}
		}

	return kJFalse;
}
Beispiel #3
0
JBoolean
SyGIsTrashDirectory
	(
	const JCharacter* path
	)
{
	JString dir;
	return JI2B(SyGGetTrashDirectory(&dir, kJFalse) &&
				JSameDirEntry(dir, path));
}
JBoolean
SVNWDManager::GetBrowser
	(
	const JCharacter*	path,
	SVNMainDirector**	dir
	)
{
	*dir = NULL;

	JString p1;
	JBoolean isURL = JIsURL(path);
	if (isURL)
		{
		p1 = path;
		JAppendDirSeparator(&p1);
		}
	else if (!JGetTrueName(path, &p1))
		{
		return kJFalse;
		}

	JPtrArray<JXWindowDirector> windowList(JPtrArrayT::kForgetAll);
	GetDirectors(&windowList);

	const JSize windowCount = windowList.GetElementCount();
	JString p2, p3;
	for (JIndex i=1; i<=windowCount; i++)
		{
		SVNMainDirector* d = dynamic_cast<SVNMainDirector*>(windowList.NthElement(i));
		if (d == NULL)
			{
			continue;
			}

		if (isURL && d->GetRepoPath(&p2))
			{
			JAppendDirSeparator(&p2);
			if (p1.BeginsWith(p2))
				{
				*dir = d;
				break;
				}
			}
		else if (!isURL && d->GetPath(&p3) &&
				 (JSameDirEntry(p1, p3) ||
				  (JGetTrueName(p3, &p2) && p1.BeginsWith(p2))))
			{
			*dir = d;
			break;
			}
		}

	return JI2B( *dir != NULL );
}
void
CBNewProjectSaveFileDialog::BuildTemplateMenuItems
	(
	const JCharacter*	path,
	const JBoolean		isUserPath,
	JPtrArray<JString>*	menuText,
	const JCharacter*	templateFile,
	JString**			menuTextStr
	)
	const
{
	JDirInfo* info = NULL;
	if (JDirInfo::Create(path, &info))
		{
		info->ShowDirs(kJFalse);

		const JSize count = info->GetEntryCount();
		JString fullName, templateType;
		for (JIndex i=1; i<=count; i++)
			{
			fullName = (info->GetEntry(i)).GetFullName();
			if (CBProjectDocument::GetProjectTemplateType(fullName, &templateType))
				{
				JString* s = jnew JString((info->GetEntry(i)).GetName());
				assert( s != NULL );

				if (isUserPath)
					{
					*s += kUserTemplateMarker;
					}
				else
					{
					*s += kSysTemplateMarker;
					}

				menuText->InsertSorted(s);

				// save item corresponding to initial template selection

				if (JSameDirEntry(templateFile, fullName))
					{
					*menuTextStr = s;
					}
				}
			}
		}
}
void
CMSourceDirector::DisplayFile
	(
	const JCharacter*	fileName,
	const JIndex		lineNumber,
	const JBoolean		markLine
	)
{
	assert( !JStringEmpty(fileName) );

	if (!itsCurrentFile.IsEmpty() && JSameDirEntry(fileName, itsCurrentFile))
		{
		DisplayLine(lineNumber, markLine);
		UpdateWindowTitle(NULL);
		}
	else if (JFileReadable(fileName))
		{
		itsCurrentFile = fileName;

		JTextEditor::PlainTextFormat format;
		itsText->ReadPlainText(itsCurrentFile, &format);

		// Assembly must not end with newline, so we have to enforce this for
		// source code, too.

		const JString& text = itsText->GetText();
		JIndex i = text.GetLength();
		while (text.GetCharacter(i) == '\n')
			{
			i--;
			}
		if (i < text.GetLength())
			{
			itsText->SetSelection(i+1, text.GetLength());
			itsText->DeleteSelection();
			}
		itsText->SetCaretLocation(1);

		DisplayLine(lineNumber, markLine);
		itsFileDisplay->SetText(itsCurrentFile);

		UpdateFileType();
		UpdateWindowTitle(NULL);
		}
}
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);
}
JBoolean
JXDocumentManager::FileDocumentIsOpen
	(
	const JCharacter*	fileName,
	JXFileDocument**	doc
	)
	const
{
	*doc = NULL;

	// check that the file exists

	if (!JFileExists(fileName))
		{
		return kJFalse;
		}

	// search for an open JXFileDocument that uses this file

	const JSize count = itsDocList->GetElementCount();
	for (JIndex i=1; i<=count; i++)
		{
		const DocInfo info            = itsDocList->GetElement(i);
		const JXFileDocument* fileDoc = (info.doc)->CastToJXFileDocument();
		if (fileDoc != NULL)
			{
			JBoolean onDisk;
			const JString docName = fileDoc->GetFullName(&onDisk);

			if (onDisk && JSameDirEntry(fileName, docName))
				{
				*doc = const_cast<JXFileDocument*>(fileDoc);
				return kJTrue;
				}
			}
		}

	return kJFalse;
}
JError
JRenameDirEntry
	(
	const JCharacter* oldName,
	const JCharacter* newName
	)
{
	if (JNameUsed(newName))
		{
		return JDirEntryAlreadyExists(newName);
		}
	else if (JSameDirEntry(oldName, newName))
		{
		return JNoError();
		}

	jclear_errno();
	if (rename(oldName, newName) == 0)
		{
		return JNoError();
		}

	const int err = jerrno();
	if (err == EISDIR)
		{
		return JCantRenameFileToDirectory(oldName, newName);
		}
	else if (err == EXDEV)
		{
		return JCantRenameAcrossFilesystems();
		}
	else if (err == ENOTEMPTY)
		{
		return JCantRenameToNonemptyDirectory();
		}
	else if (err == EEXIST)
		{
		return JDirEntryAlreadyExists(newName);
		}
	else if (err == EBUSY)
		{
		return JFileBusy(newName);
		}
	else if (err == EINVAL)
		{
		return JDirectoryCantBeOwnChild();
		}
	else if (err == EMLINK)
		{
		return JTooManyLinks(oldName);
		}
	else if (err == ENOTDIR)
		{
		return JComponentNotDirectory(oldName, newName);
		}
	else if (err == EFAULT)
		{
		return JSegFault();
		}
	else if (err == EACCES || err == EPERM)
		{
		return JAccessDenied(oldName, newName);
		}
	else if (err == ENAMETOOLONG)
		{
		return JNameTooLong();
		}
	else if (err == ENOENT)
		{
		return JBadPath(oldName, newName);
		}
	else if (err == ENOMEM)
		{
		return JNoKernelMemory();
		}
	else if (err == EROFS)
		{
		return JFileSystemReadOnly();
		}
	else if (err == ELOOP)
		{
		return JPathContainsLoop(oldName, newName);
		}
	else if (err == ENOSPC)
		{
		return JFileSystemFull();
		}
	else
		{
		return JUnexpectedError(err);
		}
}
Beispiel #10
0
JIndex
SyGGetMountPointLargeIcon
	(
	const JCharacter*	path,
	SyGFileTreeList*	fileList,
	JXPM*				plainIcon,
	JXPM*				selectedIcon
	)
{
	JMountType type;
	const JBoolean isMP = theApplication->IsMountPoint(path, &type);

	if (!isMP)
		{
		JBoolean writable, isTop;
		JString device, fsTypeString;
		JFileSystemType fsType;
		if (JIsMounted(path, &writable, &isTop, &device, &fsType, &fsTypeString))
			{
			type = JGetUserMountPointType(path, device, fsTypeString);
			}
		else
			{
			type = kJHardDisk;
			}
		}

	const JBoolean writable = JDirectoryWritable(path);

	JString dir;
	if (JGetHomeDirectory(&dir) && JSameDirEntry(dir, path))
		{
		*plainIcon    = syg_home_folder_large;
		*selectedIcon = syg_home_folder_selected_large;
		return 1;
		}
	else if (SyGIsTrashDirectory(path))
		{
		(fileList->GetSyGFileTree())->Update();
		if (fileList->IsEmpty())
			{
			*plainIcon    = jx_trash_can_empty_large;
			*selectedIcon = jx_trash_can_empty_selected_large;
			return 2;
			}
		else
			{
			*plainIcon    = jx_trash_can_full_large;
			*selectedIcon = jx_trash_can_full_selected_large;
			return 3;
			}
		}
	else if (!isMP && type == kJFloppyDisk && !writable)
		{
		*plainIcon    = syg_floppy_folder_read_only_large;
		*selectedIcon = syg_floppy_folder_read_only_large;
		return 4;
		}
	else if (!isMP && type == kJFloppyDisk)
		{
		*plainIcon    = syg_floppy_folder_large;
		*selectedIcon = syg_floppy_folder_large;
		return 5;
		}
	else if (!isMP && type == kJCDROM && !writable)
		{
		*plainIcon    = syg_cdrom_folder_read_only_large;
		*selectedIcon = syg_cdrom_folder_read_only_large;
		return 4;
		}
	else if (!isMP && type == kJCDROM)
		{
		*plainIcon    = syg_cdrom_folder_large;
		*selectedIcon = syg_cdrom_folder_large;
		return 5;
		}
	else if (!isMP && !writable)
		{
		*plainIcon    = jx_folder_read_only_large;
		*selectedIcon = jx_folder_read_only_selected_large;
		return 6;
		}
	else if (!isMP)
		{
		*plainIcon    = jx_folder_large;
		*selectedIcon = jx_folder_selected_large;
		return 7;
		}
	else if (type == kJFloppyDisk)
		{
		*plainIcon    = jx_floppy_disk_large;
		*selectedIcon = jx_floppy_disk_selected_large;
		return 8;
		}
	else if (type == kJCDROM)
		{
		*plainIcon    = jx_cdrom_disk_large;
		*selectedIcon = jx_cdrom_disk_selected_large;
		return 9;
		}
	else
		{
		*plainIcon    = jx_hard_disk_large;
		*selectedIcon = jx_hard_disk_selected_large;
		return 11;
		}
}
JBoolean
SyGApplication::OpenDirectory
	(
	const JString&	pathName,
	SyGTreeDir**	dir,
	JIndex*			row,
	const JBoolean	deiconify,
	const JBoolean	reportError,
	const JBoolean	forceNew,
	const JBoolean	clearSelection
	)
{
	if (dir != NULL)
		{
		*dir = NULL;
		}

	if (row != NULL)
		{
		*row = 0;
		}

	JString fixedName, trueName;
	if (!JExpandHomeDirShortcut(pathName, &fixedName) ||
		!JConvertToAbsolutePath(fixedName, NULL, &trueName))
		{
		if (reportError)
			{
			JString msg = "\"";
			msg += pathName;
			msg += "\" does not exist.";
			(JGetUserNotification())->ReportError(msg);
			}
		return kJFalse;
		}

	// if file, select it after opening the window

	JString selectName;
	if (JFileExists(trueName) ||
		!JDirectoryExists(trueName))	// broken link
		{
		JStripTrailingDirSeparator(&trueName);
		JString path;
		JSplitPathAndName(trueName, &path, &selectName);
		trueName = path;
		}

	// can't check this until after making sure that trueName is directory

	if (!JFSFileTreeNode::CanHaveChildren(trueName))
		{
		if (reportError)
			{
			JString msg = "Unable to read contents of \"";
			msg += pathName;
			msg += "\"";
			(JGetUserNotification())->ReportError(msg);
			}
		return kJFalse;
		}

	// resolve all .. in path

	JIndex i;
	JString p, p1;
	while (trueName.LocateSubstring("..", &i))
		{
		p = trueName.GetSubstring(1, i+1);
		if (!JGetTrueName(p, &p1))
			{
			if (reportError)
				{
				JString msg = "\"";
				msg += p;
				msg += "\" does not exist.";
				(JGetUserNotification())->ReportError(msg);
				}
			return kJFalse;
			}

		trueName.ReplaceSubstring(1, i+1, p1);
		}

	// check if window is already open

	JString ancestor = trueName, n;
	JPtrArray<JString> pathList(JPtrArrayT::kDeleteAll);
	while (!JIsRootDirectory(ancestor))
		{
		const JIndex count = itsWindowList->GetElementCount();
		for (JIndex i=1; i<=count; i++)
			{
			const JString name = (itsWindowList->NthElement(i))->GetDirectory();
			if (JSameDirEntry(name, ancestor))
				{
				SyGTreeDir* childDir = itsWindowList->NthElement(i);
				childDir->Activate();
				if (dir != NULL)
					{
					*dir = childDir;
					}

				JPoint cell;
				(childDir->GetTable())->SelectName(pathList, selectName, &cell, clearSelection);
				if (row != NULL)
					{
					*row = cell.y;
					}

				return kJTrue;
				}
			}

		if (forceNew)
			{
			break;
			}

		JStripTrailingDirSeparator(&ancestor);
		JSplitPathAndName(ancestor, &p, &n);
		ancestor = p;
		pathList.Prepend(n);
		}

	// create new window

	fixedName = trueName;
	JGetTrueName(fixedName, &trueName);

	SyGTreeDir* childDir = new SyGTreeDir(trueName);
	assert( childDir != NULL );

	childDir->Activate();

	JPoint cell;
	(childDir->GetTable())->SelectName(selectName, NULL, &cell);
	if (row != NULL)
		{
		*row = cell.y;
		}

	if (deiconify)
		{
		childDir->GetWindow()->Deiconify();
		}
	itsWindowList->Append(childDir);

	if (dir != NULL)
		{
		*dir = childDir;
		}
	return kJTrue;
}
JBoolean
CBFileNameDisplay::InputValid()
{
	const JString& text = GetText();
	if (itsUnfocusAction == kCancel)
		{
		return kJTrue;
		}
	else if (text.IsEmpty())
		{
		(JGetUserNotification())->ReportError(JGetString(kEmptyErrorID));
		return kJFalse;
		}
	else if (text.EndsWith(ACE_DIRECTORY_SEPARATOR_STR))
		{
		(JGetUserNotification())->ReportError(JGetString(kNoFileNameID));
		return kJFalse;
		}
	else if (JIsRelativePath(text))
		{
		return kJTrue;	// open Choose File dialog
		}

	JString path, fullPath, name;
	JSplitPathAndName(text, &path, &name);
	if (!JExpandHomeDirShortcut(path, &fullPath))
		{
		return kJFalse;
		}

	const JString fullName = JCombinePathAndName(fullPath, name);
	JBoolean onDisk;
	const JString origFullName = itsDoc->GetFullName(&onDisk);
	if (onDisk && JSameDirEntry(origFullName, fullName))
		{
		itsUnfocusAction = kCancel;
		return kJTrue;
		}

	if (JFileExists(fullName))
		{
		const JCharacter* map[] =
			{
			"f", text
			};
		const JString msg = JGetString(kOKToReplaceID, map, sizeof(map));
		if (!(JGetUserNotification())->AskUserNo(msg))
			{
			return kJFalse;
			}
		}

	if (!JDirectoryExists(fullPath))
		{
		const JError err = JCreateDirectory(fullPath);
		if (!err.OK())
			{
			err.ReportIfError();
			return kJFalse;
			}
		}
	else if (!JDirectoryWritable(fullPath))
		{
		const JError err = JAccessDenied(fullPath);
		err.ReportIfError();
		return kJFalse;
		}

	if (itsUnfocusAction == kRename)
		{
		const JError err = JRenameVCS(origFullName, fullName);
		err.ReportIfError();
		return err.OK();
		}
	else
		{
		return kJTrue;
		}
}