3 // *** Color Schemes ***
5 // *** The Old Color Scheme that was causing me auras and ophtalmic migraines -- Uncomment at your own risk! ***
7 FontResource panelFont { "Courier New", 10 };
8 FontResource codeFont { "Courier New", 10 };
9 Color selectionColor = Color { 10, 36, 106 };
10 Color selectionText = white;
11 Color viewsBackground = white;
12 Color viewsText = black;
13 Color outputBackground = white;
14 Color outputText = black;
15 Color projectViewBackground = white;
16 Color projectViewText = black;
17 Color codeEditorBG = white;
18 Color codeEditorFG = black;
19 Color marginColor = Color {230, 230, 230};
20 Color selectedMarginColor = Color {200, 200, 200};
21 Color lineNumbersColor = Color {60, 60, 60};
22 SyntaxColorScheme colorScheme
24 keywordColors = [ blue, blue ];
25 commentColor = dimGray;
26 charLiteralColor = crimson;
27 stringLiteralColor = crimson;
28 preprocessorColor = green;
33 // The new nice dark scheme -- so peaceful on my brain
35 FontResource panelFont { "Courier New", 10 };
36 FontResource codeFont { "Courier New", 10 };
38 FontResource panelFont { "Consolas", 10.5f };
39 FontResource codeFont { "Consolas", 10.5f };
41 Color selectionColor = lightYellow;
42 Color selectionText = Color { 30, 40, 50 };
43 Color viewsBackground = Color { 30, 40, 50 };
44 Color viewsText = lightGray;
45 Color outputBackground = black;
46 Color outputText = lime;
47 Color projectViewBackground = Color { 30, 40, 50 };
48 Color projectViewText = lightGray;
49 Color codeEditorBG = black;
50 Color codeEditorFG = ivory;
51 Color marginColor = Color {24, 24, 24};
52 Color selectedMarginColor = Color {64, 64, 64};
53 Color lineNumbersColor = Color {160, 160, 160};
54 SyntaxColorScheme colorScheme
56 keywordColors = [ skyBlue, skyBlue ];
57 commentColor = Color { 125, 125, 125 };
58 charLiteralColor = Color { 245, 50, 245 };
59 stringLiteralColor = Color { 245, 50, 245 };
60 preprocessorColor = { 120, 220, 140 };
61 numberColor = Color { 0, 192, 192 };
64 // *********************
70 // UNTIL IMPLEMENTED IN GRAMMAR
71 #define ACCESS_CLASSDATA(_class, baseClass) \
72 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
75 extern int __attribute__((__stdcall__)) __ecereDll_Load_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
76 extern int __attribute__((__stdcall__)) __ecereDll_Unload_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
79 static Array<FileFilter> fileFilters
81 { $"C/C++/eC Files (*.ec, *.eh, *.c, *.cpp, *.cc, *.cxx, *.h, *.hpp, *.hh, *.hxx)", "ec, eh, c, cpp, cc, cxx, h, hpp, hh, hxx" },
82 { $"Header Files for C/C++ (*.eh, *.h, *.hpp, *.hh, *.hxx)", "eh, h, hpp, hh, hxx" },
83 { $"C/C++/eC Source Files (*.ec, *.c, *.cpp, *.cc, *.cxx)", "ec, c, cpp, cc, cxx" },
84 { $"Text files (*.txt)", "txt" },
85 { $"All files", null }
88 static Array<FileType> fileTypes
90 { $"eC Source Code", "ec", whenNoneGiven },
91 { $"Text Files", "txt", never }
94 static char * iconNames[] =
96 "<:ecere>constructs/class.png",
97 "<:ecere>constructs/data.png",
98 "<:ecere>constructs/method.png",
99 "<:ecere>constructs/event.png",
100 "<:ecere>constructs/property.png",
101 "<:ecere>constructs/namespace.png",
102 "<:ecere>constructs/dataType.png",
103 "<:ecere>constructs/enumValue.png",
104 "<:ecere>constructs/dataPrivate.png",
105 "<:ecere>constructs/methodPrivate.png",
106 "<:ecere>constructs/propertyPrivate.png"
109 enum SheetType { methods, properties };
111 extern int __ecereVMethodID_class_OnEdit;
112 extern int __ecereVMethodID_class_OnDisplay;
113 extern int __ecereVMethodID_class_OnGetString;
114 extern int __ecereVMethodID_class_OnFree;
115 extern int __ecereVMethodID_class_OnCompare;
116 extern int __ecereVMethodID_class_OnCopy;
117 extern int __ecereVMethodID_class_OnSaveEdit;
118 extern int __ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad;
120 class EditFileDialog : FileDialog
124 if(!ide.projectView && ideSettings.ideFileDialogLocation)
125 currentDirectory = ideSettings.ideFileDialogLocation;
126 return FileDialog::OnCreate();
130 EditFileDialog codeEditorFileDialog
132 type = multiOpen, text = $"Open",
133 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType);
134 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
137 EditFileDialog codeEditorFormFileDialog
139 type = open, text = $"Open Project",
140 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType),
141 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
144 define OpenBracket = '{';
145 define CloseBracket = '}';
150 actionDeleteMethod = 2,
151 actionDetachMethod = 3,
152 actionAttachMethod = 4,
153 actionReattachMethod = 5
156 //extern StatusField pos, ovr, caps, num;
157 //extern Class thisClass;
163 bool parseError = false;
168 Expression ctxInsideExp;
169 Expression paramsInsideExp;
170 ClassFunction insideFunction;
178 /****************************************************************************
180 ****************************************************************************/
182 static void OutputString(File f, char * string)
185 for(c = 0; string[c]; c++)
187 if(string[c] == '\"')
189 else if(string[c] == '\\')
196 void OutputType(File f, Type type, bool outputName)
206 if(!type.isSigned) f.Printf("unsigned ");
210 if(!type.isSigned) f.Printf("unsigned ");
214 if(!type.isSigned) f.Printf("unsigned ");
218 if(!type.isSigned) f.Printf("unsigned ");
222 if(!type.isSigned) f.Printf("unsigned ");
232 // ADD CODE TO DECIDE WHETHER TO OUTPUT FULLY QUAlIFIED OR NOT:
233 f.Printf(type._class.shortName ? type._class.shortName : type._class.string);
242 OutputType(f, type.type, false);
245 OutputType(f, type.type, false);
264 if(type.kind == arrayType)
267 f.Printf("%d", type.arraySize);
273 void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
279 f.Seek(pos - *position, current);
281 // Try to delete spaces and \n before...
287 /*else if(ch == '\n')
289 // Look for // comments on the line before
290 EditBox editBox = f.editBox;
291 EditLine line = editBox.line;
298 for(c = 0; text[c]; c++)
307 if(text[c] == '/' && last == '/')
319 f.DeleteBytes(before);
324 void GetLocText(EditBox editBox, File f, int position, Location loc, char ** text, int * size, int pad, int linePad)
329 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
331 // Cut & Paste function
337 f.Seek(loc.start.pos - position, current);
339 x1 = editBox.charPos;
340 y1 = editBox.lineNumber;
341 f.Seek(loc.end.pos - loc.start.pos, current);
343 x2 = editBox.charPos;
344 y2 = editBox.lineNumber;
345 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
347 *size = editBox.SelSize();
348 *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
349 editBox.GetSel(*text, false);
352 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
353 f.Printf(""); // Make the stream point to where the editbox is
356 void Code_FixProperty(Property prop, Instance object)
358 Designer::FixProperty(prop, object);
361 bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
364 if(prop.dataTypeString && (!prop.IsSet || prop.IsSet(selected.instance)))
366 Class dataType = prop.dataTypeClass;
367 char string[1024] = "";
370 dataType = prop.dataTypeClass = eSystem_FindClass(test._class.module, prop.dataTypeString);
372 if(dataType && dataType._vTbl && dataType.type == structClass)
374 void * dataForm = new0 byte[dataType.structSize];
375 void * dataTest = new0 byte[dataType.structSize];
377 prop.Get(selected.instance, dataForm);
378 prop.Get(test, dataTest);
380 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
382 prop.Set(test, dataForm);
388 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
390 void * dataForm, * dataTest;
392 dataForm = (void *)prop.Get(selected.instance);
393 dataTest = (void *)prop.Get(test);
395 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
397 prop.Set(test, dataForm);
401 else if(dataType && dataType._vTbl)
403 DataValue dataForm, dataTest;
405 GetProperty(prop, selected.instance, &dataForm);
406 GetProperty(prop, test, &dataTest);
408 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
410 SetProperty(prop, test, dataForm);
412 // In case setting on test unset on real instance (e.g. isDefault)
413 if(strcmp(prop.name, "name"))
415 GetProperty(prop, selected.instance, &dataTest);
416 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
417 SetProperty(prop, selected.instance, dataForm);
426 bool Code_IsPropertyDisabled(ObjectInfo selected, char * name)
428 bool disabled = false;
429 if(selected.oClass == selected)
432 if(selected.classDefinition)
434 for(def = selected.classDefinition.definitions->first; def; def = def.next)
436 if(def.type == defaultPropertiesClassDef)
439 for(prop = def.defProperties->first; prop; prop = prop.next)
441 if(prop.identifiers && prop.identifiers->first)
443 Identifier id = prop.identifiers->first;
444 if(prop.variable && !strcmp(id.string, name))
456 else if(selected.instCode)
459 if(selected.instCode.members)
461 for(members = selected.instCode.members->first; members; members = members.next)
463 if(members.type == dataMembersInit && members.dataMembers)
466 for(prop = members.dataMembers->first; prop; prop = prop.next)
468 if(prop.identifiers && prop.identifiers->first)
470 Identifier id = prop.identifiers->first;
471 if(prop.variable && !strcmp(id.string, name))
486 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
491 method.dataType = ProcessTypeString(method.dataTypeString, false);
492 if(!method.dataType.thisClass && !isForm)
495 method.dataType.thisClass = selectedClass;
497 //result = MatchTypes(method.dataType, type, null, regClass, regClass, false);
498 result = MatchTypes(type, method.dataType, null, regClass, regClass, false, true, true, false);
500 method.dataType.thisClass = null;
504 bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo object)
506 bool confirmation = true;
507 Statement body = function.body;
508 // Check if it contains any code
509 if((!body.compound.declarations || !body.compound.declarations->count) && (!body.compound.statements || body.compound.statements->count <= 1))
511 Class moduleClass = eSystem_FindClass(object.instance._class.module, "Module");
512 Statement stmt = body.compound.statements ? body.compound.statements->first : null;
513 Type dataType = method.dataType;
514 Type returnType = dataType.returnType;
515 Expression exp = null;
518 method.dataType = ProcessTypeString(method.dataTypeString, false);
520 confirmation = false;
522 // Check if default function should be calling base class:
523 if(object.instance._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
525 if(returnType.kind != voidType)
527 if(!stmt || stmt.type != returnStmt || !stmt.expressions || stmt.expressions->count != 1)
531 exp = stmt.expressions->first;
532 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
534 if( (exp.type != identifierExp || strcmp(exp.identifier.string, "true")) &&
535 (exp.type != constantExp || strcmp(exp.constant, "1")))
540 if(exp.type != constantExp || strcmp(exp.constant, "0"))
555 if(returnType.kind != voidType)
557 if(stmt.type == returnStmt && stmt.expressions && stmt.expressions->count == 1)
558 exp = stmt.expressions->first;
560 else if(stmt.type == expressionStmt && stmt.expressions && stmt.expressions->count == 1)
561 exp = stmt.expressions->first;
564 if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
568 Identifier id = exp.call.exp.identifier;
569 Class base = object.instance._class;
570 if(!id._class || (id._class.name && !strcmp(id._class.name, base.name)) || strcmp(id.string, method.name))
574 Expression arg = exp.call.arguments ? exp.call.arguments->first : null;
575 if(!arg || arg.type != identifierExp || strcmp("this", arg.identifier.string))
581 for(param = dataType.params.first; param; param = param.next)
583 if(!arg || arg.type != identifierExp || strcmp(param.name, arg.identifier.string))
588 arg = arg ?arg.next : null;
595 return !confirmation;
598 class CodeEditor : Window
600 background = marginColor;
601 borderStyle = sizableDeep;
606 isActiveClient = true;
607 anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
610 // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
611 // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
613 SheetType sheetSelected;
618 Context globalContext { };
619 OldList excludedSymbols { offset = (uint)&((Symbol)0).left };
632 MethodAction methodAction;
634 ClassFunction function;
636 char methodName[1024];
640 bool membersListShown;
643 EditLine membersLine;
645 Type functionType, instanceType;
649 Point paramsPosition;
650 Expression functionExp;
653 BitmapResource icons[CodeObjectType];
655 FontResource boldFont { "Tahoma", 8.25f, bold = true, window = this };
656 FontResource normalFont { "Tahoma", 8.25f, window = this };
658 Module privateModule;
659 NameSpace globalData;
662 OpenedFileInfo openedFileInfo;
664 FontResource font { codeFont.faceName, codeFont.size };
665 saveDialog = codeEditorFileDialog;
667 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
669 void ProcessCaretMove(EditBox editBox, int line, int charPos)
672 ObjectInfo classItem;
674 // OnActivateClient is called after OnActivate
677 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
680 if(sheet.codeEditor != this) return;
684 for(classItem = classes.first; classItem; classItem = classItem.next)
686 ClassDefinition classDef = classItem.classDefinition;
687 if(classDef && classDef.loc.Inside(line, charPos))
694 for(object = classItem.instances.first; object; object = object.next)
698 if(object.instCode.loc.Inside(line, charPos))
703 sheet.SelectObject(object);
705 sheet.SelectObject(classItem);
710 //sheet.SelectObject(null);
714 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
718 expectingMove = false;
724 if(line-1 != membersLoc.start.line)
728 char * buffer = membersLine.text;
731 if(charPos - 1 < membersLoc.start.charPos)
733 else if(charPos - 1 > membersLoc.end.charPos)
735 char * buffer = membersLine.text;
736 //if(membersList.currentRow)
740 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
741 if(buffer[c] != ' ' && buffer[c] != '\t')
743 if(c < charPos && buffer[c])
750 membersList.Destroy(0);
751 membersListShown = false;
755 bool back = codeModified;
756 codeModified = false;
758 InvokeParameters(false, false, false);
759 /*if(membersListShown)
760 InvokeAutoComplete(false, 0, true);*/
767 watch(modifiedDocument)
769 ProjectView projectView = ide.projectView;
772 ProjectNode node = projectView.GetNodeFromWindow(this, null);
775 node.modified = modifiedDocument;
776 projectView.Update(null);
784 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
785 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
786 tabKey = true, smartHome = true;
787 tabSelection = true, maxLineSize = 65536, parent = this, hasHorzScroll = true, hasVertScroll = true;
788 selectionColor = selectionColor, selectionText = selectionText,
789 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
790 font = font, borderStyle = none;
791 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
793 bool OnMouseOver(int x, int y, Modifiers mods)
795 CodeEditor editor = (CodeEditor)master;
796 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
801 void NotifyCaretMove(EditBox editBox, int line, int charPos)
803 // Update Line Numbers
805 int oldLine = lastLine;
806 display.FontExtent(font.font, " ", 1, null, &spaceH);
808 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
812 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
817 if(ide.activeClient == this)
818 ProcessCaretMove(editBox, line, charPos);
820 openedFileInfo.CaretMove(line, charPos);
823 void NotifyOvrToggle(EditBox editBox, bool overwrite)
825 ide.ovr.color = overwrite ? black : Color { 128, 128, 128 };
828 void NotifyUpdate(EditBox editBox)
835 designer.modifiedDocument = true;
838 modifiedDocument = true;
841 bool NotifyUnsetModified(EditBox editBox)
843 modifiedDocument = false;
847 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
853 if(after.y != before.y)
855 ProjectView projectView = ide.projectView;
856 if(projectView && fileName)
859 // HOW WE MIGHT WANT TO DO IT:
860 char * text = before.line.text;
861 for(c = before.x-1; c>= 0; c--)
862 if(!isspace(text[c]))
864 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
866 // HOW VISUAL STUDIO DOES IT:
868 char * text = after.line.text;
869 for(c = after.line.count-1; c>= 0; c--)
870 if(!isspace(text[c]))
872 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
879 for(oClass = classes.first; oClass; oClass = oClass.next)
882 for(object = oClass.instances.first; object; object = object.next)
886 object.instCode.loc.start.AdjustAdd(before, after);
887 object.instCode.loc.end.AdjustAdd(before, after);
892 oClass.classDefinition.loc.start.AdjustAdd(before, after);
893 oClass.classDefinition.loc.end.AdjustAdd(before, after);
899 expectingMove = true;
903 if(before.y != after.y)
907 char * buffer = membersLine.text;
909 bool firstChar = true;
910 bool addedChar = false;
916 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
918 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
920 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
921 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
930 membersLoc.start.charPos++;
935 string[len++] = buffer[c];
939 row = membersList.currentRow;
940 if(row && row.selected)
944 membersLoc.start.charPos--;
952 row = membersList.FindSubString(string);
954 membersList.currentRow = row;
957 row = membersList.FindSubStringi(string);
959 membersList.currentRow = row;
960 membersList.currentRow.selected = false;
963 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
967 row = membersList.currentRow;
970 // Accept current string if hiding typing char
971 if(hide && row && row.selected)
973 char * string = row.string;
974 int len = strlen(string);
975 membersLoc.end.charPos -= after.x - before.x;
976 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
977 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
978 membersLine, membersLoc.end.line, membersLoc.end.charPos);
979 editBox.PutS(string);
980 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
982 after.x += membersLoc.start.charPos + len - before.x;
983 before.x = membersLoc.start.charPos + len;
988 membersList.Destroy(0);
989 membersListShown = false;
992 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
994 EditLine line = editBox.line;
995 char * text = line.text;
996 char ch = text[after.x-1];
997 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1001 // Can we call invoke auto complete here instead?
1011 // Force caret update already...
1012 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1013 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1015 editBox.GetCaretPosition(&caret);
1019 // Go back in the buffer until no space before
1021 codeModified = true;
1025 EditBoxStream f { editBox = editBox };
1029 if(text[after.x-1] == '>')
1035 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1039 if(!f.Seek(-1, current))
1042 if(!isspace(ch)) break;
1043 f.Seek(-1, current);
1045 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1047 line = editBox.lineNumber + 1;
1048 charPos = editBox.charPos + 1;
1052 exp = FindExpTree(ast, line, charPos);
1056 Type type = exp.expType;
1058 if(type && text[after.x-1] != '.')
1060 if(type.kind == TypePointer || type.kind == TypeArray)
1066 membersList.Clear();
1069 if(membersList.rowCount)
1071 membersList.Sort(null, 1);
1072 membersList.master = this;
1074 caret.y += editBox.GetCaretSize();
1077 membersList.Create();
1080 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1081 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1082 Window parent = membersList.parent;
1084 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1086 y -= editBox.GetCaretSize() + membersList.GetHeight();
1087 membersAbove = true;
1090 membersAbove = false;
1092 membersList.position = { x, y };
1096 membersLoc.start.line = line - 1;
1097 membersLoc.start.charPos = oldCharPos;
1098 membersLoc.end = membersLoc.start;
1099 membersListShown = true;
1104 SetCurrentContext(globalContext);
1106 codeModified = true;
1107 skipModified = true;
1108 if(text[after.x-1] == ':')
1109 InvokeAutoComplete(false, 0, false);
1110 else if(text[after.x-1] == '.')
1111 InvokeAutoComplete(false, 1, false);
1112 else if(text[after.x-1] == '>')
1113 InvokeAutoComplete(false, 2, false);
1114 skipModified = false;
1116 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1118 codeModified = true;
1119 skipModified = true;
1121 if(InvokeAutoComplete(true, 0, false))
1123 if(ch == '(' || ch == OpenBracket)
1124 InvokeParameters(true, true, false);
1126 InvokeParameters(this.functionType ? false : true, false, false);
1129 // InvokeAutoComplete(true, 0, false);
1130 skipModified = false;
1132 else if(ch == ')' || ch == '}' || ch == ';')
1134 codeModified = true;
1135 skipModified = true;
1137 InvokeParameters(false, true, false);
1138 skipModified = false;
1142 bool back = codeModified;
1143 codeModified = false;
1145 InvokeParameters(false, false, true);
1146 if(membersListShown)
1147 InvokeAutoComplete(false, 0, true);
1148 codeModified = back;
1153 bool back = codeModified;
1154 codeModified = false;
1157 InvokeParameters(false, false, true);
1158 /*if(membersListShown)
1159 InvokeAutoComplete(false, 0, true);*/
1161 codeModified = back;
1168 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1174 if(after.y != before.y)
1176 ProjectView projectView = ide.projectView;
1177 if(projectView && fileName)
1179 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1184 for(oClass = classes.first; oClass; oClass = oClass.next)
1188 for(object = oClass.instances.first; object; object = object.next)
1192 loc = &object.instCode.loc;
1194 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1195 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1197 object.instCode = null;
1201 loc->start.AdjustDelete(before, after);
1202 loc->end.AdjustDelete(before, after);
1206 if(oClass.classDefinition)
1208 loc = &oClass.classDefinition.loc;
1209 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1210 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1212 oClass.classDefinition = null;
1216 loc->start.AdjustDelete(before, after);
1217 loc->end.AdjustDelete(before, after);
1222 if(membersListShown)
1225 if(pasteOperation || before.y != after.y)
1229 char * buffer = membersLine.text;
1231 bool firstChar = true;
1235 if(before.x >= membersLoc.start.charPos)
1237 for(c = membersLoc.start.charPos; c<before.x; c++)
1239 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1240 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1245 if(!isSpace) firstChar = false;
1248 string[len++] = buffer[c];
1253 // If deleting spaces before...
1254 for(c = before.x; c<membersLoc.start.charPos; c++)
1256 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1264 membersLoc.start.charPos = before.x;
1267 if(membersLoc.end.charPos >= after.x)
1269 for(c = after.x; c<membersLoc.end.charPos; c++)
1271 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1272 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1277 if(!isSpace) firstChar = false;
1280 string[len++] = buffer[c];
1288 membersLoc.end.charPos -= after.x - before.x;
1292 row = membersList.FindSubString(string);
1295 row = membersList.FindSubStringi(string);
1297 membersList.currentRow = row;
1298 membersList.currentRow.selected = false;
1301 membersList.currentRow = row;
1303 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1308 membersList.Destroy(0);
1309 membersListShown = false;
1315 InvokeParameters(false, false);
1323 bool NotifyDropped(EditBox editBox, int x, int y)
1325 char * controlClass = toolBox.controlClass;
1326 if(controlClass && controlClass[0])
1330 ObjectInfo classObject;
1332 //editBox.NotifyCaretMove(this, editBox, y, x);
1333 editBox.GoToLineNum(y);
1334 editBox.GoToPosition(editBox.line, y, x);
1336 classObject = selected ? selected.oClass : null;
1338 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1339 selected = classObject.instances.last;
1342 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1345 AddObject(control, &object);
1347 designer.CreateObject(control, object, false, classObject.instance);
1348 // designer.PostCreateObject(control, object, false, classObject.instance);
1349 designer.DroppedObject(control, object, false, classObject.instance);
1351 sheet.AddObject(object, object.name, typeData /* className*/, true);
1354 //codeModified = true;
1361 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1363 if(key == Key { space, ctrl = true })
1365 membersList.Destroy(0);
1366 membersListShown = false;
1367 InvokeAutoComplete(false, 0, false);
1370 else if(key == Key { space, ctrl = true, shift = true })
1371 InvokeParameters(false, true, false);
1372 else if(key == escape)
1373 ide.RepositionWindows(true);
1374 else if(key == ctrlF7)
1378 ProjectNode node = ide.projectView.GetNodeFromWindow(this, null);
1382 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1383 $"It can't be compiled.");
1384 MessageBox { type = ok, parent = ide, master = ide, text = $"File not in project error", contents = s }.Modal();
1393 bool OnKeyDown(Key key, unichar ch)
1395 CodeEditor editor = (CodeEditor)master;
1396 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1398 if(editor.membersListShown)
1400 editor.membersList.Destroy(0);
1401 editor.membersListShown = false;
1404 if(editor.paramsShown)
1406 editor.paramsList.Destroy(0);
1407 editor.paramsShown = false;
1408 FreeType(editor.functionType);
1409 FreeType(editor.instanceType);
1411 editor.functionType = null;
1412 editor.instanceType = null;
1413 editor.paramsID = -1;
1417 return EditBox::OnKeyDown(key, ch);
1420 void OnVScroll(ScrollBarAction action, int position, Key key)
1422 if(anchor.left.distance)
1424 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1427 EditBox::OnVScroll(action, position, key);
1429 CodeEditor ce = (CodeEditor)parent;
1430 if(ce.openedFileInfo)
1431 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1435 void OnHScroll(ScrollBarAction action, int position, Key key)
1437 EditBox::OnHScroll(action, position, key);
1439 CodeEditor ce = (CodeEditor)parent;
1440 if(ce.openedFileInfo)
1441 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1448 fullRowSelect = false,
1451 borderStyle = bevel;
1452 // size = { 200, 400 };
1454 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1456 DataRow row = listBox.currentRow;
1459 char * string = row.string;
1461 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1463 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1464 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1465 editBox.PutS(string);
1468 membersListShown = false;
1473 bool OnKeyDown(Key key, unichar ch)
1475 CodeEditor editor = (CodeEditor) master;
1476 if(key == escape || key == leftAlt || key == rightAlt ||
1477 (key.ctrl && key.code != left && key.code != right &&
1478 key.code != leftShift && key.code != rightShift && key.code != space))
1480 if(editor.paramsShown)
1481 editor.paramsList.Destroy(0);
1482 if(editor.membersListShown)
1483 editor.membersList.Destroy(0);
1485 editor.paramsShown = false;
1486 FreeType(editor.functionType);
1487 FreeType(editor.instanceType);
1489 editor.functionType = null;
1490 editor.instanceType = null;
1491 editor.paramsID = -1;
1493 editor.membersListShown = false;
1497 return editor.editBox.OnKeyDown(key, ch);
1501 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1503 CodeEditor editor = (CodeEditor)master;
1507 editor.membersListShown = false;
1509 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1512 bool OnKeyHit(Key key, unichar ch)
1514 CodeEditor editor = (CodeEditor) master;
1518 case enter: case tab:
1520 DataRow row = currentRow;
1521 if(row && row.selected)
1523 char * string = row.string;
1525 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1526 editor.editBox.Delete(
1527 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1528 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1529 editor.editBox.PutS(string);
1532 editor.membersListShown = false;
1535 editor.editBox.OnKeyHit(key, ch);
1545 return ListBox::OnKeyHit(key, ch);
1551 // If before . or after
1552 //listBox.Destroy(true);
1553 result = editor.editBox.OnKeyHit(key, ch);
1568 clickThrough = true,
1570 borderStyle = contour,
1572 background = { 255,255,225 },
1574 OnKeyDown = membersList.OnKeyDown;
1576 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1578 CodeEditor editor = (CodeEditor)master;
1582 editor.membersListShown = false;
1584 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1587 bool OnKeyHit(Key key, unichar ch)
1589 CodeEditor editor = (CodeEditor)master;
1591 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1594 bool result = true; editor.editBox.OnKeyHit(key, ch);
1595 return (!created) ? false : result;
1602 void OnRedraw(Surface surface)
1604 CodeEditor editor = (CodeEditor) master;
1605 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1607 Type methodType = null;
1611 int functionW, nameW = 0;
1613 int spaceW, spaceH, commaW, commaWB, parW;
1615 int maxW = 0, lineW = 0;
1621 Font font = editor.normalFont.font;
1622 Font boldFont = editor.boldFont.font;
1623 Display display = this.display;
1625 if(!type) { return; };
1627 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1629 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1630 display.FontExtent(font, ", ", 2, &commaW, null);
1631 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1632 display.FontExtent(font, ")", 1, &parW, null);
1635 if(editor.functionType)
1637 PrintType(type.returnType, string, true, true);
1638 display.FontExtent(font, string, strlen(string), &functionW, null);
1640 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1641 totalW = nameW + functionW + 2 * parW;
1645 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1646 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1647 if(instanceName && type.kind != functionType)
1648 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1649 totalW = functionW + nameW;
1650 surface.TextFont(boldFont);
1653 surface.WriteText(x, y, string, strlen(string));
1654 x += functionW + spaceW;
1656 if(editor.functionType)
1659 surface.WriteText(x, y, type.name, strlen(type.name));
1661 surface.WriteText(x, y, "(", 1);
1664 if(methodType && !methodType.staticMethod)
1668 if(id == editor.paramsID)
1669 surface.TextFont(boldFont);
1671 if(methodType.methodClass)
1672 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1676 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1677 width += ((id == editor.paramsID) ? commaWB : commaW);
1682 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1687 x = 2 + nameW + spaceW + functionW + parW;
1691 if(methodType.methodClass)
1692 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1695 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1697 surface.WriteText(x, y, ",", 1);
1698 x += ((id == editor.paramsID) ? commaWB : commaW);
1706 if(id == editor.paramsID)
1707 surface.TextFont(font);
1711 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1713 for(param = type.params.first; param; param = param.next)
1715 char paramString[1024];
1718 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1719 surface.TextFont(boldFont);
1722 PrintType(param, paramString, true, true);
1723 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1725 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1730 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1735 x = 2 + nameW + spaceW + functionW + parW;
1739 surface.WriteText(x, y, paramString, strlen(paramString));
1743 surface.WriteText(x, y, ",", 1);
1744 x += ((id == editor.paramsID) ? commaWB : commaW);
1752 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1753 surface.TextFont(font);
1758 surface.WriteText(x, y, ")", 1);
1760 else if(instanceName && type.kind != functionType)
1762 surface.WriteText(x, y, instanceName, strlen(instanceName));
1766 bool OnResizing(int * w, int * h)
1768 CodeEditor editor = (CodeEditor) master;
1769 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1771 Type methodType = null;
1775 int functionW = 0, nameW = 0;
1777 int spaceW, spaceH, commaW, commaWB, parW;
1779 int maxW = 0, lineW = 0;
1784 Font font = editor.normalFont.font;
1785 Font boldFont = editor.boldFont.font;
1786 Display display = this.display;
1788 if(type.kind == TypeKind::methodType)
1791 ProcessMethodType(type.method);
1792 type = type.method.dataType;
1795 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1796 display.FontExtent(font, ", ", 2, &commaW, null);
1797 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1798 display.FontExtent(font, ")", 1, &parW, null);
1801 if(editor.functionType && type)
1803 PrintType(type.returnType, string, true, true);
1804 display.FontExtent(font, string, strlen(string), &functionW, null);
1806 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1807 totalW = nameW + spaceW + functionW + 2 * parW;
1811 PrintType(type, string, false, true); // /*true);
1812 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1813 if(instanceName && type.kind != functionType)
1814 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1815 totalW = functionW + nameW + spaceW;
1818 if(editor.functionType)
1824 if(methodType.methodClass)
1825 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1826 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1827 width += ((id == editor.paramsID) ? commaWB : commaW);
1832 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1845 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1847 for(param = type.params.first; param; param = param.next)
1849 char paramString[1024];
1853 PrintType(param, paramString, true, true);
1854 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1856 width += ((id == editor.paramsID) ? commaWB : commaW);
1861 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1878 *w = realW + totalW + 4;
1884 Menu fileMenu { menu, $"File", f }; // MenuPlacement?
1885 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1886 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1888 Menu debugMenu { menu, $"Debug", d }; // MenuPlacement?
1889 MenuItem debugRunToCursor
1891 debugMenu, $"Run To Cursor", c, Key { f10, ctrl = true };
1892 bool NotifySelect(MenuItem selection, Modifiers mods)
1894 ProjectView projectView = ide.projectView;
1895 if(!projectView.buildInProgress)
1897 int line = editBox.lineNumber + 1;
1899 ide.debugger.RunToCursor(fileName, line, false);
1904 MenuItem debugSkipRunToCursor
1906 debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true };
1907 bool NotifySelect(MenuItem selection, Modifiers mods)
1909 ProjectView projectView = ide.projectView;
1910 int line = editBox.lineNumber + 1;
1912 ide.debugger.RunToCursor(fileName, line, true);
1916 MenuDivider { debugMenu };
1917 MenuItem debugToggleBreakpoint
1919 debugMenu, $"Toggle Breakpoint", t, f9;
1920 bool NotifySelect(MenuItem selection, Modifiers mods)
1922 ProjectView projectView = ide.projectView;
1923 if(projectView && fileName)
1925 int line = editBox.lineNumber + 1;
1926 char name[MAX_LOCATION];
1928 // TOFIX: This only looks at the filename...
1929 GetLastDirectory(fileName, name);
1930 if(ide && ide.workspace)
1932 for(p : ide.workspace.projects)
1934 if(p.topNode.Find(name, false))
1942 for(p : ide.workspace.projects)
1944 if(eString_PathInsideOf(fileName, p.topNode.path))
1952 ide.debugger.ToggleBreakpoint(fileName, line, prj);
1962 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1966 designer.parent = parent;
1969 toolBox = ((IDE)master).toolBox;
1971 // Debugger bug here: value of toolBox appears as 0
1973 sheet = ((IDE)master).sheet;
1978 bool OnClose(bool parentClosing)
1982 if(ide.workspace && fileName)
1983 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
1985 if(inUseDebug && !debugClosing)
1987 debugClosing = true;
1989 if(CloseConfirmation(false))
1992 OnFileModified({ modified = true }, null);
1994 debugClosing = false;
1997 if(designer && !designer.closing)
1999 if(designer.visible)
2006 //Window formEditor = designer;
2007 //formEditor.Destroy(0);
2014 void OnDestroy(void)
2016 ObjectInfo oClass, next;
2017 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2019 FreeType(this.functionType);
2020 FreeType(this.instanceType);
2025 designer.codeEditor = null;
2026 designer.Destroy(0);
2030 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2032 ObjectInfo object, next;
2034 for(object = oClass.instances.first; object; object = next)
2039 Designer::DestroyObject(object.instance);
2040 delete object.instance;
2042 sheet.DeleteObject(object);
2044 oClass.instances.Delete(object);
2048 Designer::DestroyObject(oClass.instance);
2049 delete oClass.instance;
2051 sheet.DeleteObject(oClass);
2053 classes.Delete(oClass);
2056 if(windowClass && windowClass.data)
2057 UnapplySkin(windowClass);
2061 if(sheet.codeEditor == this)
2063 sheet.codeEditor = null;
2064 toolBox.codeEditor = null;
2070 ProjectView projectView = ide.projectView;
2073 ProjectNode node = projectView.GetNodeFromWindow(this, null);
2074 if(node && node.modified)
2076 node.modified = false;
2077 projectView.Update(null);
2083 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2085 // 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
2087 if(directActivation)
2088 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2090 if(active && directActivation)
2093 openedFileInfo.Activate();
2097 Location * loc = null;
2098 UpdateFormCode(); // To ensure update when modifying properties...
2100 // Got to the right spot in code so we don't lose our form selection...
2103 if(selected.instCode)
2104 loc = &selected.instCode.loc;
2105 else if(selected.classDefinition)
2106 loc = &selected.classDefinition.loc;
2108 line = editBox.lineNumber + 1;
2109 charPos = editBox.charPos + 1;
2114 if(selected && !loc->Inside(line, charPos))
2116 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2117 line = editBox.lineNumber + 1;
2118 charPos = editBox.charPos + 1;
2120 else if(selected && selected.classDefinition)
2123 for(object = selected.instances.first; object; object = object.next)
2127 if(object.instCode.loc.Inside(line, charPos))
2133 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2134 line = editBox.lineNumber + 1;
2135 charPos = editBox.charPos + 1;
2140 ProcessCaretMove(editBox, line, charPos);
2146 bool OnSaveFile(char * fileName)
2153 f = FileOpen(fileName, write);
2156 if(!ide.projectView)
2157 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2161 this.fileName = fileName; // Put this here because the form designer will check for it...
2162 designer.fileName = fileName;
2163 designer.modifiedDocument = false;
2165 editBox.Save(f, false);
2166 modifiedDocument = false;
2174 bool OnFileModified(FileChange fileChange, char * param)
2176 bool reload = false;
2177 if(visible == false && inUseDebug == true)
2183 sprintf(message, $"The document %s was modified by another application.\n"
2184 "Would you like to reload it and lose your changes?", fileName);
2185 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2186 contents = message }.Modal() == yes)
2192 File f = FileOpen(fileName, read);
2195 int lineNumber, charPos, len;
2198 updatingCode = true;
2199 lineNumber = editBox.lineNumber;
2200 charPos = editBox.charPos;
2201 scroll = editBox.scroll;
2204 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2205 len = strlen(editBox.line.text);
2206 editBox.GoToLineNum(lineNumber);
2207 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2208 editBox.scroll = scroll;
2209 updatingCode = false;
2211 codeModified = true;
2215 designer.modifiedDocument = false;
2217 modifiedDocument = false;
2225 void OnRedraw(Surface surface)
2228 surface.SetBackground(marginColor);
2229 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2230 if(ideSettings.showLineNumbers)
2232 int currentLineNumber;
2237 surface.textOpacity = false;
2238 surface.font = font.font;
2239 surface.TextExtent(" ", 1, null, &spaceH);
2240 currentLineNumber = editBox.scroll.y / spaceH + 1;
2242 surface.SetForeground(lineNumbersColor);
2243 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2245 // Highlight current line
2246 if(editBox.lineNumber == currentLineNumber - 1)
2248 surface.SetBackground(selectedMarginColor);
2249 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2250 surface.SetBackground(marginColor);
2252 sprintf(lineText,"%5u ", currentLineNumber % 100000);
2253 if(currentLineNumber <= editBox.numLines)
2254 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,6);
2256 currentLineNumber++;
2260 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2262 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2263 int lineCursor, lineTopFrame, breakpointLines[128];
2264 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2265 Debugger debugger = ide.debugger;
2266 BitmapResource bmpRes;
2268 boxH = clientSize.h;
2269 scrollY = editBox.scroll.y;
2270 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2272 bpOnCursor = bpOnTopFrame = false;
2273 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2276 for(i = 0; i < count; i++)
2278 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2280 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2281 if(breakpointLines[i] == lineCursor)
2283 if(breakpointLines[i] == lineTopFrame)
2284 bpOnTopFrame = true;
2287 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2289 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2292 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2293 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2294 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2296 if(editBox.anchor.left.distance)
2298 if(editBox.horzScroll && editBox.horzScroll.visible)
2300 surface.SetBackground(control);
2301 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2306 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2311 lineY = (line - 1) * lineH;
2312 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2314 Bitmap bitmap = resource.bitmap;
2316 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2323 char ext[MAX_EXTENSION];
2324 char * fileName = property::fileName;
2326 if(SearchString(fileName, 0, "Makefile", false, true))
2327 editBox.useTab = true;
2328 designer.fileName = fileName;
2332 GetExtension(fileName, ext);
2333 if(!strcmpi(ext, "ec"))
2335 codeModified = true;
2339 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"))
2340 editBox.syntaxHighlighting = true;
2342 editBox.syntaxHighlighting = false;
2345 display.FontExtent(font.font, " ", 1, &spaceW, null);
2346 editBox.anchor = Anchor
2348 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2349 right = 0, top = 0, bottom = 0
2358 display.FontExtent(font.font, " ", 1, &spaceW, null);
2359 editBox.anchor = Anchor
2361 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2362 right = 0, top = 0, bottom = 0
2367 bool LoadFile(char * filePath)
2369 File f = FileOpen(filePath, read);
2372 // Added this here...
2373 fileName = filePath;
2374 updatingCode = true;
2376 updatingCode = false;
2385 void DebugMenusDisabled()
2387 bool debugMenusDisabled = ide.GetDebugMenusDisabled();
2388 debugRunToCursor.disabled = debugMenusDisabled;
2389 debugSkipRunToCursor.disabled = debugMenusDisabled;
2390 debugToggleBreakpoint.disabled = debugMenusDisabled;
2396 ProjectView projectView = ide.projectView;
2399 designer.fileName = fileName;
2405 sprintf(title, $"Untitled %d", documentID);
2406 // designer.fileName = CopyString(title);
2407 designer.fileName = title;
2410 DebugMenusDisabled();
2412 for(c = 0; c < CodeObjectType::enumSize; c++)
2413 icons[c] = BitmapResource { iconNames[c], window = this };
2415 codeModified = true;
2427 selected.modified = true;
2428 selected.oClass.modified = true;
2430 designer.modifiedDocument = true;
2431 modifiedDocument = true;
2432 formModified = true;
2435 /****************************************************************************
2437 ****************************************************************************/
2440 this.defines.Free(FreeModuleDefine);
2441 this.imports.Free(FreeModuleImport);
2448 FreeExcludedSymbols(this.excludedSymbols);
2449 FreeContext(this.globalContext);
2451 FreeGlobalData(&this.globalData);
2453 if(GetGlobalContext() == globalContext)
2455 SetGlobalData(null);
2456 SetGlobalContext(null);
2457 SetExcludedSymbols(null);
2458 SetTopContext(null);
2459 SetCurrentContext(null);
2462 SetPrivateModule(null);
2465 if(this.privateModule)
2467 FreeTypeData(this.privateModule);
2468 delete this.privateModule;
2469 this.privateModule = null;
2475 static bool reentrant = false;
2480 char * selectedClassName = null, * selectedName = null;
2481 int selectedPos = 0;
2482 Designer backDesigner;
2483 char oldWorkDir[MAX_LOCATION];
2484 char mainModuleName[MAX_FILENAME] = "";
2486 ImportedModule module;
2487 char extension[MAX_EXTENSION];
2489 Time parseCodeStart = GetTime();
2490 Time startTime, startFindClass;
2492 findClassTotalTime = 0;
2493 checkTypeTotalTime = 0;
2494 externalImportTotalTime = 0;
2495 findClassIgnoreNSTotalTime = 0;
2496 findSymbolTotalTime = 0;
2497 //ResetClassFindTime();
2501 // 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)
2502 if(reentrant) return;
2509 selectedClassName = CopyString(oClass.name);
2510 if(selected != oClass)
2512 ObjectInfo object = this.selected;
2513 selectedName = CopyString(object.name);
2517 for(check = this.oClass.instances.first; check; check = check.next)
2529 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2531 defines.Free(FreeModuleDefine);
2532 imports.Free(FreeModuleImport);
2534 SetGlobalData(&globalData);
2535 SetGlobalContext(globalContext);
2536 SetExcludedSymbols(&excludedSymbols);
2537 SetTopContext(globalContext);
2538 SetCurrentContext(globalContext);
2539 SetDefines(&defines);
2540 SetImports(&imports);
2541 SetCurrentNameSpace(null);
2544 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2545 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2546 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2547 "/I T:\\ecere\\include /E %s", argv[1]);
2551 ChangeWorkingDir("e:\\ec");
2552 sprintf(command, "gcc -x c -E -");
2553 fileInput = DualPipeOpen({ output = true, input = true }, command);
2554 SetFileInput(fileInput);
2559 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2561 fileInput.Write(buffer, 1, count);
2566 fileInput.CloseOutput();
2570 // TOCHECK: COULDN'T WE CALL FreeParser here?
2572 this.functionType = null;
2573 this.instanceType = null;
2576 sheet.SelectObject(null);
2582 // We don't want the designer to be notified of selection when deleting rows...
2583 backDesigner = designer;
2588 ObjectInfo _class, next;
2590 for(_class = classes.first; _class; _class = next)
2596 for(;object = _class.instances.first;)
2600 Designer::DestroyObject(object.instance);
2601 delete object.instance;
2603 sheet.DeleteObject(object);
2605 _class.instances.Delete(object);
2609 Designer::DestroyObject(_class.instance);
2610 delete _class.instance;
2612 sheet.DeleteObject(_class);
2614 classes.Delete(_class);
2620 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2621 if(windowClass && windowClass.data)
2622 UnapplySkin(windowClass);
2625 designer = backDesigner;
2628 fileInput = editFile = EditBoxStream { editBox = editBox };
2629 SetFileInput(fileInput);
2638 FreeContext(this.globalContext);
2639 FreeExcludedSymbols(this.excludedSymbols);
2642 FreeGlobalData(&this.globalData);
2644 if(this.privateModule)
2646 FreeTypeData(this.privateModule);
2647 delete this.privateModule;
2651 startTime = GetTime();
2652 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2654 printf("classes.count: %d\n", globalContext.classes.count);
2657 this.privateModule = __ecere_COM_Initialize(false, 1, null);
2659 SetPrivateModule(privateModule);
2662 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2663 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2664 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2665 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2666 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2669 fileName = this.fileName;
2671 if(ide.workspace && ide.workspace.projects && fileName)
2673 for(p : ide.workspace.projects)
2675 char path[MAX_LOCATION];
2677 MakePathRelative(fileName, p.topNode.path, path);
2678 MakeSlashPath(path);
2680 pn = p.topNode.FindWithPath(path, false);
2689 project = ide.project;
2691 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2693 ChangeWorkingDir(project.topNode.path);
2695 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2697 GetLastDirectory(fileName, mainModuleName);
2698 GetExtension(mainModuleName, extension);
2700 SetBuildingEcereCom(false);
2701 SetBuildingEcereComModule(false);
2703 // TODO: Get symbolsDir from project settings instead...
2706 DirExpression objDir = project.objDir;
2707 SetSymbolsDir(objDir.dir);
2709 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2710 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2714 switch(GetRuntimePlatform())
2716 case win32: SetSymbolsDir("obj/debug.win32"); break;
2717 case tux: SetSymbolsDir("obj/debug.linux"); break;
2718 case apple: SetSymbolsDir("obj/debug.apple"); break;
2720 SetIncludeDirs(null);
2721 SetSysIncludeDirs(null);
2725 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2727 // TODO FIX for configless project
2728 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2730 for(item : ide.project.config.options.preprocessorDefinitions)
2732 if(!strcmp(item, "BUILDING_ECERE_COM"))
2734 SetBuildingEcereCom(true);
2741 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2742 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2743 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2744 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2745 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2746 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2747 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2748 strcmpi(mainModuleName, "Mutex.ec")))
2750 SetBuildingEcereComModule(true);
2753 // Predeclare all classes
2755 char symFile[MAX_FILENAME];
2756 char symLocation[MAX_LOCATION];
2757 ImportedModule module, next;
2759 GetLastDirectory(fileName, symFile);
2760 ChangeExtension(symFile, "sym", symFile);
2762 strcpy(symLocation, GetSymbolsDir());
2763 PathCat(symLocation, symFile);
2765 // if(!GetEcereImported() && !GetBuildingEcereCom())
2766 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2769 startTime = GetTime();
2771 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2773 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2778 startTime = GetTime();
2780 // LoadSymbols(symLocation, normalImport, true);
2781 LoadSymbols(symLocation, preDeclImport, false);
2783 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2786 for(module = defines.first; module; module = next)
2789 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2792 defines.Delete(module);
2797 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2798 SetDefaultDeclMode(privateAccess);
2800 SetDefaultDeclMode(defaultAccess);
2802 StripExtension(mainModuleName);
2803 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2804 defines.AddName(module);
2812 startTime = GetTime();
2813 startFindClass = checkTypeTotalTime;
2817 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2819 CheckDataRedefinitions();
2822 SetIncludeDirs(null);
2823 SetSysIncludeDirs(null);
2834 startTime = GetTime();
2836 PrePreProcessClassDefinitions();
2837 ComputeModuleClasses(privateModule);
2838 PreProcessClassDefinitions();
2839 ProcessClassDefinitions();
2841 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2842 startTime = GetTime();
2847 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2848 startTime = GetTime();
2850 ProcessInstantiations();
2852 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2855 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2857 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2858 if(!windowClass || windowClass.internalDecl)
2861 startTime = GetTime();
2863 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2864 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2865 eModule_Load(this.privateModule, "ecere", privateAccess);
2867 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2870 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2872 if(windowClass && windowClass.data)
2873 ApplySkin(windowClass, app.currentSkin.name, null);
2877 startTime = GetTime();
2879 for(external = ast->first; external; external = external.next)
2881 if(external.type == classExternal)
2883 ClassDefinition _class = external._class;
2884 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2886 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2889 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2891 Instance instance = eInstance_New(regClass);
2892 ObjectInfo classObject
2894 name = CopyString(_class._class.name);
2895 instance = instance;
2896 classDefinition = _class;
2897 oClass = classObject;
2900 classes.Add(classObject);
2904 // Moved this at bottom so that the file dialog doesn't show up in eCom
2905 designer.CreateObject(instance, classObject, true, null);
2906 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
2908 if(_class.definitions)
2912 for(def = _class.definitions->first; def; def = def.next)
2916 case defaultPropertiesClassDef:
2919 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
2921 Identifier id = propDef.identifiers->first;
2924 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
2927 Class propertyClass = prop.dataTypeClass;
2929 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
2930 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
2932 FreeType(propDef.initializer.exp.destType);
2933 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
2934 ProcessExpressionType(propDef.initializer.exp);
2936 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
2938 Expression computed = CopyExpression(propDef.initializer.exp);
2939 ComputeExpression(computed);
2941 if(computed.isConstant && computed.type == instanceExp && !id.next)
2945 if(computed.instance._class && computed.instance._class.symbol &&
2946 computed.instance._class.symbol.registered &&
2947 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
2949 prop.Set(instance, computed.instance.data);
2951 // This was saved in the control and shouldn't be freed by FreeExpression...
2952 if(propertyClass.type == normalClass)
2953 computed.instance.data = null;
2957 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
2958 else if(computed.type == stringExp)
2961 ReadString(temp, computed.string);
2962 prop.Set(instance, temp);
2965 propDef.variable = true;
2967 FreeExpression(computed);
2971 Expression computed = CopyExpression(propDef.initializer.exp);
2972 ComputeExpression(computed);
2973 if(computed.isConstant)
2975 //if(computed.type == memberExp) computed = computed.member.exp;
2977 if(computed.type == constantExp)
2979 Operand value = GetOperand(computed);
2980 DataValue valueData;
2981 valueData.i64 = value.i64;
2982 SetProperty(prop, instance, valueData);
2984 else if(computed.type == stringExp)
2987 ReadString(temp, computed.string);
2988 prop.Set(instance, temp);
2992 propDef.variable = true;
2994 FreeExpression(computed);
2998 propDef.variable = true;
3002 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3003 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3004 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3007 // Maintain a list in FunctionDefinition of who is attached to it
3008 for(def = _class.definitions->first; def; def = def.next)
3010 if(def.type == functionClassDef)
3012 ClassFunction function = def.function;
3013 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3015 function.attached.Add(OldLink { data = method });
3025 case declarationClassDef:
3027 Declaration decl = def.decl;
3030 case instDeclaration:
3032 Instantiation inst = decl.inst;
3033 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3034 if(instClass && eClass_GetDesigner(instClass))
3036 Instance control = eInstance_New(instClass);
3041 oClass = classObject;
3045 classObject.instances.Add(object);
3047 // TOCHECK: Why is this needed now?
3048 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3049 def.object = object;
3051 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3053 designer.CreateObject(control, object, false, classObject.instance);
3054 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3064 // Second pass, process instantiation members
3066 for(def = _class.definitions->first; def; def = def.next)
3070 case declarationClassDef:
3072 Declaration decl = def.decl;
3075 case instDeclaration:
3077 Instantiation inst = decl.inst;
3078 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3079 if(instClass && eClass_GetDesigner(instClass))
3082 object = object ? object.next : classObject.instances.first;
3083 control = object.instance;
3087 MembersInit members;
3088 for(members = inst.members->first; members; members = members.next)
3090 switch(members.type)
3092 case dataMembersInit:
3094 if(members.dataMembers)
3097 DataMember curMember = null;
3098 Class curClass = null;
3099 DataMember subMemberStack[256];
3100 int subMemberStackPos = 0;
3102 for(member = members.dataMembers->first; member; member = member.next)
3105 Identifier ident = member.identifiers ? member.identifiers->first : null;
3108 DataMember _subMemberStack[256];
3109 int _subMemberStackPos = 0;
3110 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3114 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3116 if(thisMember && thisMember.memberAccess == publicAccess)
3118 curMember = thisMember;
3119 curClass = curMember._class;
3120 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
3121 subMemberStackPos = _subMemberStackPos;
3127 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3128 if(curMember) found = true;
3130 if(found && curMember.isProperty)
3132 Property prop = (Property) curMember;
3133 Class propertyClass = prop.dataTypeClass;
3135 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3137 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3139 FreeType(member.initializer.exp.destType);
3140 member.initializer.exp.destType = MkClassType(propertyClass.name);
3143 ProcessExpressionType(member.initializer.exp);
3145 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3147 Expression computed;
3149 /*char debugExpString[4096];
3150 debugExpString[0] = '\0';
3151 PrintExpression(member.initializer.exp, debugExpString);*/
3153 computed = CopyExpression(member.initializer.exp);
3156 ComputeExpression(computed);
3158 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3160 if(computed.instance.data)
3162 if(computed.instance._class && computed.instance._class.symbol &&
3163 computed.instance._class.symbol.registered &&
3164 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3166 prop.Set(control, computed.instance.data);
3168 // This was saved in the control and shouldn't be freed by FreeExpression...
3169 if(propertyClass.type == normalClass)
3170 computed.instance.data = null;
3174 else if(computed.type == identifierExp)
3176 member.variable = true;
3178 if(eClass_GetDesigner(propertyClass))
3181 char * name = computed.identifier.string;
3182 if(!strcmp(name, "this"))
3185 prop.Set(control, instance);
3186 member.variable = false;
3191 for(check = classObject.instances.first; check; check = check.next)
3192 if(check.name && !strcmp(name, check.name))
3195 prop.Set(control, check.instance);
3196 member.variable = false;
3202 else if(computed.type == memberExp)
3204 member.variable = true;
3205 if(computed.member.exp.type == identifierExp)
3207 char * name = computed.member.exp.identifier.string;
3208 if(!strcmp(name, "this"))
3210 char * name = computed.member.member.string;
3213 for(check = classObject.instances.first; check; check = check.next)
3214 if(check.name && !strcmp(name, check.name))
3217 prop.Set(control, check.instance);
3218 member.variable = false;
3226 for(check = classObject.instances.first; check; check = check.next)
3228 if(check.name && !strcmp(name, check.name))
3230 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3233 DataValue value { };
3234 GetProperty(getProperty, check.instance, &value);
3235 SetProperty(prop, control, value);
3236 member.variable = false;
3244 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3245 else if(computed.isConstant && computed.type == stringExp && (propertyClass.dataTypeString && !strcmp(propertyClass.dataTypeString, "char *")))
3248 ReadString(temp, computed.string);
3249 prop.Set(control, temp);
3252 member.variable = true;
3254 FreeExpression(computed);
3259 Expression computed = CopyExpression(member.initializer.exp);
3262 ComputeExpression(computed);
3263 if(computed.isConstant)
3265 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3267 if(!strcmp(propertyClass.dataTypeString, "float"))
3268 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3269 else if(!strcmp(propertyClass.dataTypeString, "double"))
3270 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3272 prop.Set(control, strtol(computed.constant, null, 0));
3274 else if(computed.type == stringExp && (propertyClass.dataTypeString && !strcmp(propertyClass.dataTypeString, "char *"))) // || (!strcmp(propertyClass.name, "String"))))
3277 ReadString(temp, computed.string);
3278 prop.Set(control, temp);
3282 member.variable = true;
3284 FreeExpression(computed);
3290 member.variable = true;
3292 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3293 member.initializer.exp.type == memberExp) // identifierExp
3295 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3296 if(method && method.type == virtualMethod)
3299 // Maintain a list in FunctionDefinition of who is attached to it
3300 for(def = _class.definitions->first; def; def = def.next)
3302 if(def.type == functionClassDef)
3304 ClassFunction function = def.function;
3305 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3306 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3308 function.attached.Add(OldLink { data = method });
3309 // Reference this particular instance?
3324 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3335 //designer.CreateObject(instance, classObject, true, null);
3336 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3338 designer.PostCreateObject(instance, classObject, true, null);
3340 //instance.state = Hidden;
3341 //instance.Create();
3342 //instance.SetState(Normal, true, 0);
3351 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3355 // Restore Selection
3356 if(selectedClassName)
3359 for(oClass = classes.first; oClass; oClass = oClass.next)
3361 if(!strcmp(oClass.name, selectedClassName))
3363 this.oClass = oClass;
3367 delete selectedClassName;
3376 for(check = this.oClass.instances.first; check; check = check.next)
3378 if(check.name && !strcmp(check.name, selectedName))
3380 this.selected = check;
3386 if(this.oClass.instances.first)
3387 this.selected = this.oClass.instances.first;
3389 this.selected = this.oClass;
3392 else if(selectedPos == -1 || !this.oClass.instances.count)
3393 this.selected = this.oClass;
3399 if(selectedPos > this.oClass.instances.count)
3401 for(check = this.oClass.instances.first; check; check = check.next)
3403 if(selectedPos == pos++)
3405 this.selected = check;
3413 this.oClass = classes.first;
3414 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3416 delete selectedName;
3417 SetSymbolsDir(null);
3419 if(sheet.codeEditor == this)
3420 sheet.SelectObject(selected);
3423 codeModified = false;
3425 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3428 InvokeParameters(false, false, false);
3431 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3437 ChangeWorkingDir(oldWorkDir);
3439 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3440 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3441 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3442 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3443 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3445 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3447 if(inUseDebug && ide.projectView)
3448 ide.debugger.EvaluateWatches();
3451 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3454 Window control = (Window)object.instance;
3455 ObjectInfo classObject = object.oClass;
3457 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3459 if(!strcmp(_class.name, "DesignerBase")) return;
3461 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3463 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3464 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3466 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3467 (!prop.IsSet || prop.IsSet(control)))
3469 Class dataType = prop.dataTypeClass;
3471 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3475 if(dataType.type == structClass)
3477 void * dataForm = new0 byte[dataType.structSize];
3478 void * dataTest = new0 byte[dataType.structSize];
3480 ((void (*)())(void *)prop.Get)(control, dataForm);
3481 prop.Get(test, dataTest);
3483 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
3485 char tempString[1024] = "";
3487 bool needClass = true;
3491 prop.Set(test, dataForm);
3493 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
3495 eClass_FindNextMember(_class, curClass, curMember, null, null);
3496 if(*curMember != (DataMember)prop)
3497 f.Printf("%s = ", prop.name);
3499 *curMember = (DataMember)prop;
3500 *curClass = curMember->_class;
3503 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3505 f.Printf("%s", string);
3512 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3514 void * dataForm, * dataTest;
3516 dataForm = (void *)prop.Get(control);
3517 dataTest = (void *)prop.Get(test);
3519 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
3521 char tempString[1024] = "";
3526 prop.Set(test, dataForm);
3528 eClass_FindNextMember(_class, curClass, curMember, null, null);
3529 if(*curMember != (DataMember)prop)
3530 f.Printf("%s = ", prop.name);
3531 *curMember = (DataMember)prop;
3532 *curClass = curMember->_class;
3534 if(eClass_GetDesigner(dataType))
3536 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3537 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3538 f.Printf("this", prop.name);
3541 //ObjectInfo classObject;
3542 //for(classObject = classes.first; classObject; classObject = classObject.next)
3546 for(object = classObject.instances.first; object; object = object.next)
3548 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3550 f.Printf("%s", object.name);
3557 bool needClass = true;
3558 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
3559 f.Printf("%s", string);
3566 bool needClass = true;
3567 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
3569 if(!strcmp(dataType.dataTypeString, "char *"))
3572 OutputString(f, string);
3576 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3578 f.Printf("%s", string);
3581 *lastIsMethod = false;
3586 DataValue dataForm, dataTest;
3588 GetProperty(prop, control, &dataForm);
3589 GetProperty(prop, test, &dataTest);
3591 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
3594 char tempString[1024] = "";
3595 SetProperty(prop, test, dataForm);
3597 if(dataType.type != bitClass)
3599 bool needClass = true;
3601 if(dataType.type == enumClass)
3604 Class enumClass = eSystem_FindClass(privateModule, "enum");
3605 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3607 for(value = e.values.first; value; value = value.next)
3609 if((int)value.data == dataForm.i)
3611 string = value.name;
3617 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
3619 if(string && string[0])
3624 eClass_FindNextMember(_class, curClass, curMember, null, null);
3625 if(*curMember != (DataMember)prop)
3626 f.Printf("%s = ", prop.name);
3627 *curMember = (DataMember)prop;
3628 *curClass = curMember->_class;
3630 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3631 f.Printf("%sf", string);
3633 f.Printf("%s", string);
3637 else if(dataType.type == bitClass)
3639 bool needClass = true;
3641 if(*prev) f.Printf(", ");
3643 eClass_FindNextMember(_class, curClass, curMember, null, null);
3644 if(*curMember != (DataMember)prop)
3645 f.Printf("%s = ", prop.name);
3646 *curMember = (DataMember)prop;
3647 *curClass = curMember->_class;
3649 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm.ui, tempString, null, &needClass);
3651 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3653 f.Printf("%s", string);
3655 *lastIsMethod = false;
3665 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3667 Instantiation inst = object.instCode;
3668 Window control = (Window)object.instance;
3670 bool methodPresent = false;
3672 bool lastIsMethod = true;
3673 ObjectInfo classObject = object.oClass;
3679 // Instance removed, delete it
3680 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3682 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3683 position = inst.loc.end.pos + 1;
3687 bool multiLine = false;
3690 // Check if it's an unnamed instance
3693 f.Seek(inst.nameLoc.start.pos - position, current);
3694 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3695 position = inst.nameLoc.end.pos;
3697 f.Printf(object.name);
3702 if(isspace(ch) && ch != '\n')
3704 f.Seek(-1, current);
3712 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3714 f.Seek(pos - position, current);
3719 f.Seek(-1, current);
3728 f.Puts(object.name);
3733 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3734 methodPresent = true;
3742 if(ch == OpenBracket)
3748 // TODO: Simplify this?
3757 f.Seek(-1, current);
3769 if(ch == '\n') { toDelete = count; count = 0; }
3770 else if(isspace(ch)) count++;
3773 f.Seek(-1, current);
3777 toDelete += count - 6;
3787 f.Seek(-toDelete-count, current);
3788 f.DeleteBytes(toDelete);
3789 f.Seek(count, current);
3794 for(c = 0; c<toAdd; c++)
3800 methodPresent = multiLine;
3803 f.Printf(methodPresent ? "\n " : " ");
3809 // Instance not there, create a brand new one
3810 DeleteJunkBefore(f, position, &position);
3811 f.Printf(*firstObject ? "\n\n" : "\n");
3812 *firstObject = false;
3814 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3815 methodPresent = true;
3820 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3822 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3827 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3829 f.Printf(" %s %c ", control._class.name, OpenBracket);
3835 Instance test = eInstance_New(control._class);
3836 DataMember curMember = null;
3837 Class curClass = null;
3840 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3844 // Attach Method here
3845 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3847 if(prev) f.Printf(", ");
3848 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3853 if(inst && !object.deleted)
3855 MembersInit members;
3856 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3858 DeleteJunkBefore(f, position, &position);
3860 // Instance already there, clear out the properties
3861 for(members = inst.members->first; members; members = members.next)
3863 if(members.type == dataMembersInit)
3867 if(members.dataMembers)
3869 bool keptMember = false;
3870 MemberInit lastKept = null;
3872 for(member = members.dataMembers->first; member; member = member.next)
3874 Identifier ident = member.identifiers ? member.identifiers->first : null;
3875 bool deleted = false;
3877 // For now delete if it's not a method
3878 if(!member.variable) // && ident)
3880 if(!ident || !ident.next)
3882 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3885 f.Seek(member.loc.start.pos - position, current);
3886 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3887 position = member.loc.end.pos;
3892 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3893 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3894 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
3896 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
3897 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
3899 f.Seek(member.loc.start.pos - position, current);
3900 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3901 position = member.loc.end.pos;
3913 //f.Seek(member.loc.start.pos - position, current);
3914 //position = member.loc.start.pos;
3915 DeleteJunkBefore(f, member.loc.start.pos, &position);
3916 if(prev) f.Printf(", ");
3917 else if(keptMember) f.Printf(" ");
3922 if(!keptMember || !members.next)
3927 if(keptMember && lastKept != members.dataMembers->last)
3932 f.Seek(-1, current);
3938 f.Seek(-1, current);
3941 else if(!isspace(ch))
3943 f.Seek(-2, current);
3948 f.DeleteBytes(count);
3951 f.Seek(members.loc.end.pos - position, current);
3956 f.Seek(-1, current);
3958 position = members.loc.end.pos + 1;
3962 f.Seek(-1, current);
3963 position = members.loc.end.pos;
3969 lastIsMethod = false;
3974 DeleteJunkBefore(f, position, &position);
3977 if(lastKept != members.dataMembers->last)
3982 f.Seek(-1, current);
3988 f.Seek(-1, current);
3991 else if(!isspace(ch))
3993 f.Seek(-2, current);
3998 f.DeleteBytes(count);
4002 f.Seek(members.loc.end.pos - position, current);
4003 position = members.loc.end.pos;
4007 lastIsMethod = true;
4010 lastIsMethod = false;
4016 f.Seek(members.loc.end.pos - position, current);
4017 position = members.loc.end.pos;
4019 lastIsMethod = true;
4022 else if(members.type == methodMembersInit)
4024 if(this.methodAction == actionDeleteMethod && members.function == function);
4026 methodPresent = true;
4028 // Delete instance method here
4029 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4030 members.function == function)
4032 if(this.moveAttached && !*text)
4033 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4035 DeleteJunkBefore(f, members.loc.start.pos, &position);
4036 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4037 position = members.loc.end.pos + 1;
4042 DeleteJunkBefore(f, position, &position);
4046 DeleteJunkBefore(f, members.loc.start.pos, &position);
4047 lastIsMethod = true;
4051 f.Seek(members.loc.end.pos - position, current);
4052 position = members.loc.end.pos;
4054 DeleteJunkBefore(f, position, &position);
4063 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4065 Method method = this.method;
4066 DeleteJunkBefore(f, position, &position);
4072 if(!method.dataType)
4073 method.dataType = ProcessTypeString(method.dataTypeString, false);
4076 Type dataType = method.dataType;
4077 Type returnType = dataType.returnType;
4080 if(this.moveAttached)
4082 // Move function here:
4083 int newLen = strlen(method.name);
4088 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4090 // First change name of function
4091 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4092 *textSize += newLen - movedFuncIdLen;
4093 memcpy(*text + movedFuncIdPos, method.name, newLen);
4095 // Second, tab right
4098 for(c = 0; (*text)[c]; )
4101 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4104 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4105 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4109 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4119 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4121 // ADDING METHOD HERE
4123 OutputType(f, returnType, false);
4126 if(dataType.thisClass)
4128 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4130 if(dataType.thisClass.shortName)
4131 f.Printf(dataType.thisClass.shortName);
4133 f.Printf(dataType.thisClass.string);
4137 f.Printf(method.name);
4139 for(param = dataType.params.first; param; param = param.next)
4141 OutputType(f, param, true);
4146 f.Printf(" %c\n\n", OpenBracket);
4148 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4150 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4151 f.Printf(" return true;\n");
4152 else if(returnType.kind != voidType)
4153 f.Printf(" return 0;\n");
4158 if(returnType.kind != voidType)
4159 f.Printf("return ");
4160 f.Printf("%s::%s(", control._class.name, method.name);
4161 for(param = dataType.params.first; param; param = param.next)
4163 if(param.prev) f.Printf(", ");
4164 f.Printf(param.name);
4168 f.Printf(" %c\n", CloseBracket);
4174 if(!object.instCode)
4177 f.Printf(" %c;\n", CloseBracket);
4179 f.Printf("%c;\n", CloseBracket);
4181 else if(!object.deleted)
4183 // Turn this into a multiline instance when adding a method
4184 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4186 f.Printf(methodPresent ? "\n " : " ");
4188 f.Seek(inst.loc.end.pos + 1 - position, current);
4189 position = inst.loc.end.pos + 1;
4194 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4197 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4199 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4201 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4203 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4204 if(prop && prop.isProperty && !prop.conversion)
4206 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4207 (!prop.IsSet || prop.IsSet(classObject.instance)))
4209 Class dataType = prop.dataTypeClass;
4210 char tempString[1024] = "";
4212 bool specify = false;
4215 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4216 if(member && member._class == regClass)
4220 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4222 if(dataType && dataType.type == structClass)
4224 void * dataForm = new0 byte[dataType.structSize];
4225 void * dataTest = new0 byte[dataType.structSize];
4227 prop.Get(classObject.instance, dataForm);
4228 prop.Get(test, dataTest);
4230 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
4232 bool needClass = true;
4234 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
4235 prop.Set(test, dataForm);
4237 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4239 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4244 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4246 void * dataForm, * dataTest;
4248 dataForm = (void *)prop.Get(classObject.instance);
4249 dataTest = (void *)prop.Get(test);
4251 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
4253 char tempString[1024] = "";
4255 prop.Set(test, dataForm);
4257 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4259 // Shouldn't go here ...
4260 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4264 bool needClass = true;
4266 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
4268 if(!strcmp(dataType.dataTypeString, "char *"))
4270 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4271 OutputString(f, string);
4275 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4277 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4283 DataValue dataForm, dataTest;
4285 GetProperty(prop, classObject.instance, &dataForm);
4286 GetProperty(prop, test, &dataTest);
4288 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
4290 SetProperty(prop, test, dataForm);
4291 if(dataType.type == bitClass)
4293 bool needClass = true;
4294 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
4296 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4298 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4302 bool needClass = true;
4303 if(dataType.type == enumClass)
4306 Class enumClass = eSystem_FindClass(privateModule, "enum");
4307 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4309 for(value = e.values.first; value; value = value.next)
4311 if((int)value.data == dataForm.i)
4313 string = value.name;
4319 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
4320 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4321 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4323 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4332 void UpdateFormCode()
4341 else if(formModified)
4343 EditBoxStream f { editBox = editBox };
4347 Identifier movedFuncId;
4348 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4349 ObjectInfo classObject;
4355 movedFuncId = GetDeclId(function.declarator);
4356 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4357 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4360 for(classObject = classes.first; classObject; classObject = classObject.next)
4363 ClassDefinition classDef = classObject.classDefinition;
4364 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4367 bool firstObject = true;
4368 ObjectInfo object = classObject.instances.first;
4369 bool lastIsDecl = false;
4371 if(!classObject.modified) continue;
4373 test = eInstance_New(regClass);
4376 // Put it in the same desktop window...
4377 designer.PrepareTestObject(test);
4379 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4380 //f.Printf("%c\n\n", OpenBracket);
4382 // Change the _class name
4383 f.Seek(classDef.nameLoc.start.pos - position, current);
4384 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4385 f.Printf(classObject.name);
4386 position = classDef.nameLoc.end.pos;
4389 // Go to block start, delete all until no white space, put \n
4393 f.Seek(classDef.blockStart.end.pos - position, current);
4394 position = classDef.blockStart.end.pos;
4396 for(; f.Getc(&ch); count++)
4400 f.Seek(-1, current);
4410 f.Seek(-count, current);
4412 f.DeleteBytes(count-back);
4414 position += count-back;
4417 // Output properties
4418 OutputClassProperties(classObject.instance._class, classObject, f, test);
4420 for(def = classDef.definitions->first; def; def = def.next)
4424 case defaultPropertiesClassDef:
4426 bool keptMember = false;
4428 MemberInit lastKept = null;
4431 DeleteJunkBefore(f, def.loc.start.pos, &position);
4434 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4436 Identifier ident = propDef.identifiers->first;
4437 bool deleted = false;
4439 // For now delete if it's a prop
4440 if(!propDef.variable && ident)
4444 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4447 f.Seek(propDef.loc.start.pos - position, current);
4448 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4449 position = propDef.loc.end.pos;
4454 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4455 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4457 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4458 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4460 f.Seek(propDef.loc.start.pos - position, current);
4461 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4462 position = propDef.loc.end.pos;
4480 f.Seek(def.loc.end.pos - position - 1, current);
4485 f.Seek(-1, current);
4488 position = def.loc.end.pos;
4492 if(lastKept != def.defProperties->last)
4497 f.Seek(-1, current);
4503 f.Seek(-1, current);
4506 else if(!isspace(ch))
4508 f.Seek(-2, current);
4513 f.DeleteBytes(count);
4517 f.Seek(def.loc.end.pos - position, current);
4518 position = def.loc.end.pos;
4523 case declarationClassDef:
4525 Declaration decl = def.decl;
4527 if(decl.type == instDeclaration)
4529 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4531 while(def.object && object != def.object)
4533 if(object /*&& ((ObjectInfo)def.object).modified*/)
4534 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4535 object = object.next;
4538 DeleteJunkBefore(f, def.loc.start.pos, &position);
4539 f.Printf(firstObject ? "\n\n " : "\n ");
4540 firstObject = false;
4542 if(def.object && ((ObjectInfo)def.object).modified)
4543 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4545 object = object ? object.next : null;
4549 DeleteJunkBefore(f, def.loc.start.pos, &position);
4550 f.Printf(firstObject ? "\n\n " : "\n ");
4551 firstObject = false;
4557 DeleteJunkBefore(f, def.loc.start.pos, &position);
4558 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4563 case functionClassDef:
4565 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4566 if(!def.function.body) continue;
4570 DeleteJunkBefore(f, def.loc.start.pos, &position);
4573 // Delete _class methods
4574 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4575 def.function == function)
4580 if(moveAttached && !text)
4582 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4585 f.Seek(def.loc.end.pos - position, current);
4586 for(; f.Getc(&ch); count++)
4590 f.Seek(-1, current);
4594 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4596 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4597 position = def.loc.end.pos + count;
4600 // In case of detaching methods in the _class, simply rename the method
4601 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4603 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4604 f.DeleteBytes(movedFuncIdLen);
4606 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4609 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4610 function == def.function)
4612 // In case of attaching methods in the _class, simply rename the method
4613 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4614 position = function.loc.start.pos + movedFuncIdPos;
4615 f.DeleteBytes(movedFuncIdLen);
4616 if(method.dataType.thisClass)
4617 f.Printf("%s::", method.dataType.thisClass.string);
4618 f.Puts(method.name);
4619 position += movedFuncIdLen;
4624 DeleteJunkBefore(f, def.loc.start.pos, &position);
4625 if(def.type == memberAccessClassDef)
4628 firstObject = false;
4638 f.Seek(def.loc.end.pos - position, current);
4639 position = def.loc.end.pos;
4642 // Output attached methods
4643 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4645 DeleteJunkBefore(f, position, &position);
4646 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4649 // ********** INSTANCES ***************
4650 for(; object; object = object.next)
4652 if(!object.instCode)
4654 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4658 DeleteJunkBefore(f, position, &position);
4660 // ****************** METHODS ***********************
4661 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4663 // If detaching an instance method
4664 if(selected != classObject)
4666 int newLen = strlen(methodName);
4669 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4670 // Tab selection left
4673 for(c = 0; text[c]; )
4676 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4677 memmove(text+start, text+start+i, textSize+1-start-i);
4680 for(; text[c] && text[c] != '\n'; c++);
4686 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4687 textSize += newLen - movedFuncIdLen;
4688 memcpy(text + movedFuncIdPos, methodName, newLen);
4695 if(methodAction == actionAddMethod && selected == classObject)
4697 Method method = this.method;
4699 if(!method.dataType)
4700 method.dataType = ProcessTypeString(method.dataTypeString, false);
4702 // ADDING METHOD HERE
4704 Type dataType = method.dataType;
4705 Type returnType = dataType.returnType;
4707 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4711 OutputType(f, returnType, false);
4714 if(dataType.thisClass && !dataType.classObjectType)
4716 if(dataType.thisClass.shortName)
4717 f.Printf(dataType.thisClass.shortName);
4719 f.Printf(dataType.thisClass.string);
4722 f.Printf(method.name);
4724 for(param = dataType.params.first; param; param = param.next)
4726 OutputType(f, param, true);
4731 f.Printf(" %c\n\n", OpenBracket);
4733 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4735 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4736 f.Printf(" return true;\n");
4737 else if(returnType && returnType.kind != voidType)
4738 f.Printf(" return 0;\n");
4743 if(returnType.kind != voidType)
4744 f.Printf("return ");
4746 char * name = ((Specifier)classDef.baseSpecs->first).name;
4747 Symbol _class = FindClass(name);
4748 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4750 for(param = dataType.params.first; param; param = param.next)
4752 if(param.prev) f.Printf(", ");
4753 if(param.kind != voidType)
4754 f.Printf(param.name);
4759 f.Printf(" %c", CloseBracket);
4763 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4775 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4776 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4780 codeModified = false;
4781 formModified = false;
4783 moveAttached = false;
4788 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4791 ClassFunction function = null;
4794 ObjectInfo object = this.selected;
4796 if(object && object == this.oClass)
4798 ClassDefinition classDef = object.oClass.classDefinition;
4800 if(classDef && classDef.definitions)
4802 for(def = classDef.definitions->first; def; def = def.next)
4804 if(def.type == functionClassDef && def.function.declarator)
4806 if(!strcmp(def.function.declarator.symbol.string, methodName))
4808 function = def.function;
4813 else if(def.type == defaultPropertiesClassDef)
4817 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4819 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4820 if(ident && !ident.next)
4822 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4826 propLoc = propDef.loc;
4829 ClassDefinition classDef = object.oClass.classDefinition;
4831 if(classDef.definitions)
4833 for(def = classDef.definitions->first; def; def = def.next)
4835 if(def.type == functionClassDef)
4837 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4839 function = def.function;
4858 Instantiation inst = object.instCode;
4860 // Check here to see if the method already exists, no need to call ModifyCode in that case
4861 if(inst && inst.members)
4863 MembersInit members;
4864 for(members = inst.members->first; members; members = members.next)
4866 switch(members.type)
4868 case dataMembersInit:
4870 if(members.dataMembers)
4873 for(member = members.dataMembers->first; member; member = member.next)
4875 Identifier ident = member.identifiers ? member.identifiers->first : null;
4876 if(ident && !ident.next)
4878 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4882 propLoc = member.loc;
4885 ClassDefinition classDef = object.oClass.classDefinition;
4887 if(classDef.definitions)
4889 for(def = classDef.definitions->first; def; def = def.next)
4891 if(def.type == functionClassDef)
4893 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
4895 function = def.function;
4904 // TODO: Fix memory leak
4905 function = ClassFunction
4907 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
4919 case methodMembersInit:
4921 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
4923 function = members.function;
4935 if(functionPtr) *functionPtr = function;
4939 void GoToMethod(char * methodName /*Method method*/)
4943 ObjectInfo object = selected;
4944 EditBoxStream f { editBox = editBox };
4945 ClassFunction function = null;
4946 bool atChar = false;
4950 Location propLoc = { {0,0,-1} };
4953 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
4954 if(function && function.body)
4957 f.Seek(function.body.loc.start.pos+1, current);
4967 f.Seek(-1, current);
4972 else if(!isspace(ch))
4974 f.Seek(-1, current);
4980 else if(propLoc.start.pos > -1)
4982 f.Seek(propLoc.start.pos, current);
4985 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
4987 if(function || propLoc.start.pos > -1)
4989 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
4990 editBox.CenterOnCursor();
4991 SetState(normal, false, 0);
4994 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
4996 FreeClassFunction(function);
5002 void FindCompatibleMethods(Method method, OldList compatible)
5004 ClassDefinition classDef = this.oClass.classDefinition;
5005 if(classDef && classDef.definitions)
5008 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5011 Symbol classSym { };
5012 Symbol selectedClass;
5013 if(this.selected == this.oClass)
5014 selectedClass = classSym;
5016 selectedClass = FindClass(this.selected.instance._class.name);
5018 regClass.name = classDef._class.name;
5019 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5020 for(def = classDef.definitions->first; def; def = def.next)
5022 if(def.type == functionClassDef && def.function.declarator)
5024 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5026 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5029 Type type = def.function.declarator.symbol.type;
5030 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5032 compatible.Add(OldLink { data = def.function });
5038 if(this.oClass && this.oClass.instance)
5040 classSym.registered = regClass;
5041 //classSym.registered = this.oClass.oClass;
5043 for(_class = regClass.base; _class; _class = _class.base)
5046 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5048 // TODO: Understand why these functions popup in attach list
5049 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5051 if(!testMethod.dataType)
5052 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5054 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5055 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5056 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5058 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5059 // ClassFunction function { };
5060 FunctionDefinition function { };
5062 function.declarator = Declarator { };
5063 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5064 excludedSymbols.Add(function.declarator.symbol);
5066 compatible.Add(OldLink { data = function });
5077 void AddMethod(Method method)
5081 char methodName[1024];
5082 strcpy(methodName, method.name);
5083 if(!FindMethod(methodName, null, null))
5085 methodAction = actionAddMethod;
5086 this.method = method;
5090 GoToMethod(methodName);
5094 void DeleteMethod(ClassFunction function)
5098 methodAction = actionDeleteMethod;
5099 this.function = function;
5107 void AttachMethod(Method method, ClassFunction function)
5111 // If it's an instance we'll ask if we want to move it inside...
5112 if(!function.attached.count && function.body)
5114 // Find the function in the _class to check if it's a virtual function
5115 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5116 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5117 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5119 for(def = this.classDefinition.first; def; def = def.next)
5121 if(def.type == functionClassDef)
5123 if(def.function == function)
5128 if(!method || method.type != virtualMethod)
5131 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5132 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5134 moveAttached = true;
5139 methodAction = actionAttachMethod;
5140 this.method = method;
5141 this.function = function;
5148 void ReAttachMethod(Method method, ClassFunction function)
5152 // If it's an instance we'll ask if we want to move it inside...
5153 if(!function.attached.count && function.body)
5155 // Find the function in the _class to check if it's a virtual function
5156 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5157 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5158 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5160 for(def = this.classDefinition.first; def; def = def.next)
5162 if(def.type == functionClassDef)
5164 if(def.function == function)
5169 if(!method || method.type != virtualMethod)
5172 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5173 if(MessageBox { type = yesNo, master = parent, text = title,
5174 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5176 moveAttached = true;
5181 methodAction = actionReattachMethod;
5182 this.method = method;
5183 this.function = function;
5190 void DetachMethod(Method method, ClassFunction function, int type)
5198 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5199 master = sheet, text = $"Name detached method", background = activeBorder
5203 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5204 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5208 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5209 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5213 dialog, anchor = { left = 5, right = 5, top = 5 }
5215 sprintf(methodName, "%s_%s", selected.name, method.name);
5216 nameBox.contents = methodName;
5218 result = dialog.Modal() == ok;
5219 strcpy(methodName, nameBox.contents);
5224 // If the method is not attached, move it outside
5227 // Add this class to the methodName
5228 char name[1024] = "";
5230 if(this.selected != this.oClass && !method.dataType.thisClass)
5232 strcat(name, this.selected.instance._class.name);
5234 strcat(name, this.methodName);
5235 strcpy(this.methodName, name);
5237 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5239 strcat(name, method.dataType.thisClass.string);
5241 strcat(name, this.methodName);
5242 strcpy(this.methodName, name);
5245 this.moveAttached = true;
5248 this.methodAction = actionDetachMethod;
5249 this.method = method;
5250 this.function = function;
5257 void AddObject(Instance instance, ObjectInfo * object)
5261 //*object = _class.instances.Add(sizeof(ObjectInfo));
5262 *object = ObjectInfo { };
5263 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5264 (*object).oClass = oClass;
5265 (*object).instance = instance;
5270 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5272 // if(strcmp(name, this.oClass.instance.name))
5275 for(check = oClass.instances.first; check; check = check.next)
5276 if(!check.deleted && check.name && !strcmp(name, check.name))
5280 (*object).name = CopyString(name);
5285 toolBox.controlClass = null;
5289 //sheet.AddObject(*object, (*object).name, TypeData, true);
5294 void EnsureUpToDate()
5296 if(sheet && codeModified)
5300 void SelectObject(ObjectInfo object)
5303 oClass = object ? object.oClass : null;
5305 designer.SelectObject(object, object ? object.instance : null);
5308 void SelectObjectFromDesigner(ObjectInfo object)
5311 sheet.SelectObject(object);
5314 void EnumerateObjects(Sheet sheet)
5318 for(oClass = classes.first; oClass; oClass = oClass.next)
5324 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5325 for(object = oClass.instances.first; object; object = object.next)
5326 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5329 sheet.SelectObject(selected);
5334 designer.AddObject();
5337 void DeleteObject(ObjectInfo object)
5339 delete object.instance;
5340 object.deleted = true;
5341 object.modified = true;
5342 object.oClass.modified = true;
5344 if(selected == object)
5346 bool looped = false;
5347 ObjectInfo select = object;
5351 select = select.prev;
5355 select = object.oClass.instances.last;
5362 sheet.SelectObject(select ? select : oClass);
5365 if(!object.instCode && object.oClass != object)
5368 oClass.instances.Delete(object);
5371 if(sheet.codeEditor == this)
5372 sheet.DeleteObject(object);
5375 void RenameObject(ObjectInfo object, char * name)
5379 // Validate the name:
5380 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5381 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5384 for(c = 0; name[c]; c++)
5385 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5393 object.name = (name && name[0]) ? CopyString(name) : null;
5395 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5399 void DesignerModifiedObject()
5401 sheet.ListProperties(false);
5405 void ListSubMembers(Type member)
5409 for(subMember = member.members.first; subMember; subMember = subMember.next)
5413 DataRow row = membersList.AddString(subMember.name);
5414 row.icon = icons[typeData];
5418 ListSubMembers(subMember);
5423 void ListSubDataMembers(DataMember member, bool isPrivate)
5425 DataMember subMember;
5426 for(subMember = member.members.first; subMember; subMember = subMember.next)
5428 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5432 DataRow row = membersList.AddString(subMember.name);
5433 BitmapResource bitmap = null;
5434 if(!subMember.dataType)
5435 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5437 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5439 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5442 bitmap = { bitmapName };
5443 membersList.AddResource(bitmap);
5446 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5450 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5456 void ListClassMembers(Class whatClass, bool methodsOnly)
5459 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5460 bool isPrivate = false;
5462 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5464 Method method, methodIt;
5466 DataMember memberIt;
5468 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5470 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5471 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5473 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5475 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5477 DataRow row = membersList.FindString(method.name);
5480 row = membersList.AddString(method.name);
5482 if(!method.dataType)
5483 method.dataType = ProcessTypeString(method.dataTypeString, false);
5485 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5493 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5497 if(memberIt.isProperty)
5499 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5501 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5505 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5507 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5510 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5516 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5518 if(member.isProperty)
5520 Property prop = (Property) member;
5521 if(!membersList.FindString(prop.name))
5523 DataRow row = membersList.AddString(prop.name);
5524 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5527 else if(member.name && !membersList.FindString(member.name))
5529 DataRow row = membersList.AddString(member.name);
5531 BitmapResource bitmap = null;
5532 if(!member.dataType)
5533 member.dataType = ProcessTypeString(member.dataTypeString, false);
5535 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5537 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5540 bitmap = { bitmapName };
5541 membersList.AddResource(bitmap);
5544 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5547 ListSubDataMembers(member, member.memberAccess == privateAccess);
5551 if(_class.inheritanceAccess == privateAccess)
5554 if(_class.module != privateModule) break;
5559 void ListClassMembersMatch(Class whatClass, Type methodType)
5562 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5563 bool isPrivate = false;
5565 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5571 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5573 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5575 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5577 if(!method.dataType)
5578 method.dataType = ProcessTypeString(method.dataTypeString, false);
5580 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5582 DataRow row = membersList.FindString(method.name);
5585 row = membersList.AddString(method.name);
5586 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5592 if(_class.inheritanceAccess == privateAccess)
5595 if(_class.module != privateModule) break;
5600 void ListClassPropertiesAndVirtual(Class whatClass)
5603 bool isPrivate = false;
5604 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5610 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5612 if(method.type == virtualMethod)
5614 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5616 DataRow row = membersList.FindString(method.name);
5619 row = membersList.AddString(method.name);
5621 if(!method.dataType)
5622 method.dataType = ProcessTypeString(method.dataTypeString, false);
5624 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5630 for(member = _class.membersAndProperties.first; member; member = member.next)
5632 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5634 if(member.isProperty)
5636 Property prop = (Property)member;
5638 DataRow row = membersList.AddString(prop.name);
5639 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5642 else if(member.name)
5644 DataRow row = membersList.AddString(member.name);
5646 BitmapResource bitmap = null;
5647 if(!member.dataType)
5648 member.dataType = ProcessTypeString(member.dataTypeString, false);
5650 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5652 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5655 bitmap = { bitmapName };
5656 membersList.AddResource(bitmap);
5659 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5662 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5665 if(_class.inheritanceAccess == privateAccess)
5668 if(_class.module != privateModule) break;
5673 void ListMembers(Type type)
5675 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5679 if(type.kind == classType)
5682 ListClassMembers(type._class.registered, false);
5687 for(member = type.members.first; member; member = member.next)
5691 DataRow row = membersList.AddString(member.name);
5692 row.icon = icons[typeData];
5694 else if(member.kind == structType || member.kind == unionType)
5695 ListSubMembers(member);
5701 void ListModule(Module mainModule, int recurse, bool listClasses)
5704 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5705 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5706 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5707 for(module = mainModule.application.allModules.first; module; module = module.next)
5709 if(ModuleVisibility(mainModule, module))
5710 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5714 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5721 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5723 Class _class = link.data;
5724 if(_class.type != systemClass)
5726 DataRow row = membersList.AddString(_class.name);
5727 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5732 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5734 DefinedExpression definedExp = link.data;
5735 DataRow row = membersList.AddString(link /*definedExp*/.name);
5736 row.icon = icons[typeData];
5739 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5741 GlobalFunction function = link.data;
5742 DataRow row = membersList.AddString(link /*function*/.name);
5743 row.icon = icons[typeMethod];
5747 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5749 if(recurse != 2 && listClasses)
5751 if(!membersList.FindString(ns->name))
5753 DataRow row = membersList.AddString(ns->name);
5754 row.icon = icons[typeNameSpace];
5759 ListNameSpace(ns, 2, listClasses);
5763 void ListEnumValues(Class _class)
5765 for(; _class && _class.type == enumClass; _class = _class.base)
5767 EnumClassData enumeration = (EnumClassData)_class.data;
5769 for(item = enumeration.values.first; item; item = item.next)
5771 DataRow row = membersList.AddString(item.name);
5772 row.icon = icons[typeEnumValue];
5777 bool ListEnumsModule(Module mainModule, Type dest)
5779 bool result = false;
5781 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5782 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5783 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5784 for(module = mainModule.application.allModules.first; module; module = module.next)
5786 if(ModuleVisibility(mainModule, module))
5787 result |= ListEnums(module.publicNameSpace, dest);
5792 void ListNameSpaceByString(Module mainModule, char * string)
5794 NameSpace * nameSpace;
5796 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5797 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5798 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5799 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5800 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5801 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5802 for(module = mainModule.application.allModules.first; module; module = module.next)
5804 if(ModuleVisibility(mainModule, module))
5806 nameSpace = FindNameSpace(module.publicNameSpace, string);
5807 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5812 bool ListEnums(NameSpace nameSpace, Type dest)
5815 bool result = false;
5817 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5819 Class _class = link.data;
5820 if(_class.type == enumClass && (dest.kind != classType || !dest._class || dest._class.registered != _class))
5822 OldList conversions { };
5824 type.kind = classType;
5825 type._class = FindClass(_class.name);
5826 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5828 ListEnumValues(_class);
5831 conversions.Free(null);
5835 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5837 result |= ListEnums(nameSpace, dest);
5842 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5846 for(c = 0; (ch = name[c]); c++)
5848 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5850 NameSpace * newSpace;
5851 char * spaceName = new char[c - start + 1];
5852 memcpy(spaceName, name + start, c - start);
5853 spaceName[c-start] = '\0';
5854 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5858 nameSpace = newSpace;
5867 return (NameSpace *)nameSpace;
5870 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5872 bool listedEnums = false;
5873 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5874 bool listClasses = true;
5876 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5878 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5879 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5880 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5882 if(exp.type == identifierExp)
5883 id = realIdentifier;
5885 if(id && id._class && !id._class.name)
5887 listClasses = false;
5890 else if(id && id._class && id._class.name)
5894 Class _class = id.classSym.registered;
5895 if(_class && _class.type == enumClass)
5897 ListEnumValues(_class);
5900 ListClassMembers(id.classSym.registered, true);
5905 else if(id && colons)
5907 ListNameSpaceByString(this.privateModule, id.string);
5912 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
5914 listedEnums = ListEnumsModule(this.privateModule, destType);
5917 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
5919 ListEnumValues(destType._class.registered);
5922 ListClassPropertiesAndVirtual(insideClass);
5926 else if(destType && destType.kind == enumType)
5930 for(value = destType.members.first; value; value = value.next)
5932 DataRow row = membersList.AddString(value.name);
5933 row.icon = icons[typeEnumValue];
5937 ListClassPropertiesAndVirtual(insideClass);
5941 else if(insideClass && !enumOnly)
5943 ListClassPropertiesAndVirtual(insideClass);
5946 if(listedEnums && string && string[0])
5948 DataRow row = membersList.FindSubString(string);
5950 listedEnums = false;
5953 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
5955 ListClassMembersMatch(GetThisClass(), exp.destType);
5957 else if(!insideClass && !enumOnly && !listedEnums)
5960 Symbol symbol = null;
5964 ListClassMembers(GetThisClass(), false);
5967 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
5969 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
5971 // Don't list enum values?
5972 //if(symbol.type.kind != TypeEnum)
5973 DataRow row = membersList.FindString(symbol.string);
5976 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
5978 row = membersList.AddString(symbol.string);
5979 if(symbol.type && symbol.type.kind == functionType)
5980 row.icon = icons[typeMethod];
5981 else if(symbol.type && symbol.type.kind == enumType)
5983 row.icon = icons[typeEnumValue];
5987 BitmapResource bitmap = null;
5988 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
5990 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
5993 bitmap = { bitmapName };
5994 membersList.AddResource(bitmap);
5997 row.icon = bitmap ? bitmap : icons[typeData];
6004 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6006 DataRow row = membersList.FindString(symbol.string);
6009 row = membersList.AddString(symbol.string);
6010 if(symbol.type.kind == functionType)
6011 row.icon = icons[typeMethod];
6012 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6014 row.icon = icons[typeClass];
6018 row.icon = icons[typeDataType];
6025 ListModule(this.privateModule, 1, listClasses);
6026 // TODO: Implement this with name space
6030 for(data = globalData.first; data; data = data.next)
6032 DataRow row = membersList.FindString(data.name);
6034 data.dataType = ProcessTypeString(data.dataTypeString, false);
6037 row = membersList.AddString(data.name);
6039 if(data.dataType && data.dataType.kind == TypeEnum)
6041 row.icon = icons[typeEnumValue];
6045 BitmapResource bitmap = null;
6046 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6048 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6051 bitmap = { bitmapName };
6052 membersList.AddResource(bitmap);
6055 row.icon = bitmap ? bitmap : icons[typeData];
6063 DataRow row = membersList.AddString("Min");
6064 row.icon = icons[typeMethod];
6066 row = membersList.AddString("Max");
6067 row.icon = icons[typeMethod];
6069 row = membersList.AddString("Abs");
6070 row.icon = icons[typeMethod];
6072 row = membersList.AddString("Sgn");
6073 row.icon = icons[typeMethod];
6079 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6081 EditBoxStream f { editBox = editBox };
6086 updatingCode = true;
6088 if(!method.dataType)
6089 method.dataType = ProcessTypeString(method.dataTypeString, false);
6091 DeleteJunkBefore(f, function.loc.start.pos, &position);
6092 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6094 // ADDING METHOD HERE
6096 Type dataType = method.dataType;
6097 Type returnType = dataType.returnType;
6099 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6105 if(extraIndent) f.Printf(" ");
6107 OutputType(f, returnType, false);
6111 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6113 if(dataType.thisClass.shortName)
6114 f.Printf(dataType.thisClass.shortName);
6116 f.Printf(dataType.thisClass.string);
6119 f.Printf(method.name);
6121 for(param = dataType.params.first; param; param = param.next)
6123 // Decided not to write void...
6124 if(param.kind != voidType)
6126 OutputType(f, param, true);
6132 if(extraIndent) f.Printf(" ");
6133 f.Printf(" %c\n", OpenBracket);
6135 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6139 //if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
6141 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6143 if(extraIndent) f.Printf(" ");
6144 f.Printf(" return true;\n");
6146 else if(returnType && returnType.kind != voidType)
6148 if(extraIndent) f.Printf(" ");
6149 f.Printf(" return 0;\n");
6155 if(returnType.kind != voidType)
6156 f.Printf("return ");
6157 f.Printf("%s::%s(this", classDef.base.name, method.name);
6158 for(param = dataType.params.first; param; param = param.next)
6161 f.Printf(param.name);
6168 if(extraIndent) f.Printf(" ");
6169 f.Printf(" %c", CloseBracket);
6174 if(extraIndent) { x1 += 3; x2 += 3; }
6175 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6177 this.updatingCode = false;
6181 // Return false if we overrided a function and don't want to run params listing
6182 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6184 bool didOverride = false;
6185 EditLine line = editBox.line;
6186 char * text = line.text;
6187 int lineNum, charPos;
6188 Expression exp = null;
6191 //Identifier id = null;
6192 Expression memberExp = null;
6193 Identifier realIdentifier = null;
6195 if(!privateModule) return !didOverride;
6197 insideFunction = null;
6199 charPos = editBox.charPos + 1;
6200 if(!membersListShown)
6205 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6207 EditBoxStream f { editBox = editBox };
6209 updatingCode = true;
6210 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6214 if(!f.Seek(-1, current))
6217 if(!isspace(ch)) break;
6218 f.Seek(-1, current);
6220 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6222 lineNum = editBox.lineNumber + 1;
6223 charPos = editBox.charPos + 1;
6225 updatingCode = false;
6228 if(!membersListShown)
6230 memberExp = FindExpTree(ast, lineNum, charPos);
6231 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6236 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6238 EditBoxStream f { editBox = editBox };
6241 updatingCode = true;
6243 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6246 if(ch == '}' || ch == ',' || ch == ')')
6248 f.Seek(-1, current);
6256 if(!f.Seek(-1, current))
6259 if(!isspace(ch)) break;
6260 f.Seek(-1, current);
6264 f.Seek(-1, current);
6266 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6268 lineNum = editBox.lineNumber + 1;
6269 charPos = editBox.charPos + 1;
6271 updatingCode = false;
6274 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6279 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6280 lineNum = editBox.lineNumber + 1;
6281 charPos = editBox.charPos/* + 1*/;
6285 char tempString[1024];
6286 char * string = null;
6287 CodePosition idStart, idEnd;
6289 if(membersListShown)
6291 char * buffer = membersLine.text;
6293 bool firstChar = true;
6295 string = tempString;
6297 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6299 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6300 if(!isSpace) firstChar = false;
6302 string[len++] = buffer[c];
6306 else //if(realIdentifier)//if(id)
6309 char * buffer = id.string;
6311 bool firstChar = true;
6313 string = tempString;
6314 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6316 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6317 if(!isSpace) firstChar = false;
6319 string[len++] = buffer[c];
6325 EditLine editLine = editBox.line;
6326 bool firstChar = true;
6329 string = tempString;
6330 for(y = lineNum-1; y >= 0; y--)
6332 char * buffer = editLine.text;
6333 int lineCount = editLine.count;
6334 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6336 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6341 idEnd.charPos = x + 2;
6346 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6349 idEnd.charPos = x + 2;
6356 if(!isalnum(buffer[x]) && buffer[x] != '_')
6362 memmove(string+1, string, len++);
6363 string[0] = buffer[x];
6367 //if(done || firstChar)
6368 if(done || !firstChar)
6370 editLine = editLine.prev;
6373 if(!strcmp(string, "case"))
6379 else if(!strcmp(string, "return"))
6385 else if(!strcmp(string, "delete"))
6391 else if(!strcmp(string, "new"))
6397 else if(!strcmp(string, "renew"))
6405 idStart.charPos = x + 1;
6406 idStart.line = y + 1;
6409 if(!membersListShown)
6411 membersList.Clear();
6412 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6414 Type type = memberExp.member.exp.expType;
6415 if(pointer == 2 && type)
6417 if(type.kind == pointerType || type.kind == arrayType)
6426 ListSymbols(exp, enumOnly, string, realIdentifier);
6428 membersList.Sort(null, 1);
6433 // Virtual function override
6434 Identifier id = GetDeclId(insideFunction.declarator);
6435 char * string = id ? id.string : null;
6437 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6440 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6441 insideFunction = null;
6444 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6449 if(!didOverride) //insideFunction)
6451 rowCount = membersList.rowCount;
6454 DataRow row = string ? membersList.FindSubString(string) : null;
6455 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6457 char * newString = row.string;
6458 if(!membersListShown)
6460 membersLoc.start.line = idStart.line-1;
6461 membersLoc.start.charPos = idStart.charPos-1;
6462 //membersLoc.end = membersLoc.start;
6463 membersLoc.end.charPos = idEnd.charPos-1;
6464 membersLoc.end.line = idEnd.line-1;
6465 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6466 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6471 membersList.Destroy(0);
6472 membersListShown = false;
6475 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6477 line, membersLoc.start.line, membersLoc.start.charPos,
6478 line, membersLoc.end.line, membersLoc.end.charPos);
6479 editBox.PutS(newString);
6485 row = membersList.FindSubStringi(string);
6487 membersList.currentRow = row;
6488 membersList.currentRow.selected = false;
6491 membersList.currentRow = row;
6493 if(!membersListShown)
6497 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6498 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6499 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6500 editBox.GetCaretPosition(caret);
6501 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6503 membersList.master = this;
6505 caret.y += editBox.GetCaretSize();
6507 membersList.Create();
6510 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6511 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6512 Window parent = membersList.parent;
6514 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6516 y -= editBox.GetCaretSize() + membersList.size.h;
6517 membersAbove = true;
6520 membersAbove = false;
6522 membersList.position = { x, y };
6526 membersLoc.start.line = lineNum - 1;
6528 if(string && string[0])
6530 membersLoc.start.charPos = idStart.charPos-1;
6531 membersLoc.end = membersLoc.start;
6532 //membersLoc.end.charPos = id.loc.end.charPos-1;
6533 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6537 membersLoc.start.charPos = charPos;
6538 membersLoc.end = membersLoc.start;
6539 membersLoc.end.charPos = charPos;
6541 membersListShown = true;
6543 // Hack to keep caret shown
6544 editBox.GetCaretPosition(caret);
6545 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6548 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6554 SetCurrentContext(globalContext);
6557 return !didOverride;
6560 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6562 EditLine line = editBox.line;
6563 char * text = line.text;
6564 int lineNum, charPos;
6565 Expression exp = null;
6569 charPos = editBox.charPos + 1;
6572 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6574 EditBoxStream f { editBox = editBox };
6577 updatingCode = true;
6578 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6581 if(ch == '}' || ch == ',' || ch == ')')
6583 f.Seek(-1, current);
6591 if(!f.Seek(-1, current))
6594 if(!isspace(ch)) break;
6595 f.Seek(-1, current);
6599 f.Seek(-1, current);
6601 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6603 lineNum = editBox.lineNumber + 1;
6604 charPos = editBox.charPos + 1;
6606 updatingCode = false;
6609 charPos = Min(charPos, l1.count + 1);
6611 FindParamsTree(ast, lineNum, charPos);
6613 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6614 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6616 ::functionType = null;
6617 ::instanceType = null;
6620 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6621 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6625 Window parent = paramsList.parent;
6627 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6630 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6631 // ( Dummy exp: always ends up with same memory)
6633 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6634 editBox.GetCaretPosition(paramsPosition);
6635 this.paramsPosition.y += editBox.GetCaretSize();
6638 FreeType(this.functionType);
6639 FreeType(this.instanceType);
6641 this.functionType = ::functionType;
6642 this.instanceType = ::instanceType;
6644 if(this.functionType) this.functionType.refCount++;
6645 if(this.instanceType) this.instanceType.refCount++;
6647 this.paramsID = ::paramsID;
6648 functionExp = paramsInsideExp;
6650 paramsList.master = this;
6652 paramsList.Create();
6654 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6655 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6657 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6659 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6663 paramsAbove = false;
6664 if(x + paramsList.size.w > parent.clientSize.w)
6666 x = parent.clientSize.w - paramsList.size.w;
6670 paramsList.position = { x, y };
6672 // Hack to keep caret shown
6675 editBox.GetCaretPosition(caret);
6676 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6679 this.paramsShown = true;
6681 else if((!::functionType && !::instanceType) || reposition)
6683 paramsList.Destroy(0);
6684 paramsShown = false;
6686 FreeType(this.functionType);
6687 FreeType(this.instanceType);
6688 this.functionType = null;
6689 this.instanceType = null;
6693 SetCurrentContext(globalContext);
6701 designer.visible = true;
6702 designer.Activate();
6708 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6710 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };