developing designer assist

This commit is contained in:
Mirek Fidler 2022-08-13 18:43:56 +02:00
parent 795b842adf
commit ff357a5ffc
8 changed files with 81 additions and 80 deletions

View file

@ -25,6 +25,7 @@ bool IsPendif(const String& l)
return l.Find("#endif") >= 0;
}
/* TODO remove
void Ide::FindId(const String& id)
{
int pos = editor.GetCursor();
@ -48,6 +49,7 @@ void Ide::FindId(const String& id)
pos++;
}
}
*/
bool Ide::OpenLink(const String& s, int pos)
{ // try to find link at cursor, either http, https or file
@ -184,6 +186,7 @@ void Ide::ContextGoto0(int pos)
found_nest = m.nest;
}
}
if(found_path.GetCount()) {
AddHistory();
EditFile(found_path);
@ -226,40 +229,46 @@ void Ide::CtrlClick(int64 pos)
ContextGoto0((int)pos);
}
bool Ide::GotoDesignerFile(const String& path, const String& scope, const String& name, int line)
void Ide::FindDesignerItemReferences(const String& id, const String& name)
{
if(ToLower(GetFileExt(path)) == ".lay") {
AddHistory();
EditFile(path);
LayDesigner *l = dynamic_cast<LayDesigner *>(~designer);
if(l) {
if(scope.StartsWith("With"))
l->FindLayout(scope.Mid(4), name);
else
if(name.StartsWith("SetLayout_"))
l->FindLayout(name.Mid(10), Null);
String path = NormalizePath(editfile);
int q = CodeIndex().Find(path);
if(q >= 0) {
AnnotationItem cm;
for(const AnnotationItem& m : CodeIndex()[q].items)
if(m.id.EndsWith(id) &&
(m.id.GetCount() <= id.GetCount() || !iscid(m.id[m.id.GetCount() - id.GetCount() - 1]))) {
cm = m;
break;
}
if(cm.id.GetCount()) {
Vector<Tuple<String, Point>> set;
for(const auto& f : ~CodeIndex()) {
if(f.key != path) {
for(const AnnotationItem& m : f.value.items)
if(FindId(m.type, cm.id) >= 0 || FindId(m.bases, cm.id) >= 0 || FindId(m.pretty, cm.id) >= 0)
set.Add({ f.key, m.pos });
for(const ReferenceItem& m : f.value.refs)
if(FindId(m.id, id) >= 0)
set.Add({ f.key, m.pos });
}
}
if(set.GetCount()) {
if(set.GetCount() > 1) {
SetFFound(ffoundi_next);
FFound().Clear();
for(auto& m : set)
AddReferenceLine(m.a, m.b, name);
SortByKey(CodeIndex());
FFoundFinish();
}
GotoPos(set[0].a, set[0].b);
return;
}
}
else {
editor.SetCursor(editor.GetPos64(line - 1));
editor.TopCursor(4);
editor.SetFocus();
}
AddHistory();
return true;
}
else
if(ToLower(GetFileExt(path)) == ".iml") {
AddHistory();
EditFile(path);
IdeIconDes *l = dynamic_cast<IdeIconDes *>(~designer);
if(l)
l->FindId(name);
else
editor.SetFocus();
AddHistory();
return true;
}
return false;
Exclamation("No usage has been found.");
}
void Ide::GotoFileAndId(const String& path, const String& id)

View file

@ -1,6 +1,7 @@
#include "LayDes.h"
#include <ide/Common/Common.h>
#include <ide/ide.h>
#define LTIMING(x) //TIMING(x)
@ -165,23 +166,11 @@ 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(IsSourceFile(path) || IsHeaderFile(path)) {
if(false) { // TODO
IdeGotoFileAndId(path, lid);
return;
}
}
}
}
Exclamation("No code found using this layout.");
if(item.IsCursor()) // TODO not for label
TheIde()->FindDesignerItemReferences("With" + CurrentLayout().name, ~item.Get(1));
else
TheIde()->FindDesignerItemReferences(CurrentLayout().name + "__layid", "With" + CurrentLayout().name);
}
void LayDes::OptionBar(Bar& bar)

View file

