From: Scott D. <sd...@ya...> - 2008-10-22 16:13:43
|
Eran, I think I've managed to address most of the concerns in your comment to this FR (except for altering stable code... :-) I'm including the entire revised patch here, because I don't have an easy way to do a patch of a patch. In addition, another tiny change is included because I had already completed it before remaking the patch. That one adds a couple of entries to the editor tab context menu, Show in Workspace, and Show in Explorer. They just call the appropriate-file-tree::ExpandToPath(editor-filename) method. I use it when I turn off Link to Editor. Scott Index: CodeLite/ctags_manager.cpp =================================================================== --- CodeLite/ctags_manager.cpp (revision 2304) +++ CodeLite/ctags_manager.cpp (working copy) @@ -349,13 +349,27 @@ TagTreePtr TagsManager::Load(const wxFileName& fileName) { + return Load(std::vector<wxFileName>(1, fileName)); +} + +TagTreePtr TagsManager::Load(const std::vector<wxFileName> &files) +{ + wxString sql = wxT("select * from tags "); + if (!files.empty()) { + sql << wxT("where file in ('") << files[0].GetFullPath() << wxT("'"); + for (size_t i = 1; i < files.size(); i++) { + sql << wxT(", '") << files[i].GetFullPath() << wxT("'"); + } + sql << wxT(") "); + } + // Make this call threadsafe wxCriticalSectionLocker locker(m_cs); // Incase empty file path is provided, use the current file name TagTreePtr tree; try { - wxSQLite3ResultSet rs = m_workspaceDatabase->SelectTagsByFile(fileName.GetFullPath()); + wxSQLite3ResultSet rs = m_workspaceDatabase->Query(sql); // Load the records and build a language tree TagEntry root; Index: CodeLite/ctags_manager.h =================================================================== --- CodeLite/ctags_manager.h (revision 2304) +++ CodeLite/ctags_manager.h (working copy) @@ -253,6 +253,14 @@ TagTreePtr Load(const wxFileName& fileName); /** + * load all symbols of fileNames from the database and return them + * to user as tree + * @param fileNames file sto load symbols from + * @return tag tree + */ + TagTreePtr Load(const std::vector<wxFileName>& fileNames); + + /** * Open sqlite database. * @param fileName Database file name */ Index: CodeLite/symbol_tree.cpp =================================================================== --- CodeLite/symbol_tree.cpp (revision 2304) +++ CodeLite/symbol_tree.cpp (working copy) @@ -23,6 +23,7 @@ ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// #include "precompiled_header.h" +#include <wx/settings.h> #ifdef __VISUALC__ #ifdef _DEBUG @@ -57,14 +58,17 @@ //-------------------------------------------------------- // Initialise the images map (kind:icon_index) //-------------------------------------------------------- - m_imagesMap[wxT("class_view")] = 14; + m_imagesMap[wxT("class_view")] = 18; + m_imagesMap[wxT("project")] = 0; m_imagesMap[wxT("namespace")] = 1; m_imagesMap[wxT("globals")] = 2; m_imagesMap[wxT("class")] = 3; + m_imagesMap[wxT("interface")] = 3; m_imagesMap[wxT("interface_private")] = 3; m_imagesMap[wxT("interface_protected")] = 3; + m_imagesMap[wxT("class_private")] = 3; m_imagesMap[wxT("class_public")] = 3; m_imagesMap[wxT("class_protected")] = 3; @@ -74,38 +78,44 @@ m_imagesMap[wxT("struct_public")] = 4; m_imagesMap[wxT("struct_protected")] = 4; - m_imagesMap[wxT("function")] = 5; m_imagesMap[wxT("prototype")] = 5; - m_imagesMap[wxT("function_public")] = 5; m_imagesMap[wxT("prototype_public")] = 5; - - m_imagesMap[wxT("function_protected")] = 6; m_imagesMap[wxT("prototype_protected")] = 6; - m_imagesMap[wxT("function_private")] = 7; m_imagesMap[wxT("prototype_private")] = 7; - m_imagesMap[wxT("variable")] = 8; - m_imagesMap[wxT("member")] = 8; - m_imagesMap[wxT("member_public")] = 8; - m_imagesMap[wxT("member_protected")] = 9; - m_imagesMap[wxT("member_private")] = 10; - m_imagesMap[wxT("typedef")] = 11; - m_imagesMap[wxT("typedef_public")] = 11; - m_imagesMap[wxT("typedef_private")] = 11; - m_imagesMap[wxT("typedef_protected")] = 11; - m_imagesMap[wxT("macro")] = 12; - m_imagesMap[wxT("macro_private")] = 12; - m_imagesMap[wxT("macro_protected")] = 12; - m_imagesMap[wxT("macro_public")] = 12; - m_imagesMap[wxT("enum")] = 13; - m_imagesMap[wxT("enum_private")] = 13; - m_imagesMap[wxT("enum_public")] = 13; - m_imagesMap[wxT("enum_protected")] = 13; - m_imagesMap[wxT("enumerator")] = 14; + + m_imagesMap[wxT("function")] = 8; + m_imagesMap[wxT("function_public")] = 8; + m_imagesMap[wxT("function_protected")] = 9; + m_imagesMap[wxT("function_private")] = 10; + + m_imagesMap[wxT("method")] = 8; + m_imagesMap[wxT("method_public")] = 8; + m_imagesMap[wxT("method_protected")] = 9; + m_imagesMap[wxT("method_private")] = 10; - m_imagesMap[wxT("method")] = 5; - m_imagesMap[wxT("method_public")] = 5; - m_imagesMap[wxT("method_protected")] = 6; - m_imagesMap[wxT("method_private")] = 7; + m_imagesMap[wxT("variable")] = 11; + + m_imagesMap[wxT("member")] = 11; + m_imagesMap[wxT("member_public")] = 11; + m_imagesMap[wxT("member_protected")] = 12; + m_imagesMap[wxT("member_private")] = 13; + + m_imagesMap[wxT("typedef")] = 14; + m_imagesMap[wxT("typedef_public")] = 14; + m_imagesMap[wxT("typedef_private")] = 14; + m_imagesMap[wxT("typedef_protected")] = 14; + + m_imagesMap[wxT("macro")] = 15; + m_imagesMap[wxT("macro_private")] = 15; + m_imagesMap[wxT("macro_protected")] = 15; + m_imagesMap[wxT("macro_public")] = 15; + + m_imagesMap[wxT("enum")] = 16; + m_imagesMap[wxT("enum_private")] = 16; + m_imagesMap[wxT("enum_public")] = 16; + m_imagesMap[wxT("enum_protected")] = 16; + + m_imagesMap[wxT("enumerator")] = 17; //----------------------------------------------------------- // Populate globals kind @@ -128,7 +138,7 @@ BuildTree( wxFileName() ); } -void SymbolTree::BuildTree(const wxFileName &fileName) +void SymbolTree::BuildTree(const wxFileName &treeFileName, const std::vector<wxFileName> &tagFileNames) { // Clear the tree DeleteAllItems(); @@ -138,16 +148,19 @@ m_macrosNode = wxTreeItemId(); m_sortItems.clear(); - m_fileName = fileName; + if (!treeFileName.IsOk()) { + // if name is empty, leave tree completely empty (it will be filled in later) + return; + } + + m_fileName = treeFileName; // Get the current tree - m_tree = TagsManagerST::Get()->Load(m_fileName); + m_tree = TagsManagerST::Get()->Load(tagFileNames); if ( !m_tree ) { return; } - // Add invisible root node - wxTreeItemId root; - root = AddRoot(fileName.GetFullName(), 15, 15); + wxTreeItemId root = AddRoot(treeFileName.GetFullName(), 18, 18); TreeWalker<wxString, TagEntry> walker(m_tree->GetRoot()); @@ -174,6 +187,7 @@ } SortTree(m_sortItems); + Expand(root); Thaw(); //select the root node by default @@ -190,6 +204,7 @@ int iconIndex = GetItemIconIndex(nodeData.GetKind(), nodeData.GetAccess()); wxString displayName(nodeData.GetDisplayName()); + displayName.Replace(wxT(": [prototype]"), wxT("")); wxTreeItemId parentHti; if (nodeData.GetName().IsEmpty()) @@ -221,12 +236,19 @@ parentHti = GetRootItem(); } + // put prototypes in italic so they stand out from definitions + wxFont prototypeFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + prototypeFont.SetStyle(wxFONTSTYLE_ITALIC); + if (parentHti.IsOk()) { hti = AppendItem(parentHti, // parent displayName, // display name iconIndex, // item image index iconIndex, // selected item image new MyTreeItemData(node->GetData().GetFile(), node->GetData().GetPattern())); + if (nodeData.GetKind() == wxT("prototype")) { + SetItemFont(hti, prototypeFont); + } node->GetData().SetTreeItemId( hti ); m_sortItems[parentHti.m_pItem] = true; m_items[nodeData.Key()] = hti.m_pItem; Index: CodeLite/symbol_tree.h =================================================================== --- CodeLite/symbol_tree.h (revision 2304) +++ CodeLite/symbol_tree.h (working copy) @@ -114,12 +114,21 @@ * \param size Window size * \param style Window style */ - virtual void Create(wxWindow *parent, const wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTR_HIDE_ROOT | wxTR_HAS_BUTTONS); + virtual void Create(wxWindow *parent, const wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTR_HAS_BUTTONS); /** - * Construct a outline tree for fileName + * Construct an outline tree for a group of filenames. + * \param treeFileName the name of this tree (file, project, or workspace) + * \param tagFileNames the files whose tags are loaded into this tree */ - void BuildTree(const wxFileName &fileName); + void BuildTree(const wxFileName &treeFileName, const std::vector<wxFileName> &tagFileNames); + + /** + * Construct an outline tree for a single source file. + * \param fileName the name of the file to load + */ + void BuildTree(const wxFileName &fileName) + { BuildTree(fileName, std::vector<wxFileName>(1, fileName)); } /** * User provided icons for the symbols tree. Index: LiteEditor/cpp_symbol_tree.cpp =================================================================== --- LiteEditor/cpp_symbol_tree.cpp (revision 2304) +++ LiteEditor/cpp_symbol_tree.cpp (working copy) @@ -48,33 +48,40 @@ images->Add(wxXmlResource::Get()->LoadBitmap(_T("globals"))); // 2 images->Add(wxXmlResource::Get()->LoadBitmap(_T("class"))); // 3 images->Add(wxXmlResource::Get()->LoadBitmap(_T("struct"))); // 4 - images->Add(wxXmlResource::Get()->LoadBitmap(_T("func_public"))); // 5 + + // load bitmaps for function prototypes + images->Add(wxXmlResource::Get()->LoadBitmap(_T("func_public"))); // 5 images->Add(wxXmlResource::Get()->LoadBitmap(_T("func_protected"))); // 6 images->Add(wxXmlResource::Get()->LoadBitmap(_T("func_private"))); // 7 - images->Add(wxXmlResource::Get()->LoadBitmap(_T("member_public"))); // 8 - images->Add(wxXmlResource::Get()->LoadBitmap(_T("member_protected")));// 9 - images->Add(wxXmlResource::Get()->LoadBitmap(_T("member_private"))); // 10 + // load them again for function/method definitions + images->Add(wxXmlResource::Get()->LoadBitmap(_T("func_public"))); // 8 + images->Add(wxXmlResource::Get()->LoadBitmap(_T("func_protected"))); // 9 + images->Add(wxXmlResource::Get()->LoadBitmap(_T("func_private"))); // 10 + + images->Add(wxXmlResource::Get()->LoadBitmap(_T("member_public"))); // 11 + images->Add(wxXmlResource::Get()->LoadBitmap(_T("member_protected")));// 12 + images->Add(wxXmlResource::Get()->LoadBitmap(_T("member_private"))); // 13 wxBitmap bmp; // typedef - bmp = wxXmlResource::Get()->LoadBitmap(_T("typedef")); // 11 + bmp = wxXmlResource::Get()->LoadBitmap(_T("typedef")); // 14 bmp.SetMask(new wxMask(bmp, wxColor(0, 128, 128))); images->Add(bmp); // macro (same icon as typedef) - bmp = wxXmlResource::Get()->LoadBitmap(_T("typedef")); // 12 + bmp = wxXmlResource::Get()->LoadBitmap(_T("typedef")); // 15 bmp.SetMask(new wxMask(bmp, wxColor(0, 128, 128))); images->Add(bmp); - bmp = wxXmlResource::Get()->LoadBitmap(_T("enum")); // 13 + bmp = wxXmlResource::Get()->LoadBitmap(_T("enum")); // 16 bmp.SetMask(new wxMask(bmp, wxColor(0, 128, 128))); images->Add(bmp); - bmp = wxXmlResource::Get()->LoadBitmap(wxT("enumerator")); //14 + bmp = wxXmlResource::Get()->LoadBitmap(wxT("enumerator")); //17 images->Add(bmp); - bmp = wxXmlResource::Get()->LoadBitmap(wxT("class_view")); //15 + bmp = wxXmlResource::Get()->LoadBitmap(wxT("class_view")); //18 images->Add(bmp); return images; } @@ -165,6 +172,7 @@ e.SetEventObject(this); wxPostEvent(GetEventHandler(), e); } + return true; } Index: LiteEditor/cpp_symbol_tree.h =================================================================== --- LiteEditor/cpp_symbol_tree.h (revision 2304) +++ LiteEditor/cpp_symbol_tree.h (working copy) @@ -40,7 +40,7 @@ CppSymbolTree(); /// Nothing special here, just call our parent constructor - CppSymbolTree(wxWindow *parent, const wxWindowID id, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxTR_HIDE_ROOT | wxTR_HAS_BUTTONS); + CppSymbolTree(wxWindow *parent, const wxWindowID id, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxTR_HAS_BUTTONS); /// destructor Index: LiteEditor/fileexplorer.cpp =================================================================== --- LiteEditor/fileexplorer.cpp (revision 2304) +++ LiteEditor/fileexplorer.cpp (working copy) @@ -25,6 +25,7 @@ #include "wx/xrc/xmlres.h" #include "fileexplorer.h" #include "fileexplorertree.h" +#include "frame.h" #include "wx/sizer.h" #include "wx/tokenzr.h" @@ -192,4 +193,8 @@ m_isLinkedToEditor = !m_isLinkedToEditor; // save the value EditorConfigST::Get()->SaveLongValue(wxT("LinkFileExplorerToEditor"), m_isLinkedToEditor ? 1 : 0); + if (m_isLinkedToEditor) { + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, XRCID("show_in_explorer")); + Frame::Get()->AddPendingEvent(event); + } } Index: LiteEditor/frame.cpp =================================================================== --- LiteEditor/frame.cpp (revision 2304) +++ LiteEditor/frame.cpp (working copy) @@ -107,6 +107,7 @@ #include "globals.h" #include "workspacetab.h" #include "fileexplorer.h" +#include "symbolview.h" #include "custom_notebook.h" #ifdef __WXGTK20__ @@ -164,6 +165,10 @@ EVT_MENU(XRCID("close_other_tabs"), Frame::OnCloseAllButThis) EVT_MENU(XRCID("copy_file_name"), Frame::OnCopyFilePath) EVT_MENU(XRCID("copy_file_path"), Frame::OnCopyFilePathOnly) + EVT_MENU(XRCID("show_in_workspace"), Frame::OnShowInWorkspace) + EVT_UPDATE_UI(XRCID("show_in_workspace"), Frame::OnShowInWorkspaceUI) + EVT_MENU(XRCID("show_in_explorer"), Frame::OnShowInExplorer) + EVT_UPDATE_UI(XRCID("show_in_explorer"), Frame::OnShowInExplorerUI) EVT_MENU(XRCID("open_shell_from_filepath"), Frame::OnOpenShellFromFilePath) EVT_UPDATE_UI(XRCID("open_shell_from_filepath"), Frame::OnFileExistUpdateUI) @@ -1366,12 +1371,7 @@ ClosePage(editor, true, event.GetSelection(), false, veto); if ( veto ) { event.Veto(); - } else { - //update the symbol view - if (!editor->GetProject().IsEmpty()) { - GetWorkspacePane()->DeleteSymbolTree(editor->GetFileName()); - } - } + } //update the titlebar SetFrameTitle(NULL); @@ -1395,7 +1395,7 @@ //update the symbol view as well in case we are in a workspace context if (!editor->GetProject().IsEmpty()) { - GetWorkspacePane()->DisplaySymbolTree(editor->GetFileName()); + GetSymbolView()->DisplaySymbolTree(editor->GetFileName()); if (GetWorkspaceTab()->GetIsLinkedToEditor()) { GetWorkspacePane()->GetFileViewTree()->ExpandToPath(editor->GetProject(), editor->GetFileName()); } @@ -1433,9 +1433,12 @@ //clean the navigation bar GetMainBook()->Clear(); - // if no more editors are available, collapse the workspace tree - if (GetWorkspaceTab()->GetIsLinkedToEditor() && GetMainBook()->GetNotebook()->GetPageCount() == 0) { - GetWorkspacePane()->CollpaseAll(); + if (GetMainBook()->GetNotebook()->GetPageCount() == 0) { + // no more editors are left + if (GetWorkspaceTab()->GetIsLinkedToEditor()) { + // collapse the workspace tree + GetWorkspacePane()->CollpaseAll(); + } } } @@ -1475,7 +1478,6 @@ return; } else { if ( doDelete ) { - GetWorkspacePane()->DeleteSymbolTree(editor->GetFileName()); GetNotebook()->DeletePage(index, notify); } } @@ -1487,7 +1489,6 @@ case wxNO: // just delete the tab without saving the changes if ( doDelete ) { - GetWorkspacePane()->DeleteSymbolTree(editor->GetFileName()); GetNotebook()->DeletePage(index, notify); } break; @@ -1495,10 +1496,11 @@ } else { // file is not modified, just remove the tab if ( doDelete ) { - GetWorkspacePane()->DeleteSymbolTree(editor->GetFileName()); GetNotebook()->DeletePage(index, notify); } // if( doDelete ) } + if (!editor->GetProject().IsEmpty()) + GetSymbolView()->DeleteSymbolTree(editor->GetFileName()); } void Frame::OnSearchThread(wxCommandEvent &event) @@ -2331,27 +2333,17 @@ void Frame::OnAddSymbols(SymbolTreeEvent &event) { - SymbolTree *tree = GetWorkspacePane()->GetSymbolTree(event.GetFileName()); - if (tree) { - tree->AddSymbols(event); - } + GetSymbolView()->OnAddSymbols(event); } void Frame::OnDeleteSymbols(SymbolTreeEvent &event) { - // make sure we direct the events to the correct tree - SymbolTree *tree = GetWorkspacePane()->GetSymbolTree(event.GetFileName()); - if (tree) { - tree->DeleteSymbols(event); - } + GetSymbolView()->OnDeleteSymbols(event); } void Frame::OnUpdateSymbols(SymbolTreeEvent &event) { - SymbolTree *tree = GetWorkspacePane()->GetSymbolTree(event.GetFileName()); - if (tree) { - tree->UpdateSymbols(event); - } + GetSymbolView()->OnUpdateSymbols(event); } wxString Frame::CreateWorkspaceTable() @@ -3021,6 +3013,11 @@ return GetWorkspacePane()->GetFileExplorer(); } +SymbolView *Frame::GetSymbolView() +{ + return GetWorkspacePane()->GetSymbolView(); +} + void Frame::OnLoadWelcomePage(wxCommandEvent &event) { SetFrameFlag(event.IsChecked(), CL_SHOW_WELCOME_PAGE); @@ -3703,3 +3700,54 @@ wxUnusedVar( event ); ManagerST::Get()->RetagWorkspace(); } + +void Frame::OnShowInExplorer(wxCommandEvent& e) +{ + LEditor *editor = ManagerST::Get()->GetActiveEditor(); + if (editor) { + wxFileName filepath = editor->GetFileName(); + if (filepath.FileExists()) { + GetFileExplorer()->GetFileTree()->ExpandToPath(filepath); + ManagerST::Get()->ShowWorkspacePane(WorkspacePane::EXPLORER); + } + } +} + +void Frame::OnShowInExplorerUI(wxUpdateUIEvent& e) +{ + e.Enable(false); + LEditor *editor = ManagerST::Get()->GetActiveEditor(); + if (editor) { + wxFileName filepath = editor->GetFileName(); + if (filepath.FileExists()) { + e.Enable(true); + } + } +} + +void Frame::OnShowInWorkspace(wxCommandEvent& e) +{ + LEditor *editor = ManagerST::Get()->GetActiveEditor(); + if (editor) { + wxString project = editor->GetProject(); + wxFileName filepath = editor->GetFileName(); + if (!project.IsEmpty()) { + GetWorkspaceTab()->GetFileView()->ExpandToPath(project, filepath); + ManagerST::Get()->ShowWorkspacePane(WorkspacePane::FILE_VIEW); + } + } +} + +void Frame::OnShowInWorkspaceUI(wxUpdateUIEvent& e) +{ + e.Enable(false); + LEditor *editor = ManagerST::Get()->GetActiveEditor(); + if (editor) { + wxString project = editor->GetProject(); + wxFileName filepath = editor->GetFileName(); + if (!project.IsEmpty()) { + e.Enable(true); + } + } +} + Index: LiteEditor/frame.h =================================================================== --- LiteEditor/frame.h (revision 2304) +++ LiteEditor/frame.h (working copy) @@ -51,6 +51,7 @@ class WorkspacePane; class wxToolBar; class Notebook; +class SymbolView; class OpenWindowsPanel; class WorkspaceTab; class FileExplorer; @@ -184,6 +185,11 @@ */ OpenWindowsPanel *GetOpenWindowsPane(); + /** + * return the symbol view pane + */ + SymbolView *GetSymbolView(); + /** * \return return AUI docking manager */ @@ -374,6 +380,10 @@ void OnHighlightWord(wxCommandEvent &event); void OnShowNavBar(wxCommandEvent &e); void OnShowNavBarUI(wxUpdateUIEvent &e); + void OnShowInWorkspace(wxCommandEvent &e); + void OnShowInWorkspaceUI(wxUpdateUIEvent &e); + void OnShowInExplorer(wxCommandEvent &e); + void OnShowInExplorerUI(wxUpdateUIEvent &e); void OnOpenShellFromFilePath(wxCommandEvent &e); void OnQuickDebug(wxCommandEvent &e); void OnQuickDebugUI(wxUpdateUIEvent &e); Index: LiteEditor/LiteEditor.project =================================================================== --- LiteEditor/LiteEditor.project (revision 2304) +++ LiteEditor/LiteEditor.project (working copy) @@ -355,6 +355,8 @@ <File Name="taskbasepanel.cpp"/> <File Name="taskbasepanel.h"/> <File Name="taskpanel.cpp"/> + <File Name="symbolview.cpp"/> + <File Name="symbolview.h"/> </VirtualDirectory> <VirtualDirectory Name="Plugins"> <File Name="pluginmanager.h"/> Index: LiteEditor/manager.cpp =================================================================== --- LiteEditor/manager.cpp (revision 2304) +++ LiteEditor/manager.cpp (working copy) @@ -86,6 +86,7 @@ #include "custom_notebook.h" #include "sessionmanager.h" #include "workspacetab.h" +#include "symbolview.h" #include <vector> extern unsigned int UTF8Length(const wchar_t *uptr, unsigned int tlen); @@ -199,14 +200,7 @@ bool Manager::OpenFile(const wxString &file_name, const wxString &projectName, int lineno, long position) { - wxFileName fileName(file_name); - wxString projName(projectName); - Notebook *notebook = Frame::Get()->GetNotebook(); - bool updTree = false; - bool fileWasOpenedInNB(false); - int selection(wxNOT_FOUND); wxWindow *returnFocusWin(NULL); - wxWindow *focusWin = wxWindow::FindFocus(); if (focusWin == Frame::Get()->GetOutputPane()->GetDebugWindow()->GetInWin()) { returnFocusWin = focusWin; @@ -219,19 +213,21 @@ Frame::Get()->GetDockingManager().Update(); } - // Search to see if this file is already opened - // in the notebook + wxFileName fileName(file_name); + Notebook *notebook = Frame::Get()->GetNotebook(); + + // Search to see if this file is already opened in the notebook LEditor* editor = NULL; - size_t nCount = 0; - for (; nCount < (size_t)notebook ->GetPageCount(); nCount++) { + int selection(wxNOT_FOUND); + for (size_t nCount = 0; nCount < (size_t)notebook ->GetPageCount(); nCount++) { editor = dynamic_cast<LEditor*>(notebook ->GetPage(nCount)); if ( editor ) { wxString f1 = editor->GetFileName().GetFullPath(); wxString f2 = fileName.GetFullPath(); if (f1 == f2) { - notebook->SetSelection( nCount ); + //notebook->SetSelection( nCount ); selection = (int)nCount; - fileWasOpenedInNB = true; + //fileWasOpenedInNB = true; break; } editor = NULL; @@ -241,6 +237,7 @@ //even in cases were a project name is empty, we try //to match a project name to the actual file. otherwise, CC may not work //since it depends on a valid project name in the editor + wxString projName(projectName); if (projectName.IsEmpty()) { projName = GetProjectNameByFile(fileName.GetFullPath()); } @@ -260,55 +257,32 @@ // Create new editor and add it to the notebook notebook->Freeze(); - // create new instance from pool editor = EditorCreatorST::Get()->NewInstance(); editor->Create(projName, fileName); editor->SetSyntaxHighlight(editor->GetContext()->GetName()); - notebook->AddPage(editor, fileName.GetFullName(), wxNullBitmap, true); + notebook->AddPage(editor, fileName.GetFullName(), wxNullBitmap, false); notebook->Thaw(); selection = (int)notebook->GetPageCount()-1; - updTree = true; } + editor->SetProject( projName ); + // Go to tag line number and gives scintilla the focus if ( position != wxNOT_FOUND ) { - int lineno = editor->LineFromPosition(position); - editor->GotoLine( lineno ); editor->SetCaretAt( position ); - editor->EnsureVisible(lineno); - } else { - if (!(fileWasOpenedInNB && lineno == wxNOT_FOUND)) { - editor->GotoLine( lineno ); - editor->EnsureVisible(lineno); - } + } else if (lineno != wxNOT_FOUND) { + editor->GotoLine( lineno ); } + editor->EnsureCaretVisible(); - //update the symbol tree - if (updTree && !editor->GetProject().IsEmpty()) - Frame::Get()->GetWorkspacePane()->BuildSymbolTree(fileName); + notebook->SetSelection(selection); + //update the open files list + Frame::Get()->GetOpenWindowsPane()->UpdateList(); + //update the 'Recent file' history AddToRecentlyOpenedFiles(fileName.GetFullPath()); - if (selection != wxNOT_FOUND) { - notebook->SetSelection(selection); - } - - editor->SetProject( projName ); - - //Synchronize the file view tree - if (IsWorkspaceOpen() && Frame::Get()->GetWorkspacePane()->GetWorkspaceTab()->GetIsLinkedToEditor()) { - Frame::Get()->GetWorkspacePane()->GetFileViewTree()->ExpandToPath(editor->GetProject(), editor->GetFileName()); - } - - if (Frame::Get()->GetFileExplorer()->GetIsLinkedToEditor()) { - Frame::Get()->GetFileExplorer()->GetFileTree()->ExpandToPath(editor->GetFileName()); - } - - //update the open files list - Frame::Get()->GetOpenWindowsPane()->UpdateList(); - editor->SetActive(); - if (returnFocusWin) { returnFocusWin->SetFocus(); } @@ -525,6 +499,7 @@ } } + Frame::Get()->GetSymbolView()->DeleteAllSymbolTrees(); Frame::Get()->GetNotebook()->Refresh(); Frame::Get()->GetWorkspacePane()->BuildFileTree(); @@ -613,6 +588,9 @@ RetagProject(projectName); RebuildFileView(); + Frame::Get()->GetSymbolView()->RefreshSymbolTree(fn); + Frame::Get()->GetSymbolView()->RefreshSymbolTree(WorkspaceST::Get()->GetWorkspaceFileName()); + //notify plugins SendCmdEvent(wxEVT_PROJ_ADDED, (void*)&projectName); } @@ -642,6 +620,8 @@ proj->GetFiles(projectFiles, true); TagsManagerST::Get()->DeleteFilesTags(projectFiles); RemoveProjectNameFromOpenFiles(projectFiles); + Frame::Get()->GetSymbolView()->DeleteSymbolTree(proj->GetFileName()); + Frame::Get()->GetSymbolView()->RefreshSymbolTree(WorkspaceST::Get()->GetWorkspaceFileName()); } // if(proj) Frame::Get()->GetWorkspacePane()->GetFileViewTree()->BuildTree(); @@ -665,6 +645,7 @@ for (size_t j=0; j<project_files.size(); j++) { if (openFileFP == project_files.at(j).GetFullPath()) { editor->SetProject(wxEmptyString); + Frame::Get()->GetSymbolView()->DeleteSymbolTree(project_files.at(j)); break; } } @@ -712,6 +693,9 @@ bool res = WorkspaceST::Get()->RemoveVirtualDirectory(virtualDirFullPath, errMsg); CHECK_MSGBOX(res); + Frame::Get()->GetSymbolView()->RefreshSymbolTree(p->GetFileName()); + Frame::Get()->GetSymbolView()->RefreshSymbolTree(WorkspaceST::Get()->GetWorkspaceFileName()); + SendCmdEvent(wxEVT_PROJ_FILE_REMOVED, (void*)&files); } @@ -746,10 +730,6 @@ return false; } - if ( openIt ) { - OpenFile(fileName, project); - } - TagTreePtr ttp; if ( project.IsEmpty() == false ) { std::vector<DbRecordPtr> comments; @@ -762,6 +742,16 @@ TagsManagerST::Get()->Store(ttp); } + ProjectPtr proj = GetProject(project); + if (proj) { + Frame::Get()->GetSymbolView()->RefreshSymbolTree(proj->GetFileName()); + } + Frame::Get()->GetSymbolView()->RefreshSymbolTree(WorkspaceST::Get()->GetWorkspaceFileName()); + + if ( openIt ) { + OpenFile(fileName, project); + } + //send notification command event that files was added to //project wxArrayString files; @@ -805,6 +795,12 @@ TagsManagerST::Get()->RetagFiles(vFiles); } + ProjectPtr proj = GetProject(project); + if (proj) { + Frame::Get()->GetSymbolView()->RefreshSymbolTree(proj->GetFileName()); + } + Frame::Get()->GetSymbolView()->RefreshSymbolTree(WorkspaceST::Get()->GetWorkspaceFileName()); + SendCmdEvent(wxEVT_PROJ_FILE_ADDED, (void*)&actualAdded); } @@ -838,6 +834,12 @@ CHECK_MSGBOX_BOOL(res); RemoveFileFromSymbolTree(absPath, project); + ProjectPtr proj = GetProject(project); + if (proj) { + Frame::Get()->GetSymbolView()->RefreshSymbolTree(proj->GetFileName()); + } + Frame::Get()->GetSymbolView()->RefreshSymbolTree(WorkspaceST::Get()->GetWorkspaceFileName()); + return true; } @@ -1425,6 +1427,8 @@ //call tags manager for re-tagging TagsManagerST::Get()->RetagFiles(projectFiles); + Frame::Get()->GetSymbolView()->RefreshSymbolTree(proj->GetFileName()); + Frame::Get()->GetSymbolView()->RefreshSymbolTree(WorkspaceST::Get()->GetWorkspaceFileName()); } } @@ -1447,6 +1451,13 @@ } //call tags manager for re-tagging TagsManagerST::Get()->RetagFiles(projectFiles); + for (size_t i = 0; i < projects.GetCount(); i++) { + ProjectPtr proj = GetProject(projects.Item(i)); + if (proj) { + Frame::Get()->GetSymbolView()->RefreshSymbolTree(proj->GetFileName()); + } + } + Frame::Get()->GetSymbolView()->RefreshSymbolTree(WorkspaceST::Get()->GetWorkspaceFileName()); } void Manager::WriteProgram(const wxString &line) @@ -1713,8 +1724,7 @@ dlg->Destroy(); } - //remove all symbol trees from the outline view - Frame::Get()->GetWorkspacePane()->DeleteAllSymbolTrees(); + Frame::Get()->GetSymbolView()->DisplaySymbolTree(); } bool Manager::MoveFileToVD(const wxString &fileName, const wxString &srcVD, const wxString &targetVD) @@ -3139,6 +3149,7 @@ } } + Frame::Get()->GetSymbolView()->RefreshSymbolTree(path); SendCmdEvent(wxEVT_WORKSPACE_LOADED); } Index: LiteEditor/symbolview.cpp =================================================================== --- LiteEditor/symbolview.cpp (revision 0) +++ LiteEditor/symbolview.cpp (revision 0) @@ -0,0 +1,352 @@ +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// +// +// copyright : (C) 2008 by Eran Ifrah +// file name : symbolview.h +// +// ------------------------------------------------------------------------- +// A +// _____ _ _ _ _ +// / __ \ | | | | (_) | +// | / \/ ___ __| | ___| | _| |_ ___ +// | | / _ \ / _ |/ _ \ | | | __/ _ ) +// | \__/\ (_) | (_| | __/ |___| | || __/ +// \____/\___/ \__,_|\___\_____/_|\__\___| +// +// F i l e +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// +#include <wx/xrc/xmlres.h> +#include <wx/sizer.h> +#include "macros.h" +#include "frame.h" +#include "manager.h" +#include "ctags_manager.h" +#include "editor_config.h" +#include "cpp_symbol_tree.h" +#include "symbolview.h" +#include "parse_thread.h" +#include "windowstack.h" + +extern wxImageList* CreateSymbolTreeImages(); + + +static wxArrayString s_viewModeNames; + + +SymbolView::SymbolView(wxWindow *parent) + : wxPanel(parent) + , m_viewMode(0) + , m_winStack(NULL) + , m_isLinkedToEditor(false) +{ + long link(0); + EditorConfigST::Get()->GetLongValue(wxT("LinkSymbolViewToEditor"), link); + m_isLinkedToEditor = link ? true : false; + s_viewModeNames.Add(wxT("Current File")); + s_viewModeNames.Add(wxT("Current Project")); + s_viewModeNames.Add(wxT("Current Workspace")); + CreateGUIControls(); +} + +SymbolView::~SymbolView() +{ +} + +BEGIN_EVENT_TABLE(SymbolView, wxPanel) + EVT_MENU(XRCID("link_editor"), SymbolView::OnLinkEditor) + EVT_MENU(XRCID("collapse_all"), SymbolView::OnCollapseAll) + EVT_UPDATE_UI(XRCID("collapse_all"), SymbolView::OnCollapseAllUI) + EVT_MENU(XRCID("gohome"), SymbolView::OnGoHome) + EVT_UPDATE_UI(XRCID("gohome"), SymbolView::OnGoHomeUI) + EVT_UPDATE_UI(wxID_ANY, SymbolView::OnUpdateUI) +END_EVENT_TABLE() + +void SymbolView::CreateGUIControls() +{ + wxBoxSizer *sz = new wxBoxSizer(wxVERTICAL); + SetSizer(sz); + + m_viewChoice = new wxChoice(this, wxID_ANY); + m_viewChoice->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(SymbolView::OnViewModeMouseDown), NULL, this); + ConnectChoice(m_viewChoice, SymbolView::OnViewTypeChanged); + m_viewChoice->Append(s_viewModeNames[m_viewMode]); + m_viewChoice->Select(m_viewMode); + sz->Add(m_viewChoice, 0, wxEXPAND|wxALL, 1); + + m_winStack = new WindowStack(this); + sz->Add(m_winStack, 1, wxEXPAND|wxALL, 1); + + wxToolBar *tb = new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_FLAT|wxTB_HORIZONTAL); + tb->AddTool(XRCID("link_editor"), wxEmptyString, wxXmlResource::Get()->LoadBitmap(wxT("link_editor")), wxT("Link Editor"), wxITEM_CHECK); + tb->ToggleTool(XRCID("link_editor"), m_isLinkedToEditor); + tb->AddTool(XRCID("collapse_all"), wxEmptyString, wxXmlResource::Get()->LoadBitmap(wxT("collapse")), wxT("Collapse All"), wxITEM_NORMAL); + tb->AddTool(XRCID("gohome"), wxEmptyString, wxXmlResource::Get()->LoadBitmap(wxT("gohome")), wxEmptyString, wxITEM_NORMAL); + tb->Realize(); + sz->Add(tb, 0, wxEXPAND); + + sz->Layout(); +} + +void SymbolView::OnViewModeMouseDown(wxMouseEvent &event) +{ + if (ManagerST::Get()->IsWorkspaceOpen()) { + m_viewChoice->Freeze(); + m_viewChoice->Clear(); + m_viewChoice->Append(s_viewModeNames); + m_viewChoice->Select(m_viewMode); + m_viewChoice->Thaw(); + } + event.Skip(); +} + +void SymbolView::OnViewTypeChanged(wxCommandEvent &event) +{ + if (m_viewMode != event.GetSelection()) { + m_viewMode = event.GetSelection(); + DisplaySymbolTree(); + } + event.Skip(); +} + +SymbolTree *SymbolView::GetSymbolTree(const wxString &fileName) +{ + return dynamic_cast<CppSymbolTree*>(m_winStack->Find(fileName)); +} + +wxString SymbolView::GetSelected() +{ + SymbolTree *tree = dynamic_cast<CppSymbolTree*>(m_winStack->GetSelected()); + return tree ? tree->GetFilename().GetFullPath() : wxString(); +} + +void SymbolView::DisplaySymbolTree(const wxFileName &file_name, bool immediate) +{ + if (!ManagerST::Get()->IsWorkspaceOpen()) { + m_winStack->SelectNone(); + return; + } + + wxFileName fileName = file_name; + if (!fileName.IsOk()) { + // no name was given, so try to pick a reasonable default + LEditor *editor = ManagerST::Get()->GetActiveEditor(); + wxString project = ManagerST::Get()->GetActiveProjectName(); + wxString dummy; + + if (editor && editor->GetFileName().IsOk() && !editor->GetProject().IsEmpty()) + fileName = editor->GetFileName(); + else if (!project.IsEmpty()) + fileName = WorkspaceST::Get()->FindProjectByName(project, dummy)->GetFileName(); + else + fileName = WorkspaceST::Get()->GetWorkspaceFileName(); + } + + // now enforce user's view mode selection + if (m_viewMode == 2) { + // substitute workspace path + fileName = WorkspaceST::Get()->GetWorkspaceFileName(); + } else if (m_viewMode == 1) { + if (fileName == WorkspaceST::Get()->GetWorkspaceFileName()) { + m_winStack->SelectNone(); + return; + } + wxString projName = ManagerST::Get()->GetProjectNameByFile(fileName.GetFullPath()); + ProjectPtr project = !projName.IsEmpty() ? ManagerST::Get()->GetProject(projName) : ProjectPtr(); + if (project) { + // replace file path with file's project + fileName = project->GetFileName(); + } + } else { + if (!TagsManagerST::Get()->IsValidCtagsFile(fileName)) { + m_winStack->SelectNone(); + return; + } + } + + // get the symbol tree for the specified path (make if necessary) + SymbolTree *tree = GetSymbolTree(fileName.GetFullPath()); + if (tree == NULL) { + tree = new CppSymbolTree(m_winStack, wxID_ANY); + tree->SetSymbolsImages(CreateSymbolTreeImages()); + m_winStack->Add(tree, fileName.GetFullPath()); + } + + Freeze(); + + if (tree->IsEmpty() && (immediate || IsShown())) { + // tree neds to be built, so choose files to load tags from + std::vector<wxFileName> filesToLoad; + if (fileName == WorkspaceST::Get()->GetWorkspaceFileName()) { + // leave filesToLoad empty, which actually will load all files in WS + } else { + ProjectPtr project = ManagerST::Get()->GetProject(fileName.GetName()); + if (project && project->GetFileName() == fileName) { + // get all files in the project + project->GetFiles(filesToLoad, true); + } else if (TagsManagerST::Get()->IsValidCtagsFile(fileName)) { + // just use this file itself + filesToLoad.push_back(fileName); + } else { + Thaw(); + return; // invalid filename + } + } + tree->BuildTree(fileName, filesToLoad); + } else if (m_winStack->GetSelectedKey() == fileName.GetFullPath()) { + // this tree is already visible + Thaw(); + return; + } + + m_winStack->Select(fileName.GetFullPath()); + m_viewChoice->Clear(); + m_viewChoice->Append(s_viewModeNames[m_viewMode]); + m_viewChoice->Select(0); + + Thaw(); +} + +void SymbolView::DeleteSymbolTree(const wxFileName &filename) +{ + m_winStack->Delete(filename.GetFullPath()); +} + +void SymbolView::DeleteAllSymbolTrees() +{ + m_winStack->Clear(); +} + +void SymbolView::RefreshSymbolTree(const wxFileName& filename) +{ + Freeze(); + DeleteSymbolTree(filename); + DisplaySymbolTree(filename); + Thaw(); +} + +void SymbolView::OnAddSymbols(SymbolTreeEvent &event) +{ + wxString path = event.GetFileName(); + SymbolTree *tree = GetSymbolTree(path); + if (tree && !tree->IsEmpty()) { + tree->AddSymbols(event); + } + + wxString projectName = ManagerST::Get()->GetProjectNameByFile(path); + if (!projectName.IsEmpty()) { + ProjectPtr project = ManagerST::Get()->GetProject(projectName); + path = project->GetFileName().GetFullPath(); + tree = GetSymbolTree(path); + if (tree && !tree->IsEmpty()) { + tree->AddSymbols(event); + } + } + + path = WorkspaceST::Get()->GetWorkspaceFileName().GetFullPath(); + tree = GetSymbolTree(path); + if (tree && !tree->IsEmpty()) { + tree->AddSymbols(event); + } +} + +void SymbolView::OnDeleteSymbols(SymbolTreeEvent &event) +{ + wxString path = event.GetFileName(); + SymbolTree *tree = GetSymbolTree(path); + if (tree && !tree->IsEmpty()) { + tree->DeleteSymbols(event); + } + + wxString projectName = ManagerST::Get()->GetProjectNameByFile(path); + if (!projectName.IsEmpty()) { + ProjectPtr project = ManagerST::Get()->GetProject(projectName); + path = project->GetFileName().GetFullPath(); + tree = GetSymbolTree(path); + if (tree && !tree->IsEmpty()) { + tree->DeleteSymbols(event); + } + } + + path = WorkspaceST::Get()->GetWorkspaceFileName().GetFullPath(); + tree = GetSymbolTree(path); + if (tree && !tree->IsEmpty()) { + tree->DeleteSymbols(event); + } +} + +void SymbolView::OnUpdateSymbols(SymbolTreeEvent &event) +{ + wxString path = event.GetFileName(); + SymbolTree *tree = GetSymbolTree(path); + if (tree && !tree->IsEmpty()) { + tree->UpdateSymbols(event); + } + + wxString projectName = ManagerST::Get()->GetProjectNameByFile(path); + if (!projectName.IsEmpty()) { + ProjectPtr project = ManagerST::Get()->GetProject(projectName); + path = project->GetFileName().GetFullPath(); + tree = GetSymbolTree(path); + if (tree && !tree->IsEmpty()) { + tree->UpdateSymbols(event); + } + } + + path = WorkspaceST::Get()->GetWorkspaceFileName().GetFullPath(); + tree = GetSymbolTree(path); + if (tree && !tree->IsEmpty()) { + tree->UpdateSymbols(event); + } +} + +void SymbolView::OnLinkEditor(wxCommandEvent &e) +{ + wxUnusedVar(e); + m_isLinkedToEditor = !m_isLinkedToEditor; + // save the value + EditorConfigST::Get()->SaveLongValue(wxT("LinkSymbolViewToEditor"), m_isLinkedToEditor ? 1 : 0); +} + +void SymbolView::OnCollapseAll(wxCommandEvent& event) +{ + SymbolTree *tree = dynamic_cast<SymbolTree*>(m_winStack->GetSelected()); + if (tree && !tree->IsEmpty()) { + tree->Freeze(); + tree->CollapseAll(); + tree->Expand(tree->GetRootItem()); + tree->Thaw(); + } +} + +void SymbolView::OnCollapseAllUI(wxUpdateUIEvent& event) +{ + SymbolTree *tree = dynamic_cast<SymbolTree*>(m_winStack->GetSelected()); + event.Enable(tree != NULL && !tree->IsEmpty()); +} + +void SymbolView::OnGoHome(wxCommandEvent& event) +{ + wxUnusedVar(event); +} + +void SymbolView::OnGoHomeUI(wxUpdateUIEvent& event) +{ + event.Enable(false); +} + +void SymbolView::OnUpdateUI(wxUpdateUIEvent& event) +{ + SymbolTree *tree = dynamic_cast<CppSymbolTree*>(m_winStack->GetSelected()); + if (tree && tree->IsEmpty()) { + DisplaySymbolTree(m_winStack->GetSelectedKey(), true); + } + event.Skip(); +} + Index: LiteEditor/symbolview.h =================================================================== --- LiteEditor/symbolview.h (revision 0) +++ LiteEditor/symbolview.h (revision 0) @@ -0,0 +1,80 @@ +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// +// +// copyright : (C) 2008 by Eran Ifrah +// file name : symbolview.h +// +// ------------------------------------------------------------------------- +// A +// _____ _ _ _ _ +// / __ \ | | | | (_) | +// | / \/ ___ __| | ___| | _| |_ ___ +// | | / _ \ / _ |/ _ \ | | | __/ _ ) +// | \__/\ (_) | (_| | __/ |___| | || __/ +// \____/\___/ \__,_|\___\_____/_|\__\___| +// +// F i l e +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// +#ifndef __symbolview__ +#define __symbolview__ + +#include <wx/panel.h> + +// forward decls +class WindowStack; +class SymbolTree; +class SymbolTreeEvent; + + +class SymbolView : public wxPanel { +private: + wxChoice *m_viewChoice; + int m_viewMode; + WindowStack *m_winStack; + bool m_isLinkedToEditor; + + void OnViewModeMouseDown(wxMouseEvent &event); + void OnViewTypeChanged(wxCommandEvent &event); + void OnLinkEditor(wxCommandEvent &e); + void OnCollapseAll(wxCommandEvent &event); + void OnCollapseAllUI(wxUpdateUIEvent &event); + void OnGoHome(wxCommandEvent &event); + void OnGoHomeUI(wxUpdateUIEvent &event); + void OnUpdateUI(wxUpdateUIEvent &event); + +protected: + void CreateGUIControls(); + + SymbolTree *GetSymbolTree(const wxString &fileName); + +public: + SymbolView(wxWindow *parent); + virtual ~SymbolView(); + + wxString GetSelected(); + + //handle symbol tree events + void OnAddSymbols(SymbolTreeEvent &event); + void OnDeleteSymbols(SymbolTreeEvent &event); + void OnUpdateSymbols(SymbolTreeEvent &event); + + void DisplaySymbolTree(const wxFileName &filename = wxFileName(), bool immediate = false); + void DeleteSymbolTree(const wxFileName &filename); + void DeleteAllSymbolTrees(); + + void RefreshSymbolTree(const wxFileName &filename); + + bool GetIsLinkedToEditor() const { return m_isLinkedToEditor; } + +private: + DECLARE_EVENT_TABLE() +}; + +#endif // __symbolview__ Index: LiteEditor/windowstack.cpp =================================================================== --- LiteEditor/windowstack.cpp (revision 2304) +++ LiteEditor/windowstack.cpp (working copy) @@ -26,7 +26,8 @@ WindowStack::WindowStack(wxWindow *parent, wxWindowID id) : wxPanel(parent, id) -, m_selection(NULL) +, m_selection(NULL) +, m_selectionKey(wxEmptyString) { m_mainSizer = new wxBoxSizer(wxVERTICAL); SetSizer(m_mainSizer); @@ -72,9 +73,21 @@ m_mainSizer->Add(win, 1, wxEXPAND); win->Show(); - m_selection = win; + m_selection = win; + m_selectionKey = key; m_mainSizer->Layout(); Thaw(); +} + +void WindowStack::SelectNone() +{ + if (m_selection) { + Freeze(); + m_mainSizer->Detach(m_selection); + m_selection->Hide(); + m_selectionKey.Empty(); + Thaw(); + } } void WindowStack::Clear() @@ -85,7 +98,8 @@ } m_mainSizer->Layout(); - m_selection = NULL; + m_selection = NULL; + m_selectionKey.Empty(); m_windows.clear(); } @@ -107,7 +121,8 @@ win->Hide(); //if the removed page was also the selection, unselect it if(win == m_selection){ - m_selection = NULL; + m_selection = NULL; + m_selectionKey.Empty(); } m_windows.erase(iter); win->Destroy(); Index: LiteEditor/windowstack.h =================================================================== --- LiteEditor/windowstack.h (revision 2304) +++ LiteEditor/windowstack.h (working copy) @@ -32,17 +32,22 @@ class WindowStack : public wxPanel { std::map<wxString, wxWindow*> m_windows; wxBoxSizer *m_mainSizer; - wxWindow *m_selection; + wxWindow *m_selection; + wxString m_selectionKey; public: WindowStack(wxWindow *parent, wxWindowID id = wxID_ANY); virtual ~WindowStack(); void Add(wxWindow *win, const wxString &key); - void Select(const wxString &key); + void Select(const wxString &key); + void SelectNone(); void Clear(); void Delete(const wxString &key); - wxWindow *Find(const wxString &key); + wxWindow *Find(const wxString &key); + + wxWindow *GetSelected() {return m_selection;} + wxString GetSelectedKey() const { return m_selectionKey; } }; #endif //WINDOWSTACK_H Index: LiteEditor/workspace_pane.cpp =================================================================== --- LiteEditor/workspace_pane.cpp (revision 2304) +++ LiteEditor/workspace_pane.cpp (working copy) @@ -30,11 +30,10 @@ #include "manager.h" #include "custom_notebook.h" #include "fileview.h" -#include "cpp_symbol_tree.h" #include <wx/xrc/xmlres.h> #include "frame.h" #include "checkdirtreectrl.h" -#include "windowstack.h" +#include "symbolview.h" #include "openwindowspanel.h" #include "macros.h" #include "fileexplorer.h" @@ -129,8 +128,8 @@ m_explorer = new FileExplorer(m_book, wxT("Explorer")); ADD_WORKSPACE_PAGE(m_explorer, WorkspacePane::EXPLORER); - m_winStack = new WindowStack(m_book, wxID_ANY); - ADD_WORKSPACE_PAGE(m_winStack, WorkspacePane::SYMBOL_VIEW); + m_symView = new SymbolView(m_book); + ADD_WORKSPACE_PAGE(m_symView, WorkspacePane::SYMBOL_VIEW); m_openWindowsPane = new OpenWindowsPanel(m_book); ADD_WORKSPACE_PAGE(m_openWindowsPane, WorkspacePane::OPEN_FILES); @@ -141,69 +140,21 @@ m_mgr->Update(); } -CppSymbolTree *WorkspacePane::GetTreeByFilename(const wxFileName &filename) -{ - wxWindow *win = m_winStack->Find(filename.GetFullPath()); - if (win) { - return dynamic_cast<CppSymbolTree *>(win); - } - return NULL; -} - -void WorkspacePane::BuildSymbolTree(const wxFileName &filename) -{ - CppSymbolTree *tree = GetTreeByFilename(filename); - if (!tree) { - tree = new CppSymbolTree(m_winStack, wxID_ANY); - tree->SetSymbolsImages(CreateSymbolTreeImages()); - m_winStack->Add(tree, filename.GetFullPath()); - m_winStack->Select(filename.GetFullPath()); - } - tree->BuildTree(filename); -} - void WorkspacePane::BuildFileTree() { m_workspaceTab->BuildFileTree(); } -SymbolTree *WorkspacePane::GetSymbolTree(const wxString &fileName) +FileViewTree* WorkspacePane::GetFileViewTree() { - // if fileName is not empty use it to find the tree - if (fileName.IsEmpty()) { - int id = Frame::Get()->GetNotebook()->GetSelection(); - if (id != wxNOT_FOUND) { - LEditor *editor = dynamic_cast<LEditor*>( Frame::Get()->GetNotebook()->GetPage((size_t)id)); - if (editor) { - return GetTreeByFilename(editor->GetFileName()); - } - } - } else { - return GetTreeByFilename(wxFileName(fileName)); - } - return NULL; + return m_workspaceTab->GetFileView(); } -void WorkspacePane::DisplaySymbolTree(const wxFileName &filename) +SymbolView* WorkspacePane::GetSymbolView() { - m_winStack->Select(filename.GetFullPath()); + return m_symView; } -void WorkspacePane::DeleteSymbolTree(const wxFileName &filename) -{ - m_winStack->Delete(filename.GetFullPath()); -} - -void WorkspacePane::DeleteAllSymbolTrees() -{ - m_winStack->Clear(); -} - -FileViewTree* WorkspacePane::GetFileViewTree() -{ - return m_workspaceTab->GetFileView(); -} - wxComboBox* WorkspacePane::GetConfigCombBox() { return m_workspaceConfig; Index: LiteEditor/workspace_pane.h =================================================================== --- LiteEditor/workspace_pane.h (revision 2304) +++ LiteEditor/workspace_pane.h (working copy) @@ -31,11 +31,9 @@ #include "wx/filename.h" class FileViewTree; -class SymbolTree; -class CppSymbolTree; -class WindowStack; class OpenWindowsPanel; class wxComboBox; +class SymbolView; class FileExplorer; class WorkspaceTab; class Notebook; @@ -51,7 +49,7 @@ Notebook *m_book; wxString m_caption; - WindowStack *m_winStack; + SymbolView *m_symView; OpenWindowsPanel *m_openWindowsPane; FileExplorer *m_explorer; WorkspaceTab *m_workspaceTab; @@ -60,7 +58,6 @@ private: void CreateGUIControls(); - CppSymbolTree *GetTreeByFilename(const wxFileName &filename); public: WorkspacePane(wxWindow *parent, const wxString &caption, wxAuiManager *mgr); @@ -69,11 +66,7 @@ //----------------------------------------------- // Operations //----------------------------------------------- - void BuildSymbolTree(const wxFileName &filename); void BuildFileTree(); - void DisplaySymbolTree(const wxFileName &filename); - void DeleteSymbolTree(const wxFileName &filename); - void DeleteAllSymbolTrees(); void CollpaseAll(); void OnConfigurationManager(wxCommandEvent &e); void OnConfigurationManagerUI(wxUpdateUIEvent &e); @@ -86,7 +79,7 @@ //----------------------------------------------- Notebook *GetNotebook() { return m_book; } - SymbolTree *GetSymbolTree(const wxString &fileName = wxEmptyString); + SymbolView *GetSymbolView(); FileViewTree *GetFileViewTree(); OpenWindowsPanel *GetOpenedWindows() {return m_openWindowsPane;} const wxString &GetCaption() const {return m_caption;} Index: LiteEditor/workspacetab.cpp =================================================================== --- LiteEditor/workspacetab.cpp (revision 2304) +++ LiteEditor/workspacetab.cpp (working copy) @@ -136,6 +136,10 @@ m_isLinkedToEditor = !m_isLinkedToEditor; // save the value EditorConfigST::Get()->SaveLongValue(wxT("LinkWorkspaceViewToEditor"), m_isLinkedToEditor ? 1 : 0); + if (m_isLinkedToEditor) { + wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, XRCID("show_in_workspace")); + Frame::Get()->AddPendingEvent(event); + } } void WorkspaceTab::OnGoHome(wxCommandEvent &e) Index: Runtime/rc/menu.xrc =================================================================== --- Runtime/rc/menu.xrc (revision 2304) +++ Runtime/rc/menu.xrc (working copy) @@ -523,6 +523,13 @@ <object class="wxMenuItem" name="save_file_as"> <label>Save As</label> </object> + <object class="wxMenuItem" name="wxID_SEPARATOR"/> + <object class="wxMenuItem" name="show_in_workspace"> + <label>Show In Workspace</label> + </object> + <object class="wxMenuItem" name="show_in_explorer"> + <label>Show In Explorer</label> + </object> <object class="wxMenuItem" name="wxID_SEPARATOR"/> <object class="wxMenuItem" name="copy_file_name"> <label>Copy Full Path to Clipboard</label> |