void CodeLiteApp::AdjustPathForCygwinIfNeeded() { #ifdef __WXMSW__ CL_DEBUG("AdjustPathForCygwinIfNeeded called"); if(!::clIsCygwinEnvironment()) { CL_DEBUG("Not running under Cygwin - nothing be done"); return; } CL_SYSTEM("Cygwin environment detected"); wxString cygwinRootDir; CompilerLocatorCygwin cygwin; if(cygwin.Locate()) { // this will return the base folder for cygwin (e.g. D:\cygwin) cygwinRootDir = (*cygwin.GetCompilers().begin())->GetInstallationPath(); } // Running under Cygwin // Adjust the PATH environment variable wxString pathEnv; ::wxGetEnv("PATH", &pathEnv); // Always add the default paths wxArrayString paths; if(!cygwinRootDir.IsEmpty()) { CL_SYSTEM("Cygwin root folder is: %s", cygwinRootDir); wxFileName cygwinBinFolder(cygwinRootDir, ""); cygwinBinFolder.AppendDir("bin"); paths.Add(cygwinBinFolder.GetPath()); } paths.Add("/usr/local/bin"); paths.Add("/usr/bin"); paths.Add("/usr/sbin"); paths.Add("/bin"); paths.Add("/sbin"); // Append the paths from the environment variables wxArrayString userPaths = ::wxStringTokenize(pathEnv, ";", wxTOKEN_STRTOK); paths.insert(paths.end(), userPaths.begin(), userPaths.end()); wxString fixedPath; for(size_t i = 0; i < paths.GetCount(); ++i) { wxString& curpath = paths.Item(i); static wxRegEx reCygdrive("/cygdrive/([A-Za-z])"); if(reCygdrive.Matches(curpath)) { // Get the drive letter wxString volume = reCygdrive.GetMatch(curpath, 1); volume << ":"; reCygdrive.Replace(&curpath, volume); } fixedPath << curpath << ";"; } CL_DEBUG("Setting PATH environment variable to:\n%s", fixedPath); ::wxSetEnv("PATH", fixedPath); #endif }
void SetFilter(wxString filter) { // Escape any regular-expression special characters static wxRegEx escape_meta("[-[\\]{}()*+?.,\\\\^$|#]", wxRE_ADVANCED); escape_meta.Replace(&filter, "\\\\&"); // Using wxRegEx for case-insensitive contains wxRegEx re(filter, wxRE_ADVANCED | wxRE_ICASE | wxRE_NOSUB); for_each(categories.begin(), categories.end(), bind(&HotkeyModelCategory::SetFilter, std::tr1::placeholders::_1, std::tr1::ref(re))); }
void OpenResourceDialog::GetLineNumberFromFilter(const wxString& filter, wxString& modFilter, long& lineNumber) { modFilter = filter; lineNumber = -1; static wxRegEx reNumber(":([0-9]+)", wxRE_ADVANCED); if(reNumber.IsValid() && reNumber.Matches(modFilter)) { wxString strLineNumber; strLineNumber = reNumber.GetMatch(modFilter, 1); strLineNumber.ToCLong(&lineNumber); reNumber.Replace(&modFilter, ""); } }
void CPasswordSubset::OnChar( wxKeyEvent& event ) { static wxRegEx charSet("[[:digit:]]|[[:space:]]|,|-|;"); static wxRegEx seps(",|;"); wxASSERT(charSet.IsValid() && seps.IsValid()); wxChar uc = event.GetUnicodeKey(); if (uc != WXK_NONE) { const int N = m_password.length(); if (charSet.Matches(wxString(uc, 1))) { event.Skip(true); // accept // Check against valid pos regexp and update vals accordingly wxString pos_str = m_pos->GetLineText(0); pos_str += uc; // since accepted char will only be added to control later // could have used xwStringTokenizer in following, but this way we also convert to int // and catch bad usage of '-' seps.Replace(&pos_str, wxT(" ")); // replace ';' and ',' with ' ' for stream tokenizing m_vals->Clear(); m_error->SetLabel(wxEmptyString); std::wistringstream is(pos_str.wc_str()); int pos; while (is >> pos) { if (pos > 0 && pos <= N) *m_vals << m_password[pos - 1] << wxT(" "); else if (pos < 0 && pos >= -N) *m_vals << m_password[N + pos] << wxT(" "); else { m_error->SetLabel(_("Invalid position")); } } if (!is.eof()) { m_error->SetLabel(_("Invalid position")); } } else { if (uc == WXK_BACK)
LEditor* MainBook::OpenFile(const wxString& file_name, const wxString& projectName, int lineno, long position, OF_extra extra /*=OF_AddJump*/, bool preserveSelection /*=true*/) { wxFileName fileName(file_name); fileName.MakeAbsolute(); #ifdef __WXMSW__ // Handle cygwin paths wxString curpath = fileName.GetFullPath(); static wxRegEx reCygdrive("/cygdrive/([A-Za-z])"); if(reCygdrive.Matches(curpath)) { // Replace the /cygdrive/c with volume C: wxString volume = reCygdrive.GetMatch(curpath, 1); volume << ":"; reCygdrive.Replace(&curpath, volume); fileName = curpath; } #endif if(!IsFileExists(fileName)) { wxLogMessage(wxT("Failed to open: %s: No such file or directory"), fileName.GetFullPath().c_str()); return NULL; } if(FileExtManager::GetType(fileName.GetFullName()) == FileExtManager::TypeBmp) { // a bitmap file, open it using an image viewer DoOpenImageViewer(fileName); return NULL; } wxString projName = projectName; if(projName.IsEmpty()) { // try to match a project name to the file. otherwise, CC may not work projName = ManagerST::Get()->GetProjectNameByFile(fileName.GetFullPath()); } LEditor* editor = GetActiveEditor(true); BrowseRecord jumpfrom = editor ? editor->CreateBrowseRecord() : BrowseRecord(); editor = FindEditor(fileName.GetFullPath()); if(editor) { editor->SetProject(projName); } else if(fileName.IsOk() == false) { wxLogMessage(wxT("Invalid file name: ") + fileName.GetFullPath()); return NULL; } else if(!fileName.FileExists()) { wxLogMessage(wxT("File: ") + fileName.GetFullPath() + wxT(" does not exist!")); return NULL; } else { // A Nice trick: hide the notebook, open the editor // and then show it bool hidden(false); if(m_book->GetPageCount() == 0) hidden = GetSizer()->Hide(m_book); editor = new LEditor(m_book); editor->Create(projName, fileName); int sel = m_book->GetSelection(); if((extra & OF_PlaceNextToCurrent) && (sel != wxNOT_FOUND)) { AddPage(editor, fileName.GetFullName(), fileName.GetFullPath(), wxNullBitmap, false, sel + 1); } else { AddPage(editor, fileName.GetFullName(), fileName.GetFullPath()); } editor->SetSyntaxHighlight(); // mark the editor as read only if neede MarkEditorReadOnly(editor); // SHow the notebook if(hidden) GetSizer()->Show(m_book); if(position == wxNOT_FOUND && lineno == wxNOT_FOUND && editor->GetContext()->GetName() == wxT("C++")) { // try to find something interesting in the file to put the caret at // for now, just skip past initial blank lines and comments for(lineno = 0; lineno < editor->GetLineCount(); lineno++) { switch(editor->GetStyleAt(editor->PositionFromLine(lineno))) { case wxSTC_C_DEFAULT: case wxSTC_C_COMMENT: case wxSTC_C_COMMENTDOC: case wxSTC_C_COMMENTLINE: case wxSTC_C_COMMENTLINEDOC: continue; } // if we got here, it's a line to stop on break; } if(lineno == editor->GetLineCount()) { lineno = 1; // makes sure a navigation record gets saved } } } if(position != wxNOT_FOUND) { editor->SetEnsureCaretIsVisible(position, preserveSelection); editor->SetLineVisible(editor->LineFromPosition(position)); } else if(lineno != wxNOT_FOUND) { editor->CenterLine(lineno); } if(m_reloadingDoRaise) { if(GetActiveEditor() == editor) { editor->SetActive(); } else { SelectPage(editor); } } // Add this file to the history. Don't check for uniqueness: // if it's already on the list, wxFileHistory will move it to the top // Also, sync between the history object and the configuration file m_recentFiles.AddFileToHistory(fileName.GetFullPath()); clConfig::Get().AddRecentFile(fileName.GetFullPath()); if(extra & OF_AddJump) { BrowseRecord jumpto = editor->CreateBrowseRecord(); NavMgr::Get()->AddJump(jumpfrom, jumpto); } #if !CL_USE_NATIVEBOOK if(m_book->GetPageCount() == 1) { m_book->GetSizer()->Layout(); } #endif return editor; }