예제 #1
0
void
StartWindow::MessageReceived(BMessage *msg)
{
	switch (msg->what)
	{
		case M_NEW_PROJECT:
		{
			TemplateWindow *twin = new TemplateWindow(BRect(0,0,400,300));
			twin->Show();
			PostMessage(B_QUIT_REQUESTED);
			break;
		}
		case M_SHOW_OPEN_PROJECT:
		{
			fOpenPanel->Show();
			break;
		}
		case M_OPEN_SELECTION:
		{
			RefStringItem *item = (RefStringItem*)fListView->ItemAt(fListView->CurrentSelection());
			if (!item)
				break;
			
			msg->AddRef("refs",&item->ref);
			
			// fall through to M_OPEN_PROJECT
		}
		case M_OPEN_PROJECT:
		{
			// gQuitOnZeroWindows is a special flag which we set to 0 so that when this window
			// quits and deregisters itself with the app, Paladin doesn't close.
			Hide();
			atomic_add(&gQuitOnZeroWindows,-1);
			msg->what = B_REFS_RECEIVED;
			be_app->PostMessage(msg);
			PostMessage(B_QUIT_REQUESTED);
			break;
		}
		case M_SHOW_IMPORT:
		{
			fImportPanel->Show();
			break;
		}
		case M_ONLINE_IMPORT:
		{
			if (!gHgAvailable && !gGitAvailable && !gSvnAvailable)
			{
				ShowAlert("Online import requires Mercurial, "
							"Git, and/or Subversion to be installed, "
							"but Paladin can't find them. Sorry.");
			}
			else
			{
				SCMImportWindow *win = new SCMImportWindow();
				win->Show();
			}
			break;
		}
		case M_OPEN_FROM_LIST:
		{
			int32 index;
			if (msg->FindInt32("index", &index) == B_OK)
			{
				fListView->Select(index);
				PostMessage(M_OPEN_SELECTION);
			}
			break;
		}
		case M_QUICK_IMPORT:
		{
			Hide();
			be_app->PostMessage(msg);
			atomic_add(&gQuitOnZeroWindows,-1);
			PostMessage(B_QUIT_REQUESTED);
			break;
		}
		case M_REMOVE_FROM_LIST:
		{
			RefStringItem *item = (RefStringItem*)fListView->ItemAt(fListView->CurrentSelection());
			if (!item)
				break;
			
			fListView->RemoveItem(item);
			
			gSettings.Lock();
			
			entry_ref ref;
			int32 index = 0;
			while (gSettings.FindRef("recentitems",index++,&ref) == B_OK)
			{
				
				if (ref == item->ref)
				{
					gSettings.RemoveData("recentitems",index - 1);
					break;
				}
			}
			
			gSettings.Unlock();
			
			delete item;
			
			break;
		}
		default:
			DWindow::MessageReceived(msg);
	}
}
예제 #2
0
void
App::MessageReceived(BMessage *msg)
{
	switch (msg->what)
	{
		case M_MAKE_PROJECT:
		case M_RUN_PROJECT:
		case M_RUN_IN_TERMINAL:
		case M_RUN_IN_DEBUGGER:
		case M_RUN_WITH_ARGS:
		case M_FORCE_REBUILD:
		case M_SHOW_ADD_NEW_PANEL:
		case M_SHOW_FIND_AND_OPEN_PANEL:
		case M_SHOW_FIND_IN_PROJECT_FILES:
		case M_SHOW_ERROR_WINDOW:
		case M_TOGGLE_ERROR_WINDOW:
		{
			entry_ref ref;
			if (msg->FindRef("refs",&ref) == B_OK)
				PostToProjectWindow(msg,&ref);
			else
				PostToProjectWindow(msg,NULL);
			
			break;
		}

		case M_OPEN_PARTNER:
		{
			entry_ref ref;
			if (msg->FindRef("refs",&ref) == B_OK)
				OpenPartner(ref);
			break;
		}

		case M_NEW_PROJECT:
		{
			TemplateWindow *win = new TemplateWindow(BRect(100, 100, 400, 300));
			win->Show();
			break;
		}

		case M_SHOW_OPEN_PROJECT:
		{
			CheckCreateOpenPanel();
			fOpenPanel->Show();
			break;
		}

		case M_CREATE_PROJECT:
		{
			CreateNewProject(*msg);
			break;
		}

		case M_QUICK_IMPORT:
		{
			entry_ref ref;
			if (msg->FindRef("refs",&ref) != B_OK || !QuickImportProject(DPath(ref)))
			{
				StartWindow *startwin = new StartWindow();
				startwin->Show();
				break;
			}
			break;
		}
		
		// These are for quit determination. We have to use our own counter variable
		// (sWindowCount) because BFilePanels throw the count off. Using a variable
		// is much preferable to subclassing just for this reason.
		case M_REGISTER_WINDOW:
		{
			sWindowCount++;
			break;
		}

		case M_DEREGISTER_WINDOW:
		{
			sWindowCount--;
			if (sWindowCount <= 1)
				PostMessage(B_QUIT_REQUESTED);
			break;
		}

		case EDIT_OPEN_FILE:
		{
			int32 index = 0;
			entry_ref ref;
			while (msg->FindRef("refs",index,&ref) == B_OK)
			{
				int32 line;
				if (msg->FindInt32("line",index,&line) != B_OK)
					line = -1;
				int32 column;
				if (msg->FindInt32("column",index,&column) != B_OK)
					column = -1;
				
				OpenFile(ref,line,column);
				
				index++;
			}
			
			CheckCreateOpenPanel();
			fOpenPanel->GetPanelDirectory(&ref);
			gLastProjectPath.SetTo(ref);
			BWindow* openWindow = fOpenPanel->Window();
			break;
		}

		case M_FIND_AND_OPEN_FILE:
		{
			FindAndOpenFile(msg);
			break;
		}

		case M_BUILDING_FILE:
		{
			SourceFile *file;
			if (msg->FindPointer("sourcefile",(void**)&file) == B_OK)
				printf(B_TRANSLATE("Building %s\n"),file->GetPath().GetFileName());
			else
				printf(B_TRANSLATE("NULL pointer in M_BUILDING_FILE\n"));
			break;
		}

		case M_LINKING_PROJECT:
		{
			printf(B_TRANSLATE("Linking\n"));
			break;
		}

		case M_UPDATING_RESOURCES:
		{
			printf(B_TRANSLATE("Updating resources\n"));
			break;
		}

		case M_BUILD_FAILURE:
		{
			BString errstr;
			if (msg->FindString("errstr",&errstr) == B_OK)
				printf("%s\n",errstr.String());
			else
			{
				ErrorList errors;
				errors.Unflatten(*msg);
				printf(B_TRANSLATE("Build failure\n%s"), errors.AsString().String());
			}
			sReturnCode = -1;
			PostMessage(B_QUIT_REQUESTED);
			break;
		}

		case M_BUILD_WARNINGS:
		{
			BString errstr;
			if (msg->FindString("errstr",&errstr) == B_OK)
				printf("%s\n",errstr.String());
			break;
		}

		case M_BUILD_SUCCESS:
		{
			printf(B_TRANSLATE("Success\n"));
			PostMessage(B_QUIT_REQUESTED);
			break;
		}

		default:
			BApplication::MessageReceived(msg);
	}
}