void CodeBrowser::Load() { String find = ToUpper((String)~search); String match = ToUpper((String)~search_scope); String pm = GetPm(); Vector<String> txt; Vector<Value> ndx; Index<int> fi; Index<String> fs; for(int i = 0; i < CodeBase().GetCount(); i++) { String s = CodeBase().GetKey(i); const Array<CppItem>& n = CodeBase()[i]; if(s.GetCount()) if(MatchCib(s, match) && (MatchCib(s, find) || HasItem(n, find)) && MatchPm(n, pm)) { txt.Add(s); ndx.Add(s); } for(int i = 0; i < n.GetCount(); i++) { int f = n[i].file; if(fi.Find(f) < 0) { String s = GetFileText(GetSourceFilePath(f)); if(s.StartsWith(pm) && MatchCib(s, match) && (IsNull(find) || MatchCib(s, find) || n[i].uname.StartsWith(find))) { txt.Add(s); ndx.Add(f); fs.Add(s); fi.Add(f); } } } } const Workspace& wspc = GetIdeWorkspace(); for(int i = 0; i < wspc.GetCount(); i++) { String pn = wspc[i]; const Package& p = wspc.GetPackage(i); String pp = PackageDirectory(pn); for(int j = 0; j < p.GetCount(); j++) if(!p[j].separator) { String fn = AppendFileName(pp, p[j]); String s = GetFileText(AppendFileName(pn, p[j])); if(fs.Find(s) < 0 && (IsNull(find) || MatchCib(s, find)) && MatchCib(s, match) && MatchPm(fn, pm)) { int f = GetSourceFileIndex(SourcePath(pn, p[j])); txt.Add(s); ndx.Add(f); fs.Add(s); } } } IndexSort(txt, ndx, ScopeLess()); Value key = scope.GetKey(); int sc = scope.GetCursorSc(); scope.Clear(); for(int i = 0; i < txt.GetCount(); i++) scope.Add(IsString(ndx[i]) ? ndx[i] : Null, txt[i], ndx[i]); if(scope.FindSetCursor(key)) scope.ScCursor(sc); // clear.Enable(IsSearch()); }
void Navigator::NavGroup(bool local) { for(int i = 0; i < nitem.GetCount(); i++) { NavItem& m = nitem[i]; String g = m.nest; if(m.kind == TYPEDEF) g.Trim(max(g.ReverseFind("::"), 0)); if(IsNull(g) || CodeBase().namespaces.Find(m.nest) >= 0) { if(g.GetCount()) // We want to show the namespace g << '\xff'; else g.Clear(); g << GetSourceFilePath(m.decl_file); g = '\xff' + g; } if(!local) g = (char)(m.pass + 10) + g; if(local) if(gitem.GetCount() && gitem.TopKey() == g) gitem.Top().Add(&m); else gitem.Add(g).Add(&m); else gitem.GetAdd(g).Add(&m); } }
Vector<Navigator::NavLine> Navigator::GetNavLines(const NavItem& m) { Vector<NavLine> l; int q = CodeBase().Find(m.nest); if(q < 0 || IsNull(m.qitem)) return l; const Array<CppItem>& a = CodeBase()[q]; for(int i = 0; i < a.GetCount(); i++) { const CppItem& mm = a[i]; if(mm.qitem == m.qitem) { NavLine& nl = l.Add(); nl.impl = mm.impl; nl.file = mm.file; nl.line = mm.line; } } Sort(l); return l; }
Size MakeLogo(Ctrl& parent, Array<Ctrl>& ctrl) { Image logo = IdeImg::logo(); Size isz = logo.GetSize(); ImageCtrl& l = ctrl.Create<ImageCtrl>(); Label& v1 = ctrl.Create<Label>(); l.SetImage(logo); Size sz = Size(isz.cx, isz.cy/* + 80*/); const CppBase& cpp = CodeBase(); int total = 0; for(int i = 0; i < cpp.GetCount(); i++) total += cpp[i].GetCount(); String h; #ifdef bmSVN_REVISION h << "Version " << bmSVN_REVISION; #else h << "Version " << IDE_VERSION; #endif if(sizeof(void *) == 8) h << "\n(64 bit)"; else h << "\n(32 bit)"; #ifdef _MSC_VER h << " (MSC)"; #endif #if __GNUC__ #if __clang__ h << " (CLANG)"; #else h << " (GCC)"; #endif #endif #if __cplusplus >= 201100 h << " (C++11)"; #endif #ifdef GUI_GTK h << " (Gtk)"; #endif h << "\n"; #ifdef bmTIME h << "Compiled " << bmTIME << "\n"; #endif h << "Using " << MemoryUsedKb() << " KB\n"; if(cpp.GetCount()) h << "CodeBase: " << cpp.GetCount() << " classes, " << total << " items\n"; v1 = h; v1.HSizePos(DPI(220), DPI(10)).BottomPos(DPI(20), Arial(DPI(20)).GetHeight() * 5); v1.SetFont(Arial(DPI(10))); l.Add(v1); parent.Add(ctrl.Create<StaticRect>().Color(White).SizePos()); parent.Add(l.TopPos(0, isz.cy).LeftPos(0, isz.cx)); return sz; }
void CodeBrowser::LoadScope() { String find = ToUpper((String)~search); Value key = item.GetKey(); int sc = item.GetCursorSc(); item.Clear(); if(!scope.IsCursor()) return; Value x = scope.Get(2); int file = IsNumber(x) ? (int)x : -1; String scope = file < 0 ? String(x) : String(); int q = CodeBase().Find(scope); bool filematch = file >= 0 && MatchCib(GetFileText(GetSourceFilePath(file)), find); bool scopematch = !filematch && MatchCib(scope, find); if(q >= 0) { const Array<CppItem>& n = CodeBase()[q]; VectorMap<String, bool> inherited; if(file < 0) GatherMethods(scope, inherited, false); Index<String> set; for(int i = 0; i < n.GetCount(); i++) { CppItemInfo m; (CppItem&) m = n[i]; if((find.GetCount() && m.uname.StartsWith(find) || filematch && m.file == file || scopematch) && set.Find(m.qitem) < 0) { set.Add(m.qitem); int q = inherited.Find(m.qitem); if(q >= 0) { m.over = true; m.virt = m.virt || inherited[q]; } item.Add(m.qitem, RawToValue(m)); } } } item.Sort(1, sort ? ItemCompareLexical : ItemCompare); if(item.FindSetCursor(key)) item.ScCursor(sc); // clear.Enable(IsSearch()); }
void GatherMethods(const String& type, VectorMap<String, bool>& inherited, bool g, Index<String>& done) { if(done.Find(type) >= 0) return; done.Add(type); int q = CodeBase().Find(type); if(q < 0) return; const Array<CppItem>& n = CodeBase()[q]; Index<String> set; for(int i = 0; i < n.GetCount(); i++) { const CppItem& m = n[i]; if(set.Find(m.qitem) < 0) { set.Add(m.qitem); if(m.IsType()) { Vector<String> base = Split(m.qptype, ';'); for(int i = 0; i < base.GetCount(); i++) GatherMethods(base[i], inherited, true, done); } if(m.IsCode() && g) { bool& virt = inherited.GetAdd(m.qitem); virt = virt || m.virt; } } } }
void TopicEditor::FixTopic() { String nest; if(!EditText(nest, "Fix topic", "Nest")) return; CppBase& base = CodeBase(); int q = base.Find(nest); if(q < 0) { Exclamation("Nest not found"); return; } Array<CppItem>& n = base[q]; Index<String> natural; Vector<String> link; for(int i = 0; i < n.GetCount(); i++) { const CppItem& m = n[i]; String nat; if(m.virt) nat << "virtual "; if(m.kind == CLASSFUNCTION || m.kind == CLASSFUNCTIONTEMPLATE) nat << "static "; nat << m.natural; natural.Add(nat); link.Add(MakeCodeRef(nest, n[i].qitem)); } RichText result; const RichText& txt = editor.Get(); bool started = false; int l, h; if(editor.GetSelection(l, h)) { l = txt.FindPart(l); h = txt.FindPart(h); } else { l = 0; h = txt.GetPartCount(); } for(int i = 0; i < txt.GetPartCount(); i++) if(txt.IsPara(i)) { RichPara p = txt.Get(i); if(i >= l && i < h) { WString h = p.GetText(); String nat; const wchar *s = h; while(*s) if(*s == 160 || *s == ' ') { nat.Cat(' '); while(*s == 160 || *s == ' ') s++; } else nat.Cat(*s++); int q = nat.GetCount() ? natural.Find(nat) : -1; if(q >= 0) { started = true; const CppItem& m = n[q]; RichText h = ParseQTF(styles + ("[s7; &]" + CreateQtf(link[q], n[q].name, m, GetLang(), true))); if(h.GetPartCount()) h.RemovePart(h.GetPartCount() - 1); result.CatPick(pick(h)); } else if(!started || p.GetLength()) result.Cat(p); } else result.Cat(p); } else { RichTable b; b <<= txt.GetTable(i); result.CatPick(pick(b)); } RichPara empty; result.Cat(empty); editor.BeginOp(); editor.SetSelection(0, txt.GetLength()); editor.PasteText(result); }
bool IsCodeRefType(const String& type) { if(type.GetCount() == 0) return false; return CodeBase().Find(type) >= 0; }
void Navigator::Search() { sortitems.Check(sorting); int sc = scope.GetScroll(); String key = scope.GetKey(); String s = TrimBoth(~search); String search_name, search_nest; bool wholeclass = false; bool both = false; navigator_global = false; if(s.Find('.') >= 0) { Vector<String> h = Split((String)~search, '.'); if(*s.Last() == '.') search_nest = Join(h, "::"); else { search_name = h.Pop(); if(h.GetCount()) search_nest = Join(h, "::"); } wholeclass = *s == '.' && search_nest.GetCount(); } else { search_name = search_nest = ~search; both = true; } s = Join(Split(s, '.'), "::") + (s.EndsWith(".") ? "::" : ""); int lineno = StrInt(s); gitem.Clear(); nitem.Clear(); if(IsNull(theide->editfile)) return; int fileii = GetSourceFileIndex(theide->editfile); if(!IsNull(lineno)) { NavItem& m = nitem.Add(); m.type = "Go to line " + AsString(lineno); m.kind = KIND_LINE; m.line = lineno; gitem.Add(Null).Add(&m); } else if(IsNull(s) && !sorting) { const CppBase& b = CodeBase(); for(int i = 0; i < b.GetCount(); i++) { String nest = b.GetKey(i); const Array<CppItem>& ci = b[i]; for(int j = 0; j < ci.GetCount(); j++) { const CppItem& m = ci[j]; if(m.file == fileii) { NavItem& n = nitem.Add(); n.Set(m); n.nest = nest; n.decl_line = m.line; n.decl_file = m.file; n.decl = !m.impl; NavLine& l = n.linefo.Add(); l.impl = m.impl; l.file = m.file; l.line = m.line; } } } Sort(nitem, FieldRelation(&NavItem::line, StdLess<int>())); NavGroup(true); } else { navigator_global = true; const CppBase& b = CodeBase(); String usearch_nest = ToUpper(search_nest); String usearch_name = ToUpper(search_name); ArrayMap<String, NavItem> imap; bool local = sorting && IsNull(s); VectorMap<String, int> nest_pass; for(int pass = -1; pass < 2; pass++) { for(int i = 0; i < b.GetCount(); i++) { String nest = b.GetKey(i); bool foundnest = (wholeclass ? pass < 0 ? false : pass ? ToUpper(nest) == usearch_nest : nest == search_nest : pass < 0 ? nest == search_nest : (pass ? ToUpper(nest).Find(usearch_nest) >= 0 : nest.StartsWith(search_nest))) && nest.Find('@') < 0; if(local || foundnest || both) { const Array<CppItem>& ci = b[i]; for(int j = 0; j < ci.GetCount(); j++) { const CppItem& m = ci[j]; if(local ? m.file == fileii : m.uname.Find('@') < 0 && (pass < 0 ? m.name == search_name : pass ? m.uname.Find(usearch_name) >= 0 : m.name.StartsWith(search_name)) || both && foundnest) { String key = nest + '\1' + m.qitem; int q = nest_pass.Find(nest); int p = pass; if(q < 0) // We do not want classes to be split based on pass nest_pass.Add(nest, pass); else p = nest_pass[q]; q = imap.Find(key); if(q < 0) { NavItem& ni = imap.Add(key); ni.Set(m); ni.nest = nest; ni.decl_line = ni.line; ni.decl_file = ni.file; ni.decl = !ni.impl; ni.pass = p; NavLine& l = ni.linefo.Add(); l.impl = m.impl; l.file = m.file; l.line = m.line; } else { NavItem& mm = imap[q]; if(!m.impl && (!mm.decl || CombineCompare(mm.decl_file, m.file)(mm.decl_line, m.line) < 0)) { mm.decl = true; mm.decl_line = m.line; mm.decl_file = m.file; mm.natural = m.natural; } NavLine& l = mm.linefo.Add(); l.impl = m.impl; l.file = m.file; l.line = m.line; } } } } } } nitem = imap.PickValues(); NavGroup(false); SortByKey(gitem); Vector<String> keys = gitem.PickKeys(); Vector<Vector<NavItem *> > values = gitem.PickValues(); IndexSort(keys, values); for(int i = 0; i < keys.GetCount(); i++) keys[i].Remove(0); VectorMap<String, Vector<NavItem *> > h(pick(keys), pick(values)); gitem = pick(h); for(int i = 0; i < gitem.GetCount(); i++) Sort(gitem[i], sorting ? SortByNames : SortByLines); } scope.Clear(); scope.Add(Null); Index<String> done; for(int i = 0; i < gitem.GetCount(); i++) { String s = gitem.GetKey(i); if(done.Find(s) < 0) { done.Add(s); scope.Add(s); } } scope.ScrollTo(sc); if(!navigator_global || !scope.FindSetCursor(key)) scope.GoBegin(); }