bool MFindAndOpenDialog::OKClicked() { string s; GetText(kTextBoxControlID, s); Preferences::SetString("last open include", s); if (mController != nil) { if (not mController->OpenInclude(s)) PlaySound("warning"); } else { MProject* project = dynamic_cast<MProject*>(GetParentWindow()); if (project == nil) project = MProject::Instance(); MPath p(s); if (exists(p) or (project != nil and project->LocateFile(s, true, p))) gApp->OpenOneDocument(MUrl(p)); } return true; }
bool MController::OpenInclude( string inFileName) { MProject* project = MProject::Instance(); MUrl url; if (mDocument != nil) { url = mDocument->GetURL(); url.SetPath(url.GetPath().branch_path() / inFileName); } bool result = false; if (url.IsValid()) { if (url.IsLocal()) result = fs::exists(url.GetPath()); else result = true; } MPath p; if (not result and project != nil and project->LocateFile(inFileName, true, p)) { result = true; url = MUrl(p); } if (result) gApp->OpenOneDocument(url); return result; }
void MTextController::DoOpenCounterpart() { MTextDocument* doc = dynamic_cast<MTextDocument*>(mDocument); if (doc == nil) return; bool result = false; const char* kSourceExtensions[] = { "c", "cc", "cp", "cpp", "c++", nil }; const char* kHeaderExtensions[] = { "h", "hp", "hpp", nil }; if (doc->IsSpecified()) { string name = doc->GetURL().GetFileName(); fs::path p; const char** ext = nil; if (FileNameMatches("*.h;*.hp;*.hpp", name)) ext = kSourceExtensions; else if (FileNameMatches("*.c;*.cc;*.cp;*.cpp;*.c++;*.inl", name)) ext = kHeaderExtensions; if (ext != nil) { name.erase(name.rfind('.') + 1); MProject* project = MProject::Instance(); if (project != nil) { for (const char** e = ext; result == false and *e != nil; ++e) result = project->LocateFile(name + *e, true, p); if (result) gApp->OpenOneDocument(MUrl(p)); } if (not result) { for (const char** e = ext; result == false and *e != nil; ++e) result = OpenInclude(name + *e); } } } if (not result) PlaySound("warning"); }