コード例 #1
0
ファイル: TemplateWindow.cpp プロジェクト: passick/Paladin
void
TemplateWindow::MessageReceived(BMessage *msg)
{
	switch (msg->what)
	{
		case M_NAME_CHANGED:
		case M_TARGET_CHANGED:
		{
			if (fNameBox->Text() && strlen(fNameBox->Text()) > 0 &&
				fTargetBox->Text() && strlen(fTargetBox->Text()) > 0)
				fOK->SetEnabled(true);
			else
				fOK->SetEnabled(false);
			break;
		}
		case M_CREATE_PROJECT:
		{
			BMenu *menu = fTemplateField->Menu();
			BMenuItem *item = menu->FindMarked();
			if (!item)
				break;
			
			int32 selection = menu->IndexOf(item);
			ProjectTemplate *ptemp = fTempList.TemplateAt(selection);
			
			BMessage projmsg(M_CREATE_PROJECT),reply;
			projmsg.AddString("name",fNameBox->Text());
			projmsg.AddString("target",fTargetBox->Text());
			projmsg.AddInt32("type",ptemp->TargetType());
			projmsg.AddString("path",fPathBox->Path());
			projmsg.AddString("template", ptemp->GetRef().name);
			projmsg.AddString("pldfile", ptemp->ProjectFileName());
			
			BMenu *scmMenu = fSCMChooser->Menu();
			int32 scm = scmMenu->IndexOf(scmMenu->FindMarked());
			projmsg.AddInt32("scmtype",scm);
			
			if (!ptemp->ProjectFileName())
			{
				for (int32 i = 0; i < ptemp->CountFiles(); i++)
					projmsg.AddRef("refs",ptemp->FileAt(i));
				
				for (int32 i = 0; i < ptemp->CountLibs(); i++)
					projmsg.AddRef("libs",ptemp->LibAt(i));
			}
			
			projmsg.AddBool("createfolder",(fCreateFolder->Value() == B_CONTROL_ON));
			be_app_messenger.SendMessage(&projmsg,&reply);
			PostMessage(B_QUIT_REQUESTED);
			break;
		}
		default:
		{
			DWindow::MessageReceived(msg);
			break;
		}
	}
}
コード例 #2
0
ファイル: TemplateWindow.cpp プロジェクト: passick/Paladin
TemplateWindow::TemplateWindow(const BRect &frame)
	:	DWindow(frame,TR("Choose a Project Type"),B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS |
				B_NOT_V_RESIZABLE)
{
	RegisterWindow();
	
	MakeCenteredOnShow(true);
	
	CheckTemplates();
	
	DPath templatePath(gAppPath.GetFolder());
	templatePath << TR("Templates");
	fTempList.ScanFolder(templatePath.GetFullPath());
	
	BView *top = GetBackgroundView();
	
	if (Bounds().Height() < 100)
		ResizeTo(Bounds().Width(),100);
	if (Bounds().Width() < 100)
		ResizeTo(100,Bounds().Height());
	
	BRect r(Bounds());
	BRect bounds(r);
	
	float divider = be_plain_font->StringWidth(TR("Source Control:")) + 5.0;
	
	BMenu *menu = new BMenu("Project Type");
	for (int32 i = 0; i < fTempList.CountTemplates(); i++)
	{
		ProjectTemplate *ptemp = fTempList.TemplateAt(i);
		entry_ref ref = ptemp->GetRef();
		menu->AddItem(new BMenuItem(ref.name,new BMessage(M_TEMPLATE_SELECTED)));
	}
	
	menu->SetRadioMode(true);
	menu->SetLabelFromMarked(true);
	menu->ItemAt(0L)->SetMarked(true);
	
	font_height fh;
	be_plain_font->GetHeight(&fh);
	float fontHeight = fh.ascent + fh.descent + fh.leading;
	r.bottom = MAX(fontHeight,20.0);
	
	r.OffsetBy(10,10);
	fTemplateField = new BMenuField(r,"templatefield",TR("Project Type: "), menu);
	fTemplateField->SetDivider(be_plain_font->StringWidth(TR("Project Type:")) + 5);
	top->AddChild(fTemplateField);
	
	// controls for the options for all project types
	r.OffsetBy(0,r.IntegerHeight() + 10);
	fNameBox = new AutoTextControl(r,"namebox",TR("Project Name:"),NULL,
									new BMessage(M_NAME_CHANGED),
									B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	top->AddChild(fNameBox);
	fNameBox->ResizeToPreferred();
	r.bottom = r.top + fNameBox->Bounds().Height();
	fNameBox->ResizeTo(bounds.Width() - 20.0,r.Height());
	fNameBox->SetDivider(divider);
	SetToolTip(fNameBox, "The name of your project. It can be the same as the Target Name, "
						"but it does not have to be.");
	
	r.OffsetBy(0,r.IntegerHeight() + 10);
	fTargetBox = new AutoTextControl(r,"targetbox",TR("Target Name:"),"BeApp",
									new BMessage(M_TARGET_CHANGED),
									B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	top->AddChild(fTargetBox);
	fTargetBox->ResizeToPreferred();
	r.bottom = r.top + fTargetBox->Bounds().Height();
	fTargetBox->ResizeTo(bounds.Width() - 20.0,r.Height());
	fTargetBox->SetDivider(divider);
	SetToolTip(fTargetBox, "The name of the compiled application or library");
	
	if (!BEntry(PROJECT_PATH).Exists())
		create_directory(PROJECT_PATH,0777);
	
	r.OffsetBy(0,r.Height() + 10);
	fPathBox = new PathBox(r,"pathbox",gProjectPath.GetFullPath(),TR("Location:"),
							B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	top->AddChild(fPathBox);
	fPathBox->ResizeToPreferred();
	r.bottom = r.top + fPathBox->Bounds().Height();
	fPathBox->ResizeTo(bounds.Width() - 20.0,r.Height());
	fPathBox->SetDivider(divider);
	SetToolTip(fPathBox, "Set the location for your project.");
	
	menu = new BMenu("SCM Chooser");
	menu->AddItem(new BMenuItem("Mercurial", new BMessage()));
	menu->AddItem(new BMenuItem("Git", new BMessage()));
	menu->AddItem(new BMenuItem("Subversion", new BMessage()));
	menu->AddItem(new BMenuItem("None", new BMessage()));
	
	if (!gHgAvailable)
	{
		menu->ItemAt(0)->SetEnabled(false);
		menu->ItemAt(0)->SetLabel("Mercurial Unavailable");
	}
	
	if (!gGitAvailable)
	{
		menu->ItemAt(1)->SetEnabled(false);
		menu->ItemAt(1)->SetLabel("Git Unavailable");
	}
	
	if (!gSvnAvailable)
	{
		menu->ItemAt(2)->SetEnabled(false);
		menu->ItemAt(2)->SetLabel("Subversion Unavailable");
	}
	
	
	r.OffsetBy(0,r.Height() + 5.0);
	fSCMChooser = new BMenuField(r, "scmchooser", "Source Control: ", menu);
	top->AddChild(fSCMChooser);
	fSCMChooser->SetDivider(divider);
	SetToolTip(fSCMChooser, "Choose the source control manager for your project, if any.");
	
	menu->SetLabelFromMarked(true);
	menu->ItemAt(gDefaultSCM)->SetMarked(true);
	
	BMenuItem *item = menu->FindMarked();
	if (!item->IsEnabled())
	{
		item->SetMarked(false);
		for (int32 i = 0; i < menu->CountItems(); i++)
		{
			if (menu->ItemAt(i)->IsEnabled())
			{
				menu->ItemAt(i)->SetMarked(true);
				break;
			}
		}
	}
	menu->SetLabelFromMarked(true);
	
	r.OffsetBy(0,r.Height() + 5.0);
	fCreateFolder = new BCheckBox(r,"createfolder",TR("Create Project Folder"),NULL);
	fCreateFolder->MoveTo(divider + 10.0, r.top);
	fCreateFolder->SetValue(B_CONTROL_ON);
	top->AddChild(fCreateFolder);
	SetToolTip(fCreateFolder, "If checked, a folder for your project will be created "
							"in the folder in the Location box above.");
	
	r.OffsetBy(0,r.Height() + 5.0);
	fOK = new BButton(r,"ok",TR("Create Project…"), new BMessage(M_CREATE_PROJECT));
	fOK->ResizeToPreferred();
	top->AddChild(fOK);
	fOK->SetEnabled(false);
	fOK->MakeDefault(true);
	
	float offset = fPathBox->Divider();
	fOK->MoveBy(offset,0);
	
	float minwidth = Bounds().Width();
	float minheight = fOK->Frame().bottom + 10.0;
	SetSizeLimits(minwidth,30000,minheight,30000);
	
	gSettings.Lock();
	BRect savedframe;
	if (gSettings.FindRect("template_frame",&savedframe) == B_OK)
		ResizeTo(savedframe.Width(),savedframe.Height());
	else
		ResizeTo(minwidth,minheight);
	gSettings.Unlock();
		
	fNameBox->MakeFocus(true);
}
コード例 #3
0
ファイル: TemplateWindow.cpp プロジェクト: jscipione/Paladin
TemplateWindow::TemplateWindow(const BRect& frame)
	:
	BWindow(frame, TR("Choose a project type"), B_TITLED_WINDOW,
		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
{
	RegisterWindow();

	CheckTemplates();

	DPath templatePath(gAppPath.GetFolder());
	templatePath << TR("Templates");
	fTempList.ScanFolder(templatePath.GetFullPath());

	// project type

	BPopUpMenu* projectTypeMenu = new BPopUpMenu("Project type");
	for (int32 i = 0; i < fTempList.CountTemplates(); i++) {
		ProjectTemplate* ptemp = fTempList.TemplateAt(i);
		entry_ref ref = ptemp->GetRef();
		projectTypeMenu->AddItem(new BMenuItem(ref.name,
			new BMessage(M_TEMPLATE_SELECTED)));
	}
	projectTypeMenu->ItemAt(0L)->SetMarked(true);

	fTemplateField = new BMenuField("templatefield", TR("Project type: "),
		projectTypeMenu);
	fTemplateField->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	// project name

	fNameBox = new AutoTextControl("namebox", TR("Project name:"), "",
		new BMessage(M_NAME_CHANGED));
	SetToolTip(fNameBox, TR("The name of your project. "
		"It can be the same as the Target name, but it does not have to be."));

	// target name

	fTargetBox = new AutoTextControl("targetbox", TR("Target name:"), "BeApp",
		new BMessage(M_TARGET_CHANGED));
	SetToolTip(fTargetBox, TR("The name of the compiled application or library"));

	// project path

	fPathBox = new PathBox("pathbox", gProjectPath.GetFullPath(), "");
	fPathBox->SetExplicitMinSize(BSize(be_plain_font->StringWidth("M") * 36,
		B_SIZE_UNSET)),
	SetToolTip(fPathBox, TR("Set the location for your project."));

	// source control

	BPopUpMenu* scmMenu = new BPopUpMenu("SCM Chooser");
	scmMenu->AddItem(new BMenuItem(TR("Mercurial"), new BMessage()));
	scmMenu->AddItem(new BMenuItem(TR("Git"), new BMessage()));
	scmMenu->AddItem(new BMenuItem(TR("Subversion"), new BMessage()));
	scmMenu->AddItem(new BMenuItem(TR("None"), new BMessage()));

	if (!gHgAvailable) {
		scmMenu->ItemAt(0)->SetEnabled(false);
		scmMenu->ItemAt(0)->SetLabel(TR("Mercurial unavailable"));
	}
	if (!gGitAvailable) {
		scmMenu->ItemAt(1)->SetEnabled(false);
		scmMenu->ItemAt(1)->SetLabel(TR("Git unavailable"));
	}
	if (!gSvnAvailable) {
		scmMenu->ItemAt(2)->SetEnabled(false);
		scmMenu->ItemAt(2)->SetLabel(TR("Subversion unavailable"));
	}

	fSCMChooser = new BMenuField("scmchooser", TR("Source control: "), scmMenu);
	fSCMChooser->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	SetToolTip(fSCMChooser,
		TR("Choose the source control manager for your project, if any."));

	scmMenu->ItemAt(gDefaultSCM)->SetMarked(true);

	BMenuItem* item = scmMenu->FindMarked();
	if (!item->IsEnabled()) {
		item->SetMarked(false);
		for (int32 i = 0; i < scmMenu->CountItems(); i++) {
			if (scmMenu->ItemAt(i)->IsEnabled()) {
				scmMenu->ItemAt(i)->SetMarked(true);
				break;
			}
		}
	}

	// create folder check box

	fCreateFolder = new BCheckBox(TR("Create project folder"));
	fCreateFolder->SetValue(B_CONTROL_ON);
	SetToolTip(fCreateFolder, TR("If checked, a folder for your project will be created "
		"in the folder in the Location box above."));

	// create project button

	fCreateProjectButton = new BButton("ok", TR("Create project") B_UTF8_ELLIPSIS,
		new BMessage(M_CREATE_PROJECT));
	fCreateProjectButton->SetEnabled(false);
	fCreateProjectButton->MakeDefault(true);

	// layout

	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
			.Add(fTemplateField->CreateLabelLayoutItem(), 0, 0)
			.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 0)
				.Add(fTemplateField->CreateMenuBarLayoutItem())
				.AddGlue()
				.End()

			.Add(fNameBox->CreateLabelLayoutItem(), 0, 1)
			.Add(fNameBox->CreateTextViewLayoutItem(), 1, 1)

			.Add(fTargetBox->CreateLabelLayoutItem(), 0, 2)
			.Add(fTargetBox->CreateTextViewLayoutItem(), 1, 2)

			.Add(new BStringView("location", TR("Location:")), 0, 3)
			.Add(fPathBox, 1, 3)

			.Add(fSCMChooser->CreateLabelLayoutItem(), 0, 4)
			.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 4)
				.Add(fSCMChooser->CreateMenuBarLayoutItem())
				.AddGlue()
				.End()

			.Add(fCreateFolder, 1, 5)
			.End()
		.AddGlue()
		.AddGroup(B_HORIZONTAL)
			.AddGlue()
			.Add(fCreateProjectButton)
			.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
		.End();

	fNameBox->MakeFocus(true);

	CenterOnScreen();
}