void OpenFilesListPlugin::RebuildOpenFilesTree() { if (Manager::IsAppShuttingDown()) return; EditorManager* mgr = Manager::Get()->GetEditorManager(); m_pTree->Freeze(); m_pTree->DeleteChildren(m_pTree->GetRootItem()); if (!mgr->GetEditorsCount()) { m_pTree->Thaw(); return; } // loop all open editors for (int i = 0; i < mgr->GetEditorsCount(); ++i) { EditorBase* ed = mgr->GetEditor(i); if (!ed || !ed->VisibleToTree()) continue; wxString shortname = ed->GetShortName(); int mod = GetOpenFilesListIcon(ed); wxTreeItemId item = m_pTree->AppendItem(m_pTree->GetRootItem(), shortname, mod, mod, new OpenFilesListData(ed)); if (mgr->GetActiveEditor() == ed) m_pTree->SelectItem(item); } m_pTree->SortChildren(m_pTree->GetRootItem()); m_pTree->Expand(m_pTree->GetRootItem()); m_pTree->Thaw(); }
void CodeRefactoring::GetOpenedFiles(wxArrayString& files) { EditorManager* edMan = Manager::Get()->GetEditorManager(); if (edMan) { for (int i = 0; i < edMan->GetEditorsCount(); ++i) files.Add(edMan->GetEditor(i)->GetFilename()); } }
inline void CrashHandlerSaveEditorFiles(wxString& buf) { wxString path; //get the "My Files" folder HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, wxStringBuffer(path, MAX_PATH)); if (FAILED(result)) { //get at least the profiles folder path = ConfigManager::GetHomeFolder(); } path << _T("\\cb-crash-recover"); if (!wxDirExists(path)) wxMkdir(path); //make a sub-directory of the current date & time wxDateTime now = wxDateTime::Now(); path << now.Format(_T("\\%Y%m%d-%H%M%S")); EditorManager* em = Manager::Get()->GetEditorManager(); if (em) { bool AnyFileSaved = false; if (wxMkdir(path) && wxDirExists(path)) { for (int i = 0; i < em->GetEditorsCount(); ++i) { cbEditor* ed = em->GetBuiltinEditor(em->GetEditor(i)); if (ed) { wxFileName fn(ed->GetFilename()); wxString fnpath = path + _T("/") + fn.GetFullName(); wxString newfnpath = fnpath; // add number if filename already exists e.g. main.cpp.001, main.cpp.002, ... int j = 1; while (wxFileExists(newfnpath)) newfnpath = fnpath + wxString::Format(wxT(".%03d"),j); if (cbSaveToFile(newfnpath, ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom() ) ) { AnyFileSaved = true; } } } if (AnyFileSaved) { buf << _("The currently opened files have been saved to the directory\n"); buf << path; buf << _("\nHopefully, this will prevent you from losing recent modifications.\n\n"); } else wxRmdir(path); } } }
// ---------------------------------------------------------------------------- void JumpTracker::OnMenuJumpNext(wxCommandEvent &event) // ---------------------------------------------------------------------------- { #if defined(LOGGING) //LOGIT( _T("JT [%s]"), _T("OnMenuJumpNext")); #endif m_bJumpInProgress = true; do { int count = m_ArrayOfJumpData.GetCount(); if (not count) break; if ( count > 1 ) m_Cursor += 1; if (m_Cursor > (int)count-1) m_Cursor = 0; EditorManager* edmgr = Manager::Get()->GetEditorManager(); int cursor = m_Cursor; wxString edFilename; long edPosn; bool found = false; for (int i = 0; i<count; ++i, ++cursor) { if (cursor > count-1) cursor = 0; JumpData& jumpNext = m_ArrayOfJumpData.Item(cursor); edFilename = jumpNext.GetFilename(); edPosn = jumpNext.GetPosition(); if (not edmgr->IsOpen(edFilename)) continue; found = true; break; } if (not found) break; m_Cursor = cursor; #if defined(LOGGING) LOGIT( _T("JT OnMenuJumpNext [%s][%ld]curs[%d]"), edFilename.c_str(), edPosn, m_Cursor); #endif // activate editor EditorBase* eb = edmgr->GetEditor(edFilename); if (not eb) break; edmgr->SetActiveEditor(eb); // position to editor line cbEditor* cbed = edmgr->GetBuiltinEditor(eb); if (not cbed) break; cbed->GotoLine(cbed->GetControl()->LineFromPosition(edPosn)); //center on scrn cbed->GetControl()->GotoPos(edPosn); }while(0); m_bJumpInProgress = false; return; }
inline void RefreshBreakpoints(cb_unused const cbDebuggerPlugin* plugin) { EditorManager *editorManager = Manager::Get()->GetEditorManager(); int count = editorManager->GetEditorsCount(); for (int ii = 0; ii < count; ++ii) { EditorBase *editor = editorManager->GetEditor(ii); if (!editor->IsBuiltinEditor()) continue; editor->RefreshBreakpointMarkers(); } }
LoaderBase* FileManager::Load(const wxString& file, bool reuseEditors) { if (reuseEditors) { // if a file is opened in the editor, and the file get modified, we use the content of the // editor, otherwise, we still use the original file EditorManager* em = Manager::Get()->GetEditorManager(); if (em) { wxFileName fileName(file); for (int i = 0; i < em->GetEditorsCount(); ++i) { cbEditor* ed = em->GetBuiltinEditor(em->GetEditor(i)); if (ed && fileName == ed->GetFilename()) { if (!ed->GetModified()) break; EditorReuser *nl = new EditorReuser(file, ed->GetControl()->GetText()); return nl; } } } } if (file.StartsWith(_T("http://"))) { URLLoader *ul = new URLLoader(file); urlLoaderThread.Queue(ul); return ul; } FileLoader *fl = new FileLoader(file); if (file.length() > 2 && file[0] == _T('\\') && file[1] == _T('\\')) { // UNC files behave like "normal" files, but since we know they are served over the network, // we can run them independently from local filesystem files for higher concurrency uncLoaderThread.Queue(fl); return fl; } fileLoaderThread.Queue(fl); return fl; }
void Autosave::OnTimer(wxTimerEvent& e) { if(e.GetId() == 10000) { int method = Manager::Get()->GetConfigManager(_T("autosave"))->ReadInt(_T("method")); bool allProjects = Manager::Get()->GetConfigManager(_T("autosave"))->ReadBool(_T("all_projects"), true); bool doWorkspace = Manager::Get()->GetConfigManager(_T("autosave"))->ReadBool(_T("do_workspace"), true); ProjectManager *pm = Manager::Get()->GetProjectManager(); if(pm)// && pm->GetActiveProject()) { if (allProjects) { ProjectsArray *projects = pm->GetProjects(); for (size_t ii = 0; ii < projects->GetCount(); ++ii) SaveProject((*projects)[ii], method); } else if(cbProject *p = pm->GetActiveProject()) SaveProject(p, method); cbWorkspace *workspace = pm->GetWorkspace(); if (doWorkspace && workspace && workspace->GetModified()) { switch(method) { case 0: if(::wxRenameFile(workspace->GetFilename(), workspace->GetFilename() + _T(".bak"))) workspace->Save(); break; case 1: workspace->Save(); break; case 2: case 3: { WorkspaceLoader loader; loader.Save(workspace->GetTitle(), workspace->GetFilename() + wxT(".save")); workspace->SetModified(true); break; } default: break; } } } } else if(e.GetId() == 20000) { int method = Manager::Get()->GetConfigManager(_T("autosave"))->ReadInt(_T("method")); EditorManager* em = Manager::Get()->GetEditorManager(); if(em) { for(int i = 0; i < em->GetEditorsCount(); ++i) { cbEditor* ed = em->GetBuiltinEditor(em->GetEditor(i)); if(ed && ed->GetModified()) { wxFileName fn(ed->GetFilename()); switch(method) { case 0: { if(::wxRenameFile(fn.GetFullPath(), fn.GetFullPath() + _T(".bak"))) cbSaveToFile(fn.GetFullPath(), ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom()); break; } case 1: { ed->Save(); break; } case 2: { cbSaveToFile(fn.GetFullPath() + _T(".save"), ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom()); ed->SetModified(); // the "real" file has not been saved! break; } case 3: { wxString tmp1; wxString tmp2; for(unsigned int revisions = 8; revisions; --revisions) { tmp1.Printf(_T("%s/%s.%u.%s"), fn.GetPath().c_str(), fn.GetName().c_str(), revisions, fn.GetExt().c_str()); tmp2.Printf(_T("%s/%s.%u.%s"), fn.GetPath().c_str(), fn.GetName().c_str(), revisions+1, fn.GetExt().c_str()); if(::wxFileExists(tmp2)) ::wxRemoveFile(tmp2); if(::wxFileExists(tmp1)) ::wxRenameFile(tmp1, tmp2); } tmp1.Printf(_T("%s/%s.1.%s"), fn.GetPath().c_str(), fn.GetName().c_str(), fn.GetExt().c_str()); cbSaveToFile(tmp1, ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom()); ed->SetModified(); // the "real" file has not been saved! break; } default: break; } } } } } }
void Autosave::OnTimer(wxTimerEvent& e) { if(e.GetId() == 10000) { PluginManager *plm = Manager::Get()->GetPluginManager(); int method = Manager::Get()->GetConfigManager(_T("autosave"))->ReadInt(_T("method")); ProjectManager *pm = Manager::Get()->GetProjectManager(); if(pm && pm->GetActiveProject()) { if(cbProject * p = pm->GetActiveProject()) { switch(method) { case 0: { if(p->GetModified()) { if(::wxRenameFile(p->GetFilename(), p->GetFilename() + _T(".bak"))) if(p->Save()) { CodeBlocksEvent e(cbEVT_PROJECT_SAVE, 0, p); plm->NotifyPlugins(e); } } wxFileName file = p->GetFilename(); file.SetExt(_T("layout")); wxString filename = file.GetFullPath(); if(::wxRenameFile(filename, filename + _T(".bak"))) p->SaveLayout(); break; } case 1: { if(p->GetModified() && p->Save()) { CodeBlocksEvent e(cbEVT_PROJECT_SAVE, 0, p); plm->NotifyPlugins(e); } p->SaveLayout(); break; } case 2: case 3: // doesn't really make sense to keep so many versions of a project file { if (p->IsLoaded() == false) return; if(p->GetModified()) { ProjectLoader loader(p); if(loader.Save(p->GetFilename() + _T(".save"))) { CodeBlocksEvent e(cbEVT_PROJECT_SAVE, 0, p); plm->NotifyPlugins(e); } p->SetModified(); // the actual project file is still not updated! } wxFileName file = wxFileName(p->GetFilename()); file.SetExt(_T("layout")); wxString filename = file.GetFullPath(); wxString temp = filename + _T(".temp"); wxString save = filename + _T(".save"); if(::wxFileExists(filename) && ::wxCopyFile(filename, temp)) { p->SaveLayout(); ::wxRenameFile(filename, save); ::wxRenameFile(temp, filename); } break; } } } } } else if(e.GetId() == 20000) { int method = Manager::Get()->GetConfigManager(_T("autosave"))->ReadInt(_T("method")); EditorManager* em = Manager::Get()->GetEditorManager(); if(em) { for(int i = 0; i < em->GetEditorsCount(); ++i) { cbEditor* ed = em->GetBuiltinEditor(em->GetEditor(i)); if(ed && ed->GetModified()) { wxFileName fn(ed->GetFilename()); switch(method) { case 0: { if(::wxRenameFile(fn.GetFullPath(), fn.GetFullPath() + _T(".bak"))) cbSaveToFile(fn.GetFullPath(), ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom()); break; } case 1: { ed->Save(); break; } case 2: { cbSaveToFile(fn.GetFullPath() + _T(".save"), ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom()); ed->SetModified(); // the "real" file has not been saved! break; } case 3: { wxString tmp1; wxString tmp2; for(unsigned int i = 8; i; --i) { tmp1.Printf(_T("%s/%s.%u.%s"), fn.GetPath().c_str(), fn.GetName().c_str(), i, fn.GetExt().c_str()); tmp2.Printf(_T("%s/%s.%u.%s"), fn.GetPath().c_str(), fn.GetName().c_str(), i+1, fn.GetExt().c_str()); if(::wxFileExists(tmp2)) ::wxRemoveFile(tmp2); if(::wxFileExists(tmp1)) ::wxRenameFile(tmp1, tmp2); } tmp1.Printf(_T("%s/%s.1.%s"), fn.GetPath().c_str(), fn.GetName().c_str(), fn.GetExt().c_str()); cbSaveToFile(tmp1, ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom()); ed->SetModified(); // the "real" file has not been saved! break; } } } } } } }