void MainBook::DetachActiveEditor() { if(GetActiveEditor()) { LEditor* editor = GetActiveEditor(); m_book->RemovePage(m_book->GetSelection(), true); EditorFrame* frame = new EditorFrame(clMainFrame::Get(), editor); frame->Show(); m_detachedEditors.push_back(frame); } }
void MainBook::CreateSession(SessionEntry& session, wxArrayInt* excludeArr) { std::vector<LEditor*> editors; GetAllEditors(editors, kGetAll_RetainOrder); session.SetSelectedTab(0); std::vector<TabInfo> vTabInfoArr; for(size_t i = 0; i < editors.size(); i++) { if(excludeArr && (excludeArr->GetCount() > i) && (!excludeArr->Item(i))) { // If we're saving only selected editors, and this isn't one of them... continue; } if(editors[i] == GetActiveEditor()) { session.SetSelectedTab(vTabInfoArr.size()); } TabInfo oTabInfo; oTabInfo.SetFileName(editors[i]->GetFileName().GetFullPath()); oTabInfo.SetFirstVisibleLine(editors[i]->GetFirstVisibleLine()); oTabInfo.SetCurrentLine(editors[i]->GetCurrentLine()); wxArrayString astrBookmarks; editors[i]->StoreMarkersToArray(astrBookmarks); oTabInfo.SetBookmarks(astrBookmarks); std::vector<int> folds; editors[i]->StoreCollapsedFoldsToArray(folds); oTabInfo.SetCollapsedFolds(folds); vTabInfoArr.push_back(oTabInfo); } session.SetTabInfoArr(vTabInfoArr); }
void MainBook::DoUpdateNotebookTheme() { size_t initialStyle = m_book->GetStyle(); size_t style = m_book->GetStyle(); if(EditorConfigST::Get()->GetOptions()->IsTabColourMatchesTheme()) { // Update theme IEditor* editor = GetActiveEditor(); if(editor) { wxColour bgColour = editor->GetCtrl()->StyleGetBackground(0); if(DrawingUtils::IsDark(bgColour) && !(m_book->GetStyle() & kNotebook_DarkTabs)) { style &= ~kNotebook_LightTabs; style |= kNotebook_DarkTabs; } else if(!DrawingUtils::IsDark(bgColour) && !(m_book->GetStyle() & kNotebook_LightTabs)) { style &= ~kNotebook_DarkTabs; style |= kNotebook_LightTabs; } } else { style &= ~kNotebook_DarkTabs; style |= kNotebook_LightTabs; } } else { style &= ~kNotebook_DarkTabs; style |= kNotebook_LightTabs; } if(!EditorConfigST::Get()->GetOptions()->IsTabHasXButton()) { style &= ~(kNotebook_CloseButtonOnActiveTab | kNotebook_CloseButtonOnActiveTabFireEvent); } else { style |= (kNotebook_CloseButtonOnActiveTab | kNotebook_CloseButtonOnActiveTabFireEvent); } if(initialStyle != style) { m_book->SetStyle(style); } }
void CommandCopyPasteHeightmap::UpdateLandscapeTilemap(DAVA::Image *image) { Texture* texture = Texture::CreateFromData(image->GetPixelFormat(), image->GetData(), image->GetWidth(), image->GetHeight(), false); texture->relativePathname = tilemapSavedPathname; texture->GenerateMipmaps(); texture->SetWrapMode(Texture::WRAP_REPEAT, Texture::WRAP_REPEAT); LandscapeEditorBase* editor = GetActiveEditor(); if (editor) { editor->UpdateLandscapeTilemap(texture); } else { SceneEditorScreenMain *screen = dynamic_cast<SceneEditorScreenMain *>(UIScreenManager::Instance()->GetScreen()); EditorScene* scene = screen->FindCurrentBody()->bodyControl->GetScene(); Landscape* landscape = scene->GetLandscape(scene); landscape->SetTexture(Landscape::TEXTURE_TILE_MASK, texture); landscape->UpdateFullTiledTexture(); ImageLoader::Save(image, tilemapSavedPathname); } SafeRelease(texture); }
int ProjectFrame::CloseFile() { EditorView *vw = GetActiveEditor(); if (vw) return CloseEditor(vw->GetItem()); return 0; }
void MainBook::OnPageChanging(wxBookCtrlEvent& e) { LEditor* editor = GetActiveEditor(); if(editor) { editor->CallTipCancel(); } #if HAS_LIBCLANG ClangCodeCompletion::Instance()->CancelCodeComplete(); #endif e.Skip(); }
int ProjectFrame::SaveFile() { EditorView *vw = GetActiveEditor(); if (vw) { ProjectItem *itm = vw->GetItem(); if (itm) return itm->SaveItem(); } return 0; }
void MainBook::OnPageClosed(NotebookEvent &e) { SelectPage(m_book->GetCurrentPage()); m_quickFindBar->SetEditor(GetActiveEditor()); // any editors left open? LEditor *editor = NULL; for (size_t i = 0; i < m_book->GetPageCount() && editor == NULL; i++) { editor = dynamic_cast<LEditor*>(m_book->GetPage(i)); } if (m_book->GetPageCount() == 0) { SendCmdEvent(wxEVT_ALL_EDITORS_CLOSED); ShowQuickBar(false); } }
void CommandDrawTilemap::UpdateLandscapeTilemap(DAVA::Image *image) { Texture* texture = Texture::CreateFromData(image->GetPixelFormat(), image->GetData(), image->GetWidth(), image->GetHeight(), false); texture->relativePathname = savedPathname; texture->SetWrapMode(Texture::WRAP_REPEAT, Texture::WRAP_REPEAT); LandscapeEditorBase* editor = GetActiveEditor(); if (editor) { editor->UpdateLandscapeTilemap(texture); } else if (landscape) { landscape->SetTexture(Landscape::TEXTURE_TILE_MASK, texture); landscape->UpdateFullTiledTexture(); ImageLoader::Save(image, savedPathname); } SafeRelease(texture); }
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; }
void ProjectFrame::MarkerPrev() { EditorView *vw = GetActiveEditor(); if (vw) vw->PrevMarker(); }
void ProjectFrame::MarkerClear() { EditorView *vw = GetActiveEditor(); if (vw) vw->ClearMarkers(); }
void ProjectFrame::EditGoto() { EditorView *vw = GetActiveEditor(); if (vw) vw->GotoLine(-1); }
void ProjectFrame::MarkerNext() { EditorView *vw = GetActiveEditor(); if (vw) vw->NextMarker(); }
void ProjectFrame::EditSelectAll() { EditorView *vw = GetActiveEditor(); if (vw) vw->SelectAll(); }
void ProjectFrame::EditFindNext() { EditorView *vw = GetActiveEditor(); if (vw) vw->FindNext(); }
void ProjectFrame::EditPaste() { EditorView *vw = GetActiveEditor(); if (vw) vw->Paste(); }
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(); if(IsFileExists(fileName) == false) { wxLogMessage(wxT("Failed to open: %s: No such file or directory"), fileName.GetFullPath().c_str()); 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); // If we're here from 'Swap Header/Implementation file', insert the new page next door #if !CL_USE_NATIVEBOOK size_t sel = m_book->GetVisibleEditorIndex(); #else size_t sel = (size_t)m_book->GetSelection(); #endif if ((extra & OF_PlaceNextToCurrent) && (sel != Notebook::npos)) { AddPage(editor, fileName.GetFullName(), wxNullBitmap, false, sel+1); } else { AddPage(editor, fileName.GetFullName()); } editor->SetSyntaxHighlight(); // mark the editor as read only if needed MarkEditorReadOnly(editor, IsFileReadOnly(editor->GetFileName())); // 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); } else if (lineno != wxNOT_FOUND) { editor->SetEnsureCaretIsVisible(editor->PositionFromLine(lineno), preserveSelection); } 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() ); wxArrayString files; m_recentFiles.GetFiles ( files ); EditorConfigST::Get()->SetRecentItems( files, wxT("RecentFiles") ); 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; }
void MainBook::ShowNavBar(bool s) { m_navBar->DoShow(s); UpdateNavBar(GetActiveEditor()); }
void ProjectFrame::EditUndo() { EditorView *vw = GetActiveEditor(); if (vw) vw->Undo(); }
void ProjectFrame::EditCut() { EditorView *vw = GetActiveEditor(); if (vw) vw->Cut(); }