bool RealNameAttributeText::CommitEditedTextFlavor(BTextView* textView) { const char* text = textView->Text(); BEntry entry(fModel->EntryRef()); if (entry.InitCheck() != B_OK) return false; BDirectory parent; if (entry.GetParent(&parent) != B_OK) return false; bool removeExisting = false; if (parent.Contains(text)) { BAlert* alert = new BAlert("", B_TRANSLATE("That name is already taken. " "Please type another one."), B_TRANSLATE("Replace other file"), B_TRANSLATE("OK"), NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); alert->SetShortcut(0, 'r'); if (alert->Go()) return false; removeExisting = true; } // TODO: // use model-flavor specific virtuals for all of these special // renamings status_t result; if (fModel->IsVolume()) { BVolume volume(fModel->NodeRef()->device); result = volume.InitCheck(); if (result == B_OK) { RenameVolumeUndo undo(volume, text); result = volume.SetName(text); if (result != B_OK) undo.Remove(); } } else { if (fModel->IsQuery()) { BModelWriteOpener opener(fModel); ASSERT(fModel->Node()); MoreOptionsStruct::SetQueryTemporary(fModel->Node(), false); } RenameUndo undo(entry, text); result = entry.Rename(text, removeExisting); if (result != B_OK) undo.Remove(); } return result == B_OK; }
int32_t PDirectoryContains(void *pobject, void *in, void *out, void *extraData) { if (!pobject || !in || !out) return B_ERROR; PDirectory *parent = static_cast<PDirectory*>(pobject); if (!parent) return B_BAD_TYPE; BDirectory *backend = (BDirectory*)parent->GetBackend(); PArgs *inArgs = static_cast<PArgs*>(in); PArgs *outArgs = static_cast<PArgs*>(out); BString path; if (inArgs->FindString("path", &path) != B_OK) return B_ERROR; int32 type; if (inArgs->FindInt32("type", &type) != B_OK) return B_ERROR; bool outValue1; outValue1 = backend->Contains(path.String(), type); outArgs->MakeEmpty(); return B_OK; }
BEntry MediaConverterApp::_CreateOutputFile(BDirectory directory, entry_ref* ref, media_file_format* outputFormat) { BString name(ref->name); // create output file name int32 extIndex = name.FindLast('.'); if (extIndex != B_ERROR) name.Truncate(extIndex + 1); else name.Append("."); name.Append(outputFormat->file_extension); BEntry inEntry(ref); BEntry outEntry; if (inEntry.InitCheck() == B_OK) { // ensure that output name is unique int32 len = name.Length(); int32 i = 1; while (directory.Contains(name.String())) { name.Truncate(len); name << " " << i; i++; } outEntry.SetTo(&directory, name.String()); } return outEntry; }
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 */
status_t GetSettingsDir(BDirectory &dir, BPath &path) { //BPath path; status_t err; // TODO: build list from text files err = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); if (err < B_OK) return err; dir.SetTo(path.Path()); if (!dir.Contains("pe")) dir.CreateDirectory("pe", NULL); path.Append("pe"); dir.SetTo(path.Path()); if (!dir.Contains("HeaderTemplates")) dir.CreateDirectory("HeaderTemplates", NULL); path.Append("HeaderTemplates"); dir.SetTo(path.Path()); return B_OK; }
bool Feeder::Excluded(entry_ref *ref) { BEntry entry(ref) ; entry_ref* excludeRef ; BDirectory excludeDirectory ; BPath path ; for (int i = 0 ; (excludeRef = (entry_ref*)fExcludeList.ItemAt(i)) != NULL ; i++) { excludeDirectory.SetTo(excludeRef) ; if (excludeDirectory.Contains(&entry)) return true ; } return false ; }
void DataTranslationsApplication::RefsReceived(BMessage* message) { BTranslatorRoster* roster = BTranslatorRoster::Default(); BPath path; status_t status = find_directory(B_USER_ADDONS_DIRECTORY, &path, true); if (status != B_OK) { _InstallError("translator", status); return; } BDirectory target; status = target.SetTo(path.Path()); if (status == B_OK) { if (!target.Contains("Translators")) status = target.CreateDirectory("Translators", &target); else status = target.SetTo(&target, "Translators"); } if (status != B_OK) { _InstallError("translator", status); return; } int32 i = 0; entry_ref ref; while (message->FindRef("refs", i++, &ref) == B_OK) { if (!roster->IsTranslator(&ref)) { _NoTranslatorError(ref.name); continue; } BEntry entry(&ref, true); status = entry.InitCheck(); if (status != B_OK) { _InstallError(ref.name, status); continue; } if (target.Contains(ref.name)) { BString string( B_TRANSLATE("An item named '%name' already exists in the " "Translators folder! Shall the existing translator be " "overwritten?")); string.ReplaceAll("%name", ref.name); BAlert* alert = new BAlert(B_TRANSLATE("DataTranslations - Note"), string.String(), B_TRANSLATE("Cancel"), B_TRANSLATE("Overwrite")); alert->SetShortcut(0, B_ESCAPE); if (alert->Go() != 1) continue; // the original file will be replaced } // find out whether we need to copy it or not status = _Install(target, entry); if (status == B_OK) { BAlert* alert = new BAlert(B_TRANSLATE("DataTranslations - Note"), B_TRANSLATE("The new translator has been installed " "successfully."), B_TRANSLATE("OK")); alert->Go(NULL); } else _InstallError(ref.name, status); } }
void TFilePanel::HandleSaveButton() { BDirectory dir; if (TargetModel()->IsRoot()) { ShowCenteredAlert( B_TRANSLATE("Sorry, you can't save things at the root of " "your system."), B_TRANSLATE("Cancel")); return; } // check for some illegal file names if (strcmp(fTextControl->Text(), ".") == 0 || strcmp(fTextControl->Text(), "..") == 0) { ShowCenteredAlert( B_TRANSLATE("The specified name is illegal. Please choose " "another name."), B_TRANSLATE("Cancel")); fTextControl->TextView()->SelectAll(); return; } if (dir.SetTo(TargetModel()->EntryRef()) != B_OK) { ShowCenteredAlert( B_TRANSLATE("There was a problem trying to save in the folder " "you specified. Please try another one."), B_TRANSLATE("Cancel")); return; } if (dir.Contains(fTextControl->Text())) { if (dir.Contains(fTextControl->Text(), B_DIRECTORY_NODE)) { ShowCenteredAlert( B_TRANSLATE("The specified name is already used as the name " "of a folder. Please choose another name."), B_TRANSLATE("Cancel")); fTextControl->TextView()->SelectAll(); return; } else { // if this was invoked by a dbl click, it is an explicit // replacement of the file. BString str(B_TRANSLATE("The file \"%name\" already exists in " "the specified folder. Do you want to replace it?")); str.ReplaceFirst("%name", fTextControl->Text()); if (ShowCenteredAlert(str.String(), B_TRANSLATE("Cancel"), B_TRANSLATE("Replace")) == 0) { // user canceled fTextControl->TextView()->SelectAll(); return; } // user selected "Replace" - let app deal with it } } BMessage message(*fMessage); message.AddRef("directory", TargetModel()->EntryRef()); message.AddString("name", fTextControl->Text()); if (fClientObject) fClientObject->SendMessage(&fTarget, &message); else fTarget.SendMessage(&message); // close window if we're dealing with standard message if (fHideWhenDone) PostMessage(B_QUIT_REQUESTED); }
void PApp::FindAndOpen(const char *file, const char* fromSource) { char *bi = NULL; bool found = false; try { BEntry e; entry_ref doc; BDirectory d; if (!found && fromSource) { BPath path; entry_ref eref; if (get_ref_for_path(fromSource, &eref) == B_OK) { vector<BString> inclPathVect; if (!ProjectRoster->GetIncludePathsForFile(&eref, inclPathVect)) ProjectRoster->GetAllIncludePaths(inclPathVect); for(uint32 i=0; !found && i<inclPathVect.size(); ++i) { if (path.SetTo(inclPathVect[i].String(), file) != B_OK) continue; if (e.SetTo(path.Path(), true) != B_OK) continue; if (e.Exists() && e.IsFile()) { FailOSErr(e.GetRef(&doc)); found = true; } } } } if (!found && gPrefs->GetPrefInt(prf_I_BeIncludes)) { bi = strdup(getenv("BEINCLUDES")); char *ip = bi; char *p = ip; while (p && !found) { char *pe = strchr(p, ';'); if (pe) *pe = 0; FailOSErr(d.SetTo(p)); if (d.Contains(file, B_FILE_NODE | B_SYMLINK_NODE)) { FailOSErr(d.FindEntry(file, &e, true)); if (!e.IsFile()) THROW((0)); FailOSErr(e.GetRef(&doc)); found = true; } p = (pe && pe[1]) ? pe + 1 : NULL; } } if (!found) { const char *p; int i = 0; while ((p = gPrefs->GetIxPrefString(prf_X_IncludePath, i++))!= NULL && !found) { if (e.SetTo(p) != B_OK || !e.Exists()) continue; FailOSErr(d.SetTo(p)); if (d.Contains(file, B_FILE_NODE | B_SYMLINK_NODE)) { FailOSErr(d.FindEntry(file, &e, true)); if (!e.IsFile()) THROW((0)); FailOSErr(e.GetRef(&doc)); found = true; } } } if (found) OpenWindow(doc); else beep(); } catch (HErr& e) { beep(); } if (bi) free(bi); } // PApp::FindAndOpen
PApp::PApp() : BApplication("application/x-vnd.dw-PalEdit") { try { try { BPath settings; FailOSErr(find_directory(B_USER_SETTINGS_DIRECTORY, &settings, true)); BDirectory e; FailOSErrMsg(e.SetTo(settings.Path()), "~/config/settings directory not found ?!?!?"); if (!e.Contains("PalEdit", B_DIRECTORY_NODE)) FailOSErr(e.CreateDirectory("PalEdit", &gPrefsDir)); else { BEntry d; FailOSErr(e.FindEntry("PalEdit", &d, B_DIRECTORY_NODE)); FailOSErr(gPrefsDir.SetTo(&d)); } } catch (HErr& e) { e.DoError(); } gPrefs = new HPreferences("PalEdit/settings"); gPrefs->ReadPrefFile(); app_info ai; GetAppInfo(&ai); BEntry entry(&ai.ref); FailOSErr(gAppFile.SetTo(&entry, B_READ_ONLY)); BPath appName; FailOSErr(entry.GetPath(&appName)); BPath dir; FailOSErr(appName.GetParent(&dir)); FailOSErr(gAppDir.SetTo(dir.Path())); fOpenPanel = new BFilePanel(); FailNil(fOpenPanel); entry_ref cwd_ref; fOpenPanel->GetPanelDirectory(&cwd_ref); FailOSErr(gCWD.SetTo(&cwd_ref)); PDoc::LoadAddOns(); InitUTFTables(); SetColor(kColorLow, prf_C_Low, 0xff, 0xff, 0xff); SetColor(kColorText, prf_C_Text, 0x00, 0x00, 0x00); SetColor(kColorSelection, prf_C_Selection, 0xd1, 0xd1, 0xff); SetColor(kColorMark, prf_C_Mark, 0x00, 0x00, 0xff); SetColor(kColorKeyword1, prf_C_Keyword1, 0x00, 0x00, 0xff); SetColor(kColorKeyword2, prf_C_Keyword2, 0x00, 0x00, 0xff); SetColor(kColorComment1, prf_C_Comment1, 0x1e, 0x93, 0x1e); SetColor(kColorComment2, prf_C_Comment2, 0x1e, 0x93, 0x1e); SetColor(kColorString1, prf_C_String1, 0x7e, 0x7e, 0x7e); SetColor(kColorString2, prf_C_String2, 0x7e, 0x7e, 0x7e); SetColor(kColorNumber1, prf_C_Number1, 0x85, 0x0a, 0x48); SetColor(kColorNumber2, prf_C_Number2, 0x85, 0x0a, 0x48); SetColor(kColorOperator1, prf_C_Operator1, 0x00, 0x00, 0x00); SetColor(kColorOperator2, prf_C_Operator2, 0x00, 0x00, 0x00); SetColor(kColorSeparator1, prf_C_Separator1, 0x00, 0x00, 0x00); SetColor(kColorSeparator2, prf_C_Separator2, 0x00, 0x00, 0x00); SetColor(kColorPreprocessor1, prf_C_Preprocessor1, 0x00, 0x00, 0xff); SetColor(kColorPreprocessor2, prf_C_Preprocessor2, 0x00, 0x00, 0xff); SetColor(kColorError1, prf_C_Error1, 0xff, 0x00, 0x00); SetColor(kColorError2, prf_C_Error2, 0xff, 0x00, 0x00); SetColor(kColorIdentifierSystem,prf_C_IdentifierSystem, 0x39, 0x79, 0x79); SetColor(kColorCharConst, prf_C_CharConst, 0x7e, 0x7e, 0x7e); SetColor(kColorIdentifierUser, prf_C_IdentifierUser, 0x00, 0x00, 0x00); SetColor(kColorTag, prf_C_Tag, 0x88, 0x88, 0x88); SetColor(kColorAttribute, prf_C_Attribute, 0xff, 0x00, 0x00); SetColor(kColorUserSet1, prf_C_UserSet1, 0x00, 0x00, 0x00); SetColor(kColorUserSet2, prf_C_UserSet2, 0x00, 0x00, 0x00); SetColor(kColorUserSet3, prf_C_UserSet3, 0x00, 0x00, 0x00); SetColor(kColorUserSet4, prf_C_UserSet4, 0x00, 0x00, 0x00); SetColor(kColorInvisibles, prf_C_Invisibles, 0xC8, 0x64, 0x64); DefineInvColors(gColor[kColorSelection]); gAutoIndent = gPrefs->GetPrefInt(prf_I_AutoIndent, 1); gSyntaxColoring = gPrefs->GetPrefInt(prf_I_SyntaxColoring, 1); gSpacesPerTab = gPrefs->GetPrefInt(prf_I_SpacesPerTab, 4); gBalance = gPrefs->GetPrefInt(prf_I_BalanceWhileTyping, 1); gBlockCursor = gPrefs->GetPrefInt(prf_I_BlockCursor, 0); gFlashCursor = gPrefs->GetPrefInt(prf_I_FlashCursor, 1); gSmartBrace = gPrefs->GetPrefInt(prf_I_SmartBraces, 1); gPopupIncludes = gPrefs->GetPrefInt(prf_I_ShowIncludes, 1); gPopupProtos = gPrefs->GetPrefInt(prf_I_ShowPrototypes, 1); gPopupFuncs = gPrefs->GetPrefInt(prf_I_ShowTypes, 1); gPopupSorted = gPrefs->GetPrefInt(prf_I_SortPopup, 0); gRedirectStdErr = gPrefs->GetPrefInt(prf_I_RedirectStdErr, 1); gUseWorksheet = gPrefs->GetPrefInt(prf_I_Worksheet, 0); gRestorePosition = gPrefs->GetPrefInt(prf_I_RestorePosition, 1); gRestoreFont = gPrefs->GetPrefInt(prf_I_RestoreFont, 1); gRestoreSelection = gPrefs->GetPrefInt(prf_I_RestoreSelection, 1); gRestoreScrollbar = gPrefs->GetPrefInt(prf_I_RestoreScrollbar, 1); gRestoreCWD = gPrefs->GetPrefInt(prf_I_RestoreCwd, 1); gSavedState = gPrefs->GetPrefInt(prf_I_SavedState, 1); if (gPrefs->GetIxPrefString(prf_X_Mimetype, 0) == NULL) { gPrefs->SetIxPrefString(prf_X_Mimetype, 0, "text/plain"); gPrefs->SetIxPrefString(prf_X_Mimetype, 1, "text/html"); gPrefs->SetIxPrefString(prf_X_Mimetype, 2, "text/x-source-code"); } strcpy(gTabChar, gPrefs->GetPrefString(prf_S_TabChar, "»")); strcpy(gReturnChar, gPrefs->GetPrefString(prf_S_ReturnChar, "¬")); strcpy(gSpaceChar, gPrefs->GetPrefString(prf_S_SpaceChar, ".")); strcpy(gControlChar, gPrefs->GetPrefString(prf_S_ControlChar, "¿")); gUid = getuid(); gGid = getgid(); gRecentBufferSize = gPrefs->GetPrefInt(prf_I_RecentSize, 10); RestoreRecentMenu(); fFindDialog = DialogCreator<CFindDialog>::CreateDialog("Find", NULL, PDoc::TopWindow()); fFindDialog->Run(); InitSelectedMap(); CLanguageInterface::SetupLanguageInterfaces(); fIsQuitting = false; fPrefsDialog = NULL; CPrefOpener *prefOpener = new CPrefOpener; fPrefOpener = prefOpener->Thread(); if (gUseWorksheet) OpenWorksheet(); // prefOpener->Run(); } catch (HErr& e) { e.DoError(); exit(1); } catch(...) { beep(); exit(1); } } /* PApp::PApp */