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, 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, false);
1398 node = ide.projectView.GetNodeFromWindow(this, null, true);
1402 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1403 $"It can't be compiled.");
1404 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1413 bool OnKeyDown(Key key, unichar ch)
1415 CodeEditor editor = (CodeEditor)master;
1416 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1418 if(editor.membersListShown)
1420 editor.membersList.Destroy(0);
1421 editor.membersListShown = false;
1424 if(editor.paramsShown)
1426 editor.paramsList.Destroy(0);
1427 editor.paramsShown = false;
1428 FreeType(editor.functionType);
1429 FreeType(editor.instanceType);
1431 editor.functionType = null;
1432 editor.instanceType = null;
1433 editor.paramsID = -1;
1437 return EditBox::OnKeyDown(key, ch);
1440 void OnVScroll(ScrollBarAction action, int position, Key key)
1442 if(anchor.left.distance)
1444 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1447 EditBox::OnVScroll(action, position, key);
1449 CodeEditor ce = (CodeEditor)parent;
1450 if(ce.openedFileInfo)
1451 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1455 void OnHScroll(ScrollBarAction action, int position, Key key)
1457 EditBox::OnHScroll(action, position, key);
1459 CodeEditor ce = (CodeEditor)parent;
1460 if(ce.openedFileInfo)
1461 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1468 fullRowSelect = false,
1471 borderStyle = bevel;
1472 // size = { 200, 400 };
1474 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1476 DataRow row = listBox.currentRow;
1479 char * string = row.string;
1481 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1483 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1484 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1485 editBox.PutS(string);
1488 membersListShown = false;
1493 bool OnKeyDown(Key key, unichar ch)
1495 CodeEditor editor = (CodeEditor) master;
1496 if(key == escape || key == leftAlt || key == rightAlt ||
1497 (key.ctrl && key.code != left && key.code != right &&
1498 key.code != leftShift && key.code != rightShift && key.code != space))
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", u, 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;
1991 char name[MAX_LOCATION];
1993 // TOFIX: This only looks at the filename...
1994 GetLastDirectory(fileName, name);
1995 if(ide && ide.workspace)
1997 for(p : ide.workspace.projects)
1999 if(p.topNode.Find(name, false))
2007 for(p : ide.workspace.projects)
2009 if(IsPathInsideOf(fileName, p.topNode.path))
2017 ide.debugger.ToggleBreakpoint(fileName, line, prj);
2027 //MenuItem viewDesignerItem, viewProperties, viewMethods;
2031 designer.parent = parent;
2034 toolBox = ((IDEWorkSpace)master).toolBox;
2036 // Debugger bug here: value of toolBox appears as 0
2038 sheet = ((IDEWorkSpace)master).sheet;
2043 bool OnClose(bool parentClosing)
2047 if(ide.workspace && fileName)
2048 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2049 if(inUseDebug && !debugClosing)
2051 debugClosing = true;
2053 if(CloseConfirmation(false))
2056 OnFileModified({ modified = true }, null);
2058 debugClosing = false;
2061 if(designer && !designer.closing)
2063 if(designer.visible)
2070 //Window formEditor = designer;
2071 //formEditor.Destroy(0);
2074 ide.AdjustFileMenus();
2079 void OnDestroy(void)
2081 ObjectInfo oClass, next;
2082 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2084 FreeType(this.functionType);
2085 FreeType(this.instanceType);
2090 designer.codeEditor = null;
2091 designer.Destroy(0);
2095 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2097 ObjectInfo object, next;
2099 for(object = oClass.instances.first; object; object = next)
2104 Designer::DestroyObject(object.instance);
2105 delete object.instance;
2107 sheet.DeleteObject(object);
2109 oClass.instances.Delete(object);
2113 Designer::DestroyObject(oClass.instance);
2114 delete oClass.instance;
2116 sheet.DeleteObject(oClass);
2118 classes.Delete(oClass);
2121 if(windowClass && windowClass.data)
2122 UnapplySkin(windowClass);
2126 if(sheet.codeEditor == this)
2128 sheet.codeEditor = null;
2129 toolBox.codeEditor = null;
2135 ProjectView projectView = ide.projectView;
2138 ProjectNode node = projectView.GetNodeFromWindow(this, null, false);
2139 if(node && node.modified)
2141 node.modified = false;
2142 projectView.Update(null);
2148 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2150 // 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
2152 if(directActivation)
2153 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2155 if(active && directActivation)
2157 AdjustDebugMenus(ide.areDebugMenusUnavailable, ide.isBreakpointTogglingUnavailable, ide.isDebuggerExecuting);
2159 openedFileInfo.Activate();
2163 Location * loc = null;
2164 UpdateFormCode(); // To ensure update when modifying properties...
2166 // Got to the right spot in code so we don't lose our form selection...
2169 if(selected.instCode)
2170 loc = &selected.instCode.loc;
2171 else if(selected.classDefinition)
2172 loc = &selected.classDefinition.loc;
2174 line = editBox.lineNumber + 1;
2175 charPos = editBox.charPos + 1;
2180 if(selected && !loc->Inside(line, charPos))
2182 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2183 line = editBox.lineNumber + 1;
2184 charPos = editBox.charPos + 1;
2186 else if(selected && selected.classDefinition)
2189 for(object = selected.instances.first; object; object = object.next)
2193 if(object.instCode.loc.Inside(line, charPos))
2199 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2200 line = editBox.lineNumber + 1;
2201 charPos = editBox.charPos + 1;
2206 ProcessCaretMove(editBox, line, charPos);
2211 if(membersListShown)
2213 membersList.Destroy(0);
2214 membersListShown = false;
2218 paramsList.Destroy(0);
2219 paramsShown = false;
2220 FreeType(functionType);
2221 FreeType(instanceType);
2223 functionType = null;
2224 instanceType = null;
2231 bool OnSaveFile(char * fileName)
2238 f = FileOpen(fileName, write);
2241 if(!ide.projectView)
2242 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2246 this.fileName = fileName; // Put this here because the form designer will check for it...
2247 designer.fileName = fileName;
2248 designer.modifiedDocument = false;
2250 editBox.Save(f, false);
2251 modifiedDocument = false;
2259 bool OnFileModified(FileChange fileChange, char * param)
2261 bool reload = false;
2262 if(visible == false && inUseDebug == true)
2268 sprintf(message, $"The document %s was modified by another application.\n"
2269 "Would you like to reload it and lose your changes?", fileName);
2270 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2271 contents = message }.Modal() == yes)
2277 File f = FileOpen(fileName, read);
2280 int lineNumber, charPos, len;
2284 updatingCode = true;
2285 lineNumber = editBox.lineNumber;
2286 charPos = editBox.charPos;
2287 scroll = editBox.scroll;
2290 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2291 len = strlen(editBox.line.text);
2292 editBox.GoToLineNum(lineNumber);
2293 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2294 editBox.scroll = scroll;
2295 updatingCode = false;
2296 loadingFile = false;
2298 codeModified = true;
2302 designer.modifiedDocument = false;
2304 modifiedDocument = false;
2312 void OnRedraw(Surface surface)
2315 surface.SetBackground(marginColor);
2316 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2317 if(ideSettings.showLineNumbers)
2319 int currentLineNumber;
2324 surface.textOpacity = false;
2325 surface.font = font.font;
2326 surface.TextExtent(" ", 1, null, &spaceH);
2327 currentLineNumber = editBox.scroll.y / spaceH + 1;
2329 surface.SetForeground(lineNumbersColor);
2330 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2332 // Highlight current line
2333 if(editBox.lineNumber == currentLineNumber - 1)
2335 surface.SetBackground(selectedMarginColor);
2336 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2337 surface.SetBackground(marginColor);
2339 sprintf(lineText,"%5u ", currentLineNumber % 100000);
2340 if(currentLineNumber <= editBox.numLines)
2341 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,6);
2343 currentLineNumber++;
2347 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2349 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2350 int lineCursor, lineTopFrame, breakpointLines[128];
2351 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2352 Debugger debugger = ide.debugger;
2353 BitmapResource bmpRes;
2355 boxH = clientSize.h;
2356 scrollY = editBox.scroll.y;
2357 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2359 bpOnCursor = bpOnTopFrame = false;
2360 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2363 for(i = 0; i < count; i++)
2365 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2367 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2368 if(breakpointLines[i] == lineCursor)
2370 if(breakpointLines[i] == lineTopFrame)
2371 bpOnTopFrame = true;
2374 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2376 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2379 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2380 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2381 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2383 if(editBox.anchor.left.distance)
2385 if(editBox.horzScroll && editBox.horzScroll.visible)
2387 surface.SetBackground(control);
2388 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2393 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2398 lineY = (line - 1) * lineH;
2399 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2401 Bitmap bitmap = resource.bitmap;
2403 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2410 char ext[MAX_EXTENSION];
2411 char * fileName = property::fileName;
2413 if(SearchString(fileName, 0, "Makefile", false, true))
2414 editBox.useTab = true;
2415 designer.fileName = fileName;
2419 GetExtension(fileName, ext);
2421 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2422 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2423 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2424 editBox.syntaxHighlighting = true;
2426 editBox.syntaxHighlighting = false;
2428 if(parsing && !strcmpi(ext, "ec"))
2430 codeModified = true;
2436 display.FontExtent(font.font, " ", 1, &spaceW, null);
2437 editBox.anchor = Anchor
2439 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2440 right = 0, top = 0, bottom = 0
2449 display.FontExtent(font.font, " ", 1, &spaceW, null);
2450 editBox.anchor = Anchor
2452 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2453 right = 0, top = 0, bottom = 0
2458 bool LoadFile(char * filePath)
2460 File f = FileOpen(filePath, read);
2463 // Added this here...
2464 fileName = filePath;
2466 updatingCode = true;
2468 updatingCode = false;
2469 loadingFile = false;
2478 void AdjustDebugMenus(bool unavailable, bool bpNoToggle, bool executing)
2480 debugRunToCursor.disabled = unavailable || executing;
2481 debugSkipRunToCursor.disabled = unavailable || executing;
2482 debugSkipRunToCursorAtSameLevel.disabled = unavailable || executing;
2483 debugToggleBreakpoint.disabled = bpNoToggle;
2489 ProjectView projectView = ide.projectView;
2492 designer.fileName = fileName;
2498 sprintf(title, $"Untitled %d", documentID);
2499 // designer.fileName = CopyString(title);
2500 designer.fileName = title;
2503 AdjustDebugMenus(ide.areDebugMenusUnavailable, ide.isBreakpointTogglingUnavailable, ide.isDebuggerExecuting);
2505 for(c = 0; c < CodeObjectType::enumSize; c++)
2506 icons[c] = BitmapResource { iconNames[c], window = this };
2508 codeModified = true;
2520 selected.modified = true;
2521 selected.oClass.modified = true;
2523 designer.modifiedDocument = true;
2524 modifiedDocument = true;
2525 formModified = true;
2528 /****************************************************************************
2530 ****************************************************************************/
2538 this.defines.Free(FreeModuleDefine);
2539 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2541 FreeExcludedSymbols(this.excludedSymbols);
2542 FreeContext(this.globalContext);
2544 FreeGlobalData(&this.globalData);
2545 FindCtx_Terminate();
2546 FindParams_Terminate();
2548 if(GetGlobalContext() == globalContext)
2550 SetGlobalData(null);
2551 SetGlobalContext(null);
2552 SetExcludedSymbols(null);
2553 SetTopContext(null);
2554 SetCurrentContext(null);
2557 SetPrivateModule(null);
2560 if(this.privateModule)
2562 FreeTypeData(this.privateModule);
2563 delete this.privateModule;
2564 this.privateModule = null;
2570 static bool reentrant = false;
2575 char * selectedClassName = null, * selectedName = null;
2576 int selectedPos = 0;
2577 Designer backDesigner;
2578 char oldWorkDir[MAX_LOCATION];
2579 char mainModuleName[MAX_FILENAME] = "";
2581 ImportedModule module;
2582 char extension[MAX_EXTENSION];
2583 PathBackup pathBackup { };
2585 Time parseCodeStart = GetTime();
2586 Time startTime, startFindClass;
2588 findClassTotalTime = 0;
2589 checkTypeTotalTime = 0;
2590 externalImportTotalTime = 0;
2591 findClassIgnoreNSTotalTime = 0;
2592 findSymbolTotalTime = 0;
2593 //ResetClassFindTime();
2597 // 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)
2598 if(reentrant) return;
2605 selectedClassName = CopyString(oClass.name);
2606 if(selected != oClass)
2608 ObjectInfo object = this.selected;
2609 selectedName = CopyString(object.name);
2613 for(check = this.oClass.instances.first; check; check = check.next)
2625 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2627 FindCtx_Terminate();
2628 FindParams_Terminate();
2630 SetGlobalData(&globalData);
2631 SetGlobalContext(globalContext);
2632 SetExcludedSymbols(&excludedSymbols);
2633 SetTopContext(globalContext);
2634 SetCurrentContext(globalContext);
2635 SetDefines(&defines);
2636 SetImports(&imports);
2637 SetCurrentNameSpace(null);
2640 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2641 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2642 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2643 "/I T:\\ecere\\include /E %s", argv[1]);
2647 ChangeWorkingDir("e:\\ec");
2648 sprintf(command, "gcc -x c -E -");
2649 fileInput = DualPipeOpen({ output = true, input = true }, command);
2650 SetFileInput(fileInput);
2655 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2657 fileInput.Write(buffer, 1, count);
2662 fileInput.CloseOutput();
2666 // TOCHECK: COULDN'T WE CALL FreeParser here?
2668 FreeType(this.functionType);
2669 FreeType(this.instanceType);
2670 this.functionType = null;
2671 this.instanceType = null;
2674 sheet.SelectObject(null);
2680 // We don't want the designer to be notified of selection when deleting rows...
2681 backDesigner = designer;
2686 ObjectInfo _class, next;
2688 for(_class = classes.first; _class; _class = next)
2694 for(;object = _class.instances.first;)
2698 Designer::DestroyObject(object.instance);
2699 delete object.instance;
2701 sheet.DeleteObject(object);
2703 _class.instances.Delete(object);
2707 Designer::DestroyObject(_class.instance);
2708 delete _class.instance;
2710 sheet.DeleteObject(_class);
2712 classes.Delete(_class);
2718 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2719 if(windowClass && windowClass.data)
2720 UnapplySkin(windowClass);
2723 designer = backDesigner;
2726 fileInput = editFile = EditBoxStream { editBox = editBox };
2727 SetFileInput(fileInput);
2735 defines.Free(FreeModuleDefine);
2736 imports.Free(FreeModuleImport);
2738 FreeContext(this.globalContext);
2739 FreeExcludedSymbols(this.excludedSymbols);
2742 FreeGlobalData(&this.globalData);
2744 if(this.privateModule)
2746 FreeTypeData(this.privateModule);
2747 delete this.privateModule;
2751 startTime = GetTime();
2752 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2754 printf("classes.count: %d\n", globalContext.classes.count);
2759 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2760 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2763 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2765 SetPrivateModule(privateModule);
2768 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2769 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2770 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2771 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2772 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2775 fileName = this.fileName;
2777 if(ide.workspace && ide.workspace.projects && fileName)
2779 for(p : ide.workspace.projects)
2781 char path[MAX_LOCATION];
2783 MakePathRelative(fileName, p.topNode.path, path);
2784 MakeSlashPath(path);
2786 pn = p.topNode.FindWithPath(path, false);
2795 project = ide.project;
2797 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2799 ChangeWorkingDir(project.topNode.path);
2801 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2803 GetLastDirectory(fileName, mainModuleName);
2804 GetExtension(mainModuleName, extension);
2806 SetBuildingEcereCom(false);
2807 SetBuildingEcereComModule(false);
2809 // TODO: Get symbolsDir from project settings instead...
2812 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2813 ProjectConfig config = project.config;
2814 int bitDepth = ide.workspace.bitDepth;
2815 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2816 SetSymbolsDir(objDir.dir);
2817 ide.SetPath(true, compiler, config, bitDepth);
2821 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2822 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2826 switch(GetRuntimePlatform())
2828 case win32: SetSymbolsDir("obj/debug.win32"); break;
2829 case tux: SetSymbolsDir("obj/debug.linux"); break;
2830 case apple: SetSymbolsDir("obj/debug.apple"); break;
2832 SetIncludeDirs(null);
2833 SetSysIncludeDirs(null);
2837 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2839 // TODO FIX for configless project
2840 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2842 for(item : ide.project.config.options.preprocessorDefinitions)
2844 if(!strcmp(item, "BUILDING_ECERE_COM"))
2846 SetBuildingEcereCom(true);
2853 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2854 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2855 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2856 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2857 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2858 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2859 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2860 strcmpi(mainModuleName, "Mutex.ec")))
2862 SetBuildingEcereComModule(true);
2865 // Predeclare all classes
2867 char symFile[MAX_FILENAME];
2868 char symLocation[MAX_LOCATION];
2869 ImportedModule module, next;
2871 GetLastDirectory(fileName, symFile);
2872 ChangeExtension(symFile, "sym", symFile);
2874 strcpy(symLocation, GetSymbolsDir());
2875 PathCat(symLocation, symFile);
2877 // if(!GetEcereImported() && !GetBuildingEcereCom())
2878 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2881 startTime = GetTime();
2883 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2885 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2890 startTime = GetTime();
2892 // LoadSymbols(symLocation, normalImport, true);
2893 LoadSymbols(symLocation, preDeclImport, false);
2895 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2898 for(module = defines.first; module; module = next)
2901 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2904 defines.Delete(module);
2909 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2911 SetDefaultDeclMode(privateAccess);
2912 SetDeclMode(privateAccess);
2916 SetDefaultDeclMode(defaultAccess);
2917 SetDeclMode(defaultAccess);
2920 StripExtension(mainModuleName);
2921 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2922 defines.AddName(module);
2925 // SetYydebug(true);
2930 startTime = GetTime();
2931 startFindClass = checkTypeTotalTime;
2935 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2937 CheckDataRedefinitions();
2940 SetIncludeDirs(null);
2941 SetSysIncludeDirs(null);
2952 startTime = GetTime();
2954 PrePreProcessClassDefinitions();
2955 ComputeModuleClasses(privateModule);
2956 PreProcessClassDefinitions();
2957 ProcessClassDefinitions();
2959 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2960 startTime = GetTime();
2965 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2966 startTime = GetTime();
2968 ProcessInstantiations();
2970 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2973 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2975 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2976 if(!windowClass || windowClass.internalDecl)
2979 startTime = GetTime();
2981 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2982 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2983 eModule_Load(this.privateModule, "ecere", privateAccess);
2985 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2988 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2990 if(windowClass && windowClass.data)
2991 ApplySkin(windowClass, app.currentSkin.name, null);
2995 startTime = GetTime();
2997 for(external = ast->first; external; external = external.next)
2999 if(external.type == classExternal)
3001 ClassDefinition _class = external._class;
3002 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
3004 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
3007 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
3009 Instance instance = eInstance_New(regClass);
3010 ObjectInfo classObject
3012 name = CopyString(_class._class.name);
3013 instance = instance;
3014 classDefinition = _class;
3015 oClass = classObject;
3018 classes.Add(classObject);
3022 // Moved this at bottom so that the file dialog doesn't show up in eCom
3023 designer.CreateObject(instance, classObject, true, null);
3024 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
3026 if(_class.definitions)
3030 for(def = _class.definitions->first; def; def = def.next)
3034 case defaultPropertiesClassDef:
3037 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3039 Identifier id = propDef.identifiers->first;
3042 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3045 Class propertyClass = prop.dataTypeClass;
3047 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3048 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3050 FreeType(propDef.initializer.exp.destType);
3051 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3052 ProcessExpressionType(propDef.initializer.exp);
3054 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
3056 Expression computed = CopyExpression(propDef.initializer.exp);
3057 ComputeExpression(computed);
3059 if(computed.isConstant && computed.type == instanceExp && !id.next)
3063 if(computed.instance._class && computed.instance._class.symbol &&
3064 computed.instance._class.symbol.registered &&
3065 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3067 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3069 // This was saved in the control and shouldn't be freed by FreeExpression...
3070 if(propertyClass.type == normalClass)
3071 computed.instance.data = null;
3075 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3076 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3078 String temp = new char[strlen(computed.string)+1];
3079 ReadString(temp, computed.string);
3080 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3084 propDef.variable = true;
3086 FreeExpression(computed);
3090 Expression computed = CopyExpression(propDef.initializer.exp);
3091 ComputeExpression(computed);
3092 if(computed.isConstant)
3094 //if(computed.type == memberExp) computed = computed.member.exp;
3096 if(computed.type == constantExp)
3098 Operand value = GetOperand(computed);
3099 DataValue valueData;
3100 valueData.i64 = value.i64;
3101 SetProperty(prop, instance, valueData);
3103 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3105 String temp = new char[strlen(computed.string)+1];
3106 ReadString(temp, computed.string);
3107 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3112 propDef.variable = true;
3114 FreeExpression(computed);
3118 propDef.variable = true;
3122 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3123 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3124 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3127 // Maintain a list in FunctionDefinition of who is attached to it
3128 for(def = _class.definitions->first; def; def = def.next)
3130 if(def.type == functionClassDef)
3132 ClassFunction function = def.function;
3133 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3135 function.attached.Add(OldLink { data = method });
3145 case declarationClassDef:
3147 Declaration decl = def.decl;
3150 case instDeclaration:
3152 Instantiation inst = decl.inst;
3153 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3154 if(instClass && eClass_GetDesigner(instClass))
3156 Instance control = eInstance_New(instClass);
3161 oClass = classObject;
3165 classObject.instances.Add(object);
3167 // TOCHECK: Why is this needed now?
3168 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3169 def.object = object;
3171 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3173 designer.CreateObject(control, object, false, classObject.instance);
3174 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3184 // Second pass, process instantiation members
3186 for(def = _class.definitions->first; def; def = def.next)
3190 case declarationClassDef:
3192 Declaration decl = def.decl;
3195 case instDeclaration:
3197 Instantiation inst = decl.inst;
3198 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3199 if(instClass && eClass_GetDesigner(instClass))
3202 object = object ? object.next : classObject.instances.first;
3203 control = object.instance;
3207 MembersInit members;
3208 for(members = inst.members->first; members; members = members.next)
3210 switch(members.type)
3212 case dataMembersInit:
3214 if(members.dataMembers)
3217 DataMember curMember = null;
3218 Class curClass = null;
3219 DataMember subMemberStack[256];
3220 int subMemberStackPos = 0;
3222 for(member = members.dataMembers->first; member; member = member.next)
3225 Identifier ident = member.identifiers ? member.identifiers->first : null;
3228 DataMember _subMemberStack[256];
3229 int _subMemberStackPos = 0;
3230 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3234 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3236 if(thisMember && thisMember.memberAccess == publicAccess)
3238 curMember = thisMember;
3239 curClass = curMember._class;
3240 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3241 subMemberStackPos = _subMemberStackPos;
3247 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3248 if(curMember) found = true;
3250 if(found && curMember.isProperty)
3252 Property prop = (Property) curMember;
3253 Class propertyClass = prop.dataTypeClass;
3255 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3257 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3259 FreeType(member.initializer.exp.destType);
3260 member.initializer.exp.destType = MkClassType(propertyClass.name);
3263 ProcessExpressionType(member.initializer.exp);
3265 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3267 Expression computed;
3269 /*char debugExpString[4096];
3270 debugExpString[0] = '\0';
3271 PrintExpression(member.initializer.exp, debugExpString);*/
3273 computed = CopyExpression(member.initializer.exp);
3276 ComputeExpression(computed);
3278 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3280 if(computed.instance.data)
3282 if(computed.instance._class && computed.instance._class.symbol &&
3283 computed.instance._class.symbol.registered &&
3284 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3286 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3288 // This was saved in the control and shouldn't be freed by FreeExpression...
3289 if(propertyClass.type == normalClass)
3290 computed.instance.data = null;
3294 else if(computed.type == identifierExp)
3296 member.variable = true;
3298 if(eClass_GetDesigner(propertyClass))
3301 char * name = computed.identifier.string;
3302 if(!strcmp(name, "this"))
3305 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3306 member.variable = false;
3311 for(check = classObject.instances.first; check; check = check.next)
3312 if(check.name && !strcmp(name, check.name))
3315 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3316 member.variable = false;
3322 else if(computed.type == memberExp)
3324 member.variable = true;
3325 if(computed.member.exp.type == identifierExp)
3327 char * name = computed.member.exp.identifier.string;
3328 if(!strcmp(name, "this"))
3330 char * name = computed.member.member.string;
3333 for(check = classObject.instances.first; check; check = check.next)
3334 if(check.name && !strcmp(name, check.name))
3337 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3338 member.variable = false;
3346 for(check = classObject.instances.first; check; check = check.next)
3348 if(check.name && !strcmp(name, check.name))
3350 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3353 DataValue value { };
3354 GetProperty(getProperty, check.instance, &value);
3355 SetProperty(prop, control, value);
3356 member.variable = false;
3364 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3365 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3367 String temp = new char[strlen(computed.string)+1];
3368 ReadString(temp, computed.string);
3369 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3373 member.variable = true;
3375 FreeExpression(computed);
3380 Expression computed = CopyExpression(member.initializer.exp);
3383 ComputeExpression(computed);
3384 if(computed.isConstant)
3386 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3388 if(!strcmp(propertyClass.dataTypeString, "float"))
3389 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3390 else if(!strcmp(propertyClass.dataTypeString, "double"))
3391 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3393 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3395 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3397 String temp = new char[strlen(computed.string)+1];
3398 ReadString(temp, computed.string);
3399 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3404 member.variable = true;
3406 FreeExpression(computed);
3412 member.variable = true;
3414 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3415 member.initializer.exp.type == memberExp) // identifierExp
3417 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3418 if(method && method.type == virtualMethod)
3421 // Maintain a list in FunctionDefinition of who is attached to it
3422 for(def = _class.definitions->first; def; def = def.next)
3424 if(def.type == functionClassDef)
3426 ClassFunction function = def.function;
3427 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3428 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3430 function.attached.Add(OldLink { data = method });
3431 // Reference this particular instance?
3446 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3457 //designer.CreateObject(instance, classObject, true, null);
3458 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3460 designer.PostCreateObject(instance, classObject, true, null);
3462 //instance.state = Hidden;
3463 //instance.Create();
3464 //instance.SetState(Normal, true, 0);
3473 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3477 // Restore Selection
3478 if(selectedClassName)
3481 for(oClass = classes.first; oClass; oClass = oClass.next)
3483 if(!strcmp(oClass.name, selectedClassName))
3485 this.oClass = oClass;
3489 delete selectedClassName;
3498 for(check = this.oClass.instances.first; check; check = check.next)
3500 if(check.name && !strcmp(check.name, selectedName))
3502 this.selected = check;
3508 if(this.oClass.instances.first)
3509 this.selected = this.oClass.instances.first;
3511 this.selected = this.oClass;
3514 else if(selectedPos == -1 || !this.oClass.instances.count)
3515 this.selected = this.oClass;
3521 if(selectedPos > this.oClass.instances.count)
3523 for(check = this.oClass.instances.first; check; check = check.next)
3525 if(selectedPos == pos++)
3527 this.selected = check;
3535 this.oClass = classes.first;
3536 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3538 delete selectedName;
3539 SetSymbolsDir(null);
3541 if(sheet.codeEditor == this)
3542 sheet.SelectObject(selected);
3545 codeModified = false;
3547 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3550 InvokeParameters(false, false, false);
3553 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3559 ChangeWorkingDir(oldWorkDir);
3561 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3562 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3563 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3564 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3565 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3567 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3569 if(inUseDebug && ide.projectView)
3570 ide.debugger.EvaluateWatches();
3575 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3578 Window control = (Window)object.instance;
3579 ObjectInfo classObject = object.oClass;
3581 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3583 if(!strcmp(_class.name, "DesignerBase")) return;
3585 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3587 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3588 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3590 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3591 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3593 Class dataType = prop.dataTypeClass;
3595 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3599 if(dataType.type == structClass)
3601 void * dataForm = new0 byte[dataType.structSize];
3602 void * dataTest = new0 byte[dataType.structSize];
3604 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3605 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3607 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3609 char tempString[1024] = "";
3611 bool needClass = true;
3615 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3617 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3619 eClass_FindNextMember(_class, curClass, curMember, null, null);
3620 if(*curMember != (DataMember)prop)
3621 f.Printf("%s = ", prop.name);
3623 *curMember = (DataMember)prop;
3624 *curClass = curMember->_class;
3627 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3629 f.Printf("%s", string);
3636 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3638 void * dataForm, * dataTest;
3640 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3641 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3643 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3645 char tempString[1024] = "";
3650 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3652 eClass_FindNextMember(_class, curClass, curMember, null, null);
3653 if(*curMember != (DataMember)prop)
3654 f.Printf("%s = ", prop.name);
3655 *curMember = (DataMember)prop;
3656 *curClass = curMember->_class;
3658 if(eClass_GetDesigner(dataType))
3660 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3661 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3662 f.Printf("this", prop.name);
3665 //ObjectInfo classObject;
3666 //for(classObject = classes.first; classObject; classObject = classObject.next)
3670 for(object = classObject.instances.first; object; object = object.next)
3672 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3674 f.Printf("%s", object.name);
3681 bool needClass = true;
3682 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3683 f.Printf("%s", string);
3690 bool needClass = true;
3691 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3693 if(!strcmp(dataType.dataTypeString, "char *"))
3696 OutputString(f, string);
3700 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3702 f.Printf("%s", string);
3705 *lastIsMethod = false;
3710 DataValue dataForm, dataTest;
3712 GetProperty(prop, control, &dataForm);
3713 GetProperty(prop, test, &dataTest);
3715 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3718 char tempString[1024] = "";
3719 SetProperty(prop, test, dataForm);
3721 if(dataType.type != bitClass)
3723 bool needClass = true;
3725 if(dataType.type == enumClass)
3728 Class enumClass = eSystem_FindClass(privateModule, "enum");
3729 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3731 for(value = e.values.first; value; value = value.next)
3733 if((int)value.data == dataForm.i)
3735 string = value.name;
3741 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3743 if(string && string[0])
3748 eClass_FindNextMember(_class, curClass, curMember, null, null);
3749 if(*curMember != (DataMember)prop)
3750 f.Printf("%s = ", prop.name);
3751 *curMember = (DataMember)prop;
3752 *curClass = curMember->_class;
3754 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3755 f.Printf("%sf", string);
3757 f.Printf("%s", string);
3761 else if(dataType.type == bitClass)
3763 bool needClass = true;
3765 if(*prev) f.Printf(", ");
3767 eClass_FindNextMember(_class, curClass, curMember, null, null);
3768 if(*curMember != (DataMember)prop)
3769 f.Printf("%s = ", prop.name);
3770 *curMember = (DataMember)prop;
3771 *curClass = curMember->_class;
3773 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3775 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3777 f.Printf("%s", string);
3779 *lastIsMethod = false;
3789 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3791 Instantiation inst = object.instCode;
3792 Window control = (Window)object.instance;
3794 bool methodPresent = false;
3796 bool lastIsMethod = true;
3797 ObjectInfo classObject = object.oClass;
3803 // Instance removed, delete it
3804 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3806 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3807 position = inst.loc.end.pos + 1;
3811 bool multiLine = false;
3814 // Check if it's an unnamed instance
3817 f.Seek(inst.nameLoc.start.pos - position, current);
3818 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3819 position = inst.nameLoc.end.pos;
3821 f.Printf(object.name);
3826 if(isspace(ch) && ch != '\n')
3828 f.Seek(-1, current);
3836 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3838 f.Seek(pos - position, current);
3843 f.Seek(-1, current);
3852 f.Puts(object.name);
3857 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3858 methodPresent = true;
3866 if(ch == OpenBracket)
3872 // TODO: Simplify this?
3881 f.Seek(-1, current);
3893 if(ch == '\n') { toDelete = count; count = 0; }
3894 else if(isspace(ch)) count++;
3897 f.Seek(-1, current);
3901 toDelete += count - 6;
3911 f.Seek(-toDelete-count, current);
3912 f.DeleteBytes(toDelete);
3913 f.Seek(count, current);
3918 for(c = 0; c<toAdd; c++)
3924 methodPresent = multiLine;
3927 f.Printf(methodPresent ? "\n " : " ");
3933 // Instance not there, create a brand new one
3934 DeleteJunkBefore(f, position, &position);
3935 f.Printf(*firstObject ? "\n\n" : "\n");
3936 *firstObject = false;
3938 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3939 methodPresent = true;
3944 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3946 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3951 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3953 f.Printf(" %s %c ", control._class.name, OpenBracket);
3959 Instance test = eInstance_New(control._class);
3960 DataMember curMember = null;
3961 Class curClass = null;
3964 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3968 // Attach Method here
3969 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3971 if(prev) f.Printf(", ");
3972 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3977 if(inst && !object.deleted)
3979 MembersInit members;
3980 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3982 DeleteJunkBefore(f, position, &position);
3984 // Instance already there, clear out the properties
3985 for(members = inst.members->first; members; members = members.next)
3987 if(members.type == dataMembersInit)
3991 if(members.dataMembers)
3993 bool keptMember = false;
3994 MemberInit lastKept = null;
3996 for(member = members.dataMembers->first; member; member = member.next)
3998 Identifier ident = member.identifiers ? member.identifiers->first : null;
3999 bool deleted = false;
4001 // For now delete if it's not a method
4002 if(!member.variable) // && ident)
4004 if(!ident || !ident.next)
4006 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
4009 f.Seek(member.loc.start.pos - position, current);
4010 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4011 position = member.loc.end.pos;
4016 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
4017 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
4018 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4020 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
4021 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
4023 f.Seek(member.loc.start.pos - position, current);
4024 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4025 position = member.loc.end.pos;
4037 //f.Seek(member.loc.start.pos - position, current);
4038 //position = member.loc.start.pos;
4039 DeleteJunkBefore(f, member.loc.start.pos, &position);
4040 if(prev) f.Printf(", ");
4041 else if(keptMember) f.Printf(" ");
4046 if(!keptMember || !members.next)
4051 if(keptMember && lastKept != members.dataMembers->last)
4056 f.Seek(-1, current);
4062 f.Seek(-1, current);
4065 else if(!isspace(ch))
4067 f.Seek(-2, current);
4072 f.DeleteBytes(count);
4075 f.Seek(members.loc.end.pos - position, current);
4080 f.Seek(-1, current);
4082 position = members.loc.end.pos + 1;
4086 f.Seek(-1, current);
4087 position = members.loc.end.pos;
4093 lastIsMethod = false;
4098 DeleteJunkBefore(f, position, &position);
4101 if(lastKept != members.dataMembers->last)
4106 f.Seek(-1, current);
4112 f.Seek(-1, current);
4115 else if(!isspace(ch))
4117 f.Seek(-2, current);
4122 f.DeleteBytes(count);
4126 f.Seek(members.loc.end.pos - position, current);
4127 position = members.loc.end.pos;
4131 lastIsMethod = true;
4134 lastIsMethod = false;
4140 f.Seek(members.loc.end.pos - position, current);
4141 position = members.loc.end.pos;
4143 lastIsMethod = true;
4146 else if(members.type == methodMembersInit)
4148 if(this.methodAction == actionDeleteMethod && members.function == function);
4150 methodPresent = true;
4152 // Delete instance method here
4153 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4154 members.function == function)
4156 if(this.moveAttached && !*text)
4157 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4159 DeleteJunkBefore(f, members.loc.start.pos, &position);
4160 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4161 position = members.loc.end.pos + 1;
4166 DeleteJunkBefore(f, position, &position);
4170 DeleteJunkBefore(f, members.loc.start.pos, &position);
4171 lastIsMethod = true;
4175 f.Seek(members.loc.end.pos - position, current);
4176 position = members.loc.end.pos;
4178 DeleteJunkBefore(f, position, &position);
4187 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4189 Method method = this.method;
4190 DeleteJunkBefore(f, position, &position);
4196 if(!method.dataType)
4197 method.dataType = ProcessTypeString(method.dataTypeString, false);
4200 Type dataType = method.dataType;
4201 Type returnType = dataType.returnType;
4204 if(this.moveAttached)
4206 // Move function here:
4207 int newLen = strlen(method.name);
4212 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4214 // First change name of function
4215 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4216 *textSize += newLen - movedFuncIdLen;
4217 memcpy(*text + movedFuncIdPos, method.name, newLen);
4219 // Second, tab right
4222 for(c = 0; (*text)[c]; )
4225 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4228 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4229 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4233 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4243 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4245 // ADDING METHOD HERE
4247 OutputType(f, returnType, false);
4250 if(dataType.thisClass)
4252 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4254 if(dataType.thisClass.shortName)
4255 f.Printf(dataType.thisClass.shortName);
4257 f.Printf(dataType.thisClass.string);
4261 f.Printf(method.name);
4263 for(param = dataType.params.first; param; param = param.next)
4265 OutputType(f, param, true);
4270 f.Printf(" %c\n\n", OpenBracket);
4272 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4274 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4275 f.Printf(" return true;\n");
4276 else if(returnType.kind != voidType)
4277 f.Printf(" return 0;\n");
4282 if(returnType.kind != voidType)
4283 f.Printf("return ");
4284 f.Printf("%s::%s(", control._class.name, method.name);
4285 for(param = dataType.params.first; param; param = param.next)
4287 if(param.prev) f.Printf(", ");
4288 if(param.kind != voidType)
4289 f.Printf(param.name);
4293 f.Printf(" %c\n", CloseBracket);
4299 if(!object.instCode)
4302 f.Printf(" %c;\n", CloseBracket);
4304 f.Printf("%c;\n", CloseBracket);
4306 else if(!object.deleted)
4308 // Turn this into a multiline instance when adding a method
4309 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4311 f.Printf(methodPresent ? "\n " : " ");
4313 f.Seek(inst.loc.end.pos + 1 - position, current);
4314 position = inst.loc.end.pos + 1;
4319 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4322 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4324 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4326 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4328 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4329 if(prop && prop.isProperty && !prop.conversion)
4331 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4332 (!prop.IsSet || prop.IsSet(classObject.instance)))
4334 Class dataType = prop.dataTypeClass;
4335 char tempString[1024] = "";
4337 bool specify = false;
4340 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4341 if(member && member._class == regClass)
4345 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4347 if(dataType && dataType.type == structClass)
4349 void * dataForm = new0 byte[dataType.structSize];
4350 void * dataTest = new0 byte[dataType.structSize];
4352 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4353 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4355 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4357 bool needClass = true;
4359 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4360 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4362 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4364 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4369 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4371 void * dataForm, * dataTest;
4373 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4374 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4376 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4378 char tempString[1024] = "";
4380 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4382 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4384 // Shouldn't go here ...
4385 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4389 bool needClass = true;
4391 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4393 if(!strcmp(dataType.dataTypeString, "char *"))
4395 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4396 OutputString(f, string);
4400 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4402 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4408 DataValue dataForm, dataTest;
4410 GetProperty(prop, classObject.instance, &dataForm);
4411 GetProperty(prop, test, &dataTest);
4413 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4415 SetProperty(prop, test, dataForm);
4416 if(dataType.type == bitClass)
4418 bool needClass = true;
4419 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4421 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4423 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4427 bool needClass = true;
4428 if(dataType.type == enumClass)
4431 Class enumClass = eSystem_FindClass(privateModule, "enum");
4432 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4434 for(value = e.values.first; value; value = value.next)
4436 if((int)value.data == dataForm.i)
4438 string = value.name;
4444 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4445 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4446 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4448 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4457 void UpdateFormCode()
4460 if(!parsing) return;
4467 else if(formModified)
4469 EditBoxStream f { editBox = editBox };
4473 Identifier movedFuncId;
4474 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4475 ObjectInfo classObject;
4481 movedFuncId = GetDeclId(function.declarator);
4482 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4483 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4486 for(classObject = classes.first; classObject; classObject = classObject.next)
4489 ClassDefinition classDef = classObject.classDefinition;
4490 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4493 bool firstObject = true;
4494 ObjectInfo object = classObject.instances.first;
4495 bool lastIsDecl = false;
4497 if(!classObject.modified) continue;
4499 test = eInstance_New(regClass);
4502 // Put it in the same desktop window...
4503 designer.PrepareTestObject(test);
4505 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4506 //f.Printf("%c\n\n", OpenBracket);
4508 // Change the _class name
4509 f.Seek(classDef.nameLoc.start.pos - position, current);
4510 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4511 f.Printf(classObject.name);
4512 position = classDef.nameLoc.end.pos;
4515 // Go to block start, delete all until no white space, put \n
4519 f.Seek(classDef.blockStart.end.pos - position, current);
4520 position = classDef.blockStart.end.pos;
4522 for(; f.Getc(&ch); count++)
4526 f.Seek(-1, current);
4536 f.Seek(-count, current);
4538 f.DeleteBytes(count-back);
4540 position += count-back;
4543 // Output properties
4544 OutputClassProperties(classObject.instance._class, classObject, f, test);
4546 for(def = classDef.definitions->first; def; def = def.next)
4550 case defaultPropertiesClassDef:
4552 bool keptMember = false;
4554 MemberInit lastKept = null;
4557 DeleteJunkBefore(f, def.loc.start.pos, &position);
4560 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4562 Identifier ident = propDef.identifiers->first;
4563 bool deleted = false;
4565 // For now delete if it's a prop
4566 if(!propDef.variable && ident)
4570 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4573 f.Seek(propDef.loc.start.pos - position, current);
4574 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4575 position = propDef.loc.end.pos;
4580 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4581 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4583 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4584 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4586 f.Seek(propDef.loc.start.pos - position, current);
4587 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4588 position = propDef.loc.end.pos;
4606 f.Seek(def.loc.end.pos - position - 1, current);
4611 f.Seek(-1, current);
4614 position = def.loc.end.pos;
4618 if(lastKept != def.defProperties->last)
4623 f.Seek(-1, current);
4629 f.Seek(-1, current);
4632 else if(!isspace(ch))
4634 f.Seek(-2, current);
4639 f.DeleteBytes(count);
4643 f.Seek(def.loc.end.pos - position, current);
4644 position = def.loc.end.pos;
4649 case declarationClassDef:
4651 Declaration decl = def.decl;
4653 if(decl.type == instDeclaration)
4655 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4657 while(def.object && object != def.object)
4659 if(object /*&& ((ObjectInfo)def.object).modified*/)
4660 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4661 object = object.next;
4664 DeleteJunkBefore(f, def.loc.start.pos, &position);
4665 f.Printf(firstObject ? "\n\n " : "\n ");
4666 firstObject = false;
4668 if(def.object && ((ObjectInfo)def.object).modified)
4669 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4671 object = object ? object.next : null;
4675 DeleteJunkBefore(f, def.loc.start.pos, &position);
4676 f.Printf(firstObject ? "\n\n " : "\n ");
4677 firstObject = false;
4683 DeleteJunkBefore(f, def.loc.start.pos, &position);
4684 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4689 case functionClassDef:
4691 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4692 if(!def.function.body) continue;
4696 DeleteJunkBefore(f, def.loc.start.pos, &position);
4699 // Delete _class methods
4700 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4701 def.function == function)
4706 if(moveAttached && !text)
4708 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4711 f.Seek(def.loc.end.pos - position, current);
4712 for(; f.Getc(&ch); count++)
4716 f.Seek(-1, current);
4720 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4722 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4723 position = def.loc.end.pos + count;
4726 // In case of detaching methods in the _class, simply rename the method
4727 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4729 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4730 f.DeleteBytes(movedFuncIdLen);
4732 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4735 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4736 function == def.function)
4738 // In case of attaching methods in the _class, simply rename the method
4739 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4740 position = function.loc.start.pos + movedFuncIdPos;
4741 f.DeleteBytes(movedFuncIdLen);
4742 if(method.dataType.thisClass)
4743 f.Printf("%s::", method.dataType.thisClass.string);
4744 f.Puts(method.name);
4745 position += movedFuncIdLen;
4750 DeleteJunkBefore(f, def.loc.start.pos, &position);
4751 if(def.type == memberAccessClassDef)
4754 firstObject = false;
4764 f.Seek(def.loc.end.pos - position, current);
4765 position = def.loc.end.pos;
4768 // Output attached methods
4769 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4771 DeleteJunkBefore(f, position, &position);
4772 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4775 // ********** INSTANCES ***************
4776 for(; object; object = object.next)
4778 if(!object.instCode)
4780 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4784 DeleteJunkBefore(f, position, &position);
4786 // ****************** METHODS ***********************
4787 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4789 // If detaching an instance method
4790 if(selected != classObject)
4792 int newLen = strlen(methodName);
4795 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4796 // Tab selection left
4799 for(c = 0; text[c]; )
4802 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4803 memmove(text+start, text+start+i, textSize+1-start-i);
4806 for(; text[c] && text[c] != '\n'; c++);
4812 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4813 textSize += newLen - movedFuncIdLen;
4814 memcpy(text + movedFuncIdPos, methodName, newLen);
4821 if(methodAction == actionAddMethod && selected == classObject)
4823 Method method = this.method;
4825 if(!method.dataType)
4826 method.dataType = ProcessTypeString(method.dataTypeString, false);
4828 // ADDING METHOD HERE
4830 Type dataType = method.dataType;
4831 Type returnType = dataType.returnType;
4833 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4837 OutputType(f, returnType, false);
4840 if(dataType.thisClass && !dataType.classObjectType)
4842 if(dataType.thisClass.shortName)
4843 f.Printf(dataType.thisClass.shortName);
4845 f.Printf(dataType.thisClass.string);
4848 f.Printf(method.name);
4850 for(param = dataType.params.first; param; param = param.next)
4852 OutputType(f, param, true);
4857 f.Printf(" %c\n\n", OpenBracket);
4859 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4861 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4862 f.Printf(" return true;\n");
4863 else if(returnType && returnType.kind != voidType)
4864 f.Printf(" return 0;\n");
4869 if(returnType.kind != voidType)
4870 f.Printf("return ");
4872 char * name = ((Specifier)classDef.baseSpecs->first).name;
4873 Symbol _class = FindClass(name);
4874 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4876 for(param = dataType.params.first; param; param = param.next)
4878 if(param.prev) f.Printf(", ");
4879 if(param.kind != voidType)
4880 f.Printf(param.name);
4885 f.Printf(" %c", CloseBracket);
4889 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4901 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4902 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4906 codeModified = false;
4907 formModified = false;
4909 moveAttached = false;
4914 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4917 ClassFunction function = null;
4920 ObjectInfo object = this.selected;
4922 if(object && object == this.oClass)
4924 ClassDefinition classDef = object.oClass.classDefinition;
4926 if(classDef && classDef.definitions)
4928 for(def = classDef.definitions->first; def; def = def.next)
4930 if(def.type == functionClassDef && def.function.declarator)
4932 if(!strcmp(def.function.declarator.symbol.string, methodName))
4934 function = def.function;
4939 else if(def.type == defaultPropertiesClassDef)
4943 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4945 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4946 if(ident && !ident.next)
4948 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4952 propLoc = propDef.loc;
4955 ClassDefinition classDef = object.oClass.classDefinition;
4957 if(classDef.definitions)
4959 for(def = classDef.definitions->first; def; def = def.next)
4961 if(def.type == functionClassDef)
4963 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4965 function = def.function;
4984 Instantiation inst = object.instCode;
4986 // Check here to see if the method already exists, no need to call ModifyCode in that case
4987 if(inst && inst.members)
4989 MembersInit members;
4990 for(members = inst.members->first; members; members = members.next)
4992 switch(members.type)
4994 case dataMembersInit:
4996 if(members.dataMembers)
4999 for(member = members.dataMembers->first; member; member = member.next)
5001 Identifier ident = member.identifiers ? member.identifiers->first : null;
5002 if(ident && !ident.next)
5004 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
5008 propLoc = member.loc;
5011 ClassDefinition classDef = object.oClass.classDefinition;
5013 if(classDef.definitions)
5015 for(def = classDef.definitions->first; def; def = def.next)
5017 if(def.type == functionClassDef)
5019 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
5021 function = def.function;
5030 // TODO: Fix memory leak
5031 function = ClassFunction
5033 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5045 case methodMembersInit:
5047 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5049 function = members.function;
5061 if(functionPtr) *functionPtr = function;
5065 void GoToMethod(char * methodName /*Method method*/)
5069 ObjectInfo object = selected;
5070 EditBoxStream f { editBox = editBox };
5071 ClassFunction function = null;
5072 bool atChar = false;
5076 Location propLoc = { {0,0,-1} };
5079 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5080 if(function && function.body)
5083 f.Seek(function.body.loc.start.pos+1, current);
5093 f.Seek(-1, current);
5098 else if(!isspace(ch))
5100 f.Seek(-1, current);
5106 else if(propLoc.start.pos > -1)
5108 f.Seek(propLoc.start.pos, current);
5111 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5113 if(function || propLoc.start.pos > -1)
5115 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5116 editBox.CenterOnCursor();
5117 SetState(normal, false, 0);
5120 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5122 FreeClassFunction(function);
5128 void FindCompatibleMethods(Method method, OldList compatible)
5130 ClassDefinition classDef = this.oClass.classDefinition;
5131 if(classDef && classDef.definitions)
5134 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5137 Symbol classSym { };
5138 Symbol selectedClass;
5139 if(this.selected == this.oClass)
5140 selectedClass = classSym;
5142 selectedClass = FindClass(this.selected.instance._class.name);
5144 regClass.name = classDef._class.name;
5145 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5146 for(def = classDef.definitions->first; def; def = def.next)
5148 if(def.type == functionClassDef && def.function.declarator)
5150 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5152 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5155 Type type = def.function.declarator.symbol.type;
5156 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5158 compatible.Add(OldLink { data = def.function });
5164 if(this.oClass && this.oClass.instance)
5166 classSym.registered = regClass;
5167 //classSym.registered = this.oClass.oClass;
5169 for(_class = regClass.base; _class; _class = _class.base)
5172 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5174 // TODO: Understand why these functions popup in attach list
5175 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5177 if(!testMethod.dataType)
5178 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5180 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5181 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5182 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5184 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5185 // ClassFunction function { };
5186 FunctionDefinition function { };
5188 function.declarator = Declarator { };
5189 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5190 excludedSymbols.Add(function.declarator.symbol);
5192 compatible.Add(OldLink { data = function });
5203 void AddMethod(Method method)
5207 char methodName[1024];
5208 strcpy(methodName, method.name);
5209 if(!FindMethod(methodName, null, null))
5211 methodAction = actionAddMethod;
5212 this.method = method;
5216 GoToMethod(methodName);
5220 void DeleteMethod(ClassFunction function)
5224 methodAction = actionDeleteMethod;
5225 this.function = function;
5233 void AttachMethod(Method method, ClassFunction function)
5237 // If it's an instance we'll ask if we want to move it inside...
5238 if(!function.attached.count && function.body)
5240 // Find the function in the _class to check if it's a virtual function
5241 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5242 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5243 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5245 for(def = this.classDefinition.first; def; def = def.next)
5247 if(def.type == functionClassDef)
5249 if(def.function == function)
5254 if(!method || method.type != virtualMethod)
5257 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5258 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5260 moveAttached = true;
5265 methodAction = actionAttachMethod;
5266 this.method = method;
5267 this.function = function;
5274 void ReAttachMethod(Method method, ClassFunction function)
5278 // If it's an instance we'll ask if we want to move it inside...
5279 if(!function.attached.count && function.body)
5281 // Find the function in the _class to check if it's a virtual function
5282 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5283 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5284 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5286 for(def = this.classDefinition.first; def; def = def.next)
5288 if(def.type == functionClassDef)
5290 if(def.function == function)
5295 if(!method || method.type != virtualMethod)
5298 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5299 if(MessageBox { type = yesNo, master = parent, text = title,
5300 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5302 moveAttached = true;
5307 methodAction = actionReattachMethod;
5308 this.method = method;
5309 this.function = function;
5316 void DetachMethod(Method method, ClassFunction function, int type)
5324 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5325 master = sheet, text = $"Name detached method", background = formColor
5329 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5330 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5334 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5335 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5339 dialog, anchor = { left = 5, right = 5, top = 5 }
5341 sprintf(methodName, "%s_%s", selected.name, method.name);
5342 nameBox.contents = methodName;
5344 result = dialog.Modal() == ok;
5345 strcpy(methodName, nameBox.contents);
5350 // If the method is not attached, move it outside
5353 // Add this class to the methodName
5354 char name[1024] = "";
5356 if(this.selected != this.oClass && !method.dataType.thisClass)
5358 strcat(name, this.selected.instance._class.name);
5360 strcat(name, this.methodName);
5361 strcpy(this.methodName, name);
5363 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5365 strcat(name, method.dataType.thisClass.string);
5367 strcat(name, this.methodName);
5368 strcpy(this.methodName, name);
5371 this.moveAttached = true;
5374 this.methodAction = actionDetachMethod;
5375 this.method = method;
5376 this.function = function;
5383 void AddObject(Instance instance, ObjectInfo * object)
5387 //*object = _class.instances.Add(sizeof(ObjectInfo));
5388 *object = ObjectInfo { };
5389 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5390 (*object).oClass = oClass;
5391 (*object).instance = instance;
5396 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5398 // if(strcmp(name, this.oClass.instance.name))
5401 for(check = oClass.instances.first; check; check = check.next)
5402 if(!check.deleted && check.name && !strcmp(name, check.name))
5406 (*object).name = CopyString(name);
5411 toolBox.controlClass = null;
5415 //sheet.AddObject(*object, (*object).name, TypeData, true);
5420 void EnsureUpToDate()
5422 if(sheet && codeModified && parsing)
5426 void SelectObject(ObjectInfo object)
5429 oClass = object ? object.oClass : null;
5431 designer.SelectObject(object, object ? object.instance : null);
5434 void SelectObjectFromDesigner(ObjectInfo object)
5437 sheet.SelectObject(object);
5440 void EnumerateObjects(Sheet sheet)
5444 for(oClass = classes.first; oClass; oClass = oClass.next)
5450 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5451 for(object = oClass.instances.first; object; object = object.next)
5452 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5455 sheet.SelectObject(selected);
5460 designer.AddObject();
5463 void DeleteObject(ObjectInfo object)
5465 delete object.instance;
5466 object.deleted = true;
5467 object.modified = true;
5468 object.oClass.modified = true;
5470 if(selected == object)
5472 bool looped = false;
5473 ObjectInfo select = object;
5477 select = select.prev;
5481 select = object.oClass.instances.last;
5488 sheet.SelectObject(select ? select : oClass);
5491 if(!object.instCode && object.oClass != object)
5494 oClass.instances.Delete(object);
5497 if(sheet.codeEditor == this)
5498 sheet.DeleteObject(object);
5501 void RenameObject(ObjectInfo object, char * name)
5505 // Validate the name:
5506 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5507 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5510 for(c = 0; name[c]; c++)
5511 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5519 object.name = (name && name[0]) ? CopyString(name) : null;
5521 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5525 void DesignerModifiedObject()
5527 sheet.ListProperties(false);
5531 void ListSubMembers(Type member)
5535 for(subMember = member.members.first; subMember; subMember = subMember.next)
5539 DataRow row = membersList.AddString(subMember.name);
5540 row.icon = icons[typeData];
5544 ListSubMembers(subMember);
5549 void ListSubDataMembers(DataMember member, bool isPrivate)
5551 DataMember subMember;
5552 for(subMember = member.members.first; subMember; subMember = subMember.next)
5554 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5558 DataRow row = membersList.AddString(subMember.name);
5559 BitmapResource bitmap = null;
5560 if(!subMember.dataType)
5561 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5563 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5565 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5568 bitmap = { bitmapName };
5569 membersList.AddResource(bitmap);
5572 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5576 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5582 void ListClassMembers(Class whatClass, bool methodsOnly)
5585 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5586 bool isPrivate = false;
5588 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5590 Method method, methodIt;
5592 DataMember memberIt;
5594 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5596 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5597 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5599 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5601 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5603 DataRow row = membersList.FindString(method.name);
5606 row = membersList.AddString(method.name);
5608 if(!method.dataType)
5609 method.dataType = ProcessTypeString(method.dataTypeString, false);
5611 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5619 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5623 if(memberIt.isProperty)
5625 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5627 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5631 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5633 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5636 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5642 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5644 if(member.isProperty)
5646 Property prop = (Property) member;
5647 if(!membersList.FindString(prop.name))
5649 DataRow row = membersList.AddString(prop.name);
5650 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5653 else if(member.name && !membersList.FindString(member.name))
5655 DataRow row = membersList.AddString(member.name);
5657 BitmapResource bitmap = null;
5658 if(!member.dataType)
5659 member.dataType = ProcessTypeString(member.dataTypeString, false);
5661 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5663 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5666 bitmap = { bitmapName };
5667 membersList.AddResource(bitmap);
5670 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5673 ListSubDataMembers(member, member.memberAccess == privateAccess);
5677 if(_class.inheritanceAccess == privateAccess)
5680 if(_class.module != privateModule) break;
5685 void ListClassMembersMatch(Class whatClass, Type methodType)
5688 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5689 bool isPrivate = false;
5691 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5697 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5699 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5701 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5703 if(!method.dataType)
5704 method.dataType = ProcessTypeString(method.dataTypeString, false);
5706 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5708 DataRow row = membersList.FindString(method.name);
5711 row = membersList.AddString(method.name);
5712 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5718 if(_class.inheritanceAccess == privateAccess)
5721 if(_class.module != privateModule) break;
5726 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5729 bool isPrivate = false;
5730 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5736 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5738 if(method.type == virtualMethod)
5740 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5742 DataRow row = membersList.FindString(method.name);
5745 row = membersList.AddString(method.name);
5747 if(!method.dataType)
5748 method.dataType = ProcessTypeString(method.dataTypeString, false);
5750 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5756 for(member = _class.membersAndProperties.first; member; member = member.next)
5758 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5760 if(member.isProperty)
5762 Property prop = (Property)member;
5764 DataRow row = membersList.AddString(prop.name);
5765 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5768 else if(member.name && (!curString || strcmp(curString, member.name)))
5770 DataRow row = membersList.AddString(member.name);
5772 BitmapResource bitmap = null;
5773 if(!member.dataType)
5774 member.dataType = ProcessTypeString(member.dataTypeString, false);
5776 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5778 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5781 bitmap = { bitmapName };
5782 membersList.AddResource(bitmap);
5785 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5788 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5791 if(_class.inheritanceAccess == privateAccess)
5794 if(_class.module != privateModule) break;
5799 void ListMembers(Type type)
5801 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5805 if(type.kind == classType)
5808 ListClassMembers(type._class.registered, false);
5813 for(member = type.members.first; member; member = member.next)
5817 DataRow row = membersList.AddString(member.name);
5818 row.icon = icons[typeData];
5820 else if(member.kind == structType || member.kind == unionType)
5821 ListSubMembers(member);
5827 void ListModule(Module mainModule, int recurse, bool listClasses)
5830 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5831 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5832 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5833 for(module = mainModule.application.allModules.first; module; module = module.next)
5835 if(ModuleVisibility(mainModule, module))
5836 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5840 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5847 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5849 Class _class = link.data;
5850 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5852 DataRow row = membersList.AddString(_class.name);
5853 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5858 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5860 DefinedExpression definedExp = link.data;
5861 DataRow row = membersList.AddString(link /*definedExp*/.name);
5862 row.icon = icons[typeData];
5865 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5867 GlobalFunction function = link.data;
5868 DataRow row = membersList.AddString(link /*function*/.name);
5869 row.icon = icons[typeMethod];
5873 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5875 if(recurse != 2 && listClasses)
5877 if(!membersList.FindString(ns->name))
5879 DataRow row = membersList.AddString(ns->name);
5880 row.icon = icons[typeNameSpace];
5885 ListNameSpace(ns, 2, listClasses);
5889 void ListEnumValues(Class _class)
5891 List<Class> classes { };
5892 for(; _class && _class.type == enumClass; _class = _class.base)
5893 classes.Insert(null, _class);
5894 for(_class : classes)
5896 EnumClassData enumeration = (EnumClassData)_class.data;
5898 for(item = enumeration.values.first; item; item = item.next)
5900 DataRow row = membersList.AddString(item.name);
5901 row.icon = icons[typeEnumValue];
5907 bool ListEnumsModule(Module mainModule, Type dest)
5909 bool result = false;
5911 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5912 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5913 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5914 for(module = mainModule.application.allModules.first; module; module = module.next)
5916 if(ModuleVisibility(mainModule, module))
5917 result |= ListEnums(module.publicNameSpace, dest);
5922 void ListNameSpaceByString(Module mainModule, char * string)
5924 NameSpace * nameSpace;
5926 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5927 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5928 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5929 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5930 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5931 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5932 for(module = mainModule.application.allModules.first; module; module = module.next)
5934 if(ModuleVisibility(mainModule, module))
5936 nameSpace = FindNameSpace(module.publicNameSpace, string);
5937 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5942 bool ListEnums(NameSpace nameSpace, Type dest)
5945 bool result = false;
5947 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5949 Class _class = link.data;
5950 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *"))) && !dest.classObjectType)) &&
5951 dest.kind != pointerType && dest.kind != ellipsisType)
5953 OldList conversions { };
5955 type.kind = classType;
5956 type._class = FindClass(_class.name);
5957 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5959 ListEnumValues(_class);
5962 conversions.Free(null);
5966 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5968 result |= ListEnums(nameSpace, dest);
5973 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5977 for(c = 0; (ch = name[c]); c++)
5979 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5981 NameSpace * newSpace;
5982 char * spaceName = new char[c - start + 1];
5983 memcpy(spaceName, name + start, c - start);
5984 spaceName[c-start] = '\0';
5985 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5989 nameSpace = newSpace;
5998 return (NameSpace *)nameSpace;
6001 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
6003 bool listedEnums = false;
6004 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
6005 bool listClasses = true;
6007 if(exp && (exp.type == identifierExp || exp.type == memberExp))
6009 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
6010 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
6011 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
6013 if(exp.type == identifierExp)
6014 id = realIdentifier;
6016 if(id && id._class && !id._class.name)
6018 listClasses = false;
6021 else if(id && id._class && id._class.name)
6025 Class _class = id.classSym.registered;
6026 if(_class && _class.type == enumClass)
6028 ListEnumValues(_class);
6031 ListClassMembers(id.classSym.registered, true);
6036 else if(id && colons)
6038 ListNameSpaceByString(this.privateModule, id.string);
6043 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6045 listedEnums = ListEnumsModule(this.privateModule, destType);
6048 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6050 ListEnumValues(destType._class.registered);
6053 ListClassPropertiesAndVirtual(insideClass, null);
6057 else if(destType && destType.kind == enumType)
6061 for(value = destType.members.first; value; value = value.next)
6063 DataRow row = membersList.AddString(value.name);
6064 row.icon = icons[typeEnumValue];
6068 ListClassPropertiesAndVirtual(insideClass, null);
6072 else if(insideClass && !enumOnly)
6074 ListClassPropertiesAndVirtual(insideClass, string);
6077 if(listedEnums && string && string[0])
6079 DataRow row = membersList.FindSubString(string);
6081 listedEnums = false;
6084 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6086 ListClassMembersMatch(GetThisClass(), exp.destType);
6088 else if(!insideClass && !enumOnly && !listedEnums)
6091 Symbol symbol = null;
6095 ListClassMembers(GetThisClass(), false);
6098 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6100 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6102 // Don't list enum values?
6103 //if(symbol.type.kind != TypeEnum)
6104 DataRow row = membersList.FindString(symbol.string);
6107 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6109 row = membersList.AddString(symbol.string);
6110 if(symbol.type && symbol.type.kind == functionType)
6111 row.icon = icons[typeMethod];
6112 else if(symbol.type && symbol.type.kind == enumType)
6114 row.icon = icons[typeEnumValue];
6118 BitmapResource bitmap = null;
6119 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6121 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6124 bitmap = { bitmapName };
6125 membersList.AddResource(bitmap);
6128 row.icon = bitmap ? bitmap : icons[typeData];
6135 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6137 DataRow row = membersList.FindString(symbol.string);
6140 row = membersList.AddString(symbol.string);
6141 if(symbol.type.kind == functionType)
6142 row.icon = icons[typeMethod];
6143 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6145 row.icon = icons[typeClass];
6149 row.icon = icons[typeDataType];
6156 ListModule(this.privateModule, 1, listClasses);
6157 // TODO: Implement this with name space
6161 for(data = globalData.first; data; data = data.next)
6163 DataRow row = membersList.FindString(data.name);
6165 data.dataType = ProcessTypeString(data.dataTypeString, false);
6168 row = membersList.AddString(data.name);
6170 if(data.dataType && data.dataType.kind == TypeEnum)
6172 row.icon = icons[typeEnumValue];
6176 BitmapResource bitmap = null;
6177 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6179 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6182 bitmap = { bitmapName };
6183 membersList.AddResource(bitmap);
6186 row.icon = bitmap ? bitmap : icons[typeData];
6194 DataRow row = membersList.AddString("Min");
6195 row.icon = icons[typeMethod];
6197 row = membersList.AddString("Max");
6198 row.icon = icons[typeMethod];
6200 row = membersList.AddString("Abs");
6201 row.icon = icons[typeMethod];
6203 row = membersList.AddString("Sgn");
6204 row.icon = icons[typeMethod];
6210 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6212 EditBoxStream f { editBox = editBox };
6217 updatingCode = true;
6219 if(!method.dataType)
6220 method.dataType = ProcessTypeString(method.dataTypeString, false);
6222 DeleteJunkBefore(f, function.loc.start.pos, &position);
6223 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6225 // ADDING METHOD HERE
6227 Type dataType = method.dataType;
6228 Type returnType = dataType.returnType;
6230 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6236 if(extraIndent) f.Printf(" ");
6238 OutputType(f, returnType, false);
6242 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6244 if(dataType.thisClass.shortName)
6245 f.Printf(dataType.thisClass.shortName);
6247 f.Printf(dataType.thisClass.string);
6250 f.Printf(method.name);
6252 for(param = dataType.params.first; param; param = param.next)
6254 // Decided not to write void...
6255 if(param.kind != voidType)
6257 OutputType(f, param, true);
6263 if(extraIndent) f.Printf(" ");
6264 f.Printf(" %c\n", OpenBracket);
6266 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6272 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6273 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6275 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6277 if(extraIndent) f.Printf(" ");
6278 f.Printf(" return true;\n");
6280 else if(returnType && returnType.kind != voidType)
6282 if(extraIndent) f.Printf(" ");
6283 f.Printf(" return 0;\n");
6288 if(extraIndent) f.Printf(" ");
6290 if(returnType.kind != voidType)
6291 f.Printf("return ");
6292 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6293 for(param = dataType.params.first; param; param = param.next)
6295 if(param.prev) f.Printf(", ");
6296 if(param.kind != voidType)
6297 f.Printf(param.name);
6303 if(extraIndent) f.Printf(" ");
6304 f.Printf(" %c", CloseBracket);
6309 if(extraIndent) { x1 += 3; x2 += 3; }
6310 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6312 this.updatingCode = false;
6316 // Return false if we overrided a function and don't want to run params listing
6317 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6319 bool didOverride = false;
6320 EditLine line = editBox.line;
6321 char * text = line.text;
6322 int lineNum, charPos;
6323 Expression exp = null;
6326 //Identifier id = null;
6327 Expression memberExp = null;
6328 Identifier realIdentifier = null;
6330 if(!parsing) return true;
6331 if(!privateModule) return !didOverride;
6333 insideFunction = null;
6335 charPos = editBox.charPos + 1;
6336 if(!membersListShown)
6341 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6343 EditBoxStream f { editBox = editBox };
6345 updatingCode = true;
6346 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6350 if(!f.Seek(-1, current))
6353 if(!isspace(ch)) break;
6354 f.Seek(-1, current);
6356 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6358 lineNum = editBox.lineNumber + 1;
6359 charPos = editBox.charPos + 1;
6361 updatingCode = false;
6364 if(!membersListShown)
6366 memberExp = FindExpTree(ast, lineNum, charPos);
6367 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6372 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6374 EditBoxStream f { editBox = editBox };
6377 updatingCode = true;
6379 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6382 if(ch == '}' || ch == ',' || ch == ')')
6384 f.Seek(-1, current);
6392 if(!f.Seek(-1, current))
6395 if(!isspace(ch)) break;
6396 f.Seek(-1, current);
6400 f.Seek(-1, current);
6402 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6404 lineNum = editBox.lineNumber + 1;
6405 charPos = editBox.charPos + 1;
6407 updatingCode = false;
6410 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6415 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6416 lineNum = editBox.lineNumber + 1;
6417 charPos = editBox.charPos/* + 1*/;
6421 char tempString[1024];
6422 char * string = null;
6423 CodePosition idStart, idEnd;
6425 if(membersListShown)
6427 char * buffer = membersLine.text;
6429 bool firstChar = true;
6431 string = tempString;
6433 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6435 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6436 if(!isSpace) firstChar = false;
6438 string[len++] = buffer[c];
6442 else //if(realIdentifier)//if(id)
6445 char * buffer = id.string;
6447 bool firstChar = true;
6449 string = tempString;
6450 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6452 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6453 if(!isSpace) firstChar = false;
6455 string[len++] = buffer[c];
6461 EditLine editLine = editBox.line;
6462 bool firstChar = true;
6465 string = tempString;
6466 for(y = lineNum-1; y >= 0; y--)
6468 char * buffer = editLine.text;
6469 int lineCount = editLine.count;
6470 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6472 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6477 idEnd.charPos = x + 2;
6482 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6485 idEnd.charPos = x + 2;
6492 if(!isalnum(buffer[x]) && buffer[x] != '_')
6498 memmove(string+1, string, len++);
6499 string[0] = buffer[x];
6503 //if(done || firstChar)
6504 if(done || !firstChar)
6506 editLine = editLine.prev;
6509 if(!strcmp(string, "case"))
6515 else if(!strcmp(string, "return"))
6521 else if(!strcmp(string, "delete"))
6527 else if(!strcmp(string, "new"))
6533 else if(!strcmp(string, "renew"))
6541 idStart.charPos = x + 1;
6542 idStart.line = y + 1;
6545 if(!membersListShown)
6547 membersList.Clear();
6548 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6550 Type type = memberExp.member.exp.expType;
6551 if(pointer == 2 && type)
6553 if(type.kind == pointerType || type.kind == arrayType)
6562 ListSymbols(exp, enumOnly, string, realIdentifier);
6564 membersList.Sort(null, 1);
6569 // Virtual function override
6570 Identifier id = GetDeclId(insideFunction.declarator);
6571 char * string = id ? id.string : null;
6573 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6576 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6577 insideFunction = null;
6580 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6585 if(!didOverride) //insideFunction)
6587 rowCount = membersList.rowCount;
6590 DataRow row = string ? membersList.FindSubString(string) : null;
6591 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6593 char * newString = row.string;
6594 if(!membersListShown)
6596 membersLoc.start.line = idStart.line-1;
6597 membersLoc.start.charPos = idStart.charPos-1;
6598 //membersLoc.end = membersLoc.start;
6599 membersLoc.end.charPos = idEnd.charPos-1;
6600 membersLoc.end.line = idEnd.line-1;
6601 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6602 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6607 membersList.Destroy(0);
6608 membersListShown = false;
6611 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6613 line, membersLoc.start.line, membersLoc.start.charPos,
6614 line, membersLoc.end.line, membersLoc.end.charPos);
6615 editBox.PutS(newString);
6621 row = membersList.FindSubStringi(string);
6623 membersList.currentRow = row;
6624 membersList.currentRow.selected = false;
6627 membersList.currentRow = row;
6629 if(!membersListShown)
6633 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6634 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6635 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6636 editBox.GetCaretPosition(caret);
6637 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6639 membersList.master = this;
6641 caret.y += editBox.GetCaretSize();
6643 membersList.Create();
6646 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6647 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6648 Window parent = membersList.parent;
6650 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6652 y -= editBox.GetCaretSize() + membersList.size.h;
6653 membersAbove = true;
6656 membersAbove = false;
6658 membersList.position = { x, y };
6662 membersLoc.start.line = lineNum - 1;
6664 if(string && string[0])
6666 membersLoc.start.charPos = idStart.charPos-1;
6667 membersLoc.end = membersLoc.start;
6668 //membersLoc.end.charPos = id.loc.end.charPos-1;
6669 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6673 membersLoc.start.charPos = charPos;
6674 membersLoc.end = membersLoc.start;
6675 membersLoc.end.charPos = charPos;
6677 membersListShown = true;
6679 // Hack to keep caret shown
6680 editBox.GetCaretPosition(caret);
6681 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6684 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6690 SetCurrentContext(globalContext);
6693 return !didOverride;
6696 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6698 EditLine line = editBox.line;
6699 char * text = line.text;
6700 int lineNum, charPos;
6701 Expression exp = null;
6705 if(!parsing) return;
6707 charPos = editBox.charPos + 1;
6710 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6712 EditBoxStream f { editBox = editBox };
6715 updatingCode = true;
6716 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6719 if(ch == '}' || ch == ',' || ch == ')')
6721 f.Seek(-1, current);
6729 if(!f.Seek(-1, current))
6732 if(!isspace(ch)) break;
6733 f.Seek(-1, current);
6737 f.Seek(-1, current);
6739 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6741 lineNum = editBox.lineNumber + 1;
6742 charPos = editBox.charPos + 1;
6744 updatingCode = false;
6747 charPos = Min(charPos, l1.count + 1);
6749 FindParamsTree(ast, lineNum, charPos);
6751 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6752 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6754 ::functionType = null;
6755 ::instanceType = null;
6758 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6759 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6763 Window parent = paramsList.parent;
6765 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6768 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6769 // ( Dummy exp: always ends up with same memory)
6771 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6772 editBox.GetCaretPosition(paramsPosition);
6773 this.paramsPosition.y += editBox.GetCaretSize();
6776 FreeType(this.functionType);
6777 FreeType(this.instanceType);
6779 this.functionType = ::functionType;
6780 this.instanceType = ::instanceType;
6782 if(this.functionType) this.functionType.refCount++;
6783 if(this.instanceType) this.instanceType.refCount++;
6785 this.paramsID = ::paramsID;
6786 functionExp = paramsInsideExp;
6788 paramsList.master = this;
6790 paramsList.Create();
6792 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6793 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6795 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6797 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6801 paramsAbove = false;
6802 if(x + paramsList.size.w > parent.clientSize.w)
6804 x = parent.clientSize.w - paramsList.size.w;
6808 paramsList.position = { x, y };
6810 // Hack to keep caret shown
6813 editBox.GetCaretPosition(caret);
6814 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6817 this.paramsShown = true;
6819 else if((!::functionType && !::instanceType) || reposition)
6821 paramsList.Destroy(0);
6822 paramsShown = false;
6824 FreeType(this.functionType);
6825 FreeType(this.instanceType);
6826 this.functionType = null;
6827 this.instanceType = null;
6831 SetCurrentContext(globalContext);
6839 designer.visible = true;
6840 designer.Activate();
6846 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6848 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };