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 prop.Get(selected.instance, dataForm);
377 prop.Get(test, dataTest);
379 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
381 prop.Set(test, dataForm);
387 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
389 void * dataForm, * dataTest;
391 dataForm = (void *)prop.Get(selected.instance);
392 dataTest = (void *)prop.Get(test);
394 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
396 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)) || 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(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);
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);
1379 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1380 $"It can't be compiled.");
1381 MessageBox { type = ok, parent = ide, master = ide, text = $"File not in project error", contents = s }.Modal();
1390 bool OnKeyDown(Key key, unichar ch)
1392 CodeEditor editor = (CodeEditor)master;
1393 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1395 if(editor.membersListShown)
1397 editor.membersList.Destroy(0);
1398 editor.membersListShown = false;
1401 if(editor.paramsShown)
1403 editor.paramsList.Destroy(0);
1404 editor.paramsShown = false;
1405 FreeType(editor.functionType);
1406 FreeType(editor.instanceType);
1408 editor.functionType = null;
1409 editor.instanceType = null;
1410 editor.paramsID = -1;
1414 return EditBox::OnKeyDown(key, ch);
1417 void OnVScroll(ScrollBarAction action, int position, Key key)
1419 if(anchor.left.distance)
1421 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1424 EditBox::OnVScroll(action, position, key);
1426 CodeEditor ce = (CodeEditor)parent;
1427 if(ce.openedFileInfo)
1428 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1432 void OnHScroll(ScrollBarAction action, int position, Key key)
1434 EditBox::OnHScroll(action, position, key);
1436 CodeEditor ce = (CodeEditor)parent;
1437 if(ce.openedFileInfo)
1438 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1445 fullRowSelect = false,
1448 borderStyle = bevel;
1449 // size = { 200, 400 };
1451 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1453 DataRow row = listBox.currentRow;
1456 char * string = row.string;
1458 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1460 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1461 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1462 editBox.PutS(string);
1465 membersListShown = false;
1470 bool OnKeyDown(Key key, unichar ch)
1472 CodeEditor editor = (CodeEditor) master;
1473 if(key == escape || key == leftAlt || key == rightAlt ||
1474 (key.ctrl && key.code != left && key.code != right &&
1475 key.code != leftShift && key.code != rightShift && key.code != space))
1477 if(editor.paramsShown)
1478 editor.paramsList.Destroy(0);
1479 if(editor.membersListShown)
1480 editor.membersList.Destroy(0);
1482 editor.paramsShown = false;
1483 FreeType(editor.functionType);
1484 FreeType(editor.instanceType);
1486 editor.functionType = null;
1487 editor.instanceType = null;
1488 editor.paramsID = -1;
1490 editor.membersListShown = false;
1494 return editor.editBox.OnKeyDown(key, ch);
1498 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1500 CodeEditor editor = (CodeEditor)master;
1504 editor.membersListShown = false;
1506 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1509 bool OnKeyHit(Key key, unichar ch)
1511 CodeEditor editor = (CodeEditor) master;
1515 case enter: case tab:
1517 DataRow row = currentRow;
1518 if(row && row.selected)
1520 char * string = row.string;
1522 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1523 editor.editBox.Delete(
1524 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1525 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1526 editor.editBox.PutS(string);
1529 editor.membersListShown = false;
1532 editor.editBox.OnKeyHit(key, ch);
1542 return ListBox::OnKeyHit(key, ch);
1548 // If before . or after
1549 //listBox.Destroy(true);
1550 result = editor.editBox.OnKeyHit(key, ch);
1565 clickThrough = true,
1567 borderStyle = contour,
1569 background = { 255,255,225 },
1571 OnKeyDown = membersList.OnKeyDown;
1573 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1575 CodeEditor editor = (CodeEditor)master;
1579 editor.membersListShown = false;
1581 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1584 bool OnKeyHit(Key key, unichar ch)
1586 CodeEditor editor = (CodeEditor)master;
1588 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1591 bool result = true; editor.editBox.OnKeyHit(key, ch);
1592 return (!created) ? false : result;
1599 void OnRedraw(Surface surface)
1601 CodeEditor editor = (CodeEditor) master;
1602 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1604 Type methodType = null;
1608 int functionW, nameW = 0;
1610 int spaceW, spaceH, commaW, commaWB, parW;
1612 int maxW = 0, lineW = 0;
1618 Font font = editor.normalFont.font;
1619 Font boldFont = editor.boldFont.font;
1620 Display display = this.display;
1622 if(!type) { return; };
1624 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1626 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1627 display.FontExtent(font, ", ", 2, &commaW, null);
1628 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1629 display.FontExtent(font, ")", 1, &parW, null);
1632 if(editor.functionType)
1634 PrintType(type.returnType, string, true, true);
1635 display.FontExtent(font, string, strlen(string), &functionW, null);
1637 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1638 totalW = nameW + functionW + 2 * parW;
1642 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1643 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1644 if(instanceName && type.kind != functionType)
1645 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1646 totalW = functionW + nameW;
1647 surface.TextFont(boldFont);
1650 surface.WriteText(x, y, string, strlen(string));
1651 x += functionW + spaceW;
1653 if(editor.functionType)
1656 surface.WriteText(x, y, type.name, strlen(type.name));
1658 surface.WriteText(x, y, "(", 1);
1661 if(methodType && !methodType.staticMethod)
1665 if(id == editor.paramsID)
1666 surface.TextFont(boldFont);
1668 if(methodType.methodClass)
1669 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1673 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1674 width += ((id == editor.paramsID) ? commaWB : commaW);
1679 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1684 x = 2 + nameW + spaceW + functionW + parW;
1688 if(methodType.methodClass)
1689 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1692 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1694 surface.WriteText(x, y, ",", 1);
1695 x += ((id == editor.paramsID) ? commaWB : commaW);
1703 if(id == editor.paramsID)
1704 surface.TextFont(font);
1708 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1710 for(param = type.params.first; param; param = param.next)
1712 char paramString[1024];
1715 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1716 surface.TextFont(boldFont);
1719 PrintType(param, paramString, true, true);
1720 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1722 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1727 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1732 x = 2 + nameW + spaceW + functionW + parW;
1736 surface.WriteText(x, y, paramString, strlen(paramString));
1740 surface.WriteText(x, y, ",", 1);
1741 x += ((id == editor.paramsID) ? commaWB : commaW);
1749 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1750 surface.TextFont(font);
1755 surface.WriteText(x, y, ")", 1);
1757 else if(instanceName && type.kind != functionType)
1759 surface.WriteText(x, y, instanceName, strlen(instanceName));
1763 bool OnResizing(int * w, int * h)
1765 CodeEditor editor = (CodeEditor) master;
1766 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1768 Type methodType = null;
1772 int functionW = 0, nameW = 0;
1774 int spaceW, spaceH, commaW, commaWB, parW;
1776 int maxW = 0, lineW = 0;
1781 Font font = editor.normalFont.font;
1782 Font boldFont = editor.boldFont.font;
1783 Display display = this.display;
1785 if(type.kind == TypeKind::methodType)
1788 ProcessMethodType(type.method);
1789 type = type.method.dataType;
1792 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1793 display.FontExtent(font, ", ", 2, &commaW, null);
1794 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1795 display.FontExtent(font, ")", 1, &parW, null);
1798 if(editor.functionType && type)
1800 PrintType(type.returnType, string, true, true);
1801 display.FontExtent(font, string, strlen(string), &functionW, null);
1803 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1804 totalW = nameW + spaceW + functionW + 2 * parW;
1808 PrintType(type, string, false, true); // /*true);
1809 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1810 if(instanceName && type.kind != functionType)
1811 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1812 totalW = functionW + nameW + spaceW;
1815 if(editor.functionType)
1821 if(methodType.methodClass)
1822 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1823 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1824 width += ((id == editor.paramsID) ? commaWB : commaW);
1829 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1842 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1844 for(param = type.params.first; param; param = param.next)
1846 char paramString[1024];
1850 PrintType(param, paramString, true, true);
1851 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1853 width += ((id == editor.paramsID) ? commaWB : commaW);
1858 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1875 *w = realW + totalW + 4;
1881 Menu fileMenu { menu, $"File", f }; // MenuPlacement?
1882 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1883 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1885 Menu debugMenu { menu, $"Debug", d }; // MenuPlacement?
1886 MenuItem debugRunToCursor
1888 debugMenu, $"Run To Cursor", c, Key { f10, ctrl = true };
1889 bool NotifySelect(MenuItem selection, Modifiers mods)
1891 ProjectView projectView = ide.projectView;
1892 if(!projectView.buildInProgress)
1894 int line = editBox.lineNumber + 1;
1897 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1898 ProjectConfig config = projectView.project.config;
1899 ide.debugger.RunToCursor(compiler, config, fileName, line, false);
1906 MenuItem debugSkipRunToCursor
1908 debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true };
1909 bool NotifySelect(MenuItem selection, Modifiers mods)
1911 ProjectView projectView = ide.projectView;
1912 int line = editBox.lineNumber + 1;
1915 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1916 ProjectConfig config = projectView.project.config;
1917 ide.debugger.RunToCursor(compiler, config, fileName, line, true);
1923 MenuDivider { debugMenu };
1924 MenuItem debugToggleBreakpoint
1926 debugMenu, $"Toggle Breakpoint", t, f9;
1927 bool NotifySelect(MenuItem selection, Modifiers mods)
1929 ProjectView projectView = ide.projectView;
1930 if(projectView && fileName)
1932 int line = editBox.lineNumber + 1;
1933 char name[MAX_LOCATION];
1935 // TOFIX: This only looks at the filename...
1936 GetLastDirectory(fileName, name);
1937 if(ide && ide.workspace)
1939 for(p : ide.workspace.projects)
1941 if(p.topNode.Find(name, false))
1949 for(p : ide.workspace.projects)
1951 if(IsPathInsideOf(fileName, p.topNode.path))
1959 ide.debugger.ToggleBreakpoint(fileName, line, prj);
1969 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1973 designer.parent = parent;
1976 toolBox = ((IDEWorkSpace)master).toolBox;
1978 // Debugger bug here: value of toolBox appears as 0
1980 sheet = ((IDEWorkSpace)master).sheet;
1985 bool OnClose(bool parentClosing)
1989 if(ide.workspace && fileName)
1990 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
1991 if(inUseDebug && !debugClosing)
1993 debugClosing = true;
1995 if(CloseConfirmation(false))
1998 OnFileModified({ modified = true }, null);
2000 debugClosing = false;
2003 if(designer && !designer.closing)
2005 if(designer.visible)
2012 //Window formEditor = designer;
2013 //formEditor.Destroy(0);
2016 ide.AdjustFileMenus();
2021 void OnDestroy(void)
2023 ObjectInfo oClass, next;
2024 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2026 FreeType(this.functionType);
2027 FreeType(this.instanceType);
2032 designer.codeEditor = null;
2033 designer.Destroy(0);
2037 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2039 ObjectInfo object, next;
2041 for(object = oClass.instances.first; object; object = next)
2046 Designer::DestroyObject(object.instance);
2047 delete object.instance;
2049 sheet.DeleteObject(object);
2051 oClass.instances.Delete(object);
2055 Designer::DestroyObject(oClass.instance);
2056 delete oClass.instance;
2058 sheet.DeleteObject(oClass);
2060 classes.Delete(oClass);
2063 if(windowClass && windowClass.data)
2064 UnapplySkin(windowClass);
2068 if(sheet.codeEditor == this)
2070 sheet.codeEditor = null;
2071 toolBox.codeEditor = null;
2077 ProjectView projectView = ide.projectView;
2080 ProjectNode node = projectView.GetNodeFromWindow(this, null);
2081 if(node && node.modified)
2083 node.modified = false;
2084 projectView.Update(null);
2090 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2092 // 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
2094 if(directActivation)
2095 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2097 if(active && directActivation)
2100 openedFileInfo.Activate();
2104 Location * loc = null;
2105 UpdateFormCode(); // To ensure update when modifying properties...
2107 // Got to the right spot in code so we don't lose our form selection...
2110 if(selected.instCode)
2111 loc = &selected.instCode.loc;
2112 else if(selected.classDefinition)
2113 loc = &selected.classDefinition.loc;
2115 line = editBox.lineNumber + 1;
2116 charPos = editBox.charPos + 1;
2121 if(selected && !loc->Inside(line, charPos))
2123 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2124 line = editBox.lineNumber + 1;
2125 charPos = editBox.charPos + 1;
2127 else if(selected && selected.classDefinition)
2130 for(object = selected.instances.first; object; object = object.next)
2134 if(object.instCode.loc.Inside(line, charPos))
2140 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2141 line = editBox.lineNumber + 1;
2142 charPos = editBox.charPos + 1;
2147 ProcessCaretMove(editBox, line, charPos);
2153 bool OnSaveFile(char * fileName)
2160 f = FileOpen(fileName, write);
2163 if(!ide.projectView)
2164 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2168 this.fileName = fileName; // Put this here because the form designer will check for it...
2169 designer.fileName = fileName;
2170 designer.modifiedDocument = false;
2172 editBox.Save(f, false);
2173 modifiedDocument = false;
2181 bool OnFileModified(FileChange fileChange, char * param)
2183 bool reload = false;
2184 if(visible == false && inUseDebug == true)
2190 sprintf(message, $"The document %s was modified by another application.\n"
2191 "Would you like to reload it and lose your changes?", fileName);
2192 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2193 contents = message }.Modal() == yes)
2199 File f = FileOpen(fileName, read);
2202 int lineNumber, charPos, len;
2206 updatingCode = true;
2207 lineNumber = editBox.lineNumber;
2208 charPos = editBox.charPos;
2209 scroll = editBox.scroll;
2212 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2213 len = strlen(editBox.line.text);
2214 editBox.GoToLineNum(lineNumber);
2215 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2216 editBox.scroll = scroll;
2217 updatingCode = false;
2218 loadingFile = false;
2220 codeModified = true;
2224 designer.modifiedDocument = false;
2226 modifiedDocument = false;
2234 void OnRedraw(Surface surface)
2237 surface.SetBackground(marginColor);
2238 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2239 if(ideSettings.showLineNumbers)
2241 int currentLineNumber;
2246 surface.textOpacity = false;
2247 surface.font = font.font;
2248 surface.TextExtent(" ", 1, null, &spaceH);
2249 currentLineNumber = editBox.scroll.y / spaceH + 1;
2251 surface.SetForeground(lineNumbersColor);
2252 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2254 // Highlight current line
2255 if(editBox.lineNumber == currentLineNumber - 1)
2257 surface.SetBackground(selectedMarginColor);
2258 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2259 surface.SetBackground(marginColor);
2261 sprintf(lineText,"%5u ", currentLineNumber % 100000);
2262 if(currentLineNumber <= editBox.numLines)
2263 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,6);
2265 currentLineNumber++;
2269 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2271 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2272 int lineCursor, lineTopFrame, breakpointLines[128];
2273 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2274 Debugger debugger = ide.debugger;
2275 BitmapResource bmpRes;
2277 boxH = clientSize.h;
2278 scrollY = editBox.scroll.y;
2279 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2281 bpOnCursor = bpOnTopFrame = false;
2282 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2285 for(i = 0; i < count; i++)
2287 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2289 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2290 if(breakpointLines[i] == lineCursor)
2292 if(breakpointLines[i] == lineTopFrame)
2293 bpOnTopFrame = true;
2296 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2298 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2301 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2302 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2303 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2305 if(editBox.anchor.left.distance)
2307 if(editBox.horzScroll && editBox.horzScroll.visible)
2309 surface.SetBackground(control);
2310 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2315 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2320 lineY = (line - 1) * lineH;
2321 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2323 Bitmap bitmap = resource.bitmap;
2325 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2332 char ext[MAX_EXTENSION];
2333 char * fileName = property::fileName;
2335 if(SearchString(fileName, 0, "Makefile", false, true))
2336 editBox.useTab = true;
2337 designer.fileName = fileName;
2341 GetExtension(fileName, ext);
2342 if(!strcmpi(ext, "ec"))
2344 codeModified = true;
2348 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"))
2349 editBox.syntaxHighlighting = true;
2351 editBox.syntaxHighlighting = false;
2354 display.FontExtent(font.font, " ", 1, &spaceW, null);
2355 editBox.anchor = Anchor
2357 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2358 right = 0, top = 0, bottom = 0
2367 display.FontExtent(font.font, " ", 1, &spaceW, null);
2368 editBox.anchor = Anchor
2370 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2371 right = 0, top = 0, bottom = 0
2376 bool LoadFile(char * filePath)
2378 File f = FileOpen(filePath, read);
2381 // Added this here...
2382 fileName = filePath;
2384 updatingCode = true;
2386 updatingCode = false;
2387 loadingFile = false;
2396 void DebugMenusDisabled()
2398 bool debugMenusDisabled = ide.GetDebugMenusDisabled();
2399 debugRunToCursor.disabled = debugMenusDisabled;
2400 debugSkipRunToCursor.disabled = debugMenusDisabled;
2401 debugToggleBreakpoint.disabled = debugMenusDisabled;
2407 ProjectView projectView = ide.projectView;
2410 designer.fileName = fileName;
2416 sprintf(title, $"Untitled %d", documentID);
2417 // designer.fileName = CopyString(title);
2418 designer.fileName = title;
2421 DebugMenusDisabled();
2423 for(c = 0; c < CodeObjectType::enumSize; c++)
2424 icons[c] = BitmapResource { iconNames[c], window = this };
2426 codeModified = true;
2438 selected.modified = true;
2439 selected.oClass.modified = true;
2441 designer.modifiedDocument = true;
2442 modifiedDocument = true;
2443 formModified = true;
2446 /****************************************************************************
2448 ****************************************************************************/
2451 this.defines.Free(FreeModuleDefine);
2452 this.imports.Free(FreeModuleImport);
2459 FreeExcludedSymbols(this.excludedSymbols);
2460 FreeContext(this.globalContext);
2462 FreeGlobalData(&this.globalData);
2464 if(GetGlobalContext() == globalContext)
2466 SetGlobalData(null);
2467 SetGlobalContext(null);
2468 SetExcludedSymbols(null);
2469 SetTopContext(null);
2470 SetCurrentContext(null);
2473 SetPrivateModule(null);
2476 if(this.privateModule)
2478 FreeTypeData(this.privateModule);
2479 delete this.privateModule;
2480 this.privateModule = null;
2486 static bool reentrant = false;
2491 char * selectedClassName = null, * selectedName = null;
2492 int selectedPos = 0;
2493 Designer backDesigner;
2494 char oldWorkDir[MAX_LOCATION];
2495 char mainModuleName[MAX_FILENAME] = "";
2497 ImportedModule module;
2498 char extension[MAX_EXTENSION];
2500 Time parseCodeStart = GetTime();
2501 Time startTime, startFindClass;
2503 findClassTotalTime = 0;
2504 checkTypeTotalTime = 0;
2505 externalImportTotalTime = 0;
2506 findClassIgnoreNSTotalTime = 0;
2507 findSymbolTotalTime = 0;
2508 //ResetClassFindTime();
2512 // 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)
2513 if(reentrant) return;
2520 selectedClassName = CopyString(oClass.name);
2521 if(selected != oClass)
2523 ObjectInfo object = this.selected;
2524 selectedName = CopyString(object.name);
2528 for(check = this.oClass.instances.first; check; check = check.next)
2540 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2542 defines.Free(FreeModuleDefine);
2543 imports.Free(FreeModuleImport);
2545 SetGlobalData(&globalData);
2546 SetGlobalContext(globalContext);
2547 SetExcludedSymbols(&excludedSymbols);
2548 SetTopContext(globalContext);
2549 SetCurrentContext(globalContext);
2550 SetDefines(&defines);
2551 SetImports(&imports);
2552 SetCurrentNameSpace(null);
2555 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2556 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2557 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2558 "/I T:\\ecere\\include /E %s", argv[1]);
2562 ChangeWorkingDir("e:\\ec");
2563 sprintf(command, "gcc -x c -E -");
2564 fileInput = DualPipeOpen({ output = true, input = true }, command);
2565 SetFileInput(fileInput);
2570 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2572 fileInput.Write(buffer, 1, count);
2577 fileInput.CloseOutput();
2581 // TOCHECK: COULDN'T WE CALL FreeParser here?
2583 this.functionType = null;
2584 this.instanceType = null;
2587 sheet.SelectObject(null);
2593 // We don't want the designer to be notified of selection when deleting rows...
2594 backDesigner = designer;
2599 ObjectInfo _class, next;
2601 for(_class = classes.first; _class; _class = next)
2607 for(;object = _class.instances.first;)
2611 Designer::DestroyObject(object.instance);
2612 delete object.instance;
2614 sheet.DeleteObject(object);
2616 _class.instances.Delete(object);
2620 Designer::DestroyObject(_class.instance);
2621 delete _class.instance;
2623 sheet.DeleteObject(_class);
2625 classes.Delete(_class);
2631 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2632 if(windowClass && windowClass.data)
2633 UnapplySkin(windowClass);
2636 designer = backDesigner;
2639 fileInput = editFile = EditBoxStream { editBox = editBox };
2640 SetFileInput(fileInput);
2649 FreeContext(this.globalContext);
2650 FreeExcludedSymbols(this.excludedSymbols);
2653 FreeGlobalData(&this.globalData);
2655 if(this.privateModule)
2657 FreeTypeData(this.privateModule);
2658 delete this.privateModule;
2662 startTime = GetTime();
2663 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2665 printf("classes.count: %d\n", globalContext.classes.count);
2668 this.privateModule = __ecere_COM_Initialize(false, 1, null);
2670 SetPrivateModule(privateModule);
2673 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2674 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2675 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2676 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2677 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2680 fileName = this.fileName;
2682 if(ide.workspace && ide.workspace.projects && fileName)
2684 for(p : ide.workspace.projects)
2686 char path[MAX_LOCATION];
2688 MakePathRelative(fileName, p.topNode.path, path);
2689 MakeSlashPath(path);
2691 pn = p.topNode.FindWithPath(path, false);
2700 project = ide.project;
2702 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2704 ChangeWorkingDir(project.topNode.path);
2706 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2708 GetLastDirectory(fileName, mainModuleName);
2709 GetExtension(mainModuleName, extension);
2711 SetBuildingEcereCom(false);
2712 SetBuildingEcereComModule(false);
2714 // TODO: Get symbolsDir from project settings instead...
2717 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2718 ProjectConfig config = project.config;
2719 DirExpression objDir = project.GetObjDir(compiler, config);
2720 SetSymbolsDir(objDir.dir);
2723 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2724 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2728 switch(GetRuntimePlatform())
2730 case win32: SetSymbolsDir("obj/debug.win32"); break;
2731 case tux: SetSymbolsDir("obj/debug.linux"); break;
2732 case apple: SetSymbolsDir("obj/debug.apple"); break;
2734 SetIncludeDirs(null);
2735 SetSysIncludeDirs(null);
2739 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2741 // TODO FIX for configless project
2742 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2744 for(item : ide.project.config.options.preprocessorDefinitions)
2746 if(!strcmp(item, "BUILDING_ECERE_COM"))
2748 SetBuildingEcereCom(true);
2755 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2756 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2757 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2758 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2759 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2760 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2761 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2762 strcmpi(mainModuleName, "Mutex.ec")))
2764 SetBuildingEcereComModule(true);
2767 // Predeclare all classes
2769 char symFile[MAX_FILENAME];
2770 char symLocation[MAX_LOCATION];
2771 ImportedModule module, next;
2773 GetLastDirectory(fileName, symFile);
2774 ChangeExtension(symFile, "sym", symFile);
2776 strcpy(symLocation, GetSymbolsDir());
2777 PathCat(symLocation, symFile);
2779 // if(!GetEcereImported() && !GetBuildingEcereCom())
2780 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2783 startTime = GetTime();
2785 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2787 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2792 startTime = GetTime();
2794 // LoadSymbols(symLocation, normalImport, true);
2795 LoadSymbols(symLocation, preDeclImport, false);
2797 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2800 for(module = defines.first; module; module = next)
2803 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2806 defines.Delete(module);
2811 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2813 SetDefaultDeclMode(privateAccess);
2814 SetDeclMode(privateAccess);
2818 SetDefaultDeclMode(defaultAccess);
2819 SetDeclMode(defaultAccess);
2822 StripExtension(mainModuleName);
2823 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2824 defines.AddName(module);
2827 // SetYydebug(true);
2832 startTime = GetTime();
2833 startFindClass = checkTypeTotalTime;
2837 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2839 CheckDataRedefinitions();
2842 SetIncludeDirs(null);
2843 SetSysIncludeDirs(null);
2854 startTime = GetTime();
2856 PrePreProcessClassDefinitions();
2857 ComputeModuleClasses(privateModule);
2858 PreProcessClassDefinitions();
2859 ProcessClassDefinitions();
2861 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2862 startTime = GetTime();
2867 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2868 startTime = GetTime();
2870 ProcessInstantiations();
2872 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2875 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2877 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2878 if(!windowClass || windowClass.internalDecl)
2881 startTime = GetTime();
2883 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2884 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2885 eModule_Load(this.privateModule, "ecere", privateAccess);
2887 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2890 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2892 if(windowClass && windowClass.data)
2893 ApplySkin(windowClass, app.currentSkin.name, null);
2897 startTime = GetTime();
2899 for(external = ast->first; external; external = external.next)
2901 if(external.type == classExternal)
2903 ClassDefinition _class = external._class;
2904 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2906 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2909 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2911 Instance instance = eInstance_New(regClass);
2912 ObjectInfo classObject
2914 name = CopyString(_class._class.name);
2915 instance = instance;
2916 classDefinition = _class;
2917 oClass = classObject;
2920 classes.Add(classObject);
2924 // Moved this at bottom so that the file dialog doesn't show up in eCom
2925 designer.CreateObject(instance, classObject, true, null);
2926 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
2928 if(_class.definitions)
2932 for(def = _class.definitions->first; def; def = def.next)
2936 case defaultPropertiesClassDef:
2939 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
2941 Identifier id = propDef.identifiers->first;
2944 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
2947 Class propertyClass = prop.dataTypeClass;
2949 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
2950 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
2952 FreeType(propDef.initializer.exp.destType);
2953 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
2954 ProcessExpressionType(propDef.initializer.exp);
2956 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
2958 Expression computed = CopyExpression(propDef.initializer.exp);
2959 ComputeExpression(computed);
2961 if(computed.isConstant && computed.type == instanceExp && !id.next)
2965 if(computed.instance._class && computed.instance._class.symbol &&
2966 computed.instance._class.symbol.registered &&
2967 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
2969 prop.Set(instance, computed.instance.data);
2971 // This was saved in the control and shouldn't be freed by FreeExpression...
2972 if(propertyClass.type == normalClass)
2973 computed.instance.data = null;
2977 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
2978 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
2980 String temp = new char[strlen(computed.string)+1];
2981 ReadString(temp, computed.string);
2982 prop.Set(instance, temp);
2986 propDef.variable = true;
2988 FreeExpression(computed);
2992 Expression computed = CopyExpression(propDef.initializer.exp);
2993 ComputeExpression(computed);
2994 if(computed.isConstant)
2996 //if(computed.type == memberExp) computed = computed.member.exp;
2998 if(computed.type == constantExp)
3000 Operand value = GetOperand(computed);
3001 DataValue valueData;
3002 valueData.i64 = value.i64;
3003 SetProperty(prop, instance, valueData);
3005 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3007 String temp = new char[strlen(computed.string)+1];
3008 ReadString(temp, computed.string);
3009 prop.Set(instance, temp);
3014 propDef.variable = true;
3016 FreeExpression(computed);
3020 propDef.variable = true;
3024 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3025 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3026 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3029 // Maintain a list in FunctionDefinition of who is attached to it
3030 for(def = _class.definitions->first; def; def = def.next)
3032 if(def.type == functionClassDef)
3034 ClassFunction function = def.function;
3035 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3037 function.attached.Add(OldLink { data = method });
3047 case declarationClassDef:
3049 Declaration decl = def.decl;
3052 case instDeclaration:
3054 Instantiation inst = decl.inst;
3055 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3056 if(instClass && eClass_GetDesigner(instClass))
3058 Instance control = eInstance_New(instClass);
3063 oClass = classObject;
3067 classObject.instances.Add(object);
3069 // TOCHECK: Why is this needed now?
3070 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3071 def.object = object;
3073 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3075 designer.CreateObject(control, object, false, classObject.instance);
3076 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3086 // Second pass, process instantiation members
3088 for(def = _class.definitions->first; def; def = def.next)
3092 case declarationClassDef:
3094 Declaration decl = def.decl;
3097 case instDeclaration:
3099 Instantiation inst = decl.inst;
3100 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3101 if(instClass && eClass_GetDesigner(instClass))
3104 object = object ? object.next : classObject.instances.first;
3105 control = object.instance;
3109 MembersInit members;
3110 for(members = inst.members->first; members; members = members.next)
3112 switch(members.type)
3114 case dataMembersInit:
3116 if(members.dataMembers)
3119 DataMember curMember = null;
3120 Class curClass = null;
3121 DataMember subMemberStack[256];
3122 int subMemberStackPos = 0;
3124 for(member = members.dataMembers->first; member; member = member.next)
3127 Identifier ident = member.identifiers ? member.identifiers->first : null;
3130 DataMember _subMemberStack[256];
3131 int _subMemberStackPos = 0;
3132 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3136 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3138 if(thisMember && thisMember.memberAccess == publicAccess)
3140 curMember = thisMember;
3141 curClass = curMember._class;
3142 memcpy(subMemberStack, _subMemberStack, sizeof(int) * _subMemberStackPos);
3143 subMemberStackPos = _subMemberStackPos;
3149 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3150 if(curMember) found = true;
3152 if(found && curMember.isProperty)
3154 Property prop = (Property) curMember;
3155 Class propertyClass = prop.dataTypeClass;
3157 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3159 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3161 FreeType(member.initializer.exp.destType);
3162 member.initializer.exp.destType = MkClassType(propertyClass.name);
3165 ProcessExpressionType(member.initializer.exp);
3167 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3169 Expression computed;
3171 /*char debugExpString[4096];
3172 debugExpString[0] = '\0';
3173 PrintExpression(member.initializer.exp, debugExpString);*/
3175 computed = CopyExpression(member.initializer.exp);
3178 ComputeExpression(computed);
3180 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3182 if(computed.instance.data)
3184 if(computed.instance._class && computed.instance._class.symbol &&
3185 computed.instance._class.symbol.registered &&
3186 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3188 prop.Set(control, computed.instance.data);
3190 // This was saved in the control and shouldn't be freed by FreeExpression...
3191 if(propertyClass.type == normalClass)
3192 computed.instance.data = null;
3196 else if(computed.type == identifierExp)
3198 member.variable = true;
3200 if(eClass_GetDesigner(propertyClass))
3203 char * name = computed.identifier.string;
3204 if(!strcmp(name, "this"))
3207 prop.Set(control, instance);
3208 member.variable = false;
3213 for(check = classObject.instances.first; check; check = check.next)
3214 if(check.name && !strcmp(name, check.name))
3217 prop.Set(control, check.instance);
3218 member.variable = false;
3224 else if(computed.type == memberExp)
3226 member.variable = true;
3227 if(computed.member.exp.type == identifierExp)
3229 char * name = computed.member.exp.identifier.string;
3230 if(!strcmp(name, "this"))
3232 char * name = computed.member.member.string;
3235 for(check = classObject.instances.first; check; check = check.next)
3236 if(check.name && !strcmp(name, check.name))
3239 prop.Set(control, check.instance);
3240 member.variable = false;
3248 for(check = classObject.instances.first; check; check = check.next)
3250 if(check.name && !strcmp(name, check.name))
3252 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3255 DataValue value { };
3256 GetProperty(getProperty, check.instance, &value);
3257 SetProperty(prop, control, value);
3258 member.variable = false;
3266 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3267 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3269 String temp = new char[strlen(computed.string)+1];
3270 ReadString(temp, computed.string);
3271 prop.Set(control, temp);
3275 member.variable = true;
3277 FreeExpression(computed);
3282 Expression computed = CopyExpression(member.initializer.exp);
3285 ComputeExpression(computed);
3286 if(computed.isConstant)
3288 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3290 if(!strcmp(propertyClass.dataTypeString, "float"))
3291 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3292 else if(!strcmp(propertyClass.dataTypeString, "double"))
3293 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3295 prop.Set(control, strtol(computed.constant, null, 0));
3297 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3299 String temp = new char[strlen(computed.string)+1];
3300 ReadString(temp, computed.string);
3301 prop.Set(control, temp);
3306 member.variable = true;
3308 FreeExpression(computed);
3314 member.variable = true;
3316 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3317 member.initializer.exp.type == memberExp) // identifierExp
3319 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3320 if(method && method.type == virtualMethod)
3323 // Maintain a list in FunctionDefinition of who is attached to it
3324 for(def = _class.definitions->first; def; def = def.next)
3326 if(def.type == functionClassDef)
3328 ClassFunction function = def.function;
3329 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3330 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3332 function.attached.Add(OldLink { data = method });
3333 // Reference this particular instance?
3348 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3359 //designer.CreateObject(instance, classObject, true, null);
3360 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3362 designer.PostCreateObject(instance, classObject, true, null);
3364 //instance.state = Hidden;
3365 //instance.Create();
3366 //instance.SetState(Normal, true, 0);
3375 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3379 // Restore Selection
3380 if(selectedClassName)
3383 for(oClass = classes.first; oClass; oClass = oClass.next)
3385 if(!strcmp(oClass.name, selectedClassName))
3387 this.oClass = oClass;
3391 delete selectedClassName;
3400 for(check = this.oClass.instances.first; check; check = check.next)
3402 if(check.name && !strcmp(check.name, selectedName))
3404 this.selected = check;
3410 if(this.oClass.instances.first)
3411 this.selected = this.oClass.instances.first;
3413 this.selected = this.oClass;
3416 else if(selectedPos == -1 || !this.oClass.instances.count)
3417 this.selected = this.oClass;
3423 if(selectedPos > this.oClass.instances.count)
3425 for(check = this.oClass.instances.first; check; check = check.next)
3427 if(selectedPos == pos++)
3429 this.selected = check;
3437 this.oClass = classes.first;
3438 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3440 delete selectedName;
3441 SetSymbolsDir(null);
3443 if(sheet.codeEditor == this)
3444 sheet.SelectObject(selected);
3447 codeModified = false;
3449 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3452 InvokeParameters(false, false, false);
3455 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3461 ChangeWorkingDir(oldWorkDir);
3463 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3464 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3465 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3466 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3467 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3469 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3471 if(inUseDebug && ide.projectView)
3472 ide.debugger.EvaluateWatches();
3475 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3478 Window control = (Window)object.instance;
3479 ObjectInfo classObject = object.oClass;
3481 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3483 if(!strcmp(_class.name, "DesignerBase")) return;
3485 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3487 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3488 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3490 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3491 (!prop.IsSet || prop.IsSet(control)))
3493 Class dataType = prop.dataTypeClass;
3495 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3499 if(dataType.type == structClass)
3501 void * dataForm = new0 byte[dataType.structSize];
3502 void * dataTest = new0 byte[dataType.structSize];
3504 ((void (*)())(void *)prop.Get)(control, dataForm);
3505 prop.Get(test, dataTest);
3507 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
3509 char tempString[1024] = "";
3511 bool needClass = true;
3515 prop.Set(test, dataForm);
3517 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
3519 eClass_FindNextMember(_class, curClass, curMember, null, null);
3520 if(*curMember != (DataMember)prop)
3521 f.Printf("%s = ", prop.name);
3523 *curMember = (DataMember)prop;
3524 *curClass = curMember->_class;
3527 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3529 f.Printf("%s", string);
3536 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3538 void * dataForm, * dataTest;
3540 dataForm = (void *)prop.Get(control);
3541 dataTest = (void *)prop.Get(test);
3543 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
3545 char tempString[1024] = "";
3550 prop.Set(test, dataForm);
3552 eClass_FindNextMember(_class, curClass, curMember, null, null);
3553 if(*curMember != (DataMember)prop)
3554 f.Printf("%s = ", prop.name);
3555 *curMember = (DataMember)prop;
3556 *curClass = curMember->_class;
3558 if(eClass_GetDesigner(dataType))
3560 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3561 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3562 f.Printf("this", prop.name);
3565 //ObjectInfo classObject;
3566 //for(classObject = classes.first; classObject; classObject = classObject.next)
3570 for(object = classObject.instances.first; object; object = object.next)
3572 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3574 f.Printf("%s", object.name);
3581 bool needClass = true;
3582 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
3583 f.Printf("%s", string);
3590 bool needClass = true;
3591 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
3593 if(!strcmp(dataType.dataTypeString, "char *"))
3596 OutputString(f, string);
3600 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3602 f.Printf("%s", string);
3605 *lastIsMethod = false;
3610 DataValue dataForm, dataTest;
3612 GetProperty(prop, control, &dataForm);
3613 GetProperty(prop, test, &dataTest);
3615 if((prop.IsSet && !prop.IsSet(test)) || dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
3618 char tempString[1024] = "";
3619 SetProperty(prop, test, dataForm);
3621 if(dataType.type != bitClass)
3623 bool needClass = true;
3625 if(dataType.type == enumClass)
3628 Class enumClass = eSystem_FindClass(privateModule, "enum");
3629 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3631 for(value = e.values.first; value; value = value.next)
3633 if((int)value.data == dataForm.i)
3635 string = value.name;
3641 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
3643 if(string && string[0])
3648 eClass_FindNextMember(_class, curClass, curMember, null, null);
3649 if(*curMember != (DataMember)prop)
3650 f.Printf("%s = ", prop.name);
3651 *curMember = (DataMember)prop;
3652 *curClass = curMember->_class;
3654 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3655 f.Printf("%sf", string);
3657 f.Printf("%s", string);
3661 else if(dataType.type == bitClass)
3663 bool needClass = true;
3665 if(*prev) f.Printf(", ");
3667 eClass_FindNextMember(_class, curClass, curMember, null, null);
3668 if(*curMember != (DataMember)prop)
3669 f.Printf("%s = ", prop.name);
3670 *curMember = (DataMember)prop;
3671 *curClass = curMember->_class;
3673 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm.ui, tempString, null, &needClass);
3675 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3677 f.Printf("%s", string);
3679 *lastIsMethod = false;
3689 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3691 Instantiation inst = object.instCode;
3692 Window control = (Window)object.instance;
3694 bool methodPresent = false;
3696 bool lastIsMethod = true;
3697 ObjectInfo classObject = object.oClass;
3703 // Instance removed, delete it
3704 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3706 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3707 position = inst.loc.end.pos + 1;
3711 bool multiLine = false;
3714 // Check if it's an unnamed instance
3717 f.Seek(inst.nameLoc.start.pos - position, current);
3718 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3719 position = inst.nameLoc.end.pos;
3721 f.Printf(object.name);
3726 if(isspace(ch) && ch != '\n')
3728 f.Seek(-1, current);
3736 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3738 f.Seek(pos - position, current);
3743 f.Seek(-1, current);
3752 f.Puts(object.name);
3757 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3758 methodPresent = true;
3766 if(ch == OpenBracket)
3772 // TODO: Simplify this?
3781 f.Seek(-1, current);
3793 if(ch == '\n') { toDelete = count; count = 0; }
3794 else if(isspace(ch)) count++;
3797 f.Seek(-1, current);
3801 toDelete += count - 6;
3811 f.Seek(-toDelete-count, current);
3812 f.DeleteBytes(toDelete);
3813 f.Seek(count, current);
3818 for(c = 0; c<toAdd; c++)
3824 methodPresent = multiLine;
3827 f.Printf(methodPresent ? "\n " : " ");
3833 // Instance not there, create a brand new one
3834 DeleteJunkBefore(f, position, &position);
3835 f.Printf(*firstObject ? "\n\n" : "\n");
3836 *firstObject = false;
3838 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3839 methodPresent = true;
3844 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3846 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3851 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3853 f.Printf(" %s %c ", control._class.name, OpenBracket);
3859 Instance test = eInstance_New(control._class);
3860 DataMember curMember = null;
3861 Class curClass = null;
3864 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3868 // Attach Method here
3869 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3871 if(prev) f.Printf(", ");
3872 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3877 if(inst && !object.deleted)
3879 MembersInit members;
3880 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3882 DeleteJunkBefore(f, position, &position);
3884 // Instance already there, clear out the properties
3885 for(members = inst.members->first; members; members = members.next)
3887 if(members.type == dataMembersInit)
3891 if(members.dataMembers)
3893 bool keptMember = false;
3894 MemberInit lastKept = null;
3896 for(member = members.dataMembers->first; member; member = member.next)
3898 Identifier ident = member.identifiers ? member.identifiers->first : null;
3899 bool deleted = false;
3901 // For now delete if it's not a method
3902 if(!member.variable) // && ident)
3904 if(!ident || !ident.next)
3906 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3909 f.Seek(member.loc.start.pos - position, current);
3910 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3911 position = member.loc.end.pos;
3916 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3917 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3918 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
3920 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
3921 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
3923 f.Seek(member.loc.start.pos - position, current);
3924 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3925 position = member.loc.end.pos;
3937 //f.Seek(member.loc.start.pos - position, current);
3938 //position = member.loc.start.pos;
3939 DeleteJunkBefore(f, member.loc.start.pos, &position);
3940 if(prev) f.Printf(", ");
3941 else if(keptMember) f.Printf(" ");
3946 if(!keptMember || !members.next)
3951 if(keptMember && lastKept != members.dataMembers->last)
3956 f.Seek(-1, current);
3962 f.Seek(-1, current);
3965 else if(!isspace(ch))
3967 f.Seek(-2, current);
3972 f.DeleteBytes(count);
3975 f.Seek(members.loc.end.pos - position, current);
3980 f.Seek(-1, current);
3982 position = members.loc.end.pos + 1;
3986 f.Seek(-1, current);
3987 position = members.loc.end.pos;
3993 lastIsMethod = false;
3998 DeleteJunkBefore(f, position, &position);
4001 if(lastKept != members.dataMembers->last)
4006 f.Seek(-1, current);
4012 f.Seek(-1, current);
4015 else if(!isspace(ch))
4017 f.Seek(-2, current);
4022 f.DeleteBytes(count);
4026 f.Seek(members.loc.end.pos - position, current);
4027 position = members.loc.end.pos;
4031 lastIsMethod = true;
4034 lastIsMethod = false;
4040 f.Seek(members.loc.end.pos - position, current);
4041 position = members.loc.end.pos;
4043 lastIsMethod = true;
4046 else if(members.type == methodMembersInit)
4048 if(this.methodAction == actionDeleteMethod && members.function == function);
4050 methodPresent = true;
4052 // Delete instance method here
4053 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4054 members.function == function)
4056 if(this.moveAttached && !*text)
4057 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4059 DeleteJunkBefore(f, members.loc.start.pos, &position);
4060 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4061 position = members.loc.end.pos + 1;
4066 DeleteJunkBefore(f, position, &position);
4070 DeleteJunkBefore(f, members.loc.start.pos, &position);
4071 lastIsMethod = true;
4075 f.Seek(members.loc.end.pos - position, current);
4076 position = members.loc.end.pos;
4078 DeleteJunkBefore(f, position, &position);
4087 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4089 Method method = this.method;
4090 DeleteJunkBefore(f, position, &position);
4096 if(!method.dataType)
4097 method.dataType = ProcessTypeString(method.dataTypeString, false);
4100 Type dataType = method.dataType;
4101 Type returnType = dataType.returnType;
4104 if(this.moveAttached)
4106 // Move function here:
4107 int newLen = strlen(method.name);
4112 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4114 // First change name of function
4115 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4116 *textSize += newLen - movedFuncIdLen;
4117 memcpy(*text + movedFuncIdPos, method.name, newLen);
4119 // Second, tab right
4122 for(c = 0; (*text)[c]; )
4125 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4128 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4129 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4133 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4143 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4145 // ADDING METHOD HERE
4147 OutputType(f, returnType, false);
4150 if(dataType.thisClass)
4152 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4154 if(dataType.thisClass.shortName)
4155 f.Printf(dataType.thisClass.shortName);
4157 f.Printf(dataType.thisClass.string);
4161 f.Printf(method.name);
4163 for(param = dataType.params.first; param; param = param.next)
4165 OutputType(f, param, true);
4170 f.Printf(" %c\n\n", OpenBracket);
4172 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4174 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4175 f.Printf(" return true;\n");
4176 else if(returnType.kind != voidType)
4177 f.Printf(" return 0;\n");
4182 if(returnType.kind != voidType)
4183 f.Printf("return ");
4184 f.Printf("%s::%s(", control._class.name, method.name);
4185 for(param = dataType.params.first; param; param = param.next)
4187 if(param.prev) f.Printf(", ");
4188 if(param.kind != voidType)
4189 f.Printf(param.name);
4193 f.Printf(" %c\n", CloseBracket);
4199 if(!object.instCode)
4202 f.Printf(" %c;\n", CloseBracket);
4204 f.Printf("%c;\n", CloseBracket);
4206 else if(!object.deleted)
4208 // Turn this into a multiline instance when adding a method
4209 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4211 f.Printf(methodPresent ? "\n " : " ");
4213 f.Seek(inst.loc.end.pos + 1 - position, current);
4214 position = inst.loc.end.pos + 1;
4219 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4222 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4224 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4226 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4228 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4229 if(prop && prop.isProperty && !prop.conversion)
4231 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4232 (!prop.IsSet || prop.IsSet(classObject.instance)))
4234 Class dataType = prop.dataTypeClass;
4235 char tempString[1024] = "";
4237 bool specify = false;
4240 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4241 if(member && member._class == regClass)
4245 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4247 if(dataType && dataType.type == structClass)
4249 void * dataForm = new0 byte[dataType.structSize];
4250 void * dataTest = new0 byte[dataType.structSize];
4252 prop.Get(classObject.instance, dataForm);
4253 prop.Get(test, dataTest);
4255 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
4257 bool needClass = true;
4259 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
4260 prop.Set(test, dataForm);
4262 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4264 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4269 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4271 void * dataForm, * dataTest;
4273 dataForm = (void *)prop.Get(classObject.instance);
4274 dataTest = (void *)prop.Get(test);
4276 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, dataForm, dataTest))
4278 char tempString[1024] = "";
4280 prop.Set(test, dataForm);
4282 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4284 // Shouldn't go here ...
4285 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4289 bool needClass = true;
4291 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, dataForm, tempString, null, &needClass);
4293 if(!strcmp(dataType.dataTypeString, "char *"))
4295 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4296 OutputString(f, string);
4300 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4302 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4308 DataValue dataForm, dataTest;
4310 GetProperty(prop, classObject.instance, &dataForm);
4311 GetProperty(prop, test, &dataTest);
4313 if(dataType._vTbl[__ecereVMethodID_class_OnCompare](dataType, &dataForm, &dataTest))
4315 SetProperty(prop, test, dataForm);
4316 if(dataType.type == bitClass)
4318 bool needClass = true;
4319 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
4321 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4323 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4327 bool needClass = true;
4328 if(dataType.type == enumClass)
4331 Class enumClass = eSystem_FindClass(privateModule, "enum");
4332 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4334 for(value = e.values.first; value; value = value.next)
4336 if((int)value.data == dataForm.i)
4338 string = value.name;
4344 string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, &dataForm, tempString, null, &needClass);
4345 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4346 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4348 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4357 void UpdateFormCode()
4366 else if(formModified)
4368 EditBoxStream f { editBox = editBox };
4372 Identifier movedFuncId;
4373 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4374 ObjectInfo classObject;
4380 movedFuncId = GetDeclId(function.declarator);
4381 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4382 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4385 for(classObject = classes.first; classObject; classObject = classObject.next)
4388 ClassDefinition classDef = classObject.classDefinition;
4389 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4392 bool firstObject = true;
4393 ObjectInfo object = classObject.instances.first;
4394 bool lastIsDecl = false;
4396 if(!classObject.modified) continue;
4398 test = eInstance_New(regClass);
4401 // Put it in the same desktop window...
4402 designer.PrepareTestObject(test);
4404 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4405 //f.Printf("%c\n\n", OpenBracket);
4407 // Change the _class name
4408 f.Seek(classDef.nameLoc.start.pos - position, current);
4409 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4410 f.Printf(classObject.name);
4411 position = classDef.nameLoc.end.pos;
4414 // Go to block start, delete all until no white space, put \n
4418 f.Seek(classDef.blockStart.end.pos - position, current);
4419 position = classDef.blockStart.end.pos;
4421 for(; f.Getc(&ch); count++)
4425 f.Seek(-1, current);
4435 f.Seek(-count, current);
4437 f.DeleteBytes(count-back);
4439 position += count-back;
4442 // Output properties
4443 OutputClassProperties(classObject.instance._class, classObject, f, test);
4445 for(def = classDef.definitions->first; def; def = def.next)
4449 case defaultPropertiesClassDef:
4451 bool keptMember = false;
4453 MemberInit lastKept = null;
4456 DeleteJunkBefore(f, def.loc.start.pos, &position);
4459 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4461 Identifier ident = propDef.identifiers->first;
4462 bool deleted = false;
4464 // For now delete if it's a prop
4465 if(!propDef.variable && ident)
4469 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4472 f.Seek(propDef.loc.start.pos - position, current);
4473 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4474 position = propDef.loc.end.pos;
4479 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4480 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4482 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4483 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4485 f.Seek(propDef.loc.start.pos - position, current);
4486 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4487 position = propDef.loc.end.pos;
4505 f.Seek(def.loc.end.pos - position - 1, current);
4510 f.Seek(-1, current);
4513 position = def.loc.end.pos;
4517 if(lastKept != def.defProperties->last)
4522 f.Seek(-1, current);
4528 f.Seek(-1, current);
4531 else if(!isspace(ch))
4533 f.Seek(-2, current);
4538 f.DeleteBytes(count);
4542 f.Seek(def.loc.end.pos - position, current);
4543 position = def.loc.end.pos;
4548 case declarationClassDef:
4550 Declaration decl = def.decl;
4552 if(decl.type == instDeclaration)
4554 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4556 while(def.object && object != def.object)
4558 if(object /*&& ((ObjectInfo)def.object).modified*/)
4559 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4560 object = object.next;
4563 DeleteJunkBefore(f, def.loc.start.pos, &position);
4564 f.Printf(firstObject ? "\n\n " : "\n ");
4565 firstObject = false;
4567 if(def.object && ((ObjectInfo)def.object).modified)
4568 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4570 object = object ? object.next : null;
4574 DeleteJunkBefore(f, def.loc.start.pos, &position);
4575 f.Printf(firstObject ? "\n\n " : "\n ");
4576 firstObject = false;
4582 DeleteJunkBefore(f, def.loc.start.pos, &position);
4583 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4588 case functionClassDef:
4590 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4591 if(!def.function.body) continue;
4595 DeleteJunkBefore(f, def.loc.start.pos, &position);
4598 // Delete _class methods
4599 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4600 def.function == function)
4605 if(moveAttached && !text)
4607 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4610 f.Seek(def.loc.end.pos - position, current);
4611 for(; f.Getc(&ch); count++)
4615 f.Seek(-1, current);
4619 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4621 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4622 position = def.loc.end.pos + count;
4625 // In case of detaching methods in the _class, simply rename the method
4626 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4628 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4629 f.DeleteBytes(movedFuncIdLen);
4631 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4634 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4635 function == def.function)
4637 // In case of attaching methods in the _class, simply rename the method
4638 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4639 position = function.loc.start.pos + movedFuncIdPos;
4640 f.DeleteBytes(movedFuncIdLen);
4641 if(method.dataType.thisClass)
4642 f.Printf("%s::", method.dataType.thisClass.string);
4643 f.Puts(method.name);
4644 position += movedFuncIdLen;
4649 DeleteJunkBefore(f, def.loc.start.pos, &position);
4650 if(def.type == memberAccessClassDef)
4653 firstObject = false;
4663 f.Seek(def.loc.end.pos - position, current);
4664 position = def.loc.end.pos;
4667 // Output attached methods
4668 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4670 DeleteJunkBefore(f, position, &position);
4671 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4674 // ********** INSTANCES ***************
4675 for(; object; object = object.next)
4677 if(!object.instCode)
4679 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4683 DeleteJunkBefore(f, position, &position);
4685 // ****************** METHODS ***********************
4686 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4688 // If detaching an instance method
4689 if(selected != classObject)
4691 int newLen = strlen(methodName);
4694 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4695 // Tab selection left
4698 for(c = 0; text[c]; )
4701 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4702 memmove(text+start, text+start+i, textSize+1-start-i);
4705 for(; text[c] && text[c] != '\n'; c++);
4711 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4712 textSize += newLen - movedFuncIdLen;
4713 memcpy(text + movedFuncIdPos, methodName, newLen);
4720 if(methodAction == actionAddMethod && selected == classObject)
4722 Method method = this.method;
4724 if(!method.dataType)
4725 method.dataType = ProcessTypeString(method.dataTypeString, false);
4727 // ADDING METHOD HERE
4729 Type dataType = method.dataType;
4730 Type returnType = dataType.returnType;
4732 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4736 OutputType(f, returnType, false);
4739 if(dataType.thisClass && !dataType.classObjectType)
4741 if(dataType.thisClass.shortName)
4742 f.Printf(dataType.thisClass.shortName);
4744 f.Printf(dataType.thisClass.string);
4747 f.Printf(method.name);
4749 for(param = dataType.params.first; param; param = param.next)
4751 OutputType(f, param, true);
4756 f.Printf(" %c\n\n", OpenBracket);
4758 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4760 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4761 f.Printf(" return true;\n");
4762 else if(returnType && returnType.kind != voidType)
4763 f.Printf(" return 0;\n");
4768 if(returnType.kind != voidType)
4769 f.Printf("return ");
4771 char * name = ((Specifier)classDef.baseSpecs->first).name;
4772 Symbol _class = FindClass(name);
4773 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4775 for(param = dataType.params.first; param; param = param.next)
4777 if(param.prev) f.Printf(", ");
4778 if(param.kind != voidType)
4779 f.Printf(param.name);
4784 f.Printf(" %c", CloseBracket);
4788 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4800 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4801 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4805 codeModified = false;
4806 formModified = false;
4808 moveAttached = false;
4813 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4816 ClassFunction function = null;
4819 ObjectInfo object = this.selected;
4821 if(object && object == this.oClass)
4823 ClassDefinition classDef = object.oClass.classDefinition;
4825 if(classDef && classDef.definitions)
4827 for(def = classDef.definitions->first; def; def = def.next)
4829 if(def.type == functionClassDef && def.function.declarator)
4831 if(!strcmp(def.function.declarator.symbol.string, methodName))
4833 function = def.function;
4838 else if(def.type == defaultPropertiesClassDef)
4842 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4844 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4845 if(ident && !ident.next)
4847 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4851 propLoc = propDef.loc;
4854 ClassDefinition classDef = object.oClass.classDefinition;
4856 if(classDef.definitions)
4858 for(def = classDef.definitions->first; def; def = def.next)
4860 if(def.type == functionClassDef)
4862 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4864 function = def.function;
4883 Instantiation inst = object.instCode;
4885 // Check here to see if the method already exists, no need to call ModifyCode in that case
4886 if(inst && inst.members)
4888 MembersInit members;
4889 for(members = inst.members->first; members; members = members.next)
4891 switch(members.type)
4893 case dataMembersInit:
4895 if(members.dataMembers)
4898 for(member = members.dataMembers->first; member; member = member.next)
4900 Identifier ident = member.identifiers ? member.identifiers->first : null;
4901 if(ident && !ident.next)
4903 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4907 propLoc = member.loc;
4910 ClassDefinition classDef = object.oClass.classDefinition;
4912 if(classDef.definitions)
4914 for(def = classDef.definitions->first; def; def = def.next)
4916 if(def.type == functionClassDef)
4918 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
4920 function = def.function;
4929 // TODO: Fix memory leak
4930 function = ClassFunction
4932 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
4944 case methodMembersInit:
4946 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
4948 function = members.function;
4960 if(functionPtr) *functionPtr = function;
4964 void GoToMethod(char * methodName /*Method method*/)
4968 ObjectInfo object = selected;
4969 EditBoxStream f { editBox = editBox };
4970 ClassFunction function = null;
4971 bool atChar = false;
4975 Location propLoc = { {0,0,-1} };
4978 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
4979 if(function && function.body)
4982 f.Seek(function.body.loc.start.pos+1, current);
4992 f.Seek(-1, current);
4997 else if(!isspace(ch))
4999 f.Seek(-1, current);
5005 else if(propLoc.start.pos > -1)
5007 f.Seek(propLoc.start.pos, current);
5010 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5012 if(function || propLoc.start.pos > -1)
5014 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5015 editBox.CenterOnCursor();
5016 SetState(normal, false, 0);
5019 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5021 FreeClassFunction(function);
5027 void FindCompatibleMethods(Method method, OldList compatible)
5029 ClassDefinition classDef = this.oClass.classDefinition;
5030 if(classDef && classDef.definitions)
5033 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5036 Symbol classSym { };
5037 Symbol selectedClass;
5038 if(this.selected == this.oClass)
5039 selectedClass = classSym;
5041 selectedClass = FindClass(this.selected.instance._class.name);
5043 regClass.name = classDef._class.name;
5044 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5045 for(def = classDef.definitions->first; def; def = def.next)
5047 if(def.type == functionClassDef && def.function.declarator)
5049 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5051 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5054 Type type = def.function.declarator.symbol.type;
5055 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5057 compatible.Add(OldLink { data = def.function });
5063 if(this.oClass && this.oClass.instance)
5065 classSym.registered = regClass;
5066 //classSym.registered = this.oClass.oClass;
5068 for(_class = regClass.base; _class; _class = _class.base)
5071 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5073 // TODO: Understand why these functions popup in attach list
5074 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5076 if(!testMethod.dataType)
5077 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5079 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5080 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5081 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5083 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5084 // ClassFunction function { };
5085 FunctionDefinition function { };
5087 function.declarator = Declarator { };
5088 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5089 excludedSymbols.Add(function.declarator.symbol);
5091 compatible.Add(OldLink { data = function });
5102 void AddMethod(Method method)
5106 char methodName[1024];
5107 strcpy(methodName, method.name);
5108 if(!FindMethod(methodName, null, null))
5110 methodAction = actionAddMethod;
5111 this.method = method;
5115 GoToMethod(methodName);
5119 void DeleteMethod(ClassFunction function)
5123 methodAction = actionDeleteMethod;
5124 this.function = function;
5132 void AttachMethod(Method method, ClassFunction function)
5136 // If it's an instance we'll ask if we want to move it inside...
5137 if(!function.attached.count && function.body)
5139 // Find the function in the _class to check if it's a virtual function
5140 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5141 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5142 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5144 for(def = this.classDefinition.first; def; def = def.next)
5146 if(def.type == functionClassDef)
5148 if(def.function == function)
5153 if(!method || method.type != virtualMethod)
5156 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5157 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5159 moveAttached = true;
5164 methodAction = actionAttachMethod;
5165 this.method = method;
5166 this.function = function;
5173 void ReAttachMethod(Method method, ClassFunction function)
5177 // If it's an instance we'll ask if we want to move it inside...
5178 if(!function.attached.count && function.body)
5180 // Find the function in the _class to check if it's a virtual function
5181 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5182 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5183 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5185 for(def = this.classDefinition.first; def; def = def.next)
5187 if(def.type == functionClassDef)
5189 if(def.function == function)
5194 if(!method || method.type != virtualMethod)
5197 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5198 if(MessageBox { type = yesNo, master = parent, text = title,
5199 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5201 moveAttached = true;
5206 methodAction = actionReattachMethod;
5207 this.method = method;
5208 this.function = function;
5215 void DetachMethod(Method method, ClassFunction function, int type)
5223 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5224 master = sheet, text = $"Name detached method", background = formColor
5228 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5229 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5233 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5234 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5238 dialog, anchor = { left = 5, right = 5, top = 5 }
5240 sprintf(methodName, "%s_%s", selected.name, method.name);
5241 nameBox.contents = methodName;
5243 result = dialog.Modal() == ok;
5244 strcpy(methodName, nameBox.contents);
5249 // If the method is not attached, move it outside
5252 // Add this class to the methodName
5253 char name[1024] = "";
5255 if(this.selected != this.oClass && !method.dataType.thisClass)
5257 strcat(name, this.selected.instance._class.name);
5259 strcat(name, this.methodName);
5260 strcpy(this.methodName, name);
5262 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5264 strcat(name, method.dataType.thisClass.string);
5266 strcat(name, this.methodName);
5267 strcpy(this.methodName, name);
5270 this.moveAttached = true;
5273 this.methodAction = actionDetachMethod;
5274 this.method = method;
5275 this.function = function;
5282 void AddObject(Instance instance, ObjectInfo * object)
5286 //*object = _class.instances.Add(sizeof(ObjectInfo));
5287 *object = ObjectInfo { };
5288 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5289 (*object).oClass = oClass;
5290 (*object).instance = instance;
5295 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5297 // if(strcmp(name, this.oClass.instance.name))
5300 for(check = oClass.instances.first; check; check = check.next)
5301 if(!check.deleted && check.name && !strcmp(name, check.name))
5305 (*object).name = CopyString(name);
5310 toolBox.controlClass = null;
5314 //sheet.AddObject(*object, (*object).name, TypeData, true);
5319 void EnsureUpToDate()
5321 if(sheet && codeModified)
5325 void SelectObject(ObjectInfo object)
5328 oClass = object ? object.oClass : null;
5330 designer.SelectObject(object, object ? object.instance : null);
5333 void SelectObjectFromDesigner(ObjectInfo object)
5336 sheet.SelectObject(object);
5339 void EnumerateObjects(Sheet sheet)
5343 for(oClass = classes.first; oClass; oClass = oClass.next)
5349 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5350 for(object = oClass.instances.first; object; object = object.next)
5351 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5354 sheet.SelectObject(selected);
5359 designer.AddObject();
5362 void DeleteObject(ObjectInfo object)
5364 delete object.instance;
5365 object.deleted = true;
5366 object.modified = true;
5367 object.oClass.modified = true;
5369 if(selected == object)
5371 bool looped = false;
5372 ObjectInfo select = object;
5376 select = select.prev;
5380 select = object.oClass.instances.last;
5387 sheet.SelectObject(select ? select : oClass);
5390 if(!object.instCode && object.oClass != object)
5393 oClass.instances.Delete(object);
5396 if(sheet.codeEditor == this)
5397 sheet.DeleteObject(object);
5400 void RenameObject(ObjectInfo object, char * name)
5404 // Validate the name:
5405 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5406 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5409 for(c = 0; name[c]; c++)
5410 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5418 object.name = (name && name[0]) ? CopyString(name) : null;
5420 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5424 void DesignerModifiedObject()
5426 sheet.ListProperties(false);
5430 void ListSubMembers(Type member)
5434 for(subMember = member.members.first; subMember; subMember = subMember.next)
5438 DataRow row = membersList.AddString(subMember.name);
5439 row.icon = icons[typeData];
5443 ListSubMembers(subMember);
5448 void ListSubDataMembers(DataMember member, bool isPrivate)
5450 DataMember subMember;
5451 for(subMember = member.members.first; subMember; subMember = subMember.next)
5453 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5457 DataRow row = membersList.AddString(subMember.name);
5458 BitmapResource bitmap = null;
5459 if(!subMember.dataType)
5460 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5462 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5464 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5467 bitmap = { bitmapName };
5468 membersList.AddResource(bitmap);
5471 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5475 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5481 void ListClassMembers(Class whatClass, bool methodsOnly)
5484 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5485 bool isPrivate = false;
5487 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5489 Method method, methodIt;
5491 DataMember memberIt;
5493 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5495 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5496 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5498 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5500 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5502 DataRow row = membersList.FindString(method.name);
5505 row = membersList.AddString(method.name);
5507 if(!method.dataType)
5508 method.dataType = ProcessTypeString(method.dataTypeString, false);
5510 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5518 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5522 if(memberIt.isProperty)
5524 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5526 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5530 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5532 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5535 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5541 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5543 if(member.isProperty)
5545 Property prop = (Property) member;
5546 if(!membersList.FindString(prop.name))
5548 DataRow row = membersList.AddString(prop.name);
5549 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5552 else if(member.name && !membersList.FindString(member.name))
5554 DataRow row = membersList.AddString(member.name);
5556 BitmapResource bitmap = null;
5557 if(!member.dataType)
5558 member.dataType = ProcessTypeString(member.dataTypeString, false);
5560 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5562 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5565 bitmap = { bitmapName };
5566 membersList.AddResource(bitmap);
5569 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5572 ListSubDataMembers(member, member.memberAccess == privateAccess);
5576 if(_class.inheritanceAccess == privateAccess)
5579 if(_class.module != privateModule) break;
5584 void ListClassMembersMatch(Class whatClass, Type methodType)
5587 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5588 bool isPrivate = false;
5590 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5596 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5598 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5600 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5602 if(!method.dataType)
5603 method.dataType = ProcessTypeString(method.dataTypeString, false);
5605 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5607 DataRow row = membersList.FindString(method.name);
5610 row = membersList.AddString(method.name);
5611 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5617 if(_class.inheritanceAccess == privateAccess)
5620 if(_class.module != privateModule) break;
5625 void ListClassPropertiesAndVirtual(Class whatClass)
5628 bool isPrivate = false;
5629 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5635 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5637 if(method.type == virtualMethod)
5639 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5641 DataRow row = membersList.FindString(method.name);
5644 row = membersList.AddString(method.name);
5646 if(!method.dataType)
5647 method.dataType = ProcessTypeString(method.dataTypeString, false);
5649 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5655 for(member = _class.membersAndProperties.first; member; member = member.next)
5657 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5659 if(member.isProperty)
5661 Property prop = (Property)member;
5663 DataRow row = membersList.AddString(prop.name);
5664 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5667 else if(member.name)
5669 DataRow row = membersList.AddString(member.name);
5671 BitmapResource bitmap = null;
5672 if(!member.dataType)
5673 member.dataType = ProcessTypeString(member.dataTypeString, false);
5675 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5677 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5680 bitmap = { bitmapName };
5681 membersList.AddResource(bitmap);
5684 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5687 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5690 if(_class.inheritanceAccess == privateAccess)
5693 if(_class.module != privateModule) break;
5698 void ListMembers(Type type)
5700 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5704 if(type.kind == classType)
5707 ListClassMembers(type._class.registered, false);
5712 for(member = type.members.first; member; member = member.next)
5716 DataRow row = membersList.AddString(member.name);
5717 row.icon = icons[typeData];
5719 else if(member.kind == structType || member.kind == unionType)
5720 ListSubMembers(member);
5726 void ListModule(Module mainModule, int recurse, bool listClasses)
5729 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5730 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5731 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5732 for(module = mainModule.application.allModules.first; module; module = module.next)
5734 if(ModuleVisibility(mainModule, module))
5735 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5739 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5746 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5748 Class _class = link.data;
5749 if(_class.type != systemClass)
5751 DataRow row = membersList.AddString(_class.name);
5752 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5757 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5759 DefinedExpression definedExp = link.data;
5760 DataRow row = membersList.AddString(link /*definedExp*/.name);
5761 row.icon = icons[typeData];
5764 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5766 GlobalFunction function = link.data;
5767 DataRow row = membersList.AddString(link /*function*/.name);
5768 row.icon = icons[typeMethod];
5772 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5774 if(recurse != 2 && listClasses)
5776 if(!membersList.FindString(ns->name))
5778 DataRow row = membersList.AddString(ns->name);
5779 row.icon = icons[typeNameSpace];
5784 ListNameSpace(ns, 2, listClasses);
5788 void ListEnumValues(Class _class)
5790 List<Class> classes { };
5791 for(; _class && _class.type == enumClass; _class = _class.base)
5792 classes.Insert(null, _class);
5793 for(_class : classes)
5795 EnumClassData enumeration = (EnumClassData)_class.data;
5797 for(item = enumeration.values.first; item; item = item.next)
5799 DataRow row = membersList.AddString(item.name);
5800 row.icon = icons[typeEnumValue];
5806 bool ListEnumsModule(Module mainModule, Type dest)
5808 bool result = false;
5810 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5811 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5812 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5813 for(module = mainModule.application.allModules.first; module; module = module.next)
5815 if(ModuleVisibility(mainModule, module))
5816 result |= ListEnums(module.publicNameSpace, dest);
5821 void ListNameSpaceByString(Module mainModule, char * string)
5823 NameSpace * nameSpace;
5825 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5826 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5827 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5828 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5829 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5830 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5831 for(module = mainModule.application.allModules.first; module; module = module.next)
5833 if(ModuleVisibility(mainModule, module))
5835 nameSpace = FindNameSpace(module.publicNameSpace, string);
5836 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5841 bool ListEnums(NameSpace nameSpace, Type dest)
5844 bool result = false;
5846 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5848 Class _class = link.data;
5849 if(_class.type == enumClass && (dest.kind != classType || !dest._class || dest._class.registered != _class))
5851 OldList conversions { };
5853 type.kind = classType;
5854 type._class = FindClass(_class.name);
5855 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5857 ListEnumValues(_class);
5860 conversions.Free(null);
5864 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5866 result |= ListEnums(nameSpace, dest);
5871 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5875 for(c = 0; (ch = name[c]); c++)
5877 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5879 NameSpace * newSpace;
5880 char * spaceName = new char[c - start + 1];
5881 memcpy(spaceName, name + start, c - start);
5882 spaceName[c-start] = '\0';
5883 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5887 nameSpace = newSpace;
5896 return (NameSpace *)nameSpace;
5899 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5901 bool listedEnums = false;
5902 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5903 bool listClasses = true;
5905 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5907 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5908 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5909 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5911 if(exp.type == identifierExp)
5912 id = realIdentifier;
5914 if(id && id._class && !id._class.name)
5916 listClasses = false;
5919 else if(id && id._class && id._class.name)
5923 Class _class = id.classSym.registered;
5924 if(_class && _class.type == enumClass)
5926 ListEnumValues(_class);
5929 ListClassMembers(id.classSym.registered, true);
5934 else if(id && colons)
5936 ListNameSpaceByString(this.privateModule, id.string);
5941 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
5943 listedEnums = ListEnumsModule(this.privateModule, destType);
5946 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
5948 ListEnumValues(destType._class.registered);
5951 ListClassPropertiesAndVirtual(insideClass);
5955 else if(destType && destType.kind == enumType)
5959 for(value = destType.members.first; value; value = value.next)
5961 DataRow row = membersList.AddString(value.name);
5962 row.icon = icons[typeEnumValue];
5966 ListClassPropertiesAndVirtual(insideClass);
5970 else if(insideClass && !enumOnly)
5972 ListClassPropertiesAndVirtual(insideClass);
5975 if(listedEnums && string && string[0])
5977 DataRow row = membersList.FindSubString(string);
5979 listedEnums = false;
5982 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
5984 ListClassMembersMatch(GetThisClass(), exp.destType);
5986 else if(!insideClass && !enumOnly && !listedEnums)
5989 Symbol symbol = null;
5993 ListClassMembers(GetThisClass(), false);
5996 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
5998 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6000 // Don't list enum values?
6001 //if(symbol.type.kind != TypeEnum)
6002 DataRow row = membersList.FindString(symbol.string);
6005 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6007 row = membersList.AddString(symbol.string);
6008 if(symbol.type && symbol.type.kind == functionType)
6009 row.icon = icons[typeMethod];
6010 else if(symbol.type && symbol.type.kind == enumType)
6012 row.icon = icons[typeEnumValue];
6016 BitmapResource bitmap = null;
6017 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6019 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6022 bitmap = { bitmapName };
6023 membersList.AddResource(bitmap);
6026 row.icon = bitmap ? bitmap : icons[typeData];
6033 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6035 DataRow row = membersList.FindString(symbol.string);
6038 row = membersList.AddString(symbol.string);
6039 if(symbol.type.kind == functionType)
6040 row.icon = icons[typeMethod];
6041 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6043 row.icon = icons[typeClass];
6047 row.icon = icons[typeDataType];
6054 ListModule(this.privateModule, 1, listClasses);
6055 // TODO: Implement this with name space
6059 for(data = globalData.first; data; data = data.next)
6061 DataRow row = membersList.FindString(data.name);
6063 data.dataType = ProcessTypeString(data.dataTypeString, false);
6066 row = membersList.AddString(data.name);
6068 if(data.dataType && data.dataType.kind == TypeEnum)
6070 row.icon = icons[typeEnumValue];
6074 BitmapResource bitmap = null;
6075 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6077 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6080 bitmap = { bitmapName };
6081 membersList.AddResource(bitmap);
6084 row.icon = bitmap ? bitmap : icons[typeData];
6092 DataRow row = membersList.AddString("Min");
6093 row.icon = icons[typeMethod];
6095 row = membersList.AddString("Max");
6096 row.icon = icons[typeMethod];
6098 row = membersList.AddString("Abs");
6099 row.icon = icons[typeMethod];
6101 row = membersList.AddString("Sgn");
6102 row.icon = icons[typeMethod];
6108 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6110 EditBoxStream f { editBox = editBox };
6115 updatingCode = true;
6117 if(!method.dataType)
6118 method.dataType = ProcessTypeString(method.dataTypeString, false);
6120 DeleteJunkBefore(f, function.loc.start.pos, &position);
6121 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6123 // ADDING METHOD HERE
6125 Type dataType = method.dataType;
6126 Type returnType = dataType.returnType;
6128 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6134 if(extraIndent) f.Printf(" ");
6136 OutputType(f, returnType, false);
6140 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6142 if(dataType.thisClass.shortName)
6143 f.Printf(dataType.thisClass.shortName);
6145 f.Printf(dataType.thisClass.string);
6148 f.Printf(method.name);
6150 for(param = dataType.params.first; param; param = param.next)
6152 // Decided not to write void...
6153 if(param.kind != voidType)
6155 OutputType(f, param, true);
6161 if(extraIndent) f.Printf(" ");
6162 f.Printf(" %c\n", OpenBracket);
6164 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6170 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6171 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6173 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6175 if(extraIndent) f.Printf(" ");
6176 f.Printf(" return true;\n");
6178 else if(returnType && returnType.kind != voidType)
6180 if(extraIndent) f.Printf(" ");
6181 f.Printf(" return 0;\n");
6186 if(extraIndent) f.Printf(" ");
6188 if(returnType.kind != voidType)
6189 f.Printf("return ");
6190 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6191 for(param = dataType.params.first; param; param = param.next)
6193 if(param.prev) f.Printf(", ");
6194 if(param.kind != voidType)
6195 f.Printf(param.name);
6201 if(extraIndent) f.Printf(" ");
6202 f.Printf(" %c", CloseBracket);
6207 if(extraIndent) { x1 += 3; x2 += 3; }
6208 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6210 this.updatingCode = false;
6214 // Return false if we overrided a function and don't want to run params listing
6215 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6217 bool didOverride = false;
6218 EditLine line = editBox.line;
6219 char * text = line.text;
6220 int lineNum, charPos;
6221 Expression exp = null;
6224 //Identifier id = null;
6225 Expression memberExp = null;
6226 Identifier realIdentifier = null;
6228 if(!privateModule) return !didOverride;
6230 insideFunction = null;
6232 charPos = editBox.charPos + 1;
6233 if(!membersListShown)
6238 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6240 EditBoxStream f { editBox = editBox };
6242 updatingCode = true;
6243 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6247 if(!f.Seek(-1, current))
6250 if(!isspace(ch)) break;
6251 f.Seek(-1, current);
6253 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6255 lineNum = editBox.lineNumber + 1;
6256 charPos = editBox.charPos + 1;
6258 updatingCode = false;
6261 if(!membersListShown)
6263 memberExp = FindExpTree(ast, lineNum, charPos);
6264 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6269 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6271 EditBoxStream f { editBox = editBox };
6274 updatingCode = true;
6276 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6279 if(ch == '}' || ch == ',' || ch == ')')
6281 f.Seek(-1, current);
6289 if(!f.Seek(-1, current))
6292 if(!isspace(ch)) break;
6293 f.Seek(-1, current);
6297 f.Seek(-1, current);
6299 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6301 lineNum = editBox.lineNumber + 1;
6302 charPos = editBox.charPos + 1;
6304 updatingCode = false;
6307 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6312 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6313 lineNum = editBox.lineNumber + 1;
6314 charPos = editBox.charPos/* + 1*/;
6318 char tempString[1024];
6319 char * string = null;
6320 CodePosition idStart, idEnd;
6322 if(membersListShown)
6324 char * buffer = membersLine.text;
6326 bool firstChar = true;
6328 string = tempString;
6330 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6332 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6333 if(!isSpace) firstChar = false;
6335 string[len++] = buffer[c];
6339 else //if(realIdentifier)//if(id)
6342 char * buffer = id.string;
6344 bool firstChar = true;
6346 string = tempString;
6347 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6349 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6350 if(!isSpace) firstChar = false;
6352 string[len++] = buffer[c];
6358 EditLine editLine = editBox.line;
6359 bool firstChar = true;
6362 string = tempString;
6363 for(y = lineNum-1; y >= 0; y--)
6365 char * buffer = editLine.text;
6366 int lineCount = editLine.count;
6367 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6369 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6374 idEnd.charPos = x + 2;
6379 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6382 idEnd.charPos = x + 2;
6389 if(!isalnum(buffer[x]) && buffer[x] != '_')
6395 memmove(string+1, string, len++);
6396 string[0] = buffer[x];
6400 //if(done || firstChar)
6401 if(done || !firstChar)
6403 editLine = editLine.prev;
6406 if(!strcmp(string, "case"))
6412 else if(!strcmp(string, "return"))
6418 else if(!strcmp(string, "delete"))
6424 else if(!strcmp(string, "new"))
6430 else if(!strcmp(string, "renew"))
6438 idStart.charPos = x + 1;
6439 idStart.line = y + 1;
6442 if(!membersListShown)
6444 membersList.Clear();
6445 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6447 Type type = memberExp.member.exp.expType;
6448 if(pointer == 2 && type)
6450 if(type.kind == pointerType || type.kind == arrayType)
6459 ListSymbols(exp, enumOnly, string, realIdentifier);
6461 membersList.Sort(null, 1);
6466 // Virtual function override
6467 Identifier id = GetDeclId(insideFunction.declarator);
6468 char * string = id ? id.string : null;
6470 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6473 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6474 insideFunction = null;
6477 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6482 if(!didOverride) //insideFunction)
6484 rowCount = membersList.rowCount;
6487 DataRow row = string ? membersList.FindSubString(string) : null;
6488 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6490 char * newString = row.string;
6491 if(!membersListShown)
6493 membersLoc.start.line = idStart.line-1;
6494 membersLoc.start.charPos = idStart.charPos-1;
6495 //membersLoc.end = membersLoc.start;
6496 membersLoc.end.charPos = idEnd.charPos-1;
6497 membersLoc.end.line = idEnd.line-1;
6498 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6499 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6504 membersList.Destroy(0);
6505 membersListShown = false;
6508 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6510 line, membersLoc.start.line, membersLoc.start.charPos,
6511 line, membersLoc.end.line, membersLoc.end.charPos);
6512 editBox.PutS(newString);
6518 row = membersList.FindSubStringi(string);
6520 membersList.currentRow = row;
6521 membersList.currentRow.selected = false;
6524 membersList.currentRow = row;
6526 if(!membersListShown)
6530 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6531 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6532 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6533 editBox.GetCaretPosition(caret);
6534 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6536 membersList.master = this;
6538 caret.y += editBox.GetCaretSize();
6540 membersList.Create();
6543 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6544 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6545 Window parent = membersList.parent;
6547 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6549 y -= editBox.GetCaretSize() + membersList.size.h;
6550 membersAbove = true;
6553 membersAbove = false;
6555 membersList.position = { x, y };
6559 membersLoc.start.line = lineNum - 1;
6561 if(string && string[0])
6563 membersLoc.start.charPos = idStart.charPos-1;
6564 membersLoc.end = membersLoc.start;
6565 //membersLoc.end.charPos = id.loc.end.charPos-1;
6566 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6570 membersLoc.start.charPos = charPos;
6571 membersLoc.end = membersLoc.start;
6572 membersLoc.end.charPos = charPos;
6574 membersListShown = true;
6576 // Hack to keep caret shown
6577 editBox.GetCaretPosition(caret);
6578 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6581 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6587 SetCurrentContext(globalContext);
6590 return !didOverride;
6593 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6595 EditLine line = editBox.line;
6596 char * text = line.text;
6597 int lineNum, charPos;
6598 Expression exp = null;
6602 charPos = editBox.charPos + 1;
6605 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6607 EditBoxStream f { editBox = editBox };
6610 updatingCode = true;
6611 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6614 if(ch == '}' || ch == ',' || ch == ')')
6616 f.Seek(-1, current);
6624 if(!f.Seek(-1, current))
6627 if(!isspace(ch)) break;
6628 f.Seek(-1, current);
6632 f.Seek(-1, current);
6634 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6636 lineNum = editBox.lineNumber + 1;
6637 charPos = editBox.charPos + 1;
6639 updatingCode = false;
6642 charPos = Min(charPos, l1.count + 1);
6644 FindParamsTree(ast, lineNum, charPos);
6646 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6647 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6649 ::functionType = null;
6650 ::instanceType = null;
6653 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6654 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6658 Window parent = paramsList.parent;
6660 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6663 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6664 // ( Dummy exp: always ends up with same memory)
6666 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6667 editBox.GetCaretPosition(paramsPosition);
6668 this.paramsPosition.y += editBox.GetCaretSize();
6671 FreeType(this.functionType);
6672 FreeType(this.instanceType);
6674 this.functionType = ::functionType;
6675 this.instanceType = ::instanceType;
6677 if(this.functionType) this.functionType.refCount++;
6678 if(this.instanceType) this.instanceType.refCount++;
6680 this.paramsID = ::paramsID;
6681 functionExp = paramsInsideExp;
6683 paramsList.master = this;
6685 paramsList.Create();
6687 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6688 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6690 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6692 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6696 paramsAbove = false;
6697 if(x + paramsList.size.w > parent.clientSize.w)
6699 x = parent.clientSize.w - paramsList.size.w;
6703 paramsList.position = { x, y };
6705 // Hack to keep caret shown
6708 editBox.GetCaretPosition(caret);
6709 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6712 this.paramsShown = true;
6714 else if((!::functionType && !::instanceType) || reposition)
6716 paramsList.Destroy(0);
6717 paramsShown = false;
6719 FreeType(this.functionType);
6720 FreeType(this.instanceType);
6721 this.functionType = null;
6722 this.instanceType = null;
6726 SetCurrentContext(globalContext);
6734 designer.visible = true;
6735 designer.Activate();
6741 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6743 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };