bool AliasMap::Load(const char *path) { String file = LoadFile(path); if(file.IsVoid()) return false; obj_source.Clear(); obj_dest.Clear(); for(const char *s = file; *s;) { bool is_dest = (*s == ' ' || *s == '\t'); while(*s == ' ' || *s == '\t') s++; const char *b = s; while(*s && *s != '\n') s++; const char *e = s; while(e > b && (byte)e[-1] <= ' ') e--; String part(b, e); if(is_dest) { while(obj_dest.GetCount() < obj_source.GetCount()) obj_dest.Add(part); } else obj_source.Add(part); if(*s) s++; } if(obj_dest.GetCount() < obj_source.GetCount()) obj_source.SetCount(obj_dest.GetCount()); IndexSort(obj_source, obj_dest, StdLess<String>()); return true; }
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()); }
bool AliasMap::Save(const char *path) { IndexSort(obj_dest, obj_source, StdLess<String>()); String out; for(int i = 0; i < obj_source.GetCount(); i++) { out.Cat(obj_source[i]); out.Cat("\r\n"); if(i + 1 >= obj_source.GetCount() || obj_dest[i + 1] != obj_dest[i]) { out.Cat('\t'); out.Cat(obj_dest[i]); out.Cat("\r\n"); } } IndexSort(obj_source, obj_dest, StdLess<String>()); return SaveFile(path, out); }
void RichEdit::ReadStyles() { int i; style.Clear(); Vector<Uuid> id; Vector<String> name; for(i = 0; i < text.GetStyleCount(); i++) { id.Add(text.GetStyleId(i)); name.Add(text.GetStyle(i).name); } IndexSort(name, id, sCompareLess()); for(i = 0; i < id.GetCount(); i++) style.Add(id[i], name[i]); }
void WorkspaceWork::ScanWorkspace() { Workspace wspc; if(main.GetCount()) wspc.Scan(main); actualpackage.Clear(); actualfileindex = -1; filelist.Clear(); package.Clear(); Vector<String> pks; speed.Clear(); for(int i = 0; i < wspc.package.GetCount(); i++) { pks.Add(wspc.package.GetKey(i)); speed.Add(wspc.GetPackage(i).optimize_speed); } if(sort && wspc.GetCount()) { PackageOrder po; po.mainpath = PackagePath(pks[0]); IndexSort(pks.Begin() + 1, pks.End(), speed.Begin() + 1, po); } for(int i = 0; i < wspc.package.GetCount(); i++) { String pk = pks[i]; Font fnt = ListFont(); if(i == 0) fnt.Bold(); PackageInfo pi = GetPackageInfo(pk); if(pi.bold) fnt.Bold(); if(pi.italic) fnt.Italic(); package.Add(pk, Null, fnt, Nvl(pi.ink, SColorText()), false, 0, Null, SColorMark); } if(!organizer) { if(main.GetCount()) package.Add(prjaux, IdeImg::PrjAux(), ListFont(), Magenta); package.Add(ideaux, IdeImg::IdeAux(), ListFont(), Magenta); package.Add(tempaux, IdeImg::TempAux(), ListFont(), Magenta); if(main.GetCount()) package.Add(METAPACKAGE, IdeImg::Meta(), ListFont(), Red); } package.SetCursor(0); SyncErrorPackages(); }
void LineEdit::Sort() { if(!IsRectSelection()) return; CopyRectSelection(); Rect rect = GetRectSelection(); Vector<WString> key; Vector<WString> ln; for(int i = rect.top; i <= rect.bottom; i++) { int l, h; GetRectSelection(rect, i, l, h); key.Add(GetW(l, h - l)); ln.Add(line[i]); } int sell = GetPos(rect.top); int selh = rect.bottom + 1 < line.GetCount() ? GetPos(rect.bottom + 1) : GetLength(); IndexSort(key, ln, sSortLineOrder); Remove(sell, selh - sell); Insert(sell, Join(ln, "\n")); }
void GetAllMacros(Md5Stream& md5, const String& id, Index<int>& segment_id) { Vector< Tuple2<int, int> > pos; Vector<const CppMacro *> def; String r; int q = sAllMacros.Find(id); while(q >= 0) { const PPMacro& m = sAllMacros[q]; int si = segment_id.Find(m.segment_id); if(si >= 0) { pos.Add(MakeTuple(si, m.line)); def.Add(&m.macro); } q = sAllMacros.FindNext(q); } IndexSort(pos, def); int n = def.GetCount(); if(n) { md5.Put(&n, sizeof(int)); md5.Put(id); for(int i = 0; i < n; i++) md5.Put(def[i]->md5, 16); } }
NAMESPACE_UPP // recalculates relative toolbar's positions // needed after adding or removing a toolbar void XMLToolBarFrame::Reposition(void) { // clears position mapper posMapper.Clear(); // setup a dummy frame size, just in case frame is empty frameSize = 3; // if no toolbars inside, just do nothing else if(!toolBars.GetCount()) return; // fixup 'vertical' positions, i.e. rows on which toolbars belong Array<int>vPos; for(int iPos = 0; iPos < relativePositions.GetCount(); iPos++) { Size const &sz = relativePositions[iPos]; vPos.Add(sz.cy); } Sort(vPos); VectorMap<int, int>vMap; int v = 0; for(int iPos = 0; iPos < vPos.GetCount(); iPos++) { if(vMap.Find(vPos[iPos]) < 0) { vMap.Add(vPos[iPos], v); v ++; } } for(int iPos = 0; iPos < relativePositions.GetCount(); iPos++) { Size &sz = relativePositions[iPos]; sz.cy = vMap.Get(sz.cy); } // now, scans each row, fixing up positions inside it and // building true toolbars positions int curVPos = 0; for(int iRow = 0; iRow < vMap.GetCount(); iRow++) { Vector<int>ps, idx; int rowHeight = 0; for(int iPos = 0; iPos < relativePositions.GetCount(); iPos++) { Size &sz = relativePositions[iPos]; if(sz.cy == iRow) { ps.Add(sz.cx); idx.Add(iPos); } } IndexSort(ps, idx); int minNextPos = 0; for(int i = 0; i < ps.GetCount(); i++) { if(ps[i] < minNextPos) ps[i] = minNextPos; XMLToolBarCtrl &tb = *toolBars[idx[i]]; Size sz; switch(toolBarState) { case TOOLBAR_LEFT : case TOOLBAR_RIGHT : sz = tb.GetVertSize(); rowHeight = max(rowHeight, sz.cx); minNextPos = ps[i] + sz.cy + 2; // 2 pixels gap between columns break; case TOOLBAR_TOP : case TOOLBAR_BOTTOM : sz = tb.GetHorzSize(); rowHeight = max(rowHeight, sz.cy); minNextPos = ps[i] + sz.cx + 2; // 2 pixels gap between columns break; default: NEVER(); } } VectorMap<int, int> &rowMap = posMapper.Add(curVPos); for(int i = 0; i < ps.GetCount(); i++) rowMap.Add(ps[i], idx[i]); curVPos += rowHeight; } // store total frame size frameSize = curVPos; // if reversed direction, fixup cols if(toolBarState == TOOLBAR_RIGHT || toolBarState == TOOLBAR_BOTTOM) { int lastPos = posMapper.GetKey(posMapper.GetCount()-1); for(int iRow = 0; iRow < posMapper.GetCount(); iRow++) posMapper.SetKey(iRow, lastPos - posMapper.GetKey(iRow)); } }
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(); }