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 ProjectNode node = projectView.GetNodeFromWindow(this, null, true, false);
805 node.modified = modifiedDocument;
806 projectView.Update(null);
814 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
815 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
816 tabKey = true, smartHome = true;
817 tabSelection = true, /*maxLineSize = 65536, */parent = this, hasHorzScroll = true, hasVertScroll = true;
818 selectionColor = selectionColor, selectionText = selectionText,
819 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
820 font = font, borderStyle = none;
821 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
823 bool OnMouseOver(int x, int y, Modifiers mods)
825 CodeEditor editor = (CodeEditor)master;
826 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
831 void NotifyCaretMove(EditBox editBox, int line, int charPos)
833 // Update Line Numbers
835 int oldLine = lastLine;
836 display.FontExtent(font.font, " ", 1, null, &spaceH);
838 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
842 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
847 if(ide.activeClient == this)
848 ProcessCaretMove(editBox, line, charPos);
850 openedFileInfo.CaretMove(line, charPos);
853 void NotifyOvrToggle(EditBox editBox, bool overwrite)
855 ide.ovr.color = overwrite ? black : Color { 128, 128, 128 };
858 void NotifyUpdate(EditBox editBox)
865 designer.modifiedDocument = true;
868 modifiedDocument = true;
871 bool NotifyUnsetModified(EditBox editBox)
873 modifiedDocument = false;
877 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
879 if(!loadingFile && after.y != before.y)
881 ProjectView projectView = ide.projectView;
882 if(projectView && fileName)
885 // HOW WE MIGHT WANT TO DO IT:
886 char * text = before.line.text;
887 for(c = before.x-1; c>= 0; c--)
888 if(!isspace(text[c]))
890 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
892 // HOW VISUAL STUDIO DOES IT:
894 char * text = after.line.text;
895 for(c = after.line.count-1; c>= 0; c--)
896 if(!isspace(text[c]))
898 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
901 Update({ 0, 0, editBox.position.x, clientSize.h });
909 for(oClass = classes.first; oClass; oClass = oClass.next)
912 for(object = oClass.instances.first; object; object = object.next)
916 object.instCode.loc.start.AdjustAdd(before, after);
917 object.instCode.loc.end.AdjustAdd(before, after);
922 oClass.classDefinition.loc.start.AdjustAdd(before, after);
923 oClass.classDefinition.loc.end.AdjustAdd(before, after);
929 expectingMove = true;
933 if(before.y != after.y)
937 char * buffer = membersLine.text;
939 bool firstChar = true;
940 bool addedChar = false;
946 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
948 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
950 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
951 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
960 membersLoc.start.charPos++;
965 string[len++] = buffer[c];
969 row = membersList.currentRow;
970 if(row && row.selected)
974 membersLoc.start.charPos--;
982 row = membersList.FindSubString(string);
984 membersList.currentRow = row;
987 row = membersList.FindSubStringi(string);
989 membersList.currentRow = row;
990 membersList.currentRow.selected = false;
993 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
997 row = membersList.currentRow;
1000 // Accept current string if hiding typing char
1001 if(hide && row && row.selected)
1003 char * string = row.string;
1004 int len = strlen(string);
1005 membersLoc.end.charPos -= after.x - before.x;
1006 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1007 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
1008 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1009 editBox.PutS(string);
1010 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
1012 after.x += membersLoc.start.charPos + len - before.x;
1013 before.x = membersLoc.start.charPos + len;
1018 membersList.Destroy(0);
1019 membersListShown = false;
1022 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
1024 EditLine line = editBox.line;
1025 char * text = line.text;
1026 char ch = text[after.x-1];
1027 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1031 // Can we call invoke auto complete here instead?
1041 // Force caret update already...
1042 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1043 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1045 editBox.GetCaretPosition(&caret);
1049 // Go back in the buffer until no space before
1051 codeModified = true;
1055 EditBoxStream f { editBox = editBox };
1059 if(text[after.x-1] == '>')
1065 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1069 if(!f.Seek(-1, current))
1072 if(!isspace(ch)) break;
1073 f.Seek(-1, current);
1075 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1077 line = editBox.lineNumber + 1;
1078 charPos = editBox.charPos + 1;
1082 exp = FindExpTree(ast, line, charPos);
1086 Type type = exp.expType;
1088 if(type && text[after.x-1] != '.')
1090 if(type.kind == TypePointer || type.kind == TypeArray)
1096 membersList.Clear();
1099 if(membersList.rowCount)
1101 membersList.Sort(null, 1);
1102 membersList.master = this;
1104 caret.y += editBox.GetCaretSize();
1107 membersList.Create();
1110 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1111 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1112 Window parent = membersList.parent;
1114 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1116 y -= editBox.GetCaretSize() + membersList.GetHeight();
1117 membersAbove = true;
1120 membersAbove = false;
1122 membersList.position = { x, y };
1126 membersLoc.start.line = line - 1;
1127 membersLoc.start.charPos = oldCharPos;
1128 membersLoc.end = membersLoc.start;
1129 membersListShown = true;
1134 SetCurrentContext(globalContext);
1136 codeModified = true;
1137 skipModified = true;
1138 if(text[after.x-1] == ':')
1139 InvokeAutoComplete(false, 0, false);
1140 else if(text[after.x-1] == '.')
1141 InvokeAutoComplete(false, 1, false);
1142 else if(text[after.x-1] == '>')
1143 InvokeAutoComplete(false, 2, false);
1144 skipModified = false;
1146 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1148 codeModified = true;
1149 skipModified = true;
1151 if(InvokeAutoComplete(true, 0, false))
1153 if(ch == '(' || ch == OpenBracket)
1154 InvokeParameters(true, true, false);
1156 InvokeParameters(this.functionType ? false : true, false, false);
1159 // InvokeAutoComplete(true, 0, false);
1160 skipModified = false;
1162 else if(ch == ')' || ch == '}' || ch == ';')
1164 codeModified = true;
1165 skipModified = true;
1167 InvokeParameters(false, true, false);
1168 skipModified = false;
1172 bool back = codeModified;
1173 codeModified = false;
1175 InvokeParameters(false, false, true);
1176 if(membersListShown)
1177 InvokeAutoComplete(false, 0, true);
1178 codeModified = back;
1183 bool back = codeModified;
1184 codeModified = false;
1187 InvokeParameters(false, false, true);
1188 /*if(membersListShown)
1189 InvokeAutoComplete(false, 0, true);*/
1191 codeModified = back;
1198 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1200 if(!loadingFile && after.y != before.y)
1202 ProjectView projectView = ide.projectView;
1203 if(projectView && fileName)
1204 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1205 Update({ 0, 0, editBox.position.x, clientSize.h });
1213 for(oClass = classes.first; oClass; oClass = oClass.next)
1217 for(object = oClass.instances.first; object; object = object.next)
1221 loc = &object.instCode.loc;
1223 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1224 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1226 object.instCode = null;
1230 loc->start.AdjustDelete(before, after);
1231 loc->end.AdjustDelete(before, after);
1235 if(oClass.classDefinition)
1237 loc = &oClass.classDefinition.loc;
1238 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1239 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1241 oClass.classDefinition = null;
1245 loc->start.AdjustDelete(before, after);
1246 loc->end.AdjustDelete(before, after);
1251 if(membersListShown)
1254 if(pasteOperation || before.y != after.y)
1258 char * buffer = membersLine.text;
1260 bool firstChar = true;
1264 if(before.x >= membersLoc.start.charPos)
1266 for(c = membersLoc.start.charPos; c<before.x && len < sizeof(string)-1; c++)
1268 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1269 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1274 if(!isSpace) firstChar = false;
1277 string[len++] = buffer[c];
1282 // If deleting spaces before...
1283 for(c = before.x; c<membersLoc.start.charPos; c++)
1285 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1293 membersLoc.start.charPos = before.x;
1296 if(membersLoc.end.charPos >= after.x)
1298 for(c = after.x; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1300 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1301 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1306 if(!isSpace) firstChar = false;
1309 string[len++] = buffer[c];
1317 membersLoc.end.charPos -= after.x - before.x;
1321 row = membersList.FindSubString(string);
1324 row = membersList.FindSubStringi(string);
1326 membersList.currentRow = row;
1327 membersList.currentRow.selected = false;
1330 membersList.currentRow = row;
1332 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1337 membersList.Destroy(0);
1338 membersListShown = false;
1344 InvokeParameters(false, false);
1352 bool NotifyDropped(EditBox editBox, int x, int y)
1354 char * controlClass = toolBox.controlClass;
1355 if(controlClass && controlClass[0])
1359 ObjectInfo classObject;
1361 //editBox.NotifyCaretMove(this, editBox, y, x);
1362 editBox.GoToLineNum(y);
1363 editBox.GoToPosition(editBox.line, y, x);
1365 classObject = selected ? selected.oClass : null;
1367 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1368 selected = classObject.instances.last;
1371 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1374 AddObject(control, &object);
1376 designer.CreateObject(control, object, false, classObject.instance);
1377 // designer.PostCreateObject(control, object, false, classObject.instance);
1378 designer.DroppedObject(control, object, false, classObject.instance);
1380 sheet.AddObject(object, object.name, typeData /* className*/, true);
1383 //codeModified = true;
1390 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1392 if(key == ctrlSpace)
1394 membersList.Destroy(0);
1395 membersListShown = false;
1396 InvokeAutoComplete(false, 0, false);
1399 else if(key == Key { space, ctrl = true, shift = true })
1400 InvokeParameters(false, true, false);
1401 else if(key == escape)
1402 ide.RepositionWindows(true);
1403 else if(key == ctrlF7)
1407 ProjectNode node = ide.projectView.GetNodeFromWindow(this, null, true, false);
1409 node = ide.projectView.GetNodeFromWindow(this, null, true, true);
1413 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1414 $"It can't be compiled.");
1415 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1424 bool OnKeyDown(Key key, unichar ch)
1426 CodeEditor editor = (CodeEditor)master;
1427 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1429 if(editor.membersListShown)
1431 editor.membersList.Destroy(0);
1432 editor.membersListShown = false;
1435 if(editor.paramsShown)
1437 editor.paramsList.Destroy(0);
1438 editor.paramsShown = false;
1439 FreeType(editor.functionType);
1440 FreeType(editor.instanceType);
1442 editor.functionType = null;
1443 editor.instanceType = null;
1444 editor.paramsID = -1;
1448 return EditBox::OnKeyDown(key, ch);
1451 void OnVScroll(ScrollBarAction action, int position, Key key)
1453 if(anchor.left.distance)
1455 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1458 EditBox::OnVScroll(action, position, key);
1460 CodeEditor ce = (CodeEditor)parent;
1461 if(ce.openedFileInfo)
1462 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1466 void OnHScroll(ScrollBarAction action, int position, Key key)
1468 EditBox::OnHScroll(action, position, key);
1470 CodeEditor ce = (CodeEditor)parent;
1471 if(ce.openedFileInfo)
1472 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1479 fullRowSelect = false,
1482 borderStyle = bevel;
1483 // size = { 200, 400 };
1485 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1487 DataRow row = listBox.currentRow;
1490 char * string = row.string;
1492 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1494 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1495 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1496 editBox.PutS(string);
1499 membersListShown = false;
1504 bool OnKeyDown(Key key, unichar ch)
1506 CodeEditor editor = (CodeEditor) master;
1507 if(key == escape || key == leftAlt || key == rightAlt ||
1508 (key.ctrl && key.code != left && key.code != right &&
1509 key.code != leftShift && key.code != rightShift && key.code != space))
1512 if(editor.paramsShown)
1516 editor.paramsList.Destroy(0);
1517 editor.paramsShown = false;
1519 if(editor.membersListShown)
1523 editor.membersList.Destroy(0);
1524 editor.membersListShown = false;
1527 FreeType(editor.functionType);
1528 editor.functionType = null;
1530 FreeType(editor.instanceType);
1531 editor.instanceType = null;
1533 editor.paramsID = -1;
1538 return editor.editBox.OnKeyDown(key, ch);
1542 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1544 CodeEditor editor = (CodeEditor)master;
1545 Window rw = previous ? previous.rootWindow : null;
1546 if(!active && rw != editor.paramsList)
1549 editor.membersListShown = false;
1551 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1554 bool OnKeyHit(Key key, unichar ch)
1556 CodeEditor editor = (CodeEditor) master;
1560 case enter: case tab:
1562 DataRow row = currentRow;
1563 if(row && row.selected)
1565 char * string = row.string;
1567 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1568 editor.editBox.Delete(
1569 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1570 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1571 editor.editBox.PutS(string);
1574 editor.membersListShown = false;
1577 editor.editBox.OnKeyHit(key, ch);
1587 return ListBox::OnKeyHit(key, ch);
1593 // If before . or after
1594 //listBox.Destroy(true);
1595 result = editor.editBox.OnKeyHit(key, ch);
1610 clickThrough = true,
1612 borderStyle = contour,
1614 background = { 255,255,225 },
1616 OnKeyDown = membersList.OnKeyDown;
1618 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1620 CodeEditor editor = (CodeEditor)master;
1621 Window rw = previous ? previous.rootWindow : null;
1622 if(!active && previous != editor.editBox && rw != editor.membersList)
1625 editor.paramsShown = false;
1627 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1630 bool OnKeyHit(Key key, unichar ch)
1632 CodeEditor editor = (CodeEditor)master;
1634 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1637 bool result = true; editor.editBox.OnKeyHit(key, ch);
1638 return (!created) ? false : result;
1645 void OnRedraw(Surface surface)
1647 CodeEditor editor = (CodeEditor) master;
1648 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1650 Type methodType = null;
1654 int functionW, nameW = 0;
1656 int spaceW, spaceH, commaW, commaWB, parW;
1658 int maxW = 0, lineW = 0;
1664 Font font = editor.normalFont.font;
1665 Font boldFont = editor.boldFont.font;
1666 Display display = this.display;
1668 if(!type) { return; };
1670 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1672 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1673 display.FontExtent(font, ", ", 2, &commaW, null);
1674 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1675 display.FontExtent(font, ")", 1, &parW, null);
1678 if(editor.functionType)
1680 PrintType(type.returnType, string, true, true);
1681 display.FontExtent(font, string, strlen(string), &functionW, null);
1683 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1684 totalW = nameW + functionW + 2 * parW;
1688 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1689 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1690 if(instanceName && type.kind != functionType)
1691 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1692 totalW = functionW + nameW;
1693 surface.TextFont(boldFont);
1696 surface.WriteText(x, y, string, strlen(string));
1697 x += functionW + spaceW;
1699 if(editor.functionType)
1702 surface.WriteText(x, y, type.name, strlen(type.name));
1704 surface.WriteText(x, y, "(", 1);
1707 if(methodType && !methodType.staticMethod && methodType.methodClass)
1711 if(id == editor.paramsID)
1712 surface.TextFont(boldFont);
1714 if(methodType.methodClass)
1715 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1719 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1720 width += ((id == editor.paramsID) ? commaWB : commaW);
1725 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1730 x = 2 + nameW + spaceW + functionW + parW;
1734 if(methodType.methodClass)
1735 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1738 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1740 surface.WriteText(x, y, ",", 1);
1741 x += ((id == editor.paramsID) ? commaWB : commaW);
1749 if(id == editor.paramsID)
1750 surface.TextFont(font);
1754 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1756 for(param = type.params.first; param; param = param.next)
1758 char paramString[1024];
1761 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1762 surface.TextFont(boldFont);
1765 PrintType(param, paramString, true, true);
1766 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1768 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1773 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1778 x = 2 + nameW + spaceW + functionW + parW;
1782 surface.WriteText(x, y, paramString, strlen(paramString));
1786 surface.WriteText(x, y, ",", 1);
1787 x += ((id == editor.paramsID) ? commaWB : commaW);
1795 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1796 surface.TextFont(font);
1801 surface.WriteText(x, y, ")", 1);
1803 else if(instanceName && type.kind != functionType)
1805 surface.WriteText(x, y, instanceName, strlen(instanceName));
1809 bool OnResizing(int * w, int * h)
1811 CodeEditor editor = (CodeEditor) master;
1812 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1814 Type methodType = null;
1818 int functionW = 0, nameW = 0;
1820 int spaceW, spaceH, commaW, commaWB, parW;
1822 int maxW = 0, lineW = 0;
1827 Font font = editor.normalFont.font;
1828 Font boldFont = editor.boldFont.font;
1829 Display display = this.display;
1831 if(type.kind == TypeKind::methodType)
1834 ProcessMethodType(type.method);
1835 type = type.method.dataType;
1838 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1839 display.FontExtent(font, ", ", 2, &commaW, null);
1840 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1841 display.FontExtent(font, ")", 1, &parW, null);
1844 if(editor.functionType && type)
1846 PrintType(type.returnType, string, true, true);
1847 display.FontExtent(font, string, strlen(string), &functionW, null);
1849 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1850 totalW = nameW + spaceW + functionW + 2 * parW;
1854 PrintType(type, string, false, true); // /*true);
1855 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1856 if(instanceName && type.kind != functionType)
1857 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1858 totalW = functionW + nameW + spaceW;
1861 if(editor.functionType)
1867 if(methodType.methodClass)
1868 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1869 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1870 width += ((id == editor.paramsID) ? commaWB : commaW);
1875 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1888 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1890 for(param = type.params.first; param; param = param.next)
1892 char paramString[1024];
1896 PrintType(param, paramString, true, true);
1897 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1899 width += ((id == editor.paramsID) ? commaWB : commaW);
1904 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1921 *w = realW + totalW + 4;
1927 Menu fileMenu { menu, $"File", f };
1928 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1929 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1931 Menu debugMenu { menu, $"Debug", d };
1932 MenuItem debugRunToCursor { debugMenu, $"Run To Cursor", c, ctrlF10, id = RTCMenuBits { false, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1933 MenuItem debugSkipRunToCursor { debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true }, id = RTCMenuBits { true, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1934 MenuItem debugRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level", l, altF10, id = RTCMenuBits { false, true, false }, NotifySelect = RTCMenu_NotifySelect; };
1935 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; };
1937 MenuItem debugBpRunToCursor { debugMenu, $"BP Run To Cursor"/*, c, ctrlF10*/, id = RTCMenuBits { false, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1938 MenuItem debugBpSkipRunToCursor { debugMenu, $"BP Run To Cursor Skipping Breakpoints"/*, u, Key { f10, ctrl = true, shift = true }*/, id = RTCMenuBits { true, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1939 MenuItem debugBpRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level"/*, l, altF10*/, id = RTCMenuBits { false, true, true }, NotifySelect = RTCMenu_NotifySelect; };
1940 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; };
1942 bool RTCMenu_NotifySelect(MenuItem selection, Modifiers mods)
1944 ProjectView projectView = ide.projectView;
1945 if(!projectView.buildInProgress)
1947 RTCMenuBits bits = (RTCMenuBits)selection.id;
1948 int line = editBox.lineNumber + 1;
1951 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1952 ProjectConfig config = projectView.project.config;
1953 int bitDepth = ide.workspace.bitDepth;
1954 bool useValgrind = ide.workspace.useValgrind;
1955 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, bits.ignoreBreakpoints, bits.atSameLevel, bits.oldImplementation);
1961 MenuDivider { debugMenu };
1962 MenuItem debugToggleBreakpoint
1964 debugMenu, $"Toggle Breakpoint", t, f9;
1965 bool NotifySelect(MenuItem selection, Modifiers mods)
1967 ProjectView projectView = ide.projectView;
1968 if(projectView && fileName)
1970 int line = editBox.lineNumber + 1;
1971 ide.debugger.ToggleBreakpoint(fileName, line);
1981 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1985 designer.parent = parent;
1988 toolBox = ((IDEWorkSpace)master).toolBox;
1990 // Debugger bug here: value of toolBox appears as 0
1992 sheet = ((IDEWorkSpace)master).sheet;
1997 bool OnClose(bool parentClosing)
2001 if(ide.workspace && fileName)
2002 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2003 if(inUseDebug && !debugClosing)
2005 debugClosing = true;
2007 if(CloseConfirmation(false))
2010 if(modifiedDocument)
2011 OnFileModified({ modified = true }, null);
2013 debugClosing = false;
2016 if(designer && !designer.closing)
2018 if(designer.visible)
2025 //Window formEditor = designer;
2026 //formEditor.Destroy(0);
2029 ide.AdjustFileMenus();
2034 void OnDestroy(void)
2036 ObjectInfo oClass, next;
2037 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2039 FreeType(this.functionType);
2040 FreeType(this.instanceType);
2045 designer.codeEditor = null;
2046 designer.Destroy(0);
2050 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2052 ObjectInfo object, next;
2054 for(object = oClass.instances.first; object; object = next)
2059 Designer::DestroyObject(object.instance);
2060 delete object.instance;
2062 sheet.DeleteObject(object);
2064 oClass.instances.Delete(object);
2068 Designer::DestroyObject(oClass.instance);
2069 delete oClass.instance;
2071 sheet.DeleteObject(oClass);
2073 classes.Delete(oClass);
2076 if(windowClass && windowClass.data)
2077 UnapplySkin(windowClass);
2081 if(sheet.codeEditor == this)
2083 sheet.codeEditor = null;
2084 toolBox.codeEditor = null;
2090 ProjectView projectView = ide.projectView;
2093 ProjectNode node = projectView.GetNodeFromWindow(this, null, false, false);
2094 if(node && node.modified)
2096 node.modified = false;
2097 projectView.Update(null);
2103 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2105 // 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
2107 if(directActivation)
2108 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2110 if(active && directActivation)
2114 openedFileInfo.Activate();
2118 Location * loc = null;
2119 UpdateFormCode(); // To ensure update when modifying properties...
2121 // Got to the right spot in code so we don't lose our form selection...
2124 if(selected.instCode)
2125 loc = &selected.instCode.loc;
2126 else if(selected.classDefinition)
2127 loc = &selected.classDefinition.loc;
2129 line = editBox.lineNumber + 1;
2130 charPos = editBox.charPos + 1;
2135 if(selected && !loc->Inside(line, charPos))
2137 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2138 line = editBox.lineNumber + 1;
2139 charPos = editBox.charPos + 1;
2141 else if(selected && selected.classDefinition)
2144 for(object = selected.instances.first; object; object = object.next)
2148 if(object.instCode.loc.Inside(line, charPos))
2154 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2155 line = editBox.lineNumber + 1;
2156 charPos = editBox.charPos + 1;
2161 ProcessCaretMove(editBox, line, charPos);
2166 if(membersListShown)
2168 membersList.Destroy(0);
2169 membersListShown = false;
2173 paramsList.Destroy(0);
2174 paramsShown = false;
2175 FreeType(functionType);
2176 FreeType(instanceType);
2178 functionType = null;
2179 instanceType = null;
2186 bool OnSaveFile(char * fileName)
2193 f = FileOpen(fileName, write);
2196 if(!ide.projectView)
2197 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2201 this.fileName = fileName; // Put this here because the form designer will check for it...
2202 designer.fileName = fileName;
2203 designer.modifiedDocument = false;
2205 editBox.Save(f, false);
2206 modifiedDocument = false;
2214 bool OnFileModified(FileChange fileChange, char * param)
2216 bool reload = false;
2217 if(visible == false && inUseDebug == true)
2218 ide.debugger.WatchesReleaseCodeEditor();
2223 sprintf(message, $"The document %s was modified by another application.\n"
2224 "Would you like to reload it and lose your changes?", fileName);
2225 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2226 contents = message }.Modal() == yes)
2232 File f = FileOpen(fileName, read);
2235 int lineNumber, charPos, len;
2239 updatingCode = true;
2240 lineNumber = editBox.lineNumber;
2241 charPos = editBox.charPos;
2242 scroll = editBox.scroll;
2245 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2246 len = strlen(editBox.line.text);
2247 editBox.GoToLineNum(lineNumber);
2248 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2249 editBox.scroll = scroll;
2250 updatingCode = false;
2251 loadingFile = false;
2253 codeModified = true;
2257 designer.modifiedDocument = false;
2259 modifiedDocument = false;
2267 void OnRedraw(Surface surface)
2270 surface.SetBackground(marginColor);
2271 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2272 if(ideSettings.showLineNumbers)
2274 int currentLineNumber;
2276 char lineFormat[16];
2280 surface.textOpacity = false;
2281 surface.font = font.font;
2282 surface.TextExtent(" ", 1, null, &spaceH);
2283 currentLineNumber = editBox.scroll.y / spaceH + 1;
2284 sprintf(lineFormat, " %%%du", maxLineNumberLength);
2286 surface.SetForeground(lineNumbersColor);
2287 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2289 // Highlight current line
2290 if(editBox.lineNumber == currentLineNumber - 1)
2292 surface.SetBackground(selectedMarginColor);
2293 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2294 surface.SetBackground(marginColor);
2296 sprintf(lineText, lineFormat, currentLineNumber);
2297 if(currentLineNumber <= editBox.numLines)
2298 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
2299 currentLineNumber++;
2303 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2305 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2306 int lineCursor, lineTopFrame, breakpointLines[128];
2307 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2308 Debugger debugger = ide.debugger;
2309 BitmapResource bmpRes;
2311 boxH = clientSize.h;
2312 scrollY = editBox.scroll.y;
2313 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2315 bpOnCursor = bpOnTopFrame = false;
2316 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2319 for(i = 0; i < count; i++)
2321 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2323 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2324 if(breakpointLines[i] == lineCursor)
2326 if(breakpointLines[i] == lineTopFrame)
2327 bpOnTopFrame = true;
2330 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2332 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2335 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2336 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2337 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2339 if(editBox.anchor.left.distance)
2341 if(editBox.horzScroll && editBox.horzScroll.visible)
2343 surface.SetBackground(control);
2344 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2349 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2354 lineY = (line - 1) * lineH;
2355 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2357 Bitmap bitmap = resource.bitmap;
2359 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2366 char ext[MAX_EXTENSION];
2367 char * fileName = property::fileName;
2369 if(SearchString(fileName, 0, "Makefile", false, true))
2370 editBox.useTab = true;
2371 designer.fileName = fileName;
2375 GetExtension(fileName, ext);
2377 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2378 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2379 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2380 editBox.syntaxHighlighting = true;
2382 editBox.syntaxHighlighting = false;
2384 if(parsing && !strcmpi(ext, "ec"))
2386 codeModified = true;
2394 bool UpdateMarginSize()
2396 static int lineCount = -1;
2397 if(editBox.numLines != lineCount)
2400 lineCount = editBox.numLines;
2401 if(nofdigits(lineCount) != maxLineNumberLength)
2403 maxLineNumberLength = nofdigits(lineCount);
2404 display.FontExtent(font.font, "0", 1, &digitWidth, null);
2405 editBox.anchor = Anchor
2407 left = editBox.syntaxHighlighting * 20 + (ideSettings.showLineNumbers ? ((maxLineNumberLength+2) * digitWidth) : 0),
2408 right = 0, top = 0, bottom = 0
2421 bool LoadFile(char * filePath)
2423 File f = FileOpen(filePath, read);
2426 // Added this here...
2427 fileName = filePath;
2429 updatingCode = true;
2431 updatingCode = false;
2432 loadingFile = false;
2441 void AdjustDebugMenus()
2443 bool unavailable = ide.areDebugMenusUnavailable;
2444 bool isNotNotRunning = unavailable || ide.isDebuggerRunning;
2445 bool isNotStopped = unavailable || !ide.isDebuggerStopped;
2446 bool noBreakpointToggle = ide.isBreakpointTogglingUnavailable;
2448 debugRunToCursor.disabled = isNotNotRunning;
2449 debugSkipRunToCursor.disabled = isNotNotRunning;
2450 debugRunToCursorAtSameLevel.disabled = isNotStopped;
2451 debugSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2453 debugBpRunToCursor.disabled = isNotNotRunning;
2454 debugBpSkipRunToCursor.disabled = isNotNotRunning;
2455 debugBpRunToCursorAtSameLevel.disabled = isNotStopped;
2456 debugBpSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2458 debugToggleBreakpoint.disabled = noBreakpointToggle;
2464 ProjectView projectView = ide.projectView;
2467 designer.fileName = fileName;
2473 sprintf(title, $"Untitled %d", documentID);
2474 // designer.fileName = CopyString(title);
2475 designer.fileName = title;
2480 for(c = 0; c < CodeObjectType::enumSize; c++)
2481 icons[c] = BitmapResource { iconNames[c], window = this };
2483 codeModified = true;
2495 selected.modified = true;
2496 selected.oClass.modified = true;
2498 designer.modifiedDocument = true;
2499 modifiedDocument = true;
2500 formModified = true;
2503 /****************************************************************************
2505 ****************************************************************************/
2513 this.defines.Free(FreeModuleDefine);
2514 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2516 FreeExcludedSymbols(this.excludedSymbols);
2517 FreeContext(this.globalContext);
2519 FreeGlobalData(&this.globalData);
2520 FindCtx_Terminate();
2521 FindParams_Terminate();
2523 if(GetGlobalContext() == globalContext)
2525 SetGlobalData(null);
2526 SetGlobalContext(null);
2527 SetExcludedSymbols(null);
2528 SetTopContext(null);
2529 SetCurrentContext(null);
2532 SetPrivateModule(null);
2535 if(this.privateModule)
2537 FreeTypeData(this.privateModule);
2538 delete this.privateModule;
2539 this.privateModule = null;
2545 static bool reentrant = false;
2550 char * selectedClassName = null, * selectedName = null;
2551 int selectedPos = 0;
2552 Designer backDesigner;
2553 char oldWorkDir[MAX_LOCATION];
2554 char mainModuleName[MAX_FILENAME] = "";
2556 ImportedModule module;
2557 char extension[MAX_EXTENSION];
2558 PathBackup pathBackup { };
2560 Time parseCodeStart = GetTime();
2561 Time startTime, startFindClass;
2563 findClassTotalTime = 0;
2564 checkTypeTotalTime = 0;
2565 externalImportTotalTime = 0;
2566 findClassIgnoreNSTotalTime = 0;
2567 findSymbolTotalTime = 0;
2568 //ResetClassFindTime();
2572 // 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)
2573 if(reentrant) return;
2580 selectedClassName = CopyString(oClass.name);
2581 if(selected != oClass)
2583 ObjectInfo object = this.selected;
2584 selectedName = CopyString(object.name);
2588 for(check = this.oClass.instances.first; check; check = check.next)
2600 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2602 FindCtx_Terminate();
2603 FindParams_Terminate();
2605 SetGlobalData(&globalData);
2606 SetGlobalContext(globalContext);
2607 SetExcludedSymbols(&excludedSymbols);
2608 SetTopContext(globalContext);
2609 SetCurrentContext(globalContext);
2610 SetDefines(&defines);
2611 SetImports(&imports);
2612 SetCurrentNameSpace(null);
2615 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2616 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2617 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2618 "/I T:\\ecere\\include /E %s", argv[1]);
2622 ChangeWorkingDir("e:\\ec");
2623 sprintf(command, "gcc -x c -E -");
2624 fileInput = DualPipeOpen({ output = true, input = true }, command);
2625 SetFileInput(fileInput);
2630 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2632 fileInput.Write(buffer, 1, count);
2637 fileInput.CloseOutput();
2641 // TOCHECK: COULDN'T WE CALL FreeParser here?
2643 FreeType(this.functionType);
2644 FreeType(this.instanceType);
2645 this.functionType = null;
2646 this.instanceType = null;
2649 sheet.SelectObject(null);
2655 // We don't want the designer to be notified of selection when deleting rows...
2656 backDesigner = designer;
2661 ObjectInfo _class, next;
2663 for(_class = classes.first; _class; _class = next)
2669 for(;object = _class.instances.first;)
2673 Designer::DestroyObject(object.instance);
2674 delete object.instance;
2676 sheet.DeleteObject(object);
2678 _class.instances.Delete(object);
2682 Designer::DestroyObject(_class.instance);
2683 delete _class.instance;
2685 sheet.DeleteObject(_class);
2687 classes.Delete(_class);
2693 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2694 if(windowClass && windowClass.data)
2695 UnapplySkin(windowClass);
2698 designer = backDesigner;
2701 fileInput = editFile = EditBoxStream { editBox = editBox };
2702 SetFileInput(fileInput);
2710 defines.Free(FreeModuleDefine);
2711 imports.Free(FreeModuleImport);
2713 FreeContext(this.globalContext);
2714 FreeExcludedSymbols(this.excludedSymbols);
2717 FreeGlobalData(&this.globalData);
2719 if(this.privateModule)
2721 FreeTypeData(this.privateModule);
2722 delete this.privateModule;
2726 startTime = GetTime();
2727 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2729 printf("classes.count: %d\n", globalContext.classes.count);
2734 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2735 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2738 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2740 SetPrivateModule(privateModule);
2743 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2744 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2745 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2746 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2747 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2750 fileName = this.fileName;
2752 if(ide.workspace && ide.workspace.projects && fileName)
2754 for(p : ide.workspace.projects)
2756 char path[MAX_LOCATION];
2758 MakePathRelative(fileName, p.topNode.path, path);
2759 MakeSlashPath(path);
2761 pn = p.topNode.FindWithPath(path, false);
2770 project = ide.project;
2772 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2774 ChangeWorkingDir(project.topNode.path);
2776 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2778 GetLastDirectory(fileName, mainModuleName);
2779 GetExtension(mainModuleName, extension);
2781 SetBuildingEcereCom(false);
2782 SetBuildingEcereComModule(false);
2784 // TODO: Get symbolsDir from project settings instead...
2787 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2788 ProjectConfig config = project.config;
2789 int bitDepth = ide.workspace.bitDepth;
2790 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2791 SetSymbolsDir(objDir.dir);
2792 ide.SetPath(true, compiler, config, bitDepth);
2796 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2797 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2801 switch(GetRuntimePlatform())
2803 case win32: SetSymbolsDir("obj/debug.win32"); break;
2804 case tux: SetSymbolsDir("obj/debug.linux"); break;
2805 case apple: SetSymbolsDir("obj/debug.apple"); break;
2807 SetIncludeDirs(null);
2808 SetSysIncludeDirs(null);
2812 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2814 // TODO FIX for configless project
2815 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2817 for(item : ide.project.config.options.preprocessorDefinitions)
2819 if(!strcmp(item, "BUILDING_ECERE_COM"))
2821 SetBuildingEcereCom(true);
2828 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2829 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2830 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2831 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2832 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2833 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2834 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2835 strcmpi(mainModuleName, "Mutex.ec")))
2837 SetBuildingEcereComModule(true);
2840 // Predeclare all classes
2842 char symFile[MAX_FILENAME];
2843 char symLocation[MAX_LOCATION];
2844 ImportedModule module, next;
2846 GetLastDirectory(fileName, symFile);
2847 ChangeExtension(symFile, "sym", symFile);
2849 strcpy(symLocation, GetSymbolsDir());
2850 PathCat(symLocation, symFile);
2852 // if(!GetEcereImported() && !GetBuildingEcereCom())
2853 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2856 startTime = GetTime();
2858 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2860 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2865 startTime = GetTime();
2867 // LoadSymbols(symLocation, normalImport, true);
2868 LoadSymbols(symLocation, preDeclImport, false);
2870 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2873 for(module = defines.first; module; module = next)
2876 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2879 defines.Delete(module);
2884 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2886 SetDefaultDeclMode(privateAccess);
2887 SetDeclMode(privateAccess);
2891 SetDefaultDeclMode(defaultAccess);
2892 SetDeclMode(defaultAccess);
2895 StripExtension(mainModuleName);
2896 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2897 defines.AddName(module);
2900 // SetYydebug(true);
2905 startTime = GetTime();
2906 startFindClass = checkTypeTotalTime;
2910 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2912 CheckDataRedefinitions();
2915 SetIncludeDirs(null);
2916 SetSysIncludeDirs(null);
2927 startTime = GetTime();
2929 PrePreProcessClassDefinitions();
2930 ComputeModuleClasses(privateModule);
2931 PreProcessClassDefinitions();
2932 ProcessClassDefinitions();
2934 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2935 startTime = GetTime();
2940 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2941 startTime = GetTime();
2943 ProcessInstantiations();
2945 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2948 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2950 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2951 if(!windowClass || windowClass.internalDecl)
2954 startTime = GetTime();
2956 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2957 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2958 eModule_Load(this.privateModule, "ecere", privateAccess);
2960 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2963 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2965 if(windowClass && windowClass.data)
2966 ApplySkin(windowClass, app.currentSkin.name, null);
2970 startTime = GetTime();
2972 for(external = ast->first; external; external = external.next)
2974 if(external.type == classExternal)
2976 ClassDefinition _class = external._class;
2977 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2979 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2982 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2984 Instance instance = eInstance_New(regClass);
2985 ObjectInfo classObject
2987 name = CopyString(_class._class.name);
2988 instance = instance;
2989 classDefinition = _class;
2990 oClass = classObject;
2993 classes.Add(classObject);
2997 // Moved this at bottom so that the file dialog doesn't show up in eCom
2998 designer.CreateObject(instance, classObject, true, null);
2999 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
3001 if(_class.definitions)
3005 for(def = _class.definitions->first; def; def = def.next)
3009 case defaultPropertiesClassDef:
3012 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3014 Identifier id = propDef.identifiers->first;
3017 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3020 Class propertyClass = prop.dataTypeClass;
3022 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3023 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3025 FreeType(propDef.initializer.exp.destType);
3026 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3027 ProcessExpressionType(propDef.initializer.exp);
3029 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
3031 Expression computed = CopyExpression(propDef.initializer.exp);
3032 ComputeExpression(computed);
3034 if(computed.isConstant && computed.type == instanceExp && !id.next)
3038 if(computed.instance._class && computed.instance._class.symbol &&
3039 computed.instance._class.symbol.registered &&
3040 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3042 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3044 // This was saved in the control and shouldn't be freed by FreeExpression...
3045 // (Not doing this anymore, incrementing refCount in pass15 instead)
3046 /*if(propertyClass.type == normalClass)
3047 computed.instance.data = null;*/
3051 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3052 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3054 String temp = new char[strlen(computed.string)+1];
3055 ReadString(temp, computed.string);
3056 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3060 propDef.variable = true;
3062 FreeExpression(computed);
3066 Expression computed = CopyExpression(propDef.initializer.exp);
3067 ComputeExpression(computed);
3068 if(computed.isConstant)
3070 //if(computed.type == memberExp) computed = computed.member.exp;
3072 if(computed.type == constantExp)
3074 Operand value = GetOperand(computed);
3075 DataValue valueData;
3076 valueData.i64 = value.i64;
3077 SetProperty(prop, instance, valueData);
3079 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3081 String temp = new char[strlen(computed.string)+1];
3082 ReadString(temp, computed.string);
3083 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3088 propDef.variable = true;
3090 FreeExpression(computed);
3094 propDef.variable = true;
3098 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3099 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3100 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3103 // Maintain a list in FunctionDefinition of who is attached to it
3104 for(def = _class.definitions->first; def; def = def.next)
3106 if(def.type == functionClassDef)
3108 ClassFunction function = def.function;
3109 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3111 function.attached.Add(OldLink { data = method });
3121 case declarationClassDef:
3123 Declaration decl = def.decl;
3126 case instDeclaration:
3128 Instantiation inst = decl.inst;
3129 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3130 if(instClass && eClass_GetDesigner(instClass))
3132 Instance control = eInstance_New(instClass);
3137 oClass = classObject;
3141 classObject.instances.Add(object);
3143 // TOCHECK: Why is this needed now?
3144 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3145 def.object = object;
3147 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3149 designer.CreateObject(control, object, false, classObject.instance);
3150 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3160 // Second pass, process instantiation members
3162 for(def = _class.definitions->first; def; def = def.next)
3166 case declarationClassDef:
3168 Declaration decl = def.decl;
3171 case instDeclaration:
3173 Instantiation inst = decl.inst;
3174 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3175 if(instClass && eClass_GetDesigner(instClass))
3178 object = object ? object.next : classObject.instances.first;
3179 control = object.instance;
3183 MembersInit members;
3184 for(members = inst.members->first; members; members = members.next)
3186 switch(members.type)
3188 case dataMembersInit:
3190 if(members.dataMembers)
3193 DataMember curMember = null;
3194 Class curClass = null;
3195 DataMember subMemberStack[256];
3196 int subMemberStackPos = 0;
3198 for(member = members.dataMembers->first; member; member = member.next)
3201 Identifier ident = member.identifiers ? member.identifiers->first : null;
3204 DataMember _subMemberStack[256];
3205 int _subMemberStackPos = 0;
3206 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3210 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3212 if(thisMember && thisMember.memberAccess == publicAccess)
3214 curMember = thisMember;
3215 curClass = curMember._class;
3216 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3217 subMemberStackPos = _subMemberStackPos;
3223 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3224 if(curMember) found = true;
3226 if(found && curMember.isProperty)
3228 Property prop = (Property) curMember;
3229 Class propertyClass = prop.dataTypeClass;
3231 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3233 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3235 FreeType(member.initializer.exp.destType);
3236 member.initializer.exp.destType = MkClassType(propertyClass.name);
3239 ProcessExpressionType(member.initializer.exp);
3241 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3243 Expression computed;
3245 /*char debugExpString[4096];
3246 debugExpString[0] = '\0';
3247 PrintExpression(member.initializer.exp, debugExpString);*/
3249 computed = CopyExpression(member.initializer.exp);
3252 ComputeExpression(computed);
3254 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3256 if(computed.instance.data)
3258 if(computed.instance._class && computed.instance._class.symbol &&
3259 computed.instance._class.symbol.registered &&
3260 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3262 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3264 // This was saved in the control and shouldn't be freed by FreeExpression...
3265 // (Not doing this anymore, incrementing refCount in pass15 instead)
3266 /*if(propertyClass.type == normalClass)
3267 computed.instance.data = null;*/
3271 else if(computed.type == identifierExp)
3273 member.variable = true;
3275 if(eClass_GetDesigner(propertyClass))
3278 char * name = computed.identifier.string;
3279 if(!strcmp(name, "this"))
3282 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3283 member.variable = false;
3288 for(check = classObject.instances.first; check; check = check.next)
3289 if(check.name && !strcmp(name, check.name))
3292 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3293 member.variable = false;
3299 else if(computed.type == memberExp)
3301 member.variable = true;
3302 if(computed.member.exp.type == identifierExp)
3304 char * name = computed.member.exp.identifier.string;
3305 if(!strcmp(name, "this"))
3307 char * name = computed.member.member.string;
3310 for(check = classObject.instances.first; check; check = check.next)
3311 if(check.name && !strcmp(name, check.name))
3314 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3315 member.variable = false;
3323 for(check = classObject.instances.first; check; check = check.next)
3325 if(check.name && !strcmp(name, check.name))
3327 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3330 DataValue value { };
3331 GetProperty(getProperty, check.instance, &value);
3332 SetProperty(prop, control, value);
3333 member.variable = false;
3341 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3342 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3344 String temp = new char[strlen(computed.string)+1];
3345 ReadString(temp, computed.string);
3346 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3350 member.variable = true;
3352 FreeExpression(computed);
3357 Expression computed = CopyExpression(member.initializer.exp);
3360 ComputeExpression(computed);
3361 if(computed.isConstant)
3363 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3365 if(!strcmp(propertyClass.dataTypeString, "float"))
3366 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3367 else if(!strcmp(propertyClass.dataTypeString, "double"))
3368 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3370 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3372 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3374 String temp = new char[strlen(computed.string)+1];
3375 ReadString(temp, computed.string);
3376 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3381 member.variable = true;
3383 FreeExpression(computed);
3389 member.variable = true;
3391 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3392 member.initializer.exp.type == memberExp) // identifierExp
3394 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3395 if(method && method.type == virtualMethod)
3398 // Maintain a list in FunctionDefinition of who is attached to it
3399 for(def = _class.definitions->first; def; def = def.next)
3401 if(def.type == functionClassDef)
3403 ClassFunction function = def.function;
3404 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3405 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3407 function.attached.Add(OldLink { data = method });
3408 // Reference this particular instance?
3423 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3434 //designer.CreateObject(instance, classObject, true, null);
3435 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3437 designer.PostCreateObject(instance, classObject, true, null);
3439 //instance.state = Hidden;
3440 //instance.Create();
3441 //instance.SetState(Normal, true, 0);
3450 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3454 // Restore Selection
3455 if(selectedClassName)
3458 for(oClass = classes.first; oClass; oClass = oClass.next)
3460 if(!strcmp(oClass.name, selectedClassName))
3462 this.oClass = oClass;
3466 delete selectedClassName;
3475 for(check = this.oClass.instances.first; check; check = check.next)
3477 if(check.name && !strcmp(check.name, selectedName))
3479 this.selected = check;
3485 if(this.oClass.instances.first)
3486 this.selected = this.oClass.instances.first;
3488 this.selected = this.oClass;
3491 else if(selectedPos == -1 || !this.oClass.instances.count)
3492 this.selected = this.oClass;
3498 if(selectedPos > this.oClass.instances.count)
3500 for(check = this.oClass.instances.first; check; check = check.next)
3502 if(selectedPos == pos++)
3504 this.selected = check;
3512 this.oClass = classes.first;
3513 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3515 delete selectedName;
3516 SetSymbolsDir(null);
3518 if(sheet.codeEditor == this)
3519 sheet.SelectObject(selected);
3522 codeModified = false;
3524 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3527 InvokeParameters(false, false, false);
3530 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3536 ChangeWorkingDir(oldWorkDir);
3538 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3539 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3540 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3541 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3542 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3544 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3546 if(inUseDebug && ide.projectView)
3547 ide.debugger.EvaluateWatches();
3552 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3555 Window control = (Window)object.instance;
3556 ObjectInfo classObject = object.oClass;
3558 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3560 if(!strcmp(_class.name, "DesignerBase")) return;
3562 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3564 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3565 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3567 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3568 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3570 Class dataType = prop.dataTypeClass;
3572 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3576 if(dataType.type == structClass)
3578 void * dataForm = new0 byte[dataType.structSize];
3579 void * dataTest = new0 byte[dataType.structSize];
3581 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3582 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3584 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3586 char tempString[1024] = "";
3588 bool needClass = true;
3592 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3594 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3596 eClass_FindNextMember(_class, curClass, curMember, null, null);
3597 if(*curMember != (DataMember)prop)
3598 f.Printf("%s = ", prop.name);
3600 *curMember = (DataMember)prop;
3601 *curClass = curMember->_class;
3604 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3606 f.Printf("%s", string);
3613 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3615 void * dataForm, * dataTest;
3617 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3618 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3620 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3622 char tempString[1024] = "";
3627 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3629 eClass_FindNextMember(_class, curClass, curMember, null, null);
3630 if(*curMember != (DataMember)prop)
3631 f.Printf("%s = ", prop.name);
3632 *curMember = (DataMember)prop;
3633 *curClass = curMember->_class;
3635 if(eClass_GetDesigner(dataType))
3637 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3638 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3639 f.Printf("this", prop.name);
3642 //ObjectInfo classObject;
3643 //for(classObject = classes.first; classObject; classObject = classObject.next)
3647 for(object = classObject.instances.first; object; object = object.next)
3649 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3651 f.Printf("%s", object.name);
3658 bool needClass = true;
3659 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3660 f.Printf("%s", string);
3667 bool needClass = true;
3668 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3670 if(!strcmp(dataType.dataTypeString, "char *"))
3673 OutputString(f, string);
3677 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3679 f.Printf("%s", string);
3682 *lastIsMethod = false;
3687 DataValue dataForm, dataTest;
3689 GetProperty(prop, control, &dataForm);
3690 GetProperty(prop, test, &dataTest);
3692 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3695 char tempString[1024] = "";
3696 SetProperty(prop, test, dataForm);
3698 if(dataType.type != bitClass)
3700 bool needClass = true;
3702 if(dataType.type == enumClass)
3705 Class enumClass = eSystem_FindClass(privateModule, "enum");
3706 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3708 for(value = e.values.first; value; value = value.next)
3710 if((int)value.data == dataForm.i)
3712 string = value.name;
3718 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3720 if(string && string[0])
3725 eClass_FindNextMember(_class, curClass, curMember, null, null);
3726 if(*curMember != (DataMember)prop)
3727 f.Printf("%s = ", prop.name);
3728 *curMember = (DataMember)prop;
3729 *curClass = curMember->_class;
3731 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3732 f.Printf("%sf", string);
3734 f.Printf("%s", string);
3738 else if(dataType.type == bitClass)
3740 bool needClass = true;
3742 if(*prev) f.Printf(", ");
3744 eClass_FindNextMember(_class, curClass, curMember, null, null);
3745 if(*curMember != (DataMember)prop)
3746 f.Printf("%s = ", prop.name);
3747 *curMember = (DataMember)prop;
3748 *curClass = curMember->_class;
3750 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3752 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3754 f.Printf("%s", string);
3756 *lastIsMethod = false;
3766 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3768 Instantiation inst = object.instCode;
3769 Window control = (Window)object.instance;
3771 bool methodPresent = false;
3773 bool lastIsMethod = true;
3774 ObjectInfo classObject = object.oClass;
3780 // Instance removed, delete it
3781 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3783 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3784 position = inst.loc.end.pos + 1;
3788 bool multiLine = false;
3791 // Check if it's an unnamed instance
3794 f.Seek(inst.nameLoc.start.pos - position, current);
3795 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3796 position = inst.nameLoc.end.pos;
3798 f.Printf(object.name);
3803 if(isspace(ch) && ch != '\n')
3805 f.Seek(-1, current);
3813 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3815 f.Seek(pos - position, current);
3820 f.Seek(-1, current);
3829 f.Puts(object.name);
3834 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3835 methodPresent = true;
3843 if(ch == OpenBracket)
3849 // TODO: Simplify this?
3858 f.Seek(-1, current);
3870 if(ch == '\n') { toDelete = count; count = 0; }
3871 else if(isspace(ch)) count++;
3874 f.Seek(-1, current);
3878 toDelete += count - 6;
3888 f.Seek(-toDelete-count, current);
3889 f.DeleteBytes(toDelete);
3890 f.Seek(count, current);
3895 for(c = 0; c<toAdd; c++)
3901 methodPresent = multiLine;
3904 f.Printf(methodPresent ? "\n " : " ");
3910 // Instance not there, create a brand new one
3911 DeleteJunkBefore(f, position, &position);
3912 f.Printf(*firstObject ? "\n\n" : "\n");
3913 *firstObject = false;
3915 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3916 methodPresent = true;
3921 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3923 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3928 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3930 f.Printf(" %s %c ", control._class.name, OpenBracket);
3936 Instance test = eInstance_New(control._class);
3937 DataMember curMember = null;
3938 Class curClass = null;
3941 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3945 // Attach Method here
3946 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3948 if(prev) f.Printf(", ");
3949 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3954 if(inst && !object.deleted)
3956 MembersInit members;
3957 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3959 DeleteJunkBefore(f, position, &position);
3961 // Instance already there, clear out the properties
3962 for(members = inst.members->first; members; members = members.next)
3964 if(members.type == dataMembersInit)
3968 if(members.dataMembers)
3970 bool keptMember = false;
3971 MemberInit lastKept = null;
3973 for(member = members.dataMembers->first; member; member = member.next)
3975 Identifier ident = member.identifiers ? member.identifiers->first : null;
3976 bool deleted = false;
3978 // For now delete if it's not a method
3979 if(!member.variable) // && ident)
3981 if(!ident || !ident.next)
3983 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3986 f.Seek(member.loc.start.pos - position, current);
3987 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3988 position = member.loc.end.pos;
3993 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3994 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3995 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
3997 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
3998 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
4000 f.Seek(member.loc.start.pos - position, current);
4001 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4002 position = member.loc.end.pos;
4014 //f.Seek(member.loc.start.pos - position, current);
4015 //position = member.loc.start.pos;
4016 DeleteJunkBefore(f, member.loc.start.pos, &position);
4017 if(prev) f.Printf(", ");
4018 else if(keptMember) f.Printf(" ");
4023 if(!keptMember || !members.next)
4028 if(keptMember && lastKept != members.dataMembers->last)
4033 f.Seek(-1, current);
4039 f.Seek(-1, current);
4042 else if(!isspace(ch))
4044 f.Seek(-2, current);
4049 f.DeleteBytes(count);
4052 f.Seek(members.loc.end.pos - position, current);
4057 f.Seek(-1, current);
4059 position = members.loc.end.pos + 1;
4063 f.Seek(-1, current);
4064 position = members.loc.end.pos;
4070 lastIsMethod = false;
4075 DeleteJunkBefore(f, position, &position);
4078 if(lastKept != members.dataMembers->last)
4083 f.Seek(-1, current);
4089 f.Seek(-1, current);
4092 else if(!isspace(ch))
4094 f.Seek(-2, current);
4099 f.DeleteBytes(count);
4103 f.Seek(members.loc.end.pos - position, current);
4104 position = members.loc.end.pos;
4108 lastIsMethod = true;
4111 lastIsMethod = false;
4117 f.Seek(members.loc.end.pos - position, current);
4118 position = members.loc.end.pos;
4120 lastIsMethod = true;
4123 else if(members.type == methodMembersInit)
4125 if(this.methodAction == actionDeleteMethod && members.function == function);
4127 methodPresent = true;
4129 // Delete instance method here
4130 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4131 members.function == function)
4133 if(this.moveAttached && !*text)
4134 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4136 DeleteJunkBefore(f, members.loc.start.pos, &position);
4137 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4138 position = members.loc.end.pos + 1;
4143 DeleteJunkBefore(f, position, &position);
4147 DeleteJunkBefore(f, members.loc.start.pos, &position);
4148 lastIsMethod = true;
4152 f.Seek(members.loc.end.pos - position, current);
4153 position = members.loc.end.pos;
4155 DeleteJunkBefore(f, position, &position);
4164 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4166 Method method = this.method;
4167 DeleteJunkBefore(f, position, &position);
4173 if(!method.dataType)
4174 method.dataType = ProcessTypeString(method.dataTypeString, false);
4177 Type dataType = method.dataType;
4178 Type returnType = dataType.returnType;
4181 if(this.moveAttached)
4183 // Move function here:
4184 int newLen = strlen(method.name);
4189 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4191 // First change name of function
4192 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4193 *textSize += newLen - movedFuncIdLen;
4194 memcpy(*text + movedFuncIdPos, method.name, newLen);
4196 // Second, tab right
4199 for(c = 0; (*text)[c]; )
4202 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4205 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4206 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4210 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4220 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4222 // ADDING METHOD HERE
4224 OutputType(f, returnType, false);
4227 if(dataType.thisClass)
4229 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4231 if(dataType.thisClass.shortName)
4232 f.Printf(dataType.thisClass.shortName);
4234 f.Printf(dataType.thisClass.string);
4238 f.Printf(method.name);
4240 for(param = dataType.params.first; param; param = param.next)
4242 OutputType(f, param, true);
4247 f.Printf(" %c\n\n", OpenBracket);
4249 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4251 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4252 f.Printf(" return true;\n");
4253 else if(returnType.kind != voidType)
4254 f.Printf(" return 0;\n");
4259 if(returnType.kind != voidType)
4260 f.Printf("return ");
4261 f.Printf("%s::%s(", control._class.name, method.name);
4262 for(param = dataType.params.first; param; param = param.next)
4264 if(param.prev) f.Printf(", ");
4265 if(param.kind != voidType)
4266 f.Printf(param.name);
4270 f.Printf(" %c\n", CloseBracket);
4276 if(!object.instCode)
4279 f.Printf(" %c;\n", CloseBracket);
4281 f.Printf("%c;\n", CloseBracket);
4283 else if(!object.deleted)
4285 // Turn this into a multiline instance when adding a method
4286 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4288 f.Printf(methodPresent ? "\n " : " ");
4290 f.Seek(inst.loc.end.pos + 1 - position, current);
4291 position = inst.loc.end.pos + 1;
4296 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4299 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4301 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4303 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4305 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4306 if(prop && prop.isProperty && !prop.conversion)
4308 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4309 (!prop.IsSet || prop.IsSet(classObject.instance)))
4311 Class dataType = prop.dataTypeClass;
4312 char tempString[1024] = "";
4314 bool specify = false;
4317 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4318 if(member && member._class == regClass)
4322 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4324 if(dataType && dataType.type == structClass)
4326 void * dataForm = new0 byte[dataType.structSize];
4327 void * dataTest = new0 byte[dataType.structSize];
4329 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4330 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4332 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4334 bool needClass = true;
4336 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4337 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4339 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4341 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4346 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4348 void * dataForm, * dataTest;
4350 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4351 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4353 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4355 char tempString[1024] = "";
4357 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4359 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4361 // Shouldn't go here ...
4362 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4366 bool needClass = true;
4368 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4370 if(!strcmp(dataType.dataTypeString, "char *"))
4372 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4373 OutputString(f, string);
4377 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4379 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4385 DataValue dataForm, dataTest;
4387 GetProperty(prop, classObject.instance, &dataForm);
4388 GetProperty(prop, test, &dataTest);
4390 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4392 SetProperty(prop, test, dataForm);
4393 if(dataType.type == bitClass)
4395 bool needClass = true;
4396 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4398 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4400 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4404 bool needClass = true;
4405 if(dataType.type == enumClass)
4408 Class enumClass = eSystem_FindClass(privateModule, "enum");
4409 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4411 for(value = e.values.first; value; value = value.next)
4413 if((int)value.data == dataForm.i)
4415 string = value.name;
4421 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4422 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4423 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4425 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4434 void UpdateFormCode()
4437 if(!parsing) return;
4444 else if(formModified)
4446 EditBoxStream f { editBox = editBox };
4450 Identifier movedFuncId;
4451 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4452 ObjectInfo classObject;
4458 movedFuncId = GetDeclId(function.declarator);
4459 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4460 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4463 for(classObject = classes.first; classObject; classObject = classObject.next)
4466 ClassDefinition classDef = classObject.classDefinition;
4467 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4470 bool firstObject = true;
4471 ObjectInfo object = classObject.instances.first;
4472 bool lastIsDecl = false;
4474 if(!classObject.modified) continue;
4476 test = eInstance_New(regClass);
4479 // Put it in the same desktop window...
4480 designer.PrepareTestObject(test);
4482 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4483 //f.Printf("%c\n\n", OpenBracket);
4485 // Change the _class name
4486 f.Seek(classDef.nameLoc.start.pos - position, current);
4487 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4488 f.Printf(classObject.name);
4489 position = classDef.nameLoc.end.pos;
4492 // Go to block start, delete all until no white space, put \n
4496 f.Seek(classDef.blockStart.end.pos - position, current);
4497 position = classDef.blockStart.end.pos;
4499 for(; f.Getc(&ch); count++)
4503 f.Seek(-1, current);
4513 f.Seek(-count, current);
4515 f.DeleteBytes(count-back);
4517 position += count-back;
4520 // Output properties
4521 OutputClassProperties(classObject.instance._class, classObject, f, test);
4523 for(def = classDef.definitions->first; def; def = def.next)
4527 case defaultPropertiesClassDef:
4529 bool keptMember = false;
4531 MemberInit lastKept = null;
4534 DeleteJunkBefore(f, def.loc.start.pos, &position);
4537 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4539 Identifier ident = propDef.identifiers->first;
4540 bool deleted = false;
4542 // For now delete if it's a prop
4543 if(!propDef.variable && ident)
4547 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4550 f.Seek(propDef.loc.start.pos - position, current);
4551 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4552 position = propDef.loc.end.pos;
4557 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4558 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4560 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4561 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4563 f.Seek(propDef.loc.start.pos - position, current);
4564 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4565 position = propDef.loc.end.pos;
4583 f.Seek(def.loc.end.pos - position - 1, current);
4588 f.Seek(-1, current);
4591 position = def.loc.end.pos;
4595 if(lastKept != def.defProperties->last)
4600 f.Seek(-1, current);
4606 f.Seek(-1, current);
4609 else if(!isspace(ch))
4611 f.Seek(-2, current);
4616 f.DeleteBytes(count);
4620 f.Seek(def.loc.end.pos - position, current);
4621 position = def.loc.end.pos;
4626 case declarationClassDef:
4628 Declaration decl = def.decl;
4630 if(decl.type == instDeclaration)
4632 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4634 while(def.object && object != def.object)
4636 if(object /*&& ((ObjectInfo)def.object).modified*/)
4637 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4638 object = object.next;
4641 DeleteJunkBefore(f, def.loc.start.pos, &position);
4642 f.Printf(firstObject ? "\n\n " : "\n ");
4643 firstObject = false;
4645 if(def.object && ((ObjectInfo)def.object).modified)
4646 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4648 object = object ? object.next : null;
4652 DeleteJunkBefore(f, def.loc.start.pos, &position);
4653 f.Printf(firstObject ? "\n\n " : "\n ");
4654 firstObject = false;
4660 DeleteJunkBefore(f, def.loc.start.pos, &position);
4661 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4666 case functionClassDef:
4668 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4669 if(!def.function.body) continue;
4673 DeleteJunkBefore(f, def.loc.start.pos, &position);
4676 // Delete _class methods
4677 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4678 def.function == function)
4683 if(moveAttached && !text)
4685 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4688 f.Seek(def.loc.end.pos - position, current);
4689 for(; f.Getc(&ch); count++)
4693 f.Seek(-1, current);
4697 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4699 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4700 position = def.loc.end.pos + count;
4703 // In case of detaching methods in the _class, simply rename the method
4704 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4706 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4707 f.DeleteBytes(movedFuncIdLen);
4709 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4712 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4713 function == def.function)
4715 // In case of attaching methods in the _class, simply rename the method
4716 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4717 position = function.loc.start.pos + movedFuncIdPos;
4718 f.DeleteBytes(movedFuncIdLen);
4719 if(method.dataType.thisClass)
4720 f.Printf("%s::", method.dataType.thisClass.string);
4721 f.Puts(method.name);
4722 position += movedFuncIdLen;
4727 DeleteJunkBefore(f, def.loc.start.pos, &position);
4728 if(def.type == memberAccessClassDef)
4731 firstObject = false;
4741 f.Seek(def.loc.end.pos - position, current);
4742 position = def.loc.end.pos;
4745 // Output attached methods
4746 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4748 DeleteJunkBefore(f, position, &position);
4749 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4752 // ********** INSTANCES ***************
4753 for(; object; object = object.next)
4755 if(!object.instCode)
4757 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4761 DeleteJunkBefore(f, position, &position);
4763 // ****************** METHODS ***********************
4764 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4766 // If detaching an instance method
4767 if(selected != classObject)
4769 int newLen = strlen(methodName);
4772 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4773 // Tab selection left
4776 for(c = 0; text[c]; )
4779 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4780 memmove(text+start, text+start+i, textSize+1-start-i);
4783 for(; text[c] && text[c] != '\n'; c++);
4789 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4790 textSize += newLen - movedFuncIdLen;
4791 memcpy(text + movedFuncIdPos, methodName, newLen);
4798 if(methodAction == actionAddMethod && selected == classObject)
4800 Method method = this.method;
4802 if(!method.dataType)
4803 method.dataType = ProcessTypeString(method.dataTypeString, false);
4805 // ADDING METHOD HERE
4807 Type dataType = method.dataType;
4808 Type returnType = dataType.returnType;
4810 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4814 OutputType(f, returnType, false);
4817 if(dataType.thisClass && !dataType.classObjectType)
4819 if(dataType.thisClass.shortName)
4820 f.Printf(dataType.thisClass.shortName);
4822 f.Printf(dataType.thisClass.string);
4825 f.Printf(method.name);
4827 for(param = dataType.params.first; param; param = param.next)
4829 OutputType(f, param, true);
4834 f.Printf(" %c\n\n", OpenBracket);
4836 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4838 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4839 f.Printf(" return true;\n");
4840 else if(returnType && returnType.kind != voidType)
4841 f.Printf(" return 0;\n");
4846 if(returnType.kind != voidType)
4847 f.Printf("return ");
4849 char * name = ((Specifier)classDef.baseSpecs->first).name;
4850 Symbol _class = FindClass(name);
4851 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4853 for(param = dataType.params.first; param; param = param.next)
4855 if(param.prev) f.Printf(", ");
4856 if(param.kind != voidType)
4857 f.Printf(param.name);
4862 f.Printf(" %c", CloseBracket);
4866 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4878 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4879 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4883 codeModified = false;
4884 formModified = false;
4886 moveAttached = false;
4891 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4894 ClassFunction function = null;
4897 ObjectInfo object = this.selected;
4899 if(object && object == this.oClass)
4901 ClassDefinition classDef = object.oClass.classDefinition;
4903 if(classDef && classDef.definitions)
4905 for(def = classDef.definitions->first; def; def = def.next)
4907 if(def.type == functionClassDef && def.function.declarator)
4909 if(!strcmp(def.function.declarator.symbol.string, methodName))
4911 function = def.function;
4916 else if(def.type == defaultPropertiesClassDef)
4920 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4922 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4923 if(ident && !ident.next)
4925 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4929 propLoc = propDef.loc;
4932 ClassDefinition classDef = object.oClass.classDefinition;
4934 if(classDef.definitions)
4936 for(def = classDef.definitions->first; def; def = def.next)
4938 if(def.type == functionClassDef)
4940 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4942 function = def.function;
4961 Instantiation inst = object.instCode;
4963 // Check here to see if the method already exists, no need to call ModifyCode in that case
4964 if(inst && inst.members)
4966 MembersInit members;
4967 for(members = inst.members->first; members; members = members.next)
4969 switch(members.type)
4971 case dataMembersInit:
4973 if(members.dataMembers)
4976 for(member = members.dataMembers->first; member; member = member.next)
4978 Identifier ident = member.identifiers ? member.identifiers->first : null;
4979 if(ident && !ident.next)
4981 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4985 propLoc = member.loc;
4988 ClassDefinition classDef = object.oClass.classDefinition;
4990 if(classDef.definitions)
4992 for(def = classDef.definitions->first; def; def = def.next)
4994 if(def.type == functionClassDef)
4996 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
4998 function = def.function;
5007 // TODO: Fix memory leak
5008 function = ClassFunction
5010 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5022 case methodMembersInit:
5024 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5026 function = members.function;
5038 if(functionPtr) *functionPtr = function;
5042 void GoToMethod(char * methodName /*Method method*/)
5046 ObjectInfo object = selected;
5047 EditBoxStream f { editBox = editBox };
5048 ClassFunction function = null;
5049 bool atChar = false;
5053 Location propLoc = { {0,0,-1} };
5056 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5057 if(function && function.body)
5060 f.Seek(function.body.loc.start.pos+1, current);
5070 f.Seek(-1, current);
5075 else if(!isspace(ch))
5077 f.Seek(-1, current);
5083 else if(propLoc.start.pos > -1)
5085 f.Seek(propLoc.start.pos, current);
5088 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5090 if(function || propLoc.start.pos > -1)
5092 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5093 editBox.CenterOnCursor();
5094 SetState(normal, false, 0);
5097 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5099 FreeClassFunction(function);
5105 void FindCompatibleMethods(Method method, OldList compatible)
5107 ClassDefinition classDef = this.oClass.classDefinition;
5108 if(classDef && classDef.definitions)
5111 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5114 Symbol classSym { };
5115 Symbol selectedClass;
5116 if(this.selected == this.oClass)
5117 selectedClass = classSym;
5119 selectedClass = FindClass(this.selected.instance._class.name);
5121 regClass.name = classDef._class.name;
5122 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5123 for(def = classDef.definitions->first; def; def = def.next)
5125 if(def.type == functionClassDef && def.function.declarator)
5127 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5129 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5132 Type type = def.function.declarator.symbol.type;
5133 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5135 compatible.Add(OldLink { data = def.function });
5141 if(this.oClass && this.oClass.instance)
5143 classSym.registered = regClass;
5144 //classSym.registered = this.oClass.oClass;
5146 for(_class = regClass.base; _class; _class = _class.base)
5149 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5151 // TODO: Understand why these functions popup in attach list
5152 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5154 if(!testMethod.dataType)
5155 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5157 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5158 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5159 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5161 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5162 // ClassFunction function { };
5163 FunctionDefinition function { };
5165 function.declarator = Declarator { };
5166 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5167 excludedSymbols.Add(function.declarator.symbol);
5169 compatible.Add(OldLink { data = function });
5180 void AddMethod(Method method)
5184 char methodName[1024];
5185 strcpy(methodName, method.name);
5186 if(!FindMethod(methodName, null, null))
5188 methodAction = actionAddMethod;
5189 this.method = method;
5193 GoToMethod(methodName);
5197 void DeleteMethod(ClassFunction function)
5201 methodAction = actionDeleteMethod;
5202 this.function = function;
5210 void AttachMethod(Method method, ClassFunction function)
5214 // If it's an instance we'll ask if we want to move it inside...
5215 if(!function.attached.count && function.body)
5217 // Find the function in the _class to check if it's a virtual function
5218 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5219 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5220 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5222 for(def = this.classDefinition.first; def; def = def.next)
5224 if(def.type == functionClassDef)
5226 if(def.function == function)
5231 if(!method || method.type != virtualMethod)
5234 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5235 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5237 moveAttached = true;
5242 methodAction = actionAttachMethod;
5243 this.method = method;
5244 this.function = function;
5251 void ReAttachMethod(Method method, ClassFunction function)
5255 // If it's an instance we'll ask if we want to move it inside...
5256 if(!function.attached.count && function.body)
5258 // Find the function in the _class to check if it's a virtual function
5259 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5260 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5261 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5263 for(def = this.classDefinition.first; def; def = def.next)
5265 if(def.type == functionClassDef)
5267 if(def.function == function)
5272 if(!method || method.type != virtualMethod)
5275 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5276 if(MessageBox { type = yesNo, master = parent, text = title,
5277 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5279 moveAttached = true;
5284 methodAction = actionReattachMethod;
5285 this.method = method;
5286 this.function = function;
5293 void DetachMethod(Method method, ClassFunction function, int type)
5301 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5302 master = sheet, text = $"Name detached method", background = formColor
5306 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5307 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5311 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5312 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5316 dialog, anchor = { left = 5, right = 5, top = 5 }
5318 sprintf(methodName, "%s_%s", selected.name, method.name);
5319 nameBox.contents = methodName;
5321 result = dialog.Modal() == ok;
5322 strcpy(methodName, nameBox.contents);
5327 // If the method is not attached, move it outside
5330 // Add this class to the methodName
5331 char name[1024] = "";
5333 if(this.selected != this.oClass && !method.dataType.thisClass)
5335 strcat(name, this.selected.instance._class.name);
5337 strcat(name, this.methodName);
5338 strcpy(this.methodName, name);
5340 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5342 strcat(name, method.dataType.thisClass.string);
5344 strcat(name, this.methodName);
5345 strcpy(this.methodName, name);
5348 this.moveAttached = true;
5351 this.methodAction = actionDetachMethod;
5352 this.method = method;
5353 this.function = function;
5360 void AddObject(Instance instance, ObjectInfo * object)
5364 //*object = _class.instances.Add(sizeof(ObjectInfo));
5365 *object = ObjectInfo { };
5366 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5367 (*object).oClass = oClass;
5368 (*object).instance = instance;
5373 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5375 // if(strcmp(name, this.oClass.instance.name))
5378 for(check = oClass.instances.first; check; check = check.next)
5379 if(!check.deleted && check.name && !strcmp(name, check.name))
5383 (*object).name = CopyString(name);
5388 toolBox.controlClass = null;
5392 //sheet.AddObject(*object, (*object).name, TypeData, true);
5397 void EnsureUpToDate()
5399 if(sheet && codeModified && parsing)
5403 void SelectObject(ObjectInfo object)
5406 oClass = object ? object.oClass : null;
5408 designer.SelectObject(object, object ? object.instance : null);
5411 void SelectObjectFromDesigner(ObjectInfo object)
5414 sheet.SelectObject(object);
5417 void EnumerateObjects(Sheet sheet)
5421 for(oClass = classes.first; oClass; oClass = oClass.next)
5427 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5428 for(object = oClass.instances.first; object; object = object.next)
5429 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5432 sheet.SelectObject(selected);
5437 designer.AddObject();
5440 void DeleteObject(ObjectInfo object)
5442 delete object.instance;
5443 object.deleted = true;
5444 object.modified = true;
5445 object.oClass.modified = true;
5447 if(selected == object)
5449 bool looped = false;
5450 ObjectInfo select = object;
5454 select = select.prev;
5458 select = object.oClass.instances.last;
5465 sheet.SelectObject(select ? select : oClass);
5468 if(!object.instCode && object.oClass != object)
5471 oClass.instances.Delete(object);
5474 if(sheet.codeEditor == this)
5475 sheet.DeleteObject(object);
5478 void RenameObject(ObjectInfo object, char * name)
5482 // Validate the name:
5483 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5484 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5487 for(c = 0; name[c]; c++)
5488 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5496 object.name = (name && name[0]) ? CopyString(name) : null;
5498 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5502 void DesignerModifiedObject()
5504 sheet.ListProperties(false);
5508 void ListSubMembers(Type member)
5512 for(subMember = member.members.first; subMember; subMember = subMember.next)
5516 DataRow row = membersList.AddString(subMember.name);
5517 row.icon = icons[typeData];
5521 ListSubMembers(subMember);
5526 void ListSubDataMembers(DataMember member, bool isPrivate)
5528 DataMember subMember;
5529 for(subMember = member.members.first; subMember; subMember = subMember.next)
5531 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5535 DataRow row = membersList.AddString(subMember.name);
5536 BitmapResource bitmap = null;
5537 if(!subMember.dataType)
5538 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5540 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5542 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5545 bitmap = { bitmapName };
5546 membersList.AddResource(bitmap);
5549 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5553 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5559 void ListClassMembers(Class whatClass, bool methodsOnly)
5562 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5563 bool isPrivate = false;
5565 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5567 Method method, methodIt;
5569 DataMember memberIt;
5571 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5573 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5574 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5576 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5578 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5580 DataRow row = membersList.FindString(method.name);
5583 row = membersList.AddString(method.name);
5585 if(!method.dataType)
5586 method.dataType = ProcessTypeString(method.dataTypeString, false);
5588 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5596 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5600 if(memberIt.isProperty)
5602 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5604 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5608 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5610 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5613 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5619 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5621 if(member.isProperty)
5623 Property prop = (Property) member;
5624 if(!membersList.FindString(prop.name))
5626 DataRow row = membersList.AddString(prop.name);
5627 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5630 else if(member.name && !membersList.FindString(member.name))
5632 DataRow row = membersList.AddString(member.name);
5634 BitmapResource bitmap = null;
5635 if(!member.dataType)
5636 member.dataType = ProcessTypeString(member.dataTypeString, false);
5638 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5640 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5643 bitmap = { bitmapName };
5644 membersList.AddResource(bitmap);
5647 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5650 ListSubDataMembers(member, member.memberAccess == privateAccess);
5654 if(_class.inheritanceAccess == privateAccess)
5657 if(_class.module != privateModule) break;
5662 void ListClassMembersMatch(Class whatClass, Type methodType)
5665 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5666 bool isPrivate = false;
5668 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5674 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5676 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5678 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5680 if(!method.dataType)
5681 method.dataType = ProcessTypeString(method.dataTypeString, false);
5683 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5685 DataRow row = membersList.FindString(method.name);
5688 row = membersList.AddString(method.name);
5689 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5695 if(_class.inheritanceAccess == privateAccess)
5698 if(_class.module != privateModule) break;
5703 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5706 bool isPrivate = false;
5707 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5713 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5715 if(method.type == virtualMethod)
5717 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5719 DataRow row = membersList.FindString(method.name);
5722 row = membersList.AddString(method.name);
5724 if(!method.dataType)
5725 method.dataType = ProcessTypeString(method.dataTypeString, false);
5727 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5733 for(member = _class.membersAndProperties.first; member; member = member.next)
5735 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5737 if(member.isProperty)
5739 Property prop = (Property)member;
5741 DataRow row = membersList.AddString(prop.name);
5742 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5745 else if(member.name && (!curString || strcmp(curString, member.name)))
5747 DataRow row = membersList.AddString(member.name);
5749 BitmapResource bitmap = null;
5750 if(!member.dataType)
5751 member.dataType = ProcessTypeString(member.dataTypeString, false);
5753 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5755 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5758 bitmap = { bitmapName };
5759 membersList.AddResource(bitmap);
5762 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5765 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5768 if(_class.inheritanceAccess == privateAccess)
5771 if(_class.module != privateModule) break;
5776 void ListMembers(Type type)
5778 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5782 if(type.kind == classType)
5785 ListClassMembers(type._class.registered, false);
5790 for(member = type.members.first; member; member = member.next)
5794 DataRow row = membersList.AddString(member.name);
5795 row.icon = icons[typeData];
5797 else if(member.kind == structType || member.kind == unionType)
5798 ListSubMembers(member);
5804 void ListModule(Module mainModule, int recurse, bool listClasses)
5807 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5808 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5809 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5810 for(module = mainModule.application.allModules.first; module; module = module.next)
5812 if(ModuleVisibility(mainModule, module))
5813 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5817 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5824 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5826 Class _class = link.data;
5827 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5829 DataRow row = membersList.AddString(_class.name);
5830 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5835 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5837 DefinedExpression definedExp = link.data;
5838 DataRow row = membersList.AddString(link /*definedExp*/.name);
5839 row.icon = icons[typeData];
5842 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5844 GlobalFunction function = link.data;
5845 DataRow row = membersList.AddString(link /*function*/.name);
5846 row.icon = icons[typeMethod];
5850 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5852 if(recurse != 2 && listClasses)
5854 if(!membersList.FindString(ns->name))
5856 DataRow row = membersList.AddString(ns->name);
5857 row.icon = icons[typeNameSpace];
5862 ListNameSpace(ns, 2, listClasses);
5866 void ListEnumValues(Class _class)
5868 List<Class> classes { };
5869 for(; _class && _class.type == enumClass; _class = _class.base)
5870 classes.Insert(null, _class);
5871 for(_class : classes)
5873 EnumClassData enumeration = (EnumClassData)_class.data;
5875 for(item = enumeration.values.first; item; item = item.next)
5877 DataRow row = membersList.AddString(item.name);
5878 row.icon = icons[typeEnumValue];
5884 bool ListEnumsModule(Module mainModule, Type dest)
5886 bool result = false;
5888 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5889 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5890 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5891 for(module = mainModule.application.allModules.first; module; module = module.next)
5893 if(ModuleVisibility(mainModule, module))
5894 result |= ListEnums(module.publicNameSpace, dest);
5899 void ListNameSpaceByString(Module mainModule, char * string)
5901 NameSpace * nameSpace;
5903 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5904 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5905 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5906 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5907 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5908 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5909 for(module = mainModule.application.allModules.first; module; module = module.next)
5911 if(ModuleVisibility(mainModule, module))
5913 nameSpace = FindNameSpace(module.publicNameSpace, string);
5914 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5919 bool ListEnums(NameSpace nameSpace, Type dest)
5922 bool result = false;
5924 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5926 Class _class = link.data;
5927 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *"))) && !dest.classObjectType)) &&
5928 dest.kind != pointerType && dest.kind != ellipsisType)
5930 OldList conversions { };
5932 type.kind = classType;
5933 type._class = FindClass(_class.name);
5934 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5936 ListEnumValues(_class);
5939 conversions.Free(null);
5943 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5945 result |= ListEnums(nameSpace, dest);
5950 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5954 for(c = 0; (ch = name[c]); c++)
5956 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5958 NameSpace * newSpace;
5959 char * spaceName = new char[c - start + 1];
5960 memcpy(spaceName, name + start, c - start);
5961 spaceName[c-start] = '\0';
5962 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5966 nameSpace = newSpace;
5975 return (NameSpace *)nameSpace;
5978 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5980 bool listedEnums = false;
5981 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5982 bool listClasses = true;
5984 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5986 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5987 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5988 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5990 if(exp.type == identifierExp)
5991 id = realIdentifier;
5993 if(id && id._class && !id._class.name)
5995 listClasses = false;
5998 else if(id && id._class && id._class.name)
6002 Class _class = id.classSym.registered;
6003 if(_class && _class.type == enumClass)
6005 ListEnumValues(_class);
6008 ListClassMembers(id.classSym.registered, true);
6013 else if(id && colons)
6015 ListNameSpaceByString(this.privateModule, id.string);
6020 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6022 listedEnums = ListEnumsModule(this.privateModule, destType);
6025 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6027 ListEnumValues(destType._class.registered);
6030 ListClassPropertiesAndVirtual(insideClass, null);
6034 else if(destType && destType.kind == enumType)
6038 for(value = destType.members.first; value; value = value.next)
6040 DataRow row = membersList.AddString(value.name);
6041 row.icon = icons[typeEnumValue];
6045 ListClassPropertiesAndVirtual(insideClass, null);
6049 else if(insideClass && !enumOnly)
6051 ListClassPropertiesAndVirtual(insideClass, string);
6054 if(listedEnums && string && string[0])
6056 DataRow row = membersList.FindSubString(string);
6058 listedEnums = false;
6061 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6063 ListClassMembersMatch(GetThisClass(), exp.destType);
6065 else if(!insideClass && !enumOnly && !listedEnums)
6068 Symbol symbol = null;
6072 ListClassMembers(GetThisClass(), false);
6075 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6077 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6079 // Don't list enum values?
6080 //if(symbol.type.kind != TypeEnum)
6081 DataRow row = membersList.FindString(symbol.string);
6084 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6086 row = membersList.AddString(symbol.string);
6087 if(symbol.type && symbol.type.kind == functionType)
6088 row.icon = icons[typeMethod];
6089 else if(symbol.type && symbol.type.kind == enumType)
6091 row.icon = icons[typeEnumValue];
6095 BitmapResource bitmap = null;
6096 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6098 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6101 bitmap = { bitmapName };
6102 membersList.AddResource(bitmap);
6105 row.icon = bitmap ? bitmap : icons[typeData];
6112 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6114 DataRow row = membersList.FindString(symbol.string);
6117 row = membersList.AddString(symbol.string);
6118 if(symbol.type.kind == functionType)
6119 row.icon = icons[typeMethod];
6120 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6122 row.icon = icons[typeClass];
6126 row.icon = icons[typeDataType];
6133 ListModule(this.privateModule, 1, listClasses);
6134 // TODO: Implement this with name space
6138 for(data = globalData.first; data; data = data.next)
6140 DataRow row = membersList.FindString(data.name);
6142 data.dataType = ProcessTypeString(data.dataTypeString, false);
6145 row = membersList.AddString(data.name);
6147 if(data.dataType && data.dataType.kind == TypeEnum)
6149 row.icon = icons[typeEnumValue];
6153 BitmapResource bitmap = null;
6154 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6156 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6159 bitmap = { bitmapName };
6160 membersList.AddResource(bitmap);
6163 row.icon = bitmap ? bitmap : icons[typeData];
6171 DataRow row = membersList.AddString("Min");
6172 row.icon = icons[typeMethod];
6174 row = membersList.AddString("Max");
6175 row.icon = icons[typeMethod];
6177 row = membersList.AddString("Abs");
6178 row.icon = icons[typeMethod];
6180 row = membersList.AddString("Sgn");
6181 row.icon = icons[typeMethod];
6187 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6189 EditBoxStream f { editBox = editBox };
6194 updatingCode = true;
6196 if(!method.dataType)
6197 method.dataType = ProcessTypeString(method.dataTypeString, false);
6199 DeleteJunkBefore(f, function.loc.start.pos, &position);
6200 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6202 // ADDING METHOD HERE
6204 Type dataType = method.dataType;
6205 Type returnType = dataType.returnType;
6207 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6213 if(extraIndent) f.Printf(" ");
6215 OutputType(f, returnType, false);
6219 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6221 if(dataType.thisClass.shortName)
6222 f.Printf(dataType.thisClass.shortName);
6224 f.Printf(dataType.thisClass.string);
6227 f.Printf(method.name);
6229 for(param = dataType.params.first; param; param = param.next)
6231 // Decided not to write void...
6232 if(param.kind != voidType)
6234 OutputType(f, param, true);
6240 if(extraIndent) f.Printf(" ");
6241 f.Printf(" %c\n", OpenBracket);
6243 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6249 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6250 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6252 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6254 if(extraIndent) f.Printf(" ");
6255 f.Printf(" return true;\n");
6257 else if(returnType && returnType.kind != voidType)
6259 if(extraIndent) f.Printf(" ");
6260 f.Printf(" return 0;\n");
6265 if(extraIndent) f.Printf(" ");
6267 if(returnType.kind != voidType)
6268 f.Printf("return ");
6269 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6270 for(param = dataType.params.first; param; param = param.next)
6272 if(param.prev) f.Printf(", ");
6273 if(param.kind != voidType)
6274 f.Printf(param.name);
6280 if(extraIndent) f.Printf(" ");
6281 f.Printf(" %c", CloseBracket);
6286 if(extraIndent) { x1 += 3; x2 += 3; }
6287 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6289 this.updatingCode = false;
6293 // Return false if we overrided a function and don't want to run params listing
6294 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6296 bool didOverride = false;
6297 EditLine line = editBox.line;
6298 char * text = line.text;
6299 int lineNum, charPos;
6300 Expression exp = null;
6303 //Identifier id = null;
6304 Expression memberExp = null;
6305 Identifier realIdentifier = null;
6307 if(!parsing) return true;
6308 if(!privateModule) return !didOverride;
6310 insideFunction = null;
6312 charPos = editBox.charPos + 1;
6313 if(!membersListShown)
6318 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6320 EditBoxStream f { editBox = editBox };
6322 updatingCode = true;
6323 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6327 if(!f.Seek(-1, current))
6330 if(!isspace(ch)) break;
6331 f.Seek(-1, current);
6333 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6335 lineNum = editBox.lineNumber + 1;
6336 charPos = editBox.charPos + 1;
6338 updatingCode = false;
6341 if(!membersListShown)
6343 memberExp = FindExpTree(ast, lineNum, charPos);
6344 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6349 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6351 EditBoxStream f { editBox = editBox };
6354 updatingCode = true;
6356 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6359 if(ch == '}' || ch == ',' || ch == ')')
6361 f.Seek(-1, current);
6369 if(!f.Seek(-1, current))
6372 if(!isspace(ch)) break;
6373 f.Seek(-1, current);
6377 f.Seek(-1, current);
6379 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6381 lineNum = editBox.lineNumber + 1;
6382 charPos = editBox.charPos + 1;
6384 updatingCode = false;
6387 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6392 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6393 lineNum = editBox.lineNumber + 1;
6394 charPos = editBox.charPos/* + 1*/;
6398 char tempString[1024];
6399 char * string = null;
6400 CodePosition idStart, idEnd;
6402 if(membersListShown)
6404 char * buffer = membersLine.text;
6406 bool firstChar = true;
6408 string = tempString;
6410 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6412 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6413 if(!isSpace) firstChar = false;
6415 string[len++] = buffer[c];
6419 else //if(realIdentifier)//if(id)
6422 char * buffer = id.string;
6424 bool firstChar = true;
6426 string = tempString;
6427 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6429 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6430 if(!isSpace) firstChar = false;
6432 string[len++] = buffer[c];
6438 EditLine editLine = editBox.line;
6439 bool firstChar = true;
6442 string = tempString;
6443 for(y = lineNum-1; y >= 0; y--)
6445 char * buffer = editLine.text;
6446 int lineCount = editLine.count;
6447 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6449 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6454 idEnd.charPos = x + 2;
6459 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6462 idEnd.charPos = x + 2;
6469 if(!isalnum(buffer[x]) && buffer[x] != '_')
6475 memmove(string+1, string, len++);
6476 string[0] = buffer[x];
6480 //if(done || firstChar)
6481 if(done || !firstChar)
6483 editLine = editLine.prev;
6486 if(!strcmp(string, "case"))
6492 else if(!strcmp(string, "return"))
6498 else if(!strcmp(string, "delete"))
6504 else if(!strcmp(string, "new"))
6510 else if(!strcmp(string, "renew"))
6518 idStart.charPos = x + 1;
6519 idStart.line = y + 1;
6522 if(!membersListShown)
6524 membersList.Clear();
6525 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6527 Type type = memberExp.member.exp.expType;
6528 if(pointer == 2 && type)
6530 if(type.kind == pointerType || type.kind == arrayType)
6539 ListSymbols(exp, enumOnly, string, realIdentifier);
6541 membersList.Sort(null, 1);
6546 // Virtual function override
6547 Identifier id = GetDeclId(insideFunction.declarator);
6548 char * string = id ? id.string : null;
6550 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6553 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6554 insideFunction = null;
6557 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6562 if(!didOverride) //insideFunction)
6564 rowCount = membersList.rowCount;
6567 DataRow row = string ? membersList.FindSubString(string) : null;
6568 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6570 char * newString = row.string;
6571 if(!membersListShown)
6573 membersLoc.start.line = idStart.line-1;
6574 membersLoc.start.charPos = idStart.charPos-1;
6575 //membersLoc.end = membersLoc.start;
6576 membersLoc.end.charPos = idEnd.charPos-1;
6577 membersLoc.end.line = idEnd.line-1;
6578 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6579 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6584 membersList.Destroy(0);
6585 membersListShown = false;
6588 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6590 line, membersLoc.start.line, membersLoc.start.charPos,
6591 line, membersLoc.end.line, membersLoc.end.charPos);
6592 editBox.PutS(newString);
6598 row = membersList.FindSubStringi(string);
6600 membersList.currentRow = row;
6601 membersList.currentRow.selected = false;
6604 membersList.currentRow = row;
6606 if(!membersListShown)
6610 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6611 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6612 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6613 editBox.GetCaretPosition(caret);
6614 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6616 membersList.master = this;
6618 caret.y += editBox.GetCaretSize();
6620 membersList.Create();
6623 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6624 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6625 Window parent = membersList.parent;
6627 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6629 y -= editBox.GetCaretSize() + membersList.size.h;
6630 membersAbove = true;
6633 membersAbove = false;
6635 membersList.position = { x, y };
6639 membersLoc.start.line = lineNum - 1;
6641 if(string && string[0])
6643 membersLoc.start.charPos = idStart.charPos-1;
6644 membersLoc.end = membersLoc.start;
6645 //membersLoc.end.charPos = id.loc.end.charPos-1;
6646 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6650 membersLoc.start.charPos = charPos;
6651 membersLoc.end = membersLoc.start;
6652 membersLoc.end.charPos = charPos;
6654 membersListShown = true;
6656 // Hack to keep caret shown
6657 editBox.GetCaretPosition(caret);
6658 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6661 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6667 SetCurrentContext(globalContext);
6670 return !didOverride;
6673 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6675 EditLine line = editBox.line;
6676 char * text = line.text;
6677 int lineNum, charPos;
6678 Expression exp = null;
6682 if(!parsing) return;
6684 charPos = editBox.charPos + 1;
6687 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6689 EditBoxStream f { editBox = editBox };
6692 updatingCode = true;
6693 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6696 if(ch == '}' || ch == ',' || ch == ')')
6698 f.Seek(-1, current);
6706 if(!f.Seek(-1, current))
6709 if(!isspace(ch)) break;
6710 f.Seek(-1, current);
6714 f.Seek(-1, current);
6716 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6718 lineNum = editBox.lineNumber + 1;
6719 charPos = editBox.charPos + 1;
6721 updatingCode = false;
6724 charPos = Min(charPos, l1.count + 1);
6726 FindParamsTree(ast, lineNum, charPos);
6728 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6729 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6731 ::functionType = null;
6732 ::instanceType = null;
6735 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6736 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6740 Window parent = paramsList.parent;
6742 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6745 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6746 // ( Dummy exp: always ends up with same memory)
6748 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6749 editBox.GetCaretPosition(paramsPosition);
6750 this.paramsPosition.y += editBox.GetCaretSize();
6753 FreeType(this.functionType);
6754 FreeType(this.instanceType);
6756 this.functionType = ::functionType;
6757 this.instanceType = ::instanceType;
6759 if(this.functionType) this.functionType.refCount++;
6760 if(this.instanceType) this.instanceType.refCount++;
6762 this.paramsID = ::paramsID;
6763 functionExp = paramsInsideExp;
6765 paramsList.master = this;
6767 paramsList.Create();
6769 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6770 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6772 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6774 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6778 paramsAbove = false;
6779 if(x + paramsList.size.w > parent.clientSize.w)
6781 x = parent.clientSize.w - paramsList.size.w;
6785 paramsList.position = { x, y };
6787 // Hack to keep caret shown
6790 editBox.GetCaretPosition(caret);
6791 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6794 this.paramsShown = true;
6796 else if((!::functionType && !::instanceType) || reposition)
6798 paramsList.Destroy(0);
6799 paramsShown = false;
6801 FreeType(this.functionType);
6802 FreeType(this.instanceType);
6803 this.functionType = null;
6804 this.instanceType = null;
6808 SetCurrentContext(globalContext);
6816 designer.visible = true;
6817 designer.Activate();
6823 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6825 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };
6830 static int nofdigits(int v)
6832 if(v == MININT) return 10 + 1;
6833 if(v < 0) return nofdigits(-v) + 1;