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", 12 };
39 FontResource codeFont { $"Consolas", 12 };
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];
641 bool membersListShown;
644 EditLine membersLine;
646 Type functionType, instanceType;
650 Point paramsPosition;
651 Expression functionExp;
654 BitmapResource icons[CodeObjectType];
656 FontResource boldFont { $"Tahoma", 8.25f, bold = true, window = this };
657 FontResource normalFont { $"Tahoma", 8.25f, window = this };
659 Module privateModule;
660 NameSpace globalData;
663 OpenedFileInfo openedFileInfo;
665 FontResource font { codeFont.faceName, codeFont.size };
666 saveDialog = codeEditorFileDialog;
668 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
670 void ProcessCaretMove(EditBox editBox, int line, int charPos)
673 ObjectInfo classItem;
675 // OnActivateClient is called after OnActivate
678 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
681 if(sheet.codeEditor != this) return;
685 for(classItem = classes.first; classItem; classItem = classItem.next)
687 ClassDefinition classDef = classItem.classDefinition;
688 if(classDef && classDef.loc.Inside(line, charPos))
695 for(object = classItem.instances.first; object; object = object.next)
699 if(object.instCode.loc.Inside(line, charPos))
704 sheet.SelectObject(object);
706 sheet.SelectObject(classItem);
711 //sheet.SelectObject(null);
715 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
719 expectingMove = false;
725 if(line-1 != membersLoc.start.line)
729 char * buffer = membersLine.text;
732 if(charPos - 1 < membersLoc.start.charPos)
734 else if(charPos - 1 > membersLoc.end.charPos)
736 char * buffer = membersLine.text;
737 //if(membersList.currentRow)
741 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
742 if(buffer[c] != ' ' && buffer[c] != '\t')
744 if(c < charPos && buffer[c])
751 membersList.Destroy(0);
752 membersListShown = false;
756 bool back = codeModified;
757 codeModified = false;
759 InvokeParameters(false, false, false);
760 /*if(membersListShown)
761 InvokeAutoComplete(false, 0, true);*/
768 watch(modifiedDocument)
770 ProjectView projectView = ide.projectView;
773 ProjectNode node = projectView.GetNodeFromWindow(this, null);
776 node.modified = modifiedDocument;
777 projectView.Update(null);
785 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
786 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
787 tabKey = true, smartHome = true;
788 tabSelection = true, maxLineSize = 65536, parent = this, hasHorzScroll = true, hasVertScroll = true;
789 selectionColor = selectionColor, selectionText = selectionText,
790 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
791 font = font, borderStyle = none;
792 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
794 bool OnMouseOver(int x, int y, Modifiers mods)
796 CodeEditor editor = (CodeEditor)master;
797 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
802 void NotifyCaretMove(EditBox editBox, int line, int charPos)
804 // Update Line Numbers
806 int oldLine = lastLine;
807 display.FontExtent(font.font, " ", 1, null, &spaceH);
809 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
813 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
818 if(ide.activeClient == this)
819 ProcessCaretMove(editBox, line, charPos);
821 openedFileInfo.CaretMove(line, charPos);
824 void NotifyOvrToggle(EditBox editBox, bool overwrite)
826 ide.ovr.color = overwrite ? black : Color { 128, 128, 128 };
829 void NotifyUpdate(EditBox editBox)
836 designer.modifiedDocument = true;
839 modifiedDocument = true;
842 bool NotifyUnsetModified(EditBox editBox)
844 modifiedDocument = false;
848 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
850 if(!loadingFile && after.y != before.y)
852 ProjectView projectView = ide.projectView;
853 if(projectView && fileName)
856 // HOW WE MIGHT WANT TO DO IT:
857 char * text = before.line.text;
858 for(c = before.x-1; c>= 0; c--)
859 if(!isspace(text[c]))
861 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
863 // HOW VISUAL STUDIO DOES IT:
865 char * text = after.line.text;
866 for(c = after.line.count-1; c>= 0; c--)
867 if(!isspace(text[c]))
869 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
872 Update({ 0, 0, editBox.position.x, clientSize.h });
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)
1170 if(!loadingFile && after.y != before.y)
1172 ProjectView projectView = ide.projectView;
1173 if(projectView && fileName)
1174 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1175 Update({ 0, 0, editBox.position.x, clientSize.h });
1182 for(oClass = classes.first; oClass; oClass = oClass.next)
1186 for(object = oClass.instances.first; object; object = object.next)
1190 loc = &object.instCode.loc;
1192 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1193 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1195 object.instCode = null;
1199 loc->start.AdjustDelete(before, after);
1200 loc->end.AdjustDelete(before, after);
1204 if(oClass.classDefinition)
1206 loc = &oClass.classDefinition.loc;
1207 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1208 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1210 oClass.classDefinition = null;
1214 loc->start.AdjustDelete(before, after);
1215 loc->end.AdjustDelete(before, after);
1220 if(membersListShown)
1223 if(pasteOperation || before.y != after.y)
1227 char * buffer = membersLine.text;
1229 bool firstChar = true;
1233 if(before.x >= membersLoc.start.charPos)
1235 for(c = membersLoc.start.charPos; c<before.x; c++)
1237 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1238 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1243 if(!isSpace) firstChar = false;
1246 string[len++] = buffer[c];
1251 // If deleting spaces before...
1252 for(c = before.x; c<membersLoc.start.charPos; c++)
1254 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1262 membersLoc.start.charPos = before.x;
1265 if(membersLoc.end.charPos >= after.x)
1267 for(c = after.x; c<membersLoc.end.charPos; c++)
1269 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1270 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1275 if(!isSpace) firstChar = false;
1278 string[len++] = buffer[c];
1286 membersLoc.end.charPos -= after.x - before.x;
1290 row = membersList.FindSubString(string);
1293 row = membersList.FindSubStringi(string);
1295 membersList.currentRow = row;
1296 membersList.currentRow.selected = false;
1299 membersList.currentRow = row;
1301 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1306 membersList.Destroy(0);
1307 membersListShown = false;
1313 InvokeParameters(false, false);
1321 bool NotifyDropped(EditBox editBox, int x, int y)
1323 char * controlClass = toolBox.controlClass;
1324 if(controlClass && controlClass[0])
1328 ObjectInfo classObject;
1330 //editBox.NotifyCaretMove(this, editBox, y, x);
1331 editBox.GoToLineNum(y);
1332 editBox.GoToPosition(editBox.line, y, x);
1334 classObject = selected ? selected.oClass : null;
1336 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1337 selected = classObject.instances.last;
1340 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1343 AddObject(control, &object);
1345 designer.CreateObject(control, object, false, classObject.instance);
1346 // designer.PostCreateObject(control, object, false, classObject.instance);
1347 designer.DroppedObject(control, object, false, classObject.instance);
1349 sheet.AddObject(object, object.name, typeData /* className*/, true);
1352 //codeModified = true;
1359 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1361 if(key == Key { space, ctrl = true })
1363 membersList.Destroy(0);
1364 membersListShown = false;
1365 InvokeAutoComplete(false, 0, false);
1368 else if(key == Key { space, ctrl = true, shift = true })
1369 InvokeParameters(false, true, false);
1370 else if(key == escape)
1371 ide.RepositionWindows(true);
1372 else if(key == ctrlF7)
1376 ProjectNode node = ide.projectView.GetNodeFromWindow(this, null);
1380 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1381 $"It can't be compiled.");
1382 MessageBox { type = ok, parent = ide, master = ide, text = $"File not in project error", contents = s }.Modal();
1391 bool OnKeyDown(Key key, unichar ch)
1393 CodeEditor editor = (CodeEditor)master;
1394 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1396 if(editor.membersListShown)
1398 editor.membersList.Destroy(0);
1399 editor.membersListShown = false;
1402 if(editor.paramsShown)
1404 editor.paramsList.Destroy(0);
1405 editor.paramsShown = false;
1406 FreeType(editor.functionType);
1407 FreeType(editor.instanceType);
1409 editor.functionType = null;
1410 editor.instanceType = null;
1411 editor.paramsID = -1;
1415 return EditBox::OnKeyDown(key, ch);
1418 void OnVScroll(ScrollBarAction action, int position, Key key)
1420 if(anchor.left.distance)
1422 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1425 EditBox::OnVScroll(action, position, key);
1427 CodeEditor ce = (CodeEditor)parent;
1428 if(ce.openedFileInfo)
1429 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1433 void OnHScroll(ScrollBarAction action, int position, Key key)
1435 EditBox::OnHScroll(action, position, key);
1437 CodeEditor ce = (CodeEditor)parent;
1438 if(ce.openedFileInfo)
1439 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1446 fullRowSelect = false,
1449 borderStyle = bevel;
1450 // size = { 200, 400 };
1452 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1454 DataRow row = listBox.currentRow;
1457 char * string = row.string;
1459 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1461 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1462 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1463 editBox.PutS(string);
1466 membersListShown = false;
1471 bool OnKeyDown(Key key, unichar ch)
1473 CodeEditor editor = (CodeEditor) master;
1474 if(key == escape || key == leftAlt || key == rightAlt ||
1475 (key.ctrl && key.code != left && key.code != right &&
1476 key.code != leftShift && key.code != rightShift && key.code != space))
1478 if(editor.paramsShown)
1479 editor.paramsList.Destroy(0);
1480 if(editor.membersListShown)
1481 editor.membersList.Destroy(0);
1483 editor.paramsShown = false;
1484 FreeType(editor.functionType);
1485 FreeType(editor.instanceType);
1487 editor.functionType = null;
1488 editor.instanceType = null;
1489 editor.paramsID = -1;
1491 editor.membersListShown = false;
1495 return editor.editBox.OnKeyDown(key, ch);
1499 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1501 CodeEditor editor = (CodeEditor)master;
1505 editor.membersListShown = false;
1507 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1510 bool OnKeyHit(Key key, unichar ch)
1512 CodeEditor editor = (CodeEditor) master;
1516 case enter: case tab:
1518 DataRow row = currentRow;
1519 if(row && row.selected)
1521 char * string = row.string;
1523 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1524 editor.editBox.Delete(
1525 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1526 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1527 editor.editBox.PutS(string);
1530 editor.membersListShown = false;
1533 editor.editBox.OnKeyHit(key, ch);
1543 return ListBox::OnKeyHit(key, ch);
1549 // If before . or after
1550 //listBox.Destroy(true);
1551 result = editor.editBox.OnKeyHit(key, ch);
1566 clickThrough = true,
1568 borderStyle = contour,
1570 background = { 255,255,225 },
1572 OnKeyDown = membersList.OnKeyDown;
1574 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1576 CodeEditor editor = (CodeEditor)master;
1580 editor.membersListShown = false;
1582 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1585 bool OnKeyHit(Key key, unichar ch)
1587 CodeEditor editor = (CodeEditor)master;
1589 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1592 bool result = true; editor.editBox.OnKeyHit(key, ch);
1593 return (!created) ? false : result;
1600 void OnRedraw(Surface surface)
1602 CodeEditor editor = (CodeEditor) master;
1603 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1605 Type methodType = null;
1609 int functionW, nameW = 0;
1611 int spaceW, spaceH, commaW, commaWB, parW;
1613 int maxW = 0, lineW = 0;
1619 Font font = editor.normalFont.font;
1620 Font boldFont = editor.boldFont.font;
1621 Display display = this.display;
1623 if(!type) { return; };
1625 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1627 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1628 display.FontExtent(font, ", ", 2, &commaW, null);
1629 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1630 display.FontExtent(font, ")", 1, &parW, null);
1633 if(editor.functionType)
1635 PrintType(type.returnType, string, true, true);
1636 display.FontExtent(font, string, strlen(string), &functionW, null);
1638 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1639 totalW = nameW + functionW + 2 * parW;
1643 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1644 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1645 if(instanceName && type.kind != functionType)
1646 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1647 totalW = functionW + nameW;
1648 surface.TextFont(boldFont);
1651 surface.WriteText(x, y, string, strlen(string));
1652 x += functionW + spaceW;
1654 if(editor.functionType)
1657 surface.WriteText(x, y, type.name, strlen(type.name));
1659 surface.WriteText(x, y, "(", 1);
1662 if(methodType && !methodType.staticMethod)
1666 if(id == editor.paramsID)
1667 surface.TextFont(boldFont);
1669 if(methodType.methodClass)
1670 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1674 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1675 width += ((id == editor.paramsID) ? commaWB : commaW);
1680 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1685 x = 2 + nameW + spaceW + functionW + parW;
1689 if(methodType.methodClass)
1690 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1693 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1695 surface.WriteText(x, y, ",", 1);
1696 x += ((id == editor.paramsID) ? commaWB : commaW);
1704 if(id == editor.paramsID)
1705 surface.TextFont(font);
1709 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1711 for(param = type.params.first; param; param = param.next)
1713 char paramString[1024];
1716 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1717 surface.TextFont(boldFont);
1720 PrintType(param, paramString, true, true);
1721 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1723 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1728 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1733 x = 2 + nameW + spaceW + functionW + parW;
1737 surface.WriteText(x, y, paramString, strlen(paramString));
1741 surface.WriteText(x, y, ",", 1);
1742 x += ((id == editor.paramsID) ? commaWB : commaW);
1750 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1751 surface.TextFont(font);
1756 surface.WriteText(x, y, ")", 1);
1758 else if(instanceName && type.kind != functionType)
1760 surface.WriteText(x, y, instanceName, strlen(instanceName));
1764 bool OnResizing(int * w, int * h)
1766 CodeEditor editor = (CodeEditor) master;
1767 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1769 Type methodType = null;
1773 int functionW = 0, nameW = 0;
1775 int spaceW, spaceH, commaW, commaWB, parW;
1777 int maxW = 0, lineW = 0;
1782 Font font = editor.normalFont.font;
1783 Font boldFont = editor.boldFont.font;
1784 Display display = this.display;
1786 if(type.kind == TypeKind::methodType)
1789 ProcessMethodType(type.method);
1790 type = type.method.dataType;
1793 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1794 display.FontExtent(font, ", ", 2, &commaW, null);
1795 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1796 display.FontExtent(font, ")", 1, &parW, null);
1799 if(editor.functionType && type)
1801 PrintType(type.returnType, string, true, true);
1802 display.FontExtent(font, string, strlen(string), &functionW, null);
1804 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1805 totalW = nameW + spaceW + functionW + 2 * parW;
1809 PrintType(type, string, false, true); // /*true);
1810 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1811 if(instanceName && type.kind != functionType)
1812 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1813 totalW = functionW + nameW + spaceW;
1816 if(editor.functionType)
1822 if(methodType.methodClass)
1823 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1824 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1825 width += ((id == editor.paramsID) ? commaWB : commaW);
1830 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1843 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1845 for(param = type.params.first; param; param = param.next)
1847 char paramString[1024];
1851 PrintType(param, paramString, true, true);
1852 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1854 width += ((id == editor.paramsID) ? commaWB : commaW);
1859 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1876 *w = realW + totalW + 4;
1882 Menu fileMenu { menu, $"File", f }; // MenuPlacement?
1883 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1884 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1886 Menu debugMenu { menu, $"Debug", d }; // MenuPlacement?
1887 MenuItem debugRunToCursor
1889 debugMenu, $"Run To Cursor", c, Key { f10, ctrl = true };
1890 bool NotifySelect(MenuItem selection, Modifiers mods)
1892 ProjectView projectView = ide.projectView;
1893 if(!projectView.buildInProgress)
1895 int line = editBox.lineNumber + 1;
1898 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1899 ProjectConfig config = projectView.project.config;
1900 ide.debugger.RunToCursor(compiler, config, fileName, line, false);
1907 MenuItem debugSkipRunToCursor
1909 debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true };
1910 bool NotifySelect(MenuItem selection, Modifiers mods)
1912 ProjectView projectView = ide.projectView;
1913 int line = editBox.lineNumber + 1;
1916 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1917 ProjectConfig config = projectView.project.config;
1918 ide.debugger.RunToCursor(compiler, config, fileName, line, true);
1924 MenuDivider { debugMenu };
1925 MenuItem debugToggleBreakpoint
1927 debugMenu, $"Toggle Breakpoint", t, f9;
1928 bool NotifySelect(MenuItem selection, Modifiers mods)
1930 ProjectView projectView = ide.projectView;
1931 if(projectView && fileName)
1933 int line = editBox.lineNumber + 1;
1934 char name[MAX_LOCATION];
1936 // TOFIX: This only looks at the filename...
1937 GetLastDirectory(fileName, name);
1938 if(ide && ide.workspace)
1940 for(p : ide.workspace.projects)
1942 if(p.topNode.Find(name, false))
1950 for(p : ide.workspace.projects)
1952 if(eString_PathInsideOf(fileName, p.topNode.path))
1960 ide.debugger.ToggleBreakpoint(fileName, line, prj);
1970 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1974 designer.parent = parent;
1977 toolBox = ((IDEWorkSpace)master).toolBox;
1979 // Debugger bug here: value of toolBox appears as 0
1981 sheet = ((IDEWorkSpace)master).sheet;
1986 bool OnClose(bool parentClosing)
1990 if(ide.workspace && fileName)
1991 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
1993 if(inUseDebug && !debugClosing)
1995 debugClosing = true;
1997 if(CloseConfirmation(false))
2000 OnFileModified({ modified = true }, null);
2002 debugClosing = false;
2005 if(designer && !designer.closing)
2007 if(designer.visible)
2014 //Window formEditor = designer;
2015 //formEditor.Destroy(0);
2022 void OnDestroy(void)
2024 ObjectInfo oClass, next;
2025 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2027 FreeType(this.functionType);
2028 FreeType(this.instanceType);
2033 designer.codeEditor = null;
2034 designer.Destroy(0);
2038 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2040 ObjectInfo object, next;
2042 for(object = oClass.instances.first; object; object = next)
2047 Designer::DestroyObject(object.instance);
2048 delete object.instance;
2050 sheet.DeleteObject(object);
2052 oClass.instances.Delete(object);
2056 Designer::DestroyObject(oClass.instance);
2057 delete oClass.instance;
2059 sheet.DeleteObject(oClass);
2061 classes.Delete(oClass);
2064 if(windowClass && windowClass.data)
2065 UnapplySkin(windowClass);
2069 if(sheet.codeEditor == this)
2071 sheet.codeEditor = null;
2072 toolBox.codeEditor = null;
2078 ProjectView projectView = ide.projectView;
2081 ProjectNode node = projectView.GetNodeFromWindow(this, null);
2082 if(node && node.modified)
2084 node.modified = false;
2085 projectView.Update(null);
2091 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2093 // 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
2095 if(directActivation)
2096 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2098 if(active && directActivation)
2101 openedFileInfo.Activate();
2105 Location * loc = null;
2106 UpdateFormCode(); // To ensure update when modifying properties...
2108 // Got to the right spot in code so we don't lose our form selection...
2111 if(selected.instCode)
2112 loc = &selected.instCode.loc;
2113 else if(selected.classDefinition)
2114 loc = &selected.classDefinition.loc;
2116 line = editBox.lineNumber + 1;
2117 charPos = editBox.charPos + 1;
2122 if(selected && !loc->Inside(line, charPos))
2124 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2125 line = editBox.lineNumber + 1;
2126 charPos = editBox.charPos + 1;
2128 else if(selected && selected.classDefinition)
2131 for(object = selected.instances.first; object; object = object.next)
2135 if(object.instCode.loc.Inside(line, charPos))
2141 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2142 line = editBox.lineNumber + 1;
2143 charPos = editBox.charPos + 1;
2148 ProcessCaretMove(editBox, line, charPos);
2154 bool OnSaveFile(char * fileName)
2161 f = FileOpen(fileName, write);
2164 if(!ide.projectView)
2165 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2169 this.fileName = fileName; // Put this here because the form designer will check for it...
2170 designer.fileName = fileName;
2171 designer.modifiedDocument = false;
2173 editBox.Save(f, false);
2174 modifiedDocument = false;
2182 bool OnFileModified(FileChange fileChange, char * param)
2184 bool reload = false;
2185 if(visible == false && inUseDebug == true)
2191 sprintf(message, $"The document %s was modified by another application.\n"
2192 "Would you like to reload it and lose your changes?", fileName);
2193 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2194 contents = message }.Modal() == yes)
2200 File f = FileOpen(fileName, read);
2203 int lineNumber, charPos, len;
2207 updatingCode = true;
2208 lineNumber = editBox.lineNumber;
2209 charPos = editBox.charPos;
2210 scroll = editBox.scroll;
2213 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2214 len = strlen(editBox.line.text);
2215 editBox.GoToLineNum(lineNumber);
2216 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2217 editBox.scroll = scroll;
2218 updatingCode = false;
2219 loadingFile = 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;
2385 updatingCode = true;
2387 updatingCode = false;
2388 loadingFile = false;
2397 void DebugMenusDisabled()
2399 bool debugMenusDisabled = ide.GetDebugMenusDisabled();
2400 debugRunToCursor.disabled = debugMenusDisabled;
2401 debugSkipRunToCursor.disabled = debugMenusDisabled;
2402 debugToggleBreakpoint.disabled = debugMenusDisabled;
2408 ProjectView projectView = ide.projectView;
2411 designer.fileName = fileName;
2417 sprintf(title, $"Untitled %d", documentID);
2418 // designer.fileName = CopyString(title);
2419 designer.fileName = title;
2422 DebugMenusDisabled();
2424 for(c = 0; c < CodeObjectType::enumSize; c++)
2425 icons[c] = BitmapResource { iconNames[c], window = this };
2427 codeModified = true;
2439 selected.modified = true;
2440 selected.oClass.modified = true;
2442 designer.modifiedDocument = true;
2443 modifiedDocument = true;
2444 formModified = true;
2447 /****************************************************************************
2449 ****************************************************************************/
2452 this.defines.Free(FreeModuleDefine);
2453 this.imports.Free(FreeModuleImport);
2460 FreeExcludedSymbols(this.excludedSymbols);
2461 FreeContext(this.globalContext);
2463 FreeGlobalData(&this.globalData);
2465 if(GetGlobalContext() == globalContext)
2467 SetGlobalData(null);
2468 SetGlobalContext(null);
2469 SetExcludedSymbols(null);
2470 SetTopContext(null);
2471 SetCurrentContext(null);
2474 SetPrivateModule(null);
2477 if(this.privateModule)
2479 FreeTypeData(this.privateModule);
2480 delete this.privateModule;
2481 this.privateModule = null;
2487 static bool reentrant = false;
2492 char * selectedClassName = null, * selectedName = null;
2493 int selectedPos = 0;
2494 Designer backDesigner;
2495 char oldWorkDir[MAX_LOCATION];
2496 char mainModuleName[MAX_FILENAME] = "";
2498 ImportedModule module;
2499 char extension[MAX_EXTENSION];
2501 Time parseCodeStart = GetTime();
2502 Time startTime, startFindClass;
2504 findClassTotalTime = 0;
2505 checkTypeTotalTime = 0;
2506 externalImportTotalTime = 0;
2507 findClassIgnoreNSTotalTime = 0;
2508 findSymbolTotalTime = 0;
2509 //ResetClassFindTime();
2513 // 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)
2514 if(reentrant) return;
2521 selectedClassName = CopyString(oClass.name);
2522 if(selected != oClass)
2524 ObjectInfo object = this.selected;
2525 selectedName = CopyString(object.name);
2529 for(check = this.oClass.instances.first; check; check = check.next)
2541 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2543 defines.Free(FreeModuleDefine);
2544 imports.Free(FreeModuleImport);
2546 SetGlobalData(&globalData);
2547 SetGlobalContext(globalContext);
2548 SetExcludedSymbols(&excludedSymbols);
2549 SetTopContext(globalContext);
2550 SetCurrentContext(globalContext);
2551 SetDefines(&defines);
2552 SetImports(&imports);
2553 SetCurrentNameSpace(null);
2556 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2557 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2558 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2559 "/I T:\\ecere\\include /E %s", argv[1]);
2563 ChangeWorkingDir("e:\\ec");
2564 sprintf(command, "gcc -x c -E -");
2565 fileInput = DualPipeOpen({ output = true, input = true }, command);
2566 SetFileInput(fileInput);
2571 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2573 fileInput.Write(buffer, 1, count);
2578 fileInput.CloseOutput();
2582 // TOCHECK: COULDN'T WE CALL FreeParser here?
2584 this.functionType = null;
2585 this.instanceType = null;
2588 sheet.SelectObject(null);
2594 // We don't want the designer to be notified of selection when deleting rows...
2595 backDesigner = designer;
2600 ObjectInfo _class, next;
2602 for(_class = classes.first; _class; _class = next)
2608 for(;object = _class.instances.first;)
2612 Designer::DestroyObject(object.instance);
2613 delete object.instance;
2615 sheet.DeleteObject(object);
2617 _class.instances.Delete(object);
2621 Designer::DestroyObject(_class.instance);
2622 delete _class.instance;
2624 sheet.DeleteObject(_class);
2626 classes.Delete(_class);
2632 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2633 if(windowClass && windowClass.data)
2634 UnapplySkin(windowClass);
2637 designer = backDesigner;
2640 fileInput = editFile = EditBoxStream { editBox = editBox };
2641 SetFileInput(fileInput);
2650 FreeContext(this.globalContext);
2651 FreeExcludedSymbols(this.excludedSymbols);
2654 FreeGlobalData(&this.globalData);
2656 if(this.privateModule)
2658 FreeTypeData(this.privateModule);
2659 delete this.privateModule;
2663 startTime = GetTime();
2664 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2666 printf("classes.count: %d\n", globalContext.classes.count);
2669 this.privateModule = __ecere_COM_Initialize(false, 1, null);
2671 SetPrivateModule(privateModule);
2674 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2675 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2676 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2677 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2678 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2681 fileName = this.fileName;
2683 if(ide.workspace && ide.workspace.projects && fileName)
2685 for(p : ide.workspace.projects)
2687 char path[MAX_LOCATION];
2689 MakePathRelative(fileName, p.topNode.path, path);
2690 MakeSlashPath(path);
2692 pn = p.topNode.FindWithPath(path, false);
2701 project = ide.project;
2703 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2705 ChangeWorkingDir(project.topNode.path);
2707 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2709 GetLastDirectory(fileName, mainModuleName);
2710 GetExtension(mainModuleName, extension);
2712 SetBuildingEcereCom(false);
2713 SetBuildingEcereComModule(false);
2715 // TODO: Get symbolsDir from project settings instead...
2718 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2719 ProjectConfig config = project.config;
2720 DirExpression objDir = project.GetObjDir(compiler, config);
2721 SetSymbolsDir(objDir.dir);
2724 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2725 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2729 switch(GetRuntimePlatform())
2731 case win32: SetSymbolsDir("obj/debug.win32"); break;
2732 case tux: SetSymbolsDir("obj/debug.linux"); break;
2733 case apple: SetSymbolsDir("obj/debug.apple"); break;
2735 SetIncludeDirs(null);
2736 SetSysIncludeDirs(null);
2740 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2742 // TODO FIX for configless project
2743 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2745 for(item : ide.project.config.options.preprocessorDefinitions)
2747 if(!strcmp(item, "BUILDING_ECERE_COM"))
2749 SetBuildingEcereCom(true);
2756 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2757 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2758 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2759 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2760 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2761 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2762 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2763 strcmpi(mainModuleName, "Mutex.ec")))
2765 SetBuildingEcereComModule(true);
2768 // Predeclare all classes
2770 char symFile[MAX_FILENAME];
2771 char symLocation[MAX_LOCATION];
2772 ImportedModule module, next;
2774 GetLastDirectory(fileName, symFile);
2775 ChangeExtension(symFile, "sym", symFile);
2777 strcpy(symLocation, GetSymbolsDir());
2778 PathCat(symLocation, symFile);
2780 // if(!GetEcereImported() && !GetBuildingEcereCom())
2781 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2784 startTime = GetTime();
2786 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2788 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2793 startTime = GetTime();
2795 // LoadSymbols(symLocation, normalImport, true);
2796 LoadSymbols(symLocation, preDeclImport, false);
2798 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2801 for(module = defines.first; module; module = next)
2804 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2807 defines.Delete(module);
2812 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2814 SetDefaultDeclMode(privateAccess);
2815 SetDeclMode(privateAccess);
2819 SetDefaultDeclMode(defaultAccess);
2820 SetDeclMode(defaultAccess);
2823 StripExtension(mainModuleName);
2824 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2825 defines.AddName(module);
2828 // SetYydebug(true);
2833 startTime = GetTime();
2834 startFindClass = checkTypeTotalTime;
2838 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2840 CheckDataRedefinitions();
2843 SetIncludeDirs(null);
2844 SetSysIncludeDirs(null);
2855 startTime = GetTime();
2857 PrePreProcessClassDefinitions();
2858 ComputeModuleClasses(privateModule);
2859 PreProcessClassDefinitions();
2860 ProcessClassDefinitions();
2862 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2863 startTime = GetTime();
2868 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2869 startTime = GetTime();
2871 ProcessInstantiations();
2873 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2876 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2878 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2879 if(!windowClass || windowClass.internalDecl)
2882 startTime = GetTime();
2884 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2885 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2886 eModule_Load(this.privateModule, "ecere", privateAccess);
2888 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2891 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2893 if(windowClass && windowClass.data)
2894 ApplySkin(windowClass, app.currentSkin.name, null);
2898 startTime = GetTime();
2900 for(external = ast->first; external; external = external.next)
2902 if(external.type == classExternal)
2904 ClassDefinition _class = external._class;
2905 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2907 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2910 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2912 Instance instance = eInstance_New(regClass);
2913 ObjectInfo classObject
2915 name = CopyString(_class._class.name);
2916 instance = instance;
2917 classDefinition = _class;
2918 oClass = classObject;
2921 classes.Add(classObject);
2925 // Moved this at bottom so that the file dialog doesn't show up in eCom
2926 designer.CreateObject(instance, classObject, true, null);
2927 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
2929 if(_class.definitions)
2933 for(def = _class.definitions->first; def; def = def.next)
2937 case defaultPropertiesClassDef:
2940 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
2942 Identifier id = propDef.identifiers->first;
2945 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
2948 Class propertyClass = prop.dataTypeClass;
2950 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
2951 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
2953 FreeType(propDef.initializer.exp.destType);
2954 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
2955 ProcessExpressionType(propDef.initializer.exp);
2957 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
2959 Expression computed = CopyExpression(propDef.initializer.exp);
2960 ComputeExpression(computed);
2962 if(computed.isConstant && computed.type == instanceExp && !id.next)
2966 if(computed.instance._class && computed.instance._class.symbol &&
2967 computed.instance._class.symbol.registered &&
2968 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
2970 prop.Set(instance, computed.instance.data);
2972 // This was saved in the control and shouldn't be freed by FreeExpression...
2973 if(propertyClass.type == normalClass)
2974 computed.instance.data = null;
2978 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
2979 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
2982 ReadString(temp, computed.string);
2983 prop.Set(instance, temp);
2986 propDef.variable = true;
2988 FreeExpression(computed);
2992 Expression computed = CopyExpression(propDef.initializer.exp);
2993 ComputeExpression(computed);
2994 if(computed.isConstant)
2996 //if(computed.type == memberExp) computed = computed.member.exp;
2998 if(computed.type == constantExp)
3000 Operand value = GetOperand(computed);
3001 DataValue valueData;
3002 valueData.i64 = value.i64;
3003 SetProperty(prop, instance, valueData);
3005 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3008 ReadString(temp, computed.string);
3009 prop.Set(instance, temp);
3013 propDef.variable = true;
3015 FreeExpression(computed);
3019 propDef.variable = true;
3023 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3024 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3025 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3028 // Maintain a list in FunctionDefinition of who is attached to it
3029 for(def = _class.definitions->first; def; def = def.next)
3031 if(def.type == functionClassDef)
3033 ClassFunction function = def.function;
3034 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3036 function.attached.Add(OldLink { data = method });
3046 case declarationClassDef:
3048 Declaration decl = def.decl;
3051 case instDeclaration:
3053 Instantiation inst = decl.inst;
3054 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3055 if(instClass && eClass_GetDesigner(instClass))
3057 Instance control = eInstance_New(instClass);
3062 oClass = classObject;
3066 classObject.instances.Add(object);
3068 // TOCHECK: Why is this needed now?
3069 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3070 def.object = object;
3072 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3074 designer.CreateObject(control, object, false, classObject.instance);
3075 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3085 // Second pass, process instantiation members
3087 for(def = _class.definitions->first; def; def = def.next)
3091 case declarationClassDef:
3093 Declaration decl = def.decl;
3096 case instDeclaration:
3098 Instantiation inst = decl.inst;
3099 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3100 if(instClass && eClass_GetDesigner(instClass))
3103 object = object ? object.next : classObject.instances.first;
3104 control = object.instance;
3108 MembersInit members;
3109 for(members = inst.members->first; members; members = members.next)
3111 switch(members.type)
3113 case dataMembersInit:
3115 if(members.dataMembers)
3118 DataMember curMember = null;
3119 Class curClass = null;
3120 DataMember subMemberStack[256];
3121 int subMemberStackPos = 0;
3123 for(member = members.dataMembers->first; member; member = member.next)
3126 Identifier ident = member.identifiers ? member.identifiers->first : null;
3129 DataMember _subMemberStack[256];
3130 int _subMemberStackPos = 0;
3131 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3135 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3137 if(thisMember && thisMember.memberAccess == publicAccess)
3139 curMember = thisMember;
3140 curClass = curMember._class;
3141 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
3142 subMemberStackPos = _subMemberStackPos;
3148 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3149 if(curMember) found = true;
3151 if(found && curMember.isProperty)
3153 Property prop = (Property) curMember;
3154 Class propertyClass = prop.dataTypeClass;
3156 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3158 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3160 FreeType(member.initializer.exp.destType);
3161 member.initializer.exp.destType = MkClassType(propertyClass.name);
3164 ProcessExpressionType(member.initializer.exp);
3166 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3168 Expression computed;
3170 /*char debugExpString[4096];
3171 debugExpString[0] = '\0';
3172 PrintExpression(member.initializer.exp, debugExpString);*/
3174 computed = CopyExpression(member.initializer.exp);
3177 ComputeExpression(computed);
3179 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3181 if(computed.instance.data)
3183 if(computed.instance._class && computed.instance._class.symbol &&
3184 computed.instance._class.symbol.registered &&
3185 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3187 prop.Set(control, computed.instance.data);
3189 // This was saved in the control and shouldn't be freed by FreeExpression...
3190 if(propertyClass.type == normalClass)
3191 computed.instance.data = null;
3195 else if(computed.type == identifierExp)
3197 member.variable = true;
3199 if(eClass_GetDesigner(propertyClass))
3202 char * name = computed.identifier.string;
3203 if(!strcmp(name, "this"))
3206 prop.Set(control, instance);
3207 member.variable = false;
3212 for(check = classObject.instances.first; check; check = check.next)
3213 if(check.name && !strcmp(name, check.name))
3216 prop.Set(control, check.instance);
3217 member.variable = false;
3223 else if(computed.type == memberExp)
3225 member.variable = true;
3226 if(computed.member.exp.type == identifierExp)
3228 char * name = computed.member.exp.identifier.string;
3229 if(!strcmp(name, "this"))
3231 char * name = computed.member.member.string;
3234 for(check = classObject.instances.first; check; check = check.next)
3235 if(check.name && !strcmp(name, check.name))
3238 prop.Set(control, check.instance);
3239 member.variable = false;
3247 for(check = classObject.instances.first; check; check = check.next)
3249 if(check.name && !strcmp(name, check.name))
3251 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3254 DataValue value { };
3255 GetProperty(getProperty, check.instance, &value);
3256 SetProperty(prop, control, value);
3257 member.variable = false;
3265 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3266 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3269 ReadString(temp, computed.string);
3270 prop.Set(control, temp);
3273 member.variable = true;
3275 FreeExpression(computed);
3280 Expression computed = CopyExpression(member.initializer.exp);
3283 ComputeExpression(computed);
3284 if(computed.isConstant)
3286 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3288 if(!strcmp(propertyClass.dataTypeString, "float"))
3289 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3290 else if(!strcmp(propertyClass.dataTypeString, "double"))
3291 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3293 prop.Set(control, strtol(computed.constant, null, 0));
3295 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3298 ReadString(temp, computed.string);
3299 prop.Set(control, temp);
3303 member.variable = true;
3305 FreeExpression(computed);
3311 member.variable = true;
3313 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3314 member.initializer.exp.type == memberExp) // identifierExp
3316 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3317 if(method && method.type == virtualMethod)
3320 // Maintain a list in FunctionDefinition of who is attached to it
3321 for(def = _class.definitions->first; def; def = def.next)
3323 if(def.type == functionClassDef)
3325 ClassFunction function = def.function;
3326 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3327 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3329 function.attached.Add(OldLink { data = method });
3330 // Reference this particular instance?
3345 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3356 //designer.CreateObject(instance, classObject, true, null);
3357 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3359 designer.PostCreateObject(instance, classObject, true, null);
3361 //instance.state = Hidden;
3362 //instance.Create();
3363 //instance.SetState(Normal, true, 0);
3372 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3376 // Restore Selection
3377 if(selectedClassName)
3380 for(oClass = classes.first; oClass; oClass = oClass.next)
3382 if(!strcmp(oClass.name, selectedClassName))
3384 this.oClass = oClass;
3388 delete selectedClassName;
3397 for(check = this.oClass.instances.first; check; check = check.next)
3399 if(check.name && !strcmp(check.name, selectedName))
3401 this.selected = check;
3407 if(this.oClass.instances.first)
3408 this.selected = this.oClass.instances.first;
3410 this.selected = this.oClass;
3413 else if(selectedPos == -1 || !this.oClass.instances.count)
3414 this.selected = this.oClass;
3420 if(selectedPos > this.oClass.instances.count)
3422 for(check = this.oClass.instances.first; check; check = check.next)
3424 if(selectedPos == pos++)
3426 this.selected = check;
3434 this.oClass = classes.first;
3435 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3437 delete selectedName;
3438 SetSymbolsDir(null);
3440 if(sheet.codeEditor == this)
3441 sheet.SelectObject(selected);
3444 codeModified = false;
3446 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3449 InvokeParameters(false, false, false);
3452 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3458 ChangeWorkingDir(oldWorkDir);
3460 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3461 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3462 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3463 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3464 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3466 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3468 if(inUseDebug && ide.projectView)
3469 ide.debugger.EvaluateWatches();
3472 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3475 Window control = (Window)object.instance;
3476 ObjectInfo classObject = object.oClass;
3478 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3480 if(!strcmp(_class.name, "DesignerBase")) return;
3482 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3484 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3485 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3487 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3488 (!prop.IsSet || prop.IsSet(control)))
3490 Class dataType = prop.dataTypeClass;
3492 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3496 if(dataType.type == structClass)
3498 void * dataForm = new0 byte[dataType.structSize];
3499 void * dataTest = new0 byte[dataType.structSize];
3501 ((void (*)())(void *)prop.Get)(control, dataForm);
3502 prop.Get(test, dataTest);
3504 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
3506 char tempString[1024] = "";
3508 bool needClass = true;
3512 prop.Set(test, dataForm);
3514 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
3516 eClass_FindNextMember(_class, curClass, curMember, null, null);
3517 if(*curMember != (DataMember)prop)
3518 f.Printf("%s = ", prop.name);
3520 *curMember = (DataMember)prop;
3521 *curClass = curMember->_class;
3524 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3526 f.Printf("%s", string);
3533 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3535 void * dataForm, * dataTest;
3537 dataForm = (void *)prop.Get(control);
3538 dataTest = (void *)prop.Get(test);
3540 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
3542 char tempString[1024] = "";
3547 prop.Set(test, dataForm);
3549 eClass_FindNextMember(_class, curClass, curMember, null, null);
3550 if(*curMember != (DataMember)prop)
3551 f.Printf("%s = ", prop.name);
3552 *curMember = (DataMember)prop;
3553 *curClass = curMember->_class;
3555 if(eClass_GetDesigner(dataType))
3557 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3558 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3559 f.Printf("this", prop.name);
3562 //ObjectInfo classObject;
3563 //for(classObject = classes.first; classObject; classObject = classObject.next)
3567 for(object = classObject.instances.first; object; object = object.next)
3569 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3571 f.Printf("%s", object.name);
3578 bool needClass = true;
3579 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
3580 f.Printf("%s", string);
3587 bool needClass = true;
3588 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
3590 if(!strcmp(dataType.dataTypeString, "char *"))
3593 OutputString(f, string);
3597 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3599 f.Printf("%s", string);
3602 *lastIsMethod = false;
3607 DataValue dataForm, dataTest;
3609 GetProperty(prop, control, &dataForm);
3610 GetProperty(prop, test, &dataTest);
3612 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
3615 char tempString[1024] = "";
3616 SetProperty(prop, test, dataForm);
3618 if(dataType.type != bitClass)
3620 bool needClass = true;
3622 if(dataType.type == enumClass)
3625 Class enumClass = eSystem_FindClass(privateModule, "enum");
3626 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3628 for(value = e.values.first; value; value = value.next)
3630 if((int)value.data == dataForm.i)
3632 string = value.name;
3638 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
3640 if(string && string[0])
3645 eClass_FindNextMember(_class, curClass, curMember, null, null);
3646 if(*curMember != (DataMember)prop)
3647 f.Printf("%s = ", prop.name);
3648 *curMember = (DataMember)prop;
3649 *curClass = curMember->_class;
3651 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3652 f.Printf("%sf", string);
3654 f.Printf("%s", string);
3658 else if(dataType.type == bitClass)
3660 bool needClass = true;
3662 if(*prev) f.Printf(", ");
3664 eClass_FindNextMember(_class, curClass, curMember, null, null);
3665 if(*curMember != (DataMember)prop)
3666 f.Printf("%s = ", prop.name);
3667 *curMember = (DataMember)prop;
3668 *curClass = curMember->_class;
3670 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm.ui, tempString, null, &needClass);
3672 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3674 f.Printf("%s", string);
3676 *lastIsMethod = false;
3686 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3688 Instantiation inst = object.instCode;
3689 Window control = (Window)object.instance;
3691 bool methodPresent = false;
3693 bool lastIsMethod = true;
3694 ObjectInfo classObject = object.oClass;
3700 // Instance removed, delete it
3701 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3703 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3704 position = inst.loc.end.pos + 1;
3708 bool multiLine = false;
3711 // Check if it's an unnamed instance
3714 f.Seek(inst.nameLoc.start.pos - position, current);
3715 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3716 position = inst.nameLoc.end.pos;
3718 f.Printf(object.name);
3723 if(isspace(ch) && ch != '\n')
3725 f.Seek(-1, current);
3733 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3735 f.Seek(pos - position, current);
3740 f.Seek(-1, current);
3749 f.Puts(object.name);
3754 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3755 methodPresent = true;
3763 if(ch == OpenBracket)
3769 // TODO: Simplify this?
3778 f.Seek(-1, current);
3790 if(ch == '\n') { toDelete = count; count = 0; }
3791 else if(isspace(ch)) count++;
3794 f.Seek(-1, current);
3798 toDelete += count - 6;
3808 f.Seek(-toDelete-count, current);
3809 f.DeleteBytes(toDelete);
3810 f.Seek(count, current);
3815 for(c = 0; c<toAdd; c++)
3821 methodPresent = multiLine;
3824 f.Printf(methodPresent ? "\n " : " ");
3830 // Instance not there, create a brand new one
3831 DeleteJunkBefore(f, position, &position);
3832 f.Printf(*firstObject ? "\n\n" : "\n");
3833 *firstObject = false;
3835 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3836 methodPresent = true;
3841 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3843 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3848 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3850 f.Printf(" %s %c ", control._class.name, OpenBracket);
3856 Instance test = eInstance_New(control._class);
3857 DataMember curMember = null;
3858 Class curClass = null;
3861 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3865 // Attach Method here
3866 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3868 if(prev) f.Printf(", ");
3869 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3874 if(inst && !object.deleted)
3876 MembersInit members;
3877 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3879 DeleteJunkBefore(f, position, &position);
3881 // Instance already there, clear out the properties
3882 for(members = inst.members->first; members; members = members.next)
3884 if(members.type == dataMembersInit)
3888 if(members.dataMembers)
3890 bool keptMember = false;
3891 MemberInit lastKept = null;
3893 for(member = members.dataMembers->first; member; member = member.next)
3895 Identifier ident = member.identifiers ? member.identifiers->first : null;
3896 bool deleted = false;
3898 // For now delete if it's not a method
3899 if(!member.variable) // && ident)
3901 if(!ident || !ident.next)
3903 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3906 f.Seek(member.loc.start.pos - position, current);
3907 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3908 position = member.loc.end.pos;
3913 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3914 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3915 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
3917 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
3918 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
3920 f.Seek(member.loc.start.pos - position, current);
3921 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3922 position = member.loc.end.pos;
3934 //f.Seek(member.loc.start.pos - position, current);
3935 //position = member.loc.start.pos;
3936 DeleteJunkBefore(f, member.loc.start.pos, &position);
3937 if(prev) f.Printf(", ");
3938 else if(keptMember) f.Printf(" ");
3943 if(!keptMember || !members.next)
3948 if(keptMember && lastKept != members.dataMembers->last)
3953 f.Seek(-1, current);
3959 f.Seek(-1, current);
3962 else if(!isspace(ch))
3964 f.Seek(-2, current);
3969 f.DeleteBytes(count);
3972 f.Seek(members.loc.end.pos - position, current);
3977 f.Seek(-1, current);
3979 position = members.loc.end.pos + 1;
3983 f.Seek(-1, current);
3984 position = members.loc.end.pos;
3990 lastIsMethod = false;
3995 DeleteJunkBefore(f, position, &position);
3998 if(lastKept != members.dataMembers->last)
4003 f.Seek(-1, current);
4009 f.Seek(-1, current);
4012 else if(!isspace(ch))
4014 f.Seek(-2, current);
4019 f.DeleteBytes(count);
4023 f.Seek(members.loc.end.pos - position, current);
4024 position = members.loc.end.pos;
4028 lastIsMethod = true;
4031 lastIsMethod = false;
4037 f.Seek(members.loc.end.pos - position, current);
4038 position = members.loc.end.pos;
4040 lastIsMethod = true;
4043 else if(members.type == methodMembersInit)
4045 if(this.methodAction == actionDeleteMethod && members.function == function);
4047 methodPresent = true;
4049 // Delete instance method here
4050 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4051 members.function == function)
4053 if(this.moveAttached && !*text)
4054 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4056 DeleteJunkBefore(f, members.loc.start.pos, &position);
4057 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4058 position = members.loc.end.pos + 1;
4063 DeleteJunkBefore(f, position, &position);
4067 DeleteJunkBefore(f, members.loc.start.pos, &position);
4068 lastIsMethod = true;
4072 f.Seek(members.loc.end.pos - position, current);
4073 position = members.loc.end.pos;
4075 DeleteJunkBefore(f, position, &position);
4084 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4086 Method method = this.method;
4087 DeleteJunkBefore(f, position, &position);
4093 if(!method.dataType)
4094 method.dataType = ProcessTypeString(method.dataTypeString, false);
4097 Type dataType = method.dataType;
4098 Type returnType = dataType.returnType;
4101 if(this.moveAttached)
4103 // Move function here:
4104 int newLen = strlen(method.name);
4109 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4111 // First change name of function
4112 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4113 *textSize += newLen - movedFuncIdLen;
4114 memcpy(*text + movedFuncIdPos, method.name, newLen);
4116 // Second, tab right
4119 for(c = 0; (*text)[c]; )
4122 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4125 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4126 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4130 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4140 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4142 // ADDING METHOD HERE
4144 OutputType(f, returnType, false);
4147 if(dataType.thisClass)
4149 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4151 if(dataType.thisClass.shortName)
4152 f.Printf(dataType.thisClass.shortName);
4154 f.Printf(dataType.thisClass.string);
4158 f.Printf(method.name);
4160 for(param = dataType.params.first; param; param = param.next)
4162 OutputType(f, param, true);
4167 f.Printf(" %c\n\n", OpenBracket);
4169 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4171 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4172 f.Printf(" return true;\n");
4173 else if(returnType.kind != voidType)
4174 f.Printf(" return 0;\n");
4179 if(returnType.kind != voidType)
4180 f.Printf("return ");
4181 f.Printf("%s::%s(", control._class.name, method.name);
4182 for(param = dataType.params.first; param; param = param.next)
4184 if(param.prev) f.Printf(", ");
4185 f.Printf(param.name);
4189 f.Printf(" %c\n", CloseBracket);
4195 if(!object.instCode)
4198 f.Printf(" %c;\n", CloseBracket);
4200 f.Printf("%c;\n", CloseBracket);
4202 else if(!object.deleted)
4204 // Turn this into a multiline instance when adding a method
4205 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4207 f.Printf(methodPresent ? "\n " : " ");
4209 f.Seek(inst.loc.end.pos + 1 - position, current);
4210 position = inst.loc.end.pos + 1;
4215 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4218 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4220 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4222 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4224 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4225 if(prop && prop.isProperty && !prop.conversion)
4227 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4228 (!prop.IsSet || prop.IsSet(classObject.instance)))
4230 Class dataType = prop.dataTypeClass;
4231 char tempString[1024] = "";
4233 bool specify = false;
4236 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4237 if(member && member._class == regClass)
4241 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4243 if(dataType && dataType.type == structClass)
4245 void * dataForm = new0 byte[dataType.structSize];
4246 void * dataTest = new0 byte[dataType.structSize];
4248 prop.Get(classObject.instance, dataForm);
4249 prop.Get(test, dataTest);
4251 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
4253 bool needClass = true;
4255 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
4256 prop.Set(test, dataForm);
4258 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4260 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4265 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4267 void * dataForm, * dataTest;
4269 dataForm = (void *)prop.Get(classObject.instance);
4270 dataTest = (void *)prop.Get(test);
4272 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
4274 char tempString[1024] = "";
4276 prop.Set(test, dataForm);
4278 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4280 // Shouldn't go here ...
4281 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4285 bool needClass = true;
4287 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
4289 if(!strcmp(dataType.dataTypeString, "char *"))
4291 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4292 OutputString(f, string);
4296 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4298 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4304 DataValue dataForm, dataTest;
4306 GetProperty(prop, classObject.instance, &dataForm);
4307 GetProperty(prop, test, &dataTest);
4309 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
4311 SetProperty(prop, test, dataForm);
4312 if(dataType.type == bitClass)
4314 bool needClass = true;
4315 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
4317 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4319 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4323 bool needClass = true;
4324 if(dataType.type == enumClass)
4327 Class enumClass = eSystem_FindClass(privateModule, "enum");
4328 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4330 for(value = e.values.first; value; value = value.next)
4332 if((int)value.data == dataForm.i)
4334 string = value.name;
4340 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
4341 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4342 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4344 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4353 void UpdateFormCode()
4362 else if(formModified)
4364 EditBoxStream f { editBox = editBox };
4368 Identifier movedFuncId;
4369 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4370 ObjectInfo classObject;
4376 movedFuncId = GetDeclId(function.declarator);
4377 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4378 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4381 for(classObject = classes.first; classObject; classObject = classObject.next)
4384 ClassDefinition classDef = classObject.classDefinition;
4385 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4388 bool firstObject = true;
4389 ObjectInfo object = classObject.instances.first;
4390 bool lastIsDecl = false;
4392 if(!classObject.modified) continue;
4394 test = eInstance_New(regClass);
4397 // Put it in the same desktop window...
4398 designer.PrepareTestObject(test);
4400 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4401 //f.Printf("%c\n\n", OpenBracket);
4403 // Change the _class name
4404 f.Seek(classDef.nameLoc.start.pos - position, current);
4405 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4406 f.Printf(classObject.name);
4407 position = classDef.nameLoc.end.pos;
4410 // Go to block start, delete all until no white space, put \n
4414 f.Seek(classDef.blockStart.end.pos - position, current);
4415 position = classDef.blockStart.end.pos;
4417 for(; f.Getc(&ch); count++)
4421 f.Seek(-1, current);
4431 f.Seek(-count, current);
4433 f.DeleteBytes(count-back);
4435 position += count-back;
4438 // Output properties
4439 OutputClassProperties(classObject.instance._class, classObject, f, test);
4441 for(def = classDef.definitions->first; def; def = def.next)
4445 case defaultPropertiesClassDef:
4447 bool keptMember = false;
4449 MemberInit lastKept = null;
4452 DeleteJunkBefore(f, def.loc.start.pos, &position);
4455 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4457 Identifier ident = propDef.identifiers->first;
4458 bool deleted = false;
4460 // For now delete if it's a prop
4461 if(!propDef.variable && ident)
4465 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4468 f.Seek(propDef.loc.start.pos - position, current);
4469 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4470 position = propDef.loc.end.pos;
4475 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4476 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4478 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4479 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4481 f.Seek(propDef.loc.start.pos - position, current);
4482 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4483 position = propDef.loc.end.pos;
4501 f.Seek(def.loc.end.pos - position - 1, current);
4506 f.Seek(-1, current);
4509 position = def.loc.end.pos;
4513 if(lastKept != def.defProperties->last)
4518 f.Seek(-1, current);
4524 f.Seek(-1, current);
4527 else if(!isspace(ch))
4529 f.Seek(-2, current);
4534 f.DeleteBytes(count);
4538 f.Seek(def.loc.end.pos - position, current);
4539 position = def.loc.end.pos;
4544 case declarationClassDef:
4546 Declaration decl = def.decl;
4548 if(decl.type == instDeclaration)
4550 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4552 while(def.object && object != def.object)
4554 if(object /*&& ((ObjectInfo)def.object).modified*/)
4555 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4556 object = object.next;
4559 DeleteJunkBefore(f, def.loc.start.pos, &position);
4560 f.Printf(firstObject ? "\n\n " : "\n ");
4561 firstObject = false;
4563 if(def.object && ((ObjectInfo)def.object).modified)
4564 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4566 object = object ? object.next : null;
4570 DeleteJunkBefore(f, def.loc.start.pos, &position);
4571 f.Printf(firstObject ? "\n\n " : "\n ");
4572 firstObject = false;
4578 DeleteJunkBefore(f, def.loc.start.pos, &position);
4579 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4584 case functionClassDef:
4586 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4587 if(!def.function.body) continue;
4591 DeleteJunkBefore(f, def.loc.start.pos, &position);
4594 // Delete _class methods
4595 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4596 def.function == function)
4601 if(moveAttached && !text)
4603 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4606 f.Seek(def.loc.end.pos - position, current);
4607 for(; f.Getc(&ch); count++)
4611 f.Seek(-1, current);
4615 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4617 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4618 position = def.loc.end.pos + count;
4621 // In case of detaching methods in the _class, simply rename the method
4622 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4624 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4625 f.DeleteBytes(movedFuncIdLen);
4627 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4630 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4631 function == def.function)
4633 // In case of attaching methods in the _class, simply rename the method
4634 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4635 position = function.loc.start.pos + movedFuncIdPos;
4636 f.DeleteBytes(movedFuncIdLen);
4637 if(method.dataType.thisClass)
4638 f.Printf("%s::", method.dataType.thisClass.string);
4639 f.Puts(method.name);
4640 position += movedFuncIdLen;
4645 DeleteJunkBefore(f, def.loc.start.pos, &position);
4646 if(def.type == memberAccessClassDef)
4649 firstObject = false;
4659 f.Seek(def.loc.end.pos - position, current);
4660 position = def.loc.end.pos;
4663 // Output attached methods
4664 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4666 DeleteJunkBefore(f, position, &position);
4667 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4670 // ********** INSTANCES ***************
4671 for(; object; object = object.next)
4673 if(!object.instCode)
4675 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4679 DeleteJunkBefore(f, position, &position);
4681 // ****************** METHODS ***********************
4682 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4684 // If detaching an instance method
4685 if(selected != classObject)
4687 int newLen = strlen(methodName);
4690 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4691 // Tab selection left
4694 for(c = 0; text[c]; )
4697 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4698 memmove(text+start, text+start+i, textSize+1-start-i);
4701 for(; text[c] && text[c] != '\n'; c++);
4707 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4708 textSize += newLen - movedFuncIdLen;
4709 memcpy(text + movedFuncIdPos, methodName, newLen);
4716 if(methodAction == actionAddMethod && selected == classObject)
4718 Method method = this.method;
4720 if(!method.dataType)
4721 method.dataType = ProcessTypeString(method.dataTypeString, false);
4723 // ADDING METHOD HERE
4725 Type dataType = method.dataType;
4726 Type returnType = dataType.returnType;
4728 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4732 OutputType(f, returnType, false);
4735 if(dataType.thisClass && !dataType.classObjectType)
4737 if(dataType.thisClass.shortName)
4738 f.Printf(dataType.thisClass.shortName);
4740 f.Printf(dataType.thisClass.string);
4743 f.Printf(method.name);
4745 for(param = dataType.params.first; param; param = param.next)
4747 OutputType(f, param, true);
4752 f.Printf(" %c\n\n", OpenBracket);
4754 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4756 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4757 f.Printf(" return true;\n");
4758 else if(returnType && returnType.kind != voidType)
4759 f.Printf(" return 0;\n");
4764 if(returnType.kind != voidType)
4765 f.Printf("return ");
4767 char * name = ((Specifier)classDef.baseSpecs->first).name;
4768 Symbol _class = FindClass(name);
4769 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4771 for(param = dataType.params.first; param; param = param.next)
4773 if(param.prev) f.Printf(", ");
4774 if(param.kind != voidType)
4775 f.Printf(param.name);
4780 f.Printf(" %c", CloseBracket);
4784 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4796 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4797 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4801 codeModified = false;
4802 formModified = false;
4804 moveAttached = false;
4809 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4812 ClassFunction function = null;
4815 ObjectInfo object = this.selected;
4817 if(object && object == this.oClass)
4819 ClassDefinition classDef = object.oClass.classDefinition;
4821 if(classDef && classDef.definitions)
4823 for(def = classDef.definitions->first; def; def = def.next)
4825 if(def.type == functionClassDef && def.function.declarator)
4827 if(!strcmp(def.function.declarator.symbol.string, methodName))
4829 function = def.function;
4834 else if(def.type == defaultPropertiesClassDef)
4838 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4840 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4841 if(ident && !ident.next)
4843 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4847 propLoc = propDef.loc;
4850 ClassDefinition classDef = object.oClass.classDefinition;
4852 if(classDef.definitions)
4854 for(def = classDef.definitions->first; def; def = def.next)
4856 if(def.type == functionClassDef)
4858 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4860 function = def.function;
4879 Instantiation inst = object.instCode;
4881 // Check here to see if the method already exists, no need to call ModifyCode in that case
4882 if(inst && inst.members)
4884 MembersInit members;
4885 for(members = inst.members->first; members; members = members.next)
4887 switch(members.type)
4889 case dataMembersInit:
4891 if(members.dataMembers)
4894 for(member = members.dataMembers->first; member; member = member.next)
4896 Identifier ident = member.identifiers ? member.identifiers->first : null;
4897 if(ident && !ident.next)
4899 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4903 propLoc = member.loc;
4906 ClassDefinition classDef = object.oClass.classDefinition;
4908 if(classDef.definitions)
4910 for(def = classDef.definitions->first; def; def = def.next)
4912 if(def.type == functionClassDef)
4914 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
4916 function = def.function;
4925 // TODO: Fix memory leak
4926 function = ClassFunction
4928 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
4940 case methodMembersInit:
4942 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
4944 function = members.function;
4956 if(functionPtr) *functionPtr = function;
4960 void GoToMethod(char * methodName /*Method method*/)
4964 ObjectInfo object = selected;
4965 EditBoxStream f { editBox = editBox };
4966 ClassFunction function = null;
4967 bool atChar = false;
4971 Location propLoc = { {0,0,-1} };
4974 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
4975 if(function && function.body)
4978 f.Seek(function.body.loc.start.pos+1, current);
4988 f.Seek(-1, current);
4993 else if(!isspace(ch))
4995 f.Seek(-1, current);
5001 else if(propLoc.start.pos > -1)
5003 f.Seek(propLoc.start.pos, current);
5006 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5008 if(function || propLoc.start.pos > -1)
5010 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5011 editBox.CenterOnCursor();
5012 SetState(normal, false, 0);
5015 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5017 FreeClassFunction(function);
5023 void FindCompatibleMethods(Method method, OldList compatible)
5025 ClassDefinition classDef = this.oClass.classDefinition;
5026 if(classDef && classDef.definitions)
5029 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5032 Symbol classSym { };
5033 Symbol selectedClass;
5034 if(this.selected == this.oClass)
5035 selectedClass = classSym;
5037 selectedClass = FindClass(this.selected.instance._class.name);
5039 regClass.name = classDef._class.name;
5040 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5041 for(def = classDef.definitions->first; def; def = def.next)
5043 if(def.type == functionClassDef && def.function.declarator)
5045 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5047 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5050 Type type = def.function.declarator.symbol.type;
5051 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5053 compatible.Add(OldLink { data = def.function });
5059 if(this.oClass && this.oClass.instance)
5061 classSym.registered = regClass;
5062 //classSym.registered = this.oClass.oClass;
5064 for(_class = regClass.base; _class; _class = _class.base)
5067 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5069 // TODO: Understand why these functions popup in attach list
5070 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5072 if(!testMethod.dataType)
5073 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5075 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5076 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5077 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5079 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5080 // ClassFunction function { };
5081 FunctionDefinition function { };
5083 function.declarator = Declarator { };
5084 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5085 excludedSymbols.Add(function.declarator.symbol);
5087 compatible.Add(OldLink { data = function });
5098 void AddMethod(Method method)
5102 char methodName[1024];
5103 strcpy(methodName, method.name);
5104 if(!FindMethod(methodName, null, null))
5106 methodAction = actionAddMethod;
5107 this.method = method;
5111 GoToMethod(methodName);
5115 void DeleteMethod(ClassFunction function)
5119 methodAction = actionDeleteMethod;
5120 this.function = function;
5128 void AttachMethod(Method method, ClassFunction function)
5132 // If it's an instance we'll ask if we want to move it inside...
5133 if(!function.attached.count && function.body)
5135 // Find the function in the _class to check if it's a virtual function
5136 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5137 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5138 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5140 for(def = this.classDefinition.first; def; def = def.next)
5142 if(def.type == functionClassDef)
5144 if(def.function == function)
5149 if(!method || method.type != virtualMethod)
5152 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5153 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5155 moveAttached = true;
5160 methodAction = actionAttachMethod;
5161 this.method = method;
5162 this.function = function;
5169 void ReAttachMethod(Method method, ClassFunction function)
5173 // If it's an instance we'll ask if we want to move it inside...
5174 if(!function.attached.count && function.body)
5176 // Find the function in the _class to check if it's a virtual function
5177 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5178 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5179 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5181 for(def = this.classDefinition.first; def; def = def.next)
5183 if(def.type == functionClassDef)
5185 if(def.function == function)
5190 if(!method || method.type != virtualMethod)
5193 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5194 if(MessageBox { type = yesNo, master = parent, text = title,
5195 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5197 moveAttached = true;
5202 methodAction = actionReattachMethod;
5203 this.method = method;
5204 this.function = function;
5211 void DetachMethod(Method method, ClassFunction function, int type)
5219 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5220 master = sheet, text = $"Name detached method", background = formColor
5224 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5225 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5229 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5230 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5234 dialog, anchor = { left = 5, right = 5, top = 5 }
5236 sprintf(methodName, "%s_%s", selected.name, method.name);
5237 nameBox.contents = methodName;
5239 result = dialog.Modal() == ok;
5240 strcpy(methodName, nameBox.contents);
5245 // If the method is not attached, move it outside
5248 // Add this class to the methodName
5249 char name[1024] = "";
5251 if(this.selected != this.oClass && !method.dataType.thisClass)
5253 strcat(name, this.selected.instance._class.name);
5255 strcat(name, this.methodName);
5256 strcpy(this.methodName, name);
5258 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5260 strcat(name, method.dataType.thisClass.string);
5262 strcat(name, this.methodName);
5263 strcpy(this.methodName, name);
5266 this.moveAttached = true;
5269 this.methodAction = actionDetachMethod;
5270 this.method = method;
5271 this.function = function;
5278 void AddObject(Instance instance, ObjectInfo * object)
5282 //*object = _class.instances.Add(sizeof(ObjectInfo));
5283 *object = ObjectInfo { };
5284 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5285 (*object).oClass = oClass;
5286 (*object).instance = instance;
5291 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5293 // if(strcmp(name, this.oClass.instance.name))
5296 for(check = oClass.instances.first; check; check = check.next)
5297 if(!check.deleted && check.name && !strcmp(name, check.name))
5301 (*object).name = CopyString(name);
5306 toolBox.controlClass = null;
5310 //sheet.AddObject(*object, (*object).name, TypeData, true);
5315 void EnsureUpToDate()
5317 if(sheet && codeModified)
5321 void SelectObject(ObjectInfo object)
5324 oClass = object ? object.oClass : null;
5326 designer.SelectObject(object, object ? object.instance : null);
5329 void SelectObjectFromDesigner(ObjectInfo object)
5332 sheet.SelectObject(object);
5335 void EnumerateObjects(Sheet sheet)
5339 for(oClass = classes.first; oClass; oClass = oClass.next)
5345 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5346 for(object = oClass.instances.first; object; object = object.next)
5347 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5350 sheet.SelectObject(selected);
5355 designer.AddObject();
5358 void DeleteObject(ObjectInfo object)
5360 delete object.instance;
5361 object.deleted = true;
5362 object.modified = true;
5363 object.oClass.modified = true;
5365 if(selected == object)
5367 bool looped = false;
5368 ObjectInfo select = object;
5372 select = select.prev;
5376 select = object.oClass.instances.last;
5383 sheet.SelectObject(select ? select : oClass);
5386 if(!object.instCode && object.oClass != object)
5389 oClass.instances.Delete(object);
5392 if(sheet.codeEditor == this)
5393 sheet.DeleteObject(object);
5396 void RenameObject(ObjectInfo object, char * name)
5400 // Validate the name:
5401 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5402 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5405 for(c = 0; name[c]; c++)
5406 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5414 object.name = (name && name[0]) ? CopyString(name) : null;
5416 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5420 void DesignerModifiedObject()
5422 sheet.ListProperties(false);
5426 void ListSubMembers(Type member)
5430 for(subMember = member.members.first; subMember; subMember = subMember.next)
5434 DataRow row = membersList.AddString(subMember.name);
5435 row.icon = icons[typeData];
5439 ListSubMembers(subMember);
5444 void ListSubDataMembers(DataMember member, bool isPrivate)
5446 DataMember subMember;
5447 for(subMember = member.members.first; subMember; subMember = subMember.next)
5449 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5453 DataRow row = membersList.AddString(subMember.name);
5454 BitmapResource bitmap = null;
5455 if(!subMember.dataType)
5456 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5458 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5460 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5463 bitmap = { bitmapName };
5464 membersList.AddResource(bitmap);
5467 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5471 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5477 void ListClassMembers(Class whatClass, bool methodsOnly)
5480 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5481 bool isPrivate = false;
5483 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5485 Method method, methodIt;
5487 DataMember memberIt;
5489 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5491 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5492 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5494 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5496 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5498 DataRow row = membersList.FindString(method.name);
5501 row = membersList.AddString(method.name);
5503 if(!method.dataType)
5504 method.dataType = ProcessTypeString(method.dataTypeString, false);
5506 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5514 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5518 if(memberIt.isProperty)
5520 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5522 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5526 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5528 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5531 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5537 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5539 if(member.isProperty)
5541 Property prop = (Property) member;
5542 if(!membersList.FindString(prop.name))
5544 DataRow row = membersList.AddString(prop.name);
5545 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5548 else if(member.name && !membersList.FindString(member.name))
5550 DataRow row = membersList.AddString(member.name);
5552 BitmapResource bitmap = null;
5553 if(!member.dataType)
5554 member.dataType = ProcessTypeString(member.dataTypeString, false);
5556 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5558 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5561 bitmap = { bitmapName };
5562 membersList.AddResource(bitmap);
5565 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5568 ListSubDataMembers(member, member.memberAccess == privateAccess);
5572 if(_class.inheritanceAccess == privateAccess)
5575 if(_class.module != privateModule) break;
5580 void ListClassMembersMatch(Class whatClass, Type methodType)
5583 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5584 bool isPrivate = false;
5586 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5592 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5594 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5596 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5598 if(!method.dataType)
5599 method.dataType = ProcessTypeString(method.dataTypeString, false);
5601 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5603 DataRow row = membersList.FindString(method.name);
5606 row = membersList.AddString(method.name);
5607 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5613 if(_class.inheritanceAccess == privateAccess)
5616 if(_class.module != privateModule) break;
5621 void ListClassPropertiesAndVirtual(Class whatClass)
5624 bool isPrivate = false;
5625 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5631 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5633 if(method.type == virtualMethod)
5635 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5637 DataRow row = membersList.FindString(method.name);
5640 row = membersList.AddString(method.name);
5642 if(!method.dataType)
5643 method.dataType = ProcessTypeString(method.dataTypeString, false);
5645 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5651 for(member = _class.membersAndProperties.first; member; member = member.next)
5653 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5655 if(member.isProperty)
5657 Property prop = (Property)member;
5659 DataRow row = membersList.AddString(prop.name);
5660 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5663 else if(member.name)
5665 DataRow row = membersList.AddString(member.name);
5667 BitmapResource bitmap = null;
5668 if(!member.dataType)
5669 member.dataType = ProcessTypeString(member.dataTypeString, false);
5671 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5673 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5676 bitmap = { bitmapName };
5677 membersList.AddResource(bitmap);
5680 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5683 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5686 if(_class.inheritanceAccess == privateAccess)
5689 if(_class.module != privateModule) break;
5694 void ListMembers(Type type)
5696 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5700 if(type.kind == classType)
5703 ListClassMembers(type._class.registered, false);
5708 for(member = type.members.first; member; member = member.next)
5712 DataRow row = membersList.AddString(member.name);
5713 row.icon = icons[typeData];
5715 else if(member.kind == structType || member.kind == unionType)
5716 ListSubMembers(member);
5722 void ListModule(Module mainModule, int recurse, bool listClasses)
5725 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5726 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5727 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5728 for(module = mainModule.application.allModules.first; module; module = module.next)
5730 if(ModuleVisibility(mainModule, module))
5731 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5735 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5742 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5744 Class _class = link.data;
5745 if(_class.type != systemClass)
5747 DataRow row = membersList.AddString(_class.name);
5748 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5753 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5755 DefinedExpression definedExp = link.data;
5756 DataRow row = membersList.AddString(link /*definedExp*/.name);
5757 row.icon = icons[typeData];
5760 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5762 GlobalFunction function = link.data;
5763 DataRow row = membersList.AddString(link /*function*/.name);
5764 row.icon = icons[typeMethod];
5768 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5770 if(recurse != 2 && listClasses)
5772 if(!membersList.FindString(ns->name))
5774 DataRow row = membersList.AddString(ns->name);
5775 row.icon = icons[typeNameSpace];
5780 ListNameSpace(ns, 2, listClasses);
5784 void ListEnumValues(Class _class)
5786 for(; _class && _class.type == enumClass; _class = _class.base)
5788 EnumClassData enumeration = (EnumClassData)_class.data;
5790 for(item = enumeration.values.first; item; item = item.next)
5792 DataRow row = membersList.AddString(item.name);
5793 row.icon = icons[typeEnumValue];
5798 bool ListEnumsModule(Module mainModule, Type dest)
5800 bool result = false;
5802 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5803 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5804 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5805 for(module = mainModule.application.allModules.first; module; module = module.next)
5807 if(ModuleVisibility(mainModule, module))
5808 result |= ListEnums(module.publicNameSpace, dest);
5813 void ListNameSpaceByString(Module mainModule, char * string)
5815 NameSpace * nameSpace;
5817 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5818 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5819 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5820 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5821 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5822 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5823 for(module = mainModule.application.allModules.first; module; module = module.next)
5825 if(ModuleVisibility(mainModule, module))
5827 nameSpace = FindNameSpace(module.publicNameSpace, string);
5828 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5833 bool ListEnums(NameSpace nameSpace, Type dest)
5836 bool result = false;
5838 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5840 Class _class = link.data;
5841 if(_class.type == enumClass && (dest.kind != classType || !dest._class || dest._class.registered != _class))
5843 OldList conversions { };
5845 type.kind = classType;
5846 type._class = FindClass(_class.name);
5847 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5849 ListEnumValues(_class);
5852 conversions.Free(null);
5856 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5858 result |= ListEnums(nameSpace, dest);
5863 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5867 for(c = 0; (ch = name[c]); c++)
5869 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5871 NameSpace * newSpace;
5872 char * spaceName = new char[c - start + 1];
5873 memcpy(spaceName, name + start, c - start);
5874 spaceName[c-start] = '\0';
5875 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5879 nameSpace = newSpace;
5888 return (NameSpace *)nameSpace;
5891 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5893 bool listedEnums = false;
5894 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5895 bool listClasses = true;
5897 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5899 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5900 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5901 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5903 if(exp.type == identifierExp)
5904 id = realIdentifier;
5906 if(id && id._class && !id._class.name)
5908 listClasses = false;
5911 else if(id && id._class && id._class.name)
5915 Class _class = id.classSym.registered;
5916 if(_class && _class.type == enumClass)
5918 ListEnumValues(_class);
5921 ListClassMembers(id.classSym.registered, true);
5926 else if(id && colons)
5928 ListNameSpaceByString(this.privateModule, id.string);
5933 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
5935 listedEnums = ListEnumsModule(this.privateModule, destType);
5938 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
5940 ListEnumValues(destType._class.registered);
5943 ListClassPropertiesAndVirtual(insideClass);
5947 else if(destType && destType.kind == enumType)
5951 for(value = destType.members.first; value; value = value.next)
5953 DataRow row = membersList.AddString(value.name);
5954 row.icon = icons[typeEnumValue];
5958 ListClassPropertiesAndVirtual(insideClass);
5962 else if(insideClass && !enumOnly)
5964 ListClassPropertiesAndVirtual(insideClass);
5967 if(listedEnums && string && string[0])
5969 DataRow row = membersList.FindSubString(string);
5971 listedEnums = false;
5974 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
5976 ListClassMembersMatch(GetThisClass(), exp.destType);
5978 else if(!insideClass && !enumOnly && !listedEnums)
5981 Symbol symbol = null;
5985 ListClassMembers(GetThisClass(), false);
5988 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
5990 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
5992 // Don't list enum values?
5993 //if(symbol.type.kind != TypeEnum)
5994 DataRow row = membersList.FindString(symbol.string);
5997 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
5999 row = membersList.AddString(symbol.string);
6000 if(symbol.type && symbol.type.kind == functionType)
6001 row.icon = icons[typeMethod];
6002 else if(symbol.type && symbol.type.kind == enumType)
6004 row.icon = icons[typeEnumValue];
6008 BitmapResource bitmap = null;
6009 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6011 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6014 bitmap = { bitmapName };
6015 membersList.AddResource(bitmap);
6018 row.icon = bitmap ? bitmap : icons[typeData];
6025 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6027 DataRow row = membersList.FindString(symbol.string);
6030 row = membersList.AddString(symbol.string);
6031 if(symbol.type.kind == functionType)
6032 row.icon = icons[typeMethod];
6033 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6035 row.icon = icons[typeClass];
6039 row.icon = icons[typeDataType];
6046 ListModule(this.privateModule, 1, listClasses);
6047 // TODO: Implement this with name space
6051 for(data = globalData.first; data; data = data.next)
6053 DataRow row = membersList.FindString(data.name);
6055 data.dataType = ProcessTypeString(data.dataTypeString, false);
6058 row = membersList.AddString(data.name);
6060 if(data.dataType && data.dataType.kind == TypeEnum)
6062 row.icon = icons[typeEnumValue];
6066 BitmapResource bitmap = null;
6067 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6069 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6072 bitmap = { bitmapName };
6073 membersList.AddResource(bitmap);
6076 row.icon = bitmap ? bitmap : icons[typeData];
6084 DataRow row = membersList.AddString("Min");
6085 row.icon = icons[typeMethod];
6087 row = membersList.AddString("Max");
6088 row.icon = icons[typeMethod];
6090 row = membersList.AddString("Abs");
6091 row.icon = icons[typeMethod];
6093 row = membersList.AddString("Sgn");
6094 row.icon = icons[typeMethod];
6100 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6102 EditBoxStream f { editBox = editBox };
6107 updatingCode = true;
6109 if(!method.dataType)
6110 method.dataType = ProcessTypeString(method.dataTypeString, false);
6112 DeleteJunkBefore(f, function.loc.start.pos, &position);
6113 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6115 // ADDING METHOD HERE
6117 Type dataType = method.dataType;
6118 Type returnType = dataType.returnType;
6120 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6126 if(extraIndent) f.Printf(" ");
6128 OutputType(f, returnType, false);
6132 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6134 if(dataType.thisClass.shortName)
6135 f.Printf(dataType.thisClass.shortName);
6137 f.Printf(dataType.thisClass.string);
6140 f.Printf(method.name);
6142 for(param = dataType.params.first; param; param = param.next)
6144 // Decided not to write void...
6145 if(param.kind != voidType)
6147 OutputType(f, param, true);
6153 if(extraIndent) f.Printf(" ");
6154 f.Printf(" %c\n", OpenBracket);
6156 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6160 //if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
6162 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6164 if(extraIndent) f.Printf(" ");
6165 f.Printf(" return true;\n");
6167 else if(returnType && returnType.kind != voidType)
6169 if(extraIndent) f.Printf(" ");
6170 f.Printf(" return 0;\n");
6176 if(returnType.kind != voidType)
6177 f.Printf("return ");
6178 f.Printf("%s::%s(this", classDef.base.name, method.name);
6179 for(param = dataType.params.first; param; param = param.next)
6182 f.Printf(param.name);
6189 if(extraIndent) f.Printf(" ");
6190 f.Printf(" %c", CloseBracket);
6195 if(extraIndent) { x1 += 3; x2 += 3; }
6196 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6198 this.updatingCode = false;
6202 // Return false if we overrided a function and don't want to run params listing
6203 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6205 bool didOverride = false;
6206 EditLine line = editBox.line;
6207 char * text = line.text;
6208 int lineNum, charPos;
6209 Expression exp = null;
6212 //Identifier id = null;
6213 Expression memberExp = null;
6214 Identifier realIdentifier = null;
6216 if(!privateModule) return !didOverride;
6218 insideFunction = null;
6220 charPos = editBox.charPos + 1;
6221 if(!membersListShown)
6226 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6228 EditBoxStream f { editBox = editBox };
6230 updatingCode = true;
6231 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6235 if(!f.Seek(-1, current))
6238 if(!isspace(ch)) break;
6239 f.Seek(-1, current);
6241 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6243 lineNum = editBox.lineNumber + 1;
6244 charPos = editBox.charPos + 1;
6246 updatingCode = false;
6249 if(!membersListShown)
6251 memberExp = FindExpTree(ast, lineNum, charPos);
6252 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6257 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6259 EditBoxStream f { editBox = editBox };
6262 updatingCode = true;
6264 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6267 if(ch == '}' || ch == ',' || ch == ')')
6269 f.Seek(-1, current);
6277 if(!f.Seek(-1, current))
6280 if(!isspace(ch)) break;
6281 f.Seek(-1, current);
6285 f.Seek(-1, current);
6287 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6289 lineNum = editBox.lineNumber + 1;
6290 charPos = editBox.charPos + 1;
6292 updatingCode = false;
6295 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6300 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6301 lineNum = editBox.lineNumber + 1;
6302 charPos = editBox.charPos/* + 1*/;
6306 char tempString[1024];
6307 char * string = null;
6308 CodePosition idStart, idEnd;
6310 if(membersListShown)
6312 char * buffer = membersLine.text;
6314 bool firstChar = true;
6316 string = tempString;
6318 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6320 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6321 if(!isSpace) firstChar = false;
6323 string[len++] = buffer[c];
6327 else //if(realIdentifier)//if(id)
6330 char * buffer = id.string;
6332 bool firstChar = true;
6334 string = tempString;
6335 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6337 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6338 if(!isSpace) firstChar = false;
6340 string[len++] = buffer[c];
6346 EditLine editLine = editBox.line;
6347 bool firstChar = true;
6350 string = tempString;
6351 for(y = lineNum-1; y >= 0; y--)
6353 char * buffer = editLine.text;
6354 int lineCount = editLine.count;
6355 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6357 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6362 idEnd.charPos = x + 2;
6367 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6370 idEnd.charPos = x + 2;
6377 if(!isalnum(buffer[x]) && buffer[x] != '_')
6383 memmove(string+1, string, len++);
6384 string[0] = buffer[x];
6388 //if(done || firstChar)
6389 if(done || !firstChar)
6391 editLine = editLine.prev;
6394 if(!strcmp(string, "case"))
6400 else if(!strcmp(string, "return"))
6406 else if(!strcmp(string, "delete"))
6412 else if(!strcmp(string, "new"))
6418 else if(!strcmp(string, "renew"))
6426 idStart.charPos = x + 1;
6427 idStart.line = y + 1;
6430 if(!membersListShown)
6432 membersList.Clear();
6433 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6435 Type type = memberExp.member.exp.expType;
6436 if(pointer == 2 && type)
6438 if(type.kind == pointerType || type.kind == arrayType)
6447 ListSymbols(exp, enumOnly, string, realIdentifier);
6449 membersList.Sort(null, 1);
6454 // Virtual function override
6455 Identifier id = GetDeclId(insideFunction.declarator);
6456 char * string = id ? id.string : null;
6458 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6461 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6462 insideFunction = null;
6465 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6470 if(!didOverride) //insideFunction)
6472 rowCount = membersList.rowCount;
6475 DataRow row = string ? membersList.FindSubString(string) : null;
6476 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6478 char * newString = row.string;
6479 if(!membersListShown)
6481 membersLoc.start.line = idStart.line-1;
6482 membersLoc.start.charPos = idStart.charPos-1;
6483 //membersLoc.end = membersLoc.start;
6484 membersLoc.end.charPos = idEnd.charPos-1;
6485 membersLoc.end.line = idEnd.line-1;
6486 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6487 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6492 membersList.Destroy(0);
6493 membersListShown = false;
6496 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6498 line, membersLoc.start.line, membersLoc.start.charPos,
6499 line, membersLoc.end.line, membersLoc.end.charPos);
6500 editBox.PutS(newString);
6506 row = membersList.FindSubStringi(string);
6508 membersList.currentRow = row;
6509 membersList.currentRow.selected = false;
6512 membersList.currentRow = row;
6514 if(!membersListShown)
6518 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6519 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6520 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6521 editBox.GetCaretPosition(caret);
6522 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6524 membersList.master = this;
6526 caret.y += editBox.GetCaretSize();
6528 membersList.Create();
6531 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6532 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6533 Window parent = membersList.parent;
6535 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6537 y -= editBox.GetCaretSize() + membersList.size.h;
6538 membersAbove = true;
6541 membersAbove = false;
6543 membersList.position = { x, y };
6547 membersLoc.start.line = lineNum - 1;
6549 if(string && string[0])
6551 membersLoc.start.charPos = idStart.charPos-1;
6552 membersLoc.end = membersLoc.start;
6553 //membersLoc.end.charPos = id.loc.end.charPos-1;
6554 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6558 membersLoc.start.charPos = charPos;
6559 membersLoc.end = membersLoc.start;
6560 membersLoc.end.charPos = charPos;
6562 membersListShown = true;
6564 // Hack to keep caret shown
6565 editBox.GetCaretPosition(caret);
6566 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6569 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6575 SetCurrentContext(globalContext);
6578 return !didOverride;
6581 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6583 EditLine line = editBox.line;
6584 char * text = line.text;
6585 int lineNum, charPos;
6586 Expression exp = null;
6590 charPos = editBox.charPos + 1;
6593 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6595 EditBoxStream f { editBox = editBox };
6598 updatingCode = true;
6599 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6602 if(ch == '}' || ch == ',' || ch == ')')
6604 f.Seek(-1, current);
6612 if(!f.Seek(-1, current))
6615 if(!isspace(ch)) break;
6616 f.Seek(-1, current);
6620 f.Seek(-1, current);
6622 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6624 lineNum = editBox.lineNumber + 1;
6625 charPos = editBox.charPos + 1;
6627 updatingCode = false;
6630 charPos = Min(charPos, l1.count + 1);
6632 FindParamsTree(ast, lineNum, charPos);
6634 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6635 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6637 ::functionType = null;
6638 ::instanceType = null;
6641 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6642 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6646 Window parent = paramsList.parent;
6648 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6651 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6652 // ( Dummy exp: always ends up with same memory)
6654 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6655 editBox.GetCaretPosition(paramsPosition);
6656 this.paramsPosition.y += editBox.GetCaretSize();
6659 FreeType(this.functionType);
6660 FreeType(this.instanceType);
6662 this.functionType = ::functionType;
6663 this.instanceType = ::instanceType;
6665 if(this.functionType) this.functionType.refCount++;
6666 if(this.instanceType) this.instanceType.refCount++;
6668 this.paramsID = ::paramsID;
6669 functionExp = paramsInsideExp;
6671 paramsList.master = this;
6673 paramsList.Create();
6675 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6676 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6678 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6680 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6684 paramsAbove = false;
6685 if(x + paramsList.size.w > parent.clientSize.w)
6687 x = parent.clientSize.w - paramsList.size.w;
6691 paramsList.position = { x, y };
6693 // Hack to keep caret shown
6696 editBox.GetCaretPosition(caret);
6697 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6700 this.paramsShown = true;
6702 else if((!::functionType && !::instanceType) || reposition)
6704 paramsList.Destroy(0);
6705 paramsShown = false;
6707 FreeType(this.functionType);
6708 FreeType(this.instanceType);
6709 this.functionType = null;
6710 this.instanceType = null;
6714 SetCurrentContext(globalContext);
6722 designer.visible = true;
6723 designer.Activate();
6729 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6731 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };