Ejemplo n.º 1
0
bool
App::QuickImportProject(DPath folder)
{
	// Quickly makes a project in a folder by importing all resource files and C++ sources.
	if (!BEntry(folder.GetFullPath()).Exists())
		return false;

	BMessage settings;
	settings.AddString("name", folder.GetFileName());
	settings.AddString("target", folder.GetFileName());
	// skipping templatename field on purpose
	settings.AddInt32("type", PROJECT_GUI);
	settings.AddString("path", folder.GetFullPath());
	settings.AddInt32("scmtype", gDefaultSCM);
	settings.AddBool("createfolder", false);
	
	DPath path(folder);
	BEntry entry(path.GetFullPath());
	Project *proj = CreateNewProject(settings);
	if (!proj)
		return false;
	
	entry.SetTo(folder.GetFullPath());
	entry_ref addref;
	entry.GetRef(&addref);
	BMessage addmsg(M_ADD_FILES);
	addmsg.AddRef("refs",&addref);
	
	PostToProjectWindow(&addmsg,NULL);
	return true;
}
Ejemplo n.º 2
0
void
EnsureTemplates(void)
{
	// Because creating a new project depends on the existence of the Templates folder,
	// make sure that we have some (very) basic templates to work with if the folder
	// has been deleted.
	DPath templatePath = gAppPath.GetFolder();
	templatePath << "Templates";
	
	bool missing = false;
	BDirectory tempDir;
	if (!BEntry(templatePath.GetFullPath()).Exists())
	{
		BDirectory appDir(gAppPath.GetFolder());
		appDir.CreateDirectory("Templates", &tempDir);
		missing = true;
	}
	else
	{
		tempDir.SetTo(templatePath.GetFullPath());
		if (tempDir.CountEntries() == 0)
			missing = true;
	}
	
	if (missing)
	{
		BDirectory dir;
		tempDir.CreateDirectory("Empty Application", &dir);
		tempDir.CreateDirectory("Kernel Driver", &dir);
		tempDir.CreateDirectory("Shared Library or Addon", &dir);
		tempDir.CreateDirectory("Static Library", &dir);
		
		DPath filePath;
		TextFile file;
		
		filePath = templatePath;
		filePath << "Empty Application/TEMPLATEINFO";
		file.SetTo(filePath.GetFullPath(), B_CREATE_FILE | B_READ_WRITE);
		file.WriteString("TYPE=Application\nLIB=B_BEOS_LIB_DIRECTORY/libsupc++.so\n");
		
		filePath = templatePath;
		filePath << "Kernel Driver/TEMPLATEINFO";
		file.SetTo(filePath.GetFullPath(), B_CREATE_FILE | B_READ_WRITE);
		file.WriteString("TYPE=Driver\n");
		
		filePath = templatePath;
		filePath << "Shared Library or Addon/TEMPLATEINFO";
		file.SetTo(filePath.GetFullPath(), B_CREATE_FILE | B_READ_WRITE);
		file.WriteString("TYPE=Shared\n");
		
		filePath = templatePath;
		filePath << "Static Library/TEMPLATEINFO";
		file.SetTo(filePath.GetFullPath(), B_CREATE_FILE | B_READ_WRITE);
		file.WriteString("TYPE=Static\n");
		
		file.Unset();
	}
}
Ejemplo n.º 3
0
Project *
App::CreateNewProject(const BMessage &settings)
{
	Project *proj = NULL;
	
	BString projectName, targetName, projectPath, templateName, pldName;
	int32 projectType, scmType;
	bool createFolder, populateProject = true;
	
	settings.FindString("name",&projectName);
	settings.FindString("target",&targetName);
	settings.FindInt32("type",&projectType);
	settings.FindString("path",&projectPath);
	settings.FindInt32("scmtype", &scmType);
	settings.FindBool("createfolder",&createFolder);
	settings.FindString("template", &templateName);
	settings.FindString("pldfile", &pldName);

	if (templateName.CountChars() > 0)
	{
		// Templates are now a directory with a TEMPLATEINFO file. All files in the
		// directory are copies, allowing for much greater flexibility than before.
		
		BString projectFileName(projectName);
		projectFileName << ".pld";
		
		DPath templatePath(gAppPath.GetFolder());
		templatePath << "Templates" << templateName;
		
		// Copy the contents of the chosen template folder to the project path
		DPath sourcePath(templatePath);
		DPath destPath(gProjectPath);
		
		if (createFolder)
		{
			destPath << projectName;
			create_directory(destPath.GetFullPath(), 0700);
		}
		
		BString wildcard("'");
		wildcard << sourcePath.GetFullPath() << "'/*";
		ShellHelper shell("cp -a ");
		shell << wildcard;
		shell.AddQuotedArg(destPath.GetFullPath());
		shell.Run();
		
		// The copy command copies *everything*, so we have to delete the
		// TEMPLATEINFO file.
		DPath templateInfo(destPath);
		templateInfo << "TEMPLATEINFO";
		BEntry infoEntry(templateInfo.GetFullPath());
		infoEntry.Remove();
		infoEntry.Unset();
		
		DPath finalPath;
		
		// Load project and set info or create one, if needed.
		
		// If the settings contain the name of a .pld project file, we'll search
		// for that first. Assuming that it exists, we'll rename that file to the
		// project name specified. If it doesn't exist or the .pld name is empty,
		// we'll create a new project with the appropriate name.
		
		// The pldname field comes from the TEMPLATEINFO file, which can designate
		// the main project file in a template. This allows a template to have
		// multiple project files, such as for the Tracker Add-on development framework
		// which has both a project file for generating the actual addon and another
		// one which is the testing framework.
		bool createProjFile = true;
		if (pldName.CountChars() > 0)
		{
			// If a .pld project file was specified in TEMPLATEINFO, check to see if
			// the file exists and rename it. If it doesn't exist, we'll create a new
			// file, and if a .pld file already exists with the intended name, we won't
			// do anything except tell the user what's happened.
			DPath oldPldNamePath(destPath);
			oldPldNamePath << pldName;
			BEntry oldPldNameEntry(oldPldNamePath.GetFullPath());
			
			DPath newPldNamePath(destPath);
			newPldNamePath << projectFileName;
			
			BEntry newPldNameEntry(newPldNamePath.GetFullPath());
			if (newPldNameEntry.Exists())
			{
				// createProjFile is false here only if there is a .pld file with the
				// user's chosen project name. If that is the case, we keep both files and
				// let the user sort it out.
				BString errMsg = B_TRANSLATE(
					"Project file '%projectname%.pld' already exists. The "
					"original file for this template is '%pldname%'. You'll need "
					"to open the project folder and figure out which one you wish to keep.");
				errMsg.ReplaceFirst("%projectname%", projectName);
				errMsg.ReplaceFirst("%pldname%", pldName);
				ShowAlert(errMsg);
				populateProject = createProjFile = false;
				
				finalPath = newPldNamePath;
			}
			else
			if (oldPldNameEntry.Exists())
			{
				oldPldNameEntry.Rename(projectFileName.String());
				populateProject = createProjFile = false;
				
				finalPath = newPldNamePath;
			}
		}
		
		if (createProjFile)
		{
			proj = Project::CreateProject(projectName.String(), targetName.String(),
									projectType, projectPath.String(), createFolder);
			if (proj)
				finalPath = proj->GetPath();
		}
		else
		{
			proj = new Project();
			if (proj->Load(finalPath.GetFullPath()) != B_OK)
			{
				delete proj;
				return NULL;
			}
		}
	}
	else
	{
		// This case is for stuff like the Quick Import feature
		proj = Project::CreateProject(projectName.String(), targetName.String(),
									projectType, projectPath.String(), createFolder);
	}
	
	if (!proj)
		return NULL;
	
	scm_t detectedSCM = DetectSCM(projectPath);
	proj->SetSourceControl(detectedSCM == SCM_NONE ? (scm_t)scmType : detectedSCM);
	
	gCurrentProject = proj;
	gProjectList->Lock();
	gProjectList->AddItem(proj);
	gProjectList->Unlock();
	
	BRect r(0,0,200,300);
	/*
	r.OffsetTo(gProjectWindowPoint);
	gProjectWindowPoint.x += 25;
	gProjectWindowPoint.y += 25;
	if (gProjectWindowPoint.x < 0)
		gProjectWindowPoint.x = 0;
	if (gProjectWindowPoint.y < 0)
		gProjectWindowPoint.y - 0;
		*/
	ProjectWindow *projwin = new ProjectWindow(r,gCurrentProject);
	projwin->Show();
	
	BEntry entry(gCurrentProject->GetPath().GetFullPath());
	if (entry.InitCheck() == B_OK)
	{
		entry_ref newprojref;
		entry.GetRef(&newprojref);
		UpdateRecentItems(newprojref);
	}
	
	if (populateProject)
	{
		entry_ref addRef;
		int32 i = 0;
		while (settings.FindRef("libs",i++,&addRef) == B_OK)
		{
			if (BEntry(&addRef).Exists())
				proj->AddLibrary(DPath(addRef).GetFullPath());
		}
		
		i = 0;
		BMessage addMsg(M_IMPORT_REFS);
		while (settings.FindRef("refs",i++,&addRef) == B_OK)
			addMsg.AddRef("refs",&addRef);
		PostToProjectWindow(&addMsg,NULL);
	}
	
	return proj;
}
Ejemplo n.º 4
0
void
InitGlobals(void)
{
	app_info ai;
	be_app->GetAppInfo(&ai);
	BPath path(&ai.ref);
	gAppPath = path.Path();
	
	DPath settingsPath(B_USER_SETTINGS_DIRECTORY);
	settingsPath << "Paladin_settings";
	
	gSettings.Load(settingsPath.GetFullPath());
	
	gDontManageHeaders = gSettings.GetBool("dontmanageheaders",true);
	gSingleThreadedBuild = gSettings.GetBool("singlethreaded",false);
	gShowFolderOnOpen = gSettings.GetBool("showfolderonopen",false);
	gAutoSyncModules = gSettings.GetBool("autosyncmodules",true);
	gUseCCache = gSettings.GetBool("ccache",false);
	gUseFastDep = gSettings.GetBool("fastdep",false);
	
	gDefaultSCM = (scm_t)gSettings.GetInt32("defaultSCM", SCM_HG);
	
	system_info sysinfo;
	get_system_info(&sysinfo);
	gCPUCount = sysinfo.cpu_count;
	
	gPlatform = DetectPlatform();
	
	// This will make sure that we can still build if ccache is borked and the user
	// wants to use it.
	if ((gPlatform == PLATFORM_HAIKU || gPlatform == PLATFORM_HAIKU_GCC4 || gPlatform == PLATFORM_ZETA) &&
		system("ccache > /dev/null 2>&1") == 1)
	{
		gCCacheAvailable = true;
	}
		
	if (gPlatform == PLATFORM_HAIKU || gPlatform == PLATFORM_HAIKU_GCC4)
	{
		if (system("fastdep > /dev/null 2>&1") == 0)
			gFastDepAvailable = true;
		
		if (system("hg > /dev/null 2>&1") == 0)
			gHgAvailable = true;
		
		#ifndef DISABLE_GIT_SUPPORT
		if (system("git > /dev/null 2>&1") == 1)
			gGitAvailable = true;
		#endif
		
		gUsePipeHack = true;
	}
	
	if (system("svn > /dev/null 2>&1") == 1)
		gSvnAvailable = true;
	
	if (system("lua -v > /dev/null 2>&1") == 0)
		gLuaAvailable = true;
	
	gProjectPath.SetTo(gSettings.GetString("projectpath",PROJECT_PATH));
	gLastProjectPath.SetTo(gSettings.GetString("lastprojectpath",PROJECT_PATH));
	
	DPath defaultBackupPath(B_DESKTOP_DIRECTORY);
	gBackupPath.SetTo(gSettings.GetString("backuppath", defaultBackupPath.GetFullPath()));
	
	DPath defaultRepoPath(B_USER_DIRECTORY);
	defaultRepoPath << "Paladin SVN Repos";
	gSVNRepoPath.SetTo(gSettings.GetString("svnrepopath", defaultRepoPath.GetFullPath()));
	
	
	gCodeLib.ScanFolders();
}
Ejemplo n.º 5
0
int32
LibraryWindow::ScanThread(void *data)
{
	LibraryWindow *win = (LibraryWindow *)data;

	float maxwidth;
	BRect r(5,5,105,20);
	
	BView *systemheader = win->AddHeader(r.LeftTop(),TR("System Libraries:"));
	
	win->Lock();
	r = systemheader->Frame();
	win->Unlock();
	maxwidth = r.right;
	
	r.OffsetBy(0,r.Height() + 10);
	
	DPath sysPath = GetSystemPath(B_USER_DEVELOP_DIRECTORY);
	sysPath << "lib/x86";
	BRect out = win->ScanFolder(r.LeftTop(),sysPath.GetFullPath(),&maxwidth);
	if (out != BRect(0,0,-1,-1))
	{
		r = out;
		r.OffsetBy(0,10);
	}
	
	if (gPlatform == PLATFORM_HAIKU || gPlatform == PLATFORM_HAIKU_GCC4)
	{
		BView *commonheader = win->AddHeader(r.LeftTop(),TR("Common Libraries:"));
		win->Lock();
		r = commonheader->Frame();
		win->Unlock();
		maxwidth = MAX(r.right,maxwidth);
		
		r.OffsetBy(0,r.Height() + 10);
		
		out = win->ScanFolder(r.LeftTop(),GetSystemPath(B_USER_LIB_DIRECTORY).GetFullPath(),
							&maxwidth);
		if (out != BRect(0,0,-1,-1))
		{
			r = out;
			r.OffsetBy(0,10);
		}
	}
	
	BView *userheader = win->AddHeader(r.LeftTop(),TR("User Libraries:"));
	win->Lock();
	r = userheader->Frame();
	win->Unlock();
	maxwidth = MAX(r.right,maxwidth);
	
	r.OffsetBy(0,r.Height() + 10);
	
	out = win->ScanFolder(r.LeftTop(),GetSystemPath(B_USER_LIB_DIRECTORY).GetFullPath(),
						&maxwidth);
	if (out.IsValid())
	{
		r = out;
		r.OffsetBy(0,10);
	}
	
	win->Lock();
	BView *top = win->GetBackgroundView();
	BScrollView *scrollView = (BScrollView*)top->FindView("scrollView");
	
	BScrollBar *vbar = scrollView->ScrollBar(B_VERTICAL);
	vbar->SetRange(0, r.bottom - scrollView->Bounds().Height());
	vbar->SetSteps(r.Height() * 2.0,r.Height() * 8.0);
	gSettings.Lock();
	BRect savedframe;
	if (gSettings.FindRect("libwin_frame",&savedframe) == B_OK)
		win->ResizeTo(savedframe.Width(),savedframe.Height());
	gSettings.Unlock();
	
	BStringView *label = (BStringView*)top->FindView("label");
	label->SetText(TR("Choose the system libraries for your project."));
	float minw = label->Frame().right + 10;
	win->SetSizeLimits(minw,30000,200,30000);
	if (win->Bounds().Width() < minw)
		win->ResizeTo(minw,win->Bounds().Height());
	win->fScanThread = -1;
	win->Unlock();
	
	return 0;
}