3 // *** Color Schemes ***
5 // *** The Old Color Scheme that was causing me auras and ophtalmic migraines -- Uncomment at your own risk! ***
7 FontResource panelFont { "Courier New", 10 };
8 FontResource codeFont { "Courier New", 10 };
9 Color selectionColor = Color { 10, 36, 106 };
10 Color selectionText = white;
11 Color viewsBackground = white;
12 Color viewsText = black;
13 Color outputBackground = white;
14 Color outputText = black;
15 Color projectViewBackground = white;
16 Color projectViewText = black;
17 Color codeEditorBG = white;
18 Color codeEditorFG = black;
19 Color marginColor = Color {230, 230, 230};
20 Color selectedMarginColor = Color {200, 200, 200};
21 Color lineNumbersColor = Color {60, 60, 60};
22 SyntaxColorScheme colorScheme
24 keywordColors = [ blue, blue ];
25 commentColor = dimGray;
26 charLiteralColor = crimson;
27 stringLiteralColor = crimson;
28 preprocessorColor = green;
33 // The new nice dark scheme -- so peaceful on my brain
35 FontResource panelFont { "Courier New", 10 };
36 FontResource codeFont { "Courier New", 10 };
38 FontResource panelFont { "Consolas", 10.5f };
39 FontResource codeFont { "Consolas", 10.5f };
41 Color selectionColor = lightYellow;
42 Color selectionText = Color { 30, 40, 50 };
43 Color viewsBackground = Color { 30, 40, 50 };
44 Color viewsText = lightGray;
45 Color outputBackground = black;
46 Color outputText = lime;
47 Color projectViewBackground = Color { 30, 40, 50 };
48 Color projectViewText = lightGray;
49 Color codeEditorBG = black;
50 Color codeEditorFG = ivory;
51 Color marginColor = Color {24, 24, 24};
52 Color selectedMarginColor = Color {64, 64, 64};
53 Color lineNumbersColor = Color {160, 160, 160};
54 SyntaxColorScheme colorScheme
56 keywordColors = [ skyBlue, skyBlue ];
57 commentColor = Color { 125, 125, 125 };
58 charLiteralColor = Color { 245, 50, 245 };
59 stringLiteralColor = Color { 245, 50, 245 };
60 preprocessorColor = { 120, 220, 140 };
61 numberColor = Color { 0, 192, 192 };
64 // *********************
70 // UNTIL IMPLEMENTED IN GRAMMAR
71 #define ACCESS_CLASSDATA(_class, baseClass) \
72 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
75 extern int __attribute__((__stdcall__)) __ecereDll_Load_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
76 extern int __attribute__((__stdcall__)) __ecereDll_Unload_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
79 static Array<FileFilter> fileFilters
81 { $"C/C++/eC Files (*.ec, *.eh, *.c, *.cpp, *.cc, *.cxx, *.h, *.hpp, *.hh, *.hxx)", "ec, eh, c, cpp, cc, cxx, h, hpp, hh, hxx" },
82 { $"Header Files for C/C++ (*.eh, *.h, *.hpp, *.hh, *.hxx)", "eh, h, hpp, hh, hxx" },
83 { $"C/C++/eC Source Files (*.ec, *.c, *.cpp, *.cc, *.cxx)", "ec, c, cpp, cc, cxx" },
84 { $"Text files (*.txt)", "txt" },
85 { $"All files", null }
88 static Array<FileType> fileTypes
90 { $"eC Source Code", "ec", whenNoneGiven },
91 { $"Text Files", "txt", never }
94 static char * iconNames[] =
96 "<:ecere>constructs/class.png",
97 "<:ecere>constructs/data.png",
98 "<:ecere>constructs/method.png",
99 "<:ecere>constructs/event.png",
100 "<:ecere>constructs/property.png",
101 "<:ecere>constructs/namespace.png",
102 "<:ecere>constructs/dataType.png",
103 "<:ecere>constructs/enumValue.png",
104 "<:ecere>constructs/dataPrivate.png",
105 "<:ecere>constructs/methodPrivate.png",
106 "<:ecere>constructs/propertyPrivate.png"
109 enum SheetType { methods, properties };
111 extern int __ecereVMethodID_class_OnEdit;
112 extern int __ecereVMethodID_class_OnDisplay;
113 extern int __ecereVMethodID_class_OnGetString;
114 extern int __ecereVMethodID_class_OnFree;
115 extern int __ecereVMethodID_class_OnCompare;
116 extern int __ecereVMethodID_class_OnCopy;
117 extern int __ecereVMethodID_class_OnSaveEdit;
118 extern int __ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad;
120 class EditFileDialog : FileDialog
124 if(!ide.projectView && ideSettings.ideFileDialogLocation)
125 currentDirectory = ideSettings.ideFileDialogLocation;
126 return FileDialog::OnCreate();
130 EditFileDialog codeEditorFileDialog
132 type = multiOpen, text = $"Open",
133 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType);
134 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
137 EditFileDialog codeEditorFormFileDialog
139 type = open, text = $"Open Project",
140 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType),
141 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
144 define OpenBracket = '{';
145 define CloseBracket = '}';
150 actionDeleteMethod = 2,
151 actionDetachMethod = 3,
152 actionAttachMethod = 4,
153 actionReattachMethod = 5
156 //extern StatusField pos, ovr, caps, num;
157 //extern Class thisClass;
163 bool parseError = false;
168 Expression ctxInsideExp;
169 Expression paramsInsideExp;
170 ClassFunction insideFunction;
178 /****************************************************************************
180 ****************************************************************************/
182 static void OutputString(File f, char * string)
185 for(c = 0; string[c]; c++)
187 if(string[c] == '\"')
189 else if(string[c] == '\\')
196 void OutputType(File f, Type type, bool outputName)
206 if(!type.isSigned) f.Printf("unsigned ");
210 if(!type.isSigned) f.Printf("unsigned ");
214 if(!type.isSigned) f.Printf("unsigned ");
218 if(!type.isSigned) f.Printf("unsigned ");
222 if(!type.isSigned) f.Printf("unsigned ");
232 // ADD CODE TO DECIDE WHETHER TO OUTPUT FULLY QUAlIFIED OR NOT:
233 f.Printf(type._class.shortName ? type._class.shortName : type._class.string);
242 OutputType(f, type.type, false);
245 OutputType(f, type.type, false);
264 if(type.kind == arrayType)
267 f.Printf("%d", type.arraySize);
273 void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
279 f.Seek(pos - *position, current);
281 // Try to delete spaces and \n before...
287 /*else if(ch == '\n')
289 // Look for // comments on the line before
290 EditBox editBox = f.editBox;
291 EditLine line = editBox.line;
298 for(c = 0; text[c]; c++)
307 if(text[c] == '/' && last == '/')
319 f.DeleteBytes(before);
324 void GetLocText(EditBox editBox, File f, int position, Location loc, char ** text, int * size, int pad, int linePad)
329 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
331 // Cut & Paste function
337 f.Seek(loc.start.pos - position, current);
339 x1 = editBox.charPos;
340 y1 = editBox.lineNumber;
341 f.Seek(loc.end.pos - loc.start.pos, current);
343 x2 = editBox.charPos;
344 y2 = editBox.lineNumber;
345 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
347 *size = editBox.SelSize();
348 *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
349 editBox.GetSel(*text, false);
352 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
353 f.Printf(""); // Make the stream point to where the editbox is
356 void Code_FixProperty(Property prop, Instance object)
358 Designer::FixProperty(prop, object);
361 bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
364 if(prop.dataTypeString && (!prop.IsSet || prop.IsSet(selected.instance)))
366 Class dataType = prop.dataTypeClass;
367 char string[1024] = "";
370 dataType = prop.dataTypeClass = eSystem_FindClass(test._class.module, prop.dataTypeString);
372 if(dataType && dataType._vTbl && dataType.type == structClass)
374 void * dataForm = new0 byte[dataType.structSize];
375 void * dataTest = new0 byte[dataType.structSize];
377 prop.Get(selected.instance, dataForm);
378 prop.Get(test, dataTest);
380 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
382 prop.Set(test, dataForm);
388 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
390 void * dataForm, * dataTest;
392 dataForm = (void *)prop.Get(selected.instance);
393 dataTest = (void *)prop.Get(test);
395 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
397 prop.Set(test, dataForm);
401 else if(dataType && dataType._vTbl)
403 DataValue dataForm, dataTest;
405 GetProperty(prop, selected.instance, &dataForm);
406 GetProperty(prop, test, &dataTest);
408 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
410 SetProperty(prop, test, dataForm);
412 // In case setting on test unset on real instance (e.g. isDefault)
413 if(strcmp(prop.name, "name"))
415 GetProperty(prop, selected.instance, &dataTest);
416 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
417 SetProperty(prop, selected.instance, dataForm);
426 bool Code_IsPropertyDisabled(ObjectInfo selected, char * name)
428 bool disabled = false;
429 if(selected.oClass == selected)
432 if(selected.classDefinition)
434 for(def = selected.classDefinition.definitions->first; def; def = def.next)
436 if(def.type == defaultPropertiesClassDef)
439 for(prop = def.defProperties->first; prop; prop = prop.next)
441 if(prop.identifiers && prop.identifiers->first)
443 Identifier id = prop.identifiers->first;
444 if(prop.variable && !strcmp(id.string, name))
456 else if(selected.instCode)
459 if(selected.instCode.members)
461 for(members = selected.instCode.members->first; members; members = members.next)
463 if(members.type == dataMembersInit && members.dataMembers)
466 for(prop = members.dataMembers->first; prop; prop = prop.next)
468 if(prop.identifiers && prop.identifiers->first)
470 Identifier id = prop.identifiers->first;
471 if(prop.variable && !strcmp(id.string, name))
486 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
491 method.dataType = ProcessTypeString(method.dataTypeString, false);
492 if(!method.dataType.thisClass && !isForm)
495 method.dataType.thisClass = selectedClass;
497 //result = MatchTypes(method.dataType, type, null, regClass, regClass, false);
498 result = MatchTypes(type, method.dataType, null, regClass, regClass, false, true, true, false);
500 method.dataType.thisClass = null;
504 bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo object)
506 bool confirmation = true;
507 Statement body = function.body;
508 // Check if it contains any code
509 if((!body.compound.declarations || !body.compound.declarations->count) && (!body.compound.statements || body.compound.statements->count <= 1))
511 Class moduleClass = eSystem_FindClass(object.instance._class.module, "Module");
512 Statement stmt = body.compound.statements ? body.compound.statements->first : null;
513 Type dataType = method.dataType;
514 Type returnType = dataType.returnType;
515 Expression exp = null;
518 method.dataType = ProcessTypeString(method.dataTypeString, false);
520 confirmation = false;
522 // Check if default function should be calling base class:
523 if(object.instance._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
525 if(returnType.kind != voidType)
527 if(!stmt || stmt.type != returnStmt || !stmt.expressions || stmt.expressions->count != 1)
531 exp = stmt.expressions->first;
532 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
534 if( (exp.type != identifierExp || strcmp(exp.identifier.string, "true")) &&
535 (exp.type != constantExp || strcmp(exp.constant, "1")))
540 if(exp.type != constantExp || strcmp(exp.constant, "0"))
555 if(returnType.kind != voidType)
557 if(stmt.type == returnStmt && stmt.expressions && stmt.expressions->count == 1)
558 exp = stmt.expressions->first;
560 else if(stmt.type == expressionStmt && stmt.expressions && stmt.expressions->count == 1)
561 exp = stmt.expressions->first;
564 if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
568 Identifier id = exp.call.exp.identifier;
569 Class base = object.instance._class;
570 if(!id._class || (id._class.name && !strcmp(id._class.name, base.name)) || strcmp(id.string, method.name))
574 Expression arg = exp.call.arguments ? exp.call.arguments->first : null;
575 if(!arg || arg.type != identifierExp || strcmp("this", arg.identifier.string))
581 for(param = dataType.params.first; param; param = param.next)
583 if(!arg || arg.type != identifierExp || strcmp(param.name, arg.identifier.string))
588 arg = arg ?arg.next : null;
595 return !confirmation;
598 class CodeEditor : Window
600 background = marginColor;
601 borderStyle = sizableDeep;
606 isActiveClient = true;
607 anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
610 // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
611 // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
613 SheetType sheetSelected;
618 Context globalContext { };
619 OldList excludedSymbols { offset = (uint)&((Symbol)0).left };
632 MethodAction methodAction;
634 ClassFunction function;
636 char methodName[1024];
640 bool membersListShown;
643 EditLine membersLine;
645 Type functionType, instanceType;
649 Point paramsPosition;
650 Expression functionExp;
653 BitmapResource icons[CodeObjectType];
655 FontResource boldFont { "Tahoma", 8.25f, bold = true, window = this };
656 FontResource normalFont { "Tahoma", 8.25f, window = this };
658 Module privateModule;
659 NameSpace globalData;
662 OpenedFileInfo openedFileInfo;
664 FontResource font { codeFont.faceName, codeFont.size };
665 saveDialog = codeEditorFileDialog;
667 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
669 void ProcessCaretMove(EditBox editBox, int line, int charPos)
672 ObjectInfo classItem;
674 // OnActivateClient is called after OnActivate
677 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
680 if(sheet.codeEditor != this) return;
684 for(classItem = classes.first; classItem; classItem = classItem.next)
686 ClassDefinition classDef = classItem.classDefinition;
687 if(classDef && classDef.loc.Inside(line, charPos))
694 for(object = classItem.instances.first; object; object = object.next)
698 if(object.instCode.loc.Inside(line, charPos))
703 sheet.SelectObject(object);
705 sheet.SelectObject(classItem);
710 //sheet.SelectObject(null);
714 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
718 expectingMove = false;
724 if(line-1 != membersLoc.start.line)
728 char * buffer = membersLine.text;
731 if(charPos - 1 < membersLoc.start.charPos)
733 else if(charPos - 1 > membersLoc.end.charPos)
735 char * buffer = membersLine.text;
736 //if(membersList.currentRow)
740 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
741 if(buffer[c] != ' ' && buffer[c] != '\t')
743 if(c < charPos && buffer[c])
750 membersList.Destroy(0);
751 membersListShown = false;
755 bool back = codeModified;
756 codeModified = false;
758 InvokeParameters(false, false, false);
759 /*if(membersListShown)
760 InvokeAutoComplete(false, 0, true);*/
767 watch(modifiedDocument)
769 ProjectView projectView = ide.projectView;
772 ProjectNode node = projectView.GetNodeFromWindow(this, null);
775 node.modified = modifiedDocument;
776 projectView.Update(null);
784 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
785 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
786 tabKey = true, smartHome = true;
787 tabSelection = true, maxLineSize = 65536, parent = this, hasHorzScroll = true, hasVertScroll = true;
788 selectionColor = selectionColor, selectionText = selectionText,
789 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
790 font = font, borderStyle = none;
791 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
793 bool OnMouseOver(int x, int y, Modifiers mods)
795 CodeEditor editor = (CodeEditor)master;
796 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
801 void NotifyCaretMove(EditBox editBox, int line, int charPos)
803 // Update Line Numbers
805 int oldLine = lastLine;
806 display.FontExtent(font.font, " ", 1, null, &spaceH);
808 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
812 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
817 if(ide.activeClient == this)
818 ProcessCaretMove(editBox, line, charPos);
820 openedFileInfo.CaretMove(line, charPos);
823 void NotifyOvrToggle(EditBox editBox, bool overwrite)
825 ide.ovr.color = overwrite ? black : Color { 128, 128, 128 };
828 void NotifyUpdate(EditBox editBox)
835 designer.modifiedDocument = true;
838 modifiedDocument = true;
841 bool NotifyUnsetModified(EditBox editBox)
843 modifiedDocument = false;
847 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
853 if(after.y != before.y)
855 ProjectView projectView = ide.projectView;
856 if(projectView && fileName)
859 // HOW WE MIGHT WANT TO DO IT:
860 char * text = before.line.text;
861 for(c = before.x-1; c>= 0; c--)
862 if(!isspace(text[c]))
864 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
866 // HOW VISUAL STUDIO DOES IT:
868 char * text = after.line.text;
869 for(c = after.line.count-1; c>= 0; c--)
870 if(!isspace(text[c]))
872 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
879 for(oClass = classes.first; oClass; oClass = oClass.next)
882 for(object = oClass.instances.first; object; object = object.next)
886 object.instCode.loc.start.AdjustAdd(before, after);
887 object.instCode.loc.end.AdjustAdd(before, after);
892 oClass.classDefinition.loc.start.AdjustAdd(before, after);
893 oClass.classDefinition.loc.end.AdjustAdd(before, after);
899 expectingMove = true;
903 if(before.y != after.y)
907 char * buffer = membersLine.text;
909 bool firstChar = true;
910 bool addedChar = false;
916 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
918 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
920 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
921 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
930 membersLoc.start.charPos++;
935 string[len++] = buffer[c];
939 row = membersList.currentRow;
940 if(row && row.selected)
944 membersLoc.start.charPos--;
952 row = membersList.FindSubString(string);
954 membersList.currentRow = row;
957 row = membersList.FindSubStringi(string);
959 membersList.currentRow = row;
960 membersList.currentRow.selected = false;
963 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
967 row = membersList.currentRow;
970 // Accept current string if hiding typing char
971 if(hide && row && row.selected)
973 char * string = row.string;
974 int len = strlen(string);
975 membersLoc.end.charPos -= after.x - before.x;
976 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
977 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
978 membersLine, membersLoc.end.line, membersLoc.end.charPos);
979 editBox.PutS(string);
980 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
982 after.x += membersLoc.start.charPos + len - before.x;
983 before.x = membersLoc.start.charPos + len;
988 membersList.Destroy(0);
989 membersListShown = false;
992 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
994 EditLine line = editBox.line;
995 char * text = line.text;
996 char ch = text[after.x-1];
997 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1001 // Can we call invoke auto complete here instead?
1011 // Force caret update already...
1012 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1013 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1015 editBox.GetCaretPosition(&caret);
1019 // Go back in the buffer until no space before
1021 codeModified = true;
1025 EditBoxStream f { editBox = editBox };
1029 if(text[after.x-1] == '>')
1035 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1039 if(!f.Seek(-1, current))
1042 if(!isspace(ch)) break;
1043 f.Seek(-1, current);
1045 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1047 line = editBox.lineNumber + 1;
1048 charPos = editBox.charPos + 1;
1052 exp = FindExpTree(ast, line, charPos);
1056 Type type = exp.expType;
1058 if(type && text[after.x-1] != '.')
1060 if(type.kind == TypePointer || type.kind == TypeArray)
1066 membersList.Clear();
1069 if(membersList.rowCount)
1071 membersList.Sort(null, 1);
1072 membersList.master = this;
1074 caret.y += editBox.GetCaretSize();
1077 membersList.Create();
1080 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1081 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1082 Window parent = membersList.parent;
1084 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1086 y -= editBox.GetCaretSize() + membersList.GetHeight();
1087 membersAbove = true;
1090 membersAbove = false;
1092 membersList.position = { x, y };
1096 membersLoc.start.line = line - 1;
1097 membersLoc.start.charPos = oldCharPos;
1098 membersLoc.end = membersLoc.start;
1099 membersListShown = true;
1104 SetCurrentContext(globalContext);
1106 codeModified = true;
1107 skipModified = true;
1108 if(text[after.x-1] == ':')
1109 InvokeAutoComplete(false, 0, false);
1110 else if(text[after.x-1] == '.')
1111 InvokeAutoComplete(false, 1, false);
1112 else if(text[after.x-1] == '>')
1113 InvokeAutoComplete(false, 2, false);
1114 skipModified = false;
1116 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1118 codeModified = true;
1119 skipModified = true;
1121 if(InvokeAutoComplete(true, 0, false))
1123 if(ch == '(' || ch == OpenBracket)
1124 InvokeParameters(true, true, false);
1126 InvokeParameters(this.functionType ? false : true, false, false);
1129 // InvokeAutoComplete(true, 0, false);
1130 skipModified = false;
1132 else if(ch == ')' || ch == '}' || ch == ';')
1134 codeModified = true;
1135 skipModified = true;
1137 InvokeParameters(false, true, false);
1138 skipModified = false;
1142 bool back = codeModified;
1143 codeModified = false;
1145 InvokeParameters(false, false, true);
1146 if(membersListShown)
1147 InvokeAutoComplete(false, 0, true);
1148 codeModified = back;
1153 bool back = codeModified;
1154 codeModified = false;
1157 InvokeParameters(false, false, true);
1158 /*if(membersListShown)
1159 InvokeAutoComplete(false, 0, true);*/
1161 codeModified = back;
1168 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1174 if(after.y != before.y)
1176 ProjectView projectView = ide.projectView;
1177 if(projectView && fileName)
1179 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1184 for(oClass = classes.first; oClass; oClass = oClass.next)
1188 for(object = oClass.instances.first; object; object = object.next)
1192 loc = &object.instCode.loc;
1194 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1195 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1197 object.instCode = null;
1201 loc->start.AdjustDelete(before, after);
1202 loc->end.AdjustDelete(before, after);
1206 if(oClass.classDefinition)
1208 loc = &oClass.classDefinition.loc;
1209 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1210 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1212 oClass.classDefinition = null;
1216 loc->start.AdjustDelete(before, after);
1217 loc->end.AdjustDelete(before, after);
1222 if(membersListShown)
1225 if(pasteOperation || before.y != after.y)
1229 char * buffer = membersLine.text;
1231 bool firstChar = true;
1235 if(before.x >= membersLoc.start.charPos)
1237 for(c = membersLoc.start.charPos; c<before.x; c++)
1239 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1240 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1245 if(!isSpace) firstChar = false;
1248 string[len++] = buffer[c];
1253 // If deleting spaces before...
1254 for(c = before.x; c<membersLoc.start.charPos; c++)
1256 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1264 membersLoc.start.charPos = before.x;
1267 if(membersLoc.end.charPos >= after.x)
1269 for(c = after.x; c<membersLoc.end.charPos; c++)
1271 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1272 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1277 if(!isSpace) firstChar = false;
1280 string[len++] = buffer[c];
1288 membersLoc.end.charPos -= after.x - before.x;
1292 row = membersList.FindSubString(string);
1295 row = membersList.FindSubStringi(string);
1297 membersList.currentRow = row;
1298 membersList.currentRow.selected = false;
1301 membersList.currentRow = row;
1303 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1308 membersList.Destroy(0);
1309 membersListShown = false;
1315 InvokeParameters(false, false);
1323 bool NotifyDropped(EditBox editBox, int x, int y)
1325 char * controlClass = toolBox.controlClass;
1326 if(controlClass && controlClass[0])
1330 ObjectInfo classObject;
1332 //editBox.NotifyCaretMove(this, editBox, y, x);
1333 editBox.GoToLineNum(y);
1334 editBox.GoToPosition(editBox.line, y, x);
1336 classObject = selected ? selected.oClass : null;
1338 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1339 selected = classObject.instances.last;
1342 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1345 AddObject(control, &object);
1347 designer.CreateObject(control, object, false, classObject.instance);
1348 // designer.PostCreateObject(control, object, false, classObject.instance);
1349 designer.DroppedObject(control, object, false, classObject.instance);
1351 sheet.AddObject(object, object.name, typeData /* className*/, true);
1354 //codeModified = true;
1361 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1363 if(key == Key { space, ctrl = true })
1365 membersList.Destroy(0);
1366 membersListShown = false;
1367 InvokeAutoComplete(false, 0, false);
1370 else if(key == Key { space, ctrl = true, shift = true })
1371 InvokeParameters(false, true, false);
1372 else if(key == escape)
1373 ide.RepositionWindows(true);
1374 else if(key == ctrlF7)
1378 ProjectNode node = ide.projectView.GetNodeFromWindow(this, null);
1382 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1383 $"It can't be compiled.");
1384 MessageBox { type = ok, parent = ide, master = ide, text = $"File not in project error", contents = s }.Modal();
1393 bool OnKeyDown(Key key, unichar ch)
1395 CodeEditor editor = (CodeEditor)master;
1396 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1398 if(editor.membersListShown)
1400 editor.membersList.Destroy(0);
1401 editor.membersListShown = false;
1404 if(editor.paramsShown)
1406 editor.paramsList.Destroy(0);
1407 editor.paramsShown = false;
1408 FreeType(editor.functionType);
1409 FreeType(editor.instanceType);
1411 editor.functionType = null;
1412 editor.instanceType = null;
1413 editor.paramsID = -1;
1417 return EditBox::OnKeyDown(key, ch);
1420 void OnVScroll(ScrollBarAction action, int position, Key key)
1422 if(anchor.left.distance)
1424 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1427 EditBox::OnVScroll(action, position, key);
1429 CodeEditor ce = (CodeEditor)parent;
1430 if(ce.openedFileInfo)
1431 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1435 void OnHScroll(ScrollBarAction action, int position, Key key)
1437 EditBox::OnHScroll(action, position, key);
1439 CodeEditor ce = (CodeEditor)parent;
1440 if(ce.openedFileInfo)
1441 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1448 fullRowSelect = false,
1451 borderStyle = bevel;
1452 // size = { 200, 400 };
1454 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1456 DataRow row = listBox.currentRow;
1459 char * string = row.string;
1461 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1463 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1464 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1465 editBox.PutS(string);
1468 membersListShown = false;
1473 bool OnKeyDown(Key key, unichar ch)
1475 CodeEditor editor = (CodeEditor) master;
1476 if(key == escape || key == leftAlt || key == rightAlt ||
1477 (key.ctrl && key.code != left && key.code != right &&
1478 key.code != leftShift && key.code != rightShift && key.code != space))
1480 if(editor.paramsShown)
1481 editor.paramsList.Destroy(0);
1482 if(editor.membersListShown)
1483 editor.membersList.Destroy(0);
1485 editor.paramsShown = false;
1486 FreeType(editor.functionType);
1487 FreeType(editor.instanceType);
1489 editor.functionType = null;
1490 editor.instanceType = null;
1491 editor.paramsID = -1;
1493 editor.membersListShown = false;
1497 return editor.editBox.OnKeyDown(key, ch);
1501 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1503 CodeEditor editor = (CodeEditor)master;
1507 editor.membersListShown = false;
1509 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1512 bool OnKeyHit(Key key, unichar ch)
1514 CodeEditor editor = (CodeEditor) master;
1518 case enter: case tab:
1520 DataRow row = currentRow;
1521 if(row && row.selected)
1523 char * string = row.string;
1525 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1526 editor.editBox.Delete(
1527 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1528 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1529 editor.editBox.PutS(string);
1532 editor.membersListShown = false;
1535 editor.editBox.OnKeyHit(key, ch);
1545 return ListBox::OnKeyHit(key, ch);
1551 // If before . or after
1552 //listBox.Destroy(true);
1553 result = editor.editBox.OnKeyHit(key, ch);
1568 clickThrough = true,
1570 borderStyle = contour,
1572 background = { 255,255,225 },
1574 OnKeyDown = membersList.OnKeyDown;
1576 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1578 CodeEditor editor = (CodeEditor)master;
1582 editor.membersListShown = false;
1584 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1587 bool OnKeyHit(Key key, unichar ch)
1589 CodeEditor editor = (CodeEditor)master;
1591 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1594 bool result = true; editor.editBox.OnKeyHit(key, ch);
1595 return (!created) ? false : result;
1602 void OnRedraw(Surface surface)
1604 CodeEditor editor = (CodeEditor) master;
1605 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1607 Type methodType = null;
1611 int functionW, nameW = 0;
1613 int spaceW, spaceH, commaW, commaWB, parW;
1615 int maxW = 0, lineW = 0;
1621 Font font = editor.normalFont.font;
1622 Font boldFont = editor.boldFont.font;
1623 Display display = this.display;
1625 if(!type) { return; };
1627 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1629 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1630 display.FontExtent(font, ", ", 2, &commaW, null);
1631 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1632 display.FontExtent(font, ")", 1, &parW, null);
1635 if(editor.functionType)
1637 PrintType(type.returnType, string, true, true);
1638 display.FontExtent(font, string, strlen(string), &functionW, null);
1640 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1641 totalW = nameW + functionW + 2 * parW;
1645 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1646 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1647 if(instanceName && type.kind != functionType)
1648 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1649 totalW = functionW + nameW;
1650 surface.TextFont(boldFont);
1653 surface.WriteText(x, y, string, strlen(string));
1654 x += functionW + spaceW;
1656 if(editor.functionType)
1659 surface.WriteText(x, y, type.name, strlen(type.name));
1661 surface.WriteText(x, y, "(", 1);
1664 if(methodType && !methodType.staticMethod)
1668 if(id == editor.paramsID)
1669 surface.TextFont(boldFont);
1671 if(methodType.methodClass)
1672 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1676 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1677 width += ((id == editor.paramsID) ? commaWB : commaW);
1682 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1687 x = 2 + nameW + spaceW + functionW + parW;
1691 if(methodType.methodClass)
1692 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1695 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1697 surface.WriteText(x, y, ",", 1);
1698 x += ((id == editor.paramsID) ? commaWB : commaW);
1706 if(id == editor.paramsID)
1707 surface.TextFont(font);
1711 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1713 for(param = type.params.first; param; param = param.next)
1715 char paramString[1024];
1718 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1719 surface.TextFont(boldFont);
1722 PrintType(param, paramString, true, true);
1723 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1725 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1730 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1735 x = 2 + nameW + spaceW + functionW + parW;
1739 surface.WriteText(x, y, paramString, strlen(paramString));
1743 surface.WriteText(x, y, ",", 1);
1744 x += ((id == editor.paramsID) ? commaWB : commaW);
1752 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1753 surface.TextFont(font);
1758 surface.WriteText(x, y, ")", 1);
1760 else if(instanceName && type.kind != functionType)
1762 surface.WriteText(x, y, instanceName, strlen(instanceName));
1766 bool OnResizing(int * w, int * h)
1768 CodeEditor editor = (CodeEditor) master;
1769 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1771 Type methodType = null;
1775 int functionW = 0, nameW = 0;
1777 int spaceW, spaceH, commaW, commaWB, parW;
1779 int maxW = 0, lineW = 0;
1784 Font font = editor.normalFont.font;
1785 Font boldFont = editor.boldFont.font;
1786 Display display = this.display;
1788 if(type.kind == TypeKind::methodType)
1791 ProcessMethodType(type.method);
1792 type = type.method.dataType;
1795 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1796 display.FontExtent(font, ", ", 2, &commaW, null);
1797 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1798 display.FontExtent(font, ")", 1, &parW, null);
1801 if(editor.functionType && type)
1803 PrintType(type.returnType, string, true, true);
1804 display.FontExtent(font, string, strlen(string), &functionW, null);
1806 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1807 totalW = nameW + spaceW + functionW + 2 * parW;
1811 PrintType(type, string, false, true); // /*true);
1812 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1813 if(instanceName && type.kind != functionType)
1814 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1815 totalW = functionW + nameW + spaceW;
1818 if(editor.functionType)
1824 if(methodType.methodClass)
1825 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1826 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1827 width += ((id == editor.paramsID) ? commaWB : commaW);
1832 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1845 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1847 for(param = type.params.first; param; param = param.next)
1849 char paramString[1024];
1853 PrintType(param, paramString, true, true);
1854 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1856 width += ((id == editor.paramsID) ? commaWB : commaW);
1861 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1878 *w = realW + totalW + 4;
1884 Menu fileMenu { menu, $"File", f }; // MenuPlacement?
1885 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1886 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1888 Menu debugMenu { menu, $"Debug", d }; // MenuPlacement?
1889 MenuItem debugRunToCursor
1891 debugMenu, $"Run To Cursor", c, Key { f10, ctrl = true };
1892 bool NotifySelect(MenuItem selection, Modifiers mods)
1894 ProjectView projectView = ide.projectView;
1895 if(!projectView.buildInProgress)
1897 int line = editBox.lineNumber + 1;
1900 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1901 ProjectConfig config = projectView.project.config;
1902 ide.debugger.RunToCursor(compiler, config, fileName, line, false);
1909 MenuItem debugSkipRunToCursor
1911 debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true };
1912 bool NotifySelect(MenuItem selection, Modifiers mods)
1914 ProjectView projectView = ide.projectView;
1915 int line = editBox.lineNumber + 1;
1918 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1919 ProjectConfig config = projectView.project.config;
1920 ide.debugger.RunToCursor(compiler, config, fileName, line, true);
1926 MenuDivider { debugMenu };
1927 MenuItem debugToggleBreakpoint
1929 debugMenu, $"Toggle Breakpoint", t, f9;
1930 bool NotifySelect(MenuItem selection, Modifiers mods)
1932 ProjectView projectView = ide.projectView;
1933 if(projectView && fileName)
1935 int line = editBox.lineNumber + 1;
1936 char name[MAX_LOCATION];
1938 // TOFIX: This only looks at the filename...
1939 GetLastDirectory(fileName, name);
1940 if(ide && ide.workspace)
1942 for(p : ide.workspace.projects)
1944 if(p.topNode.Find(name, false))
1952 for(p : ide.workspace.projects)
1954 if(eString_PathInsideOf(fileName, p.topNode.path))
1962 ide.debugger.ToggleBreakpoint(fileName, line, prj);
1972 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1976 designer.parent = parent;
1979 toolBox = ((IDE)master).toolBox;
1981 // Debugger bug here: value of toolBox appears as 0
1983 sheet = ((IDE)master).sheet;
1988 bool OnClose(bool parentClosing)
1992 if(ide.workspace && fileName)
1993 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
1995 if(inUseDebug && !debugClosing)
1997 debugClosing = true;
1999 if(CloseConfirmation(false))
2002 OnFileModified({ modified = true }, null);
2004 debugClosing = false;
2007 if(designer && !designer.closing)
2009 if(designer.visible)
2016 //Window formEditor = designer;
2017 //formEditor.Destroy(0);
2024 void OnDestroy(void)
2026 ObjectInfo oClass, next;
2027 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2029 FreeType(this.functionType);
2030 FreeType(this.instanceType);
2035 designer.codeEditor = null;
2036 designer.Destroy(0);
2040 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2042 ObjectInfo object, next;
2044 for(object = oClass.instances.first; object; object = next)
2049 Designer::DestroyObject(object.instance);
2050 delete object.instance;
2052 sheet.DeleteObject(object);
2054 oClass.instances.Delete(object);
2058 Designer::DestroyObject(oClass.instance);
2059 delete oClass.instance;
2061 sheet.DeleteObject(oClass);
2063 classes.Delete(oClass);
2066 if(windowClass && windowClass.data)
2067 UnapplySkin(windowClass);
2071 if(sheet.codeEditor == this)
2073 sheet.codeEditor = null;
2074 toolBox.codeEditor = null;
2080 ProjectView projectView = ide.projectView;
2083 ProjectNode node = projectView.GetNodeFromWindow(this, null);
2084 if(node && node.modified)
2086 node.modified = false;
2087 projectView.Update(null);
2093 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2095 // WHY WAS THIS HERE? I think this was here because once you move a window in the ide it's hard to reposition it correctly
2097 if(directActivation)
2098 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2100 if(active && directActivation)
2103 openedFileInfo.Activate();
2107 Location * loc = null;
2108 UpdateFormCode(); // To ensure update when modifying properties...
2110 // Got to the right spot in code so we don't lose our form selection...
2113 if(selected.instCode)
2114 loc = &selected.instCode.loc;
2115 else if(selected.classDefinition)
2116 loc = &selected.classDefinition.loc;
2118 line = editBox.lineNumber + 1;
2119 charPos = editBox.charPos + 1;
2124 if(selected && !loc->Inside(line, charPos))
2126 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2127 line = editBox.lineNumber + 1;
2128 charPos = editBox.charPos + 1;
2130 else if(selected && selected.classDefinition)
2133 for(object = selected.instances.first; object; object = object.next)
2137 if(object.instCode.loc.Inside(line, charPos))
2143 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2144 line = editBox.lineNumber + 1;
2145 charPos = editBox.charPos + 1;
2150 ProcessCaretMove(editBox, line, charPos);
2156 bool OnSaveFile(char * fileName)
2163 f = FileOpen(fileName, write);
2166 if(!ide.projectView)
2167 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2171 this.fileName = fileName; // Put this here because the form designer will check for it...
2172 designer.fileName = fileName;
2173 designer.modifiedDocument = false;
2175 editBox.Save(f, false);
2176 modifiedDocument = false;
2184 bool OnFileModified(FileChange fileChange, char * param)
2186 bool reload = false;
2187 if(visible == false && inUseDebug == true)
2193 sprintf(message, $"The document %s was modified by another application.\n"
2194 "Would you like to reload it and lose your changes?", fileName);
2195 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2196 contents = message }.Modal() == yes)
2202 File f = FileOpen(fileName, read);
2205 int lineNumber, charPos, len;
2208 updatingCode = true;
2209 lineNumber = editBox.lineNumber;
2210 charPos = editBox.charPos;
2211 scroll = editBox.scroll;
2214 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2215 len = strlen(editBox.line.text);
2216 editBox.GoToLineNum(lineNumber);
2217 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2218 editBox.scroll = scroll;
2219 updatingCode = false;
2221 codeModified = true;
2225 designer.modifiedDocument = false;
2227 modifiedDocument = false;
2235 void OnRedraw(Surface surface)
2238 surface.SetBackground(marginColor);
2239 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2240 if(ideSettings.showLineNumbers)
2242 int currentLineNumber;
2247 surface.textOpacity = false;
2248 surface.font = font.font;
2249 surface.TextExtent(" ", 1, null, &spaceH);
2250 currentLineNumber = editBox.scroll.y / spaceH + 1;
2252 surface.SetForeground(lineNumbersColor);
2253 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2255 // Highlight current line
2256 if(editBox.lineNumber == currentLineNumber - 1)
2258 surface.SetBackground(selectedMarginColor);
2259 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2260 surface.SetBackground(marginColor);
2262 sprintf(lineText,"%5u ", currentLineNumber % 100000);
2263 if(currentLineNumber <= editBox.numLines)
2264 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,6);
2266 currentLineNumber++;
2270 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2272 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2273 int lineCursor, lineTopFrame, breakpointLines[128];
2274 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2275 Debugger debugger = ide.debugger;
2276 BitmapResource bmpRes;
2278 boxH = clientSize.h;
2279 scrollY = editBox.scroll.y;
2280 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2282 bpOnCursor = bpOnTopFrame = false;
2283 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2286 for(i = 0; i < count; i++)
2288 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2290 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2291 if(breakpointLines[i] == lineCursor)
2293 if(breakpointLines[i] == lineTopFrame)
2294 bpOnTopFrame = true;
2297 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2299 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2302 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2303 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2304 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2306 if(editBox.anchor.left.distance)
2308 if(editBox.horzScroll && editBox.horzScroll.visible)
2310 surface.SetBackground(control);
2311 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2316 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2321 lineY = (line - 1) * lineH;
2322 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2324 Bitmap bitmap = resource.bitmap;
2326 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2333 char ext[MAX_EXTENSION];
2334 char * fileName = property::fileName;
2336 if(SearchString(fileName, 0, "Makefile", false, true))
2337 editBox.useTab = true;
2338 designer.fileName = fileName;
2342 GetExtension(fileName, ext);
2343 if(!strcmpi(ext, "ec"))
2345 codeModified = true;
2349 if(!strcmpi(ext, "ec") || !strcmpi(ext, "c") || !strcmpi(ext, "cc") || !strcmpi(ext, "cpp") || !strcmpi(ext, "eh") || !strcmpi(ext, "hh") || !strcmpi(ext, "hpp") || !strcmpi(ext, "h") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cxx"))
2350 editBox.syntaxHighlighting = true;
2352 editBox.syntaxHighlighting = false;
2355 display.FontExtent(font.font, " ", 1, &spaceW, null);
2356 editBox.anchor = Anchor
2358 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2359 right = 0, top = 0, bottom = 0
2368 display.FontExtent(font.font, " ", 1, &spaceW, null);
2369 editBox.anchor = Anchor
2371 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2372 right = 0, top = 0, bottom = 0
2377 bool LoadFile(char * filePath)
2379 File f = FileOpen(filePath, read);
2382 // Added this here...
2383 fileName = filePath;
2384 updatingCode = true;
2386 updatingCode = false;
2395 void DebugMenusDisabled()
2397 bool debugMenusDisabled = ide.GetDebugMenusDisabled();
2398 debugRunToCursor.disabled = debugMenusDisabled;
2399 debugSkipRunToCursor.disabled = debugMenusDisabled;
2400 debugToggleBreakpoint.disabled = debugMenusDisabled;
2406 ProjectView projectView = ide.projectView;
2409 designer.fileName = fileName;
2415 sprintf(title, $"Untitled %d", documentID);
2416 // designer.fileName = CopyString(title);
2417 designer.fileName = title;
2420 DebugMenusDisabled();
2422 for(c = 0; c < CodeObjectType::enumSize; c++)
2423 icons[c] = BitmapResource { iconNames[c], window = this };
2425 codeModified = true;
2437 selected.modified = true;
2438 selected.oClass.modified = true;
2440 designer.modifiedDocument = true;
2441 modifiedDocument = true;
2442 formModified = true;
2445 /****************************************************************************
2447 ****************************************************************************/
2450 this.defines.Free(FreeModuleDefine);
2451 this.imports.Free(FreeModuleImport);
2458 FreeExcludedSymbols(this.excludedSymbols);
2459 FreeContext(this.globalContext);
2461 FreeGlobalData(&this.globalData);
2463 if(GetGlobalContext() == globalContext)
2465 SetGlobalData(null);
2466 SetGlobalContext(null);
2467 SetExcludedSymbols(null);
2468 SetTopContext(null);
2469 SetCurrentContext(null);
2472 SetPrivateModule(null);
2475 if(this.privateModule)
2477 FreeTypeData(this.privateModule);
2478 delete this.privateModule;
2479 this.privateModule = null;
2485 static bool reentrant = false;
2490 char * selectedClassName = null, * selectedName = null;
2491 int selectedPos = 0;
2492 Designer backDesigner;
2493 char oldWorkDir[MAX_LOCATION];
2494 char mainModuleName[MAX_FILENAME] = "";
2496 ImportedModule module;
2497 char extension[MAX_EXTENSION];
2499 Time parseCodeStart = GetTime();
2500 Time startTime, startFindClass;
2502 findClassTotalTime = 0;
2503 checkTypeTotalTime = 0;
2504 externalImportTotalTime = 0;
2505 findClassIgnoreNSTotalTime = 0;
2506 findSymbolTotalTime = 0;
2507 //ResetClassFindTime();
2511 // This temporarily fixes issue with 2 overrides in release mode with VC6 (only happens with both ecere.dll and ide.exe compiled in release mode)
2512 if(reentrant) return;
2519 selectedClassName = CopyString(oClass.name);
2520 if(selected != oClass)
2522 ObjectInfo object = this.selected;
2523 selectedName = CopyString(object.name);
2527 for(check = this.oClass.instances.first; check; check = check.next)
2539 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2541 defines.Free(FreeModuleDefine);
2542 imports.Free(FreeModuleImport);
2544 SetGlobalData(&globalData);
2545 SetGlobalContext(globalContext);
2546 SetExcludedSymbols(&excludedSymbols);
2547 SetTopContext(globalContext);
2548 SetCurrentContext(globalContext);
2549 SetDefines(&defines);
2550 SetImports(&imports);
2551 SetCurrentNameSpace(null);
2554 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2555 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2556 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2557 "/I T:\\ecere\\include /E %s", argv[1]);
2561 ChangeWorkingDir("e:\\ec");
2562 sprintf(command, "gcc -x c -E -");
2563 fileInput = DualPipeOpen({ output = true, input = true }, command);
2564 SetFileInput(fileInput);
2569 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2571 fileInput.Write(buffer, 1, count);
2576 fileInput.CloseOutput();
2580 // TOCHECK: COULDN'T WE CALL FreeParser here?
2582 this.functionType = null;
2583 this.instanceType = null;
2586 sheet.SelectObject(null);
2592 // We don't want the designer to be notified of selection when deleting rows...
2593 backDesigner = designer;
2598 ObjectInfo _class, next;
2600 for(_class = classes.first; _class; _class = next)
2606 for(;object = _class.instances.first;)
2610 Designer::DestroyObject(object.instance);
2611 delete object.instance;
2613 sheet.DeleteObject(object);
2615 _class.instances.Delete(object);
2619 Designer::DestroyObject(_class.instance);
2620 delete _class.instance;
2622 sheet.DeleteObject(_class);
2624 classes.Delete(_class);
2630 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2631 if(windowClass && windowClass.data)
2632 UnapplySkin(windowClass);
2635 designer = backDesigner;
2638 fileInput = editFile = EditBoxStream { editBox = editBox };
2639 SetFileInput(fileInput);
2648 FreeContext(this.globalContext);
2649 FreeExcludedSymbols(this.excludedSymbols);
2652 FreeGlobalData(&this.globalData);
2654 if(this.privateModule)
2656 FreeTypeData(this.privateModule);
2657 delete this.privateModule;
2661 startTime = GetTime();
2662 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2664 printf("classes.count: %d\n", globalContext.classes.count);
2667 this.privateModule = __ecere_COM_Initialize(false, 1, null);
2669 SetPrivateModule(privateModule);
2672 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2673 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2674 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2675 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2676 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2679 fileName = this.fileName;
2681 if(ide.workspace && ide.workspace.projects && fileName)
2683 for(p : ide.workspace.projects)
2685 char path[MAX_LOCATION];
2687 MakePathRelative(fileName, p.topNode.path, path);
2688 MakeSlashPath(path);
2690 pn = p.topNode.FindWithPath(path, false);
2699 project = ide.project;
2701 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2703 ChangeWorkingDir(project.topNode.path);
2705 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2707 GetLastDirectory(fileName, mainModuleName);
2708 GetExtension(mainModuleName, extension);
2710 SetBuildingEcereCom(false);
2711 SetBuildingEcereComModule(false);
2713 // TODO: Get symbolsDir from project settings instead...
2716 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2717 ProjectConfig config = project.config;
2718 DirExpression objDir = project.GetObjDir(compiler, config);
2719 SetSymbolsDir(objDir.dir);
2722 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2723 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2727 switch(GetRuntimePlatform())
2729 case win32: SetSymbolsDir("obj/debug.win32"); break;
2730 case tux: SetSymbolsDir("obj/debug.linux"); break;
2731 case apple: SetSymbolsDir("obj/debug.apple"); break;
2733 SetIncludeDirs(null);
2734 SetSysIncludeDirs(null);
2738 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2740 // TODO FIX for configless project
2741 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2743 for(item : ide.project.config.options.preprocessorDefinitions)
2745 if(!strcmp(item, "BUILDING_ECERE_COM"))
2747 SetBuildingEcereCom(true);
2754 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2755 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2756 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2757 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2758 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2759 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2760 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2761 strcmpi(mainModuleName, "Mutex.ec")))
2763 SetBuildingEcereComModule(true);
2766 // Predeclare all classes
2768 char symFile[MAX_FILENAME];
2769 char symLocation[MAX_LOCATION];
2770 ImportedModule module, next;
2772 GetLastDirectory(fileName, symFile);
2773 ChangeExtension(symFile, "sym", symFile);
2775 strcpy(symLocation, GetSymbolsDir());
2776 PathCat(symLocation, symFile);
2778 // if(!GetEcereImported() && !GetBuildingEcereCom())
2779 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2782 startTime = GetTime();
2784 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2786 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2791 startTime = GetTime();
2793 // LoadSymbols(symLocation, normalImport, true);
2794 LoadSymbols(symLocation, preDeclImport, false);
2796 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2799 for(module = defines.first; module; module = next)
2802 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2805 defines.Delete(module);
2810 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2812 SetDefaultDeclMode(privateAccess);
2813 SetDeclMode(privateAccess);
2817 SetDefaultDeclMode(defaultAccess);
2818 SetDeclMode(defaultAccess);
2821 StripExtension(mainModuleName);
2822 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2823 defines.AddName(module);
2831 startTime = GetTime();
2832 startFindClass = checkTypeTotalTime;
2836 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2838 CheckDataRedefinitions();
2841 SetIncludeDirs(null);
2842 SetSysIncludeDirs(null);
2853 startTime = GetTime();
2855 PrePreProcessClassDefinitions();
2856 ComputeModuleClasses(privateModule);
2857 PreProcessClassDefinitions();
2858 ProcessClassDefinitions();
2860 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2861 startTime = GetTime();
2866 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2867 startTime = GetTime();
2869 ProcessInstantiations();
2871 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2874 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2876 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2877 if(!windowClass || windowClass.internalDecl)
2880 startTime = GetTime();
2882 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2883 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2884 eModule_Load(this.privateModule, "ecere", privateAccess);
2886 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2889 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2891 if(windowClass && windowClass.data)
2892 ApplySkin(windowClass, app.currentSkin.name, null);
2896 startTime = GetTime();
2898 for(external = ast->first; external; external = external.next)
2900 if(external.type == classExternal)
2902 ClassDefinition _class = external._class;
2903 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2905 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2908 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2910 Instance instance = eInstance_New(regClass);
2911 ObjectInfo classObject
2913 name = CopyString(_class._class.name);
2914 instance = instance;
2915 classDefinition = _class;
2916 oClass = classObject;
2919 classes.Add(classObject);
2923 // Moved this at bottom so that the file dialog doesn't show up in eCom
2924 designer.CreateObject(instance, classObject, true, null);
2925 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
2927 if(_class.definitions)
2931 for(def = _class.definitions->first; def; def = def.next)
2935 case defaultPropertiesClassDef:
2938 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
2940 Identifier id = propDef.identifiers->first;
2943 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
2946 Class propertyClass = prop.dataTypeClass;
2948 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
2949 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
2951 FreeType(propDef.initializer.exp.destType);
2952 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
2953 ProcessExpressionType(propDef.initializer.exp);
2955 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
2957 Expression computed = CopyExpression(propDef.initializer.exp);
2958 ComputeExpression(computed);
2960 if(computed.isConstant && computed.type == instanceExp && !id.next)
2964 if(computed.instance._class && computed.instance._class.symbol &&
2965 computed.instance._class.symbol.registered &&
2966 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
2968 prop.Set(instance, computed.instance.data);
2970 // This was saved in the control and shouldn't be freed by FreeExpression...
2971 if(propertyClass.type == normalClass)
2972 computed.instance.data = null;
2976 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
2977 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
2980 ReadString(temp, computed.string);
2981 prop.Set(instance, temp);
2984 propDef.variable = true;
2986 FreeExpression(computed);
2990 Expression computed = CopyExpression(propDef.initializer.exp);
2991 ComputeExpression(computed);
2992 if(computed.isConstant)
2994 //if(computed.type == memberExp) computed = computed.member.exp;
2996 if(computed.type == constantExp)
2998 Operand value = GetOperand(computed);
2999 DataValue valueData;
3000 valueData.i64 = value.i64;
3001 SetProperty(prop, instance, valueData);
3003 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3006 ReadString(temp, computed.string);
3007 prop.Set(instance, temp);
3011 propDef.variable = true;
3013 FreeExpression(computed);
3017 propDef.variable = true;
3021 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3022 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3023 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3026 // Maintain a list in FunctionDefinition of who is attached to it
3027 for(def = _class.definitions->first; def; def = def.next)
3029 if(def.type == functionClassDef)
3031 ClassFunction function = def.function;
3032 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3034 function.attached.Add(OldLink { data = method });
3044 case declarationClassDef:
3046 Declaration decl = def.decl;
3049 case instDeclaration:
3051 Instantiation inst = decl.inst;
3052 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3053 if(instClass && eClass_GetDesigner(instClass))
3055 Instance control = eInstance_New(instClass);
3060 oClass = classObject;
3064 classObject.instances.Add(object);
3066 // TOCHECK: Why is this needed now?
3067 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3068 def.object = object;
3070 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3072 designer.CreateObject(control, object, false, classObject.instance);
3073 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3083 // Second pass, process instantiation members
3085 for(def = _class.definitions->first; def; def = def.next)
3089 case declarationClassDef:
3091 Declaration decl = def.decl;
3094 case instDeclaration:
3096 Instantiation inst = decl.inst;
3097 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3098 if(instClass && eClass_GetDesigner(instClass))
3101 object = object ? object.next : classObject.instances.first;
3102 control = object.instance;
3106 MembersInit members;
3107 for(members = inst.members->first; members; members = members.next)
3109 switch(members.type)
3111 case dataMembersInit:
3113 if(members.dataMembers)
3116 DataMember curMember = null;
3117 Class curClass = null;
3118 DataMember subMemberStack[256];
3119 int subMemberStackPos = 0;
3121 for(member = members.dataMembers->first; member; member = member.next)
3124 Identifier ident = member.identifiers ? member.identifiers->first : null;
3127 DataMember _subMemberStack[256];
3128 int _subMemberStackPos = 0;
3129 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3133 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3135 if(thisMember && thisMember.memberAccess == publicAccess)
3137 curMember = thisMember;
3138 curClass = curMember._class;
3139 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
3140 subMemberStackPos = _subMemberStackPos;
3146 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3147 if(curMember) found = true;
3149 if(found && curMember.isProperty)
3151 Property prop = (Property) curMember;
3152 Class propertyClass = prop.dataTypeClass;
3154 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3156 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3158 FreeType(member.initializer.exp.destType);
3159 member.initializer.exp.destType = MkClassType(propertyClass.name);
3162 ProcessExpressionType(member.initializer.exp);
3164 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3166 Expression computed;
3168 /*char debugExpString[4096];
3169 debugExpString[0] = '\0';
3170 PrintExpression(member.initializer.exp, debugExpString);*/
3172 computed = CopyExpression(member.initializer.exp);
3175 ComputeExpression(computed);
3177 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3179 if(computed.instance.data)
3181 if(computed.instance._class && computed.instance._class.symbol &&
3182 computed.instance._class.symbol.registered &&
3183 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3185 prop.Set(control, computed.instance.data);
3187 // This was saved in the control and shouldn't be freed by FreeExpression...
3188 if(propertyClass.type == normalClass)
3189 computed.instance.data = null;
3193 else if(computed.type == identifierExp)
3195 member.variable = true;
3197 if(eClass_GetDesigner(propertyClass))
3200 char * name = computed.identifier.string;
3201 if(!strcmp(name, "this"))
3204 prop.Set(control, instance);
3205 member.variable = false;
3210 for(check = classObject.instances.first; check; check = check.next)
3211 if(check.name && !strcmp(name, check.name))
3214 prop.Set(control, check.instance);
3215 member.variable = false;
3221 else if(computed.type == memberExp)
3223 member.variable = true;
3224 if(computed.member.exp.type == identifierExp)
3226 char * name = computed.member.exp.identifier.string;
3227 if(!strcmp(name, "this"))
3229 char * name = computed.member.member.string;
3232 for(check = classObject.instances.first; check; check = check.next)
3233 if(check.name && !strcmp(name, check.name))
3236 prop.Set(control, check.instance);
3237 member.variable = false;
3245 for(check = classObject.instances.first; check; check = check.next)
3247 if(check.name && !strcmp(name, check.name))
3249 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3252 DataValue value { };
3253 GetProperty(getProperty, check.instance, &value);
3254 SetProperty(prop, control, value);
3255 member.variable = false;
3263 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3264 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3267 ReadString(temp, computed.string);
3268 prop.Set(control, temp);
3271 member.variable = true;
3273 FreeExpression(computed);
3278 Expression computed = CopyExpression(member.initializer.exp);
3281 ComputeExpression(computed);
3282 if(computed.isConstant)
3284 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3286 if(!strcmp(propertyClass.dataTypeString, "float"))
3287 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3288 else if(!strcmp(propertyClass.dataTypeString, "double"))
3289 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3291 prop.Set(control, strtol(computed.constant, null, 0));
3293 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3296 ReadString(temp, computed.string);
3297 prop.Set(control, temp);
3301 member.variable = true;
3303 FreeExpression(computed);
3309 member.variable = true;
3311 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3312 member.initializer.exp.type == memberExp) // identifierExp
3314 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3315 if(method && method.type == virtualMethod)
3318 // Maintain a list in FunctionDefinition of who is attached to it
3319 for(def = _class.definitions->first; def; def = def.next)
3321 if(def.type == functionClassDef)
3323 ClassFunction function = def.function;
3324 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3325 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3327 function.attached.Add(OldLink { data = method });
3328 // Reference this particular instance?
3343 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3354 //designer.CreateObject(instance, classObject, true, null);
3355 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3357 designer.PostCreateObject(instance, classObject, true, null);
3359 //instance.state = Hidden;
3360 //instance.Create();
3361 //instance.SetState(Normal, true, 0);
3370 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3374 // Restore Selection
3375 if(selectedClassName)
3378 for(oClass = classes.first; oClass; oClass = oClass.next)
3380 if(!strcmp(oClass.name, selectedClassName))
3382 this.oClass = oClass;
3386 delete selectedClassName;
3395 for(check = this.oClass.instances.first; check; check = check.next)
3397 if(check.name && !strcmp(check.name, selectedName))
3399 this.selected = check;
3405 if(this.oClass.instances.first)
3406 this.selected = this.oClass.instances.first;
3408 this.selected = this.oClass;
3411 else if(selectedPos == -1 || !this.oClass.instances.count)
3412 this.selected = this.oClass;
3418 if(selectedPos > this.oClass.instances.count)
3420 for(check = this.oClass.instances.first; check; check = check.next)
3422 if(selectedPos == pos++)
3424 this.selected = check;
3432 this.oClass = classes.first;
3433 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3435 delete selectedName;
3436 SetSymbolsDir(null);
3438 if(sheet.codeEditor == this)
3439 sheet.SelectObject(selected);
3442 codeModified = false;
3444 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3447 InvokeParameters(false, false, false);
3450 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3456 ChangeWorkingDir(oldWorkDir);
3458 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3459 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3460 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3461 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3462 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3464 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3466 if(inUseDebug && ide.projectView)
3467 ide.debugger.EvaluateWatches();
3470 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3473 Window control = (Window)object.instance;
3474 ObjectInfo classObject = object.oClass;
3476 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3478 if(!strcmp(_class.name, "DesignerBase")) return;
3480 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3482 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3483 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3485 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3486 (!prop.IsSet || prop.IsSet(control)))
3488 Class dataType = prop.dataTypeClass;
3490 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3494 if(dataType.type == structClass)
3496 void * dataForm = new0 byte[dataType.structSize];
3497 void * dataTest = new0 byte[dataType.structSize];
3499 ((void (*)())(void *)prop.Get)(control, dataForm);
3500 prop.Get(test, dataTest);
3502 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
3504 char tempString[1024] = "";
3506 bool needClass = true;
3510 prop.Set(test, dataForm);
3512 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
3514 eClass_FindNextMember(_class, curClass, curMember, null, null);
3515 if(*curMember != (DataMember)prop)
3516 f.Printf("%s = ", prop.name);
3518 *curMember = (DataMember)prop;
3519 *curClass = curMember->_class;
3522 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3524 f.Printf("%s", string);
3531 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3533 void * dataForm, * dataTest;
3535 dataForm = (void *)prop.Get(control);
3536 dataTest = (void *)prop.Get(test);
3538 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
3540 char tempString[1024] = "";
3545 prop.Set(test, dataForm);
3547 eClass_FindNextMember(_class, curClass, curMember, null, null);
3548 if(*curMember != (DataMember)prop)
3549 f.Printf("%s = ", prop.name);
3550 *curMember = (DataMember)prop;
3551 *curClass = curMember->_class;
3553 if(eClass_GetDesigner(dataType))
3555 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3556 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3557 f.Printf("this", prop.name);
3560 //ObjectInfo classObject;
3561 //for(classObject = classes.first; classObject; classObject = classObject.next)
3565 for(object = classObject.instances.first; object; object = object.next)
3567 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3569 f.Printf("%s", object.name);
3576 bool needClass = true;
3577 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
3578 f.Printf("%s", string);
3585 bool needClass = true;
3586 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
3588 if(!strcmp(dataType.dataTypeString, "char *"))
3591 OutputString(f, string);
3595 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3597 f.Printf("%s", string);
3600 *lastIsMethod = false;
3605 DataValue dataForm, dataTest;
3607 GetProperty(prop, control, &dataForm);
3608 GetProperty(prop, test, &dataTest);
3610 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
3613 char tempString[1024] = "";
3614 SetProperty(prop, test, dataForm);
3616 if(dataType.type != bitClass)
3618 bool needClass = true;
3620 if(dataType.type == enumClass)
3623 Class enumClass = eSystem_FindClass(privateModule, "enum");
3624 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3626 for(value = e.values.first; value; value = value.next)
3628 if((int)value.data == dataForm.i)
3630 string = value.name;
3636 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
3638 if(string && string[0])
3643 eClass_FindNextMember(_class, curClass, curMember, null, null);
3644 if(*curMember != (DataMember)prop)
3645 f.Printf("%s = ", prop.name);
3646 *curMember = (DataMember)prop;
3647 *curClass = curMember->_class;
3649 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3650 f.Printf("%sf", string);
3652 f.Printf("%s", string);
3656 else if(dataType.type == bitClass)
3658 bool needClass = true;
3660 if(*prev) f.Printf(", ");
3662 eClass_FindNextMember(_class, curClass, curMember, null, null);
3663 if(*curMember != (DataMember)prop)
3664 f.Printf("%s = ", prop.name);
3665 *curMember = (DataMember)prop;
3666 *curClass = curMember->_class;
3668 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm.ui, tempString, null, &needClass);
3670 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3672 f.Printf("%s", string);
3674 *lastIsMethod = false;
3684 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3686 Instantiation inst = object.instCode;
3687 Window control = (Window)object.instance;
3689 bool methodPresent = false;
3691 bool lastIsMethod = true;
3692 ObjectInfo classObject = object.oClass;
3698 // Instance removed, delete it
3699 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3701 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3702 position = inst.loc.end.pos + 1;
3706 bool multiLine = false;
3709 // Check if it's an unnamed instance
3712 f.Seek(inst.nameLoc.start.pos - position, current);
3713 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3714 position = inst.nameLoc.end.pos;
3716 f.Printf(object.name);
3721 if(isspace(ch) && ch != '\n')
3723 f.Seek(-1, current);
3731 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3733 f.Seek(pos - position, current);
3738 f.Seek(-1, current);
3747 f.Puts(object.name);
3752 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3753 methodPresent = true;
3761 if(ch == OpenBracket)
3767 // TODO: Simplify this?
3776 f.Seek(-1, current);
3788 if(ch == '\n') { toDelete = count; count = 0; }
3789 else if(isspace(ch)) count++;
3792 f.Seek(-1, current);
3796 toDelete += count - 6;
3806 f.Seek(-toDelete-count, current);
3807 f.DeleteBytes(toDelete);
3808 f.Seek(count, current);
3813 for(c = 0; c<toAdd; c++)
3819 methodPresent = multiLine;
3822 f.Printf(methodPresent ? "\n " : " ");
3828 // Instance not there, create a brand new one
3829 DeleteJunkBefore(f, position, &position);
3830 f.Printf(*firstObject ? "\n\n" : "\n");
3831 *firstObject = false;
3833 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3834 methodPresent = true;
3839 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3841 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3846 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3848 f.Printf(" %s %c ", control._class.name, OpenBracket);
3854 Instance test = eInstance_New(control._class);
3855 DataMember curMember = null;
3856 Class curClass = null;
3859 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3863 // Attach Method here
3864 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3866 if(prev) f.Printf(", ");
3867 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3872 if(inst && !object.deleted)
3874 MembersInit members;
3875 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3877 DeleteJunkBefore(f, position, &position);
3879 // Instance already there, clear out the properties
3880 for(members = inst.members->first; members; members = members.next)
3882 if(members.type == dataMembersInit)
3886 if(members.dataMembers)
3888 bool keptMember = false;
3889 MemberInit lastKept = null;
3891 for(member = members.dataMembers->first; member; member = member.next)
3893 Identifier ident = member.identifiers ? member.identifiers->first : null;
3894 bool deleted = false;
3896 // For now delete if it's not a method
3897 if(!member.variable) // && ident)
3899 if(!ident || !ident.next)
3901 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3904 f.Seek(member.loc.start.pos - position, current);
3905 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3906 position = member.loc.end.pos;
3911 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3912 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3913 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
3915 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
3916 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
3918 f.Seek(member.loc.start.pos - position, current);
3919 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3920 position = member.loc.end.pos;
3932 //f.Seek(member.loc.start.pos - position, current);
3933 //position = member.loc.start.pos;
3934 DeleteJunkBefore(f, member.loc.start.pos, &position);
3935 if(prev) f.Printf(", ");
3936 else if(keptMember) f.Printf(" ");
3941 if(!keptMember || !members.next)
3946 if(keptMember && lastKept != members.dataMembers->last)
3951 f.Seek(-1, current);
3957 f.Seek(-1, current);
3960 else if(!isspace(ch))
3962 f.Seek(-2, current);
3967 f.DeleteBytes(count);
3970 f.Seek(members.loc.end.pos - position, current);
3975 f.Seek(-1, current);
3977 position = members.loc.end.pos + 1;
3981 f.Seek(-1, current);
3982 position = members.loc.end.pos;
3988 lastIsMethod = false;
3993 DeleteJunkBefore(f, position, &position);
3996 if(lastKept != members.dataMembers->last)
4001 f.Seek(-1, current);
4007 f.Seek(-1, current);
4010 else if(!isspace(ch))
4012 f.Seek(-2, current);
4017 f.DeleteBytes(count);
4021 f.Seek(members.loc.end.pos - position, current);
4022 position = members.loc.end.pos;
4026 lastIsMethod = true;
4029 lastIsMethod = false;
4035 f.Seek(members.loc.end.pos - position, current);
4036 position = members.loc.end.pos;
4038 lastIsMethod = true;
4041 else if(members.type == methodMembersInit)
4043 if(this.methodAction == actionDeleteMethod && members.function == function);
4045 methodPresent = true;
4047 // Delete instance method here
4048 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4049 members.function == function)
4051 if(this.moveAttached && !*text)
4052 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4054 DeleteJunkBefore(f, members.loc.start.pos, &position);
4055 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4056 position = members.loc.end.pos + 1;
4061 DeleteJunkBefore(f, position, &position);
4065 DeleteJunkBefore(f, members.loc.start.pos, &position);
4066 lastIsMethod = true;
4070 f.Seek(members.loc.end.pos - position, current);
4071 position = members.loc.end.pos;
4073 DeleteJunkBefore(f, position, &position);
4082 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4084 Method method = this.method;
4085 DeleteJunkBefore(f, position, &position);
4091 if(!method.dataType)
4092 method.dataType = ProcessTypeString(method.dataTypeString, false);
4095 Type dataType = method.dataType;
4096 Type returnType = dataType.returnType;
4099 if(this.moveAttached)
4101 // Move function here:
4102 int newLen = strlen(method.name);
4107 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4109 // First change name of function
4110 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4111 *textSize += newLen - movedFuncIdLen;
4112 memcpy(*text + movedFuncIdPos, method.name, newLen);
4114 // Second, tab right
4117 for(c = 0; (*text)[c]; )
4120 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4123 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4124 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4128 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4138 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4140 // ADDING METHOD HERE
4142 OutputType(f, returnType, false);
4145 if(dataType.thisClass)
4147 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4149 if(dataType.thisClass.shortName)
4150 f.Printf(dataType.thisClass.shortName);
4152 f.Printf(dataType.thisClass.string);
4156 f.Printf(method.name);
4158 for(param = dataType.params.first; param; param = param.next)
4160 OutputType(f, param, true);
4165 f.Printf(" %c\n\n", OpenBracket);
4167 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4169 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4170 f.Printf(" return true;\n");
4171 else if(returnType.kind != voidType)
4172 f.Printf(" return 0;\n");
4177 if(returnType.kind != voidType)
4178 f.Printf("return ");
4179 f.Printf("%s::%s(", control._class.name, method.name);
4180 for(param = dataType.params.first; param; param = param.next)
4182 if(param.prev) f.Printf(", ");
4183 f.Printf(param.name);
4187 f.Printf(" %c\n", CloseBracket);
4193 if(!object.instCode)
4196 f.Printf(" %c;\n", CloseBracket);
4198 f.Printf("%c;\n", CloseBracket);
4200 else if(!object.deleted)
4202 // Turn this into a multiline instance when adding a method
4203 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4205 f.Printf(methodPresent ? "\n " : " ");
4207 f.Seek(inst.loc.end.pos + 1 - position, current);
4208 position = inst.loc.end.pos + 1;
4213 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4216 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4218 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4220 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4222 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4223 if(prop && prop.isProperty && !prop.conversion)
4225 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4226 (!prop.IsSet || prop.IsSet(classObject.instance)))
4228 Class dataType = prop.dataTypeClass;
4229 char tempString[1024] = "";
4231 bool specify = false;
4234 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4235 if(member && member._class == regClass)
4239 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4241 if(dataType && dataType.type == structClass)
4243 void * dataForm = new0 byte[dataType.structSize];
4244 void * dataTest = new0 byte[dataType.structSize];
4246 prop.Get(classObject.instance, dataForm);
4247 prop.Get(test, dataTest);
4249 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
4251 bool needClass = true;
4253 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
4254 prop.Set(test, dataForm);
4256 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4258 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4263 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4265 void * dataForm, * dataTest;
4267 dataForm = (void *)prop.Get(classObject.instance);
4268 dataTest = (void *)prop.Get(test);
4270 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
4272 char tempString[1024] = "";
4274 prop.Set(test, dataForm);
4276 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4278 // Shouldn't go here ...
4279 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4283 bool needClass = true;
4285 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
4287 if(!strcmp(dataType.dataTypeString, "char *"))
4289 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4290 OutputString(f, string);
4294 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4296 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4302 DataValue dataForm, dataTest;
4304 GetProperty(prop, classObject.instance, &dataForm);
4305 GetProperty(prop, test, &dataTest);
4307 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
4309 SetProperty(prop, test, dataForm);
4310 if(dataType.type == bitClass)
4312 bool needClass = true;
4313 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
4315 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4317 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4321 bool needClass = true;
4322 if(dataType.type == enumClass)
4325 Class enumClass = eSystem_FindClass(privateModule, "enum");
4326 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4328 for(value = e.values.first; value; value = value.next)
4330 if((int)value.data == dataForm.i)
4332 string = value.name;
4338 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
4339 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4340 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4342 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4351 void UpdateFormCode()
4360 else if(formModified)
4362 EditBoxStream f { editBox = editBox };
4366 Identifier movedFuncId;
4367 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4368 ObjectInfo classObject;
4374 movedFuncId = GetDeclId(function.declarator);
4375 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4376 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4379 for(classObject = classes.first; classObject; classObject = classObject.next)
4382 ClassDefinition classDef = classObject.classDefinition;
4383 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4386 bool firstObject = true;
4387 ObjectInfo object = classObject.instances.first;
4388 bool lastIsDecl = false;
4390 if(!classObject.modified) continue;
4392 test = eInstance_New(regClass);
4395 // Put it in the same desktop window...
4396 designer.PrepareTestObject(test);
4398 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4399 //f.Printf("%c\n\n", OpenBracket);
4401 // Change the _class name
4402 f.Seek(classDef.nameLoc.start.pos - position, current);
4403 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4404 f.Printf(classObject.name);
4405 position = classDef.nameLoc.end.pos;
4408 // Go to block start, delete all until no white space, put \n
4412 f.Seek(classDef.blockStart.end.pos - position, current);
4413 position = classDef.blockStart.end.pos;
4415 for(; f.Getc(&ch); count++)
4419 f.Seek(-1, current);
4429 f.Seek(-count, current);
4431 f.DeleteBytes(count-back);
4433 position += count-back;
4436 // Output properties
4437 OutputClassProperties(classObject.instance._class, classObject, f, test);
4439 for(def = classDef.definitions->first; def; def = def.next)
4443 case defaultPropertiesClassDef:
4445 bool keptMember = false;
4447 MemberInit lastKept = null;
4450 DeleteJunkBefore(f, def.loc.start.pos, &position);
4453 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4455 Identifier ident = propDef.identifiers->first;
4456 bool deleted = false;
4458 // For now delete if it's a prop
4459 if(!propDef.variable && ident)
4463 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4466 f.Seek(propDef.loc.start.pos - position, current);
4467 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4468 position = propDef.loc.end.pos;
4473 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4474 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4476 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4477 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4479 f.Seek(propDef.loc.start.pos - position, current);
4480 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4481 position = propDef.loc.end.pos;
4499 f.Seek(def.loc.end.pos - position - 1, current);
4504 f.Seek(-1, current);
4507 position = def.loc.end.pos;
4511 if(lastKept != def.defProperties->last)
4516 f.Seek(-1, current);
4522 f.Seek(-1, current);
4525 else if(!isspace(ch))
4527 f.Seek(-2, current);
4532 f.DeleteBytes(count);
4536 f.Seek(def.loc.end.pos - position, current);
4537 position = def.loc.end.pos;
4542 case declarationClassDef:
4544 Declaration decl = def.decl;
4546 if(decl.type == instDeclaration)
4548 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4550 while(def.object && object != def.object)
4552 if(object /*&& ((ObjectInfo)def.object).modified*/)
4553 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4554 object = object.next;
4557 DeleteJunkBefore(f, def.loc.start.pos, &position);
4558 f.Printf(firstObject ? "\n\n " : "\n ");
4559 firstObject = false;
4561 if(def.object && ((ObjectInfo)def.object).modified)
4562 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4564 object = object ? object.next : null;
4568 DeleteJunkBefore(f, def.loc.start.pos, &position);
4569 f.Printf(firstObject ? "\n\n " : "\n ");
4570 firstObject = false;
4576 DeleteJunkBefore(f, def.loc.start.pos, &position);
4577 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4582 case functionClassDef:
4584 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4585 if(!def.function.body) continue;
4589 DeleteJunkBefore(f, def.loc.start.pos, &position);
4592 // Delete _class methods
4593 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4594 def.function == function)
4599 if(moveAttached && !text)
4601 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4604 f.Seek(def.loc.end.pos - position, current);
4605 for(; f.Getc(&ch); count++)
4609 f.Seek(-1, current);
4613 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4615 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4616 position = def.loc.end.pos + count;
4619 // In case of detaching methods in the _class, simply rename the method
4620 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4622 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4623 f.DeleteBytes(movedFuncIdLen);
4625 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4628 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4629 function == def.function)
4631 // In case of attaching methods in the _class, simply rename the method
4632 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4633 position = function.loc.start.pos + movedFuncIdPos;
4634 f.DeleteBytes(movedFuncIdLen);
4635 if(method.dataType.thisClass)
4636 f.Printf("%s::", method.dataType.thisClass.string);
4637 f.Puts(method.name);
4638 position += movedFuncIdLen;
4643 DeleteJunkBefore(f, def.loc.start.pos, &position);
4644 if(def.type == memberAccessClassDef)
4647 firstObject = false;
4657 f.Seek(def.loc.end.pos - position, current);
4658 position = def.loc.end.pos;
4661 // Output attached methods
4662 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4664 DeleteJunkBefore(f, position, &position);
4665 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4668 // ********** INSTANCES ***************
4669 for(; object; object = object.next)
4671 if(!object.instCode)
4673 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4677 DeleteJunkBefore(f, position, &position);
4679 // ****************** METHODS ***********************
4680 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4682 // If detaching an instance method
4683 if(selected != classObject)
4685 int newLen = strlen(methodName);
4688 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4689 // Tab selection left
4692 for(c = 0; text[c]; )
4695 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4696 memmove(text+start, text+start+i, textSize+1-start-i);
4699 for(; text[c] && text[c] != '\n'; c++);
4705 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4706 textSize += newLen - movedFuncIdLen;
4707 memcpy(text + movedFuncIdPos, methodName, newLen);
4714 if(methodAction == actionAddMethod && selected == classObject)
4716 Method method = this.method;
4718 if(!method.dataType)
4719 method.dataType = ProcessTypeString(method.dataTypeString, false);
4721 // ADDING METHOD HERE
4723 Type dataType = method.dataType;
4724 Type returnType = dataType.returnType;
4726 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4730 OutputType(f, returnType, false);
4733 if(dataType.thisClass && !dataType.classObjectType)
4735 if(dataType.thisClass.shortName)
4736 f.Printf(dataType.thisClass.shortName);
4738 f.Printf(dataType.thisClass.string);
4741 f.Printf(method.name);
4743 for(param = dataType.params.first; param; param = param.next)
4745 OutputType(f, param, true);
4750 f.Printf(" %c\n\n", OpenBracket);
4752 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4754 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4755 f.Printf(" return true;\n");
4756 else if(returnType && returnType.kind != voidType)
4757 f.Printf(" return 0;\n");
4762 if(returnType.kind != voidType)
4763 f.Printf("return ");
4765 char * name = ((Specifier)classDef.baseSpecs->first).name;
4766 Symbol _class = FindClass(name);
4767 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4769 for(param = dataType.params.first; param; param = param.next)
4771 if(param.prev) f.Printf(", ");
4772 if(param.kind != voidType)
4773 f.Printf(param.name);
4778 f.Printf(" %c", CloseBracket);
4782 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4794 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4795 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4799 codeModified = false;
4800 formModified = false;
4802 moveAttached = false;
4807 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4810 ClassFunction function = null;
4813 ObjectInfo object = this.selected;
4815 if(object && object == this.oClass)
4817 ClassDefinition classDef = object.oClass.classDefinition;
4819 if(classDef && classDef.definitions)
4821 for(def = classDef.definitions->first; def; def = def.next)
4823 if(def.type == functionClassDef && def.function.declarator)
4825 if(!strcmp(def.function.declarator.symbol.string, methodName))
4827 function = def.function;
4832 else if(def.type == defaultPropertiesClassDef)
4836 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4838 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4839 if(ident && !ident.next)
4841 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4845 propLoc = propDef.loc;
4848 ClassDefinition classDef = object.oClass.classDefinition;
4850 if(classDef.definitions)
4852 for(def = classDef.definitions->first; def; def = def.next)
4854 if(def.type == functionClassDef)
4856 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4858 function = def.function;
4877 Instantiation inst = object.instCode;
4879 // Check here to see if the method already exists, no need to call ModifyCode in that case
4880 if(inst && inst.members)
4882 MembersInit members;
4883 for(members = inst.members->first; members; members = members.next)
4885 switch(members.type)
4887 case dataMembersInit:
4889 if(members.dataMembers)
4892 for(member = members.dataMembers->first; member; member = member.next)
4894 Identifier ident = member.identifiers ? member.identifiers->first : null;
4895 if(ident && !ident.next)
4897 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4901 propLoc = member.loc;
4904 ClassDefinition classDef = object.oClass.classDefinition;
4906 if(classDef.definitions)
4908 for(def = classDef.definitions->first; def; def = def.next)
4910 if(def.type == functionClassDef)
4912 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
4914 function = def.function;
4923 // TODO: Fix memory leak
4924 function = ClassFunction
4926 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
4938 case methodMembersInit:
4940 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
4942 function = members.function;
4954 if(functionPtr) *functionPtr = function;
4958 void GoToMethod(char * methodName /*Method method*/)
4962 ObjectInfo object = selected;
4963 EditBoxStream f { editBox = editBox };
4964 ClassFunction function = null;
4965 bool atChar = false;
4969 Location propLoc = { {0,0,-1} };
4972 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
4973 if(function && function.body)
4976 f.Seek(function.body.loc.start.pos+1, current);
4986 f.Seek(-1, current);
4991 else if(!isspace(ch))
4993 f.Seek(-1, current);
4999 else if(propLoc.start.pos > -1)
5001 f.Seek(propLoc.start.pos, current);
5004 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5006 if(function || propLoc.start.pos > -1)
5008 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5009 editBox.CenterOnCursor();
5010 SetState(normal, false, 0);
5013 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5015 FreeClassFunction(function);
5021 void FindCompatibleMethods(Method method, OldList compatible)
5023 ClassDefinition classDef = this.oClass.classDefinition;
5024 if(classDef && classDef.definitions)
5027 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5030 Symbol classSym { };
5031 Symbol selectedClass;
5032 if(this.selected == this.oClass)
5033 selectedClass = classSym;
5035 selectedClass = FindClass(this.selected.instance._class.name);
5037 regClass.name = classDef._class.name;
5038 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5039 for(def = classDef.definitions->first; def; def = def.next)
5041 if(def.type == functionClassDef && def.function.declarator)
5043 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5045 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5048 Type type = def.function.declarator.symbol.type;
5049 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5051 compatible.Add(OldLink { data = def.function });
5057 if(this.oClass && this.oClass.instance)
5059 classSym.registered = regClass;
5060 //classSym.registered = this.oClass.oClass;
5062 for(_class = regClass.base; _class; _class = _class.base)
5065 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5067 // TODO: Understand why these functions popup in attach list
5068 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5070 if(!testMethod.dataType)
5071 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5073 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5074 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5075 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5077 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5078 // ClassFunction function { };
5079 FunctionDefinition function { };
5081 function.declarator = Declarator { };
5082 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5083 excludedSymbols.Add(function.declarator.symbol);
5085 compatible.Add(OldLink { data = function });
5096 void AddMethod(Method method)
5100 char methodName[1024];
5101 strcpy(methodName, method.name);
5102 if(!FindMethod(methodName, null, null))
5104 methodAction = actionAddMethod;
5105 this.method = method;
5109 GoToMethod(methodName);
5113 void DeleteMethod(ClassFunction function)
5117 methodAction = actionDeleteMethod;
5118 this.function = function;
5126 void AttachMethod(Method method, ClassFunction function)
5130 // If it's an instance we'll ask if we want to move it inside...
5131 if(!function.attached.count && function.body)
5133 // Find the function in the _class to check if it's a virtual function
5134 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5135 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5136 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5138 for(def = this.classDefinition.first; def; def = def.next)
5140 if(def.type == functionClassDef)
5142 if(def.function == function)
5147 if(!method || method.type != virtualMethod)
5150 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5151 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5153 moveAttached = true;
5158 methodAction = actionAttachMethod;
5159 this.method = method;
5160 this.function = function;
5167 void ReAttachMethod(Method method, ClassFunction function)
5171 // If it's an instance we'll ask if we want to move it inside...
5172 if(!function.attached.count && function.body)
5174 // Find the function in the _class to check if it's a virtual function
5175 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5176 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5177 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5179 for(def = this.classDefinition.first; def; def = def.next)
5181 if(def.type == functionClassDef)
5183 if(def.function == function)
5188 if(!method || method.type != virtualMethod)
5191 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5192 if(MessageBox { type = yesNo, master = parent, text = title,
5193 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5195 moveAttached = true;
5200 methodAction = actionReattachMethod;
5201 this.method = method;
5202 this.function = function;
5209 void DetachMethod(Method method, ClassFunction function, int type)
5217 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5218 master = sheet, text = $"Name detached method", background = activeBorder
5222 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5223 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5227 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5228 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5232 dialog, anchor = { left = 5, right = 5, top = 5 }
5234 sprintf(methodName, "%s_%s", selected.name, method.name);
5235 nameBox.contents = methodName;
5237 result = dialog.Modal() == ok;
5238 strcpy(methodName, nameBox.contents);
5243 // If the method is not attached, move it outside
5246 // Add this class to the methodName
5247 char name[1024] = "";
5249 if(this.selected != this.oClass && !method.dataType.thisClass)
5251 strcat(name, this.selected.instance._class.name);
5253 strcat(name, this.methodName);
5254 strcpy(this.methodName, name);
5256 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5258 strcat(name, method.dataType.thisClass.string);
5260 strcat(name, this.methodName);
5261 strcpy(this.methodName, name);
5264 this.moveAttached = true;
5267 this.methodAction = actionDetachMethod;
5268 this.method = method;
5269 this.function = function;
5276 void AddObject(Instance instance, ObjectInfo * object)
5280 //*object = _class.instances.Add(sizeof(ObjectInfo));
5281 *object = ObjectInfo { };
5282 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5283 (*object).oClass = oClass;
5284 (*object).instance = instance;
5289 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5291 // if(strcmp(name, this.oClass.instance.name))
5294 for(check = oClass.instances.first; check; check = check.next)
5295 if(!check.deleted && check.name && !strcmp(name, check.name))
5299 (*object).name = CopyString(name);
5304 toolBox.controlClass = null;
5308 //sheet.AddObject(*object, (*object).name, TypeData, true);
5313 void EnsureUpToDate()
5315 if(sheet && codeModified)
5319 void SelectObject(ObjectInfo object)
5322 oClass = object ? object.oClass : null;
5324 designer.SelectObject(object, object ? object.instance : null);
5327 void SelectObjectFromDesigner(ObjectInfo object)
5330 sheet.SelectObject(object);
5333 void EnumerateObjects(Sheet sheet)
5337 for(oClass = classes.first; oClass; oClass = oClass.next)
5343 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5344 for(object = oClass.instances.first; object; object = object.next)
5345 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5348 sheet.SelectObject(selected);
5353 designer.AddObject();
5356 void DeleteObject(ObjectInfo object)
5358 delete object.instance;
5359 object.deleted = true;
5360 object.modified = true;
5361 object.oClass.modified = true;
5363 if(selected == object)
5365 bool looped = false;
5366 ObjectInfo select = object;
5370 select = select.prev;
5374 select = object.oClass.instances.last;
5381 sheet.SelectObject(select ? select : oClass);
5384 if(!object.instCode && object.oClass != object)
5387 oClass.instances.Delete(object);
5390 if(sheet.codeEditor == this)
5391 sheet.DeleteObject(object);
5394 void RenameObject(ObjectInfo object, char * name)
5398 // Validate the name:
5399 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5400 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5403 for(c = 0; name[c]; c++)
5404 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5412 object.name = (name && name[0]) ? CopyString(name) : null;
5414 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5418 void DesignerModifiedObject()
5420 sheet.ListProperties(false);
5424 void ListSubMembers(Type member)
5428 for(subMember = member.members.first; subMember; subMember = subMember.next)
5432 DataRow row = membersList.AddString(subMember.name);
5433 row.icon = icons[typeData];
5437 ListSubMembers(subMember);
5442 void ListSubDataMembers(DataMember member, bool isPrivate)
5444 DataMember subMember;
5445 for(subMember = member.members.first; subMember; subMember = subMember.next)
5447 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5451 DataRow row = membersList.AddString(subMember.name);
5452 BitmapResource bitmap = null;
5453 if(!subMember.dataType)
5454 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5456 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5458 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5461 bitmap = { bitmapName };
5462 membersList.AddResource(bitmap);
5465 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5469 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5475 void ListClassMembers(Class whatClass, bool methodsOnly)
5478 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5479 bool isPrivate = false;
5481 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5483 Method method, methodIt;
5485 DataMember memberIt;
5487 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5489 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5490 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5492 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5494 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5496 DataRow row = membersList.FindString(method.name);
5499 row = membersList.AddString(method.name);
5501 if(!method.dataType)
5502 method.dataType = ProcessTypeString(method.dataTypeString, false);
5504 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5512 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5516 if(memberIt.isProperty)
5518 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5520 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5524 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5526 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5529 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5535 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5537 if(member.isProperty)
5539 Property prop = (Property) member;
5540 if(!membersList.FindString(prop.name))
5542 DataRow row = membersList.AddString(prop.name);
5543 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5546 else if(member.name && !membersList.FindString(member.name))
5548 DataRow row = membersList.AddString(member.name);
5550 BitmapResource bitmap = null;
5551 if(!member.dataType)
5552 member.dataType = ProcessTypeString(member.dataTypeString, false);
5554 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5556 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5559 bitmap = { bitmapName };
5560 membersList.AddResource(bitmap);
5563 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5566 ListSubDataMembers(member, member.memberAccess == privateAccess);
5570 if(_class.inheritanceAccess == privateAccess)
5573 if(_class.module != privateModule) break;
5578 void ListClassMembersMatch(Class whatClass, Type methodType)
5581 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5582 bool isPrivate = false;
5584 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5590 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5592 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5594 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5596 if(!method.dataType)
5597 method.dataType = ProcessTypeString(method.dataTypeString, false);
5599 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5601 DataRow row = membersList.FindString(method.name);
5604 row = membersList.AddString(method.name);
5605 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5611 if(_class.inheritanceAccess == privateAccess)
5614 if(_class.module != privateModule) break;
5619 void ListClassPropertiesAndVirtual(Class whatClass)
5622 bool isPrivate = false;
5623 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5629 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5631 if(method.type == virtualMethod)
5633 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5635 DataRow row = membersList.FindString(method.name);
5638 row = membersList.AddString(method.name);
5640 if(!method.dataType)
5641 method.dataType = ProcessTypeString(method.dataTypeString, false);
5643 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5649 for(member = _class.membersAndProperties.first; member; member = member.next)
5651 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5653 if(member.isProperty)
5655 Property prop = (Property)member;
5657 DataRow row = membersList.AddString(prop.name);
5658 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5661 else if(member.name)
5663 DataRow row = membersList.AddString(member.name);
5665 BitmapResource bitmap = null;
5666 if(!member.dataType)
5667 member.dataType = ProcessTypeString(member.dataTypeString, false);
5669 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5671 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5674 bitmap = { bitmapName };
5675 membersList.AddResource(bitmap);
5678 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5681 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5684 if(_class.inheritanceAccess == privateAccess)
5687 if(_class.module != privateModule) break;
5692 void ListMembers(Type type)
5694 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5698 if(type.kind == classType)
5701 ListClassMembers(type._class.registered, false);
5706 for(member = type.members.first; member; member = member.next)
5710 DataRow row = membersList.AddString(member.name);
5711 row.icon = icons[typeData];
5713 else if(member.kind == structType || member.kind == unionType)
5714 ListSubMembers(member);
5720 void ListModule(Module mainModule, int recurse, bool listClasses)
5723 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5724 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5725 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5726 for(module = mainModule.application.allModules.first; module; module = module.next)
5728 if(ModuleVisibility(mainModule, module))
5729 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5733 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5740 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5742 Class _class = link.data;
5743 if(_class.type != systemClass)
5745 DataRow row = membersList.AddString(_class.name);
5746 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5751 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5753 DefinedExpression definedExp = link.data;
5754 DataRow row = membersList.AddString(link /*definedExp*/.name);
5755 row.icon = icons[typeData];
5758 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5760 GlobalFunction function = link.data;
5761 DataRow row = membersList.AddString(link /*function*/.name);
5762 row.icon = icons[typeMethod];
5766 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5768 if(recurse != 2 && listClasses)
5770 if(!membersList.FindString(ns->name))
5772 DataRow row = membersList.AddString(ns->name);
5773 row.icon = icons[typeNameSpace];
5778 ListNameSpace(ns, 2, listClasses);
5782 void ListEnumValues(Class _class)
5784 for(; _class && _class.type == enumClass; _class = _class.base)
5786 EnumClassData enumeration = (EnumClassData)_class.data;
5788 for(item = enumeration.values.first; item; item = item.next)
5790 DataRow row = membersList.AddString(item.name);
5791 row.icon = icons[typeEnumValue];
5796 bool ListEnumsModule(Module mainModule, Type dest)
5798 bool result = false;
5800 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5801 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5802 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5803 for(module = mainModule.application.allModules.first; module; module = module.next)
5805 if(ModuleVisibility(mainModule, module))
5806 result |= ListEnums(module.publicNameSpace, dest);
5811 void ListNameSpaceByString(Module mainModule, char * string)
5813 NameSpace * nameSpace;
5815 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5816 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5817 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5818 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5819 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5820 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5821 for(module = mainModule.application.allModules.first; module; module = module.next)
5823 if(ModuleVisibility(mainModule, module))
5825 nameSpace = FindNameSpace(module.publicNameSpace, string);
5826 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5831 bool ListEnums(NameSpace nameSpace, Type dest)
5834 bool result = false;
5836 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5838 Class _class = link.data;
5839 if(_class.type == enumClass && (dest.kind != classType || !dest._class || dest._class.registered != _class))
5841 OldList conversions { };
5843 type.kind = classType;
5844 type._class = FindClass(_class.name);
5845 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5847 ListEnumValues(_class);
5850 conversions.Free(null);
5854 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5856 result |= ListEnums(nameSpace, dest);
5861 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5865 for(c = 0; (ch = name[c]); c++)
5867 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5869 NameSpace * newSpace;
5870 char * spaceName = new char[c - start + 1];
5871 memcpy(spaceName, name + start, c - start);
5872 spaceName[c-start] = '\0';
5873 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5877 nameSpace = newSpace;
5886 return (NameSpace *)nameSpace;
5889 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5891 bool listedEnums = false;
5892 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5893 bool listClasses = true;
5895 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5897 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5898 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5899 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5901 if(exp.type == identifierExp)
5902 id = realIdentifier;
5904 if(id && id._class && !id._class.name)
5906 listClasses = false;
5909 else if(id && id._class && id._class.name)
5913 Class _class = id.classSym.registered;
5914 if(_class && _class.type == enumClass)
5916 ListEnumValues(_class);
5919 ListClassMembers(id.classSym.registered, true);
5924 else if(id && colons)
5926 ListNameSpaceByString(this.privateModule, id.string);
5931 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
5933 listedEnums = ListEnumsModule(this.privateModule, destType);
5936 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
5938 ListEnumValues(destType._class.registered);
5941 ListClassPropertiesAndVirtual(insideClass);
5945 else if(destType && destType.kind == enumType)
5949 for(value = destType.members.first; value; value = value.next)
5951 DataRow row = membersList.AddString(value.name);
5952 row.icon = icons[typeEnumValue];
5956 ListClassPropertiesAndVirtual(insideClass);
5960 else if(insideClass && !enumOnly)
5962 ListClassPropertiesAndVirtual(insideClass);
5965 if(listedEnums && string && string[0])
5967 DataRow row = membersList.FindSubString(string);
5969 listedEnums = false;
5972 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
5974 ListClassMembersMatch(GetThisClass(), exp.destType);
5976 else if(!insideClass && !enumOnly && !listedEnums)
5979 Symbol symbol = null;
5983 ListClassMembers(GetThisClass(), false);
5986 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
5988 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
5990 // Don't list enum values?
5991 //if(symbol.type.kind != TypeEnum)
5992 DataRow row = membersList.FindString(symbol.string);
5995 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
5997 row = membersList.AddString(symbol.string);
5998 if(symbol.type && symbol.type.kind == functionType)
5999 row.icon = icons[typeMethod];
6000 else if(symbol.type && symbol.type.kind == enumType)
6002 row.icon = icons[typeEnumValue];
6006 BitmapResource bitmap = null;
6007 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6009 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6012 bitmap = { bitmapName };
6013 membersList.AddResource(bitmap);
6016 row.icon = bitmap ? bitmap : icons[typeData];
6023 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6025 DataRow row = membersList.FindString(symbol.string);
6028 row = membersList.AddString(symbol.string);
6029 if(symbol.type.kind == functionType)
6030 row.icon = icons[typeMethod];
6031 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6033 row.icon = icons[typeClass];
6037 row.icon = icons[typeDataType];
6044 ListModule(this.privateModule, 1, listClasses);
6045 // TODO: Implement this with name space
6049 for(data = globalData.first; data; data = data.next)
6051 DataRow row = membersList.FindString(data.name);
6053 data.dataType = ProcessTypeString(data.dataTypeString, false);
6056 row = membersList.AddString(data.name);
6058 if(data.dataType && data.dataType.kind == TypeEnum)
6060 row.icon = icons[typeEnumValue];
6064 BitmapResource bitmap = null;
6065 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6067 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6070 bitmap = { bitmapName };
6071 membersList.AddResource(bitmap);
6074 row.icon = bitmap ? bitmap : icons[typeData];
6082 DataRow row = membersList.AddString("Min");
6083 row.icon = icons[typeMethod];
6085 row = membersList.AddString("Max");
6086 row.icon = icons[typeMethod];
6088 row = membersList.AddString("Abs");
6089 row.icon = icons[typeMethod];
6091 row = membersList.AddString("Sgn");
6092 row.icon = icons[typeMethod];
6098 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6100 EditBoxStream f { editBox = editBox };
6105 updatingCode = true;
6107 if(!method.dataType)
6108 method.dataType = ProcessTypeString(method.dataTypeString, false);
6110 DeleteJunkBefore(f, function.loc.start.pos, &position);
6111 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6113 // ADDING METHOD HERE
6115 Type dataType = method.dataType;
6116 Type returnType = dataType.returnType;
6118 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6124 if(extraIndent) f.Printf(" ");
6126 OutputType(f, returnType, false);
6130 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6132 if(dataType.thisClass.shortName)
6133 f.Printf(dataType.thisClass.shortName);
6135 f.Printf(dataType.thisClass.string);
6138 f.Printf(method.name);
6140 for(param = dataType.params.first; param; param = param.next)
6142 // Decided not to write void...
6143 if(param.kind != voidType)
6145 OutputType(f, param, true);
6151 if(extraIndent) f.Printf(" ");
6152 f.Printf(" %c\n", OpenBracket);
6154 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6158 //if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
6160 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6162 if(extraIndent) f.Printf(" ");
6163 f.Printf(" return true;\n");
6165 else if(returnType && returnType.kind != voidType)
6167 if(extraIndent) f.Printf(" ");
6168 f.Printf(" return 0;\n");
6174 if(returnType.kind != voidType)
6175 f.Printf("return ");
6176 f.Printf("%s::%s(this", classDef.base.name, method.name);
6177 for(param = dataType.params.first; param; param = param.next)
6180 f.Printf(param.name);
6187 if(extraIndent) f.Printf(" ");
6188 f.Printf(" %c", CloseBracket);
6193 if(extraIndent) { x1 += 3; x2 += 3; }
6194 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6196 this.updatingCode = false;
6200 // Return false if we overrided a function and don't want to run params listing
6201 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6203 bool didOverride = false;
6204 EditLine line = editBox.line;
6205 char * text = line.text;
6206 int lineNum, charPos;
6207 Expression exp = null;
6210 //Identifier id = null;
6211 Expression memberExp = null;
6212 Identifier realIdentifier = null;
6214 if(!privateModule) return !didOverride;
6216 insideFunction = null;
6218 charPos = editBox.charPos + 1;
6219 if(!membersListShown)
6224 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6226 EditBoxStream f { editBox = editBox };
6228 updatingCode = true;
6229 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6233 if(!f.Seek(-1, current))
6236 if(!isspace(ch)) break;
6237 f.Seek(-1, current);
6239 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6241 lineNum = editBox.lineNumber + 1;
6242 charPos = editBox.charPos + 1;
6244 updatingCode = false;
6247 if(!membersListShown)
6249 memberExp = FindExpTree(ast, lineNum, charPos);
6250 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6255 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6257 EditBoxStream f { editBox = editBox };
6260 updatingCode = true;
6262 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6265 if(ch == '}' || ch == ',' || ch == ')')
6267 f.Seek(-1, current);
6275 if(!f.Seek(-1, current))
6278 if(!isspace(ch)) break;
6279 f.Seek(-1, current);
6283 f.Seek(-1, current);
6285 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6287 lineNum = editBox.lineNumber + 1;
6288 charPos = editBox.charPos + 1;
6290 updatingCode = false;
6293 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6298 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6299 lineNum = editBox.lineNumber + 1;
6300 charPos = editBox.charPos/* + 1*/;
6304 char tempString[1024];
6305 char * string = null;
6306 CodePosition idStart, idEnd;
6308 if(membersListShown)
6310 char * buffer = membersLine.text;
6312 bool firstChar = true;
6314 string = tempString;
6316 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6318 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6319 if(!isSpace) firstChar = false;
6321 string[len++] = buffer[c];
6325 else //if(realIdentifier)//if(id)
6328 char * buffer = id.string;
6330 bool firstChar = true;
6332 string = tempString;
6333 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6335 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6336 if(!isSpace) firstChar = false;
6338 string[len++] = buffer[c];
6344 EditLine editLine = editBox.line;
6345 bool firstChar = true;
6348 string = tempString;
6349 for(y = lineNum-1; y >= 0; y--)
6351 char * buffer = editLine.text;
6352 int lineCount = editLine.count;
6353 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6355 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6360 idEnd.charPos = x + 2;
6365 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6368 idEnd.charPos = x + 2;
6375 if(!isalnum(buffer[x]) && buffer[x] != '_')
6381 memmove(string+1, string, len++);
6382 string[0] = buffer[x];
6386 //if(done || firstChar)
6387 if(done || !firstChar)
6389 editLine = editLine.prev;
6392 if(!strcmp(string, "case"))
6398 else if(!strcmp(string, "return"))
6404 else if(!strcmp(string, "delete"))
6410 else if(!strcmp(string, "new"))
6416 else if(!strcmp(string, "renew"))
6424 idStart.charPos = x + 1;
6425 idStart.line = y + 1;
6428 if(!membersListShown)
6430 membersList.Clear();
6431 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6433 Type type = memberExp.member.exp.expType;
6434 if(pointer == 2 && type)
6436 if(type.kind == pointerType || type.kind == arrayType)
6445 ListSymbols(exp, enumOnly, string, realIdentifier);
6447 membersList.Sort(null, 1);
6452 // Virtual function override
6453 Identifier id = GetDeclId(insideFunction.declarator);
6454 char * string = id ? id.string : null;
6456 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6459 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6460 insideFunction = null;
6463 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6468 if(!didOverride) //insideFunction)
6470 rowCount = membersList.rowCount;
6473 DataRow row = string ? membersList.FindSubString(string) : null;
6474 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6476 char * newString = row.string;
6477 if(!membersListShown)
6479 membersLoc.start.line = idStart.line-1;
6480 membersLoc.start.charPos = idStart.charPos-1;
6481 //membersLoc.end = membersLoc.start;
6482 membersLoc.end.charPos = idEnd.charPos-1;
6483 membersLoc.end.line = idEnd.line-1;
6484 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6485 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6490 membersList.Destroy(0);
6491 membersListShown = false;
6494 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6496 line, membersLoc.start.line, membersLoc.start.charPos,
6497 line, membersLoc.end.line, membersLoc.end.charPos);
6498 editBox.PutS(newString);
6504 row = membersList.FindSubStringi(string);
6506 membersList.currentRow = row;
6507 membersList.currentRow.selected = false;
6510 membersList.currentRow = row;
6512 if(!membersListShown)
6516 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6517 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6518 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6519 editBox.GetCaretPosition(caret);
6520 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6522 membersList.master = this;
6524 caret.y += editBox.GetCaretSize();
6526 membersList.Create();
6529 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6530 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6531 Window parent = membersList.parent;
6533 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6535 y -= editBox.GetCaretSize() + membersList.size.h;
6536 membersAbove = true;
6539 membersAbove = false;
6541 membersList.position = { x, y };
6545 membersLoc.start.line = lineNum - 1;
6547 if(string && string[0])
6549 membersLoc.start.charPos = idStart.charPos-1;
6550 membersLoc.end = membersLoc.start;
6551 //membersLoc.end.charPos = id.loc.end.charPos-1;
6552 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6556 membersLoc.start.charPos = charPos;
6557 membersLoc.end = membersLoc.start;
6558 membersLoc.end.charPos = charPos;
6560 membersListShown = true;
6562 // Hack to keep caret shown
6563 editBox.GetCaretPosition(caret);
6564 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6567 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6573 SetCurrentContext(globalContext);
6576 return !didOverride;
6579 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6581 EditLine line = editBox.line;
6582 char * text = line.text;
6583 int lineNum, charPos;
6584 Expression exp = null;
6588 charPos = editBox.charPos + 1;
6591 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6593 EditBoxStream f { editBox = editBox };
6596 updatingCode = true;
6597 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6600 if(ch == '}' || ch == ',' || ch == ')')
6602 f.Seek(-1, current);
6610 if(!f.Seek(-1, current))
6613 if(!isspace(ch)) break;
6614 f.Seek(-1, current);
6618 f.Seek(-1, current);
6620 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6622 lineNum = editBox.lineNumber + 1;
6623 charPos = editBox.charPos + 1;
6625 updatingCode = false;
6628 charPos = Min(charPos, l1.count + 1);
6630 FindParamsTree(ast, lineNum, charPos);
6632 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6633 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6635 ::functionType = null;
6636 ::instanceType = null;
6639 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6640 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6644 Window parent = paramsList.parent;
6646 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6649 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6650 // ( Dummy exp: always ends up with same memory)
6652 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6653 editBox.GetCaretPosition(paramsPosition);
6654 this.paramsPosition.y += editBox.GetCaretSize();
6657 FreeType(this.functionType);
6658 FreeType(this.instanceType);
6660 this.functionType = ::functionType;
6661 this.instanceType = ::instanceType;
6663 if(this.functionType) this.functionType.refCount++;
6664 if(this.instanceType) this.instanceType.refCount++;
6666 this.paramsID = ::paramsID;
6667 functionExp = paramsInsideExp;
6669 paramsList.master = this;
6671 paramsList.Create();
6673 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6674 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6676 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6678 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6682 paramsAbove = false;
6683 if(x + paramsList.size.w > parent.clientSize.w)
6685 x = parent.clientSize.w - paramsList.size.w;
6689 paramsList.position = { x, y };
6691 // Hack to keep caret shown
6694 editBox.GetCaretPosition(caret);
6695 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6698 this.paramsShown = true;
6700 else if((!::functionType && !::instanceType) || reposition)
6702 paramsList.Destroy(0);
6703 paramsShown = false;
6705 FreeType(this.functionType);
6706 FreeType(this.instanceType);
6707 this.functionType = null;
6708 this.instanceType = null;
6712 SetCurrentContext(globalContext);
6720 designer.visible = true;
6721 designer.Activate();
6727 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6729 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };