void ProjectWindow::UpdateDependencies(void) { bool toggleHack = false; if (gPlatform == PLATFORM_HAIKU || gPlatform == PLATFORM_HAIKU_GCC4) toggleHack = true; if (toggleHack) gUsePipeHack = false; fStatusBar->SetText("Updating dependencies"); SetMenuLock(true); for (int32 i = 0; i < fProjectList->CountItems(); i++) { SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->FullListItemAt(i)); if (item) item->GetData()->UpdateDependencies(*fProject->GetBuildInfo()); UpdateIfNeeded(); } SetMenuLock(false); fStatusBar->SetText(""); if (toggleHack) gUsePipeHack = true; }
void MediaConverterWindow::SourceFileSelectionChanged() { int32 selected = fListView->CurrentSelection(); BMediaFile* file = NULL; entry_ref ref; bool enabled = GetSourceFileAt(selected, &file, &ref) == B_OK; fPreviewButton->SetEnabled(enabled); fVideoQualitySlider->SetEnabled(enabled); fAudioQualitySlider->SetEnabled(enabled); fStartDurationTC->SetEnabled(enabled); fEndDurationTC->SetEnabled(enabled); BString duration; if (enabled) { fInfoView->Update(file, &ref); // HACK: get the fInfoView to update the duration "synchronously" UpdateIfNeeded(); duration << fInfoView->Duration() / 1000; } else duration = "0"; // update duration text controls fStartDurationTC->SetText("0"); fEndDurationTC->SetText(duration.String()); }
//------------------------------------------------------------------- void MainWindow::MessageReceived(BMessage * message) { switch(message->what) { case ABOUT: case CLEAR: case SPEED1: case SPEED2: case SPEED3: case SPEED4: case SPEED5: case LOOP1: case LOOP2: case LOOP3: case LOOP4: case LOOP5: case ANIMATE: Main->MessageReceived(message);break; default:BWindow::MessageReceived(message);break; } UpdateIfNeeded(); }
void ErrorWindow::RefreshList(void) { EmptyList(); fErrors.Rewind(); error_msg* item = fErrors.GetNextItem(); int32 counter = 0; while (item != NULL) { ErrMsgToItem(item); if (counter % 5 == 0) UpdateIfNeeded(); counter++; item = fErrors.GetNextItem(); } }
void MidiPlayerWindow::OnInputChanged(BMessage* msg) { int32 newId; if (msg->FindInt32("id", &newId) == B_OK) { BMidiProducer* endp; endp = BMidiRoster::FindProducer(inputId); if (endp != NULL) { endp->Disconnect(bridge); endp->Release(); } inputId = newId; endp = BMidiRoster::FindProducer(inputId); if (endp != NULL) { if (!instrLoaded) { scopeView->SetLoading(true); scopeView->Invalidate(); UpdateIfNeeded(); bridge->Init(B_BIG_SYNTH); instrLoaded = true; scopeView->SetLoading(false); scopeView->Invalidate(); } endp->Connect(bridge); endp->Release(); scopeView->SetLiveInput(true); scopeView->Invalidate(); } else { scopeView->SetLiveInput(false); scopeView->Invalidate(); } } }
void MidiPlayerWindow::OnPlayStop() { if (playing) { playButton->SetEnabled(false); scopeView->SetPlaying(false); scopeView->Invalidate(); UpdateIfNeeded(); StopSynth(); } else { playButton->SetLabel(B_TRANSLATE("Stop")); scopeView->SetPlaying(true); scopeView->Invalidate(); StartSynth(); } }
void ErrorWindow::AppendToList(ErrorList& list) { list.Rewind(); error_msg* message = list.GetNextItem(); int32 counter = 0; while (message != NULL) { error_msg* newmessage = new error_msg; *newmessage = *message; fErrors.msglist.AddItem(newmessage); ErrMsgToItem(newmessage); if (counter % 5 == 0) UpdateIfNeeded(); counter++; message = list.GetNextItem(); } }
void MidiPlayerWindow::LoadFile(entry_ref* ref) { if (playing) { scopeView->SetPlaying(false); scopeView->Invalidate(); UpdateIfNeeded(); StopSynth(); } synth.UnloadFile(); if (synth.LoadFile(ref) == B_OK) { // Ideally, we would call SetVolume() in InitControls(), // but for some reason that doesn't work: BMidiSynthFile // will use the default volume instead. So we do it here. synth.SetVolume(volume / 100.0f); playButton->SetEnabled(true); playButton->SetLabel(B_TRANSLATE("Stop")); scopeView->SetHaveFile(true); scopeView->SetPlaying(true); scopeView->Invalidate(); StartSynth(); } else { playButton->SetEnabled(false); playButton->SetLabel(B_TRANSLATE("Play")); scopeView->SetHaveFile(false); scopeView->SetPlaying(false); scopeView->Invalidate(); (new BAlert(NULL, B_TRANSLATE("Could not load song"), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go(); } }
void AuthenticationPanel::MessageReceived(BMessage* message) { switch (message->what) { case kMsgPanelOK: release_sem(m_exitSemaphore); break; case kHidePassword: { // TODO: Toggling this is broken in BTextView. Workaround is to // set the text and selection again. BString text = m_passwordTextControl->Text(); int32 selectionStart; int32 selectionEnd; m_passwordTextControl->TextView()->GetSelection(&selectionStart, &selectionEnd); m_passwordTextControl->TextView()->HideTyping( m_hidePasswordCheckBox->Value() == B_CONTROL_ON); m_passwordTextControl->SetText(text.String()); m_passwordTextControl->TextView()->Select(selectionStart, selectionEnd); break; } case kMsgJitter: { UpdateIfNeeded(); BPoint leftTop = Frame().LeftTop(); const float jitterOffsets[] = { -10, 0, 10, 0 }; const int32 jitterOffsetCount = sizeof(jitterOffsets) / sizeof(float); for (int32 i = 0; i < 20; i++) { float offset = jitterOffsets[i % jitterOffsetCount]; MoveTo(leftTop.x + offset, leftTop.y); snooze(15000); } MoveTo(leftTop); break; } default: BWindow::MessageReceived(message); } }
void ProjectWindow::DoBuild(int32 postbuild) { if (fErrorWindow) fErrorWindow->PostMessage(M_CLEAR_ERROR_LIST); fProject->GetErrorList()->msglist.MakeEmpty(); // Missing file check for (int32 i = 0; i < fProjectList->CountItems(); i++) { SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->ItemAt(i)); if (item && item->GetDisplayState() == SFITEM_MISSING) { ShowAlert(TR("The project cannot be built because some of its files are missing.")); return; } } fStatusBar->SetText("Examining source files"); UpdateIfNeeded(); SetMenuLock(true); fBuilder.BuildProject(fProject,postbuild); }
void ApplicationTypesWindow::_RemoveUninstalled() { // Note: this runs in the looper's thread, which isn't that nice int32 removed = 0; volatile bool quit = false; BWindow* progressWindow = new ProgressWindow( B_TRANSLATE("Removing uninstalled application types"), fTypeListView->FullListCountItems(), &quit); progressWindow->AddToSubset(this); progressWindow->Show(); for (int32 i = fTypeListView->FullListCountItems(); i-- > 0 && !quit;) { MimeTypeItem* item = dynamic_cast<MimeTypeItem*> (fTypeListView->FullListItemAt(i)); progressWindow->PostMessage(B_UPDATE_STATUS_BAR); if (item == NULL) continue; // search for application on all volumes bool found = false; BVolumeRoster volumeRoster; BVolume volume; while (volumeRoster.GetNextVolume(&volume) == B_OK) { if (!volume.KnowsQuery()) continue; BQuery query; query.PushAttr("BEOS:APP_SIG"); query.PushString(item->Type()); query.PushOp(B_EQ); query.SetVolume(&volume); query.Fetch(); entry_ref ref; if (query.GetNextRef(&ref) == B_OK) { found = true; break; } } if (!found) { BMimeType mimeType(item->Type()); mimeType.Delete(); removed++; // We're blocking the message loop that received the MIME changes, // so we dequeue all waiting messages from time to time if (removed % 10 == 0) UpdateIfNeeded(); } } progressWindow->PostMessage(B_QUIT_REQUESTED); static BMessageFormat format(B_TRANSLATE("{0, plural, " "one{# Application type could be removed} " "other{# Application types could be removed}}")); BString message; format.Format(message, removed); error_alert(message, B_OK, B_INFO_ALERT); }
void CFtpDialog::ListDirectory() { if (fSocket < 0) { beep(); return; } for (int i = fListView->CountItems() - 1; i >= 0; i--) delete fListView->RemoveItem(i); int data = 0; try { struct sockaddr_in saData; struct sockaddr_in saCmd; data = socket(AF_INET, SOCK_STREAM, 0); if (data < 0) THROW(("Failed to get socket: %s", strerror(errno))); memset(&saData, 0, sizeof(saData)); saData.sin_family = AF_INET; socklen_t size = sizeof(saData); bool passive = IsOn("pssv"); if (passive) { // switch to passive mode s_printf(fSocketFD, "pasv\r\n"); } else { FailSockErr(bind(data, (struct sockaddr *)&saData, sizeof(saData))); FailSockErr(listen(data, 5)); // [zooey]: calling getsockname() on a socket that has been bound to // IN_ADDR_ANY (the wildcard-address) will *not* return any IP-address, // as this will only be setup by the system during connect or accept. // [refer to W.R. Stevens - Unix Network Programming, Vol 1, p. 92] // BeOS R5 however, *does* fill in the IP-address at this stage (that's // why this code worked for R5 but didn't work for BONE). // In order to fix this problem, we simply use the IP-address of the // command-socket for the PORT-command: // // fetch port from data-socket: FailSockErr(getsockname(data, (struct sockaddr *)&saData, &size)); unsigned char *pap = (unsigned char *)&saData.sin_port; // fetch ip-address from cmd-socket: FailSockErr(getsockname(fSocketFD->sSocket, (struct sockaddr *)&saCmd, &size)); unsigned char *sap = (unsigned char *)&saCmd.sin_addr.s_addr; // combine both into the PORT-command: s_printf(fSocketFD, "port %d,%d,%d,%d,%d,%d\r\n", sap[0], sap[1], sap[2], sap[3], pap[0], pap[1]); } int state = 1; SOCK* dsf = NULL; while (state) { GetReply(); switch (state) { case 1: if (passive) { unsigned int sap[4]; unsigned int pap[2]; if (*fReply != '2') THROW(("Pasv command failed: %s", fReply)); char* pos = strchr(fReply,'('); if (!pos) THROW(("Answer to Pasv has unknown format: %s", fReply)); int cnt = sscanf(pos+1, "%u,%u,%u,%u,%u,%u", &sap[0], &sap[1], &sap[2], &sap[3], &pap[0], &pap[1]); if (cnt != 6) THROW(("Could not parse answer to Pasv (%d of 6): %s", cnt, fReply)); char ipAddr[20]; sprintf(ipAddr, "%d.%d.%d.%d", sap[0], sap[1], sap[2], sap[3]); saData.sin_port = htons(pap[0]*256+pap[1]); saData.sin_addr.s_addr = inet_addr(ipAddr); FailOSErr(connect(data, (struct sockaddr *)&saData, sizeof(saData))); dsf = s_open(data, "r+"); } else { if (*fReply != '2') THROW(("Port command failed: %s", fReply)); } s_printf(fSocketFD, "list\r\n"); state = 2; break; case 2: if (*fReply == '1') { int ds = 0; if (!passive) { FailSockErr(ds = accept(data, (struct sockaddr *)&saData, &size)); dsf = s_open(ds, "r+"); } try { CFtpListItem *item; char s[256]; bool showAll = IsOn("dotf"); int entryCount = 0; while (s_gets(s, 256, dsf)) { entryCount++; item = new CFtpListItem(this, s); if (item->IsValid() && (showAll || !item->IsDotFile())) { fListView->AddItem(item); } else delete item; } if (entryCount == 0) THROW(("Could not get listing.")); fListView->Invalidate(); UpdateIfNeeded(); s_close(dsf); if (!passive) closesocket(ds); } catch (HErr& e) { EnableUpdates(); s_close(dsf); closesocket(ds); throw; } state = 3; } else THROW(("Failed to get listing: %s", fReply)); break; case 3: if (*fReply != '2') THROW(("Something went wrong fetching the directory listing")); state = 0; break; } } closesocket(data); } catch (HErr& e) { if (data) closesocket(data); e.DoError(); } } // CFtpDialog::ListDirectory
void ShowImageWindow::MessageReceived(BMessage* message) { if (message->WasDropped()) { uint32 type; int32 count; status_t status = message->GetInfo("refs", &type, &count); if (status == B_OK && type == B_REF_TYPE) { message->what = B_REFS_RECEIVED; be_app->PostMessage(message); } } switch (message->what) { case kMsgImageCacheImageLoaded: { fProgressWindow->Stop(); BitmapOwner* bitmapOwner = NULL; message->FindPointer("bitmapOwner", (void**)&bitmapOwner); bool first = fImageView->Bitmap() == NULL; entry_ref ref; message->FindRef("ref", &ref); if (!first && ref != fNavigator.CurrentRef()) { // ignore older images if (bitmapOwner != NULL) bitmapOwner->ReleaseReference(); break; } int32 page = message->FindInt32("page"); int32 pageCount = message->FindInt32("pageCount"); if (!first && page != fNavigator.CurrentPage()) { // ignore older pages if (bitmapOwner != NULL) bitmapOwner->ReleaseReference(); break; } status_t status = fImageView->SetImage(message); if (status != B_OK) { if (bitmapOwner != NULL) bitmapOwner->ReleaseReference(); _LoadError(ref); // quit if file could not be opened if (first) Quit(); break; } fImageType = message->FindString("type"); fNavigator.SetTo(ref, page, pageCount); fImageView->FitToBounds(); if (first) { fImageView->MakeFocus(true); // to receive key messages Show(); } _UpdateRatingMenu(); // Set width and height attributes of the currently showed file. // This should only be a temporary solution. _SaveWidthAndHeight(); break; } case kMsgImageCacheProgressUpdate: { entry_ref ref; if (message->FindRef("ref", &ref) == B_OK && ref == fNavigator.CurrentRef()) { message->what = kMsgProgressUpdate; fProgressWindow->PostMessage(message); } break; } case MSG_MODIFIED: // If image has been modified due to a Cut or Paste fModified = true; break; case MSG_OUTPUT_TYPE: // User clicked Save As then choose an output format if (!fSavePanel) // If user doesn't already have a save panel open _SaveAs(message); break; case MSG_SAVE_PANEL: // User specified where to save the output image _SaveToFile(message); break; case B_CANCEL: delete fSavePanel; fSavePanel = NULL; break; case MSG_UPDATE_STATUS: { int32 pages = fNavigator.PageCount(); int32 currentPage = fNavigator.CurrentPage(); _EnableMenuItem(fBar, MSG_PAGE_FIRST, fNavigator.HasPreviousPage()); _EnableMenuItem(fBar, MSG_PAGE_LAST, fNavigator.HasNextPage()); _EnableMenuItem(fBar, MSG_PAGE_NEXT, fNavigator.HasNextPage()); _EnableMenuItem(fBar, MSG_PAGE_PREV, fNavigator.HasPreviousPage()); fGoToPageMenu->SetEnabled(pages > 1); _EnableMenuItem(fBar, MSG_FILE_NEXT, fNavigator.HasNextFile()); _EnableMenuItem(fBar, MSG_FILE_PREV, fNavigator.HasPreviousFile()); if (fGoToPageMenu->CountItems() != pages) { // Only rebuild the submenu if the number of // pages is different while (fGoToPageMenu->CountItems() > 0) { // Remove all page numbers delete fGoToPageMenu->RemoveItem((int32)0); } for (int32 i = 1; i <= pages; i++) { // Fill Go To page submenu with an entry for each page BMessage* goTo = new BMessage(MSG_GOTO_PAGE); goTo->AddInt32("page", i); char shortcut = 0; if (i < 10) shortcut = '0' + i; BString strCaption; strCaption << i; BMenuItem* item = new BMenuItem(strCaption.String(), goTo, shortcut, B_SHIFT_KEY); if (currentPage == i) item->SetMarked(true); fGoToPageMenu->AddItem(item); } } else { // Make sure the correct page is marked BMenuItem* currentItem = fGoToPageMenu->ItemAt(currentPage - 1); if (currentItem != NULL && !currentItem->IsMarked()) currentItem->SetMarked(true); } _UpdateStatusText(message); BPath path(fImageView->Image()); SetTitle(path.Path()); break; } case MSG_UPDATE_STATUS_TEXT: { _UpdateStatusText(message); break; } case MSG_SELECTION: { // The view sends this message when a selection is // made or the selection is cleared so that the window // can update the state of the appropriate menu items bool enable; if (message->FindBool("has_selection", &enable) == B_OK) { _EnableMenuItem(fBar, B_COPY, enable); _EnableMenuItem(fBar, MSG_CLEAR_SELECT, enable); } break; } case B_COPY: fImageView->CopySelectionToClipboard(); break; case MSG_SELECTION_MODE: { bool selectionMode = _ToggleMenuItem(MSG_SELECTION_MODE); fImageView->SetSelectionMode(selectionMode); if (!selectionMode) fImageView->ClearSelection(); break; } case MSG_CLEAR_SELECT: fImageView->ClearSelection(); break; case MSG_SELECT_ALL: fImageView->SelectAll(); break; case MSG_PAGE_FIRST: if (_ClosePrompt() && fNavigator.FirstPage()) _LoadImage(); break; case MSG_PAGE_LAST: if (_ClosePrompt() && fNavigator.LastPage()) _LoadImage(); break; case MSG_PAGE_NEXT: if (_ClosePrompt() && fNavigator.NextPage()) _LoadImage(); break; case MSG_PAGE_PREV: if (_ClosePrompt() && fNavigator.PreviousPage()) _LoadImage(); break; case MSG_GOTO_PAGE: { if (!_ClosePrompt()) break; int32 newPage; if (message->FindInt32("page", &newPage) != B_OK) break; int32 currentPage = fNavigator.CurrentPage(); int32 pages = fNavigator.PageCount(); // TODO: use radio mode instead! if (newPage > 0 && newPage <= pages) { BMenuItem* currentItem = fGoToPageMenu->ItemAt(currentPage - 1); BMenuItem* newItem = fGoToPageMenu->ItemAt(newPage - 1); if (currentItem != NULL && newItem != NULL) { currentItem->SetMarked(false); newItem->SetMarked(true); if (fNavigator.GoToPage(newPage)) _LoadImage(); } } break; } case kMsgFitToWindow: fImageView->FitToBounds(); break; case kMsgStretchToWindow: fImageView->SetStretchToBounds( _ToggleMenuItem(kMsgStretchToWindow)); break; case MSG_FILE_PREV: if (_ClosePrompt() && fNavigator.PreviousFile()) _LoadImage(false); break; case MSG_FILE_NEXT: case kMsgNextSlide: if (_ClosePrompt() && fNavigator.NextFile()) _LoadImage(); break; case kMsgDeleteCurrentFile: { if (fNavigator.MoveFileToTrash()) _LoadImage(); else PostMessage(B_QUIT_REQUESTED); break; } case MSG_ROTATE_90: fImageView->Rotate(90); break; case MSG_ROTATE_270: fImageView->Rotate(270); break; case MSG_FLIP_LEFT_TO_RIGHT: fImageView->Flip(true); break; case MSG_FLIP_TOP_TO_BOTTOM: fImageView->Flip(false); break; case MSG_SLIDE_SHOW: { bool fullScreen = false; message->FindBool("full screen", &fullScreen); BMenuItem* item = fBar->FindItem(message->what); if (item == NULL) break; if (item->IsMarked()) { item->SetMarked(false); _StopSlideShow(); fToolBar->SetActionPressed(MSG_SLIDE_SHOW, false); } else if (_ClosePrompt()) { item->SetMarked(true); if (!fFullScreen && fullScreen) _ToggleFullScreen(); _StartSlideShow(); fToolBar->SetActionPressed(MSG_SLIDE_SHOW, true); } break; } case kMsgStopSlideShow: { BMenuItem* item = fBar->FindItem(MSG_SLIDE_SHOW); if (item != NULL) item->SetMarked(false); _StopSlideShow(); fToolBar->SetActionPressed(MSG_SLIDE_SHOW, false); break; } case MSG_SLIDE_SHOW_DELAY: { bigtime_t delay; if (message->FindInt64("delay", &delay) == B_OK) { _SetSlideShowDelay(delay); // in case message is sent from popup menu _MarkSlideShowDelay(delay); } break; } case MSG_FULL_SCREEN: _ToggleFullScreen(); break; case MSG_EXIT_FULL_SCREEN: if (fFullScreen) _ToggleFullScreen(); break; case MSG_SHOW_CAPTION: { fShowCaption = _ToggleMenuItem(message->what); ShowImageSettings* settings = my_app->Settings(); if (settings->Lock()) { settings->SetBool("ShowCaption", fShowCaption); settings->Unlock(); } if (fFullScreen) fImageView->SetShowCaption(fShowCaption); } break; case MSG_PAGE_SETUP: _PageSetup(); break; case MSG_PREPARE_PRINT: _PrepareForPrint(); break; case MSG_PRINT: _Print(message); break; case MSG_ZOOM_IN: fImageView->ZoomIn(); break; case MSG_ZOOM_OUT: fImageView->ZoomOut(); break; case MSG_UPDATE_STATUS_ZOOM: fStatusView->SetZoom(fImageView->Zoom()); break; case kMsgOriginalSize: if (message->FindInt32("behavior") == BButton::B_TOGGLE_BEHAVIOR) { bool force = (message->FindInt32("be:value") == B_CONTROL_ON); fImageView->ForceOriginalSize(force); if (!force) break; } fImageView->SetZoom(1.0); break; case MSG_SCALE_BILINEAR: fImageView->SetScaleBilinear(_ToggleMenuItem(message->what)); break; case MSG_DESKTOP_BACKGROUND: { BMessage backgroundsMessage(B_REFS_RECEIVED); backgroundsMessage.AddRef("refs", fImageView->Image()); // This is used in the Backgrounds code for scaled placement backgroundsMessage.AddInt32("placement", 'scpl'); be_roster->Launch("application/x-vnd.haiku-backgrounds", &backgroundsMessage); break; } case MSG_SET_RATING: { int32 rating; if (message->FindInt32("rating", &rating) != B_OK) break; BFile file(&fNavigator.CurrentRef(), B_WRITE_ONLY); if (file.InitCheck() != B_OK) break; file.WriteAttr("Media:Rating", B_INT32_TYPE, 0, &rating, sizeof(rating)); _UpdateRatingMenu(); break; } case kMsgToggleToolBar: { fShowToolBar = _ToggleMenuItem(message->what); _SetToolBarVisible(fShowToolBar, true); ShowImageSettings* settings = my_app->Settings(); if (settings->Lock()) { settings->SetBool("ShowToolBar", fShowToolBar); settings->Unlock(); } break; } case kShowToolBarIfEnabled: { bool show; if (message->FindBool("show", &show) != B_OK) break; _SetToolBarVisible(fShowToolBar && show, true); break; } case kMsgSlideToolBar: { float offset; if (message->FindFloat("offset", &offset) == B_OK) { fToolBar->MoveBy(0, offset); fScrollView->ResizeBy(0, -offset); fScrollView->MoveBy(0, offset); UpdateIfNeeded(); snooze(15000); } break; } case kMsgFinishSlidingToolBar: { float offset; bool show; if (message->FindFloat("offset", &offset) == B_OK && message->FindBool("show", &show) == B_OK) { // Compensate rounding errors with the final placement fToolBar->MoveTo(fToolBar->Frame().left, offset); if (!show) fToolBar->Hide(); BRect frame = fToolBar->Parent()->Bounds(); frame.top = fToolBar->Frame().bottom + 1; fScrollView->MoveTo(fScrollView->Frame().left, frame.top); fScrollView->ResizeTo(fScrollView->Bounds().Width(), frame.Height() + 1); } break; } default: BWindow::MessageReceived(message); break; } }
void ProjectWindow::MessageReceived(BMessage *msg) { status_t status; if ( (msg->WasDropped() && msg->what == B_SIMPLE_DATA) || msg->what == M_ADD_FILES) { fAddFileStruct.refmsg = *msg; fAddFileStruct.parent = this; uint32 buttons; fProjectList->GetMouse(&fAddFileStruct.droppt,&buttons); thread_id addThread = spawn_thread(AddFileThread,"file adding thread", B_NORMAL_PRIORITY, &fAddFileStruct); if (addThread >= 0) resume_thread(addThread); } switch (msg->what) { case M_IMPORT_REFS: { fImportStruct.refmsg = *msg; fImportStruct.parent = this; thread_id importThread = spawn_thread(ImportFileThread,"file import thread", B_NORMAL_PRIORITY, &fImportStruct); if (importThread >= 0) resume_thread(importThread); break; } case M_BACKUP_PROJECT: { thread_id backupThread = spawn_thread(BackupThread,"project backup thread", B_NORMAL_PRIORITY, this); if (backupThread >= 0) { fStatusBar->SetText(TR("Backing up project")); UpdateIfNeeded(); SetMenuLock(true); resume_thread(backupThread); } break; } case M_GET_CHECK_IN_MSG: { if (!fSourceControl) { printf("NULL source control\n"); break; } BString out; fSourceControl->GetCheckinHeader(out); bool select = false; if (out.CountChars() > 1) out.Prepend("\n\n"); else { out = TR("Enter the description for the changes in this revision."); select = true; } GetTextWindow *gtw = new GetTextWindow("Paladin", out.String(), BMessage(M_CHECK_IN_PROJECT), BMessenger(this)); if (!select) gtw->GetTextView()->Select(0,0); gtw->Show(); break; } case M_CHECK_IN_PROJECT: { BString commitstr; if (msg->FindString("text", &commitstr) == B_OK && fSourceControl) { SCMOutputWindow *win = new SCMOutputWindow(TR("Commit")); win->Show(); fSourceControl->Commit(commitstr.String()); } break; } case M_REVERT_PROJECT: { if (!fSourceControl) break; int32 result = ShowAlert(TR("This will undo all changes since the last commit. " "Continue?"), "Don't Revert", "Revert"); if (result == 1) { SCMOutputWindow *win = new SCMOutputWindow(TR("Revert")); win->Show(); fSourceControl->Revert(NULL); } break; } case M_REBUILD_FILE: case M_ADD_SELECTION_TO_REPO: case M_REMOVE_SELECTION_FROM_REPO: case M_REVERT_SELECTION: case M_DIFF_SELECTION: { ActOnSelectedFiles(msg->what); break; } case M_DIFF_PROJECT: { if (fSourceControl) { SCMOutputWindow *win = new SCMOutputWindow(TR("Differences")); win->Show(); fSourceControl->Diff(NULL); } break; } case M_PROJECT_SCM_STATUS: { if (fSourceControl) { SCMOutputWindow *win = new SCMOutputWindow(TR("Project Status")); BString strstatus; fSourceControl->GetChangeStatus(strstatus); win->GetTextView()->SetText(strstatus.String()); win->Show(); } break; } case M_PUSH_PROJECT: { if (fSourceControl) { SCMOutputWindow *win = new SCMOutputWindow(TR("Push")); win->Show(); fSourceControl->Push(NULL); } break; } case M_PULL_PROJECT: { if (fSourceControl) { SCMOutputWindow *win = new SCMOutputWindow(TR("Pull")); win->Show(); status = fSourceControl->Pull(NULL); if (!status) ShowAlert("Unable to pull from the remote repository. If it " "uses a secure connection, please set up the appropriate " "SSH keys on the remote server.", "OK"); } break; } case M_CULL_EMPTY_GROUPS: { CullEmptyGroups(); break; } case M_RUN_FILE_TYPES: { int32 selection = fProjectList->FullListCurrentSelection(); if (selection < 0) break; SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->FullListItemAt(selection)); if (!item) break; SpawnFileTypes(item->GetData()->GetPath()); break; } case M_OPEN_PARENT_FOLDER: { BMessage openmsg(B_REFS_RECEIVED); int32 selindex = 0; int32 selection = fProjectList->FullListCurrentSelection(); selindex++; if (selection >= 0) { while (selection >= 0) { SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->FullListItemAt(selection)); if (!item) break; SourceFile *file = item->GetData(); BString abspath = file->GetPath().GetFullPath(); if (abspath[0] != '/') { abspath.Prepend("/"); abspath.Prepend(fProject->GetPath().GetFolder()); } DPath filepath(abspath); entry_ref ref; BEntry(filepath.GetFolder()).GetRef(&ref); openmsg.AddRef("refs",&ref); selection = fProjectList->FullListCurrentSelection(selindex++); } BMessenger msgr("application/x-vnd.Be-TRAK"); msgr.SendMessage(&openmsg); } break; } case M_SHOW_PROJECT_FOLDER: { entry_ref ref; BEntry(fProject->GetPath().GetFolder()).GetRef(&ref); BMessenger msgr("application/x-vnd.Be-TRAK"); BMessage openmsg(B_REFS_RECEIVED); openmsg.AddRef("refs",&ref); msgr.SendMessage(&openmsg); break; } case M_SHOW_ASCII_TABLE: { AsciiWindow *ascwin = new AsciiWindow(); ascwin->Show(); break; } case M_SHOW_VREGEX: { VRegWindow *vregwin = new VRegWindow(); vregwin->Show(); break; } case M_SHOW_LICENSES: { LicenseManager *man = new LicenseManager(fProject->GetPath().GetFolder()); man->Show(); break; } case M_RUN_TOOL: { BString sig; if (msg->FindString("signature", &sig) == B_OK) { LaunchHelper launcher(sig.String()); launcher.Launch(); } break; } case M_MAKE_MAKE: { DPath out(fProject->GetPath().GetFolder()); out.Append("Makefile"); if (MakeMake(fProject,out) == B_OK); { BEntry entry(out.GetFullPath()); entry_ref ref; if (entry.InitCheck() == B_OK) { entry.GetRef(&ref); BMessage refmsg(B_REFS_RECEIVED); refmsg.AddRef("refs",&ref); be_app->PostMessage(&refmsg); } } break; } case M_SHOW_CODE_LIBRARY: { #ifdef BUILD_CODE_LIBRARY CodeLibWindow *libwin = CodeLibWindow::GetInstance(BRect(100,100,500,350)); libwin->Show(); #endif break; } case M_OPEN_PARTNER: { int32 selection = fProjectList->FullListCurrentSelection(); if (selection < 0) break; SourceFileItem *item = dynamic_cast<SourceFileItem*>( fProjectList->FullListItemAt(selection)); if (!item) break; entry_ref ref; BEntry(fProject->GetPathForFile(item->GetData()).GetFullPath()).GetRef(&ref); BMessage refmsg(M_OPEN_PARTNER); refmsg.AddRef("refs",&ref); be_app->PostMessage(&refmsg); break; } case M_NEW_GROUP: { MakeGroup(fProjectList->FullListCurrentSelection()); PostMessage(M_SHOW_RENAME_GROUP); break; } case M_SHOW_RENAME_GROUP: { int32 selection = fProjectList->FullListCurrentSelection(); SourceGroupItem *groupItem = NULL; if (selection < 0) { // Don't need a selection if there is only one group in the project if (fProject->CountGroups() == 1) groupItem = fProjectList->ItemForGroup(fProject->GroupAt(0)); } else { BStringItem *strItem = (BStringItem*)fProjectList->FullListItemAt(selection); groupItem = fProjectList->GroupForItem(strItem); } if (!groupItem) break; GroupRenameWindow *grwin = new GroupRenameWindow(groupItem->GetData(), BMessage(M_RENAME_GROUP), BMessenger(this)); grwin->Show(); break; } case M_RENAME_GROUP: { SourceGroup *group; BString newname; if (msg->FindPointer("group",(void**)&group) != B_OK || msg->FindString("newname",&newname) != B_OK) break; group->name = newname; SourceGroupItem *groupItem = fProjectList->ItemForGroup(group); if (!groupItem) break; groupItem->SetText(newname.String()); fProjectList->InvalidateItem(fProjectList->IndexOf(groupItem)); fProject->Save(); break; } case M_SORT_GROUP: { int32 selection = fProjectList->FullListCurrentSelection(); SourceGroupItem *groupItem = NULL; if (selection < 0) { // Don't need a selection if there is only one group in the project if (fProject->CountGroups() == 1) groupItem = fProjectList->ItemForGroup(fProject->GroupAt(0)); } else { BStringItem *strItem = (BStringItem*)fProjectList->FullListItemAt(selection); groupItem = fProjectList->GroupForItem(strItem); } if (!groupItem) break; fProjectList->SortItemsUnder(groupItem,true,compare_source_file_items); groupItem->GetData()->Sort(); fProject->Save(); break; } case M_TOGGLE_ERROR_WINDOW: { ToggleErrorWindow(fProject->GetErrorList()); break; } case M_SHOW_ERROR_WINDOW: { ShowErrorWindow(fProject->GetErrorList()); break; } case M_SHOW_PROJECT_SETTINGS: { BRect r(0,0,350,300); BRect screen(BScreen().Frame()); r.OffsetTo((screen.Width() - r.Width()) / 2.0, (screen.Height() - r.Height()) / 2.0); ProjectSettingsWindow *win = new ProjectSettingsWindow(r,fProject); win->Show(); break; } case M_SHOW_RUN_ARGS: { RunArgsWindow *argwin = new RunArgsWindow(fProject); argwin->Show(); break; } case M_JUMP_TO_MSG: { entry_ref ref; if (msg->FindRef("refs",&ref) == B_OK) { msg->what = B_REFS_RECEIVED; be_app->PostMessage(msg); } break; } case B_ABOUT_REQUESTED: { be_app->PostMessage(B_ABOUT_REQUESTED); break; } case M_SHOW_OPEN_PROJECT: { be_app->PostMessage(msg); break; } case M_NEW_WINDOW: { be_app->PostMessage(M_NEW_PROJECT); break; } case M_SHOW_PROGRAM_SETTINGS: { PrefsWindow *prefwin = new PrefsWindow(BRect(0,0,500,400)); prefwin->Show(); break; } case M_SHOW_FIND_AND_OPEN_PANEL: { BString text; msg->FindString("name",&text); // Passing a NULL string to this is OK FindOpenFileWindow *findwin = new FindOpenFileWindow(text.String()); findwin->Show(); break; } case M_FILE_NEEDS_BUILD: { SourceFile *file; if (msg->FindPointer("file",(void**)&file) == B_OK) { SourceFileItem *item = fProjectList->ItemForFile(file); if (item) { item->SetDisplayState(SFITEM_NEEDS_BUILD); fProjectList->InvalidateItem(fProjectList->IndexOf(item)); } } break; } case M_EDIT_FILE: { int32 i = 0; int32 selection = fProjectList->FullListCurrentSelection(i); i++; BMessage refmsg(B_REFS_RECEIVED); while (selection >= 0) { SourceFileItem *item = dynamic_cast<SourceFileItem*> (fProjectList->FullListItemAt(selection)); if (item && item->GetData()) { BString abspath = item->GetData()->GetPath().GetFullPath(); if (abspath[0] != '/') { abspath.Prepend("/"); abspath.Prepend(fProject->GetPath().GetFolder()); } BEntry entry(abspath.String()); if (entry.InitCheck() == B_OK) { entry_ref ref; entry.GetRef(&ref); refmsg.AddRef("refs",&ref); } else { if (!entry.Exists()) { BString errmsg = TR("Couldn't find XXXXX. It may have been moved or renamed."); errmsg.ReplaceFirst("XXXXX",abspath.String()); ShowAlert(errmsg.String()); } } } else { SourceGroupItem *groupItem = dynamic_cast<SourceGroupItem*> (fProjectList->FullListItemAt(selection)); if (groupItem) { if (groupItem->IsExpanded()) fProjectList->Collapse(groupItem); else fProjectList->Expand(groupItem); groupItem->GetData()->expanded = groupItem->IsExpanded(); } } selection = fProjectList->CurrentSelection(i); i++; } be_app->PostMessage(&refmsg); break; } case M_LIBWIN_CLOSED: { fShowingLibs = false; break; } case M_SHOW_LIBRARIES: { fShowingLibs = true; LibraryWindow *libwin = new LibraryWindow(Frame().OffsetByCopy(15,15), BMessenger(this), fProject); libwin->Show(); break; } case M_SHOW_ADD_NEW_PANEL: { AddNewFileWindow *anfwin = new AddNewFileWindow(BMessage(M_ADD_NEW_FILE), BMessenger(this)); anfwin->Show(); break; } case M_SHOW_FIND_IN_PROJECT_FILES: { if (!gLuaAvailable) { ShowAlert("Paladin's multi-file Find window depends on Lua. It will " "need to be installed if you wish to use this feature.", "OK", NULL, NULL, B_STOP_ALERT); break; } FindWindow *findwin = new FindWindow(); findwin->Show(); break; } case M_ADD_NEW_FILE: { BString name; bool makepair; if (msg->FindString("name",&name) == B_OK && msg->FindBool("makepair",&makepair) == B_OK) AddNewFile(name,makepair); break; } case M_SHOW_ADD_PANEL: { if (!fFilePanel) { BMessenger msgr(this); BEntry entry(fProject->GetPath().GetFolder()); entry_ref ref; entry.GetRef(&ref); fFilePanel = new BFilePanel(B_OPEN_PANEL,&msgr,&ref,B_FILE_NODE,true, new BMessage(M_ADD_FILES)); } fFilePanel->Show(); break; } case M_REMOVE_FILES: { bool save = false; for (int32 i = 0; i < fProjectList->CountItems(); i++) { SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->ItemAt(i)); if (item && item->IsSelected()) { fProjectList->RemoveItem(item); fProject->RemoveFile(item->GetData()); delete item; save = true; i--; } } CullEmptyGroups(); if (save) fProject->Save(); break; } case M_EMPTY_CCACHE: { // We don't do this when forcing a rebuild of the sources because sometimes it // can take quite a while if (gUseCCache && gCCacheAvailable) { fStatusBar->SetText(TR("Emptying build cache")); UpdateIfNeeded(); system("ccache -c > /dev/null"); fStatusBar->SetText(""); UpdateIfNeeded(); } break; } case M_FORCE_REBUILD: { fProject->ForceRebuild(); for (int32 i = 0; i < fProjectList->FullListCountItems(); i++) { SourceFileItem *item = dynamic_cast<SourceFileItem*>(fProjectList->FullListItemAt(i)); if (!item) continue; SourceFile *file = item->GetData(); if (file->UsesBuild()) { item->SetDisplayState(SFITEM_NEEDS_BUILD); fProjectList->InvalidateItem(i); } } // This is necessary because InvalidateItem() uses indices from ItemAt(), // not FullListItemAt fProjectList->Invalidate(); break; } case M_UPDATE_DEPENDENCIES: { UpdateDependencies(); break; } case M_MAKE_PROJECT: case M_BUILD_PROJECT: { fBuildingFile = 0; DoBuild(POSTBUILD_NOTHING); break; } case M_RUN_PROJECT: { DoBuild(POSTBUILD_RUN); break; } case M_RUN_IN_TERMINAL: { DoBuild(POSTBUILD_RUN_IN_TERMINAL); break; } case M_DEBUG_PROJECT: { if (!fProject->Debug()) { BString errmsg = TR("Your project does not have debugging information compiled "); errmsg << TR("in and will need to be rebuilt to debug. Do you wish to rebuild and ") << TR("run the debugger?"); int32 result = ShowAlert("Debugging information needs to compiled into " "your project. This may take some time for large " "projects. Do you wish to rebuild and run " "the debugger?", "Rebuild","Cancel"); if (result == 1) break; fProject->SetDebug(true); fProject->Save(); fProject->ForceRebuild(); } DoBuild(POSTBUILD_DEBUG); break; } case M_EXAMINING_FILE: { SourceFile *file; if (msg->FindPointer("file",(void**)&file) == B_OK) { BString out; out << TR("Examining ") << file->GetPath().GetFileName(); fStatusBar->SetText(out.String()); } break; } case M_BUILDING_FILE: { SourceFile *file; if (msg->FindPointer("sourcefile",(void**)&file) == B_OK) { SourceFileItem *item = fProjectList->ItemForFile(file); if (item) { item->SetDisplayState(SFITEM_BUILDING); fProjectList->InvalidateItem(fProjectList->IndexOf(item)); BString out; int32 count,total; if (msg->FindInt32("count",&count) == B_OK && msg->FindInt32("total",&total) == B_OK) { fBuildingFile = MAX(fBuildingFile, count); out << "(" << fBuildingFile << "/" << total << ") "; } out << TR("Building ") << item->Text(); fStatusBar->SetText(out.String()); } } break; } case M_BUILDING_DONE: { SourceFile *file; if (msg->FindPointer("sourcefile",(void**)&file) == B_OK) { SourceFileItem *item = fProjectList->ItemForFile(file); if (item) { item->SetDisplayState(SFITEM_NORMAL); fProjectList->InvalidateItem(fProjectList->IndexOf(item)); } } break; } case M_LINKING_PROJECT: { fStatusBar->SetText(TR("Linking")); break; } case M_UPDATING_RESOURCES: { fStatusBar->SetText(TR("Updating Resources")); break; } case M_DOING_POSTBUILD: { fStatusBar->SetText(TR("Performing Post-build tasks")); break; } case M_BUILD_FAILURE: { SetMenuLock(false); // fall through } case M_BUILD_MESSAGES: case M_BUILD_WARNINGS: { if (!fErrorWindow) { BRect screen(BScreen().Frame()); BRect r(screen); r.left = r.right / 4.0; r.right *= .75; r.top = r.bottom - 200; BDeskbar deskbar; if (deskbar.Location() == B_DESKBAR_BOTTOM) r.OffsetBy(0,-deskbar.Frame().Height()); fErrorWindow = new ErrorWindow(r,this); fErrorWindow->Show(); } else { if (!fErrorWindow->IsFront()) fErrorWindow->Activate(); } fStatusBar->SetText(""); // Should this be an Unflatten or an Append? ErrorList *errorList = fProject->GetErrorList(); errorList->Unflatten(*msg); fErrorWindow->PostMessage(msg); break; } case M_BUILD_SUCCESS: { SetMenuLock(false); fStatusBar->SetText(""); break; } case M_ERRORWIN_CLOSED: { fErrorWindow = NULL; break; } case M_SYNC_MODULES: { #ifdef BUILD_CODE_LIBRARY thread_id syncID = spawn_thread(SyncThread,"module update thread", B_NORMAL_PRIORITY, this); if (syncID >= 0) resume_thread(syncID); #endif break; } case M_TOGGLE_DEBUG_MENU: { ToggleDebugMenu(); break; } case M_DEBUG_DUMP_DEPENDENCIES: { DumpDependencies(fProject); break; } case M_DEBUG_DUMP_INCLUDES: { DumpIncludes(fProject); break; } default: { DWindow::MessageReceived(msg); break; } } }
void ProjectWindow::AddFolder(entry_ref folderref) { BDirectory dir; if (dir.SetTo(&folderref) != B_OK) return; if (strcmp(folderref.name,"CVS") == 0 || strcmp(folderref.name,".svn") == 0 || strcmp(folderref.name,".git") == 0 || strcmp(folderref.name,".hg") == 0) return; dir.Rewind(); entry_ref ref; while (dir.GetNextRef(&ref) == B_OK) { if (BEntry(&ref).IsDirectory()) AddFolder(ref); else { // Here is where we actually add the file to the project. The name of the folder // containing the file will be the name of the file's group. If the group doesn't // exist, it will be created at the end of the list, but if it does, we will fake // a drop onto the group item to reuse the code path by finding the group and getting // its position in the list. DPath filepath(ref); if (filepath.GetExtension() && !( strcmp(filepath.GetExtension(),"cpp") == 0 || strcmp(filepath.GetExtension(),"c") == 0 || strcmp(filepath.GetExtension(),"cc") == 0 || strcmp(filepath.GetExtension(),"cxx") == 0 || strcmp(filepath.GetExtension(),"rdef") == 0 || strcmp(filepath.GetExtension(),"rsrc") == 0) ) continue; // Don't bother adding build files from other systems if (strcmp(filepath.GetFileName(), "Jamfile") == 0 || strcmp(filepath.GetFileName(), "Makefile") == 0) continue; DPath parent(filepath.GetFolder()); SourceGroup *group = NULL; SourceGroupItem *groupItem = NULL; fProject->Lock(); group = fProject->FindGroup(parent.GetFileName()); Lock(); if (group) groupItem = fProjectList->ItemForGroup(group); else { group = fProject->AddGroup(parent.GetFileName()); groupItem = new SourceGroupItem(group); fProjectList->AddItem(groupItem); UpdateIfNeeded(); } if (groupItem) { int32 index = fProjectList->IndexOf(groupItem); BPoint pt = fProjectList->ItemFrame(index).LeftTop(); pt.x += 5; pt.y += 5; AddFile(ref,&pt); } Unlock(); fProject->Unlock(); } } }