예제 #1
0
JBoolean
jSearchVCSRoot
	(
	const JCharacter*	path,
	const JCharacter*	vcsDirName,
	JString*			vcsRoot
	)
{
	JString p = path, n;
	if (JFileExists(path) ||
		!JDirectoryExists(path))	// broken link
		{
		JSplitPathAndName(path, &p, &n);
		}

	do
		{
		n = JCombinePathAndName(p, vcsDirName);
		if (JDirectoryExists(n))
			{
			*vcsRoot = p;
			return kJTrue;
			}

		JSplitPathAndName(p, &p, &n);
		}
		while (!JIsRootDirectory(p));

	vcsRoot->Clear();
	return kJFalse;
}
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);
		}
}
void
JXFSBindingManager::Exec
(
    const JCharacter*	fullProgramName,
    const JBoolean		askForArgs
)
{
    JXFSBindingManager* me = Instance();

    JString cmd;
    JSplitPathAndName(fullProgramName, &(me->itsScriptPath), &cmd);

#ifdef _J_UNIX
    cmd.Prepend("./");
#endif

    if (askForArgs && me->itsRunScriptDialog == NULL)
    {
        me->itsRunScriptDialog = new JXFSRunScriptDialog(cmd);
        assert( me->itsRunScriptDialog != NULL );
        me->ListenTo(me->itsRunScriptDialog);
        me->itsRunScriptDialog->BeginDialog();
    }
    else if (!askForArgs)
    {
        (JXGetApplication())->DisplayBusyCursor();
        Exec(me->itsScriptPath, cmd, JFSBinding::kRunPlain);
    }
}
예제 #4
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);
}
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);
		}
}
예제 #6
0
JBoolean
GMApp::NewMailbox
	(
	const JCharacter*	filename,
	const JBoolean		openFile
	)
{
	JString path;
	JString name;
	JSplitPathAndName(filename, &path, &name);
	if (path.IsEmpty())
		{
		path = JGetCurrentDirectory();
		}
	if (!(JDirectoryExists(path) && JDirectoryReadable(path)))
		{
		JString notice = "You do not have write permissions in directory \"" + path + "\"";
		JGetUserNotification()->ReportError(notice);
		return kJFalse;
		}
	ofstream os(filename);
	if (!os.good())
		{
		JString notice = "Unable to create file \"" + path + name + "\"";
		JGetUserNotification()->ReportError(notice);
		return kJFalse;
		}
	os.close();
	if (openFile)
		{
		OpenMailbox(filename);
		}
	return kJTrue;
}
예제 #7
0
void
JUpdateCVSIgnore
	(
	const JCharacter* ignoreFullName
	)
{
	JString path, name;
	JSplitPathAndName(ignoreFullName, &path, &name);
	const JString cvsFile = JCombinePathAndName(path, ".cvsignore");

	if (!JFileExists(cvsFile) && JGetVCSType(path) != kJCVSType)
		{
		return;
		}

	JString cvsData;
	JReadFile(cvsFile, &cvsData);
	if (!cvsData.IsEmpty() && !cvsData.EndsWith("\n"))
		{
		cvsData += "\n";
		}

	name += "\n";
	if (!cvsData.Contains(name))
		{
		JEditVCS(cvsFile);
		cvsData += name;

		ofstream output(cvsFile);
		cvsData.Print(output);
		}
}
JXSharedPrefsManager::JXSharedPrefsManager()
{
	itsFile = NULL;

	if (JExpandHomeDirShortcut(kSignalFileName, &itsSignalFileName))
		{
		JString path, name;
		JSplitPathAndName(itsSignalFileName, &path, &name);
		if (JCreateDirectory(path, 0700) != kJNoError)
			{
			itsSignalFileName.Clear();
			}
		}
	else
		{
		itsSignalFileName.Clear();
		}

	GetAll(&itsWasNewFlag);

	itsUpdateTask = new JXTimerTask(kUpdateInterval);
	assert( itsUpdateTask != NULL );
	itsUpdateTask->Start();
	ListenTo(itsUpdateTask);
}
void
SyGDuplicateProcess::ProcessNextFile()
{
	if (itsFullNameList.IsEmpty())
		{
		JXDeleteObjectTask<JBroadcaster>::Delete(this);
		return;
		}

	const JString* origName = itsFullNameList.FirstElement();
	JString path, name, root, suffix;
	JSplitPathAndName(*origName, &path, &name);
	if (JSplitRootAndSuffix(name, &root, &suffix))
		{
		suffix.PrependCharacter('.');
		}

	root += "_copy";
	name  = JGetUniqueDirEntryName(path, root, suffix);

	JSplitPathAndName(name, &path, &itsCurrentName);

	const JCharacter* argv[] = { "cp", "-Rdf", *origName, name, NULL };

	JVCSType type;
	if (JIsManagedByVCS(*origName, &type) && type == kJSVNType)
		{
		argv[0] = "svn";
		argv[1] = "cp";
		}

	const JError err = JSimpleProcess::Create(&itsProcess, argv, sizeof(argv));
	err.ReportIfError();
	itsFullNameList.DeleteElement(1);		// before ProcessNextFile()

	if (err.OK())
		{
		ListenTo(itsProcess);
		JThisProcess::Ignore(itsProcess);	// detach so it always finishes
		}
	else
		{
		itsProcess = NULL;
		itsNodeList.RemoveElement(1);
		ProcessNextFile();
		}
}
예제 #10
0
JVCSType
JGetVCSType
	(
	const JCharacter*	path,
	const JBoolean		deepInspection
	)
{
	JString p = path, n;
	if (JFileExists(path) ||
		!JDirectoryExists(path))	// broken link
		{
		JSplitPathAndName(path, &p, &n);
		}

	// can't read newer versions

	JString vcsDir = JCombinePathAndName(p, kSubversionDirName);
	vcsDir         = JCombinePathAndName(vcsDir, kSubversionFileName);
	if (JFileExists(vcsDir))
		{
		if (!deepInspection)
			{
			return kJSVNType;
			}

		JSize size;
		const JError err = JGetFileLength(vcsDir, &size);
		if (err.OK() && size > 10)
			{
			return kJSVNType;
			}
		}

	vcsDir = JCombinePathAndName(p, kCVSDirName);
	if (JDirectoryExists(vcsDir))
		{
		return kJCVSType;
		}

	vcsDir = JCombinePathAndName(p, kSCCSDirName);
	if (JDirectoryExists(vcsDir))
		{
		return kJSCCSType;
		}

	// check git & new svc last, since they need to search directory tree up to root

	if (JSearchGitRoot(p, &n))
	{
		return kJGitType;
	}
	else if (!deepInspection && jSearchVCSRoot(p, kSubversionDirName, &n))
	{
		return kJSVNType;
	}

	return kJUnknownVCSType;
}
예제 #11
0
void
SyGAddRecentFile
	(
	const JCharacter* fullname
	)
{
	JString recentDir;
	JString filename;
	JString path;
	if (SyGGetRecentFileDirectory(&recentDir) &&
		JSplitPathAndName(fullname, &path, &filename))
		{
		const JString recentFile = JCombinePathAndName(recentDir, filename);
		if (JNameUsed(recentFile))
			{
			JRemoveFile(recentFile);
			JCreateSymbolicLink(fullname, recentFile);
			return;
			}

		// remove oldest links such that only kRecentFileCount - 1 remain

		JDirInfo* info;
		if (JDirInfo::Create(recentDir, &info))
			{
			JBoolean changed = kJFalse;

			JSize count = info->GetEntryCount();
			for (JIndex i=1; i<=count; i++)
				{
				if (info->GetEntry(i).IsBrokenLink())
					{
					JRemoveFile(info->GetEntry(i).GetFullName());
					changed = kJTrue;
					}
				}

			if (changed)
				{
				info->ForceUpdate();
				}

			count = info->GetEntryCount();
			if (count >= kRecentFileCount)
				{
				info->ChangeSort(JDirEntry::CompareModTimes, JOrderedSetT::kSortDescending);
				for (JIndex i=count; i>=kRecentFileCount; i--)
					{
					JRemoveFile(info->GetEntry(i).GetFullName());
					}
				}

			// add new entry

			JCreateSymbolicLink(fullname, recentFile);
			}
		}
}
void
JXFileHistoryMenu::AddFile
	(
	const JCharacter* fullName
	)
{
	JString path, name;
	JSplitPathAndName(fullName, &path, &name);
	AddFile(path, name);
}
void
JXDSSFinishSaveTask::Save
	(
	const JString& fullName
	)
{
	JString name;
	JSplitPathAndName(fullName, itsDirName, &name);
	Go();
}
GLFitDirector::GLFitDirector
	(
	PlotDir* 			supervisor,
	J2DPlotWidget*		plot,
	const JCharacter*	file
	)
	:
	JXWindowDirector(supervisor),
	itsPlot(plot),
	itsCurrentFit(NULL),
	itsTestFunction(NULL),
	itsNLFitDialog(NULL),
	itsPolyFitDialog(NULL),
	itsDir(supervisor),
	itsPrinter(NULL)
{
	BuildWindow();

	itsToolBar->LoadPrefs();
	if (itsToolBar->IsEmpty())
		{
		itsToolBar->AppendButton(itsFitMenu, kFitCmd);
		itsToolBar->AppendButton(itsFitMenu, kTestFitCmd);
		itsToolBar->AppendButton(itsFitMenu, kRefitCmd);
		itsToolBar->AppendButton(itsFitMenu, kPlotCmd);
		itsToolBar->NewGroup();
		itsToolBar->AppendButton(itsFitMenu, kCloseCmd);
		itsToolBar->NewGroup();
		itsToolBar->AppendButton(itsHelpMenu, kTOCCmd);
		itsToolBar->AppendButton(itsHelpMenu, kThisWindowCmd);
		}

	itsHistory	= new GloveHistoryDir(this);
	assert(itsHistory != NULL);

	JString name;
	JString path;
	JSplitPathAndName(file, &path, &name);
	JString title	= "Fit: " + name;
	GetWindow()->SetTitle(title);

	itsPrinter = new JXPSPrinter(GetDisplay());
	assert( itsPrinter != NULL );
	itsPrinter->SetOrientation(JPSPrinter::kPortrait);

	ListenTo(itsPrinter);
}
예제 #15
0
JBoolean
JIsManagedByVCS
	(
	const JCharacter*	fullName,
	JVCSType*			returnType
	)
{
	const JVCSType type = JGetVCSType(fullName);

	JBoolean isManaged = kJFalse;
	if (type == kJSVNType)
		{
		JString path, name, entriesFileName, data, pattern;
		JSplitPathAndName(fullName, &path, &name);
		entriesFileName = JCombinePathAndName(path, kSubversionDirName);
		entriesFileName = JCombinePathAndName(entriesFileName, kSubversionFileName);
		JReadFile(entriesFileName, &data);

		if (data.BeginsWith("<?xml"))
			{
			pattern = "<entry[^>]+name=\"" + JRegex::BackslashForLiteral(name) + "\"(.|\n)*?>";
			const JRegex r(pattern);
			isManaged = r.Match(data);
			}
		else
			{
			std::istrstream input(data, data.GetLength());

			const JString version = JReadLine(input);
			if (version == "8" || version == "9" || version == "10")
				{
				pattern = "\n\f\n" + name + "\n";
				JIgnoreUntil(input, pattern, &isManaged);
				}
			}
		}
	else if (type == kJGitType)
		{
		isManaged = kJTrue;	// TODO: ask git (until then, better safe than sorry)
		}

	if (returnType != NULL)
		{
		*returnType = (isManaged ? type : kJUnknownVCSType);
		}
	return isManaged;
}
void
CMSourceDirector::UpdateWindowTitle
	(
	const JCharacter* binaryName
	)
{
	JString path, title, prefix;
	if (itsType == kMainAsmType || itsType == kAsmType)
		{
		prefix = JGetString("WindowTitlePrefixMainAsm::CMSourceDirector");
		title  = itsCurrentFn.IsEmpty() ? JGetString("WindowTitleNoAsm::CMSourceDirector") : itsCurrentFn;
		}
	else
		{
		prefix = JGetString("WindowTitlePrefixMainSrc::CMSourceDirector");

		if (itsCurrentFile.IsEmpty())
			{
			title = JGetString("WindowTitleNoSrc::CMSourceDirector");
			}
		else
			{
			JSplitPathAndName(itsCurrentFile, &path, &title);
			}
		}

	if (IsMainSourceWindow())
		{
		// Save prefix with binary name since we will be called when file
		// name changes, too.

		if (binaryName != NULL)
			{
			itsWindowTitlePrefix  = binaryName;
			itsWindowTitlePrefix += prefix;
			}
		else if (itsWindowTitlePrefix.IsEmpty())
			{
			itsWindowTitlePrefix = prefix;
			}

		title.Prepend(itsWindowTitlePrefix);
		}

	GetWindow()->SetTitle(title);
}
JBoolean
CBNewProjectSaveFileDialog::OKToReplaceFile
	(
	const JCharacter* fullName,
	const JCharacter* programName
	)
{
	JString path, name;
	JSplitPathAndName(fullName, &path, &name);

	const JCharacter* map[] =
		{
		"file",   name.GetCString(),
		"method", programName
		};
	const JString msg = JGetString(kWarnFileExistsID, map, sizeof(map));

	return (JGetUserNotification())->AskUserNo(msg);
}
예제 #18
0
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);
			}
		}
}
void
GDBGetSourceFileList::HandleSuccess
	(
	const JString& origData
	)
{
	if (origData.BeginsWith("Source files for which symbols have been read in:"))
		{
		(JXGetApplication())->DisplayBusyCursor();

		JXFileListTable* table = (GetFileList())->GetTable();
		table->RemoveAllFiles();

		JString data = origData;
		JIndex i,j;
		while (data.LocateSubstring("Source files for which symbols", &i))
			{
			j = i;
			if (!data.LocateNextSubstring(":", &j))
				{
				j = data.GetLength();
				}
			data.ReplaceSubstring(i, j, ",");
			}
		data.TrimWhitespace();		// no comma after last file

		std::istrstream input(data.GetCString(), data.GetLength());
		JString fullName, path, name, s;
		JBoolean foundDelimiter;
		do
			{
			input >> ws;
			fullName = JReadUntil(input, ',', &foundDelimiter);
			fullName.TrimWhitespace();
			if (!fullName.IsEmpty())
				{
				JSplitPathAndName(fullName, &path, &name);
				table->AddFile(name);
				}
			}
			while (foundDelimiter);
		}
JFSBindingList*
JFSBindingList::Create
	(
	const JCharacter** needUserCheck
	)
{
	JString signalFileName, path, name;
	if (JExpandHomeDirShortcut(kSignalFileName, &signalFileName))
		{
		JSplitPathAndName(signalFileName, &path, &name);
		if ((JCreateDirectory(path, 0700)).OK() && JDirectoryWritable(path))
			{
			JFSBindingList* list = new JFSBindingList(signalFileName, needUserCheck);
			assert( list != NULL );
			return list;
			}
		}

	JFSBindingList* list = new JFSBindingList("", needUserCheck);
	assert( list != NULL );
	return list;
}
예제 #21
0
void
XDLink::SetProgram
	(
	const JCharacter* fileName
	)
{
	Send("detach");

//	StopDebugger();		// avoid broadcasting DebuggerRestarted
//	StartDebugger();

	itsProgramConfigFileName.Clear();
	itsSourcePathList->DeleteAll();

	JString fullName;
	if (!JConvertToAbsolutePath(fileName, NULL, &fullName) ||
		!JFileReadable(fullName))
		{
		const JString error = JGetString("ConfigFileUnreadable::XDLink");
		Broadcast(UserOutput(error, kJTrue));
		return;
		}
	else if (CMMDIServer::IsBinary(fullName))
		{
		const JString error = JGetString("ConfigFileIsBinary::XDLink");
		Broadcast(UserOutput(error, kJTrue));
		return;
		}

	JString line;
	if (!CMMDIServer::GetLanguage(fullName, &line) ||
		JStringCompare(line, "php", kJFalse) != 0)
		{
		const JString error = JGetString("ConfigFileWrongLanguage::XDLink");
		Broadcast(UserOutput(error, kJTrue));
		return;
		}

	JString path, name, suffix;
	JSplitPathAndName(fullName, &path, &name);
	JSplitRootAndSuffix(name, &itsProgramName, &suffix);

	itsProgramConfigFileName = fullName;

	ifstream input(fullName);
	while (1)
		{
		line = JReadLine(input);
		line.TrimWhitespace();

		if (line.BeginsWith("source-path:"))
			{
			line.RemoveSubstring(1, 12);
			line.TrimWhitespace();

			name = JCombinePathAndName(path, line);
			itsSourcePathList->Append(name);
			}
		else if (!line.IsEmpty() && !line.BeginsWith("code-medic:"))
			{
			line.Prepend("Unknown option: ");
			line.AppendCharacter('\n');
			Broadcast(UserOutput(line, kJTrue));
			}

		if (!input.good())
			{
			break;
			}
		}

	XDSetProgramTask* task = new XDSetProgramTask();
	assert( task != NULL );
	task->Go();
}
예제 #22
0
JBoolean
JGetVCSRepositoryPath
	(
	const JCharacter*	origPath,
	JString*			repoPath
	)
{
	JString path = origPath, name;
	if (JFileExists(origPath) ||
		!JDirectoryExists(origPath))	// broken link
		{
		JSplitPathAndName(origPath, &path, &name);
		}

	const JVCSType type = JGetVCSType(path);
	JBoolean found      = kJFalse;
	if (type == kJCVSType)
		{
		const JString cvsPath = JCombinePathAndName(path, kCVSDirName);

		JString fullName = JCombinePathAndName(cvsPath, "Root");
		JReadFile(fullName, repoPath);

		fullName = JCombinePathAndName(cvsPath, "Repository");
		JString repo;
		JReadFile(fullName, &repo);

		if (!repoPath->IsEmpty() && !repo.IsEmpty())
			{
			*repoPath = JCombinePathAndName(*repoPath, repo);
			found = kJTrue;
			}
		}
	else if (type == kJSVNType)
		{
		JString entriesFileName, data;
		entriesFileName = JCombinePathAndName(path, kSubversionDirName);
		entriesFileName = JCombinePathAndName(entriesFileName, kSubversionFileName);
		JReadFile(entriesFileName, &data);

		if (data.BeginsWith("<?xml"))
			{
			JIndexRange range;
			JArray<JIndexRange> matchList;
			if (svn4RepositoryPattern1.Match(data, &range) &&
				svn4RepositoryPattern2.MatchWithin(data, range, &matchList))
				{
				*repoPath = data.GetSubstring(matchList.GetElement(2));
				found = kJTrue;
				}
			}
		else
			{
			std::istrstream input(data, data.GetLength());

			const JString version = JReadLine(input);
			if (version == "8" || version == "9" || version == "10")
				{
				JIgnoreLine(input);		// ???
				JIgnoreLine(input);		// dir
				JIgnoreLine(input);		// latest update version

				*repoPath = JReadLine(input);
				found     = JI2B(input.good());
				}
			}
		}

	if (found)
		{
		if (!name.IsEmpty())
			{
			*repoPath = JCombinePathAndName(*repoPath, name);
			}
		return kJTrue;
		}
	else
		{
		repoPath->Clear();
		return kJFalse;
		}
}
예제 #23
0
JBoolean
JGetTrueName
	(
	const JCharacter*	name,
	JString*			trueName
	)
{
	trueName->Clear();

	if (!JNameUsed(name))
		{
		return kJFalse;
		}

	// check if it is a directory

	else if (JDirectoryExists(name))
		{
		const JString currPath = JGetCurrentDirectory();

		JError err = JChangeDirectory(name);
		if (!err.OK())
			{
			return kJFalse;
			}

		*trueName = JGetCurrentDirectory();

		err = JChangeDirectory(currPath);
		assert_ok( err );

		return kJTrue;
		}

	// it is a file, socket, fifo, etc.

	else
		{
		JString origPath, fileName;
		JSplitPathAndName(name, &origPath, &fileName);

		// get true directory

		JString truePath;
		if (!JGetTrueName(origPath, &truePath))
			{
			return kJFalse;
			}

		// resolve symbolic link

		JString target;
		if ((JGetSymbolicLinkTarget(name, &target)).OK())
			{
			if (JIsRelativePath(target))
				{
				target.Prepend(truePath);
				}
			return JGetTrueName(target, trueName);
			}
		else
			{
			*trueName = JCombinePathAndName(truePath, fileName);
			return kJTrue;
			}
		}
}
예제 #24
0
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;
}
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;
}
예제 #26
0
JBoolean
JGetCurrentSVNRevision
	(
	const JCharacter*	fullName,
	JString*			rev
	)
{
	JString path, name, entriesFileName, data, pattern;
	JSplitPathAndName(fullName, &path, &name);
	entriesFileName = JCombinePathAndName(path, kSubversionDirName);
	entriesFileName = JCombinePathAndName(entriesFileName, kSubversionFileName);
	JReadFile(entriesFileName, &data);

	if (data.BeginsWith("<?xml"))
		{
		pattern = "<entry[^>]+name=\"" + JRegex::BackslashForLiteral(name) + "\"(.|\n)*?>";
		JRegex r(pattern);
		JIndexRange range;
		JArray<JIndexRange> matchList;
		if (r.Match(data, &range) &&
			svn4RevisionPattern.MatchWithin(data, range, &matchList))
			{
			*rev = data.GetSubstring(matchList.GetElement(2));
			return kJTrue;
			}
		}
	else
		{
		std::istrstream input(data, data.GetLength());

		const JString version = JReadLine(input);
		if (version == "8" || version == "9" || version == "10")
			{
			pattern = "\n\f\n" + name + "\n";

			JBoolean found;
			JIgnoreUntil(input, pattern, &found);
			if (found)
				{
				const JString data2 = JReadUntil(input, '\f');
				std::istrstream input2(data2, data2.GetLength());

				JIgnoreLine(input2);		// file
				JIgnoreLine(input2);		// ???
				JIgnoreLine(input2);		// ???
				JIgnoreLine(input2);		// ???
				JIgnoreLine(input2);		// ???
				JIgnoreLine(input2);		// timestamp
				JIgnoreLine(input2);		// hash
				JIgnoreLine(input2);		// timestamp

				*rev = JReadLine(input2);
				if (input2.good())
					{
					return kJTrue;
					}
				}
			}
		}

	rev->Clear();
	return kJFalse;
}
예제 #27
0
void
CBFileNode::CreateFilesForTemplate
	(
	istream&			input,
	const JFileVersion	vers
	)
	const
{
	CBFileNodeBase::CreateFilesForTemplate(input, vers);

	JBoolean exists;
	input >> exists;
	if (exists)
		{
		JString relName, data;
		input >> relName >> data;

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

		const CBProjectTree* projTree = dynamic_cast<const CBProjectTree*>(GetTree());
		assert( projTree != NULL );

		const JString& basePath = (projTree->GetProjectDoc())->GetFilePath();
		path = JCombinePathAndName(basePath, path);

		JUserNotification* un = JGetUserNotification();
		if (!JDirectoryExists(path))
			{
			const JError err = JCreateDirectory(path);
			if (!err.OK())
				{
				JString msg = "Unable to create the file ";
				msg += relName;
				msg += " from the template because:\n\n";
				msg += err.GetMessage();
				un->ReportError(msg);
				return;
				}
			}

		const JString fullName = JCombinePathAndName(path, name);
		if (JFileExists(fullName))
			{
			JString msg = fullName;
			msg.PrependCharacter('"');
			msg += "\" already exists.  Do you want to overwrite it?";
			if (!un->AskUserNo(msg))
				{
				return;
				}
			}

		ofstream output(fullName);
		if (output.good())
			{
			data.Print(output);
			}
		else
			{
			JString msg = "Unable to create the file ";
			msg += relName;
			msg += " from the template.";
			un->ReportError(msg);
			}
		}
}
void
CBSymbolList::ReadSymbolList
	(
	istream&			input,
	const CBLanguage	lang,
	const JCharacter*	fullName,
	const JFAID_t		fileID
	)
{
	JString path, fileName;
	JSplitPathAndName(fullName, &path, &fileName);

	input >> ws;
	while (input.peek() == '!')
		{
		JIgnoreLine(input);
		input >> ws;
		}

	JStringPtrMap<JString> flags(JPtrArrayT::kDeleteAll);
	while (1)
		{
		JString* name = new JString;
		assert( name != NULL );

		input >> ws;
		*name = JReadUntil(input, '\t');		// symbol name
		if (input.eof() || input.fail())
			{
			delete name;
			break;
			}

		JIgnoreUntil(input, '\t');				// file name

		JIndex lineIndex;
		input >> lineIndex;						// line index

		ReadExtensionFlags(input, &flags);

		JCharacter typeChar = ' ';
		JString* value;
		if (flags.GetElement("kind", &value) && !value->IsEmpty())
			{
			typeChar = value->GetFirstCharacter();
			}

		JString* signature = NULL;
		if (flags.GetElement("signature", &value) && !value->IsEmpty())
			{
			signature = new JString(*value);
			assert( signature != NULL );
			signature->PrependCharacter(' ');
			}

		if (IgnoreSymbol(*name))
			{
			delete name;
			}
		else
			{
			const Type type = DecodeSymbolType(lang, typeChar);
			if (signature == NULL &&
				(IsFunction(type) || IsPrototype(type)))
				{
				signature = new JString(" ( )");
				assert( signature != NULL );
				}

			const SymbolInfo info(name, signature, lang, type,
								  kJFalse, fileID, lineIndex);
			itsSymbolList->InsertSorted(info);

			// add file:name

			if (IsFileScope(type))
				{
				JString* name1 = new JString(fileName);
				assert( name1 != NULL );
				*name1 += ":";
				*name1 += *name;

				JString* sig1 = NULL;
				if (signature != NULL)
					{
					sig1 = new JString(*signature);
					assert( sig1 != NULL );
					}

				const SymbolInfo info1(name1, sig1, lang, type,
									   kJTrue, fileID, lineIndex);
				itsSymbolList->InsertSorted(info1);
				}
			}
		}
}
예제 #29
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;
		}
}
void
JXFSBindingManager::Exec
(
    const JIndex startIndex,
    const JIndex endIndex
)
{
    // check if same path for all files

    JBoolean samePath = kJTrue;

    JString path, name;
    if (endIndex > startIndex)
    {
        JString p;
        for (JIndex i=startIndex; i<=endIndex; i++)
        {
            const JString& fullName = (itsFileList->NthElement(i))->GetPattern();
            JSplitPathAndName(fullName, &p, &name);
            if (i > startIndex && p != path)
            {
                samePath = kJFalse;
                break;
            }
            path = p;
        }
    }

    // build $q, $u, $qf, $uf

    JString q, u, qf, uf;
    for (JIndex i=startIndex; i<=endIndex; i++)
    {
        const JString& fullName = (itsFileList->NthElement(i))->GetPattern();

        if (samePath)
        {
            JSplitPathAndName(fullName, &path, &name);
        }
        else
        {
            name = fullName;
        }

        q += JPrepArgForExec(name);
        q += " ";

        u += name;
        u += " ";

        qf += JPrepArgForExec(fullName);
        qf += " ";

        uf += fullName;
        uf += " ";
    }

    // run command

    JFSBinding* f = itsFileList->NthElement(startIndex);
    JSplitPathAndName(f->GetPattern(), &path, &name);

    JFSBinding::CommandType type;
    JBoolean singleFile;
    JString cmd = f->GetCommand(&type, &singleFile);

    assert( ( singleFile && startIndex == endIndex) ||
            (!singleFile && startIndex <= endIndex) );

    BuildCommand(&cmd, q, u, qf, uf);
    Exec(path, cmd, type);
}