/* * Implementation of EntityTextEd and EntityTextList */ #include "rtexted.h" #include EntityTextEd::EntityTextEd(int rows, int cols, bool readonly, RSLBrowser* browser) : Sted(rows, cols, 8, Reversed, readonly, browser) { this->parent = parent; this->filename = null; es = null; } EntityTextEd::EntityTextEd(int rows, int cols, bool readonly, EntityTextEdList* parent, const char* filename, RSLBrowser* browser) : Sted(filename, rows, cols, 8, Reversed, readonly, browser) { this->parent = parent; this->filename = newstr(filename); es = null; } EntityTextEd::~EntityTextEd() { if (filename) delete filename; } EntityTextEd *EntityTextEd::ScrollToName(EntityStruct* es) { /* * Scroll the editor so that the name of the given entity is highlighted * in the middle of the this's window. If the file of the given entity * is not currently open in this, open it and then do the scrolling. */ SymtabEntry* curSym; SymtabEntry* newSym = es->GetSym(); char* fname = newSym->Loc.file; Regexp re(newSym->Symbol); bool startup = false; /* * Check if we've been here before or are just starting up. */ if (this->es) { curSym = this->es->GetSym(); } else { startup = true; } /* * Make the given es the current es. */ this->es = es; /* * Check if file for given entity is current, and if not make it so. */ if (startup or (curSym->Loc.file != fname)) parent->Open(fname); /* * Do it to it. */ BeginningOfText(); ForwardLine(newSym->Loc.line - 1); ForwardCharacter(newSym->Loc.col-1); ScrollToSelection(); /* * NOTE: confirm that the next two lines are necessary in order to * hightlight. So confirmed -- not necessary (or wanted). text->ForwardSearch(&re, Dot()); Select(re.EndOfMatch(), re.BeginningOfMatch()); */ Select(Dot(), Dot() + strlen(newSym->Symbol)); /*SelectAll();*/ return this; } EntityTextEdList::EntityTextEdList() {} EntityTextEd* EntityTextEdList::CurEd() { /* * Return the current editor. */ return curEd; } EntityTextEdList* EntityTextEdList::SetFixedEd(EntityTextEd* ed) { /* * Set current editor. Cant be done in constructor because EntityTextEd and * EntityTextEdList are mutually referencial. */ curEd = fixedEd = ed; return this; } EntityTextEdList* EntityTextEdList::Add(char* pathname = 0) { /* * Add a new editor containing the contents of the given path. Make the * new editor current. If path == 0, then editor is intially empty. */ return this; } EntityTextEdList* EntityTextEdList::Add(EntityTextEd* ed) { /* * Add the given new editor to the current list and make it current. */ Put(new EntityTextEdListElem(ed)); curEd = ed; return this; } EntityTextEdList* EntityTextEdList::Open(const char* pathname) { /* * Fill the current editor with the contents of the given path. */ curEd->Open(pathname); return this; } EntityTextEdList* EntityTextEdList::Del(char* pathname = 0) { /* * Delete the editor containing the given path. If path == 0, del the * current editor. */ return this; } EntityTextEdList* EntityTextEdList::MakeCur(char* pathname) { /* * Make the editor containing the given path contents the current editor. */ return MakeCur(Find(pathname)->data); } EntityTextEdList* EntityTextEdList::MakeCur(EntityTextEd* ed) { /* * Make the given editor the current editor. */ curEd = ed; return this; } EntityTextEdList* EntityTextEdList::ScrollToName(EntityStruct* es) { /* * Call ScrollToName on the current editor. */ curEd = Find(es->GetSym()->Loc.file)->data; curEd->ScrollToName(es); return this; } EntityTextEdList* EntityTextEdList::ScrollToPosition(int line, int col) { return this; } /* * Call ScrollToPosition on the current editor. */ EntityTextEdList* EntityTextEdList::SearchForw(const char* string) { /* * Search for the given string in the current editor. */ Regexp re(string); /* * Following code is straight from sted.c imple of search command. */ if (curEd->GetBuffer()->ForwardSearch(&re, curEd->Dot()) >= 0 || curEd->GetBuffer()->ForwardSearch( &re, curEd->GetBuffer()->BeginningOfText()) >= 0) { curEd->Select(re.EndOfMatch(), re.BeginningOfMatch()); curEd->ScrollToSelection(); } else { /*curEd->Complain();*/ } return this; } EntityTextEdList* EntityTextEdList::SearchBack(const char* string) { /* * Ibid. */ Regexp re(string); /* * Following code is straight from sted.c imple of search command. */ if (curEd->GetBuffer()->BackwardSearch(&re, curEd->Dot()) >= 0 || curEd->GetBuffer()->BackwardSearch( &re, curEd->GetBuffer()->BeginningOfText()) >= 0) { curEd->Select(re.EndOfMatch(), re.BeginningOfMatch()); curEd->ScrollToSelection(); } else { /*curEd->Complain();*/ } return this; } EntityTextEdList* EntityTextEdList:: GotoLine(int line) { /* * Goto the specified line in the current editor. Note no range checking. */ curEd->BeginningOfText(); curEd->ForwardLine(line); curEd->BeginningOfLine(); curEd->ScrollToSelection(); curEd->Select(curEd->Dot()); return this; } EntityTextEdList* EntityTextEdList::NewEditor(char* filename, int rows, int cols) { /* * Create a new, detached, text ed window and make it current. Its * contents are intially empty (later we may implement the filename parm, which * would cause the intial contents to be the file so named. */ return this; } EntityTextEdList* EntityTextEdList:: ReadonlyOn() { EntityTextEdListElem* el; while (el = Enum()) { el->GetData()->ReadonlyOn(); } return this; } EntityTextEdList* EntityTextEdList:: ReadonlyOff() { EntityTextEdListElem* el; while (el = Enum()) { el->GetData()->ReadonlyOff(); } return this; } Box* EntityTextEdList::InitialLayout() { VBox* edBox = new VBox(); edBox->Insert(new PaintLabel("Text:", "times", "bold", "r", "14")); edBox->Insert(new Frame(fixedEd)); return edBox; } /*** * Utility string-level operations. */ EntityTextEdListElem* EntityTextEdList::Find(const char* k) { return (EntityTextEdListElem*) List::Find((ListElemKey*) k); } int EntityTextEdList::FindPos(const char* k) { return List::FindPos((ListElemKey*) k); } EntityTextEdListElem* EntityTextEdList::DelNth(int n) { return (EntityTextEdListElem*) List::DelNth(n); } EntityTextEdListElem* EntityTextEdList::Enum() { return (EntityTextEdListElem*) List::Enum(); } EntityTextEdListElem::EntityTextEdListElem(EntityTextEd* ed) : data(ed) {} ListElemKey* EntityTextEdListElem::Key() { return (ListElemKey*) data->filename; } EntityTextEdListElem::KeyCompare(ListElemKey* key) { return strcmp(this->data->filename, (char*) key); } EntityTextEd* EntityTextEdListElem::GetData() { return data; } /* * New little puppies. void EntityTextEdListElem::ChangeEdName(origname, filename) { EntityTextEd* ed = Find(origname)-> */