9 extern int __ecereVMethodID_class_OnFree;
10 extern int __ecereVMethodID_class_OnGetString;
11 extern int __ecereVMethodID_class_OnGetDataFromString;
16 // #define _DEBUG_LINE
19 #define FULL_STRING_SEARCH
21 #define UTF8_IS_FIRST(x) (__extension__({ byte b = x; (!(b) || !((b) & 0x80) || ((b) & 0x40)); }))
22 #define UTF8_NUM_BYTES(x) (__extension__({ byte b = x; (b & 0x80 && b & 0x40) ? ((b & 0x20) ? ((b & 0x10) ? 4 : 3) : 2) : 1; }))
24 define newEntryStringDebug = $"New|id=";
25 define newEntryString = $"New";
27 public char ToASCII(unichar ch)
32 if(ch == 'À' || ch == 'Á' || ch == 'Â' || ch == 'Ã' || ch == 'Ä' || ch == 'Å')
36 else if(ch == 'È' || ch == 'É' || ch == 'Ê' || ch == 'Ë')
38 else if(ch == 'Ì' || ch == 'Í' || ch == 'Î' || ch == 'Ï')
42 else if(ch == 'Ò' || ch == 'Ó' || ch == 'Ô' || ch == 'Õ' || ch == 'Ö')
44 else if(ch == 'Ù' || ch == 'Ú' || ch == 'Û' || ch == 'Ü')
46 else if(ch == 'à' || ch == 'á' || ch == 'â' || ch == 'ã' || ch == 'ä' || ch == 'å')
50 else if(ch == 'è' || ch == 'é' || ch == 'ê' || ch == 'ë')
52 else if(ch == 'ì' || ch == 'í' || ch == 'î' || ch == 'ï')
56 else if(ch == 'ò' || ch == 'ó' || ch == 'ô' || ch == 'õ' || ch == 'ö')
58 else if(ch == 'ù' || ch == 'ú' || ch == 'û' || ch == 'ü')
66 public char * ConvertToASCII(const char * string, char * newString, int * len, bool lowerCase)
73 for(c = 0; (unich = UTF8GetChar(string + c, &nb)); c += nb)
75 char ch = ToASCII(unich);
77 newString[d++] = lowerCase ? (char)tolower(ch) : (char)ch;
85 public class NoCaseAccent : SQLCustomFunction
87 Array<char> array { minAllocSize = 1024 };
89 String function(String text)
91 int len = text ? strlen(text) : 0;
93 ConvertToASCII(text ? text : "", array.array, &len, true);
98 public class MemberStringSample
103 default extern int __ecereVMethodID_class_OnUnserialize;
105 public class GetMemberString<class NT:void * = MemberStringSample, name = NT::name> : NoCaseAccent
108 String function(NT pn)
110 return NoCaseAccent::function((pn && pn.name) ? pn.name : null);
114 // The old way is still possible...
115 SerialBuffer buffer { };
116 String function(void * ptr)
121 buffer.count = MAXINT;
123 ((void (*)(void *, void *, void *))(void *)class(NT)._vTbl[__ecereVMethodID_class_OnUnserialize])(class(NT), &pn, buffer);
124 result = NoCaseAccent::function((pn && pn.name) ? pn.name : null);
126 buffer.buffer = null;
128 // TOFIX: If we name GetName's type 'T', the following name confuses with Array's 'T'
129 //ConvertToASCII(s ? s : "", array.array, &len, true);
135 // Rename TableEditor to TableControl and move to eda/src/gui/controls
136 public class TableEditor : public Window
143 DebugLn("TableEditor::table|set");
146 get { return table; }
153 DebugLn("TableEditor::index|set");
155 filterRow.tbl = index;
157 get { return index; }
162 DebugLn("TableEditor::OnPostCreate");
170 InitFieldsBoxes(); // IMPORTANT: table must be set *AFTER* all related FieldEditors have been initialized
172 Field fldId = idField, fldName = stringField, fldActive = null;
173 FieldIndex indexedFields[1];
174 if(!idField) fldId = table.FindField(defaultIdField);
175 if(!fldName) fldName = table.FindField(defaultNameField);
176 if(!fldActive) fldActive = table.FindField(defaultActiveField);
177 indexedFields[0] = { fldId };
178 table.Index(1, indexedFields);
186 if(!listEnumerationTimer.hasCompleted)
188 if(list && !list.currentRow)
189 list.SelectRow(list.firstRow); // should the tableeditor select method be used here?
194 bool OnClose(bool parentClosing)
196 bool result = NotifyClosing();
205 property ListBox list
209 DebugLn("TableEditor::list|set");
214 property Array<ListField> listFields
218 DebugLn("TableEditor::listFields|set");
223 property int listSortOrder
225 set { listSortOrder = value; }
226 get { return listSortOrder; }
228 property DataField listSortField
230 set { listSortField = value; }
231 get { return listSortField; }
233 property bool disabledFullListing
235 set { disabledFullListing = value; }
236 get { return disabledFullListing; }
239 property Array<StringSearchField> searchFields
243 StringSearchTable searchTable { table, idField, value };
244 DebugLn("TableEditor::searchFields|set");
245 // The searchTables property will incref...
246 property::searchTables = { [ searchTable ] };
250 property Array<StringSearchTable> searchTables
254 // This API is not very clear on ownership of search tables array/search table/field...
255 // Right now both the array and tables themselves are incref'ed here
257 for(t : value) { incref t; }
258 DebugLn("TableEditor::searchTables|set");
259 if(searchTables) searchTables.Free();
261 searchTables = value;
265 property Array<SQLiteSearchTable> sqliteSearchTables
270 for(t : value) { incref t; }
271 DebugLn("TableEditor::searchTables|set");
272 if(sqliteSearchTables) sqliteSearchTables.Free();
273 delete sqliteSearchTables;
274 sqliteSearchTables = value;
278 property const String searchString
282 bool modified = modifiedDocument;
283 DebugLn("TableEditor::searchString|set");
284 switch(modified ? OnLeavingModifiedDocument() : no)
294 if(value && value[0])
295 searchString = CopyString(value);
301 property Array<LookupEditor> dynamicLookupEditors
305 DebugLn("TableEditor::dynamicLookupEditors|set");
306 dynamicLookupEditors = value;
311 property Id selectedId { get { return selectedId; } }
313 property Field idField
315 set { idField = value; }
316 get { return idField; }
318 property Field stringField
320 set { stringField = value; }
321 get { return stringField; }
323 property Field indexFilterField
325 set { indexFilterField = value; }
326 get { return indexFilterField; }
329 property bool readOnly
331 set { readOnly = value; }
332 get { return readOnly; }
335 virtual void OnInitialize();
336 virtual void OnLoad();
337 virtual void OnStateChanged();
339 void NotifyModifiedDocument()
341 DebugLn("TableEditor::NotifyModifiedDocument");
342 if(!internalModifications)
346 //virtual bool Window::NotifyNew(AltListSection listSection, Row r);
347 //virtual void Window::NotifyInitFields(AltEditSection editSection);
349 virtual DialogResult OnLeavingModifiedDocument()
351 DebugLn("TableEditor::OnLeavingModifiedDocument");
352 return MessageBox { master = this, type = yesNoCancel, text = text && text[0] ? text : $"Table Editor",
353 contents = $"You have modified this entry. Would you like to save it before proceeding?"
357 virtual bool OnRemovalRequest()
359 DebugLn("TableEditor::OnRemovalRequest");
360 return MessageBox { master = this, type = yesNo, text = text && text[0] ? text : $"Table Editor",
361 contents = $"You are about to permanently remove an entry.\n"
362 "Do you wish to continue?"
366 //virtual void Window::NotifyDeleting(ListSection listSection);
367 //virtual void Window::NotifyDeleted(ListSection listSection);
372 DebugLn("TableEditor::NotifyClosing");
375 switch(OnLeavingModifiedDocument())
389 StopWordListPrepTimer();
390 StopListEnumerationTimer();
395 //void List() // this gets called out of nowhere by some constructor thing...
398 DebugLn("TableEditor::Enumerate");
401 StopListEnumerationTimer();
405 if(list || OnList != TableEditor::OnList)
408 Array<Id> matches = null;
409 listEnumerationTimer.sqliteSearch = false;
410 if(searchTables && searchTables.count)
411 matches = SearchWordList();
412 //else if(sqliteSearchTables && sqliteSearchTables.count)
413 //matches = SearchSQLite();
414 else if(searchString && searchString[0] &&
415 sqliteSearchTables && sqliteSearchTables.count &&
416 sqliteSearchTables[0].table && sqliteSearchTables[0].idField &&
417 sqliteSearchTables[0].searchFields && sqliteSearchTables[0].searchFields.count &&
418 sqliteSearchTables[0].searchFields[0].field)
419 listEnumerationTimer.sqliteSearch = true;
420 if(matches && matches.count)
421 PrintLn("results count: ", matches.count);
426 modifiedDocument = false; // setting this here is not really logical, enumeration and modified have nothing to do with eachother
429 virtual void OnList(Row r, Array<Id> matches)
431 DebugLn("TableEditor::OnList");
432 if(!listEnumerationTimer.started)
434 listEnumerationTimer.hasCompleted = false;
435 listEnumerationTimer.matchesIndex = 0;
436 listEnumerationTimer.tablesIndex = 0;
437 if(!listEnumerationTimer.sqliteSearch)
438 listEnumerationTimer.row = Row { r.tbl };
441 listEnumerationTimer.matches = { };
442 // TOFIX: This (void *) cast here should NOT be required... Fix this Container warning:
443 // warning: incompatible expression matches (ecere::com::Array<eda::Id>); expected ecere::com::Container<T>
444 listEnumerationTimer.matches.Copy((void *)matches);
447 listEnumerationTimer.matches = null;
448 listEnumerationTimer.Start();
451 DebugLn("TableEditor::OnList -- timer state error");
454 virtual void OnCreateDynamicLookupEditors()
456 DebugLn("TableEditor::OnCreateLookupEditors");
457 if(dynamicLookupEditors && dynamicLookupEditors.count)
459 for(f : dynamicLookupEditors)
461 if(f.editorClass && f.parentWindow && f.lookupFindField)
463 Row row { f.lookupFindIndex ? f.lookupFindIndex : f.lookupFindField.table };
464 // todo: make this work for all types
466 editRow.GetData(f.lookupValueField, id);
467 // TODO: add alternative class instance for creation when no rows are found via lookup
468 for(row.Find(f.lookupFindField, middle, nil, id); !row.nil; row.Next())
470 // todo: make this work for all types, although this is meant to be an id field
472 TableEditor editor = eInstance_New(f.editorClass);
474 editor.parent = f.parentWindow;
475 editor.master = this;
476 dynamicLookupTableEditors.Add(editor);
478 row.GetData(f.lookupIdField, id);
487 property TableEditor masterEditor
491 if(value != masterEditor)
494 masterEditor.RemoveTableEditor(this);
495 masterEditor = value;
497 value.AddTableEditor(this);
500 get { return masterEditor; }
505 if(eClass_IsDerived(parent._class, class(TableEditor)))
506 property::masterEditor = (TableEditor)parent;
511 if(eClass_IsDerived(master._class, class(TableEditor)))
512 property::masterEditor = (TableEditor)master;
515 watch(modifiedDocument)
517 NotifyModifiedDocument();
522 DebugLn("TableEditor::CreateRow");
523 //list.NotifySelect(this, list, null, 0);
524 if(table && editRow && editRow.tbl && !modifiedDocument)
526 uint id; // = table.rowsCount + 1; // this is bad with deleted rows, won't work, how to have unique id?
527 // I think the 3 following comment lines apply to the old sqlite driver before many fix we done for wsms
528 Row r = editRow;// { table }; // the multipurpose row is buggy with sqlite driver, you can't use the same row to do Row::Last(), Row::Next(), Row::Find(), etc...
529 //Row r { editRow.tbl }; // for example, Row::Last() here is not using the proper sqlite statement and fails to
530 // return false when no rows are present in a table
534 /*uint count = editRow.tbl.GetRowsCount();
537 // r.Last() is returning true even if there are not rows in this table (SQLite)
538 if(count && !(r.Last() || r.Last()))
539 DebugLn("PROBLEM");*/
540 if(r.Last()) // this will reuse ids in cases where the item(s) with the last id have been deleted
542 r.GetData(idField, id);
552 // Patch for SQLite driver which auto-increments IDs
554 if(r.GetData(idField, curId))
557 r.SetData(idField, id);
560 r.SetData(fldActive, active);*/
564 newText = PrintString("[", newEntryStringDebug, id, "]");
566 newText = PrintString("[", newEntryString, "]");
569 //if(NotifyNew(master, this, r))
570 if(listFields && idField)
574 if(lf.dataField && lf.field)
576 if(lf.field.type == class(String))
577 r.SetData(lf.field, newText);
578 else // this whole block is new?
580 if(lf.field.type._vTbl[__ecereVMethodID_class_OnGetDataFromString])
582 Class dataType = lf.field.type;
583 int64 dataHolder = 0;
584 void * data = &dataHolder;
586 if(dataType && dataType.type == structClass)
588 dataHolder = (int64)(intptr)new0 byte[dataType.structSize];
589 data = (void *)(intptr)dataHolder;
591 /*else if(dataType && (dataType.type == noHeadClass || dataType.type == normalClass))
593 if(eClass_IsDerived(dataType, class(char*)))
594 dataHolder = (int64)CopyString("");
596 dataHolder = (int64)eInstance_New(dataType);
597 data = (void *)&dataHolder;
605 ((bool (*)(void *, void *, const char *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetDataFromString])(dataType, data, newText);
608 /*((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, dataHolder);
609 if(dataType.type == structClass)
611 void * dataPtr = (void *)dataHolder;
623 // have a better technique than Row::Next(); Row::Find(...); to make sure Row::GetData() will work right after a Row::SetData()?
624 // it seems we're missing Row::Update()
629 // next line is a patch for SQLite not returning data from GetData right after a SetData
630 if(idField && r.Find(idField, middle, nil, id))
631 SetListRowFields(r, row, false);
634 else if(idField && stringField)
636 r.SetData(stringField, newText);
639 row = list.AddString(newText);
649 list.Sort(listSortField, listSortOrder);
650 if(row) SelectListRow(row);
658 DebugLn("TableEditor::Remove");
659 if(editRow.sysID) //list && list.currentRow)
661 if(OnRemovalRequest())
665 list.DeleteRow(list.currentRow);
667 //NotifyDeleted(master, this);
669 SelectListRow(list.currentRow);
677 DebugLn("TableEditor::Load");
683 DebugLn("TableEditor::Write");
687 bool ListSelect(DataRow row)
690 DebugLn("TableEditor::ListSelect");
691 if(/*-row && -*/row != lastRow)
696 list.currentRow = lastRow;
698 switch(OnLeavingModifiedDocument())
706 list.currentRow = row;
710 if(list.currentRow == row)
719 DebugLn("TableEditor::Select");
720 // EDA is now set up so that Next()/Prev() will work with sysID = , but not with Find() (As Find() will return a particular set of results)
721 if(idField && editRow && (editRow.sysID = id, !editRow.nil))// && editRow.Find(idField, middle, nil, id))
723 selectedId = editRow.sysID;
735 DebugLn("TableEditor::Filter");
736 if(selectedId && index && indexFilterField)
738 for(filterRow.Find(indexFilterField, middle, nil, id); !filterRow.nil; filterRow.Next())
741 filterRow.GetData(idField, id2);
742 if(id2 == selectedId)
753 bool SelectNext(bool loopAround)
755 bool result = NotifyClosing();
756 bool wasNil = !editRow.sysID;
757 DebugLn("TableEditor::SelectNext");
762 if(!filterRow.Next() && loopAround)
764 //filterRow.First(); // Row::First doesn't behave properly in a filtered table
765 while(filterRow.Previous())
771 if(wasNil && filterRow.sysID == selectedId)
772 filterRow.Next(); // this whole wasNil thing makes no sense to me?
773 editRow.sysID = filterRow.sysID;
780 if(!editRow.Next() && loopAround)
785 selectedId = editRow.sysID;
794 bool SelectPrevious(bool loopAround)
796 bool result = NotifyClosing();
797 bool wasNil = !editRow.sysID;
798 DebugLn("TableEditor::SelectPrevious");
803 if(!filterRow.Previous() && loopAround)
805 //filterRow.Last(); // Row::Last doesn't behave properly in a filtered table
806 while(filterRow.Next())
808 filterRow.Previous();
812 if(wasNil && filterRow.sysID == selectedId)
813 filterRow.Previous(); // this whole wasNil thing makes no sense to me?
814 editRow.sysID = filterRow.sysID;
821 if(!editRow.Previous() && loopAround)
826 selectedId = editRow.sysID;
835 void SelectListRow(DataRow row)
837 // Time startTime = GetTime();
838 DebugLn("TableEditor::SelectListRow");
841 // TOFIX: Id is still 32-bit; Also the warning without this cast seems wrong (It says row.tag is of type eda::Id, while it is int64)
842 selectedId = (Id)row.tag;
845 if(list.currentRow != row)
846 list.currentRow = row;
847 if(idField && editRow.Find(idField, middle, nil, selectedId))
850 //NotifySelectListRow(master, this, selectedId);
854 // Logf("SelectListRow took %f seconds\n", GetTime() - startTime);
862 Field indexFilterField;
865 Array<StringSearchTable> searchTables;
866 Array<SQLiteSearchTable> sqliteSearchTables;
869 Map<Table, Lookup> lookups;
871 Array<LookupEditor> dynamicLookupEditors;
872 Array<FieldBox> fieldsBoxes { };
873 Array<TableEditor> tableEditors { };
874 Array<TableEditor> dynamicLookupTableEditors { };
877 bool internalModifications;
878 TableEditor masterEditor;
886 Array<char> searchCI { };
887 WordEntry letters[26];
888 WordEntry doubleLetters[26][26];
890 Array<ListField> listFields;
892 DataField listSortField;
893 bool disabledFullListing;
895 ListEnumerationTimer listEnumerationTimer
897 userData = this, delay = 0.1f;
900 static Time startTime;
903 Row row = listEnumerationTimer.row;
904 Array<Id> matches = listEnumerationTimer.matches;
905 Time delay = listEnumerationTimer.delay;
906 Time lastTime = GetTime();
907 static int slice = 128;
909 static int ticks = 0;
912 PrintLn("listing... ");
916 int index = listEnumerationTimer.matchesIndex;
917 if(listFields && idField)
919 for(c=0; c<slice && (next = index++<matches.count); c++)
921 if(row.Find(idField, middle, nil, matches[index]))
924 DataRow dataRow = list.AddRow();
925 row.GetData(idField, id);
927 SetListRowFields(row, dataRow, true);
930 DebugLn($"WordList match cannot be found in database.");
932 listEnumerationTimer.matchesIndex = index;
933 if(next) slice = Max(32, (int)(slice * (delay / (GetTime() - lastTime))));
935 else if(idField && stringField)
937 for(c=0; c<slice && (next = index++<matches.count); c++)
939 if(row.Find(idField, middle, nil, matches[index]))
943 row.GetData(idField, id);
944 row.GetData(stringField, s);
945 list.AddString(s).tag = id;
949 DebugLn($"WordList match cannot be found in database.");
951 listEnumerationTimer.matchesIndex = index;
952 if(next) slice = Max(32, (int)(slice * (delay / (GetTime() - lastTime))));
955 else if(listEnumerationTimer.sqliteSearch)
957 static SQLiteSearchTable st = null;
958 Row lookupRow { table };
959 Map<Id, int> uniques = listEnumerationTimer.uniques;
962 if(listEnumerationTimer.tablesIndex < sqliteSearchTables.count)
964 char queryString[4096*4];
966 if(!listEnumerationTimer.uniques)
967 listEnumerationTimer.uniques = uniques = { };
969 st = sqliteSearchTables[listEnumerationTimer.tablesIndex];
970 if(st.table && st.idField && st.searchFields && st.searchFields.count)
973 if(st.table && st.idField && st.searchFields && st.searchFields.count &&
974 st.searchFields[0].field)
979 listEnumerationTimer.row = row = { st.table };
982 int len = searchString ? strlen(searchString) : 0;
983 searchCI.size = len + 1;
984 ConvertToASCII(searchString ? searchString : "", searchCI.array, &len, true);
985 searchCI.count = len + 1;
988 sprintf(queryString, "SELECT ROWID, * FROM `%s`", st.table.name);
989 strcat(queryString, " WHERE ");
990 for(sf : st.searchFields)
995 strcat(queryString, " OR ");
996 #define PERSON_SEARCH_LIKE
997 // This code tries to implement the logic of PersonName::OnGetDataFromString because PersonName is inaccessible from here
998 if(strstr(sf.field.type.name, "PersonName"))
1000 #ifdef PERSON_SEARCH_LIKE
1001 String ln = null, fn = null, mn = null;
1002 char * comma = strchr(searchCI.array, ',');
1005 int len = comma - searchCI.array;
1006 ln = new char[len + 1];
1007 memcpy(ln, searchCI.array, len);
1010 fn = CopyString(comma+1);
1013 for(c = strlen(fn)-2; c > 0; c--)
1017 mn = CopyString(fn + c + 1);
1024 ln = CopyString(searchCI.array);
1027 TrimLSpaces(ln, ln);
1028 TrimRSpaces(ln, ln);
1032 TrimLSpaces(fn, fn);
1033 TrimRSpaces(fn, fn);
1037 TrimLSpaces(mn, mn);
1038 TrimRSpaces(mn, mn);
1041 /* We could simply do this if we had access to PersonName: (don't forget the delete pn; below)
1043 pn.OnGetDataFromString(searchCI.array);
1045 if(ln && !fn && !mn)
1047 // Only last name is pecified in search object, it is looked for in all fields
1048 strcatf(queryString, "(PNLastName(`%s`) LIKE '%%%s%%' OR PNFirstName(`%s`) LIKE '%%%s%%' OR PNMiddleName(`%s`) LIKE '%%%s%%')",
1049 sf.field.name, searchCI.array, sf.field.name, searchCI.array, sf.field.name, ln);
1051 else if(ln || fn || mn)
1053 // Otherwise search is in respective fields only (all specified must match)
1055 strcatf(queryString, "(");
1058 if(!first) strcatf(queryString, " AND ");
1060 strcatf(queryString, "PNLastName(`%s`) LIKE '%%%s%%'", sf.field.name, ln);
1064 if(!first) strcatf(queryString, " AND ");
1066 strcatf(queryString, "PNFirstName(`%s`) LIKE '%%%s%%'", sf.field.name, fn);
1070 if(!first) strcatf(queryString, " AND ");
1072 strcatf(queryString, "PNMiddleName(`%s`) LIKE '%%%s%%'", sf.field.name, mn);
1074 strcatf(queryString, ")");
1077 delete ln; delete fn; delete mn;
1079 // To use CompPersonName::OnCompare:
1080 strcatf(queryString, "`%s` = ?", sf.field.name);
1084 strcatf(queryString, "`%s` LIKE '%%%s%%'", sf.field.name, searchString);
1088 PrintLn(queryString);
1089 startTime = GetTime();
1090 row.query = queryString;
1091 #ifndef PERSON_SEARCH_LIKE
1092 // To use CompPersonName::OnCompare:
1093 for(sf : st.searchFields)
1097 if(strstr(sf.field.type.name, "PersonName"))
1100 ((bool (*)(void *, void *, const char *))(void *)sf.field.type._vTbl[__ecereVMethodID_class_OnGetDataFromString])(sf.field.type, &pn, searchCI.array);
1101 row.SetQueryParamObject(++bindId, pn, sf.field.type);
1117 if(listFields && idField)
1119 // should we not start with a Next() ??? :S -- right now, query = does not need a Next(), unless it had parameters (SetQueryParam), See #591
1120 // when going through all the rows in a table you always start with Next() no?
1121 // is this different for query results?
1122 for(c = 0, next = !row.nil; c<slice && next; c++, next = row.Next())
1125 row.GetData(st.idField, id);
1126 //if(uniques[id]++ == 0)
1127 if(uniques[id] == 0)
1129 DataRow dataRow = list.AddRow();
1131 if(st.table == table)
1132 SetListRowFields(row, dataRow, true);
1133 else if(lookupRow.Find(idField, middle, nil, id))
1134 SetListRowFields(lookupRow, dataRow, true);
1138 uniques[id] = uniques[id] + 1;
1140 if(next) slice = Max(32, (int)(slice * (delay / (GetTime() - lastTime))));
1143 delete listEnumerationTimer.row; row = null;
1144 next = ++listEnumerationTimer.tablesIndex < sqliteSearchTables.count;
1147 else if(idField && stringField)
1149 // should we not start with a Next() ??? :S
1150 // when going through all the rows in a table you always start with Next() no?
1151 // is this different for query results?
1152 for(c = 0, next = !row.nil; c<slice && next; c++, next = row.Next())
1155 row.GetData(st.idField, id);
1156 //if(uniques[id]++ == 0)
1157 if(uniques[id] == 0)
1160 if(st.table == table)
1161 row.GetData(stringField, s);
1162 else if(lookupRow.Find(idField, middle, nil, id))
1163 lookupRow.GetData(stringField, s);
1166 list.AddString(s).tag = id;
1169 uniques[id] = uniques[id] + 1;
1171 if(next) slice = Max(32, (int)(slice * (delay / (GetTime() - lastTime))));
1174 delete listEnumerationTimer.row; row = null;
1175 next = ++listEnumerationTimer.tablesIndex < sqliteSearchTables.count;
1181 else if(!disabledFullListing)
1183 if(listFields && idField)
1185 for(c = 0; c<slice && (next = row.Next()); c++)
1188 DataRow dataRow = list.AddRow();
1189 row.GetData(idField, id);
1191 SetListRowFields(row, dataRow, true);
1192 //app.UpdateDisplay();
1194 if(next) slice = Max(32, (int)(slice * (delay / (GetTime() - lastTime))));
1196 else if(idField && stringField)
1198 for(c = 0; c<slice && (next = row.Next()); c++)
1202 row.GetData(idField, id);
1203 row.GetData(stringField, s);
1204 list.AddString(s).tag = id;
1207 if(next) slice = Max(32, (int)(slice * (delay / (GetTime() - lastTime))));
1211 list.Sort(listSortField, listSortOrder);
1215 listEnumerationTimer.hasCompleted = true;
1216 StopListEnumerationTimer();
1218 if(startTime) PrintLn("*** Search took ", (uint)((GetTime() - startTime) * 1000), "ms ***");
1223 void StopListEnumerationTimer()
1225 listEnumerationTimer.Stop();
1226 listEnumerationTimer.matchesIndex = 0;
1227 listEnumerationTimer.tablesIndex = 0;
1228 delete listEnumerationTimer.row;
1229 delete listEnumerationTimer.matches;
1230 delete listEnumerationTimer.uniques;
1233 WordListPrepTimer wordListPrepTimer
1235 userData = this, delay = 0.1f;
1239 Row row = wordListPrepTimer.row;
1240 static int slice = 512;
1241 static StringSearchTable st = null;
1243 static int wordListPrepRowCount = 0, wordListPrepRowNum = 0, ticks = 0;
1247 if(wordListPrepTimer.tablesIndex < searchTables.count)
1249 st = searchTables[wordListPrepTimer.tablesIndex];
1250 if(st.table && st.idField && st.searchFields && st.searchFields.count)
1252 wordListPrepRowNum = 0;
1253 wordListPrepRowCount = st.table.rowsCount;
1255 wordListPrepTimer.row = row = { st.table };
1256 DebugLn("building word list for ", st.table.name, " table ------------------------------------- ");
1263 Time delay = wordListPrepTimer.delay;
1264 Time lastTime = GetTime();
1268 PrintLn("indexing ", wordListPrepRowNum, " of ", wordListPrepRowCount, " --- slice is ", slice);
1270 for(c = 0; c<slice && (next = row.Next()); c++)
1273 row.GetData(st.idField, id);
1275 wordListPrepRowNum++;
1277 for(sf : st.searchFields)
1279 Field field = sf.field;
1280 StringSearchIndexingMethod method = sf.method;
1281 if(field && field.type == class(String))
1283 String string = null;
1284 row.GetData(field, string);
1286 if(string && string[0])
1287 ProcessWordListString(string, method, id);
1290 // todo: need to improve on this...
1291 // else ... call OnGetString of type ... etc...
1292 //PrintLn("todo: support other field types for string search");
1293 else if(field && field.type)
1295 char tempString[MAX_F_STRING];
1297 Class type = field.type;
1299 if(type.type == unitClass && !type.typeSize)
1301 Class dataType = eSystem_FindClass(type.module, type.dataTypeString);
1305 if(type.type == structClass)
1306 data = (int64)(intptr)new0 byte[type.structSize];
1307 ((bool (*)())(void *)row.GetData)(row, field, type, (type.type == structClass) ? (void *)(intptr)data : &data);
1309 if(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass)
1310 s = ((char *(*)(void *, void *, char *, void *, bool *))(void *)field.type._vTbl[__ecereVMethodID_class_OnGetString])(field.type, &data, tempString, null, null);
1312 s = ((char *(*)(void *, void *, char *, void *, bool *))(void *)field.type._vTbl[__ecereVMethodID_class_OnGetString])(field.type, (void *)(intptr)data, tempString, null, null);
1315 ProcessWordListString(s, method, id);
1317 if(!(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass))
1318 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)(intptr)data);
1319 if(type.type == structClass)
1320 delete (void *)(intptr)data;
1324 if(next) slice = Max(32, (int)(slice * (delay / (GetTime() - lastTime))));
1327 delete wordListPrepTimer.row; row = null;
1328 next = ++wordListPrepTimer.tablesIndex < searchTables.count;
1334 char filePath[MAX_FILENAME];
1337 sprintf(filePath, "%s.search", table.name);
1338 // this doesn't want to work? :S :S :S
1340 f = FileOpenBuffered(filePath, read);
1347 wordListPrepTimer.hasCompleted = true;
1348 StopWordListPrepTimer();
1354 void StopWordListPrepTimer()
1356 wordListPrepTimer.Stop();
1357 wordListPrepTimer.tablesIndex = 0;
1358 delete wordListPrepTimer.row;
1363 DebugLn("TableEditor::~()");
1365 fieldsBoxes.Free(); // TOCHECK: do I need to delete each to oppose the incref in AddFieldBox? -- Free() does just that
1366 delete searchString;
1371 delete dynamicLookupEditors;
1372 delete dynamicLookupTableEditors;
1373 if(searchTables) searchTables.Free();
1374 delete searchTables;
1375 if(sqliteSearchTables) sqliteSearchTables.Free();
1376 delete sqliteSearchTables;
1379 void ResetListFields()
1381 DebugLn("TableEditor::ResetListFields");
1382 if(list && listFields && listFields.count)
1385 for(lf : listFields)
1387 list.AddField(lf.dataField);
1388 incref lf.dataField;
1393 void AddTableEditor(TableEditor tableEditor)
1395 DebugLn("TableEditor::AddTableEditor");
1396 if(!tableEditors.Find(tableEditor))
1398 tableEditors.Add(tableEditor);
1402 DebugLn(" TableEditor instance already added");
1405 void RemoveTableEditor(TableEditor tableEditor)
1407 Iterator<TableEditor> it { tableEditors };
1408 DebugLn("TableEditor::RemoveTableEditor");
1409 if(it.Find(tableEditor))
1411 it.Remove(); // tableEditors.Remove(it.pointer); // <-- any reason why we would want to do that instead? -- It's the same.
1412 delete tableEditor; // AddTableEditor increfs...
1415 DebugLn(" TableEditor instance not found, no need to remove");
1418 void AddFieldBox(FieldBox fieldBox)
1420 // I was putting this here to force autosize on the lists (e.g. the Radiologists fields):
1422 if(!fieldBox.autoSize)
1423 fieldBox.autoSize = true;
1425 DebugLn("TableEditor::AddFieldBox");
1426 if(!fieldsBoxes.Find(fieldBox))
1428 fieldsBoxes.Add(fieldBox);
1434 DebugLn(" FieldBox instance already added");
1437 void RemoveFieldBox(FieldBox fieldBox)
1439 Iterator<FieldBox> it { fieldsBoxes };
1440 DebugLn("TableEditor::RemoveFieldBox");
1441 if(it.Find(fieldBox))
1443 it.Remove(); // fieldsBoxes.Remove(it.pointer); // <-- any reason why we would want to do that instead? -- It's the same.
1446 DebugLn(" FieldBox instance not found, no need to remove");
1449 void InitFieldsBoxes()
1451 DebugLn("TableEditor::InitFieldsBoxes");
1454 for(fb : fieldsBoxes)
1462 for(fb : fieldsBoxes)
1465 //NotifyInitFields(master, this);
1470 DebugLn("TableEditor::EditNew");
1472 modifiedDocument = false;
1477 DebugLn("TableEditor::EditSave");
1478 internalModifications = true;
1479 for(fb : fieldsBoxes)
1482 if(idField && list && listFields && listFields.count)
1484 DataRow listRow = list.currentRow;
1485 // ADDED THIS HERE FOR SQLITE TO REFRESH
1486 editRow.Find(idField, middle, nil, listRow.tag);
1487 SetListRowFields(editRow, listRow, false);
1488 list.Sort(listSortField, listSortOrder);
1490 internalModifications = false;
1492 for(te : tableEditors)
1495 modifiedDocument = false;
1501 Id selId = selectedId;
1502 DebugLn("TableEditor::EditLoad");
1506 internalModifications = true;
1512 lu.row = { lu.findIndex ? lu.findIndex : lu.findField.table };
1513 if(lu.valueField && eClass_IsDerived(lu.valueField.type, class(Id)) &&
1514 lu.findField && eClass_IsDerived(lu.findField.type, class(Id)))
1517 editRow.GetData(lu.valueField, id);
1518 lu.row.Find(lu.findField, middle, nil, id);
1522 for(fb : fieldsBoxes)
1524 OnCreateDynamicLookupEditors();
1525 internalModifications = false;
1526 size = size; // This seems to be required to fix autoSize on entering order screen
1528 DebugLn(" TODO: implement virtual method TableEditor::OnSubEditorsLoad");
1530 modifiedDocument = false;
1536 DebugLn("TableEditor::EditClear");
1538 internalModifications = true;
1539 for(fb : fieldsBoxes)
1541 for(e : dynamicLookupTableEditors)
1543 for(e : tableEditors)
1545 tableEditors.Free();
1546 dynamicLookupTableEditors.Free();
1547 //dynamicLookupTableEditors.size = 0;
1548 internalModifications = false;
1550 DebugLn(" TODO: remove all sub table editors");
1552 modifiedDocument = false;
1556 void SetListRowFields(Row dbRow, DataRow listRow, bool restoreSelection)
1558 // DebugLn("TableEditor::SetListRowFields");
1559 for(lf : listFields)
1561 if(lf.dataField && lf.field)
1563 if(eClass_IsDerived(lf.field.type, class(char*)))
1566 dbRow.GetData(lf.field, s);
1567 listRow.SetData(lf.dataField, s);
1570 else if(eClass_IsDerived(lf.field.type, class(Id)))
1576 dbRow.GetData(lf.field, id);
1577 s = lf.CustomLookup(id);
1578 listRow.SetData(lf.dataField, s);
1581 else if(lf.lookupFindField && (lf.lookupFindIndex || lf.lookupFindField.table) && lf.lookupValueField &&
1582 eClass_IsDerived(lf.lookupFindField.type, class(Id)) &&
1583 eClass_IsDerived(lf.lookupValueField.type, class(char*)))
1587 Row lookupRow { lf.lookupFindIndex ? lf.lookupFindIndex : lf.lookupFindField.table };
1588 dbRow.GetData(lf.field, id);
1589 if(lookupRow.Find(lf.lookupFindField, middle, nil, id))
1590 lookupRow.GetData(lf.lookupValueField, s);
1591 listRow.SetData(lf.dataField, s);
1596 else if(lf.CustomLookup && lf.field.type)
1600 Class type = lf.field.type;
1601 if(type.type == unitClass && !type.typeSize)
1603 Class dataType = eSystem_FindClass(type.module, type.dataTypeString);
1607 if(type.type == structClass)
1608 data = (int64)(intptr)new0 byte[type.structSize];
1609 ((bool (*)())(void *)dbRow.GetData)(dbRow, lf.field, type, (type.type == structClass) ? (void *)(intptr)data : &data);
1610 s = lf.CustomLookup((int)data);
1611 listRow.SetData(lf.dataField, s);
1612 if(!(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass))
1613 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)(intptr)data);
1614 if(type.type == structClass)
1615 delete (void *)(intptr)data;
1618 else if(lf.field.type && eClass_IsDerived(lf.dataField.dataType, class(char*)))
1620 char tempString[MAX_F_STRING];
1622 Class type = lf.field.type;
1624 if(type.type == unitClass && !type.typeSize)
1626 Class dataType = eSystem_FindClass(type.module, type.dataTypeString);
1630 if(type.type == structClass)
1631 data = (int64)(intptr)new0 byte[type.structSize];
1632 ((bool (*)())(void *)dbRow.GetData)(dbRow, lf.field, type, (type.type == structClass) ? (void *)(intptr)data : &data);
1633 if(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass)
1634 s = ((char *(*)(void *, void *, char *, void *, bool *))(void *)lf.field.type._vTbl[__ecereVMethodID_class_OnGetString])(lf.field.type, &data, tempString, null, null);
1636 s = ((char *(*)(void *, void *, char *, void *, bool *))(void *)lf.field.type._vTbl[__ecereVMethodID_class_OnGetString])(lf.field.type, (void*)(intptr)data, tempString, null, null);
1638 listRow.SetData(lf.dataField, s);
1640 if(!(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass))
1641 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)(intptr)data);
1642 if(type.type == structClass)
1643 delete (void *)(intptr)data;
1645 else if(lf.field.type)
1647 //char tempString[256];
1649 Class type = lf.field.type;
1650 if(type.type == unitClass && !type.typeSize)
1652 Class dataType = eSystem_FindClass(type.module, type.dataTypeString);
1656 if(type.type == structClass)
1657 data = (int64)(intptr)new0 byte[type.structSize];
1658 ((bool (*)())(void *)dbRow.GetData)(dbRow, lf.field, type, (type.type == structClass) ? (void *)(intptr)data : &data);
1659 if(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass)
1660 listRow.SetData(lf.dataField, (void *)&data);
1662 listRow.SetData(lf.dataField, (void *)(intptr)data);
1663 if(!(type.type == systemClass || type.type == unitClass || type.type == bitClass || type.type == enumClass))
1664 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)(intptr)data);
1665 if(type.type == structClass)
1666 delete (void *)(intptr)data;
1670 if(restoreSelection && !list.currentRow)
1673 if((select = list.FindRow(selectedId)))
1674 SelectListRow(select);
1678 Array<Id> SearchWordList()
1680 DebugLn("TableEditor::SearchWordList");
1681 #ifdef FULL_STRING_SEARCH
1686 WordEntry entries[256];
1687 Array<Id> results = null;
1688 if(searchTables && searchTables.count && searchString && searchString[0])
1690 char * searchCopy = CopyString(searchString);
1691 numTokens = TokenizeWith(searchCopy, sizeof(words) / sizeof(char *), words, " ',/-;[]{}", false);
1692 for(c = 0; c<numTokens; c++)
1695 entries[c] = (WordEntry)wordTree.FindString(words[c]);
1705 Map<Id, int> matches { };
1706 Map<Id, int> uniques { };
1707 MapNode<Id, int> mn;
1709 for(c = 0; c<numTokens; c++)
1711 if(entries[c] && entries[c].items && entries[c].items.count)
1713 for(i = 0; i<entries[c].items.count; i++)
1716 int count = uniques[entries[c].items.ids[i]];
1720 matches[entries[c].items.ids[i]]++;
1725 for(mn = matches.root.minimum; mn; mn = mn.next)
1728 results.Add(mn.key);
1734 else if(numTokens == 1)
1737 if(entries[0] && entries[0].items && entries[0].items.count)
1739 for(c = 0; c<entries[0].items.count; c++)
1740 results.Add(entries[0].items.ids[c]);
1752 // find a way to not load a tree for different searchFields
1753 // if the code that sets the searchFields has changed
1754 // store a search index signature containing following:
1755 // tables name, idField name and type, fields name and type
1756 void PrepareWordList()
1758 DebugLn("TableEditor::PrepareWordList");
1759 #ifdef FULL_STRING_SEARCH
1761 char filePath[MAX_FILENAME];
1764 sprintf(filePath, "%s.search", table.name);
1765 f = FileOpenBuffered(filePath, read);
1772 for(a = 0; a<26; a++)
1776 word[0] = 'a' + (char)a;
1779 letters[a] = (WordEntry)wordTree.FindString(word);
1780 for(b = 0; b<26; b++)
1782 word[1] = 'a' + (char)b;
1783 doubleLetters[a][b] = (WordEntry)wordTree.FindString(word);
1787 else if(searchTables && searchTables.count)
1792 for(a = 0; a<26; a++)
1796 word[0] = 'a' + (char)a;
1799 wordTree.Add((BTNode)(letters[a] = WordEntry { string = CopyString(word) }));
1800 for(b = 0; b<26; b++)
1802 word[1] = 'a' + (char)b;
1803 wordTree.Add((BTNode)(doubleLetters[a][b] = WordEntry { string = CopyString(word) }));
1808 wordListPrepTimer.tablesIndex = 0;
1809 wordListPrepTimer.Start();
1815 void ProcessWordListString(char * string, StringSearchIndexingMethod method, Id id)
1824 char asciiWord[1024];
1826 for(c = 0; ; c += nb)
1828 ch = UTF8GetChar(string + c, &nb);
1830 if(!ch || CharMatchCategories(ch, separators) ||
1831 (count && CharMatchCategories(ch, letters|numbers|marks|connector) != CharMatchCategories(lastCh, letters|numbers|marks|connector)))
1836 asciiWord[numChars] = 0;
1840 AddWord(word, count, method == allSubstrings, id);
1841 if(count > numChars)
1842 AddWord(asciiWord, strlen(asciiWord), method == allSubstrings, id);
1846 if(!CharMatchCategories(ch, separators))
1849 for(cc = 0; cc < nb; cc++)
1850 word[count++] = string[c + cc];
1852 asciiWord[numChars++] = ToASCII(ch);
1860 for(cc = 0; cc < nb; cc++)
1861 word[count++] = string[c + cc];
1863 asciiWord[numChars++] = ToASCII(ch);
1869 /*static */WordEntryBinaryTree wordTree
1871 CompareKey = (void *)BinaryTree::CompareString;
1872 FreeKey = BinaryTree::FreeString;
1875 void AddWord(char * word, int count, bool addAllSubstrings, Id id)
1877 //DebugLn("TableEditor::AddWord");
1878 #ifdef FULL_STRING_SEARCH
1880 if(addAllSubstrings)
1883 WordEntry mainEntry = null;
1884 WordEntry sEntry = null;
1886 for(s = 0; s < count; s += UTF8_NUM_BYTES(word[s]))
1891 WordEntry lEntry = null;
1892 memcpy(subWord, word + s, count-s);
1893 subWord[count-s] = 0; // THIS IS REQUIRED!! THE WHILE LOOP BELOW CHECKED count-s FIRST!!
1896 for(l = count-s; l>0; l--)
1898 WordEntry start = null, wordEntry;
1900 while(l > 0 && !UTF8_IS_FIRST(subWord[l])) l--;
1905 if(ch1 >= 'a' && ch1 <= 'z')
1907 char ch2 = subWord[1];
1908 if(count - s > 1 && ch2 >= 'a' && ch2 <= 'z')
1910 char ch2 = subWord[1];
1911 start = doubleLetters[ch1 - 'a'][ch2 - 'a'];
1915 start = letters[ch1 - 'a'];
1922 while(start && (max = (WordEntry)((BTNode)start).maximum))
1924 if(strcmp(max.string, subWord) >= 0)
1926 start = start.parent;
1931 start = (WordEntry)wordTree.root;
1933 if((wordEntry = (WordEntry)((BTNode)start).FindString(subWord)))
1939 wordTree.Add((BTNode)(wordEntry = WordEntry { string = CopyString(subWord) }));
1943 mainEntry = wordEntry;
1951 if(!wordEntry.words) wordEntry.words = IdList { };
1952 wordEntry.words.Add((Id)(uintptr)mainEntry);
1957 if(!wordEntry.words) wordEntry.words = IdList { };
1958 wordEntry.words.Add((Id)(uintptr)sEntry);
1962 if(!wordEntry.words) wordEntry.words = IdList { };
1963 wordEntry.words.Add((Id)(uintptr)lEntry);
1965 if(!wordEntry.items) wordEntry.items = IdList { };
1966 wordEntry.items.Add(id);
1972 WordEntry wordEntry;
1973 if(!(wordEntry = (WordEntry)(wordTree.root).FindString(word)))
1974 wordTree.Add((BTNode)(wordEntry = WordEntry { string = CopyString(word) }));
1975 if(!wordEntry.items) wordEntry.items = IdList { };
1976 wordEntry.items.Add(id);
1983 public class ListField : struct
1987 DataField dataField;
1988 Field lookupFindField;
1989 Field lookupValueField;
1990 Table lookupFindIndex;
1991 String (*CustomLookup)(Id);
2016 public class LookupEditor : struct
2019 subclass(TableEditor) editorClass;
2020 Window parentWindow;
2021 Field lookupValueField;
2022 Field lookupFindField;
2023 Field lookupIdField;
2024 Table lookupFindIndex;
2027 // all methods currently perform ascii conversion and all that jazz on every string added to the index
2028 public enum StringSearchIndexingMethod { fullString, allSubstrings };
2030 public class StringSearchField
2034 StringSearchIndexingMethod method;
2036 Field lookupFindField;
2037 Field lookupValueField;
2039 //String (*CustomRead)(Id);
2042 public class StringSearchTable
2047 Array<StringSearchField> searchFields;
2050 ~StringSearchTable()
2052 delete searchFields;
2056 public class SQLiteSearchField
2060 //StringSearchIndexingMethod method;
2063 public class SQLiteSearchTable
2068 Array<SQLiteSearchField> searchFields;
2071 ~SQLiteSearchTable()
2073 delete searchFields;
2077 static WordEntry * btnodes;
2079 struct WordEntryBinaryTree : BinaryTree
2081 WordEntry * entries;
2083 void OnSerialize(IOChannel channel)
2087 DebugLn("WordEntryBinaryTree::OnSerialize");
2088 for(id = 1, node = (WordEntry)root; node;)
2095 else if(node.parent)
2097 bool isLeft = node == node.parent.left;
2102 if(isLeft && node.right)
2108 isLeft = node == node.parent.left;
2117 channel.Serialize(id);
2118 channel.Serialize((WordEntry)root);
2121 void OnUnserialize(IOChannel channel)
2123 WordEntry root, node;
2125 DebugLn("WordEntryBinaryTree::OnUnserialize");
2126 channel.Unserialize(count);
2127 entries = new WordEntry[count];
2129 channel.Unserialize(root);
2130 this.root = (BTNode)root;
2131 // count = root ? this.root.count : 0;
2133 for(node = (WordEntry)root; node;)
2138 for(c = 0; c<node.words.count; c++)
2139 node.words.ids[c] = (Id)(uintptr)btnodes[node.words.ids[c] - 1];
2145 else if(node.parent)
2147 bool isLeft = node == node.parent.left;
2152 if(isLeft && node.right)
2158 isLeft = node == node.parent.left;
2170 class WordEntry : struct
2174 WordEntry left, right;
2187 void OnSerialize(IOChannel channel)
2189 #ifdef FULL_STRING_SEARCH
2192 channel.Serialize(id);
2193 channel.Serialize(string);
2194 channel.Serialize(items);
2199 channel.Serialize(words.count);
2200 for(c = 0; c < words.count; c++)
2202 uint id = (uint)((WordEntry)(uintptr)words.ids[c]).id;
2203 channel.Serialize(id);
2209 channel.Serialize(none);
2212 // channel.Serialize(words);
2213 channel.Serialize(left);
2214 channel.Serialize(right);
2219 channel.Serialize(nothing);
2224 void OnUnserialize(IOChannel channel)
2226 #ifdef FULL_STRING_SEARCH
2228 channel.Unserialize(id);
2232 // TODO: Fix typed_object issues
2233 entry = btnodes[id - 1] = eInstance_New(class(WordEntry));
2234 this = (void *)entry;
2236 channel.Unserialize(string);
2237 channel.Unserialize(items);
2238 channel.Unserialize(words);
2240 channel.Unserialize(left);
2241 if(left) { left.parent = (void *)this; }
2242 channel.Unserialize(right);
2243 if(right) { right.parent = (void *)this; }
2245 // TODO: Precomp errors without extra brackets
2246 depth = ((BTNode)((void *)this)).depthProp;
2255 class ListEnumerationTimer : Timer
2263 Map<Id, int> uniques;
2266 class WordListPrepTimer : Timer
2274 class EnumerateThread : Thread
2293 bool abort, abortNow;
2300 //if(app.ProcessInput(true))
2303 Row r { editor.table };
2307 if(editor.listFields && editor.idField)
2309 /*for(c=0; c<matches.count && !abort; c++)
2311 if(r.Find(editor.idField, middle, nil, matches[c]))
2316 row = editor.list.AddRow();
2317 r.GetData(editor.idField, id);
2319 editor.SetListRowFields(r, row, true);
2323 DebugLn($"WordList match cannot be found in database.");
2326 else if(editor.idField && editor.stringField)
2328 /*for(c=0; c<matches.count && !abort; c++)
2330 if(r.Find(editor.idField, middle, nil, matches[c]))
2334 r.GetData(editor.idField, id);
2335 r.GetData(editor.stringField, s);
2337 editor.list.AddString(s).tag = id;
2342 DebugLn($"WordList match cannot be found in database.");
2348 else if(!editor.disabledFullListing)
2350 if(editor.listFields && editor.idField)
2353 while(r.Next() && !abort)
2358 r.GetData(editor.idField, id);
2359 //if(app.ProcessInput(true))
2363 row = editor.list.AddRow();
2365 editor.SetListRowFields(r, row, true);
2370 else if(editor.idField && editor.stringField)
2372 /*while(r.Next() && !abort)
2377 r.GetData(editor.idField, id);
2378 r.GetData(editor.stringField, s);
2379 editor.list.AddString(s).tag = id;
2391 editor.list.Sort(editor.listSortField, editor.listSortOrder);
2410 editor.list.Update(null);
2411 //app.Wait(); // Sleep(0.2f);
2412 //if(app.ProcessInput(true))
2415 //app.UpdateDisplay();
2422 static define app = ((GuiApplication)__thisModule);
2424 static inline void DebugLn(typed_object object, ...)
2426 #if defined(_DEBUG_LINE)
2429 va_start(args, object);
2430 PrintStdArgsToBuffer(buffer, sizeof(buffer), object, args);