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 editBox.syntaxHighlighting && !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, true, 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 == ctrlSpace)
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, true, false);
1398 node = ide.projectView.GetNodeFromWindow(this, null, true, 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))
1501 if(editor.paramsShown)
1505 editor.paramsList.Destroy(0);
1506 editor.paramsShown = false;
1508 if(editor.membersListShown)
1512 editor.membersList.Destroy(0);
1513 editor.membersListShown = false;
1516 FreeType(editor.functionType);
1517 editor.functionType = null;
1519 FreeType(editor.instanceType);
1520 editor.instanceType = null;
1522 editor.paramsID = -1;
1527 return editor.editBox.OnKeyDown(key, ch);
1531 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1533 CodeEditor editor = (CodeEditor)master;
1534 Window rw = previous ? previous.rootWindow : null;
1535 if(!active && rw != editor.paramsList)
1538 editor.membersListShown = false;
1540 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1543 bool OnKeyHit(Key key, unichar ch)
1545 CodeEditor editor = (CodeEditor) master;
1549 case enter: case tab:
1551 DataRow row = currentRow;
1552 if(row && row.selected)
1554 char * string = row.string;
1556 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1557 editor.editBox.Delete(
1558 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1559 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1560 editor.editBox.PutS(string);
1563 editor.membersListShown = false;
1566 editor.editBox.OnKeyHit(key, ch);
1576 return ListBox::OnKeyHit(key, ch);
1582 // If before . or after
1583 //listBox.Destroy(true);
1584 result = editor.editBox.OnKeyHit(key, ch);
1599 clickThrough = true,
1601 borderStyle = contour,
1603 background = { 255,255,225 },
1605 OnKeyDown = membersList.OnKeyDown;
1607 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1609 CodeEditor editor = (CodeEditor)master;
1610 Window rw = previous ? previous.rootWindow : null;
1611 if(!active && previous != editor.editBox && rw != editor.membersList)
1614 editor.paramsShown = false;
1616 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1619 bool OnKeyHit(Key key, unichar ch)
1621 CodeEditor editor = (CodeEditor)master;
1623 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1626 bool result = true; editor.editBox.OnKeyHit(key, ch);
1627 return (!created) ? false : result;
1634 void OnRedraw(Surface surface)
1636 CodeEditor editor = (CodeEditor) master;
1637 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1639 Type methodType = null;
1643 int functionW, nameW = 0;
1645 int spaceW, spaceH, commaW, commaWB, parW;
1647 int maxW = 0, lineW = 0;
1653 Font font = editor.normalFont.font;
1654 Font boldFont = editor.boldFont.font;
1655 Display display = this.display;
1657 if(!type) { return; };
1659 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1661 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1662 display.FontExtent(font, ", ", 2, &commaW, null);
1663 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1664 display.FontExtent(font, ")", 1, &parW, null);
1667 if(editor.functionType)
1669 PrintType(type.returnType, string, true, true);
1670 display.FontExtent(font, string, strlen(string), &functionW, null);
1672 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1673 totalW = nameW + functionW + 2 * parW;
1677 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1678 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1679 if(instanceName && type.kind != functionType)
1680 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1681 totalW = functionW + nameW;
1682 surface.TextFont(boldFont);
1685 surface.WriteText(x, y, string, strlen(string));
1686 x += functionW + spaceW;
1688 if(editor.functionType)
1691 surface.WriteText(x, y, type.name, strlen(type.name));
1693 surface.WriteText(x, y, "(", 1);
1696 if(methodType && !methodType.staticMethod && methodType.methodClass)
1700 if(id == editor.paramsID)
1701 surface.TextFont(boldFont);
1703 if(methodType.methodClass)
1704 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1708 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1709 width += ((id == editor.paramsID) ? commaWB : commaW);
1714 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1719 x = 2 + nameW + spaceW + functionW + parW;
1723 if(methodType.methodClass)
1724 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1727 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1729 surface.WriteText(x, y, ",", 1);
1730 x += ((id == editor.paramsID) ? commaWB : commaW);
1738 if(id == editor.paramsID)
1739 surface.TextFont(font);
1743 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1745 for(param = type.params.first; param; param = param.next)
1747 char paramString[1024];
1750 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1751 surface.TextFont(boldFont);
1754 PrintType(param, paramString, true, true);
1755 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1757 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1762 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1767 x = 2 + nameW + spaceW + functionW + parW;
1771 surface.WriteText(x, y, paramString, strlen(paramString));
1775 surface.WriteText(x, y, ",", 1);
1776 x += ((id == editor.paramsID) ? commaWB : commaW);
1784 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1785 surface.TextFont(font);
1790 surface.WriteText(x, y, ")", 1);
1792 else if(instanceName && type.kind != functionType)
1794 surface.WriteText(x, y, instanceName, strlen(instanceName));
1798 bool OnResizing(int * w, int * h)
1800 CodeEditor editor = (CodeEditor) master;
1801 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1803 Type methodType = null;
1807 int functionW = 0, nameW = 0;
1809 int spaceW, spaceH, commaW, commaWB, parW;
1811 int maxW = 0, lineW = 0;
1816 Font font = editor.normalFont.font;
1817 Font boldFont = editor.boldFont.font;
1818 Display display = this.display;
1820 if(type.kind == TypeKind::methodType)
1823 ProcessMethodType(type.method);
1824 type = type.method.dataType;
1827 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1828 display.FontExtent(font, ", ", 2, &commaW, null);
1829 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1830 display.FontExtent(font, ")", 1, &parW, null);
1833 if(editor.functionType && type)
1835 PrintType(type.returnType, string, true, true);
1836 display.FontExtent(font, string, strlen(string), &functionW, null);
1838 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1839 totalW = nameW + spaceW + functionW + 2 * parW;
1843 PrintType(type, string, false, true); // /*true);
1844 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1845 if(instanceName && type.kind != functionType)
1846 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1847 totalW = functionW + nameW + spaceW;
1850 if(editor.functionType)
1856 if(methodType.methodClass)
1857 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1858 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1859 width += ((id == editor.paramsID) ? commaWB : commaW);
1864 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1877 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1879 for(param = type.params.first; param; param = param.next)
1881 char paramString[1024];
1885 PrintType(param, paramString, true, true);
1886 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1888 width += ((id == editor.paramsID) ? commaWB : commaW);
1893 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1910 *w = realW + totalW + 4;
1916 Menu fileMenu { menu, $"File", f }; // MenuPlacement?
1917 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1918 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1920 Menu debugMenu { menu, $"Debug", d }; // MenuPlacement?
1921 MenuItem debugRunToCursor
1923 debugMenu, $"Run To Cursor", c, Key { f10, ctrl = true };
1924 bool NotifySelect(MenuItem selection, Modifiers mods)
1926 ProjectView projectView = ide.projectView;
1927 if(!projectView.buildInProgress)
1929 int line = editBox.lineNumber + 1;
1932 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1933 ProjectConfig config = projectView.project.config;
1934 int bitDepth = ide.workspace.bitDepth;
1935 bool useValgrind = ide.workspace.useValgrind;
1936 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, false, false);
1943 MenuItem debugSkipRunToCursor
1945 debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true };
1946 bool NotifySelect(MenuItem selection, Modifiers mods)
1948 ProjectView projectView = ide.projectView;
1949 int line = editBox.lineNumber + 1;
1952 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1953 ProjectConfig config = projectView.project.config;
1954 int bitDepth = ide.workspace.bitDepth;
1955 bool useValgrind = ide.workspace.useValgrind;
1956 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, true, false);
1962 MenuItem debugSkipRunToCursorAtSameLevel
1964 debugMenu, $"Run To Cursor At Same Level Skipping Breakpoints", l, Key { f10, alt = true };
1965 bool NotifySelect(MenuItem selection, Modifiers mods)
1967 ProjectView projectView = ide.projectView;
1968 int line = editBox.lineNumber + 1;
1971 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1972 ProjectConfig config = projectView.project.config;
1973 int bitDepth = ide.workspace.bitDepth;
1974 bool useValgrind = ide.workspace.useValgrind;
1975 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, true, true);
1981 MenuDivider { debugMenu };
1982 MenuItem debugToggleBreakpoint
1984 debugMenu, $"Toggle Breakpoint", t, f9;
1985 bool NotifySelect(MenuItem selection, Modifiers mods)
1987 ProjectView projectView = ide.projectView;
1988 if(projectView && fileName)
1990 int line = editBox.lineNumber + 1;
1992 if(ide && ide.workspace)
1994 for(p : ide.workspace.projects)
1996 if(p.topNode.FindByFullPath(fileName, false))
2004 for(p : ide.workspace.projects)
2006 if(IsPathInsideOf(fileName, p.topNode.path))
2014 ide.debugger.ToggleBreakpoint(fileName, line, prj);
2024 //MenuItem viewDesignerItem, viewProperties, viewMethods;
2028 designer.parent = parent;
2031 toolBox = ((IDEWorkSpace)master).toolBox;
2033 // Debugger bug here: value of toolBox appears as 0
2035 sheet = ((IDEWorkSpace)master).sheet;
2040 bool OnClose(bool parentClosing)
2044 if(ide.workspace && fileName)
2045 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2046 if(inUseDebug && !debugClosing)
2048 debugClosing = true;
2050 if(CloseConfirmation(false))
2053 OnFileModified({ modified = true }, null);
2055 debugClosing = false;
2058 if(designer && !designer.closing)
2060 if(designer.visible)
2067 //Window formEditor = designer;
2068 //formEditor.Destroy(0);
2071 ide.AdjustFileMenus();
2076 void OnDestroy(void)
2078 ObjectInfo oClass, next;
2079 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2081 FreeType(this.functionType);
2082 FreeType(this.instanceType);
2087 designer.codeEditor = null;
2088 designer.Destroy(0);
2092 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2094 ObjectInfo object, next;
2096 for(object = oClass.instances.first; object; object = next)
2101 Designer::DestroyObject(object.instance);
2102 delete object.instance;
2104 sheet.DeleteObject(object);
2106 oClass.instances.Delete(object);
2110 Designer::DestroyObject(oClass.instance);
2111 delete oClass.instance;
2113 sheet.DeleteObject(oClass);
2115 classes.Delete(oClass);
2118 if(windowClass && windowClass.data)
2119 UnapplySkin(windowClass);
2123 if(sheet.codeEditor == this)
2125 sheet.codeEditor = null;
2126 toolBox.codeEditor = null;
2132 ProjectView projectView = ide.projectView;
2135 ProjectNode node = projectView.GetNodeFromWindow(this, null, false, false);
2136 if(node && node.modified)
2138 node.modified = false;
2139 projectView.Update(null);
2145 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2147 // 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
2149 if(directActivation)
2150 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2152 if(active && directActivation)
2154 AdjustDebugMenus(ide.areDebugMenusUnavailable, ide.isBreakpointTogglingUnavailable, ide.isDebuggerExecuting);
2156 openedFileInfo.Activate();
2160 Location * loc = null;
2161 UpdateFormCode(); // To ensure update when modifying properties...
2163 // Got to the right spot in code so we don't lose our form selection...
2166 if(selected.instCode)
2167 loc = &selected.instCode.loc;
2168 else if(selected.classDefinition)
2169 loc = &selected.classDefinition.loc;
2171 line = editBox.lineNumber + 1;
2172 charPos = editBox.charPos + 1;
2177 if(selected && !loc->Inside(line, charPos))
2179 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2180 line = editBox.lineNumber + 1;
2181 charPos = editBox.charPos + 1;
2183 else if(selected && selected.classDefinition)
2186 for(object = selected.instances.first; object; object = object.next)
2190 if(object.instCode.loc.Inside(line, charPos))
2196 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2197 line = editBox.lineNumber + 1;
2198 charPos = editBox.charPos + 1;
2203 ProcessCaretMove(editBox, line, charPos);
2208 if(membersListShown)
2210 membersList.Destroy(0);
2211 membersListShown = false;
2215 paramsList.Destroy(0);
2216 paramsShown = false;
2217 FreeType(functionType);
2218 FreeType(instanceType);
2220 functionType = null;
2221 instanceType = null;
2228 bool OnSaveFile(char * fileName)
2235 f = FileOpen(fileName, write);
2238 if(!ide.projectView)
2239 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2243 this.fileName = fileName; // Put this here because the form designer will check for it...
2244 designer.fileName = fileName;
2245 designer.modifiedDocument = false;
2247 editBox.Save(f, false);
2248 modifiedDocument = false;
2256 bool OnFileModified(FileChange fileChange, char * param)
2258 bool reload = false;
2259 if(visible == false && inUseDebug == true)
2265 sprintf(message, $"The document %s was modified by another application.\n"
2266 "Would you like to reload it and lose your changes?", fileName);
2267 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2268 contents = message }.Modal() == yes)
2274 File f = FileOpen(fileName, read);
2277 int lineNumber, charPos, len;
2281 updatingCode = true;
2282 lineNumber = editBox.lineNumber;
2283 charPos = editBox.charPos;
2284 scroll = editBox.scroll;
2287 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2288 len = strlen(editBox.line.text);
2289 editBox.GoToLineNum(lineNumber);
2290 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2291 editBox.scroll = scroll;
2292 updatingCode = false;
2293 loadingFile = false;
2295 codeModified = true;
2299 designer.modifiedDocument = false;
2301 modifiedDocument = false;
2309 void OnRedraw(Surface surface)
2312 surface.SetBackground(marginColor);
2313 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2314 if(ideSettings.showLineNumbers)
2316 int currentLineNumber;
2321 surface.textOpacity = false;
2322 surface.font = font.font;
2323 surface.TextExtent(" ", 1, null, &spaceH);
2324 currentLineNumber = editBox.scroll.y / spaceH + 1;
2326 surface.SetForeground(lineNumbersColor);
2327 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2329 // Highlight current line
2330 if(editBox.lineNumber == currentLineNumber - 1)
2332 surface.SetBackground(selectedMarginColor);
2333 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2334 surface.SetBackground(marginColor);
2336 sprintf(lineText,"%5u ", currentLineNumber % 100000);
2337 if(currentLineNumber <= editBox.numLines)
2338 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,6);
2340 currentLineNumber++;
2344 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2346 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2347 int lineCursor, lineTopFrame, breakpointLines[128];
2348 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2349 Debugger debugger = ide.debugger;
2350 BitmapResource bmpRes;
2352 boxH = clientSize.h;
2353 scrollY = editBox.scroll.y;
2354 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2356 bpOnCursor = bpOnTopFrame = false;
2357 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2360 for(i = 0; i < count; i++)
2362 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2364 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2365 if(breakpointLines[i] == lineCursor)
2367 if(breakpointLines[i] == lineTopFrame)
2368 bpOnTopFrame = true;
2371 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2373 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2376 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2377 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2378 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2380 if(editBox.anchor.left.distance)
2382 if(editBox.horzScroll && editBox.horzScroll.visible)
2384 surface.SetBackground(control);
2385 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2390 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2395 lineY = (line - 1) * lineH;
2396 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2398 Bitmap bitmap = resource.bitmap;
2400 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2407 char ext[MAX_EXTENSION];
2408 char * fileName = property::fileName;
2410 if(SearchString(fileName, 0, "Makefile", false, true))
2411 editBox.useTab = true;
2412 designer.fileName = fileName;
2416 GetExtension(fileName, ext);
2418 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2419 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2420 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2421 editBox.syntaxHighlighting = true;
2423 editBox.syntaxHighlighting = false;
2425 if(parsing && !strcmpi(ext, "ec"))
2427 codeModified = true;
2433 display.FontExtent(font.font, " ", 1, &spaceW, null);
2434 editBox.anchor = Anchor
2436 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2437 right = 0, top = 0, bottom = 0
2446 display.FontExtent(font.font, " ", 1, &spaceW, null);
2447 editBox.anchor = Anchor
2449 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2450 right = 0, top = 0, bottom = 0
2455 bool LoadFile(char * filePath)
2457 File f = FileOpen(filePath, read);
2460 // Added this here...
2461 fileName = filePath;
2463 updatingCode = true;
2465 updatingCode = false;
2466 loadingFile = false;
2475 void AdjustDebugMenus(bool unavailable, bool bpNoToggle, bool executing)
2477 debugRunToCursor.disabled = unavailable || executing;
2478 debugSkipRunToCursor.disabled = unavailable || executing;
2479 debugSkipRunToCursorAtSameLevel.disabled = unavailable || executing;
2480 debugToggleBreakpoint.disabled = bpNoToggle;
2486 ProjectView projectView = ide.projectView;
2489 designer.fileName = fileName;
2495 sprintf(title, $"Untitled %d", documentID);
2496 // designer.fileName = CopyString(title);
2497 designer.fileName = title;
2500 AdjustDebugMenus(ide.areDebugMenusUnavailable, ide.isBreakpointTogglingUnavailable, ide.isDebuggerExecuting);
2502 for(c = 0; c < CodeObjectType::enumSize; c++)
2503 icons[c] = BitmapResource { iconNames[c], window = this };
2505 codeModified = true;
2517 selected.modified = true;
2518 selected.oClass.modified = true;
2520 designer.modifiedDocument = true;
2521 modifiedDocument = true;
2522 formModified = true;
2525 /****************************************************************************
2527 ****************************************************************************/
2535 this.defines.Free(FreeModuleDefine);
2536 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2538 FreeExcludedSymbols(this.excludedSymbols);
2539 FreeContext(this.globalContext);
2541 FreeGlobalData(&this.globalData);
2542 FindCtx_Terminate();
2543 FindParams_Terminate();
2545 if(GetGlobalContext() == globalContext)
2547 SetGlobalData(null);
2548 SetGlobalContext(null);
2549 SetExcludedSymbols(null);
2550 SetTopContext(null);
2551 SetCurrentContext(null);
2554 SetPrivateModule(null);
2557 if(this.privateModule)
2559 FreeTypeData(this.privateModule);
2560 delete this.privateModule;
2561 this.privateModule = null;
2567 static bool reentrant = false;
2572 char * selectedClassName = null, * selectedName = null;
2573 int selectedPos = 0;
2574 Designer backDesigner;
2575 char oldWorkDir[MAX_LOCATION];
2576 char mainModuleName[MAX_FILENAME] = "";
2578 ImportedModule module;
2579 char extension[MAX_EXTENSION];
2580 PathBackup pathBackup { };
2582 Time parseCodeStart = GetTime();
2583 Time startTime, startFindClass;
2585 findClassTotalTime = 0;
2586 checkTypeTotalTime = 0;
2587 externalImportTotalTime = 0;
2588 findClassIgnoreNSTotalTime = 0;
2589 findSymbolTotalTime = 0;
2590 //ResetClassFindTime();
2594 // 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)
2595 if(reentrant) return;
2602 selectedClassName = CopyString(oClass.name);
2603 if(selected != oClass)
2605 ObjectInfo object = this.selected;
2606 selectedName = CopyString(object.name);
2610 for(check = this.oClass.instances.first; check; check = check.next)
2622 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2624 FindCtx_Terminate();
2625 FindParams_Terminate();
2627 SetGlobalData(&globalData);
2628 SetGlobalContext(globalContext);
2629 SetExcludedSymbols(&excludedSymbols);
2630 SetTopContext(globalContext);
2631 SetCurrentContext(globalContext);
2632 SetDefines(&defines);
2633 SetImports(&imports);
2634 SetCurrentNameSpace(null);
2637 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2638 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2639 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2640 "/I T:\\ecere\\include /E %s", argv[1]);
2644 ChangeWorkingDir("e:\\ec");
2645 sprintf(command, "gcc -x c -E -");
2646 fileInput = DualPipeOpen({ output = true, input = true }, command);
2647 SetFileInput(fileInput);
2652 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2654 fileInput.Write(buffer, 1, count);
2659 fileInput.CloseOutput();
2663 // TOCHECK: COULDN'T WE CALL FreeParser here?
2665 FreeType(this.functionType);
2666 FreeType(this.instanceType);
2667 this.functionType = null;
2668 this.instanceType = null;
2671 sheet.SelectObject(null);
2677 // We don't want the designer to be notified of selection when deleting rows...
2678 backDesigner = designer;
2683 ObjectInfo _class, next;
2685 for(_class = classes.first; _class; _class = next)
2691 for(;object = _class.instances.first;)
2695 Designer::DestroyObject(object.instance);
2696 delete object.instance;
2698 sheet.DeleteObject(object);
2700 _class.instances.Delete(object);
2704 Designer::DestroyObject(_class.instance);
2705 delete _class.instance;
2707 sheet.DeleteObject(_class);
2709 classes.Delete(_class);
2715 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2716 if(windowClass && windowClass.data)
2717 UnapplySkin(windowClass);
2720 designer = backDesigner;
2723 fileInput = editFile = EditBoxStream { editBox = editBox };
2724 SetFileInput(fileInput);
2732 defines.Free(FreeModuleDefine);
2733 imports.Free(FreeModuleImport);
2735 FreeContext(this.globalContext);
2736 FreeExcludedSymbols(this.excludedSymbols);
2739 FreeGlobalData(&this.globalData);
2741 if(this.privateModule)
2743 FreeTypeData(this.privateModule);
2744 delete this.privateModule;
2748 startTime = GetTime();
2749 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2751 printf("classes.count: %d\n", globalContext.classes.count);
2756 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2757 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2760 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2762 SetPrivateModule(privateModule);
2765 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2766 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2767 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2768 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2769 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2772 fileName = this.fileName;
2774 if(ide.workspace && ide.workspace.projects && fileName)
2776 for(p : ide.workspace.projects)
2778 char path[MAX_LOCATION];
2780 MakePathRelative(fileName, p.topNode.path, path);
2781 MakeSlashPath(path);
2783 pn = p.topNode.FindWithPath(path, false);
2792 project = ide.project;
2794 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2796 ChangeWorkingDir(project.topNode.path);
2798 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2800 GetLastDirectory(fileName, mainModuleName);
2801 GetExtension(mainModuleName, extension);
2803 SetBuildingEcereCom(false);
2804 SetBuildingEcereComModule(false);
2806 // TODO: Get symbolsDir from project settings instead...
2809 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2810 ProjectConfig config = project.config;
2811 int bitDepth = ide.workspace.bitDepth;
2812 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2813 SetSymbolsDir(objDir.dir);
2814 ide.SetPath(true, compiler, config, bitDepth);
2818 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2819 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2823 switch(GetRuntimePlatform())
2825 case win32: SetSymbolsDir("obj/debug.win32"); break;
2826 case tux: SetSymbolsDir("obj/debug.linux"); break;
2827 case apple: SetSymbolsDir("obj/debug.apple"); break;
2829 SetIncludeDirs(null);
2830 SetSysIncludeDirs(null);
2834 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2836 // TODO FIX for configless project
2837 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2839 for(item : ide.project.config.options.preprocessorDefinitions)
2841 if(!strcmp(item, "BUILDING_ECERE_COM"))
2843 SetBuildingEcereCom(true);
2850 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2851 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2852 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2853 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2854 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2855 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2856 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2857 strcmpi(mainModuleName, "Mutex.ec")))
2859 SetBuildingEcereComModule(true);
2862 // Predeclare all classes
2864 char symFile[MAX_FILENAME];
2865 char symLocation[MAX_LOCATION];
2866 ImportedModule module, next;
2868 GetLastDirectory(fileName, symFile);
2869 ChangeExtension(symFile, "sym", symFile);
2871 strcpy(symLocation, GetSymbolsDir());
2872 PathCat(symLocation, symFile);
2874 // if(!GetEcereImported() && !GetBuildingEcereCom())
2875 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2878 startTime = GetTime();
2880 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2882 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2887 startTime = GetTime();
2889 // LoadSymbols(symLocation, normalImport, true);
2890 LoadSymbols(symLocation, preDeclImport, false);
2892 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2895 for(module = defines.first; module; module = next)
2898 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2901 defines.Delete(module);
2906 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2908 SetDefaultDeclMode(privateAccess);
2909 SetDeclMode(privateAccess);
2913 SetDefaultDeclMode(defaultAccess);
2914 SetDeclMode(defaultAccess);
2917 StripExtension(mainModuleName);
2918 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2919 defines.AddName(module);
2922 // SetYydebug(true);
2927 startTime = GetTime();
2928 startFindClass = checkTypeTotalTime;
2932 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2934 CheckDataRedefinitions();
2937 SetIncludeDirs(null);
2938 SetSysIncludeDirs(null);
2949 startTime = GetTime();
2951 PrePreProcessClassDefinitions();
2952 ComputeModuleClasses(privateModule);
2953 PreProcessClassDefinitions();
2954 ProcessClassDefinitions();
2956 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2957 startTime = GetTime();
2962 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2963 startTime = GetTime();
2965 ProcessInstantiations();
2967 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2970 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2972 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2973 if(!windowClass || windowClass.internalDecl)
2976 startTime = GetTime();
2978 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2979 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2980 eModule_Load(this.privateModule, "ecere", privateAccess);
2982 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2985 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2987 if(windowClass && windowClass.data)
2988 ApplySkin(windowClass, app.currentSkin.name, null);
2992 startTime = GetTime();
2994 for(external = ast->first; external; external = external.next)
2996 if(external.type == classExternal)
2998 ClassDefinition _class = external._class;
2999 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
3001 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
3004 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
3006 Instance instance = eInstance_New(regClass);
3007 ObjectInfo classObject
3009 name = CopyString(_class._class.name);
3010 instance = instance;
3011 classDefinition = _class;
3012 oClass = classObject;
3015 classes.Add(classObject);
3019 // Moved this at bottom so that the file dialog doesn't show up in eCom
3020 designer.CreateObject(instance, classObject, true, null);
3021 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
3023 if(_class.definitions)
3027 for(def = _class.definitions->first; def; def = def.next)
3031 case defaultPropertiesClassDef:
3034 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3036 Identifier id = propDef.identifiers->first;
3039 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3042 Class propertyClass = prop.dataTypeClass;
3044 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3045 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3047 FreeType(propDef.initializer.exp.destType);
3048 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3049 ProcessExpressionType(propDef.initializer.exp);
3051 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
3053 Expression computed = CopyExpression(propDef.initializer.exp);
3054 ComputeExpression(computed);
3056 if(computed.isConstant && computed.type == instanceExp && !id.next)
3060 if(computed.instance._class && computed.instance._class.symbol &&
3061 computed.instance._class.symbol.registered &&
3062 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3064 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3066 // This was saved in the control and shouldn't be freed by FreeExpression...
3067 if(propertyClass.type == normalClass)
3068 computed.instance.data = null;
3072 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3073 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3075 String temp = new char[strlen(computed.string)+1];
3076 ReadString(temp, computed.string);
3077 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3081 propDef.variable = true;
3083 FreeExpression(computed);
3087 Expression computed = CopyExpression(propDef.initializer.exp);
3088 ComputeExpression(computed);
3089 if(computed.isConstant)
3091 //if(computed.type == memberExp) computed = computed.member.exp;
3093 if(computed.type == constantExp)
3095 Operand value = GetOperand(computed);
3096 DataValue valueData;
3097 valueData.i64 = value.i64;
3098 SetProperty(prop, instance, valueData);
3100 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3102 String temp = new char[strlen(computed.string)+1];
3103 ReadString(temp, computed.string);
3104 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3109 propDef.variable = true;
3111 FreeExpression(computed);
3115 propDef.variable = true;
3119 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3120 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3121 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3124 // Maintain a list in FunctionDefinition of who is attached to it
3125 for(def = _class.definitions->first; def; def = def.next)
3127 if(def.type == functionClassDef)
3129 ClassFunction function = def.function;
3130 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3132 function.attached.Add(OldLink { data = method });
3142 case declarationClassDef:
3144 Declaration decl = def.decl;
3147 case instDeclaration:
3149 Instantiation inst = decl.inst;
3150 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3151 if(instClass && eClass_GetDesigner(instClass))
3153 Instance control = eInstance_New(instClass);
3158 oClass = classObject;
3162 classObject.instances.Add(object);
3164 // TOCHECK: Why is this needed now?
3165 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3166 def.object = object;
3168 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3170 designer.CreateObject(control, object, false, classObject.instance);
3171 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3181 // Second pass, process instantiation members
3183 for(def = _class.definitions->first; def; def = def.next)
3187 case declarationClassDef:
3189 Declaration decl = def.decl;
3192 case instDeclaration:
3194 Instantiation inst = decl.inst;
3195 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3196 if(instClass && eClass_GetDesigner(instClass))
3199 object = object ? object.next : classObject.instances.first;
3200 control = object.instance;
3204 MembersInit members;
3205 for(members = inst.members->first; members; members = members.next)
3207 switch(members.type)
3209 case dataMembersInit:
3211 if(members.dataMembers)
3214 DataMember curMember = null;
3215 Class curClass = null;
3216 DataMember subMemberStack[256];
3217 int subMemberStackPos = 0;
3219 for(member = members.dataMembers->first; member; member = member.next)
3222 Identifier ident = member.identifiers ? member.identifiers->first : null;
3225 DataMember _subMemberStack[256];
3226 int _subMemberStackPos = 0;
3227 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3231 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3233 if(thisMember && thisMember.memberAccess == publicAccess)
3235 curMember = thisMember;
3236 curClass = curMember._class;
3237 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3238 subMemberStackPos = _subMemberStackPos;
3244 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3245 if(curMember) found = true;
3247 if(found && curMember.isProperty)
3249 Property prop = (Property) curMember;
3250 Class propertyClass = prop.dataTypeClass;
3252 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3254 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3256 FreeType(member.initializer.exp.destType);
3257 member.initializer.exp.destType = MkClassType(propertyClass.name);
3260 ProcessExpressionType(member.initializer.exp);
3262 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3264 Expression computed;
3266 /*char debugExpString[4096];
3267 debugExpString[0] = '\0';
3268 PrintExpression(member.initializer.exp, debugExpString);*/
3270 computed = CopyExpression(member.initializer.exp);
3273 ComputeExpression(computed);
3275 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3277 if(computed.instance.data)
3279 if(computed.instance._class && computed.instance._class.symbol &&
3280 computed.instance._class.symbol.registered &&
3281 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3283 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3285 // This was saved in the control and shouldn't be freed by FreeExpression...
3286 if(propertyClass.type == normalClass)
3287 computed.instance.data = null;
3291 else if(computed.type == identifierExp)
3293 member.variable = true;
3295 if(eClass_GetDesigner(propertyClass))
3298 char * name = computed.identifier.string;
3299 if(!strcmp(name, "this"))
3302 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3303 member.variable = false;
3308 for(check = classObject.instances.first; check; check = check.next)
3309 if(check.name && !strcmp(name, check.name))
3312 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3313 member.variable = false;
3319 else if(computed.type == memberExp)
3321 member.variable = true;
3322 if(computed.member.exp.type == identifierExp)
3324 char * name = computed.member.exp.identifier.string;
3325 if(!strcmp(name, "this"))
3327 char * name = computed.member.member.string;
3330 for(check = classObject.instances.first; check; check = check.next)
3331 if(check.name && !strcmp(name, check.name))
3334 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3335 member.variable = false;
3343 for(check = classObject.instances.first; check; check = check.next)
3345 if(check.name && !strcmp(name, check.name))
3347 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3350 DataValue value { };
3351 GetProperty(getProperty, check.instance, &value);
3352 SetProperty(prop, control, value);
3353 member.variable = false;
3361 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3362 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3364 String temp = new char[strlen(computed.string)+1];
3365 ReadString(temp, computed.string);
3366 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3370 member.variable = true;
3372 FreeExpression(computed);
3377 Expression computed = CopyExpression(member.initializer.exp);
3380 ComputeExpression(computed);
3381 if(computed.isConstant)
3383 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3385 if(!strcmp(propertyClass.dataTypeString, "float"))
3386 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3387 else if(!strcmp(propertyClass.dataTypeString, "double"))
3388 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3390 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3392 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3394 String temp = new char[strlen(computed.string)+1];
3395 ReadString(temp, computed.string);
3396 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3401 member.variable = true;
3403 FreeExpression(computed);
3409 member.variable = true;
3411 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3412 member.initializer.exp.type == memberExp) // identifierExp
3414 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3415 if(method && method.type == virtualMethod)
3418 // Maintain a list in FunctionDefinition of who is attached to it
3419 for(def = _class.definitions->first; def; def = def.next)
3421 if(def.type == functionClassDef)
3423 ClassFunction function = def.function;
3424 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3425 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3427 function.attached.Add(OldLink { data = method });
3428 // Reference this particular instance?
3443 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3454 //designer.CreateObject(instance, classObject, true, null);
3455 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3457 designer.PostCreateObject(instance, classObject, true, null);
3459 //instance.state = Hidden;
3460 //instance.Create();
3461 //instance.SetState(Normal, true, 0);
3470 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3474 // Restore Selection
3475 if(selectedClassName)
3478 for(oClass = classes.first; oClass; oClass = oClass.next)
3480 if(!strcmp(oClass.name, selectedClassName))
3482 this.oClass = oClass;
3486 delete selectedClassName;
3495 for(check = this.oClass.instances.first; check; check = check.next)
3497 if(check.name && !strcmp(check.name, selectedName))
3499 this.selected = check;
3505 if(this.oClass.instances.first)
3506 this.selected = this.oClass.instances.first;
3508 this.selected = this.oClass;
3511 else if(selectedPos == -1 || !this.oClass.instances.count)
3512 this.selected = this.oClass;
3518 if(selectedPos > this.oClass.instances.count)
3520 for(check = this.oClass.instances.first; check; check = check.next)
3522 if(selectedPos == pos++)
3524 this.selected = check;
3532 this.oClass = classes.first;
3533 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3535 delete selectedName;
3536 SetSymbolsDir(null);
3538 if(sheet.codeEditor == this)
3539 sheet.SelectObject(selected);
3542 codeModified = false;
3544 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3547 InvokeParameters(false, false, false);
3550 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3556 ChangeWorkingDir(oldWorkDir);
3558 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3559 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3560 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3561 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3562 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3564 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3566 if(inUseDebug && ide.projectView)
3567 ide.debugger.EvaluateWatches();
3572 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3575 Window control = (Window)object.instance;
3576 ObjectInfo classObject = object.oClass;
3578 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3580 if(!strcmp(_class.name, "DesignerBase")) return;
3582 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3584 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3585 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3587 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3588 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3590 Class dataType = prop.dataTypeClass;
3592 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3596 if(dataType.type == structClass)
3598 void * dataForm = new0 byte[dataType.structSize];
3599 void * dataTest = new0 byte[dataType.structSize];
3601 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3602 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3604 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3606 char tempString[1024] = "";
3608 bool needClass = true;
3612 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3614 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3616 eClass_FindNextMember(_class, curClass, curMember, null, null);
3617 if(*curMember != (DataMember)prop)
3618 f.Printf("%s = ", prop.name);
3620 *curMember = (DataMember)prop;
3621 *curClass = curMember->_class;
3624 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3626 f.Printf("%s", string);
3633 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3635 void * dataForm, * dataTest;
3637 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3638 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3640 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3642 char tempString[1024] = "";
3647 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3649 eClass_FindNextMember(_class, curClass, curMember, null, null);
3650 if(*curMember != (DataMember)prop)
3651 f.Printf("%s = ", prop.name);
3652 *curMember = (DataMember)prop;
3653 *curClass = curMember->_class;
3655 if(eClass_GetDesigner(dataType))
3657 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3658 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3659 f.Printf("this", prop.name);
3662 //ObjectInfo classObject;
3663 //for(classObject = classes.first; classObject; classObject = classObject.next)
3667 for(object = classObject.instances.first; object; object = object.next)
3669 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3671 f.Printf("%s", object.name);
3678 bool needClass = true;
3679 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3680 f.Printf("%s", string);
3687 bool needClass = true;
3688 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3690 if(!strcmp(dataType.dataTypeString, "char *"))
3693 OutputString(f, string);
3697 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3699 f.Printf("%s", string);
3702 *lastIsMethod = false;
3707 DataValue dataForm, dataTest;
3709 GetProperty(prop, control, &dataForm);
3710 GetProperty(prop, test, &dataTest);
3712 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3715 char tempString[1024] = "";
3716 SetProperty(prop, test, dataForm);
3718 if(dataType.type != bitClass)
3720 bool needClass = true;
3722 if(dataType.type == enumClass)
3725 Class enumClass = eSystem_FindClass(privateModule, "enum");
3726 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3728 for(value = e.values.first; value; value = value.next)
3730 if((int)value.data == dataForm.i)
3732 string = value.name;
3738 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3740 if(string && string[0])
3745 eClass_FindNextMember(_class, curClass, curMember, null, null);
3746 if(*curMember != (DataMember)prop)
3747 f.Printf("%s = ", prop.name);
3748 *curMember = (DataMember)prop;
3749 *curClass = curMember->_class;
3751 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3752 f.Printf("%sf", string);
3754 f.Printf("%s", string);
3758 else if(dataType.type == bitClass)
3760 bool needClass = true;
3762 if(*prev) f.Printf(", ");
3764 eClass_FindNextMember(_class, curClass, curMember, null, null);
3765 if(*curMember != (DataMember)prop)
3766 f.Printf("%s = ", prop.name);
3767 *curMember = (DataMember)prop;
3768 *curClass = curMember->_class;
3770 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3772 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3774 f.Printf("%s", string);
3776 *lastIsMethod = false;
3786 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3788 Instantiation inst = object.instCode;
3789 Window control = (Window)object.instance;
3791 bool methodPresent = false;
3793 bool lastIsMethod = true;
3794 ObjectInfo classObject = object.oClass;
3800 // Instance removed, delete it
3801 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3803 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3804 position = inst.loc.end.pos + 1;
3808 bool multiLine = false;
3811 // Check if it's an unnamed instance
3814 f.Seek(inst.nameLoc.start.pos - position, current);
3815 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3816 position = inst.nameLoc.end.pos;
3818 f.Printf(object.name);
3823 if(isspace(ch) && ch != '\n')
3825 f.Seek(-1, current);
3833 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3835 f.Seek(pos - position, current);
3840 f.Seek(-1, current);
3849 f.Puts(object.name);
3854 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3855 methodPresent = true;
3863 if(ch == OpenBracket)
3869 // TODO: Simplify this?
3878 f.Seek(-1, current);
3890 if(ch == '\n') { toDelete = count; count = 0; }
3891 else if(isspace(ch)) count++;
3894 f.Seek(-1, current);
3898 toDelete += count - 6;
3908 f.Seek(-toDelete-count, current);
3909 f.DeleteBytes(toDelete);
3910 f.Seek(count, current);
3915 for(c = 0; c<toAdd; c++)
3921 methodPresent = multiLine;
3924 f.Printf(methodPresent ? "\n " : " ");
3930 // Instance not there, create a brand new one
3931 DeleteJunkBefore(f, position, &position);
3932 f.Printf(*firstObject ? "\n\n" : "\n");
3933 *firstObject = false;
3935 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3936 methodPresent = true;
3941 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3943 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3948 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3950 f.Printf(" %s %c ", control._class.name, OpenBracket);
3956 Instance test = eInstance_New(control._class);
3957 DataMember curMember = null;
3958 Class curClass = null;
3961 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3965 // Attach Method here
3966 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3968 if(prev) f.Printf(", ");
3969 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3974 if(inst && !object.deleted)
3976 MembersInit members;
3977 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3979 DeleteJunkBefore(f, position, &position);
3981 // Instance already there, clear out the properties
3982 for(members = inst.members->first; members; members = members.next)
3984 if(members.type == dataMembersInit)
3988 if(members.dataMembers)
3990 bool keptMember = false;
3991 MemberInit lastKept = null;
3993 for(member = members.dataMembers->first; member; member = member.next)
3995 Identifier ident = member.identifiers ? member.identifiers->first : null;
3996 bool deleted = false;
3998 // For now delete if it's not a method
3999 if(!member.variable) // && ident)
4001 if(!ident || !ident.next)
4003 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
4006 f.Seek(member.loc.start.pos - position, current);
4007 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4008 position = member.loc.end.pos;
4013 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
4014 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
4015 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4017 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
4018 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
4020 f.Seek(member.loc.start.pos - position, current);
4021 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4022 position = member.loc.end.pos;
4034 //f.Seek(member.loc.start.pos - position, current);
4035 //position = member.loc.start.pos;
4036 DeleteJunkBefore(f, member.loc.start.pos, &position);
4037 if(prev) f.Printf(", ");
4038 else if(keptMember) f.Printf(" ");
4043 if(!keptMember || !members.next)
4048 if(keptMember && lastKept != members.dataMembers->last)
4053 f.Seek(-1, current);
4059 f.Seek(-1, current);
4062 else if(!isspace(ch))
4064 f.Seek(-2, current);
4069 f.DeleteBytes(count);
4072 f.Seek(members.loc.end.pos - position, current);
4077 f.Seek(-1, current);
4079 position = members.loc.end.pos + 1;
4083 f.Seek(-1, current);
4084 position = members.loc.end.pos;
4090 lastIsMethod = false;
4095 DeleteJunkBefore(f, position, &position);
4098 if(lastKept != members.dataMembers->last)
4103 f.Seek(-1, current);
4109 f.Seek(-1, current);
4112 else if(!isspace(ch))
4114 f.Seek(-2, current);
4119 f.DeleteBytes(count);
4123 f.Seek(members.loc.end.pos - position, current);
4124 position = members.loc.end.pos;
4128 lastIsMethod = true;
4131 lastIsMethod = false;
4137 f.Seek(members.loc.end.pos - position, current);
4138 position = members.loc.end.pos;
4140 lastIsMethod = true;
4143 else if(members.type == methodMembersInit)
4145 if(this.methodAction == actionDeleteMethod && members.function == function);
4147 methodPresent = true;
4149 // Delete instance method here
4150 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4151 members.function == function)
4153 if(this.moveAttached && !*text)
4154 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4156 DeleteJunkBefore(f, members.loc.start.pos, &position);
4157 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4158 position = members.loc.end.pos + 1;
4163 DeleteJunkBefore(f, position, &position);
4167 DeleteJunkBefore(f, members.loc.start.pos, &position);
4168 lastIsMethod = true;
4172 f.Seek(members.loc.end.pos - position, current);
4173 position = members.loc.end.pos;
4175 DeleteJunkBefore(f, position, &position);
4184 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4186 Method method = this.method;
4187 DeleteJunkBefore(f, position, &position);
4193 if(!method.dataType)
4194 method.dataType = ProcessTypeString(method.dataTypeString, false);
4197 Type dataType = method.dataType;
4198 Type returnType = dataType.returnType;
4201 if(this.moveAttached)
4203 // Move function here:
4204 int newLen = strlen(method.name);
4209 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4211 // First change name of function
4212 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4213 *textSize += newLen - movedFuncIdLen;
4214 memcpy(*text + movedFuncIdPos, method.name, newLen);
4216 // Second, tab right
4219 for(c = 0; (*text)[c]; )
4222 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4225 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4226 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4230 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4240 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4242 // ADDING METHOD HERE
4244 OutputType(f, returnType, false);
4247 if(dataType.thisClass)
4249 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4251 if(dataType.thisClass.shortName)
4252 f.Printf(dataType.thisClass.shortName);
4254 f.Printf(dataType.thisClass.string);
4258 f.Printf(method.name);
4260 for(param = dataType.params.first; param; param = param.next)
4262 OutputType(f, param, true);
4267 f.Printf(" %c\n\n", OpenBracket);
4269 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4271 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4272 f.Printf(" return true;\n");
4273 else if(returnType.kind != voidType)
4274 f.Printf(" return 0;\n");
4279 if(returnType.kind != voidType)
4280 f.Printf("return ");
4281 f.Printf("%s::%s(", control._class.name, method.name);
4282 for(param = dataType.params.first; param; param = param.next)
4284 if(param.prev) f.Printf(", ");
4285 if(param.kind != voidType)
4286 f.Printf(param.name);
4290 f.Printf(" %c\n", CloseBracket);
4296 if(!object.instCode)
4299 f.Printf(" %c;\n", CloseBracket);
4301 f.Printf("%c;\n", CloseBracket);
4303 else if(!object.deleted)
4305 // Turn this into a multiline instance when adding a method
4306 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4308 f.Printf(methodPresent ? "\n " : " ");
4310 f.Seek(inst.loc.end.pos + 1 - position, current);
4311 position = inst.loc.end.pos + 1;
4316 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4319 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4321 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4323 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4325 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4326 if(prop && prop.isProperty && !prop.conversion)
4328 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4329 (!prop.IsSet || prop.IsSet(classObject.instance)))
4331 Class dataType = prop.dataTypeClass;
4332 char tempString[1024] = "";
4334 bool specify = false;
4337 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4338 if(member && member._class == regClass)
4342 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4344 if(dataType && dataType.type == structClass)
4346 void * dataForm = new0 byte[dataType.structSize];
4347 void * dataTest = new0 byte[dataType.structSize];
4349 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4350 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4352 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4354 bool needClass = true;
4356 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4357 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4359 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4361 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4366 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4368 void * dataForm, * dataTest;
4370 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4371 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4373 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4375 char tempString[1024] = "";
4377 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4379 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4381 // Shouldn't go here ...
4382 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4386 bool needClass = true;
4388 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4390 if(!strcmp(dataType.dataTypeString, "char *"))
4392 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4393 OutputString(f, string);
4397 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4399 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4405 DataValue dataForm, dataTest;
4407 GetProperty(prop, classObject.instance, &dataForm);
4408 GetProperty(prop, test, &dataTest);
4410 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4412 SetProperty(prop, test, dataForm);
4413 if(dataType.type == bitClass)
4415 bool needClass = true;
4416 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4418 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4420 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4424 bool needClass = true;
4425 if(dataType.type == enumClass)
4428 Class enumClass = eSystem_FindClass(privateModule, "enum");
4429 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4431 for(value = e.values.first; value; value = value.next)
4433 if((int)value.data == dataForm.i)
4435 string = value.name;
4441 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4442 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4443 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4445 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4454 void UpdateFormCode()
4457 if(!parsing) return;
4464 else if(formModified)
4466 EditBoxStream f { editBox = editBox };
4470 Identifier movedFuncId;
4471 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4472 ObjectInfo classObject;
4478 movedFuncId = GetDeclId(function.declarator);
4479 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4480 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4483 for(classObject = classes.first; classObject; classObject = classObject.next)
4486 ClassDefinition classDef = classObject.classDefinition;
4487 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4490 bool firstObject = true;
4491 ObjectInfo object = classObject.instances.first;
4492 bool lastIsDecl = false;
4494 if(!classObject.modified) continue;
4496 test = eInstance_New(regClass);
4499 // Put it in the same desktop window...
4500 designer.PrepareTestObject(test);
4502 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4503 //f.Printf("%c\n\n", OpenBracket);
4505 // Change the _class name
4506 f.Seek(classDef.nameLoc.start.pos - position, current);
4507 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4508 f.Printf(classObject.name);
4509 position = classDef.nameLoc.end.pos;
4512 // Go to block start, delete all until no white space, put \n
4516 f.Seek(classDef.blockStart.end.pos - position, current);
4517 position = classDef.blockStart.end.pos;
4519 for(; f.Getc(&ch); count++)
4523 f.Seek(-1, current);
4533 f.Seek(-count, current);
4535 f.DeleteBytes(count-back);
4537 position += count-back;
4540 // Output properties
4541 OutputClassProperties(classObject.instance._class, classObject, f, test);
4543 for(def = classDef.definitions->first; def; def = def.next)
4547 case defaultPropertiesClassDef:
4549 bool keptMember = false;
4551 MemberInit lastKept = null;
4554 DeleteJunkBefore(f, def.loc.start.pos, &position);
4557 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4559 Identifier ident = propDef.identifiers->first;
4560 bool deleted = false;
4562 // For now delete if it's a prop
4563 if(!propDef.variable && ident)
4567 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4570 f.Seek(propDef.loc.start.pos - position, current);
4571 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4572 position = propDef.loc.end.pos;
4577 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4578 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4580 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4581 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4583 f.Seek(propDef.loc.start.pos - position, current);
4584 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4585 position = propDef.loc.end.pos;
4603 f.Seek(def.loc.end.pos - position - 1, current);
4608 f.Seek(-1, current);
4611 position = def.loc.end.pos;
4615 if(lastKept != def.defProperties->last)
4620 f.Seek(-1, current);
4626 f.Seek(-1, current);
4629 else if(!isspace(ch))
4631 f.Seek(-2, current);
4636 f.DeleteBytes(count);
4640 f.Seek(def.loc.end.pos - position, current);
4641 position = def.loc.end.pos;
4646 case declarationClassDef:
4648 Declaration decl = def.decl;
4650 if(decl.type == instDeclaration)
4652 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4654 while(def.object && object != def.object)
4656 if(object /*&& ((ObjectInfo)def.object).modified*/)
4657 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4658 object = object.next;
4661 DeleteJunkBefore(f, def.loc.start.pos, &position);
4662 f.Printf(firstObject ? "\n\n " : "\n ");
4663 firstObject = false;
4665 if(def.object && ((ObjectInfo)def.object).modified)
4666 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4668 object = object ? object.next : null;
4672 DeleteJunkBefore(f, def.loc.start.pos, &position);
4673 f.Printf(firstObject ? "\n\n " : "\n ");
4674 firstObject = false;
4680 DeleteJunkBefore(f, def.loc.start.pos, &position);
4681 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4686 case functionClassDef:
4688 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4689 if(!def.function.body) continue;
4693 DeleteJunkBefore(f, def.loc.start.pos, &position);
4696 // Delete _class methods
4697 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4698 def.function == function)
4703 if(moveAttached && !text)
4705 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4708 f.Seek(def.loc.end.pos - position, current);
4709 for(; f.Getc(&ch); count++)
4713 f.Seek(-1, current);
4717 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4719 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4720 position = def.loc.end.pos + count;
4723 // In case of detaching methods in the _class, simply rename the method
4724 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4726 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4727 f.DeleteBytes(movedFuncIdLen);
4729 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4732 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4733 function == def.function)
4735 // In case of attaching methods in the _class, simply rename the method
4736 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4737 position = function.loc.start.pos + movedFuncIdPos;
4738 f.DeleteBytes(movedFuncIdLen);
4739 if(method.dataType.thisClass)
4740 f.Printf("%s::", method.dataType.thisClass.string);
4741 f.Puts(method.name);
4742 position += movedFuncIdLen;
4747 DeleteJunkBefore(f, def.loc.start.pos, &position);
4748 if(def.type == memberAccessClassDef)
4751 firstObject = false;
4761 f.Seek(def.loc.end.pos - position, current);
4762 position = def.loc.end.pos;
4765 // Output attached methods
4766 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4768 DeleteJunkBefore(f, position, &position);
4769 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4772 // ********** INSTANCES ***************
4773 for(; object; object = object.next)
4775 if(!object.instCode)
4777 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4781 DeleteJunkBefore(f, position, &position);
4783 // ****************** METHODS ***********************
4784 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4786 // If detaching an instance method
4787 if(selected != classObject)
4789 int newLen = strlen(methodName);
4792 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4793 // Tab selection left
4796 for(c = 0; text[c]; )
4799 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4800 memmove(text+start, text+start+i, textSize+1-start-i);
4803 for(; text[c] && text[c] != '\n'; c++);
4809 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4810 textSize += newLen - movedFuncIdLen;
4811 memcpy(text + movedFuncIdPos, methodName, newLen);
4818 if(methodAction == actionAddMethod && selected == classObject)
4820 Method method = this.method;
4822 if(!method.dataType)
4823 method.dataType = ProcessTypeString(method.dataTypeString, false);
4825 // ADDING METHOD HERE
4827 Type dataType = method.dataType;
4828 Type returnType = dataType.returnType;
4830 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4834 OutputType(f, returnType, false);
4837 if(dataType.thisClass && !dataType.classObjectType)
4839 if(dataType.thisClass.shortName)
4840 f.Printf(dataType.thisClass.shortName);
4842 f.Printf(dataType.thisClass.string);
4845 f.Printf(method.name);
4847 for(param = dataType.params.first; param; param = param.next)
4849 OutputType(f, param, true);
4854 f.Printf(" %c\n\n", OpenBracket);
4856 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4858 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4859 f.Printf(" return true;\n");
4860 else if(returnType && returnType.kind != voidType)
4861 f.Printf(" return 0;\n");
4866 if(returnType.kind != voidType)
4867 f.Printf("return ");
4869 char * name = ((Specifier)classDef.baseSpecs->first).name;
4870 Symbol _class = FindClass(name);
4871 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4873 for(param = dataType.params.first; param; param = param.next)
4875 if(param.prev) f.Printf(", ");
4876 if(param.kind != voidType)
4877 f.Printf(param.name);
4882 f.Printf(" %c", CloseBracket);
4886 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4898 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4899 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4903 codeModified = false;
4904 formModified = false;
4906 moveAttached = false;
4911 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4914 ClassFunction function = null;
4917 ObjectInfo object = this.selected;
4919 if(object && object == this.oClass)
4921 ClassDefinition classDef = object.oClass.classDefinition;
4923 if(classDef && classDef.definitions)
4925 for(def = classDef.definitions->first; def; def = def.next)
4927 if(def.type == functionClassDef && def.function.declarator)
4929 if(!strcmp(def.function.declarator.symbol.string, methodName))
4931 function = def.function;
4936 else if(def.type == defaultPropertiesClassDef)
4940 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4942 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4943 if(ident && !ident.next)
4945 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4949 propLoc = propDef.loc;
4952 ClassDefinition classDef = object.oClass.classDefinition;
4954 if(classDef.definitions)
4956 for(def = classDef.definitions->first; def; def = def.next)
4958 if(def.type == functionClassDef)
4960 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4962 function = def.function;
4981 Instantiation inst = object.instCode;
4983 // Check here to see if the method already exists, no need to call ModifyCode in that case
4984 if(inst && inst.members)
4986 MembersInit members;
4987 for(members = inst.members->first; members; members = members.next)
4989 switch(members.type)
4991 case dataMembersInit:
4993 if(members.dataMembers)
4996 for(member = members.dataMembers->first; member; member = member.next)
4998 Identifier ident = member.identifiers ? member.identifiers->first : null;
4999 if(ident && !ident.next)
5001 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
5005 propLoc = member.loc;
5008 ClassDefinition classDef = object.oClass.classDefinition;
5010 if(classDef.definitions)
5012 for(def = classDef.definitions->first; def; def = def.next)
5014 if(def.type == functionClassDef)
5016 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
5018 function = def.function;
5027 // TODO: Fix memory leak
5028 function = ClassFunction
5030 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5042 case methodMembersInit:
5044 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5046 function = members.function;
5058 if(functionPtr) *functionPtr = function;
5062 void GoToMethod(char * methodName /*Method method*/)
5066 ObjectInfo object = selected;
5067 EditBoxStream f { editBox = editBox };
5068 ClassFunction function = null;
5069 bool atChar = false;
5073 Location propLoc = { {0,0,-1} };
5076 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5077 if(function && function.body)
5080 f.Seek(function.body.loc.start.pos+1, current);
5090 f.Seek(-1, current);
5095 else if(!isspace(ch))
5097 f.Seek(-1, current);
5103 else if(propLoc.start.pos > -1)
5105 f.Seek(propLoc.start.pos, current);
5108 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5110 if(function || propLoc.start.pos > -1)
5112 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5113 editBox.CenterOnCursor();
5114 SetState(normal, false, 0);
5117 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5119 FreeClassFunction(function);
5125 void FindCompatibleMethods(Method method, OldList compatible)
5127 ClassDefinition classDef = this.oClass.classDefinition;
5128 if(classDef && classDef.definitions)
5131 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5134 Symbol classSym { };
5135 Symbol selectedClass;
5136 if(this.selected == this.oClass)
5137 selectedClass = classSym;
5139 selectedClass = FindClass(this.selected.instance._class.name);
5141 regClass.name = classDef._class.name;
5142 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5143 for(def = classDef.definitions->first; def; def = def.next)
5145 if(def.type == functionClassDef && def.function.declarator)
5147 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5149 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5152 Type type = def.function.declarator.symbol.type;
5153 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5155 compatible.Add(OldLink { data = def.function });
5161 if(this.oClass && this.oClass.instance)
5163 classSym.registered = regClass;
5164 //classSym.registered = this.oClass.oClass;
5166 for(_class = regClass.base; _class; _class = _class.base)
5169 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5171 // TODO: Understand why these functions popup in attach list
5172 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5174 if(!testMethod.dataType)
5175 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5177 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5178 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5179 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5181 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5182 // ClassFunction function { };
5183 FunctionDefinition function { };
5185 function.declarator = Declarator { };
5186 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5187 excludedSymbols.Add(function.declarator.symbol);
5189 compatible.Add(OldLink { data = function });
5200 void AddMethod(Method method)
5204 char methodName[1024];
5205 strcpy(methodName, method.name);
5206 if(!FindMethod(methodName, null, null))
5208 methodAction = actionAddMethod;
5209 this.method = method;
5213 GoToMethod(methodName);
5217 void DeleteMethod(ClassFunction function)
5221 methodAction = actionDeleteMethod;
5222 this.function = function;
5230 void AttachMethod(Method method, ClassFunction function)
5234 // If it's an instance we'll ask if we want to move it inside...
5235 if(!function.attached.count && function.body)
5237 // Find the function in the _class to check if it's a virtual function
5238 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5239 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5240 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5242 for(def = this.classDefinition.first; def; def = def.next)
5244 if(def.type == functionClassDef)
5246 if(def.function == function)
5251 if(!method || method.type != virtualMethod)
5254 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5255 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5257 moveAttached = true;
5262 methodAction = actionAttachMethod;
5263 this.method = method;
5264 this.function = function;
5271 void ReAttachMethod(Method method, ClassFunction function)
5275 // If it's an instance we'll ask if we want to move it inside...
5276 if(!function.attached.count && function.body)
5278 // Find the function in the _class to check if it's a virtual function
5279 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5280 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5281 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5283 for(def = this.classDefinition.first; def; def = def.next)
5285 if(def.type == functionClassDef)
5287 if(def.function == function)
5292 if(!method || method.type != virtualMethod)
5295 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5296 if(MessageBox { type = yesNo, master = parent, text = title,
5297 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5299 moveAttached = true;
5304 methodAction = actionReattachMethod;
5305 this.method = method;
5306 this.function = function;
5313 void DetachMethod(Method method, ClassFunction function, int type)
5321 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5322 master = sheet, text = $"Name detached method", background = formColor
5326 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5327 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5331 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5332 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5336 dialog, anchor = { left = 5, right = 5, top = 5 }
5338 sprintf(methodName, "%s_%s", selected.name, method.name);
5339 nameBox.contents = methodName;
5341 result = dialog.Modal() == ok;
5342 strcpy(methodName, nameBox.contents);
5347 // If the method is not attached, move it outside
5350 // Add this class to the methodName
5351 char name[1024] = "";
5353 if(this.selected != this.oClass && !method.dataType.thisClass)
5355 strcat(name, this.selected.instance._class.name);
5357 strcat(name, this.methodName);
5358 strcpy(this.methodName, name);
5360 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5362 strcat(name, method.dataType.thisClass.string);
5364 strcat(name, this.methodName);
5365 strcpy(this.methodName, name);
5368 this.moveAttached = true;
5371 this.methodAction = actionDetachMethod;
5372 this.method = method;
5373 this.function = function;
5380 void AddObject(Instance instance, ObjectInfo * object)
5384 //*object = _class.instances.Add(sizeof(ObjectInfo));
5385 *object = ObjectInfo { };
5386 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5387 (*object).oClass = oClass;
5388 (*object).instance = instance;
5393 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5395 // if(strcmp(name, this.oClass.instance.name))
5398 for(check = oClass.instances.first; check; check = check.next)
5399 if(!check.deleted && check.name && !strcmp(name, check.name))
5403 (*object).name = CopyString(name);
5408 toolBox.controlClass = null;
5412 //sheet.AddObject(*object, (*object).name, TypeData, true);
5417 void EnsureUpToDate()
5419 if(sheet && codeModified && parsing)
5423 void SelectObject(ObjectInfo object)
5426 oClass = object ? object.oClass : null;
5428 designer.SelectObject(object, object ? object.instance : null);
5431 void SelectObjectFromDesigner(ObjectInfo object)
5434 sheet.SelectObject(object);
5437 void EnumerateObjects(Sheet sheet)
5441 for(oClass = classes.first; oClass; oClass = oClass.next)
5447 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5448 for(object = oClass.instances.first; object; object = object.next)
5449 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5452 sheet.SelectObject(selected);
5457 designer.AddObject();
5460 void DeleteObject(ObjectInfo object)
5462 delete object.instance;
5463 object.deleted = true;
5464 object.modified = true;
5465 object.oClass.modified = true;
5467 if(selected == object)
5469 bool looped = false;
5470 ObjectInfo select = object;
5474 select = select.prev;
5478 select = object.oClass.instances.last;
5485 sheet.SelectObject(select ? select : oClass);
5488 if(!object.instCode && object.oClass != object)
5491 oClass.instances.Delete(object);
5494 if(sheet.codeEditor == this)
5495 sheet.DeleteObject(object);
5498 void RenameObject(ObjectInfo object, char * name)
5502 // Validate the name:
5503 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5504 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5507 for(c = 0; name[c]; c++)
5508 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5516 object.name = (name && name[0]) ? CopyString(name) : null;
5518 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5522 void DesignerModifiedObject()
5524 sheet.ListProperties(false);
5528 void ListSubMembers(Type member)
5532 for(subMember = member.members.first; subMember; subMember = subMember.next)
5536 DataRow row = membersList.AddString(subMember.name);
5537 row.icon = icons[typeData];
5541 ListSubMembers(subMember);
5546 void ListSubDataMembers(DataMember member, bool isPrivate)
5548 DataMember subMember;
5549 for(subMember = member.members.first; subMember; subMember = subMember.next)
5551 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5555 DataRow row = membersList.AddString(subMember.name);
5556 BitmapResource bitmap = null;
5557 if(!subMember.dataType)
5558 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5560 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5562 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5565 bitmap = { bitmapName };
5566 membersList.AddResource(bitmap);
5569 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5573 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5579 void ListClassMembers(Class whatClass, bool methodsOnly)
5582 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5583 bool isPrivate = false;
5585 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5587 Method method, methodIt;
5589 DataMember memberIt;
5591 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5593 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5594 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5596 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5598 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5600 DataRow row = membersList.FindString(method.name);
5603 row = membersList.AddString(method.name);
5605 if(!method.dataType)
5606 method.dataType = ProcessTypeString(method.dataTypeString, false);
5608 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5616 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5620 if(memberIt.isProperty)
5622 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5624 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5628 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5630 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5633 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5639 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5641 if(member.isProperty)
5643 Property prop = (Property) member;
5644 if(!membersList.FindString(prop.name))
5646 DataRow row = membersList.AddString(prop.name);
5647 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5650 else if(member.name && !membersList.FindString(member.name))
5652 DataRow row = membersList.AddString(member.name);
5654 BitmapResource bitmap = null;
5655 if(!member.dataType)
5656 member.dataType = ProcessTypeString(member.dataTypeString, false);
5658 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5660 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5663 bitmap = { bitmapName };
5664 membersList.AddResource(bitmap);
5667 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5670 ListSubDataMembers(member, member.memberAccess == privateAccess);
5674 if(_class.inheritanceAccess == privateAccess)
5677 if(_class.module != privateModule) break;
5682 void ListClassMembersMatch(Class whatClass, Type methodType)
5685 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5686 bool isPrivate = false;
5688 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5694 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5696 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5698 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5700 if(!method.dataType)
5701 method.dataType = ProcessTypeString(method.dataTypeString, false);
5703 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5705 DataRow row = membersList.FindString(method.name);
5708 row = membersList.AddString(method.name);
5709 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5715 if(_class.inheritanceAccess == privateAccess)
5718 if(_class.module != privateModule) break;
5723 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5726 bool isPrivate = false;
5727 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5733 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5735 if(method.type == virtualMethod)
5737 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5739 DataRow row = membersList.FindString(method.name);
5742 row = membersList.AddString(method.name);
5744 if(!method.dataType)
5745 method.dataType = ProcessTypeString(method.dataTypeString, false);
5747 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5753 for(member = _class.membersAndProperties.first; member; member = member.next)
5755 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5757 if(member.isProperty)
5759 Property prop = (Property)member;
5761 DataRow row = membersList.AddString(prop.name);
5762 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5765 else if(member.name && (!curString || strcmp(curString, member.name)))
5767 DataRow row = membersList.AddString(member.name);
5769 BitmapResource bitmap = null;
5770 if(!member.dataType)
5771 member.dataType = ProcessTypeString(member.dataTypeString, false);
5773 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5775 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5778 bitmap = { bitmapName };
5779 membersList.AddResource(bitmap);
5782 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5785 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5788 if(_class.inheritanceAccess == privateAccess)
5791 if(_class.module != privateModule) break;
5796 void ListMembers(Type type)
5798 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5802 if(type.kind == classType)
5805 ListClassMembers(type._class.registered, false);
5810 for(member = type.members.first; member; member = member.next)
5814 DataRow row = membersList.AddString(member.name);
5815 row.icon = icons[typeData];
5817 else if(member.kind == structType || member.kind == unionType)
5818 ListSubMembers(member);
5824 void ListModule(Module mainModule, int recurse, bool listClasses)
5827 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5828 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5829 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5830 for(module = mainModule.application.allModules.first; module; module = module.next)
5832 if(ModuleVisibility(mainModule, module))
5833 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5837 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5844 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5846 Class _class = link.data;
5847 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5849 DataRow row = membersList.AddString(_class.name);
5850 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5855 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5857 DefinedExpression definedExp = link.data;
5858 DataRow row = membersList.AddString(link /*definedExp*/.name);
5859 row.icon = icons[typeData];
5862 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5864 GlobalFunction function = link.data;
5865 DataRow row = membersList.AddString(link /*function*/.name);
5866 row.icon = icons[typeMethod];
5870 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5872 if(recurse != 2 && listClasses)
5874 if(!membersList.FindString(ns->name))
5876 DataRow row = membersList.AddString(ns->name);
5877 row.icon = icons[typeNameSpace];
5882 ListNameSpace(ns, 2, listClasses);
5886 void ListEnumValues(Class _class)
5888 List<Class> classes { };
5889 for(; _class && _class.type == enumClass; _class = _class.base)
5890 classes.Insert(null, _class);
5891 for(_class : classes)
5893 EnumClassData enumeration = (EnumClassData)_class.data;
5895 for(item = enumeration.values.first; item; item = item.next)
5897 DataRow row = membersList.AddString(item.name);
5898 row.icon = icons[typeEnumValue];
5904 bool ListEnumsModule(Module mainModule, Type dest)
5906 bool result = false;
5908 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5909 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5910 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5911 for(module = mainModule.application.allModules.first; module; module = module.next)
5913 if(ModuleVisibility(mainModule, module))
5914 result |= ListEnums(module.publicNameSpace, dest);
5919 void ListNameSpaceByString(Module mainModule, char * string)
5921 NameSpace * nameSpace;
5923 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5924 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5925 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5926 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5927 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5928 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5929 for(module = mainModule.application.allModules.first; module; module = module.next)
5931 if(ModuleVisibility(mainModule, module))
5933 nameSpace = FindNameSpace(module.publicNameSpace, string);
5934 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5939 bool ListEnums(NameSpace nameSpace, Type dest)
5942 bool result = false;
5944 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5946 Class _class = link.data;
5947 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *"))) && !dest.classObjectType)) &&
5948 dest.kind != pointerType && dest.kind != ellipsisType)
5950 OldList conversions { };
5952 type.kind = classType;
5953 type._class = FindClass(_class.name);
5954 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5956 ListEnumValues(_class);
5959 conversions.Free(null);
5963 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5965 result |= ListEnums(nameSpace, dest);
5970 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5974 for(c = 0; (ch = name[c]); c++)
5976 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5978 NameSpace * newSpace;
5979 char * spaceName = new char[c - start + 1];
5980 memcpy(spaceName, name + start, c - start);
5981 spaceName[c-start] = '\0';
5982 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5986 nameSpace = newSpace;
5995 return (NameSpace *)nameSpace;
5998 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
6000 bool listedEnums = false;
6001 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
6002 bool listClasses = true;
6004 if(exp && (exp.type == identifierExp || exp.type == memberExp))
6006 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
6007 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
6008 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
6010 if(exp.type == identifierExp)
6011 id = realIdentifier;
6013 if(id && id._class && !id._class.name)
6015 listClasses = false;
6018 else if(id && id._class && id._class.name)
6022 Class _class = id.classSym.registered;
6023 if(_class && _class.type == enumClass)
6025 ListEnumValues(_class);
6028 ListClassMembers(id.classSym.registered, true);
6033 else if(id && colons)
6035 ListNameSpaceByString(this.privateModule, id.string);
6040 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6042 listedEnums = ListEnumsModule(this.privateModule, destType);
6045 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6047 ListEnumValues(destType._class.registered);
6050 ListClassPropertiesAndVirtual(insideClass, null);
6054 else if(destType && destType.kind == enumType)
6058 for(value = destType.members.first; value; value = value.next)
6060 DataRow row = membersList.AddString(value.name);
6061 row.icon = icons[typeEnumValue];
6065 ListClassPropertiesAndVirtual(insideClass, null);
6069 else if(insideClass && !enumOnly)
6071 ListClassPropertiesAndVirtual(insideClass, string);
6074 if(listedEnums && string && string[0])
6076 DataRow row = membersList.FindSubString(string);
6078 listedEnums = false;
6081 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6083 ListClassMembersMatch(GetThisClass(), exp.destType);
6085 else if(!insideClass && !enumOnly && !listedEnums)
6088 Symbol symbol = null;
6092 ListClassMembers(GetThisClass(), false);
6095 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6097 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6099 // Don't list enum values?
6100 //if(symbol.type.kind != TypeEnum)
6101 DataRow row = membersList.FindString(symbol.string);
6104 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6106 row = membersList.AddString(symbol.string);
6107 if(symbol.type && symbol.type.kind == functionType)
6108 row.icon = icons[typeMethod];
6109 else if(symbol.type && symbol.type.kind == enumType)
6111 row.icon = icons[typeEnumValue];
6115 BitmapResource bitmap = null;
6116 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6118 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6121 bitmap = { bitmapName };
6122 membersList.AddResource(bitmap);
6125 row.icon = bitmap ? bitmap : icons[typeData];
6132 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6134 DataRow row = membersList.FindString(symbol.string);
6137 row = membersList.AddString(symbol.string);
6138 if(symbol.type.kind == functionType)
6139 row.icon = icons[typeMethod];
6140 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6142 row.icon = icons[typeClass];
6146 row.icon = icons[typeDataType];
6153 ListModule(this.privateModule, 1, listClasses);
6154 // TODO: Implement this with name space
6158 for(data = globalData.first; data; data = data.next)
6160 DataRow row = membersList.FindString(data.name);
6162 data.dataType = ProcessTypeString(data.dataTypeString, false);
6165 row = membersList.AddString(data.name);
6167 if(data.dataType && data.dataType.kind == TypeEnum)
6169 row.icon = icons[typeEnumValue];
6173 BitmapResource bitmap = null;
6174 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6176 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6179 bitmap = { bitmapName };
6180 membersList.AddResource(bitmap);
6183 row.icon = bitmap ? bitmap : icons[typeData];
6191 DataRow row = membersList.AddString("Min");
6192 row.icon = icons[typeMethod];
6194 row = membersList.AddString("Max");
6195 row.icon = icons[typeMethod];
6197 row = membersList.AddString("Abs");
6198 row.icon = icons[typeMethod];
6200 row = membersList.AddString("Sgn");
6201 row.icon = icons[typeMethod];
6207 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6209 EditBoxStream f { editBox = editBox };
6214 updatingCode = true;
6216 if(!method.dataType)
6217 method.dataType = ProcessTypeString(method.dataTypeString, false);
6219 DeleteJunkBefore(f, function.loc.start.pos, &position);
6220 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6222 // ADDING METHOD HERE
6224 Type dataType = method.dataType;
6225 Type returnType = dataType.returnType;
6227 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6233 if(extraIndent) f.Printf(" ");
6235 OutputType(f, returnType, false);
6239 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6241 if(dataType.thisClass.shortName)
6242 f.Printf(dataType.thisClass.shortName);
6244 f.Printf(dataType.thisClass.string);
6247 f.Printf(method.name);
6249 for(param = dataType.params.first; param; param = param.next)
6251 // Decided not to write void...
6252 if(param.kind != voidType)
6254 OutputType(f, param, true);
6260 if(extraIndent) f.Printf(" ");
6261 f.Printf(" %c\n", OpenBracket);
6263 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6269 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6270 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6272 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6274 if(extraIndent) f.Printf(" ");
6275 f.Printf(" return true;\n");
6277 else if(returnType && returnType.kind != voidType)
6279 if(extraIndent) f.Printf(" ");
6280 f.Printf(" return 0;\n");
6285 if(extraIndent) f.Printf(" ");
6287 if(returnType.kind != voidType)
6288 f.Printf("return ");
6289 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6290 for(param = dataType.params.first; param; param = param.next)
6292 if(param.prev) f.Printf(", ");
6293 if(param.kind != voidType)
6294 f.Printf(param.name);
6300 if(extraIndent) f.Printf(" ");
6301 f.Printf(" %c", CloseBracket);
6306 if(extraIndent) { x1 += 3; x2 += 3; }
6307 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6309 this.updatingCode = false;
6313 // Return false if we overrided a function and don't want to run params listing
6314 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6316 bool didOverride = false;
6317 EditLine line = editBox.line;
6318 char * text = line.text;
6319 int lineNum, charPos;
6320 Expression exp = null;
6323 //Identifier id = null;
6324 Expression memberExp = null;
6325 Identifier realIdentifier = null;
6327 if(!parsing) return true;
6328 if(!privateModule) return !didOverride;
6330 insideFunction = null;
6332 charPos = editBox.charPos + 1;
6333 if(!membersListShown)
6338 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6340 EditBoxStream f { editBox = editBox };
6342 updatingCode = true;
6343 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6347 if(!f.Seek(-1, current))
6350 if(!isspace(ch)) break;
6351 f.Seek(-1, current);
6353 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6355 lineNum = editBox.lineNumber + 1;
6356 charPos = editBox.charPos + 1;
6358 updatingCode = false;
6361 if(!membersListShown)
6363 memberExp = FindExpTree(ast, lineNum, charPos);
6364 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6369 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6371 EditBoxStream f { editBox = editBox };
6374 updatingCode = true;
6376 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6379 if(ch == '}' || ch == ',' || ch == ')')
6381 f.Seek(-1, current);
6389 if(!f.Seek(-1, current))
6392 if(!isspace(ch)) break;
6393 f.Seek(-1, current);
6397 f.Seek(-1, current);
6399 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6401 lineNum = editBox.lineNumber + 1;
6402 charPos = editBox.charPos + 1;
6404 updatingCode = false;
6407 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6412 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6413 lineNum = editBox.lineNumber + 1;
6414 charPos = editBox.charPos/* + 1*/;
6418 char tempString[1024];
6419 char * string = null;
6420 CodePosition idStart, idEnd;
6422 if(membersListShown)
6424 char * buffer = membersLine.text;
6426 bool firstChar = true;
6428 string = tempString;
6430 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6432 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6433 if(!isSpace) firstChar = false;
6435 string[len++] = buffer[c];
6439 else //if(realIdentifier)//if(id)
6442 char * buffer = id.string;
6444 bool firstChar = true;
6446 string = tempString;
6447 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6449 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6450 if(!isSpace) firstChar = false;
6452 string[len++] = buffer[c];
6458 EditLine editLine = editBox.line;
6459 bool firstChar = true;
6462 string = tempString;
6463 for(y = lineNum-1; y >= 0; y--)
6465 char * buffer = editLine.text;
6466 int lineCount = editLine.count;
6467 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6469 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6474 idEnd.charPos = x + 2;
6479 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6482 idEnd.charPos = x + 2;
6489 if(!isalnum(buffer[x]) && buffer[x] != '_')
6495 memmove(string+1, string, len++);
6496 string[0] = buffer[x];
6500 //if(done || firstChar)
6501 if(done || !firstChar)
6503 editLine = editLine.prev;
6506 if(!strcmp(string, "case"))
6512 else if(!strcmp(string, "return"))
6518 else if(!strcmp(string, "delete"))
6524 else if(!strcmp(string, "new"))
6530 else if(!strcmp(string, "renew"))
6538 idStart.charPos = x + 1;
6539 idStart.line = y + 1;
6542 if(!membersListShown)
6544 membersList.Clear();
6545 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6547 Type type = memberExp.member.exp.expType;
6548 if(pointer == 2 && type)
6550 if(type.kind == pointerType || type.kind == arrayType)
6559 ListSymbols(exp, enumOnly, string, realIdentifier);
6561 membersList.Sort(null, 1);
6566 // Virtual function override
6567 Identifier id = GetDeclId(insideFunction.declarator);
6568 char * string = id ? id.string : null;
6570 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6573 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6574 insideFunction = null;
6577 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6582 if(!didOverride) //insideFunction)
6584 rowCount = membersList.rowCount;
6587 DataRow row = string ? membersList.FindSubString(string) : null;
6588 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6590 char * newString = row.string;
6591 if(!membersListShown)
6593 membersLoc.start.line = idStart.line-1;
6594 membersLoc.start.charPos = idStart.charPos-1;
6595 //membersLoc.end = membersLoc.start;
6596 membersLoc.end.charPos = idEnd.charPos-1;
6597 membersLoc.end.line = idEnd.line-1;
6598 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6599 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6604 membersList.Destroy(0);
6605 membersListShown = false;
6608 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6610 line, membersLoc.start.line, membersLoc.start.charPos,
6611 line, membersLoc.end.line, membersLoc.end.charPos);
6612 editBox.PutS(newString);
6618 row = membersList.FindSubStringi(string);
6620 membersList.currentRow = row;
6621 membersList.currentRow.selected = false;
6624 membersList.currentRow = row;
6626 if(!membersListShown)
6630 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6631 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6632 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6633 editBox.GetCaretPosition(caret);
6634 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6636 membersList.master = this;
6638 caret.y += editBox.GetCaretSize();
6640 membersList.Create();
6643 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6644 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6645 Window parent = membersList.parent;
6647 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6649 y -= editBox.GetCaretSize() + membersList.size.h;
6650 membersAbove = true;
6653 membersAbove = false;
6655 membersList.position = { x, y };
6659 membersLoc.start.line = lineNum - 1;
6661 if(string && string[0])
6663 membersLoc.start.charPos = idStart.charPos-1;
6664 membersLoc.end = membersLoc.start;
6665 //membersLoc.end.charPos = id.loc.end.charPos-1;
6666 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6670 membersLoc.start.charPos = charPos;
6671 membersLoc.end = membersLoc.start;
6672 membersLoc.end.charPos = charPos;
6674 membersListShown = true;
6676 // Hack to keep caret shown
6677 editBox.GetCaretPosition(caret);
6678 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6681 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6687 SetCurrentContext(globalContext);
6690 return !didOverride;
6693 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6695 EditLine line = editBox.line;
6696 char * text = line.text;
6697 int lineNum, charPos;
6698 Expression exp = null;
6702 if(!parsing) return;
6704 charPos = editBox.charPos + 1;
6707 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6709 EditBoxStream f { editBox = editBox };
6712 updatingCode = true;
6713 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6716 if(ch == '}' || ch == ',' || ch == ')')
6718 f.Seek(-1, current);
6726 if(!f.Seek(-1, current))
6729 if(!isspace(ch)) break;
6730 f.Seek(-1, current);
6734 f.Seek(-1, current);
6736 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6738 lineNum = editBox.lineNumber + 1;
6739 charPos = editBox.charPos + 1;
6741 updatingCode = false;
6744 charPos = Min(charPos, l1.count + 1);
6746 FindParamsTree(ast, lineNum, charPos);
6748 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6749 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6751 ::functionType = null;
6752 ::instanceType = null;
6755 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6756 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6760 Window parent = paramsList.parent;
6762 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6765 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6766 // ( Dummy exp: always ends up with same memory)
6768 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6769 editBox.GetCaretPosition(paramsPosition);
6770 this.paramsPosition.y += editBox.GetCaretSize();
6773 FreeType(this.functionType);
6774 FreeType(this.instanceType);
6776 this.functionType = ::functionType;
6777 this.instanceType = ::instanceType;
6779 if(this.functionType) this.functionType.refCount++;
6780 if(this.instanceType) this.instanceType.refCount++;
6782 this.paramsID = ::paramsID;
6783 functionExp = paramsInsideExp;
6785 paramsList.master = this;
6787 paramsList.Create();
6789 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6790 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6792 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6794 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6798 paramsAbove = false;
6799 if(x + paramsList.size.w > parent.clientSize.w)
6801 x = parent.clientSize.w - paramsList.size.w;
6805 paramsList.position = { x, y };
6807 // Hack to keep caret shown
6810 editBox.GetCaretPosition(caret);
6811 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6814 this.paramsShown = true;
6816 else if((!::functionType && !::instanceType) || reposition)
6818 paramsList.Destroy(0);
6819 paramsShown = false;
6821 FreeType(this.functionType);
6822 FreeType(this.instanceType);
6823 this.functionType = null;
6824 this.instanceType = null;
6828 SetCurrentContext(globalContext);
6836 designer.visible = true;
6837 designer.Activate();
6843 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6845 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };