3 // *** Color Schemes ***
5 // *** The Old Color Scheme that was causing me auras and ophtalmic migraines -- Uncomment at your own risk! ***
7 FontResource panelFont { $"Courier New", 10 };
8 FontResource codeFont { $"Courier New", 10 };
9 Color selectionColor = Color { 10, 36, 106 };
10 Color selectionText = white;
11 Color viewsBackground = white;
12 Color viewsText = black;
13 Color outputBackground = white;
14 Color outputText = black;
15 Color projectViewBackground = white;
16 Color projectViewText = black;
17 Color codeEditorBG = white;
18 Color codeEditorFG = black;
19 Color marginColor = Color {230, 230, 230};
20 Color selectedMarginColor = Color {200, 200, 200};
21 Color lineNumbersColor = Color {60, 60, 60};
22 SyntaxColorScheme colorScheme
24 keywordColors = [ blue, blue ];
25 commentColor = dimGray;
26 charLiteralColor = crimson;
27 stringLiteralColor = crimson;
28 preprocessorColor = green;
33 // The new nice dark scheme -- so peaceful on my brain
35 FontResource panelFont { $"Courier New", 10 };
36 FontResource codeFont { $"Courier New", 10 };
38 FontResource panelFont { $"Consolas", 12 };
39 FontResource codeFont { $"Consolas", 12 };
41 Color selectionColor = lightYellow;
42 Color selectionText = Color { 30, 40, 50 };
43 Color viewsBackground = Color { 30, 40, 50 };
44 Color viewsText = lightGray;
45 Color outputBackground = black;
46 Color outputText = lime;
47 Color projectViewBackground = Color { 30, 40, 50 };
48 Color projectViewText = lightGray;
49 Color codeEditorBG = black;
50 Color codeEditorFG = ivory;
51 Color marginColor = Color {24, 24, 24};
52 Color selectedMarginColor = Color {64, 64, 64};
53 Color lineNumbersColor = Color {160, 160, 160};
54 SyntaxColorScheme colorScheme
56 keywordColors = [ skyBlue, skyBlue ];
57 commentColor = Color { 125, 125, 125 };
58 charLiteralColor = Color { 245, 50, 245 };
59 stringLiteralColor = Color { 245, 50, 245 };
60 preprocessorColor = { 120, 220, 140 };
61 numberColor = Color { 0, 192, 192 };
64 // *********************
70 // UNTIL IMPLEMENTED IN GRAMMAR
71 #define ACCESS_CLASSDATA(_class, baseClass) \
72 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
75 extern int __attribute__((__stdcall__)) __ecereDll_Load_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
76 extern int __attribute__((__stdcall__)) __ecereDll_Unload_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
79 static Array<FileFilter> fileFilters
81 { $"C/C++/eC Files (*.ec, *.eh, *.c, *.cpp, *.cc, *.cxx, *.h, *.hpp, *.hh, *.hxx)", "ec, eh, c, cpp, cc, cxx, h, hpp, hh, hxx" },
82 { $"Header Files for C/C++ (*.eh, *.h, *.hpp, *.hh, *.hxx)", "eh, h, hpp, hh, hxx" },
83 { $"C/C++/eC Source Files (*.ec, *.c, *.cpp, *.cc, *.cxx)", "ec, c, cpp, cc, cxx" },
84 { $"Text files (*.txt)", "txt" },
85 { $"All files", null }
88 static Array<FileType> fileTypes
90 { $"eC Source Code", "ec", whenNoneGiven },
91 { $"Text Files", "txt", never }
94 static char * iconNames[] =
96 "<:ecere>constructs/class.png",
97 "<:ecere>constructs/data.png",
98 "<:ecere>constructs/method.png",
99 "<:ecere>constructs/event.png",
100 "<:ecere>constructs/property.png",
101 "<:ecere>constructs/namespace.png",
102 "<:ecere>constructs/dataType.png",
103 "<:ecere>constructs/enumValue.png",
104 "<:ecere>constructs/dataPrivate.png",
105 "<:ecere>constructs/methodPrivate.png",
106 "<:ecere>constructs/propertyPrivate.png"
109 enum SheetType { methods, properties };
111 extern int __ecereVMethodID_class_OnEdit;
112 extern int __ecereVMethodID_class_OnDisplay;
113 extern int __ecereVMethodID_class_OnGetString;
114 extern int __ecereVMethodID_class_OnFree;
115 extern int __ecereVMethodID_class_OnCompare;
116 extern int __ecereVMethodID_class_OnCopy;
117 extern int __ecereVMethodID_class_OnSaveEdit;
118 extern int __ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad;
123 bool ignoreBreakpoints:1;
125 bool oldImplementation:1;
128 class EditFileDialog : FileDialog
132 if(!ide.projectView && ideSettings.ideFileDialogLocation)
133 currentDirectory = ideSettings.ideFileDialogLocation;
134 return FileDialog::OnCreate();
138 EditFileDialog codeEditorFileDialog
140 type = multiOpen, text = $"Open",
141 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType);
142 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
145 EditFileDialog codeEditorFormFileDialog
147 type = open, text = $"Open Project",
148 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType),
149 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
152 define OpenBracket = '{';
153 define CloseBracket = '}';
158 actionDeleteMethod = 2,
159 actionDetachMethod = 3,
160 actionAttachMethod = 4,
161 actionReattachMethod = 5
164 //extern StatusField pos, ovr, caps, num;
165 //extern Class thisClass;
171 bool parseError = false;
176 Expression ctxInsideExp;
177 Expression paramsInsideExp;
178 ClassFunction insideFunction;
186 /****************************************************************************
188 ****************************************************************************/
190 static void OutputString(File f, char * string)
193 for(c = 0; string[c]; c++)
195 if(string[c] == '\"')
197 else if(string[c] == '\\')
204 void OutputType(File f, Type type, bool outputName)
214 if(!type.isSigned) f.Printf("unsigned ");
218 if(!type.isSigned) f.Printf("unsigned ");
222 if(!type.isSigned) f.Printf("unsigned ");
226 if(!type.isSigned) f.Printf("unsigned ");
230 if(!type.isSigned) f.Printf("unsigned ");
241 if(type._class && !strcmp(type._class.string, "class"))
243 switch(type.classObjectType)
246 f.Printf("any_object");
249 f.Printf("typed_object");
256 // ADD CODE TO DECIDE WHETHER TO OUTPUT FULLY QUAlIFIED OR NOT:
257 f.Printf(type._class.shortName ? type._class.shortName : type._class.string);
267 OutputType(f, type.type, false);
270 OutputType(f, type.type, false);
289 if(type.kind == arrayType)
292 f.Printf("%d", type.arraySize);
298 void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
304 f.Seek(pos - *position, current);
306 // Try to delete spaces and \n before...
312 /*else if(ch == '\n')
314 // Look for // comments on the line before
315 EditBox editBox = f.editBox;
316 EditLine line = editBox.line;
323 for(c = 0; text[c]; c++)
332 if(text[c] == '/' && last == '/')
344 f.DeleteBytes(before);
349 void GetLocText(EditBox editBox, File f, int position, Location loc, char ** text, int * size, int pad, int linePad)
354 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
356 // Cut & Paste function
362 f.Seek(loc.start.pos - position, current);
364 x1 = editBox.charPos;
365 y1 = editBox.lineNumber;
366 f.Seek(loc.end.pos - loc.start.pos, current);
368 x2 = editBox.charPos;
369 y2 = editBox.lineNumber;
370 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
372 *size = editBox.SelSize();
373 *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
374 editBox.GetSel(*text, false);
377 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
378 f.Printf(""); // Make the stream point to where the editbox is
381 void Code_FixProperty(Property prop, Instance object)
383 Designer::FixProperty(prop, object);
386 bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
389 if(prop.dataTypeString && (!prop.IsSet || prop.IsSet(selected.instance)))
391 Class dataType = prop.dataTypeClass;
394 dataType = prop.dataTypeClass = eSystem_FindClass(test._class.module, prop.dataTypeString);
396 if(dataType && dataType._vTbl && dataType.type == structClass)
398 void * dataForm = new0 byte[dataType.structSize];
399 void * dataTest = new0 byte[dataType.structSize];
401 ((void (*)(void *, void *))(void *)prop.Get)(selected.instance, dataForm);
402 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
404 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
406 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
412 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
414 void * dataForm, * dataTest;
416 dataForm = ((void *(*)(void *))(void *)prop.Get)(selected.instance);
417 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
419 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
421 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
425 else if(dataType && dataType._vTbl)
427 DataValue dataForm, dataTest;
429 GetProperty(prop, selected.instance, &dataForm);
430 GetProperty(prop, test, &dataTest);
432 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
434 SetProperty(prop, test, dataForm);
436 // In case setting on test unset on real instance (e.g. isDefault)
437 if(strcmp(prop.name, "name"))
439 GetProperty(prop, selected.instance, &dataTest);
440 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
441 SetProperty(prop, selected.instance, dataForm);
450 bool Code_IsPropertyDisabled(ObjectInfo selected, char * name)
452 bool disabled = false;
453 if(selected.oClass == selected)
456 if(selected.classDefinition)
458 for(def = selected.classDefinition.definitions->first; def; def = def.next)
460 if(def.type == defaultPropertiesClassDef)
463 for(prop = def.defProperties->first; prop; prop = prop.next)
465 if(prop.identifiers && prop.identifiers->first)
467 Identifier id = prop.identifiers->first;
468 if(prop.variable && !strcmp(id.string, name))
480 else if(selected.instCode)
483 if(selected.instCode.members)
485 for(members = selected.instCode.members->first; members; members = members.next)
487 if(members.type == dataMembersInit && members.dataMembers)
490 for(prop = members.dataMembers->first; prop; prop = prop.next)
492 if(prop.identifiers && prop.identifiers->first)
494 Identifier id = prop.identifiers->first;
495 if(prop.variable && !strcmp(id.string, name))
510 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
515 method.dataType = ProcessTypeString(method.dataTypeString, false);
516 if(!method.dataType.thisClass && !isForm)
519 method.dataType.thisClass = selectedClass;
521 //result = MatchTypes(method.dataType, type, null, regClass, regClass, false);
522 result = MatchTypes(type, method.dataType, null, regClass, regClass, false, true, true, false);
524 method.dataType.thisClass = null;
528 bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo object)
530 bool confirmation = true;
531 Statement body = function.body;
532 // Check if it contains any code
533 if((!body.compound.declarations || !body.compound.declarations->count) && (!body.compound.statements || body.compound.statements->count <= 1))
535 Class moduleClass = eSystem_FindClass(object.instance._class.module, "Module");
536 Statement stmt = body.compound.statements ? body.compound.statements->first : null;
537 Type dataType = method.dataType;
538 Type returnType = dataType.returnType;
539 Expression exp = null;
542 method.dataType = ProcessTypeString(method.dataTypeString, false);
544 confirmation = false;
546 // Check if default function should be calling base class:
547 if(object.instance._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
549 if(returnType.kind != voidType)
551 if(!stmt || stmt.type != returnStmt || !stmt.expressions || stmt.expressions->count != 1)
555 exp = stmt.expressions->first;
556 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
558 if( (exp.type != identifierExp || strcmp(exp.identifier.string, "true")) &&
559 (exp.type != constantExp || strcmp(exp.constant, "1")))
564 if(exp.type != constantExp || strcmp(exp.constant, "0"))
579 if(returnType.kind != voidType)
581 if(stmt.type == returnStmt && stmt.expressions && stmt.expressions->count == 1)
582 exp = stmt.expressions->first;
584 else if(stmt.type == expressionStmt && stmt.expressions && stmt.expressions->count == 1)
585 exp = stmt.expressions->first;
588 if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
592 Identifier id = exp.call.exp.identifier;
593 Class base = object.instance._class;
594 if(!id._class || (id._class.name && !strcmp(id._class.name, base.name)) || strcmp(id.string, method.name))
598 Expression arg = exp.call.arguments ? exp.call.arguments->first : null;
599 if(!arg || arg.type != identifierExp || strcmp("this", arg.identifier.string))
605 for(param = dataType.params.first; param; param = param.next)
607 if(!arg || arg.type != identifierExp || strcmp(param.name, arg.identifier.string))
612 arg = arg ?arg.next : null;
619 return !confirmation;
622 class CodeEditor : Window
624 background = marginColor;
625 borderStyle = sizableDeep;
630 isActiveClient = true;
631 anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
634 // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
635 // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
637 SheetType sheetSelected;
642 Context globalContext { };
643 OldList excludedSymbols { offset = (uint)&((Symbol)0).left };
656 MethodAction methodAction;
658 ClassFunction function;
660 char methodName[1024];
665 bool membersListShown;
668 EditLine membersLine;
670 Type functionType, instanceType;
674 Point paramsPosition;
675 Expression functionExp;
678 BitmapResource icons[CodeObjectType];
680 FontResource boldFont { $"Tahoma", 8.25f, bold = true, window = this };
681 FontResource normalFont { $"Tahoma", 8.25f, window = this };
683 Module privateModule;
684 NameSpace globalData;
687 OpenedFileInfo openedFileInfo;
689 FontResource font { codeFont.faceName, codeFont.size };
690 saveDialog = codeEditorFileDialog;
692 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
695 int maxLineNumberLength;
697 property bool parsing { get { return editBox.syntaxHighlighting && !noParsing && !ide.noParsing; } };
699 void ProcessCaretMove(EditBox editBox, int line, int charPos)
702 ObjectInfo classItem;
704 // OnActivateClient is called after OnActivate
707 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
710 if(sheet.codeEditor != this) return;
714 for(classItem = classes.first; classItem; classItem = classItem.next)
716 ClassDefinition classDef = classItem.classDefinition;
717 if(classDef && classDef.loc.Inside(line, charPos))
724 for(object = classItem.instances.first; object; object = object.next)
728 if(object.instCode.loc.Inside(line, charPos))
733 sheet.SelectObject(object);
735 sheet.SelectObject(classItem);
740 //sheet.SelectObject(null);
744 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
748 expectingMove = false;
754 if(line-1 != membersLoc.start.line)
758 char * buffer = membersLine.text;
761 if(charPos - 1 < membersLoc.start.charPos)
763 else if(charPos - 1 > membersLoc.end.charPos)
765 char * buffer = membersLine.text;
766 //if(membersList.currentRow)
770 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
771 if(buffer[c] != ' ' && buffer[c] != '\t')
773 if(c < charPos && buffer[c])
780 membersList.Destroy(0);
781 membersListShown = false;
785 bool back = codeModified;
786 codeModified = false;
788 InvokeParameters(false, false, false);
789 /*if(membersListShown)
790 InvokeAutoComplete(false, 0, true);*/
797 watch(modifiedDocument)
799 ProjectView projectView = ide.projectView;
802 char buffer[MAX_LOCATION];
803 char * fullPath = GetSlashPathBuffer(buffer, fileName);
804 Array<ProjectNode> nodes = ide.workspace.GetAllProjectNodes(fullPath, false);
808 node.modified = modifiedDocument;
809 projectView.Update(null);
818 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
819 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
820 tabKey = true, smartHome = true;
821 tabSelection = true, /*maxLineSize = 65536, */parent = this, hasHorzScroll = true, hasVertScroll = true;
822 selectionColor = selectionColor, selectionText = selectionText,
823 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
824 font = font, borderStyle = none;
825 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
827 bool OnMouseOver(int x, int y, Modifiers mods)
829 CodeEditor editor = (CodeEditor)master;
830 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
835 void NotifyCaretMove(EditBox editBox, int line, int charPos)
837 // Update Line Numbers
839 int oldLine = lastLine;
840 display.FontExtent(font.font, " ", 1, null, &spaceH);
842 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
846 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
851 if(ide.activeClient == this)
852 ProcessCaretMove(editBox, line, charPos);
854 openedFileInfo.CaretMove(line, charPos);
857 void NotifyOvrToggle(EditBox editBox, bool overwrite)
859 ide.UpdateStateLight(ide.ovr, overwrite);
862 void NotifyUpdate(EditBox editBox)
869 designer.modifiedDocument = true;
872 modifiedDocument = true;
875 bool NotifyUnsetModified(EditBox editBox)
877 modifiedDocument = false;
881 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
883 if(!loadingFile && after.y != before.y)
885 ProjectView projectView = ide.projectView;
886 if(projectView && fileName)
889 // HOW WE MIGHT WANT TO DO IT:
890 char * text = before.line.text;
891 for(c = before.x-1; c>= 0; c--)
892 if(!isspace(text[c]))
894 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
896 // HOW VISUAL STUDIO DOES IT:
898 char * text = after.line.text;
899 for(c = after.line.count-1; c>= 0; c--)
900 if(!isspace(text[c]))
902 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
905 Update({ 0, 0, editBox.position.x, clientSize.h });
913 for(oClass = classes.first; oClass; oClass = oClass.next)
916 for(object = oClass.instances.first; object; object = object.next)
920 object.instCode.loc.start.AdjustAdd(before, after);
921 object.instCode.loc.end.AdjustAdd(before, after);
926 oClass.classDefinition.loc.start.AdjustAdd(before, after);
927 oClass.classDefinition.loc.end.AdjustAdd(before, after);
933 expectingMove = true;
937 if(before.y != after.y)
941 char * buffer = membersLine.text;
943 bool firstChar = true;
944 bool addedChar = false;
950 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
952 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
954 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
955 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
964 membersLoc.start.charPos++;
969 string[len++] = buffer[c];
973 row = membersList.currentRow;
974 if(row && row.selected)
978 membersLoc.start.charPos--;
986 row = membersList.FindSubString(string);
988 membersList.currentRow = row;
991 row = membersList.FindSubStringi(string);
993 membersList.currentRow = row;
994 membersList.currentRow.selected = false;
997 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
1001 row = membersList.currentRow;
1004 // Accept current string if hiding typing char
1005 if(hide && row && row.selected)
1007 char * string = row.string;
1008 int len = strlen(string);
1009 membersLoc.end.charPos -= after.x - before.x;
1010 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1011 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
1012 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1013 editBox.PutS(string);
1014 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
1016 after.x += membersLoc.start.charPos + len - before.x;
1017 before.x = membersLoc.start.charPos + len;
1022 membersList.Destroy(0);
1023 membersListShown = false;
1026 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
1028 EditLine line = editBox.line;
1029 char * text = line.text;
1030 char ch = text[after.x-1];
1031 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1035 // Can we call invoke auto complete here instead?
1045 // Force caret update already...
1046 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1047 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1049 editBox.GetCaretPosition(&caret);
1053 // Go back in the buffer until no space before
1055 codeModified = true;
1059 EditBoxStream f { editBox = editBox };
1063 if(text[after.x-1] == '>')
1069 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1073 if(!f.Seek(-1, current))
1076 if(!isspace(ch)) break;
1077 f.Seek(-1, current);
1079 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1081 line = editBox.lineNumber + 1;
1082 charPos = editBox.charPos + 1;
1086 exp = FindExpTree(ast, line, charPos);
1090 Type type = exp.expType;
1092 if(type && text[after.x-1] != '.')
1094 if(type.kind == TypePointer || type.kind == TypeArray)
1100 membersList.Clear();
1103 if(membersList.rowCount)
1105 membersList.Sort(null, 1);
1106 membersList.master = this;
1108 caret.y += editBox.GetCaretSize();
1111 membersList.Create();
1114 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1115 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1116 Window parent = membersList.parent;
1118 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1120 y -= editBox.GetCaretSize() + membersList.GetHeight();
1121 membersAbove = true;
1124 membersAbove = false;
1126 membersList.position = { x, y };
1130 membersLoc.start.line = line - 1;
1131 membersLoc.start.charPos = oldCharPos;
1132 membersLoc.end = membersLoc.start;
1133 membersListShown = true;
1138 SetCurrentContext(globalContext);
1140 codeModified = true;
1141 skipModified = true;
1142 if(text[after.x-1] == ':')
1143 InvokeAutoComplete(false, 0, false);
1144 else if(text[after.x-1] == '.')
1145 InvokeAutoComplete(false, 1, false);
1146 else if(text[after.x-1] == '>')
1147 InvokeAutoComplete(false, 2, false);
1148 skipModified = false;
1150 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1152 codeModified = true;
1153 skipModified = true;
1155 if(InvokeAutoComplete(true, 0, false))
1157 if(ch == '(' || ch == OpenBracket)
1158 InvokeParameters(true, true, false);
1160 InvokeParameters(this.functionType ? false : true, false, false);
1163 // InvokeAutoComplete(true, 0, false);
1164 skipModified = false;
1166 else if(ch == ')' || ch == '}' || ch == ';')
1168 codeModified = true;
1169 skipModified = true;
1171 InvokeParameters(false, true, false);
1172 skipModified = false;
1176 bool back = codeModified;
1177 codeModified = false;
1179 InvokeParameters(false, false, true);
1180 if(membersListShown)
1181 InvokeAutoComplete(false, 0, true);
1182 codeModified = back;
1187 bool back = codeModified;
1188 codeModified = false;
1191 InvokeParameters(false, false, true);
1192 /*if(membersListShown)
1193 InvokeAutoComplete(false, 0, true);*/
1195 codeModified = back;
1202 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1204 if(!loadingFile && after.y != before.y)
1206 ProjectView projectView = ide.projectView;
1207 if(projectView && fileName)
1208 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1209 Update({ 0, 0, editBox.position.x, clientSize.h });
1217 for(oClass = classes.first; oClass; oClass = oClass.next)
1221 for(object = oClass.instances.first; object; object = object.next)
1225 loc = &object.instCode.loc;
1227 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1228 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1230 object.instCode = null;
1234 loc->start.AdjustDelete(before, after);
1235 loc->end.AdjustDelete(before, after);
1239 if(oClass.classDefinition)
1241 loc = &oClass.classDefinition.loc;
1242 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1243 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1245 oClass.classDefinition = null;
1249 loc->start.AdjustDelete(before, after);
1250 loc->end.AdjustDelete(before, after);
1255 if(membersListShown)
1258 if(pasteOperation || before.y != after.y)
1262 char * buffer = membersLine.text;
1264 bool firstChar = true;
1268 if(before.x >= membersLoc.start.charPos)
1270 for(c = membersLoc.start.charPos; c<before.x && len < sizeof(string)-1; c++)
1272 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1273 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1278 if(!isSpace) firstChar = false;
1281 string[len++] = buffer[c];
1286 // If deleting spaces before...
1287 for(c = before.x; c<membersLoc.start.charPos; c++)
1289 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1297 membersLoc.start.charPos = before.x;
1300 if(membersLoc.end.charPos >= after.x)
1302 for(c = after.x; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1304 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1305 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1310 if(!isSpace) firstChar = false;
1313 string[len++] = buffer[c];
1321 membersLoc.end.charPos -= after.x - before.x;
1325 row = membersList.FindSubString(string);
1328 row = membersList.FindSubStringi(string);
1330 membersList.currentRow = row;
1331 membersList.currentRow.selected = false;
1334 membersList.currentRow = row;
1336 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1341 membersList.Destroy(0);
1342 membersListShown = false;
1348 InvokeParameters(false, false);
1356 bool NotifyDropped(EditBox editBox, int x, int y)
1358 char * controlClass = toolBox.controlClass;
1359 if(controlClass && controlClass[0])
1363 ObjectInfo classObject;
1365 editBox.GoToLineNum(y);
1366 x = Min(x, editBox.line.count);
1367 editBox.GoToPosition(editBox.line, y, x);
1368 // Note: Uncommented this to drag objects after the member instance on which they are dropped
1369 editBox.NotifyCaretMove(this, editBox, y+1, x+1);
1371 classObject = selected ? selected.oClass : null;
1373 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1374 selected = classObject.instances.last;
1377 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1380 AddObject(control, &object);
1382 designer.CreateObject(control, object, false, classObject.instance);
1383 // designer.PostCreateObject(control, object, false, classObject.instance);
1384 designer.DroppedObject(control, object, false, classObject.instance);
1386 sheet.AddObject(object, object.name, typeData /* className*/, true);
1389 //codeModified = true;
1396 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1398 if(key == ctrlSpace)
1400 membersList.Destroy(0);
1401 membersListShown = false;
1402 InvokeAutoComplete(false, 0, false);
1405 else if(key == Key { space, ctrl = true, shift = true })
1406 InvokeParameters(false, true, false);
1407 else if(key == escape)
1408 ide.RepositionWindows(true);
1409 else if(key == ctrlF7)
1413 ProjectNode node = ide.projectView.GetNodeForCompilationFromWindow(this, false, null, null);
1417 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1418 $"It can't be compiled.");
1419 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1428 bool OnKeyDown(Key key, unichar ch)
1430 CodeEditor editor = (CodeEditor)master;
1431 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1433 if(editor.membersListShown)
1435 editor.membersList.Destroy(0);
1436 editor.membersListShown = false;
1439 if(editor.paramsShown)
1441 editor.paramsList.Destroy(0);
1442 editor.paramsShown = false;
1443 FreeType(editor.functionType);
1444 FreeType(editor.instanceType);
1446 editor.functionType = null;
1447 editor.instanceType = null;
1448 editor.paramsID = -1;
1452 return EditBox::OnKeyDown(key, ch);
1455 void OnVScroll(ScrollBarAction action, int position, Key key)
1457 if(anchor.left.distance)
1459 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1462 EditBox::OnVScroll(action, position, key);
1464 CodeEditor ce = (CodeEditor)parent;
1465 if(ce.openedFileInfo)
1466 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1470 void OnHScroll(ScrollBarAction action, int position, Key key)
1472 EditBox::OnHScroll(action, position, key);
1474 CodeEditor ce = (CodeEditor)parent;
1475 if(ce.openedFileInfo)
1476 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1483 fullRowSelect = false,
1486 borderStyle = bevel;
1487 // size = { 200, 400 };
1489 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1491 DataRow row = listBox.currentRow;
1494 char * string = row.string;
1496 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1498 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1499 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1500 editBox.PutS(string);
1503 membersListShown = false;
1508 bool OnKeyDown(Key key, unichar ch)
1510 CodeEditor editor = (CodeEditor) master;
1511 if(key == escape || key == leftAlt || key == rightAlt ||
1512 (key.ctrl && key.code != left && key.code != right &&
1513 key.code != leftShift && key.code != rightShift && key.code != space))
1516 if(editor.paramsShown)
1520 editor.paramsList.Destroy(0);
1521 editor.paramsShown = false;
1523 if(editor.membersListShown)
1527 editor.membersList.Destroy(0);
1528 editor.membersListShown = false;
1531 FreeType(editor.functionType);
1532 editor.functionType = null;
1534 FreeType(editor.instanceType);
1535 editor.instanceType = null;
1537 editor.paramsID = -1;
1542 return editor.editBox.OnKeyDown(key, ch);
1546 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1548 CodeEditor editor = (CodeEditor)master;
1549 Window rw = previous ? previous.rootWindow : null;
1550 if(!active && rw != editor.paramsList)
1553 editor.membersListShown = false;
1555 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1558 bool OnKeyHit(Key key, unichar ch)
1560 CodeEditor editor = (CodeEditor) master;
1564 case enter: case tab:
1566 DataRow row = currentRow;
1567 if(row && row.selected)
1569 char * string = row.string;
1571 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1572 editor.editBox.Delete(
1573 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1574 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1575 editor.editBox.PutS(string);
1578 editor.membersListShown = false;
1581 editor.editBox.OnKeyHit(key, ch);
1591 return ListBox::OnKeyHit(key, ch);
1597 // If before . or after
1598 //listBox.Destroy(true);
1599 result = editor.editBox.OnKeyHit(key, ch);
1614 clickThrough = true,
1616 borderStyle = contour,
1618 background = { 255,255,225 },
1620 OnKeyDown = membersList.OnKeyDown;
1622 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1624 CodeEditor editor = (CodeEditor)master;
1625 Window rw = previous ? previous.rootWindow : null;
1626 if(!active && previous != editor.editBox && rw != editor.membersList)
1629 editor.paramsShown = false;
1631 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1634 bool OnKeyHit(Key key, unichar ch)
1636 CodeEditor editor = (CodeEditor)master;
1638 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1641 bool result = true; editor.editBox.OnKeyHit(key, ch);
1642 return (!created) ? false : result;
1649 void OnRedraw(Surface surface)
1651 CodeEditor editor = (CodeEditor) master;
1652 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1654 Type methodType = null;
1658 int functionW, nameW = 0;
1660 int spaceW, spaceH, commaW, commaWB, parW;
1662 int maxW = 0, lineW = 0;
1668 Font font = editor.normalFont.font;
1669 Font boldFont = editor.boldFont.font;
1670 Display display = this.display;
1672 if(!type) { return; };
1674 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1676 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1677 display.FontExtent(font, ", ", 2, &commaW, null);
1678 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1679 display.FontExtent(font, ")", 1, &parW, null);
1682 if(editor.functionType)
1684 PrintType(type.returnType, string, true, true);
1685 display.FontExtent(font, string, strlen(string), &functionW, null);
1687 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1688 totalW = nameW + functionW + 2 * parW;
1692 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1693 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1694 if(instanceName && type.kind != functionType)
1695 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1696 totalW = functionW + nameW;
1697 surface.TextFont(boldFont);
1700 surface.WriteText(x, y, string, strlen(string));
1701 x += functionW + spaceW;
1703 if(editor.functionType)
1706 surface.WriteText(x, y, type.name, strlen(type.name));
1708 surface.WriteText(x, y, "(", 1);
1711 if(methodType && !methodType.staticMethod && methodType.methodClass)
1715 if(id == editor.paramsID)
1716 surface.TextFont(boldFont);
1718 if(methodType.methodClass)
1719 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1723 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1724 width += ((id == editor.paramsID) ? commaWB : commaW);
1729 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1734 x = 2 + nameW + spaceW + functionW + parW;
1738 if(methodType.methodClass)
1739 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1742 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1744 surface.WriteText(x, y, ",", 1);
1745 x += ((id == editor.paramsID) ? commaWB : commaW);
1753 if(id == editor.paramsID)
1754 surface.TextFont(font);
1758 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1760 for(param = type.params.first; param; param = param.next)
1762 char paramString[1024];
1765 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1766 surface.TextFont(boldFont);
1769 PrintType(param, paramString, true, true);
1770 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1772 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1777 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1782 x = 2 + nameW + spaceW + functionW + parW;
1786 surface.WriteText(x, y, paramString, strlen(paramString));
1790 surface.WriteText(x, y, ",", 1);
1791 x += ((id == editor.paramsID) ? commaWB : commaW);
1799 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1800 surface.TextFont(font);
1805 surface.WriteText(x, y, ")", 1);
1807 else if(instanceName && type.kind != functionType)
1809 surface.WriteText(x, y, instanceName, strlen(instanceName));
1813 bool OnResizing(int * w, int * h)
1815 CodeEditor editor = (CodeEditor) master;
1816 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1818 Type methodType = null;
1822 int functionW = 0, nameW = 0;
1824 int spaceW, spaceH, commaW, commaWB, parW;
1826 int maxW = 0, lineW = 0;
1831 Font font = editor.normalFont.font;
1832 Font boldFont = editor.boldFont.font;
1833 Display display = this.display;
1835 if(type.kind == TypeKind::methodType)
1838 ProcessMethodType(type.method);
1839 type = type.method.dataType;
1842 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1843 display.FontExtent(font, ", ", 2, &commaW, null);
1844 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1845 display.FontExtent(font, ")", 1, &parW, null);
1848 if(editor.functionType && type)
1850 PrintType(type.returnType, string, true, true);
1851 display.FontExtent(font, string, strlen(string), &functionW, null);
1853 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1854 totalW = nameW + spaceW + functionW + 2 * parW;
1858 PrintType(type, string, false, true); // /*true);
1859 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1860 if(instanceName && type.kind != functionType)
1861 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1862 totalW = functionW + nameW + spaceW;
1865 if(editor.functionType)
1871 if(methodType.methodClass)
1872 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1873 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1874 width += ((id == editor.paramsID) ? commaWB : commaW);
1879 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1892 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1894 for(param = type.params.first; param; param = param.next)
1896 char paramString[1024];
1900 PrintType(param, paramString, true, true);
1901 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1903 width += ((id == editor.paramsID) ? commaWB : commaW);
1908 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1925 *w = realW + totalW + 4;
1931 Menu fileMenu { menu, $"File", f };
1932 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1933 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1935 Menu debugMenu { menu, $"Debug", d };
1936 MenuItem debugRunToCursor { debugMenu, $"Run To Cursor", c, ctrlF10, id = RTCMenuBits { false, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1937 MenuItem debugSkipRunToCursor { debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true }, id = RTCMenuBits { true, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1938 MenuItem debugRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level", l, altF10, id = RTCMenuBits { false, true, false }, NotifySelect = RTCMenu_NotifySelect; };
1939 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; };
1941 MenuItem debugBpRunToCursor { debugMenu, $"BP Run To Cursor"/*, c, ctrlF10*/, id = RTCMenuBits { false, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1942 MenuItem debugBpSkipRunToCursor { debugMenu, $"BP Run To Cursor Skipping Breakpoints"/*, u, Key { f10, ctrl = true, shift = true }*/, id = RTCMenuBits { true, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1943 MenuItem debugBpRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level"/*, l, altF10*/, id = RTCMenuBits { false, true, true }, NotifySelect = RTCMenu_NotifySelect; };
1944 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; };
1946 bool RTCMenu_NotifySelect(MenuItem selection, Modifiers mods)
1948 ProjectView projectView = ide.projectView;
1949 if(!projectView.buildInProgress)
1951 RTCMenuBits bits = (RTCMenuBits)selection.id;
1952 int line = editBox.lineNumber + 1;
1955 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1956 ProjectConfig config = projectView.project.config;
1957 int bitDepth = ide.workspace.bitDepth;
1958 bool useValgrind = ide.workspace.useValgrind;
1959 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, bits.ignoreBreakpoints, bits.atSameLevel, bits.oldImplementation);
1965 MenuDivider { debugMenu };
1966 MenuItem debugToggleBreakpoint
1968 debugMenu, $"Toggle Breakpoint", t, f9;
1969 bool NotifySelect(MenuItem selection, Modifiers mods)
1971 ProjectView projectView = ide.projectView;
1972 if(projectView && fileName)
1974 int line = editBox.lineNumber + 1;
1975 ide.debugger.ToggleBreakpoint(fileName, line);
1985 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1989 designer.parent = parent;
1992 toolBox = ((IDEWorkSpace)master).toolBox;
1994 // Debugger bug here: value of toolBox appears as 0
1996 sheet = ((IDEWorkSpace)master).sheet;
2001 bool OnClose(bool parentClosing)
2005 if(ide.workspace && fileName)
2006 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2007 if(inUseDebug && !debugClosing)
2009 debugClosing = true;
2011 if(CloseConfirmation(false))
2014 if(modifiedDocument)
2015 OnFileModified({ modified = true }, null);
2017 debugClosing = false;
2020 if(designer && !designer.closing)
2022 if(designer.visible)
2029 //Window formEditor = designer;
2030 //formEditor.Destroy(0);
2033 ide.AdjustFileMenus();
2038 void OnDestroy(void)
2040 ObjectInfo oClass, next;
2041 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2043 FreeType(this.functionType);
2044 FreeType(this.instanceType);
2049 designer.codeEditor = null;
2050 designer.Destroy(0);
2054 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2056 ObjectInfo object, next;
2058 for(object = oClass.instances.first; object; object = next)
2063 Designer::DestroyObject(object.instance);
2064 delete object.instance;
2066 sheet.DeleteObject(object);
2068 oClass.instances.Delete(object);
2072 Designer::DestroyObject(oClass.instance);
2073 delete oClass.instance;
2075 sheet.DeleteObject(oClass);
2077 classes.Delete(oClass);
2080 if(windowClass && windowClass.data)
2081 UnapplySkin(windowClass);
2085 if(sheet.codeEditor == this)
2087 sheet.codeEditor = null;
2088 toolBox.codeEditor = null;
2094 ProjectView projectView = ide.projectView;
2097 ProjectNode node = projectView.GetNodeFromWindow(this, null, true, false, null);
2098 if(node && node.modified)
2100 node.modified = false;
2101 projectView.Update(null);
2107 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2109 // 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
2111 if(directActivation)
2112 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2114 if(active && directActivation)
2118 openedFileInfo.Activate();
2122 Location * loc = null;
2123 UpdateFormCode(); // To ensure update when modifying properties...
2125 // Got to the right spot in code so we don't lose our form selection...
2128 if(selected.instCode)
2129 loc = &selected.instCode.loc;
2130 else if(selected.classDefinition)
2131 loc = &selected.classDefinition.loc;
2133 line = editBox.lineNumber + 1;
2134 charPos = editBox.charPos + 1;
2139 if(selected && !loc->Inside(line, charPos))
2141 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2142 line = editBox.lineNumber + 1;
2143 charPos = editBox.charPos + 1;
2145 else if(selected && selected.classDefinition)
2148 for(object = selected.instances.first; object; object = object.next)
2152 if(object.instCode.loc.Inside(line, charPos))
2158 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2159 line = editBox.lineNumber + 1;
2160 charPos = editBox.charPos + 1;
2165 ProcessCaretMove(editBox, line, charPos);
2170 if(membersListShown)
2172 membersList.Destroy(0);
2173 membersListShown = false;
2177 paramsList.Destroy(0);
2178 paramsShown = false;
2179 FreeType(functionType);
2180 FreeType(instanceType);
2182 functionType = null;
2183 instanceType = null;
2190 bool OnSaveFile(char * fileName)
2197 f = FileOpen(fileName, write);
2200 if(!ide.projectView)
2201 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2205 this.fileName = fileName; // Put this here because the form designer will check for it...
2206 designer.fileName = fileName;
2207 designer.modifiedDocument = false;
2210 if(editBox.syntaxHighlighting)
2212 // Nuke trailing spaces
2215 for(line = editBox.firstLine; line; line = line.next, y++)
2217 String buffer = line.text;
2218 int count = line.count, i = count-1;
2219 while(i > 0 && isspace(buffer[i])) i--;
2221 editBox.Delete(line, y, i, line, y, count);
2225 editBox.Save(f, false);
2226 modifiedDocument = false;
2234 bool OnFileModified(FileChange fileChange, char * param)
2236 bool reload = false;
2237 if(visible == false && inUseDebug == true)
2238 ide.debugger.WatchesReleaseCodeEditor();
2243 sprintf(message, $"The document %s was modified by another application.\n"
2244 "Would you like to reload it and lose your changes?", fileName);
2245 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2246 contents = message }.Modal() == yes)
2252 File f = FileOpen(fileName, read);
2255 int lineNumber, charPos, len;
2259 updatingCode = true;
2260 lineNumber = editBox.lineNumber;
2261 charPos = editBox.charPos;
2262 scroll = editBox.scroll;
2265 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2266 len = strlen(editBox.line.text);
2267 editBox.GoToLineNum(lineNumber);
2268 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2269 editBox.scroll = scroll;
2270 updatingCode = false;
2271 loadingFile = false;
2273 codeModified = true;
2277 designer.modifiedDocument = false;
2279 modifiedDocument = false;
2287 void OnRedraw(Surface surface)
2290 surface.SetBackground(marginColor);
2291 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2292 if(ideSettings.showLineNumbers)
2294 int currentLineNumber;
2296 char lineFormat[16];
2300 surface.textOpacity = false;
2301 surface.font = font.font;
2302 surface.TextExtent(" ", 1, null, &spaceH);
2303 currentLineNumber = editBox.scroll.y / spaceH + 1;
2304 sprintf(lineFormat, " %%%du", maxLineNumberLength);
2306 surface.SetForeground(lineNumbersColor);
2307 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2309 // Highlight current line
2310 if(editBox.lineNumber == currentLineNumber - 1)
2312 surface.SetBackground(selectedMarginColor);
2313 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2314 surface.SetBackground(marginColor);
2316 sprintf(lineText, lineFormat, currentLineNumber);
2317 if(currentLineNumber <= editBox.numLines)
2318 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
2319 currentLineNumber++;
2323 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2325 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2326 int lineCursor, lineTopFrame, breakpointLines[128];
2327 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2328 Debugger debugger = ide.debugger;
2329 BitmapResource bmpRes;
2331 boxH = clientSize.h;
2332 scrollY = editBox.scroll.y;
2333 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2335 bpOnCursor = bpOnTopFrame = false;
2336 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2339 for(i = 0; i < count; i++)
2341 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2343 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2344 if(breakpointLines[i] == lineCursor)
2346 if(breakpointLines[i] == lineTopFrame)
2347 bpOnTopFrame = true;
2350 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2352 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2355 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2356 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2357 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2359 if(editBox.anchor.left.distance)
2361 if(editBox.horzScroll && editBox.horzScroll.visible)
2363 surface.SetBackground(control);
2364 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2369 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2374 lineY = (line - 1) * lineH;
2375 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2377 Bitmap bitmap = resource.bitmap;
2379 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2386 char ext[MAX_EXTENSION];
2387 char * fileName = property::fileName;
2389 if(SearchString(fileName, 0, "Makefile", false, true))
2390 editBox.useTab = true;
2391 designer.fileName = fileName;
2395 GetExtension(fileName, ext);
2397 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2398 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2399 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2400 editBox.syntaxHighlighting = true;
2402 editBox.syntaxHighlighting = false;
2404 if(parsing && !strcmpi(ext, "ec"))
2406 codeModified = true;
2410 maxLineNumberLength = 0;
2415 bool UpdateMarginSize()
2417 if(ideSettings.showLineNumbers)
2419 int numLen = Max(4, nofdigits(editBox.numLines));
2421 maxLineNumberLength = numLen;
2422 display.FontExtent(font.font, "0", 1, &digitWidth, null);
2423 editBox.anchor = Anchor
2425 left = editBox.syntaxHighlighting * 20 + ideSettings.showLineNumbers * (maxLineNumberLength+2) * digitWidth,
2426 right = 0, top = 0, bottom = 0
2431 maxLineNumberLength = 0;
2432 editBox.anchor = Anchor
2434 left = editBox.syntaxHighlighting * 20,
2435 right = 0, top = 0, bottom = 0
2447 bool LoadFile(char * filePath)
2449 File f = FileOpen(filePath, read);
2452 // Added this here...
2453 fileName = filePath;
2455 updatingCode = true;
2457 updatingCode = false;
2458 loadingFile = false;
2467 void AdjustDebugMenus()
2469 bool unavailable = ide.areDebugMenusUnavailable;
2470 bool isNotNotRunning = unavailable || ide.isDebuggerRunning;
2471 bool isNotStopped = unavailable || !ide.isDebuggerStopped;
2472 bool noBreakpointToggle = ide.isBreakpointTogglingUnavailable;
2474 debugRunToCursor.disabled = isNotNotRunning;
2475 debugSkipRunToCursor.disabled = isNotNotRunning;
2476 debugRunToCursorAtSameLevel.disabled = isNotStopped;
2477 debugSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2479 debugBpRunToCursor.disabled = isNotNotRunning;
2480 debugBpSkipRunToCursor.disabled = isNotNotRunning;
2481 debugBpRunToCursorAtSameLevel.disabled = isNotStopped;
2482 debugBpSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2484 debugToggleBreakpoint.disabled = noBreakpointToggle;
2490 ProjectView projectView = ide.projectView;
2493 designer.fileName = fileName;
2499 sprintf(title, $"Untitled %d", documentID);
2500 // designer.fileName = CopyString(title);
2501 designer.fileName = title;
2506 for(c = 0; c < CodeObjectType::enumSize; c++)
2507 icons[c] = BitmapResource { iconNames[c], window = this };
2509 codeModified = true;
2521 selected.modified = true;
2522 selected.oClass.modified = true;
2524 designer.modifiedDocument = true;
2525 modifiedDocument = true;
2526 formModified = true;
2529 /****************************************************************************
2531 ****************************************************************************/
2539 this.defines.Free(FreeModuleDefine);
2540 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2542 FreeExcludedSymbols(this.excludedSymbols);
2543 FreeContext(this.globalContext);
2545 FreeGlobalData(&this.globalData);
2546 FindCtx_Terminate();
2547 FindParams_Terminate();
2549 if(GetGlobalContext() == globalContext)
2551 SetGlobalData(null);
2552 SetGlobalContext(null);
2553 SetExcludedSymbols(null);
2554 SetTopContext(null);
2555 SetCurrentContext(null);
2558 SetPrivateModule(null);
2561 if(this.privateModule)
2563 FreeTypeData(this.privateModule);
2564 delete this.privateModule;
2565 this.privateModule = null;
2571 static bool reentrant = false;
2576 char * selectedClassName = null, * selectedName = null;
2577 int selectedPos = 0;
2578 Designer backDesigner;
2579 char oldWorkDir[MAX_LOCATION];
2580 char mainModuleName[MAX_FILENAME] = "";
2582 ImportedModule module;
2583 char extension[MAX_EXTENSION];
2584 PathBackup pathBackup { };
2586 Time parseCodeStart = GetTime();
2587 Time startTime, startFindClass;
2589 findClassTotalTime = 0;
2590 checkTypeTotalTime = 0;
2591 externalImportTotalTime = 0;
2592 findClassIgnoreNSTotalTime = 0;
2593 findSymbolTotalTime = 0;
2594 //ResetClassFindTime();
2598 // 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)
2599 if(reentrant) return;
2606 selectedClassName = CopyString(oClass.name);
2607 if(selected != oClass)
2609 ObjectInfo object = this.selected;
2610 selectedName = CopyString(object.name);
2614 for(check = this.oClass.instances.first; check; check = check.next)
2626 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2628 FindCtx_Terminate();
2629 FindParams_Terminate();
2631 SetGlobalData(&globalData);
2632 SetGlobalContext(globalContext);
2633 SetExcludedSymbols(&excludedSymbols);
2634 SetTopContext(globalContext);
2635 SetCurrentContext(globalContext);
2636 SetDefines(&defines);
2637 SetImports(&imports);
2638 SetCurrentNameSpace(null);
2641 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2642 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2643 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2644 "/I T:\\ecere\\include /E %s", argv[1]);
2648 ChangeWorkingDir("e:\\ec");
2649 sprintf(command, "gcc -x c -E -");
2650 fileInput = DualPipeOpen({ output = true, input = true }, command);
2651 SetFileInput(fileInput);
2656 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2658 fileInput.Write(buffer, 1, count);
2663 fileInput.CloseOutput();
2667 // TOCHECK: COULDN'T WE CALL FreeParser here?
2669 FreeType(this.functionType);
2670 FreeType(this.instanceType);
2671 this.functionType = null;
2672 this.instanceType = null;
2675 sheet.SelectObject(null);
2681 // We don't want the designer to be notified of selection when deleting rows...
2682 backDesigner = designer;
2687 ObjectInfo _class, next;
2689 for(_class = classes.first; _class; _class = next)
2695 for(;object = _class.instances.first;)
2699 Designer::DestroyObject(object.instance);
2700 delete object.instance;
2702 sheet.DeleteObject(object);
2704 _class.instances.Delete(object);
2708 Designer::DestroyObject(_class.instance);
2709 delete _class.instance;
2711 sheet.DeleteObject(_class);
2713 classes.Delete(_class);
2719 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2720 if(windowClass && windowClass.data)
2721 UnapplySkin(windowClass);
2724 designer = backDesigner;
2727 fileInput = editFile = EditBoxStream { editBox = editBox };
2728 SetFileInput(fileInput);
2736 defines.Free(FreeModuleDefine);
2737 imports.Free(FreeModuleImport);
2739 FreeContext(this.globalContext);
2740 FreeExcludedSymbols(this.excludedSymbols);
2743 FreeGlobalData(&this.globalData);
2745 if(this.privateModule)
2747 FreeTypeData(this.privateModule);
2748 delete this.privateModule;
2752 startTime = GetTime();
2753 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2755 printf("classes.count: %d\n", globalContext.classes.count);
2760 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2761 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2764 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2766 SetPrivateModule(privateModule);
2769 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2770 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2771 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2772 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2773 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2776 fileName = this.fileName;
2778 if(ide.workspace && ide.workspace.projects && fileName)
2780 for(p : ide.workspace.projects)
2782 char path[MAX_LOCATION];
2784 MakePathRelative(fileName, p.topNode.path, path);
2785 MakeSlashPath(path);
2787 pn = p.topNode.FindWithPath(path, false);
2796 project = ide.project;
2798 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2800 ChangeWorkingDir(project.topNode.path);
2802 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2804 GetLastDirectory(fileName, mainModuleName);
2805 GetExtension(mainModuleName, extension);
2807 SetBuildingEcereCom(false);
2808 SetBuildingEcereComModule(false);
2810 // TODO: Get symbolsDir from project settings instead...
2813 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2814 ProjectConfig config = project.config;
2815 int bitDepth = ide.workspace.bitDepth;
2816 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2817 SetSymbolsDir(objDir.dir);
2818 ide.SetPath(true, compiler, config, bitDepth);
2822 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2823 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2827 switch(GetRuntimePlatform())
2829 case win32: SetSymbolsDir("obj/debug.win32"); break;
2830 case tux: SetSymbolsDir("obj/debug.linux"); break;
2831 case apple: SetSymbolsDir("obj/debug.apple"); break;
2833 SetIncludeDirs(null);
2834 SetSysIncludeDirs(null);
2838 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2840 // TODO FIX for configless project
2841 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2843 for(item : ide.project.config.options.preprocessorDefinitions)
2845 if(!strcmp(item, "BUILDING_ECERE_COM"))
2847 SetBuildingEcereCom(true);
2854 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2855 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2856 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2857 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2858 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2859 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2860 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2861 strcmpi(mainModuleName, "Mutex.ec")))
2863 SetBuildingEcereComModule(true);
2866 // Predeclare all classes
2868 char symFile[MAX_FILENAME];
2869 char symLocation[MAX_LOCATION];
2870 ImportedModule module, next;
2872 GetLastDirectory(fileName, symFile);
2873 ChangeExtension(symFile, "sym", symFile);
2875 strcpy(symLocation, GetSymbolsDir());
2876 PathCat(symLocation, symFile);
2878 // if(!GetEcereImported() && !GetBuildingEcereCom())
2879 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2882 startTime = GetTime();
2884 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2886 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2891 startTime = GetTime();
2893 // LoadSymbols(symLocation, normalImport, true);
2894 LoadSymbols(symLocation, preDeclImport, false);
2896 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2899 for(module = defines.first; module; module = next)
2902 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2905 defines.Delete(module);
2910 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2912 SetDefaultDeclMode(privateAccess);
2913 SetDeclMode(privateAccess);
2917 SetDefaultDeclMode(defaultAccess);
2918 SetDeclMode(defaultAccess);
2921 StripExtension(mainModuleName);
2922 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2923 defines.AddName(module);
2926 // SetYydebug(true);
2931 startTime = GetTime();
2932 startFindClass = checkTypeTotalTime;
2936 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2938 CheckDataRedefinitions();
2941 SetIncludeDirs(null);
2942 SetSysIncludeDirs(null);
2953 startTime = GetTime();
2955 PrePreProcessClassDefinitions();
2956 ComputeModuleClasses(privateModule);
2957 PreProcessClassDefinitions();
2958 ProcessClassDefinitions();
2960 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2961 startTime = GetTime();
2966 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2967 startTime = GetTime();
2969 ProcessInstantiations();
2971 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2974 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2976 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2977 if(!windowClass || windowClass.internalDecl)
2980 startTime = GetTime();
2982 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2983 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2984 eModule_Load(this.privateModule, "ecere", privateAccess);
2986 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2989 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2991 if(windowClass && windowClass.data)
2992 ApplySkin(windowClass, app.currentSkin.name, null);
2996 startTime = GetTime();
2998 for(external = ast->first; external; external = external.next)
3000 if(external.type == classExternal)
3002 ClassDefinition _class = external._class;
3003 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
3005 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
3008 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
3010 Instance instance = eInstance_New(regClass);
3011 ObjectInfo classObject
3013 name = CopyString(_class._class.name);
3014 instance = instance;
3015 classDefinition = _class;
3016 oClass = classObject;
3019 classes.Add(classObject);
3023 // Moved this at bottom so that the file dialog doesn't show up in eCom
3024 designer.CreateObject(instance, classObject, true, null);
3025 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
3027 if(_class.definitions)
3031 for(def = _class.definitions->first; def; def = def.next)
3035 case defaultPropertiesClassDef:
3038 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3040 Identifier id = propDef.identifiers->first;
3043 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3046 Class propertyClass = prop.dataTypeClass;
3048 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3049 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3051 FreeType(propDef.initializer.exp.destType);
3052 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3053 ProcessExpressionType(propDef.initializer.exp);
3055 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
3057 Expression computed = CopyExpression(propDef.initializer.exp);
3058 ComputeExpression(computed);
3060 if(computed.isConstant && computed.type == instanceExp && !id.next)
3064 if(computed.instance._class && computed.instance._class.symbol &&
3065 computed.instance._class.symbol.registered &&
3066 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3068 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3070 // This was saved in the control and shouldn't be freed by FreeExpression...
3071 // (Not doing this anymore, incrementing refCount in pass15 instead)
3072 /*if(propertyClass.type == normalClass)
3073 computed.instance.data = null;*/
3077 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3078 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3080 String temp = new char[strlen(computed.string)+1];
3081 ReadString(temp, computed.string);
3082 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3086 propDef.variable = true;
3088 FreeExpression(computed);
3092 Expression computed = CopyExpression(propDef.initializer.exp);
3093 ComputeExpression(computed);
3094 if(computed.isConstant)
3096 //if(computed.type == memberExp) computed = computed.member.exp;
3098 if(computed.type == constantExp)
3100 Operand value = GetOperand(computed);
3101 DataValue valueData;
3102 valueData.i64 = value.i64;
3103 SetProperty(prop, instance, valueData);
3105 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3107 String temp = new char[strlen(computed.string)+1];
3108 ReadString(temp, computed.string);
3109 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3114 propDef.variable = true;
3116 FreeExpression(computed);
3120 propDef.variable = true;
3124 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3125 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3126 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3129 // Maintain a list in FunctionDefinition of who is attached to it
3130 for(def = _class.definitions->first; def; def = def.next)
3132 if(def.type == functionClassDef)
3134 ClassFunction function = def.function;
3135 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3137 function.attached.Add(OldLink { data = method });
3147 case declarationClassDef:
3149 Declaration decl = def.decl;
3152 case instDeclaration:
3154 Instantiation inst = decl.inst;
3155 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3156 if(instClass && eClass_GetDesigner(instClass))
3158 Instance control = eInstance_New(instClass);
3163 oClass = classObject;
3167 classObject.instances.Add(object);
3169 // TOCHECK: Why is this needed now?
3170 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3171 def.object = object;
3173 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3175 designer.CreateObject(control, object, false, classObject.instance);
3176 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3186 // Second pass, process instantiation members
3188 for(def = _class.definitions->first; def; def = def.next)
3192 case declarationClassDef:
3194 Declaration decl = def.decl;
3197 case instDeclaration:
3199 Instantiation inst = decl.inst;
3200 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3201 if(instClass && eClass_GetDesigner(instClass))
3204 object = object ? object.next : classObject.instances.first;
3205 control = object.instance;
3209 MembersInit members;
3210 for(members = inst.members->first; members; members = members.next)
3212 switch(members.type)
3214 case dataMembersInit:
3216 if(members.dataMembers)
3219 DataMember curMember = null;
3220 Class curClass = null;
3221 DataMember subMemberStack[256];
3222 int subMemberStackPos = 0;
3224 for(member = members.dataMembers->first; member; member = member.next)
3227 Identifier ident = member.identifiers ? member.identifiers->first : null;
3230 DataMember _subMemberStack[256];
3231 int _subMemberStackPos = 0;
3232 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3236 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3238 if(thisMember && thisMember.memberAccess == publicAccess)
3240 curMember = thisMember;
3241 curClass = curMember._class;
3242 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3243 subMemberStackPos = _subMemberStackPos;
3249 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3250 if(curMember) found = true;
3252 if(found && curMember.isProperty)
3254 Property prop = (Property) curMember;
3255 Class propertyClass = prop.dataTypeClass;
3257 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3259 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3261 FreeType(member.initializer.exp.destType);
3262 member.initializer.exp.destType = MkClassType(propertyClass.name);
3265 ProcessExpressionType(member.initializer.exp);
3267 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3269 Expression computed;
3271 /*char debugExpString[4096];
3272 debugExpString[0] = '\0';
3273 PrintExpression(member.initializer.exp, debugExpString);*/
3275 computed = CopyExpression(member.initializer.exp);
3278 ComputeExpression(computed);
3280 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3282 if(computed.instance.data)
3284 if(computed.instance._class && computed.instance._class.symbol &&
3285 computed.instance._class.symbol.registered &&
3286 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3288 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3290 // This was saved in the control and shouldn't be freed by FreeExpression...
3291 // (Not doing this anymore, incrementing refCount in pass15 instead)
3292 /*if(propertyClass.type == normalClass)
3293 computed.instance.data = null;*/
3297 else if(computed.type == identifierExp)
3299 member.variable = true;
3301 if(eClass_GetDesigner(propertyClass))
3304 char * name = computed.identifier.string;
3305 if(!strcmp(name, "this"))
3308 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3309 member.variable = false;
3314 for(check = classObject.instances.first; check; check = check.next)
3315 if(check.name && !strcmp(name, check.name))
3318 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3319 member.variable = false;
3325 else if(computed.type == memberExp)
3327 member.variable = true;
3328 if(computed.member.exp.type == identifierExp)
3330 char * name = computed.member.exp.identifier.string;
3331 if(!strcmp(name, "this"))
3333 char * name = computed.member.member.string;
3336 for(check = classObject.instances.first; check; check = check.next)
3337 if(check.name && !strcmp(name, check.name))
3340 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3341 member.variable = false;
3349 for(check = classObject.instances.first; check; check = check.next)
3351 if(check.name && !strcmp(name, check.name))
3353 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3356 DataValue value { };
3357 GetProperty(getProperty, check.instance, &value);
3358 SetProperty(prop, control, value);
3359 member.variable = false;
3367 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3368 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3370 String temp = new char[strlen(computed.string)+1];
3371 ReadString(temp, computed.string);
3372 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3376 member.variable = true;
3378 FreeExpression(computed);
3383 Expression computed = CopyExpression(member.initializer.exp);
3386 ComputeExpression(computed);
3387 if(computed.isConstant)
3389 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3391 if(!strcmp(propertyClass.dataTypeString, "float"))
3392 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3393 else if(!strcmp(propertyClass.dataTypeString, "double"))
3394 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3396 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3398 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3400 String temp = new char[strlen(computed.string)+1];
3401 ReadString(temp, computed.string);
3402 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3407 member.variable = true;
3409 FreeExpression(computed);
3415 member.variable = true;
3417 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3418 member.initializer.exp.type == memberExp) // identifierExp
3420 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3421 if(method && method.type == virtualMethod)
3424 // Maintain a list in FunctionDefinition of who is attached to it
3425 for(def = _class.definitions->first; def; def = def.next)
3427 if(def.type == functionClassDef)
3429 ClassFunction function = def.function;
3430 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3431 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3433 function.attached.Add(OldLink { data = method });
3434 // Reference this particular instance?
3449 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3460 //designer.CreateObject(instance, classObject, true, null);
3461 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3463 designer.PostCreateObject(instance, classObject, true, null);
3465 //instance.state = Hidden;
3466 //instance.Create();
3467 //instance.SetState(Normal, true, 0);
3476 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3480 // Restore Selection
3481 if(selectedClassName)
3484 for(oClass = classes.first; oClass; oClass = oClass.next)
3486 if(!strcmp(oClass.name, selectedClassName))
3488 this.oClass = oClass;
3492 delete selectedClassName;
3501 for(check = this.oClass.instances.first; check; check = check.next)
3503 if(check.name && !strcmp(check.name, selectedName))
3505 this.selected = check;
3511 if(this.oClass.instances.first)
3512 this.selected = this.oClass.instances.first;
3514 this.selected = this.oClass;
3517 else if(selectedPos == -1 || !this.oClass.instances.count)
3518 this.selected = this.oClass;
3524 if(selectedPos > this.oClass.instances.count)
3526 for(check = this.oClass.instances.first; check; check = check.next)
3528 if(selectedPos == pos++)
3530 this.selected = check;
3538 this.oClass = classes.first;
3539 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3541 delete selectedName;
3542 SetSymbolsDir(null);
3544 if(sheet.codeEditor == this)
3545 sheet.SelectObject(selected);
3548 codeModified = false;
3550 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3553 InvokeParameters(false, false, false);
3556 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3562 ChangeWorkingDir(oldWorkDir);
3564 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3565 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3566 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3567 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3568 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3570 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3572 if(inUseDebug && ide.projectView)
3573 ide.debugger.EvaluateWatches();
3578 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3581 Window control = (Window)object.instance;
3582 ObjectInfo classObject = object.oClass;
3584 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3586 if(!strcmp(_class.name, "DesignerBase")) return;
3588 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3590 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3591 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3593 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3594 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3596 Class dataType = prop.dataTypeClass;
3598 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3602 if(dataType.type == structClass)
3604 void * dataForm = new0 byte[dataType.structSize];
3605 void * dataTest = new0 byte[dataType.structSize];
3607 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3608 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3610 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3612 char tempString[1024] = "";
3614 bool needClass = true;
3618 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3620 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3622 eClass_FindNextMember(_class, curClass, curMember, null, null);
3623 if(*curMember != (DataMember)prop)
3624 f.Printf("%s = ", prop.name);
3626 *curMember = (DataMember)prop;
3627 *curClass = curMember->_class;
3630 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3632 f.Printf("%s", string);
3639 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3641 void * dataForm, * dataTest;
3643 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3644 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3646 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3648 char tempString[1024] = "";
3653 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3655 eClass_FindNextMember(_class, curClass, curMember, null, null);
3656 if(*curMember != (DataMember)prop)
3657 f.Printf("%s = ", prop.name);
3658 *curMember = (DataMember)prop;
3659 *curClass = curMember->_class;
3661 if(eClass_GetDesigner(dataType))
3663 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3664 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3665 f.Printf("this", prop.name);
3668 //ObjectInfo classObject;
3669 //for(classObject = classes.first; classObject; classObject = classObject.next)
3673 for(object = classObject.instances.first; object; object = object.next)
3675 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3677 f.Printf("%s", object.name);
3684 bool needClass = true;
3685 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3686 f.Printf("%s", string);
3693 bool needClass = true;
3694 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3696 if(!strcmp(dataType.dataTypeString, "char *"))
3699 OutputString(f, string);
3703 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3705 f.Printf("%s", string);
3708 *lastIsMethod = false;
3713 DataValue dataForm, dataTest;
3715 GetProperty(prop, control, &dataForm);
3716 GetProperty(prop, test, &dataTest);
3718 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3721 char tempString[1024] = "";
3722 SetProperty(prop, test, dataForm);
3724 if(dataType.type != bitClass)
3726 bool needClass = true;
3728 if(dataType.type == enumClass)
3731 Class enumClass = eSystem_FindClass(privateModule, "enum");
3732 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3734 for(value = e.values.first; value; value = value.next)
3736 if((int)value.data == dataForm.i)
3738 string = value.name;
3744 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3746 if(string && string[0])
3751 eClass_FindNextMember(_class, curClass, curMember, null, null);
3752 if(*curMember != (DataMember)prop)
3753 f.Printf("%s = ", prop.name);
3754 *curMember = (DataMember)prop;
3755 *curClass = curMember->_class;
3757 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3758 f.Printf("%sf", string);
3760 f.Printf("%s", string);
3764 else if(dataType.type == bitClass)
3766 bool needClass = true;
3768 if(*prev) f.Printf(", ");
3770 eClass_FindNextMember(_class, curClass, curMember, null, null);
3771 if(*curMember != (DataMember)prop)
3772 f.Printf("%s = ", prop.name);
3773 *curMember = (DataMember)prop;
3774 *curClass = curMember->_class;
3776 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3778 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3780 f.Printf("%s", string);
3782 *lastIsMethod = false;
3792 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3794 Instantiation inst = object.instCode;
3795 Window control = (Window)object.instance;
3797 bool methodPresent = false;
3799 bool lastIsMethod = true;
3800 ObjectInfo classObject = object.oClass;
3806 // Instance removed, delete it
3807 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3809 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3810 position = inst.loc.end.pos + 1;
3814 bool multiLine = false;
3817 // Check if it's an unnamed instance
3820 f.Seek(inst.nameLoc.start.pos - position, current);
3821 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3822 position = inst.nameLoc.end.pos;
3824 f.Printf(object.name);
3829 if(isspace(ch) && ch != '\n')
3831 f.Seek(-1, current);
3839 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3841 f.Seek(pos - position, current);
3846 f.Seek(-1, current);
3855 f.Puts(object.name);
3860 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3861 methodPresent = true;
3869 if(ch == OpenBracket)
3875 // TODO: Simplify this?
3884 f.Seek(-1, current);
3885 DeleteJunkBefore(f, position, &position);
3897 if(ch == '\n') { toDelete = count; count = 0; }
3898 else if(isspace(ch)) count++;
3901 f.Seek(-1, current);
3905 toDelete += count - 6;
3915 f.Seek(-toDelete-count, current);
3916 f.DeleteBytes(toDelete);
3917 f.Seek(count, current);
3920 DeleteJunkBefore(f, position, &position);
3922 // Removed this here as it was adding trailing spaces when adding a method
3927 for(c = 0; c<toAdd; c++)
3934 methodPresent = multiLine;
3936 //if(!prev) -- always false
3937 f.Printf(methodPresent ? "\n " : " ");
3942 // Instance not there, create a brand new one
3943 DeleteJunkBefore(f, position, &position);
3944 f.Printf(*firstObject ? "\n\n" : "\n");
3945 *firstObject = false;
3947 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3948 methodPresent = true;
3953 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3955 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3960 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3962 f.Printf(" %s %c ", control._class.name, OpenBracket);
3968 Instance test = eInstance_New(control._class);
3969 DataMember curMember = null;
3970 Class curClass = null;
3973 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3977 // Attach Method here
3978 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3980 if(prev) f.Printf(", ");
3981 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3986 if(inst && !object.deleted)
3988 MembersInit members;
3989 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3991 DeleteJunkBefore(f, position, &position);
3993 // Instance already there, clear out the properties
3994 for(members = inst.members ? inst.members->first : null; members; members = members.next)
3996 if(members.type == dataMembersInit)
4000 if(members.dataMembers)
4002 bool keptMember = false;
4003 MemberInit lastKept = null;
4005 for(member = members.dataMembers->first; member; member = member.next)
4007 Identifier ident = member.identifiers ? member.identifiers->first : null;
4008 bool deleted = false;
4010 // For now delete if it's not a method
4011 if(!member.variable) // && ident)
4013 if(!ident || !ident.next)
4015 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
4018 f.Seek(member.loc.start.pos - position, current);
4019 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4020 position = member.loc.end.pos;
4025 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
4026 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
4027 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4029 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
4030 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
4032 f.Seek(member.loc.start.pos - position, current);
4033 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4034 position = member.loc.end.pos;
4046 //f.Seek(member.loc.start.pos - position, current);
4047 //position = member.loc.start.pos;
4048 DeleteJunkBefore(f, member.loc.start.pos, &position);
4049 if(prev) f.Printf(", ");
4050 else if(keptMember) f.Printf(" ");
4055 if(!keptMember || !members.next)
4060 if(keptMember && lastKept != members.dataMembers->last)
4065 f.Seek(-1, current);
4071 f.Seek(-1, current);
4074 else if(!isspace(ch))
4076 f.Seek(-2, current);
4081 f.DeleteBytes(count);
4084 f.Seek(members.loc.end.pos - position, current);
4089 f.Seek(-1, current);
4091 position = members.loc.end.pos + 1;
4095 f.Seek(-1, current);
4096 position = members.loc.end.pos;
4102 lastIsMethod = false;
4107 DeleteJunkBefore(f, position, &position);
4110 if(lastKept != members.dataMembers->last)
4115 f.Seek(-1, current);
4121 f.Seek(-1, current);
4124 else if(!isspace(ch))
4126 f.Seek(-2, current);
4131 f.DeleteBytes(count);
4135 f.Seek(members.loc.end.pos - position, current);
4136 position = members.loc.end.pos;
4140 lastIsMethod = true;
4143 lastIsMethod = false;
4149 f.Seek(members.loc.end.pos - position, current);
4150 position = members.loc.end.pos;
4152 lastIsMethod = true;
4155 else if(members.type == methodMembersInit)
4157 if(this.methodAction == actionDeleteMethod && members.function == function);
4159 methodPresent = true;
4161 // Delete instance method here
4162 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4163 members.function == function)
4165 if(this.moveAttached && !*text)
4166 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4168 DeleteJunkBefore(f, members.loc.start.pos, &position);
4169 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4170 position = members.loc.end.pos + 1;
4175 DeleteJunkBefore(f, position, &position);
4179 DeleteJunkBefore(f, members.loc.start.pos, &position);
4180 lastIsMethod = true;
4184 f.Seek(members.loc.end.pos - position, current);
4185 position = members.loc.end.pos;
4187 DeleteJunkBefore(f, position, &position);
4196 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4198 Method method = this.method;
4199 DeleteJunkBefore(f, position, &position);
4205 if(!method.dataType)
4206 method.dataType = ProcessTypeString(method.dataTypeString, false);
4209 Type dataType = method.dataType;
4210 Type returnType = dataType.returnType;
4213 if(this.moveAttached)
4215 // Move function here:
4216 int newLen = strlen(method.name);
4221 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4223 // First change name of function
4224 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4225 *textSize += newLen - movedFuncIdLen;
4226 memcpy(*text + movedFuncIdPos, method.name, newLen);
4228 // Second, tab right
4231 for(c = 0; (*text)[c]; )
4234 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4237 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4238 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4242 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4252 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4254 // ADDING METHOD HERE
4256 OutputType(f, returnType, false);
4259 if(dataType.thisClass)
4261 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4263 if(dataType.thisClass.shortName)
4264 f.Printf(dataType.thisClass.shortName);
4266 f.Printf(dataType.thisClass.string);
4270 f.Printf(method.name);
4272 for(param = dataType.params.first; param; param = param.next)
4274 OutputType(f, param, true);
4279 f.Printf(" %c\n\n", OpenBracket);
4281 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4283 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4284 f.Printf(" return true;\n");
4285 else if(returnType.kind != voidType)
4286 f.Printf(" return 0;\n");
4291 if(returnType.kind != voidType)
4292 f.Printf("return ");
4293 f.Printf("%s::%s(", control._class.name, method.name);
4294 for(param = dataType.params.first; param; param = param.next)
4296 if(param.prev) f.Printf(", ");
4297 if(param.kind != voidType)
4298 f.Printf(param.name);
4302 f.Printf(" %c\n", CloseBracket);
4308 if(!object.instCode)
4309 f.Printf(methodPresent ? " %c;" : "%c;", CloseBracket);
4310 else if(!object.deleted)
4312 // Turn this into a multiline instance when adding a method
4313 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4315 f.Printf(methodPresent ? "\n " : " ");
4317 f.Seek(inst.loc.end.pos + 1 - position, current);
4318 position = inst.loc.end.pos + 1;
4323 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4326 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4328 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4330 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4332 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4333 if(prop && prop.isProperty && !prop.conversion)
4335 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4336 (!prop.IsSet || prop.IsSet(classObject.instance)))
4338 Class dataType = prop.dataTypeClass;
4339 char tempString[1024] = "";
4341 bool specify = false;
4344 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4345 if(member && member._class == regClass)
4349 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4351 if(dataType && dataType.type == structClass)
4353 void * dataForm = new0 byte[dataType.structSize];
4354 void * dataTest = new0 byte[dataType.structSize];
4356 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4357 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4359 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4361 bool needClass = true;
4363 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4364 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4366 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4368 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4373 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4375 void * dataForm, * dataTest;
4377 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4378 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4380 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4382 char tempString[1024] = "";
4384 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4386 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4388 // Shouldn't go here ...
4389 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4393 bool needClass = true;
4395 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4397 if(!strcmp(dataType.dataTypeString, "char *"))
4399 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4400 OutputString(f, string);
4404 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4406 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4412 DataValue dataForm, dataTest;
4414 GetProperty(prop, classObject.instance, &dataForm);
4415 GetProperty(prop, test, &dataTest);
4417 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4419 SetProperty(prop, test, dataForm);
4420 if(dataType.type == bitClass)
4422 bool needClass = true;
4423 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4425 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4427 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4431 bool needClass = true;
4432 if(dataType.type == enumClass)
4435 Class enumClass = eSystem_FindClass(privateModule, "enum");
4436 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4438 for(value = e.values.first; value; value = value.next)
4440 if((int)value.data == dataForm.i)
4442 string = value.name;
4448 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4449 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4450 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4452 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4461 void UpdateFormCode()
4464 if(!parsing) return;
4471 else if(formModified)
4473 EditBoxStream f { editBox = editBox };
4477 Identifier movedFuncId;
4478 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4479 ObjectInfo classObject;
4485 movedFuncId = GetDeclId(function.declarator);
4486 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4487 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4490 for(classObject = classes.first; classObject; classObject = classObject.next)
4493 ClassDefinition classDef = classObject.classDefinition;
4494 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4497 bool firstObject = true;
4498 ObjectInfo object = classObject.instances.first;
4499 bool lastIsDecl = false;
4501 if(!classObject.modified) continue;
4503 test = eInstance_New(regClass);
4506 // Put it in the same desktop window...
4507 designer.PrepareTestObject(test);
4509 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4510 //f.Printf("%c\n\n", OpenBracket);
4512 // Change the _class name
4513 f.Seek(classDef.nameLoc.start.pos - position, current);
4514 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4515 f.Printf(classObject.name);
4516 position = classDef.nameLoc.end.pos;
4519 // Go to block start, delete all until no white space, put \n
4523 f.Seek(classDef.blockStart.end.pos - position, current);
4524 position = classDef.blockStart.end.pos;
4526 for(; f.Getc(&ch); count++)
4530 f.Seek(-1, current);
4540 f.Seek(-count, current);
4542 f.DeleteBytes(count-back);
4544 position += count-back;
4547 // Output properties
4548 OutputClassProperties(classObject.instance._class, classObject, f, test);
4550 for(def = classDef.definitions->first; def; def = def.next)
4554 case defaultPropertiesClassDef:
4556 bool keptMember = false;
4558 MemberInit lastKept = null;
4561 DeleteJunkBefore(f, def.loc.start.pos, &position);
4563 // This was adding blank spaces between comment and properties -- What was it for?
4566 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4568 Identifier ident = propDef.identifiers->first;
4569 bool deleted = false;
4571 // For now delete if it's a prop
4572 if(!propDef.variable && ident)
4576 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4579 f.Seek(propDef.loc.start.pos - position, current);
4580 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4581 position = propDef.loc.end.pos;
4586 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4587 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4589 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4590 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4592 f.Seek(propDef.loc.start.pos - position, current);
4593 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4594 position = propDef.loc.end.pos;
4612 f.Seek(def.loc.end.pos - position - 1, current);
4617 f.Seek(-1, current);
4620 position = def.loc.end.pos;
4624 if(lastKept != def.defProperties->last)
4629 f.Seek(-1, current);
4635 f.Seek(-1, current);
4638 else if(!isspace(ch))
4640 f.Seek(-2, current);
4645 f.DeleteBytes(count);
4649 f.Seek(def.loc.end.pos - position, current);
4650 position = def.loc.end.pos;
4655 case declarationClassDef:
4657 Declaration decl = def.decl;
4659 if(decl.type == instDeclaration)
4661 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4663 while(def.object && object != def.object)
4665 if(object /*&& ((ObjectInfo)def.object).modified*/)
4666 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4667 object = object.next;
4670 DeleteJunkBefore(f, def.loc.start.pos, &position);
4671 f.Printf(firstObject ? "\n\n " : "\n ");
4672 firstObject = false;
4674 if(def.object && ((ObjectInfo)def.object).modified)
4675 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4677 object = object ? object.next : null;
4681 DeleteJunkBefore(f, def.loc.start.pos, &position);
4682 f.Printf(firstObject ? "\n\n " : "\n ");
4683 firstObject = false;
4689 DeleteJunkBefore(f, def.loc.start.pos, &position);
4690 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4695 case functionClassDef:
4697 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4698 if(!def.function.body) continue;
4702 DeleteJunkBefore(f, def.loc.start.pos, &position);
4705 // Delete _class methods
4706 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4707 def.function == function)
4712 if(moveAttached && !text)
4714 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4717 f.Seek(def.loc.end.pos - position, current);
4718 for(; f.Getc(&ch); count++)
4722 f.Seek(-1, current);
4726 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4728 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4729 position = def.loc.end.pos + count;
4732 // In case of detaching methods in the _class, simply rename the method
4733 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4735 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4736 f.DeleteBytes(movedFuncIdLen);
4738 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4741 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4742 function == def.function)
4744 // In case of attaching methods in the _class, simply rename the method
4745 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4746 position = function.loc.start.pos + movedFuncIdPos;
4747 f.DeleteBytes(movedFuncIdLen);
4748 if(method.dataType.thisClass)
4749 f.Printf("%s::", method.dataType.thisClass.string);
4750 f.Puts(method.name);
4751 position += movedFuncIdLen;
4756 DeleteJunkBefore(f, def.loc.start.pos, &position);
4757 if(def.type == memberAccessClassDef)
4760 firstObject = false;
4770 f.Seek(def.loc.end.pos - position, current);
4771 position = def.loc.end.pos;
4774 // Output attached methods
4775 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4777 DeleteJunkBefore(f, position, &position);
4778 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4781 // ********** INSTANCES ***************
4782 for(; object; object = object.next)
4784 if(!object.instCode)
4786 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4790 DeleteJunkBefore(f, position, &position);
4792 // ****************** METHODS ***********************
4793 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4795 // If detaching an instance method
4796 if(selected != classObject)
4798 int newLen = strlen(methodName);
4801 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4802 // Tab selection left
4805 for(c = 0; text[c]; )
4808 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4809 memmove(text+start, text+start+i, textSize+1-start-i);
4812 for(; text[c] && text[c] != '\n'; c++);
4818 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4819 textSize += newLen - movedFuncIdLen;
4820 memcpy(text + movedFuncIdPos, methodName, newLen);
4827 if(methodAction == actionAddMethod && selected == classObject)
4829 Method method = this.method;
4831 if(!method.dataType)
4832 method.dataType = ProcessTypeString(method.dataTypeString, false);
4834 // ADDING METHOD HERE
4836 Type dataType = method.dataType;
4837 Type returnType = dataType.returnType;
4839 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4843 OutputType(f, returnType, false);
4846 if(dataType.thisClass && !dataType.classObjectType)
4848 if(dataType.thisClass.shortName)
4849 f.Printf(dataType.thisClass.shortName);
4851 f.Printf(dataType.thisClass.string);
4854 f.Printf(method.name);
4856 for(param = dataType.params.first; param; param = param.next)
4858 OutputType(f, param, true);
4863 f.Printf(" %c\n\n", OpenBracket);
4865 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4867 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4868 f.Printf(" return true;\n");
4869 else if(returnType && returnType.kind != voidType)
4870 f.Printf(" return 0;\n");
4875 if(returnType.kind != voidType)
4876 f.Printf("return ");
4878 char * name = ((Specifier)classDef.baseSpecs->first).name;
4879 Symbol _class = FindClass(name);
4880 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4882 for(param = dataType.params.first; param; param = param.next)
4884 if(param.prev) f.Printf(", ");
4885 if(param.kind != voidType)
4886 f.Printf(param.name);
4891 f.Printf(" %c", CloseBracket);
4895 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4907 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4908 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4912 codeModified = false;
4913 formModified = false;
4915 moveAttached = false;
4920 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4923 ClassFunction function = null;
4926 ObjectInfo object = this.selected;
4928 if(object && object == this.oClass)
4930 ClassDefinition classDef = object.oClass.classDefinition;
4932 if(classDef && classDef.definitions)
4934 for(def = classDef.definitions->first; def; def = def.next)
4936 if(def.type == functionClassDef && def.function.declarator)
4938 if(!strcmp(def.function.declarator.symbol.string, methodName))
4940 function = def.function;
4945 else if(def.type == defaultPropertiesClassDef)
4949 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4951 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4952 if(ident && !ident.next)
4954 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4958 propLoc = propDef.loc;
4961 ClassDefinition classDef = object.oClass.classDefinition;
4963 if(classDef.definitions)
4965 for(def = classDef.definitions->first; def; def = def.next)
4967 if(def.type == functionClassDef)
4969 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4971 function = def.function;
4990 Instantiation inst = object.instCode;
4992 // Check here to see if the method already exists, no need to call ModifyCode in that case
4993 if(inst && inst.members)
4995 MembersInit members;
4996 for(members = inst.members->first; members; members = members.next)
4998 switch(members.type)
5000 case dataMembersInit:
5002 if(members.dataMembers)
5005 for(member = members.dataMembers->first; member; member = member.next)
5007 Identifier ident = member.identifiers ? member.identifiers->first : null;
5008 if(ident && !ident.next)
5010 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
5014 propLoc = member.loc;
5017 ClassDefinition classDef = object.oClass.classDefinition;
5019 if(classDef.definitions)
5021 for(def = classDef.definitions->first; def; def = def.next)
5023 if(def.type == functionClassDef)
5025 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
5027 function = def.function;
5036 // TODO: Fix memory leak
5037 function = ClassFunction
5039 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5051 case methodMembersInit:
5053 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5055 function = members.function;
5067 if(functionPtr) *functionPtr = function;
5071 void GoToMethod(char * methodName /*Method method*/)
5075 ObjectInfo object = selected;
5076 EditBoxStream f { editBox = editBox };
5077 ClassFunction function = null;
5078 bool atChar = false;
5082 Location propLoc = { {0,0,-1} };
5085 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5086 if(function && function.body)
5089 f.Seek(function.body.loc.start.pos+1, current);
5099 f.Seek(-1, current);
5104 else if(!isspace(ch))
5106 f.Seek(-1, current);
5112 else if(propLoc.start.pos > -1)
5114 f.Seek(propLoc.start.pos, current);
5117 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5119 if(function || propLoc.start.pos > -1)
5121 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5122 editBox.CenterOnCursor();
5123 SetState(normal, false, 0);
5126 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5128 FreeClassFunction(function);
5134 void FindCompatibleMethods(Method method, OldList compatible)
5136 ClassDefinition classDef = this.oClass.classDefinition;
5137 if(classDef && classDef.definitions)
5140 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5143 Symbol classSym { };
5144 Symbol selectedClass;
5145 if(this.selected == this.oClass)
5146 selectedClass = classSym;
5148 selectedClass = FindClass(this.selected.instance._class.name);
5150 regClass.name = classDef._class.name;
5151 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5152 for(def = classDef.definitions->first; def; def = def.next)
5154 if(def.type == functionClassDef && def.function.declarator)
5156 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5158 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5161 Type type = def.function.declarator.symbol.type;
5162 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5164 compatible.Add(OldLink { data = def.function });
5170 if(this.oClass && this.oClass.instance)
5172 classSym.registered = regClass;
5173 //classSym.registered = this.oClass.oClass;
5175 for(_class = regClass.base; _class; _class = _class.base)
5178 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5180 // TODO: Understand why these functions popup in attach list
5181 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5183 if(!testMethod.dataType)
5184 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5186 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5187 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5188 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5190 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5191 // ClassFunction function { };
5192 FunctionDefinition function { };
5194 function.declarator = Declarator { };
5195 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5196 excludedSymbols.Add(function.declarator.symbol);
5198 compatible.Add(OldLink { data = function });
5209 void AddMethod(Method method)
5213 char methodName[1024];
5214 strcpy(methodName, method.name);
5215 if(!FindMethod(methodName, null, null))
5217 methodAction = actionAddMethod;
5218 this.method = method;
5222 GoToMethod(methodName);
5226 void DeleteMethod(ClassFunction function)
5230 methodAction = actionDeleteMethod;
5231 this.function = function;
5239 void AttachMethod(Method method, ClassFunction function)
5243 // If it's an instance we'll ask if we want to move it inside...
5244 if(!function.attached.count && function.body)
5246 // Find the function in the _class to check if it's a virtual function
5247 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5248 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5249 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5251 for(def = this.classDefinition.first; def; def = def.next)
5253 if(def.type == functionClassDef)
5255 if(def.function == function)
5260 if(!method || method.type != virtualMethod)
5263 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5264 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5266 moveAttached = true;
5271 methodAction = actionAttachMethod;
5272 this.method = method;
5273 this.function = function;
5280 void ReAttachMethod(Method method, ClassFunction function)
5284 // If it's an instance we'll ask if we want to move it inside...
5285 if(!function.attached.count && function.body)
5287 // Find the function in the _class to check if it's a virtual function
5288 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5289 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5290 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5292 for(def = this.classDefinition.first; def; def = def.next)
5294 if(def.type == functionClassDef)
5296 if(def.function == function)
5301 if(!method || method.type != virtualMethod)
5304 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5305 if(MessageBox { type = yesNo, master = parent, text = title,
5306 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5308 moveAttached = true;
5313 methodAction = actionReattachMethod;
5314 this.method = method;
5315 this.function = function;
5322 void DetachMethod(Method method, ClassFunction function, int type)
5330 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5331 master = sheet, text = $"Name detached method", background = formColor
5335 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5336 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5340 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5341 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5345 dialog, anchor = { left = 5, right = 5, top = 5 }
5347 sprintf(methodName, "%s_%s", selected.name, method.name);
5348 nameBox.contents = methodName;
5350 result = dialog.Modal() == ok;
5351 strcpy(methodName, nameBox.contents);
5356 // If the method is not attached, move it outside
5359 // Add this class to the methodName
5360 char name[1024] = "";
5362 if(this.selected != this.oClass && !method.dataType.thisClass)
5364 strcat(name, this.selected.instance._class.name);
5366 strcat(name, this.methodName);
5367 strcpy(this.methodName, name);
5369 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5371 strcat(name, method.dataType.thisClass.string);
5373 strcat(name, this.methodName);
5374 strcpy(this.methodName, name);
5377 this.moveAttached = true;
5380 this.methodAction = actionDetachMethod;
5381 this.method = method;
5382 this.function = function;
5389 void AddObject(Instance instance, ObjectInfo * object)
5393 //*object = _class.instances.Add(sizeof(ObjectInfo));
5394 *object = ObjectInfo { };
5395 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5396 (*object).oClass = oClass;
5397 (*object).instance = instance;
5402 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5404 // if(strcmp(name, this.oClass.instance.name))
5407 for(check = oClass.instances.first; check; check = check.next)
5408 if(!check.deleted && check.name && !strcmp(name, check.name))
5412 (*object).name = CopyString(name);
5417 toolBox.controlClass = null;
5421 //sheet.AddObject(*object, (*object).name, TypeData, true);
5426 void EnsureUpToDate()
5428 if(sheet && codeModified && parsing)
5432 void SelectObject(ObjectInfo object)
5435 oClass = object ? object.oClass : null;
5437 designer.SelectObject(object, object ? object.instance : null);
5440 void SelectObjectFromDesigner(ObjectInfo object)
5443 sheet.SelectObject(object);
5446 void EnumerateObjects(Sheet sheet)
5450 for(oClass = classes.first; oClass; oClass = oClass.next)
5456 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5457 for(object = oClass.instances.first; object; object = object.next)
5458 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5461 sheet.SelectObject(selected);
5466 designer.AddObject();
5469 void DeleteObject(ObjectInfo object)
5471 delete object.instance;
5472 object.deleted = true;
5473 object.modified = true;
5474 object.oClass.modified = true;
5476 if(selected == object)
5478 bool looped = false;
5479 ObjectInfo select = object;
5483 select = select.prev;
5487 select = object.oClass.instances.last;
5494 sheet.SelectObject(select ? select : oClass);
5497 if(!object.instCode && object.oClass != object)
5500 oClass.instances.Delete(object);
5503 if(sheet.codeEditor == this)
5504 sheet.DeleteObject(object);
5507 void RenameObject(ObjectInfo object, char * name)
5511 // Validate the name:
5512 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5513 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5516 for(c = 0; name[c]; c++)
5517 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5525 object.name = (name && name[0]) ? CopyString(name) : null;
5527 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5531 void DesignerModifiedObject()
5533 sheet.ListProperties(false);
5537 void ListSubMembers(Type member)
5541 for(subMember = member.members.first; subMember; subMember = subMember.next)
5545 DataRow row = membersList.AddString(subMember.name);
5546 row.icon = icons[typeData];
5550 ListSubMembers(subMember);
5555 void ListSubDataMembers(DataMember member, bool isPrivate)
5557 DataMember subMember;
5558 for(subMember = member.members.first; subMember; subMember = subMember.next)
5560 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5564 DataRow row = membersList.AddString(subMember.name);
5565 BitmapResource bitmap = null;
5566 if(!subMember.dataType)
5567 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5569 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5571 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5574 bitmap = { bitmapName };
5575 membersList.AddResource(bitmap);
5578 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5582 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5588 void ListClassMembers(Class whatClass, bool methodsOnly)
5591 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5592 bool isPrivate = false;
5594 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5596 Method method, methodIt;
5598 DataMember memberIt;
5600 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5602 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5603 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5605 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5607 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5609 DataRow row = membersList.FindString(method.name);
5612 row = membersList.AddString(method.name);
5614 if(!method.dataType)
5615 method.dataType = ProcessTypeString(method.dataTypeString, false);
5617 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5625 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5629 if(memberIt.isProperty)
5631 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5633 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5637 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5639 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5642 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5648 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5650 if(member.isProperty)
5652 Property prop = (Property) member;
5653 if(!membersList.FindString(prop.name))
5655 DataRow row = membersList.AddString(prop.name);
5656 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5659 else if(member.name && !membersList.FindString(member.name))
5661 DataRow row = membersList.AddString(member.name);
5663 BitmapResource bitmap = null;
5664 if(!member.dataType)
5665 member.dataType = ProcessTypeString(member.dataTypeString, false);
5667 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5669 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5672 bitmap = { bitmapName };
5673 membersList.AddResource(bitmap);
5676 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5679 ListSubDataMembers(member, member.memberAccess == privateAccess);
5683 if(_class.inheritanceAccess == privateAccess)
5686 if(_class.module != privateModule) break;
5691 void ListClassMembersMatch(Class whatClass, Type methodType)
5694 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5695 bool isPrivate = false;
5697 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5703 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5705 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5707 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5709 if(!method.dataType)
5710 method.dataType = ProcessTypeString(method.dataTypeString, false);
5712 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5714 DataRow row = membersList.FindString(method.name);
5717 row = membersList.AddString(method.name);
5718 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5724 if(_class.inheritanceAccess == privateAccess)
5727 if(_class.module != privateModule) break;
5732 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5735 bool isPrivate = false;
5736 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5742 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5744 if(method.type == virtualMethod)
5746 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5748 DataRow row = membersList.FindString(method.name);
5751 row = membersList.AddString(method.name);
5753 if(!method.dataType)
5754 method.dataType = ProcessTypeString(method.dataTypeString, false);
5756 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5762 for(member = _class.membersAndProperties.first; member; member = member.next)
5764 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5766 if(member.isProperty)
5768 Property prop = (Property)member;
5770 DataRow row = membersList.AddString(prop.name);
5771 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5774 else if(member.name && (!curString || strcmp(curString, member.name)))
5776 DataRow row = membersList.AddString(member.name);
5778 BitmapResource bitmap = null;
5779 if(!member.dataType)
5780 member.dataType = ProcessTypeString(member.dataTypeString, false);
5782 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5784 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5787 bitmap = { bitmapName };
5788 membersList.AddResource(bitmap);
5791 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5794 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5797 if(_class.inheritanceAccess == privateAccess)
5800 if(_class.module != privateModule) break;
5805 void ListMembers(Type type)
5807 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5811 if(type.kind == classType)
5814 ListClassMembers(type._class.registered, false);
5819 for(member = type.members.first; member; member = member.next)
5823 DataRow row = membersList.AddString(member.name);
5824 row.icon = icons[typeData];
5826 else if(member.kind == structType || member.kind == unionType)
5827 ListSubMembers(member);
5833 void ListModule(Module mainModule, int recurse, bool listClasses)
5836 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5837 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5838 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5839 for(module = mainModule.application.allModules.first; module; module = module.next)
5841 if(ModuleVisibility(mainModule, module))
5842 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5846 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5853 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5855 Class _class = link.data;
5856 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5858 DataRow row = membersList.AddString(_class.name);
5859 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5864 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5866 DefinedExpression definedExp = link.data;
5867 DataRow row = membersList.AddString(link /*definedExp*/.name);
5868 row.icon = icons[typeData];
5871 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5873 GlobalFunction function = link.data;
5874 DataRow row = membersList.AddString(link /*function*/.name);
5875 row.icon = icons[typeMethod];
5879 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5881 if(recurse != 2 && listClasses)
5883 if(!membersList.FindString(ns->name))
5885 DataRow row = membersList.AddString(ns->name);
5886 row.icon = icons[typeNameSpace];
5891 ListNameSpace(ns, 2, listClasses);
5895 void ListEnumValues(Class _class)
5897 List<Class> classes { };
5898 for(; _class && _class.type == enumClass; _class = _class.base)
5899 classes.Insert(null, _class);
5900 for(_class : classes)
5902 EnumClassData enumeration = (EnumClassData)_class.data;
5904 for(item = enumeration.values.first; item; item = item.next)
5906 DataRow row = membersList.AddString(item.name);
5907 row.icon = icons[typeEnumValue];
5913 bool ListEnumsModule(Module mainModule, Type dest)
5915 bool result = false;
5917 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5918 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5919 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5920 for(module = mainModule.application.allModules.first; module; module = module.next)
5922 if(ModuleVisibility(mainModule, module))
5923 result |= ListEnums(module.publicNameSpace, dest);
5928 void ListNameSpaceByString(Module mainModule, char * string)
5930 NameSpace * nameSpace;
5932 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5933 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5934 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5935 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5936 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5937 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5938 for(module = mainModule.application.allModules.first; module; module = module.next)
5940 if(ModuleVisibility(mainModule, module))
5942 nameSpace = FindNameSpace(module.publicNameSpace, string);
5943 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5948 bool ListEnums(NameSpace nameSpace, Type dest)
5951 bool result = false;
5953 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5955 Class _class = link.data;
5956 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *"))) && !dest.classObjectType)) &&
5957 dest.kind != pointerType && dest.kind != ellipsisType)
5959 OldList conversions { };
5961 type.kind = classType;
5962 type._class = FindClass(_class.name);
5963 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5965 ListEnumValues(_class);
5968 conversions.Free(null);
5972 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5974 result |= ListEnums(nameSpace, dest);
5979 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5983 for(c = 0; (ch = name[c]); c++)
5985 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5987 NameSpace * newSpace;
5988 char * spaceName = new char[c - start + 1];
5989 memcpy(spaceName, name + start, c - start);
5990 spaceName[c-start] = '\0';
5991 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5995 nameSpace = newSpace;
6004 return (NameSpace *)nameSpace;
6007 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
6009 bool listedEnums = false;
6010 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
6011 bool listClasses = true;
6013 if(exp && (exp.type == identifierExp || exp.type == memberExp))
6015 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
6016 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
6017 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
6019 if(exp.type == identifierExp)
6020 id = realIdentifier;
6022 if(id && id._class && !id._class.name)
6024 listClasses = false;
6027 else if(id && id._class && id._class.name)
6031 Class _class = id.classSym.registered;
6032 if(_class && _class.type == enumClass)
6034 ListEnumValues(_class);
6037 ListClassMembers(id.classSym.registered, true);
6042 else if(id && colons)
6044 ListNameSpaceByString(this.privateModule, id.string);
6049 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6051 listedEnums = ListEnumsModule(this.privateModule, destType);
6054 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6056 ListEnumValues(destType._class.registered);
6059 ListClassPropertiesAndVirtual(insideClass, null);
6063 else if(destType && destType.kind == enumType)
6067 for(value = destType.members.first; value; value = value.next)
6069 DataRow row = membersList.AddString(value.name);
6070 row.icon = icons[typeEnumValue];
6074 ListClassPropertiesAndVirtual(insideClass, null);
6078 else if(insideClass && !enumOnly)
6080 ListClassPropertiesAndVirtual(insideClass, string);
6083 if(listedEnums && string && string[0])
6085 DataRow row = membersList.FindSubString(string);
6087 listedEnums = false;
6090 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6092 ListClassMembersMatch(GetThisClass(), exp.destType);
6094 else if(!insideClass && !enumOnly && !listedEnums)
6097 Symbol symbol = null;
6101 ListClassMembers(GetThisClass(), false);
6104 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6106 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6108 // Don't list enum values?
6109 //if(symbol.type.kind != TypeEnum)
6110 DataRow row = membersList.FindString(symbol.string);
6113 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6115 row = membersList.AddString(symbol.string);
6116 if(symbol.type && symbol.type.kind == functionType)
6117 row.icon = icons[typeMethod];
6118 else if(symbol.type && symbol.type.kind == enumType)
6120 row.icon = icons[typeEnumValue];
6124 BitmapResource bitmap = null;
6125 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6127 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6130 bitmap = { bitmapName };
6131 membersList.AddResource(bitmap);
6134 row.icon = bitmap ? bitmap : icons[typeData];
6141 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6143 DataRow row = membersList.FindString(symbol.string);
6146 row = membersList.AddString(symbol.string);
6147 if(symbol.type.kind == functionType)
6148 row.icon = icons[typeMethod];
6149 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6151 row.icon = icons[typeClass];
6155 row.icon = icons[typeDataType];
6162 ListModule(this.privateModule, 1, listClasses);
6163 // TODO: Implement this with name space
6167 for(data = globalData.first; data; data = data.next)
6169 DataRow row = membersList.FindString(data.name);
6171 data.dataType = ProcessTypeString(data.dataTypeString, false);
6174 row = membersList.AddString(data.name);
6176 if(data.dataType && data.dataType.kind == TypeEnum)
6178 row.icon = icons[typeEnumValue];
6182 BitmapResource bitmap = null;
6183 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6185 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6188 bitmap = { bitmapName };
6189 membersList.AddResource(bitmap);
6192 row.icon = bitmap ? bitmap : icons[typeData];
6200 DataRow row = membersList.AddString("Min");
6201 row.icon = icons[typeMethod];
6203 row = membersList.AddString("Max");
6204 row.icon = icons[typeMethod];
6206 row = membersList.AddString("Abs");
6207 row.icon = icons[typeMethod];
6209 row = membersList.AddString("Sgn");
6210 row.icon = icons[typeMethod];
6216 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6218 EditBoxStream f { editBox = editBox };
6223 updatingCode = true;
6225 if(!method.dataType)
6226 method.dataType = ProcessTypeString(method.dataTypeString, false);
6228 DeleteJunkBefore(f, function.loc.start.pos, &position);
6229 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6231 // ADDING METHOD HERE
6233 Type dataType = method.dataType;
6234 Type returnType = dataType.returnType;
6236 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6242 if(extraIndent) f.Printf(" ");
6244 OutputType(f, returnType, false);
6248 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6250 if(dataType.thisClass.shortName)
6251 f.Printf(dataType.thisClass.shortName);
6253 f.Printf(dataType.thisClass.string);
6256 f.Printf(method.name);
6258 for(param = dataType.params.first; param; param = param.next)
6260 // Decided not to write void...
6261 if(param.kind != voidType)
6263 OutputType(f, param, true);
6269 if(extraIndent) f.Printf(" ");
6270 f.Printf(" %c\n", OpenBracket);
6272 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6278 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6279 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6281 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6283 if(extraIndent) f.Printf(" ");
6284 f.Printf(" return true;\n");
6286 else if(returnType && returnType.kind != voidType)
6288 if(extraIndent) f.Printf(" ");
6289 f.Printf(" return 0;\n");
6294 if(extraIndent) f.Printf(" ");
6296 if(returnType.kind != voidType)
6297 f.Printf("return ");
6298 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6299 for(param = dataType.params.first; param; param = param.next)
6301 if(param.prev) f.Printf(", ");
6302 if(param.kind != voidType)
6303 f.Printf(param.name);
6309 if(extraIndent) f.Printf(" ");
6310 f.Printf(" %c", CloseBracket);
6315 if(extraIndent) { x1 += 3; x2 += 3; }
6316 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6318 this.updatingCode = false;
6322 // Return false if we overrided a function and don't want to run params listing
6323 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6325 bool didOverride = false;
6326 EditLine line = editBox.line;
6327 char * text = line.text;
6328 int lineNum, charPos;
6329 Expression exp = null;
6332 //Identifier id = null;
6333 Expression memberExp = null;
6334 Identifier realIdentifier = null;
6336 if(!parsing) return true;
6337 if(!privateModule) return !didOverride;
6339 insideFunction = null;
6341 charPos = editBox.charPos + 1;
6342 if(!membersListShown)
6347 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6349 EditBoxStream f { editBox = editBox };
6351 updatingCode = true;
6352 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6356 if(!f.Seek(-1, current))
6359 if(!isspace(ch)) break;
6360 f.Seek(-1, current);
6362 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6364 lineNum = editBox.lineNumber + 1;
6365 charPos = editBox.charPos + 1;
6367 updatingCode = false;
6370 if(!membersListShown)
6372 memberExp = FindExpTree(ast, lineNum, charPos);
6373 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6378 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6380 EditBoxStream f { editBox = editBox };
6383 updatingCode = true;
6385 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6388 if(ch == '}' || ch == ',' || ch == ')')
6390 f.Seek(-1, current);
6398 if(!f.Seek(-1, current))
6401 if(!isspace(ch)) break;
6402 f.Seek(-1, current);
6406 f.Seek(-1, current);
6408 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6410 lineNum = editBox.lineNumber + 1;
6411 charPos = editBox.charPos + 1;
6413 updatingCode = false;
6416 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6421 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6422 lineNum = editBox.lineNumber + 1;
6423 charPos = editBox.charPos/* + 1*/;
6427 char tempString[1024];
6428 char * string = null;
6429 CodePosition idStart, idEnd;
6431 if(membersListShown)
6433 char * buffer = membersLine.text;
6435 bool firstChar = true;
6437 string = tempString;
6439 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6441 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6442 if(!isSpace) firstChar = false;
6444 string[len++] = buffer[c];
6448 else //if(realIdentifier)//if(id)
6451 char * buffer = id.string;
6453 bool firstChar = true;
6455 string = tempString;
6456 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6458 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6459 if(!isSpace) firstChar = false;
6461 string[len++] = buffer[c];
6467 EditLine editLine = editBox.line;
6468 bool firstChar = true;
6471 string = tempString;
6472 for(y = lineNum-1; y >= 0; y--)
6474 char * buffer = editLine.text;
6475 int lineCount = editLine.count;
6476 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6478 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6483 idEnd.charPos = x + 2;
6488 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6491 idEnd.charPos = x + 2;
6498 if(!isalnum(buffer[x]) && buffer[x] != '_')
6504 memmove(string+1, string, len++);
6505 string[0] = buffer[x];
6509 //if(done || firstChar)
6510 if(done || !firstChar)
6512 editLine = editLine.prev;
6515 if(!strcmp(string, "case"))
6521 else if(!strcmp(string, "return"))
6527 else if(!strcmp(string, "delete"))
6533 else if(!strcmp(string, "new"))
6539 else if(!strcmp(string, "renew"))
6547 idStart.charPos = x + 1;
6548 idStart.line = y + 1;
6551 if(!membersListShown)
6553 membersList.Clear();
6554 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6556 Type type = memberExp.member.exp.expType;
6557 if(pointer == 2 && type)
6559 if(type.kind == pointerType || type.kind == arrayType)
6568 ListSymbols(exp, enumOnly, string, realIdentifier);
6570 membersList.Sort(null, 1);
6575 // Virtual function override
6576 Identifier id = GetDeclId(insideFunction.declarator);
6577 char * string = id ? id.string : null;
6579 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6582 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6583 insideFunction = null;
6586 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6591 if(!didOverride) //insideFunction)
6593 rowCount = membersList.rowCount;
6596 DataRow row = string ? membersList.FindSubString(string) : null;
6597 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6599 char * newString = row.string;
6600 if(!membersListShown)
6602 membersLoc.start.line = idStart.line-1;
6603 membersLoc.start.charPos = idStart.charPos-1;
6604 //membersLoc.end = membersLoc.start;
6605 membersLoc.end.charPos = idEnd.charPos-1;
6606 membersLoc.end.line = idEnd.line-1;
6607 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6608 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6613 membersList.Destroy(0);
6614 membersListShown = false;
6617 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6619 line, membersLoc.start.line, membersLoc.start.charPos,
6620 line, membersLoc.end.line, membersLoc.end.charPos);
6621 editBox.PutS(newString);
6627 row = membersList.FindSubStringi(string);
6629 membersList.currentRow = row;
6630 membersList.currentRow.selected = false;
6633 membersList.currentRow = row;
6635 if(!membersListShown)
6639 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6640 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6641 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6642 editBox.GetCaretPosition(caret);
6643 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6645 membersList.master = this;
6647 caret.y += editBox.GetCaretSize();
6649 membersList.Create();
6652 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6653 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6654 Window parent = membersList.parent;
6656 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6658 y -= editBox.GetCaretSize() + membersList.size.h;
6659 membersAbove = true;
6662 membersAbove = false;
6664 membersList.position = { x, y };
6668 membersLoc.start.line = lineNum - 1;
6670 if(string && string[0])
6672 membersLoc.start.charPos = idStart.charPos-1;
6673 membersLoc.end = membersLoc.start;
6674 //membersLoc.end.charPos = id.loc.end.charPos-1;
6675 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6679 membersLoc.start.charPos = charPos;
6680 membersLoc.end = membersLoc.start;
6681 membersLoc.end.charPos = charPos;
6683 membersListShown = true;
6685 // Hack to keep caret shown
6686 editBox.GetCaretPosition(caret);
6687 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6690 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6696 SetCurrentContext(globalContext);
6699 return !didOverride;
6702 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6704 EditLine line = editBox.line;
6705 char * text = line.text;
6706 int lineNum, charPos;
6707 Expression exp = null;
6711 if(!parsing) return;
6713 charPos = editBox.charPos + 1;
6716 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6718 EditBoxStream f { editBox = editBox };
6721 updatingCode = true;
6722 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6725 if(ch == '}' || ch == ',' || ch == ')')
6727 f.Seek(-1, current);
6735 if(!f.Seek(-1, current))
6738 if(!isspace(ch)) break;
6739 f.Seek(-1, current);
6743 f.Seek(-1, current);
6745 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6747 lineNum = editBox.lineNumber + 1;
6748 charPos = editBox.charPos + 1;
6750 updatingCode = false;
6753 charPos = Min(charPos, l1.count + 1);
6755 FindParamsTree(ast, lineNum, charPos);
6757 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6758 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6760 ::functionType = null;
6761 ::instanceType = null;
6764 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6765 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6769 Window parent = paramsList.parent;
6771 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6774 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6775 // ( Dummy exp: always ends up with same memory)
6777 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6778 editBox.GetCaretPosition(paramsPosition);
6779 this.paramsPosition.y += editBox.GetCaretSize();
6782 FreeType(this.functionType);
6783 FreeType(this.instanceType);
6785 this.functionType = ::functionType;
6786 this.instanceType = ::instanceType;
6788 if(this.functionType) this.functionType.refCount++;
6789 if(this.instanceType) this.instanceType.refCount++;
6791 this.paramsID = ::paramsID;
6792 functionExp = paramsInsideExp;
6794 paramsList.master = this;
6796 paramsList.Create();
6798 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6799 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6801 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6803 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6807 paramsAbove = false;
6808 if(x + paramsList.size.w > parent.clientSize.w)
6810 x = parent.clientSize.w - paramsList.size.w;
6814 paramsList.position = { x, y };
6816 // Hack to keep caret shown
6819 editBox.GetCaretPosition(caret);
6820 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6823 this.paramsShown = true;
6825 else if((!::functionType && !::instanceType) || reposition)
6827 paramsList.Destroy(0);
6828 paramsShown = false;
6830 FreeType(this.functionType);
6831 FreeType(this.instanceType);
6832 this.functionType = null;
6833 this.instanceType = null;
6837 SetCurrentContext(globalContext);
6845 designer.visible = true;
6846 designer.Activate();
6852 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6854 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };
6859 static int nofdigits(int v)
6861 if(v == MININT) return 10 + 1;
6862 if(v < 0) return nofdigits(-v) + 1;