@ -78,6 +78,23 @@ String GetFileLine(const String& path, int linei)
return linei >= 0 && linei < line.GetCount() ? line[linei] : String();
}
void Ide::AddReferenceLine(const String& path, Point mpos, const String& name)
{
String ln = GetFileLine(path, mpos.y);
int count = 0;
int pos = 0;
if(name.GetCount()) {
pos = FindId(ln.Mid(mpos.x), name);
if(pos >= 0) {
count = name.GetCount();
pos += mpos.x;
}
else
pos = 0;
}
AddFoundFile(path, mpos.y + 1, ln, pos, count);
}
void Ide::References()
{
if(designer)
@ -90,17 +107,6 @@ void Ide::References()
SortByKey(CodeIndex());
for(const auto& f : ~CodeIndex()) {
auto Add = [&](Point mpos) {
String ln = GetFileLine(f.key, mpos.y);
int count = 0;
int pos = 0;
if(cm.name.GetCount()) {
pos = ::FindId(ln + mpos.x, cm.name);
if(pos >= 0)
count = cm.name.GetCount();
else
pos = 0;
}
AddFoundFile(f.key, mpos.y + 1, ln, pos, count);
};
for(const AnnotationItem& m : f.value.items)
if(m.id == cm.id)

View file

@ -103,7 +103,7 @@ void DumpIndex()
for(const auto& m : ~x) {
out << m.key << "\n";
for(const auto& n : m.value.items)
out << '\t' << n.name << " " << n.type << " " << n.id << " " << n.pretty << "\n";
out << '\t' << n.name << " " << n.type << " " << n.id << " " << n.pretty << " " << n.bases << "\n";
for(const auto& n : m.value.refs)
out << '\t' << n.pos << " " << n.id << "\n";
}

View file

@ -50,7 +50,7 @@ bool IsStruct(int kind);
bool IsTemplate(int kind);
bool IsFunction(int kind);
bool IsVariable(int kind);
int FindId(const char *s, const String& id);
int FindId(const String& s, const String& id);
enum {
ITEM_TEXT,

View file

@ -162,6 +162,10 @@ ISUES:
- remove bool Ide::GotoDesignerFile(const String& path, const String& scope, const String& name, int line)
- Usage .lay of FileSel::dir adds some strange lines
- Alt-J at CtrlLib/CtrlUtil.cpp:143 does not
GREAT CODEBASE PURGE:
- ReferenceDlg
@ -179,8 +183,6 @@ GREAT CODEBASE PURGE:
- IdeGotoCodeRef
- thisbacks
NONCLANG:
- Wind/MetTimeProf.cpp:881 jump on CUtil::
@ -240,6 +242,8 @@ LATER:
DONE:
- thisbacks
- virtuals
- different master header currentfile / index issue

View file

@ -40,18 +40,9 @@ bool IsVariable(int kind)
return findarg(kind, CXCursor_VarDecl, CXCursor_FieldDecl) >= 0;
}
int FindId(const char *s, const String& id)
{
try {
CParser p(s);
while(!p.IsEof()) {
const char *q = p.GetPtr();
if(p.Id(id))
return q - s;
else
p.Skip();
}
}
catch(CParser::Error) {}
return -1;
}
int FindId(const String& s, const String& id) {
int q = s.Find(id);
return q < 0 ||
q > 0 && iscid(s[q - 1]) ||
q + id.GetCount() < s.GetCount() && iscid(s[q + id.GetCount()]) ? -1 : q;
};

View file

@ -985,8 +985,9 @@ public:
void NavigatorDlg();
void Cycle(const AnnotationItem& cm);
void SwapS();
void AddReferenceLine(const String& path, Point pos, const String& name);
void References();
void FindId(const String& id);
// void FindId(const String& id); TODO remove
bool OpenLink(const String& s, int pos);
void ContextGoto0(int pos);
void ContextGoto();
@ -1001,6 +1002,7 @@ public:
void DoPatchDiff();
void AsErrors();
void RemoveDs();
void FindDesignerItemReferences(const String& id, const String& name);
void HelpMenu(Bar& menu);
void ViewIdeLogFile();
@ -1163,8 +1165,8 @@ public:
bool OpenMainPackage();
void NewMainPackage();
bool GotoDesignerFile(const String& path, const String& scope, const String& name, int line);
void GotoFileAndId(const String& path, const String& id);
void GotoDesignerItem(const String& path, const String& id);
void SearchTopics();
void ShowTopics();
void ShowTopicsWin();