Пример #1
0
void
BToolbar::AddAction(BMessage* message, BHandler* target,
	const BBitmap* icon, const char* toolTipText, bool lockable)
{

	BButton* button;
	if (lockable)
		button = new LockableButton(NULL, NULL, message);
	else
		button = new BButton(NULL, NULL, message);
	button->SetIcon(icon);
	button->SetFlat(true);
	if (toolTipText != NULL)
		button->SetToolTip(toolTipText);
	_AddView(button);
	button->SetTarget(target);
}
Пример #2
0
ProjectSettingsWindow::ProjectSettingsWindow(BRect frame, Project* project)
	:
	BWindow(frame, TR("Project settings"), B_TITLED_WINDOW,
		B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS),
	fProject(project),
	fDirty(false)
{
	if (fProject == NULL)
		debugger("Bad project given to Project Settings window");

	fRefFilter = new TypedRefFilter(NULL, B_DIRECTORY_NODE);

	BMessenger messenger(this);
	entry_ref projectFolderRef;
	BEntry(fProject->GetPath().GetFolder()).GetRef(&projectFolderRef);
	fFilePanel = new BFilePanel(B_OPEN_PANEL, &messenger, &projectFolderRef,
		B_DIRECTORY_NODE, true, new BMessage(M_ADD_PATH), fRefFilter);

	fAutolock = new BAutolock(fProject);

	AddCommonFilter(new EscapeCancelFilter());

	fTargetText = new AutoTextControl("targetname", TR("Target name:"),
		fProject->GetTargetName(), new BMessage(M_TARGET_NAME_CHANGED));

	BPopUpMenu* targetTypeMenu = new BPopUpMenu(TR("Target type"));
	targetTypeMenu->AddItem(new BMenuItem(TR("Application"),
		new BMessage(M_SET_TARGET_TYPE)));
	targetTypeMenu->AddItem(new BMenuItem(TR("Shared library"),
		new BMessage(M_SET_TARGET_TYPE)));
	targetTypeMenu->AddItem(new BMenuItem(TR("Static library"),
		new BMessage(M_SET_TARGET_TYPE)));
	targetTypeMenu->AddItem(new BMenuItem(TR("Device driver"),
		new BMessage(M_SET_TARGET_TYPE)));

	fTypeField = new BMenuField("type", TR("Target type:"), targetTypeMenu);
	SetToolTip(fTypeField, TR("The kind of program you want to build"));

	BMenuItem* item = targetTypeMenu->ItemAt(fProject->TargetType());
	if (item != NULL)
		item->SetMarked(true);

	fIncludeList = new IncludeList(fProject->GetPath().GetFolder());
	SetToolTip(fIncludeList,
		TR("The folders you want Paladin to search for header files"));

	BScrollView* includeScrollView = new BScrollView("includescrollview",
		fIncludeList, B_WILL_DRAW, true, true);
	includeScrollView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	includeScrollView->SetExplicitMinSize(
		BSize(be_plain_font->StringWidth("M") * 34.0f,
			be_plain_font->StringWidth("M") * 12.0f));

	for (int32 i = 0; i < fProject->CountLocalIncludes(); i++) {
		fIncludeList->AddItem(new BStringItem(
			fProject->LocalIncludeAt(i).Relative().String()));
	}

	float buttonWidth = be_plain_font->StringWidth("+") * 2.0f + 3.0f;

	BButton* addButton = new BButton("addbutton", TR("+"),
		new BMessage(M_SHOW_ADD_PATH));
	addButton->SetExplicitSize(BSize(buttonWidth, buttonWidth));
	addButton->SetToolTip(TR("Add a file to the include path list"));

	BButton* removeButton = new BButton("removebutton", TR("−"),
		new BMessage(M_REMOVE_PATH));
	removeButton->SetExplicitSize(BSize(buttonWidth, buttonWidth));
	removeButton->SetToolTip(TR("Remove the selected path"));

	// general tab

	fGeneralView = new BView(TR("General"), B_WILL_DRAW);
	fGeneralView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	BLayoutBuilder::Group<>(fGeneralView, B_VERTICAL, 0)
		.AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
			.Add(fTargetText->CreateLabelLayoutItem(), 0, 0)
			.Add(fTargetText->CreateTextViewLayoutItem(), 1, 0)

			.Add(fTypeField->CreateLabelLayoutItem(), 0, 1)
			.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 1)
				.Add(fTypeField->CreateMenuBarLayoutItem())
				.AddGlue()
				.End()
			.End()
		.AddStrut(B_USE_DEFAULT_SPACING)
		.AddGroup(B_VERTICAL, 2.0f)
			.Add(new BStringView("include paths", TR("Include paths:")))
			.AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING)
				.Add(includeScrollView)
				.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
					.Add(addButton)
					.Add(removeButton)
					.AddGlue()
					.End()
				.End()
			.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
		.End();

	BPopUpMenu* optimizationMenu = new BPopUpMenu(TR("Optimization"));
	optimizationMenu->AddItem(new BMenuItem(TR("None"),
		new BMessage(M_SET_OP_VALUE)));
	optimizationMenu->AddItem(new BMenuItem(TR("Some"),
		new BMessage(M_SET_OP_VALUE)));
	optimizationMenu->AddItem(new BMenuItem(TR("More"),
		new BMessage(M_SET_OP_VALUE)));
	optimizationMenu->AddItem(new BMenuItem(TR("Full"),
		new BMessage(M_SET_OP_VALUE)));

	fOpField = new BMenuField("optimize", TR("Optimize:"), optimizationMenu);
	SetToolTip(fOpField, TR("Compiler optimization level. "
		"Disabled when debugging info is checked."));

	item = optimizationMenu->ItemAt(fProject->OpLevel());
	if (item != NULL)
		item->SetMarked(true);

	fOpSizeBox = new BCheckBox("opsizebox", TR("Optimize for size over speed"),
		new BMessage(M_TOGGLE_OPSIZE));

	if (fProject->OpForSize())
		fOpSizeBox->SetValue(B_CONTROL_ON);
	
	if (fProject->Debug()) {
		fOpField->SetEnabled(false);
		fOpSizeBox->SetEnabled(false);
	}

	fDebugBox = new BCheckBox("debugbox", TR("Build debugging information"),
		new BMessage(M_TOGGLE_DEBUG));
	SetToolTip(fDebugBox,
		TR("Check this if you want to use your program in a debugger "
		   "during development. You'll want to rebuild your project "
		   "after change this."));

	if (fProject->Debug())
		fDebugBox->SetValue(B_CONTROL_ON);

	fProfileBox = new BCheckBox("profilebox", TR("Build profiling information"),
		new BMessage(M_TOGGLE_PROFILE));
	SetToolTip(fProfileBox,
		TR("Check this if you want to use your program "
		   "with gprof or bprof for profiling."));

	if (fProject->Profiling())
		fProfileBox->SetValue(B_CONTROL_ON);

	fCompileText = new AutoTextControl("extracc", "Extra compiler options:",
		fProject->ExtraCompilerOptions(), new BMessage(M_CCOPTS_CHANGED));
	SetToolTip(fCompileText,
		TR("Extra GCC flags you wish included when each file is compiled."));

	fLinkText = new AutoTextControl("extrald" ,TR("Extra linker options:"),
		fProject->ExtraLinkerOptions(), new BMessage(M_LDOPTS_CHANGED));
	SetToolTip(fLinkText,
		TR("Extra GCC linker flags you wish included when your project "
		   "is linked."));

	// build tab

	fBuildView = new BView("Build", B_WILL_DRAW);
	fBuildView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	BLayoutBuilder::Group<>(fBuildView, B_VERTICAL)
		.AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
			.Add(fOpField->CreateLabelLayoutItem(), 0, 0)
			.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 0)
				.Add(fOpField->CreateMenuBarLayoutItem())
				.AddGlue()
				.End()
			.AddGroup(B_VERTICAL, 0.0f, 1, 2)
				.Add(fOpSizeBox)
				.AddStrut(B_USE_SMALL_SPACING)
				.Add(fDebugBox)
				.Add(fProfileBox)
				.End()
			.End()
		.AddGlue()
		.AddGroup(B_VERTICAL, 0)
			.Add(fCompileText->CreateLabelLayoutItem())
			.Add(fCompileText->CreateTextViewLayoutItem())
			.End()
		.AddGroup(B_VERTICAL, 0)
			.Add(fLinkText->CreateLabelLayoutItem())
			.Add(fLinkText->CreateTextViewLayoutItem())
			.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
		.End();

	fTabView = new BTabView("tabview", B_WIDTH_FROM_LABEL);
	fTabView->SetBorder(B_NO_BORDER);
	fTabView->AddTab(fGeneralView);
	fTabView->AddTab(fBuildView);
	fTabView->Select(0L);

	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
		.AddStrut(B_USE_SMALL_SPACING)
		.Add(fTabView)
		.End();

	targetTypeMenu->SetTargetForItems(this);
	optimizationMenu->SetTargetForItems(this);

	fIncludeList->Select(0);
	fTargetText->MakeFocus(true);
}