3 // *** Color Schemes ***
5 // *** The Old Color Scheme that was causing me auras and ophtalmic migraines -- Uncomment at your own risk! ***
7 FontResource panelFont { $"Courier New", 10 };
8 FontResource codeFont { $"Courier New", 10 };
9 Color selectionColor = Color { 10, 36, 106 };
10 Color selectionText = white;
11 Color viewsBackground = white;
12 Color viewsText = black;
13 Color outputBackground = white;
14 Color outputText = black;
15 Color projectViewBackground = white;
16 Color projectViewText = black;
17 Color codeEditorBG = white;
18 Color codeEditorFG = black;
19 Color marginColor = Color {230, 230, 230};
20 Color selectedMarginColor = Color {200, 200, 200};
21 Color lineNumbersColor = Color {60, 60, 60};
22 SyntaxColorScheme colorScheme
24 keywordColors = [ blue, blue ];
25 commentColor = dimGray;
26 charLiteralColor = crimson;
27 stringLiteralColor = crimson;
28 preprocessorColor = green;
33 // The new nice dark scheme -- so peaceful on my brain
35 FontResource panelFont { $"Courier New", 10 };
36 FontResource codeFont { $"Courier New", 10 };
38 FontResource panelFont { $"Consolas", 12 };
39 FontResource codeFont { $"Consolas", 12 };
41 Color selectionColor = lightYellow;
42 Color selectionText = Color { 30, 40, 50 };
43 Color viewsBackground = Color { 30, 40, 50 };
44 Color viewsText = lightGray;
45 Color outputBackground = black;
46 Color outputText = lime;
47 Color projectViewBackground = Color { 30, 40, 50 };
48 Color projectViewText = lightGray;
49 Color codeEditorBG = black;
50 Color codeEditorFG = ivory;
51 Color marginColor = Color {24, 24, 24};
52 Color selectedMarginColor = Color {64, 64, 64};
53 Color lineNumbersColor = Color {160, 160, 160};
54 SyntaxColorScheme colorScheme
56 keywordColors = [ skyBlue, skyBlue ];
57 commentColor = Color { 125, 125, 125 };
58 charLiteralColor = Color { 245, 50, 245 };
59 stringLiteralColor = Color { 245, 50, 245 };
60 preprocessorColor = { 120, 220, 140 };
61 numberColor = Color { 0, 192, 192 };
64 // *********************
70 // UNTIL IMPLEMENTED IN GRAMMAR
71 #define ACCESS_CLASSDATA(_class, baseClass) \
72 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
75 extern int __attribute__((__stdcall__)) __ecereDll_Load_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
76 extern int __attribute__((__stdcall__)) __ecereDll_Unload_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
79 static Array<FileFilter> fileFilters
81 { $"C/C++/eC Files (*.ec, *.eh, *.c, *.cpp, *.cc, *.cxx, *.h, *.hpp, *.hh, *.hxx)", "ec, eh, c, cpp, cc, cxx, h, hpp, hh, hxx" },
82 { $"Header Files for C/C++ (*.eh, *.h, *.hpp, *.hh, *.hxx)", "eh, h, hpp, hh, hxx" },
83 { $"C/C++/eC Source Files (*.ec, *.c, *.cpp, *.cc, *.cxx)", "ec, c, cpp, cc, cxx" },
84 { $"Text files (*.txt)", "txt" },
85 { $"All files", null }
88 static Array<FileType> fileTypes
90 { $"eC Source Code", "ec", whenNoneGiven },
91 { $"Text Files", "txt", never }
94 static char * iconNames[] =
96 "<:ecere>constructs/class.png",
97 "<:ecere>constructs/data.png",
98 "<:ecere>constructs/method.png",
99 "<:ecere>constructs/event.png",
100 "<:ecere>constructs/property.png",
101 "<:ecere>constructs/namespace.png",
102 "<:ecere>constructs/dataType.png",
103 "<:ecere>constructs/enumValue.png",
104 "<:ecere>constructs/dataPrivate.png",
105 "<:ecere>constructs/methodPrivate.png",
106 "<:ecere>constructs/propertyPrivate.png"
109 enum SheetType { methods, properties };
111 extern int __ecereVMethodID_class_OnEdit;
112 extern int __ecereVMethodID_class_OnDisplay;
113 extern int __ecereVMethodID_class_OnGetString;
114 extern int __ecereVMethodID_class_OnFree;
115 extern int __ecereVMethodID_class_OnCompare;
116 extern int __ecereVMethodID_class_OnCopy;
117 extern int __ecereVMethodID_class_OnSaveEdit;
118 extern int __ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad;
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;
171 bool parseError = false;
176 Expression ctxInsideExp;
177 Expression paramsInsideExp;
178 ClassFunction insideFunction;
186 /****************************************************************************
188 ****************************************************************************/
190 static void OutputString(File f, char * string)
193 for(c = 0; string[c]; c++)
195 if(string[c] == '\"')
197 else if(string[c] == '\\')
204 void OutputType(File f, Type type, bool outputName)
214 if(!type.isSigned) f.Printf("unsigned ");
218 if(!type.isSigned) f.Printf("unsigned ");
222 if(!type.isSigned) f.Printf("unsigned ");
226 if(!type.isSigned) f.Printf("unsigned ");
230 if(!type.isSigned) f.Printf("unsigned ");
241 if(type._class && !strcmp(type._class.string, "class"))
243 switch(type.classObjectType)
246 f.Printf("any_object");
249 f.Printf("typed_object");
256 // ADD CODE TO DECIDE WHETHER TO OUTPUT FULLY QUAlIFIED OR NOT:
257 f.Printf(type._class.shortName ? type._class.shortName : type._class.string);
267 OutputType(f, type.type, false);
270 OutputType(f, type.type, false);
289 if(type.kind == arrayType)
292 f.Printf("%d", type.arraySize);
298 void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
304 f.Seek(pos - *position, current);
306 // Try to delete spaces and \n before...
312 /*else if(ch == '\n')
314 // Look for // comments on the line before
315 EditBox editBox = f.editBox;
316 EditLine line = editBox.line;
323 for(c = 0; text[c]; c++)
332 if(text[c] == '/' && last == '/')
344 f.DeleteBytes(before);
349 void GetLocText(EditBox editBox, File f, int position, Location loc, char ** text, int * size, int pad, int linePad)
354 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
356 // Cut & Paste function
362 f.Seek(loc.start.pos - position, current);
364 x1 = editBox.charPos;
365 y1 = editBox.lineNumber;
366 f.Seek(loc.end.pos - loc.start.pos, current);
368 x2 = editBox.charPos;
369 y2 = editBox.lineNumber;
370 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
372 *size = editBox.SelSize();
373 *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
374 editBox.GetSel(*text, false);
377 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
378 f.Printf(""); // Make the stream point to where the editbox is
381 void Code_FixProperty(Property prop, Instance object)
383 Designer::FixProperty(prop, object);
386 bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
389 if(prop.dataTypeString && (!prop.IsSet || prop.IsSet(selected.instance)))
391 Class dataType = prop.dataTypeClass;
394 dataType = prop.dataTypeClass = eSystem_FindClass(test._class.module, prop.dataTypeString);
396 if(dataType && dataType._vTbl && dataType.type == structClass)
398 void * dataForm = new0 byte[dataType.structSize];
399 void * dataTest = new0 byte[dataType.structSize];
401 ((void (*)(void *, void *))(void *)prop.Get)(selected.instance, dataForm);
402 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
404 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
406 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
412 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
414 void * dataForm, * dataTest;
416 dataForm = ((void *(*)(void *))(void *)prop.Get)(selected.instance);
417 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
419 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
421 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
425 else if(dataType && dataType._vTbl)
427 DataValue dataForm, dataTest;
429 GetProperty(prop, selected.instance, &dataForm);
430 GetProperty(prop, test, &dataTest);
432 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
434 SetProperty(prop, test, dataForm);
436 // In case setting on test unset on real instance (e.g. isDefault)
437 if(strcmp(prop.name, "name"))
439 GetProperty(prop, selected.instance, &dataTest);
440 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
441 SetProperty(prop, selected.instance, dataForm);
450 bool Code_IsPropertyDisabled(ObjectInfo selected, char * name)
452 bool disabled = false;
453 if(selected.oClass == selected)
456 if(selected.classDefinition)
458 for(def = selected.classDefinition.definitions->first; def; def = def.next)
460 if(def.type == defaultPropertiesClassDef)
463 for(prop = def.defProperties->first; prop; prop = prop.next)
465 if(prop.identifiers && prop.identifiers->first)
467 Identifier id = prop.identifiers->first;
468 if(prop.variable && !strcmp(id.string, name))
480 else if(selected.instCode)
483 if(selected.instCode.members)
485 for(members = selected.instCode.members->first; members; members = members.next)
487 if(members.type == dataMembersInit && members.dataMembers)
490 for(prop = members.dataMembers->first; prop; prop = prop.next)
492 if(prop.identifiers && prop.identifiers->first)
494 Identifier id = prop.identifiers->first;
495 if(prop.variable && !strcmp(id.string, name))
510 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
515 method.dataType = ProcessTypeString(method.dataTypeString, false);
516 if(!method.dataType.thisClass && !isForm)
519 method.dataType.thisClass = selectedClass;
521 //result = MatchTypes(method.dataType, type, null, regClass, regClass, false);
522 result = MatchTypes(type, method.dataType, null, regClass, regClass, false, true, true, false);
524 method.dataType.thisClass = null;
528 bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo object)
530 bool confirmation = true;
531 Statement body = function.body;
532 // Check if it contains any code
533 if((!body.compound.declarations || !body.compound.declarations->count) && (!body.compound.statements || body.compound.statements->count <= 1))
535 Class moduleClass = eSystem_FindClass(object.instance._class.module, "Module");
536 Statement stmt = body.compound.statements ? body.compound.statements->first : null;
537 Type dataType = method.dataType;
538 Type returnType = dataType.returnType;
539 Expression exp = null;
542 method.dataType = ProcessTypeString(method.dataTypeString, false);
544 confirmation = false;
546 // Check if default function should be calling base class:
547 if(object.instance._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
549 if(returnType.kind != voidType)
551 if(!stmt || stmt.type != returnStmt || !stmt.expressions || stmt.expressions->count != 1)
555 exp = stmt.expressions->first;
556 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
558 if( (exp.type != identifierExp || strcmp(exp.identifier.string, "true")) &&
559 (exp.type != constantExp || strcmp(exp.constant, "1")))
564 if(exp.type != constantExp || strcmp(exp.constant, "0"))
579 if(returnType.kind != voidType)
581 if(stmt.type == returnStmt && stmt.expressions && stmt.expressions->count == 1)
582 exp = stmt.expressions->first;
584 else if(stmt.type == expressionStmt && stmt.expressions && stmt.expressions->count == 1)
585 exp = stmt.expressions->first;
588 if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
592 Identifier id = exp.call.exp.identifier;
593 Class base = object.instance._class;
594 if(!id._class || (id._class.name && !strcmp(id._class.name, base.name)) || strcmp(id.string, method.name))
598 Expression arg = exp.call.arguments ? exp.call.arguments->first : null;
599 if(!arg || arg.type != identifierExp || strcmp("this", arg.identifier.string))
605 for(param = dataType.params.first; param; param = param.next)
607 if(!arg || arg.type != identifierExp || strcmp(param.name, arg.identifier.string))
612 arg = arg ?arg.next : null;
619 return !confirmation;
622 class CodeEditor : Window
624 background = marginColor;
625 borderStyle = sizableDeep;
630 isActiveClient = true;
631 anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
634 // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
635 // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
637 SheetType sheetSelected;
642 Context globalContext { };
643 OldList excludedSymbols { offset = (uint)&((Symbol)0).left };
656 MethodAction methodAction;
658 ClassFunction function;
660 char methodName[1024];
665 bool membersListShown;
668 EditLine membersLine;
670 Type functionType, instanceType;
674 Point paramsPosition;
675 Expression functionExp;
678 BitmapResource icons[CodeObjectType];
680 FontResource boldFont { $"Tahoma", 8.25f, bold = true, window = this };
681 FontResource normalFont { $"Tahoma", 8.25f, window = this };
683 Module privateModule;
684 NameSpace globalData;
687 OpenedFileInfo openedFileInfo;
689 FontResource font { codeFont.faceName, codeFont.size };
690 saveDialog = codeEditorFileDialog;
692 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
695 int maxLineNumberLength;
697 property bool parsing { get { return editBox.syntaxHighlighting && !noParsing && !ide.noParsing; } };
699 void ProcessCaretMove(EditBox editBox, int line, int charPos)
702 ObjectInfo classItem;
704 // OnActivateClient is called after OnActivate
707 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
710 if(sheet.codeEditor != this) return;
714 for(classItem = classes.first; classItem; classItem = classItem.next)
716 ClassDefinition classDef = classItem.classDefinition;
717 if(classDef && classDef.loc.Inside(line, charPos))
724 for(object = classItem.instances.first; object; object = object.next)
728 if(object.instCode.loc.Inside(line, charPos))
733 sheet.SelectObject(object);
735 sheet.SelectObject(classItem);
740 //sheet.SelectObject(null);
744 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
748 expectingMove = false;
754 if(line-1 != membersLoc.start.line)
758 char * buffer = membersLine.text;
761 if(charPos - 1 < membersLoc.start.charPos)
763 else if(charPos - 1 > membersLoc.end.charPos)
765 char * buffer = membersLine.text;
766 //if(membersList.currentRow)
770 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
771 if(buffer[c] != ' ' && buffer[c] != '\t')
773 if(c < charPos && buffer[c])
780 membersList.Destroy(0);
781 membersListShown = false;
785 bool back = codeModified;
786 codeModified = false;
788 InvokeParameters(false, false, false);
789 /*if(membersListShown)
790 InvokeAutoComplete(false, 0, true);*/
797 watch(modifiedDocument)
799 ProjectView projectView = ide.projectView;
802 char buffer[MAX_LOCATION];
803 char * fullPath = GetSlashPathBuffer(buffer, fileName);
804 Array<ProjectNode> nodes = ide.workspace.GetAllProjectNodes(fullPath, false);
808 node.modified = modifiedDocument;
809 projectView.Update(null);
817 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
818 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
819 tabKey = true, smartHome = true;
820 tabSelection = true, /*maxLineSize = 65536, */parent = this, hasHorzScroll = true, hasVertScroll = true;
821 selectionColor = selectionColor, selectionText = selectionText,
822 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
823 font = font, borderStyle = none;
824 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
826 bool OnMouseOver(int x, int y, Modifiers mods)
828 CodeEditor editor = (CodeEditor)master;
829 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
834 void NotifyCaretMove(EditBox editBox, int line, int charPos)
836 // Update Line Numbers
838 int oldLine = lastLine;
839 display.FontExtent(font.font, " ", 1, null, &spaceH);
841 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
845 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
850 if(ide.activeClient == this)
851 ProcessCaretMove(editBox, line, charPos);
853 openedFileInfo.CaretMove(line, charPos);
856 void NotifyOvrToggle(EditBox editBox, bool overwrite)
858 ide.ovr.color = overwrite ? black : Color { 128, 128, 128 };
861 void NotifyUpdate(EditBox editBox)
868 designer.modifiedDocument = true;
871 modifiedDocument = true;
874 bool NotifyUnsetModified(EditBox editBox)
876 modifiedDocument = false;
880 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
882 if(!loadingFile && after.y != before.y)
884 ProjectView projectView = ide.projectView;
885 if(projectView && fileName)
888 // HOW WE MIGHT WANT TO DO IT:
889 char * text = before.line.text;
890 for(c = before.x-1; c>= 0; c--)
891 if(!isspace(text[c]))
893 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
895 // HOW VISUAL STUDIO DOES IT:
897 char * text = after.line.text;
898 for(c = after.line.count-1; c>= 0; c--)
899 if(!isspace(text[c]))
901 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
904 Update({ 0, 0, editBox.position.x, clientSize.h });
912 for(oClass = classes.first; oClass; oClass = oClass.next)
915 for(object = oClass.instances.first; object; object = object.next)
919 object.instCode.loc.start.AdjustAdd(before, after);
920 object.instCode.loc.end.AdjustAdd(before, after);
925 oClass.classDefinition.loc.start.AdjustAdd(before, after);
926 oClass.classDefinition.loc.end.AdjustAdd(before, after);
932 expectingMove = true;
936 if(before.y != after.y)
940 char * buffer = membersLine.text;
942 bool firstChar = true;
943 bool addedChar = false;
949 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
951 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
953 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
954 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
963 membersLoc.start.charPos++;
968 string[len++] = buffer[c];
972 row = membersList.currentRow;
973 if(row && row.selected)
977 membersLoc.start.charPos--;
985 row = membersList.FindSubString(string);
987 membersList.currentRow = row;
990 row = membersList.FindSubStringi(string);
992 membersList.currentRow = row;
993 membersList.currentRow.selected = false;
996 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
1000 row = membersList.currentRow;
1003 // Accept current string if hiding typing char
1004 if(hide && row && row.selected)
1006 char * string = row.string;
1007 int len = strlen(string);
1008 membersLoc.end.charPos -= after.x - before.x;
1009 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1010 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
1011 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1012 editBox.PutS(string);
1013 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
1015 after.x += membersLoc.start.charPos + len - before.x;
1016 before.x = membersLoc.start.charPos + len;
1021 membersList.Destroy(0);
1022 membersListShown = false;
1025 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
1027 EditLine line = editBox.line;
1028 char * text = line.text;
1029 char ch = text[after.x-1];
1030 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1034 // Can we call invoke auto complete here instead?
1044 // Force caret update already...
1045 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1046 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1048 editBox.GetCaretPosition(&caret);
1052 // Go back in the buffer until no space before
1054 codeModified = true;
1058 EditBoxStream f { editBox = editBox };
1062 if(text[after.x-1] == '>')
1068 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1072 if(!f.Seek(-1, current))
1075 if(!isspace(ch)) break;
1076 f.Seek(-1, current);
1078 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1080 line = editBox.lineNumber + 1;
1081 charPos = editBox.charPos + 1;
1085 exp = FindExpTree(ast, line, charPos);
1089 Type type = exp.expType;
1091 if(type && text[after.x-1] != '.')
1093 if(type.kind == TypePointer || type.kind == TypeArray)
1099 membersList.Clear();
1102 if(membersList.rowCount)
1104 membersList.Sort(null, 1);
1105 membersList.master = this;
1107 caret.y += editBox.GetCaretSize();
1110 membersList.Create();
1113 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1114 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1115 Window parent = membersList.parent;
1117 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1119 y -= editBox.GetCaretSize() + membersList.GetHeight();
1120 membersAbove = true;
1123 membersAbove = false;
1125 membersList.position = { x, y };
1129 membersLoc.start.line = line - 1;
1130 membersLoc.start.charPos = oldCharPos;
1131 membersLoc.end = membersLoc.start;
1132 membersListShown = true;
1137 SetCurrentContext(globalContext);
1139 codeModified = true;
1140 skipModified = true;
1141 if(text[after.x-1] == ':')
1142 InvokeAutoComplete(false, 0, false);
1143 else if(text[after.x-1] == '.')
1144 InvokeAutoComplete(false, 1, false);
1145 else if(text[after.x-1] == '>')
1146 InvokeAutoComplete(false, 2, false);
1147 skipModified = false;
1149 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1151 codeModified = true;
1152 skipModified = true;
1154 if(InvokeAutoComplete(true, 0, false))
1156 if(ch == '(' || ch == OpenBracket)
1157 InvokeParameters(true, true, false);
1159 InvokeParameters(this.functionType ? false : true, false, false);
1162 // InvokeAutoComplete(true, 0, false);
1163 skipModified = false;
1165 else if(ch == ')' || ch == '}' || ch == ';')
1167 codeModified = true;
1168 skipModified = true;
1170 InvokeParameters(false, true, false);
1171 skipModified = false;
1175 bool back = codeModified;
1176 codeModified = false;
1178 InvokeParameters(false, false, true);
1179 if(membersListShown)
1180 InvokeAutoComplete(false, 0, true);
1181 codeModified = back;
1186 bool back = codeModified;
1187 codeModified = false;
1190 InvokeParameters(false, false, true);
1191 /*if(membersListShown)
1192 InvokeAutoComplete(false, 0, true);*/
1194 codeModified = back;
1201 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1203 if(!loadingFile && after.y != before.y)
1205 ProjectView projectView = ide.projectView;
1206 if(projectView && fileName)
1207 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1208 Update({ 0, 0, editBox.position.x, clientSize.h });
1216 for(oClass = classes.first; oClass; oClass = oClass.next)
1220 for(object = oClass.instances.first; object; object = object.next)
1224 loc = &object.instCode.loc;
1226 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1227 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1229 object.instCode = null;
1233 loc->start.AdjustDelete(before, after);
1234 loc->end.AdjustDelete(before, after);
1238 if(oClass.classDefinition)
1240 loc = &oClass.classDefinition.loc;
1241 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1242 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1244 oClass.classDefinition = null;
1248 loc->start.AdjustDelete(before, after);
1249 loc->end.AdjustDelete(before, after);
1254 if(membersListShown)
1257 if(pasteOperation || before.y != after.y)
1261 char * buffer = membersLine.text;
1263 bool firstChar = true;
1267 if(before.x >= membersLoc.start.charPos)
1269 for(c = membersLoc.start.charPos; c<before.x && len < sizeof(string)-1; c++)
1271 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1272 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1277 if(!isSpace) firstChar = false;
1280 string[len++] = buffer[c];
1285 // If deleting spaces before...
1286 for(c = before.x; c<membersLoc.start.charPos; c++)
1288 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1296 membersLoc.start.charPos = before.x;
1299 if(membersLoc.end.charPos >= after.x)
1301 for(c = after.x; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1303 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1304 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1309 if(!isSpace) firstChar = false;
1312 string[len++] = buffer[c];
1320 membersLoc.end.charPos -= after.x - before.x;
1324 row = membersList.FindSubString(string);
1327 row = membersList.FindSubStringi(string);
1329 membersList.currentRow = row;
1330 membersList.currentRow.selected = false;
1333 membersList.currentRow = row;
1335 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1340 membersList.Destroy(0);
1341 membersListShown = false;
1347 InvokeParameters(false, false);
1355 bool NotifyDropped(EditBox editBox, int x, int y)
1357 char * controlClass = toolBox.controlClass;
1358 if(controlClass && controlClass[0])
1362 ObjectInfo classObject;
1364 //editBox.NotifyCaretMove(this, editBox, y, x);
1365 editBox.GoToLineNum(y);
1366 editBox.GoToPosition(editBox.line, y, x);
1368 classObject = selected ? selected.oClass : null;
1370 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1371 selected = classObject.instances.last;
1374 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1377 AddObject(control, &object);
1379 designer.CreateObject(control, object, false, classObject.instance);
1380 // designer.PostCreateObject(control, object, false, classObject.instance);
1381 designer.DroppedObject(control, object, false, classObject.instance);
1383 sheet.AddObject(object, object.name, typeData /* className*/, true);
1386 //codeModified = true;
1393 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1395 if(key == ctrlSpace)
1397 membersList.Destroy(0);
1398 membersListShown = false;
1399 InvokeAutoComplete(false, 0, false);
1402 else if(key == Key { space, ctrl = true, shift = true })
1403 InvokeParameters(false, true, false);
1404 else if(key == escape)
1405 ide.RepositionWindows(true);
1406 else if(key == ctrlF7)
1410 ProjectNode node = ide.projectView.GetNodeFromWindow(this, null, true, false);
1412 node = ide.projectView.GetNodeFromWindow(this, null, true, true);
1416 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1417 $"It can't be compiled.");
1418 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1427 bool OnKeyDown(Key key, unichar ch)
1429 CodeEditor editor = (CodeEditor)master;
1430 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1432 if(editor.membersListShown)
1434 editor.membersList.Destroy(0);
1435 editor.membersListShown = false;
1438 if(editor.paramsShown)
1440 editor.paramsList.Destroy(0);
1441 editor.paramsShown = false;
1442 FreeType(editor.functionType);
1443 FreeType(editor.instanceType);
1445 editor.functionType = null;
1446 editor.instanceType = null;
1447 editor.paramsID = -1;
1451 return EditBox::OnKeyDown(key, ch);
1454 void OnVScroll(ScrollBarAction action, int position, Key key)
1456 if(anchor.left.distance)
1458 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1461 EditBox::OnVScroll(action, position, key);
1463 CodeEditor ce = (CodeEditor)parent;
1464 if(ce.openedFileInfo)
1465 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1469 void OnHScroll(ScrollBarAction action, int position, Key key)
1471 EditBox::OnHScroll(action, position, key);
1473 CodeEditor ce = (CodeEditor)parent;
1474 if(ce.openedFileInfo)
1475 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1482 fullRowSelect = false,
1485 borderStyle = bevel;
1486 // size = { 200, 400 };
1488 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1490 DataRow row = listBox.currentRow;
1493 char * string = row.string;
1495 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1497 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1498 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1499 editBox.PutS(string);
1502 membersListShown = false;
1507 bool OnKeyDown(Key key, unichar ch)
1509 CodeEditor editor = (CodeEditor) master;
1510 if(key == escape || key == leftAlt || key == rightAlt ||
1511 (key.ctrl && key.code != left && key.code != right &&
1512 key.code != leftShift && key.code != rightShift && key.code != space))
1515 if(editor.paramsShown)
1519 editor.paramsList.Destroy(0);
1520 editor.paramsShown = false;
1522 if(editor.membersListShown)
1526 editor.membersList.Destroy(0);
1527 editor.membersListShown = false;
1530 FreeType(editor.functionType);
1531 editor.functionType = null;
1533 FreeType(editor.instanceType);
1534 editor.instanceType = null;
1536 editor.paramsID = -1;
1541 return editor.editBox.OnKeyDown(key, ch);
1545 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1547 CodeEditor editor = (CodeEditor)master;
1548 Window rw = previous ? previous.rootWindow : null;
1549 if(!active && rw != editor.paramsList)
1552 editor.membersListShown = false;
1554 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1557 bool OnKeyHit(Key key, unichar ch)
1559 CodeEditor editor = (CodeEditor) master;
1563 case enter: case tab:
1565 DataRow row = currentRow;
1566 if(row && row.selected)
1568 char * string = row.string;
1570 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1571 editor.editBox.Delete(
1572 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1573 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1574 editor.editBox.PutS(string);
1577 editor.membersListShown = false;
1580 editor.editBox.OnKeyHit(key, ch);
1590 return ListBox::OnKeyHit(key, ch);
1596 // If before . or after
1597 //listBox.Destroy(true);
1598 result = editor.editBox.OnKeyHit(key, ch);
1613 clickThrough = true,
1615 borderStyle = contour,
1617 background = { 255,255,225 },
1619 OnKeyDown = membersList.OnKeyDown;
1621 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1623 CodeEditor editor = (CodeEditor)master;
1624 Window rw = previous ? previous.rootWindow : null;
1625 if(!active && previous != editor.editBox && rw != editor.membersList)
1628 editor.paramsShown = false;
1630 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1633 bool OnKeyHit(Key key, unichar ch)
1635 CodeEditor editor = (CodeEditor)master;
1637 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1640 bool result = true; editor.editBox.OnKeyHit(key, ch);
1641 return (!created) ? false : result;
1648 void OnRedraw(Surface surface)
1650 CodeEditor editor = (CodeEditor) master;
1651 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1653 Type methodType = null;
1657 int functionW, nameW = 0;
1659 int spaceW, spaceH, commaW, commaWB, parW;
1661 int maxW = 0, lineW = 0;
1667 Font font = editor.normalFont.font;
1668 Font boldFont = editor.boldFont.font;
1669 Display display = this.display;
1671 if(!type) { return; };
1673 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1675 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1676 display.FontExtent(font, ", ", 2, &commaW, null);
1677 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1678 display.FontExtent(font, ")", 1, &parW, null);
1681 if(editor.functionType)
1683 PrintType(type.returnType, string, true, true);
1684 display.FontExtent(font, string, strlen(string), &functionW, null);
1686 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1687 totalW = nameW + functionW + 2 * parW;
1691 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1692 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1693 if(instanceName && type.kind != functionType)
1694 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1695 totalW = functionW + nameW;
1696 surface.TextFont(boldFont);
1699 surface.WriteText(x, y, string, strlen(string));
1700 x += functionW + spaceW;
1702 if(editor.functionType)
1705 surface.WriteText(x, y, type.name, strlen(type.name));
1707 surface.WriteText(x, y, "(", 1);
1710 if(methodType && !methodType.staticMethod && methodType.methodClass)
1714 if(id == editor.paramsID)
1715 surface.TextFont(boldFont);
1717 if(methodType.methodClass)
1718 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1722 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1723 width += ((id == editor.paramsID) ? commaWB : commaW);
1728 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1733 x = 2 + nameW + spaceW + functionW + parW;
1737 if(methodType.methodClass)
1738 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1741 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1743 surface.WriteText(x, y, ",", 1);
1744 x += ((id == editor.paramsID) ? commaWB : commaW);
1752 if(id == editor.paramsID)
1753 surface.TextFont(font);
1757 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1759 for(param = type.params.first; param; param = param.next)
1761 char paramString[1024];
1764 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1765 surface.TextFont(boldFont);
1768 PrintType(param, paramString, true, true);
1769 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1771 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1776 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1781 x = 2 + nameW + spaceW + functionW + parW;
1785 surface.WriteText(x, y, paramString, strlen(paramString));
1789 surface.WriteText(x, y, ",", 1);
1790 x += ((id == editor.paramsID) ? commaWB : commaW);
1798 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1799 surface.TextFont(font);
1804 surface.WriteText(x, y, ")", 1);
1806 else if(instanceName && type.kind != functionType)
1808 surface.WriteText(x, y, instanceName, strlen(instanceName));
1812 bool OnResizing(int * w, int * h)
1814 CodeEditor editor = (CodeEditor) master;
1815 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1817 Type methodType = null;
1821 int functionW = 0, nameW = 0;
1823 int spaceW, spaceH, commaW, commaWB, parW;
1825 int maxW = 0, lineW = 0;
1830 Font font = editor.normalFont.font;
1831 Font boldFont = editor.boldFont.font;
1832 Display display = this.display;
1834 if(type.kind == TypeKind::methodType)
1837 ProcessMethodType(type.method);
1838 type = type.method.dataType;
1841 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1842 display.FontExtent(font, ", ", 2, &commaW, null);
1843 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1844 display.FontExtent(font, ")", 1, &parW, null);
1847 if(editor.functionType && type)
1849 PrintType(type.returnType, string, true, true);
1850 display.FontExtent(font, string, strlen(string), &functionW, null);
1852 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1853 totalW = nameW + spaceW + functionW + 2 * parW;
1857 PrintType(type, string, false, true); // /*true);
1858 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1859 if(instanceName && type.kind != functionType)
1860 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1861 totalW = functionW + nameW + spaceW;
1864 if(editor.functionType)
1870 if(methodType.methodClass)
1871 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1872 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1873 width += ((id == editor.paramsID) ? commaWB : commaW);
1878 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1891 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1893 for(param = type.params.first; param; param = param.next)
1895 char paramString[1024];
1899 PrintType(param, paramString, true, true);
1900 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1902 width += ((id == editor.paramsID) ? commaWB : commaW);
1907 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1924 *w = realW + totalW + 4;
1930 Menu fileMenu { menu, $"File", f };
1931 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1932 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1934 Menu debugMenu { menu, $"Debug", d };
1935 MenuItem debugRunToCursor { debugMenu, $"Run To Cursor", c, ctrlF10, id = RTCMenuBits { false, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1936 MenuItem debugSkipRunToCursor { debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true }, id = RTCMenuBits { true, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1937 MenuItem debugRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level", l, altF10, id = RTCMenuBits { false, true, false }, NotifySelect = RTCMenu_NotifySelect; };
1938 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; };
1940 MenuItem debugBpRunToCursor { debugMenu, $"BP Run To Cursor"/*, c, ctrlF10*/, id = RTCMenuBits { false, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1941 MenuItem debugBpSkipRunToCursor { debugMenu, $"BP Run To Cursor Skipping Breakpoints"/*, u, Key { f10, ctrl = true, shift = true }*/, id = RTCMenuBits { true, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1942 MenuItem debugBpRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level"/*, l, altF10*/, id = RTCMenuBits { false, true, true }, NotifySelect = RTCMenu_NotifySelect; };
1943 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; };
1945 bool RTCMenu_NotifySelect(MenuItem selection, Modifiers mods)
1947 ProjectView projectView = ide.projectView;
1948 if(!projectView.buildInProgress)
1950 RTCMenuBits bits = (RTCMenuBits)selection.id;
1951 int line = editBox.lineNumber + 1;
1954 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1955 ProjectConfig config = projectView.project.config;
1956 int bitDepth = ide.workspace.bitDepth;
1957 bool useValgrind = ide.workspace.useValgrind;
1958 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, bits.ignoreBreakpoints, bits.atSameLevel, bits.oldImplementation);
1964 MenuDivider { debugMenu };
1965 MenuItem debugToggleBreakpoint
1967 debugMenu, $"Toggle Breakpoint", t, f9;
1968 bool NotifySelect(MenuItem selection, Modifiers mods)
1970 ProjectView projectView = ide.projectView;
1971 if(projectView && fileName)
1973 int line = editBox.lineNumber + 1;
1974 ide.debugger.ToggleBreakpoint(fileName, line);
1984 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1988 designer.parent = parent;
1991 toolBox = ((IDEWorkSpace)master).toolBox;
1993 // Debugger bug here: value of toolBox appears as 0
1995 sheet = ((IDEWorkSpace)master).sheet;
2000 bool OnClose(bool parentClosing)
2004 if(ide.workspace && fileName)
2005 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2006 if(inUseDebug && !debugClosing)
2008 debugClosing = true;
2010 if(CloseConfirmation(false))
2013 if(modifiedDocument)
2014 OnFileModified({ modified = true }, null);
2016 debugClosing = false;
2019 if(designer && !designer.closing)
2021 if(designer.visible)
2028 //Window formEditor = designer;
2029 //formEditor.Destroy(0);
2032 ide.AdjustFileMenus();
2037 void OnDestroy(void)
2039 ObjectInfo oClass, next;
2040 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2042 FreeType(this.functionType);
2043 FreeType(this.instanceType);
2048 designer.codeEditor = null;
2049 designer.Destroy(0);
2053 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2055 ObjectInfo object, next;
2057 for(object = oClass.instances.first; object; object = next)
2062 Designer::DestroyObject(object.instance);
2063 delete object.instance;
2065 sheet.DeleteObject(object);
2067 oClass.instances.Delete(object);
2071 Designer::DestroyObject(oClass.instance);
2072 delete oClass.instance;
2074 sheet.DeleteObject(oClass);
2076 classes.Delete(oClass);
2079 if(windowClass && windowClass.data)
2080 UnapplySkin(windowClass);
2084 if(sheet.codeEditor == this)
2086 sheet.codeEditor = null;
2087 toolBox.codeEditor = null;
2093 ProjectView projectView = ide.projectView;
2096 ProjectNode node = projectView.GetNodeFromWindow(this, null, false, false);
2097 if(node && node.modified)
2099 node.modified = false;
2100 projectView.Update(null);
2106 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2108 // 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
2110 if(directActivation)
2111 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2113 if(active && directActivation)
2117 openedFileInfo.Activate();
2121 Location * loc = null;
2122 UpdateFormCode(); // To ensure update when modifying properties...
2124 // Got to the right spot in code so we don't lose our form selection...
2127 if(selected.instCode)
2128 loc = &selected.instCode.loc;
2129 else if(selected.classDefinition)
2130 loc = &selected.classDefinition.loc;
2132 line = editBox.lineNumber + 1;
2133 charPos = editBox.charPos + 1;
2138 if(selected && !loc->Inside(line, charPos))
2140 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2141 line = editBox.lineNumber + 1;
2142 charPos = editBox.charPos + 1;
2144 else if(selected && selected.classDefinition)
2147 for(object = selected.instances.first; object; object = object.next)
2151 if(object.instCode.loc.Inside(line, charPos))
2157 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2158 line = editBox.lineNumber + 1;
2159 charPos = editBox.charPos + 1;
2164 ProcessCaretMove(editBox, line, charPos);
2169 if(membersListShown)
2171 membersList.Destroy(0);
2172 membersListShown = false;
2176 paramsList.Destroy(0);
2177 paramsShown = false;
2178 FreeType(functionType);
2179 FreeType(instanceType);
2181 functionType = null;
2182 instanceType = null;
2189 bool OnSaveFile(char * fileName)
2196 f = FileOpen(fileName, write);
2199 if(!ide.projectView)
2200 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2204 this.fileName = fileName; // Put this here because the form designer will check for it...
2205 designer.fileName = fileName;
2206 designer.modifiedDocument = false;
2208 editBox.Save(f, false);
2209 modifiedDocument = false;
2217 bool OnFileModified(FileChange fileChange, char * param)
2219 bool reload = false;
2220 if(visible == false && inUseDebug == true)
2221 ide.debugger.WatchesReleaseCodeEditor();
2226 sprintf(message, $"The document %s was modified by another application.\n"
2227 "Would you like to reload it and lose your changes?", fileName);
2228 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2229 contents = message }.Modal() == yes)
2235 File f = FileOpen(fileName, read);
2238 int lineNumber, charPos, len;
2242 updatingCode = true;
2243 lineNumber = editBox.lineNumber;
2244 charPos = editBox.charPos;
2245 scroll = editBox.scroll;
2248 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2249 len = strlen(editBox.line.text);
2250 editBox.GoToLineNum(lineNumber);
2251 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2252 editBox.scroll = scroll;
2253 updatingCode = false;
2254 loadingFile = false;
2256 codeModified = true;
2260 designer.modifiedDocument = false;
2262 modifiedDocument = false;
2270 void OnRedraw(Surface surface)
2273 surface.SetBackground(marginColor);
2274 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2275 if(ideSettings.showLineNumbers)
2277 int currentLineNumber;
2279 char lineFormat[16];
2283 surface.textOpacity = false;
2284 surface.font = font.font;
2285 surface.TextExtent(" ", 1, null, &spaceH);
2286 currentLineNumber = editBox.scroll.y / spaceH + 1;
2287 sprintf(lineFormat, " %%%du", maxLineNumberLength);
2289 surface.SetForeground(lineNumbersColor);
2290 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2292 // Highlight current line
2293 if(editBox.lineNumber == currentLineNumber - 1)
2295 surface.SetBackground(selectedMarginColor);
2296 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2297 surface.SetBackground(marginColor);
2299 sprintf(lineText, lineFormat, currentLineNumber);
2300 if(currentLineNumber <= editBox.numLines)
2301 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
2302 currentLineNumber++;
2306 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2308 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2309 int lineCursor, lineTopFrame, breakpointLines[128];
2310 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2311 Debugger debugger = ide.debugger;
2312 BitmapResource bmpRes;
2314 boxH = clientSize.h;
2315 scrollY = editBox.scroll.y;
2316 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2318 bpOnCursor = bpOnTopFrame = false;
2319 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2322 for(i = 0; i < count; i++)
2324 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2326 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2327 if(breakpointLines[i] == lineCursor)
2329 if(breakpointLines[i] == lineTopFrame)
2330 bpOnTopFrame = true;
2333 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2335 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2338 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2339 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2340 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2342 if(editBox.anchor.left.distance)
2344 if(editBox.horzScroll && editBox.horzScroll.visible)
2346 surface.SetBackground(control);
2347 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2352 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2357 lineY = (line - 1) * lineH;
2358 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2360 Bitmap bitmap = resource.bitmap;
2362 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2369 char ext[MAX_EXTENSION];
2370 char * fileName = property::fileName;
2372 if(SearchString(fileName, 0, "Makefile", false, true))
2373 editBox.useTab = true;
2374 designer.fileName = fileName;
2378 GetExtension(fileName, ext);
2380 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2381 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2382 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2383 editBox.syntaxHighlighting = true;
2385 editBox.syntaxHighlighting = false;
2387 if(parsing && !strcmpi(ext, "ec"))
2389 codeModified = true;
2393 maxLineNumberLength = 0;
2398 bool UpdateMarginSize()
2400 if(ideSettings.showLineNumbers)
2402 int numLen = Max(4, nofdigits(editBox.numLines));
2404 maxLineNumberLength = numLen;
2405 display.FontExtent(font.font, "0", 1, &digitWidth, null);
2406 editBox.anchor = Anchor
2408 left = editBox.syntaxHighlighting * 20 + ideSettings.showLineNumbers * (maxLineNumberLength+2) * digitWidth,
2409 right = 0, top = 0, bottom = 0
2414 maxLineNumberLength = 0;
2415 editBox.anchor = Anchor
2417 left = editBox.syntaxHighlighting * 20,
2418 right = 0, top = 0, bottom = 0
2430 bool LoadFile(char * filePath)
2432 File f = FileOpen(filePath, read);
2435 // Added this here...
2436 fileName = filePath;
2438 updatingCode = true;
2440 updatingCode = false;
2441 loadingFile = false;
2450 void AdjustDebugMenus()
2452 bool unavailable = ide.areDebugMenusUnavailable;
2453 bool isNotNotRunning = unavailable || ide.isDebuggerRunning;
2454 bool isNotStopped = unavailable || !ide.isDebuggerStopped;
2455 bool noBreakpointToggle = ide.isBreakpointTogglingUnavailable;
2457 debugRunToCursor.disabled = isNotNotRunning;
2458 debugSkipRunToCursor.disabled = isNotNotRunning;
2459 debugRunToCursorAtSameLevel.disabled = isNotStopped;
2460 debugSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2462 debugBpRunToCursor.disabled = isNotNotRunning;
2463 debugBpSkipRunToCursor.disabled = isNotNotRunning;
2464 debugBpRunToCursorAtSameLevel.disabled = isNotStopped;
2465 debugBpSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2467 debugToggleBreakpoint.disabled = noBreakpointToggle;
2473 ProjectView projectView = ide.projectView;
2476 designer.fileName = fileName;
2482 sprintf(title, $"Untitled %d", documentID);
2483 // designer.fileName = CopyString(title);
2484 designer.fileName = title;
2489 for(c = 0; c < CodeObjectType::enumSize; c++)
2490 icons[c] = BitmapResource { iconNames[c], window = this };
2492 codeModified = true;
2504 selected.modified = true;
2505 selected.oClass.modified = true;
2507 designer.modifiedDocument = true;
2508 modifiedDocument = true;
2509 formModified = true;
2512 /****************************************************************************
2514 ****************************************************************************/
2522 this.defines.Free(FreeModuleDefine);
2523 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2525 FreeExcludedSymbols(this.excludedSymbols);
2526 FreeContext(this.globalContext);
2528 FreeGlobalData(&this.globalData);
2529 FindCtx_Terminate();
2530 FindParams_Terminate();
2532 if(GetGlobalContext() == globalContext)
2534 SetGlobalData(null);
2535 SetGlobalContext(null);
2536 SetExcludedSymbols(null);
2537 SetTopContext(null);
2538 SetCurrentContext(null);
2541 SetPrivateModule(null);
2544 if(this.privateModule)
2546 FreeTypeData(this.privateModule);
2547 delete this.privateModule;
2548 this.privateModule = null;
2554 static bool reentrant = false;
2559 char * selectedClassName = null, * selectedName = null;
2560 int selectedPos = 0;
2561 Designer backDesigner;
2562 char oldWorkDir[MAX_LOCATION];
2563 char mainModuleName[MAX_FILENAME] = "";
2565 ImportedModule module;
2566 char extension[MAX_EXTENSION];
2567 PathBackup pathBackup { };
2569 Time parseCodeStart = GetTime();
2570 Time startTime, startFindClass;
2572 findClassTotalTime = 0;
2573 checkTypeTotalTime = 0;
2574 externalImportTotalTime = 0;
2575 findClassIgnoreNSTotalTime = 0;
2576 findSymbolTotalTime = 0;
2577 //ResetClassFindTime();
2581 // 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)
2582 if(reentrant) return;
2589 selectedClassName = CopyString(oClass.name);
2590 if(selected != oClass)
2592 ObjectInfo object = this.selected;
2593 selectedName = CopyString(object.name);
2597 for(check = this.oClass.instances.first; check; check = check.next)
2609 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2611 FindCtx_Terminate();
2612 FindParams_Terminate();
2614 SetGlobalData(&globalData);
2615 SetGlobalContext(globalContext);
2616 SetExcludedSymbols(&excludedSymbols);
2617 SetTopContext(globalContext);
2618 SetCurrentContext(globalContext);
2619 SetDefines(&defines);
2620 SetImports(&imports);
2621 SetCurrentNameSpace(null);
2624 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2625 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2626 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2627 "/I T:\\ecere\\include /E %s", argv[1]);
2631 ChangeWorkingDir("e:\\ec");
2632 sprintf(command, "gcc -x c -E -");
2633 fileInput = DualPipeOpen({ output = true, input = true }, command);
2634 SetFileInput(fileInput);
2639 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2641 fileInput.Write(buffer, 1, count);
2646 fileInput.CloseOutput();
2650 // TOCHECK: COULDN'T WE CALL FreeParser here?
2652 FreeType(this.functionType);
2653 FreeType(this.instanceType);
2654 this.functionType = null;
2655 this.instanceType = null;
2658 sheet.SelectObject(null);
2664 // We don't want the designer to be notified of selection when deleting rows...
2665 backDesigner = designer;
2670 ObjectInfo _class, next;
2672 for(_class = classes.first; _class; _class = next)
2678 for(;object = _class.instances.first;)
2682 Designer::DestroyObject(object.instance);
2683 delete object.instance;
2685 sheet.DeleteObject(object);
2687 _class.instances.Delete(object);
2691 Designer::DestroyObject(_class.instance);
2692 delete _class.instance;
2694 sheet.DeleteObject(_class);
2696 classes.Delete(_class);
2702 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2703 if(windowClass && windowClass.data)
2704 UnapplySkin(windowClass);
2707 designer = backDesigner;
2710 fileInput = editFile = EditBoxStream { editBox = editBox };
2711 SetFileInput(fileInput);
2719 defines.Free(FreeModuleDefine);
2720 imports.Free(FreeModuleImport);
2722 FreeContext(this.globalContext);
2723 FreeExcludedSymbols(this.excludedSymbols);
2726 FreeGlobalData(&this.globalData);
2728 if(this.privateModule)
2730 FreeTypeData(this.privateModule);
2731 delete this.privateModule;
2735 startTime = GetTime();
2736 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2738 printf("classes.count: %d\n", globalContext.classes.count);
2743 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2744 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2747 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2749 SetPrivateModule(privateModule);
2752 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2753 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2754 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2755 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2756 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2759 fileName = this.fileName;
2761 if(ide.workspace && ide.workspace.projects && fileName)
2763 for(p : ide.workspace.projects)
2765 char path[MAX_LOCATION];
2767 MakePathRelative(fileName, p.topNode.path, path);
2768 MakeSlashPath(path);
2770 pn = p.topNode.FindWithPath(path, false);
2779 project = ide.project;
2781 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2783 ChangeWorkingDir(project.topNode.path);
2785 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2787 GetLastDirectory(fileName, mainModuleName);
2788 GetExtension(mainModuleName, extension);
2790 SetBuildingEcereCom(false);
2791 SetBuildingEcereComModule(false);
2793 // TODO: Get symbolsDir from project settings instead...
2796 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2797 ProjectConfig config = project.config;
2798 int bitDepth = ide.workspace.bitDepth;
2799 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2800 SetSymbolsDir(objDir.dir);
2801 ide.SetPath(true, compiler, config, bitDepth);
2805 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2806 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2810 switch(GetRuntimePlatform())
2812 case win32: SetSymbolsDir("obj/debug.win32"); break;
2813 case tux: SetSymbolsDir("obj/debug.linux"); break;
2814 case apple: SetSymbolsDir("obj/debug.apple"); break;
2816 SetIncludeDirs(null);
2817 SetSysIncludeDirs(null);
2821 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2823 // TODO FIX for configless project
2824 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2826 for(item : ide.project.config.options.preprocessorDefinitions)
2828 if(!strcmp(item, "BUILDING_ECERE_COM"))
2830 SetBuildingEcereCom(true);
2837 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2838 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2839 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2840 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2841 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2842 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2843 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2844 strcmpi(mainModuleName, "Mutex.ec")))
2846 SetBuildingEcereComModule(true);
2849 // Predeclare all classes
2851 char symFile[MAX_FILENAME];
2852 char symLocation[MAX_LOCATION];
2853 ImportedModule module, next;
2855 GetLastDirectory(fileName, symFile);
2856 ChangeExtension(symFile, "sym", symFile);
2858 strcpy(symLocation, GetSymbolsDir());
2859 PathCat(symLocation, symFile);
2861 // if(!GetEcereImported() && !GetBuildingEcereCom())
2862 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2865 startTime = GetTime();
2867 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2869 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2874 startTime = GetTime();
2876 // LoadSymbols(symLocation, normalImport, true);
2877 LoadSymbols(symLocation, preDeclImport, false);
2879 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2882 for(module = defines.first; module; module = next)
2885 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2888 defines.Delete(module);
2893 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2895 SetDefaultDeclMode(privateAccess);
2896 SetDeclMode(privateAccess);
2900 SetDefaultDeclMode(defaultAccess);
2901 SetDeclMode(defaultAccess);
2904 StripExtension(mainModuleName);
2905 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2906 defines.AddName(module);
2909 // SetYydebug(true);
2914 startTime = GetTime();
2915 startFindClass = checkTypeTotalTime;
2919 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2921 CheckDataRedefinitions();
2924 SetIncludeDirs(null);
2925 SetSysIncludeDirs(null);
2936 startTime = GetTime();
2938 PrePreProcessClassDefinitions();
2939 ComputeModuleClasses(privateModule);
2940 PreProcessClassDefinitions();
2941 ProcessClassDefinitions();
2943 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2944 startTime = GetTime();
2949 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2950 startTime = GetTime();
2952 ProcessInstantiations();
2954 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2957 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2959 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2960 if(!windowClass || windowClass.internalDecl)
2963 startTime = GetTime();
2965 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2966 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2967 eModule_Load(this.privateModule, "ecere", privateAccess);
2969 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2972 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2974 if(windowClass && windowClass.data)
2975 ApplySkin(windowClass, app.currentSkin.name, null);
2979 startTime = GetTime();
2981 for(external = ast->first; external; external = external.next)
2983 if(external.type == classExternal)
2985 ClassDefinition _class = external._class;
2986 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2988 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2991 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2993 Instance instance = eInstance_New(regClass);
2994 ObjectInfo classObject
2996 name = CopyString(_class._class.name);
2997 instance = instance;
2998 classDefinition = _class;
2999 oClass = classObject;
3002 classes.Add(classObject);
3006 // Moved this at bottom so that the file dialog doesn't show up in eCom
3007 designer.CreateObject(instance, classObject, true, null);
3008 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
3010 if(_class.definitions)
3014 for(def = _class.definitions->first; def; def = def.next)
3018 case defaultPropertiesClassDef:
3021 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3023 Identifier id = propDef.identifiers->first;
3026 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3029 Class propertyClass = prop.dataTypeClass;
3031 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3032 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3034 FreeType(propDef.initializer.exp.destType);
3035 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3036 ProcessExpressionType(propDef.initializer.exp);
3038 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
3040 Expression computed = CopyExpression(propDef.initializer.exp);
3041 ComputeExpression(computed);
3043 if(computed.isConstant && computed.type == instanceExp && !id.next)
3047 if(computed.instance._class && computed.instance._class.symbol &&
3048 computed.instance._class.symbol.registered &&
3049 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3051 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3053 // This was saved in the control and shouldn't be freed by FreeExpression...
3054 // (Not doing this anymore, incrementing refCount in pass15 instead)
3055 /*if(propertyClass.type == normalClass)
3056 computed.instance.data = null;*/
3060 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3061 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3063 String temp = new char[strlen(computed.string)+1];
3064 ReadString(temp, computed.string);
3065 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3069 propDef.variable = true;
3071 FreeExpression(computed);
3075 Expression computed = CopyExpression(propDef.initializer.exp);
3076 ComputeExpression(computed);
3077 if(computed.isConstant)
3079 //if(computed.type == memberExp) computed = computed.member.exp;
3081 if(computed.type == constantExp)
3083 Operand value = GetOperand(computed);
3084 DataValue valueData;
3085 valueData.i64 = value.i64;
3086 SetProperty(prop, instance, valueData);
3088 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3090 String temp = new char[strlen(computed.string)+1];
3091 ReadString(temp, computed.string);
3092 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3097 propDef.variable = true;
3099 FreeExpression(computed);
3103 propDef.variable = true;
3107 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3108 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3109 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3112 // Maintain a list in FunctionDefinition of who is attached to it
3113 for(def = _class.definitions->first; def; def = def.next)
3115 if(def.type == functionClassDef)
3117 ClassFunction function = def.function;
3118 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3120 function.attached.Add(OldLink { data = method });
3130 case declarationClassDef:
3132 Declaration decl = def.decl;
3135 case instDeclaration:
3137 Instantiation inst = decl.inst;
3138 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3139 if(instClass && eClass_GetDesigner(instClass))
3141 Instance control = eInstance_New(instClass);
3146 oClass = classObject;
3150 classObject.instances.Add(object);
3152 // TOCHECK: Why is this needed now?
3153 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3154 def.object = object;
3156 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3158 designer.CreateObject(control, object, false, classObject.instance);
3159 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3169 // Second pass, process instantiation members
3171 for(def = _class.definitions->first; def; def = def.next)
3175 case declarationClassDef:
3177 Declaration decl = def.decl;
3180 case instDeclaration:
3182 Instantiation inst = decl.inst;
3183 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3184 if(instClass && eClass_GetDesigner(instClass))
3187 object = object ? object.next : classObject.instances.first;
3188 control = object.instance;
3192 MembersInit members;
3193 for(members = inst.members->first; members; members = members.next)
3195 switch(members.type)
3197 case dataMembersInit:
3199 if(members.dataMembers)
3202 DataMember curMember = null;
3203 Class curClass = null;
3204 DataMember subMemberStack[256];
3205 int subMemberStackPos = 0;
3207 for(member = members.dataMembers->first; member; member = member.next)
3210 Identifier ident = member.identifiers ? member.identifiers->first : null;
3213 DataMember _subMemberStack[256];
3214 int _subMemberStackPos = 0;
3215 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3219 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3221 if(thisMember && thisMember.memberAccess == publicAccess)
3223 curMember = thisMember;
3224 curClass = curMember._class;
3225 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3226 subMemberStackPos = _subMemberStackPos;
3232 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3233 if(curMember) found = true;
3235 if(found && curMember.isProperty)
3237 Property prop = (Property) curMember;
3238 Class propertyClass = prop.dataTypeClass;
3240 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3242 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3244 FreeType(member.initializer.exp.destType);
3245 member.initializer.exp.destType = MkClassType(propertyClass.name);
3248 ProcessExpressionType(member.initializer.exp);
3250 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3252 Expression computed;
3254 /*char debugExpString[4096];
3255 debugExpString[0] = '\0';
3256 PrintExpression(member.initializer.exp, debugExpString);*/
3258 computed = CopyExpression(member.initializer.exp);
3261 ComputeExpression(computed);
3263 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3265 if(computed.instance.data)
3267 if(computed.instance._class && computed.instance._class.symbol &&
3268 computed.instance._class.symbol.registered &&
3269 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3271 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3273 // This was saved in the control and shouldn't be freed by FreeExpression...
3274 // (Not doing this anymore, incrementing refCount in pass15 instead)
3275 /*if(propertyClass.type == normalClass)
3276 computed.instance.data = null;*/
3280 else if(computed.type == identifierExp)
3282 member.variable = true;
3284 if(eClass_GetDesigner(propertyClass))
3287 char * name = computed.identifier.string;
3288 if(!strcmp(name, "this"))
3291 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3292 member.variable = false;
3297 for(check = classObject.instances.first; check; check = check.next)
3298 if(check.name && !strcmp(name, check.name))
3301 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3302 member.variable = false;
3308 else if(computed.type == memberExp)
3310 member.variable = true;
3311 if(computed.member.exp.type == identifierExp)
3313 char * name = computed.member.exp.identifier.string;
3314 if(!strcmp(name, "this"))
3316 char * name = computed.member.member.string;
3319 for(check = classObject.instances.first; check; check = check.next)
3320 if(check.name && !strcmp(name, check.name))
3323 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3324 member.variable = false;
3332 for(check = classObject.instances.first; check; check = check.next)
3334 if(check.name && !strcmp(name, check.name))
3336 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3339 DataValue value { };
3340 GetProperty(getProperty, check.instance, &value);
3341 SetProperty(prop, control, value);
3342 member.variable = false;
3350 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3351 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3353 String temp = new char[strlen(computed.string)+1];
3354 ReadString(temp, computed.string);
3355 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3359 member.variable = true;
3361 FreeExpression(computed);
3366 Expression computed = CopyExpression(member.initializer.exp);
3369 ComputeExpression(computed);
3370 if(computed.isConstant)
3372 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3374 if(!strcmp(propertyClass.dataTypeString, "float"))
3375 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3376 else if(!strcmp(propertyClass.dataTypeString, "double"))
3377 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3379 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3381 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3383 String temp = new char[strlen(computed.string)+1];
3384 ReadString(temp, computed.string);
3385 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3390 member.variable = true;
3392 FreeExpression(computed);
3398 member.variable = true;
3400 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3401 member.initializer.exp.type == memberExp) // identifierExp
3403 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3404 if(method && method.type == virtualMethod)
3407 // Maintain a list in FunctionDefinition of who is attached to it
3408 for(def = _class.definitions->first; def; def = def.next)
3410 if(def.type == functionClassDef)
3412 ClassFunction function = def.function;
3413 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3414 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3416 function.attached.Add(OldLink { data = method });
3417 // Reference this particular instance?
3432 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3443 //designer.CreateObject(instance, classObject, true, null);
3444 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3446 designer.PostCreateObject(instance, classObject, true, null);
3448 //instance.state = Hidden;
3449 //instance.Create();
3450 //instance.SetState(Normal, true, 0);
3459 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3463 // Restore Selection
3464 if(selectedClassName)
3467 for(oClass = classes.first; oClass; oClass = oClass.next)
3469 if(!strcmp(oClass.name, selectedClassName))
3471 this.oClass = oClass;
3475 delete selectedClassName;
3484 for(check = this.oClass.instances.first; check; check = check.next)
3486 if(check.name && !strcmp(check.name, selectedName))
3488 this.selected = check;
3494 if(this.oClass.instances.first)
3495 this.selected = this.oClass.instances.first;
3497 this.selected = this.oClass;
3500 else if(selectedPos == -1 || !this.oClass.instances.count)
3501 this.selected = this.oClass;
3507 if(selectedPos > this.oClass.instances.count)
3509 for(check = this.oClass.instances.first; check; check = check.next)
3511 if(selectedPos == pos++)
3513 this.selected = check;
3521 this.oClass = classes.first;
3522 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3524 delete selectedName;
3525 SetSymbolsDir(null);
3527 if(sheet.codeEditor == this)
3528 sheet.SelectObject(selected);
3531 codeModified = false;
3533 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3536 InvokeParameters(false, false, false);
3539 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3545 ChangeWorkingDir(oldWorkDir);
3547 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3548 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3549 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3550 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3551 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3553 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3555 if(inUseDebug && ide.projectView)
3556 ide.debugger.EvaluateWatches();
3561 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3564 Window control = (Window)object.instance;
3565 ObjectInfo classObject = object.oClass;
3567 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3569 if(!strcmp(_class.name, "DesignerBase")) return;
3571 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3573 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3574 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3576 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3577 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3579 Class dataType = prop.dataTypeClass;
3581 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3585 if(dataType.type == structClass)
3587 void * dataForm = new0 byte[dataType.structSize];
3588 void * dataTest = new0 byte[dataType.structSize];
3590 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3591 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3593 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3595 char tempString[1024] = "";
3597 bool needClass = true;
3601 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3603 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3605 eClass_FindNextMember(_class, curClass, curMember, null, null);
3606 if(*curMember != (DataMember)prop)
3607 f.Printf("%s = ", prop.name);
3609 *curMember = (DataMember)prop;
3610 *curClass = curMember->_class;
3613 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3615 f.Printf("%s", string);
3622 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3624 void * dataForm, * dataTest;
3626 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3627 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3629 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3631 char tempString[1024] = "";
3636 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3638 eClass_FindNextMember(_class, curClass, curMember, null, null);
3639 if(*curMember != (DataMember)prop)
3640 f.Printf("%s = ", prop.name);
3641 *curMember = (DataMember)prop;
3642 *curClass = curMember->_class;
3644 if(eClass_GetDesigner(dataType))
3646 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3647 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3648 f.Printf("this", prop.name);
3651 //ObjectInfo classObject;
3652 //for(classObject = classes.first; classObject; classObject = classObject.next)
3656 for(object = classObject.instances.first; object; object = object.next)
3658 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3660 f.Printf("%s", object.name);
3667 bool needClass = true;
3668 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3669 f.Printf("%s", string);
3676 bool needClass = true;
3677 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3679 if(!strcmp(dataType.dataTypeString, "char *"))
3682 OutputString(f, string);
3686 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3688 f.Printf("%s", string);
3691 *lastIsMethod = false;
3696 DataValue dataForm, dataTest;
3698 GetProperty(prop, control, &dataForm);
3699 GetProperty(prop, test, &dataTest);
3701 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3704 char tempString[1024] = "";
3705 SetProperty(prop, test, dataForm);
3707 if(dataType.type != bitClass)
3709 bool needClass = true;
3711 if(dataType.type == enumClass)
3714 Class enumClass = eSystem_FindClass(privateModule, "enum");
3715 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3717 for(value = e.values.first; value; value = value.next)
3719 if((int)value.data == dataForm.i)
3721 string = value.name;
3727 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3729 if(string && string[0])
3734 eClass_FindNextMember(_class, curClass, curMember, null, null);
3735 if(*curMember != (DataMember)prop)
3736 f.Printf("%s = ", prop.name);
3737 *curMember = (DataMember)prop;
3738 *curClass = curMember->_class;
3740 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3741 f.Printf("%sf", string);
3743 f.Printf("%s", string);
3747 else if(dataType.type == bitClass)
3749 bool needClass = true;
3751 if(*prev) f.Printf(", ");
3753 eClass_FindNextMember(_class, curClass, curMember, null, null);
3754 if(*curMember != (DataMember)prop)
3755 f.Printf("%s = ", prop.name);
3756 *curMember = (DataMember)prop;
3757 *curClass = curMember->_class;
3759 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3761 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3763 f.Printf("%s", string);
3765 *lastIsMethod = false;
3775 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3777 Instantiation inst = object.instCode;
3778 Window control = (Window)object.instance;
3780 bool methodPresent = false;
3782 bool lastIsMethod = true;
3783 ObjectInfo classObject = object.oClass;
3789 // Instance removed, delete it
3790 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3792 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3793 position = inst.loc.end.pos + 1;
3797 bool multiLine = false;
3800 // Check if it's an unnamed instance
3803 f.Seek(inst.nameLoc.start.pos - position, current);
3804 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3805 position = inst.nameLoc.end.pos;
3807 f.Printf(object.name);
3812 if(isspace(ch) && ch != '\n')
3814 f.Seek(-1, current);
3822 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3824 f.Seek(pos - position, current);
3829 f.Seek(-1, current);
3838 f.Puts(object.name);
3843 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3844 methodPresent = true;
3852 if(ch == OpenBracket)
3858 // TODO: Simplify this?
3867 f.Seek(-1, current);
3879 if(ch == '\n') { toDelete = count; count = 0; }
3880 else if(isspace(ch)) count++;
3883 f.Seek(-1, current);
3887 toDelete += count - 6;
3897 f.Seek(-toDelete-count, current);
3898 f.DeleteBytes(toDelete);
3899 f.Seek(count, current);
3904 for(c = 0; c<toAdd; c++)
3910 methodPresent = multiLine;
3913 f.Printf(methodPresent ? "\n " : " ");
3919 // Instance not there, create a brand new one
3920 DeleteJunkBefore(f, position, &position);
3921 f.Printf(*firstObject ? "\n\n" : "\n");
3922 *firstObject = false;
3924 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3925 methodPresent = true;
3930 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3932 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3937 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3939 f.Printf(" %s %c ", control._class.name, OpenBracket);
3945 Instance test = eInstance_New(control._class);
3946 DataMember curMember = null;
3947 Class curClass = null;
3950 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3954 // Attach Method here
3955 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3957 if(prev) f.Printf(", ");
3958 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3963 if(inst && !object.deleted)
3965 MembersInit members;
3966 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3968 DeleteJunkBefore(f, position, &position);
3970 // Instance already there, clear out the properties
3971 for(members = inst.members->first; members; members = members.next)
3973 if(members.type == dataMembersInit)
3977 if(members.dataMembers)
3979 bool keptMember = false;
3980 MemberInit lastKept = null;
3982 for(member = members.dataMembers->first; member; member = member.next)
3984 Identifier ident = member.identifiers ? member.identifiers->first : null;
3985 bool deleted = false;
3987 // For now delete if it's not a method
3988 if(!member.variable) // && ident)
3990 if(!ident || !ident.next)
3992 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3995 f.Seek(member.loc.start.pos - position, current);
3996 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3997 position = member.loc.end.pos;
4002 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
4003 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
4004 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4006 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
4007 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
4009 f.Seek(member.loc.start.pos - position, current);
4010 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4011 position = member.loc.end.pos;
4023 //f.Seek(member.loc.start.pos - position, current);
4024 //position = member.loc.start.pos;
4025 DeleteJunkBefore(f, member.loc.start.pos, &position);
4026 if(prev) f.Printf(", ");
4027 else if(keptMember) f.Printf(" ");
4032 if(!keptMember || !members.next)
4037 if(keptMember && lastKept != members.dataMembers->last)
4042 f.Seek(-1, current);
4048 f.Seek(-1, current);
4051 else if(!isspace(ch))
4053 f.Seek(-2, current);
4058 f.DeleteBytes(count);
4061 f.Seek(members.loc.end.pos - position, current);
4066 f.Seek(-1, current);
4068 position = members.loc.end.pos + 1;
4072 f.Seek(-1, current);
4073 position = members.loc.end.pos;
4079 lastIsMethod = false;
4084 DeleteJunkBefore(f, position, &position);
4087 if(lastKept != members.dataMembers->last)
4092 f.Seek(-1, current);
4098 f.Seek(-1, current);
4101 else if(!isspace(ch))
4103 f.Seek(-2, current);
4108 f.DeleteBytes(count);
4112 f.Seek(members.loc.end.pos - position, current);
4113 position = members.loc.end.pos;
4117 lastIsMethod = true;
4120 lastIsMethod = false;
4126 f.Seek(members.loc.end.pos - position, current);
4127 position = members.loc.end.pos;
4129 lastIsMethod = true;
4132 else if(members.type == methodMembersInit)
4134 if(this.methodAction == actionDeleteMethod && members.function == function);
4136 methodPresent = true;
4138 // Delete instance method here
4139 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4140 members.function == function)
4142 if(this.moveAttached && !*text)
4143 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4145 DeleteJunkBefore(f, members.loc.start.pos, &position);
4146 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4147 position = members.loc.end.pos + 1;
4152 DeleteJunkBefore(f, position, &position);
4156 DeleteJunkBefore(f, members.loc.start.pos, &position);
4157 lastIsMethod = true;
4161 f.Seek(members.loc.end.pos - position, current);
4162 position = members.loc.end.pos;
4164 DeleteJunkBefore(f, position, &position);
4173 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4175 Method method = this.method;
4176 DeleteJunkBefore(f, position, &position);
4182 if(!method.dataType)
4183 method.dataType = ProcessTypeString(method.dataTypeString, false);
4186 Type dataType = method.dataType;
4187 Type returnType = dataType.returnType;
4190 if(this.moveAttached)
4192 // Move function here:
4193 int newLen = strlen(method.name);
4198 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4200 // First change name of function
4201 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4202 *textSize += newLen - movedFuncIdLen;
4203 memcpy(*text + movedFuncIdPos, method.name, newLen);
4205 // Second, tab right
4208 for(c = 0; (*text)[c]; )
4211 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4214 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4215 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4219 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4229 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4231 // ADDING METHOD HERE
4233 OutputType(f, returnType, false);
4236 if(dataType.thisClass)
4238 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4240 if(dataType.thisClass.shortName)
4241 f.Printf(dataType.thisClass.shortName);
4243 f.Printf(dataType.thisClass.string);
4247 f.Printf(method.name);
4249 for(param = dataType.params.first; param; param = param.next)
4251 OutputType(f, param, true);
4256 f.Printf(" %c\n\n", OpenBracket);
4258 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4260 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4261 f.Printf(" return true;\n");
4262 else if(returnType.kind != voidType)
4263 f.Printf(" return 0;\n");
4268 if(returnType.kind != voidType)
4269 f.Printf("return ");
4270 f.Printf("%s::%s(", control._class.name, method.name);
4271 for(param = dataType.params.first; param; param = param.next)
4273 if(param.prev) f.Printf(", ");
4274 if(param.kind != voidType)
4275 f.Printf(param.name);
4279 f.Printf(" %c\n", CloseBracket);
4285 if(!object.instCode)
4288 f.Printf(" %c;\n", CloseBracket);
4290 f.Printf("%c;\n", CloseBracket);
4292 else if(!object.deleted)
4294 // Turn this into a multiline instance when adding a method
4295 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4297 f.Printf(methodPresent ? "\n " : " ");
4299 f.Seek(inst.loc.end.pos + 1 - position, current);
4300 position = inst.loc.end.pos + 1;
4305 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4308 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4310 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4312 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4314 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4315 if(prop && prop.isProperty && !prop.conversion)
4317 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4318 (!prop.IsSet || prop.IsSet(classObject.instance)))
4320 Class dataType = prop.dataTypeClass;
4321 char tempString[1024] = "";
4323 bool specify = false;
4326 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4327 if(member && member._class == regClass)
4331 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4333 if(dataType && dataType.type == structClass)
4335 void * dataForm = new0 byte[dataType.structSize];
4336 void * dataTest = new0 byte[dataType.structSize];
4338 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4339 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4341 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4343 bool needClass = true;
4345 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4346 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4348 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4350 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4355 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4357 void * dataForm, * dataTest;
4359 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4360 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4362 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4364 char tempString[1024] = "";
4366 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4368 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4370 // Shouldn't go here ...
4371 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4375 bool needClass = true;
4377 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4379 if(!strcmp(dataType.dataTypeString, "char *"))
4381 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4382 OutputString(f, string);
4386 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4388 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4394 DataValue dataForm, dataTest;
4396 GetProperty(prop, classObject.instance, &dataForm);
4397 GetProperty(prop, test, &dataTest);
4399 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4401 SetProperty(prop, test, dataForm);
4402 if(dataType.type == bitClass)
4404 bool needClass = true;
4405 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4407 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4409 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4413 bool needClass = true;
4414 if(dataType.type == enumClass)
4417 Class enumClass = eSystem_FindClass(privateModule, "enum");
4418 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4420 for(value = e.values.first; value; value = value.next)
4422 if((int)value.data == dataForm.i)
4424 string = value.name;
4430 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4431 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4432 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4434 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4443 void UpdateFormCode()
4446 if(!parsing) return;
4453 else if(formModified)
4455 EditBoxStream f { editBox = editBox };
4459 Identifier movedFuncId;
4460 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4461 ObjectInfo classObject;
4467 movedFuncId = GetDeclId(function.declarator);
4468 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4469 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4472 for(classObject = classes.first; classObject; classObject = classObject.next)
4475 ClassDefinition classDef = classObject.classDefinition;
4476 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4479 bool firstObject = true;
4480 ObjectInfo object = classObject.instances.first;
4481 bool lastIsDecl = false;
4483 if(!classObject.modified) continue;
4485 test = eInstance_New(regClass);
4488 // Put it in the same desktop window...
4489 designer.PrepareTestObject(test);
4491 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4492 //f.Printf("%c\n\n", OpenBracket);
4494 // Change the _class name
4495 f.Seek(classDef.nameLoc.start.pos - position, current);
4496 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4497 f.Printf(classObject.name);
4498 position = classDef.nameLoc.end.pos;
4501 // Go to block start, delete all until no white space, put \n
4505 f.Seek(classDef.blockStart.end.pos - position, current);
4506 position = classDef.blockStart.end.pos;
4508 for(; f.Getc(&ch); count++)
4512 f.Seek(-1, current);
4522 f.Seek(-count, current);
4524 f.DeleteBytes(count-back);
4526 position += count-back;
4529 // Output properties
4530 OutputClassProperties(classObject.instance._class, classObject, f, test);
4532 for(def = classDef.definitions->first; def; def = def.next)
4536 case defaultPropertiesClassDef:
4538 bool keptMember = false;
4540 MemberInit lastKept = null;
4543 DeleteJunkBefore(f, def.loc.start.pos, &position);
4546 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4548 Identifier ident = propDef.identifiers->first;
4549 bool deleted = false;
4551 // For now delete if it's a prop
4552 if(!propDef.variable && ident)
4556 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4559 f.Seek(propDef.loc.start.pos - position, current);
4560 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4561 position = propDef.loc.end.pos;
4566 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4567 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4569 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4570 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4572 f.Seek(propDef.loc.start.pos - position, current);
4573 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4574 position = propDef.loc.end.pos;
4592 f.Seek(def.loc.end.pos - position - 1, current);
4597 f.Seek(-1, current);
4600 position = def.loc.end.pos;
4604 if(lastKept != def.defProperties->last)
4609 f.Seek(-1, current);
4615 f.Seek(-1, current);
4618 else if(!isspace(ch))
4620 f.Seek(-2, current);
4625 f.DeleteBytes(count);
4629 f.Seek(def.loc.end.pos - position, current);
4630 position = def.loc.end.pos;
4635 case declarationClassDef:
4637 Declaration decl = def.decl;
4639 if(decl.type == instDeclaration)
4641 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4643 while(def.object && object != def.object)
4645 if(object /*&& ((ObjectInfo)def.object).modified*/)
4646 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4647 object = object.next;
4650 DeleteJunkBefore(f, def.loc.start.pos, &position);
4651 f.Printf(firstObject ? "\n\n " : "\n ");
4652 firstObject = false;
4654 if(def.object && ((ObjectInfo)def.object).modified)
4655 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4657 object = object ? object.next : null;
4661 DeleteJunkBefore(f, def.loc.start.pos, &position);
4662 f.Printf(firstObject ? "\n\n " : "\n ");
4663 firstObject = false;
4669 DeleteJunkBefore(f, def.loc.start.pos, &position);
4670 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4675 case functionClassDef:
4677 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4678 if(!def.function.body) continue;
4682 DeleteJunkBefore(f, def.loc.start.pos, &position);
4685 // Delete _class methods
4686 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4687 def.function == function)
4692 if(moveAttached && !text)
4694 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4697 f.Seek(def.loc.end.pos - position, current);
4698 for(; f.Getc(&ch); count++)
4702 f.Seek(-1, current);
4706 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4708 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4709 position = def.loc.end.pos + count;
4712 // In case of detaching methods in the _class, simply rename the method
4713 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4715 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4716 f.DeleteBytes(movedFuncIdLen);
4718 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4721 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4722 function == def.function)
4724 // In case of attaching methods in the _class, simply rename the method
4725 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4726 position = function.loc.start.pos + movedFuncIdPos;
4727 f.DeleteBytes(movedFuncIdLen);
4728 if(method.dataType.thisClass)
4729 f.Printf("%s::", method.dataType.thisClass.string);
4730 f.Puts(method.name);
4731 position += movedFuncIdLen;
4736 DeleteJunkBefore(f, def.loc.start.pos, &position);
4737 if(def.type == memberAccessClassDef)
4740 firstObject = false;
4750 f.Seek(def.loc.end.pos - position, current);
4751 position = def.loc.end.pos;
4754 // Output attached methods
4755 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4757 DeleteJunkBefore(f, position, &position);
4758 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4761 // ********** INSTANCES ***************
4762 for(; object; object = object.next)
4764 if(!object.instCode)
4766 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4770 DeleteJunkBefore(f, position, &position);
4772 // ****************** METHODS ***********************
4773 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4775 // If detaching an instance method
4776 if(selected != classObject)
4778 int newLen = strlen(methodName);
4781 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4782 // Tab selection left
4785 for(c = 0; text[c]; )
4788 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4789 memmove(text+start, text+start+i, textSize+1-start-i);
4792 for(; text[c] && text[c] != '\n'; c++);
4798 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4799 textSize += newLen - movedFuncIdLen;
4800 memcpy(text + movedFuncIdPos, methodName, newLen);
4807 if(methodAction == actionAddMethod && selected == classObject)
4809 Method method = this.method;
4811 if(!method.dataType)
4812 method.dataType = ProcessTypeString(method.dataTypeString, false);
4814 // ADDING METHOD HERE
4816 Type dataType = method.dataType;
4817 Type returnType = dataType.returnType;
4819 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4823 OutputType(f, returnType, false);
4826 if(dataType.thisClass && !dataType.classObjectType)
4828 if(dataType.thisClass.shortName)
4829 f.Printf(dataType.thisClass.shortName);
4831 f.Printf(dataType.thisClass.string);
4834 f.Printf(method.name);
4836 for(param = dataType.params.first; param; param = param.next)
4838 OutputType(f, param, true);
4843 f.Printf(" %c\n\n", OpenBracket);
4845 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4847 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4848 f.Printf(" return true;\n");
4849 else if(returnType && returnType.kind != voidType)
4850 f.Printf(" return 0;\n");
4855 if(returnType.kind != voidType)
4856 f.Printf("return ");
4858 char * name = ((Specifier)classDef.baseSpecs->first).name;
4859 Symbol _class = FindClass(name);
4860 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4862 for(param = dataType.params.first; param; param = param.next)
4864 if(param.prev) f.Printf(", ");
4865 if(param.kind != voidType)
4866 f.Printf(param.name);
4871 f.Printf(" %c", CloseBracket);
4875 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4887 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4888 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4892 codeModified = false;
4893 formModified = false;
4895 moveAttached = false;
4900 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4903 ClassFunction function = null;
4906 ObjectInfo object = this.selected;
4908 if(object && object == this.oClass)
4910 ClassDefinition classDef = object.oClass.classDefinition;
4912 if(classDef && classDef.definitions)
4914 for(def = classDef.definitions->first; def; def = def.next)
4916 if(def.type == functionClassDef && def.function.declarator)
4918 if(!strcmp(def.function.declarator.symbol.string, methodName))
4920 function = def.function;
4925 else if(def.type == defaultPropertiesClassDef)
4929 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4931 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4932 if(ident && !ident.next)
4934 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4938 propLoc = propDef.loc;
4941 ClassDefinition classDef = object.oClass.classDefinition;
4943 if(classDef.definitions)
4945 for(def = classDef.definitions->first; def; def = def.next)
4947 if(def.type == functionClassDef)
4949 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4951 function = def.function;
4970 Instantiation inst = object.instCode;
4972 // Check here to see if the method already exists, no need to call ModifyCode in that case
4973 if(inst && inst.members)
4975 MembersInit members;
4976 for(members = inst.members->first; members; members = members.next)
4978 switch(members.type)
4980 case dataMembersInit:
4982 if(members.dataMembers)
4985 for(member = members.dataMembers->first; member; member = member.next)
4987 Identifier ident = member.identifiers ? member.identifiers->first : null;
4988 if(ident && !ident.next)
4990 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4994 propLoc = member.loc;
4997 ClassDefinition classDef = object.oClass.classDefinition;
4999 if(classDef.definitions)
5001 for(def = classDef.definitions->first; def; def = def.next)
5003 if(def.type == functionClassDef)
5005 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
5007 function = def.function;
5016 // TODO: Fix memory leak
5017 function = ClassFunction
5019 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5031 case methodMembersInit:
5033 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5035 function = members.function;
5047 if(functionPtr) *functionPtr = function;
5051 void GoToMethod(char * methodName /*Method method*/)
5055 ObjectInfo object = selected;
5056 EditBoxStream f { editBox = editBox };
5057 ClassFunction function = null;
5058 bool atChar = false;
5062 Location propLoc = { {0,0,-1} };
5065 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5066 if(function && function.body)
5069 f.Seek(function.body.loc.start.pos+1, current);
5079 f.Seek(-1, current);
5084 else if(!isspace(ch))
5086 f.Seek(-1, current);
5092 else if(propLoc.start.pos > -1)
5094 f.Seek(propLoc.start.pos, current);
5097 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5099 if(function || propLoc.start.pos > -1)
5101 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5102 editBox.CenterOnCursor();
5103 SetState(normal, false, 0);
5106 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5108 FreeClassFunction(function);
5114 void FindCompatibleMethods(Method method, OldList compatible)
5116 ClassDefinition classDef = this.oClass.classDefinition;
5117 if(classDef && classDef.definitions)
5120 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5123 Symbol classSym { };
5124 Symbol selectedClass;
5125 if(this.selected == this.oClass)
5126 selectedClass = classSym;
5128 selectedClass = FindClass(this.selected.instance._class.name);
5130 regClass.name = classDef._class.name;
5131 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5132 for(def = classDef.definitions->first; def; def = def.next)
5134 if(def.type == functionClassDef && def.function.declarator)
5136 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5138 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5141 Type type = def.function.declarator.symbol.type;
5142 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5144 compatible.Add(OldLink { data = def.function });
5150 if(this.oClass && this.oClass.instance)
5152 classSym.registered = regClass;
5153 //classSym.registered = this.oClass.oClass;
5155 for(_class = regClass.base; _class; _class = _class.base)
5158 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5160 // TODO: Understand why these functions popup in attach list
5161 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5163 if(!testMethod.dataType)
5164 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5166 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5167 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5168 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5170 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5171 // ClassFunction function { };
5172 FunctionDefinition function { };
5174 function.declarator = Declarator { };
5175 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5176 excludedSymbols.Add(function.declarator.symbol);
5178 compatible.Add(OldLink { data = function });
5189 void AddMethod(Method method)
5193 char methodName[1024];
5194 strcpy(methodName, method.name);
5195 if(!FindMethod(methodName, null, null))
5197 methodAction = actionAddMethod;
5198 this.method = method;
5202 GoToMethod(methodName);
5206 void DeleteMethod(ClassFunction function)
5210 methodAction = actionDeleteMethod;
5211 this.function = function;
5219 void AttachMethod(Method method, ClassFunction function)
5223 // If it's an instance we'll ask if we want to move it inside...
5224 if(!function.attached.count && function.body)
5226 // Find the function in the _class to check if it's a virtual function
5227 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5228 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5229 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5231 for(def = this.classDefinition.first; def; def = def.next)
5233 if(def.type == functionClassDef)
5235 if(def.function == function)
5240 if(!method || method.type != virtualMethod)
5243 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5244 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5246 moveAttached = true;
5251 methodAction = actionAttachMethod;
5252 this.method = method;
5253 this.function = function;
5260 void ReAttachMethod(Method method, ClassFunction function)
5264 // If it's an instance we'll ask if we want to move it inside...
5265 if(!function.attached.count && function.body)
5267 // Find the function in the _class to check if it's a virtual function
5268 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5269 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5270 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5272 for(def = this.classDefinition.first; def; def = def.next)
5274 if(def.type == functionClassDef)
5276 if(def.function == function)
5281 if(!method || method.type != virtualMethod)
5284 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5285 if(MessageBox { type = yesNo, master = parent, text = title,
5286 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5288 moveAttached = true;
5293 methodAction = actionReattachMethod;
5294 this.method = method;
5295 this.function = function;
5302 void DetachMethod(Method method, ClassFunction function, int type)
5310 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5311 master = sheet, text = $"Name detached method", background = formColor
5315 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5316 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5320 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5321 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5325 dialog, anchor = { left = 5, right = 5, top = 5 }
5327 sprintf(methodName, "%s_%s", selected.name, method.name);
5328 nameBox.contents = methodName;
5330 result = dialog.Modal() == ok;
5331 strcpy(methodName, nameBox.contents);
5336 // If the method is not attached, move it outside
5339 // Add this class to the methodName
5340 char name[1024] = "";
5342 if(this.selected != this.oClass && !method.dataType.thisClass)
5344 strcat(name, this.selected.instance._class.name);
5346 strcat(name, this.methodName);
5347 strcpy(this.methodName, name);
5349 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5351 strcat(name, method.dataType.thisClass.string);
5353 strcat(name, this.methodName);
5354 strcpy(this.methodName, name);
5357 this.moveAttached = true;
5360 this.methodAction = actionDetachMethod;
5361 this.method = method;
5362 this.function = function;
5369 void AddObject(Instance instance, ObjectInfo * object)
5373 //*object = _class.instances.Add(sizeof(ObjectInfo));
5374 *object = ObjectInfo { };
5375 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5376 (*object).oClass = oClass;
5377 (*object).instance = instance;
5382 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5384 // if(strcmp(name, this.oClass.instance.name))
5387 for(check = oClass.instances.first; check; check = check.next)
5388 if(!check.deleted && check.name && !strcmp(name, check.name))
5392 (*object).name = CopyString(name);
5397 toolBox.controlClass = null;
5401 //sheet.AddObject(*object, (*object).name, TypeData, true);
5406 void EnsureUpToDate()
5408 if(sheet && codeModified && parsing)
5412 void SelectObject(ObjectInfo object)
5415 oClass = object ? object.oClass : null;
5417 designer.SelectObject(object, object ? object.instance : null);
5420 void SelectObjectFromDesigner(ObjectInfo object)
5423 sheet.SelectObject(object);
5426 void EnumerateObjects(Sheet sheet)
5430 for(oClass = classes.first; oClass; oClass = oClass.next)
5436 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5437 for(object = oClass.instances.first; object; object = object.next)
5438 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5441 sheet.SelectObject(selected);
5446 designer.AddObject();
5449 void DeleteObject(ObjectInfo object)
5451 delete object.instance;
5452 object.deleted = true;
5453 object.modified = true;
5454 object.oClass.modified = true;
5456 if(selected == object)
5458 bool looped = false;
5459 ObjectInfo select = object;
5463 select = select.prev;
5467 select = object.oClass.instances.last;
5474 sheet.SelectObject(select ? select : oClass);
5477 if(!object.instCode && object.oClass != object)
5480 oClass.instances.Delete(object);
5483 if(sheet.codeEditor == this)
5484 sheet.DeleteObject(object);
5487 void RenameObject(ObjectInfo object, char * name)
5491 // Validate the name:
5492 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5493 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5496 for(c = 0; name[c]; c++)
5497 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5505 object.name = (name && name[0]) ? CopyString(name) : null;
5507 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5511 void DesignerModifiedObject()
5513 sheet.ListProperties(false);
5517 void ListSubMembers(Type member)
5521 for(subMember = member.members.first; subMember; subMember = subMember.next)
5525 DataRow row = membersList.AddString(subMember.name);
5526 row.icon = icons[typeData];
5530 ListSubMembers(subMember);
5535 void ListSubDataMembers(DataMember member, bool isPrivate)
5537 DataMember subMember;
5538 for(subMember = member.members.first; subMember; subMember = subMember.next)
5540 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5544 DataRow row = membersList.AddString(subMember.name);
5545 BitmapResource bitmap = null;
5546 if(!subMember.dataType)
5547 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5549 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5551 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5554 bitmap = { bitmapName };
5555 membersList.AddResource(bitmap);
5558 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5562 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5568 void ListClassMembers(Class whatClass, bool methodsOnly)
5571 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5572 bool isPrivate = false;
5574 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5576 Method method, methodIt;
5578 DataMember memberIt;
5580 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5582 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5583 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5585 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5587 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5589 DataRow row = membersList.FindString(method.name);
5592 row = membersList.AddString(method.name);
5594 if(!method.dataType)
5595 method.dataType = ProcessTypeString(method.dataTypeString, false);
5597 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5605 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5609 if(memberIt.isProperty)
5611 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5613 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5617 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5619 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5622 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5628 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5630 if(member.isProperty)
5632 Property prop = (Property) member;
5633 if(!membersList.FindString(prop.name))
5635 DataRow row = membersList.AddString(prop.name);
5636 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5639 else if(member.name && !membersList.FindString(member.name))
5641 DataRow row = membersList.AddString(member.name);
5643 BitmapResource bitmap = null;
5644 if(!member.dataType)
5645 member.dataType = ProcessTypeString(member.dataTypeString, false);
5647 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5649 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5652 bitmap = { bitmapName };
5653 membersList.AddResource(bitmap);
5656 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5659 ListSubDataMembers(member, member.memberAccess == privateAccess);
5663 if(_class.inheritanceAccess == privateAccess)
5666 if(_class.module != privateModule) break;
5671 void ListClassMembersMatch(Class whatClass, Type methodType)
5674 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5675 bool isPrivate = false;
5677 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5683 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5685 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5687 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5689 if(!method.dataType)
5690 method.dataType = ProcessTypeString(method.dataTypeString, false);
5692 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5694 DataRow row = membersList.FindString(method.name);
5697 row = membersList.AddString(method.name);
5698 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5704 if(_class.inheritanceAccess == privateAccess)
5707 if(_class.module != privateModule) break;
5712 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5715 bool isPrivate = false;
5716 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5722 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5724 if(method.type == virtualMethod)
5726 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5728 DataRow row = membersList.FindString(method.name);
5731 row = membersList.AddString(method.name);
5733 if(!method.dataType)
5734 method.dataType = ProcessTypeString(method.dataTypeString, false);
5736 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5742 for(member = _class.membersAndProperties.first; member; member = member.next)
5744 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5746 if(member.isProperty)
5748 Property prop = (Property)member;
5750 DataRow row = membersList.AddString(prop.name);
5751 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5754 else if(member.name && (!curString || strcmp(curString, member.name)))
5756 DataRow row = membersList.AddString(member.name);
5758 BitmapResource bitmap = null;
5759 if(!member.dataType)
5760 member.dataType = ProcessTypeString(member.dataTypeString, false);
5762 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5764 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5767 bitmap = { bitmapName };
5768 membersList.AddResource(bitmap);
5771 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5774 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5777 if(_class.inheritanceAccess == privateAccess)
5780 if(_class.module != privateModule) break;
5785 void ListMembers(Type type)
5787 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5791 if(type.kind == classType)
5794 ListClassMembers(type._class.registered, false);
5799 for(member = type.members.first; member; member = member.next)
5803 DataRow row = membersList.AddString(member.name);
5804 row.icon = icons[typeData];
5806 else if(member.kind == structType || member.kind == unionType)
5807 ListSubMembers(member);
5813 void ListModule(Module mainModule, int recurse, bool listClasses)
5816 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5817 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5818 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5819 for(module = mainModule.application.allModules.first; module; module = module.next)
5821 if(ModuleVisibility(mainModule, module))
5822 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5826 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5833 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5835 Class _class = link.data;
5836 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5838 DataRow row = membersList.AddString(_class.name);
5839 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5844 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5846 DefinedExpression definedExp = link.data;
5847 DataRow row = membersList.AddString(link /*definedExp*/.name);
5848 row.icon = icons[typeData];
5851 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5853 GlobalFunction function = link.data;
5854 DataRow row = membersList.AddString(link /*function*/.name);
5855 row.icon = icons[typeMethod];
5859 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5861 if(recurse != 2 && listClasses)
5863 if(!membersList.FindString(ns->name))
5865 DataRow row = membersList.AddString(ns->name);
5866 row.icon = icons[typeNameSpace];
5871 ListNameSpace(ns, 2, listClasses);
5875 void ListEnumValues(Class _class)
5877 List<Class> classes { };
5878 for(; _class && _class.type == enumClass; _class = _class.base)
5879 classes.Insert(null, _class);
5880 for(_class : classes)
5882 EnumClassData enumeration = (EnumClassData)_class.data;
5884 for(item = enumeration.values.first; item; item = item.next)
5886 DataRow row = membersList.AddString(item.name);
5887 row.icon = icons[typeEnumValue];
5893 bool ListEnumsModule(Module mainModule, Type dest)
5895 bool result = false;
5897 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5898 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5899 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5900 for(module = mainModule.application.allModules.first; module; module = module.next)
5902 if(ModuleVisibility(mainModule, module))
5903 result |= ListEnums(module.publicNameSpace, dest);
5908 void ListNameSpaceByString(Module mainModule, char * string)
5910 NameSpace * nameSpace;
5912 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5913 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5914 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5915 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5916 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5917 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5918 for(module = mainModule.application.allModules.first; module; module = module.next)
5920 if(ModuleVisibility(mainModule, module))
5922 nameSpace = FindNameSpace(module.publicNameSpace, string);
5923 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5928 bool ListEnums(NameSpace nameSpace, Type dest)
5931 bool result = false;
5933 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5935 Class _class = link.data;
5936 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *"))) && !dest.classObjectType)) &&
5937 dest.kind != pointerType && dest.kind != ellipsisType)
5939 OldList conversions { };
5941 type.kind = classType;
5942 type._class = FindClass(_class.name);
5943 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5945 ListEnumValues(_class);
5948 conversions.Free(null);
5952 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5954 result |= ListEnums(nameSpace, dest);
5959 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5963 for(c = 0; (ch = name[c]); c++)
5965 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5967 NameSpace * newSpace;
5968 char * spaceName = new char[c - start + 1];
5969 memcpy(spaceName, name + start, c - start);
5970 spaceName[c-start] = '\0';
5971 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5975 nameSpace = newSpace;
5984 return (NameSpace *)nameSpace;
5987 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5989 bool listedEnums = false;
5990 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5991 bool listClasses = true;
5993 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5995 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5996 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5997 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5999 if(exp.type == identifierExp)
6000 id = realIdentifier;
6002 if(id && id._class && !id._class.name)
6004 listClasses = false;
6007 else if(id && id._class && id._class.name)
6011 Class _class = id.classSym.registered;
6012 if(_class && _class.type == enumClass)
6014 ListEnumValues(_class);
6017 ListClassMembers(id.classSym.registered, true);
6022 else if(id && colons)
6024 ListNameSpaceByString(this.privateModule, id.string);
6029 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6031 listedEnums = ListEnumsModule(this.privateModule, destType);
6034 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6036 ListEnumValues(destType._class.registered);
6039 ListClassPropertiesAndVirtual(insideClass, null);
6043 else if(destType && destType.kind == enumType)
6047 for(value = destType.members.first; value; value = value.next)
6049 DataRow row = membersList.AddString(value.name);
6050 row.icon = icons[typeEnumValue];
6054 ListClassPropertiesAndVirtual(insideClass, null);
6058 else if(insideClass && !enumOnly)
6060 ListClassPropertiesAndVirtual(insideClass, string);
6063 if(listedEnums && string && string[0])
6065 DataRow row = membersList.FindSubString(string);
6067 listedEnums = false;
6070 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6072 ListClassMembersMatch(GetThisClass(), exp.destType);
6074 else if(!insideClass && !enumOnly && !listedEnums)
6077 Symbol symbol = null;
6081 ListClassMembers(GetThisClass(), false);
6084 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6086 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6088 // Don't list enum values?
6089 //if(symbol.type.kind != TypeEnum)
6090 DataRow row = membersList.FindString(symbol.string);
6093 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6095 row = membersList.AddString(symbol.string);
6096 if(symbol.type && symbol.type.kind == functionType)
6097 row.icon = icons[typeMethod];
6098 else if(symbol.type && symbol.type.kind == enumType)
6100 row.icon = icons[typeEnumValue];
6104 BitmapResource bitmap = null;
6105 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6107 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6110 bitmap = { bitmapName };
6111 membersList.AddResource(bitmap);
6114 row.icon = bitmap ? bitmap : icons[typeData];
6121 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6123 DataRow row = membersList.FindString(symbol.string);
6126 row = membersList.AddString(symbol.string);
6127 if(symbol.type.kind == functionType)
6128 row.icon = icons[typeMethod];
6129 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6131 row.icon = icons[typeClass];
6135 row.icon = icons[typeDataType];
6142 ListModule(this.privateModule, 1, listClasses);
6143 // TODO: Implement this with name space
6147 for(data = globalData.first; data; data = data.next)
6149 DataRow row = membersList.FindString(data.name);
6151 data.dataType = ProcessTypeString(data.dataTypeString, false);
6154 row = membersList.AddString(data.name);
6156 if(data.dataType && data.dataType.kind == TypeEnum)
6158 row.icon = icons[typeEnumValue];
6162 BitmapResource bitmap = null;
6163 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6165 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6168 bitmap = { bitmapName };
6169 membersList.AddResource(bitmap);
6172 row.icon = bitmap ? bitmap : icons[typeData];
6180 DataRow row = membersList.AddString("Min");
6181 row.icon = icons[typeMethod];
6183 row = membersList.AddString("Max");
6184 row.icon = icons[typeMethod];
6186 row = membersList.AddString("Abs");
6187 row.icon = icons[typeMethod];
6189 row = membersList.AddString("Sgn");
6190 row.icon = icons[typeMethod];
6196 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6198 EditBoxStream f { editBox = editBox };
6203 updatingCode = true;
6205 if(!method.dataType)
6206 method.dataType = ProcessTypeString(method.dataTypeString, false);
6208 DeleteJunkBefore(f, function.loc.start.pos, &position);
6209 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6211 // ADDING METHOD HERE
6213 Type dataType = method.dataType;
6214 Type returnType = dataType.returnType;
6216 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6222 if(extraIndent) f.Printf(" ");
6224 OutputType(f, returnType, false);
6228 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6230 if(dataType.thisClass.shortName)
6231 f.Printf(dataType.thisClass.shortName);
6233 f.Printf(dataType.thisClass.string);
6236 f.Printf(method.name);
6238 for(param = dataType.params.first; param; param = param.next)
6240 // Decided not to write void...
6241 if(param.kind != voidType)
6243 OutputType(f, param, true);
6249 if(extraIndent) f.Printf(" ");
6250 f.Printf(" %c\n", OpenBracket);
6252 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6258 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6259 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6261 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6263 if(extraIndent) f.Printf(" ");
6264 f.Printf(" return true;\n");
6266 else if(returnType && returnType.kind != voidType)
6268 if(extraIndent) f.Printf(" ");
6269 f.Printf(" return 0;\n");
6274 if(extraIndent) f.Printf(" ");
6276 if(returnType.kind != voidType)
6277 f.Printf("return ");
6278 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6279 for(param = dataType.params.first; param; param = param.next)
6281 if(param.prev) f.Printf(", ");
6282 if(param.kind != voidType)
6283 f.Printf(param.name);
6289 if(extraIndent) f.Printf(" ");
6290 f.Printf(" %c", CloseBracket);
6295 if(extraIndent) { x1 += 3; x2 += 3; }
6296 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6298 this.updatingCode = false;
6302 // Return false if we overrided a function and don't want to run params listing
6303 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6305 bool didOverride = false;
6306 EditLine line = editBox.line;
6307 char * text = line.text;
6308 int lineNum, charPos;
6309 Expression exp = null;
6312 //Identifier id = null;
6313 Expression memberExp = null;
6314 Identifier realIdentifier = null;
6316 if(!parsing) return true;
6317 if(!privateModule) return !didOverride;
6319 insideFunction = null;
6321 charPos = editBox.charPos + 1;
6322 if(!membersListShown)
6327 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6329 EditBoxStream f { editBox = editBox };
6331 updatingCode = true;
6332 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6336 if(!f.Seek(-1, current))
6339 if(!isspace(ch)) break;
6340 f.Seek(-1, current);
6342 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6344 lineNum = editBox.lineNumber + 1;
6345 charPos = editBox.charPos + 1;
6347 updatingCode = false;
6350 if(!membersListShown)
6352 memberExp = FindExpTree(ast, lineNum, charPos);
6353 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6358 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6360 EditBoxStream f { editBox = editBox };
6363 updatingCode = true;
6365 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6368 if(ch == '}' || ch == ',' || ch == ')')
6370 f.Seek(-1, current);
6378 if(!f.Seek(-1, current))
6381 if(!isspace(ch)) break;
6382 f.Seek(-1, current);
6386 f.Seek(-1, current);
6388 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6390 lineNum = editBox.lineNumber + 1;
6391 charPos = editBox.charPos + 1;
6393 updatingCode = false;
6396 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6401 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6402 lineNum = editBox.lineNumber + 1;
6403 charPos = editBox.charPos/* + 1*/;
6407 char tempString[1024];
6408 char * string = null;
6409 CodePosition idStart, idEnd;
6411 if(membersListShown)
6413 char * buffer = membersLine.text;
6415 bool firstChar = true;
6417 string = tempString;
6419 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6421 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6422 if(!isSpace) firstChar = false;
6424 string[len++] = buffer[c];
6428 else //if(realIdentifier)//if(id)
6431 char * buffer = id.string;
6433 bool firstChar = true;
6435 string = tempString;
6436 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6438 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6439 if(!isSpace) firstChar = false;
6441 string[len++] = buffer[c];
6447 EditLine editLine = editBox.line;
6448 bool firstChar = true;
6451 string = tempString;
6452 for(y = lineNum-1; y >= 0; y--)
6454 char * buffer = editLine.text;
6455 int lineCount = editLine.count;
6456 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6458 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6463 idEnd.charPos = x + 2;
6468 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6471 idEnd.charPos = x + 2;
6478 if(!isalnum(buffer[x]) && buffer[x] != '_')
6484 memmove(string+1, string, len++);
6485 string[0] = buffer[x];
6489 //if(done || firstChar)
6490 if(done || !firstChar)
6492 editLine = editLine.prev;
6495 if(!strcmp(string, "case"))
6501 else if(!strcmp(string, "return"))
6507 else if(!strcmp(string, "delete"))
6513 else if(!strcmp(string, "new"))
6519 else if(!strcmp(string, "renew"))
6527 idStart.charPos = x + 1;
6528 idStart.line = y + 1;
6531 if(!membersListShown)
6533 membersList.Clear();
6534 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6536 Type type = memberExp.member.exp.expType;
6537 if(pointer == 2 && type)
6539 if(type.kind == pointerType || type.kind == arrayType)
6548 ListSymbols(exp, enumOnly, string, realIdentifier);
6550 membersList.Sort(null, 1);
6555 // Virtual function override
6556 Identifier id = GetDeclId(insideFunction.declarator);
6557 char * string = id ? id.string : null;
6559 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6562 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6563 insideFunction = null;
6566 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6571 if(!didOverride) //insideFunction)
6573 rowCount = membersList.rowCount;
6576 DataRow row = string ? membersList.FindSubString(string) : null;
6577 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6579 char * newString = row.string;
6580 if(!membersListShown)
6582 membersLoc.start.line = idStart.line-1;
6583 membersLoc.start.charPos = idStart.charPos-1;
6584 //membersLoc.end = membersLoc.start;
6585 membersLoc.end.charPos = idEnd.charPos-1;
6586 membersLoc.end.line = idEnd.line-1;
6587 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6588 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6593 membersList.Destroy(0);
6594 membersListShown = false;
6597 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6599 line, membersLoc.start.line, membersLoc.start.charPos,
6600 line, membersLoc.end.line, membersLoc.end.charPos);
6601 editBox.PutS(newString);
6607 row = membersList.FindSubStringi(string);
6609 membersList.currentRow = row;
6610 membersList.currentRow.selected = false;
6613 membersList.currentRow = row;
6615 if(!membersListShown)
6619 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6620 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6621 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6622 editBox.GetCaretPosition(caret);
6623 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6625 membersList.master = this;
6627 caret.y += editBox.GetCaretSize();
6629 membersList.Create();
6632 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6633 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6634 Window parent = membersList.parent;
6636 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6638 y -= editBox.GetCaretSize() + membersList.size.h;
6639 membersAbove = true;
6642 membersAbove = false;
6644 membersList.position = { x, y };
6648 membersLoc.start.line = lineNum - 1;
6650 if(string && string[0])
6652 membersLoc.start.charPos = idStart.charPos-1;
6653 membersLoc.end = membersLoc.start;
6654 //membersLoc.end.charPos = id.loc.end.charPos-1;
6655 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6659 membersLoc.start.charPos = charPos;
6660 membersLoc.end = membersLoc.start;
6661 membersLoc.end.charPos = charPos;
6663 membersListShown = true;
6665 // Hack to keep caret shown
6666 editBox.GetCaretPosition(caret);
6667 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6670 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6676 SetCurrentContext(globalContext);
6679 return !didOverride;
6682 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6684 EditLine line = editBox.line;
6685 char * text = line.text;
6686 int lineNum, charPos;
6687 Expression exp = null;
6691 if(!parsing) return;
6693 charPos = editBox.charPos + 1;
6696 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6698 EditBoxStream f { editBox = editBox };
6701 updatingCode = true;
6702 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6705 if(ch == '}' || ch == ',' || ch == ')')
6707 f.Seek(-1, current);
6715 if(!f.Seek(-1, current))
6718 if(!isspace(ch)) break;
6719 f.Seek(-1, current);
6723 f.Seek(-1, current);
6725 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6727 lineNum = editBox.lineNumber + 1;
6728 charPos = editBox.charPos + 1;
6730 updatingCode = false;
6733 charPos = Min(charPos, l1.count + 1);
6735 FindParamsTree(ast, lineNum, charPos);
6737 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6738 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6740 ::functionType = null;
6741 ::instanceType = null;
6744 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6745 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6749 Window parent = paramsList.parent;
6751 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6754 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6755 // ( Dummy exp: always ends up with same memory)
6757 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6758 editBox.GetCaretPosition(paramsPosition);
6759 this.paramsPosition.y += editBox.GetCaretSize();
6762 FreeType(this.functionType);
6763 FreeType(this.instanceType);
6765 this.functionType = ::functionType;
6766 this.instanceType = ::instanceType;
6768 if(this.functionType) this.functionType.refCount++;
6769 if(this.instanceType) this.instanceType.refCount++;
6771 this.paramsID = ::paramsID;
6772 functionExp = paramsInsideExp;
6774 paramsList.master = this;
6776 paramsList.Create();
6778 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6779 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6781 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6783 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6787 paramsAbove = false;
6788 if(x + paramsList.size.w > parent.clientSize.w)
6790 x = parent.clientSize.w - paramsList.size.w;
6794 paramsList.position = { x, y };
6796 // Hack to keep caret shown
6799 editBox.GetCaretPosition(caret);
6800 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6803 this.paramsShown = true;
6805 else if((!::functionType && !::instanceType) || reposition)
6807 paramsList.Destroy(0);
6808 paramsShown = false;
6810 FreeType(this.functionType);
6811 FreeType(this.instanceType);
6812 this.functionType = null;
6813 this.instanceType = null;
6817 SetCurrentContext(globalContext);
6825 designer.visible = true;
6826 designer.Activate();
6832 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6834 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };
6839 static int nofdigits(int v)
6841 if(v == MININT) return 10 + 1;
6842 if(v < 0) return nofdigits(-v) + 1;