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;
120 class EditFileDialog : FileDialog
124 if(!ide.projectView && ideSettings.ideFileDialogLocation)
125 currentDirectory = ideSettings.ideFileDialogLocation;
126 return FileDialog::OnCreate();
130 EditFileDialog codeEditorFileDialog
132 type = multiOpen, text = $"Open",
133 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType);
134 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
137 EditFileDialog codeEditorFormFileDialog
139 type = open, text = $"Open Project",
140 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType),
141 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
144 define OpenBracket = '{';
145 define CloseBracket = '}';
150 actionDeleteMethod = 2,
151 actionDetachMethod = 3,
152 actionAttachMethod = 4,
153 actionReattachMethod = 5
156 //extern StatusField pos, ovr, caps, num;
157 //extern Class thisClass;
163 bool parseError = false;
168 Expression ctxInsideExp;
169 Expression paramsInsideExp;
170 ClassFunction insideFunction;
178 /****************************************************************************
180 ****************************************************************************/
182 static void OutputString(File f, char * string)
185 for(c = 0; string[c]; c++)
187 if(string[c] == '\"')
189 else if(string[c] == '\\')
196 void OutputType(File f, Type type, bool outputName)
206 if(!type.isSigned) f.Printf("unsigned ");
210 if(!type.isSigned) f.Printf("unsigned ");
214 if(!type.isSigned) f.Printf("unsigned ");
218 if(!type.isSigned) f.Printf("unsigned ");
222 if(!type.isSigned) f.Printf("unsigned ");
232 // ADD CODE TO DECIDE WHETHER TO OUTPUT FULLY QUAlIFIED OR NOT:
233 f.Printf(type._class.shortName ? type._class.shortName : type._class.string);
242 OutputType(f, type.type, false);
245 OutputType(f, type.type, false);
264 if(type.kind == arrayType)
267 f.Printf("%d", type.arraySize);
273 void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
279 f.Seek(pos - *position, current);
281 // Try to delete spaces and \n before...
287 /*else if(ch == '\n')
289 // Look for // comments on the line before
290 EditBox editBox = f.editBox;
291 EditLine line = editBox.line;
298 for(c = 0; text[c]; c++)
307 if(text[c] == '/' && last == '/')
319 f.DeleteBytes(before);
324 void GetLocText(EditBox editBox, File f, int position, Location loc, char ** text, int * size, int pad, int linePad)
329 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
331 // Cut & Paste function
337 f.Seek(loc.start.pos - position, current);
339 x1 = editBox.charPos;
340 y1 = editBox.lineNumber;
341 f.Seek(loc.end.pos - loc.start.pos, current);
343 x2 = editBox.charPos;
344 y2 = editBox.lineNumber;
345 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
347 *size = editBox.SelSize();
348 *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
349 editBox.GetSel(*text, false);
352 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
353 f.Printf(""); // Make the stream point to where the editbox is
356 void Code_FixProperty(Property prop, Instance object)
358 Designer::FixProperty(prop, object);
361 bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
364 if(prop.dataTypeString && (!prop.IsSet || prop.IsSet(selected.instance)))
366 Class dataType = prop.dataTypeClass;
369 dataType = prop.dataTypeClass = eSystem_FindClass(test._class.module, prop.dataTypeString);
371 if(dataType && dataType._vTbl && dataType.type == structClass)
373 void * dataForm = new0 byte[dataType.structSize];
374 void * dataTest = new0 byte[dataType.structSize];
376 ((void (*)(void *, void *))(void *)prop.Get)(selected.instance, dataForm);
377 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
379 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
381 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
387 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
389 void * dataForm, * dataTest;
391 dataForm = ((void *(*)(void *))(void *)prop.Get)(selected.instance);
392 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
394 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
396 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
400 else if(dataType && dataType._vTbl)
402 DataValue dataForm, dataTest;
404 GetProperty(prop, selected.instance, &dataForm);
405 GetProperty(prop, test, &dataTest);
407 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
409 SetProperty(prop, test, dataForm);
411 // In case setting on test unset on real instance (e.g. isDefault)
412 if(strcmp(prop.name, "name"))
414 GetProperty(prop, selected.instance, &dataTest);
415 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
416 SetProperty(prop, selected.instance, dataForm);
425 bool Code_IsPropertyDisabled(ObjectInfo selected, char * name)
427 bool disabled = false;
428 if(selected.oClass == selected)
431 if(selected.classDefinition)
433 for(def = selected.classDefinition.definitions->first; def; def = def.next)
435 if(def.type == defaultPropertiesClassDef)
438 for(prop = def.defProperties->first; prop; prop = prop.next)
440 if(prop.identifiers && prop.identifiers->first)
442 Identifier id = prop.identifiers->first;
443 if(prop.variable && !strcmp(id.string, name))
455 else if(selected.instCode)
458 if(selected.instCode.members)
460 for(members = selected.instCode.members->first; members; members = members.next)
462 if(members.type == dataMembersInit && members.dataMembers)
465 for(prop = members.dataMembers->first; prop; prop = prop.next)
467 if(prop.identifiers && prop.identifiers->first)
469 Identifier id = prop.identifiers->first;
470 if(prop.variable && !strcmp(id.string, name))
485 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
490 method.dataType = ProcessTypeString(method.dataTypeString, false);
491 if(!method.dataType.thisClass && !isForm)
494 method.dataType.thisClass = selectedClass;
496 //result = MatchTypes(method.dataType, type, null, regClass, regClass, false);
497 result = MatchTypes(type, method.dataType, null, regClass, regClass, false, true, true, false);
499 method.dataType.thisClass = null;
503 bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo object)
505 bool confirmation = true;
506 Statement body = function.body;
507 // Check if it contains any code
508 if((!body.compound.declarations || !body.compound.declarations->count) && (!body.compound.statements || body.compound.statements->count <= 1))
510 Class moduleClass = eSystem_FindClass(object.instance._class.module, "Module");
511 Statement stmt = body.compound.statements ? body.compound.statements->first : null;
512 Type dataType = method.dataType;
513 Type returnType = dataType.returnType;
514 Expression exp = null;
517 method.dataType = ProcessTypeString(method.dataTypeString, false);
519 confirmation = false;
521 // Check if default function should be calling base class:
522 if(object.instance._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
524 if(returnType.kind != voidType)
526 if(!stmt || stmt.type != returnStmt || !stmt.expressions || stmt.expressions->count != 1)
530 exp = stmt.expressions->first;
531 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
533 if( (exp.type != identifierExp || strcmp(exp.identifier.string, "true")) &&
534 (exp.type != constantExp || strcmp(exp.constant, "1")))
539 if(exp.type != constantExp || strcmp(exp.constant, "0"))
554 if(returnType.kind != voidType)
556 if(stmt.type == returnStmt && stmt.expressions && stmt.expressions->count == 1)
557 exp = stmt.expressions->first;
559 else if(stmt.type == expressionStmt && stmt.expressions && stmt.expressions->count == 1)
560 exp = stmt.expressions->first;
563 if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
567 Identifier id = exp.call.exp.identifier;
568 Class base = object.instance._class;
569 if(!id._class || (id._class.name && !strcmp(id._class.name, base.name)) || strcmp(id.string, method.name))
573 Expression arg = exp.call.arguments ? exp.call.arguments->first : null;
574 if(!arg || arg.type != identifierExp || strcmp("this", arg.identifier.string))
580 for(param = dataType.params.first; param; param = param.next)
582 if(!arg || arg.type != identifierExp || strcmp(param.name, arg.identifier.string))
587 arg = arg ?arg.next : null;
594 return !confirmation;
597 class CodeEditor : Window
599 background = marginColor;
600 borderStyle = sizableDeep;
605 isActiveClient = true;
606 anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
609 // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
610 // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
612 SheetType sheetSelected;
617 Context globalContext { };
618 OldList excludedSymbols { offset = (uint)&((Symbol)0).left };
631 MethodAction methodAction;
633 ClassFunction function;
635 char methodName[1024];
640 bool membersListShown;
643 EditLine membersLine;
645 Type functionType, instanceType;
649 Point paramsPosition;
650 Expression functionExp;
653 BitmapResource icons[CodeObjectType];
655 FontResource boldFont { $"Tahoma", 8.25f, bold = true, window = this };
656 FontResource normalFont { $"Tahoma", 8.25f, window = this };
658 Module privateModule;
659 NameSpace globalData;
662 OpenedFileInfo openedFileInfo;
664 FontResource font { codeFont.faceName, codeFont.size };
665 saveDialog = codeEditorFileDialog;
667 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
669 void ProcessCaretMove(EditBox editBox, int line, int charPos)
672 ObjectInfo classItem;
674 // OnActivateClient is called after OnActivate
677 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
680 if(sheet.codeEditor != this) return;
684 for(classItem = classes.first; classItem; classItem = classItem.next)
686 ClassDefinition classDef = classItem.classDefinition;
687 if(classDef && classDef.loc.Inside(line, charPos))
694 for(object = classItem.instances.first; object; object = object.next)
698 if(object.instCode.loc.Inside(line, charPos))
703 sheet.SelectObject(object);
705 sheet.SelectObject(classItem);
710 //sheet.SelectObject(null);
714 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
718 expectingMove = false;
724 if(line-1 != membersLoc.start.line)
728 char * buffer = membersLine.text;
731 if(charPos - 1 < membersLoc.start.charPos)
733 else if(charPos - 1 > membersLoc.end.charPos)
735 char * buffer = membersLine.text;
736 //if(membersList.currentRow)
740 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
741 if(buffer[c] != ' ' && buffer[c] != '\t')
743 if(c < charPos && buffer[c])
750 membersList.Destroy(0);
751 membersListShown = false;
755 bool back = codeModified;
756 codeModified = false;
758 InvokeParameters(false, false, false);
759 /*if(membersListShown)
760 InvokeAutoComplete(false, 0, true);*/
767 watch(modifiedDocument)
769 ProjectView projectView = ide.projectView;
772 ProjectNode node = projectView.GetNodeFromWindow(this, null, false);
775 node.modified = modifiedDocument;
776 projectView.Update(null);
784 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
785 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
786 tabKey = true, smartHome = true;
787 tabSelection = true, maxLineSize = 65536, parent = this, hasHorzScroll = true, hasVertScroll = true;
788 selectionColor = selectionColor, selectionText = selectionText,
789 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
790 font = font, borderStyle = none;
791 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
793 bool OnMouseOver(int x, int y, Modifiers mods)
795 CodeEditor editor = (CodeEditor)master;
796 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
801 void NotifyCaretMove(EditBox editBox, int line, int charPos)
803 // Update Line Numbers
805 int oldLine = lastLine;
806 display.FontExtent(font.font, " ", 1, null, &spaceH);
808 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
812 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
817 if(ide.activeClient == this)
818 ProcessCaretMove(editBox, line, charPos);
820 openedFileInfo.CaretMove(line, charPos);
823 void NotifyOvrToggle(EditBox editBox, bool overwrite)
825 ide.ovr.color = overwrite ? black : Color { 128, 128, 128 };
828 void NotifyUpdate(EditBox editBox)
835 designer.modifiedDocument = true;
838 modifiedDocument = true;
841 bool NotifyUnsetModified(EditBox editBox)
843 modifiedDocument = false;
847 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
849 if(!loadingFile && after.y != before.y)
851 ProjectView projectView = ide.projectView;
852 if(projectView && fileName)
855 // HOW WE MIGHT WANT TO DO IT:
856 char * text = before.line.text;
857 for(c = before.x-1; c>= 0; c--)
858 if(!isspace(text[c]))
860 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
862 // HOW VISUAL STUDIO DOES IT:
864 char * text = after.line.text;
865 for(c = after.line.count-1; c>= 0; c--)
866 if(!isspace(text[c]))
868 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
871 Update({ 0, 0, editBox.position.x, clientSize.h });
878 for(oClass = classes.first; oClass; oClass = oClass.next)
881 for(object = oClass.instances.first; object; object = object.next)
885 object.instCode.loc.start.AdjustAdd(before, after);
886 object.instCode.loc.end.AdjustAdd(before, after);
891 oClass.classDefinition.loc.start.AdjustAdd(before, after);
892 oClass.classDefinition.loc.end.AdjustAdd(before, after);
898 expectingMove = true;
902 if(before.y != after.y)
906 char * buffer = membersLine.text;
908 bool firstChar = true;
909 bool addedChar = false;
915 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
917 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
919 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
920 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
929 membersLoc.start.charPos++;
934 string[len++] = buffer[c];
938 row = membersList.currentRow;
939 if(row && row.selected)
943 membersLoc.start.charPos--;
951 row = membersList.FindSubString(string);
953 membersList.currentRow = row;
956 row = membersList.FindSubStringi(string);
958 membersList.currentRow = row;
959 membersList.currentRow.selected = false;
962 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
966 row = membersList.currentRow;
969 // Accept current string if hiding typing char
970 if(hide && row && row.selected)
972 char * string = row.string;
973 int len = strlen(string);
974 membersLoc.end.charPos -= after.x - before.x;
975 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
976 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
977 membersLine, membersLoc.end.line, membersLoc.end.charPos);
978 editBox.PutS(string);
979 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
981 after.x += membersLoc.start.charPos + len - before.x;
982 before.x = membersLoc.start.charPos + len;
987 membersList.Destroy(0);
988 membersListShown = false;
991 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
993 EditLine line = editBox.line;
994 char * text = line.text;
995 char ch = text[after.x-1];
996 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1000 // Can we call invoke auto complete here instead?
1010 // Force caret update already...
1011 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1012 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1014 editBox.GetCaretPosition(&caret);
1018 // Go back in the buffer until no space before
1020 codeModified = true;
1024 EditBoxStream f { editBox = editBox };
1028 if(text[after.x-1] == '>')
1034 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1038 if(!f.Seek(-1, current))
1041 if(!isspace(ch)) break;
1042 f.Seek(-1, current);
1044 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1046 line = editBox.lineNumber + 1;
1047 charPos = editBox.charPos + 1;
1051 exp = FindExpTree(ast, line, charPos);
1055 Type type = exp.expType;
1057 if(type && text[after.x-1] != '.')
1059 if(type.kind == TypePointer || type.kind == TypeArray)
1065 membersList.Clear();
1068 if(membersList.rowCount)
1070 membersList.Sort(null, 1);
1071 membersList.master = this;
1073 caret.y += editBox.GetCaretSize();
1076 membersList.Create();
1079 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1080 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1081 Window parent = membersList.parent;
1083 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1085 y -= editBox.GetCaretSize() + membersList.GetHeight();
1086 membersAbove = true;
1089 membersAbove = false;
1091 membersList.position = { x, y };
1095 membersLoc.start.line = line - 1;
1096 membersLoc.start.charPos = oldCharPos;
1097 membersLoc.end = membersLoc.start;
1098 membersListShown = true;
1103 SetCurrentContext(globalContext);
1105 codeModified = true;
1106 skipModified = true;
1107 if(text[after.x-1] == ':')
1108 InvokeAutoComplete(false, 0, false);
1109 else if(text[after.x-1] == '.')
1110 InvokeAutoComplete(false, 1, false);
1111 else if(text[after.x-1] == '>')
1112 InvokeAutoComplete(false, 2, false);
1113 skipModified = false;
1115 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1117 codeModified = true;
1118 skipModified = true;
1120 if(InvokeAutoComplete(true, 0, false))
1122 if(ch == '(' || ch == OpenBracket)
1123 InvokeParameters(true, true, false);
1125 InvokeParameters(this.functionType ? false : true, false, false);
1128 // InvokeAutoComplete(true, 0, false);
1129 skipModified = false;
1131 else if(ch == ')' || ch == '}' || ch == ';')
1133 codeModified = true;
1134 skipModified = true;
1136 InvokeParameters(false, true, false);
1137 skipModified = false;
1141 bool back = codeModified;
1142 codeModified = false;
1144 InvokeParameters(false, false, true);
1145 if(membersListShown)
1146 InvokeAutoComplete(false, 0, true);
1147 codeModified = back;
1152 bool back = codeModified;
1153 codeModified = false;
1156 InvokeParameters(false, false, true);
1157 /*if(membersListShown)
1158 InvokeAutoComplete(false, 0, true);*/
1160 codeModified = back;
1167 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1169 if(!loadingFile && after.y != before.y)
1171 ProjectView projectView = ide.projectView;
1172 if(projectView && fileName)
1173 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1174 Update({ 0, 0, editBox.position.x, clientSize.h });
1181 for(oClass = classes.first; oClass; oClass = oClass.next)
1185 for(object = oClass.instances.first; object; object = object.next)
1189 loc = &object.instCode.loc;
1191 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1192 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1194 object.instCode = null;
1198 loc->start.AdjustDelete(before, after);
1199 loc->end.AdjustDelete(before, after);
1203 if(oClass.classDefinition)
1205 loc = &oClass.classDefinition.loc;
1206 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1207 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1209 oClass.classDefinition = null;
1213 loc->start.AdjustDelete(before, after);
1214 loc->end.AdjustDelete(before, after);
1219 if(membersListShown)
1222 if(pasteOperation || before.y != after.y)
1226 char * buffer = membersLine.text;
1228 bool firstChar = true;
1232 if(before.x >= membersLoc.start.charPos)
1234 for(c = membersLoc.start.charPos; c<before.x && len < sizeof(string)-1; c++)
1236 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1237 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1242 if(!isSpace) firstChar = false;
1245 string[len++] = buffer[c];
1250 // If deleting spaces before...
1251 for(c = before.x; c<membersLoc.start.charPos; c++)
1253 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1261 membersLoc.start.charPos = before.x;
1264 if(membersLoc.end.charPos >= after.x)
1266 for(c = after.x; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1268 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1269 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1274 if(!isSpace) firstChar = false;
1277 string[len++] = buffer[c];
1285 membersLoc.end.charPos -= after.x - before.x;
1289 row = membersList.FindSubString(string);
1292 row = membersList.FindSubStringi(string);
1294 membersList.currentRow = row;
1295 membersList.currentRow.selected = false;
1298 membersList.currentRow = row;
1300 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1305 membersList.Destroy(0);
1306 membersListShown = false;
1312 InvokeParameters(false, false);
1320 bool NotifyDropped(EditBox editBox, int x, int y)
1322 char * controlClass = toolBox.controlClass;
1323 if(controlClass && controlClass[0])
1327 ObjectInfo classObject;
1329 //editBox.NotifyCaretMove(this, editBox, y, x);
1330 editBox.GoToLineNum(y);
1331 editBox.GoToPosition(editBox.line, y, x);
1333 classObject = selected ? selected.oClass : null;
1335 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1336 selected = classObject.instances.last;
1339 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1342 AddObject(control, &object);
1344 designer.CreateObject(control, object, false, classObject.instance);
1345 // designer.PostCreateObject(control, object, false, classObject.instance);
1346 designer.DroppedObject(control, object, false, classObject.instance);
1348 sheet.AddObject(object, object.name, typeData /* className*/, true);
1351 //codeModified = true;
1358 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1360 if(key == Key { space, ctrl = true })
1362 membersList.Destroy(0);
1363 membersListShown = false;
1364 InvokeAutoComplete(false, 0, false);
1367 else if(key == Key { space, ctrl = true, shift = true })
1368 InvokeParameters(false, true, false);
1369 else if(key == escape)
1370 ide.RepositionWindows(true);
1371 else if(key == ctrlF7)
1375 ProjectNode node = ide.projectView.GetNodeFromWindow(this, null, false);
1377 node = ide.projectView.GetNodeFromWindow(this, null, true);
1381 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1382 $"It can't be compiled.");
1383 MessageBox { type = ok, parent = ide, master = ide, text = $"File not in project error", contents = s }.Modal();
1392 bool OnKeyDown(Key key, unichar ch)
1394 CodeEditor editor = (CodeEditor)master;
1395 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1397 if(editor.membersListShown)
1399 editor.membersList.Destroy(0);
1400 editor.membersListShown = false;
1403 if(editor.paramsShown)
1405 editor.paramsList.Destroy(0);
1406 editor.paramsShown = false;
1407 FreeType(editor.functionType);
1408 FreeType(editor.instanceType);
1410 editor.functionType = null;
1411 editor.instanceType = null;
1412 editor.paramsID = -1;
1416 return EditBox::OnKeyDown(key, ch);
1419 void OnVScroll(ScrollBarAction action, int position, Key key)
1421 if(anchor.left.distance)
1423 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1426 EditBox::OnVScroll(action, position, key);
1428 CodeEditor ce = (CodeEditor)parent;
1429 if(ce.openedFileInfo)
1430 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1434 void OnHScroll(ScrollBarAction action, int position, Key key)
1436 EditBox::OnHScroll(action, position, key);
1438 CodeEditor ce = (CodeEditor)parent;
1439 if(ce.openedFileInfo)
1440 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1447 fullRowSelect = false,
1450 borderStyle = bevel;
1451 // size = { 200, 400 };
1453 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1455 DataRow row = listBox.currentRow;
1458 char * string = row.string;
1460 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1462 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1463 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1464 editBox.PutS(string);
1467 membersListShown = false;
1472 bool OnKeyDown(Key key, unichar ch)
1474 CodeEditor editor = (CodeEditor) master;
1475 if(key == escape || key == leftAlt || key == rightAlt ||
1476 (key.ctrl && key.code != left && key.code != right &&
1477 key.code != leftShift && key.code != rightShift && key.code != space))
1479 if(editor.paramsShown)
1480 editor.paramsList.Destroy(0);
1481 if(editor.membersListShown)
1482 editor.membersList.Destroy(0);
1484 editor.paramsShown = false;
1485 FreeType(editor.functionType);
1486 FreeType(editor.instanceType);
1488 editor.functionType = null;
1489 editor.instanceType = null;
1490 editor.paramsID = -1;
1492 editor.membersListShown = false;
1496 return editor.editBox.OnKeyDown(key, ch);
1500 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1502 CodeEditor editor = (CodeEditor)master;
1506 editor.membersListShown = false;
1508 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1511 bool OnKeyHit(Key key, unichar ch)
1513 CodeEditor editor = (CodeEditor) master;
1517 case enter: case tab:
1519 DataRow row = currentRow;
1520 if(row && row.selected)
1522 char * string = row.string;
1524 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1525 editor.editBox.Delete(
1526 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1527 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1528 editor.editBox.PutS(string);
1531 editor.membersListShown = false;
1534 editor.editBox.OnKeyHit(key, ch);
1544 return ListBox::OnKeyHit(key, ch);
1550 // If before . or after
1551 //listBox.Destroy(true);
1552 result = editor.editBox.OnKeyHit(key, ch);
1567 clickThrough = true,
1569 borderStyle = contour,
1571 background = { 255,255,225 },
1573 OnKeyDown = membersList.OnKeyDown;
1575 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1577 CodeEditor editor = (CodeEditor)master;
1581 editor.membersListShown = false;
1583 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1586 bool OnKeyHit(Key key, unichar ch)
1588 CodeEditor editor = (CodeEditor)master;
1590 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1593 bool result = true; editor.editBox.OnKeyHit(key, ch);
1594 return (!created) ? false : result;
1601 void OnRedraw(Surface surface)
1603 CodeEditor editor = (CodeEditor) master;
1604 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1606 Type methodType = null;
1610 int functionW, nameW = 0;
1612 int spaceW, spaceH, commaW, commaWB, parW;
1614 int maxW = 0, lineW = 0;
1620 Font font = editor.normalFont.font;
1621 Font boldFont = editor.boldFont.font;
1622 Display display = this.display;
1624 if(!type) { return; };
1626 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1628 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1629 display.FontExtent(font, ", ", 2, &commaW, null);
1630 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1631 display.FontExtent(font, ")", 1, &parW, null);
1634 if(editor.functionType)
1636 PrintType(type.returnType, string, true, true);
1637 display.FontExtent(font, string, strlen(string), &functionW, null);
1639 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1640 totalW = nameW + functionW + 2 * parW;
1644 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1645 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1646 if(instanceName && type.kind != functionType)
1647 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1648 totalW = functionW + nameW;
1649 surface.TextFont(boldFont);
1652 surface.WriteText(x, y, string, strlen(string));
1653 x += functionW + spaceW;
1655 if(editor.functionType)
1658 surface.WriteText(x, y, type.name, strlen(type.name));
1660 surface.WriteText(x, y, "(", 1);
1663 if(methodType && !methodType.staticMethod)
1667 if(id == editor.paramsID)
1668 surface.TextFont(boldFont);
1670 if(methodType.methodClass)
1671 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1675 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1676 width += ((id == editor.paramsID) ? commaWB : commaW);
1681 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1686 x = 2 + nameW + spaceW + functionW + parW;
1690 if(methodType.methodClass)
1691 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1694 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1696 surface.WriteText(x, y, ",", 1);
1697 x += ((id == editor.paramsID) ? commaWB : commaW);
1705 if(id == editor.paramsID)
1706 surface.TextFont(font);
1710 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1712 for(param = type.params.first; param; param = param.next)
1714 char paramString[1024];
1717 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1718 surface.TextFont(boldFont);
1721 PrintType(param, paramString, true, true);
1722 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1724 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1729 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1734 x = 2 + nameW + spaceW + functionW + parW;
1738 surface.WriteText(x, y, paramString, strlen(paramString));
1742 surface.WriteText(x, y, ",", 1);
1743 x += ((id == editor.paramsID) ? commaWB : commaW);
1751 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1752 surface.TextFont(font);
1757 surface.WriteText(x, y, ")", 1);
1759 else if(instanceName && type.kind != functionType)
1761 surface.WriteText(x, y, instanceName, strlen(instanceName));
1765 bool OnResizing(int * w, int * h)
1767 CodeEditor editor = (CodeEditor) master;
1768 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1770 Type methodType = null;
1774 int functionW = 0, nameW = 0;
1776 int spaceW, spaceH, commaW, commaWB, parW;
1778 int maxW = 0, lineW = 0;
1783 Font font = editor.normalFont.font;
1784 Font boldFont = editor.boldFont.font;
1785 Display display = this.display;
1787 if(type.kind == TypeKind::methodType)
1790 ProcessMethodType(type.method);
1791 type = type.method.dataType;
1794 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1795 display.FontExtent(font, ", ", 2, &commaW, null);
1796 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1797 display.FontExtent(font, ")", 1, &parW, null);
1800 if(editor.functionType && type)
1802 PrintType(type.returnType, string, true, true);
1803 display.FontExtent(font, string, strlen(string), &functionW, null);
1805 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1806 totalW = nameW + spaceW + functionW + 2 * parW;
1810 PrintType(type, string, false, true); // /*true);
1811 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1812 if(instanceName && type.kind != functionType)
1813 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1814 totalW = functionW + nameW + spaceW;
1817 if(editor.functionType)
1823 if(methodType.methodClass)
1824 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1825 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1826 width += ((id == editor.paramsID) ? commaWB : commaW);
1831 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1844 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1846 for(param = type.params.first; param; param = param.next)
1848 char paramString[1024];
1852 PrintType(param, paramString, true, true);
1853 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1855 width += ((id == editor.paramsID) ? commaWB : commaW);
1860 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1877 *w = realW + totalW + 4;
1883 Menu fileMenu { menu, $"File", f }; // MenuPlacement?
1884 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1885 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1887 Menu debugMenu { menu, $"Debug", d }; // MenuPlacement?
1888 MenuItem debugRunToCursor
1890 debugMenu, $"Run To Cursor", c, Key { f10, ctrl = true };
1891 bool NotifySelect(MenuItem selection, Modifiers mods)
1893 ProjectView projectView = ide.projectView;
1894 if(!projectView.buildInProgress)
1896 int line = editBox.lineNumber + 1;
1899 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1900 ProjectConfig config = projectView.project.config;
1901 ide.debugger.RunToCursor(compiler, config, fileName, line, false);
1908 MenuItem debugSkipRunToCursor
1910 debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true };
1911 bool NotifySelect(MenuItem selection, Modifiers mods)
1913 ProjectView projectView = ide.projectView;
1914 int line = editBox.lineNumber + 1;
1917 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1918 ProjectConfig config = projectView.project.config;
1919 ide.debugger.RunToCursor(compiler, config, fileName, line, true);
1925 MenuDivider { debugMenu };
1926 MenuItem debugToggleBreakpoint
1928 debugMenu, $"Toggle Breakpoint", t, f9;
1929 bool NotifySelect(MenuItem selection, Modifiers mods)
1931 ProjectView projectView = ide.projectView;
1932 if(projectView && fileName)
1934 int line = editBox.lineNumber + 1;
1935 char name[MAX_LOCATION];
1937 // TOFIX: This only looks at the filename...
1938 GetLastDirectory(fileName, name);
1939 if(ide && ide.workspace)
1941 for(p : ide.workspace.projects)
1943 if(p.topNode.Find(name, false))
1951 for(p : ide.workspace.projects)
1953 if(IsPathInsideOf(fileName, p.topNode.path))
1961 ide.debugger.ToggleBreakpoint(fileName, line, prj);
1971 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1975 designer.parent = parent;
1978 toolBox = ((IDEWorkSpace)master).toolBox;
1980 // Debugger bug here: value of toolBox appears as 0
1982 sheet = ((IDEWorkSpace)master).sheet;
1987 bool OnClose(bool parentClosing)
1991 if(ide.workspace && fileName)
1992 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
1993 if(inUseDebug && !debugClosing)
1995 debugClosing = true;
1997 if(CloseConfirmation(false))
2000 OnFileModified({ modified = true }, null);
2002 debugClosing = false;
2005 if(designer && !designer.closing)
2007 if(designer.visible)
2014 //Window formEditor = designer;
2015 //formEditor.Destroy(0);
2018 ide.AdjustFileMenus();
2023 void OnDestroy(void)
2025 ObjectInfo oClass, next;
2026 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2028 FreeType(this.functionType);
2029 FreeType(this.instanceType);
2034 designer.codeEditor = null;
2035 designer.Destroy(0);
2039 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2041 ObjectInfo object, next;
2043 for(object = oClass.instances.first; object; object = next)
2048 Designer::DestroyObject(object.instance);
2049 delete object.instance;
2051 sheet.DeleteObject(object);
2053 oClass.instances.Delete(object);
2057 Designer::DestroyObject(oClass.instance);
2058 delete oClass.instance;
2060 sheet.DeleteObject(oClass);
2062 classes.Delete(oClass);
2065 if(windowClass && windowClass.data)
2066 UnapplySkin(windowClass);
2070 if(sheet.codeEditor == this)
2072 sheet.codeEditor = null;
2073 toolBox.codeEditor = null;
2079 ProjectView projectView = ide.projectView;
2082 ProjectNode node = projectView.GetNodeFromWindow(this, null, false);
2083 if(node && node.modified)
2085 node.modified = false;
2086 projectView.Update(null);
2092 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2094 // 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
2096 if(directActivation)
2097 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2099 if(active && directActivation)
2102 openedFileInfo.Activate();
2106 Location * loc = null;
2107 UpdateFormCode(); // To ensure update when modifying properties...
2109 // Got to the right spot in code so we don't lose our form selection...
2112 if(selected.instCode)
2113 loc = &selected.instCode.loc;
2114 else if(selected.classDefinition)
2115 loc = &selected.classDefinition.loc;
2117 line = editBox.lineNumber + 1;
2118 charPos = editBox.charPos + 1;
2123 if(selected && !loc->Inside(line, charPos))
2125 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2126 line = editBox.lineNumber + 1;
2127 charPos = editBox.charPos + 1;
2129 else if(selected && selected.classDefinition)
2132 for(object = selected.instances.first; object; object = object.next)
2136 if(object.instCode.loc.Inside(line, charPos))
2142 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2143 line = editBox.lineNumber + 1;
2144 charPos = editBox.charPos + 1;
2149 ProcessCaretMove(editBox, line, charPos);
2155 bool OnSaveFile(char * fileName)
2162 f = FileOpen(fileName, write);
2165 if(!ide.projectView)
2166 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2170 this.fileName = fileName; // Put this here because the form designer will check for it...
2171 designer.fileName = fileName;
2172 designer.modifiedDocument = false;
2174 editBox.Save(f, false);
2175 modifiedDocument = false;
2183 bool OnFileModified(FileChange fileChange, char * param)
2185 bool reload = false;
2186 if(visible == false && inUseDebug == true)
2192 sprintf(message, $"The document %s was modified by another application.\n"
2193 "Would you like to reload it and lose your changes?", fileName);
2194 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2195 contents = message }.Modal() == yes)
2201 File f = FileOpen(fileName, read);
2204 int lineNumber, charPos, len;
2208 updatingCode = true;
2209 lineNumber = editBox.lineNumber;
2210 charPos = editBox.charPos;
2211 scroll = editBox.scroll;
2214 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2215 len = strlen(editBox.line.text);
2216 editBox.GoToLineNum(lineNumber);
2217 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2218 editBox.scroll = scroll;
2219 updatingCode = false;
2220 loadingFile = false;
2222 codeModified = true;
2226 designer.modifiedDocument = false;
2228 modifiedDocument = false;
2236 void OnRedraw(Surface surface)
2239 surface.SetBackground(marginColor);
2240 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2241 if(ideSettings.showLineNumbers)
2243 int currentLineNumber;
2248 surface.textOpacity = false;
2249 surface.font = font.font;
2250 surface.TextExtent(" ", 1, null, &spaceH);
2251 currentLineNumber = editBox.scroll.y / spaceH + 1;
2253 surface.SetForeground(lineNumbersColor);
2254 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2256 // Highlight current line
2257 if(editBox.lineNumber == currentLineNumber - 1)
2259 surface.SetBackground(selectedMarginColor);
2260 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2261 surface.SetBackground(marginColor);
2263 sprintf(lineText,"%5u ", currentLineNumber % 100000);
2264 if(currentLineNumber <= editBox.numLines)
2265 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,6);
2267 currentLineNumber++;
2271 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2273 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2274 int lineCursor, lineTopFrame, breakpointLines[128];
2275 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2276 Debugger debugger = ide.debugger;
2277 BitmapResource bmpRes;
2279 boxH = clientSize.h;
2280 scrollY = editBox.scroll.y;
2281 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2283 bpOnCursor = bpOnTopFrame = false;
2284 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2287 for(i = 0; i < count; i++)
2289 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2291 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2292 if(breakpointLines[i] == lineCursor)
2294 if(breakpointLines[i] == lineTopFrame)
2295 bpOnTopFrame = true;
2298 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2300 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2303 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2304 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2305 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2307 if(editBox.anchor.left.distance)
2309 if(editBox.horzScroll && editBox.horzScroll.visible)
2311 surface.SetBackground(control);
2312 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2317 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2322 lineY = (line - 1) * lineH;
2323 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2325 Bitmap bitmap = resource.bitmap;
2327 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2334 char ext[MAX_EXTENSION];
2335 char * fileName = property::fileName;
2337 if(SearchString(fileName, 0, "Makefile", false, true))
2338 editBox.useTab = true;
2339 designer.fileName = fileName;
2343 GetExtension(fileName, ext);
2344 if(!strcmpi(ext, "ec"))
2346 codeModified = true;
2350 if(!strcmpi(ext, "ec") || !strcmpi(ext, "c") || !strcmpi(ext, "cc") || !strcmpi(ext, "cpp") || !strcmpi(ext, "eh") || !strcmpi(ext, "hh") || !strcmpi(ext, "hpp") || !strcmpi(ext, "h") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cxx"))
2351 editBox.syntaxHighlighting = true;
2353 editBox.syntaxHighlighting = false;
2356 display.FontExtent(font.font, " ", 1, &spaceW, null);
2357 editBox.anchor = Anchor
2359 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2360 right = 0, top = 0, bottom = 0
2369 display.FontExtent(font.font, " ", 1, &spaceW, null);
2370 editBox.anchor = Anchor
2372 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2373 right = 0, top = 0, bottom = 0
2378 bool LoadFile(char * filePath)
2380 File f = FileOpen(filePath, read);
2383 // Added this here...
2384 fileName = filePath;
2386 updatingCode = true;
2388 updatingCode = false;
2389 loadingFile = false;
2398 void DebugMenusDisabled()
2400 bool debugMenusDisabled = ide.GetDebugMenusDisabled();
2401 debugRunToCursor.disabled = debugMenusDisabled;
2402 debugSkipRunToCursor.disabled = debugMenusDisabled;
2403 debugToggleBreakpoint.disabled = debugMenusDisabled;
2409 ProjectView projectView = ide.projectView;
2412 designer.fileName = fileName;
2418 sprintf(title, $"Untitled %d", documentID);
2419 // designer.fileName = CopyString(title);
2420 designer.fileName = title;
2423 DebugMenusDisabled();
2425 for(c = 0; c < CodeObjectType::enumSize; c++)
2426 icons[c] = BitmapResource { iconNames[c], window = this };
2428 codeModified = true;
2440 selected.modified = true;
2441 selected.oClass.modified = true;
2443 designer.modifiedDocument = true;
2444 modifiedDocument = true;
2445 formModified = true;
2448 /****************************************************************************
2450 ****************************************************************************/
2453 this.defines.Free(FreeModuleDefine);
2454 this.imports.Free(FreeModuleImport);
2461 FreeExcludedSymbols(this.excludedSymbols);
2462 FreeContext(this.globalContext);
2464 FreeGlobalData(&this.globalData);
2466 if(GetGlobalContext() == globalContext)
2468 SetGlobalData(null);
2469 SetGlobalContext(null);
2470 SetExcludedSymbols(null);
2471 SetTopContext(null);
2472 SetCurrentContext(null);
2475 SetPrivateModule(null);
2478 if(this.privateModule)
2480 FreeTypeData(this.privateModule);
2481 delete this.privateModule;
2482 this.privateModule = null;
2488 static bool reentrant = false;
2493 char * selectedClassName = null, * selectedName = null;
2494 int selectedPos = 0;
2495 Designer backDesigner;
2496 char oldWorkDir[MAX_LOCATION];
2497 char mainModuleName[MAX_FILENAME] = "";
2499 ImportedModule module;
2500 char extension[MAX_EXTENSION];
2502 Time parseCodeStart = GetTime();
2503 Time startTime, startFindClass;
2505 findClassTotalTime = 0;
2506 checkTypeTotalTime = 0;
2507 externalImportTotalTime = 0;
2508 findClassIgnoreNSTotalTime = 0;
2509 findSymbolTotalTime = 0;
2510 //ResetClassFindTime();
2514 // 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)
2515 if(reentrant) return;
2522 selectedClassName = CopyString(oClass.name);
2523 if(selected != oClass)
2525 ObjectInfo object = this.selected;
2526 selectedName = CopyString(object.name);
2530 for(check = this.oClass.instances.first; check; check = check.next)
2542 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2544 defines.Free(FreeModuleDefine);
2545 imports.Free(FreeModuleImport);
2547 SetGlobalData(&globalData);
2548 SetGlobalContext(globalContext);
2549 SetExcludedSymbols(&excludedSymbols);
2550 SetTopContext(globalContext);
2551 SetCurrentContext(globalContext);
2552 SetDefines(&defines);
2553 SetImports(&imports);
2554 SetCurrentNameSpace(null);
2557 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2558 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2559 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2560 "/I T:\\ecere\\include /E %s", argv[1]);
2564 ChangeWorkingDir("e:\\ec");
2565 sprintf(command, "gcc -x c -E -");
2566 fileInput = DualPipeOpen({ output = true, input = true }, command);
2567 SetFileInput(fileInput);
2572 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2574 fileInput.Write(buffer, 1, count);
2579 fileInput.CloseOutput();
2583 // TOCHECK: COULDN'T WE CALL FreeParser here?
2585 this.functionType = null;
2586 this.instanceType = null;
2589 sheet.SelectObject(null);
2595 // We don't want the designer to be notified of selection when deleting rows...
2596 backDesigner = designer;
2601 ObjectInfo _class, next;
2603 for(_class = classes.first; _class; _class = next)
2609 for(;object = _class.instances.first;)
2613 Designer::DestroyObject(object.instance);
2614 delete object.instance;
2616 sheet.DeleteObject(object);
2618 _class.instances.Delete(object);
2622 Designer::DestroyObject(_class.instance);
2623 delete _class.instance;
2625 sheet.DeleteObject(_class);
2627 classes.Delete(_class);
2633 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2634 if(windowClass && windowClass.data)
2635 UnapplySkin(windowClass);
2638 designer = backDesigner;
2641 fileInput = editFile = EditBoxStream { editBox = editBox };
2642 SetFileInput(fileInput);
2651 FreeContext(this.globalContext);
2652 FreeExcludedSymbols(this.excludedSymbols);
2655 FreeGlobalData(&this.globalData);
2657 if(this.privateModule)
2659 FreeTypeData(this.privateModule);
2660 delete this.privateModule;
2664 startTime = GetTime();
2665 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2667 printf("classes.count: %d\n", globalContext.classes.count);
2672 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2673 SetTargetBits(compiler.supportsBitDepth ? 32 : GetHostBits());
2676 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2678 SetPrivateModule(privateModule);
2681 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2682 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2683 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2684 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2685 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2688 fileName = this.fileName;
2690 if(ide.workspace && ide.workspace.projects && fileName)
2692 for(p : ide.workspace.projects)
2694 char path[MAX_LOCATION];
2696 MakePathRelative(fileName, p.topNode.path, path);
2697 MakeSlashPath(path);
2699 pn = p.topNode.FindWithPath(path, false);
2708 project = ide.project;
2710 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2712 ChangeWorkingDir(project.topNode.path);
2714 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2716 GetLastDirectory(fileName, mainModuleName);
2717 GetExtension(mainModuleName, extension);
2719 SetBuildingEcereCom(false);
2720 SetBuildingEcereComModule(false);
2722 // TODO: Get symbolsDir from project settings instead...
2725 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2726 ProjectConfig config = project.config;
2727 DirExpression objDir = project.GetObjDir(compiler, config);
2728 SetSymbolsDir(objDir.dir);
2731 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2732 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2736 switch(GetRuntimePlatform())
2738 case win32: SetSymbolsDir("obj/debug.win32"); break;
2739 case tux: SetSymbolsDir("obj/debug.linux"); break;
2740 case apple: SetSymbolsDir("obj/debug.apple"); break;
2742 SetIncludeDirs(null);
2743 SetSysIncludeDirs(null);
2747 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2749 // TODO FIX for configless project
2750 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2752 for(item : ide.project.config.options.preprocessorDefinitions)
2754 if(!strcmp(item, "BUILDING_ECERE_COM"))
2756 SetBuildingEcereCom(true);
2763 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2764 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2765 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2766 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2767 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2768 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2769 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2770 strcmpi(mainModuleName, "Mutex.ec")))
2772 SetBuildingEcereComModule(true);
2775 // Predeclare all classes
2777 char symFile[MAX_FILENAME];
2778 char symLocation[MAX_LOCATION];
2779 ImportedModule module, next;
2781 GetLastDirectory(fileName, symFile);
2782 ChangeExtension(symFile, "sym", symFile);
2784 strcpy(symLocation, GetSymbolsDir());
2785 PathCat(symLocation, symFile);
2787 // if(!GetEcereImported() && !GetBuildingEcereCom())
2788 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2791 startTime = GetTime();
2793 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2795 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2800 startTime = GetTime();
2802 // LoadSymbols(symLocation, normalImport, true);
2803 LoadSymbols(symLocation, preDeclImport, false);
2805 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2808 for(module = defines.first; module; module = next)
2811 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2814 defines.Delete(module);
2819 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2821 SetDefaultDeclMode(privateAccess);
2822 SetDeclMode(privateAccess);
2826 SetDefaultDeclMode(defaultAccess);
2827 SetDeclMode(defaultAccess);
2830 StripExtension(mainModuleName);
2831 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2832 defines.AddName(module);
2835 // SetYydebug(true);
2840 startTime = GetTime();
2841 startFindClass = checkTypeTotalTime;
2845 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2847 CheckDataRedefinitions();
2850 SetIncludeDirs(null);
2851 SetSysIncludeDirs(null);
2862 startTime = GetTime();
2864 PrePreProcessClassDefinitions();
2865 ComputeModuleClasses(privateModule);
2866 PreProcessClassDefinitions();
2867 ProcessClassDefinitions();
2869 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2870 startTime = GetTime();
2875 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2876 startTime = GetTime();
2878 ProcessInstantiations();
2880 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2883 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2885 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2886 if(!windowClass || windowClass.internalDecl)
2889 startTime = GetTime();
2891 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2892 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2893 eModule_Load(this.privateModule, "ecere", privateAccess);
2895 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2898 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2900 if(windowClass && windowClass.data)
2901 ApplySkin(windowClass, app.currentSkin.name, null);
2905 startTime = GetTime();
2907 for(external = ast->first; external; external = external.next)
2909 if(external.type == classExternal)
2911 ClassDefinition _class = external._class;
2912 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2914 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2917 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2919 Instance instance = eInstance_New(regClass);
2920 ObjectInfo classObject
2922 name = CopyString(_class._class.name);
2923 instance = instance;
2924 classDefinition = _class;
2925 oClass = classObject;
2928 classes.Add(classObject);
2932 // Moved this at bottom so that the file dialog doesn't show up in eCom
2933 designer.CreateObject(instance, classObject, true, null);
2934 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
2936 if(_class.definitions)
2940 for(def = _class.definitions->first; def; def = def.next)
2944 case defaultPropertiesClassDef:
2947 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
2949 Identifier id = propDef.identifiers->first;
2952 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
2955 Class propertyClass = prop.dataTypeClass;
2957 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
2958 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
2960 FreeType(propDef.initializer.exp.destType);
2961 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
2962 ProcessExpressionType(propDef.initializer.exp);
2964 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
2966 Expression computed = CopyExpression(propDef.initializer.exp);
2967 ComputeExpression(computed);
2969 if(computed.isConstant && computed.type == instanceExp && !id.next)
2973 if(computed.instance._class && computed.instance._class.symbol &&
2974 computed.instance._class.symbol.registered &&
2975 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
2977 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
2979 // This was saved in the control and shouldn't be freed by FreeExpression...
2980 if(propertyClass.type == normalClass)
2981 computed.instance.data = null;
2985 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
2986 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
2988 String temp = new char[strlen(computed.string)+1];
2989 ReadString(temp, computed.string);
2990 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
2994 propDef.variable = true;
2996 FreeExpression(computed);
3000 Expression computed = CopyExpression(propDef.initializer.exp);
3001 ComputeExpression(computed);
3002 if(computed.isConstant)
3004 //if(computed.type == memberExp) computed = computed.member.exp;
3006 if(computed.type == constantExp)
3008 Operand value = GetOperand(computed);
3009 DataValue valueData;
3010 valueData.i64 = value.i64;
3011 SetProperty(prop, instance, valueData);
3013 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3015 String temp = new char[strlen(computed.string)+1];
3016 ReadString(temp, computed.string);
3017 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3022 propDef.variable = true;
3024 FreeExpression(computed);
3028 propDef.variable = true;
3032 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3033 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3034 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3037 // Maintain a list in FunctionDefinition of who is attached to it
3038 for(def = _class.definitions->first; def; def = def.next)
3040 if(def.type == functionClassDef)
3042 ClassFunction function = def.function;
3043 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3045 function.attached.Add(OldLink { data = method });
3055 case declarationClassDef:
3057 Declaration decl = def.decl;
3060 case instDeclaration:
3062 Instantiation inst = decl.inst;
3063 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3064 if(instClass && eClass_GetDesigner(instClass))
3066 Instance control = eInstance_New(instClass);
3071 oClass = classObject;
3075 classObject.instances.Add(object);
3077 // TOCHECK: Why is this needed now?
3078 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3079 def.object = object;
3081 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3083 designer.CreateObject(control, object, false, classObject.instance);
3084 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3094 // Second pass, process instantiation members
3096 for(def = _class.definitions->first; def; def = def.next)
3100 case declarationClassDef:
3102 Declaration decl = def.decl;
3105 case instDeclaration:
3107 Instantiation inst = decl.inst;
3108 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3109 if(instClass && eClass_GetDesigner(instClass))
3112 object = object ? object.next : classObject.instances.first;
3113 control = object.instance;
3117 MembersInit members;
3118 for(members = inst.members->first; members; members = members.next)
3120 switch(members.type)
3122 case dataMembersInit:
3124 if(members.dataMembers)
3127 DataMember curMember = null;
3128 Class curClass = null;
3129 DataMember subMemberStack[256];
3130 int subMemberStackPos = 0;
3132 for(member = members.dataMembers->first; member; member = member.next)
3135 Identifier ident = member.identifiers ? member.identifiers->first : null;
3138 DataMember _subMemberStack[256];
3139 int _subMemberStackPos = 0;
3140 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3144 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3146 if(thisMember && thisMember.memberAccess == publicAccess)
3148 curMember = thisMember;
3149 curClass = curMember._class;
3150 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
3151 subMemberStackPos = _subMemberStackPos;
3157 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3158 if(curMember) found = true;
3160 if(found && curMember.isProperty)
3162 Property prop = (Property) curMember;
3163 Class propertyClass = prop.dataTypeClass;
3165 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3167 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3169 FreeType(member.initializer.exp.destType);
3170 member.initializer.exp.destType = MkClassType(propertyClass.name);
3173 ProcessExpressionType(member.initializer.exp);
3175 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3177 Expression computed;
3179 /*char debugExpString[4096];
3180 debugExpString[0] = '\0';
3181 PrintExpression(member.initializer.exp, debugExpString);*/
3183 computed = CopyExpression(member.initializer.exp);
3186 ComputeExpression(computed);
3188 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3190 if(computed.instance.data)
3192 if(computed.instance._class && computed.instance._class.symbol &&
3193 computed.instance._class.symbol.registered &&
3194 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3196 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3198 // This was saved in the control and shouldn't be freed by FreeExpression...
3199 if(propertyClass.type == normalClass)
3200 computed.instance.data = null;
3204 else if(computed.type == identifierExp)
3206 member.variable = true;
3208 if(eClass_GetDesigner(propertyClass))
3211 char * name = computed.identifier.string;
3212 if(!strcmp(name, "this"))
3215 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3216 member.variable = false;
3221 for(check = classObject.instances.first; check; check = check.next)
3222 if(check.name && !strcmp(name, check.name))
3225 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3226 member.variable = false;
3232 else if(computed.type == memberExp)
3234 member.variable = true;
3235 if(computed.member.exp.type == identifierExp)
3237 char * name = computed.member.exp.identifier.string;
3238 if(!strcmp(name, "this"))
3240 char * name = computed.member.member.string;
3243 for(check = classObject.instances.first; check; check = check.next)
3244 if(check.name && !strcmp(name, check.name))
3247 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3248 member.variable = false;
3256 for(check = classObject.instances.first; check; check = check.next)
3258 if(check.name && !strcmp(name, check.name))
3260 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3263 DataValue value { };
3264 GetProperty(getProperty, check.instance, &value);
3265 SetProperty(prop, control, value);
3266 member.variable = false;
3274 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3275 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3277 String temp = new char[strlen(computed.string)+1];
3278 ReadString(temp, computed.string);
3279 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3283 member.variable = true;
3285 FreeExpression(computed);
3290 Expression computed = CopyExpression(member.initializer.exp);
3293 ComputeExpression(computed);
3294 if(computed.isConstant)
3296 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3298 if(!strcmp(propertyClass.dataTypeString, "float"))
3299 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3300 else if(!strcmp(propertyClass.dataTypeString, "double"))
3301 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3303 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3305 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3307 String temp = new char[strlen(computed.string)+1];
3308 ReadString(temp, computed.string);
3309 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3314 member.variable = true;
3316 FreeExpression(computed);
3322 member.variable = true;
3324 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3325 member.initializer.exp.type == memberExp) // identifierExp
3327 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3328 if(method && method.type == virtualMethod)
3331 // Maintain a list in FunctionDefinition of who is attached to it
3332 for(def = _class.definitions->first; def; def = def.next)
3334 if(def.type == functionClassDef)
3336 ClassFunction function = def.function;
3337 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3338 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3340 function.attached.Add(OldLink { data = method });
3341 // Reference this particular instance?
3356 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3367 //designer.CreateObject(instance, classObject, true, null);
3368 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3370 designer.PostCreateObject(instance, classObject, true, null);
3372 //instance.state = Hidden;
3373 //instance.Create();
3374 //instance.SetState(Normal, true, 0);
3383 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3387 // Restore Selection
3388 if(selectedClassName)
3391 for(oClass = classes.first; oClass; oClass = oClass.next)
3393 if(!strcmp(oClass.name, selectedClassName))
3395 this.oClass = oClass;
3399 delete selectedClassName;
3408 for(check = this.oClass.instances.first; check; check = check.next)
3410 if(check.name && !strcmp(check.name, selectedName))
3412 this.selected = check;
3418 if(this.oClass.instances.first)
3419 this.selected = this.oClass.instances.first;
3421 this.selected = this.oClass;
3424 else if(selectedPos == -1 || !this.oClass.instances.count)
3425 this.selected = this.oClass;
3431 if(selectedPos > this.oClass.instances.count)
3433 for(check = this.oClass.instances.first; check; check = check.next)
3435 if(selectedPos == pos++)
3437 this.selected = check;
3445 this.oClass = classes.first;
3446 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3448 delete selectedName;
3449 SetSymbolsDir(null);
3451 if(sheet.codeEditor == this)
3452 sheet.SelectObject(selected);
3455 codeModified = false;
3457 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3460 InvokeParameters(false, false, false);
3463 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3469 ChangeWorkingDir(oldWorkDir);
3471 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3472 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3473 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3474 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3475 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3477 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3479 if(inUseDebug && ide.projectView)
3480 ide.debugger.EvaluateWatches();
3483 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3486 Window control = (Window)object.instance;
3487 ObjectInfo classObject = object.oClass;
3489 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3491 if(!strcmp(_class.name, "DesignerBase")) return;
3493 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3495 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3496 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3498 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3499 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3501 Class dataType = prop.dataTypeClass;
3503 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3507 if(dataType.type == structClass)
3509 void * dataForm = new0 byte[dataType.structSize];
3510 void * dataTest = new0 byte[dataType.structSize];
3512 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3513 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3515 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3517 char tempString[1024] = "";
3519 bool needClass = true;
3523 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3525 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3527 eClass_FindNextMember(_class, curClass, curMember, null, null);
3528 if(*curMember != (DataMember)prop)
3529 f.Printf("%s = ", prop.name);
3531 *curMember = (DataMember)prop;
3532 *curClass = curMember->_class;
3535 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3537 f.Printf("%s", string);
3544 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3546 void * dataForm, * dataTest;
3548 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3549 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3551 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3553 char tempString[1024] = "";
3558 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3560 eClass_FindNextMember(_class, curClass, curMember, null, null);
3561 if(*curMember != (DataMember)prop)
3562 f.Printf("%s = ", prop.name);
3563 *curMember = (DataMember)prop;
3564 *curClass = curMember->_class;
3566 if(eClass_GetDesigner(dataType))
3568 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3569 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3570 f.Printf("this", prop.name);
3573 //ObjectInfo classObject;
3574 //for(classObject = classes.first; classObject; classObject = classObject.next)
3578 for(object = classObject.instances.first; object; object = object.next)
3580 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3582 f.Printf("%s", object.name);
3589 bool needClass = true;
3590 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3591 f.Printf("%s", string);
3598 bool needClass = true;
3599 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3601 if(!strcmp(dataType.dataTypeString, "char *"))
3604 OutputString(f, string);
3608 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3610 f.Printf("%s", string);
3613 *lastIsMethod = false;
3618 DataValue dataForm, dataTest;
3620 GetProperty(prop, control, &dataForm);
3621 GetProperty(prop, test, &dataTest);
3623 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3626 char tempString[1024] = "";
3627 SetProperty(prop, test, dataForm);
3629 if(dataType.type != bitClass)
3631 bool needClass = true;
3633 if(dataType.type == enumClass)
3636 Class enumClass = eSystem_FindClass(privateModule, "enum");
3637 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3639 for(value = e.values.first; value; value = value.next)
3641 if((int)value.data == dataForm.i)
3643 string = value.name;
3649 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3651 if(string && string[0])
3656 eClass_FindNextMember(_class, curClass, curMember, null, null);
3657 if(*curMember != (DataMember)prop)
3658 f.Printf("%s = ", prop.name);
3659 *curMember = (DataMember)prop;
3660 *curClass = curMember->_class;
3662 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3663 f.Printf("%sf", string);
3665 f.Printf("%s", string);
3669 else if(dataType.type == bitClass)
3671 bool needClass = true;
3673 if(*prev) f.Printf(", ");
3675 eClass_FindNextMember(_class, curClass, curMember, null, null);
3676 if(*curMember != (DataMember)prop)
3677 f.Printf("%s = ", prop.name);
3678 *curMember = (DataMember)prop;
3679 *curClass = curMember->_class;
3681 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3683 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3685 f.Printf("%s", string);
3687 *lastIsMethod = false;
3697 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3699 Instantiation inst = object.instCode;
3700 Window control = (Window)object.instance;
3702 bool methodPresent = false;
3704 bool lastIsMethod = true;
3705 ObjectInfo classObject = object.oClass;
3711 // Instance removed, delete it
3712 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3714 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3715 position = inst.loc.end.pos + 1;
3719 bool multiLine = false;
3722 // Check if it's an unnamed instance
3725 f.Seek(inst.nameLoc.start.pos - position, current);
3726 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3727 position = inst.nameLoc.end.pos;
3729 f.Printf(object.name);
3734 if(isspace(ch) && ch != '\n')
3736 f.Seek(-1, current);
3744 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3746 f.Seek(pos - position, current);
3751 f.Seek(-1, current);
3760 f.Puts(object.name);
3765 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3766 methodPresent = true;
3774 if(ch == OpenBracket)
3780 // TODO: Simplify this?
3789 f.Seek(-1, current);
3801 if(ch == '\n') { toDelete = count; count = 0; }
3802 else if(isspace(ch)) count++;
3805 f.Seek(-1, current);
3809 toDelete += count - 6;
3819 f.Seek(-toDelete-count, current);
3820 f.DeleteBytes(toDelete);
3821 f.Seek(count, current);
3826 for(c = 0; c<toAdd; c++)
3832 methodPresent = multiLine;
3835 f.Printf(methodPresent ? "\n " : " ");
3841 // Instance not there, create a brand new one
3842 DeleteJunkBefore(f, position, &position);
3843 f.Printf(*firstObject ? "\n\n" : "\n");
3844 *firstObject = false;
3846 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3847 methodPresent = true;
3852 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3854 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3859 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3861 f.Printf(" %s %c ", control._class.name, OpenBracket);
3867 Instance test = eInstance_New(control._class);
3868 DataMember curMember = null;
3869 Class curClass = null;
3872 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3876 // Attach Method here
3877 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3879 if(prev) f.Printf(", ");
3880 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3885 if(inst && !object.deleted)
3887 MembersInit members;
3888 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3890 DeleteJunkBefore(f, position, &position);
3892 // Instance already there, clear out the properties
3893 for(members = inst.members->first; members; members = members.next)
3895 if(members.type == dataMembersInit)
3899 if(members.dataMembers)
3901 bool keptMember = false;
3902 MemberInit lastKept = null;
3904 for(member = members.dataMembers->first; member; member = member.next)
3906 Identifier ident = member.identifiers ? member.identifiers->first : null;
3907 bool deleted = false;
3909 // For now delete if it's not a method
3910 if(!member.variable) // && ident)
3912 if(!ident || !ident.next)
3914 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3917 f.Seek(member.loc.start.pos - position, current);
3918 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3919 position = member.loc.end.pos;
3924 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3925 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3926 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
3928 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
3929 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
3931 f.Seek(member.loc.start.pos - position, current);
3932 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3933 position = member.loc.end.pos;
3945 //f.Seek(member.loc.start.pos - position, current);
3946 //position = member.loc.start.pos;
3947 DeleteJunkBefore(f, member.loc.start.pos, &position);
3948 if(prev) f.Printf(", ");
3949 else if(keptMember) f.Printf(" ");
3954 if(!keptMember || !members.next)
3959 if(keptMember && lastKept != members.dataMembers->last)
3964 f.Seek(-1, current);
3970 f.Seek(-1, current);
3973 else if(!isspace(ch))
3975 f.Seek(-2, current);
3980 f.DeleteBytes(count);
3983 f.Seek(members.loc.end.pos - position, current);
3988 f.Seek(-1, current);
3990 position = members.loc.end.pos + 1;
3994 f.Seek(-1, current);
3995 position = members.loc.end.pos;
4001 lastIsMethod = false;
4006 DeleteJunkBefore(f, position, &position);
4009 if(lastKept != members.dataMembers->last)
4014 f.Seek(-1, current);
4020 f.Seek(-1, current);
4023 else if(!isspace(ch))
4025 f.Seek(-2, current);
4030 f.DeleteBytes(count);
4034 f.Seek(members.loc.end.pos - position, current);
4035 position = members.loc.end.pos;
4039 lastIsMethod = true;
4042 lastIsMethod = false;
4048 f.Seek(members.loc.end.pos - position, current);
4049 position = members.loc.end.pos;
4051 lastIsMethod = true;
4054 else if(members.type == methodMembersInit)
4056 if(this.methodAction == actionDeleteMethod && members.function == function);
4058 methodPresent = true;
4060 // Delete instance method here
4061 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4062 members.function == function)
4064 if(this.moveAttached && !*text)
4065 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4067 DeleteJunkBefore(f, members.loc.start.pos, &position);
4068 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4069 position = members.loc.end.pos + 1;
4074 DeleteJunkBefore(f, position, &position);
4078 DeleteJunkBefore(f, members.loc.start.pos, &position);
4079 lastIsMethod = true;
4083 f.Seek(members.loc.end.pos - position, current);
4084 position = members.loc.end.pos;
4086 DeleteJunkBefore(f, position, &position);
4095 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4097 Method method = this.method;
4098 DeleteJunkBefore(f, position, &position);
4104 if(!method.dataType)
4105 method.dataType = ProcessTypeString(method.dataTypeString, false);
4108 Type dataType = method.dataType;
4109 Type returnType = dataType.returnType;
4112 if(this.moveAttached)
4114 // Move function here:
4115 int newLen = strlen(method.name);
4120 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4122 // First change name of function
4123 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4124 *textSize += newLen - movedFuncIdLen;
4125 memcpy(*text + movedFuncIdPos, method.name, newLen);
4127 // Second, tab right
4130 for(c = 0; (*text)[c]; )
4133 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4136 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4137 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4141 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4151 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4153 // ADDING METHOD HERE
4155 OutputType(f, returnType, false);
4158 if(dataType.thisClass)
4160 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4162 if(dataType.thisClass.shortName)
4163 f.Printf(dataType.thisClass.shortName);
4165 f.Printf(dataType.thisClass.string);
4169 f.Printf(method.name);
4171 for(param = dataType.params.first; param; param = param.next)
4173 OutputType(f, param, true);
4178 f.Printf(" %c\n\n", OpenBracket);
4180 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4182 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4183 f.Printf(" return true;\n");
4184 else if(returnType.kind != voidType)
4185 f.Printf(" return 0;\n");
4190 if(returnType.kind != voidType)
4191 f.Printf("return ");
4192 f.Printf("%s::%s(", control._class.name, method.name);
4193 for(param = dataType.params.first; param; param = param.next)
4195 if(param.prev) f.Printf(", ");
4196 if(param.kind != voidType)
4197 f.Printf(param.name);
4201 f.Printf(" %c\n", CloseBracket);
4207 if(!object.instCode)
4210 f.Printf(" %c;\n", CloseBracket);
4212 f.Printf("%c;\n", CloseBracket);
4214 else if(!object.deleted)
4216 // Turn this into a multiline instance when adding a method
4217 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4219 f.Printf(methodPresent ? "\n " : " ");
4221 f.Seek(inst.loc.end.pos + 1 - position, current);
4222 position = inst.loc.end.pos + 1;
4227 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4230 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4232 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4234 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4236 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4237 if(prop && prop.isProperty && !prop.conversion)
4239 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4240 (!prop.IsSet || prop.IsSet(classObject.instance)))
4242 Class dataType = prop.dataTypeClass;
4243 char tempString[1024] = "";
4245 bool specify = false;
4248 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4249 if(member && member._class == regClass)
4253 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4255 if(dataType && dataType.type == structClass)
4257 void * dataForm = new0 byte[dataType.structSize];
4258 void * dataTest = new0 byte[dataType.structSize];
4260 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4261 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4263 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4265 bool needClass = true;
4267 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4268 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4270 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4272 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4277 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4279 void * dataForm, * dataTest;
4281 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4282 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4284 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4286 char tempString[1024] = "";
4288 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4290 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4292 // Shouldn't go here ...
4293 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4297 bool needClass = true;
4299 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4301 if(!strcmp(dataType.dataTypeString, "char *"))
4303 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4304 OutputString(f, string);
4308 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4310 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4316 DataValue dataForm, dataTest;
4318 GetProperty(prop, classObject.instance, &dataForm);
4319 GetProperty(prop, test, &dataTest);
4321 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4323 SetProperty(prop, test, dataForm);
4324 if(dataType.type == bitClass)
4326 bool needClass = true;
4327 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4329 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4331 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4335 bool needClass = true;
4336 if(dataType.type == enumClass)
4339 Class enumClass = eSystem_FindClass(privateModule, "enum");
4340 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4342 for(value = e.values.first; value; value = value.next)
4344 if((int)value.data == dataForm.i)
4346 string = value.name;
4352 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4353 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4354 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4356 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4365 void UpdateFormCode()
4374 else if(formModified)
4376 EditBoxStream f { editBox = editBox };
4380 Identifier movedFuncId;
4381 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4382 ObjectInfo classObject;
4388 movedFuncId = GetDeclId(function.declarator);
4389 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4390 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4393 for(classObject = classes.first; classObject; classObject = classObject.next)
4396 ClassDefinition classDef = classObject.classDefinition;
4397 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4400 bool firstObject = true;
4401 ObjectInfo object = classObject.instances.first;
4402 bool lastIsDecl = false;
4404 if(!classObject.modified) continue;
4406 test = eInstance_New(regClass);
4409 // Put it in the same desktop window...
4410 designer.PrepareTestObject(test);
4412 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4413 //f.Printf("%c\n\n", OpenBracket);
4415 // Change the _class name
4416 f.Seek(classDef.nameLoc.start.pos - position, current);
4417 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4418 f.Printf(classObject.name);
4419 position = classDef.nameLoc.end.pos;
4422 // Go to block start, delete all until no white space, put \n
4426 f.Seek(classDef.blockStart.end.pos - position, current);
4427 position = classDef.blockStart.end.pos;
4429 for(; f.Getc(&ch); count++)
4433 f.Seek(-1, current);
4443 f.Seek(-count, current);
4445 f.DeleteBytes(count-back);
4447 position += count-back;
4450 // Output properties
4451 OutputClassProperties(classObject.instance._class, classObject, f, test);
4453 for(def = classDef.definitions->first; def; def = def.next)
4457 case defaultPropertiesClassDef:
4459 bool keptMember = false;
4461 MemberInit lastKept = null;
4464 DeleteJunkBefore(f, def.loc.start.pos, &position);
4467 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4469 Identifier ident = propDef.identifiers->first;
4470 bool deleted = false;
4472 // For now delete if it's a prop
4473 if(!propDef.variable && ident)
4477 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4480 f.Seek(propDef.loc.start.pos - position, current);
4481 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4482 position = propDef.loc.end.pos;
4487 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4488 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4490 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4491 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4493 f.Seek(propDef.loc.start.pos - position, current);
4494 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4495 position = propDef.loc.end.pos;
4513 f.Seek(def.loc.end.pos - position - 1, current);
4518 f.Seek(-1, current);
4521 position = def.loc.end.pos;
4525 if(lastKept != def.defProperties->last)
4530 f.Seek(-1, current);
4536 f.Seek(-1, current);
4539 else if(!isspace(ch))
4541 f.Seek(-2, current);
4546 f.DeleteBytes(count);
4550 f.Seek(def.loc.end.pos - position, current);
4551 position = def.loc.end.pos;
4556 case declarationClassDef:
4558 Declaration decl = def.decl;
4560 if(decl.type == instDeclaration)
4562 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4564 while(def.object && object != def.object)
4566 if(object /*&& ((ObjectInfo)def.object).modified*/)
4567 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4568 object = object.next;
4571 DeleteJunkBefore(f, def.loc.start.pos, &position);
4572 f.Printf(firstObject ? "\n\n " : "\n ");
4573 firstObject = false;
4575 if(def.object && ((ObjectInfo)def.object).modified)
4576 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4578 object = object ? object.next : null;
4582 DeleteJunkBefore(f, def.loc.start.pos, &position);
4583 f.Printf(firstObject ? "\n\n " : "\n ");
4584 firstObject = false;
4590 DeleteJunkBefore(f, def.loc.start.pos, &position);
4591 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4596 case functionClassDef:
4598 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4599 if(!def.function.body) continue;
4603 DeleteJunkBefore(f, def.loc.start.pos, &position);
4606 // Delete _class methods
4607 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4608 def.function == function)
4613 if(moveAttached && !text)
4615 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4618 f.Seek(def.loc.end.pos - position, current);
4619 for(; f.Getc(&ch); count++)
4623 f.Seek(-1, current);
4627 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4629 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4630 position = def.loc.end.pos + count;
4633 // In case of detaching methods in the _class, simply rename the method
4634 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4636 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4637 f.DeleteBytes(movedFuncIdLen);
4639 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4642 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4643 function == def.function)
4645 // In case of attaching methods in the _class, simply rename the method
4646 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4647 position = function.loc.start.pos + movedFuncIdPos;
4648 f.DeleteBytes(movedFuncIdLen);
4649 if(method.dataType.thisClass)
4650 f.Printf("%s::", method.dataType.thisClass.string);
4651 f.Puts(method.name);
4652 position += movedFuncIdLen;
4657 DeleteJunkBefore(f, def.loc.start.pos, &position);
4658 if(def.type == memberAccessClassDef)
4661 firstObject = false;
4671 f.Seek(def.loc.end.pos - position, current);
4672 position = def.loc.end.pos;
4675 // Output attached methods
4676 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4678 DeleteJunkBefore(f, position, &position);
4679 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4682 // ********** INSTANCES ***************
4683 for(; object; object = object.next)
4685 if(!object.instCode)
4687 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4691 DeleteJunkBefore(f, position, &position);
4693 // ****************** METHODS ***********************
4694 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4696 // If detaching an instance method
4697 if(selected != classObject)
4699 int newLen = strlen(methodName);
4702 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4703 // Tab selection left
4706 for(c = 0; text[c]; )
4709 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4710 memmove(text+start, text+start+i, textSize+1-start-i);
4713 for(; text[c] && text[c] != '\n'; c++);
4719 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4720 textSize += newLen - movedFuncIdLen;
4721 memcpy(text + movedFuncIdPos, methodName, newLen);
4728 if(methodAction == actionAddMethod && selected == classObject)
4730 Method method = this.method;
4732 if(!method.dataType)
4733 method.dataType = ProcessTypeString(method.dataTypeString, false);
4735 // ADDING METHOD HERE
4737 Type dataType = method.dataType;
4738 Type returnType = dataType.returnType;
4740 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4744 OutputType(f, returnType, false);
4747 if(dataType.thisClass && !dataType.classObjectType)
4749 if(dataType.thisClass.shortName)
4750 f.Printf(dataType.thisClass.shortName);
4752 f.Printf(dataType.thisClass.string);
4755 f.Printf(method.name);
4757 for(param = dataType.params.first; param; param = param.next)
4759 OutputType(f, param, true);
4764 f.Printf(" %c\n\n", OpenBracket);
4766 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4768 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4769 f.Printf(" return true;\n");
4770 else if(returnType && returnType.kind != voidType)
4771 f.Printf(" return 0;\n");
4776 if(returnType.kind != voidType)
4777 f.Printf("return ");
4779 char * name = ((Specifier)classDef.baseSpecs->first).name;
4780 Symbol _class = FindClass(name);
4781 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4783 for(param = dataType.params.first; param; param = param.next)
4785 if(param.prev) f.Printf(", ");
4786 if(param.kind != voidType)
4787 f.Printf(param.name);
4792 f.Printf(" %c", CloseBracket);
4796 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4808 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4809 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4813 codeModified = false;
4814 formModified = false;
4816 moveAttached = false;
4821 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4824 ClassFunction function = null;
4827 ObjectInfo object = this.selected;
4829 if(object && object == this.oClass)
4831 ClassDefinition classDef = object.oClass.classDefinition;
4833 if(classDef && classDef.definitions)
4835 for(def = classDef.definitions->first; def; def = def.next)
4837 if(def.type == functionClassDef && def.function.declarator)
4839 if(!strcmp(def.function.declarator.symbol.string, methodName))
4841 function = def.function;
4846 else if(def.type == defaultPropertiesClassDef)
4850 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4852 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4853 if(ident && !ident.next)
4855 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4859 propLoc = propDef.loc;
4862 ClassDefinition classDef = object.oClass.classDefinition;
4864 if(classDef.definitions)
4866 for(def = classDef.definitions->first; def; def = def.next)
4868 if(def.type == functionClassDef)
4870 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4872 function = def.function;
4891 Instantiation inst = object.instCode;
4893 // Check here to see if the method already exists, no need to call ModifyCode in that case
4894 if(inst && inst.members)
4896 MembersInit members;
4897 for(members = inst.members->first; members; members = members.next)
4899 switch(members.type)
4901 case dataMembersInit:
4903 if(members.dataMembers)
4906 for(member = members.dataMembers->first; member; member = member.next)
4908 Identifier ident = member.identifiers ? member.identifiers->first : null;
4909 if(ident && !ident.next)
4911 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4915 propLoc = member.loc;
4918 ClassDefinition classDef = object.oClass.classDefinition;
4920 if(classDef.definitions)
4922 for(def = classDef.definitions->first; def; def = def.next)
4924 if(def.type == functionClassDef)
4926 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
4928 function = def.function;
4937 // TODO: Fix memory leak
4938 function = ClassFunction
4940 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
4952 case methodMembersInit:
4954 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
4956 function = members.function;
4968 if(functionPtr) *functionPtr = function;
4972 void GoToMethod(char * methodName /*Method method*/)
4976 ObjectInfo object = selected;
4977 EditBoxStream f { editBox = editBox };
4978 ClassFunction function = null;
4979 bool atChar = false;
4983 Location propLoc = { {0,0,-1} };
4986 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
4987 if(function && function.body)
4990 f.Seek(function.body.loc.start.pos+1, current);
5000 f.Seek(-1, current);
5005 else if(!isspace(ch))
5007 f.Seek(-1, current);
5013 else if(propLoc.start.pos > -1)
5015 f.Seek(propLoc.start.pos, current);
5018 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5020 if(function || propLoc.start.pos > -1)
5022 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5023 editBox.CenterOnCursor();
5024 SetState(normal, false, 0);
5027 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5029 FreeClassFunction(function);
5035 void FindCompatibleMethods(Method method, OldList compatible)
5037 ClassDefinition classDef = this.oClass.classDefinition;
5038 if(classDef && classDef.definitions)
5041 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5044 Symbol classSym { };
5045 Symbol selectedClass;
5046 if(this.selected == this.oClass)
5047 selectedClass = classSym;
5049 selectedClass = FindClass(this.selected.instance._class.name);
5051 regClass.name = classDef._class.name;
5052 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5053 for(def = classDef.definitions->first; def; def = def.next)
5055 if(def.type == functionClassDef && def.function.declarator)
5057 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5059 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5062 Type type = def.function.declarator.symbol.type;
5063 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5065 compatible.Add(OldLink { data = def.function });
5071 if(this.oClass && this.oClass.instance)
5073 classSym.registered = regClass;
5074 //classSym.registered = this.oClass.oClass;
5076 for(_class = regClass.base; _class; _class = _class.base)
5079 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5081 // TODO: Understand why these functions popup in attach list
5082 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5084 if(!testMethod.dataType)
5085 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5087 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5088 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5089 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5091 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5092 // ClassFunction function { };
5093 FunctionDefinition function { };
5095 function.declarator = Declarator { };
5096 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5097 excludedSymbols.Add(function.declarator.symbol);
5099 compatible.Add(OldLink { data = function });
5110 void AddMethod(Method method)
5114 char methodName[1024];
5115 strcpy(methodName, method.name);
5116 if(!FindMethod(methodName, null, null))
5118 methodAction = actionAddMethod;
5119 this.method = method;
5123 GoToMethod(methodName);
5127 void DeleteMethod(ClassFunction function)
5131 methodAction = actionDeleteMethod;
5132 this.function = function;
5140 void AttachMethod(Method method, ClassFunction function)
5144 // If it's an instance we'll ask if we want to move it inside...
5145 if(!function.attached.count && function.body)
5147 // Find the function in the _class to check if it's a virtual function
5148 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5149 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5150 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5152 for(def = this.classDefinition.first; def; def = def.next)
5154 if(def.type == functionClassDef)
5156 if(def.function == function)
5161 if(!method || method.type != virtualMethod)
5164 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5165 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5167 moveAttached = true;
5172 methodAction = actionAttachMethod;
5173 this.method = method;
5174 this.function = function;
5181 void ReAttachMethod(Method method, ClassFunction function)
5185 // If it's an instance we'll ask if we want to move it inside...
5186 if(!function.attached.count && function.body)
5188 // Find the function in the _class to check if it's a virtual function
5189 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5190 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5191 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5193 for(def = this.classDefinition.first; def; def = def.next)
5195 if(def.type == functionClassDef)
5197 if(def.function == function)
5202 if(!method || method.type != virtualMethod)
5205 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5206 if(MessageBox { type = yesNo, master = parent, text = title,
5207 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5209 moveAttached = true;
5214 methodAction = actionReattachMethod;
5215 this.method = method;
5216 this.function = function;
5223 void DetachMethod(Method method, ClassFunction function, int type)
5231 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5232 master = sheet, text = $"Name detached method", background = formColor
5236 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5237 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5241 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5242 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5246 dialog, anchor = { left = 5, right = 5, top = 5 }
5248 sprintf(methodName, "%s_%s", selected.name, method.name);
5249 nameBox.contents = methodName;
5251 result = dialog.Modal() == ok;
5252 strcpy(methodName, nameBox.contents);
5257 // If the method is not attached, move it outside
5260 // Add this class to the methodName
5261 char name[1024] = "";
5263 if(this.selected != this.oClass && !method.dataType.thisClass)
5265 strcat(name, this.selected.instance._class.name);
5267 strcat(name, this.methodName);
5268 strcpy(this.methodName, name);
5270 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5272 strcat(name, method.dataType.thisClass.string);
5274 strcat(name, this.methodName);
5275 strcpy(this.methodName, name);
5278 this.moveAttached = true;
5281 this.methodAction = actionDetachMethod;
5282 this.method = method;
5283 this.function = function;
5290 void AddObject(Instance instance, ObjectInfo * object)
5294 //*object = _class.instances.Add(sizeof(ObjectInfo));
5295 *object = ObjectInfo { };
5296 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5297 (*object).oClass = oClass;
5298 (*object).instance = instance;
5303 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5305 // if(strcmp(name, this.oClass.instance.name))
5308 for(check = oClass.instances.first; check; check = check.next)
5309 if(!check.deleted && check.name && !strcmp(name, check.name))
5313 (*object).name = CopyString(name);
5318 toolBox.controlClass = null;
5322 //sheet.AddObject(*object, (*object).name, TypeData, true);
5327 void EnsureUpToDate()
5329 if(sheet && codeModified)
5333 void SelectObject(ObjectInfo object)
5336 oClass = object ? object.oClass : null;
5338 designer.SelectObject(object, object ? object.instance : null);
5341 void SelectObjectFromDesigner(ObjectInfo object)
5344 sheet.SelectObject(object);
5347 void EnumerateObjects(Sheet sheet)
5351 for(oClass = classes.first; oClass; oClass = oClass.next)
5357 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5358 for(object = oClass.instances.first; object; object = object.next)
5359 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5362 sheet.SelectObject(selected);
5367 designer.AddObject();
5370 void DeleteObject(ObjectInfo object)
5372 delete object.instance;
5373 object.deleted = true;
5374 object.modified = true;
5375 object.oClass.modified = true;
5377 if(selected == object)
5379 bool looped = false;
5380 ObjectInfo select = object;
5384 select = select.prev;
5388 select = object.oClass.instances.last;
5395 sheet.SelectObject(select ? select : oClass);
5398 if(!object.instCode && object.oClass != object)
5401 oClass.instances.Delete(object);
5404 if(sheet.codeEditor == this)
5405 sheet.DeleteObject(object);
5408 void RenameObject(ObjectInfo object, char * name)
5412 // Validate the name:
5413 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5414 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5417 for(c = 0; name[c]; c++)
5418 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5426 object.name = (name && name[0]) ? CopyString(name) : null;
5428 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5432 void DesignerModifiedObject()
5434 sheet.ListProperties(false);
5438 void ListSubMembers(Type member)
5442 for(subMember = member.members.first; subMember; subMember = subMember.next)
5446 DataRow row = membersList.AddString(subMember.name);
5447 row.icon = icons[typeData];
5451 ListSubMembers(subMember);
5456 void ListSubDataMembers(DataMember member, bool isPrivate)
5458 DataMember subMember;
5459 for(subMember = member.members.first; subMember; subMember = subMember.next)
5461 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5465 DataRow row = membersList.AddString(subMember.name);
5466 BitmapResource bitmap = null;
5467 if(!subMember.dataType)
5468 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5470 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5472 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5475 bitmap = { bitmapName };
5476 membersList.AddResource(bitmap);
5479 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5483 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5489 void ListClassMembers(Class whatClass, bool methodsOnly)
5492 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5493 bool isPrivate = false;
5495 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5497 Method method, methodIt;
5499 DataMember memberIt;
5501 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5503 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5504 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5506 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5508 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5510 DataRow row = membersList.FindString(method.name);
5513 row = membersList.AddString(method.name);
5515 if(!method.dataType)
5516 method.dataType = ProcessTypeString(method.dataTypeString, false);
5518 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5526 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5530 if(memberIt.isProperty)
5532 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5534 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5538 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5540 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5543 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5549 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5551 if(member.isProperty)
5553 Property prop = (Property) member;
5554 if(!membersList.FindString(prop.name))
5556 DataRow row = membersList.AddString(prop.name);
5557 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5560 else if(member.name && !membersList.FindString(member.name))
5562 DataRow row = membersList.AddString(member.name);
5564 BitmapResource bitmap = null;
5565 if(!member.dataType)
5566 member.dataType = ProcessTypeString(member.dataTypeString, false);
5568 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5570 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5573 bitmap = { bitmapName };
5574 membersList.AddResource(bitmap);
5577 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5580 ListSubDataMembers(member, member.memberAccess == privateAccess);
5584 if(_class.inheritanceAccess == privateAccess)
5587 if(_class.module != privateModule) break;
5592 void ListClassMembersMatch(Class whatClass, Type methodType)
5595 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5596 bool isPrivate = false;
5598 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5604 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5606 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5608 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5610 if(!method.dataType)
5611 method.dataType = ProcessTypeString(method.dataTypeString, false);
5613 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5615 DataRow row = membersList.FindString(method.name);
5618 row = membersList.AddString(method.name);
5619 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5625 if(_class.inheritanceAccess == privateAccess)
5628 if(_class.module != privateModule) break;
5633 void ListClassPropertiesAndVirtual(Class whatClass)
5636 bool isPrivate = false;
5637 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5643 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5645 if(method.type == virtualMethod)
5647 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5649 DataRow row = membersList.FindString(method.name);
5652 row = membersList.AddString(method.name);
5654 if(!method.dataType)
5655 method.dataType = ProcessTypeString(method.dataTypeString, false);
5657 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5663 for(member = _class.membersAndProperties.first; member; member = member.next)
5665 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5667 if(member.isProperty)
5669 Property prop = (Property)member;
5671 DataRow row = membersList.AddString(prop.name);
5672 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5675 else if(member.name)
5677 DataRow row = membersList.AddString(member.name);
5679 BitmapResource bitmap = null;
5680 if(!member.dataType)
5681 member.dataType = ProcessTypeString(member.dataTypeString, false);
5683 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5685 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5688 bitmap = { bitmapName };
5689 membersList.AddResource(bitmap);
5692 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5695 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5698 if(_class.inheritanceAccess == privateAccess)
5701 if(_class.module != privateModule) break;
5706 void ListMembers(Type type)
5708 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5712 if(type.kind == classType)
5715 ListClassMembers(type._class.registered, false);
5720 for(member = type.members.first; member; member = member.next)
5724 DataRow row = membersList.AddString(member.name);
5725 row.icon = icons[typeData];
5727 else if(member.kind == structType || member.kind == unionType)
5728 ListSubMembers(member);
5734 void ListModule(Module mainModule, int recurse, bool listClasses)
5737 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5738 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5739 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5740 for(module = mainModule.application.allModules.first; module; module = module.next)
5742 if(ModuleVisibility(mainModule, module))
5743 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5747 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5754 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5756 Class _class = link.data;
5757 if(_class.type != systemClass)
5759 DataRow row = membersList.AddString(_class.name);
5760 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5765 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5767 DefinedExpression definedExp = link.data;
5768 DataRow row = membersList.AddString(link /*definedExp*/.name);
5769 row.icon = icons[typeData];
5772 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5774 GlobalFunction function = link.data;
5775 DataRow row = membersList.AddString(link /*function*/.name);
5776 row.icon = icons[typeMethod];
5780 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5782 if(recurse != 2 && listClasses)
5784 if(!membersList.FindString(ns->name))
5786 DataRow row = membersList.AddString(ns->name);
5787 row.icon = icons[typeNameSpace];
5792 ListNameSpace(ns, 2, listClasses);
5796 void ListEnumValues(Class _class)
5798 List<Class> classes { };
5799 for(; _class && _class.type == enumClass; _class = _class.base)
5800 classes.Insert(null, _class);
5801 for(_class : classes)
5803 EnumClassData enumeration = (EnumClassData)_class.data;
5805 for(item = enumeration.values.first; item; item = item.next)
5807 DataRow row = membersList.AddString(item.name);
5808 row.icon = icons[typeEnumValue];
5814 bool ListEnumsModule(Module mainModule, Type dest)
5816 bool result = false;
5818 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5819 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5820 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5821 for(module = mainModule.application.allModules.first; module; module = module.next)
5823 if(ModuleVisibility(mainModule, module))
5824 result |= ListEnums(module.publicNameSpace, dest);
5829 void ListNameSpaceByString(Module mainModule, char * string)
5831 NameSpace * nameSpace;
5833 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5834 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5835 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5836 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5837 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5838 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5839 for(module = mainModule.application.allModules.first; module; module = module.next)
5841 if(ModuleVisibility(mainModule, module))
5843 nameSpace = FindNameSpace(module.publicNameSpace, string);
5844 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5849 bool ListEnums(NameSpace nameSpace, Type dest)
5852 bool result = false;
5854 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5856 Class _class = link.data;
5857 if(_class.type == enumClass && (dest.kind != classType || !dest._class || dest._class.registered != _class))
5859 OldList conversions { };
5861 type.kind = classType;
5862 type._class = FindClass(_class.name);
5863 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5865 ListEnumValues(_class);
5868 conversions.Free(null);
5872 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5874 result |= ListEnums(nameSpace, dest);
5879 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5883 for(c = 0; (ch = name[c]); c++)
5885 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5887 NameSpace * newSpace;
5888 char * spaceName = new char[c - start + 1];
5889 memcpy(spaceName, name + start, c - start);
5890 spaceName[c-start] = '\0';
5891 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5895 nameSpace = newSpace;
5904 return (NameSpace *)nameSpace;
5907 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5909 bool listedEnums = false;
5910 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5911 bool listClasses = true;
5913 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5915 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5916 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5917 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5919 if(exp.type == identifierExp)
5920 id = realIdentifier;
5922 if(id && id._class && !id._class.name)
5924 listClasses = false;
5927 else if(id && id._class && id._class.name)
5931 Class _class = id.classSym.registered;
5932 if(_class && _class.type == enumClass)
5934 ListEnumValues(_class);
5937 ListClassMembers(id.classSym.registered, true);
5942 else if(id && colons)
5944 ListNameSpaceByString(this.privateModule, id.string);
5949 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
5951 listedEnums = ListEnumsModule(this.privateModule, destType);
5954 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
5956 ListEnumValues(destType._class.registered);
5959 ListClassPropertiesAndVirtual(insideClass);
5963 else if(destType && destType.kind == enumType)
5967 for(value = destType.members.first; value; value = value.next)
5969 DataRow row = membersList.AddString(value.name);
5970 row.icon = icons[typeEnumValue];
5974 ListClassPropertiesAndVirtual(insideClass);
5978 else if(insideClass && !enumOnly)
5980 ListClassPropertiesAndVirtual(insideClass);
5983 if(listedEnums && string && string[0])
5985 DataRow row = membersList.FindSubString(string);
5987 listedEnums = false;
5990 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
5992 ListClassMembersMatch(GetThisClass(), exp.destType);
5994 else if(!insideClass && !enumOnly && !listedEnums)
5997 Symbol symbol = null;
6001 ListClassMembers(GetThisClass(), false);
6004 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6006 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6008 // Don't list enum values?
6009 //if(symbol.type.kind != TypeEnum)
6010 DataRow row = membersList.FindString(symbol.string);
6013 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6015 row = membersList.AddString(symbol.string);
6016 if(symbol.type && symbol.type.kind == functionType)
6017 row.icon = icons[typeMethod];
6018 else if(symbol.type && symbol.type.kind == enumType)
6020 row.icon = icons[typeEnumValue];
6024 BitmapResource bitmap = null;
6025 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6027 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6030 bitmap = { bitmapName };
6031 membersList.AddResource(bitmap);
6034 row.icon = bitmap ? bitmap : icons[typeData];
6041 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6043 DataRow row = membersList.FindString(symbol.string);
6046 row = membersList.AddString(symbol.string);
6047 if(symbol.type.kind == functionType)
6048 row.icon = icons[typeMethod];
6049 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6051 row.icon = icons[typeClass];
6055 row.icon = icons[typeDataType];
6062 ListModule(this.privateModule, 1, listClasses);
6063 // TODO: Implement this with name space
6067 for(data = globalData.first; data; data = data.next)
6069 DataRow row = membersList.FindString(data.name);
6071 data.dataType = ProcessTypeString(data.dataTypeString, false);
6074 row = membersList.AddString(data.name);
6076 if(data.dataType && data.dataType.kind == TypeEnum)
6078 row.icon = icons[typeEnumValue];
6082 BitmapResource bitmap = null;
6083 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6085 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6088 bitmap = { bitmapName };
6089 membersList.AddResource(bitmap);
6092 row.icon = bitmap ? bitmap : icons[typeData];
6100 DataRow row = membersList.AddString("Min");
6101 row.icon = icons[typeMethod];
6103 row = membersList.AddString("Max");
6104 row.icon = icons[typeMethod];
6106 row = membersList.AddString("Abs");
6107 row.icon = icons[typeMethod];
6109 row = membersList.AddString("Sgn");
6110 row.icon = icons[typeMethod];
6116 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6118 EditBoxStream f { editBox = editBox };
6123 updatingCode = true;
6125 if(!method.dataType)
6126 method.dataType = ProcessTypeString(method.dataTypeString, false);
6128 DeleteJunkBefore(f, function.loc.start.pos, &position);
6129 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6131 // ADDING METHOD HERE
6133 Type dataType = method.dataType;
6134 Type returnType = dataType.returnType;
6136 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6142 if(extraIndent) f.Printf(" ");
6144 OutputType(f, returnType, false);
6148 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6150 if(dataType.thisClass.shortName)
6151 f.Printf(dataType.thisClass.shortName);
6153 f.Printf(dataType.thisClass.string);
6156 f.Printf(method.name);
6158 for(param = dataType.params.first; param; param = param.next)
6160 // Decided not to write void...
6161 if(param.kind != voidType)
6163 OutputType(f, param, true);
6169 if(extraIndent) f.Printf(" ");
6170 f.Printf(" %c\n", OpenBracket);
6172 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6178 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6179 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6181 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6183 if(extraIndent) f.Printf(" ");
6184 f.Printf(" return true;\n");
6186 else if(returnType && returnType.kind != voidType)
6188 if(extraIndent) f.Printf(" ");
6189 f.Printf(" return 0;\n");
6194 if(extraIndent) f.Printf(" ");
6196 if(returnType.kind != voidType)
6197 f.Printf("return ");
6198 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6199 for(param = dataType.params.first; param; param = param.next)
6201 if(param.prev) f.Printf(", ");
6202 if(param.kind != voidType)
6203 f.Printf(param.name);
6209 if(extraIndent) f.Printf(" ");
6210 f.Printf(" %c", CloseBracket);
6215 if(extraIndent) { x1 += 3; x2 += 3; }
6216 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6218 this.updatingCode = false;
6222 // Return false if we overrided a function and don't want to run params listing
6223 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6225 bool didOverride = false;
6226 EditLine line = editBox.line;
6227 char * text = line.text;
6228 int lineNum, charPos;
6229 Expression exp = null;
6232 //Identifier id = null;
6233 Expression memberExp = null;
6234 Identifier realIdentifier = null;
6236 if(!privateModule) return !didOverride;
6238 insideFunction = null;
6240 charPos = editBox.charPos + 1;
6241 if(!membersListShown)
6246 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6248 EditBoxStream f { editBox = editBox };
6250 updatingCode = true;
6251 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6255 if(!f.Seek(-1, current))
6258 if(!isspace(ch)) break;
6259 f.Seek(-1, current);
6261 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6263 lineNum = editBox.lineNumber + 1;
6264 charPos = editBox.charPos + 1;
6266 updatingCode = false;
6269 if(!membersListShown)
6271 memberExp = FindExpTree(ast, lineNum, charPos);
6272 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6277 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6279 EditBoxStream f { editBox = editBox };
6282 updatingCode = true;
6284 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6287 if(ch == '}' || ch == ',' || ch == ')')
6289 f.Seek(-1, current);
6297 if(!f.Seek(-1, current))
6300 if(!isspace(ch)) break;
6301 f.Seek(-1, current);
6305 f.Seek(-1, current);
6307 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6309 lineNum = editBox.lineNumber + 1;
6310 charPos = editBox.charPos + 1;
6312 updatingCode = false;
6315 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6320 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6321 lineNum = editBox.lineNumber + 1;
6322 charPos = editBox.charPos/* + 1*/;
6326 char tempString[1024];
6327 char * string = null;
6328 CodePosition idStart, idEnd;
6330 if(membersListShown)
6332 char * buffer = membersLine.text;
6334 bool firstChar = true;
6336 string = tempString;
6338 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6340 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6341 if(!isSpace) firstChar = false;
6343 string[len++] = buffer[c];
6347 else //if(realIdentifier)//if(id)
6350 char * buffer = id.string;
6352 bool firstChar = true;
6354 string = tempString;
6355 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6357 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6358 if(!isSpace) firstChar = false;
6360 string[len++] = buffer[c];
6366 EditLine editLine = editBox.line;
6367 bool firstChar = true;
6370 string = tempString;
6371 for(y = lineNum-1; y >= 0; y--)
6373 char * buffer = editLine.text;
6374 int lineCount = editLine.count;
6375 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6377 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6382 idEnd.charPos = x + 2;
6387 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6390 idEnd.charPos = x + 2;
6397 if(!isalnum(buffer[x]) && buffer[x] != '_')
6403 memmove(string+1, string, len++);
6404 string[0] = buffer[x];
6408 //if(done || firstChar)
6409 if(done || !firstChar)
6411 editLine = editLine.prev;
6414 if(!strcmp(string, "case"))
6420 else if(!strcmp(string, "return"))
6426 else if(!strcmp(string, "delete"))
6432 else if(!strcmp(string, "new"))
6438 else if(!strcmp(string, "renew"))
6446 idStart.charPos = x + 1;
6447 idStart.line = y + 1;
6450 if(!membersListShown)
6452 membersList.Clear();
6453 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6455 Type type = memberExp.member.exp.expType;
6456 if(pointer == 2 && type)
6458 if(type.kind == pointerType || type.kind == arrayType)
6467 ListSymbols(exp, enumOnly, string, realIdentifier);
6469 membersList.Sort(null, 1);
6474 // Virtual function override
6475 Identifier id = GetDeclId(insideFunction.declarator);
6476 char * string = id ? id.string : null;
6478 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6481 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6482 insideFunction = null;
6485 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6490 if(!didOverride) //insideFunction)
6492 rowCount = membersList.rowCount;
6495 DataRow row = string ? membersList.FindSubString(string) : null;
6496 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6498 char * newString = row.string;
6499 if(!membersListShown)
6501 membersLoc.start.line = idStart.line-1;
6502 membersLoc.start.charPos = idStart.charPos-1;
6503 //membersLoc.end = membersLoc.start;
6504 membersLoc.end.charPos = idEnd.charPos-1;
6505 membersLoc.end.line = idEnd.line-1;
6506 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6507 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6512 membersList.Destroy(0);
6513 membersListShown = false;
6516 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6518 line, membersLoc.start.line, membersLoc.start.charPos,
6519 line, membersLoc.end.line, membersLoc.end.charPos);
6520 editBox.PutS(newString);
6526 row = membersList.FindSubStringi(string);
6528 membersList.currentRow = row;
6529 membersList.currentRow.selected = false;
6532 membersList.currentRow = row;
6534 if(!membersListShown)
6538 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6539 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6540 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6541 editBox.GetCaretPosition(caret);
6542 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6544 membersList.master = this;
6546 caret.y += editBox.GetCaretSize();
6548 membersList.Create();
6551 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6552 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6553 Window parent = membersList.parent;
6555 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6557 y -= editBox.GetCaretSize() + membersList.size.h;
6558 membersAbove = true;
6561 membersAbove = false;
6563 membersList.position = { x, y };
6567 membersLoc.start.line = lineNum - 1;
6569 if(string && string[0])
6571 membersLoc.start.charPos = idStart.charPos-1;
6572 membersLoc.end = membersLoc.start;
6573 //membersLoc.end.charPos = id.loc.end.charPos-1;
6574 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6578 membersLoc.start.charPos = charPos;
6579 membersLoc.end = membersLoc.start;
6580 membersLoc.end.charPos = charPos;
6582 membersListShown = true;
6584 // Hack to keep caret shown
6585 editBox.GetCaretPosition(caret);
6586 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6589 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6595 SetCurrentContext(globalContext);
6598 return !didOverride;
6601 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6603 EditLine line = editBox.line;
6604 char * text = line.text;
6605 int lineNum, charPos;
6606 Expression exp = null;
6610 charPos = editBox.charPos + 1;
6613 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6615 EditBoxStream f { editBox = editBox };
6618 updatingCode = true;
6619 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6622 if(ch == '}' || ch == ',' || ch == ')')
6624 f.Seek(-1, current);
6632 if(!f.Seek(-1, current))
6635 if(!isspace(ch)) break;
6636 f.Seek(-1, current);
6640 f.Seek(-1, current);
6642 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6644 lineNum = editBox.lineNumber + 1;
6645 charPos = editBox.charPos + 1;
6647 updatingCode = false;
6650 charPos = Min(charPos, l1.count + 1);
6652 FindParamsTree(ast, lineNum, charPos);
6654 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6655 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6657 ::functionType = null;
6658 ::instanceType = null;
6661 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6662 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6666 Window parent = paramsList.parent;
6668 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6671 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6672 // ( Dummy exp: always ends up with same memory)
6674 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6675 editBox.GetCaretPosition(paramsPosition);
6676 this.paramsPosition.y += editBox.GetCaretSize();
6679 FreeType(this.functionType);
6680 FreeType(this.instanceType);
6682 this.functionType = ::functionType;
6683 this.instanceType = ::instanceType;
6685 if(this.functionType) this.functionType.refCount++;
6686 if(this.instanceType) this.instanceType.refCount++;
6688 this.paramsID = ::paramsID;
6689 functionExp = paramsInsideExp;
6691 paramsList.master = this;
6693 paramsList.Create();
6695 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6696 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6698 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6700 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6704 paramsAbove = false;
6705 if(x + paramsList.size.w > parent.clientSize.w)
6707 x = parent.clientSize.w - paramsList.size.w;
6711 paramsList.position = { x, y };
6713 // Hack to keep caret shown
6716 editBox.GetCaretPosition(caret);
6717 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6720 this.paramsShown = true;
6722 else if((!::functionType && !::instanceType) || reposition)
6724 paramsList.Destroy(0);
6725 paramsShown = false;
6727 FreeType(this.functionType);
6728 FreeType(this.instanceType);
6729 this.functionType = null;
6730 this.instanceType = null;
6734 SetCurrentContext(globalContext);
6742 designer.visible = true;
6743 designer.Activate();
6749 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6751 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };