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 ");
233 if(type._class && !strcmp(type._class.string, "class"))
235 switch(type.classObjectType)
238 f.Printf("any_object");
241 f.Printf("typed_object");
248 // ADD CODE TO DECIDE WHETHER TO OUTPUT FULLY QUAlIFIED OR NOT:
249 f.Printf(type._class.shortName ? type._class.shortName : type._class.string);
259 OutputType(f, type.type, false);
262 OutputType(f, type.type, false);
281 if(type.kind == arrayType)
284 f.Printf("%d", type.arraySize);
290 void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
296 f.Seek(pos - *position, current);
298 // Try to delete spaces and \n before...
304 /*else if(ch == '\n')
306 // Look for // comments on the line before
307 EditBox editBox = f.editBox;
308 EditLine line = editBox.line;
315 for(c = 0; text[c]; c++)
324 if(text[c] == '/' && last == '/')
336 f.DeleteBytes(before);
341 void GetLocText(EditBox editBox, File f, int position, Location loc, char ** text, int * size, int pad, int linePad)
346 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
348 // Cut & Paste function
354 f.Seek(loc.start.pos - position, current);
356 x1 = editBox.charPos;
357 y1 = editBox.lineNumber;
358 f.Seek(loc.end.pos - loc.start.pos, current);
360 x2 = editBox.charPos;
361 y2 = editBox.lineNumber;
362 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
364 *size = editBox.SelSize();
365 *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
366 editBox.GetSel(*text, false);
369 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
370 f.Printf(""); // Make the stream point to where the editbox is
373 void Code_FixProperty(Property prop, Instance object)
375 Designer::FixProperty(prop, object);
378 bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
381 if(prop.dataTypeString && (!prop.IsSet || prop.IsSet(selected.instance)))
383 Class dataType = prop.dataTypeClass;
386 dataType = prop.dataTypeClass = eSystem_FindClass(test._class.module, prop.dataTypeString);
388 if(dataType && dataType._vTbl && dataType.type == structClass)
390 void * dataForm = new0 byte[dataType.structSize];
391 void * dataTest = new0 byte[dataType.structSize];
393 ((void (*)(void *, void *))(void *)prop.Get)(selected.instance, dataForm);
394 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
396 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
398 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
404 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
406 void * dataForm, * dataTest;
408 dataForm = ((void *(*)(void *))(void *)prop.Get)(selected.instance);
409 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
411 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
413 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
417 else if(dataType && dataType._vTbl)
419 DataValue dataForm, dataTest;
421 GetProperty(prop, selected.instance, &dataForm);
422 GetProperty(prop, test, &dataTest);
424 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
426 SetProperty(prop, test, dataForm);
428 // In case setting on test unset on real instance (e.g. isDefault)
429 if(strcmp(prop.name, "name"))
431 GetProperty(prop, selected.instance, &dataTest);
432 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
433 SetProperty(prop, selected.instance, dataForm);
442 bool Code_IsPropertyDisabled(ObjectInfo selected, char * name)
444 bool disabled = false;
445 if(selected.oClass == selected)
448 if(selected.classDefinition)
450 for(def = selected.classDefinition.definitions->first; def; def = def.next)
452 if(def.type == defaultPropertiesClassDef)
455 for(prop = def.defProperties->first; prop; prop = prop.next)
457 if(prop.identifiers && prop.identifiers->first)
459 Identifier id = prop.identifiers->first;
460 if(prop.variable && !strcmp(id.string, name))
472 else if(selected.instCode)
475 if(selected.instCode.members)
477 for(members = selected.instCode.members->first; members; members = members.next)
479 if(members.type == dataMembersInit && members.dataMembers)
482 for(prop = members.dataMembers->first; prop; prop = prop.next)
484 if(prop.identifiers && prop.identifiers->first)
486 Identifier id = prop.identifiers->first;
487 if(prop.variable && !strcmp(id.string, name))
502 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
507 method.dataType = ProcessTypeString(method.dataTypeString, false);
508 if(!method.dataType.thisClass && !isForm)
511 method.dataType.thisClass = selectedClass;
513 //result = MatchTypes(method.dataType, type, null, regClass, regClass, false);
514 result = MatchTypes(type, method.dataType, null, regClass, regClass, false, true, true, false);
516 method.dataType.thisClass = null;
520 bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo object)
522 bool confirmation = true;
523 Statement body = function.body;
524 // Check if it contains any code
525 if((!body.compound.declarations || !body.compound.declarations->count) && (!body.compound.statements || body.compound.statements->count <= 1))
527 Class moduleClass = eSystem_FindClass(object.instance._class.module, "Module");
528 Statement stmt = body.compound.statements ? body.compound.statements->first : null;
529 Type dataType = method.dataType;
530 Type returnType = dataType.returnType;
531 Expression exp = null;
534 method.dataType = ProcessTypeString(method.dataTypeString, false);
536 confirmation = false;
538 // Check if default function should be calling base class:
539 if(object.instance._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
541 if(returnType.kind != voidType)
543 if(!stmt || stmt.type != returnStmt || !stmt.expressions || stmt.expressions->count != 1)
547 exp = stmt.expressions->first;
548 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
550 if( (exp.type != identifierExp || strcmp(exp.identifier.string, "true")) &&
551 (exp.type != constantExp || strcmp(exp.constant, "1")))
556 if(exp.type != constantExp || strcmp(exp.constant, "0"))
571 if(returnType.kind != voidType)
573 if(stmt.type == returnStmt && stmt.expressions && stmt.expressions->count == 1)
574 exp = stmt.expressions->first;
576 else if(stmt.type == expressionStmt && stmt.expressions && stmt.expressions->count == 1)
577 exp = stmt.expressions->first;
580 if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
584 Identifier id = exp.call.exp.identifier;
585 Class base = object.instance._class;
586 if(!id._class || (id._class.name && !strcmp(id._class.name, base.name)) || strcmp(id.string, method.name))
590 Expression arg = exp.call.arguments ? exp.call.arguments->first : null;
591 if(!arg || arg.type != identifierExp || strcmp("this", arg.identifier.string))
597 for(param = dataType.params.first; param; param = param.next)
599 if(!arg || arg.type != identifierExp || strcmp(param.name, arg.identifier.string))
604 arg = arg ?arg.next : null;
611 return !confirmation;
614 class CodeEditor : Window
616 background = marginColor;
617 borderStyle = sizableDeep;
622 isActiveClient = true;
623 anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
626 // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
627 // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
629 SheetType sheetSelected;
634 Context globalContext { };
635 OldList excludedSymbols { offset = (uint)&((Symbol)0).left };
648 MethodAction methodAction;
650 ClassFunction function;
652 char methodName[1024];
657 bool membersListShown;
660 EditLine membersLine;
662 Type functionType, instanceType;
666 Point paramsPosition;
667 Expression functionExp;
670 BitmapResource icons[CodeObjectType];
672 FontResource boldFont { $"Tahoma", 8.25f, bold = true, window = this };
673 FontResource normalFont { $"Tahoma", 8.25f, window = this };
675 Module privateModule;
676 NameSpace globalData;
679 OpenedFileInfo openedFileInfo;
681 FontResource font { codeFont.faceName, codeFont.size };
682 saveDialog = codeEditorFileDialog;
684 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
688 property bool parsing { get { return !noParsing && !ide.noParsing; } };
690 void ProcessCaretMove(EditBox editBox, int line, int charPos)
693 ObjectInfo classItem;
695 // OnActivateClient is called after OnActivate
698 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
701 if(sheet.codeEditor != this) return;
705 for(classItem = classes.first; classItem; classItem = classItem.next)
707 ClassDefinition classDef = classItem.classDefinition;
708 if(classDef && classDef.loc.Inside(line, charPos))
715 for(object = classItem.instances.first; object; object = object.next)
719 if(object.instCode.loc.Inside(line, charPos))
724 sheet.SelectObject(object);
726 sheet.SelectObject(classItem);
731 //sheet.SelectObject(null);
735 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
739 expectingMove = false;
745 if(line-1 != membersLoc.start.line)
749 char * buffer = membersLine.text;
752 if(charPos - 1 < membersLoc.start.charPos)
754 else if(charPos - 1 > membersLoc.end.charPos)
756 char * buffer = membersLine.text;
757 //if(membersList.currentRow)
761 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
762 if(buffer[c] != ' ' && buffer[c] != '\t')
764 if(c < charPos && buffer[c])
771 membersList.Destroy(0);
772 membersListShown = false;
776 bool back = codeModified;
777 codeModified = false;
779 InvokeParameters(false, false, false);
780 /*if(membersListShown)
781 InvokeAutoComplete(false, 0, true);*/
788 watch(modifiedDocument)
790 ProjectView projectView = ide.projectView;
793 ProjectNode node = projectView.GetNodeFromWindow(this, null, false);
796 node.modified = modifiedDocument;
797 projectView.Update(null);
805 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
806 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
807 tabKey = true, smartHome = true;
808 tabSelection = true, /*maxLineSize = 65536, */parent = this, hasHorzScroll = true, hasVertScroll = true;
809 selectionColor = selectionColor, selectionText = selectionText,
810 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
811 font = font, borderStyle = none;
812 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
814 bool OnMouseOver(int x, int y, Modifiers mods)
816 CodeEditor editor = (CodeEditor)master;
817 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
822 void NotifyCaretMove(EditBox editBox, int line, int charPos)
824 // Update Line Numbers
826 int oldLine = lastLine;
827 display.FontExtent(font.font, " ", 1, null, &spaceH);
829 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
833 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
838 if(ide.activeClient == this)
839 ProcessCaretMove(editBox, line, charPos);
841 openedFileInfo.CaretMove(line, charPos);
844 void NotifyOvrToggle(EditBox editBox, bool overwrite)
846 ide.ovr.color = overwrite ? black : Color { 128, 128, 128 };
849 void NotifyUpdate(EditBox editBox)
856 designer.modifiedDocument = true;
859 modifiedDocument = true;
862 bool NotifyUnsetModified(EditBox editBox)
864 modifiedDocument = false;
868 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
870 if(!loadingFile && after.y != before.y)
872 ProjectView projectView = ide.projectView;
873 if(projectView && fileName)
876 // HOW WE MIGHT WANT TO DO IT:
877 char * text = before.line.text;
878 for(c = before.x-1; c>= 0; c--)
879 if(!isspace(text[c]))
881 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
883 // HOW VISUAL STUDIO DOES IT:
885 char * text = after.line.text;
886 for(c = after.line.count-1; c>= 0; c--)
887 if(!isspace(text[c]))
889 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
892 Update({ 0, 0, editBox.position.x, clientSize.h });
899 for(oClass = classes.first; oClass; oClass = oClass.next)
902 for(object = oClass.instances.first; object; object = object.next)
906 object.instCode.loc.start.AdjustAdd(before, after);
907 object.instCode.loc.end.AdjustAdd(before, after);
912 oClass.classDefinition.loc.start.AdjustAdd(before, after);
913 oClass.classDefinition.loc.end.AdjustAdd(before, after);
919 expectingMove = true;
923 if(before.y != after.y)
927 char * buffer = membersLine.text;
929 bool firstChar = true;
930 bool addedChar = false;
936 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
938 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
940 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
941 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
950 membersLoc.start.charPos++;
955 string[len++] = buffer[c];
959 row = membersList.currentRow;
960 if(row && row.selected)
964 membersLoc.start.charPos--;
972 row = membersList.FindSubString(string);
974 membersList.currentRow = row;
977 row = membersList.FindSubStringi(string);
979 membersList.currentRow = row;
980 membersList.currentRow.selected = false;
983 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
987 row = membersList.currentRow;
990 // Accept current string if hiding typing char
991 if(hide && row && row.selected)
993 char * string = row.string;
994 int len = strlen(string);
995 membersLoc.end.charPos -= after.x - before.x;
996 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
997 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
998 membersLine, membersLoc.end.line, membersLoc.end.charPos);
999 editBox.PutS(string);
1000 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
1002 after.x += membersLoc.start.charPos + len - before.x;
1003 before.x = membersLoc.start.charPos + len;
1008 membersList.Destroy(0);
1009 membersListShown = false;
1012 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
1014 EditLine line = editBox.line;
1015 char * text = line.text;
1016 char ch = text[after.x-1];
1017 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1021 // Can we call invoke auto complete here instead?
1031 // Force caret update already...
1032 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1033 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1035 editBox.GetCaretPosition(&caret);
1039 // Go back in the buffer until no space before
1041 codeModified = true;
1045 EditBoxStream f { editBox = editBox };
1049 if(text[after.x-1] == '>')
1055 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1059 if(!f.Seek(-1, current))
1062 if(!isspace(ch)) break;
1063 f.Seek(-1, current);
1065 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1067 line = editBox.lineNumber + 1;
1068 charPos = editBox.charPos + 1;
1072 exp = FindExpTree(ast, line, charPos);
1076 Type type = exp.expType;
1078 if(type && text[after.x-1] != '.')
1080 if(type.kind == TypePointer || type.kind == TypeArray)
1086 membersList.Clear();
1089 if(membersList.rowCount)
1091 membersList.Sort(null, 1);
1092 membersList.master = this;
1094 caret.y += editBox.GetCaretSize();
1097 membersList.Create();
1100 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1101 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1102 Window parent = membersList.parent;
1104 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1106 y -= editBox.GetCaretSize() + membersList.GetHeight();
1107 membersAbove = true;
1110 membersAbove = false;
1112 membersList.position = { x, y };
1116 membersLoc.start.line = line - 1;
1117 membersLoc.start.charPos = oldCharPos;
1118 membersLoc.end = membersLoc.start;
1119 membersListShown = true;
1124 SetCurrentContext(globalContext);
1126 codeModified = true;
1127 skipModified = true;
1128 if(text[after.x-1] == ':')
1129 InvokeAutoComplete(false, 0, false);
1130 else if(text[after.x-1] == '.')
1131 InvokeAutoComplete(false, 1, false);
1132 else if(text[after.x-1] == '>')
1133 InvokeAutoComplete(false, 2, false);
1134 skipModified = false;
1136 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1138 codeModified = true;
1139 skipModified = true;
1141 if(InvokeAutoComplete(true, 0, false))
1143 if(ch == '(' || ch == OpenBracket)
1144 InvokeParameters(true, true, false);
1146 InvokeParameters(this.functionType ? false : true, false, false);
1149 // InvokeAutoComplete(true, 0, false);
1150 skipModified = false;
1152 else if(ch == ')' || ch == '}' || ch == ';')
1154 codeModified = true;
1155 skipModified = true;
1157 InvokeParameters(false, true, false);
1158 skipModified = false;
1162 bool back = codeModified;
1163 codeModified = false;
1165 InvokeParameters(false, false, true);
1166 if(membersListShown)
1167 InvokeAutoComplete(false, 0, true);
1168 codeModified = back;
1173 bool back = codeModified;
1174 codeModified = false;
1177 InvokeParameters(false, false, true);
1178 /*if(membersListShown)
1179 InvokeAutoComplete(false, 0, true);*/
1181 codeModified = back;
1188 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1190 if(!loadingFile && after.y != before.y)
1192 ProjectView projectView = ide.projectView;
1193 if(projectView && fileName)
1194 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1195 Update({ 0, 0, editBox.position.x, clientSize.h });
1202 for(oClass = classes.first; oClass; oClass = oClass.next)
1206 for(object = oClass.instances.first; object; object = object.next)
1210 loc = &object.instCode.loc;
1212 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1213 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1215 object.instCode = null;
1219 loc->start.AdjustDelete(before, after);
1220 loc->end.AdjustDelete(before, after);
1224 if(oClass.classDefinition)
1226 loc = &oClass.classDefinition.loc;
1227 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1228 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1230 oClass.classDefinition = null;
1234 loc->start.AdjustDelete(before, after);
1235 loc->end.AdjustDelete(before, after);
1240 if(membersListShown)
1243 if(pasteOperation || before.y != after.y)
1247 char * buffer = membersLine.text;
1249 bool firstChar = true;
1253 if(before.x >= membersLoc.start.charPos)
1255 for(c = membersLoc.start.charPos; c<before.x && len < sizeof(string)-1; c++)
1257 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1258 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1263 if(!isSpace) firstChar = false;
1266 string[len++] = buffer[c];
1271 // If deleting spaces before...
1272 for(c = before.x; c<membersLoc.start.charPos; c++)
1274 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1282 membersLoc.start.charPos = before.x;
1285 if(membersLoc.end.charPos >= after.x)
1287 for(c = after.x; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1289 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1290 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1295 if(!isSpace) firstChar = false;
1298 string[len++] = buffer[c];
1306 membersLoc.end.charPos -= after.x - before.x;
1310 row = membersList.FindSubString(string);
1313 row = membersList.FindSubStringi(string);
1315 membersList.currentRow = row;
1316 membersList.currentRow.selected = false;
1319 membersList.currentRow = row;
1321 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1326 membersList.Destroy(0);
1327 membersListShown = false;
1333 InvokeParameters(false, false);
1341 bool NotifyDropped(EditBox editBox, int x, int y)
1343 char * controlClass = toolBox.controlClass;
1344 if(controlClass && controlClass[0])
1348 ObjectInfo classObject;
1350 //editBox.NotifyCaretMove(this, editBox, y, x);
1351 editBox.GoToLineNum(y);
1352 editBox.GoToPosition(editBox.line, y, x);
1354 classObject = selected ? selected.oClass : null;
1356 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1357 selected = classObject.instances.last;
1360 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1363 AddObject(control, &object);
1365 designer.CreateObject(control, object, false, classObject.instance);
1366 // designer.PostCreateObject(control, object, false, classObject.instance);
1367 designer.DroppedObject(control, object, false, classObject.instance);
1369 sheet.AddObject(object, object.name, typeData /* className*/, true);
1372 //codeModified = true;
1379 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1381 if(key == Key { space, ctrl = true })
1383 membersList.Destroy(0);
1384 membersListShown = false;
1385 InvokeAutoComplete(false, 0, false);
1388 else if(key == Key { space, ctrl = true, shift = true })
1389 InvokeParameters(false, true, false);
1390 else if(key == escape)
1391 ide.RepositionWindows(true);
1392 else if(key == ctrlF7)
1396 ProjectNode node = ide.projectView.GetNodeFromWindow(this, null, false);
1398 node = ide.projectView.GetNodeFromWindow(this, null, true);
1402 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1403 $"It can't be compiled.");
1404 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1413 bool OnKeyDown(Key key, unichar ch)
1415 CodeEditor editor = (CodeEditor)master;
1416 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1418 if(editor.membersListShown)
1420 editor.membersList.Destroy(0);
1421 editor.membersListShown = false;
1424 if(editor.paramsShown)
1426 editor.paramsList.Destroy(0);
1427 editor.paramsShown = false;
1428 FreeType(editor.functionType);
1429 FreeType(editor.instanceType);
1431 editor.functionType = null;
1432 editor.instanceType = null;
1433 editor.paramsID = -1;
1437 return EditBox::OnKeyDown(key, ch);
1440 void OnVScroll(ScrollBarAction action, int position, Key key)
1442 if(anchor.left.distance)
1444 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1447 EditBox::OnVScroll(action, position, key);
1449 CodeEditor ce = (CodeEditor)parent;
1450 if(ce.openedFileInfo)
1451 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1455 void OnHScroll(ScrollBarAction action, int position, Key key)
1457 EditBox::OnHScroll(action, position, key);
1459 CodeEditor ce = (CodeEditor)parent;
1460 if(ce.openedFileInfo)
1461 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1468 fullRowSelect = false,
1471 borderStyle = bevel;
1472 // size = { 200, 400 };
1474 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1476 DataRow row = listBox.currentRow;
1479 char * string = row.string;
1481 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1483 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1484 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1485 editBox.PutS(string);
1488 membersListShown = false;
1493 bool OnKeyDown(Key key, unichar ch)
1495 CodeEditor editor = (CodeEditor) master;
1496 if(key == escape || key == leftAlt || key == rightAlt ||
1497 (key.ctrl && key.code != left && key.code != right &&
1498 key.code != leftShift && key.code != rightShift && key.code != space))
1500 if(editor.paramsShown)
1501 editor.paramsList.Destroy(0);
1502 if(editor.membersListShown)
1503 editor.membersList.Destroy(0);
1505 editor.paramsShown = false;
1506 FreeType(editor.functionType);
1507 FreeType(editor.instanceType);
1509 editor.functionType = null;
1510 editor.instanceType = null;
1511 editor.paramsID = -1;
1513 editor.membersListShown = false;
1517 return editor.editBox.OnKeyDown(key, ch);
1521 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1523 CodeEditor editor = (CodeEditor)master;
1527 editor.membersListShown = false;
1529 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1532 bool OnKeyHit(Key key, unichar ch)
1534 CodeEditor editor = (CodeEditor) master;
1538 case enter: case tab:
1540 DataRow row = currentRow;
1541 if(row && row.selected)
1543 char * string = row.string;
1545 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1546 editor.editBox.Delete(
1547 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1548 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1549 editor.editBox.PutS(string);
1552 editor.membersListShown = false;
1555 editor.editBox.OnKeyHit(key, ch);
1565 return ListBox::OnKeyHit(key, ch);
1571 // If before . or after
1572 //listBox.Destroy(true);
1573 result = editor.editBox.OnKeyHit(key, ch);
1588 clickThrough = true,
1590 borderStyle = contour,
1592 background = { 255,255,225 },
1594 OnKeyDown = membersList.OnKeyDown;
1596 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1598 CodeEditor editor = (CodeEditor)master;
1602 editor.membersListShown = false;
1604 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1607 bool OnKeyHit(Key key, unichar ch)
1609 CodeEditor editor = (CodeEditor)master;
1611 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1614 bool result = true; editor.editBox.OnKeyHit(key, ch);
1615 return (!created) ? false : result;
1622 void OnRedraw(Surface surface)
1624 CodeEditor editor = (CodeEditor) master;
1625 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1627 Type methodType = null;
1631 int functionW, nameW = 0;
1633 int spaceW, spaceH, commaW, commaWB, parW;
1635 int maxW = 0, lineW = 0;
1641 Font font = editor.normalFont.font;
1642 Font boldFont = editor.boldFont.font;
1643 Display display = this.display;
1645 if(!type) { return; };
1647 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1649 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1650 display.FontExtent(font, ", ", 2, &commaW, null);
1651 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1652 display.FontExtent(font, ")", 1, &parW, null);
1655 if(editor.functionType)
1657 PrintType(type.returnType, string, true, true);
1658 display.FontExtent(font, string, strlen(string), &functionW, null);
1660 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1661 totalW = nameW + functionW + 2 * parW;
1665 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1666 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1667 if(instanceName && type.kind != functionType)
1668 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1669 totalW = functionW + nameW;
1670 surface.TextFont(boldFont);
1673 surface.WriteText(x, y, string, strlen(string));
1674 x += functionW + spaceW;
1676 if(editor.functionType)
1679 surface.WriteText(x, y, type.name, strlen(type.name));
1681 surface.WriteText(x, y, "(", 1);
1684 if(methodType && !methodType.staticMethod && methodType.methodClass)
1688 if(id == editor.paramsID)
1689 surface.TextFont(boldFont);
1691 if(methodType.methodClass)
1692 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1696 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1697 width += ((id == editor.paramsID) ? commaWB : commaW);
1702 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1707 x = 2 + nameW + spaceW + functionW + parW;
1711 if(methodType.methodClass)
1712 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1715 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1717 surface.WriteText(x, y, ",", 1);
1718 x += ((id == editor.paramsID) ? commaWB : commaW);
1726 if(id == editor.paramsID)
1727 surface.TextFont(font);
1731 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1733 for(param = type.params.first; param; param = param.next)
1735 char paramString[1024];
1738 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1739 surface.TextFont(boldFont);
1742 PrintType(param, paramString, true, true);
1743 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1745 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1750 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1755 x = 2 + nameW + spaceW + functionW + parW;
1759 surface.WriteText(x, y, paramString, strlen(paramString));
1763 surface.WriteText(x, y, ",", 1);
1764 x += ((id == editor.paramsID) ? commaWB : commaW);
1772 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1773 surface.TextFont(font);
1778 surface.WriteText(x, y, ")", 1);
1780 else if(instanceName && type.kind != functionType)
1782 surface.WriteText(x, y, instanceName, strlen(instanceName));
1786 bool OnResizing(int * w, int * h)
1788 CodeEditor editor = (CodeEditor) master;
1789 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1791 Type methodType = null;
1795 int functionW = 0, nameW = 0;
1797 int spaceW, spaceH, commaW, commaWB, parW;
1799 int maxW = 0, lineW = 0;
1804 Font font = editor.normalFont.font;
1805 Font boldFont = editor.boldFont.font;
1806 Display display = this.display;
1808 if(type.kind == TypeKind::methodType)
1811 ProcessMethodType(type.method);
1812 type = type.method.dataType;
1815 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1816 display.FontExtent(font, ", ", 2, &commaW, null);
1817 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1818 display.FontExtent(font, ")", 1, &parW, null);
1821 if(editor.functionType && type)
1823 PrintType(type.returnType, string, true, true);
1824 display.FontExtent(font, string, strlen(string), &functionW, null);
1826 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1827 totalW = nameW + spaceW + functionW + 2 * parW;
1831 PrintType(type, string, false, true); // /*true);
1832 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1833 if(instanceName && type.kind != functionType)
1834 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1835 totalW = functionW + nameW + spaceW;
1838 if(editor.functionType)
1844 if(methodType.methodClass)
1845 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1846 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1847 width += ((id == editor.paramsID) ? commaWB : commaW);
1852 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1865 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1867 for(param = type.params.first; param; param = param.next)
1869 char paramString[1024];
1873 PrintType(param, paramString, true, true);
1874 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1876 width += ((id == editor.paramsID) ? commaWB : commaW);
1881 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1898 *w = realW + totalW + 4;
1904 Menu fileMenu { menu, $"File", f }; // MenuPlacement?
1905 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1906 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1908 Menu debugMenu { menu, $"Debug", d }; // MenuPlacement?
1909 MenuItem debugRunToCursor
1911 debugMenu, $"Run To Cursor", c, Key { f10, ctrl = true };
1912 bool NotifySelect(MenuItem selection, Modifiers mods)
1914 ProjectView projectView = ide.projectView;
1915 if(!projectView.buildInProgress)
1917 int line = editBox.lineNumber + 1;
1920 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1921 ProjectConfig config = projectView.project.config;
1922 int bitDepth = ide.workspace.bitDepth;
1923 ide.debugger.RunToCursor(compiler, config, bitDepth, fileName, line, false);
1930 MenuItem debugSkipRunToCursor
1932 debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true };
1933 bool NotifySelect(MenuItem selection, Modifiers mods)
1935 ProjectView projectView = ide.projectView;
1936 int line = editBox.lineNumber + 1;
1939 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1940 ProjectConfig config = projectView.project.config;
1941 int bitDepth = ide.workspace.bitDepth;
1942 ide.debugger.RunToCursor(compiler, config, bitDepth, fileName, line, true);
1948 MenuDivider { debugMenu };
1949 MenuItem debugToggleBreakpoint
1951 debugMenu, $"Toggle Breakpoint", t, f9;
1952 bool NotifySelect(MenuItem selection, Modifiers mods)
1954 ProjectView projectView = ide.projectView;
1955 if(projectView && fileName)
1957 int line = editBox.lineNumber + 1;
1958 char name[MAX_LOCATION];
1960 // TOFIX: This only looks at the filename...
1961 GetLastDirectory(fileName, name);
1962 if(ide && ide.workspace)
1964 for(p : ide.workspace.projects)
1966 if(p.topNode.Find(name, false))
1974 for(p : ide.workspace.projects)
1976 if(IsPathInsideOf(fileName, p.topNode.path))
1984 ide.debugger.ToggleBreakpoint(fileName, line, prj);
1994 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1998 designer.parent = parent;
2001 toolBox = ((IDEWorkSpace)master).toolBox;
2003 // Debugger bug here: value of toolBox appears as 0
2005 sheet = ((IDEWorkSpace)master).sheet;
2010 bool OnClose(bool parentClosing)
2014 if(ide.workspace && fileName)
2015 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2016 if(inUseDebug && !debugClosing)
2018 debugClosing = true;
2020 if(CloseConfirmation(false))
2023 OnFileModified({ modified = true }, null);
2025 debugClosing = false;
2028 if(designer && !designer.closing)
2030 if(designer.visible)
2037 //Window formEditor = designer;
2038 //formEditor.Destroy(0);
2041 ide.AdjustFileMenus();
2046 void OnDestroy(void)
2048 ObjectInfo oClass, next;
2049 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2051 FreeType(this.functionType);
2052 FreeType(this.instanceType);
2057 designer.codeEditor = null;
2058 designer.Destroy(0);
2062 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2064 ObjectInfo object, next;
2066 for(object = oClass.instances.first; object; object = next)
2071 Designer::DestroyObject(object.instance);
2072 delete object.instance;
2074 sheet.DeleteObject(object);
2076 oClass.instances.Delete(object);
2080 Designer::DestroyObject(oClass.instance);
2081 delete oClass.instance;
2083 sheet.DeleteObject(oClass);
2085 classes.Delete(oClass);
2088 if(windowClass && windowClass.data)
2089 UnapplySkin(windowClass);
2093 if(sheet.codeEditor == this)
2095 sheet.codeEditor = null;
2096 toolBox.codeEditor = null;
2102 ProjectView projectView = ide.projectView;
2105 ProjectNode node = projectView.GetNodeFromWindow(this, null, false);
2106 if(node && node.modified)
2108 node.modified = false;
2109 projectView.Update(null);
2115 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2117 // 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
2119 if(directActivation)
2120 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2122 if(active && directActivation)
2124 AdjustDebugMenus(ide.areDebugMenusUnavailable, ide.isBreakpointTogglingUnavailable, ide.isDebuggerExecuting);
2126 openedFileInfo.Activate();
2130 Location * loc = null;
2131 UpdateFormCode(); // To ensure update when modifying properties...
2133 // Got to the right spot in code so we don't lose our form selection...
2136 if(selected.instCode)
2137 loc = &selected.instCode.loc;
2138 else if(selected.classDefinition)
2139 loc = &selected.classDefinition.loc;
2141 line = editBox.lineNumber + 1;
2142 charPos = editBox.charPos + 1;
2147 if(selected && !loc->Inside(line, charPos))
2149 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2150 line = editBox.lineNumber + 1;
2151 charPos = editBox.charPos + 1;
2153 else if(selected && selected.classDefinition)
2156 for(object = selected.instances.first; object; object = object.next)
2160 if(object.instCode.loc.Inside(line, charPos))
2166 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2167 line = editBox.lineNumber + 1;
2168 charPos = editBox.charPos + 1;
2173 ProcessCaretMove(editBox, line, charPos);
2179 bool OnSaveFile(char * fileName)
2186 f = FileOpen(fileName, write);
2189 if(!ide.projectView)
2190 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2194 this.fileName = fileName; // Put this here because the form designer will check for it...
2195 designer.fileName = fileName;
2196 designer.modifiedDocument = false;
2198 editBox.Save(f, false);
2199 modifiedDocument = false;
2207 bool OnFileModified(FileChange fileChange, char * param)
2209 bool reload = false;
2210 if(visible == false && inUseDebug == true)
2216 sprintf(message, $"The document %s was modified by another application.\n"
2217 "Would you like to reload it and lose your changes?", fileName);
2218 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2219 contents = message }.Modal() == yes)
2225 File f = FileOpen(fileName, read);
2228 int lineNumber, charPos, len;
2232 updatingCode = true;
2233 lineNumber = editBox.lineNumber;
2234 charPos = editBox.charPos;
2235 scroll = editBox.scroll;
2238 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2239 len = strlen(editBox.line.text);
2240 editBox.GoToLineNum(lineNumber);
2241 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2242 editBox.scroll = scroll;
2243 updatingCode = false;
2244 loadingFile = false;
2246 codeModified = true;
2250 designer.modifiedDocument = false;
2252 modifiedDocument = false;
2260 void OnRedraw(Surface surface)
2263 surface.SetBackground(marginColor);
2264 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2265 if(ideSettings.showLineNumbers)
2267 int currentLineNumber;
2272 surface.textOpacity = false;
2273 surface.font = font.font;
2274 surface.TextExtent(" ", 1, null, &spaceH);
2275 currentLineNumber = editBox.scroll.y / spaceH + 1;
2277 surface.SetForeground(lineNumbersColor);
2278 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2280 // Highlight current line
2281 if(editBox.lineNumber == currentLineNumber - 1)
2283 surface.SetBackground(selectedMarginColor);
2284 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2285 surface.SetBackground(marginColor);
2287 sprintf(lineText,"%5u ", currentLineNumber % 100000);
2288 if(currentLineNumber <= editBox.numLines)
2289 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,6);
2291 currentLineNumber++;
2295 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2297 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2298 int lineCursor, lineTopFrame, breakpointLines[128];
2299 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2300 Debugger debugger = ide.debugger;
2301 BitmapResource bmpRes;
2303 boxH = clientSize.h;
2304 scrollY = editBox.scroll.y;
2305 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2307 bpOnCursor = bpOnTopFrame = false;
2308 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2311 for(i = 0; i < count; i++)
2313 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2315 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2316 if(breakpointLines[i] == lineCursor)
2318 if(breakpointLines[i] == lineTopFrame)
2319 bpOnTopFrame = true;
2322 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2324 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2327 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2328 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2329 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2331 if(editBox.anchor.left.distance)
2333 if(editBox.horzScroll && editBox.horzScroll.visible)
2335 surface.SetBackground(control);
2336 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2341 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2346 lineY = (line - 1) * lineH;
2347 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2349 Bitmap bitmap = resource.bitmap;
2351 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2358 char ext[MAX_EXTENSION];
2359 char * fileName = property::fileName;
2361 if(SearchString(fileName, 0, "Makefile", false, true))
2362 editBox.useTab = true;
2363 designer.fileName = fileName;
2367 GetExtension(fileName, ext);
2368 if(parsing && !strcmpi(ext, "ec"))
2370 codeModified = true;
2374 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"))
2375 editBox.syntaxHighlighting = true;
2377 editBox.syntaxHighlighting = false;
2380 display.FontExtent(font.font, " ", 1, &spaceW, null);
2381 editBox.anchor = Anchor
2383 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2384 right = 0, top = 0, bottom = 0
2393 display.FontExtent(font.font, " ", 1, &spaceW, null);
2394 editBox.anchor = Anchor
2396 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2397 right = 0, top = 0, bottom = 0
2402 bool LoadFile(char * filePath)
2404 File f = FileOpen(filePath, read);
2407 // Added this here...
2408 fileName = filePath;
2410 updatingCode = true;
2412 updatingCode = false;
2413 loadingFile = false;
2422 void AdjustDebugMenus(bool unavailable, bool bpNoToggle, bool executing)
2424 debugRunToCursor.disabled = unavailable || executing;
2425 debugSkipRunToCursor.disabled = unavailable || executing;
2426 debugToggleBreakpoint.disabled = bpNoToggle;
2432 ProjectView projectView = ide.projectView;
2435 designer.fileName = fileName;
2441 sprintf(title, $"Untitled %d", documentID);
2442 // designer.fileName = CopyString(title);
2443 designer.fileName = title;
2446 AdjustDebugMenus(ide.areDebugMenusUnavailable, ide.isBreakpointTogglingUnavailable, ide.isDebuggerExecuting);
2448 for(c = 0; c < CodeObjectType::enumSize; c++)
2449 icons[c] = BitmapResource { iconNames[c], window = this };
2451 codeModified = true;
2463 selected.modified = true;
2464 selected.oClass.modified = true;
2466 designer.modifiedDocument = true;
2467 modifiedDocument = true;
2468 formModified = true;
2471 /****************************************************************************
2473 ****************************************************************************/
2481 this.defines.Free(FreeModuleDefine);
2482 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2484 FreeExcludedSymbols(this.excludedSymbols);
2485 FreeContext(this.globalContext);
2487 FreeGlobalData(&this.globalData);
2488 FindCtx_Terminate();
2489 FindParams_Terminate();
2491 if(GetGlobalContext() == globalContext)
2493 SetGlobalData(null);
2494 SetGlobalContext(null);
2495 SetExcludedSymbols(null);
2496 SetTopContext(null);
2497 SetCurrentContext(null);
2500 SetPrivateModule(null);
2503 if(this.privateModule)
2505 FreeTypeData(this.privateModule);
2506 delete this.privateModule;
2507 this.privateModule = null;
2513 static bool reentrant = false;
2518 char * selectedClassName = null, * selectedName = null;
2519 int selectedPos = 0;
2520 Designer backDesigner;
2521 char oldWorkDir[MAX_LOCATION];
2522 char mainModuleName[MAX_FILENAME] = "";
2524 ImportedModule module;
2525 char extension[MAX_EXTENSION];
2526 PathBackup pathBackup { };
2528 Time parseCodeStart = GetTime();
2529 Time startTime, startFindClass;
2531 findClassTotalTime = 0;
2532 checkTypeTotalTime = 0;
2533 externalImportTotalTime = 0;
2534 findClassIgnoreNSTotalTime = 0;
2535 findSymbolTotalTime = 0;
2536 //ResetClassFindTime();
2540 // 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)
2541 if(reentrant) return;
2548 selectedClassName = CopyString(oClass.name);
2549 if(selected != oClass)
2551 ObjectInfo object = this.selected;
2552 selectedName = CopyString(object.name);
2556 for(check = this.oClass.instances.first; check; check = check.next)
2568 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2570 FindCtx_Terminate();
2571 FindParams_Terminate();
2573 SetGlobalData(&globalData);
2574 SetGlobalContext(globalContext);
2575 SetExcludedSymbols(&excludedSymbols);
2576 SetTopContext(globalContext);
2577 SetCurrentContext(globalContext);
2578 SetDefines(&defines);
2579 SetImports(&imports);
2580 SetCurrentNameSpace(null);
2583 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2584 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2585 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2586 "/I T:\\ecere\\include /E %s", argv[1]);
2590 ChangeWorkingDir("e:\\ec");
2591 sprintf(command, "gcc -x c -E -");
2592 fileInput = DualPipeOpen({ output = true, input = true }, command);
2593 SetFileInput(fileInput);
2598 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2600 fileInput.Write(buffer, 1, count);
2605 fileInput.CloseOutput();
2609 // TOCHECK: COULDN'T WE CALL FreeParser here?
2611 FreeType(this.functionType);
2612 FreeType(this.instanceType);
2613 this.functionType = null;
2614 this.instanceType = null;
2617 sheet.SelectObject(null);
2623 // We don't want the designer to be notified of selection when deleting rows...
2624 backDesigner = designer;
2629 ObjectInfo _class, next;
2631 for(_class = classes.first; _class; _class = next)
2637 for(;object = _class.instances.first;)
2641 Designer::DestroyObject(object.instance);
2642 delete object.instance;
2644 sheet.DeleteObject(object);
2646 _class.instances.Delete(object);
2650 Designer::DestroyObject(_class.instance);
2651 delete _class.instance;
2653 sheet.DeleteObject(_class);
2655 classes.Delete(_class);
2661 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2662 if(windowClass && windowClass.data)
2663 UnapplySkin(windowClass);
2666 designer = backDesigner;
2669 fileInput = editFile = EditBoxStream { editBox = editBox };
2670 SetFileInput(fileInput);
2678 defines.Free(FreeModuleDefine);
2679 imports.Free(FreeModuleImport);
2681 FreeContext(this.globalContext);
2682 FreeExcludedSymbols(this.excludedSymbols);
2685 FreeGlobalData(&this.globalData);
2687 if(this.privateModule)
2689 FreeTypeData(this.privateModule);
2690 delete this.privateModule;
2694 startTime = GetTime();
2695 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2697 printf("classes.count: %d\n", globalContext.classes.count);
2702 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2703 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2706 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2708 SetPrivateModule(privateModule);
2711 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2712 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2713 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2714 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2715 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2718 fileName = this.fileName;
2720 if(ide.workspace && ide.workspace.projects && fileName)
2722 for(p : ide.workspace.projects)
2724 char path[MAX_LOCATION];
2726 MakePathRelative(fileName, p.topNode.path, path);
2727 MakeSlashPath(path);
2729 pn = p.topNode.FindWithPath(path, false);
2738 project = ide.project;
2740 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2742 ChangeWorkingDir(project.topNode.path);
2744 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2746 GetLastDirectory(fileName, mainModuleName);
2747 GetExtension(mainModuleName, extension);
2749 SetBuildingEcereCom(false);
2750 SetBuildingEcereComModule(false);
2752 // TODO: Get symbolsDir from project settings instead...
2755 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2756 ProjectConfig config = project.config;
2757 int bitDepth = ide.workspace.bitDepth;
2758 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2759 SetSymbolsDir(objDir.dir);
2760 ide.SetPath(true, compiler, config, bitDepth);
2764 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2765 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2769 switch(GetRuntimePlatform())
2771 case win32: SetSymbolsDir("obj/debug.win32"); break;
2772 case tux: SetSymbolsDir("obj/debug.linux"); break;
2773 case apple: SetSymbolsDir("obj/debug.apple"); break;
2775 SetIncludeDirs(null);
2776 SetSysIncludeDirs(null);
2780 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2782 // TODO FIX for configless project
2783 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2785 for(item : ide.project.config.options.preprocessorDefinitions)
2787 if(!strcmp(item, "BUILDING_ECERE_COM"))
2789 SetBuildingEcereCom(true);
2796 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2797 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2798 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2799 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2800 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2801 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2802 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2803 strcmpi(mainModuleName, "Mutex.ec")))
2805 SetBuildingEcereComModule(true);
2808 // Predeclare all classes
2810 char symFile[MAX_FILENAME];
2811 char symLocation[MAX_LOCATION];
2812 ImportedModule module, next;
2814 GetLastDirectory(fileName, symFile);
2815 ChangeExtension(symFile, "sym", symFile);
2817 strcpy(symLocation, GetSymbolsDir());
2818 PathCat(symLocation, symFile);
2820 // if(!GetEcereImported() && !GetBuildingEcereCom())
2821 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2824 startTime = GetTime();
2826 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2828 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2833 startTime = GetTime();
2835 // LoadSymbols(symLocation, normalImport, true);
2836 LoadSymbols(symLocation, preDeclImport, false);
2838 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2841 for(module = defines.first; module; module = next)
2844 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2847 defines.Delete(module);
2852 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2854 SetDefaultDeclMode(privateAccess);
2855 SetDeclMode(privateAccess);
2859 SetDefaultDeclMode(defaultAccess);
2860 SetDeclMode(defaultAccess);
2863 StripExtension(mainModuleName);
2864 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2865 defines.AddName(module);
2868 // SetYydebug(true);
2873 startTime = GetTime();
2874 startFindClass = checkTypeTotalTime;
2878 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2880 CheckDataRedefinitions();
2883 SetIncludeDirs(null);
2884 SetSysIncludeDirs(null);
2895 startTime = GetTime();
2897 PrePreProcessClassDefinitions();
2898 ComputeModuleClasses(privateModule);
2899 PreProcessClassDefinitions();
2900 ProcessClassDefinitions();
2902 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2903 startTime = GetTime();
2908 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2909 startTime = GetTime();
2911 ProcessInstantiations();
2913 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2916 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2918 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2919 if(!windowClass || windowClass.internalDecl)
2922 startTime = GetTime();
2924 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2925 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2926 eModule_Load(this.privateModule, "ecere", privateAccess);
2928 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2931 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2933 if(windowClass && windowClass.data)
2934 ApplySkin(windowClass, app.currentSkin.name, null);
2938 startTime = GetTime();
2940 for(external = ast->first; external; external = external.next)
2942 if(external.type == classExternal)
2944 ClassDefinition _class = external._class;
2945 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2947 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2950 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2952 Instance instance = eInstance_New(regClass);
2953 ObjectInfo classObject
2955 name = CopyString(_class._class.name);
2956 instance = instance;
2957 classDefinition = _class;
2958 oClass = classObject;
2961 classes.Add(classObject);
2965 // Moved this at bottom so that the file dialog doesn't show up in eCom
2966 designer.CreateObject(instance, classObject, true, null);
2967 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
2969 if(_class.definitions)
2973 for(def = _class.definitions->first; def; def = def.next)
2977 case defaultPropertiesClassDef:
2980 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
2982 Identifier id = propDef.identifiers->first;
2985 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
2988 Class propertyClass = prop.dataTypeClass;
2990 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
2991 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
2993 FreeType(propDef.initializer.exp.destType);
2994 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
2995 ProcessExpressionType(propDef.initializer.exp);
2997 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
2999 Expression computed = CopyExpression(propDef.initializer.exp);
3000 ComputeExpression(computed);
3002 if(computed.isConstant && computed.type == instanceExp && !id.next)
3006 if(computed.instance._class && computed.instance._class.symbol &&
3007 computed.instance._class.symbol.registered &&
3008 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3010 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3012 // This was saved in the control and shouldn't be freed by FreeExpression...
3013 if(propertyClass.type == normalClass)
3014 computed.instance.data = null;
3018 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3019 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3021 String temp = new char[strlen(computed.string)+1];
3022 ReadString(temp, computed.string);
3023 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3027 propDef.variable = true;
3029 FreeExpression(computed);
3033 Expression computed = CopyExpression(propDef.initializer.exp);
3034 ComputeExpression(computed);
3035 if(computed.isConstant)
3037 //if(computed.type == memberExp) computed = computed.member.exp;
3039 if(computed.type == constantExp)
3041 Operand value = GetOperand(computed);
3042 DataValue valueData;
3043 valueData.i64 = value.i64;
3044 SetProperty(prop, instance, valueData);
3046 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3048 String temp = new char[strlen(computed.string)+1];
3049 ReadString(temp, computed.string);
3050 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3055 propDef.variable = true;
3057 FreeExpression(computed);
3061 propDef.variable = true;
3065 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3066 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3067 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3070 // Maintain a list in FunctionDefinition of who is attached to it
3071 for(def = _class.definitions->first; def; def = def.next)
3073 if(def.type == functionClassDef)
3075 ClassFunction function = def.function;
3076 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3078 function.attached.Add(OldLink { data = method });
3088 case declarationClassDef:
3090 Declaration decl = def.decl;
3093 case instDeclaration:
3095 Instantiation inst = decl.inst;
3096 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3097 if(instClass && eClass_GetDesigner(instClass))
3099 Instance control = eInstance_New(instClass);
3104 oClass = classObject;
3108 classObject.instances.Add(object);
3110 // TOCHECK: Why is this needed now?
3111 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3112 def.object = object;
3114 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3116 designer.CreateObject(control, object, false, classObject.instance);
3117 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3127 // Second pass, process instantiation members
3129 for(def = _class.definitions->first; def; def = def.next)
3133 case declarationClassDef:
3135 Declaration decl = def.decl;
3138 case instDeclaration:
3140 Instantiation inst = decl.inst;
3141 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3142 if(instClass && eClass_GetDesigner(instClass))
3145 object = object ? object.next : classObject.instances.first;
3146 control = object.instance;
3150 MembersInit members;
3151 for(members = inst.members->first; members; members = members.next)
3153 switch(members.type)
3155 case dataMembersInit:
3157 if(members.dataMembers)
3160 DataMember curMember = null;
3161 Class curClass = null;
3162 DataMember subMemberStack[256];
3163 int subMemberStackPos = 0;
3165 for(member = members.dataMembers->first; member; member = member.next)
3168 Identifier ident = member.identifiers ? member.identifiers->first : null;
3171 DataMember _subMemberStack[256];
3172 int _subMemberStackPos = 0;
3173 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3177 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3179 if(thisMember && thisMember.memberAccess == publicAccess)
3181 curMember = thisMember;
3182 curClass = curMember._class;
3183 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3184 subMemberStackPos = _subMemberStackPos;
3190 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3191 if(curMember) found = true;
3193 if(found && curMember.isProperty)
3195 Property prop = (Property) curMember;
3196 Class propertyClass = prop.dataTypeClass;
3198 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3200 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3202 FreeType(member.initializer.exp.destType);
3203 member.initializer.exp.destType = MkClassType(propertyClass.name);
3206 ProcessExpressionType(member.initializer.exp);
3208 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3210 Expression computed;
3212 /*char debugExpString[4096];
3213 debugExpString[0] = '\0';
3214 PrintExpression(member.initializer.exp, debugExpString);*/
3216 computed = CopyExpression(member.initializer.exp);
3219 ComputeExpression(computed);
3221 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3223 if(computed.instance.data)
3225 if(computed.instance._class && computed.instance._class.symbol &&
3226 computed.instance._class.symbol.registered &&
3227 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3229 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3231 // This was saved in the control and shouldn't be freed by FreeExpression...
3232 if(propertyClass.type == normalClass)
3233 computed.instance.data = null;
3237 else if(computed.type == identifierExp)
3239 member.variable = true;
3241 if(eClass_GetDesigner(propertyClass))
3244 char * name = computed.identifier.string;
3245 if(!strcmp(name, "this"))
3248 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3249 member.variable = false;
3254 for(check = classObject.instances.first; check; check = check.next)
3255 if(check.name && !strcmp(name, check.name))
3258 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3259 member.variable = false;
3265 else if(computed.type == memberExp)
3267 member.variable = true;
3268 if(computed.member.exp.type == identifierExp)
3270 char * name = computed.member.exp.identifier.string;
3271 if(!strcmp(name, "this"))
3273 char * name = computed.member.member.string;
3276 for(check = classObject.instances.first; check; check = check.next)
3277 if(check.name && !strcmp(name, check.name))
3280 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3281 member.variable = false;
3289 for(check = classObject.instances.first; check; check = check.next)
3291 if(check.name && !strcmp(name, check.name))
3293 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3296 DataValue value { };
3297 GetProperty(getProperty, check.instance, &value);
3298 SetProperty(prop, control, value);
3299 member.variable = false;
3307 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3308 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3310 String temp = new char[strlen(computed.string)+1];
3311 ReadString(temp, computed.string);
3312 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3316 member.variable = true;
3318 FreeExpression(computed);
3323 Expression computed = CopyExpression(member.initializer.exp);
3326 ComputeExpression(computed);
3327 if(computed.isConstant)
3329 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3331 if(!strcmp(propertyClass.dataTypeString, "float"))
3332 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3333 else if(!strcmp(propertyClass.dataTypeString, "double"))
3334 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3336 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3338 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3340 String temp = new char[strlen(computed.string)+1];
3341 ReadString(temp, computed.string);
3342 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3347 member.variable = true;
3349 FreeExpression(computed);
3355 member.variable = true;
3357 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3358 member.initializer.exp.type == memberExp) // identifierExp
3360 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3361 if(method && method.type == virtualMethod)
3364 // Maintain a list in FunctionDefinition of who is attached to it
3365 for(def = _class.definitions->first; def; def = def.next)
3367 if(def.type == functionClassDef)
3369 ClassFunction function = def.function;
3370 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3371 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3373 function.attached.Add(OldLink { data = method });
3374 // Reference this particular instance?
3389 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3400 //designer.CreateObject(instance, classObject, true, null);
3401 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3403 designer.PostCreateObject(instance, classObject, true, null);
3405 //instance.state = Hidden;
3406 //instance.Create();
3407 //instance.SetState(Normal, true, 0);
3416 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3420 // Restore Selection
3421 if(selectedClassName)
3424 for(oClass = classes.first; oClass; oClass = oClass.next)
3426 if(!strcmp(oClass.name, selectedClassName))
3428 this.oClass = oClass;
3432 delete selectedClassName;
3441 for(check = this.oClass.instances.first; check; check = check.next)
3443 if(check.name && !strcmp(check.name, selectedName))
3445 this.selected = check;
3451 if(this.oClass.instances.first)
3452 this.selected = this.oClass.instances.first;
3454 this.selected = this.oClass;
3457 else if(selectedPos == -1 || !this.oClass.instances.count)
3458 this.selected = this.oClass;
3464 if(selectedPos > this.oClass.instances.count)
3466 for(check = this.oClass.instances.first; check; check = check.next)
3468 if(selectedPos == pos++)
3470 this.selected = check;
3478 this.oClass = classes.first;
3479 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3481 delete selectedName;
3482 SetSymbolsDir(null);
3484 if(sheet.codeEditor == this)
3485 sheet.SelectObject(selected);
3488 codeModified = false;
3490 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3493 InvokeParameters(false, false, false);
3496 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3502 ChangeWorkingDir(oldWorkDir);
3504 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3505 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3506 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3507 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3508 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3510 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3512 if(inUseDebug && ide.projectView)
3513 ide.debugger.EvaluateWatches();
3518 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3521 Window control = (Window)object.instance;
3522 ObjectInfo classObject = object.oClass;
3524 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3526 if(!strcmp(_class.name, "DesignerBase")) return;
3528 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3530 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3531 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3533 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3534 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3536 Class dataType = prop.dataTypeClass;
3538 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3542 if(dataType.type == structClass)
3544 void * dataForm = new0 byte[dataType.structSize];
3545 void * dataTest = new0 byte[dataType.structSize];
3547 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3548 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3550 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3552 char tempString[1024] = "";
3554 bool needClass = true;
3558 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3560 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3562 eClass_FindNextMember(_class, curClass, curMember, null, null);
3563 if(*curMember != (DataMember)prop)
3564 f.Printf("%s = ", prop.name);
3566 *curMember = (DataMember)prop;
3567 *curClass = curMember->_class;
3570 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3572 f.Printf("%s", string);
3579 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3581 void * dataForm, * dataTest;
3583 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3584 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3586 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3588 char tempString[1024] = "";
3593 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3595 eClass_FindNextMember(_class, curClass, curMember, null, null);
3596 if(*curMember != (DataMember)prop)
3597 f.Printf("%s = ", prop.name);
3598 *curMember = (DataMember)prop;
3599 *curClass = curMember->_class;
3601 if(eClass_GetDesigner(dataType))
3603 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3604 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3605 f.Printf("this", prop.name);
3608 //ObjectInfo classObject;
3609 //for(classObject = classes.first; classObject; classObject = classObject.next)
3613 for(object = classObject.instances.first; object; object = object.next)
3615 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3617 f.Printf("%s", object.name);
3624 bool needClass = true;
3625 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3626 f.Printf("%s", string);
3633 bool needClass = true;
3634 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3636 if(!strcmp(dataType.dataTypeString, "char *"))
3639 OutputString(f, string);
3643 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3645 f.Printf("%s", string);
3648 *lastIsMethod = false;
3653 DataValue dataForm, dataTest;
3655 GetProperty(prop, control, &dataForm);
3656 GetProperty(prop, test, &dataTest);
3658 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3661 char tempString[1024] = "";
3662 SetProperty(prop, test, dataForm);
3664 if(dataType.type != bitClass)
3666 bool needClass = true;
3668 if(dataType.type == enumClass)
3671 Class enumClass = eSystem_FindClass(privateModule, "enum");
3672 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3674 for(value = e.values.first; value; value = value.next)
3676 if((int)value.data == dataForm.i)
3678 string = value.name;
3684 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3686 if(string && string[0])
3691 eClass_FindNextMember(_class, curClass, curMember, null, null);
3692 if(*curMember != (DataMember)prop)
3693 f.Printf("%s = ", prop.name);
3694 *curMember = (DataMember)prop;
3695 *curClass = curMember->_class;
3697 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3698 f.Printf("%sf", string);
3700 f.Printf("%s", string);
3704 else if(dataType.type == bitClass)
3706 bool needClass = true;
3708 if(*prev) f.Printf(", ");
3710 eClass_FindNextMember(_class, curClass, curMember, null, null);
3711 if(*curMember != (DataMember)prop)
3712 f.Printf("%s = ", prop.name);
3713 *curMember = (DataMember)prop;
3714 *curClass = curMember->_class;
3716 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3718 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3720 f.Printf("%s", string);
3722 *lastIsMethod = false;
3732 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3734 Instantiation inst = object.instCode;
3735 Window control = (Window)object.instance;
3737 bool methodPresent = false;
3739 bool lastIsMethod = true;
3740 ObjectInfo classObject = object.oClass;
3746 // Instance removed, delete it
3747 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3749 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3750 position = inst.loc.end.pos + 1;
3754 bool multiLine = false;
3757 // Check if it's an unnamed instance
3760 f.Seek(inst.nameLoc.start.pos - position, current);
3761 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3762 position = inst.nameLoc.end.pos;
3764 f.Printf(object.name);
3769 if(isspace(ch) && ch != '\n')
3771 f.Seek(-1, current);
3779 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3781 f.Seek(pos - position, current);
3786 f.Seek(-1, current);
3795 f.Puts(object.name);
3800 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3801 methodPresent = true;
3809 if(ch == OpenBracket)
3815 // TODO: Simplify this?
3824 f.Seek(-1, current);
3836 if(ch == '\n') { toDelete = count; count = 0; }
3837 else if(isspace(ch)) count++;
3840 f.Seek(-1, current);
3844 toDelete += count - 6;
3854 f.Seek(-toDelete-count, current);
3855 f.DeleteBytes(toDelete);
3856 f.Seek(count, current);
3861 for(c = 0; c<toAdd; c++)
3867 methodPresent = multiLine;
3870 f.Printf(methodPresent ? "\n " : " ");
3876 // Instance not there, create a brand new one
3877 DeleteJunkBefore(f, position, &position);
3878 f.Printf(*firstObject ? "\n\n" : "\n");
3879 *firstObject = false;
3881 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3882 methodPresent = true;
3887 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3889 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3894 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3896 f.Printf(" %s %c ", control._class.name, OpenBracket);
3902 Instance test = eInstance_New(control._class);
3903 DataMember curMember = null;
3904 Class curClass = null;
3907 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3911 // Attach Method here
3912 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3914 if(prev) f.Printf(", ");
3915 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3920 if(inst && !object.deleted)
3922 MembersInit members;
3923 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3925 DeleteJunkBefore(f, position, &position);
3927 // Instance already there, clear out the properties
3928 for(members = inst.members->first; members; members = members.next)
3930 if(members.type == dataMembersInit)
3934 if(members.dataMembers)
3936 bool keptMember = false;
3937 MemberInit lastKept = null;
3939 for(member = members.dataMembers->first; member; member = member.next)
3941 Identifier ident = member.identifiers ? member.identifiers->first : null;
3942 bool deleted = false;
3944 // For now delete if it's not a method
3945 if(!member.variable) // && ident)
3947 if(!ident || !ident.next)
3949 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3952 f.Seek(member.loc.start.pos - position, current);
3953 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3954 position = member.loc.end.pos;
3959 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3960 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3961 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
3963 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
3964 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
3966 f.Seek(member.loc.start.pos - position, current);
3967 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3968 position = member.loc.end.pos;
3980 //f.Seek(member.loc.start.pos - position, current);
3981 //position = member.loc.start.pos;
3982 DeleteJunkBefore(f, member.loc.start.pos, &position);
3983 if(prev) f.Printf(", ");
3984 else if(keptMember) f.Printf(" ");
3989 if(!keptMember || !members.next)
3994 if(keptMember && lastKept != members.dataMembers->last)
3999 f.Seek(-1, current);
4005 f.Seek(-1, current);
4008 else if(!isspace(ch))
4010 f.Seek(-2, current);
4015 f.DeleteBytes(count);
4018 f.Seek(members.loc.end.pos - position, current);
4023 f.Seek(-1, current);
4025 position = members.loc.end.pos + 1;
4029 f.Seek(-1, current);
4030 position = members.loc.end.pos;
4036 lastIsMethod = false;
4041 DeleteJunkBefore(f, position, &position);
4044 if(lastKept != members.dataMembers->last)
4049 f.Seek(-1, current);
4055 f.Seek(-1, current);
4058 else if(!isspace(ch))
4060 f.Seek(-2, current);
4065 f.DeleteBytes(count);
4069 f.Seek(members.loc.end.pos - position, current);
4070 position = members.loc.end.pos;
4074 lastIsMethod = true;
4077 lastIsMethod = false;
4083 f.Seek(members.loc.end.pos - position, current);
4084 position = members.loc.end.pos;
4086 lastIsMethod = true;
4089 else if(members.type == methodMembersInit)
4091 if(this.methodAction == actionDeleteMethod && members.function == function);
4093 methodPresent = true;
4095 // Delete instance method here
4096 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4097 members.function == function)
4099 if(this.moveAttached && !*text)
4100 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4102 DeleteJunkBefore(f, members.loc.start.pos, &position);
4103 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4104 position = members.loc.end.pos + 1;
4109 DeleteJunkBefore(f, position, &position);
4113 DeleteJunkBefore(f, members.loc.start.pos, &position);
4114 lastIsMethod = true;
4118 f.Seek(members.loc.end.pos - position, current);
4119 position = members.loc.end.pos;
4121 DeleteJunkBefore(f, position, &position);
4130 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4132 Method method = this.method;
4133 DeleteJunkBefore(f, position, &position);
4139 if(!method.dataType)
4140 method.dataType = ProcessTypeString(method.dataTypeString, false);
4143 Type dataType = method.dataType;
4144 Type returnType = dataType.returnType;
4147 if(this.moveAttached)
4149 // Move function here:
4150 int newLen = strlen(method.name);
4155 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4157 // First change name of function
4158 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4159 *textSize += newLen - movedFuncIdLen;
4160 memcpy(*text + movedFuncIdPos, method.name, newLen);
4162 // Second, tab right
4165 for(c = 0; (*text)[c]; )
4168 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4171 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4172 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4176 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4186 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4188 // ADDING METHOD HERE
4190 OutputType(f, returnType, false);
4193 if(dataType.thisClass)
4195 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4197 if(dataType.thisClass.shortName)
4198 f.Printf(dataType.thisClass.shortName);
4200 f.Printf(dataType.thisClass.string);
4204 f.Printf(method.name);
4206 for(param = dataType.params.first; param; param = param.next)
4208 OutputType(f, param, true);
4213 f.Printf(" %c\n\n", OpenBracket);
4215 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4217 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4218 f.Printf(" return true;\n");
4219 else if(returnType.kind != voidType)
4220 f.Printf(" return 0;\n");
4225 if(returnType.kind != voidType)
4226 f.Printf("return ");
4227 f.Printf("%s::%s(", control._class.name, method.name);
4228 for(param = dataType.params.first; param; param = param.next)
4230 if(param.prev) f.Printf(", ");
4231 if(param.kind != voidType)
4232 f.Printf(param.name);
4236 f.Printf(" %c\n", CloseBracket);
4242 if(!object.instCode)
4245 f.Printf(" %c;\n", CloseBracket);
4247 f.Printf("%c;\n", CloseBracket);
4249 else if(!object.deleted)
4251 // Turn this into a multiline instance when adding a method
4252 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4254 f.Printf(methodPresent ? "\n " : " ");
4256 f.Seek(inst.loc.end.pos + 1 - position, current);
4257 position = inst.loc.end.pos + 1;
4262 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4265 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4267 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4269 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4271 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4272 if(prop && prop.isProperty && !prop.conversion)
4274 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4275 (!prop.IsSet || prop.IsSet(classObject.instance)))
4277 Class dataType = prop.dataTypeClass;
4278 char tempString[1024] = "";
4280 bool specify = false;
4283 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4284 if(member && member._class == regClass)
4288 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4290 if(dataType && dataType.type == structClass)
4292 void * dataForm = new0 byte[dataType.structSize];
4293 void * dataTest = new0 byte[dataType.structSize];
4295 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4296 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4298 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4300 bool needClass = true;
4302 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4303 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4305 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4307 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4312 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4314 void * dataForm, * dataTest;
4316 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4317 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4319 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4321 char tempString[1024] = "";
4323 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4325 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4327 // Shouldn't go here ...
4328 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4332 bool needClass = true;
4334 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4336 if(!strcmp(dataType.dataTypeString, "char *"))
4338 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4339 OutputString(f, string);
4343 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4345 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4351 DataValue dataForm, dataTest;
4353 GetProperty(prop, classObject.instance, &dataForm);
4354 GetProperty(prop, test, &dataTest);
4356 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4358 SetProperty(prop, test, dataForm);
4359 if(dataType.type == bitClass)
4361 bool needClass = true;
4362 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4364 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4366 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4370 bool needClass = true;
4371 if(dataType.type == enumClass)
4374 Class enumClass = eSystem_FindClass(privateModule, "enum");
4375 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4377 for(value = e.values.first; value; value = value.next)
4379 if((int)value.data == dataForm.i)
4381 string = value.name;
4387 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4388 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4389 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4391 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4400 void UpdateFormCode()
4403 if(!parsing) return;
4410 else if(formModified)
4412 EditBoxStream f { editBox = editBox };
4416 Identifier movedFuncId;
4417 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4418 ObjectInfo classObject;
4424 movedFuncId = GetDeclId(function.declarator);
4425 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4426 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4429 for(classObject = classes.first; classObject; classObject = classObject.next)
4432 ClassDefinition classDef = classObject.classDefinition;
4433 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4436 bool firstObject = true;
4437 ObjectInfo object = classObject.instances.first;
4438 bool lastIsDecl = false;
4440 if(!classObject.modified) continue;
4442 test = eInstance_New(regClass);
4445 // Put it in the same desktop window...
4446 designer.PrepareTestObject(test);
4448 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4449 //f.Printf("%c\n\n", OpenBracket);
4451 // Change the _class name
4452 f.Seek(classDef.nameLoc.start.pos - position, current);
4453 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4454 f.Printf(classObject.name);
4455 position = classDef.nameLoc.end.pos;
4458 // Go to block start, delete all until no white space, put \n
4462 f.Seek(classDef.blockStart.end.pos - position, current);
4463 position = classDef.blockStart.end.pos;
4465 for(; f.Getc(&ch); count++)
4469 f.Seek(-1, current);
4479 f.Seek(-count, current);
4481 f.DeleteBytes(count-back);
4483 position += count-back;
4486 // Output properties
4487 OutputClassProperties(classObject.instance._class, classObject, f, test);
4489 for(def = classDef.definitions->first; def; def = def.next)
4493 case defaultPropertiesClassDef:
4495 bool keptMember = false;
4497 MemberInit lastKept = null;
4500 DeleteJunkBefore(f, def.loc.start.pos, &position);
4503 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4505 Identifier ident = propDef.identifiers->first;
4506 bool deleted = false;
4508 // For now delete if it's a prop
4509 if(!propDef.variable && ident)
4513 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4516 f.Seek(propDef.loc.start.pos - position, current);
4517 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4518 position = propDef.loc.end.pos;
4523 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4524 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4526 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4527 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4529 f.Seek(propDef.loc.start.pos - position, current);
4530 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4531 position = propDef.loc.end.pos;
4549 f.Seek(def.loc.end.pos - position - 1, current);
4554 f.Seek(-1, current);
4557 position = def.loc.end.pos;
4561 if(lastKept != def.defProperties->last)
4566 f.Seek(-1, current);
4572 f.Seek(-1, current);
4575 else if(!isspace(ch))
4577 f.Seek(-2, current);
4582 f.DeleteBytes(count);
4586 f.Seek(def.loc.end.pos - position, current);
4587 position = def.loc.end.pos;
4592 case declarationClassDef:
4594 Declaration decl = def.decl;
4596 if(decl.type == instDeclaration)
4598 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4600 while(def.object && object != def.object)
4602 if(object /*&& ((ObjectInfo)def.object).modified*/)
4603 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4604 object = object.next;
4607 DeleteJunkBefore(f, def.loc.start.pos, &position);
4608 f.Printf(firstObject ? "\n\n " : "\n ");
4609 firstObject = false;
4611 if(def.object && ((ObjectInfo)def.object).modified)
4612 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4614 object = object ? object.next : null;
4618 DeleteJunkBefore(f, def.loc.start.pos, &position);
4619 f.Printf(firstObject ? "\n\n " : "\n ");
4620 firstObject = false;
4626 DeleteJunkBefore(f, def.loc.start.pos, &position);
4627 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4632 case functionClassDef:
4634 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4635 if(!def.function.body) continue;
4639 DeleteJunkBefore(f, def.loc.start.pos, &position);
4642 // Delete _class methods
4643 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4644 def.function == function)
4649 if(moveAttached && !text)
4651 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4654 f.Seek(def.loc.end.pos - position, current);
4655 for(; f.Getc(&ch); count++)
4659 f.Seek(-1, current);
4663 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4665 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4666 position = def.loc.end.pos + count;
4669 // In case of detaching methods in the _class, simply rename the method
4670 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4672 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4673 f.DeleteBytes(movedFuncIdLen);
4675 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4678 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4679 function == def.function)
4681 // In case of attaching methods in the _class, simply rename the method
4682 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4683 position = function.loc.start.pos + movedFuncIdPos;
4684 f.DeleteBytes(movedFuncIdLen);
4685 if(method.dataType.thisClass)
4686 f.Printf("%s::", method.dataType.thisClass.string);
4687 f.Puts(method.name);
4688 position += movedFuncIdLen;
4693 DeleteJunkBefore(f, def.loc.start.pos, &position);
4694 if(def.type == memberAccessClassDef)
4697 firstObject = false;
4707 f.Seek(def.loc.end.pos - position, current);
4708 position = def.loc.end.pos;
4711 // Output attached methods
4712 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4714 DeleteJunkBefore(f, position, &position);
4715 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4718 // ********** INSTANCES ***************
4719 for(; object; object = object.next)
4721 if(!object.instCode)
4723 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4727 DeleteJunkBefore(f, position, &position);
4729 // ****************** METHODS ***********************
4730 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4732 // If detaching an instance method
4733 if(selected != classObject)
4735 int newLen = strlen(methodName);
4738 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4739 // Tab selection left
4742 for(c = 0; text[c]; )
4745 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4746 memmove(text+start, text+start+i, textSize+1-start-i);
4749 for(; text[c] && text[c] != '\n'; c++);
4755 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4756 textSize += newLen - movedFuncIdLen;
4757 memcpy(text + movedFuncIdPos, methodName, newLen);
4764 if(methodAction == actionAddMethod && selected == classObject)
4766 Method method = this.method;
4768 if(!method.dataType)
4769 method.dataType = ProcessTypeString(method.dataTypeString, false);
4771 // ADDING METHOD HERE
4773 Type dataType = method.dataType;
4774 Type returnType = dataType.returnType;
4776 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4780 OutputType(f, returnType, false);
4783 if(dataType.thisClass && !dataType.classObjectType)
4785 if(dataType.thisClass.shortName)
4786 f.Printf(dataType.thisClass.shortName);
4788 f.Printf(dataType.thisClass.string);
4791 f.Printf(method.name);
4793 for(param = dataType.params.first; param; param = param.next)
4795 OutputType(f, param, true);
4800 f.Printf(" %c\n\n", OpenBracket);
4802 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4804 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4805 f.Printf(" return true;\n");
4806 else if(returnType && returnType.kind != voidType)
4807 f.Printf(" return 0;\n");
4812 if(returnType.kind != voidType)
4813 f.Printf("return ");
4815 char * name = ((Specifier)classDef.baseSpecs->first).name;
4816 Symbol _class = FindClass(name);
4817 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4819 for(param = dataType.params.first; param; param = param.next)
4821 if(param.prev) f.Printf(", ");
4822 if(param.kind != voidType)
4823 f.Printf(param.name);
4828 f.Printf(" %c", CloseBracket);
4832 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4844 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4845 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4849 codeModified = false;
4850 formModified = false;
4852 moveAttached = false;
4857 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4860 ClassFunction function = null;
4863 ObjectInfo object = this.selected;
4865 if(object && object == this.oClass)
4867 ClassDefinition classDef = object.oClass.classDefinition;
4869 if(classDef && classDef.definitions)
4871 for(def = classDef.definitions->first; def; def = def.next)
4873 if(def.type == functionClassDef && def.function.declarator)
4875 if(!strcmp(def.function.declarator.symbol.string, methodName))
4877 function = def.function;
4882 else if(def.type == defaultPropertiesClassDef)
4886 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4888 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4889 if(ident && !ident.next)
4891 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4895 propLoc = propDef.loc;
4898 ClassDefinition classDef = object.oClass.classDefinition;
4900 if(classDef.definitions)
4902 for(def = classDef.definitions->first; def; def = def.next)
4904 if(def.type == functionClassDef)
4906 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4908 function = def.function;
4927 Instantiation inst = object.instCode;
4929 // Check here to see if the method already exists, no need to call ModifyCode in that case
4930 if(inst && inst.members)
4932 MembersInit members;
4933 for(members = inst.members->first; members; members = members.next)
4935 switch(members.type)
4937 case dataMembersInit:
4939 if(members.dataMembers)
4942 for(member = members.dataMembers->first; member; member = member.next)
4944 Identifier ident = member.identifiers ? member.identifiers->first : null;
4945 if(ident && !ident.next)
4947 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4951 propLoc = member.loc;
4954 ClassDefinition classDef = object.oClass.classDefinition;
4956 if(classDef.definitions)
4958 for(def = classDef.definitions->first; def; def = def.next)
4960 if(def.type == functionClassDef)
4962 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
4964 function = def.function;
4973 // TODO: Fix memory leak
4974 function = ClassFunction
4976 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
4988 case methodMembersInit:
4990 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
4992 function = members.function;
5004 if(functionPtr) *functionPtr = function;
5008 void GoToMethod(char * methodName /*Method method*/)
5012 ObjectInfo object = selected;
5013 EditBoxStream f { editBox = editBox };
5014 ClassFunction function = null;
5015 bool atChar = false;
5019 Location propLoc = { {0,0,-1} };
5022 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5023 if(function && function.body)
5026 f.Seek(function.body.loc.start.pos+1, current);
5036 f.Seek(-1, current);
5041 else if(!isspace(ch))
5043 f.Seek(-1, current);
5049 else if(propLoc.start.pos > -1)
5051 f.Seek(propLoc.start.pos, current);
5054 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5056 if(function || propLoc.start.pos > -1)
5058 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5059 editBox.CenterOnCursor();
5060 SetState(normal, false, 0);
5063 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5065 FreeClassFunction(function);
5071 void FindCompatibleMethods(Method method, OldList compatible)
5073 ClassDefinition classDef = this.oClass.classDefinition;
5074 if(classDef && classDef.definitions)
5077 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5080 Symbol classSym { };
5081 Symbol selectedClass;
5082 if(this.selected == this.oClass)
5083 selectedClass = classSym;
5085 selectedClass = FindClass(this.selected.instance._class.name);
5087 regClass.name = classDef._class.name;
5088 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5089 for(def = classDef.definitions->first; def; def = def.next)
5091 if(def.type == functionClassDef && def.function.declarator)
5093 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5095 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5098 Type type = def.function.declarator.symbol.type;
5099 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5101 compatible.Add(OldLink { data = def.function });
5107 if(this.oClass && this.oClass.instance)
5109 classSym.registered = regClass;
5110 //classSym.registered = this.oClass.oClass;
5112 for(_class = regClass.base; _class; _class = _class.base)
5115 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5117 // TODO: Understand why these functions popup in attach list
5118 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5120 if(!testMethod.dataType)
5121 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5123 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5124 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5125 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5127 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5128 // ClassFunction function { };
5129 FunctionDefinition function { };
5131 function.declarator = Declarator { };
5132 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5133 excludedSymbols.Add(function.declarator.symbol);
5135 compatible.Add(OldLink { data = function });
5146 void AddMethod(Method method)
5150 char methodName[1024];
5151 strcpy(methodName, method.name);
5152 if(!FindMethod(methodName, null, null))
5154 methodAction = actionAddMethod;
5155 this.method = method;
5159 GoToMethod(methodName);
5163 void DeleteMethod(ClassFunction function)
5167 methodAction = actionDeleteMethod;
5168 this.function = function;
5176 void AttachMethod(Method method, ClassFunction function)
5180 // If it's an instance we'll ask if we want to move it inside...
5181 if(!function.attached.count && function.body)
5183 // Find the function in the _class to check if it's a virtual function
5184 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5185 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5186 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5188 for(def = this.classDefinition.first; def; def = def.next)
5190 if(def.type == functionClassDef)
5192 if(def.function == function)
5197 if(!method || method.type != virtualMethod)
5200 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5201 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5203 moveAttached = true;
5208 methodAction = actionAttachMethod;
5209 this.method = method;
5210 this.function = function;
5217 void ReAttachMethod(Method method, ClassFunction function)
5221 // If it's an instance we'll ask if we want to move it inside...
5222 if(!function.attached.count && function.body)
5224 // Find the function in the _class to check if it's a virtual function
5225 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5226 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5227 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5229 for(def = this.classDefinition.first; def; def = def.next)
5231 if(def.type == functionClassDef)
5233 if(def.function == function)
5238 if(!method || method.type != virtualMethod)
5241 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5242 if(MessageBox { type = yesNo, master = parent, text = title,
5243 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5245 moveAttached = true;
5250 methodAction = actionReattachMethod;
5251 this.method = method;
5252 this.function = function;
5259 void DetachMethod(Method method, ClassFunction function, int type)
5267 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5268 master = sheet, text = $"Name detached method", background = formColor
5272 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5273 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5277 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5278 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5282 dialog, anchor = { left = 5, right = 5, top = 5 }
5284 sprintf(methodName, "%s_%s", selected.name, method.name);
5285 nameBox.contents = methodName;
5287 result = dialog.Modal() == ok;
5288 strcpy(methodName, nameBox.contents);
5293 // If the method is not attached, move it outside
5296 // Add this class to the methodName
5297 char name[1024] = "";
5299 if(this.selected != this.oClass && !method.dataType.thisClass)
5301 strcat(name, this.selected.instance._class.name);
5303 strcat(name, this.methodName);
5304 strcpy(this.methodName, name);
5306 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5308 strcat(name, method.dataType.thisClass.string);
5310 strcat(name, this.methodName);
5311 strcpy(this.methodName, name);
5314 this.moveAttached = true;
5317 this.methodAction = actionDetachMethod;
5318 this.method = method;
5319 this.function = function;
5326 void AddObject(Instance instance, ObjectInfo * object)
5330 //*object = _class.instances.Add(sizeof(ObjectInfo));
5331 *object = ObjectInfo { };
5332 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5333 (*object).oClass = oClass;
5334 (*object).instance = instance;
5339 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5341 // if(strcmp(name, this.oClass.instance.name))
5344 for(check = oClass.instances.first; check; check = check.next)
5345 if(!check.deleted && check.name && !strcmp(name, check.name))
5349 (*object).name = CopyString(name);
5354 toolBox.controlClass = null;
5358 //sheet.AddObject(*object, (*object).name, TypeData, true);
5363 void EnsureUpToDate()
5365 if(sheet && codeModified && parsing)
5369 void SelectObject(ObjectInfo object)
5372 oClass = object ? object.oClass : null;
5374 designer.SelectObject(object, object ? object.instance : null);
5377 void SelectObjectFromDesigner(ObjectInfo object)
5380 sheet.SelectObject(object);
5383 void EnumerateObjects(Sheet sheet)
5387 for(oClass = classes.first; oClass; oClass = oClass.next)
5393 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5394 for(object = oClass.instances.first; object; object = object.next)
5395 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5398 sheet.SelectObject(selected);
5403 designer.AddObject();
5406 void DeleteObject(ObjectInfo object)
5408 delete object.instance;
5409 object.deleted = true;
5410 object.modified = true;
5411 object.oClass.modified = true;
5413 if(selected == object)
5415 bool looped = false;
5416 ObjectInfo select = object;
5420 select = select.prev;
5424 select = object.oClass.instances.last;
5431 sheet.SelectObject(select ? select : oClass);
5434 if(!object.instCode && object.oClass != object)
5437 oClass.instances.Delete(object);
5440 if(sheet.codeEditor == this)
5441 sheet.DeleteObject(object);
5444 void RenameObject(ObjectInfo object, char * name)
5448 // Validate the name:
5449 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5450 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5453 for(c = 0; name[c]; c++)
5454 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5462 object.name = (name && name[0]) ? CopyString(name) : null;
5464 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5468 void DesignerModifiedObject()
5470 sheet.ListProperties(false);
5474 void ListSubMembers(Type member)
5478 for(subMember = member.members.first; subMember; subMember = subMember.next)
5482 DataRow row = membersList.AddString(subMember.name);
5483 row.icon = icons[typeData];
5487 ListSubMembers(subMember);
5492 void ListSubDataMembers(DataMember member, bool isPrivate)
5494 DataMember subMember;
5495 for(subMember = member.members.first; subMember; subMember = subMember.next)
5497 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5501 DataRow row = membersList.AddString(subMember.name);
5502 BitmapResource bitmap = null;
5503 if(!subMember.dataType)
5504 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5506 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5508 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5511 bitmap = { bitmapName };
5512 membersList.AddResource(bitmap);
5515 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5519 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5525 void ListClassMembers(Class whatClass, bool methodsOnly)
5528 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5529 bool isPrivate = false;
5531 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5533 Method method, methodIt;
5535 DataMember memberIt;
5537 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5539 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5540 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5542 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5544 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5546 DataRow row = membersList.FindString(method.name);
5549 row = membersList.AddString(method.name);
5551 if(!method.dataType)
5552 method.dataType = ProcessTypeString(method.dataTypeString, false);
5554 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5562 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5566 if(memberIt.isProperty)
5568 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5570 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5574 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5576 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5579 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5585 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5587 if(member.isProperty)
5589 Property prop = (Property) member;
5590 if(!membersList.FindString(prop.name))
5592 DataRow row = membersList.AddString(prop.name);
5593 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5596 else if(member.name && !membersList.FindString(member.name))
5598 DataRow row = membersList.AddString(member.name);
5600 BitmapResource bitmap = null;
5601 if(!member.dataType)
5602 member.dataType = ProcessTypeString(member.dataTypeString, false);
5604 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5606 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5609 bitmap = { bitmapName };
5610 membersList.AddResource(bitmap);
5613 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5616 ListSubDataMembers(member, member.memberAccess == privateAccess);
5620 if(_class.inheritanceAccess == privateAccess)
5623 if(_class.module != privateModule) break;
5628 void ListClassMembersMatch(Class whatClass, Type methodType)
5631 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5632 bool isPrivate = false;
5634 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5640 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5642 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5644 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5646 if(!method.dataType)
5647 method.dataType = ProcessTypeString(method.dataTypeString, false);
5649 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5651 DataRow row = membersList.FindString(method.name);
5654 row = membersList.AddString(method.name);
5655 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5661 if(_class.inheritanceAccess == privateAccess)
5664 if(_class.module != privateModule) break;
5669 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5672 bool isPrivate = false;
5673 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5679 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5681 if(method.type == virtualMethod)
5683 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5685 DataRow row = membersList.FindString(method.name);
5688 row = membersList.AddString(method.name);
5690 if(!method.dataType)
5691 method.dataType = ProcessTypeString(method.dataTypeString, false);
5693 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5699 for(member = _class.membersAndProperties.first; member; member = member.next)
5701 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5703 if(member.isProperty)
5705 Property prop = (Property)member;
5707 DataRow row = membersList.AddString(prop.name);
5708 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5711 else if(member.name && (!curString || strcmp(curString, member.name)))
5713 DataRow row = membersList.AddString(member.name);
5715 BitmapResource bitmap = null;
5716 if(!member.dataType)
5717 member.dataType = ProcessTypeString(member.dataTypeString, false);
5719 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5721 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5724 bitmap = { bitmapName };
5725 membersList.AddResource(bitmap);
5728 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5731 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5734 if(_class.inheritanceAccess == privateAccess)
5737 if(_class.module != privateModule) break;
5742 void ListMembers(Type type)
5744 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5748 if(type.kind == classType)
5751 ListClassMembers(type._class.registered, false);
5756 for(member = type.members.first; member; member = member.next)
5760 DataRow row = membersList.AddString(member.name);
5761 row.icon = icons[typeData];
5763 else if(member.kind == structType || member.kind == unionType)
5764 ListSubMembers(member);
5770 void ListModule(Module mainModule, int recurse, bool listClasses)
5773 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5774 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5775 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5776 for(module = mainModule.application.allModules.first; module; module = module.next)
5778 if(ModuleVisibility(mainModule, module))
5779 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5783 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5790 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5792 Class _class = link.data;
5793 if(_class.type != systemClass)
5795 DataRow row = membersList.AddString(_class.name);
5796 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5801 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5803 DefinedExpression definedExp = link.data;
5804 DataRow row = membersList.AddString(link /*definedExp*/.name);
5805 row.icon = icons[typeData];
5808 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5810 GlobalFunction function = link.data;
5811 DataRow row = membersList.AddString(link /*function*/.name);
5812 row.icon = icons[typeMethod];
5816 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5818 if(recurse != 2 && listClasses)
5820 if(!membersList.FindString(ns->name))
5822 DataRow row = membersList.AddString(ns->name);
5823 row.icon = icons[typeNameSpace];
5828 ListNameSpace(ns, 2, listClasses);
5832 void ListEnumValues(Class _class)
5834 List<Class> classes { };
5835 for(; _class && _class.type == enumClass; _class = _class.base)
5836 classes.Insert(null, _class);
5837 for(_class : classes)
5839 EnumClassData enumeration = (EnumClassData)_class.data;
5841 for(item = enumeration.values.first; item; item = item.next)
5843 DataRow row = membersList.AddString(item.name);
5844 row.icon = icons[typeEnumValue];
5850 bool ListEnumsModule(Module mainModule, Type dest)
5852 bool result = false;
5854 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5855 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5856 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5857 for(module = mainModule.application.allModules.first; module; module = module.next)
5859 if(ModuleVisibility(mainModule, module))
5860 result |= ListEnums(module.publicNameSpace, dest);
5865 void ListNameSpaceByString(Module mainModule, char * string)
5867 NameSpace * nameSpace;
5869 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5870 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5871 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5872 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5873 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5874 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5875 for(module = mainModule.application.allModules.first; module; module = module.next)
5877 if(ModuleVisibility(mainModule, module))
5879 nameSpace = FindNameSpace(module.publicNameSpace, string);
5880 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5885 bool ListEnums(NameSpace nameSpace, Type dest)
5888 bool result = false;
5890 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5892 Class _class = link.data;
5893 if(_class.type == enumClass && (dest.kind != classType || !dest._class || dest._class.registered != _class))
5895 OldList conversions { };
5897 type.kind = classType;
5898 type._class = FindClass(_class.name);
5899 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5901 ListEnumValues(_class);
5904 conversions.Free(null);
5908 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5910 result |= ListEnums(nameSpace, dest);
5915 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5919 for(c = 0; (ch = name[c]); c++)
5921 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5923 NameSpace * newSpace;
5924 char * spaceName = new char[c - start + 1];
5925 memcpy(spaceName, name + start, c - start);
5926 spaceName[c-start] = '\0';
5927 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5931 nameSpace = newSpace;
5940 return (NameSpace *)nameSpace;
5943 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5945 bool listedEnums = false;
5946 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5947 bool listClasses = true;
5949 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5951 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5952 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5953 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5955 if(exp.type == identifierExp)
5956 id = realIdentifier;
5958 if(id && id._class && !id._class.name)
5960 listClasses = false;
5963 else if(id && id._class && id._class.name)
5967 Class _class = id.classSym.registered;
5968 if(_class && _class.type == enumClass)
5970 ListEnumValues(_class);
5973 ListClassMembers(id.classSym.registered, true);
5978 else if(id && colons)
5980 ListNameSpaceByString(this.privateModule, id.string);
5985 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
5987 listedEnums = ListEnumsModule(this.privateModule, destType);
5990 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
5992 ListEnumValues(destType._class.registered);
5995 ListClassPropertiesAndVirtual(insideClass, null);
5999 else if(destType && destType.kind == enumType)
6003 for(value = destType.members.first; value; value = value.next)
6005 DataRow row = membersList.AddString(value.name);
6006 row.icon = icons[typeEnumValue];
6010 ListClassPropertiesAndVirtual(insideClass, null);
6014 else if(insideClass && !enumOnly)
6016 ListClassPropertiesAndVirtual(insideClass, string);
6019 if(listedEnums && string && string[0])
6021 DataRow row = membersList.FindSubString(string);
6023 listedEnums = false;
6026 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6028 ListClassMembersMatch(GetThisClass(), exp.destType);
6030 else if(!insideClass && !enumOnly && !listedEnums)
6033 Symbol symbol = null;
6037 ListClassMembers(GetThisClass(), false);
6040 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6042 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6044 // Don't list enum values?
6045 //if(symbol.type.kind != TypeEnum)
6046 DataRow row = membersList.FindString(symbol.string);
6049 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6051 row = membersList.AddString(symbol.string);
6052 if(symbol.type && symbol.type.kind == functionType)
6053 row.icon = icons[typeMethod];
6054 else if(symbol.type && symbol.type.kind == enumType)
6056 row.icon = icons[typeEnumValue];
6060 BitmapResource bitmap = null;
6061 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6063 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6066 bitmap = { bitmapName };
6067 membersList.AddResource(bitmap);
6070 row.icon = bitmap ? bitmap : icons[typeData];
6077 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6079 DataRow row = membersList.FindString(symbol.string);
6082 row = membersList.AddString(symbol.string);
6083 if(symbol.type.kind == functionType)
6084 row.icon = icons[typeMethod];
6085 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6087 row.icon = icons[typeClass];
6091 row.icon = icons[typeDataType];
6098 ListModule(this.privateModule, 1, listClasses);
6099 // TODO: Implement this with name space
6103 for(data = globalData.first; data; data = data.next)
6105 DataRow row = membersList.FindString(data.name);
6107 data.dataType = ProcessTypeString(data.dataTypeString, false);
6110 row = membersList.AddString(data.name);
6112 if(data.dataType && data.dataType.kind == TypeEnum)
6114 row.icon = icons[typeEnumValue];
6118 BitmapResource bitmap = null;
6119 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6121 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6124 bitmap = { bitmapName };
6125 membersList.AddResource(bitmap);
6128 row.icon = bitmap ? bitmap : icons[typeData];
6136 DataRow row = membersList.AddString("Min");
6137 row.icon = icons[typeMethod];
6139 row = membersList.AddString("Max");
6140 row.icon = icons[typeMethod];
6142 row = membersList.AddString("Abs");
6143 row.icon = icons[typeMethod];
6145 row = membersList.AddString("Sgn");
6146 row.icon = icons[typeMethod];
6152 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6154 EditBoxStream f { editBox = editBox };
6159 updatingCode = true;
6161 if(!method.dataType)
6162 method.dataType = ProcessTypeString(method.dataTypeString, false);
6164 DeleteJunkBefore(f, function.loc.start.pos, &position);
6165 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6167 // ADDING METHOD HERE
6169 Type dataType = method.dataType;
6170 Type returnType = dataType.returnType;
6172 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6178 if(extraIndent) f.Printf(" ");
6180 OutputType(f, returnType, false);
6184 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6186 if(dataType.thisClass.shortName)
6187 f.Printf(dataType.thisClass.shortName);
6189 f.Printf(dataType.thisClass.string);
6192 f.Printf(method.name);
6194 for(param = dataType.params.first; param; param = param.next)
6196 // Decided not to write void...
6197 if(param.kind != voidType)
6199 OutputType(f, param, true);
6205 if(extraIndent) f.Printf(" ");
6206 f.Printf(" %c\n", OpenBracket);
6208 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6214 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6215 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6217 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6219 if(extraIndent) f.Printf(" ");
6220 f.Printf(" return true;\n");
6222 else if(returnType && returnType.kind != voidType)
6224 if(extraIndent) f.Printf(" ");
6225 f.Printf(" return 0;\n");
6230 if(extraIndent) f.Printf(" ");
6232 if(returnType.kind != voidType)
6233 f.Printf("return ");
6234 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6235 for(param = dataType.params.first; param; param = param.next)
6237 if(param.prev) f.Printf(", ");
6238 if(param.kind != voidType)
6239 f.Printf(param.name);
6245 if(extraIndent) f.Printf(" ");
6246 f.Printf(" %c", CloseBracket);
6251 if(extraIndent) { x1 += 3; x2 += 3; }
6252 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6254 this.updatingCode = false;
6258 // Return false if we overrided a function and don't want to run params listing
6259 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6261 bool didOverride = false;
6262 EditLine line = editBox.line;
6263 char * text = line.text;
6264 int lineNum, charPos;
6265 Expression exp = null;
6268 //Identifier id = null;
6269 Expression memberExp = null;
6270 Identifier realIdentifier = null;
6272 if(!parsing) return true;
6273 if(!privateModule) return !didOverride;
6275 insideFunction = null;
6277 charPos = editBox.charPos + 1;
6278 if(!membersListShown)
6283 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6285 EditBoxStream f { editBox = editBox };
6287 updatingCode = true;
6288 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6292 if(!f.Seek(-1, current))
6295 if(!isspace(ch)) break;
6296 f.Seek(-1, current);
6298 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6300 lineNum = editBox.lineNumber + 1;
6301 charPos = editBox.charPos + 1;
6303 updatingCode = false;
6306 if(!membersListShown)
6308 memberExp = FindExpTree(ast, lineNum, charPos);
6309 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6314 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6316 EditBoxStream f { editBox = editBox };
6319 updatingCode = true;
6321 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6324 if(ch == '}' || ch == ',' || ch == ')')
6326 f.Seek(-1, current);
6334 if(!f.Seek(-1, current))
6337 if(!isspace(ch)) break;
6338 f.Seek(-1, current);
6342 f.Seek(-1, current);
6344 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6346 lineNum = editBox.lineNumber + 1;
6347 charPos = editBox.charPos + 1;
6349 updatingCode = false;
6352 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6357 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6358 lineNum = editBox.lineNumber + 1;
6359 charPos = editBox.charPos/* + 1*/;
6363 char tempString[1024];
6364 char * string = null;
6365 CodePosition idStart, idEnd;
6367 if(membersListShown)
6369 char * buffer = membersLine.text;
6371 bool firstChar = true;
6373 string = tempString;
6375 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6377 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6378 if(!isSpace) firstChar = false;
6380 string[len++] = buffer[c];
6384 else //if(realIdentifier)//if(id)
6387 char * buffer = id.string;
6389 bool firstChar = true;
6391 string = tempString;
6392 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6394 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6395 if(!isSpace) firstChar = false;
6397 string[len++] = buffer[c];
6403 EditLine editLine = editBox.line;
6404 bool firstChar = true;
6407 string = tempString;
6408 for(y = lineNum-1; y >= 0; y--)
6410 char * buffer = editLine.text;
6411 int lineCount = editLine.count;
6412 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6414 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6419 idEnd.charPos = x + 2;
6424 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6427 idEnd.charPos = x + 2;
6434 if(!isalnum(buffer[x]) && buffer[x] != '_')
6440 memmove(string+1, string, len++);
6441 string[0] = buffer[x];
6445 //if(done || firstChar)
6446 if(done || !firstChar)
6448 editLine = editLine.prev;
6451 if(!strcmp(string, "case"))
6457 else if(!strcmp(string, "return"))
6463 else if(!strcmp(string, "delete"))
6469 else if(!strcmp(string, "new"))
6475 else if(!strcmp(string, "renew"))
6483 idStart.charPos = x + 1;
6484 idStart.line = y + 1;
6487 if(!membersListShown)
6489 membersList.Clear();
6490 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6492 Type type = memberExp.member.exp.expType;
6493 if(pointer == 2 && type)
6495 if(type.kind == pointerType || type.kind == arrayType)
6504 ListSymbols(exp, enumOnly, string, realIdentifier);
6506 membersList.Sort(null, 1);
6511 // Virtual function override
6512 Identifier id = GetDeclId(insideFunction.declarator);
6513 char * string = id ? id.string : null;
6515 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6518 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6519 insideFunction = null;
6522 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6527 if(!didOverride) //insideFunction)
6529 rowCount = membersList.rowCount;
6532 DataRow row = string ? membersList.FindSubString(string) : null;
6533 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6535 char * newString = row.string;
6536 if(!membersListShown)
6538 membersLoc.start.line = idStart.line-1;
6539 membersLoc.start.charPos = idStart.charPos-1;
6540 //membersLoc.end = membersLoc.start;
6541 membersLoc.end.charPos = idEnd.charPos-1;
6542 membersLoc.end.line = idEnd.line-1;
6543 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6544 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6549 membersList.Destroy(0);
6550 membersListShown = false;
6553 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6555 line, membersLoc.start.line, membersLoc.start.charPos,
6556 line, membersLoc.end.line, membersLoc.end.charPos);
6557 editBox.PutS(newString);
6563 row = membersList.FindSubStringi(string);
6565 membersList.currentRow = row;
6566 membersList.currentRow.selected = false;
6569 membersList.currentRow = row;
6571 if(!membersListShown)
6575 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6576 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6577 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6578 editBox.GetCaretPosition(caret);
6579 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6581 membersList.master = this;
6583 caret.y += editBox.GetCaretSize();
6585 membersList.Create();
6588 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6589 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6590 Window parent = membersList.parent;
6592 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6594 y -= editBox.GetCaretSize() + membersList.size.h;
6595 membersAbove = true;
6598 membersAbove = false;
6600 membersList.position = { x, y };
6604 membersLoc.start.line = lineNum - 1;
6606 if(string && string[0])
6608 membersLoc.start.charPos = idStart.charPos-1;
6609 membersLoc.end = membersLoc.start;
6610 //membersLoc.end.charPos = id.loc.end.charPos-1;
6611 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6615 membersLoc.start.charPos = charPos;
6616 membersLoc.end = membersLoc.start;
6617 membersLoc.end.charPos = charPos;
6619 membersListShown = true;
6621 // Hack to keep caret shown
6622 editBox.GetCaretPosition(caret);
6623 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6626 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6632 SetCurrentContext(globalContext);
6635 return !didOverride;
6638 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6640 EditLine line = editBox.line;
6641 char * text = line.text;
6642 int lineNum, charPos;
6643 Expression exp = null;
6647 if(!parsing) return;
6649 charPos = editBox.charPos + 1;
6652 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6654 EditBoxStream f { editBox = editBox };
6657 updatingCode = true;
6658 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6661 if(ch == '}' || ch == ',' || ch == ')')
6663 f.Seek(-1, current);
6671 if(!f.Seek(-1, current))
6674 if(!isspace(ch)) break;
6675 f.Seek(-1, current);
6679 f.Seek(-1, current);
6681 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6683 lineNum = editBox.lineNumber + 1;
6684 charPos = editBox.charPos + 1;
6686 updatingCode = false;
6689 charPos = Min(charPos, l1.count + 1);
6691 FindParamsTree(ast, lineNum, charPos);
6693 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6694 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6696 ::functionType = null;
6697 ::instanceType = null;
6700 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6701 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6705 Window parent = paramsList.parent;
6707 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6710 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6711 // ( Dummy exp: always ends up with same memory)
6713 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6714 editBox.GetCaretPosition(paramsPosition);
6715 this.paramsPosition.y += editBox.GetCaretSize();
6718 FreeType(this.functionType);
6719 FreeType(this.instanceType);
6721 this.functionType = ::functionType;
6722 this.instanceType = ::instanceType;
6724 if(this.functionType) this.functionType.refCount++;
6725 if(this.instanceType) this.instanceType.refCount++;
6727 this.paramsID = ::paramsID;
6728 functionExp = paramsInsideExp;
6730 paramsList.master = this;
6732 paramsList.Create();
6734 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6735 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6737 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6739 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6743 paramsAbove = false;
6744 if(x + paramsList.size.w > parent.clientSize.w)
6746 x = parent.clientSize.w - paramsList.size.w;
6750 paramsList.position = { x, y };
6752 // Hack to keep caret shown
6755 editBox.GetCaretPosition(caret);
6756 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6759 this.paramsShown = true;
6761 else if((!::functionType && !::instanceType) || reposition)
6763 paramsList.Destroy(0);
6764 paramsShown = false;
6766 FreeType(this.functionType);
6767 FreeType(this.instanceType);
6768 this.functionType = null;
6769 this.instanceType = null;
6773 SetCurrentContext(globalContext);
6781 designer.visible = true;
6782 designer.Activate();
6788 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6790 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };