コード例 #1
0
void
JXCurrentPathMenu::SetPath
	(
	const JCharacter* path
	)
{
	RemoveAllItems();

	JString p = path;
	JCleanPath(&p);

	JString p1, n;
	while (!JIsRootDirectory(p))
		{
		JStripTrailingDirSeparator(&p);
		JSplitPathAndName(p, &p1, &n);
		PrependItem(n);
		SetItemImage(1, GetIcon(p), kJFalse);
		p = p1;
		}

	PrependItem(p);
	SetItemImage(1, GetIcon(p), kJFalse);

	const JXImage* image = NULL;
	GetItemImage(GetItemCount(), &image);
	SetTitle(GetItemText(GetItemCount()), const_cast<JXImage*>(image), kJFalse);
	SetUpdateAction(kDisableNone);
}
コード例 #2
0
void
JWebBrowser::ShowFileLocation
	(
	const JCharacter* fileName
	)
{
	if (!JStringEmpty(itsShowFileLocationCmd))
		{
		JString fullName = fileName;
		JStripTrailingDirSeparator(&fullName);

		JString path, name;
		JSplitPathAndName(fullName, &path, &name);

		const JCharacter* map[] =
			{
			kFileVarName, fullName,
			kPathVarName, path
			};

		JString s = itsShowFileLocationCmd;
		if (!s.Contains("$"))
			{
			s += " '$";
			s += kFileVarName;
			s += "'";
			}
		(JGetStringManager())->Replace(&s, map, sizeof(map));
		JSimpleProcess::Create(s, kJTrue);
		}
}
コード例 #3
0
JError
JDirInfo::GoUp()
{
	JString theCWD = *itsCWD;

	// strip trailing slashes

	JStripTrailingDirSeparator(&theCWD);
	if (JIsRootDirectory(theCWD))
		{
		return JNoError();
		}

	// change directory

	JString newCWD, name;
	if (JSplitPathAndName(theCWD, &newCWD, &name))
		{
		return GoTo(newCWD);
		}
	else
		{
		return JBadPath(theCWD);
		}
}
コード例 #4
0
JBoolean
SVNWDManager::GetBrowserForExactURL
	(
	const JCharacter*	url,
	SVNMainDirector**	dir
	)
{
	*dir = NULL;

	JString p1 = url;
	JStripTrailingDirSeparator(&p1);

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

	const JSize windowCount = windowList.GetElementCount();
	JString p2;
	for (JIndex i=1; i<=windowCount; i++)
		{
		SVNMainDirector* d = dynamic_cast<SVNMainDirector*>(windowList.NthElement(i));
		if (d != NULL && d->GetRepoPath(&p2) && p1 == p2)
			{
			*dir = d;
			break;
			}
		}

	return JI2B( *dir != NULL );
}
コード例 #5
0
JString
SyGApplication::GetMountPointPrefsPath
	(
	const JCharacter* path
	)
	const
{
	JString s = path;
	JCleanPath(&s);
	JStripTrailingDirSeparator(&s);
	return s;
}
コード例 #6
0
JError
JDirInfo::BuildInfo()
{
	if (!JDirectoryReadable(*itsCWD))
		{
		return JAccessDenied(*itsCWD);
		}

	const JString origDir = JGetCurrentDirectory();

	JError err = JChangeDirectory(*itsCWD);
	if (!err.OK())
		{
		return err;
		}

	// clear old information

	itsDirEntries->CleanOut();

	// update instance variables

	JStripTrailingDirSeparator(itsCWD);		// keep Windows happy

	ACE_stat stbuf;
	ACE_OS::stat(*itsCWD, &stbuf);
	itsIsValidFlag    = kJTrue;
	itsIsWritableFlag = JDirectoryWritable(*itsCWD);
	itsModTime        = stbuf.st_mtime;
	itsStatusTime     = stbuf.st_ctime;

	JAppendDirSeparator(itsCWD);

	// process files in the directory

	JLatentPG pg(itsContentRegex == NULL ? 100 : 10);
	if (itsPG != NULL)
		{
		pg.SetPG(itsPG, kJFalse);
		}
	pg.VariableLengthProcessBeginning("Scanning directory...", kJTrue, kJFalse);

	BuildInfo1(pg);

	pg.ProcessFinished();

	err = JChangeDirectory(origDir);
	assert_ok( err );

	ApplyFilters(kJFalse);
	return JNoError();
}
コード例 #7
0
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;
}
コード例 #8
0
JBoolean
JXPathInput::Complete
	(
	JXInputField*				te,
	const JCharacter*			basePath,	// can be NULL
	JDirInfo*					completer,
	JXStringCompletionMenu**	menu		// constructed if NULL
	)
{
	// only complete if caret is at end of text

	JIndex caretIndex;
	if (!te->GetCaretLocation(&caretIndex) ||
		caretIndex != te->GetTextLength()+1)
		{
		return kJFalse;
		}

	// catch empty path

	if (te->IsEmpty())
		{
		const JString path = JGetRootDirectory();
		te->Paste(path);
		return kJTrue;
		}

	// convert to absolute path

	JString fullName;
	if (!JExpandHomeDirShortcut(te->GetText(), &fullName))
		{
		return kJFalse;
		}
	if (JIsRelativePath(fullName))
		{
		if (JStringEmpty(basePath))
			{
			return kJFalse;
			}
		fullName = JCombinePathAndName(basePath, fullName);
		}

	// if completing ~ rather than ~/

	if (fullName.EndsWith(ACE_DIRECTORY_SEPARATOR_STR) &&
		!(te->GetText()).EndsWith(ACE_DIRECTORY_SEPARATOR_STR))
		{
		JStripTrailingDirSeparator(&fullName);
		}

	// get path and wildcard filter

	JString path, name;
	if (fullName.EndsWith(ACE_DIRECTORY_SEPARATOR_STR))
		{
		path = fullName;
		name = "*";
		}
	else
		{
		JSplitPathAndName(fullName, &path, &name);
		name.AppendCharacter('*');
		}

	// build completion list

	if (!(completer->GoTo(path)).OK())
		{
		return kJFalse;
		}

	completer->SetWildcardFilter(name, kJFalse, kJTrue);
	if (completer->IsEmpty())
		{
		return kJFalse;
		}

	// check for characters common to all matches

	JString maxPrefix = jGetFullName(completer, 1);

	const JSize matchCount = completer->GetEntryCount();
	JString entryName;
	for (JIndex i=2; i<=matchCount; i++)
		{
		entryName                = jGetFullName(completer, i);
		const JSize matchLength  = JCalcMatchLength(maxPrefix, entryName);
		const JSize prefixLength = maxPrefix.GetLength();
		if (matchLength < prefixLength)
			{
			maxPrefix.RemoveSubstring(matchLength+1, prefixLength);
			}
		}

	// use the completion list

	if (matchCount > 0 &&
		maxPrefix.GetLength() > fullName.GetLength())
		{
		maxPrefix.RemoveSubstring(1, fullName.GetLength());
		if (matchCount == 1 && (completer->GetEntry(1)).IsDirectory())
			{
			JAppendDirSeparator(&maxPrefix);
			}
		te->Paste(maxPrefix);		// so Undo removes completion

		if (*menu != NULL)
			{
			(**menu).ClearRequestCount();
			}

		return kJTrue;
		}
	else if (matchCount > 1)
		{
		if (*menu == NULL)
			{
			*menu = new JXStringCompletionMenu(te, kJFalse);
			assert( *menu != NULL );
			}
		else
			{
			(**menu).RemoveAllItems();
			}

		for (JIndex i=1; i<=matchCount; i++)
			{
			entryName = jGetName(completer, i);
			(**menu).AddString(entryName);
			}

		(**menu).CompletionRequested(name.GetLength()-1);
		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}
コード例 #9
0
ファイル: jDirUtil.cpp プロジェクト: mbert/mulberry-lib-jx
JString
JGetClosestDirectory
	(
	const JCharacter*	origDirName,
	const JBoolean		requireWrite,
	const JCharacter*	basePath
	)
{
	assert( !JStringEmpty(origDirName) );

	JString workingDir;
	if (!JStringEmpty(basePath))
		{
		workingDir = basePath;
		JAppendDirSeparator(&workingDir);
		}
	else
		{
		workingDir = JGetCurrentDirectory();
		}

	JString dirName = origDirName;
	JString homeDir;
	JSize homeLength;
	if (origDirName[0] == '~' &&
		!JExpandHomeDirShortcut(origDirName, &dirName, &homeDir, &homeLength))
		{
		return JGetRootDirectory();
		}
	else if (JIsRelativePath(origDirName))
		{
		dirName.Prepend(workingDir);
		}

	assert( !JIsRelativePath(dirName) );

	JString newDir, junkName;
	while (!JDirectoryExists(dirName)   ||
		   !JCanEnterDirectory(dirName) ||
		   !JDirectoryReadable(dirName) ||
		   (requireWrite && !JDirectoryWritable(dirName)))
		{
		JStripTrailingDirSeparator(&dirName);
		if (JIsRootDirectory(dirName))
			{
			break;
			}
		JSplitPathAndName(dirName, &newDir, &junkName);
		dirName = newDir;
		}

	// convert back to partial path, if possible

	if (origDirName[0] == '~' &&
		dirName.BeginsWith(homeDir))
		{
		dirName.ReplaceSubstring(1, homeDir.GetLength(), origDirName, homeLength);
		}
	else if (JIsRelativePath(origDirName) &&
			 dirName.GetLength() > workingDir.GetLength() &&
			 dirName.BeginsWith(workingDir))
		{
		dirName.RemoveSubstring(1, workingDir.GetLength());
		}

	return dirName;
}