Exemplo n.º 1
0
StartWindow::StartWindow(void)
	:	DWindow(BRect(0,0,400,300),"Paladin",B_DOCUMENT_WINDOW, B_NOT_ZOOMABLE)
{
	RegisterWindow();
	AddShortcut('O',B_COMMAND_KEY, new BMessage(M_SHOW_OPEN_PROJECT));
	AddShortcut('N',B_COMMAND_KEY, new BMessage(M_NEW_PROJECT));
	AddShortcut('I',B_COMMAND_KEY, new BMessage(M_SHOW_IMPORT));
	
	AddCommonFilter(new EscapeCancelFilter());
	
	MakeCenteredOnShow(true);
	
	BView *top = GetBackgroundView();
	
	fNewButton = MakeButton("new","NewProjectButtonUp.png","NewProjectButtonDown.png",
							M_NEW_PROJECT);
	top->AddChild(fNewButton);
	fNewButton->MoveTo(10,10);
		
	ClickableStringView *label = MakeLabel(fNewButton,TR("Create a new project"));
	top->AddChild(label);
	label->SetMessage(new BMessage(M_NEW_PROJECT));
	
	fOpenButton = MakeButton("open","OpenProjectButtonUp.png",
							"OpenProjectButtonDown.png", M_SHOW_OPEN_PROJECT);
	top->AddChild(fOpenButton);
	fOpenButton->MoveTo(10,fNewButton->Frame().bottom + 10.0);
	
	label = MakeLabel(fOpenButton,"Open a project");
	top->AddChild(label);
	label->SetMessage(new BMessage(M_SHOW_OPEN_PROJECT));
	
	fOpenRecentButton = MakeButton("openrecent","OpenRecentButtonUp.png",
									"OpenRecentButtonDown.png", M_OPEN_SELECTION);
	top->AddChild(fOpenRecentButton);
	fOpenRecentButton->MoveTo(10,fOpenButton->Frame().bottom + 10.0);
	SetToolTip(fOpenRecentButton,TR("Open a project in the list on the right. You "
									"can also press Command + a number key."));
	
	label = MakeLabel(fOpenRecentButton,TR("Open the selected project"));
	top->AddChild(label);
	label->SetMessage(new BMessage(M_OPEN_SELECTION));
	
	BRect r(Bounds());
	r.left = label->Frame().right + 20.0;
	r.right -= B_V_SCROLL_BAR_WIDTH + 10.0;
	r.top += 10.0;
	r.bottom -= 10.0;
	
	fListView = new StartWindowList(r);
	BScrollView *scrollView = new BScrollView("scroller",fListView,0,
											B_FOLLOW_ALL, false, true);
	top->AddChild(scrollView);
	fListView->SetInvocationMessage(new BMessage(M_OPEN_SELECTION));
	SetToolTip(fListView, "Open a recent project. You can also press Command + a number key.");
	
	fQuickImportButton = MakeButton("quickimport","QuickImportButtonUp.png",
									"QuickImportButtonDown.png",M_SHOW_IMPORT);
	top->AddChild(fQuickImportButton);
	fQuickImportButton->MoveTo(10,fOpenRecentButton->Frame().bottom + 10.0);
	
	label = MakeLabel(fQuickImportButton,"Import an existing project");
	top->AddChild(label);
	label->SetMessage(new BMessage(M_SHOW_IMPORT));
	SetToolTip(label,TR("Quickly make a project by importing all source files and resource files.\n"
						"You can also import a BeIDE project."));
	SetToolTip(fQuickImportButton,
				TR("Quickly make a project by importing all source files and resource files.\n"
					"You can also import a BeIDE project."));	
	fOnlineImportButton = MakeButton("onlineimport","OnlineImportButtonUp.png",
									"OnlineImportButtonDown.png",M_ONLINE_IMPORT);
	top->AddChild(fOnlineImportButton);
	fOnlineImportButton->MoveTo(10,fQuickImportButton->Frame().bottom + 10.0);
	
	label = MakeLabel(fOnlineImportButton,"Import a project from online");
	top->AddChild(label);
	label->SetMessage(new BMessage(M_ONLINE_IMPORT));
	SetToolTip(label,TR("Import a project from an online repository"));
	SetToolTip(fQuickImportButton,
				TR("Import a project from an online repository"));

	
	#ifdef DISABLE_ONLINE_IMPORT
	
	fOnlineImportButton->Hide();
	SetSizeLimits(scrollView->Frame().left + 110.0,30000,
				fQuickImportButton->Frame().bottom + 10.0,30000);
	ResizeTo(scrollView->Frame().left + 160.0,fQuickImportButton->Frame().bottom + 10.0);
	
	#else
	
	SetSizeLimits(scrollView->Frame().left + 110.0,30000,
				fOnlineImportButton->Frame().bottom + 10.0,30000);
	ResizeTo(scrollView->Frame().left + 160.0,fOnlineImportButton->Frame().bottom + 10.0);
	
	#endif
	
	BMessenger msgr(this);
	BEntry entry(gProjectPath.GetFullPath());
	entry_ref ref;
	entry.GetRef(&ref);
	fOpenPanel = new BFilePanel(B_OPEN_PANEL,&msgr,&ref,B_FILE_NODE,true,
								new BMessage(M_OPEN_PROJECT));
	BString titleString(TR("Open Project"));
	titleString.Prepend("Paladin: ");
	fOpenPanel->Window()->SetTitle(titleString.String());
	
	fImportPanel = new BFilePanel(B_OPEN_PANEL,&msgr,&ref,B_DIRECTORY_NODE,true,
								new BMessage(M_QUICK_IMPORT));
	titleString = TR("Choose Project Folder");
	titleString.Prepend("Paladin: ");
	fImportPanel->Window()->SetTitle(titleString.String());
	
	gSettings.Lock();
	int32 index = 0;
	while (gSettings.FindRef("recentitems",index++,&ref) == B_OK)
	{
		if (!BEntry(&ref).Exists())
		{
			index--;
			gSettings.RemoveData("recentitems",index);
		}
		else
			fListView->AddItem(new RefStringItem(ref),0);
	}
	gSettings.Unlock();
	
	// Alt + number opens that number project from the list
	int32 count = (fListView->CountItems() > 9) ? 9 : fListView->CountItems();
	for (int32 i = 0; i < count; i++)
	{
		BMessage *listMsg = new BMessage(M_OPEN_FROM_LIST);
		listMsg->AddInt32("index", i);
		AddShortcut('1' + i, B_COMMAND_KEY, listMsg);
	}
	
	fNewButton->MakeFocus(true);
}
Exemplo n.º 2
0
StartWindow::StartWindow(void)
	:
	BWindow(BRect(0, 0, -1, -1), "Paladin", B_TITLED_WINDOW,
		B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
{
	RegisterWindow();

	AddShortcut('O', B_COMMAND_KEY, new BMessage(M_SHOW_OPEN_PROJECT));
	AddShortcut('N', B_COMMAND_KEY, new BMessage(M_NEW_PROJECT));
	AddShortcut('I', B_COMMAND_KEY, new BMessage(M_SHOW_IMPORT));

	AddCommonFilter(new EscapeCancelFilter());

	// new button and label

	fNewButton = make_button("new", "NewProjectButtonUp.png",
		"NewProjectButtonDown.png", M_NEW_PROJECT);

	ClickableStringView* newLabel = make_label(fNewButton, TR("Create a new project"));
	newLabel->SetMessage(new BMessage(M_NEW_PROJECT));

	// open button and label

	fOpenButton = make_button("open", "OpenProjectButtonUp.png",
		"OpenProjectButtonDown.png", M_SHOW_OPEN_PROJECT);

	ClickableStringView* openLabel = make_label(fOpenButton, "Open a project");
	openLabel->SetMessage(new BMessage(M_SHOW_OPEN_PROJECT));

	// open recent button and label

	fOpenRecentButton = make_button("openrecent", "OpenRecentButtonUp.png",
		"OpenRecentButtonDown.png", M_OPEN_SELECTION);
	SetToolTip(fOpenRecentButton,
		TR("Open a project in the list on the right. You "
		   "can also press Command + a number key."));

	ClickableStringView* openRecentLabel = make_label(fOpenRecentButton,
		TR("Open the selected project"));
	openRecentLabel->SetMessage(new BMessage(M_OPEN_SELECTION));

	// quick import button and label

	fQuickImportButton = make_button("quickimport", "QuickImportButtonUp.png",
		"QuickImportButtonDown.png", M_SHOW_IMPORT);
	SetToolTip(fQuickImportButton,
		TR("Quickly make a project by importing all source files and resource files.\n"
		   "You can also import a BeIDE project."));

	ClickableStringView* quickImportLabel = make_label(fQuickImportButton,
		"Import an existing project");
	quickImportLabel->SetMessage(new BMessage(M_SHOW_IMPORT));
	SetToolTip(quickImportLabel,
		TR("Quickly make a project by importing all source files "
		   "and resource files.\n You can also import a BeIDE project."));

	// online import button and label

	fOnlineImportButton = make_button("onlineimport", "OnlineImportButtonUp.png",
		"OnlineImportButtonDown.png", M_ONLINE_IMPORT);
	SetToolTip(fQuickImportButton,
		TR("Import a project from an online repository"));

	ClickableStringView* onlineImportLabel = make_label(fOnlineImportButton,
		"Import a project from online");
	onlineImportLabel->SetMessage(new BMessage(M_ONLINE_IMPORT));
	SetToolTip(onlineImportLabel, TR("Import a project from an online repository"));

	// recent projects list view and scroller

	fRecentProjectsListView = new RecentProjectsList();
	// set the minimum width to 16em
	float minWidth = fRecentProjectsListView->StringWidth("M") * 16;
	fRecentProjectsListView->SetExplicitMinSize(BSize(minWidth, B_SIZE_UNSET));
	fRecentProjectsListView->SetInvocationMessage(new BMessage(M_OPEN_SELECTION));
	SetToolTip(fRecentProjectsListView,
		"Open a recent project. You can also press Command + a number key.");

	BLayoutBuilder::Group<>(this, B_HORIZONTAL)
		.AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
			.Add(fNewButton, 0, 0)
			.Add(newLabel, 1, 0)

			.Add(fOpenButton, 0, 1)
			.Add(openLabel, 1, 1)

			.Add(fOpenRecentButton, 0, 2)
			.Add(openRecentLabel, 1, 2)

			.Add(fQuickImportButton, 0, 3)
			.Add(quickImportLabel, 1, 3)

			.Add(fOnlineImportButton, 0, 4)
			.Add(onlineImportLabel, 1, 4)
			.End()
		.AddStrut(20)
		.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
			.Add(new BStringView("recentProjectsLabel", TR("Recent projects:")))
			.Add(new BScrollView("recentProjectsScroller", fRecentProjectsListView, 0,
				false, true))
			.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
		.End();

#ifdef DISABLE_ONLINE_IMPORT
	fOnlineImportButton->Hide();
#endif

	BMessenger messager(this);
	BEntry entry(gProjectPath.GetFullPath());
	entry_ref ref;
	entry.GetRef(&ref);
	fOpenPanel = new BFilePanel(B_OPEN_PANEL, &messager, &ref, B_FILE_NODE, true,
		new BMessage(M_OPEN_PROJECT));
	BString titleString(TR("Open Project"));
	titleString.Prepend("Paladin: ");
	fOpenPanel->Window()->SetTitle(titleString.String());

	fImportPanel = new BFilePanel(B_OPEN_PANEL, &messager, &ref, B_DIRECTORY_NODE,
		true, new BMessage(M_QUICK_IMPORT));
	titleString = TR("Choose Project Folder");
	titleString.Prepend("Paladin: ");
	fImportPanel->Window()->SetTitle(titleString.String());

	gSettings.Lock();
	int32 index = 0;
	while (gSettings.FindRef("recentitems", index++, &ref) == B_OK) {
		if (!BEntry(&ref).Exists()) {
			index--;
			gSettings.RemoveData("recentitems",index);
		} else
			fRecentProjectsListView->AddItem(new RefStringItem(ref),0);
	}
	gSettings.Unlock();

	// Alt + number opens that number project from the list
	int32 count = (fRecentProjectsListView->CountItems() > 9) ? 9 : fRecentProjectsListView->CountItems();
	for (int32 i = 0; i < count; i++) {
		BMessage* listMessage = new BMessage(M_OPEN_FROM_LIST);
		listMessage->AddInt32("index", i);
		AddShortcut('1' + i, B_COMMAND_KEY, listMessage);
	}

	fNewButton->MakeFocus(true);

	CenterOnScreen();
}