3 // *** Color Schemes ***
5 // *** The Old Color Scheme that was causing me auras and ophtalmic migraines -- Uncomment at your own risk! ***
7 FontResource panelFont { $"Courier New", 10 };
8 FontResource codeFont { $"Courier New", 10 };
9 Color selectionColor = Color { 10, 36, 106 };
10 Color selectionText = white;
11 Color viewsBackground = white;
12 Color viewsText = black;
13 Color outputBackground = white;
14 Color outputText = black;
15 Color projectViewBackground = white;
16 Color projectViewText = black;
17 Color codeEditorBG = white;
18 Color codeEditorFG = black;
19 Color marginColor = Color {230, 230, 230};
20 Color selectedMarginColor = Color {200, 200, 200};
21 Color lineNumbersColor = Color {60, 60, 60};
22 SyntaxColorScheme colorScheme
24 keywordColors = [ blue, blue ];
25 commentColor = dimGray;
26 charLiteralColor = crimson;
27 stringLiteralColor = crimson;
28 preprocessorColor = green;
33 // The new nice dark scheme -- so peaceful on my brain
35 FontResource panelFont { $"Courier New", 10 };
36 FontResource codeFont { $"Courier New", 10 };
38 FontResource panelFont { $"Consolas", 12 };
39 FontResource codeFont { $"Consolas", 12 };
41 Color selectionColor = lightYellow;
42 Color selectionText = Color { 30, 40, 50 };
43 Color viewsBackground = Color { 30, 40, 50 };
44 Color viewsText = lightGray;
45 Color outputBackground = black;
46 Color outputText = lime;
47 Color projectViewBackground = Color { 30, 40, 50 };
48 Color projectViewText = lightGray;
49 Color codeEditorBG = black;
50 Color codeEditorFG = ivory;
51 Color marginColor = Color {24, 24, 24};
52 Color selectedMarginColor = Color {64, 64, 64};
53 Color lineNumbersColor = Color {160, 160, 160};
54 SyntaxColorScheme colorScheme
56 keywordColors = [ skyBlue, skyBlue ];
57 commentColor = Color { 125, 125, 125 };
58 charLiteralColor = Color { 245, 50, 245 };
59 stringLiteralColor = Color { 245, 50, 245 };
60 preprocessorColor = { 120, 220, 140 };
61 numberColor = Color { 0, 192, 192 };
64 // *********************
70 // UNTIL IMPLEMENTED IN GRAMMAR
71 #define ACCESS_CLASSDATA(_class, baseClass) \
72 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
75 extern int __attribute__((__stdcall__)) __ecereDll_Load_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
76 extern int __attribute__((__stdcall__)) __ecereDll_Unload_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
79 static Array<FileFilter> fileFilters
81 { $"C/C++/eC Files (*.ec, *.eh, *.c, *.cpp, *.cc, *.cxx, *.h, *.hpp, *.hh, *.hxx)", "ec, eh, c, cpp, cc, cxx, h, hpp, hh, hxx" },
82 { $"Header Files for C/C++ (*.eh, *.h, *.hpp, *.hh, *.hxx)", "eh, h, hpp, hh, hxx" },
83 { $"C/C++/eC Source Files (*.ec, *.c, *.cpp, *.cc, *.cxx)", "ec, c, cpp, cc, cxx" },
84 { $"Text files (*.txt)", "txt" },
85 { $"All files", null }
88 static Array<FileType> fileTypes
90 { $"eC Source Code", "ec", whenNoneGiven },
91 { $"Text Files", "txt", never }
94 static const 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;
123 bool ignoreBreakpoints:1;
125 bool oldImplementation:1;
128 class EditFileDialog : FileDialog
132 if(!ide.projectView && ideSettings.ideFileDialogLocation)
133 currentDirectory = ideSettings.ideFileDialogLocation;
134 return FileDialog::OnCreate();
138 EditFileDialog codeEditorFileDialog
140 type = multiOpen, text = $"Open",
141 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType);
142 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
145 EditFileDialog codeEditorFormFileDialog
147 type = open, text = $"Open Project",
148 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType),
149 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
152 define OpenBracket = '{';
153 define CloseBracket = '}';
158 actionDeleteMethod = 2,
159 actionDetachMethod = 3,
160 actionAttachMethod = 4,
161 actionReattachMethod = 5
164 //extern StatusField pos, ovr, caps, num;
165 //extern Class thisClass;
174 Expression ctxInsideExp;
175 Expression paramsInsideExp;
176 ClassFunction insideFunction;
179 const char * instanceName;
184 /****************************************************************************
186 ****************************************************************************/
188 static void OutputString(File f, const char * string)
191 for(c = 0; string[c]; c++)
193 if(string[c] == '\"')
195 else if(string[c] == '\\')
197 else if(string[c] == '\n')
208 // Consider merging with PrintType ?
209 void OutputType(File f, Type type, bool outputName)
213 if(type.kind != pointerType && type.constant)
221 if(!type.isSigned) f.Printf("unsigned ");
225 if(!type.isSigned) f.Printf("unsigned ");
229 if(!type.isSigned) f.Printf("unsigned ");
233 if(!type.isSigned) f.Printf("unsigned ");
237 if(!type.isSigned) f.Printf("unsigned ");
248 if(type._class && !strcmp(type._class.string, "class"))
250 switch(type.classObjectType)
253 f.Printf("any_object");
256 f.Printf("typed_object");
263 // ADD CODE TO DECIDE WHETHER TO OUTPUT FULLY QUAlIFIED OR NOT:
264 f.Printf(type._class.shortName ? type._class.shortName : type._class.string);
274 OutputType(f, type.type, false);
277 OutputType(f, type.type, false);
298 if(type.kind == arrayType)
301 f.Printf("%d", type.arraySize);
307 void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
313 f.Seek(pos - *position, current);
315 // Try to delete spaces and \n before...
321 /*else if(ch == '\n')
323 // Look for // comments on the line before
324 EditBox editBox = f.editBox;
325 EditLine line = editBox.line;
332 for(c = 0; text[c]; c++)
341 if(text[c] == '/' && last == '/')
353 f.DeleteBytes(before);
358 void GetLocText(EditBox editBox, File f, int position, Location loc, char ** text, int * size, int pad, int linePad)
363 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
365 // Cut & Paste function
371 f.Seek(loc.start.pos - position, current);
373 x1 = editBox.charPos;
374 y1 = editBox.lineNumber;
375 f.Seek(loc.end.pos - loc.start.pos, current);
377 x2 = editBox.charPos;
378 y2 = editBox.lineNumber;
379 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
381 *size = editBox.SelSize();
382 *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
383 editBox.GetSel(*text, false);
386 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
387 f.Printf(""); // Make the stream point to where the editbox is
390 static int64 GetI64EnumValue(Class dataType, DataValue dataForm)
393 switch(dataType.typeSize)
396 if(!strcmp(dataType.dataTypeString, "byte"))
397 i64Value = dataForm.uc;
399 i64Value = dataForm.c;
402 if(!strcmp(dataType.dataTypeString, "uint16"))
403 i64Value = dataForm.us;
405 i64Value = dataForm.s;
408 if(!strcmp(dataType.dataTypeString, "uint"))
409 i64Value = dataForm.ui;
411 i64Value = dataForm.i;
414 if(!strcmp(dataType.dataTypeString, "uint64"))
415 i64Value = *(int64 *)&dataForm.ui64;
417 i64Value = dataForm.i64;
423 void Code_FixProperty(Property prop, Instance object)
425 Designer::FixProperty(prop, object);
428 bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
431 if(prop.dataTypeString && (!prop.IsSet || prop.IsSet(selected.instance)))
433 Class dataType = prop.dataTypeClass;
436 dataType = prop.dataTypeClass = eSystem_FindClass(test._class.module, prop.dataTypeString);
438 if(dataType && dataType._vTbl && dataType.type == structClass)
440 void * dataForm = new0 byte[dataType.structSize];
441 void * dataTest = new0 byte[dataType.structSize];
443 ((void (*)(void *, void *))(void *)prop.Get)(selected.instance, dataForm);
444 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
446 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
448 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
454 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
456 void * dataForm, * dataTest;
457 bool isEditBoxContents = false;
458 bool freeDataForm = false, freeDataTest = false;
460 // Because contents property is broken for mutiline EditBox at the moment
461 if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox"))
462 isEditBoxContents = true;
464 if(isEditBoxContents && ((EditBox)selected.instance).multiLine)
466 dataForm = ((EditBox)selected.instance).multiLineContents;
470 dataForm = ((void *(*)(void *))(void *)prop.Get)(selected.instance);
471 if(isEditBoxContents && ((EditBox)test).multiLine)
473 dataTest = ((EditBox)test).multiLineContents;
477 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
479 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
481 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
485 // Temporary work around until we standardize how properties should manage memory
486 if(!strcmp(prop.name, "strings") && !strcmp(prop._class.name, "DirectoriesBox"))
487 freeDataForm = freeDataTest = true;
488 if(dataType.type == normalClass && dataType.structSize)
490 if(freeDataForm) eInstance_Delete(dataForm);
491 if(freeDataTest) eInstance_Delete(dataTest);
495 if(freeDataForm) delete dataForm;
496 if(freeDataTest) delete dataTest;
499 else if(dataType && dataType._vTbl)
501 DataValue dataForm, dataTest;
503 GetProperty(prop, selected.instance, &dataForm);
504 GetProperty(prop, test, &dataTest);
506 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
508 SetProperty(prop, test, dataForm);
510 // In case setting on test unset on real instance (e.g. isDefault)
511 if(strcmp(prop.name, "name"))
513 GetProperty(prop, selected.instance, &dataTest);
514 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
515 SetProperty(prop, selected.instance, dataForm);
524 bool Code_IsPropertyDisabled(ObjectInfo selected, const char * name)
526 bool disabled = false;
527 if(selected.oClass == selected)
530 if(selected.classDefinition)
532 for(def = selected.classDefinition.definitions->first; def; def = def.next)
534 if(def.type == defaultPropertiesClassDef)
537 for(prop = def.defProperties->first; prop; prop = prop.next)
539 if(prop.identifiers && prop.identifiers->first)
541 Identifier id = prop.identifiers->first;
542 if(prop.variable && !strcmp(id.string, name))
554 else if(selected.instCode)
557 if(selected.instCode.members)
559 for(members = selected.instCode.members->first; members; members = members.next)
561 if(members.type == dataMembersInit && members.dataMembers)
564 for(prop = members.dataMembers->first; prop; prop = prop.next)
566 if(prop.identifiers && prop.identifiers->first)
568 Identifier id = prop.identifiers->first;
569 if(prop.variable && !strcmp(id.string, name))
584 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
589 method.dataType = ProcessTypeString(method.dataTypeString, false);
590 if(!method.dataType.thisClass && !isForm)
593 method.dataType.thisClass = selectedClass;
595 //result = MatchTypes(method.dataType, type, null, regClass, regClass, false);
596 result = MatchTypes(type, method.dataType, null, regClass, regClass, false, true, true, false, true);
598 method.dataType.thisClass = null;
602 bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo object)
604 bool confirmation = true;
605 Statement body = function.body;
606 // Check if it contains any code
607 if((!body.compound.declarations || !body.compound.declarations->count) && (!body.compound.statements || body.compound.statements->count <= 1))
609 // Class moduleClass = eSystem_FindClass(object.instance._class.module, "Module");
610 Statement stmt = body.compound.statements ? body.compound.statements->first : null;
611 Type dataType = method.dataType;
612 Type returnType = dataType.returnType;
613 Expression exp = null;
616 method.dataType = ProcessTypeString(method.dataTypeString, false);
618 confirmation = false;
620 // Check if default function should be calling base class:
621 if(object.instance._class._vTbl[method.vid] == null /*moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]*/) // Temp Check for DefaultFunction
623 if(returnType.kind != voidType)
625 if(!stmt || stmt.type != returnStmt || !stmt.expressions || stmt.expressions->count != 1)
629 exp = stmt.expressions->first;
630 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
632 if( (exp.type != identifierExp || strcmp(exp.identifier.string, "true")) &&
633 (exp.type != constantExp || strcmp(exp.constant, "1")))
638 if(exp.type != constantExp || strcmp(exp.constant, "0"))
653 if(returnType.kind != voidType)
655 if(stmt.type == returnStmt && stmt.expressions && stmt.expressions->count == 1)
656 exp = stmt.expressions->first;
658 else if(stmt.type == expressionStmt && stmt.expressions && stmt.expressions->count == 1)
659 exp = stmt.expressions->first;
662 if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
666 Identifier id = exp.call.exp.identifier;
667 Class base = object.instance._class;
668 if(!id._class || (id._class.name && !strcmp(id._class.name, base.name)) || strcmp(id.string, method.name))
672 Expression arg = exp.call.arguments ? exp.call.arguments->first : null;
673 if(!arg || arg.type != identifierExp || strcmp("this", arg.identifier.string))
679 for(param = dataType.params.first; param; param = param.next)
681 if(!arg || arg.type != identifierExp || strcmp(param.name, arg.identifier.string))
686 arg = arg ?arg.next : null;
693 return !confirmation;
696 class CodeEditor : Window
698 background = marginColor;
699 borderStyle = sizableDeep;
704 isActiveClient = true;
705 anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
708 // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
709 // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
711 SheetType sheetSelected;
716 Context globalContext { };
717 OldList excludedSymbols { offset = (uint)(uintptr)&((Symbol)0).left };
730 MethodAction methodAction;
732 ClassFunction function;
734 char methodName[1024];
739 bool membersListShown;
742 EditLine membersLine;
744 Type functionType, instanceType;
748 Point paramsPosition;
749 Expression functionExp;
752 BitmapResource icons[CodeObjectType];
754 FontResource boldFont { $"Tahoma", 8.25f, bold = true, window = this };
755 FontResource normalFont { $"Tahoma", 8.25f, window = this };
757 Module privateModule;
758 NameSpace globalData;
761 OpenedFileInfo openedFileInfo;
763 FontResource font { codeFont.faceName, codeFont.size, codeFont.bold, codeFont.italic };
764 saveDialog = codeEditorFileDialog;
766 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
769 int maxLineNumberLength;
771 property bool parsing { get { return editBox.syntaxHighlighting && !noParsing && !ide.noParsing; } };
773 void ProcessCaretMove(EditBox editBox, int line, int charPos)
776 ObjectInfo classItem;
778 // OnActivateClient is called after OnActivate
781 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
784 if(sheet.codeEditor != this) return;
788 for(classItem = classes.first; classItem; classItem = classItem.next)
790 ClassDefinition classDef = classItem.classDefinition;
791 if(classDef && classDef.loc.Inside(line, charPos))
798 for(object = classItem.instances.first; object; object = object.next)
802 if(object.instCode.loc.Inside(line, charPos))
807 sheet.SelectObject(object);
809 sheet.SelectObject(classItem);
814 //sheet.SelectObject(null);
818 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
822 expectingMove = false;
828 if(line-1 != membersLoc.start.line)
834 if(charPos - 1 < membersLoc.start.charPos)
836 else if(charPos - 1 > membersLoc.end.charPos)
838 const char * buffer = membersLine.text;
839 //if(membersList.currentRow)
843 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
844 if(buffer[c] != ' ' && buffer[c] != '\t')
846 if(c < charPos && buffer[c])
853 membersList.Destroy(0);
854 membersListShown = false;
858 bool back = codeModified;
859 codeModified = false;
861 InvokeParameters(false, false, false);
862 /*if(membersListShown)
863 InvokeAutoComplete(false, 0, true);*/
870 watch(modifiedDocument)
872 ProjectView projectView = ide.projectView;
875 char buffer[MAX_LOCATION];
876 char * fullPath = GetSlashPathBuffer(buffer, fileName);
877 Array<ProjectNode> nodes = ide.workspace.GetAllProjectNodes(fullPath, false);
881 node.modified = modifiedDocument;
882 projectView.Update(null);
891 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
892 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
893 tabKey = true, smartHome = true;
894 tabSelection = true, /*maxLineSize = 65536, */parent = this, hasHorzScroll = true, hasVertScroll = true;
895 selectionColor = selectionColor, selectionText = selectionText,
896 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
897 font = font, borderStyle = none;
898 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
900 bool OnMouseOver(int x, int y, Modifiers mods)
902 CodeEditor editor = (CodeEditor)master;
903 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
908 void NotifyCaretMove(EditBox editBox, int line, int charPos)
910 // Update Line Numbers
912 int oldLine = lastLine;
913 display.FontExtent(font.font, " ", 1, null, &spaceH);
915 Box box { 0, (oldLine-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, oldLine*spaceH-1 - editBox.scroll.y };
919 Box box { 0, (line-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, line*spaceH-1 - editBox.scroll.y };
924 if(ide.activeClient == this)
925 ProcessCaretMove(editBox, line, charPos);
927 openedFileInfo.CaretMove(line, charPos);
930 void NotifyOvrToggle(EditBox editBox, bool overwrite)
932 ide.UpdateStateLight(ide.ovr, overwrite);
935 void NotifyUpdate(EditBox editBox)
942 designer.modifiedDocument = true;
945 modifiedDocument = true;
948 bool NotifyUnsetModified(EditBox editBox)
950 modifiedDocument = false;
954 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
956 if(!loadingFile && after.y != before.y)
958 ProjectView projectView = ide.projectView;
959 if(projectView && fileName)
962 // HOW WE MIGHT WANT TO DO IT:
963 const char * text = before.line.text;
964 for(c = Min(before.line.count, before.x-1); c>= 0; c--)
965 if(!isspace(text[c]))
967 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
969 // HOW VISUAL STUDIO DOES IT:
971 char * text = after.line.text;
972 for(c = after.line.count-1; c>= 0; c--)
973 if(!isspace(text[c]))
975 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
978 Update({ 0, 0, editBox.position.x, clientSize.h });
986 for(oClass = classes.first; oClass; oClass = oClass.next)
989 for(object = oClass.instances.first; object; object = object.next)
993 object.instCode.loc.start.AdjustAdd(before, after);
994 object.instCode.loc.end.AdjustAdd(before, after);
999 oClass.classDefinition.loc.start.AdjustAdd(before, after);
1000 oClass.classDefinition.loc.end.AdjustAdd(before, after);
1006 expectingMove = true;
1007 if(membersListShown)
1010 if(before.y != after.y)
1014 const char * buffer = membersLine.text;
1016 bool firstChar = true;
1017 bool addedChar = false;
1023 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
1025 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1027 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1028 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
1037 membersLoc.start.charPos++;
1042 string[len++] = buffer[c];
1046 row = membersList.currentRow;
1047 if(row && row.selected)
1051 membersLoc.start.charPos--;
1059 row = membersList.FindSubString(string);
1061 membersList.currentRow = row;
1064 row = membersList.FindSubStringi(string);
1066 membersList.currentRow = row;
1067 membersList.currentRow.selected = false;
1070 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
1074 row = membersList.currentRow;
1077 // Accept current string if hiding typing char
1078 if(hide && row && row.selected)
1080 const char * string = row.string;
1081 int len = strlen(string);
1082 membersLoc.end.charPos -= after.x - before.x;
1083 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1084 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
1085 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1086 editBox.PutS(string);
1087 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
1089 after.x += membersLoc.start.charPos + len - before.x;
1090 before.x = membersLoc.start.charPos + len;
1095 membersList.Destroy(0);
1096 membersListShown = false;
1099 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
1101 EditLine line = editBox.line;
1102 const char * text = line.text;
1103 char ch = text[after.x-1];
1104 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1108 // Can we call invoke auto complete here instead?
1118 // Force caret update already...
1119 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1120 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1122 editBox.GetCaretPosition(&caret);
1126 // Go back in the buffer until no space before
1128 codeModified = true;
1132 EditBoxStream f { editBox = editBox };
1136 if(text[after.x-1] == '>')
1142 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1146 if(!f.Seek(-1, current))
1149 if(!isspace(ch)) break;
1150 f.Seek(-1, current);
1152 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1154 line = editBox.lineNumber + 1;
1155 charPos = editBox.charPos + 1;
1159 exp = FindExpTree(ast, line, charPos);
1163 Type type = exp.expType;
1165 if(type && text[after.x-1] != '.')
1167 if(type.kind == TypePointer || type.kind == TypeArray)
1173 membersList.Clear();
1176 if(membersList.rowCount)
1178 membersList.Sort(null, 1);
1179 membersList.master = this;
1181 caret.y += editBox.GetCaretSize();
1184 membersList.Create();
1187 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1188 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1189 Window parent = membersList.parent;
1191 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1193 y -= editBox.GetCaretSize() + membersList.GetHeight();
1194 membersAbove = true;
1197 membersAbove = false;
1199 membersList.position = { x, y };
1203 membersLoc.start.line = line - 1;
1204 membersLoc.start.charPos = oldCharPos;
1205 membersLoc.end = membersLoc.start;
1206 membersListShown = true;
1211 SetCurrentContext(globalContext);
1213 codeModified = true;
1214 skipModified = true;
1215 if(text[after.x-1] == ':')
1216 InvokeAutoComplete(false, 0, false);
1217 else if(text[after.x-1] == '.')
1218 InvokeAutoComplete(false, 1, false);
1219 else if(text[after.x-1] == '>')
1220 InvokeAutoComplete(false, 2, false);
1221 skipModified = false;
1223 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1225 codeModified = true;
1226 skipModified = true;
1228 if(InvokeAutoComplete(true, 0, false))
1230 if(ch == '(' || ch == OpenBracket)
1231 InvokeParameters(true, true, false);
1233 InvokeParameters(this.functionType ? false : true, false, false);
1236 // InvokeAutoComplete(true, 0, false);
1237 skipModified = false;
1239 else if(ch == ')' || ch == '}' || ch == ';')
1241 codeModified = true;
1242 skipModified = true;
1244 InvokeParameters(false, true, false);
1245 skipModified = false;
1249 bool back = codeModified;
1250 codeModified = false;
1252 InvokeParameters(false, false, true);
1253 if(membersListShown)
1254 InvokeAutoComplete(false, 0, true);
1255 codeModified = back;
1260 bool back = codeModified;
1261 codeModified = false;
1264 InvokeParameters(false, false, true);
1265 /*if(membersListShown)
1266 InvokeAutoComplete(false, 0, true);*/
1268 codeModified = back;
1275 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1277 if(!loadingFile && after.y != before.y)
1279 ProjectView projectView = ide.projectView;
1280 if(projectView && fileName)
1281 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1282 Update({ 0, 0, editBox.position.x, clientSize.h });
1290 for(oClass = classes.first; oClass; oClass = oClass.next)
1294 for(object = oClass.instances.first; object; object = object.next)
1298 loc = &object.instCode.loc;
1300 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1301 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1303 object.instCode = null;
1307 loc->start.AdjustDelete(before, after);
1308 loc->end.AdjustDelete(before, after);
1312 if(oClass.classDefinition)
1314 loc = &oClass.classDefinition.loc;
1315 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1316 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1318 oClass.classDefinition = null;
1322 loc->start.AdjustDelete(before, after);
1323 loc->end.AdjustDelete(before, after);
1328 if(membersListShown)
1331 if(pasteOperation || before.y != after.y)
1335 const char * buffer = membersLine.text;
1337 bool firstChar = true;
1341 if(before.x >= membersLoc.start.charPos)
1343 for(c = membersLoc.start.charPos; c<before.x && len < sizeof(string)-1; c++)
1345 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1346 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1351 if(!isSpace) firstChar = false;
1354 string[len++] = buffer[c];
1359 // If deleting spaces before...
1360 for(c = before.x; c<membersLoc.start.charPos; c++)
1362 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1370 membersLoc.start.charPos = before.x;
1373 if(membersLoc.end.charPos >= after.x)
1375 for(c = after.x; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1377 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1378 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1383 if(!isSpace) firstChar = false;
1386 string[len++] = buffer[c];
1394 membersLoc.end.charPos -= after.x - before.x;
1398 row = membersList.FindSubString(string);
1401 row = membersList.FindSubStringi(string);
1403 membersList.currentRow = row;
1404 membersList.currentRow.selected = false;
1407 membersList.currentRow = row;
1409 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1414 membersList.Destroy(0);
1415 membersListShown = false;
1421 InvokeParameters(false, false);
1429 bool NotifyDropped(EditBox editBox, int x, int y)
1431 char * controlClass = toolBox.controlClass;
1432 if(controlClass && controlClass[0])
1436 ObjectInfo classObject;
1438 editBox.GoToLineNum(y);
1439 x = Min(x, editBox.line.count);
1440 editBox.GoToPosition(editBox.line, y, x);
1441 // Note: Uncommented this to drag objects after the member instance on which they are dropped
1442 editBox.NotifyCaretMove(this, editBox, y+1, x+1);
1444 classObject = selected ? selected.oClass : null;
1446 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1447 selected = classObject.instances.last;
1450 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1453 AddObject(control, &object);
1455 designer.CreateObject(control, object, false, classObject.instance);
1456 // designer.PostCreateObject(control, object, false, classObject.instance);
1457 designer.DroppedObject(control, object, false, classObject.instance);
1459 sheet.AddObject(object, object.name, typeData /* className*/, true);
1462 //codeModified = true;
1469 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1471 if(key == ctrlSpace)
1473 membersList.Destroy(0);
1474 membersListShown = false;
1475 InvokeAutoComplete(false, 0, false);
1478 else if(key == Key { space, ctrl = true, shift = true })
1479 InvokeParameters(false, true, false);
1480 else if(key == escape)
1481 ide.RepositionWindows(true);
1482 else if(key == ctrlF7)
1486 ProjectNode node = ide.projectView.GetNodeForCompilationFromWindow(this, false, null, null);
1490 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1491 $"It can't be compiled.");
1492 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1501 bool OnKeyDown(Key key, unichar ch)
1503 CodeEditor editor = (CodeEditor)master;
1504 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1506 if(editor.membersListShown)
1508 editor.membersList.Destroy(0);
1509 editor.membersListShown = false;
1512 if(editor.paramsShown)
1514 editor.paramsList.Destroy(0);
1515 editor.paramsShown = false;
1516 FreeType(editor.functionType);
1517 FreeType(editor.instanceType);
1519 editor.functionType = null;
1520 editor.instanceType = null;
1521 editor.paramsID = -1;
1525 return EditBox::OnKeyDown(key, ch);
1528 void OnVScroll(ScrollBarAction action, int position, Key key)
1530 if(anchor.left.distance)
1532 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1535 EditBox::OnVScroll(action, position, key);
1537 CodeEditor ce = (CodeEditor)parent;
1538 if(ce.openedFileInfo)
1539 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1543 void OnHScroll(ScrollBarAction action, int position, Key key)
1545 EditBox::OnHScroll(action, position, key);
1547 CodeEditor ce = (CodeEditor)parent;
1548 if(ce.openedFileInfo)
1549 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1556 fullRowSelect = false,
1559 borderStyle = bevel;
1560 // size = { 200, 400 };
1562 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1564 DataRow row = listBox.currentRow;
1567 const char * string = row.string;
1569 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1571 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1572 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1573 editBox.PutS(string);
1576 membersListShown = false;
1581 bool OnKeyDown(Key key, unichar ch)
1583 CodeEditor editor = (CodeEditor) master;
1584 if(key == escape || key == leftAlt || key == rightAlt ||
1585 (key.ctrl && key.code != left && key.code != right &&
1586 key.code != leftShift && key.code != rightShift && key.code != space))
1589 if(editor.paramsShown)
1593 editor.paramsList.Destroy(0);
1594 editor.paramsShown = false;
1596 if(editor.membersListShown)
1600 editor.membersList.Destroy(0);
1601 editor.membersListShown = false;
1604 FreeType(editor.functionType);
1605 editor.functionType = null;
1607 FreeType(editor.instanceType);
1608 editor.instanceType = null;
1610 editor.paramsID = -1;
1615 return editor.editBox.OnKeyDown(key, ch);
1619 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1621 CodeEditor editor = (CodeEditor)master;
1622 Window rw = previous ? previous.rootWindow : null;
1623 if(!active && rw != editor.paramsList)
1626 editor.membersListShown = false;
1628 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1631 bool OnKeyHit(Key key, unichar ch)
1633 CodeEditor editor = (CodeEditor) master;
1637 case enter: case tab:
1639 DataRow row = currentRow;
1640 if(row && row.selected)
1642 const char * string = row.string;
1644 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1645 editor.editBox.Delete(
1646 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1647 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1648 editor.editBox.PutS(string);
1651 editor.membersListShown = false;
1654 editor.editBox.OnKeyHit(key, ch);
1664 return ListBox::OnKeyHit(key, ch);
1670 // If before . or after
1671 //listBox.Destroy(true);
1672 result = editor.editBox.OnKeyHit(key, ch);
1687 clickThrough = true,
1689 borderStyle = contour,
1691 background = { 255,255,225 },
1693 OnKeyDown = membersList.OnKeyDown;
1695 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1697 CodeEditor editor = (CodeEditor)master;
1698 Window rw = previous ? previous.rootWindow : null;
1699 if(!active && previous != editor.editBox && rw != editor.membersList)
1702 editor.paramsShown = false;
1704 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1707 bool OnKeyHit(Key key, unichar ch)
1709 CodeEditor editor = (CodeEditor)master;
1711 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1714 bool result = true; editor.editBox.OnKeyHit(key, ch);
1715 return (!created) ? false : result;
1722 void OnRedraw(Surface surface)
1724 CodeEditor editor = (CodeEditor) master;
1725 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1727 Type methodType = null;
1731 int functionW, nameW = 0;
1733 int spaceW, spaceH, commaW, commaWB, parW;
1735 int maxW = 0, lineW = 0;
1741 Font font = editor.normalFont.font;
1742 Font boldFont = editor.boldFont.font;
1743 Display display = this.display;
1745 if(!type) { return; };
1747 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1749 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1750 display.FontExtent(font, ", ", 2, &commaW, null);
1751 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1752 display.FontExtent(font, ")", 1, &parW, null);
1755 if(editor.functionType && type.kind == functionType)
1757 PrintType(type.returnType, string, true, true);
1758 display.FontExtent(font, string, strlen(string), &functionW, null);
1760 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1761 totalW = nameW + functionW + 2 * parW;
1765 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1766 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1767 if(instanceName && type.kind != functionType)
1768 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1769 totalW = functionW + nameW;
1770 surface.TextFont(boldFont);
1773 surface.WriteText(x, y, string, strlen(string));
1774 x += functionW + spaceW;
1776 if(editor.functionType)
1779 surface.WriteText(x, y, type.name, strlen(type.name));
1781 surface.WriteText(x, y, "(", 1);
1784 if(methodType && !methodType.staticMethod && methodType.methodClass)
1788 if(id == editor.paramsID)
1789 surface.TextFont(boldFont);
1791 if(methodType.methodClass)
1792 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1796 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1797 width += ((id == editor.paramsID) ? commaWB : commaW);
1802 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1807 x = 2 + nameW + spaceW + functionW + parW;
1811 if(methodType.methodClass)
1812 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1815 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1817 surface.WriteText(x, y, ",", 1);
1818 x += ((id == editor.paramsID) ? commaWB : commaW);
1826 if(id == editor.paramsID)
1827 surface.TextFont(font);
1831 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1833 for(param = type.params.first; param; param = param.next)
1835 char paramString[1024];
1838 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1839 surface.TextFont(boldFont);
1842 PrintType(param, paramString, true, true);
1843 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1845 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1850 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1855 x = 2 + nameW + spaceW + functionW + parW;
1859 surface.WriteText(x, y, paramString, strlen(paramString));
1863 surface.WriteText(x, y, ",", 1);
1864 x += ((id == editor.paramsID) ? commaWB : commaW);
1872 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1873 surface.TextFont(font);
1878 surface.WriteText(x, y, ")", 1);
1880 else if(instanceName && type.kind != functionType)
1882 surface.WriteText(x, y, instanceName, strlen(instanceName));
1886 bool OnResizing(int * w, int * h)
1888 CodeEditor editor = (CodeEditor) master;
1889 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1891 Type methodType = null;
1895 int functionW = 0, nameW = 0;
1897 int spaceW, spaceH, commaW, commaWB, parW;
1899 int maxW = 0, lineW = 0;
1904 Font font = editor.normalFont.font;
1905 Font boldFont = editor.boldFont.font;
1906 Display display = this.display;
1908 if(type.kind == TypeKind::methodType)
1911 ProcessMethodType(type.method);
1912 type = type.method.dataType;
1915 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1916 display.FontExtent(font, ", ", 2, &commaW, null);
1917 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1918 display.FontExtent(font, ")", 1, &parW, null);
1921 if(editor.functionType && type && type.kind == functionType)
1923 PrintType(type.returnType, string, true, true);
1924 display.FontExtent(font, string, strlen(string), &functionW, null);
1926 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1927 totalW = nameW + spaceW + functionW + 2 * parW;
1931 PrintType(type, string, false, true); // /*true);
1932 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1933 if(instanceName && type.kind != functionType)
1934 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1935 totalW = functionW + nameW + spaceW;
1938 if(editor.functionType)
1944 if(methodType.methodClass)
1945 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1946 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1947 width += ((id == editor.paramsID) ? commaWB : commaW);
1952 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1965 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1967 for(param = type.params.first; param; param = param.next)
1969 char paramString[1024];
1973 PrintType(param, paramString, true, true);
1974 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1976 width += ((id == editor.paramsID) ? commaWB : commaW);
1981 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1998 *w = realW + totalW + 4;
2004 Menu fileMenu { menu, $"File", f };
2005 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
2006 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
2008 Menu editMenu { menu, $"Edit", e };
2009 MenuDivider { editMenu };
2010 MenuItem clearTrailingSpacesItem
2012 editMenu, $"Clear trailing spaces", t, Key { t, ctrl = true, shift = true };
2014 bool NotifySelect(MenuItem selection, Modifiers mods)
2016 // Nuke trailing spaces
2019 editBox.recordUndoEvent = true;
2020 for(line = editBox.firstLine; line; line = line.next, y++)
2022 const String buffer = line.text;
2023 int count = line.count, i = count-1;
2024 while(i >= 0 && isspace(buffer[i])) i--;
2026 editBox.Delete(line, y, i + 1, line, y, count);
2028 editBox.recordUndoEvent = false;
2033 Menu debugMenu { menu, $"Debug", d };
2034 MenuItem debugRunToCursor { debugMenu, $"Run To Cursor", c, ctrlF10, id = RTCMenuBits { false, false, false }, NotifySelect = RTCMenu_NotifySelect; };
2035 MenuItem debugSkipRunToCursor { debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true }, id = RTCMenuBits { true, false, false }, NotifySelect = RTCMenu_NotifySelect; };
2036 MenuItem debugRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level", l, altF10, id = RTCMenuBits { false, true, false }, NotifySelect = RTCMenu_NotifySelect; };
2037 MenuItem debugSkipRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level Skipping Breakpoints", g, Key { f10, shift = true, alt = true }, id = RTCMenuBits { true, true, false }, NotifySelect = RTCMenu_NotifySelect; };
2039 MenuItem debugBpRunToCursor { debugMenu, $"BP Run To Cursor"/*, c, ctrlF10*/, id = RTCMenuBits { false, false, true }, NotifySelect = RTCMenu_NotifySelect; };
2040 MenuItem debugBpSkipRunToCursor { debugMenu, $"BP Run To Cursor Skipping Breakpoints"/*, u, Key { f10, ctrl = true, shift = true }*/, id = RTCMenuBits { true, false, true }, NotifySelect = RTCMenu_NotifySelect; };
2041 MenuItem debugBpRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level"/*, l, altF10*/, id = RTCMenuBits { false, true, true }, NotifySelect = RTCMenu_NotifySelect; };
2042 MenuItem debugBpSkipRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level Skipping Breakpoints"/*, g, Key { f10, shift = true, alt = true }*/, id = RTCMenuBits { true, true, true }, NotifySelect = RTCMenu_NotifySelect; };
2044 bool RTCMenu_NotifySelect(MenuItem selection, Modifiers mods)
2046 ProjectView projectView = ide.projectView;
2047 if(!projectView.buildInProgress)
2049 RTCMenuBits bits = (RTCMenuBits)selection.id;
2050 int line = editBox.lineNumber + 1;
2053 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2054 ProjectConfig config = projectView.project.config;
2055 int bitDepth = ide.workspace.bitDepth;
2056 bool useValgrind = ide.workspace.useValgrind;
2057 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, bits.ignoreBreakpoints, bits.atSameLevel, bits.oldImplementation);
2063 MenuDivider { debugMenu };
2064 MenuItem debugToggleBreakpoint
2066 debugMenu, $"Toggle Breakpoint", t, f9;
2067 bool NotifySelect(MenuItem selection, Modifiers mods)
2069 ProjectView projectView = ide.projectView;
2070 if(projectView && fileName)
2072 int line = editBox.lineNumber + 1;
2073 ide.debugger.ToggleBreakpoint(fileName, line);
2083 //MenuItem viewDesignerItem, viewProperties, viewMethods;
2087 designer.parent = parent;
2090 toolBox = ((IDEWorkSpace)master).toolBox;
2092 // Debugger bug here: value of toolBox appears as 0
2094 sheet = ((IDEWorkSpace)master).sheet;
2099 bool OnClose(bool parentClosing)
2103 if(ide.workspace && fileName)
2104 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2105 if(inUseDebug && !debugClosing)
2107 debugClosing = true;
2109 if(CloseConfirmation(false))
2112 if(modifiedDocument)
2113 OnFileModified({ modified = true }, null);
2115 debugClosing = false;
2118 if(designer && !designer.closing)
2120 if(designer.visible)
2127 //Window formEditor = designer;
2128 //formEditor.Destroy(0);
2131 ide.AdjustFileMenus();
2136 void OnDestroy(void)
2138 ObjectInfo oClass, next;
2139 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2141 FreeType(this.functionType);
2142 FreeType(this.instanceType);
2147 designer.codeEditor = null;
2148 designer.Destroy(0);
2152 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2154 ObjectInfo object, next;
2156 for(object = oClass.instances.first; object; object = next)
2161 Designer::DestroyObject(object.instance);
2162 delete object.instance;
2164 if(object.i18nStrings)
2166 Map<String, bool> i18nStrings = object.i18nStrings;
2169 sheet.DeleteObject(object);
2171 oClass.instances.Delete(object);
2175 Designer::DestroyObject(oClass.instance);
2176 delete oClass.instance;
2178 if(oClass.i18nStrings)
2180 Map<String, bool> i18nStrings = oClass.i18nStrings;
2183 sheet.DeleteObject(oClass);
2185 classes.Delete(oClass);
2190 if(sheet.codeEditor == this)
2192 sheet.codeEditor = null;
2193 toolBox.codeEditor = null;
2199 ProjectView projectView = ide.projectView;
2202 ProjectNode node = projectView.GetNodeFromWindow(this, null, true, false, null);
2203 if(node && node.modified)
2205 node.modified = false;
2206 projectView.Update(null);
2212 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2214 // 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
2216 if(directActivation)
2217 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2219 if(active && directActivation)
2223 openedFileInfo.Activate();
2227 Location * loc = null;
2228 UpdateFormCode(); // To ensure update when modifying properties...
2230 // Got to the right spot in code so we don't lose our form selection...
2233 if(selected.instCode)
2234 loc = &selected.instCode.loc;
2235 else if(selected.classDefinition)
2236 loc = &selected.classDefinition.loc;
2238 line = editBox.lineNumber + 1;
2239 charPos = editBox.charPos + 1;
2244 if(selected && !loc->Inside(line, charPos))
2246 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2247 line = editBox.lineNumber + 1;
2248 charPos = editBox.charPos + 1;
2250 else if(selected && selected.classDefinition)
2253 for(object = selected.instances.first; object; object = object.next)
2257 if(object.instCode.loc.Inside(line, charPos))
2263 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2264 line = editBox.lineNumber + 1;
2265 charPos = editBox.charPos + 1;
2270 ProcessCaretMove(editBox, line, charPos);
2275 if(membersListShown)
2277 membersList.Destroy(0);
2278 membersListShown = false;
2282 paramsList.Destroy(0);
2283 paramsShown = false;
2284 FreeType(functionType);
2285 FreeType(instanceType);
2287 functionType = null;
2288 instanceType = null;
2295 bool OnSaveFile(const char * fileName)
2302 f = FileOpen(fileName, write);
2305 if(!ide.projectView)
2306 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2310 this.fileName = fileName; // Put this here because the form designer will check for it...
2311 designer.fileName = fileName;
2312 designer.modifiedDocument = false;
2315 editBox.Save(f, false);
2316 modifiedDocument = false;
2324 bool OnFileModified(FileChange fileChange, const char * param)
2326 bool reload = false;
2327 if(visible == false && inUseDebug == true)
2328 ide.debugger.WatchesReleaseCodeEditor();
2333 sprintf(message, $"The document %s was modified by another application.\n"
2334 "Would you like to reload it and lose your changes?", fileName);
2335 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2336 contents = message }.Modal() == yes)
2342 File f = FileOpen(fileName, read);
2345 int lineNumber, charPos, len;
2349 updatingCode = true;
2350 lineNumber = editBox.lineNumber;
2351 charPos = editBox.charPos;
2352 scroll = editBox.scroll;
2355 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2356 len = strlen(editBox.line.text);
2357 editBox.GoToLineNum(lineNumber);
2358 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2359 editBox.scroll = scroll;
2360 updatingCode = false;
2361 loadingFile = false;
2363 codeModified = true;
2367 designer.modifiedDocument = false;
2369 modifiedDocument = false;
2377 void OnRedraw(Surface surface)
2380 surface.SetBackground(marginColor);
2381 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2382 if(ideSettings.showLineNumbers)
2384 int currentLineNumber;
2386 char lineFormat[16];
2390 surface.textOpacity = false;
2391 surface.font = font.font;
2392 surface.TextExtent(" ", 1, null, &spaceH);
2393 currentLineNumber = editBox.scroll.y / spaceH + 1;
2394 sprintf(lineFormat, " %%%du", maxLineNumberLength);
2396 surface.SetForeground(lineNumbersColor);
2397 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2399 // Highlight current line
2400 if(editBox.lineNumber == currentLineNumber - 1)
2402 surface.SetBackground(selectedMarginColor);
2403 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2404 surface.SetBackground(marginColor);
2406 sprintf(lineText, lineFormat, currentLineNumber);
2407 if(currentLineNumber <= editBox.numLines)
2408 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
2409 currentLineNumber++;
2413 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2415 bool error, bpOnTopFrame, breakpointEnabled[128];
2416 int lineCursor, lineTopFrame, breakpointLines[128];
2417 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2418 Debugger debugger = ide.debugger;
2419 BitmapResource bmpRes;
2421 boxH = clientSize.h;
2422 scrollY = editBox.scroll.y;
2423 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2425 bpOnTopFrame = false;
2426 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2429 for(i = 0; i < count; i++)
2431 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2433 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2434 if(breakpointLines[i] == lineTopFrame)
2435 bpOnTopFrame = true;
2438 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2440 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2443 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2444 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2445 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2447 if(editBox.anchor.left.distance)
2449 if(editBox.horzScroll && editBox.horzScroll.visible)
2451 surface.SetBackground(control);
2452 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2457 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2462 lineY = (line - 1) * lineH;
2463 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2465 Bitmap bitmap = resource.bitmap;
2467 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2474 char ext[MAX_EXTENSION];
2475 const char * fileName = property::fileName;
2477 if(SearchString(fileName, 0, "Makefile", false, true))
2478 editBox.useTab = true;
2479 designer.fileName = fileName;
2483 GetExtension(fileName, ext);
2485 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2486 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2487 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2488 editBox.syntaxHighlighting = true;
2490 editBox.syntaxHighlighting = false;
2492 if(parsing && !strcmpi(ext, "ec"))
2494 codeModified = true;
2498 maxLineNumberLength = 0;
2503 bool UpdateMarginSize()
2505 if(ideSettings.showLineNumbers)
2507 int numLen = Max(4, nofdigits(editBox.numLines));
2509 maxLineNumberLength = numLen;
2510 display.FontExtent(font.font, "0", 1, &digitWidth, null);
2511 editBox.anchor = Anchor
2513 left = editBox.syntaxHighlighting * 20 + ideSettings.showLineNumbers * (maxLineNumberLength+2) * digitWidth,
2514 right = 0, top = 0, bottom = 0
2519 maxLineNumberLength = 0;
2520 editBox.anchor = Anchor
2522 left = editBox.syntaxHighlighting * 20,
2523 right = 0, top = 0, bottom = 0
2535 bool LoadFile(const char * filePath)
2537 File f = FileOpen(filePath, read);
2540 // Added this here...
2541 fileName = filePath;
2543 updatingCode = true;
2545 updatingCode = false;
2546 loadingFile = false;
2555 void AdjustDebugMenus()
2557 bool unavailable = ide.areDebugMenusUnavailable;
2558 bool isNotNotRunning = unavailable || ide.isDebuggerRunning;
2559 bool isNotStopped = unavailable || !ide.isDebuggerStopped;
2560 bool noBreakpointToggle = ide.isBreakpointTogglingUnavailable;
2562 debugRunToCursor.disabled = isNotNotRunning;
2563 debugSkipRunToCursor.disabled = isNotNotRunning;
2564 debugRunToCursorAtSameLevel.disabled = isNotStopped;
2565 debugSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2567 debugBpRunToCursor.disabled = isNotNotRunning;
2568 debugBpSkipRunToCursor.disabled = isNotNotRunning;
2569 debugBpRunToCursorAtSameLevel.disabled = isNotStopped;
2570 debugBpSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2572 debugToggleBreakpoint.disabled = noBreakpointToggle;
2579 globalData.classes.CompareKey = (void *)BinaryTree::CompareString;
2580 globalData.defines.CompareKey = (void *)BinaryTree::CompareString;
2581 globalData.functions.CompareKey = (void *)BinaryTree::CompareString;
2582 globalData.nameSpaces.CompareKey = (void *)BinaryTree::CompareString;
2585 designer.fileName = fileName;
2591 sprintf(title, $"Untitled %d", documentID);
2592 // designer.fileName = CopyString(title);
2593 designer.fileName = title;
2598 for(c = 0; c < CodeObjectType::enumSize; c++)
2599 icons[c] = BitmapResource { iconNames[c], window = this };
2601 codeModified = true;
2613 selected.modified = true;
2614 selected.oClass.modified = true;
2616 designer.modifiedDocument = true;
2617 modifiedDocument = true;
2618 formModified = true;
2621 /****************************************************************************
2623 ****************************************************************************/
2627 Class windowClass = eSystem_FindClass(privateModule, "ecere::gui::Window");
2628 if(windowClass && windowClass.data)
2629 UnapplySkin(windowClass);
2632 SetCurrentNameSpace(null);
2638 defines.Free(FreeModuleDefine);
2639 imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2641 FreeExcludedSymbols(excludedSymbols);
2642 FreeContext(globalContext);
2644 FreeGlobalData(&globalData);
2645 FindCtx_Terminate();
2646 FindParams_Terminate();
2648 if(GetGlobalContext() == globalContext)
2650 SetGlobalData(null);
2651 SetGlobalContext(null);
2652 SetExcludedSymbols(null);
2653 SetTopContext(null);
2654 SetCurrentContext(null);
2657 SetPrivateModule(null);
2660 // Note: This code should probably be merged with FreeParser()
2667 defines.Free(FreeModuleDefine);
2668 imports.Free(FreeModuleImport);
2670 FreeContext(this.globalContext);
2671 FreeExcludedSymbols(this.excludedSymbols);
2674 FreeGlobalData(&this.globalData);
2676 if(this.privateModule)
2678 FreeTypeData(this.privateModule);
2679 delete this.privateModule;
2685 static bool reentrant = false;
2690 char * selectedClassName = null, * selectedName = null;
2691 int selectedPos = 0;
2692 Designer backDesigner;
2693 char oldWorkDir[MAX_LOCATION];
2694 char mainModuleName[MAX_FILENAME] = "";
2695 const char * fileName;
2696 ImportedModule module;
2697 char extension[MAX_EXTENSION];
2698 PathBackup pathBackup { };
2700 Time parseCodeStart = GetTime();
2701 Time startTime, startFindClass;
2703 findClassTotalTime = 0;
2704 checkTypeTotalTime = 0;
2705 externalImportTotalTime = 0;
2706 findClassIgnoreNSTotalTime = 0;
2707 findSymbolTotalTime = 0;
2708 //ResetClassFindTime();
2712 // 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)
2713 if(reentrant) return;
2720 selectedClassName = CopyString(oClass.name);
2721 if(selected != oClass)
2723 ObjectInfo object = this.selected;
2724 selectedName = CopyString(object.name);
2728 for(check = this.oClass.instances.first; check; check = check.next)
2740 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2743 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2744 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2745 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2746 "/I T:\\ecere\\include /E %s", argv[1]);
2750 ChangeWorkingDir("e:\\ec");
2751 sprintf(command, "gcc -x c -E -");
2752 fileInput = DualPipeOpen({ output = true, input = true }, command);
2753 SetFileInput(fileInput);
2758 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2760 fileInput.Write(buffer, 1, count);
2765 fileInput.CloseOutput();
2769 // TOCHECK: COULDN'T WE CALL FreeParser here?
2771 FreeType(this.functionType);
2772 FreeType(this.instanceType);
2773 this.functionType = null;
2774 this.instanceType = null;
2777 sheet.SelectObject(null);
2783 // We don't want the designer to be notified of selection when deleting rows...
2784 backDesigner = designer;
2789 ObjectInfo _class, next;
2791 for(_class = classes.first; _class; _class = next)
2797 while((object = _class.instances.first))
2801 Designer::DestroyObject(object.instance);
2802 delete object.instance;
2804 if(object.i18nStrings)
2806 Map<String, bool> i18nStrings = object.i18nStrings;
2809 sheet.DeleteObject(object);
2811 _class.instances.Delete(object);
2815 Designer::DestroyObject(_class.instance);
2816 delete _class.instance;
2818 if(_class.i18nStrings)
2820 Map<String, bool> i18nStrings = _class.i18nStrings;
2823 sheet.DeleteObject(_class);
2825 classes.Delete(_class);
2830 designer = backDesigner;
2833 fileInput = editFile = EditBoxStream { editBox = editBox };
2834 SetFileInput(fileInput);
2838 SetGlobalData(&globalData);
2839 SetGlobalContext(globalContext);
2840 SetExcludedSymbols(&excludedSymbols);
2841 SetTopContext(globalContext);
2842 SetCurrentContext(globalContext);
2843 SetDefines(&defines);
2844 SetImports(&imports);
2847 startTime = GetTime();
2848 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2850 printf("classes.count: %d\n", globalContext.classes.count);
2855 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2856 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2859 this.privateModule = __ecere_COM_Initialize((bool)(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4)), 1, null);
2861 SetPrivateModule(privateModule);
2864 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2865 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2866 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2867 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2868 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2871 fileName = this.fileName;
2873 if(ide.workspace && ide.workspace.projects && fileName)
2875 for(p : ide.workspace.projects)
2877 char path[MAX_LOCATION];
2879 MakePathRelative(fileName, p.topNode.path, path);
2880 MakeSlashPath(path);
2882 pn = p.topNode.FindWithPath(path, false);
2891 project = ide.project;
2893 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2895 ChangeWorkingDir(project.topNode.path);
2897 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2899 GetLastDirectory(fileName, mainModuleName);
2900 GetExtension(mainModuleName, extension);
2902 SetBuildingEcereCom(false);
2903 SetBuildingEcereComModule(false);
2905 // TODO: Get symbolsDir from project settings instead...
2908 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2909 ProjectConfig config = project.config;
2910 int bitDepth = ide.workspace.bitDepth;
2911 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2912 SetSymbolsDir(objDir.dir);
2913 SetDefaultNameSpace(project.GetDefaultNameSpace(config));
2914 ide.SetPath(true, compiler, config, bitDepth);
2918 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2919 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2923 switch(__runtimePlatform)
2925 case win32: SetSymbolsDir("obj/debug.win32"); break;
2926 case tux: SetSymbolsDir("obj/debug.linux"); break;
2927 case apple: SetSymbolsDir("obj/debug.apple"); break;
2929 SetIncludeDirs(null);
2930 SetSysIncludeDirs(null);
2931 SetDefaultNameSpace(null);
2935 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2937 // TODO FIX for configless project
2938 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2940 for(item : ide.project.config.options.preprocessorDefinitions)
2942 if(!strcmp(item, "BUILDING_ECERE_COM"))
2944 SetBuildingEcereCom(true);
2951 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2952 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2953 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2954 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2955 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2956 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2957 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2958 strcmpi(mainModuleName, "Mutex.ec")))
2960 SetBuildingEcereComModule(true);
2963 // Predeclare all classes
2965 char symFile[MAX_FILENAME];
2966 char symLocation[MAX_LOCATION];
2967 ImportedModule module, next;
2969 GetLastDirectory(fileName, symFile);
2970 ChangeExtension(symFile, "sym", symFile);
2972 strcpy(symLocation, GetSymbolsDir());
2973 PathCat(symLocation, symFile);
2975 // if(!GetEcereImported() && !GetBuildingEcereCom())
2976 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2979 startTime = GetTime();
2981 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2983 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2988 startTime = GetTime();
2990 // LoadSymbols(symLocation, normalImport, true);
2991 LoadSymbols(symLocation, preDeclImport, false);
2993 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2996 for(module = defines.first; module; module = next)
2999 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
3002 defines.Delete(module);
3007 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
3009 SetDefaultDeclMode(privateAccess);
3010 SetDeclMode(privateAccess);
3014 SetDefaultDeclMode(defaultAccess);
3015 SetDeclMode(defaultAccess);
3018 StripExtension(mainModuleName);
3019 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
3020 defines.AddName(module);
3023 // SetYydebug(true);
3028 startTime = GetTime();
3029 startFindClass = checkTypeTotalTime;
3033 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
3035 CheckDataRedefinitions();
3038 SetIncludeDirs(null);
3039 SetSysIncludeDirs(null);
3050 startTime = GetTime();
3052 PrePreProcessClassDefinitions();
3053 ComputeModuleClasses(privateModule);
3054 PreProcessClassDefinitions();
3055 ProcessClassDefinitions();
3057 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
3058 startTime = GetTime();
3063 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
3064 startTime = GetTime();
3066 ProcessInstantiations();
3068 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
3071 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
3073 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
3074 if(!windowClass || windowClass.internalDecl)
3077 startTime = GetTime();
3079 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
3080 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
3081 eModule_Load(this.privateModule, "ecere", privateAccess);
3083 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
3086 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
3088 if(windowClass && windowClass.data)
3089 ApplySkin(windowClass, app.currentSkin.name, null);
3093 startTime = GetTime();
3095 for(external = ast->first; external; external = external.next)
3097 if(external.type == classExternal)
3099 ClassDefinition _class = external._class;
3100 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
3102 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
3105 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
3107 Instance instance = eInstance_New(regClass);
3108 ObjectInfo classObject
3110 name = CopyString(_class._class.name);
3111 instance = instance;
3112 classDefinition = _class;
3113 oClass = classObject;
3115 classes.Add(classObject);
3119 // Moved this at bottom so that the file dialog doesn't show up in eCom
3120 designer.CreateObject(instance, classObject, true, null);
3121 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
3123 if(_class.definitions)
3127 for(def = _class.definitions->first; def; def = def.next)
3131 case defaultPropertiesClassDef:
3134 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3136 Identifier id = propDef.identifiers->first;
3139 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3142 Class propertyClass = prop.dataTypeClass;
3144 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3145 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3147 Expression computed;
3148 bool variable = true;
3150 FreeType(propDef.initializer.exp.destType);
3151 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3152 ProcessExpressionType(propDef.initializer.exp);
3154 computed = CopyExpression(propDef.initializer.exp);
3155 ComputeExpression(computed);
3156 if(computed.isConstant)
3158 switch(computed.type)
3161 if(propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3163 String temp = new char[strlen(computed.string)+1];
3164 ReadString(temp, computed.string);
3165 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3168 if(!propDef.initializer.exp.intlString)
3170 Map<String, bool> i18nStrings = classObject.i18nStrings;
3172 classObject.i18nStrings = i18nStrings = { };
3173 i18nStrings[prop.name] = false;
3179 if((propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass) && !id.next)
3183 if(computed.instance._class && computed.instance._class.symbol &&
3184 computed.instance._class.symbol.registered &&
3185 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3187 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3189 // This was saved in the control and shouldn't be freed by FreeExpression...
3190 // (Not doing this anymore, incrementing refCount in pass15 instead)
3191 /*if(propertyClass.type == normalClass)
3192 computed.instance.data = null;*/
3200 Operand value = GetOperand(computed);
3201 DataValue valueData;
3202 valueData.i64 = value.i64;
3203 SetProperty(prop, instance, valueData);
3210 propDef.variable = true;
3211 FreeExpression(computed);
3216 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3217 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3218 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3221 // Maintain a list in FunctionDefinition of who is attached to it
3222 for(def = _class.definitions->first; def; def = def.next)
3224 if(def.type == functionClassDef)
3226 ClassFunction function = def.function;
3227 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3229 function.attached.Add(OldLink { data = method });
3239 case declarationClassDef:
3241 Declaration decl = def.decl;
3244 case instDeclaration:
3246 Instantiation inst = decl.inst;
3247 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3248 if(instClass && eClass_GetDesigner(instClass))
3250 Instance control = eInstance_New(instClass);
3255 oClass = classObject;
3259 classObject.instances.Add(object);
3261 // TOCHECK: Why is this needed now?
3262 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3263 def.object = object;
3265 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3267 designer.CreateObject(control, object, false, classObject.instance);
3268 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3278 // Second pass, process instantiation members
3280 for(def = _class.definitions->first; def; def = def.next)
3284 case declarationClassDef:
3286 Declaration decl = def.decl;
3289 case instDeclaration:
3291 Instantiation inst = decl.inst;
3292 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3293 if(instClass && eClass_GetDesigner(instClass))
3296 object = object ? object.next : classObject.instances.first;
3297 control = object.instance;
3301 MembersInit members;
3302 for(members = inst.members->first; members; members = members.next)
3304 switch(members.type)
3306 case dataMembersInit:
3308 if(members.dataMembers)
3311 DataMember curMember = null;
3312 Class curClass = null;
3313 DataMember subMemberStack[256];
3314 int subMemberStackPos = 0;
3316 for(member = members.dataMembers->first; member; member = member.next)
3319 Identifier ident = member.identifiers ? member.identifiers->first : null;
3322 DataMember _subMemberStack[256];
3323 int _subMemberStackPos = 0;
3324 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3328 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3330 if(thisMember && thisMember.memberAccess == publicAccess)
3332 curMember = thisMember;
3333 curClass = curMember._class;
3334 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3335 subMemberStackPos = _subMemberStackPos;
3341 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3342 if(curMember) found = true;
3344 if(found && curMember.isProperty)
3346 Property prop = (Property) curMember;
3347 Class propertyClass = prop.dataTypeClass;
3348 bool variable = true;
3350 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3352 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3354 FreeType(member.initializer.exp.destType);
3355 member.initializer.exp.destType = MkClassType(propertyClass.name);
3358 Expression computed;
3360 ProcessExpressionType(member.initializer.exp);
3362 computed = CopyExpression(member.initializer.exp);
3365 bool isClass = propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass;
3368 /*char debugExpString[4096];
3369 debugExpString[0] = '\0';
3370 PrintExpression(member.initializer.exp, debugExpString);*/
3372 ComputeExpression(computed);
3374 switch(computed.type)
3377 if(isClass && computed.isConstant && computed.instance.data)
3379 if(computed.instance._class && computed.instance._class.symbol &&
3380 computed.instance._class.symbol.registered &&
3381 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3383 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3385 // This was saved in the control and shouldn't be freed by FreeExpression...
3386 // (Not doing this anymore, incrementing refCount in pass15 instead)
3387 /*if(propertyClass.type == normalClass)
3388 computed.instance.data = null;*/
3394 if(isClass && eClass_GetDesigner(propertyClass))
3397 char * name = computed.identifier.string;
3398 if(!strcmp(name, "this"))
3401 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3407 for(check = classObject.instances.first; check; check = check.next)
3408 if(check.name && !strcmp(name, check.name))
3411 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3421 if(computed.member.exp.type == identifierExp)
3423 char * name = computed.member.exp.identifier.string;
3425 if(!strcmp(name, "this"))
3427 char * name = computed.member.member.string;
3429 for(check = classObject.instances.first; check; check = check.next)
3430 if(check.name && !strcmp(name, check.name))
3433 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3440 for(check = classObject.instances.first; check; check = check.next)
3442 if(check.name && !strcmp(name, check.name))
3444 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3447 DataValue value { };
3448 GetProperty(getProperty, check.instance, &value);
3449 SetProperty(prop, control, value);
3460 if(propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3462 String temp = new char[strlen(computed.string)+1];
3463 ReadString(temp, computed.string);
3464 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3467 if(!member.initializer.exp.intlString)
3469 Map<String, bool> i18nStrings = object.i18nStrings;
3471 object.i18nStrings = i18nStrings = { };
3472 i18nStrings[prop.name] = false;
3479 if(!isClass && computed.isConstant)
3481 if(!strcmp(propertyClass.dataTypeString, "float"))
3482 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3483 else if(!strcmp(propertyClass.dataTypeString, "double"))
3484 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3486 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3493 FreeExpression(computed);
3497 member.variable = true;
3499 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3500 member.initializer.exp.type == memberExp) // identifierExp
3502 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3503 if(method && method.type == virtualMethod)
3506 // Maintain a list in FunctionDefinition of who is attached to it
3507 for(def = _class.definitions->first; def; def = def.next)
3509 if(def.type == functionClassDef)
3511 ClassFunction function = def.function;
3512 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3513 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3515 function.attached.Add(OldLink { data = method });
3516 // Reference this particular instance?
3531 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3542 //designer.CreateObject(instance, classObject, true, null);
3543 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3545 designer.PostCreateObject(instance, classObject, true, null);
3547 //instance.state = Hidden;
3548 //instance.Create();
3549 //instance.SetState(Normal, true, 0);
3558 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3562 // Restore Selection
3563 if(selectedClassName)
3566 for(oClass = classes.first; oClass; oClass = oClass.next)
3568 if(!strcmp(oClass.name, selectedClassName))
3570 this.oClass = oClass;
3574 delete selectedClassName;
3582 for(check = this.oClass.instances.first; check; check = check.next)
3584 if(check.name && !strcmp(check.name, selectedName))
3586 this.selected = check;
3592 if(this.oClass.instances.first)
3593 this.selected = this.oClass.instances.first;
3595 this.selected = this.oClass;
3598 else if(selectedPos == -1 || !this.oClass.instances.count)
3599 this.selected = this.oClass;
3605 if(selectedPos > this.oClass.instances.count)
3607 for(check = this.oClass.instances.first; check; check = check.next)
3609 if(selectedPos == pos++)
3611 this.selected = check;
3619 this.oClass = classes.first;
3620 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3622 delete selectedName;
3623 SetSymbolsDir(null);
3625 if(sheet.codeEditor == this)
3626 sheet.SelectObject(selected);
3629 codeModified = false;
3631 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3634 InvokeParameters(false, false, false);
3637 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3643 ChangeWorkingDir(oldWorkDir);
3645 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3646 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3647 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3648 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3649 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3651 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3653 if(inUseDebug && ide.projectView)
3654 ide.debugger.EvaluateWatches();
3659 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3662 Window control = (Window)object.instance;
3663 ObjectInfo classObject = object.oClass;
3665 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3667 if(!strcmp(_class.name, "DesignerBase")) return;
3669 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3671 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3672 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3674 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3675 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3677 Class dataType = prop.dataTypeClass;
3679 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3683 if(dataType.type == structClass)
3685 void * dataForm = new0 byte[dataType.structSize];
3686 void * dataTest = new0 byte[dataType.structSize];
3688 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3689 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3691 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3693 char tempString[1024] = "";
3694 const char * string = "";
3695 bool needClass = true;
3699 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3701 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3703 eClass_FindNextMember(_class, curClass, curMember, null, null);
3704 if(*curMember != (DataMember)prop)
3705 f.Printf("%s = ", prop.name);
3707 *curMember = (DataMember)prop;
3708 *curClass = curMember->_class;
3711 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3713 f.Printf("%s", string);
3720 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3722 void * dataForm, * dataTest;
3723 bool isEditBoxContents = false;
3724 bool freeDataForm = false, freeDataTest = false;
3726 // Because contents property is broken for mutiline EditBox at the moment
3727 if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox"))
3728 isEditBoxContents = true;
3730 if(isEditBoxContents && ((EditBox)control).multiLine)
3732 dataForm = ((EditBox)control).multiLineContents;
3733 freeDataForm = true;
3736 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3737 if(isEditBoxContents && ((EditBox)test).multiLine)
3739 dataTest = ((EditBox)test).multiLineContents;
3740 freeDataTest = true;
3743 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3745 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3747 char tempString[1024] = "";
3748 const char * string = "";
3752 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3754 eClass_FindNextMember(_class, curClass, curMember, null, null);
3755 if(*curMember != (DataMember)prop)
3756 f.Printf("%s = ", prop.name);
3757 *curMember = (DataMember)prop;
3758 *curClass = curMember->_class;
3760 if(eClass_GetDesigner(dataType))
3762 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3763 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3764 f.Printf("this", prop.name);
3767 //ObjectInfo classObject;
3768 //for(classObject = classes.first; classObject; classObject = classObject.next)
3772 for(object = classObject.instances.first; object; object = object.next)
3774 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3776 f.Printf("%s", object.name);
3783 bool needClass = true;
3784 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3785 f.Printf("%s", string);
3792 bool needClass = true;
3793 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3795 if(!strcmp(dataType.dataTypeString, "char *"))
3797 Map<String, bool> i18nStrings = object.i18nStrings;
3799 if(i18nStrings && i18nStrings.GetAtPosition(prop.name, false, null))
3802 f.Printf("%s\"", i18n ? "$" : "");
3803 OutputString(f, string);
3807 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3809 f.Printf("%s", string);
3812 *lastIsMethod = false;
3815 if(freeDataForm) delete dataForm;
3816 if(freeDataTest) delete dataTest;
3820 DataValue dataForm, dataTest;
3822 GetProperty(prop, control, &dataForm);
3823 GetProperty(prop, test, &dataTest);
3825 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3827 char * string = null;
3828 char tempString[1024] = "";
3829 SetProperty(prop, test, dataForm);
3831 if(dataType.type != bitClass)
3833 bool needClass = true;
3835 if(dataType.type == enumClass)
3838 Class enumClass = eSystem_FindClass(privateModule, "enum");
3839 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3840 int64 i64Value = GetI64EnumValue(dataType, dataForm);
3842 for(value = e.values.first; value; value = value.next)
3844 if(value.data == i64Value)
3846 string = value.name;
3852 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3854 if(string && string[0])
3859 eClass_FindNextMember(_class, curClass, curMember, null, null);
3860 if(*curMember != (DataMember)prop)
3861 f.Printf("%s = ", prop.name);
3862 *curMember = (DataMember)prop;
3863 *curClass = curMember->_class;
3865 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3866 f.Printf("%sf", string);
3868 f.Printf("%s", string);
3872 else if(dataType.type == bitClass)
3874 bool needClass = true;
3876 if(*prev) f.Printf(", ");
3878 eClass_FindNextMember(_class, curClass, curMember, null, null);
3879 if(*curMember != (DataMember)prop)
3880 f.Printf("%s = ", prop.name);
3881 *curMember = (DataMember)prop;
3882 *curClass = curMember->_class;
3884 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3886 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3888 f.Printf("%s", string);
3890 *lastIsMethod = false;
3900 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3902 Instantiation inst = object.instCode;
3903 Window control = (Window)object.instance;
3905 bool methodPresent = false;
3906 bool lastIsMethod = true;
3912 // Instance removed, delete it
3913 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3915 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3916 position = inst.loc.end.pos + 1;
3920 bool multiLine = false;
3923 // Check if it's an unnamed instance
3926 f.Seek(inst.nameLoc.start.pos - position, current);
3927 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3928 position = inst.nameLoc.end.pos;
3930 f.Printf(object.name);
3935 if(isspace(ch) && ch != '\n')
3937 f.Seek(-1, current);
3945 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3947 f.Seek(pos - position, current);
3952 f.Seek(-1, current);
3961 f.Puts(object.name);
3966 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3967 methodPresent = true;
3975 if(ch == OpenBracket)
3981 // TODO: Simplify this?
3990 f.Seek(-1, current);
3991 DeleteJunkBefore(f, position, &position);
4003 if(ch == '\n') { toDelete = count; count = 0; }
4004 else if(isspace(ch)) count++;
4007 f.Seek(-1, current);
4011 toDelete += count - 6;
4015 toAdd = 6 - count;*/
4021 f.Seek(-toDelete-count, current);
4022 f.DeleteBytes(toDelete);
4023 f.Seek(count, current);
4026 DeleteJunkBefore(f, position, &position);
4028 // Removed this here as it was adding trailing spaces when adding a method
4033 for(c = 0; c<toAdd; c++)
4040 methodPresent = multiLine;
4042 //if(!prev) -- always false
4043 f.Printf(methodPresent ? "\n " : " ");
4048 // Instance not there, create a brand new one
4049 DeleteJunkBefore(f, position, &position);
4050 f.Printf(*firstObject ? "\n\n" : "\n");
4051 *firstObject = false;
4053 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
4054 methodPresent = true;
4059 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
4061 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
4066 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
4068 f.Printf(" %s %c ", control._class.name, OpenBracket);
4074 Instance test = eInstance_New(control._class);
4075 DataMember curMember = null;
4076 Class curClass = null;
4079 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
4083 // Attach Method here
4084 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
4086 if(prev) f.Printf(", ");
4087 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
4092 if(inst && !object.deleted)
4094 MembersInit members;
4095 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
4097 DeleteJunkBefore(f, position, &position);
4099 // Instance already there, clear out the properties
4100 for(members = inst.members ? inst.members->first : null; members; members = members.next)
4102 if(members.type == dataMembersInit)
4106 if(members.dataMembers)
4108 bool keptMember = false;
4109 MemberInit lastKept = null;
4111 for(member = members.dataMembers->first; member; member = member.next)
4113 Identifier ident = member.identifiers ? member.identifiers->first : null;
4114 bool deleted = false;
4116 // For now delete if it's not a method
4117 if(!member.variable) // && ident)
4119 if(!ident || !ident.next)
4121 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
4124 f.Seek(member.loc.start.pos - position, current);
4125 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4126 position = member.loc.end.pos;
4131 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
4132 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
4133 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4135 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
4136 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
4138 f.Seek(member.loc.start.pos - position, current);
4139 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4140 position = member.loc.end.pos;
4152 //f.Seek(member.loc.start.pos - position, current);
4153 //position = member.loc.start.pos;
4154 DeleteJunkBefore(f, member.loc.start.pos, &position);
4155 if(prev) f.Printf(", ");
4156 else if(keptMember) f.Printf(" ");
4161 if(!keptMember || !members.next)
4165 if(keptMember && lastKept != members.dataMembers->last)
4170 f.Seek(-1, current);
4176 f.Seek(-1, current);
4179 else if(!isspace(ch))
4181 f.Seek(-2, current);
4186 f.DeleteBytes(count);
4189 f.Seek(members.loc.end.pos - position, current);
4194 f.Seek(-1, current);
4196 position = members.loc.end.pos + 1;
4200 f.Seek(-1, current);
4201 position = members.loc.end.pos;
4207 lastIsMethod = false;
4212 DeleteJunkBefore(f, position, &position);
4215 if(lastKept != members.dataMembers->last)
4220 f.Seek(-1, current);
4226 f.Seek(-1, current);
4229 else if(!isspace(ch))
4231 f.Seek(-2, current);
4236 f.DeleteBytes(count);
4240 f.Seek(members.loc.end.pos - position, current);
4241 position = members.loc.end.pos;
4245 lastIsMethod = true;
4248 lastIsMethod = false;
4254 f.Seek(members.loc.end.pos - position, current);
4255 position = members.loc.end.pos;
4257 lastIsMethod = true;
4260 else if(members.type == methodMembersInit)
4262 if(this.methodAction == actionDeleteMethod && members.function == function);
4264 methodPresent = true;
4266 // Delete instance method here
4267 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4268 members.function == function)
4270 if(this.moveAttached && !*text)
4271 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4273 DeleteJunkBefore(f, members.loc.start.pos, &position);
4274 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4275 position = members.loc.end.pos + 1;
4280 DeleteJunkBefore(f, position, &position);
4284 DeleteJunkBefore(f, members.loc.start.pos, &position);
4285 lastIsMethod = true;
4289 f.Seek(members.loc.end.pos - position, current);
4290 position = members.loc.end.pos;
4292 DeleteJunkBefore(f, position, &position);
4301 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4303 Method method = this.method;
4304 DeleteJunkBefore(f, position, &position);
4310 if(!method.dataType)
4311 method.dataType = ProcessTypeString(method.dataTypeString, false);
4314 Type dataType = method.dataType;
4315 Type returnType = dataType.returnType;
4318 if(this.moveAttached)
4320 // Move function here:
4321 int newLen = strlen(method.name);
4326 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4328 // First change name of function
4329 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4330 *textSize += newLen - movedFuncIdLen;
4331 memcpy(*text + movedFuncIdPos, method.name, newLen);
4333 // Second, tab right
4336 for(c = 0; (*text)[c]; )
4339 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4342 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4343 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4347 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4357 // Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4359 // ADDING METHOD HERE
4361 OutputType(f, returnType, false);
4364 if(dataType.thisClass)
4366 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4368 if(dataType.thisClass.shortName)
4369 f.Printf(dataType.thisClass.shortName);
4371 f.Printf(dataType.thisClass.string);
4375 f.Printf(method.name);
4377 for(param = dataType.params.first; param; param = param.next)
4379 OutputType(f, param, true);
4384 f.Printf(" %c\n\n", OpenBracket);
4386 if(control._class._vTbl[method.vid] == null /*moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]*/) // Temp Check for DefaultFunction
4388 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4389 f.Printf(" return true;\n");
4390 else if(returnType.kind != voidType)
4391 f.Printf(" return 0;\n");
4396 if(returnType.kind != voidType)
4397 f.Printf("return ");
4398 f.Printf("%s::%s(", control._class.name, method.name);
4399 for(param = dataType.params.first; param; param = param.next)
4401 if(param.prev) f.Printf(", ");
4402 if(param.kind != voidType)
4403 f.Printf(param.name);
4407 f.Printf(" %c\n", CloseBracket);
4413 if(!object.instCode)
4414 f.Printf(methodPresent ? " %c;" : "%c;", CloseBracket);
4415 else if(!object.deleted)
4417 // Turn this into a multiline instance when adding a method
4418 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4420 f.Printf(methodPresent ? "\n " : " ");
4422 f.Seek(inst.loc.end.pos + 1 - position, current);
4423 position = inst.loc.end.pos + 1;
4428 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4431 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4433 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4435 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4437 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4438 if(prop && prop.isProperty && !prop.conversion)
4440 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4441 (!prop.IsSet || prop.IsSet(classObject.instance)))
4443 Class dataType = prop.dataTypeClass;
4444 char tempString[1024] = "";
4445 char * string = null;
4446 bool specify = false;
4449 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4450 if(member && member._class == regClass)
4454 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4456 if(dataType && dataType.type == structClass)
4458 void * dataForm = new0 byte[dataType.structSize];
4459 void * dataTest = new0 byte[dataType.structSize];
4461 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4462 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4464 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4466 bool needClass = true;
4468 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4469 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4471 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4473 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4478 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4480 void * dataForm, * dataTest;
4481 bool isEditBoxContents = false;
4482 bool freeDataForm = false, freeDataTest = false;
4484 // Because contents property is broken for mutiline EditBox at the moment
4485 if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox"))
4486 isEditBoxContents = true;
4488 if(isEditBoxContents && ((EditBox)classObject.instance).multiLine)
4490 dataForm = ((EditBox)classObject.instance).multiLineContents;
4491 freeDataForm = true;
4494 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4495 if(isEditBoxContents && ((EditBox)test).multiLine)
4497 dataTest = ((EditBox)test).multiLineContents;
4498 freeDataTest = true;
4501 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4503 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4505 char tempString[1024] = "";
4506 char * string = null;
4507 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4509 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4511 // Shouldn't go here ...
4512 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4516 bool needClass = true;
4518 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4520 if(!strcmp(dataType.dataTypeString, "char *"))
4522 Map<String, bool> i18nStrings = classObject.i18nStrings;
4524 if(i18nStrings && i18nStrings.GetAtPosition(prop.name, false, null))
4527 f.Printf("\n %s%s = %s\"", specify ? "property::" : "", prop.name, i18n ? "$" : "");
4528 OutputString(f, string);
4532 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4534 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4537 if(freeDataForm) delete dataForm;
4538 if(freeDataTest) delete dataTest;
4542 DataValue dataForm, dataTest;
4544 GetProperty(prop, classObject.instance, &dataForm);
4545 GetProperty(prop, test, &dataTest);
4547 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4549 SetProperty(prop, test, dataForm);
4550 if(dataType.type == bitClass)
4552 bool needClass = true;
4553 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4555 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4557 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4561 bool needClass = true;
4562 if(dataType.type == enumClass)
4565 Class enumClass = eSystem_FindClass(privateModule, "enum");
4566 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4567 int64 i64Value = GetI64EnumValue(dataType, dataForm);
4569 for(value = e.values.first; value; value = value.next)
4571 if(value.data == i64Value)
4573 string = value.name;
4579 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4580 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4581 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4583 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4592 void UpdateFormCode()
4595 if(!parsing) return;
4602 else if(formModified)
4604 EditBoxStream f { editBox = editBox };
4608 Identifier movedFuncId;
4609 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4610 ObjectInfo classObject;
4614 editBox.recordUndoEvent = true;
4618 movedFuncId = GetDeclId(function.declarator);
4619 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4620 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4623 for(classObject = classes.first; classObject; classObject = classObject.next)
4625 ClassDefinition classDef = classObject.classDefinition;
4626 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4629 bool firstObject = true;
4630 ObjectInfo object = classObject.instances.first;
4631 bool lastIsDecl = false;
4633 if(!classObject.modified) continue;
4635 test = eInstance_New(regClass);
4638 // Put it in the same desktop window...
4639 designer.PrepareTestObject(test);
4641 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4642 //f.Printf("%c\n\n", OpenBracket);
4644 // Change the _class name
4645 f.Seek(classDef.nameLoc.start.pos - position, current);
4646 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4647 f.Printf(classObject.name);
4648 position = classDef.nameLoc.end.pos;
4651 // Go to block start, delete all until no white space, put \n
4655 f.Seek(classDef.blockStart.end.pos - position, current);
4656 position = classDef.blockStart.end.pos;
4658 for(; f.Getc(&ch); count++)
4662 f.Seek(-1, current);
4672 f.Seek(-count, current);
4674 f.DeleteBytes(count-back);
4676 position += count-back;
4679 // Output properties
4680 OutputClassProperties(classObject.instance._class, classObject, f, test);
4682 for(def = classDef.definitions->first; def; def = def.next)
4686 case defaultPropertiesClassDef:
4688 bool keptMember = false;
4690 MemberInit lastKept = null;
4693 DeleteJunkBefore(f, def.loc.start.pos, &position);
4695 // This was adding blank spaces between comment and properties -- What was it for?
4698 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4700 Identifier ident = propDef.identifiers->first;
4701 bool deleted = false;
4703 // For now delete if it's a prop
4704 if(!propDef.variable && ident)
4708 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4711 f.Seek(propDef.loc.start.pos - position, current);
4712 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4713 position = propDef.loc.end.pos;
4718 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4719 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4721 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4722 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4724 f.Seek(propDef.loc.start.pos - position, current);
4725 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4726 position = propDef.loc.end.pos;
4743 f.Seek(def.loc.end.pos - position - 1, current);
4748 f.Seek(-1, current);
4751 position = def.loc.end.pos;
4755 if(lastKept != def.defProperties->last)
4760 f.Seek(-1, current);
4766 f.Seek(-1, current);
4769 else if(!isspace(ch))
4771 f.Seek(-2, current);
4776 f.DeleteBytes(count);
4780 f.Seek(def.loc.end.pos - position, current);
4781 position = def.loc.end.pos;
4786 case declarationClassDef:
4788 Declaration decl = def.decl;
4790 if(decl.type == instDeclaration)
4792 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4794 while(def.object && object != def.object)
4796 if(object /*&& ((ObjectInfo)def.object).modified*/)
4797 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4798 object = object.next;
4801 DeleteJunkBefore(f, def.loc.start.pos, &position);
4802 f.Printf(firstObject ? "\n\n " : "\n ");
4803 firstObject = false;
4805 if(def.object && ((ObjectInfo)def.object).modified)
4806 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4808 object = object ? object.next : null;
4812 DeleteJunkBefore(f, def.loc.start.pos, &position);
4813 f.Printf(firstObject ? "\n\n " : "\n ");
4814 firstObject = false;
4820 DeleteJunkBefore(f, def.loc.start.pos, &position);
4821 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4826 case functionClassDef:
4828 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4829 if(!def.function.body) continue;
4833 DeleteJunkBefore(f, def.loc.start.pos, &position);
4836 // Delete _class methods
4837 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4838 def.function == function)
4843 if(moveAttached && !text)
4845 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4848 f.Seek(def.loc.end.pos - position, current);
4849 for(; f.Getc(&ch); count++)
4853 f.Seek(-1, current);
4857 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4859 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4860 position = def.loc.end.pos + count;
4863 // In case of detaching methods in the _class, simply rename the method
4864 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4866 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4867 f.DeleteBytes(movedFuncIdLen);
4869 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4872 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4873 function == def.function)
4875 // In case of attaching methods in the _class, simply rename the method
4876 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4877 position = function.loc.start.pos + movedFuncIdPos;
4878 f.DeleteBytes(movedFuncIdLen);
4879 if(method.dataType.thisClass)
4880 f.Printf("%s::", method.dataType.thisClass.string);
4881 f.Puts(method.name);
4882 position += movedFuncIdLen;
4887 DeleteJunkBefore(f, def.loc.start.pos, &position);
4888 if(def.type == memberAccessClassDef)
4891 firstObject = false;
4901 f.Seek(def.loc.end.pos - position, current);
4902 position = def.loc.end.pos;
4905 // Output attached methods
4906 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4908 DeleteJunkBefore(f, position, &position);
4909 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4912 // ********** INSTANCES ***************
4913 for(; object; object = object.next)
4915 if(!object.instCode)
4917 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4921 DeleteJunkBefore(f, position, &position);
4923 // ****************** METHODS ***********************
4924 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4926 // If detaching an instance method
4927 if(selected != classObject)
4929 int newLen = strlen(methodName);
4932 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4933 // Tab selection left
4936 for(c = 0; text[c]; )
4939 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4940 memmove(text+start, text+start+i, textSize+1-start-i);
4943 for(; text[c] && text[c] != '\n'; c++);
4949 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4950 textSize += newLen - movedFuncIdLen;
4951 memcpy(text + movedFuncIdPos, methodName, newLen);
4958 if(methodAction == actionAddMethod && selected == classObject)
4960 Method method = this.method;
4962 if(!method.dataType)
4963 method.dataType = ProcessTypeString(method.dataTypeString, false);
4965 // ADDING METHOD HERE
4967 Type dataType = method.dataType;
4968 Type returnType = dataType.returnType;
4970 // Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4974 OutputType(f, returnType, false);
4977 if(dataType.thisClass && !dataType.classObjectType)
4979 if(dataType.thisClass.shortName)
4980 f.Printf(dataType.thisClass.shortName);
4982 f.Printf(dataType.thisClass.string);
4985 f.Printf(method.name);
4987 for(param = dataType.params.first; param; param = param.next)
4989 OutputType(f, param, true);
4994 f.Printf(" %c\n\n", OpenBracket);
4996 if(test._class._vTbl[method.vid] == null /*moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]*/) // Temp Check for DefaultFunction
4998 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4999 f.Printf(" return true;\n");
5000 else if(returnType && returnType.kind != voidType)
5001 f.Printf(" return 0;\n");
5006 if(returnType.kind != voidType)
5007 f.Printf("return ");
5009 char * name = ((Specifier)classDef.baseSpecs->first).name;
5010 Symbol _class = FindClass(name);
5011 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
5013 for(param = dataType.params.first; param; param = param.next)
5015 if(param.prev) f.Printf(", ");
5016 if(param.kind != voidType)
5017 f.Printf(param.name);
5022 f.Printf(" %c", CloseBracket);
5026 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
5032 editBox.recordUndoEvent = false;
5040 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
5041 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
5045 codeModified = false;
5046 formModified = false;
5048 moveAttached = false;
5053 int FindMethod(const char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
5056 ClassFunction function = null;
5059 ObjectInfo object = this.selected;
5061 if(object && object == this.oClass)
5063 ClassDefinition classDef = object.oClass.classDefinition;
5065 if(classDef && classDef.definitions)
5067 for(def = classDef.definitions->first; def; def = def.next)
5069 if(def.type == functionClassDef && def.function.declarator)
5071 if(!strcmp(def.function.declarator.symbol.string, methodName))
5073 function = def.function;
5078 else if(def.type == defaultPropertiesClassDef)
5082 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
5084 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
5085 if(ident && !ident.next)
5087 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
5091 propLoc = propDef.loc;
5094 ClassDefinition classDef = object.oClass.classDefinition;
5096 if(classDef.definitions)
5098 for(def = classDef.definitions->first; def; def = def.next)
5100 if(def.type == functionClassDef)
5102 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
5104 function = def.function;
5123 Instantiation inst = object.instCode;
5125 // Check here to see if the method already exists, no need to call ModifyCode in that case
5126 if(inst && inst.members)
5128 MembersInit members;
5129 for(members = inst.members->first; members; members = members.next)
5131 switch(members.type)
5133 case dataMembersInit:
5135 if(members.dataMembers)
5138 for(member = members.dataMembers->first; member; member = member.next)
5140 Identifier ident = member.identifiers ? member.identifiers->first : null;
5141 if(ident && !ident.next)
5143 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
5147 propLoc = member.loc;
5150 ClassDefinition classDef = object.oClass.classDefinition;
5152 if(classDef.definitions)
5154 for(def = classDef.definitions->first; def; def = def.next)
5156 if(def.type == functionClassDef)
5158 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
5160 function = def.function;
5169 // TODO: Fix memory leak
5170 function = ClassFunction
5172 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5184 case methodMembersInit:
5186 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5188 function = members.function;
5200 if(functionPtr) *functionPtr = function;
5204 void GoToMethod(const char * methodName /*Method method*/)
5208 ObjectInfo object = selected;
5209 EditBoxStream f { editBox = editBox };
5210 ClassFunction function = null;
5211 bool atChar = false;
5215 Location propLoc = { {0,0,-1} };
5218 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5219 if(function && function.body)
5222 f.Seek(function.body.loc.start.pos+1, current);
5232 f.Seek(-1, current);
5237 else if(!isspace(ch))
5239 f.Seek(-1, current);
5245 else if(propLoc.start.pos > -1)
5247 f.Seek(propLoc.start.pos, current);
5250 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5252 if(function || propLoc.start.pos > -1)
5254 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5255 editBox.CenterOnCursor();
5256 SetState(normal, false, 0);
5259 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5261 FreeClassFunction(function);
5267 void FindCompatibleMethods(Method method, OldList compatible)
5269 ClassDefinition classDef = this.oClass.classDefinition;
5270 if(classDef && classDef.definitions)
5273 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5276 Symbol classSym { };
5277 Symbol selectedClass;
5278 if(this.selected == this.oClass)
5279 selectedClass = classSym;
5281 selectedClass = FindClass(this.selected.instance._class.name);
5283 regClass.name = classDef._class.name;
5284 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5285 for(def = classDef.definitions->first; def; def = def.next)
5287 if(def.type == functionClassDef && def.function.declarator)
5289 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5291 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5294 Type type = def.function.declarator.symbol.type;
5295 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5297 compatible.Add(OldLink { data = def.function });
5303 if(this.oClass && this.oClass.instance)
5305 classSym.registered = regClass;
5306 //classSym.registered = this.oClass.oClass;
5308 for(_class = regClass.base; _class; _class = _class.base)
5311 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5313 // TODO: Understand why these functions popup in attach list
5314 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5316 if(!testMethod.dataType)
5317 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5319 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5320 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5321 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5323 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5324 // ClassFunction function { };
5325 FunctionDefinition function { };
5327 function.declarator = Declarator { };
5328 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5329 excludedSymbols.Add(function.declarator.symbol);
5331 compatible.Add(OldLink { data = function });
5342 void AddMethod(Method method)
5346 char methodName[1024];
5347 strcpy(methodName, method.name);
5348 if(!FindMethod(methodName, null, null))
5350 methodAction = actionAddMethod;
5351 this.method = method;
5355 GoToMethod(methodName);
5359 void DeleteMethod(ClassFunction function)
5363 methodAction = actionDeleteMethod;
5364 this.function = function;
5372 void AttachMethod(Method method, ClassFunction function)
5376 // If it's an instance we'll ask if we want to move it inside...
5377 if(!function.attached.count && function.body)
5379 // Find the function in the _class to check if it's a virtual function
5380 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5381 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5382 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5384 for(def = this.classDefinition.first; def; def = def.next)
5386 if(def.type == functionClassDef)
5388 if(def.function == function)
5393 if(!method || method.type != virtualMethod)
5396 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5397 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5399 moveAttached = true;
5404 methodAction = actionAttachMethod;
5405 this.method = method;
5406 this.function = function;
5413 void ReAttachMethod(Method method, ClassFunction function)
5417 // If it's an instance we'll ask if we want to move it inside...
5418 if(!function.attached.count && function.body)
5420 // Find the function in the _class to check if it's a virtual function
5421 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5422 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5423 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5425 for(def = this.classDefinition.first; def; def = def.next)
5427 if(def.type == functionClassDef)
5429 if(def.function == function)
5434 if(!method || method.type != virtualMethod)
5437 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5438 if(MessageBox { type = yesNo, master = parent, text = title,
5439 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5441 moveAttached = true;
5446 methodAction = actionReattachMethod;
5447 this.method = method;
5448 this.function = function;
5455 void DetachMethod(Method method, ClassFunction function, int type)
5463 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5464 master = sheet, text = $"Name detached method", background = formColor
5468 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5469 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5473 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5474 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5478 dialog, anchor = { left = 5, right = 5, top = 5 }
5480 sprintf(methodName, "%s_%s", selected.name, method.name);
5481 nameBox.contents = methodName;
5483 result = dialog.Modal() == ok;
5484 strcpy(methodName, nameBox.contents);
5489 // If the method is not attached, move it outside
5492 // Add this class to the methodName
5493 char name[1024] = "";
5495 if(this.selected != this.oClass && !method.dataType.thisClass)
5497 strcat(name, this.selected.instance._class.name);
5499 strcat(name, this.methodName);
5500 strcpy(this.methodName, name);
5502 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5504 strcat(name, method.dataType.thisClass.string);
5506 strcat(name, this.methodName);
5507 strcpy(this.methodName, name);
5510 this.moveAttached = true;
5513 this.methodAction = actionDetachMethod;
5514 this.method = method;
5515 this.function = function;
5522 void AddObject(Instance instance, ObjectInfo * object)
5526 //*object = _class.instances.Add(sizeof(ObjectInfo));
5527 *object = ObjectInfo { };
5528 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5529 (*object).oClass = oClass;
5530 (*object).instance = instance;
5535 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5537 // if(strcmp(name, this.oClass.instance.name))
5540 for(check = oClass.instances.first; check; check = check.next)
5541 if(!check.deleted && check.name && !strcmp(name, check.name))
5545 (*object).name = CopyString(name);
5550 toolBox.controlClass = null;
5554 //sheet.AddObject(*object, (*object).name, TypeData, true);
5559 void EnsureUpToDate()
5561 if(sheet && codeModified && parsing)
5565 void SelectObject(ObjectInfo object)
5568 oClass = object ? object.oClass : null;
5570 designer.SelectObject(object, object ? object.instance : null);
5573 void SelectObjectFromDesigner(ObjectInfo object)
5576 sheet.SelectObject(object);
5579 void EnumerateObjects(Sheet sheet)
5583 for(oClass = classes.first; oClass; oClass = oClass.next)
5589 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5590 for(object = oClass.instances.first; object; object = object.next)
5591 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5594 sheet.SelectObject(selected);
5599 designer.AddObject();
5602 void DeleteObject(ObjectInfo object)
5604 delete object.instance;
5605 object.deleted = true;
5606 object.modified = true;
5607 object.oClass.modified = true;
5609 if(selected == object)
5611 bool looped = false;
5612 ObjectInfo select = object;
5616 select = select.prev;
5620 select = object.oClass.instances.last;
5627 sheet.SelectObject(select ? select : oClass);
5630 if(!object.instCode && object.oClass != object)
5633 oClass.instances.Delete(object);
5636 if(sheet.codeEditor == this)
5637 sheet.DeleteObject(object);
5640 void RenameObject(ObjectInfo object, const char * name)
5644 // Validate the name:
5645 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5646 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5649 for(c = 0; name[c]; c++)
5650 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5658 object.name = (name && name[0]) ? CopyString(name) : null;
5660 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5664 void DesignerModifiedObject()
5666 sheet.ListProperties(false);
5670 void ListSubMembers(Type member)
5674 for(subMember = member.members.first; subMember; subMember = subMember.next)
5678 DataRow row = membersList.AddString(subMember.name);
5679 row.icon = icons[typeData];
5683 ListSubMembers(subMember);
5688 void ListSubDataMembers(DataMember member, bool isPrivate)
5690 DataMember subMember;
5691 for(subMember = member.members.first; subMember; subMember = subMember.next)
5693 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5697 DataRow row = membersList.AddString(subMember.name);
5698 BitmapResource bitmap = null;
5699 if(!subMember.dataType)
5700 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5702 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5704 char * bitmapName = (char *)(intptr)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5707 bitmap = { bitmapName };
5708 membersList.AddResource(bitmap);
5711 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5715 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5721 void ListClassMembers(Class whatClass, bool methodsOnly)
5724 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5725 bool isPrivate = false;
5727 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5729 Method method, methodIt;
5731 DataMember memberIt;
5733 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5735 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5736 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5738 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5740 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5742 DataRow row = membersList.FindString(method.name);
5745 row = membersList.AddString(method.name);
5747 if(!method.dataType)
5748 method.dataType = ProcessTypeString(method.dataTypeString, false);
5750 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5758 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5762 if(memberIt.isProperty)
5764 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5766 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5770 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5772 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5775 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5781 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5783 if(member.isProperty)
5785 Property prop = (Property) member;
5786 if(!membersList.FindString(prop.name))
5788 DataRow row = membersList.AddString(prop.name);
5789 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5792 else if(member.name && !membersList.FindString(member.name))
5794 DataRow row = membersList.AddString(member.name);
5796 BitmapResource bitmap = null;
5797 if(!member.dataType)
5798 member.dataType = ProcessTypeString(member.dataTypeString, false);
5800 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5802 char * bitmapName = (char *)(intptr)eClass_GetProperty(member.dataType._class.registered, "icon");
5805 bitmap = { bitmapName };
5806 membersList.AddResource(bitmap);
5809 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5812 ListSubDataMembers(member, member.memberAccess == privateAccess);
5816 if(_class.inheritanceAccess == privateAccess)
5819 if(_class.module != privateModule) break;
5824 void ListClassMembersMatch(Class whatClass, Type methodType)
5827 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5828 bool isPrivate = false;
5830 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5834 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5836 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5838 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5840 if(!method.dataType)
5841 method.dataType = ProcessTypeString(method.dataTypeString, false);
5843 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false, true))
5845 DataRow row = membersList.FindString(method.name);
5848 row = membersList.AddString(method.name);
5849 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5855 if(_class.inheritanceAccess == privateAccess)
5858 if(_class.module != privateModule) break;
5863 void ListClassPropertiesAndVirtual(Class whatClass, const String curString)
5866 bool isPrivate = false;
5867 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5872 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5874 if(method.type == virtualMethod)
5876 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5878 DataRow row = membersList.FindString(method.name);
5881 row = membersList.AddString(method.name);
5883 if(!method.dataType)
5884 method.dataType = ProcessTypeString(method.dataTypeString, false);
5886 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5892 for(member = _class.membersAndProperties.first; member; member = member.next)
5894 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5896 if(member.isProperty)
5898 Property prop = (Property)member;
5900 DataRow row = membersList.AddString(prop.name);
5901 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5904 else if(member.name && (!curString || strcmp(curString, member.name)))
5906 DataRow row = membersList.AddString(member.name);
5908 BitmapResource bitmap = null;
5909 if(!member.dataType)
5910 member.dataType = ProcessTypeString(member.dataTypeString, false);
5912 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5914 char * bitmapName = (char *)(intptr)eClass_GetProperty(member.dataType._class.registered, "icon");
5917 bitmap = { bitmapName };
5918 membersList.AddResource(bitmap);
5921 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5924 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5927 if(_class.inheritanceAccess == privateAccess)
5930 if(_class.module != privateModule) break;
5935 void ListMembers(Type type)
5937 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5939 if(type.kind == classType)
5942 ListClassMembers(type._class.registered, false);
5947 for(member = type.members.first; member; member = member.next)
5951 DataRow row = membersList.AddString(member.name);
5952 row.icon = icons[typeData];
5954 else if(member.kind == structType || member.kind == unionType)
5955 ListSubMembers(member);
5961 void ListModule(Module mainModule, int recurse, bool listClasses)
5964 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5965 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5966 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5967 for(module = mainModule.application.allModules.first; module; module = module.next)
5969 if(ModuleVisibility(mainModule, module))
5970 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5974 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5981 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5983 Class _class = link.data;
5984 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5986 DataRow row = membersList.AddString(_class.name);
5987 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5992 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5994 //DefinedExpression definedExp = link.data;
5995 DataRow row = membersList.AddString(link /*definedExp*/.name);
5996 row.icon = icons[typeData];
5999 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
6001 //GlobalFunction function = link.data;
6002 DataRow row = membersList.AddString(link /*function*/.name);
6003 row.icon = icons[typeMethod];
6007 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
6009 if(recurse != 2 && listClasses)
6011 if(!membersList.FindString(ns->name))
6013 DataRow row = membersList.AddString(ns->name);
6014 row.icon = icons[typeNameSpace];
6019 ListNameSpace(ns, 2, listClasses);
6023 void ListEnumValues(Class _class)
6025 List<Class> classes { };
6026 for(; _class && _class.type == enumClass; _class = _class.base)
6027 classes.Insert(null, _class);
6028 for(_class : classes)
6030 EnumClassData enumeration = (EnumClassData)_class.data;
6032 for(item = enumeration.values.first; item; item = item.next)
6034 DataRow row = membersList.AddString(item.name);
6035 row.icon = icons[typeEnumValue];
6041 bool ListEnumsModule(Module mainModule, Type dest)
6043 bool result = false;
6045 result |= ListEnums(mainModule.application.systemNameSpace, dest);
6046 result |= ListEnums(mainModule.application.privateNameSpace, dest);
6047 result |= ListEnums(mainModule.application.publicNameSpace, dest);
6048 for(module = mainModule.application.allModules.first; module; module = module.next)
6050 if(ModuleVisibility(mainModule, module))
6051 result |= ListEnums(module.publicNameSpace, dest);
6056 void ListNameSpaceByString(Module mainModule, const char * string)
6058 NameSpace * nameSpace;
6060 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
6061 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6062 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
6063 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6064 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
6065 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6066 for(module = mainModule.application.allModules.first; module; module = module.next)
6068 if(ModuleVisibility(mainModule, module))
6070 nameSpace = FindNameSpace(module.publicNameSpace, string);
6071 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6076 bool ListEnums(NameSpace nameSpace, Type dest)
6079 bool result = false;
6081 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
6083 Class _class = link.data;
6084 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *") && strcmp(dest._class.string, "bool"))) && !dest.classObjectType)) &&
6085 dest.kind != pointerType && dest.kind != ellipsisType)
6087 OldList conversions { };
6089 type.kind = classType;
6090 type._class = FindClass(_class.name);
6091 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false, true))
6093 ListEnumValues(_class);
6096 conversions.Free(null);
6100 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
6102 result |= ListEnums(nameSpace, dest);
6107 NameSpace * FindNameSpace(NameSpace nameSpace, const char * name)
6111 for(c = 0; (ch = name[c]); c++)
6113 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
6115 NameSpace * newSpace;
6116 char * spaceName = new char[c - start + 1];
6117 memcpy(spaceName, name + start, c - start);
6118 spaceName[c-start] = '\0';
6119 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
6123 nameSpace = newSpace;
6132 return (NameSpace *)nameSpace;
6135 void ListSymbols(Expression exp, bool enumOnly, const char * string, Identifier realIdentifier)
6137 bool listedEnums = false;
6138 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
6139 bool listClasses = true;
6141 if(exp && (exp.type == identifierExp || exp.type == memberExp))
6143 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
6144 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
6145 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
6147 if(exp.type == identifierExp)
6148 id = realIdentifier;
6150 if(id && id._class && !id._class.name)
6152 listClasses = false;
6155 else if(id && id._class && id._class.name)
6159 Class _class = id.classSym.registered;
6160 if(_class && _class.type == enumClass)
6162 ListEnumValues(_class);
6165 ListClassMembers(id.classSym.registered, true);
6170 else if(id && colons)
6172 ListNameSpaceByString(this.privateModule, id.string);
6177 if(this.privateModule && destType && (destType.kind == _BoolType || destType.kind == classType || destType.kind == enumType || destType.kind == structType || destType.kind == templateType || destType.kind == thisClassType || destType.kind == unionType ||
6178 (destType.kind == pointerType && destType.type.kind != voidType)))
6179 //if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6181 listedEnums = ListEnumsModule(this.privateModule, destType);
6184 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6186 ListEnumValues(destType._class.registered);
6189 ListClassPropertiesAndVirtual(insideClass, null);
6193 else if(destType && destType.kind == enumType)
6197 for(value = destType.members.first; value; value = value.next)
6199 DataRow row = membersList.AddString(value.name);
6200 row.icon = icons[typeEnumValue];
6204 ListClassPropertiesAndVirtual(insideClass, null);
6208 else if(insideClass && !enumOnly)
6210 ListClassPropertiesAndVirtual(insideClass, string);
6213 if(listedEnums && string && string[0])
6215 DataRow row = membersList.FindSubString(string);
6217 listedEnums = false;
6220 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6222 ListClassMembersMatch(GetThisClass(), exp.destType);
6224 else if(!insideClass && !enumOnly && !listedEnums)
6227 Symbol symbol = null;
6231 ListClassMembers(GetThisClass(), false);
6234 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6236 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6238 // Don't list enum values?
6239 //if(symbol.type.kind != TypeEnum)
6240 DataRow row = membersList.FindString(symbol.string);
6243 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6245 row = membersList.AddString(symbol.string);
6246 if(symbol.type && symbol.type.kind == functionType)
6247 row.icon = icons[typeMethod];
6248 else if(symbol.type && symbol.type.kind == enumType)
6250 row.icon = icons[typeEnumValue];
6254 BitmapResource bitmap = null;
6255 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6257 char * bitmapName = (char *)(intptr)eClass_GetProperty(symbol.type._class.registered, "icon");
6260 bitmap = { bitmapName };
6261 membersList.AddResource(bitmap);
6264 row.icon = bitmap ? bitmap : icons[typeData];
6271 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6273 DataRow row = membersList.FindString(symbol.string);
6276 row = membersList.AddString(symbol.string);
6277 if(symbol.type.kind == functionType)
6278 row.icon = icons[typeMethod];
6279 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6281 row.icon = icons[typeClass];
6285 row.icon = icons[typeDataType];
6292 ListModule(this.privateModule, 1, listClasses);
6293 // TODO: Implement this with name space
6297 for(data = globalData.first; data; data = data.next)
6299 DataRow row = membersList.FindString(data.name);
6301 data.dataType = ProcessTypeString(data.dataTypeString, false);
6304 row = membersList.AddString(data.name);
6306 if(data.dataType && data.dataType.kind == TypeEnum)
6308 row.icon = icons[typeEnumValue];
6312 BitmapResource bitmap = null;
6313 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6315 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6318 bitmap = { bitmapName };
6319 membersList.AddResource(bitmap);
6322 row.icon = bitmap ? bitmap : icons[typeData];
6330 DataRow row = membersList.AddString("Min");
6331 row.icon = icons[typeMethod];
6333 row = membersList.AddString("Max");
6334 row.icon = icons[typeMethod];
6336 row = membersList.AddString("Abs");
6337 row.icon = icons[typeMethod];
6339 row = membersList.AddString("Sgn");
6340 row.icon = icons[typeMethod];
6346 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6348 EditBoxStream f { editBox = editBox };
6353 updatingCode = true;
6355 if(!method.dataType)
6356 method.dataType = ProcessTypeString(method.dataTypeString, false);
6358 DeleteJunkBefore(f, function.loc.start.pos, &position);
6359 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6361 // ADDING METHOD HERE
6363 Type dataType = method.dataType;
6364 Type returnType = dataType.returnType;
6366 // Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6372 if(extraIndent) f.Printf(" ");
6374 OutputType(f, returnType, false);
6378 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6380 if(dataType.thisClass.shortName)
6381 f.Printf(dataType.thisClass.shortName);
6383 f.Printf(dataType.thisClass.string);
6386 f.Printf(method.name);
6388 for(param = dataType.params.first; param; param = param.next)
6390 // Decided not to write void...
6391 if(param.kind != voidType)
6393 OutputType(f, param, true);
6399 if(extraIndent) f.Printf(" ");
6400 f.Printf(" %c\n", OpenBracket);
6402 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6408 (isInstance ? _class : _class.base)._vTbl[method.vid] == null /*moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]*/ ||
6409 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6411 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6413 if(extraIndent) f.Printf(" ");
6414 f.Printf(" return true;\n");
6416 else if(returnType && returnType.kind != voidType)
6418 if(extraIndent) f.Printf(" ");
6419 f.Printf(" return 0;\n");
6424 if(extraIndent) f.Printf(" ");
6426 if(returnType.kind != voidType)
6427 f.Printf("return ");
6428 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6429 for(param = dataType.params.first; param; param = param.next)
6431 if(param.prev) f.Printf(", ");
6432 if(param.kind != voidType)
6433 f.Printf(param.name);
6439 if(extraIndent) f.Printf(" ");
6440 f.Printf(" %c", CloseBracket);
6445 if(extraIndent) { x1 += 3; x2 += 3; }
6446 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6448 this.updatingCode = false;
6452 // Return false if we overrided a function and don't want to run params listing
6453 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6455 bool didOverride = false;
6456 EditLine line = editBox.line;
6457 int lineNum, charPos;
6458 Expression exp = null;
6461 //Identifier id = null;
6462 Expression memberExp = null;
6463 Identifier realIdentifier = null;
6465 if(!parsing) return true;
6466 if(!privateModule) return !didOverride;
6468 insideFunction = null;
6470 charPos = editBox.charPos + 1;
6471 if(!membersListShown)
6476 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6478 EditBoxStream f { editBox = editBox };
6480 updatingCode = true;
6481 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6485 if(!f.Seek(-1, current))
6488 if(!isspace(ch)) break;
6489 f.Seek(-1, current);
6491 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6493 lineNum = editBox.lineNumber + 1;
6494 charPos = editBox.charPos + 1;
6496 updatingCode = false;
6499 if(!membersListShown)
6501 memberExp = FindExpTree(ast, lineNum, charPos);
6502 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6507 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6509 EditBoxStream f { editBox = editBox };
6512 updatingCode = true;
6514 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6517 if(ch == '}' || ch == ',' || ch == ')')
6519 f.Seek(-1, current);
6527 if(!f.Seek(-1, current))
6530 if(!isspace(ch)) break;
6531 f.Seek(-1, current);
6535 f.Seek(-1, current);
6537 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6539 lineNum = editBox.lineNumber + 1;
6540 charPos = editBox.charPos + 1;
6542 updatingCode = false;
6545 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6550 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6551 lineNum = editBox.lineNumber + 1;
6552 charPos = editBox.charPos/* + 1*/;
6556 char tempString[1024];
6557 char * string = null;
6558 CodePosition idStart { };
6559 CodePosition idEnd { };
6561 if(membersListShown)
6563 const char * buffer = membersLine.text;
6565 bool firstChar = true;
6567 string = tempString;
6569 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6571 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6572 if(!isSpace) firstChar = false;
6574 string[len++] = buffer[c];
6578 else //if(realIdentifier)//if(id)
6581 char * buffer = id.string;
6583 bool firstChar = true;
6585 string = tempString;
6586 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6588 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6589 if(!isSpace) firstChar = false;
6591 string[len++] = buffer[c];
6597 EditLine editLine = editBox.line;
6598 bool firstChar = true;
6601 string = tempString;
6602 for(y = lineNum-1; y >= 0; y--)
6604 const char * buffer = editLine.text;
6605 int lineCount = editLine.count;
6606 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6608 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6613 idEnd.charPos = x + 2;
6618 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6621 idEnd.charPos = x + 2;
6628 if(!isalnum(buffer[x]) && buffer[x] != '_')
6634 memmove(string+1, string, len++);
6635 string[0] = buffer[x];
6639 //if(done || firstChar)
6640 if(done || !firstChar)
6642 editLine = editLine.prev;
6645 if(!strcmp(string, "case"))
6651 else if(!strcmp(string, "return"))
6657 else if(!strcmp(string, "delete"))
6663 else if(!strcmp(string, "new"))
6669 else if(!strcmp(string, "renew"))
6677 idStart.charPos = x + 1;
6678 idStart.line = y + 1;
6681 if(!membersListShown)
6683 membersList.Clear();
6684 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6686 Type type = memberExp.member.exp.expType;
6687 if(pointer == 2 && type)
6689 if(type.kind == pointerType || type.kind == arrayType)
6698 ListSymbols(exp, enumOnly, string, realIdentifier);
6700 membersList.Sort(null, 1);
6705 // Virtual function override
6706 Identifier id = GetDeclId(insideFunction.declarator);
6707 char * string = id ? id.string : null;
6709 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6712 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6713 insideFunction = null;
6716 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6721 if(!didOverride) //insideFunction)
6723 rowCount = membersList.rowCount;
6726 DataRow row = string ? membersList.FindSubString(string) : null;
6727 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6729 const char * newString = row.string;
6730 if(!membersListShown)
6732 membersLoc.start.line = idStart.line-1;
6733 membersLoc.start.charPos = idStart.charPos-1;
6734 //membersLoc.end = membersLoc.start;
6735 membersLoc.end.charPos = idEnd.charPos-1;
6736 membersLoc.end.line = idEnd.line-1;
6737 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6738 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6743 membersList.Destroy(0);
6744 membersListShown = false;
6747 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6749 line, membersLoc.start.line, membersLoc.start.charPos,
6750 line, membersLoc.end.line, membersLoc.end.charPos);
6751 editBox.PutS(newString);
6757 row = membersList.FindSubStringi(string);
6759 membersList.currentRow = row;
6760 membersList.currentRow.selected = false;
6763 membersList.currentRow = row;
6765 if(!membersListShown)
6769 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6770 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6771 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6772 editBox.GetCaretPosition(caret);
6773 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6775 membersList.master = this;
6777 caret.y += editBox.GetCaretSize();
6779 membersList.Create();
6782 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6783 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6784 Window parent = membersList.parent;
6786 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6788 y -= editBox.GetCaretSize() + membersList.size.h;
6789 membersAbove = true;
6792 membersAbove = false;
6794 membersList.position = { x, y };
6798 membersLoc.start.line = lineNum - 1;
6800 if(string && string[0])
6802 membersLoc.start.charPos = idStart.charPos-1;
6803 membersLoc.end = membersLoc.start;
6804 //membersLoc.end.charPos = id.loc.end.charPos-1;
6805 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6809 membersLoc.start.charPos = charPos;
6810 membersLoc.end = membersLoc.start;
6811 membersLoc.end.charPos = charPos;
6813 membersListShown = true;
6815 // Hack to keep caret shown
6816 editBox.GetCaretPosition(caret);
6817 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6820 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6826 SetCurrentContext(globalContext);
6829 return !didOverride;
6832 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6834 int lineNum, charPos;
6838 if(!parsing) return;
6840 charPos = editBox.charPos + 1;
6843 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6845 EditBoxStream f { editBox = editBox };
6848 updatingCode = true;
6849 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6852 if(ch == '}' || ch == ',' || ch == ')')
6854 f.Seek(-1, current);
6862 if(!f.Seek(-1, current))
6865 if(!isspace(ch)) break;
6866 f.Seek(-1, current);
6870 f.Seek(-1, current);
6872 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6874 lineNum = editBox.lineNumber + 1;
6875 charPos = editBox.charPos + 1;
6877 updatingCode = false;
6880 charPos = Min(charPos, l1.count + 1);
6882 FindParamsTree(ast, lineNum, charPos);
6884 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6885 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6887 ::functionType = null;
6888 ::instanceType = null;
6891 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6892 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6896 Window parent = paramsList.parent;
6898 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6901 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6902 // ( Dummy exp: always ends up with same memory)
6904 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6905 editBox.GetCaretPosition(paramsPosition);
6906 this.paramsPosition.y += editBox.GetCaretSize();
6909 FreeType(this.functionType);
6910 FreeType(this.instanceType);
6912 this.functionType = ::functionType;
6913 this.instanceType = ::instanceType;
6915 if(this.functionType) this.functionType.refCount++;
6916 if(this.instanceType) this.instanceType.refCount++;
6918 this.paramsID = ::paramsID;
6919 functionExp = paramsInsideExp;
6921 paramsList.master = this;
6923 paramsList.Create();
6925 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6926 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6928 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6930 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6934 paramsAbove = false;
6935 if(x + paramsList.size.w > parent.clientSize.w)
6937 x = parent.clientSize.w - paramsList.size.w;
6941 paramsList.position = { x, y };
6943 // Hack to keep caret shown
6946 editBox.GetCaretPosition(caret);
6947 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6950 this.paramsShown = true;
6952 else if((!::functionType && !::instanceType) || reposition)
6954 paramsList.Destroy(0);
6955 paramsShown = false;
6957 FreeType(this.functionType);
6958 FreeType(this.instanceType);
6959 this.functionType = null;
6960 this.instanceType = null;
6964 SetCurrentContext(globalContext);
6972 designer.visible = true;
6973 designer.Activate();
6979 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6981 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };
6986 static int nofdigits(int v)
6988 if(v == MININT) return 10 + 1;
6989 if(v < 0) return nofdigits(-v) + 1;