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.NotifyCaretMove(this, editBox, y, x);
1366 editBox.GoToLineNum(y);
1367 editBox.GoToPosition(editBox.line, y, x);
1369 classObject = selected ? selected.oClass : null;
1371 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1372 selected = classObject.instances.last;
1375 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1378 AddObject(control, &object);
1380 designer.CreateObject(control, object, false, classObject.instance);
1381 // designer.PostCreateObject(control, object, false, classObject.instance);
1382 designer.DroppedObject(control, object, false, classObject.instance);
1384 sheet.AddObject(object, object.name, typeData /* className*/, true);
1387 //codeModified = true;
1394 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1396 if(key == ctrlSpace)
1398 membersList.Destroy(0);
1399 membersListShown = false;
1400 InvokeAutoComplete(false, 0, false);
1403 else if(key == Key { space, ctrl = true, shift = true })
1404 InvokeParameters(false, true, false);
1405 else if(key == escape)
1406 ide.RepositionWindows(true);
1407 else if(key == ctrlF7)
1411 ProjectNode node = ide.projectView.GetNodeForCompilationFromWindow(this, false, null, null);
1415 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1416 $"It can't be compiled.");
1417 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1426 bool OnKeyDown(Key key, unichar ch)
1428 CodeEditor editor = (CodeEditor)master;
1429 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1431 if(editor.membersListShown)
1433 editor.membersList.Destroy(0);
1434 editor.membersListShown = false;
1437 if(editor.paramsShown)
1439 editor.paramsList.Destroy(0);
1440 editor.paramsShown = false;
1441 FreeType(editor.functionType);
1442 FreeType(editor.instanceType);
1444 editor.functionType = null;
1445 editor.instanceType = null;
1446 editor.paramsID = -1;
1450 return EditBox::OnKeyDown(key, ch);
1453 void OnVScroll(ScrollBarAction action, int position, Key key)
1455 if(anchor.left.distance)
1457 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1460 EditBox::OnVScroll(action, position, key);
1462 CodeEditor ce = (CodeEditor)parent;
1463 if(ce.openedFileInfo)
1464 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1468 void OnHScroll(ScrollBarAction action, int position, Key key)
1470 EditBox::OnHScroll(action, position, key);
1472 CodeEditor ce = (CodeEditor)parent;
1473 if(ce.openedFileInfo)
1474 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1481 fullRowSelect = false,
1484 borderStyle = bevel;
1485 // size = { 200, 400 };
1487 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1489 DataRow row = listBox.currentRow;
1492 char * string = row.string;
1494 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1496 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1497 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1498 editBox.PutS(string);
1501 membersListShown = false;
1506 bool OnKeyDown(Key key, unichar ch)
1508 CodeEditor editor = (CodeEditor) master;
1509 if(key == escape || key == leftAlt || key == rightAlt ||
1510 (key.ctrl && key.code != left && key.code != right &&
1511 key.code != leftShift && key.code != rightShift && key.code != space))
1514 if(editor.paramsShown)
1518 editor.paramsList.Destroy(0);
1519 editor.paramsShown = false;
1521 if(editor.membersListShown)
1525 editor.membersList.Destroy(0);
1526 editor.membersListShown = false;
1529 FreeType(editor.functionType);
1530 editor.functionType = null;
1532 FreeType(editor.instanceType);
1533 editor.instanceType = null;
1535 editor.paramsID = -1;
1540 return editor.editBox.OnKeyDown(key, ch);
1544 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1546 CodeEditor editor = (CodeEditor)master;
1547 Window rw = previous ? previous.rootWindow : null;
1548 if(!active && rw != editor.paramsList)
1551 editor.membersListShown = false;
1553 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1556 bool OnKeyHit(Key key, unichar ch)
1558 CodeEditor editor = (CodeEditor) master;
1562 case enter: case tab:
1564 DataRow row = currentRow;
1565 if(row && row.selected)
1567 char * string = row.string;
1569 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1570 editor.editBox.Delete(
1571 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1572 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1573 editor.editBox.PutS(string);
1576 editor.membersListShown = false;
1579 editor.editBox.OnKeyHit(key, ch);
1589 return ListBox::OnKeyHit(key, ch);
1595 // If before . or after
1596 //listBox.Destroy(true);
1597 result = editor.editBox.OnKeyHit(key, ch);
1612 clickThrough = true,
1614 borderStyle = contour,
1616 background = { 255,255,225 },
1618 OnKeyDown = membersList.OnKeyDown;
1620 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1622 CodeEditor editor = (CodeEditor)master;
1623 Window rw = previous ? previous.rootWindow : null;
1624 if(!active && previous != editor.editBox && rw != editor.membersList)
1627 editor.paramsShown = false;
1629 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1632 bool OnKeyHit(Key key, unichar ch)
1634 CodeEditor editor = (CodeEditor)master;
1636 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1639 bool result = true; editor.editBox.OnKeyHit(key, ch);
1640 return (!created) ? false : result;
1647 void OnRedraw(Surface surface)
1649 CodeEditor editor = (CodeEditor) master;
1650 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1652 Type methodType = null;
1656 int functionW, nameW = 0;
1658 int spaceW, spaceH, commaW, commaWB, parW;
1660 int maxW = 0, lineW = 0;
1666 Font font = editor.normalFont.font;
1667 Font boldFont = editor.boldFont.font;
1668 Display display = this.display;
1670 if(!type) { return; };
1672 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1674 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1675 display.FontExtent(font, ", ", 2, &commaW, null);
1676 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1677 display.FontExtent(font, ")", 1, &parW, null);
1680 if(editor.functionType)
1682 PrintType(type.returnType, string, true, true);
1683 display.FontExtent(font, string, strlen(string), &functionW, null);
1685 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1686 totalW = nameW + functionW + 2 * parW;
1690 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1691 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1692 if(instanceName && type.kind != functionType)
1693 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1694 totalW = functionW + nameW;
1695 surface.TextFont(boldFont);
1698 surface.WriteText(x, y, string, strlen(string));
1699 x += functionW + spaceW;
1701 if(editor.functionType)
1704 surface.WriteText(x, y, type.name, strlen(type.name));
1706 surface.WriteText(x, y, "(", 1);
1709 if(methodType && !methodType.staticMethod && methodType.methodClass)
1713 if(id == editor.paramsID)
1714 surface.TextFont(boldFont);
1716 if(methodType.methodClass)
1717 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1721 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1722 width += ((id == editor.paramsID) ? commaWB : commaW);
1727 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1732 x = 2 + nameW + spaceW + functionW + parW;
1736 if(methodType.methodClass)
1737 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1740 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1742 surface.WriteText(x, y, ",", 1);
1743 x += ((id == editor.paramsID) ? commaWB : commaW);
1751 if(id == editor.paramsID)
1752 surface.TextFont(font);
1756 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1758 for(param = type.params.first; param; param = param.next)
1760 char paramString[1024];
1763 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1764 surface.TextFont(boldFont);
1767 PrintType(param, paramString, true, true);
1768 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1770 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1775 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1780 x = 2 + nameW + spaceW + functionW + parW;
1784 surface.WriteText(x, y, paramString, strlen(paramString));
1788 surface.WriteText(x, y, ",", 1);
1789 x += ((id == editor.paramsID) ? commaWB : commaW);
1797 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1798 surface.TextFont(font);
1803 surface.WriteText(x, y, ")", 1);
1805 else if(instanceName && type.kind != functionType)
1807 surface.WriteText(x, y, instanceName, strlen(instanceName));
1811 bool OnResizing(int * w, int * h)
1813 CodeEditor editor = (CodeEditor) master;
1814 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1816 Type methodType = null;
1820 int functionW = 0, nameW = 0;
1822 int spaceW, spaceH, commaW, commaWB, parW;
1824 int maxW = 0, lineW = 0;
1829 Font font = editor.normalFont.font;
1830 Font boldFont = editor.boldFont.font;
1831 Display display = this.display;
1833 if(type.kind == TypeKind::methodType)
1836 ProcessMethodType(type.method);
1837 type = type.method.dataType;
1840 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1841 display.FontExtent(font, ", ", 2, &commaW, null);
1842 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1843 display.FontExtent(font, ")", 1, &parW, null);
1846 if(editor.functionType && type)
1848 PrintType(type.returnType, string, true, true);
1849 display.FontExtent(font, string, strlen(string), &functionW, null);
1851 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1852 totalW = nameW + spaceW + functionW + 2 * parW;
1856 PrintType(type, string, false, true); // /*true);
1857 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1858 if(instanceName && type.kind != functionType)
1859 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1860 totalW = functionW + nameW + spaceW;
1863 if(editor.functionType)
1869 if(methodType.methodClass)
1870 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1871 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1872 width += ((id == editor.paramsID) ? commaWB : commaW);
1877 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1890 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1892 for(param = type.params.first; param; param = param.next)
1894 char paramString[1024];
1898 PrintType(param, paramString, true, true);
1899 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1901 width += ((id == editor.paramsID) ? commaWB : commaW);
1906 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1923 *w = realW + totalW + 4;
1929 Menu fileMenu { menu, $"File", f };
1930 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1931 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1933 Menu debugMenu { menu, $"Debug", d };
1934 MenuItem debugRunToCursor { debugMenu, $"Run To Cursor", c, ctrlF10, id = RTCMenuBits { false, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1935 MenuItem debugSkipRunToCursor { debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true }, id = RTCMenuBits { true, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1936 MenuItem debugRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level", l, altF10, id = RTCMenuBits { false, true, false }, NotifySelect = RTCMenu_NotifySelect; };
1937 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; };
1939 MenuItem debugBpRunToCursor { debugMenu, $"BP Run To Cursor"/*, c, ctrlF10*/, id = RTCMenuBits { false, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1940 MenuItem debugBpSkipRunToCursor { debugMenu, $"BP Run To Cursor Skipping Breakpoints"/*, u, Key { f10, ctrl = true, shift = true }*/, id = RTCMenuBits { true, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1941 MenuItem debugBpRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level"/*, l, altF10*/, id = RTCMenuBits { false, true, true }, NotifySelect = RTCMenu_NotifySelect; };
1942 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; };
1944 bool RTCMenu_NotifySelect(MenuItem selection, Modifiers mods)
1946 ProjectView projectView = ide.projectView;
1947 if(!projectView.buildInProgress)
1949 RTCMenuBits bits = (RTCMenuBits)selection.id;
1950 int line = editBox.lineNumber + 1;
1953 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1954 ProjectConfig config = projectView.project.config;
1955 int bitDepth = ide.workspace.bitDepth;
1956 bool useValgrind = ide.workspace.useValgrind;
1957 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, bits.ignoreBreakpoints, bits.atSameLevel, bits.oldImplementation);
1963 MenuDivider { debugMenu };
1964 MenuItem debugToggleBreakpoint
1966 debugMenu, $"Toggle Breakpoint", t, f9;
1967 bool NotifySelect(MenuItem selection, Modifiers mods)
1969 ProjectView projectView = ide.projectView;
1970 if(projectView && fileName)
1972 int line = editBox.lineNumber + 1;
1973 ide.debugger.ToggleBreakpoint(fileName, line);
1983 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1987 designer.parent = parent;
1990 toolBox = ((IDEWorkSpace)master).toolBox;
1992 // Debugger bug here: value of toolBox appears as 0
1994 sheet = ((IDEWorkSpace)master).sheet;
1999 bool OnClose(bool parentClosing)
2003 if(ide.workspace && fileName)
2004 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2005 if(inUseDebug && !debugClosing)
2007 debugClosing = true;
2009 if(CloseConfirmation(false))
2012 if(modifiedDocument)
2013 OnFileModified({ modified = true }, null);
2015 debugClosing = false;
2018 if(designer && !designer.closing)
2020 if(designer.visible)
2027 //Window formEditor = designer;
2028 //formEditor.Destroy(0);
2031 ide.AdjustFileMenus();
2036 void OnDestroy(void)
2038 ObjectInfo oClass, next;
2039 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2041 FreeType(this.functionType);
2042 FreeType(this.instanceType);
2047 designer.codeEditor = null;
2048 designer.Destroy(0);
2052 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2054 ObjectInfo object, next;
2056 for(object = oClass.instances.first; object; object = next)
2061 Designer::DestroyObject(object.instance);
2062 delete object.instance;
2064 sheet.DeleteObject(object);
2066 oClass.instances.Delete(object);
2070 Designer::DestroyObject(oClass.instance);
2071 delete oClass.instance;
2073 sheet.DeleteObject(oClass);
2075 classes.Delete(oClass);
2078 if(windowClass && windowClass.data)
2079 UnapplySkin(windowClass);
2083 if(sheet.codeEditor == this)
2085 sheet.codeEditor = null;
2086 toolBox.codeEditor = null;
2092 ProjectView projectView = ide.projectView;
2095 ProjectNode node = projectView.GetNodeFromWindow(this, null, true, false, null);
2096 if(node && node.modified)
2098 node.modified = false;
2099 projectView.Update(null);
2105 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2107 // 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
2109 if(directActivation)
2110 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2112 if(active && directActivation)
2116 openedFileInfo.Activate();
2120 Location * loc = null;
2121 UpdateFormCode(); // To ensure update when modifying properties...
2123 // Got to the right spot in code so we don't lose our form selection...
2126 if(selected.instCode)
2127 loc = &selected.instCode.loc;
2128 else if(selected.classDefinition)
2129 loc = &selected.classDefinition.loc;
2131 line = editBox.lineNumber + 1;
2132 charPos = editBox.charPos + 1;
2137 if(selected && !loc->Inside(line, charPos))
2139 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2140 line = editBox.lineNumber + 1;
2141 charPos = editBox.charPos + 1;
2143 else if(selected && selected.classDefinition)
2146 for(object = selected.instances.first; object; object = object.next)
2150 if(object.instCode.loc.Inside(line, charPos))
2156 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2157 line = editBox.lineNumber + 1;
2158 charPos = editBox.charPos + 1;
2163 ProcessCaretMove(editBox, line, charPos);
2168 if(membersListShown)
2170 membersList.Destroy(0);
2171 membersListShown = false;
2175 paramsList.Destroy(0);
2176 paramsShown = false;
2177 FreeType(functionType);
2178 FreeType(instanceType);
2180 functionType = null;
2181 instanceType = null;
2188 bool OnSaveFile(char * fileName)
2195 f = FileOpen(fileName, write);
2198 if(!ide.projectView)
2199 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2203 this.fileName = fileName; // Put this here because the form designer will check for it...
2204 designer.fileName = fileName;
2205 designer.modifiedDocument = false;
2208 if(editBox.syntaxHighlighting)
2210 // Nuke trailing spaces
2213 for(line = editBox.firstLine; line; line = line.next, y++)
2215 String buffer = line.text;
2216 int count = line.count, i = count-1;
2217 while(i > 0 && isspace(buffer[i])) i--;
2219 editBox.Delete(line, y, i, line, y, count);
2223 editBox.Save(f, false);
2224 modifiedDocument = false;
2232 bool OnFileModified(FileChange fileChange, char * param)
2234 bool reload = false;
2235 if(visible == false && inUseDebug == true)
2236 ide.debugger.WatchesReleaseCodeEditor();
2241 sprintf(message, $"The document %s was modified by another application.\n"
2242 "Would you like to reload it and lose your changes?", fileName);
2243 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2244 contents = message }.Modal() == yes)
2250 File f = FileOpen(fileName, read);
2253 int lineNumber, charPos, len;
2257 updatingCode = true;
2258 lineNumber = editBox.lineNumber;
2259 charPos = editBox.charPos;
2260 scroll = editBox.scroll;
2263 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2264 len = strlen(editBox.line.text);
2265 editBox.GoToLineNum(lineNumber);
2266 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2267 editBox.scroll = scroll;
2268 updatingCode = false;
2269 loadingFile = false;
2271 codeModified = true;
2275 designer.modifiedDocument = false;
2277 modifiedDocument = false;
2285 void OnRedraw(Surface surface)
2288 surface.SetBackground(marginColor);
2289 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2290 if(ideSettings.showLineNumbers)
2292 int currentLineNumber;
2294 char lineFormat[16];
2298 surface.textOpacity = false;
2299 surface.font = font.font;
2300 surface.TextExtent(" ", 1, null, &spaceH);
2301 currentLineNumber = editBox.scroll.y / spaceH + 1;
2302 sprintf(lineFormat, " %%%du", maxLineNumberLength);
2304 surface.SetForeground(lineNumbersColor);
2305 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2307 // Highlight current line
2308 if(editBox.lineNumber == currentLineNumber - 1)
2310 surface.SetBackground(selectedMarginColor);
2311 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2312 surface.SetBackground(marginColor);
2314 sprintf(lineText, lineFormat, currentLineNumber);
2315 if(currentLineNumber <= editBox.numLines)
2316 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
2317 currentLineNumber++;
2321 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2323 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2324 int lineCursor, lineTopFrame, breakpointLines[128];
2325 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2326 Debugger debugger = ide.debugger;
2327 BitmapResource bmpRes;
2329 boxH = clientSize.h;
2330 scrollY = editBox.scroll.y;
2331 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2333 bpOnCursor = bpOnTopFrame = false;
2334 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2337 for(i = 0; i < count; i++)
2339 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2341 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2342 if(breakpointLines[i] == lineCursor)
2344 if(breakpointLines[i] == lineTopFrame)
2345 bpOnTopFrame = true;
2348 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2350 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2353 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2354 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2355 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2357 if(editBox.anchor.left.distance)
2359 if(editBox.horzScroll && editBox.horzScroll.visible)
2361 surface.SetBackground(control);
2362 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2367 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2372 lineY = (line - 1) * lineH;
2373 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2375 Bitmap bitmap = resource.bitmap;
2377 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2384 char ext[MAX_EXTENSION];
2385 char * fileName = property::fileName;
2387 if(SearchString(fileName, 0, "Makefile", false, true))
2388 editBox.useTab = true;
2389 designer.fileName = fileName;
2393 GetExtension(fileName, ext);
2395 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2396 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2397 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2398 editBox.syntaxHighlighting = true;
2400 editBox.syntaxHighlighting = false;
2402 if(parsing && !strcmpi(ext, "ec"))
2404 codeModified = true;
2408 maxLineNumberLength = 0;
2413 bool UpdateMarginSize()
2415 if(ideSettings.showLineNumbers)
2417 int numLen = Max(4, nofdigits(editBox.numLines));
2419 maxLineNumberLength = numLen;
2420 display.FontExtent(font.font, "0", 1, &digitWidth, null);
2421 editBox.anchor = Anchor
2423 left = editBox.syntaxHighlighting * 20 + ideSettings.showLineNumbers * (maxLineNumberLength+2) * digitWidth,
2424 right = 0, top = 0, bottom = 0
2429 maxLineNumberLength = 0;
2430 editBox.anchor = Anchor
2432 left = editBox.syntaxHighlighting * 20,
2433 right = 0, top = 0, bottom = 0
2445 bool LoadFile(char * filePath)
2447 File f = FileOpen(filePath, read);
2450 // Added this here...
2451 fileName = filePath;
2453 updatingCode = true;
2455 updatingCode = false;
2456 loadingFile = false;
2465 void AdjustDebugMenus()
2467 bool unavailable = ide.areDebugMenusUnavailable;
2468 bool isNotNotRunning = unavailable || ide.isDebuggerRunning;
2469 bool isNotStopped = unavailable || !ide.isDebuggerStopped;
2470 bool noBreakpointToggle = ide.isBreakpointTogglingUnavailable;
2472 debugRunToCursor.disabled = isNotNotRunning;
2473 debugSkipRunToCursor.disabled = isNotNotRunning;
2474 debugRunToCursorAtSameLevel.disabled = isNotStopped;
2475 debugSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2477 debugBpRunToCursor.disabled = isNotNotRunning;
2478 debugBpSkipRunToCursor.disabled = isNotNotRunning;
2479 debugBpRunToCursorAtSameLevel.disabled = isNotStopped;
2480 debugBpSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2482 debugToggleBreakpoint.disabled = noBreakpointToggle;
2488 ProjectView projectView = ide.projectView;
2491 designer.fileName = fileName;
2497 sprintf(title, $"Untitled %d", documentID);
2498 // designer.fileName = CopyString(title);
2499 designer.fileName = title;
2504 for(c = 0; c < CodeObjectType::enumSize; c++)
2505 icons[c] = BitmapResource { iconNames[c], window = this };
2507 codeModified = true;
2519 selected.modified = true;
2520 selected.oClass.modified = true;
2522 designer.modifiedDocument = true;
2523 modifiedDocument = true;
2524 formModified = true;
2527 /****************************************************************************
2529 ****************************************************************************/
2537 this.defines.Free(FreeModuleDefine);
2538 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2540 FreeExcludedSymbols(this.excludedSymbols);
2541 FreeContext(this.globalContext);
2543 FreeGlobalData(&this.globalData);
2544 FindCtx_Terminate();
2545 FindParams_Terminate();
2547 if(GetGlobalContext() == globalContext)
2549 SetGlobalData(null);
2550 SetGlobalContext(null);
2551 SetExcludedSymbols(null);
2552 SetTopContext(null);
2553 SetCurrentContext(null);
2556 SetPrivateModule(null);
2559 if(this.privateModule)
2561 FreeTypeData(this.privateModule);
2562 delete this.privateModule;
2563 this.privateModule = null;
2569 static bool reentrant = false;
2574 char * selectedClassName = null, * selectedName = null;
2575 int selectedPos = 0;
2576 Designer backDesigner;
2577 char oldWorkDir[MAX_LOCATION];
2578 char mainModuleName[MAX_FILENAME] = "";
2580 ImportedModule module;
2581 char extension[MAX_EXTENSION];
2582 PathBackup pathBackup { };
2584 Time parseCodeStart = GetTime();
2585 Time startTime, startFindClass;
2587 findClassTotalTime = 0;
2588 checkTypeTotalTime = 0;
2589 externalImportTotalTime = 0;
2590 findClassIgnoreNSTotalTime = 0;
2591 findSymbolTotalTime = 0;
2592 //ResetClassFindTime();
2596 // 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)
2597 if(reentrant) return;
2604 selectedClassName = CopyString(oClass.name);
2605 if(selected != oClass)
2607 ObjectInfo object = this.selected;
2608 selectedName = CopyString(object.name);
2612 for(check = this.oClass.instances.first; check; check = check.next)
2624 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2626 FindCtx_Terminate();
2627 FindParams_Terminate();
2629 SetGlobalData(&globalData);
2630 SetGlobalContext(globalContext);
2631 SetExcludedSymbols(&excludedSymbols);
2632 SetTopContext(globalContext);
2633 SetCurrentContext(globalContext);
2634 SetDefines(&defines);
2635 SetImports(&imports);
2636 SetCurrentNameSpace(null);
2639 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2640 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2641 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2642 "/I T:\\ecere\\include /E %s", argv[1]);
2646 ChangeWorkingDir("e:\\ec");
2647 sprintf(command, "gcc -x c -E -");
2648 fileInput = DualPipeOpen({ output = true, input = true }, command);
2649 SetFileInput(fileInput);
2654 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2656 fileInput.Write(buffer, 1, count);
2661 fileInput.CloseOutput();
2665 // TOCHECK: COULDN'T WE CALL FreeParser here?
2667 FreeType(this.functionType);
2668 FreeType(this.instanceType);
2669 this.functionType = null;
2670 this.instanceType = null;
2673 sheet.SelectObject(null);
2679 // We don't want the designer to be notified of selection when deleting rows...
2680 backDesigner = designer;
2685 ObjectInfo _class, next;
2687 for(_class = classes.first; _class; _class = next)
2693 for(;object = _class.instances.first;)
2697 Designer::DestroyObject(object.instance);
2698 delete object.instance;
2700 sheet.DeleteObject(object);
2702 _class.instances.Delete(object);
2706 Designer::DestroyObject(_class.instance);
2707 delete _class.instance;
2709 sheet.DeleteObject(_class);
2711 classes.Delete(_class);
2717 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2718 if(windowClass && windowClass.data)
2719 UnapplySkin(windowClass);
2722 designer = backDesigner;
2725 fileInput = editFile = EditBoxStream { editBox = editBox };
2726 SetFileInput(fileInput);
2734 defines.Free(FreeModuleDefine);
2735 imports.Free(FreeModuleImport);
2737 FreeContext(this.globalContext);
2738 FreeExcludedSymbols(this.excludedSymbols);
2741 FreeGlobalData(&this.globalData);
2743 if(this.privateModule)
2745 FreeTypeData(this.privateModule);
2746 delete this.privateModule;
2750 startTime = GetTime();
2751 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2753 printf("classes.count: %d\n", globalContext.classes.count);
2758 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2759 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2762 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2764 SetPrivateModule(privateModule);
2767 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2768 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2769 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2770 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2771 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2774 fileName = this.fileName;
2776 if(ide.workspace && ide.workspace.projects && fileName)
2778 for(p : ide.workspace.projects)
2780 char path[MAX_LOCATION];
2782 MakePathRelative(fileName, p.topNode.path, path);
2783 MakeSlashPath(path);
2785 pn = p.topNode.FindWithPath(path, false);
2794 project = ide.project;
2796 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2798 ChangeWorkingDir(project.topNode.path);
2800 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2802 GetLastDirectory(fileName, mainModuleName);
2803 GetExtension(mainModuleName, extension);
2805 SetBuildingEcereCom(false);
2806 SetBuildingEcereComModule(false);
2808 // TODO: Get symbolsDir from project settings instead...
2811 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2812 ProjectConfig config = project.config;
2813 int bitDepth = ide.workspace.bitDepth;
2814 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2815 SetSymbolsDir(objDir.dir);
2816 ide.SetPath(true, compiler, config, bitDepth);
2820 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2821 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2825 switch(GetRuntimePlatform())
2827 case win32: SetSymbolsDir("obj/debug.win32"); break;
2828 case tux: SetSymbolsDir("obj/debug.linux"); break;
2829 case apple: SetSymbolsDir("obj/debug.apple"); break;
2831 SetIncludeDirs(null);
2832 SetSysIncludeDirs(null);
2836 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2838 // TODO FIX for configless project
2839 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2841 for(item : ide.project.config.options.preprocessorDefinitions)
2843 if(!strcmp(item, "BUILDING_ECERE_COM"))
2845 SetBuildingEcereCom(true);
2852 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2853 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2854 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2855 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2856 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2857 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2858 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2859 strcmpi(mainModuleName, "Mutex.ec")))
2861 SetBuildingEcereComModule(true);
2864 // Predeclare all classes
2866 char symFile[MAX_FILENAME];
2867 char symLocation[MAX_LOCATION];
2868 ImportedModule module, next;
2870 GetLastDirectory(fileName, symFile);
2871 ChangeExtension(symFile, "sym", symFile);
2873 strcpy(symLocation, GetSymbolsDir());
2874 PathCat(symLocation, symFile);
2876 // if(!GetEcereImported() && !GetBuildingEcereCom())
2877 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2880 startTime = GetTime();
2882 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2884 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2889 startTime = GetTime();
2891 // LoadSymbols(symLocation, normalImport, true);
2892 LoadSymbols(symLocation, preDeclImport, false);
2894 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2897 for(module = defines.first; module; module = next)
2900 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2903 defines.Delete(module);
2908 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2910 SetDefaultDeclMode(privateAccess);
2911 SetDeclMode(privateAccess);
2915 SetDefaultDeclMode(defaultAccess);
2916 SetDeclMode(defaultAccess);
2919 StripExtension(mainModuleName);
2920 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2921 defines.AddName(module);
2924 // SetYydebug(true);
2929 startTime = GetTime();
2930 startFindClass = checkTypeTotalTime;
2934 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2936 CheckDataRedefinitions();
2939 SetIncludeDirs(null);
2940 SetSysIncludeDirs(null);
2951 startTime = GetTime();
2953 PrePreProcessClassDefinitions();
2954 ComputeModuleClasses(privateModule);
2955 PreProcessClassDefinitions();
2956 ProcessClassDefinitions();
2958 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2959 startTime = GetTime();
2964 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2965 startTime = GetTime();
2967 ProcessInstantiations();
2969 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2972 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2974 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2975 if(!windowClass || windowClass.internalDecl)
2978 startTime = GetTime();
2980 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2981 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2982 eModule_Load(this.privateModule, "ecere", privateAccess);
2984 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2987 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2989 if(windowClass && windowClass.data)
2990 ApplySkin(windowClass, app.currentSkin.name, null);
2994 startTime = GetTime();
2996 for(external = ast->first; external; external = external.next)
2998 if(external.type == classExternal)
3000 ClassDefinition _class = external._class;
3001 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
3003 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
3006 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
3008 Instance instance = eInstance_New(regClass);
3009 ObjectInfo classObject
3011 name = CopyString(_class._class.name);
3012 instance = instance;
3013 classDefinition = _class;
3014 oClass = classObject;
3017 classes.Add(classObject);
3021 // Moved this at bottom so that the file dialog doesn't show up in eCom
3022 designer.CreateObject(instance, classObject, true, null);
3023 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
3025 if(_class.definitions)
3029 for(def = _class.definitions->first; def; def = def.next)
3033 case defaultPropertiesClassDef:
3036 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3038 Identifier id = propDef.identifiers->first;
3041 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3044 Class propertyClass = prop.dataTypeClass;
3046 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3047 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3049 FreeType(propDef.initializer.exp.destType);
3050 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3051 ProcessExpressionType(propDef.initializer.exp);
3053 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
3055 Expression computed = CopyExpression(propDef.initializer.exp);
3056 ComputeExpression(computed);
3058 if(computed.isConstant && computed.type == instanceExp && !id.next)
3062 if(computed.instance._class && computed.instance._class.symbol &&
3063 computed.instance._class.symbol.registered &&
3064 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3066 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3068 // This was saved in the control and shouldn't be freed by FreeExpression...
3069 // (Not doing this anymore, incrementing refCount in pass15 instead)
3070 /*if(propertyClass.type == normalClass)
3071 computed.instance.data = null;*/
3075 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3076 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3078 String temp = new char[strlen(computed.string)+1];
3079 ReadString(temp, computed.string);
3080 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3084 propDef.variable = true;
3086 FreeExpression(computed);
3090 Expression computed = CopyExpression(propDef.initializer.exp);
3091 ComputeExpression(computed);
3092 if(computed.isConstant)
3094 //if(computed.type == memberExp) computed = computed.member.exp;
3096 if(computed.type == constantExp)
3098 Operand value = GetOperand(computed);
3099 DataValue valueData;
3100 valueData.i64 = value.i64;
3101 SetProperty(prop, instance, valueData);
3103 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3105 String temp = new char[strlen(computed.string)+1];
3106 ReadString(temp, computed.string);
3107 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3112 propDef.variable = true;
3114 FreeExpression(computed);
3118 propDef.variable = true;
3122 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3123 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3124 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3127 // Maintain a list in FunctionDefinition of who is attached to it
3128 for(def = _class.definitions->first; def; def = def.next)
3130 if(def.type == functionClassDef)
3132 ClassFunction function = def.function;
3133 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3135 function.attached.Add(OldLink { data = method });
3145 case declarationClassDef:
3147 Declaration decl = def.decl;
3150 case instDeclaration:
3152 Instantiation inst = decl.inst;
3153 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3154 if(instClass && eClass_GetDesigner(instClass))
3156 Instance control = eInstance_New(instClass);
3161 oClass = classObject;
3165 classObject.instances.Add(object);
3167 // TOCHECK: Why is this needed now?
3168 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3169 def.object = object;
3171 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3173 designer.CreateObject(control, object, false, classObject.instance);
3174 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3184 // Second pass, process instantiation members
3186 for(def = _class.definitions->first; def; def = def.next)
3190 case declarationClassDef:
3192 Declaration decl = def.decl;
3195 case instDeclaration:
3197 Instantiation inst = decl.inst;
3198 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3199 if(instClass && eClass_GetDesigner(instClass))
3202 object = object ? object.next : classObject.instances.first;
3203 control = object.instance;
3207 MembersInit members;
3208 for(members = inst.members->first; members; members = members.next)
3210 switch(members.type)
3212 case dataMembersInit:
3214 if(members.dataMembers)
3217 DataMember curMember = null;
3218 Class curClass = null;
3219 DataMember subMemberStack[256];
3220 int subMemberStackPos = 0;
3222 for(member = members.dataMembers->first; member; member = member.next)
3225 Identifier ident = member.identifiers ? member.identifiers->first : null;
3228 DataMember _subMemberStack[256];
3229 int _subMemberStackPos = 0;
3230 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3234 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3236 if(thisMember && thisMember.memberAccess == publicAccess)
3238 curMember = thisMember;
3239 curClass = curMember._class;
3240 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3241 subMemberStackPos = _subMemberStackPos;
3247 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3248 if(curMember) found = true;
3250 if(found && curMember.isProperty)
3252 Property prop = (Property) curMember;
3253 Class propertyClass = prop.dataTypeClass;
3255 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3257 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3259 FreeType(member.initializer.exp.destType);
3260 member.initializer.exp.destType = MkClassType(propertyClass.name);
3263 ProcessExpressionType(member.initializer.exp);
3265 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3267 Expression computed;
3269 /*char debugExpString[4096];
3270 debugExpString[0] = '\0';
3271 PrintExpression(member.initializer.exp, debugExpString);*/
3273 computed = CopyExpression(member.initializer.exp);
3276 ComputeExpression(computed);
3278 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3280 if(computed.instance.data)
3282 if(computed.instance._class && computed.instance._class.symbol &&
3283 computed.instance._class.symbol.registered &&
3284 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3286 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3288 // This was saved in the control and shouldn't be freed by FreeExpression...
3289 // (Not doing this anymore, incrementing refCount in pass15 instead)
3290 /*if(propertyClass.type == normalClass)
3291 computed.instance.data = null;*/
3295 else if(computed.type == identifierExp)
3297 member.variable = true;
3299 if(eClass_GetDesigner(propertyClass))
3302 char * name = computed.identifier.string;
3303 if(!strcmp(name, "this"))
3306 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3307 member.variable = false;
3312 for(check = classObject.instances.first; check; check = check.next)
3313 if(check.name && !strcmp(name, check.name))
3316 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3317 member.variable = false;
3323 else if(computed.type == memberExp)
3325 member.variable = true;
3326 if(computed.member.exp.type == identifierExp)
3328 char * name = computed.member.exp.identifier.string;
3329 if(!strcmp(name, "this"))
3331 char * name = computed.member.member.string;
3334 for(check = classObject.instances.first; check; check = check.next)
3335 if(check.name && !strcmp(name, check.name))
3338 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3339 member.variable = false;
3347 for(check = classObject.instances.first; check; check = check.next)
3349 if(check.name && !strcmp(name, check.name))
3351 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3354 DataValue value { };
3355 GetProperty(getProperty, check.instance, &value);
3356 SetProperty(prop, control, value);
3357 member.variable = false;
3365 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3366 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3368 String temp = new char[strlen(computed.string)+1];
3369 ReadString(temp, computed.string);
3370 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3374 member.variable = true;
3376 FreeExpression(computed);
3381 Expression computed = CopyExpression(member.initializer.exp);
3384 ComputeExpression(computed);
3385 if(computed.isConstant)
3387 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3389 if(!strcmp(propertyClass.dataTypeString, "float"))
3390 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3391 else if(!strcmp(propertyClass.dataTypeString, "double"))
3392 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3394 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3396 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3398 String temp = new char[strlen(computed.string)+1];
3399 ReadString(temp, computed.string);
3400 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3405 member.variable = true;
3407 FreeExpression(computed);
3413 member.variable = true;
3415 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3416 member.initializer.exp.type == memberExp) // identifierExp
3418 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3419 if(method && method.type == virtualMethod)
3422 // Maintain a list in FunctionDefinition of who is attached to it
3423 for(def = _class.definitions->first; def; def = def.next)
3425 if(def.type == functionClassDef)
3427 ClassFunction function = def.function;
3428 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3429 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3431 function.attached.Add(OldLink { data = method });
3432 // Reference this particular instance?
3447 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3458 //designer.CreateObject(instance, classObject, true, null);
3459 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3461 designer.PostCreateObject(instance, classObject, true, null);
3463 //instance.state = Hidden;
3464 //instance.Create();
3465 //instance.SetState(Normal, true, 0);
3474 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3478 // Restore Selection
3479 if(selectedClassName)
3482 for(oClass = classes.first; oClass; oClass = oClass.next)
3484 if(!strcmp(oClass.name, selectedClassName))
3486 this.oClass = oClass;
3490 delete selectedClassName;
3499 for(check = this.oClass.instances.first; check; check = check.next)
3501 if(check.name && !strcmp(check.name, selectedName))
3503 this.selected = check;
3509 if(this.oClass.instances.first)
3510 this.selected = this.oClass.instances.first;
3512 this.selected = this.oClass;
3515 else if(selectedPos == -1 || !this.oClass.instances.count)
3516 this.selected = this.oClass;
3522 if(selectedPos > this.oClass.instances.count)
3524 for(check = this.oClass.instances.first; check; check = check.next)
3526 if(selectedPos == pos++)
3528 this.selected = check;
3536 this.oClass = classes.first;
3537 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3539 delete selectedName;
3540 SetSymbolsDir(null);
3542 if(sheet.codeEditor == this)
3543 sheet.SelectObject(selected);
3546 codeModified = false;
3548 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3551 InvokeParameters(false, false, false);
3554 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3560 ChangeWorkingDir(oldWorkDir);
3562 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3563 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3564 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3565 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3566 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3568 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3570 if(inUseDebug && ide.projectView)
3571 ide.debugger.EvaluateWatches();
3576 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3579 Window control = (Window)object.instance;
3580 ObjectInfo classObject = object.oClass;
3582 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3584 if(!strcmp(_class.name, "DesignerBase")) return;
3586 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3588 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3589 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3591 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3592 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3594 Class dataType = prop.dataTypeClass;
3596 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3600 if(dataType.type == structClass)
3602 void * dataForm = new0 byte[dataType.structSize];
3603 void * dataTest = new0 byte[dataType.structSize];
3605 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3606 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3608 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3610 char tempString[1024] = "";
3612 bool needClass = true;
3616 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3618 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3620 eClass_FindNextMember(_class, curClass, curMember, null, null);
3621 if(*curMember != (DataMember)prop)
3622 f.Printf("%s = ", prop.name);
3624 *curMember = (DataMember)prop;
3625 *curClass = curMember->_class;
3628 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3630 f.Printf("%s", string);
3637 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3639 void * dataForm, * dataTest;
3641 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3642 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3644 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3646 char tempString[1024] = "";
3651 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3653 eClass_FindNextMember(_class, curClass, curMember, null, null);
3654 if(*curMember != (DataMember)prop)
3655 f.Printf("%s = ", prop.name);
3656 *curMember = (DataMember)prop;
3657 *curClass = curMember->_class;
3659 if(eClass_GetDesigner(dataType))
3661 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3662 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3663 f.Printf("this", prop.name);
3666 //ObjectInfo classObject;
3667 //for(classObject = classes.first; classObject; classObject = classObject.next)
3671 for(object = classObject.instances.first; object; object = object.next)
3673 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3675 f.Printf("%s", object.name);
3682 bool needClass = true;
3683 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3684 f.Printf("%s", string);
3691 bool needClass = true;
3692 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3694 if(!strcmp(dataType.dataTypeString, "char *"))
3697 OutputString(f, string);
3701 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3703 f.Printf("%s", string);
3706 *lastIsMethod = false;
3711 DataValue dataForm, dataTest;
3713 GetProperty(prop, control, &dataForm);
3714 GetProperty(prop, test, &dataTest);
3716 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3719 char tempString[1024] = "";
3720 SetProperty(prop, test, dataForm);
3722 if(dataType.type != bitClass)
3724 bool needClass = true;
3726 if(dataType.type == enumClass)
3729 Class enumClass = eSystem_FindClass(privateModule, "enum");
3730 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3732 for(value = e.values.first; value; value = value.next)
3734 if((int)value.data == dataForm.i)
3736 string = value.name;
3742 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3744 if(string && string[0])
3749 eClass_FindNextMember(_class, curClass, curMember, null, null);
3750 if(*curMember != (DataMember)prop)
3751 f.Printf("%s = ", prop.name);
3752 *curMember = (DataMember)prop;
3753 *curClass = curMember->_class;
3755 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3756 f.Printf("%sf", string);
3758 f.Printf("%s", string);
3762 else if(dataType.type == bitClass)
3764 bool needClass = true;
3766 if(*prev) f.Printf(", ");
3768 eClass_FindNextMember(_class, curClass, curMember, null, null);
3769 if(*curMember != (DataMember)prop)
3770 f.Printf("%s = ", prop.name);
3771 *curMember = (DataMember)prop;
3772 *curClass = curMember->_class;
3774 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3776 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3778 f.Printf("%s", string);
3780 *lastIsMethod = false;
3790 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3792 Instantiation inst = object.instCode;
3793 Window control = (Window)object.instance;
3795 bool methodPresent = false;
3797 bool lastIsMethod = true;
3798 ObjectInfo classObject = object.oClass;
3804 // Instance removed, delete it
3805 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3807 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3808 position = inst.loc.end.pos + 1;
3812 bool multiLine = false;
3815 // Check if it's an unnamed instance
3818 f.Seek(inst.nameLoc.start.pos - position, current);
3819 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3820 position = inst.nameLoc.end.pos;
3822 f.Printf(object.name);
3827 if(isspace(ch) && ch != '\n')
3829 f.Seek(-1, current);
3837 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3839 f.Seek(pos - position, current);
3844 f.Seek(-1, current);
3853 f.Puts(object.name);
3858 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3859 methodPresent = true;
3867 if(ch == OpenBracket)
3873 // TODO: Simplify this?
3882 f.Seek(-1, current);
3894 if(ch == '\n') { toDelete = count; count = 0; }
3895 else if(isspace(ch)) count++;
3898 f.Seek(-1, current);
3902 toDelete += count - 6;
3912 f.Seek(-toDelete-count, current);
3913 f.DeleteBytes(toDelete);
3914 f.Seek(count, current);
3919 for(c = 0; c<toAdd; c++)
3925 methodPresent = multiLine;
3928 f.Printf(methodPresent ? "\n " : " ");
3934 // Instance not there, create a brand new one
3935 DeleteJunkBefore(f, position, &position);
3936 f.Printf(*firstObject ? "\n\n" : "\n");
3937 *firstObject = false;
3939 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3940 methodPresent = true;
3945 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3947 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3952 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3954 f.Printf(" %s %c ", control._class.name, OpenBracket);
3960 Instance test = eInstance_New(control._class);
3961 DataMember curMember = null;
3962 Class curClass = null;
3965 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3969 // Attach Method here
3970 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3972 if(prev) f.Printf(", ");
3973 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3978 if(inst && !object.deleted)
3980 MembersInit members;
3981 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3983 DeleteJunkBefore(f, position, &position);
3985 // Instance already there, clear out the properties
3986 for(members = inst.members ? inst.members->first : null; members; members = members.next)
3988 if(members.type == dataMembersInit)
3992 if(members.dataMembers)
3994 bool keptMember = false;
3995 MemberInit lastKept = null;
3997 for(member = members.dataMembers->first; member; member = member.next)
3999 Identifier ident = member.identifiers ? member.identifiers->first : null;
4000 bool deleted = false;
4002 // For now delete if it's not a method
4003 if(!member.variable) // && ident)
4005 if(!ident || !ident.next)
4007 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
4010 f.Seek(member.loc.start.pos - position, current);
4011 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4012 position = member.loc.end.pos;
4017 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
4018 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
4019 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4021 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
4022 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
4024 f.Seek(member.loc.start.pos - position, current);
4025 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4026 position = member.loc.end.pos;
4038 //f.Seek(member.loc.start.pos - position, current);
4039 //position = member.loc.start.pos;
4040 DeleteJunkBefore(f, member.loc.start.pos, &position);
4041 if(prev) f.Printf(", ");
4042 else if(keptMember) f.Printf(" ");
4047 if(!keptMember || !members.next)
4052 if(keptMember && lastKept != members.dataMembers->last)
4057 f.Seek(-1, current);
4063 f.Seek(-1, current);
4066 else if(!isspace(ch))
4068 f.Seek(-2, current);
4073 f.DeleteBytes(count);
4076 f.Seek(members.loc.end.pos - position, current);
4081 f.Seek(-1, current);
4083 position = members.loc.end.pos + 1;
4087 f.Seek(-1, current);
4088 position = members.loc.end.pos;
4094 lastIsMethod = false;
4099 DeleteJunkBefore(f, position, &position);
4102 if(lastKept != members.dataMembers->last)
4107 f.Seek(-1, current);
4113 f.Seek(-1, current);
4116 else if(!isspace(ch))
4118 f.Seek(-2, current);
4123 f.DeleteBytes(count);
4127 f.Seek(members.loc.end.pos - position, current);
4128 position = members.loc.end.pos;
4132 lastIsMethod = true;
4135 lastIsMethod = false;
4141 f.Seek(members.loc.end.pos - position, current);
4142 position = members.loc.end.pos;
4144 lastIsMethod = true;
4147 else if(members.type == methodMembersInit)
4149 if(this.methodAction == actionDeleteMethod && members.function == function);
4151 methodPresent = true;
4153 // Delete instance method here
4154 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4155 members.function == function)
4157 if(this.moveAttached && !*text)
4158 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4160 DeleteJunkBefore(f, members.loc.start.pos, &position);
4161 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4162 position = members.loc.end.pos + 1;
4167 DeleteJunkBefore(f, position, &position);
4171 DeleteJunkBefore(f, members.loc.start.pos, &position);
4172 lastIsMethod = true;
4176 f.Seek(members.loc.end.pos - position, current);
4177 position = members.loc.end.pos;
4179 DeleteJunkBefore(f, position, &position);
4188 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4190 Method method = this.method;
4191 DeleteJunkBefore(f, position, &position);
4197 if(!method.dataType)
4198 method.dataType = ProcessTypeString(method.dataTypeString, false);
4201 Type dataType = method.dataType;
4202 Type returnType = dataType.returnType;
4205 if(this.moveAttached)
4207 // Move function here:
4208 int newLen = strlen(method.name);
4213 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4215 // First change name of function
4216 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4217 *textSize += newLen - movedFuncIdLen;
4218 memcpy(*text + movedFuncIdPos, method.name, newLen);
4220 // Second, tab right
4223 for(c = 0; (*text)[c]; )
4226 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4229 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4230 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4234 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4244 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4246 // ADDING METHOD HERE
4248 OutputType(f, returnType, false);
4251 if(dataType.thisClass)
4253 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4255 if(dataType.thisClass.shortName)
4256 f.Printf(dataType.thisClass.shortName);
4258 f.Printf(dataType.thisClass.string);
4262 f.Printf(method.name);
4264 for(param = dataType.params.first; param; param = param.next)
4266 OutputType(f, param, true);
4271 f.Printf(" %c\n\n", OpenBracket);
4273 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4275 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4276 f.Printf(" return true;\n");
4277 else if(returnType.kind != voidType)
4278 f.Printf(" return 0;\n");
4283 if(returnType.kind != voidType)
4284 f.Printf("return ");
4285 f.Printf("%s::%s(", control._class.name, method.name);
4286 for(param = dataType.params.first; param; param = param.next)
4288 if(param.prev) f.Printf(", ");
4289 if(param.kind != voidType)
4290 f.Printf(param.name);
4294 f.Printf(" %c\n", CloseBracket);
4300 if(!object.instCode)
4303 f.Printf(" %c;\n", CloseBracket);
4305 f.Printf("%c;\n", CloseBracket);
4307 else if(!object.deleted)
4309 // Turn this into a multiline instance when adding a method
4310 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4312 f.Printf(methodPresent ? "\n " : " ");
4314 f.Seek(inst.loc.end.pos + 1 - position, current);
4315 position = inst.loc.end.pos + 1;
4320 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4323 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4325 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4327 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4329 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4330 if(prop && prop.isProperty && !prop.conversion)
4332 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4333 (!prop.IsSet || prop.IsSet(classObject.instance)))
4335 Class dataType = prop.dataTypeClass;
4336 char tempString[1024] = "";
4338 bool specify = false;
4341 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4342 if(member && member._class == regClass)
4346 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4348 if(dataType && dataType.type == structClass)
4350 void * dataForm = new0 byte[dataType.structSize];
4351 void * dataTest = new0 byte[dataType.structSize];
4353 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4354 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4356 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4358 bool needClass = true;
4360 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4361 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4363 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4365 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4370 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4372 void * dataForm, * dataTest;
4374 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4375 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4377 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4379 char tempString[1024] = "";
4381 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4383 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4385 // Shouldn't go here ...
4386 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4390 bool needClass = true;
4392 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4394 if(!strcmp(dataType.dataTypeString, "char *"))
4396 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4397 OutputString(f, string);
4401 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4403 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4409 DataValue dataForm, dataTest;
4411 GetProperty(prop, classObject.instance, &dataForm);
4412 GetProperty(prop, test, &dataTest);
4414 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4416 SetProperty(prop, test, dataForm);
4417 if(dataType.type == bitClass)
4419 bool needClass = true;
4420 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4422 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4424 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4428 bool needClass = true;
4429 if(dataType.type == enumClass)
4432 Class enumClass = eSystem_FindClass(privateModule, "enum");
4433 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4435 for(value = e.values.first; value; value = value.next)
4437 if((int)value.data == dataForm.i)
4439 string = value.name;
4445 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4446 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4447 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4449 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4458 void UpdateFormCode()
4461 if(!parsing) return;
4468 else if(formModified)
4470 EditBoxStream f { editBox = editBox };
4474 Identifier movedFuncId;
4475 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4476 ObjectInfo classObject;
4482 movedFuncId = GetDeclId(function.declarator);
4483 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4484 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4487 for(classObject = classes.first; classObject; classObject = classObject.next)
4490 ClassDefinition classDef = classObject.classDefinition;
4491 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4494 bool firstObject = true;
4495 ObjectInfo object = classObject.instances.first;
4496 bool lastIsDecl = false;
4498 if(!classObject.modified) continue;
4500 test = eInstance_New(regClass);
4503 // Put it in the same desktop window...
4504 designer.PrepareTestObject(test);
4506 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4507 //f.Printf("%c\n\n", OpenBracket);
4509 // Change the _class name
4510 f.Seek(classDef.nameLoc.start.pos - position, current);
4511 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4512 f.Printf(classObject.name);
4513 position = classDef.nameLoc.end.pos;
4516 // Go to block start, delete all until no white space, put \n
4520 f.Seek(classDef.blockStart.end.pos - position, current);
4521 position = classDef.blockStart.end.pos;
4523 for(; f.Getc(&ch); count++)
4527 f.Seek(-1, current);
4537 f.Seek(-count, current);
4539 f.DeleteBytes(count-back);
4541 position += count-back;
4544 // Output properties
4545 OutputClassProperties(classObject.instance._class, classObject, f, test);
4547 for(def = classDef.definitions->first; def; def = def.next)
4551 case defaultPropertiesClassDef:
4553 bool keptMember = false;
4555 MemberInit lastKept = null;
4558 DeleteJunkBefore(f, def.loc.start.pos, &position);
4561 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4563 Identifier ident = propDef.identifiers->first;
4564 bool deleted = false;
4566 // For now delete if it's a prop
4567 if(!propDef.variable && ident)
4571 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4574 f.Seek(propDef.loc.start.pos - position, current);
4575 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4576 position = propDef.loc.end.pos;
4581 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4582 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4584 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4585 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4587 f.Seek(propDef.loc.start.pos - position, current);
4588 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4589 position = propDef.loc.end.pos;
4607 f.Seek(def.loc.end.pos - position - 1, current);
4612 f.Seek(-1, current);
4615 position = def.loc.end.pos;
4619 if(lastKept != def.defProperties->last)
4624 f.Seek(-1, current);
4630 f.Seek(-1, current);
4633 else if(!isspace(ch))
4635 f.Seek(-2, current);
4640 f.DeleteBytes(count);
4644 f.Seek(def.loc.end.pos - position, current);
4645 position = def.loc.end.pos;
4650 case declarationClassDef:
4652 Declaration decl = def.decl;
4654 if(decl.type == instDeclaration)
4656 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4658 while(def.object && object != def.object)
4660 if(object /*&& ((ObjectInfo)def.object).modified*/)
4661 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4662 object = object.next;
4665 DeleteJunkBefore(f, def.loc.start.pos, &position);
4666 f.Printf(firstObject ? "\n\n " : "\n ");
4667 firstObject = false;
4669 if(def.object && ((ObjectInfo)def.object).modified)
4670 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4672 object = object ? object.next : null;
4676 DeleteJunkBefore(f, def.loc.start.pos, &position);
4677 f.Printf(firstObject ? "\n\n " : "\n ");
4678 firstObject = false;
4684 DeleteJunkBefore(f, def.loc.start.pos, &position);
4685 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4690 case functionClassDef:
4692 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4693 if(!def.function.body) continue;
4697 DeleteJunkBefore(f, def.loc.start.pos, &position);
4700 // Delete _class methods
4701 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4702 def.function == function)
4707 if(moveAttached && !text)
4709 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4712 f.Seek(def.loc.end.pos - position, current);
4713 for(; f.Getc(&ch); count++)
4717 f.Seek(-1, current);
4721 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4723 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4724 position = def.loc.end.pos + count;
4727 // In case of detaching methods in the _class, simply rename the method
4728 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4730 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4731 f.DeleteBytes(movedFuncIdLen);
4733 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4736 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4737 function == def.function)
4739 // In case of attaching methods in the _class, simply rename the method
4740 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4741 position = function.loc.start.pos + movedFuncIdPos;
4742 f.DeleteBytes(movedFuncIdLen);
4743 if(method.dataType.thisClass)
4744 f.Printf("%s::", method.dataType.thisClass.string);
4745 f.Puts(method.name);
4746 position += movedFuncIdLen;
4751 DeleteJunkBefore(f, def.loc.start.pos, &position);
4752 if(def.type == memberAccessClassDef)
4755 firstObject = false;
4765 f.Seek(def.loc.end.pos - position, current);
4766 position = def.loc.end.pos;
4769 // Output attached methods
4770 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4772 DeleteJunkBefore(f, position, &position);
4773 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4776 // ********** INSTANCES ***************
4777 for(; object; object = object.next)
4779 if(!object.instCode)
4781 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4785 DeleteJunkBefore(f, position, &position);
4787 // ****************** METHODS ***********************
4788 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4790 // If detaching an instance method
4791 if(selected != classObject)
4793 int newLen = strlen(methodName);
4796 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4797 // Tab selection left
4800 for(c = 0; text[c]; )
4803 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4804 memmove(text+start, text+start+i, textSize+1-start-i);
4807 for(; text[c] && text[c] != '\n'; c++);
4813 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4814 textSize += newLen - movedFuncIdLen;
4815 memcpy(text + movedFuncIdPos, methodName, newLen);
4822 if(methodAction == actionAddMethod && selected == classObject)
4824 Method method = this.method;
4826 if(!method.dataType)
4827 method.dataType = ProcessTypeString(method.dataTypeString, false);
4829 // ADDING METHOD HERE
4831 Type dataType = method.dataType;
4832 Type returnType = dataType.returnType;
4834 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4838 OutputType(f, returnType, false);
4841 if(dataType.thisClass && !dataType.classObjectType)
4843 if(dataType.thisClass.shortName)
4844 f.Printf(dataType.thisClass.shortName);
4846 f.Printf(dataType.thisClass.string);
4849 f.Printf(method.name);
4851 for(param = dataType.params.first; param; param = param.next)
4853 OutputType(f, param, true);
4858 f.Printf(" %c\n\n", OpenBracket);
4860 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4862 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4863 f.Printf(" return true;\n");
4864 else if(returnType && returnType.kind != voidType)
4865 f.Printf(" return 0;\n");
4870 if(returnType.kind != voidType)
4871 f.Printf("return ");
4873 char * name = ((Specifier)classDef.baseSpecs->first).name;
4874 Symbol _class = FindClass(name);
4875 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4877 for(param = dataType.params.first; param; param = param.next)
4879 if(param.prev) f.Printf(", ");
4880 if(param.kind != voidType)
4881 f.Printf(param.name);
4886 f.Printf(" %c", CloseBracket);
4890 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4902 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4903 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4907 codeModified = false;
4908 formModified = false;
4910 moveAttached = false;
4915 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4918 ClassFunction function = null;
4921 ObjectInfo object = this.selected;
4923 if(object && object == this.oClass)
4925 ClassDefinition classDef = object.oClass.classDefinition;
4927 if(classDef && classDef.definitions)
4929 for(def = classDef.definitions->first; def; def = def.next)
4931 if(def.type == functionClassDef && def.function.declarator)
4933 if(!strcmp(def.function.declarator.symbol.string, methodName))
4935 function = def.function;
4940 else if(def.type == defaultPropertiesClassDef)
4944 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4946 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4947 if(ident && !ident.next)
4949 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4953 propLoc = propDef.loc;
4956 ClassDefinition classDef = object.oClass.classDefinition;
4958 if(classDef.definitions)
4960 for(def = classDef.definitions->first; def; def = def.next)
4962 if(def.type == functionClassDef)
4964 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4966 function = def.function;
4985 Instantiation inst = object.instCode;
4987 // Check here to see if the method already exists, no need to call ModifyCode in that case
4988 if(inst && inst.members)
4990 MembersInit members;
4991 for(members = inst.members->first; members; members = members.next)
4993 switch(members.type)
4995 case dataMembersInit:
4997 if(members.dataMembers)
5000 for(member = members.dataMembers->first; member; member = member.next)
5002 Identifier ident = member.identifiers ? member.identifiers->first : null;
5003 if(ident && !ident.next)
5005 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
5009 propLoc = member.loc;
5012 ClassDefinition classDef = object.oClass.classDefinition;
5014 if(classDef.definitions)
5016 for(def = classDef.definitions->first; def; def = def.next)
5018 if(def.type == functionClassDef)
5020 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
5022 function = def.function;
5031 // TODO: Fix memory leak
5032 function = ClassFunction
5034 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5046 case methodMembersInit:
5048 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5050 function = members.function;
5062 if(functionPtr) *functionPtr = function;
5066 void GoToMethod(char * methodName /*Method method*/)
5070 ObjectInfo object = selected;
5071 EditBoxStream f { editBox = editBox };
5072 ClassFunction function = null;
5073 bool atChar = false;
5077 Location propLoc = { {0,0,-1} };
5080 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5081 if(function && function.body)
5084 f.Seek(function.body.loc.start.pos+1, current);
5094 f.Seek(-1, current);
5099 else if(!isspace(ch))
5101 f.Seek(-1, current);
5107 else if(propLoc.start.pos > -1)
5109 f.Seek(propLoc.start.pos, current);
5112 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5114 if(function || propLoc.start.pos > -1)
5116 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5117 editBox.CenterOnCursor();
5118 SetState(normal, false, 0);
5121 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5123 FreeClassFunction(function);
5129 void FindCompatibleMethods(Method method, OldList compatible)
5131 ClassDefinition classDef = this.oClass.classDefinition;
5132 if(classDef && classDef.definitions)
5135 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5138 Symbol classSym { };
5139 Symbol selectedClass;
5140 if(this.selected == this.oClass)
5141 selectedClass = classSym;
5143 selectedClass = FindClass(this.selected.instance._class.name);
5145 regClass.name = classDef._class.name;
5146 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5147 for(def = classDef.definitions->first; def; def = def.next)
5149 if(def.type == functionClassDef && def.function.declarator)
5151 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5153 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5156 Type type = def.function.declarator.symbol.type;
5157 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5159 compatible.Add(OldLink { data = def.function });
5165 if(this.oClass && this.oClass.instance)
5167 classSym.registered = regClass;
5168 //classSym.registered = this.oClass.oClass;
5170 for(_class = regClass.base; _class; _class = _class.base)
5173 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5175 // TODO: Understand why these functions popup in attach list
5176 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5178 if(!testMethod.dataType)
5179 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5181 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5182 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5183 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5185 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5186 // ClassFunction function { };
5187 FunctionDefinition function { };
5189 function.declarator = Declarator { };
5190 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5191 excludedSymbols.Add(function.declarator.symbol);
5193 compatible.Add(OldLink { data = function });
5204 void AddMethod(Method method)
5208 char methodName[1024];
5209 strcpy(methodName, method.name);
5210 if(!FindMethod(methodName, null, null))
5212 methodAction = actionAddMethod;
5213 this.method = method;
5217 GoToMethod(methodName);
5221 void DeleteMethod(ClassFunction function)
5225 methodAction = actionDeleteMethod;
5226 this.function = function;
5234 void AttachMethod(Method method, ClassFunction function)
5238 // If it's an instance we'll ask if we want to move it inside...
5239 if(!function.attached.count && function.body)
5241 // Find the function in the _class to check if it's a virtual function
5242 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5243 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5244 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5246 for(def = this.classDefinition.first; def; def = def.next)
5248 if(def.type == functionClassDef)
5250 if(def.function == function)
5255 if(!method || method.type != virtualMethod)
5258 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5259 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5261 moveAttached = true;
5266 methodAction = actionAttachMethod;
5267 this.method = method;
5268 this.function = function;
5275 void ReAttachMethod(Method method, ClassFunction function)
5279 // If it's an instance we'll ask if we want to move it inside...
5280 if(!function.attached.count && function.body)
5282 // Find the function in the _class to check if it's a virtual function
5283 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5284 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5285 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5287 for(def = this.classDefinition.first; def; def = def.next)
5289 if(def.type == functionClassDef)
5291 if(def.function == function)
5296 if(!method || method.type != virtualMethod)
5299 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5300 if(MessageBox { type = yesNo, master = parent, text = title,
5301 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5303 moveAttached = true;
5308 methodAction = actionReattachMethod;
5309 this.method = method;
5310 this.function = function;
5317 void DetachMethod(Method method, ClassFunction function, int type)
5325 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5326 master = sheet, text = $"Name detached method", background = formColor
5330 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5331 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5335 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5336 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5340 dialog, anchor = { left = 5, right = 5, top = 5 }
5342 sprintf(methodName, "%s_%s", selected.name, method.name);
5343 nameBox.contents = methodName;
5345 result = dialog.Modal() == ok;
5346 strcpy(methodName, nameBox.contents);
5351 // If the method is not attached, move it outside
5354 // Add this class to the methodName
5355 char name[1024] = "";
5357 if(this.selected != this.oClass && !method.dataType.thisClass)
5359 strcat(name, this.selected.instance._class.name);
5361 strcat(name, this.methodName);
5362 strcpy(this.methodName, name);
5364 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5366 strcat(name, method.dataType.thisClass.string);
5368 strcat(name, this.methodName);
5369 strcpy(this.methodName, name);
5372 this.moveAttached = true;
5375 this.methodAction = actionDetachMethod;
5376 this.method = method;
5377 this.function = function;
5384 void AddObject(Instance instance, ObjectInfo * object)
5388 //*object = _class.instances.Add(sizeof(ObjectInfo));
5389 *object = ObjectInfo { };
5390 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5391 (*object).oClass = oClass;
5392 (*object).instance = instance;
5397 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5399 // if(strcmp(name, this.oClass.instance.name))
5402 for(check = oClass.instances.first; check; check = check.next)
5403 if(!check.deleted && check.name && !strcmp(name, check.name))
5407 (*object).name = CopyString(name);
5412 toolBox.controlClass = null;
5416 //sheet.AddObject(*object, (*object).name, TypeData, true);
5421 void EnsureUpToDate()
5423 if(sheet && codeModified && parsing)
5427 void SelectObject(ObjectInfo object)
5430 oClass = object ? object.oClass : null;
5432 designer.SelectObject(object, object ? object.instance : null);
5435 void SelectObjectFromDesigner(ObjectInfo object)
5438 sheet.SelectObject(object);
5441 void EnumerateObjects(Sheet sheet)
5445 for(oClass = classes.first; oClass; oClass = oClass.next)
5451 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5452 for(object = oClass.instances.first; object; object = object.next)
5453 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5456 sheet.SelectObject(selected);
5461 designer.AddObject();
5464 void DeleteObject(ObjectInfo object)
5466 delete object.instance;
5467 object.deleted = true;
5468 object.modified = true;
5469 object.oClass.modified = true;
5471 if(selected == object)
5473 bool looped = false;
5474 ObjectInfo select = object;
5478 select = select.prev;
5482 select = object.oClass.instances.last;
5489 sheet.SelectObject(select ? select : oClass);
5492 if(!object.instCode && object.oClass != object)
5495 oClass.instances.Delete(object);
5498 if(sheet.codeEditor == this)
5499 sheet.DeleteObject(object);
5502 void RenameObject(ObjectInfo object, char * name)
5506 // Validate the name:
5507 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5508 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5511 for(c = 0; name[c]; c++)
5512 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5520 object.name = (name && name[0]) ? CopyString(name) : null;
5522 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5526 void DesignerModifiedObject()
5528 sheet.ListProperties(false);
5532 void ListSubMembers(Type member)
5536 for(subMember = member.members.first; subMember; subMember = subMember.next)
5540 DataRow row = membersList.AddString(subMember.name);
5541 row.icon = icons[typeData];
5545 ListSubMembers(subMember);
5550 void ListSubDataMembers(DataMember member, bool isPrivate)
5552 DataMember subMember;
5553 for(subMember = member.members.first; subMember; subMember = subMember.next)
5555 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5559 DataRow row = membersList.AddString(subMember.name);
5560 BitmapResource bitmap = null;
5561 if(!subMember.dataType)
5562 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5564 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5566 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5569 bitmap = { bitmapName };
5570 membersList.AddResource(bitmap);
5573 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5577 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5583 void ListClassMembers(Class whatClass, bool methodsOnly)
5586 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5587 bool isPrivate = false;
5589 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5591 Method method, methodIt;
5593 DataMember memberIt;
5595 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5597 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5598 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5600 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5602 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5604 DataRow row = membersList.FindString(method.name);
5607 row = membersList.AddString(method.name);
5609 if(!method.dataType)
5610 method.dataType = ProcessTypeString(method.dataTypeString, false);
5612 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5620 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5624 if(memberIt.isProperty)
5626 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5628 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5632 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5634 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5637 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5643 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5645 if(member.isProperty)
5647 Property prop = (Property) member;
5648 if(!membersList.FindString(prop.name))
5650 DataRow row = membersList.AddString(prop.name);
5651 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5654 else if(member.name && !membersList.FindString(member.name))
5656 DataRow row = membersList.AddString(member.name);
5658 BitmapResource bitmap = null;
5659 if(!member.dataType)
5660 member.dataType = ProcessTypeString(member.dataTypeString, false);
5662 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5664 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5667 bitmap = { bitmapName };
5668 membersList.AddResource(bitmap);
5671 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5674 ListSubDataMembers(member, member.memberAccess == privateAccess);
5678 if(_class.inheritanceAccess == privateAccess)
5681 if(_class.module != privateModule) break;
5686 void ListClassMembersMatch(Class whatClass, Type methodType)
5689 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5690 bool isPrivate = false;
5692 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5698 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5700 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5702 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5704 if(!method.dataType)
5705 method.dataType = ProcessTypeString(method.dataTypeString, false);
5707 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5709 DataRow row = membersList.FindString(method.name);
5712 row = membersList.AddString(method.name);
5713 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5719 if(_class.inheritanceAccess == privateAccess)
5722 if(_class.module != privateModule) break;
5727 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5730 bool isPrivate = false;
5731 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5737 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5739 if(method.type == virtualMethod)
5741 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5743 DataRow row = membersList.FindString(method.name);
5746 row = membersList.AddString(method.name);
5748 if(!method.dataType)
5749 method.dataType = ProcessTypeString(method.dataTypeString, false);
5751 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5757 for(member = _class.membersAndProperties.first; member; member = member.next)
5759 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5761 if(member.isProperty)
5763 Property prop = (Property)member;
5765 DataRow row = membersList.AddString(prop.name);
5766 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5769 else if(member.name && (!curString || strcmp(curString, member.name)))
5771 DataRow row = membersList.AddString(member.name);
5773 BitmapResource bitmap = null;
5774 if(!member.dataType)
5775 member.dataType = ProcessTypeString(member.dataTypeString, false);
5777 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5779 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5782 bitmap = { bitmapName };
5783 membersList.AddResource(bitmap);
5786 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5789 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5792 if(_class.inheritanceAccess == privateAccess)
5795 if(_class.module != privateModule) break;
5800 void ListMembers(Type type)
5802 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5806 if(type.kind == classType)
5809 ListClassMembers(type._class.registered, false);
5814 for(member = type.members.first; member; member = member.next)
5818 DataRow row = membersList.AddString(member.name);
5819 row.icon = icons[typeData];
5821 else if(member.kind == structType || member.kind == unionType)
5822 ListSubMembers(member);
5828 void ListModule(Module mainModule, int recurse, bool listClasses)
5831 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5832 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5833 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5834 for(module = mainModule.application.allModules.first; module; module = module.next)
5836 if(ModuleVisibility(mainModule, module))
5837 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5841 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5848 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5850 Class _class = link.data;
5851 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5853 DataRow row = membersList.AddString(_class.name);
5854 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5859 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5861 DefinedExpression definedExp = link.data;
5862 DataRow row = membersList.AddString(link /*definedExp*/.name);
5863 row.icon = icons[typeData];
5866 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5868 GlobalFunction function = link.data;
5869 DataRow row = membersList.AddString(link /*function*/.name);
5870 row.icon = icons[typeMethod];
5874 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5876 if(recurse != 2 && listClasses)
5878 if(!membersList.FindString(ns->name))
5880 DataRow row = membersList.AddString(ns->name);
5881 row.icon = icons[typeNameSpace];
5886 ListNameSpace(ns, 2, listClasses);
5890 void ListEnumValues(Class _class)
5892 List<Class> classes { };
5893 for(; _class && _class.type == enumClass; _class = _class.base)
5894 classes.Insert(null, _class);
5895 for(_class : classes)
5897 EnumClassData enumeration = (EnumClassData)_class.data;
5899 for(item = enumeration.values.first; item; item = item.next)
5901 DataRow row = membersList.AddString(item.name);
5902 row.icon = icons[typeEnumValue];
5908 bool ListEnumsModule(Module mainModule, Type dest)
5910 bool result = false;
5912 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5913 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5914 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5915 for(module = mainModule.application.allModules.first; module; module = module.next)
5917 if(ModuleVisibility(mainModule, module))
5918 result |= ListEnums(module.publicNameSpace, dest);
5923 void ListNameSpaceByString(Module mainModule, char * string)
5925 NameSpace * nameSpace;
5927 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5928 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5929 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5930 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5931 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5932 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5933 for(module = mainModule.application.allModules.first; module; module = module.next)
5935 if(ModuleVisibility(mainModule, module))
5937 nameSpace = FindNameSpace(module.publicNameSpace, string);
5938 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5943 bool ListEnums(NameSpace nameSpace, Type dest)
5946 bool result = false;
5948 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5950 Class _class = link.data;
5951 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *"))) && !dest.classObjectType)) &&
5952 dest.kind != pointerType && dest.kind != ellipsisType)
5954 OldList conversions { };
5956 type.kind = classType;
5957 type._class = FindClass(_class.name);
5958 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5960 ListEnumValues(_class);
5963 conversions.Free(null);
5967 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5969 result |= ListEnums(nameSpace, dest);
5974 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5978 for(c = 0; (ch = name[c]); c++)
5980 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5982 NameSpace * newSpace;
5983 char * spaceName = new char[c - start + 1];
5984 memcpy(spaceName, name + start, c - start);
5985 spaceName[c-start] = '\0';
5986 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5990 nameSpace = newSpace;
5999 return (NameSpace *)nameSpace;
6002 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
6004 bool listedEnums = false;
6005 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
6006 bool listClasses = true;
6008 if(exp && (exp.type == identifierExp || exp.type == memberExp))
6010 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
6011 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
6012 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
6014 if(exp.type == identifierExp)
6015 id = realIdentifier;
6017 if(id && id._class && !id._class.name)
6019 listClasses = false;
6022 else if(id && id._class && id._class.name)
6026 Class _class = id.classSym.registered;
6027 if(_class && _class.type == enumClass)
6029 ListEnumValues(_class);
6032 ListClassMembers(id.classSym.registered, true);
6037 else if(id && colons)
6039 ListNameSpaceByString(this.privateModule, id.string);
6044 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6046 listedEnums = ListEnumsModule(this.privateModule, destType);
6049 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6051 ListEnumValues(destType._class.registered);
6054 ListClassPropertiesAndVirtual(insideClass, null);
6058 else if(destType && destType.kind == enumType)
6062 for(value = destType.members.first; value; value = value.next)
6064 DataRow row = membersList.AddString(value.name);
6065 row.icon = icons[typeEnumValue];
6069 ListClassPropertiesAndVirtual(insideClass, null);
6073 else if(insideClass && !enumOnly)
6075 ListClassPropertiesAndVirtual(insideClass, string);
6078 if(listedEnums && string && string[0])
6080 DataRow row = membersList.FindSubString(string);
6082 listedEnums = false;
6085 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6087 ListClassMembersMatch(GetThisClass(), exp.destType);
6089 else if(!insideClass && !enumOnly && !listedEnums)
6092 Symbol symbol = null;
6096 ListClassMembers(GetThisClass(), false);
6099 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6101 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6103 // Don't list enum values?
6104 //if(symbol.type.kind != TypeEnum)
6105 DataRow row = membersList.FindString(symbol.string);
6108 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6110 row = membersList.AddString(symbol.string);
6111 if(symbol.type && symbol.type.kind == functionType)
6112 row.icon = icons[typeMethod];
6113 else if(symbol.type && symbol.type.kind == enumType)
6115 row.icon = icons[typeEnumValue];
6119 BitmapResource bitmap = null;
6120 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6122 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6125 bitmap = { bitmapName };
6126 membersList.AddResource(bitmap);
6129 row.icon = bitmap ? bitmap : icons[typeData];
6136 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6138 DataRow row = membersList.FindString(symbol.string);
6141 row = membersList.AddString(symbol.string);
6142 if(symbol.type.kind == functionType)
6143 row.icon = icons[typeMethod];
6144 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6146 row.icon = icons[typeClass];
6150 row.icon = icons[typeDataType];
6157 ListModule(this.privateModule, 1, listClasses);
6158 // TODO: Implement this with name space
6162 for(data = globalData.first; data; data = data.next)
6164 DataRow row = membersList.FindString(data.name);
6166 data.dataType = ProcessTypeString(data.dataTypeString, false);
6169 row = membersList.AddString(data.name);
6171 if(data.dataType && data.dataType.kind == TypeEnum)
6173 row.icon = icons[typeEnumValue];
6177 BitmapResource bitmap = null;
6178 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6180 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6183 bitmap = { bitmapName };
6184 membersList.AddResource(bitmap);
6187 row.icon = bitmap ? bitmap : icons[typeData];
6195 DataRow row = membersList.AddString("Min");
6196 row.icon = icons[typeMethod];
6198 row = membersList.AddString("Max");
6199 row.icon = icons[typeMethod];
6201 row = membersList.AddString("Abs");
6202 row.icon = icons[typeMethod];
6204 row = membersList.AddString("Sgn");
6205 row.icon = icons[typeMethod];
6211 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6213 EditBoxStream f { editBox = editBox };
6218 updatingCode = true;
6220 if(!method.dataType)
6221 method.dataType = ProcessTypeString(method.dataTypeString, false);
6223 DeleteJunkBefore(f, function.loc.start.pos, &position);
6224 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6226 // ADDING METHOD HERE
6228 Type dataType = method.dataType;
6229 Type returnType = dataType.returnType;
6231 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6237 if(extraIndent) f.Printf(" ");
6239 OutputType(f, returnType, false);
6243 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6245 if(dataType.thisClass.shortName)
6246 f.Printf(dataType.thisClass.shortName);
6248 f.Printf(dataType.thisClass.string);
6251 f.Printf(method.name);
6253 for(param = dataType.params.first; param; param = param.next)
6255 // Decided not to write void...
6256 if(param.kind != voidType)
6258 OutputType(f, param, true);
6264 if(extraIndent) f.Printf(" ");
6265 f.Printf(" %c\n", OpenBracket);
6267 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6273 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6274 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6276 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6278 if(extraIndent) f.Printf(" ");
6279 f.Printf(" return true;\n");
6281 else if(returnType && returnType.kind != voidType)
6283 if(extraIndent) f.Printf(" ");
6284 f.Printf(" return 0;\n");
6289 if(extraIndent) f.Printf(" ");
6291 if(returnType.kind != voidType)
6292 f.Printf("return ");
6293 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6294 for(param = dataType.params.first; param; param = param.next)
6296 if(param.prev) f.Printf(", ");
6297 if(param.kind != voidType)
6298 f.Printf(param.name);
6304 if(extraIndent) f.Printf(" ");
6305 f.Printf(" %c", CloseBracket);
6310 if(extraIndent) { x1 += 3; x2 += 3; }
6311 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6313 this.updatingCode = false;
6317 // Return false if we overrided a function and don't want to run params listing
6318 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6320 bool didOverride = false;
6321 EditLine line = editBox.line;
6322 char * text = line.text;
6323 int lineNum, charPos;
6324 Expression exp = null;
6327 //Identifier id = null;
6328 Expression memberExp = null;
6329 Identifier realIdentifier = null;
6331 if(!parsing) return true;
6332 if(!privateModule) return !didOverride;
6334 insideFunction = null;
6336 charPos = editBox.charPos + 1;
6337 if(!membersListShown)
6342 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6344 EditBoxStream f { editBox = editBox };
6346 updatingCode = true;
6347 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6351 if(!f.Seek(-1, current))
6354 if(!isspace(ch)) break;
6355 f.Seek(-1, current);
6357 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6359 lineNum = editBox.lineNumber + 1;
6360 charPos = editBox.charPos + 1;
6362 updatingCode = false;
6365 if(!membersListShown)
6367 memberExp = FindExpTree(ast, lineNum, charPos);
6368 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6373 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6375 EditBoxStream f { editBox = editBox };
6378 updatingCode = true;
6380 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6383 if(ch == '}' || ch == ',' || ch == ')')
6385 f.Seek(-1, current);
6393 if(!f.Seek(-1, current))
6396 if(!isspace(ch)) break;
6397 f.Seek(-1, current);
6401 f.Seek(-1, current);
6403 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6405 lineNum = editBox.lineNumber + 1;
6406 charPos = editBox.charPos + 1;
6408 updatingCode = false;
6411 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6416 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6417 lineNum = editBox.lineNumber + 1;
6418 charPos = editBox.charPos/* + 1*/;
6422 char tempString[1024];
6423 char * string = null;
6424 CodePosition idStart, idEnd;
6426 if(membersListShown)
6428 char * buffer = membersLine.text;
6430 bool firstChar = true;
6432 string = tempString;
6434 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6436 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6437 if(!isSpace) firstChar = false;
6439 string[len++] = buffer[c];
6443 else //if(realIdentifier)//if(id)
6446 char * buffer = id.string;
6448 bool firstChar = true;
6450 string = tempString;
6451 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6453 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6454 if(!isSpace) firstChar = false;
6456 string[len++] = buffer[c];
6462 EditLine editLine = editBox.line;
6463 bool firstChar = true;
6466 string = tempString;
6467 for(y = lineNum-1; y >= 0; y--)
6469 char * buffer = editLine.text;
6470 int lineCount = editLine.count;
6471 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6473 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6478 idEnd.charPos = x + 2;
6483 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6486 idEnd.charPos = x + 2;
6493 if(!isalnum(buffer[x]) && buffer[x] != '_')
6499 memmove(string+1, string, len++);
6500 string[0] = buffer[x];
6504 //if(done || firstChar)
6505 if(done || !firstChar)
6507 editLine = editLine.prev;
6510 if(!strcmp(string, "case"))
6516 else if(!strcmp(string, "return"))
6522 else if(!strcmp(string, "delete"))
6528 else if(!strcmp(string, "new"))
6534 else if(!strcmp(string, "renew"))
6542 idStart.charPos = x + 1;
6543 idStart.line = y + 1;
6546 if(!membersListShown)
6548 membersList.Clear();
6549 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6551 Type type = memberExp.member.exp.expType;
6552 if(pointer == 2 && type)
6554 if(type.kind == pointerType || type.kind == arrayType)
6563 ListSymbols(exp, enumOnly, string, realIdentifier);
6565 membersList.Sort(null, 1);
6570 // Virtual function override
6571 Identifier id = GetDeclId(insideFunction.declarator);
6572 char * string = id ? id.string : null;
6574 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6577 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6578 insideFunction = null;
6581 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6586 if(!didOverride) //insideFunction)
6588 rowCount = membersList.rowCount;
6591 DataRow row = string ? membersList.FindSubString(string) : null;
6592 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6594 char * newString = row.string;
6595 if(!membersListShown)
6597 membersLoc.start.line = idStart.line-1;
6598 membersLoc.start.charPos = idStart.charPos-1;
6599 //membersLoc.end = membersLoc.start;
6600 membersLoc.end.charPos = idEnd.charPos-1;
6601 membersLoc.end.line = idEnd.line-1;
6602 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6603 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6608 membersList.Destroy(0);
6609 membersListShown = false;
6612 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6614 line, membersLoc.start.line, membersLoc.start.charPos,
6615 line, membersLoc.end.line, membersLoc.end.charPos);
6616 editBox.PutS(newString);
6622 row = membersList.FindSubStringi(string);
6624 membersList.currentRow = row;
6625 membersList.currentRow.selected = false;
6628 membersList.currentRow = row;
6630 if(!membersListShown)
6634 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6635 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6636 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6637 editBox.GetCaretPosition(caret);
6638 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6640 membersList.master = this;
6642 caret.y += editBox.GetCaretSize();
6644 membersList.Create();
6647 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6648 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6649 Window parent = membersList.parent;
6651 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6653 y -= editBox.GetCaretSize() + membersList.size.h;
6654 membersAbove = true;
6657 membersAbove = false;
6659 membersList.position = { x, y };
6663 membersLoc.start.line = lineNum - 1;
6665 if(string && string[0])
6667 membersLoc.start.charPos = idStart.charPos-1;
6668 membersLoc.end = membersLoc.start;
6669 //membersLoc.end.charPos = id.loc.end.charPos-1;
6670 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6674 membersLoc.start.charPos = charPos;
6675 membersLoc.end = membersLoc.start;
6676 membersLoc.end.charPos = charPos;
6678 membersListShown = true;
6680 // Hack to keep caret shown
6681 editBox.GetCaretPosition(caret);
6682 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6685 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6691 SetCurrentContext(globalContext);
6694 return !didOverride;
6697 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6699 EditLine line = editBox.line;
6700 char * text = line.text;
6701 int lineNum, charPos;
6702 Expression exp = null;
6706 if(!parsing) return;
6708 charPos = editBox.charPos + 1;
6711 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6713 EditBoxStream f { editBox = editBox };
6716 updatingCode = true;
6717 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6720 if(ch == '}' || ch == ',' || ch == ')')
6722 f.Seek(-1, current);
6730 if(!f.Seek(-1, current))
6733 if(!isspace(ch)) break;
6734 f.Seek(-1, current);
6738 f.Seek(-1, current);
6740 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6742 lineNum = editBox.lineNumber + 1;
6743 charPos = editBox.charPos + 1;
6745 updatingCode = false;
6748 charPos = Min(charPos, l1.count + 1);
6750 FindParamsTree(ast, lineNum, charPos);
6752 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6753 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6755 ::functionType = null;
6756 ::instanceType = null;
6759 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6760 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6764 Window parent = paramsList.parent;
6766 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6769 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6770 // ( Dummy exp: always ends up with same memory)
6772 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6773 editBox.GetCaretPosition(paramsPosition);
6774 this.paramsPosition.y += editBox.GetCaretSize();
6777 FreeType(this.functionType);
6778 FreeType(this.instanceType);
6780 this.functionType = ::functionType;
6781 this.instanceType = ::instanceType;
6783 if(this.functionType) this.functionType.refCount++;
6784 if(this.instanceType) this.instanceType.refCount++;
6786 this.paramsID = ::paramsID;
6787 functionExp = paramsInsideExp;
6789 paramsList.master = this;
6791 paramsList.Create();
6793 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6794 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6796 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6798 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6802 paramsAbove = false;
6803 if(x + paramsList.size.w > parent.clientSize.w)
6805 x = parent.clientSize.w - paramsList.size.w;
6809 paramsList.position = { x, y };
6811 // Hack to keep caret shown
6814 editBox.GetCaretPosition(caret);
6815 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6818 this.paramsShown = true;
6820 else if((!::functionType && !::instanceType) || reposition)
6822 paramsList.Destroy(0);
6823 paramsShown = false;
6825 FreeType(this.functionType);
6826 FreeType(this.instanceType);
6827 this.functionType = null;
6828 this.instanceType = null;
6832 SetCurrentContext(globalContext);
6840 designer.visible = true;
6841 designer.Activate();
6847 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6849 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };
6854 static int nofdigits(int v)
6856 if(v == MININT) return 10 + 1;
6857 if(v < 0) return nofdigits(-v) + 1;