From fcb86cf2572d570e171beebe8055a9f6500a5a6f Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 10 Jul 2015 12:34:33 +0000 Subject: [PATCH] ide: Navigator: Now jumping to layout / iml items, Laydes: Nos jumping to first use of layout git-svn-id: svn://ultimatepp.org/upp/trunk@8663 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/ContextGoto.cpp | 92 +++++++++++++++++++++++++----------- uppsrc/ide/Core/Core.h | 2 + uppsrc/ide/LayDes/LayDes.h | 3 ++ uppsrc/ide/LayDes/laydes.key | 1 + uppsrc/ide/LayDes/laywin.cpp | 25 ++++++++++ uppsrc/ide/Navigator.cpp | 7 ++- uppsrc/ide/ide.h | 2 + 7 files changed, 103 insertions(+), 29 deletions(-) diff --git a/uppsrc/ide/ContextGoto.cpp b/uppsrc/ide/ContextGoto.cpp index 9c3095230..6e4cd5a03 100644 --- a/uppsrc/ide/ContextGoto.cpp +++ b/uppsrc/ide/ContextGoto.cpp @@ -344,6 +344,39 @@ void Ide::CtrlClick(int pos) ContextGoto0(pos); } +bool Ide::GotoDesignerFile(const String& path, const String& scope, const String& name, int line) +{ + if(ToLower(GetFileExt(path)) == ".lay") { + AddHistory(); + EditFile(path); + LayDesigner *l = dynamic_cast(~designer); + if(l) { + if(scope.StartsWith("With")) + l->FindLayout(scope.Mid(4), name); + } + else { + editor.SetCursor(editor.GetPos(line - 1)); + editor.TopCursor(4); + editor.SetFocus(); + } + AddHistory(); + return true; + } + else + if(ToLower(GetFileExt(path)) == ".iml") { + AddHistory(); + EditFile(path); + IdeIconDes *l = dynamic_cast(~designer); + if(l) + l->FindId(name); + else + editor.SetFocus(); + AddHistory(); + return true; + } + return false; +} + void Ide::JumpToDefinition(const Array& n, int q, const String& scope) { String qitem = n[q].qitem; @@ -375,32 +408,37 @@ void Ide::JumpToDefinition(const Array& n, int q, const String& scope) String path = GetSourceFilePath(pos.file); editastext.RemoveKey(path); editashex.RemoveKey(path); - if(ToLower(GetFileExt(path)) == ".lay") { - AddHistory(); - EditFile(path); - LayDesigner *l = dynamic_cast(~designer); - if(l) { - if(scope.StartsWith("With")) - l->FindLayout(scope.Mid(4), pos.name); - } - else { - editor.SetCursor(editor.GetPos(pos.line - 1)); - editor.TopCursor(4); - editor.SetFocus(); - } - AddHistory(); - } - else - if(ToLower(GetFileExt(path)) == ".iml") { - AddHistory(); - EditFile(path); - IdeIconDes *l = dynamic_cast(~designer); - if(l) - l->FindId(pos.name); - else - editor.SetFocus(); - AddHistory(); - } - else + if(!GotoDesignerFile(path, scope, pos.name, pos.line)) GotoCpp(pos); } + +void Ide::GotoFileAndId(const String& path, const String& id) +{ + AddHistory(); + EditFile(path); + WString wid = id.ToWString(); + if(editor.GetLength() < 100000) { + for(int i = 0; i < editor.GetLineCount(); i++) { + WString ln = editor.GetWLine(i); + int q = ln.Find(wid); + while(q >= 0) { + if(q == 0 || !iscid(ln[q - 1]) && !iscid(ln[q + wid.GetCount()])) { + editor.SetCursor(editor.GetPos(i, q)); + editor.CenterCursor(); + return; + } + if(q + 1 >= ln.GetCount()) + break; + q = ln.Find(wid, q + 1); + } + } + } + AddHistory(); +} + +void IdeGotoFileAndId(const String& path, const String& id) +{ + Ide *ide = dynamic_cast(TheIde()); + if(ide) + ide->GotoFileAndId(path, id); +} diff --git a/uppsrc/ide/Core/Core.h b/uppsrc/ide/Core/Core.h index 6b0b25a46..4d2f32173 100644 --- a/uppsrc/ide/Core/Core.h +++ b/uppsrc/ide/Core/Core.h @@ -139,6 +139,8 @@ bool IdeIsDebugLock(); void IdeSetBar(); +void IdeGotoFileAndId(const String& path, const String& id); + #include "Host.h" struct IdeMacro { diff --git a/uppsrc/ide/LayDes/LayDes.h b/uppsrc/ide/LayDes/LayDes.h index 2503b4d85..bf94ebc3d 100644 --- a/uppsrc/ide/LayDes/LayDes.h +++ b/uppsrc/ide/LayDes/LayDes.h @@ -5,6 +5,7 @@ #include #include #include +#include #define LAYOUTFILE #include @@ -448,6 +449,8 @@ private: void MainMenuBar(Bar& bar); void EditMenu(Bar& bar); + + void GotoUsing(); void SyncUsc(); void Save(); diff --git a/uppsrc/ide/LayDes/laydes.key b/uppsrc/ide/LayDes/laydes.key index e2f069947..d46c6932b 100644 --- a/uppsrc/ide/LayDes/laydes.key +++ b/uppsrc/ide/LayDes/laydes.key @@ -41,3 +41,4 @@ KEY2(MOVELAYOUTUP, "Move Layout Up", K_ALT|K_CTRL_PAGEUP, K_ALT|K_CTRL_UP) KEY2(MOVELAYOUTDOWN, "Move Layout Down", K_ALT|K_CTRL_PAGEDOWN, K_ALT|K_CTRL_DOWN) KEY(VISGEN, "Generate code..", K_ALT_C) +KEY(FINDSOURCE, "Go to class using this layout..", K_ALT_J) \ No newline at end of file diff --git a/uppsrc/ide/LayDes/laywin.cpp b/uppsrc/ide/LayDes/laywin.cpp index e4cef98d9..e763c6d36 100644 --- a/uppsrc/ide/LayDes/laywin.cpp +++ b/uppsrc/ide/LayDes/laywin.cpp @@ -29,6 +29,7 @@ void LayDes::EditBar(Bar& bar) bar.Add(islayout, "Select all", CtrlImg::select_all(), THISBACK(SelectAll)) .Key(K_CTRL_A); bar.Add(islayout, AK_VISGEN, LayImg::Members(), THISBACK(VisGen)); + bar.Add(islayout, AK_FINDSOURCE, IdeCommonImg::Cpp(), THISBACK(GotoUsing)); bar.Separator(); bar.Add(islayout && CurrentLayout().IsUndo(), "Undo", CtrlImg::undo(), THISBACK(Undo)) .Key(K_ALT_BACKSPACE) @@ -158,6 +159,30 @@ void LayDes::Settings() SyncItems(); } +void LayDes::GotoUsing() +{ + if(IsNull(currentlayout)) + return; + + String lid = "With" + CurrentLayout().name; + const Workspace& wspc = GetIdeWorkspace(); + for(int i = 0; i < wspc.GetCount(); i++) { // find lowest file time + const Package& pk = wspc.GetPackage(i); + String n = wspc[i]; + for(int i = 0; i < pk.GetCount(); i++) { + String path = SourcePath(n, pk.file[i]); + if(IsCPPFile(path) || IsHFile(path)) { + const PPFile& f = GetPPFile(NormalizeSourcePath(path)); + if(FindIndex(f.keywords, lid) >= 0) { + IdeGotoFileAndId(path, lid); + return; + } + } + } + } + Exclamation("No code found using this layout."); +} + void LayDes::OptionBar(Bar& bar) { bar.Add("Use grid", LayImg::Grid(), THISBACK(ToggleGrid)) diff --git a/uppsrc/ide/Navigator.cpp b/uppsrc/ide/Navigator.cpp index 848d21d9f..a98eb9de5 100644 --- a/uppsrc/ide/Navigator.cpp +++ b/uppsrc/ide/Navigator.cpp @@ -248,8 +248,11 @@ void Navigator::Navigate() q = (i + l.GetCount() + 1) % l.GetCount(); break; } - if(q >= 0 && q < l.GetCount()) - theide->GotoPos(GetSourceFilePath(l[q].file), l[q].line); + if(q >= 0 && q < l.GetCount()) { + String path = GetSourceFilePath(l[q].file); + if(!theide->GotoDesignerFile(path, m.nest, m.name, l[q].line)) + theide->GotoPos(path, l[q].line); + } } } navigating = false; diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index 77174da90..cab3e8b2f 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -1050,7 +1050,9 @@ public: bool OpenMainPackage(); void NewMainPackage(); + bool GotoDesignerFile(const String& path, const String& scope, const String& name, int line); void JumpToDefinition(const Array& n, int q, const String& scope); + void GotoFileAndId(const String& path, const String& id); void SearchTopics(); void ShowTopics(); void ShowTopicsWin();