PDoc* PApp::OpenWorksheet() { try { if (!gPrefsDir.Contains("Worksheet", B_FILE_NODE | B_SYMLINK_NODE)) { BFile file; gPrefsDir.CreateFile("Worksheet", &file); } BEntry w; entry_ref wr; FailOSErr(gPrefsDir.FindEntry("Worksheet", &w, true)); FailOSErr(w.GetRef(&wr)); OpenWindow(wr); PDoc *d = dynamic_cast<PDoc*>(CDoc::FindDoc(wr)); if (d) d->MakeWorksheet(); return d; } catch (HErr& e) { e.DoError(); } return NULL; } /* PApp::OpenWorksheet */
void PApp::ReadyToRun() { PDoc *doc = PDoc::TopWindow(); if (!doc || doc->IsWorksheet()) { // what to do when pe is launched switch (gPrefs->GetPrefInt(prf_I_Startup)) { case 1: // Create New Document if (CDoc::CountDocs() == 0 || (doc && doc->IsWorksheet() && CDoc::CountDocs() == 1)) NewWindow(); break; case 2: // Show Open Dialog PostMessage(msg_Open); break; default: // Do Nothing (only effective in combination with a worksheet) if (CDoc::CountDocs() == 0) NewWindow(); break; } } // BPath p; // if (find_directory(B_USER_DIRECTORY, &p) == B_OK) // gCWD.SetTo(p.Path()); } /* PApp::ReadyToRun */
status_t perform_edit(MTextAddOn *addon) { status_t result = B_OK; entry_ref headerFile; BPoint where(0,0); if (addon->Window() && addon->Window()->Lock()) { uint32 buttons; addon->Window()->ChildAt(0)->GetMouse(&where, &buttons); addon->Window()->ChildAt(0)->ConvertToScreen(&where); addon->Window()->Unlock(); where += BPoint(-3,-3); } result = addon->GetRef(headerFile); BString fileName; if (result >= B_OK) fileName = headerFile.name; CLanguageInterface *languageInterface = NULL; if (addon->Window()) { PDoc *doc = dynamic_cast<PDoc *>(addon->Window()); if (doc && doc->TextView()) { int lang = doc->TextView()->Language(); if (lang > -1) languageInterface = CLanguageInterface::FindIntf(lang); } } BString header; result = RunPopUpMenu(where, header, fileName, languageInterface); //printf("result %s\n", strerror(result)); if (result == B_CANCELED) return B_OK; if (result < B_OK) return result; #if 0 // Do not change the case if a shift key was pressed if ((modifiers() & B_SHIFT_KEY) == 0) fileName.ToUpper(); #endif addon->Select(0, 0); addon->Insert(header.String()); return result; }
BHandler *PApp::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier, int32 form, const char *property) { BHandler *result = NULL; try { PDoc *doc = NULL; if (strcmp(property, "Window") == 0 && form == B_NAME_SPECIFIER) { msg->PopSpecifier(); entry_ref file; const char *fileName; FailOSErr(specifier->FindString("name", &fileName)); if (get_ref_for_path(fileName, &file) == B_OK) { doc = dynamic_cast<PDoc*>(CDoc::FindDoc(file)); if (doc == NULL) doc = dynamic_cast<PDoc*>(OpenWindow(file, true)); } } if (doc) doc->PostMessage(msg); else result = BApplication::ResolveSpecifier(msg, index, specifier, form, property); } catch (HErr& e) { BMessage reply; reply.AddString("Error", e); msg->SendReply(&reply); } return result; } /* PApp::ResolveSpecifier */
void PApp::MessageReceived(BMessage *msg) { try { switch (msg->what) { case msg_SaveAll: { const doclist& lst = CDoc::DocList(); doclist::const_iterator di; for (di = lst.begin(); di != lst.end(); di++) { BWindow *w = dynamic_cast<PDoc*>(*di); if (w) w->PostMessage(msg_Save); } break; } case msg_CloseAll: { const doclist& lst = CDoc::DocList(); doclist::const_reverse_iterator di; for (di = lst.rbegin(); di != lst.rend(); di++) { PDoc *doc = dynamic_cast<PDoc*>(*di); if (doc && ! doc->IsWorksheet() && doc->Lock()) { if (doc->QuitRequested()) doc->Quit(); else { doc->Unlock(); break; } } } break; } case B_NODE_MONITOR: { CDoc::HandleFolderNodeMonitorMsg(msg); break; } case msg_OpenSelected: DialogCreator<COpenSelection>::CreateDialog(NULL); break; case msg_OpenInclude: { const char *i; FailOSErr(msg->FindString("include", &i)); const char *src = NULL; msg->FindString("from-source", &src); FindAndOpen(i, src); break; } case msg_FindCmd: { int c = 1 << current_workspace(); if (gPrefs->GetPrefInt(prf_I_SmartWorkspaces, 1)) FindDialog()->SetWorkspaces(c); FindDialog()->SetCaller(PDoc::TopWindow()); FindDialog()->Show(); FindDialog()->Activate(true); break; } case B_REFS_RECEIVED: case 'OpFi': RefsReceived(msg); break; case msg_About: { AboutWindow *abwin = new AboutWindow(); abwin->Show(); break; } case msg_IdeBringToFront: PDoc::IDEBringToFront(); break; case msg_IdeProjectToGroup: PDoc::IDEProject2Group(); break; case msg_FindDifferences: { BRect r(100,100,500,250); new CDiffWindow(r, "Differences"); break; } case msg_Open: { if (fOpenPanel->IsShowing()) { fOpenPanel->Window()->SetWorkspaces(1 << current_workspace()); fOpenPanel->Window()->Activate(); } else { BEntry entry; gCWD.GetEntry(&entry); BAutolock lock(fOpenPanel->Window()); entry_ref ref; entry.GetRef(&ref); fOpenPanel->SetPanelDirectory(&ref); fOpenPanel->Window()->SetWorkspaces(1 << current_workspace()); if (gPrefs->GetPrefInt(prf_I_ZoomOpenPanel, 0)) { BRect r = BScreen().Frame(); fOpenPanel->Window()->MoveTo(r.left + 80, r.top + 40); fOpenPanel->Window()->ResizeTo(480, r.Height() - 50); } fOpenPanel->Show(); } break; } case msg_CommandLineOpen: { entry_ref doc; FailOSErr (msg->FindRef("refs", &doc)); CDocWindow *w; BEntry e; if (e.SetTo(&doc) == B_OK && e.Exists()) w = dynamic_cast<CDocWindow*>(OpenWindow(doc)); else { w = NewWindow(NULL); w->SetEntryRef(&doc); } long lineNr; if (w && msg->FindInt32("line", &lineNr) == B_OK) { BMessage m(msg_SelectLines); FailOSErr(m.AddInt32("from", lineNr)); FailOSErr(m.AddInt32("to", lineNr - 1)); w->PostMessage(&m, w->PreferredHandler()); } if (w) { BMessage reply; reply.AddInt32("thread", w->Thread()); msg->SendReply(&reply); } break; } case B_SILENT_RELAUNCH: case msg_New: if (be_roster->IsRunning("application/x-vnd.dw-Paladin")) { BMessage newMsg(PALADIN_SHOW_ADD_NEW_PANEL); BMessenger msgr("application/x-vnd.dw-Paladin"); msgr.SendMessage(&newMsg); } else NewWindow(); break; case msg_Select: { PDoc *doc; if ((doc = PDoc::TopWindow()) != NULL) { BMessage copy(*msg); doc->PostMessage(©); } break; } case msg_DocClosed: if (CDoc::CountDocs() == 0) Quit(); break; case msg_Tile: PDoc::Tile(); break; case msg_Stack: PDoc::Stack(); break; case msg_Zoom: if (PDoc::TopWindow()) PDoc::TopWindow()->Zoom(); break; case msg_Worksheet: OpenWorksheet(); break; case msg_NewGroup: new PGroupWindow; break; case 1: puts(rcsid); break; case msg_Quit: PostMessage(B_QUIT_REQUESTED); break; case msg_Preferences: { long l; if (fPrefOpener) wait_for_thread(fPrefOpener, &l); fPrefOpener = (thread_id)NULL; if (fPrefsDialog) { BAutolock lock(fPrefsDialog); if (!lock.IsLocked()) { THROW(("Preferences panel failed to lock")); break; } int c = 1 << current_workspace(); if (gPrefs->GetPrefInt(prf_I_SmartWorkspaces, 1)) fPrefsDialog->SetWorkspaces(c); if (fPrefsDialog->IsHidden()) { fPrefsDialog->Show(); } fPrefsDialog->Activate(true); } else THROW(("Preferences panel failed to open")); break; } default: BApplication::MessageReceived(msg); } } catch (HErr& e) { e.DoError(); } } /* PApp::MessageReceived */
void PApp::RefsReceived(BMessage *inMessage) { try { unsigned long type; long count; inMessage->GetInfo("refs", &type, &count); for (int i = 0; i < count; i++) { entry_ref doc; FailOSErr (inMessage->FindRef("refs", i, &doc)); PDoc *d = dynamic_cast<PDoc*>(OpenWindow(doc)); if (!d) continue; if (inMessage->HasData(kTokenIdentifier, kTokenIDType)) { TokenIdentifier *ident; ssize_t size; FailOSErr(inMessage->FindData(kTokenIdentifier, kTokenIDType, (const void**)&ident, &size)); BMessage msg(msg_SelectError); FailOSErr(msg.AddInt32("start", ident->eOffset)); FailOSErr(msg.AddInt32("length", ident->eLength)); BMessenger msgr(d->TextView()); FailOSErr(msgr.SendMessage(&msg)); } else if (inMessage->HasInt32("be:selection_offset")) { int32 offset, length; FailOSErr(inMessage->FindInt32("be:selection_offset", &offset)); FailOSErr(inMessage->FindInt32("be:selection_length", &length)); BMessage msg(msg_Select); FailOSErr(msg.AddInt32("anchor", offset)); FailOSErr(msg.AddInt32("caret", offset + length)); BMessenger msgr(d->TextView()); FailOSErr(msgr.SendMessage(&msg)); } else if (inMessage->HasInt32("be:line")) { int32 line; FailOSErr(inMessage->FindInt32("be:line", &line)); BMessage msg(msg_SelectLines); FailOSErr(msg.AddInt32("from", line)); FailOSErr(msg.AddInt32("to", line - 1)); BMessenger msgr(d->TextView()); FailOSErr(msgr.SendMessage(&msg)); } } } catch (HErr& e) { e.DoError(); } } /* PApp::RefsReceived */
void PApp::ArgvReceived(int32 argc, char **argv) { try { int i = 1, lineNr = -1; char *p; while (i < argc) { switch (argv[i][0]) { case '-': if (strcmp(argv[i], "-reload_worksheet") == 0) { PDoc *d = OpenWorksheet(); if (d && d->Lock()) d->Quit(); d = OpenWorksheet(); } else { Usage(); } break; case '+': lineNr = strtoul(argv[i] + 1, &p, 10) - 1; if (!p || p == argv[i] + 1) Usage(); break; default: { BPath path; if (argv[i][0] == '/') path.SetTo(argv[i]); else path.SetTo("/boot/home"); FailOSErr (path.InitCheck()); entry_ref doc; CDocWindow *d; FailOSErr (get_ref_for_path(path.Path(), &doc)); BEntry e; FailOSErr(e.SetTo(&doc)); if (e.Exists()) d = dynamic_cast<CDocWindow*>(OpenWindow(doc)); else { d = NewWindow(NULL); d->SetEntryRef(&doc); } if (d && lineNr >= 0) { BMessage m(msg_SelectLines); m.AddInt32("from", lineNr); m.AddInt32("to", lineNr - 1); d->PostMessage(&m, d->PreferredHandler()); } break; } } i++; } } catch (HErr& e) { e.DoError(); } } /* PApp::ArgvReceived */
CDoc* PApp::OpenWindow(const entry_ref& doc, bool show) { try { BNode n(&doc); char mime[256]; BNodeInfo ni(&n); if (ni.GetType(mime) != B_OK) mime[0] = 0; if (gPrefs->GetPrefInt(prf_I_AutodetectProjects, 1)) { if (!strcmp(doc.name, "Jamfile")) ni.SetType("text/x-jamfile"); else if (!strcasecmp(doc.name, "Makefile")) ni.SetType("text/x-makefile"); ni.GetType(mime); } if (strcmp(mime, "text/x-vnd.Hekkel-Pe-Group") == 0 || strcmp(mime, "text/x-pe-group") == 0) { PGroupWindow *w = dynamic_cast<PGroupWindow*>(CDoc::FindDoc(doc)); if (w) { if (gPrefs->GetPrefInt(prf_I_SmartWorkspaces, 1)) w->SetWorkspaces(1 << current_workspace()); if (show) w->Activate(true); return CDoc::FindDoc(doc); } else return new PGroupWindow(&doc); } else if (ProjectRoster->IsProjectType(mime)) { BWindow *w = dynamic_cast<BWindow*>(CDoc::FindDoc(doc)); if (w) { if (gPrefs->GetPrefInt(prf_I_SmartWorkspaces, 1)) w->SetWorkspaces(1 << current_workspace()); if (show) w->Activate(true); return CDoc::FindDoc(doc); } else { PProjectWindow* prjWin = PProjectWindow::Create(&doc, mime); if (prjWin && prjWin->InitCheck() == B_OK) { prjWin->Show(); return prjWin; } else { delete prjWin; return gApp->NewWindow(&doc); } } } else { PDoc *d = dynamic_cast<PDoc*>(CDoc::FindDoc(doc)); if (d) { if (gPrefs->GetPrefInt(prf_I_SmartWorkspaces, 1)) d->SetWorkspaces(1 << current_workspace()); if (show) d->Activate(true); return CDoc::FindDoc(doc); } else return NewWindow(&doc, show); } } catch (HErr& e) { e.DoError(); } return NULL; } /* PApp::OpenWindow */