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(IsPathInsideOf(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);
1992 if(inUseDebug && !debugClosing)
1994 debugClosing = true;
1996 if(CloseConfirmation(false))
1999 OnFileModified({ modified = true }, null);
2001 debugClosing = false;
2004 if(designer && !designer.closing)
2006 if(designer.visible)
2013 //Window formEditor = designer;
2014 //formEditor.Destroy(0);
2017 ide.AdjustFileMenus();
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 if(param.kind != voidType)
4186 f.Printf(param.name);
4190 f.Printf(" %c\n", CloseBracket);
4196 if(!object.instCode)
4199 f.Printf(" %c;\n", CloseBracket);
4201 f.Printf("%c;\n", CloseBracket);
4203 else if(!object.deleted)
4205 // Turn this into a multiline instance when adding a method
4206 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4208 f.Printf(methodPresent ? "\n " : " ");
4210 f.Seek(inst.loc.end.pos + 1 - position, current);
4211 position = inst.loc.end.pos + 1;
4216 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4219 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4221 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4223 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4225 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4226 if(prop && prop.isProperty && !prop.conversion)
4228 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4229 (!prop.IsSet || prop.IsSet(classObject.instance)))
4231 Class dataType = prop.dataTypeClass;
4232 char tempString[1024] = "";
4234 bool specify = false;
4237 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4238 if(member && member._class == regClass)
4242 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4244 if(dataType && dataType.type == structClass)
4246 void * dataForm = new0 byte[dataType.structSize];
4247 void * dataTest = new0 byte[dataType.structSize];
4249 prop.Get(classObject.instance, dataForm);
4250 prop.Get(test, dataTest);
4252 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
4254 bool needClass = true;
4256 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
4257 prop.Set(test, dataForm);
4259 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4261 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4266 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4268 void * dataForm, * dataTest;
4270 dataForm = (void *)prop.Get(classObject.instance);
4271 dataTest = (void *)prop.Get(test);
4273 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
4275 char tempString[1024] = "";
4277 prop.Set(test, dataForm);
4279 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4281 // Shouldn't go here ...
4282 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4286 bool needClass = true;
4288 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
4290 if(!strcmp(dataType.dataTypeString, "char *"))
4292 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4293 OutputString(f, string);
4297 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4299 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4305 DataValue dataForm, dataTest;
4307 GetProperty(prop, classObject.instance, &dataForm);
4308 GetProperty(prop, test, &dataTest);
4310 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
4312 SetProperty(prop, test, dataForm);
4313 if(dataType.type == bitClass)
4315 bool needClass = true;
4316 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
4318 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4320 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4324 bool needClass = true;
4325 if(dataType.type == enumClass)
4328 Class enumClass = eSystem_FindClass(privateModule, "enum");
4329 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4331 for(value = e.values.first; value; value = value.next)
4333 if((int)value.data == dataForm.i)
4335 string = value.name;
4341 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
4342 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4343 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4345 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4354 void UpdateFormCode()
4363 else if(formModified)
4365 EditBoxStream f { editBox = editBox };
4369 Identifier movedFuncId;
4370 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4371 ObjectInfo classObject;
4377 movedFuncId = GetDeclId(function.declarator);
4378 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4379 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4382 for(classObject = classes.first; classObject; classObject = classObject.next)
4385 ClassDefinition classDef = classObject.classDefinition;
4386 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4389 bool firstObject = true;
4390 ObjectInfo object = classObject.instances.first;
4391 bool lastIsDecl = false;
4393 if(!classObject.modified) continue;
4395 test = eInstance_New(regClass);
4398 // Put it in the same desktop window...
4399 designer.PrepareTestObject(test);
4401 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4402 //f.Printf("%c\n\n", OpenBracket);
4404 // Change the _class name
4405 f.Seek(classDef.nameLoc.start.pos - position, current);
4406 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4407 f.Printf(classObject.name);
4408 position = classDef.nameLoc.end.pos;
4411 // Go to block start, delete all until no white space, put \n
4415 f.Seek(classDef.blockStart.end.pos - position, current);
4416 position = classDef.blockStart.end.pos;
4418 for(; f.Getc(&ch); count++)
4422 f.Seek(-1, current);
4432 f.Seek(-count, current);
4434 f.DeleteBytes(count-back);
4436 position += count-back;
4439 // Output properties
4440 OutputClassProperties(classObject.instance._class, classObject, f, test);
4442 for(def = classDef.definitions->first; def; def = def.next)
4446 case defaultPropertiesClassDef:
4448 bool keptMember = false;
4450 MemberInit lastKept = null;
4453 DeleteJunkBefore(f, def.loc.start.pos, &position);
4456 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4458 Identifier ident = propDef.identifiers->first;
4459 bool deleted = false;
4461 // For now delete if it's a prop
4462 if(!propDef.variable && ident)
4466 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4469 f.Seek(propDef.loc.start.pos - position, current);
4470 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4471 position = propDef.loc.end.pos;
4476 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4477 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4479 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4480 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4482 f.Seek(propDef.loc.start.pos - position, current);
4483 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4484 position = propDef.loc.end.pos;
4502 f.Seek(def.loc.end.pos - position - 1, current);
4507 f.Seek(-1, current);
4510 position = def.loc.end.pos;
4514 if(lastKept != def.defProperties->last)
4519 f.Seek(-1, current);
4525 f.Seek(-1, current);
4528 else if(!isspace(ch))
4530 f.Seek(-2, current);
4535 f.DeleteBytes(count);
4539 f.Seek(def.loc.end.pos - position, current);
4540 position = def.loc.end.pos;
4545 case declarationClassDef:
4547 Declaration decl = def.decl;
4549 if(decl.type == instDeclaration)
4551 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4553 while(def.object && object != def.object)
4555 if(object /*&& ((ObjectInfo)def.object).modified*/)
4556 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4557 object = object.next;
4560 DeleteJunkBefore(f, def.loc.start.pos, &position);
4561 f.Printf(firstObject ? "\n\n " : "\n ");
4562 firstObject = false;
4564 if(def.object && ((ObjectInfo)def.object).modified)
4565 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4567 object = object ? object.next : null;
4571 DeleteJunkBefore(f, def.loc.start.pos, &position);
4572 f.Printf(firstObject ? "\n\n " : "\n ");
4573 firstObject = false;
4579 DeleteJunkBefore(f, def.loc.start.pos, &position);
4580 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4585 case functionClassDef:
4587 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4588 if(!def.function.body) continue;
4592 DeleteJunkBefore(f, def.loc.start.pos, &position);
4595 // Delete _class methods
4596 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4597 def.function == function)
4602 if(moveAttached && !text)
4604 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4607 f.Seek(def.loc.end.pos - position, current);
4608 for(; f.Getc(&ch); count++)
4612 f.Seek(-1, current);
4616 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4618 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4619 position = def.loc.end.pos + count;
4622 // In case of detaching methods in the _class, simply rename the method
4623 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4625 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4626 f.DeleteBytes(movedFuncIdLen);
4628 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4631 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4632 function == def.function)
4634 // In case of attaching methods in the _class, simply rename the method
4635 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4636 position = function.loc.start.pos + movedFuncIdPos;
4637 f.DeleteBytes(movedFuncIdLen);
4638 if(method.dataType.thisClass)
4639 f.Printf("%s::", method.dataType.thisClass.string);
4640 f.Puts(method.name);
4641 position += movedFuncIdLen;
4646 DeleteJunkBefore(f, def.loc.start.pos, &position);
4647 if(def.type == memberAccessClassDef)
4650 firstObject = false;
4660 f.Seek(def.loc.end.pos - position, current);
4661 position = def.loc.end.pos;
4664 // Output attached methods
4665 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4667 DeleteJunkBefore(f, position, &position);
4668 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4671 // ********** INSTANCES ***************
4672 for(; object; object = object.next)
4674 if(!object.instCode)
4676 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4680 DeleteJunkBefore(f, position, &position);
4682 // ****************** METHODS ***********************
4683 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4685 // If detaching an instance method
4686 if(selected != classObject)
4688 int newLen = strlen(methodName);
4691 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4692 // Tab selection left
4695 for(c = 0; text[c]; )
4698 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4699 memmove(text+start, text+start+i, textSize+1-start-i);
4702 for(; text[c] && text[c] != '\n'; c++);
4708 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4709 textSize += newLen - movedFuncIdLen;
4710 memcpy(text + movedFuncIdPos, methodName, newLen);
4717 if(methodAction == actionAddMethod && selected == classObject)
4719 Method method = this.method;
4721 if(!method.dataType)
4722 method.dataType = ProcessTypeString(method.dataTypeString, false);
4724 // ADDING METHOD HERE
4726 Type dataType = method.dataType;
4727 Type returnType = dataType.returnType;
4729 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4733 OutputType(f, returnType, false);
4736 if(dataType.thisClass && !dataType.classObjectType)
4738 if(dataType.thisClass.shortName)
4739 f.Printf(dataType.thisClass.shortName);
4741 f.Printf(dataType.thisClass.string);
4744 f.Printf(method.name);
4746 for(param = dataType.params.first; param; param = param.next)
4748 OutputType(f, param, true);
4753 f.Printf(" %c\n\n", OpenBracket);
4755 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4757 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4758 f.Printf(" return true;\n");
4759 else if(returnType && returnType.kind != voidType)
4760 f.Printf(" return 0;\n");
4765 if(returnType.kind != voidType)
4766 f.Printf("return ");
4768 char * name = ((Specifier)classDef.baseSpecs->first).name;
4769 Symbol _class = FindClass(name);
4770 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4772 for(param = dataType.params.first; param; param = param.next)
4774 if(param.prev) f.Printf(", ");
4775 if(param.kind != voidType)
4776 f.Printf(param.name);
4781 f.Printf(" %c", CloseBracket);
4785 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4797 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4798 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4802 codeModified = false;
4803 formModified = false;
4805 moveAttached = false;
4810 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4813 ClassFunction function = null;
4816 ObjectInfo object = this.selected;
4818 if(object && object == this.oClass)
4820 ClassDefinition classDef = object.oClass.classDefinition;
4822 if(classDef && classDef.definitions)
4824 for(def = classDef.definitions->first; def; def = def.next)
4826 if(def.type == functionClassDef && def.function.declarator)
4828 if(!strcmp(def.function.declarator.symbol.string, methodName))
4830 function = def.function;
4835 else if(def.type == defaultPropertiesClassDef)
4839 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4841 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4842 if(ident && !ident.next)
4844 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4848 propLoc = propDef.loc;
4851 ClassDefinition classDef = object.oClass.classDefinition;
4853 if(classDef.definitions)
4855 for(def = classDef.definitions->first; def; def = def.next)
4857 if(def.type == functionClassDef)
4859 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4861 function = def.function;
4880 Instantiation inst = object.instCode;
4882 // Check here to see if the method already exists, no need to call ModifyCode in that case
4883 if(inst && inst.members)
4885 MembersInit members;
4886 for(members = inst.members->first; members; members = members.next)
4888 switch(members.type)
4890 case dataMembersInit:
4892 if(members.dataMembers)
4895 for(member = members.dataMembers->first; member; member = member.next)
4897 Identifier ident = member.identifiers ? member.identifiers->first : null;
4898 if(ident && !ident.next)
4900 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4904 propLoc = member.loc;
4907 ClassDefinition classDef = object.oClass.classDefinition;
4909 if(classDef.definitions)
4911 for(def = classDef.definitions->first; def; def = def.next)
4913 if(def.type == functionClassDef)
4915 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
4917 function = def.function;
4926 // TODO: Fix memory leak
4927 function = ClassFunction
4929 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
4941 case methodMembersInit:
4943 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
4945 function = members.function;
4957 if(functionPtr) *functionPtr = function;
4961 void GoToMethod(char * methodName /*Method method*/)
4965 ObjectInfo object = selected;
4966 EditBoxStream f { editBox = editBox };
4967 ClassFunction function = null;
4968 bool atChar = false;
4972 Location propLoc = { {0,0,-1} };
4975 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
4976 if(function && function.body)
4979 f.Seek(function.body.loc.start.pos+1, current);
4989 f.Seek(-1, current);
4994 else if(!isspace(ch))
4996 f.Seek(-1, current);
5002 else if(propLoc.start.pos > -1)
5004 f.Seek(propLoc.start.pos, current);
5007 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5009 if(function || propLoc.start.pos > -1)
5011 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5012 editBox.CenterOnCursor();
5013 SetState(normal, false, 0);
5016 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5018 FreeClassFunction(function);
5024 void FindCompatibleMethods(Method method, OldList compatible)
5026 ClassDefinition classDef = this.oClass.classDefinition;
5027 if(classDef && classDef.definitions)
5030 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5033 Symbol classSym { };
5034 Symbol selectedClass;
5035 if(this.selected == this.oClass)
5036 selectedClass = classSym;
5038 selectedClass = FindClass(this.selected.instance._class.name);
5040 regClass.name = classDef._class.name;
5041 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5042 for(def = classDef.definitions->first; def; def = def.next)
5044 if(def.type == functionClassDef && def.function.declarator)
5046 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5048 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5051 Type type = def.function.declarator.symbol.type;
5052 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5054 compatible.Add(OldLink { data = def.function });
5060 if(this.oClass && this.oClass.instance)
5062 classSym.registered = regClass;
5063 //classSym.registered = this.oClass.oClass;
5065 for(_class = regClass.base; _class; _class = _class.base)
5068 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5070 // TODO: Understand why these functions popup in attach list
5071 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5073 if(!testMethod.dataType)
5074 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5076 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5077 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5078 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5080 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5081 // ClassFunction function { };
5082 FunctionDefinition function { };
5084 function.declarator = Declarator { };
5085 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5086 excludedSymbols.Add(function.declarator.symbol);
5088 compatible.Add(OldLink { data = function });
5099 void AddMethod(Method method)
5103 char methodName[1024];
5104 strcpy(methodName, method.name);
5105 if(!FindMethod(methodName, null, null))
5107 methodAction = actionAddMethod;
5108 this.method = method;
5112 GoToMethod(methodName);
5116 void DeleteMethod(ClassFunction function)
5120 methodAction = actionDeleteMethod;
5121 this.function = function;
5129 void AttachMethod(Method method, ClassFunction function)
5133 // If it's an instance we'll ask if we want to move it inside...
5134 if(!function.attached.count && function.body)
5136 // Find the function in the _class to check if it's a virtual function
5137 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5138 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5139 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5141 for(def = this.classDefinition.first; def; def = def.next)
5143 if(def.type == functionClassDef)
5145 if(def.function == function)
5150 if(!method || method.type != virtualMethod)
5153 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5154 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5156 moveAttached = true;
5161 methodAction = actionAttachMethod;
5162 this.method = method;
5163 this.function = function;
5170 void ReAttachMethod(Method method, ClassFunction function)
5174 // If it's an instance we'll ask if we want to move it inside...
5175 if(!function.attached.count && function.body)
5177 // Find the function in the _class to check if it's a virtual function
5178 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5179 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5180 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5182 for(def = this.classDefinition.first; def; def = def.next)
5184 if(def.type == functionClassDef)
5186 if(def.function == function)
5191 if(!method || method.type != virtualMethod)
5194 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5195 if(MessageBox { type = yesNo, master = parent, text = title,
5196 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5198 moveAttached = true;
5203 methodAction = actionReattachMethod;
5204 this.method = method;
5205 this.function = function;
5212 void DetachMethod(Method method, ClassFunction function, int type)
5220 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5221 master = sheet, text = $"Name detached method", background = formColor
5225 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5226 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5230 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5231 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5235 dialog, anchor = { left = 5, right = 5, top = 5 }
5237 sprintf(methodName, "%s_%s", selected.name, method.name);
5238 nameBox.contents = methodName;
5240 result = dialog.Modal() == ok;
5241 strcpy(methodName, nameBox.contents);
5246 // If the method is not attached, move it outside
5249 // Add this class to the methodName
5250 char name[1024] = "";
5252 if(this.selected != this.oClass && !method.dataType.thisClass)
5254 strcat(name, this.selected.instance._class.name);
5256 strcat(name, this.methodName);
5257 strcpy(this.methodName, name);
5259 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5261 strcat(name, method.dataType.thisClass.string);
5263 strcat(name, this.methodName);
5264 strcpy(this.methodName, name);
5267 this.moveAttached = true;
5270 this.methodAction = actionDetachMethod;
5271 this.method = method;
5272 this.function = function;
5279 void AddObject(Instance instance, ObjectInfo * object)
5283 //*object = _class.instances.Add(sizeof(ObjectInfo));
5284 *object = ObjectInfo { };
5285 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5286 (*object).oClass = oClass;
5287 (*object).instance = instance;
5292 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5294 // if(strcmp(name, this.oClass.instance.name))
5297 for(check = oClass.instances.first; check; check = check.next)
5298 if(!check.deleted && check.name && !strcmp(name, check.name))
5302 (*object).name = CopyString(name);
5307 toolBox.controlClass = null;
5311 //sheet.AddObject(*object, (*object).name, TypeData, true);
5316 void EnsureUpToDate()
5318 if(sheet && codeModified)
5322 void SelectObject(ObjectInfo object)
5325 oClass = object ? object.oClass : null;
5327 designer.SelectObject(object, object ? object.instance : null);
5330 void SelectObjectFromDesigner(ObjectInfo object)
5333 sheet.SelectObject(object);
5336 void EnumerateObjects(Sheet sheet)
5340 for(oClass = classes.first; oClass; oClass = oClass.next)
5346 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5347 for(object = oClass.instances.first; object; object = object.next)
5348 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5351 sheet.SelectObject(selected);
5356 designer.AddObject();
5359 void DeleteObject(ObjectInfo object)
5361 delete object.instance;
5362 object.deleted = true;
5363 object.modified = true;
5364 object.oClass.modified = true;
5366 if(selected == object)
5368 bool looped = false;
5369 ObjectInfo select = object;
5373 select = select.prev;
5377 select = object.oClass.instances.last;
5384 sheet.SelectObject(select ? select : oClass);
5387 if(!object.instCode && object.oClass != object)
5390 oClass.instances.Delete(object);
5393 if(sheet.codeEditor == this)
5394 sheet.DeleteObject(object);
5397 void RenameObject(ObjectInfo object, char * name)
5401 // Validate the name:
5402 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5403 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5406 for(c = 0; name[c]; c++)
5407 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5415 object.name = (name && name[0]) ? CopyString(name) : null;
5417 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5421 void DesignerModifiedObject()
5423 sheet.ListProperties(false);
5427 void ListSubMembers(Type member)
5431 for(subMember = member.members.first; subMember; subMember = subMember.next)
5435 DataRow row = membersList.AddString(subMember.name);
5436 row.icon = icons[typeData];
5440 ListSubMembers(subMember);
5445 void ListSubDataMembers(DataMember member, bool isPrivate)
5447 DataMember subMember;
5448 for(subMember = member.members.first; subMember; subMember = subMember.next)
5450 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5454 DataRow row = membersList.AddString(subMember.name);
5455 BitmapResource bitmap = null;
5456 if(!subMember.dataType)
5457 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5459 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5461 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5464 bitmap = { bitmapName };
5465 membersList.AddResource(bitmap);
5468 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5472 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5478 void ListClassMembers(Class whatClass, bool methodsOnly)
5481 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5482 bool isPrivate = false;
5484 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5486 Method method, methodIt;
5488 DataMember memberIt;
5490 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5492 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5493 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5495 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5497 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5499 DataRow row = membersList.FindString(method.name);
5502 row = membersList.AddString(method.name);
5504 if(!method.dataType)
5505 method.dataType = ProcessTypeString(method.dataTypeString, false);
5507 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5515 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5519 if(memberIt.isProperty)
5521 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5523 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5527 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5529 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5532 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5538 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5540 if(member.isProperty)
5542 Property prop = (Property) member;
5543 if(!membersList.FindString(prop.name))
5545 DataRow row = membersList.AddString(prop.name);
5546 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5549 else if(member.name && !membersList.FindString(member.name))
5551 DataRow row = membersList.AddString(member.name);
5553 BitmapResource bitmap = null;
5554 if(!member.dataType)
5555 member.dataType = ProcessTypeString(member.dataTypeString, false);
5557 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5559 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5562 bitmap = { bitmapName };
5563 membersList.AddResource(bitmap);
5566 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5569 ListSubDataMembers(member, member.memberAccess == privateAccess);
5573 if(_class.inheritanceAccess == privateAccess)
5576 if(_class.module != privateModule) break;
5581 void ListClassMembersMatch(Class whatClass, Type methodType)
5584 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5585 bool isPrivate = false;
5587 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5593 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5595 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5597 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5599 if(!method.dataType)
5600 method.dataType = ProcessTypeString(method.dataTypeString, false);
5602 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5604 DataRow row = membersList.FindString(method.name);
5607 row = membersList.AddString(method.name);
5608 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5614 if(_class.inheritanceAccess == privateAccess)
5617 if(_class.module != privateModule) break;
5622 void ListClassPropertiesAndVirtual(Class whatClass)
5625 bool isPrivate = false;
5626 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5632 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5634 if(method.type == virtualMethod)
5636 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5638 DataRow row = membersList.FindString(method.name);
5641 row = membersList.AddString(method.name);
5643 if(!method.dataType)
5644 method.dataType = ProcessTypeString(method.dataTypeString, false);
5646 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5652 for(member = _class.membersAndProperties.first; member; member = member.next)
5654 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5656 if(member.isProperty)
5658 Property prop = (Property)member;
5660 DataRow row = membersList.AddString(prop.name);
5661 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5664 else if(member.name)
5666 DataRow row = membersList.AddString(member.name);
5668 BitmapResource bitmap = null;
5669 if(!member.dataType)
5670 member.dataType = ProcessTypeString(member.dataTypeString, false);
5672 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5674 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5677 bitmap = { bitmapName };
5678 membersList.AddResource(bitmap);
5681 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5684 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5687 if(_class.inheritanceAccess == privateAccess)
5690 if(_class.module != privateModule) break;
5695 void ListMembers(Type type)
5697 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5701 if(type.kind == classType)
5704 ListClassMembers(type._class.registered, false);
5709 for(member = type.members.first; member; member = member.next)
5713 DataRow row = membersList.AddString(member.name);
5714 row.icon = icons[typeData];
5716 else if(member.kind == structType || member.kind == unionType)
5717 ListSubMembers(member);
5723 void ListModule(Module mainModule, int recurse, bool listClasses)
5726 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5727 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5728 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5729 for(module = mainModule.application.allModules.first; module; module = module.next)
5731 if(ModuleVisibility(mainModule, module))
5732 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5736 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5743 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5745 Class _class = link.data;
5746 if(_class.type != systemClass)
5748 DataRow row = membersList.AddString(_class.name);
5749 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5754 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5756 DefinedExpression definedExp = link.data;
5757 DataRow row = membersList.AddString(link /*definedExp*/.name);
5758 row.icon = icons[typeData];
5761 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5763 GlobalFunction function = link.data;
5764 DataRow row = membersList.AddString(link /*function*/.name);
5765 row.icon = icons[typeMethod];
5769 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5771 if(recurse != 2 && listClasses)
5773 if(!membersList.FindString(ns->name))
5775 DataRow row = membersList.AddString(ns->name);
5776 row.icon = icons[typeNameSpace];
5781 ListNameSpace(ns, 2, listClasses);
5785 void ListEnumValues(Class _class)
5787 for(; _class && _class.type == enumClass; _class = _class.base)
5789 EnumClassData enumeration = (EnumClassData)_class.data;
5791 for(item = enumeration.values.first; item; item = item.next)
5793 DataRow row = membersList.AddString(item.name);
5794 row.icon = icons[typeEnumValue];
5799 bool ListEnumsModule(Module mainModule, Type dest)
5801 bool result = false;
5803 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5804 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5805 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5806 for(module = mainModule.application.allModules.first; module; module = module.next)
5808 if(ModuleVisibility(mainModule, module))
5809 result |= ListEnums(module.publicNameSpace, dest);
5814 void ListNameSpaceByString(Module mainModule, char * string)
5816 NameSpace * nameSpace;
5818 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5819 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5820 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5821 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5822 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5823 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5824 for(module = mainModule.application.allModules.first; module; module = module.next)
5826 if(ModuleVisibility(mainModule, module))
5828 nameSpace = FindNameSpace(module.publicNameSpace, string);
5829 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5834 bool ListEnums(NameSpace nameSpace, Type dest)
5837 bool result = false;
5839 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5841 Class _class = link.data;
5842 if(_class.type == enumClass && (dest.kind != classType || !dest._class || dest._class.registered != _class))
5844 OldList conversions { };
5846 type.kind = classType;
5847 type._class = FindClass(_class.name);
5848 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5850 ListEnumValues(_class);
5853 conversions.Free(null);
5857 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5859 result |= ListEnums(nameSpace, dest);
5864 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5868 for(c = 0; (ch = name[c]); c++)
5870 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5872 NameSpace * newSpace;
5873 char * spaceName = new char[c - start + 1];
5874 memcpy(spaceName, name + start, c - start);
5875 spaceName[c-start] = '\0';
5876 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5880 nameSpace = newSpace;
5889 return (NameSpace *)nameSpace;
5892 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5894 bool listedEnums = false;
5895 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5896 bool listClasses = true;
5898 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5900 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5901 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5902 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5904 if(exp.type == identifierExp)
5905 id = realIdentifier;
5907 if(id && id._class && !id._class.name)
5909 listClasses = false;
5912 else if(id && id._class && id._class.name)
5916 Class _class = id.classSym.registered;
5917 if(_class && _class.type == enumClass)
5919 ListEnumValues(_class);
5922 ListClassMembers(id.classSym.registered, true);
5927 else if(id && colons)
5929 ListNameSpaceByString(this.privateModule, id.string);
5934 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
5936 listedEnums = ListEnumsModule(this.privateModule, destType);
5939 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
5941 ListEnumValues(destType._class.registered);
5944 ListClassPropertiesAndVirtual(insideClass);
5948 else if(destType && destType.kind == enumType)
5952 for(value = destType.members.first; value; value = value.next)
5954 DataRow row = membersList.AddString(value.name);
5955 row.icon = icons[typeEnumValue];
5959 ListClassPropertiesAndVirtual(insideClass);
5963 else if(insideClass && !enumOnly)
5965 ListClassPropertiesAndVirtual(insideClass);
5968 if(listedEnums && string && string[0])
5970 DataRow row = membersList.FindSubString(string);
5972 listedEnums = false;
5975 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
5977 ListClassMembersMatch(GetThisClass(), exp.destType);
5979 else if(!insideClass && !enumOnly && !listedEnums)
5982 Symbol symbol = null;
5986 ListClassMembers(GetThisClass(), false);
5989 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
5991 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
5993 // Don't list enum values?
5994 //if(symbol.type.kind != TypeEnum)
5995 DataRow row = membersList.FindString(symbol.string);
5998 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6000 row = membersList.AddString(symbol.string);
6001 if(symbol.type && symbol.type.kind == functionType)
6002 row.icon = icons[typeMethod];
6003 else if(symbol.type && symbol.type.kind == enumType)
6005 row.icon = icons[typeEnumValue];
6009 BitmapResource bitmap = null;
6010 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6012 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6015 bitmap = { bitmapName };
6016 membersList.AddResource(bitmap);
6019 row.icon = bitmap ? bitmap : icons[typeData];
6026 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6028 DataRow row = membersList.FindString(symbol.string);
6031 row = membersList.AddString(symbol.string);
6032 if(symbol.type.kind == functionType)
6033 row.icon = icons[typeMethod];
6034 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6036 row.icon = icons[typeClass];
6040 row.icon = icons[typeDataType];
6047 ListModule(this.privateModule, 1, listClasses);
6048 // TODO: Implement this with name space
6052 for(data = globalData.first; data; data = data.next)
6054 DataRow row = membersList.FindString(data.name);
6056 data.dataType = ProcessTypeString(data.dataTypeString, false);
6059 row = membersList.AddString(data.name);
6061 if(data.dataType && data.dataType.kind == TypeEnum)
6063 row.icon = icons[typeEnumValue];
6067 BitmapResource bitmap = null;
6068 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6070 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6073 bitmap = { bitmapName };
6074 membersList.AddResource(bitmap);
6077 row.icon = bitmap ? bitmap : icons[typeData];
6085 DataRow row = membersList.AddString("Min");
6086 row.icon = icons[typeMethod];
6088 row = membersList.AddString("Max");
6089 row.icon = icons[typeMethod];
6091 row = membersList.AddString("Abs");
6092 row.icon = icons[typeMethod];
6094 row = membersList.AddString("Sgn");
6095 row.icon = icons[typeMethod];
6101 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6103 EditBoxStream f { editBox = editBox };
6108 updatingCode = true;
6110 if(!method.dataType)
6111 method.dataType = ProcessTypeString(method.dataTypeString, false);
6113 DeleteJunkBefore(f, function.loc.start.pos, &position);
6114 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6116 // ADDING METHOD HERE
6118 Type dataType = method.dataType;
6119 Type returnType = dataType.returnType;
6121 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6127 if(extraIndent) f.Printf(" ");
6129 OutputType(f, returnType, false);
6133 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6135 if(dataType.thisClass.shortName)
6136 f.Printf(dataType.thisClass.shortName);
6138 f.Printf(dataType.thisClass.string);
6141 f.Printf(method.name);
6143 for(param = dataType.params.first; param; param = param.next)
6145 // Decided not to write void...
6146 if(param.kind != voidType)
6148 OutputType(f, param, true);
6154 if(extraIndent) f.Printf(" ");
6155 f.Printf(" %c\n", OpenBracket);
6157 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6161 if(!_class || (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
6163 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6165 if(extraIndent) f.Printf(" ");
6166 f.Printf(" return true;\n");
6168 else if(returnType && returnType.kind != voidType)
6170 if(extraIndent) f.Printf(" ");
6171 f.Printf(" return 0;\n");
6176 if(extraIndent) f.Printf(" ");
6178 if(returnType.kind != voidType)
6179 f.Printf("return ");
6180 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6181 for(param = dataType.params.first; param; param = param.next)
6183 if(param.prev) f.Printf(", ");
6184 if(param.kind != voidType)
6185 f.Printf(param.name);
6191 if(extraIndent) f.Printf(" ");
6192 f.Printf(" %c", CloseBracket);
6197 if(extraIndent) { x1 += 3; x2 += 3; }
6198 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6200 this.updatingCode = false;
6204 // Return false if we overrided a function and don't want to run params listing
6205 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6207 bool didOverride = false;
6208 EditLine line = editBox.line;
6209 char * text = line.text;
6210 int lineNum, charPos;
6211 Expression exp = null;
6214 //Identifier id = null;
6215 Expression memberExp = null;
6216 Identifier realIdentifier = null;
6218 if(!privateModule) return !didOverride;
6220 insideFunction = null;
6222 charPos = editBox.charPos + 1;
6223 if(!membersListShown)
6228 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6230 EditBoxStream f { editBox = editBox };
6232 updatingCode = true;
6233 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6237 if(!f.Seek(-1, current))
6240 if(!isspace(ch)) break;
6241 f.Seek(-1, current);
6243 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6245 lineNum = editBox.lineNumber + 1;
6246 charPos = editBox.charPos + 1;
6248 updatingCode = false;
6251 if(!membersListShown)
6253 memberExp = FindExpTree(ast, lineNum, charPos);
6254 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6259 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6261 EditBoxStream f { editBox = editBox };
6264 updatingCode = true;
6266 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6269 if(ch == '}' || ch == ',' || ch == ')')
6271 f.Seek(-1, current);
6279 if(!f.Seek(-1, current))
6282 if(!isspace(ch)) break;
6283 f.Seek(-1, current);
6287 f.Seek(-1, current);
6289 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6291 lineNum = editBox.lineNumber + 1;
6292 charPos = editBox.charPos + 1;
6294 updatingCode = false;
6297 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6302 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6303 lineNum = editBox.lineNumber + 1;
6304 charPos = editBox.charPos/* + 1*/;
6308 char tempString[1024];
6309 char * string = null;
6310 CodePosition idStart, idEnd;
6312 if(membersListShown)
6314 char * buffer = membersLine.text;
6316 bool firstChar = true;
6318 string = tempString;
6320 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6322 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6323 if(!isSpace) firstChar = false;
6325 string[len++] = buffer[c];
6329 else //if(realIdentifier)//if(id)
6332 char * buffer = id.string;
6334 bool firstChar = true;
6336 string = tempString;
6337 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6339 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6340 if(!isSpace) firstChar = false;
6342 string[len++] = buffer[c];
6348 EditLine editLine = editBox.line;
6349 bool firstChar = true;
6352 string = tempString;
6353 for(y = lineNum-1; y >= 0; y--)
6355 char * buffer = editLine.text;
6356 int lineCount = editLine.count;
6357 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6359 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6364 idEnd.charPos = x + 2;
6369 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6372 idEnd.charPos = x + 2;
6379 if(!isalnum(buffer[x]) && buffer[x] != '_')
6385 memmove(string+1, string, len++);
6386 string[0] = buffer[x];
6390 //if(done || firstChar)
6391 if(done || !firstChar)
6393 editLine = editLine.prev;
6396 if(!strcmp(string, "case"))
6402 else if(!strcmp(string, "return"))
6408 else if(!strcmp(string, "delete"))
6414 else if(!strcmp(string, "new"))
6420 else if(!strcmp(string, "renew"))
6428 idStart.charPos = x + 1;
6429 idStart.line = y + 1;
6432 if(!membersListShown)
6434 membersList.Clear();
6435 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6437 Type type = memberExp.member.exp.expType;
6438 if(pointer == 2 && type)
6440 if(type.kind == pointerType || type.kind == arrayType)
6449 ListSymbols(exp, enumOnly, string, realIdentifier);
6451 membersList.Sort(null, 1);
6456 // Virtual function override
6457 Identifier id = GetDeclId(insideFunction.declarator);
6458 char * string = id ? id.string : null;
6460 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6463 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6464 insideFunction = null;
6467 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6472 if(!didOverride) //insideFunction)
6474 rowCount = membersList.rowCount;
6477 DataRow row = string ? membersList.FindSubString(string) : null;
6478 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6480 char * newString = row.string;
6481 if(!membersListShown)
6483 membersLoc.start.line = idStart.line-1;
6484 membersLoc.start.charPos = idStart.charPos-1;
6485 //membersLoc.end = membersLoc.start;
6486 membersLoc.end.charPos = idEnd.charPos-1;
6487 membersLoc.end.line = idEnd.line-1;
6488 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6489 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6494 membersList.Destroy(0);
6495 membersListShown = false;
6498 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6500 line, membersLoc.start.line, membersLoc.start.charPos,
6501 line, membersLoc.end.line, membersLoc.end.charPos);
6502 editBox.PutS(newString);
6508 row = membersList.FindSubStringi(string);
6510 membersList.currentRow = row;
6511 membersList.currentRow.selected = false;
6514 membersList.currentRow = row;
6516 if(!membersListShown)
6520 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6521 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6522 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6523 editBox.GetCaretPosition(caret);
6524 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6526 membersList.master = this;
6528 caret.y += editBox.GetCaretSize();
6530 membersList.Create();
6533 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6534 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6535 Window parent = membersList.parent;
6537 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6539 y -= editBox.GetCaretSize() + membersList.size.h;
6540 membersAbove = true;
6543 membersAbove = false;
6545 membersList.position = { x, y };
6549 membersLoc.start.line = lineNum - 1;
6551 if(string && string[0])
6553 membersLoc.start.charPos = idStart.charPos-1;
6554 membersLoc.end = membersLoc.start;
6555 //membersLoc.end.charPos = id.loc.end.charPos-1;
6556 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6560 membersLoc.start.charPos = charPos;
6561 membersLoc.end = membersLoc.start;
6562 membersLoc.end.charPos = charPos;
6564 membersListShown = true;
6566 // Hack to keep caret shown
6567 editBox.GetCaretPosition(caret);
6568 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6571 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6577 SetCurrentContext(globalContext);
6580 return !didOverride;
6583 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6585 EditLine line = editBox.line;
6586 char * text = line.text;
6587 int lineNum, charPos;
6588 Expression exp = null;
6592 charPos = editBox.charPos + 1;
6595 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6597 EditBoxStream f { editBox = editBox };
6600 updatingCode = true;
6601 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6604 if(ch == '}' || ch == ',' || ch == ')')
6606 f.Seek(-1, current);
6614 if(!f.Seek(-1, current))
6617 if(!isspace(ch)) break;
6618 f.Seek(-1, current);
6622 f.Seek(-1, current);
6624 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6626 lineNum = editBox.lineNumber + 1;
6627 charPos = editBox.charPos + 1;
6629 updatingCode = false;
6632 charPos = Min(charPos, l1.count + 1);
6634 FindParamsTree(ast, lineNum, charPos);
6636 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6637 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6639 ::functionType = null;
6640 ::instanceType = null;
6643 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6644 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6648 Window parent = paramsList.parent;
6650 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6653 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6654 // ( Dummy exp: always ends up with same memory)
6656 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6657 editBox.GetCaretPosition(paramsPosition);
6658 this.paramsPosition.y += editBox.GetCaretSize();
6661 FreeType(this.functionType);
6662 FreeType(this.instanceType);
6664 this.functionType = ::functionType;
6665 this.instanceType = ::instanceType;
6667 if(this.functionType) this.functionType.refCount++;
6668 if(this.instanceType) this.instanceType.refCount++;
6670 this.paramsID = ::paramsID;
6671 functionExp = paramsInsideExp;
6673 paramsList.master = this;
6675 paramsList.Create();
6677 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6678 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6680 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6682 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6686 paramsAbove = false;
6687 if(x + paramsList.size.w > parent.clientSize.w)
6689 x = parent.clientSize.w - paramsList.size.w;
6693 paramsList.position = { x, y };
6695 // Hack to keep caret shown
6698 editBox.GetCaretPosition(caret);
6699 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6702 this.paramsShown = true;
6704 else if((!::functionType && !::instanceType) || reposition)
6706 paramsList.Destroy(0);
6707 paramsShown = false;
6709 FreeType(this.functionType);
6710 FreeType(this.instanceType);
6711 this.functionType = null;
6712 this.instanceType = null;
6716 SetCurrentContext(globalContext);
6724 designer.visible = true;
6725 designer.Activate();
6731 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6733 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };