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 };
686 void ProcessCaretMove(EditBox editBox, int line, int charPos)
689 ObjectInfo classItem;
691 // OnActivateClient is called after OnActivate
694 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
697 if(sheet.codeEditor != this) return;
701 for(classItem = classes.first; classItem; classItem = classItem.next)
703 ClassDefinition classDef = classItem.classDefinition;
704 if(classDef && classDef.loc.Inside(line, charPos))
711 for(object = classItem.instances.first; object; object = object.next)
715 if(object.instCode.loc.Inside(line, charPos))
720 sheet.SelectObject(object);
722 sheet.SelectObject(classItem);
727 //sheet.SelectObject(null);
731 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
735 expectingMove = false;
741 if(line-1 != membersLoc.start.line)
745 char * buffer = membersLine.text;
748 if(charPos - 1 < membersLoc.start.charPos)
750 else if(charPos - 1 > membersLoc.end.charPos)
752 char * buffer = membersLine.text;
753 //if(membersList.currentRow)
757 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
758 if(buffer[c] != ' ' && buffer[c] != '\t')
760 if(c < charPos && buffer[c])
767 membersList.Destroy(0);
768 membersListShown = false;
772 bool back = codeModified;
773 codeModified = false;
775 InvokeParameters(false, false, false);
776 /*if(membersListShown)
777 InvokeAutoComplete(false, 0, true);*/
784 watch(modifiedDocument)
786 ProjectView projectView = ide.projectView;
789 ProjectNode node = projectView.GetNodeFromWindow(this, null, false);
792 node.modified = modifiedDocument;
793 projectView.Update(null);
801 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
802 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
803 tabKey = true, smartHome = true;
804 tabSelection = true, /*maxLineSize = 65536, */parent = this, hasHorzScroll = true, hasVertScroll = true;
805 selectionColor = selectionColor, selectionText = selectionText,
806 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
807 font = font, borderStyle = none;
808 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
810 bool OnMouseOver(int x, int y, Modifiers mods)
812 CodeEditor editor = (CodeEditor)master;
813 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
818 void NotifyCaretMove(EditBox editBox, int line, int charPos)
820 // Update Line Numbers
822 int oldLine = lastLine;
823 display.FontExtent(font.font, " ", 1, null, &spaceH);
825 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
829 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
834 if(ide.activeClient == this)
835 ProcessCaretMove(editBox, line, charPos);
837 openedFileInfo.CaretMove(line, charPos);
840 void NotifyOvrToggle(EditBox editBox, bool overwrite)
842 ide.ovr.color = overwrite ? black : Color { 128, 128, 128 };
845 void NotifyUpdate(EditBox editBox)
852 designer.modifiedDocument = true;
855 modifiedDocument = true;
858 bool NotifyUnsetModified(EditBox editBox)
860 modifiedDocument = false;
864 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
866 if(!loadingFile && after.y != before.y)
868 ProjectView projectView = ide.projectView;
869 if(projectView && fileName)
872 // HOW WE MIGHT WANT TO DO IT:
873 char * text = before.line.text;
874 for(c = before.x-1; c>= 0; c--)
875 if(!isspace(text[c]))
877 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
879 // HOW VISUAL STUDIO DOES IT:
881 char * text = after.line.text;
882 for(c = after.line.count-1; c>= 0; c--)
883 if(!isspace(text[c]))
885 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
888 Update({ 0, 0, editBox.position.x, clientSize.h });
895 for(oClass = classes.first; oClass; oClass = oClass.next)
898 for(object = oClass.instances.first; object; object = object.next)
902 object.instCode.loc.start.AdjustAdd(before, after);
903 object.instCode.loc.end.AdjustAdd(before, after);
908 oClass.classDefinition.loc.start.AdjustAdd(before, after);
909 oClass.classDefinition.loc.end.AdjustAdd(before, after);
915 expectingMove = true;
919 if(before.y != after.y)
923 char * buffer = membersLine.text;
925 bool firstChar = true;
926 bool addedChar = false;
932 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
934 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
936 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
937 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
946 membersLoc.start.charPos++;
951 string[len++] = buffer[c];
955 row = membersList.currentRow;
956 if(row && row.selected)
960 membersLoc.start.charPos--;
968 row = membersList.FindSubString(string);
970 membersList.currentRow = row;
973 row = membersList.FindSubStringi(string);
975 membersList.currentRow = row;
976 membersList.currentRow.selected = false;
979 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
983 row = membersList.currentRow;
986 // Accept current string if hiding typing char
987 if(hide && row && row.selected)
989 char * string = row.string;
990 int len = strlen(string);
991 membersLoc.end.charPos -= after.x - before.x;
992 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
993 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
994 membersLine, membersLoc.end.line, membersLoc.end.charPos);
995 editBox.PutS(string);
996 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
998 after.x += membersLoc.start.charPos + len - before.x;
999 before.x = membersLoc.start.charPos + len;
1004 membersList.Destroy(0);
1005 membersListShown = false;
1008 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
1010 EditLine line = editBox.line;
1011 char * text = line.text;
1012 char ch = text[after.x-1];
1013 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1017 // Can we call invoke auto complete here instead?
1027 // Force caret update already...
1028 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1029 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1031 editBox.GetCaretPosition(&caret);
1035 // Go back in the buffer until no space before
1037 codeModified = true;
1041 EditBoxStream f { editBox = editBox };
1045 if(text[after.x-1] == '>')
1051 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1055 if(!f.Seek(-1, current))
1058 if(!isspace(ch)) break;
1059 f.Seek(-1, current);
1061 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1063 line = editBox.lineNumber + 1;
1064 charPos = editBox.charPos + 1;
1068 exp = FindExpTree(ast, line, charPos);
1072 Type type = exp.expType;
1074 if(type && text[after.x-1] != '.')
1076 if(type.kind == TypePointer || type.kind == TypeArray)
1082 membersList.Clear();
1085 if(membersList.rowCount)
1087 membersList.Sort(null, 1);
1088 membersList.master = this;
1090 caret.y += editBox.GetCaretSize();
1093 membersList.Create();
1096 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1097 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1098 Window parent = membersList.parent;
1100 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1102 y -= editBox.GetCaretSize() + membersList.GetHeight();
1103 membersAbove = true;
1106 membersAbove = false;
1108 membersList.position = { x, y };
1112 membersLoc.start.line = line - 1;
1113 membersLoc.start.charPos = oldCharPos;
1114 membersLoc.end = membersLoc.start;
1115 membersListShown = true;
1120 SetCurrentContext(globalContext);
1122 codeModified = true;
1123 skipModified = true;
1124 if(text[after.x-1] == ':')
1125 InvokeAutoComplete(false, 0, false);
1126 else if(text[after.x-1] == '.')
1127 InvokeAutoComplete(false, 1, false);
1128 else if(text[after.x-1] == '>')
1129 InvokeAutoComplete(false, 2, false);
1130 skipModified = false;
1132 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1134 codeModified = true;
1135 skipModified = true;
1137 if(InvokeAutoComplete(true, 0, false))
1139 if(ch == '(' || ch == OpenBracket)
1140 InvokeParameters(true, true, false);
1142 InvokeParameters(this.functionType ? false : true, false, false);
1145 // InvokeAutoComplete(true, 0, false);
1146 skipModified = false;
1148 else if(ch == ')' || ch == '}' || ch == ';')
1150 codeModified = true;
1151 skipModified = true;
1153 InvokeParameters(false, true, false);
1154 skipModified = false;
1158 bool back = codeModified;
1159 codeModified = false;
1161 InvokeParameters(false, false, true);
1162 if(membersListShown)
1163 InvokeAutoComplete(false, 0, true);
1164 codeModified = back;
1169 bool back = codeModified;
1170 codeModified = false;
1173 InvokeParameters(false, false, true);
1174 /*if(membersListShown)
1175 InvokeAutoComplete(false, 0, true);*/
1177 codeModified = back;
1184 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1186 if(!loadingFile && after.y != before.y)
1188 ProjectView projectView = ide.projectView;
1189 if(projectView && fileName)
1190 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1191 Update({ 0, 0, editBox.position.x, clientSize.h });
1198 for(oClass = classes.first; oClass; oClass = oClass.next)
1202 for(object = oClass.instances.first; object; object = object.next)
1206 loc = &object.instCode.loc;
1208 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1209 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1211 object.instCode = null;
1215 loc->start.AdjustDelete(before, after);
1216 loc->end.AdjustDelete(before, after);
1220 if(oClass.classDefinition)
1222 loc = &oClass.classDefinition.loc;
1223 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1224 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1226 oClass.classDefinition = null;
1230 loc->start.AdjustDelete(before, after);
1231 loc->end.AdjustDelete(before, after);
1236 if(membersListShown)
1239 if(pasteOperation || before.y != after.y)
1243 char * buffer = membersLine.text;
1245 bool firstChar = true;
1249 if(before.x >= membersLoc.start.charPos)
1251 for(c = membersLoc.start.charPos; c<before.x && len < sizeof(string)-1; c++)
1253 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1254 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1259 if(!isSpace) firstChar = false;
1262 string[len++] = buffer[c];
1267 // If deleting spaces before...
1268 for(c = before.x; c<membersLoc.start.charPos; c++)
1270 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1278 membersLoc.start.charPos = before.x;
1281 if(membersLoc.end.charPos >= after.x)
1283 for(c = after.x; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1285 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1286 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1291 if(!isSpace) firstChar = false;
1294 string[len++] = buffer[c];
1302 membersLoc.end.charPos -= after.x - before.x;
1306 row = membersList.FindSubString(string);
1309 row = membersList.FindSubStringi(string);
1311 membersList.currentRow = row;
1312 membersList.currentRow.selected = false;
1315 membersList.currentRow = row;
1317 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1322 membersList.Destroy(0);
1323 membersListShown = false;
1329 InvokeParameters(false, false);
1337 bool NotifyDropped(EditBox editBox, int x, int y)
1339 char * controlClass = toolBox.controlClass;
1340 if(controlClass && controlClass[0])
1344 ObjectInfo classObject;
1346 //editBox.NotifyCaretMove(this, editBox, y, x);
1347 editBox.GoToLineNum(y);
1348 editBox.GoToPosition(editBox.line, y, x);
1350 classObject = selected ? selected.oClass : null;
1352 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1353 selected = classObject.instances.last;
1356 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1359 AddObject(control, &object);
1361 designer.CreateObject(control, object, false, classObject.instance);
1362 // designer.PostCreateObject(control, object, false, classObject.instance);
1363 designer.DroppedObject(control, object, false, classObject.instance);
1365 sheet.AddObject(object, object.name, typeData /* className*/, true);
1368 //codeModified = true;
1375 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1377 if(key == Key { space, ctrl = true })
1379 membersList.Destroy(0);
1380 membersListShown = false;
1381 InvokeAutoComplete(false, 0, false);
1384 else if(key == Key { space, ctrl = true, shift = true })
1385 InvokeParameters(false, true, false);
1386 else if(key == escape)
1387 ide.RepositionWindows(true);
1388 else if(key == ctrlF7)
1392 ProjectNode node = ide.projectView.GetNodeFromWindow(this, null, false);
1394 node = ide.projectView.GetNodeFromWindow(this, null, true);
1398 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1399 $"It can't be compiled.");
1400 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1409 bool OnKeyDown(Key key, unichar ch)
1411 CodeEditor editor = (CodeEditor)master;
1412 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1414 if(editor.membersListShown)
1416 editor.membersList.Destroy(0);
1417 editor.membersListShown = false;
1420 if(editor.paramsShown)
1422 editor.paramsList.Destroy(0);
1423 editor.paramsShown = false;
1424 FreeType(editor.functionType);
1425 FreeType(editor.instanceType);
1427 editor.functionType = null;
1428 editor.instanceType = null;
1429 editor.paramsID = -1;
1433 return EditBox::OnKeyDown(key, ch);
1436 void OnVScroll(ScrollBarAction action, int position, Key key)
1438 if(anchor.left.distance)
1440 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1443 EditBox::OnVScroll(action, position, key);
1445 CodeEditor ce = (CodeEditor)parent;
1446 if(ce.openedFileInfo)
1447 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1451 void OnHScroll(ScrollBarAction action, int position, Key key)
1453 EditBox::OnHScroll(action, position, key);
1455 CodeEditor ce = (CodeEditor)parent;
1456 if(ce.openedFileInfo)
1457 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1464 fullRowSelect = false,
1467 borderStyle = bevel;
1468 // size = { 200, 400 };
1470 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1472 DataRow row = listBox.currentRow;
1475 char * string = row.string;
1477 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1479 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1480 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1481 editBox.PutS(string);
1484 membersListShown = false;
1489 bool OnKeyDown(Key key, unichar ch)
1491 CodeEditor editor = (CodeEditor) master;
1492 if(key == escape || key == leftAlt || key == rightAlt ||
1493 (key.ctrl && key.code != left && key.code != right &&
1494 key.code != leftShift && key.code != rightShift && key.code != space))
1496 if(editor.paramsShown)
1497 editor.paramsList.Destroy(0);
1498 if(editor.membersListShown)
1499 editor.membersList.Destroy(0);
1501 editor.paramsShown = false;
1502 FreeType(editor.functionType);
1503 FreeType(editor.instanceType);
1505 editor.functionType = null;
1506 editor.instanceType = null;
1507 editor.paramsID = -1;
1509 editor.membersListShown = false;
1513 return editor.editBox.OnKeyDown(key, ch);
1517 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1519 CodeEditor editor = (CodeEditor)master;
1523 editor.membersListShown = false;
1525 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1528 bool OnKeyHit(Key key, unichar ch)
1530 CodeEditor editor = (CodeEditor) master;
1534 case enter: case tab:
1536 DataRow row = currentRow;
1537 if(row && row.selected)
1539 char * string = row.string;
1541 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1542 editor.editBox.Delete(
1543 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1544 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1545 editor.editBox.PutS(string);
1548 editor.membersListShown = false;
1551 editor.editBox.OnKeyHit(key, ch);
1561 return ListBox::OnKeyHit(key, ch);
1567 // If before . or after
1568 //listBox.Destroy(true);
1569 result = editor.editBox.OnKeyHit(key, ch);
1584 clickThrough = true,
1586 borderStyle = contour,
1588 background = { 255,255,225 },
1590 OnKeyDown = membersList.OnKeyDown;
1592 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1594 CodeEditor editor = (CodeEditor)master;
1598 editor.membersListShown = false;
1600 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1603 bool OnKeyHit(Key key, unichar ch)
1605 CodeEditor editor = (CodeEditor)master;
1607 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1610 bool result = true; editor.editBox.OnKeyHit(key, ch);
1611 return (!created) ? false : result;
1618 void OnRedraw(Surface surface)
1620 CodeEditor editor = (CodeEditor) master;
1621 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1623 Type methodType = null;
1627 int functionW, nameW = 0;
1629 int spaceW, spaceH, commaW, commaWB, parW;
1631 int maxW = 0, lineW = 0;
1637 Font font = editor.normalFont.font;
1638 Font boldFont = editor.boldFont.font;
1639 Display display = this.display;
1641 if(!type) { return; };
1643 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1645 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1646 display.FontExtent(font, ", ", 2, &commaW, null);
1647 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1648 display.FontExtent(font, ")", 1, &parW, null);
1651 if(editor.functionType)
1653 PrintType(type.returnType, string, true, true);
1654 display.FontExtent(font, string, strlen(string), &functionW, null);
1656 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1657 totalW = nameW + functionW + 2 * parW;
1661 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1662 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1663 if(instanceName && type.kind != functionType)
1664 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1665 totalW = functionW + nameW;
1666 surface.TextFont(boldFont);
1669 surface.WriteText(x, y, string, strlen(string));
1670 x += functionW + spaceW;
1672 if(editor.functionType)
1675 surface.WriteText(x, y, type.name, strlen(type.name));
1677 surface.WriteText(x, y, "(", 1);
1680 if(methodType && !methodType.staticMethod && methodType.methodClass)
1684 if(id == editor.paramsID)
1685 surface.TextFont(boldFont);
1687 if(methodType.methodClass)
1688 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1692 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1693 width += ((id == editor.paramsID) ? commaWB : commaW);
1698 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1703 x = 2 + nameW + spaceW + functionW + parW;
1707 if(methodType.methodClass)
1708 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1711 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1713 surface.WriteText(x, y, ",", 1);
1714 x += ((id == editor.paramsID) ? commaWB : commaW);
1722 if(id == editor.paramsID)
1723 surface.TextFont(font);
1727 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1729 for(param = type.params.first; param; param = param.next)
1731 char paramString[1024];
1734 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1735 surface.TextFont(boldFont);
1738 PrintType(param, paramString, true, true);
1739 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1741 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1746 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1751 x = 2 + nameW + spaceW + functionW + parW;
1755 surface.WriteText(x, y, paramString, strlen(paramString));
1759 surface.WriteText(x, y, ",", 1);
1760 x += ((id == editor.paramsID) ? commaWB : commaW);
1768 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1769 surface.TextFont(font);
1774 surface.WriteText(x, y, ")", 1);
1776 else if(instanceName && type.kind != functionType)
1778 surface.WriteText(x, y, instanceName, strlen(instanceName));
1782 bool OnResizing(int * w, int * h)
1784 CodeEditor editor = (CodeEditor) master;
1785 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1787 Type methodType = null;
1791 int functionW = 0, nameW = 0;
1793 int spaceW, spaceH, commaW, commaWB, parW;
1795 int maxW = 0, lineW = 0;
1800 Font font = editor.normalFont.font;
1801 Font boldFont = editor.boldFont.font;
1802 Display display = this.display;
1804 if(type.kind == TypeKind::methodType)
1807 ProcessMethodType(type.method);
1808 type = type.method.dataType;
1811 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1812 display.FontExtent(font, ", ", 2, &commaW, null);
1813 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1814 display.FontExtent(font, ")", 1, &parW, null);
1817 if(editor.functionType && type)
1819 PrintType(type.returnType, string, true, true);
1820 display.FontExtent(font, string, strlen(string), &functionW, null);
1822 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1823 totalW = nameW + spaceW + functionW + 2 * parW;
1827 PrintType(type, string, false, true); // /*true);
1828 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1829 if(instanceName && type.kind != functionType)
1830 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1831 totalW = functionW + nameW + spaceW;
1834 if(editor.functionType)
1840 if(methodType.methodClass)
1841 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1842 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1843 width += ((id == editor.paramsID) ? commaWB : commaW);
1848 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1861 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1863 for(param = type.params.first; param; param = param.next)
1865 char paramString[1024];
1869 PrintType(param, paramString, true, true);
1870 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1872 width += ((id == editor.paramsID) ? commaWB : commaW);
1877 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1894 *w = realW + totalW + 4;
1900 Menu fileMenu { menu, $"File", f }; // MenuPlacement?
1901 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1902 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1904 Menu debugMenu { menu, $"Debug", d }; // MenuPlacement?
1905 MenuItem debugRunToCursor
1907 debugMenu, $"Run To Cursor", c, Key { f10, ctrl = true };
1908 bool NotifySelect(MenuItem selection, Modifiers mods)
1910 ProjectView projectView = ide.projectView;
1911 if(!projectView.buildInProgress)
1913 int line = editBox.lineNumber + 1;
1916 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1917 ProjectConfig config = projectView.project.config;
1918 int bitDepth = ide.workspace.bitDepth;
1919 ide.debugger.RunToCursor(compiler, config, bitDepth, fileName, line, false);
1926 MenuItem debugSkipRunToCursor
1928 debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true };
1929 bool NotifySelect(MenuItem selection, Modifiers mods)
1931 ProjectView projectView = ide.projectView;
1932 int line = editBox.lineNumber + 1;
1935 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1936 ProjectConfig config = projectView.project.config;
1937 int bitDepth = ide.workspace.bitDepth;
1938 ide.debugger.RunToCursor(compiler, config, bitDepth, fileName, line, true);
1944 MenuDivider { debugMenu };
1945 MenuItem debugToggleBreakpoint
1947 debugMenu, $"Toggle Breakpoint", t, f9;
1948 bool NotifySelect(MenuItem selection, Modifiers mods)
1950 ProjectView projectView = ide.projectView;
1951 if(projectView && fileName)
1953 int line = editBox.lineNumber + 1;
1954 char name[MAX_LOCATION];
1956 // TOFIX: This only looks at the filename...
1957 GetLastDirectory(fileName, name);
1958 if(ide && ide.workspace)
1960 for(p : ide.workspace.projects)
1962 if(p.topNode.Find(name, false))
1970 for(p : ide.workspace.projects)
1972 if(IsPathInsideOf(fileName, p.topNode.path))
1980 ide.debugger.ToggleBreakpoint(fileName, line, prj);
1990 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1994 designer.parent = parent;
1997 toolBox = ((IDEWorkSpace)master).toolBox;
1999 // Debugger bug here: value of toolBox appears as 0
2001 sheet = ((IDEWorkSpace)master).sheet;
2006 bool OnClose(bool parentClosing)
2010 if(ide.workspace && fileName)
2011 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2012 if(inUseDebug && !debugClosing)
2014 debugClosing = true;
2016 if(CloseConfirmation(false))
2019 OnFileModified({ modified = true }, null);
2021 debugClosing = false;
2024 if(designer && !designer.closing)
2026 if(designer.visible)
2033 //Window formEditor = designer;
2034 //formEditor.Destroy(0);
2037 ide.AdjustFileMenus();
2042 void OnDestroy(void)
2044 ObjectInfo oClass, next;
2045 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2047 FreeType(this.functionType);
2048 FreeType(this.instanceType);
2053 designer.codeEditor = null;
2054 designer.Destroy(0);
2058 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2060 ObjectInfo object, next;
2062 for(object = oClass.instances.first; object; object = next)
2067 Designer::DestroyObject(object.instance);
2068 delete object.instance;
2070 sheet.DeleteObject(object);
2072 oClass.instances.Delete(object);
2076 Designer::DestroyObject(oClass.instance);
2077 delete oClass.instance;
2079 sheet.DeleteObject(oClass);
2081 classes.Delete(oClass);
2084 if(windowClass && windowClass.data)
2085 UnapplySkin(windowClass);
2089 if(sheet.codeEditor == this)
2091 sheet.codeEditor = null;
2092 toolBox.codeEditor = null;
2098 ProjectView projectView = ide.projectView;
2101 ProjectNode node = projectView.GetNodeFromWindow(this, null, false);
2102 if(node && node.modified)
2104 node.modified = false;
2105 projectView.Update(null);
2111 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2113 // 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
2115 if(directActivation)
2116 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2118 if(active && directActivation)
2121 openedFileInfo.Activate();
2125 Location * loc = null;
2126 UpdateFormCode(); // To ensure update when modifying properties...
2128 // Got to the right spot in code so we don't lose our form selection...
2131 if(selected.instCode)
2132 loc = &selected.instCode.loc;
2133 else if(selected.classDefinition)
2134 loc = &selected.classDefinition.loc;
2136 line = editBox.lineNumber + 1;
2137 charPos = editBox.charPos + 1;
2142 if(selected && !loc->Inside(line, charPos))
2144 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2145 line = editBox.lineNumber + 1;
2146 charPos = editBox.charPos + 1;
2148 else if(selected && selected.classDefinition)
2151 for(object = selected.instances.first; object; object = object.next)
2155 if(object.instCode.loc.Inside(line, charPos))
2161 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2162 line = editBox.lineNumber + 1;
2163 charPos = editBox.charPos + 1;
2168 ProcessCaretMove(editBox, line, charPos);
2174 bool OnSaveFile(char * fileName)
2181 f = FileOpen(fileName, write);
2184 if(!ide.projectView)
2185 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2189 this.fileName = fileName; // Put this here because the form designer will check for it...
2190 designer.fileName = fileName;
2191 designer.modifiedDocument = false;
2193 editBox.Save(f, false);
2194 modifiedDocument = false;
2202 bool OnFileModified(FileChange fileChange, char * param)
2204 bool reload = false;
2205 if(visible == false && inUseDebug == true)
2211 sprintf(message, $"The document %s was modified by another application.\n"
2212 "Would you like to reload it and lose your changes?", fileName);
2213 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2214 contents = message }.Modal() == yes)
2220 File f = FileOpen(fileName, read);
2223 int lineNumber, charPos, len;
2227 updatingCode = true;
2228 lineNumber = editBox.lineNumber;
2229 charPos = editBox.charPos;
2230 scroll = editBox.scroll;
2233 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2234 len = strlen(editBox.line.text);
2235 editBox.GoToLineNum(lineNumber);
2236 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2237 editBox.scroll = scroll;
2238 updatingCode = false;
2239 loadingFile = false;
2241 codeModified = true;
2245 designer.modifiedDocument = false;
2247 modifiedDocument = false;
2255 void OnRedraw(Surface surface)
2258 surface.SetBackground(marginColor);
2259 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2260 if(ideSettings.showLineNumbers)
2262 int currentLineNumber;
2267 surface.textOpacity = false;
2268 surface.font = font.font;
2269 surface.TextExtent(" ", 1, null, &spaceH);
2270 currentLineNumber = editBox.scroll.y / spaceH + 1;
2272 surface.SetForeground(lineNumbersColor);
2273 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2275 // Highlight current line
2276 if(editBox.lineNumber == currentLineNumber - 1)
2278 surface.SetBackground(selectedMarginColor);
2279 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2280 surface.SetBackground(marginColor);
2282 sprintf(lineText,"%5u ", currentLineNumber % 100000);
2283 if(currentLineNumber <= editBox.numLines)
2284 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,6);
2286 currentLineNumber++;
2290 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2292 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2293 int lineCursor, lineTopFrame, breakpointLines[128];
2294 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2295 Debugger debugger = ide.debugger;
2296 BitmapResource bmpRes;
2298 boxH = clientSize.h;
2299 scrollY = editBox.scroll.y;
2300 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2302 bpOnCursor = bpOnTopFrame = false;
2303 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2306 for(i = 0; i < count; i++)
2308 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2310 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2311 if(breakpointLines[i] == lineCursor)
2313 if(breakpointLines[i] == lineTopFrame)
2314 bpOnTopFrame = true;
2317 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2319 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2322 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2323 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2324 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2326 if(editBox.anchor.left.distance)
2328 if(editBox.horzScroll && editBox.horzScroll.visible)
2330 surface.SetBackground(control);
2331 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2336 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2341 lineY = (line - 1) * lineH;
2342 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2344 Bitmap bitmap = resource.bitmap;
2346 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2353 char ext[MAX_EXTENSION];
2354 char * fileName = property::fileName;
2356 if(SearchString(fileName, 0, "Makefile", false, true))
2357 editBox.useTab = true;
2358 designer.fileName = fileName;
2362 GetExtension(fileName, ext);
2363 if(!strcmpi(ext, "ec"))
2365 codeModified = true;
2369 if(!strcmpi(ext, "ec") || !strcmpi(ext, "c") || !strcmpi(ext, "cc") || !strcmpi(ext, "cpp") || !strcmpi(ext, "eh") || !strcmpi(ext, "hh") || !strcmpi(ext, "hpp") || !strcmpi(ext, "h") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cxx"))
2370 editBox.syntaxHighlighting = true;
2372 editBox.syntaxHighlighting = false;
2375 display.FontExtent(font.font, " ", 1, &spaceW, null);
2376 editBox.anchor = Anchor
2378 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2379 right = 0, top = 0, bottom = 0
2388 display.FontExtent(font.font, " ", 1, &spaceW, null);
2389 editBox.anchor = Anchor
2391 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2392 right = 0, top = 0, bottom = 0
2397 bool LoadFile(char * filePath)
2399 File f = FileOpen(filePath, read);
2402 // Added this here...
2403 fileName = filePath;
2405 updatingCode = true;
2407 updatingCode = false;
2408 loadingFile = false;
2417 void DebugMenusDisabled()
2419 bool debugMenusDisabled = ide.GetDebugMenusDisabled();
2420 debugRunToCursor.disabled = debugMenusDisabled;
2421 debugSkipRunToCursor.disabled = debugMenusDisabled;
2422 debugToggleBreakpoint.disabled = debugMenusDisabled;
2428 ProjectView projectView = ide.projectView;
2431 designer.fileName = fileName;
2437 sprintf(title, $"Untitled %d", documentID);
2438 // designer.fileName = CopyString(title);
2439 designer.fileName = title;
2442 DebugMenusDisabled();
2444 for(c = 0; c < CodeObjectType::enumSize; c++)
2445 icons[c] = BitmapResource { iconNames[c], window = this };
2447 codeModified = true;
2459 selected.modified = true;
2460 selected.oClass.modified = true;
2462 designer.modifiedDocument = true;
2463 modifiedDocument = true;
2464 formModified = true;
2467 /****************************************************************************
2469 ****************************************************************************/
2477 this.defines.Free(FreeModuleDefine);
2478 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2480 FreeExcludedSymbols(this.excludedSymbols);
2481 FreeContext(this.globalContext);
2483 FreeGlobalData(&this.globalData);
2484 FindCtx_Terminate();
2485 FindParams_Terminate();
2487 if(GetGlobalContext() == globalContext)
2489 SetGlobalData(null);
2490 SetGlobalContext(null);
2491 SetExcludedSymbols(null);
2492 SetTopContext(null);
2493 SetCurrentContext(null);
2496 SetPrivateModule(null);
2499 if(this.privateModule)
2501 FreeTypeData(this.privateModule);
2502 delete this.privateModule;
2503 this.privateModule = null;
2509 static bool reentrant = false;
2514 char * selectedClassName = null, * selectedName = null;
2515 int selectedPos = 0;
2516 Designer backDesigner;
2517 char oldWorkDir[MAX_LOCATION];
2518 char mainModuleName[MAX_FILENAME] = "";
2520 ImportedModule module;
2521 char extension[MAX_EXTENSION];
2522 PathBackup pathBackup { };
2524 Time parseCodeStart = GetTime();
2525 Time startTime, startFindClass;
2527 findClassTotalTime = 0;
2528 checkTypeTotalTime = 0;
2529 externalImportTotalTime = 0;
2530 findClassIgnoreNSTotalTime = 0;
2531 findSymbolTotalTime = 0;
2532 //ResetClassFindTime();
2536 // 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)
2537 if(reentrant) return;
2544 selectedClassName = CopyString(oClass.name);
2545 if(selected != oClass)
2547 ObjectInfo object = this.selected;
2548 selectedName = CopyString(object.name);
2552 for(check = this.oClass.instances.first; check; check = check.next)
2564 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2566 FindCtx_Terminate();
2567 FindParams_Terminate();
2569 SetGlobalData(&globalData);
2570 SetGlobalContext(globalContext);
2571 SetExcludedSymbols(&excludedSymbols);
2572 SetTopContext(globalContext);
2573 SetCurrentContext(globalContext);
2574 SetDefines(&defines);
2575 SetImports(&imports);
2576 SetCurrentNameSpace(null);
2579 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2580 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2581 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2582 "/I T:\\ecere\\include /E %s", argv[1]);
2586 ChangeWorkingDir("e:\\ec");
2587 sprintf(command, "gcc -x c -E -");
2588 fileInput = DualPipeOpen({ output = true, input = true }, command);
2589 SetFileInput(fileInput);
2594 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2596 fileInput.Write(buffer, 1, count);
2601 fileInput.CloseOutput();
2605 // TOCHECK: COULDN'T WE CALL FreeParser here?
2607 FreeType(this.functionType);
2608 FreeType(this.instanceType);
2609 this.functionType = null;
2610 this.instanceType = null;
2613 sheet.SelectObject(null);
2619 // We don't want the designer to be notified of selection when deleting rows...
2620 backDesigner = designer;
2625 ObjectInfo _class, next;
2627 for(_class = classes.first; _class; _class = next)
2633 for(;object = _class.instances.first;)
2637 Designer::DestroyObject(object.instance);
2638 delete object.instance;
2640 sheet.DeleteObject(object);
2642 _class.instances.Delete(object);
2646 Designer::DestroyObject(_class.instance);
2647 delete _class.instance;
2649 sheet.DeleteObject(_class);
2651 classes.Delete(_class);
2657 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2658 if(windowClass && windowClass.data)
2659 UnapplySkin(windowClass);
2662 designer = backDesigner;
2665 fileInput = editFile = EditBoxStream { editBox = editBox };
2666 SetFileInput(fileInput);
2674 defines.Free(FreeModuleDefine);
2675 imports.Free(FreeModuleImport);
2677 FreeContext(this.globalContext);
2678 FreeExcludedSymbols(this.excludedSymbols);
2681 FreeGlobalData(&this.globalData);
2683 if(this.privateModule)
2685 FreeTypeData(this.privateModule);
2686 delete this.privateModule;
2690 startTime = GetTime();
2691 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2693 printf("classes.count: %d\n", globalContext.classes.count);
2698 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2699 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2702 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2704 SetPrivateModule(privateModule);
2707 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2708 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2709 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2710 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2711 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2714 fileName = this.fileName;
2716 if(ide.workspace && ide.workspace.projects && fileName)
2718 for(p : ide.workspace.projects)
2720 char path[MAX_LOCATION];
2722 MakePathRelative(fileName, p.topNode.path, path);
2723 MakeSlashPath(path);
2725 pn = p.topNode.FindWithPath(path, false);
2734 project = ide.project;
2736 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2738 ChangeWorkingDir(project.topNode.path);
2740 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2742 GetLastDirectory(fileName, mainModuleName);
2743 GetExtension(mainModuleName, extension);
2745 SetBuildingEcereCom(false);
2746 SetBuildingEcereComModule(false);
2748 // TODO: Get symbolsDir from project settings instead...
2751 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2752 ProjectConfig config = project.config;
2753 int bitDepth = ide.workspace.bitDepth;
2754 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2755 SetSymbolsDir(objDir.dir);
2756 ide.SetPath(true, compiler, config, bitDepth);
2760 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2761 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2765 switch(GetRuntimePlatform())
2767 case win32: SetSymbolsDir("obj/debug.win32"); break;
2768 case tux: SetSymbolsDir("obj/debug.linux"); break;
2769 case apple: SetSymbolsDir("obj/debug.apple"); break;
2771 SetIncludeDirs(null);
2772 SetSysIncludeDirs(null);
2776 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2778 // TODO FIX for configless project
2779 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2781 for(item : ide.project.config.options.preprocessorDefinitions)
2783 if(!strcmp(item, "BUILDING_ECERE_COM"))
2785 SetBuildingEcereCom(true);
2792 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2793 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2794 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2795 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2796 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2797 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2798 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2799 strcmpi(mainModuleName, "Mutex.ec")))
2801 SetBuildingEcereComModule(true);
2804 // Predeclare all classes
2806 char symFile[MAX_FILENAME];
2807 char symLocation[MAX_LOCATION];
2808 ImportedModule module, next;
2810 GetLastDirectory(fileName, symFile);
2811 ChangeExtension(symFile, "sym", symFile);
2813 strcpy(symLocation, GetSymbolsDir());
2814 PathCat(symLocation, symFile);
2816 // if(!GetEcereImported() && !GetBuildingEcereCom())
2817 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2820 startTime = GetTime();
2822 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2824 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2829 startTime = GetTime();
2831 // LoadSymbols(symLocation, normalImport, true);
2832 LoadSymbols(symLocation, preDeclImport, false);
2834 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2837 for(module = defines.first; module; module = next)
2840 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2843 defines.Delete(module);
2848 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2850 SetDefaultDeclMode(privateAccess);
2851 SetDeclMode(privateAccess);
2855 SetDefaultDeclMode(defaultAccess);
2856 SetDeclMode(defaultAccess);
2859 StripExtension(mainModuleName);
2860 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2861 defines.AddName(module);
2864 // SetYydebug(true);
2869 startTime = GetTime();
2870 startFindClass = checkTypeTotalTime;
2874 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2876 CheckDataRedefinitions();
2879 SetIncludeDirs(null);
2880 SetSysIncludeDirs(null);
2891 startTime = GetTime();
2893 PrePreProcessClassDefinitions();
2894 ComputeModuleClasses(privateModule);
2895 PreProcessClassDefinitions();
2896 ProcessClassDefinitions();
2898 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2899 startTime = GetTime();
2904 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2905 startTime = GetTime();
2907 ProcessInstantiations();
2909 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2912 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2914 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2915 if(!windowClass || windowClass.internalDecl)
2918 startTime = GetTime();
2920 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2921 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2922 eModule_Load(this.privateModule, "ecere", privateAccess);
2924 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2927 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2929 if(windowClass && windowClass.data)
2930 ApplySkin(windowClass, app.currentSkin.name, null);
2934 startTime = GetTime();
2936 for(external = ast->first; external; external = external.next)
2938 if(external.type == classExternal)
2940 ClassDefinition _class = external._class;
2941 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2943 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2946 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2948 Instance instance = eInstance_New(regClass);
2949 ObjectInfo classObject
2951 name = CopyString(_class._class.name);
2952 instance = instance;
2953 classDefinition = _class;
2954 oClass = classObject;
2957 classes.Add(classObject);
2961 // Moved this at bottom so that the file dialog doesn't show up in eCom
2962 designer.CreateObject(instance, classObject, true, null);
2963 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
2965 if(_class.definitions)
2969 for(def = _class.definitions->first; def; def = def.next)
2973 case defaultPropertiesClassDef:
2976 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
2978 Identifier id = propDef.identifiers->first;
2981 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
2984 Class propertyClass = prop.dataTypeClass;
2986 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
2987 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
2989 FreeType(propDef.initializer.exp.destType);
2990 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
2991 ProcessExpressionType(propDef.initializer.exp);
2993 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
2995 Expression computed = CopyExpression(propDef.initializer.exp);
2996 ComputeExpression(computed);
2998 if(computed.isConstant && computed.type == instanceExp && !id.next)
3002 if(computed.instance._class && computed.instance._class.symbol &&
3003 computed.instance._class.symbol.registered &&
3004 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3006 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3008 // This was saved in the control and shouldn't be freed by FreeExpression...
3009 if(propertyClass.type == normalClass)
3010 computed.instance.data = null;
3014 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3015 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3017 String temp = new char[strlen(computed.string)+1];
3018 ReadString(temp, computed.string);
3019 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3023 propDef.variable = true;
3025 FreeExpression(computed);
3029 Expression computed = CopyExpression(propDef.initializer.exp);
3030 ComputeExpression(computed);
3031 if(computed.isConstant)
3033 //if(computed.type == memberExp) computed = computed.member.exp;
3035 if(computed.type == constantExp)
3037 Operand value = GetOperand(computed);
3038 DataValue valueData;
3039 valueData.i64 = value.i64;
3040 SetProperty(prop, instance, valueData);
3042 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3044 String temp = new char[strlen(computed.string)+1];
3045 ReadString(temp, computed.string);
3046 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3051 propDef.variable = true;
3053 FreeExpression(computed);
3057 propDef.variable = true;
3061 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3062 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3063 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3066 // Maintain a list in FunctionDefinition of who is attached to it
3067 for(def = _class.definitions->first; def; def = def.next)
3069 if(def.type == functionClassDef)
3071 ClassFunction function = def.function;
3072 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3074 function.attached.Add(OldLink { data = method });
3084 case declarationClassDef:
3086 Declaration decl = def.decl;
3089 case instDeclaration:
3091 Instantiation inst = decl.inst;
3092 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3093 if(instClass && eClass_GetDesigner(instClass))
3095 Instance control = eInstance_New(instClass);
3100 oClass = classObject;
3104 classObject.instances.Add(object);
3106 // TOCHECK: Why is this needed now?
3107 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3108 def.object = object;
3110 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3112 designer.CreateObject(control, object, false, classObject.instance);
3113 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3123 // Second pass, process instantiation members
3125 for(def = _class.definitions->first; def; def = def.next)
3129 case declarationClassDef:
3131 Declaration decl = def.decl;
3134 case instDeclaration:
3136 Instantiation inst = decl.inst;
3137 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3138 if(instClass && eClass_GetDesigner(instClass))
3141 object = object ? object.next : classObject.instances.first;
3142 control = object.instance;
3146 MembersInit members;
3147 for(members = inst.members->first; members; members = members.next)
3149 switch(members.type)
3151 case dataMembersInit:
3153 if(members.dataMembers)
3156 DataMember curMember = null;
3157 Class curClass = null;
3158 DataMember subMemberStack[256];
3159 int subMemberStackPos = 0;
3161 for(member = members.dataMembers->first; member; member = member.next)
3164 Identifier ident = member.identifiers ? member.identifiers->first : null;
3167 DataMember _subMemberStack[256];
3168 int _subMemberStackPos = 0;
3169 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3173 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3175 if(thisMember && thisMember.memberAccess == publicAccess)
3177 curMember = thisMember;
3178 curClass = curMember._class;
3179 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3180 subMemberStackPos = _subMemberStackPos;
3186 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3187 if(curMember) found = true;
3189 if(found && curMember.isProperty)
3191 Property prop = (Property) curMember;
3192 Class propertyClass = prop.dataTypeClass;
3194 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3196 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3198 FreeType(member.initializer.exp.destType);
3199 member.initializer.exp.destType = MkClassType(propertyClass.name);
3202 ProcessExpressionType(member.initializer.exp);
3204 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3206 Expression computed;
3208 /*char debugExpString[4096];
3209 debugExpString[0] = '\0';
3210 PrintExpression(member.initializer.exp, debugExpString);*/
3212 computed = CopyExpression(member.initializer.exp);
3215 ComputeExpression(computed);
3217 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3219 if(computed.instance.data)
3221 if(computed.instance._class && computed.instance._class.symbol &&
3222 computed.instance._class.symbol.registered &&
3223 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3225 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3227 // This was saved in the control and shouldn't be freed by FreeExpression...
3228 if(propertyClass.type == normalClass)
3229 computed.instance.data = null;
3233 else if(computed.type == identifierExp)
3235 member.variable = true;
3237 if(eClass_GetDesigner(propertyClass))
3240 char * name = computed.identifier.string;
3241 if(!strcmp(name, "this"))
3244 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3245 member.variable = false;
3250 for(check = classObject.instances.first; check; check = check.next)
3251 if(check.name && !strcmp(name, check.name))
3254 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3255 member.variable = false;
3261 else if(computed.type == memberExp)
3263 member.variable = true;
3264 if(computed.member.exp.type == identifierExp)
3266 char * name = computed.member.exp.identifier.string;
3267 if(!strcmp(name, "this"))
3269 char * name = computed.member.member.string;
3272 for(check = classObject.instances.first; check; check = check.next)
3273 if(check.name && !strcmp(name, check.name))
3276 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3277 member.variable = false;
3285 for(check = classObject.instances.first; check; check = check.next)
3287 if(check.name && !strcmp(name, check.name))
3289 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3292 DataValue value { };
3293 GetProperty(getProperty, check.instance, &value);
3294 SetProperty(prop, control, value);
3295 member.variable = false;
3303 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3304 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3306 String temp = new char[strlen(computed.string)+1];
3307 ReadString(temp, computed.string);
3308 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3312 member.variable = true;
3314 FreeExpression(computed);
3319 Expression computed = CopyExpression(member.initializer.exp);
3322 ComputeExpression(computed);
3323 if(computed.isConstant)
3325 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3327 if(!strcmp(propertyClass.dataTypeString, "float"))
3328 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3329 else if(!strcmp(propertyClass.dataTypeString, "double"))
3330 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3332 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3334 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3336 String temp = new char[strlen(computed.string)+1];
3337 ReadString(temp, computed.string);
3338 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3343 member.variable = true;
3345 FreeExpression(computed);
3351 member.variable = true;
3353 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3354 member.initializer.exp.type == memberExp) // identifierExp
3356 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3357 if(method && method.type == virtualMethod)
3360 // Maintain a list in FunctionDefinition of who is attached to it
3361 for(def = _class.definitions->first; def; def = def.next)
3363 if(def.type == functionClassDef)
3365 ClassFunction function = def.function;
3366 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3367 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3369 function.attached.Add(OldLink { data = method });
3370 // Reference this particular instance?
3385 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3396 //designer.CreateObject(instance, classObject, true, null);
3397 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3399 designer.PostCreateObject(instance, classObject, true, null);
3401 //instance.state = Hidden;
3402 //instance.Create();
3403 //instance.SetState(Normal, true, 0);
3412 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3416 // Restore Selection
3417 if(selectedClassName)
3420 for(oClass = classes.first; oClass; oClass = oClass.next)
3422 if(!strcmp(oClass.name, selectedClassName))
3424 this.oClass = oClass;
3428 delete selectedClassName;
3437 for(check = this.oClass.instances.first; check; check = check.next)
3439 if(check.name && !strcmp(check.name, selectedName))
3441 this.selected = check;
3447 if(this.oClass.instances.first)
3448 this.selected = this.oClass.instances.first;
3450 this.selected = this.oClass;
3453 else if(selectedPos == -1 || !this.oClass.instances.count)
3454 this.selected = this.oClass;
3460 if(selectedPos > this.oClass.instances.count)
3462 for(check = this.oClass.instances.first; check; check = check.next)
3464 if(selectedPos == pos++)
3466 this.selected = check;
3474 this.oClass = classes.first;
3475 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3477 delete selectedName;
3478 SetSymbolsDir(null);
3480 if(sheet.codeEditor == this)
3481 sheet.SelectObject(selected);
3484 codeModified = false;
3486 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3489 InvokeParameters(false, false, false);
3492 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3498 ChangeWorkingDir(oldWorkDir);
3500 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3501 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3502 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3503 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3504 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3506 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3508 if(inUseDebug && ide.projectView)
3509 ide.debugger.EvaluateWatches();
3514 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3517 Window control = (Window)object.instance;
3518 ObjectInfo classObject = object.oClass;
3520 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3522 if(!strcmp(_class.name, "DesignerBase")) return;
3524 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3526 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3527 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3529 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3530 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3532 Class dataType = prop.dataTypeClass;
3534 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3538 if(dataType.type == structClass)
3540 void * dataForm = new0 byte[dataType.structSize];
3541 void * dataTest = new0 byte[dataType.structSize];
3543 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3544 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3546 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3548 char tempString[1024] = "";
3550 bool needClass = true;
3554 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3556 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3558 eClass_FindNextMember(_class, curClass, curMember, null, null);
3559 if(*curMember != (DataMember)prop)
3560 f.Printf("%s = ", prop.name);
3562 *curMember = (DataMember)prop;
3563 *curClass = curMember->_class;
3566 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3568 f.Printf("%s", string);
3575 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3577 void * dataForm, * dataTest;
3579 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3580 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3582 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3584 char tempString[1024] = "";
3589 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3591 eClass_FindNextMember(_class, curClass, curMember, null, null);
3592 if(*curMember != (DataMember)prop)
3593 f.Printf("%s = ", prop.name);
3594 *curMember = (DataMember)prop;
3595 *curClass = curMember->_class;
3597 if(eClass_GetDesigner(dataType))
3599 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3600 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3601 f.Printf("this", prop.name);
3604 //ObjectInfo classObject;
3605 //for(classObject = classes.first; classObject; classObject = classObject.next)
3609 for(object = classObject.instances.first; object; object = object.next)
3611 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3613 f.Printf("%s", object.name);
3620 bool needClass = true;
3621 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3622 f.Printf("%s", string);
3629 bool needClass = true;
3630 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3632 if(!strcmp(dataType.dataTypeString, "char *"))
3635 OutputString(f, string);
3639 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3641 f.Printf("%s", string);
3644 *lastIsMethod = false;
3649 DataValue dataForm, dataTest;
3651 GetProperty(prop, control, &dataForm);
3652 GetProperty(prop, test, &dataTest);
3654 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3657 char tempString[1024] = "";
3658 SetProperty(prop, test, dataForm);
3660 if(dataType.type != bitClass)
3662 bool needClass = true;
3664 if(dataType.type == enumClass)
3667 Class enumClass = eSystem_FindClass(privateModule, "enum");
3668 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3670 for(value = e.values.first; value; value = value.next)
3672 if((int)value.data == dataForm.i)
3674 string = value.name;
3680 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3682 if(string && string[0])
3687 eClass_FindNextMember(_class, curClass, curMember, null, null);
3688 if(*curMember != (DataMember)prop)
3689 f.Printf("%s = ", prop.name);
3690 *curMember = (DataMember)prop;
3691 *curClass = curMember->_class;
3693 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3694 f.Printf("%sf", string);
3696 f.Printf("%s", string);
3700 else if(dataType.type == bitClass)
3702 bool needClass = true;
3704 if(*prev) f.Printf(", ");
3706 eClass_FindNextMember(_class, curClass, curMember, null, null);
3707 if(*curMember != (DataMember)prop)
3708 f.Printf("%s = ", prop.name);
3709 *curMember = (DataMember)prop;
3710 *curClass = curMember->_class;
3712 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3714 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3716 f.Printf("%s", string);
3718 *lastIsMethod = false;
3728 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3730 Instantiation inst = object.instCode;
3731 Window control = (Window)object.instance;
3733 bool methodPresent = false;
3735 bool lastIsMethod = true;
3736 ObjectInfo classObject = object.oClass;
3742 // Instance removed, delete it
3743 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3745 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3746 position = inst.loc.end.pos + 1;
3750 bool multiLine = false;
3753 // Check if it's an unnamed instance
3756 f.Seek(inst.nameLoc.start.pos - position, current);
3757 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3758 position = inst.nameLoc.end.pos;
3760 f.Printf(object.name);
3765 if(isspace(ch) && ch != '\n')
3767 f.Seek(-1, current);
3775 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3777 f.Seek(pos - position, current);
3782 f.Seek(-1, current);
3791 f.Puts(object.name);
3796 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3797 methodPresent = true;
3805 if(ch == OpenBracket)
3811 // TODO: Simplify this?
3820 f.Seek(-1, current);
3832 if(ch == '\n') { toDelete = count; count = 0; }
3833 else if(isspace(ch)) count++;
3836 f.Seek(-1, current);
3840 toDelete += count - 6;
3850 f.Seek(-toDelete-count, current);
3851 f.DeleteBytes(toDelete);
3852 f.Seek(count, current);
3857 for(c = 0; c<toAdd; c++)
3863 methodPresent = multiLine;
3866 f.Printf(methodPresent ? "\n " : " ");
3872 // Instance not there, create a brand new one
3873 DeleteJunkBefore(f, position, &position);
3874 f.Printf(*firstObject ? "\n\n" : "\n");
3875 *firstObject = false;
3877 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3878 methodPresent = true;
3883 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3885 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3890 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3892 f.Printf(" %s %c ", control._class.name, OpenBracket);
3898 Instance test = eInstance_New(control._class);
3899 DataMember curMember = null;
3900 Class curClass = null;
3903 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3907 // Attach Method here
3908 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3910 if(prev) f.Printf(", ");
3911 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3916 if(inst && !object.deleted)
3918 MembersInit members;
3919 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3921 DeleteJunkBefore(f, position, &position);
3923 // Instance already there, clear out the properties
3924 for(members = inst.members->first; members; members = members.next)
3926 if(members.type == dataMembersInit)
3930 if(members.dataMembers)
3932 bool keptMember = false;
3933 MemberInit lastKept = null;
3935 for(member = members.dataMembers->first; member; member = member.next)
3937 Identifier ident = member.identifiers ? member.identifiers->first : null;
3938 bool deleted = false;
3940 // For now delete if it's not a method
3941 if(!member.variable) // && ident)
3943 if(!ident || !ident.next)
3945 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3948 f.Seek(member.loc.start.pos - position, current);
3949 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3950 position = member.loc.end.pos;
3955 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3956 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3957 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
3959 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
3960 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
3962 f.Seek(member.loc.start.pos - position, current);
3963 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3964 position = member.loc.end.pos;
3976 //f.Seek(member.loc.start.pos - position, current);
3977 //position = member.loc.start.pos;
3978 DeleteJunkBefore(f, member.loc.start.pos, &position);
3979 if(prev) f.Printf(", ");
3980 else if(keptMember) f.Printf(" ");
3985 if(!keptMember || !members.next)
3990 if(keptMember && lastKept != members.dataMembers->last)
3995 f.Seek(-1, current);
4001 f.Seek(-1, current);
4004 else if(!isspace(ch))
4006 f.Seek(-2, current);
4011 f.DeleteBytes(count);
4014 f.Seek(members.loc.end.pos - position, current);
4019 f.Seek(-1, current);
4021 position = members.loc.end.pos + 1;
4025 f.Seek(-1, current);
4026 position = members.loc.end.pos;
4032 lastIsMethod = false;
4037 DeleteJunkBefore(f, position, &position);
4040 if(lastKept != members.dataMembers->last)
4045 f.Seek(-1, current);
4051 f.Seek(-1, current);
4054 else if(!isspace(ch))
4056 f.Seek(-2, current);
4061 f.DeleteBytes(count);
4065 f.Seek(members.loc.end.pos - position, current);
4066 position = members.loc.end.pos;
4070 lastIsMethod = true;
4073 lastIsMethod = false;
4079 f.Seek(members.loc.end.pos - position, current);
4080 position = members.loc.end.pos;
4082 lastIsMethod = true;
4085 else if(members.type == methodMembersInit)
4087 if(this.methodAction == actionDeleteMethod && members.function == function);
4089 methodPresent = true;
4091 // Delete instance method here
4092 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4093 members.function == function)
4095 if(this.moveAttached && !*text)
4096 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4098 DeleteJunkBefore(f, members.loc.start.pos, &position);
4099 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4100 position = members.loc.end.pos + 1;
4105 DeleteJunkBefore(f, position, &position);
4109 DeleteJunkBefore(f, members.loc.start.pos, &position);
4110 lastIsMethod = true;
4114 f.Seek(members.loc.end.pos - position, current);
4115 position = members.loc.end.pos;
4117 DeleteJunkBefore(f, position, &position);
4126 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4128 Method method = this.method;
4129 DeleteJunkBefore(f, position, &position);
4135 if(!method.dataType)
4136 method.dataType = ProcessTypeString(method.dataTypeString, false);
4139 Type dataType = method.dataType;
4140 Type returnType = dataType.returnType;
4143 if(this.moveAttached)
4145 // Move function here:
4146 int newLen = strlen(method.name);
4151 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4153 // First change name of function
4154 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4155 *textSize += newLen - movedFuncIdLen;
4156 memcpy(*text + movedFuncIdPos, method.name, newLen);
4158 // Second, tab right
4161 for(c = 0; (*text)[c]; )
4164 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4167 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4168 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4172 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4182 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4184 // ADDING METHOD HERE
4186 OutputType(f, returnType, false);
4189 if(dataType.thisClass)
4191 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4193 if(dataType.thisClass.shortName)
4194 f.Printf(dataType.thisClass.shortName);
4196 f.Printf(dataType.thisClass.string);
4200 f.Printf(method.name);
4202 for(param = dataType.params.first; param; param = param.next)
4204 OutputType(f, param, true);
4209 f.Printf(" %c\n\n", OpenBracket);
4211 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4213 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4214 f.Printf(" return true;\n");
4215 else if(returnType.kind != voidType)
4216 f.Printf(" return 0;\n");
4221 if(returnType.kind != voidType)
4222 f.Printf("return ");
4223 f.Printf("%s::%s(", control._class.name, method.name);
4224 for(param = dataType.params.first; param; param = param.next)
4226 if(param.prev) f.Printf(", ");
4227 if(param.kind != voidType)
4228 f.Printf(param.name);
4232 f.Printf(" %c\n", CloseBracket);
4238 if(!object.instCode)
4241 f.Printf(" %c;\n", CloseBracket);
4243 f.Printf("%c;\n", CloseBracket);
4245 else if(!object.deleted)
4247 // Turn this into a multiline instance when adding a method
4248 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4250 f.Printf(methodPresent ? "\n " : " ");
4252 f.Seek(inst.loc.end.pos + 1 - position, current);
4253 position = inst.loc.end.pos + 1;
4258 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4261 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4263 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4265 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4267 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4268 if(prop && prop.isProperty && !prop.conversion)
4270 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4271 (!prop.IsSet || prop.IsSet(classObject.instance)))
4273 Class dataType = prop.dataTypeClass;
4274 char tempString[1024] = "";
4276 bool specify = false;
4279 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4280 if(member && member._class == regClass)
4284 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4286 if(dataType && dataType.type == structClass)
4288 void * dataForm = new0 byte[dataType.structSize];
4289 void * dataTest = new0 byte[dataType.structSize];
4291 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4292 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4294 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4296 bool needClass = true;
4298 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4299 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4301 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4303 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4308 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4310 void * dataForm, * dataTest;
4312 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4313 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4315 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4317 char tempString[1024] = "";
4319 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4321 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4323 // Shouldn't go here ...
4324 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4328 bool needClass = true;
4330 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4332 if(!strcmp(dataType.dataTypeString, "char *"))
4334 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4335 OutputString(f, string);
4339 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4341 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4347 DataValue dataForm, dataTest;
4349 GetProperty(prop, classObject.instance, &dataForm);
4350 GetProperty(prop, test, &dataTest);
4352 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4354 SetProperty(prop, test, dataForm);
4355 if(dataType.type == bitClass)
4357 bool needClass = true;
4358 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4360 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4362 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4366 bool needClass = true;
4367 if(dataType.type == enumClass)
4370 Class enumClass = eSystem_FindClass(privateModule, "enum");
4371 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4373 for(value = e.values.first; value; value = value.next)
4375 if((int)value.data == dataForm.i)
4377 string = value.name;
4383 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4384 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4385 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4387 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4396 void UpdateFormCode()
4405 else if(formModified)
4407 EditBoxStream f { editBox = editBox };
4411 Identifier movedFuncId;
4412 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4413 ObjectInfo classObject;
4419 movedFuncId = GetDeclId(function.declarator);
4420 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4421 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4424 for(classObject = classes.first; classObject; classObject = classObject.next)
4427 ClassDefinition classDef = classObject.classDefinition;
4428 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4431 bool firstObject = true;
4432 ObjectInfo object = classObject.instances.first;
4433 bool lastIsDecl = false;
4435 if(!classObject.modified) continue;
4437 test = eInstance_New(regClass);
4440 // Put it in the same desktop window...
4441 designer.PrepareTestObject(test);
4443 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4444 //f.Printf("%c\n\n", OpenBracket);
4446 // Change the _class name
4447 f.Seek(classDef.nameLoc.start.pos - position, current);
4448 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4449 f.Printf(classObject.name);
4450 position = classDef.nameLoc.end.pos;
4453 // Go to block start, delete all until no white space, put \n
4457 f.Seek(classDef.blockStart.end.pos - position, current);
4458 position = classDef.blockStart.end.pos;
4460 for(; f.Getc(&ch); count++)
4464 f.Seek(-1, current);
4474 f.Seek(-count, current);
4476 f.DeleteBytes(count-back);
4478 position += count-back;
4481 // Output properties
4482 OutputClassProperties(classObject.instance._class, classObject, f, test);
4484 for(def = classDef.definitions->first; def; def = def.next)
4488 case defaultPropertiesClassDef:
4490 bool keptMember = false;
4492 MemberInit lastKept = null;
4495 DeleteJunkBefore(f, def.loc.start.pos, &position);
4498 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4500 Identifier ident = propDef.identifiers->first;
4501 bool deleted = false;
4503 // For now delete if it's a prop
4504 if(!propDef.variable && ident)
4508 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4511 f.Seek(propDef.loc.start.pos - position, current);
4512 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4513 position = propDef.loc.end.pos;
4518 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4519 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4521 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4522 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4524 f.Seek(propDef.loc.start.pos - position, current);
4525 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4526 position = propDef.loc.end.pos;
4544 f.Seek(def.loc.end.pos - position - 1, current);
4549 f.Seek(-1, current);
4552 position = def.loc.end.pos;
4556 if(lastKept != def.defProperties->last)
4561 f.Seek(-1, current);
4567 f.Seek(-1, current);
4570 else if(!isspace(ch))
4572 f.Seek(-2, current);
4577 f.DeleteBytes(count);
4581 f.Seek(def.loc.end.pos - position, current);
4582 position = def.loc.end.pos;
4587 case declarationClassDef:
4589 Declaration decl = def.decl;
4591 if(decl.type == instDeclaration)
4593 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4595 while(def.object && object != def.object)
4597 if(object /*&& ((ObjectInfo)def.object).modified*/)
4598 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4599 object = object.next;
4602 DeleteJunkBefore(f, def.loc.start.pos, &position);
4603 f.Printf(firstObject ? "\n\n " : "\n ");
4604 firstObject = false;
4606 if(def.object && ((ObjectInfo)def.object).modified)
4607 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4609 object = object ? object.next : null;
4613 DeleteJunkBefore(f, def.loc.start.pos, &position);
4614 f.Printf(firstObject ? "\n\n " : "\n ");
4615 firstObject = false;
4621 DeleteJunkBefore(f, def.loc.start.pos, &position);
4622 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4627 case functionClassDef:
4629 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4630 if(!def.function.body) continue;
4634 DeleteJunkBefore(f, def.loc.start.pos, &position);
4637 // Delete _class methods
4638 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4639 def.function == function)
4644 if(moveAttached && !text)
4646 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4649 f.Seek(def.loc.end.pos - position, current);
4650 for(; f.Getc(&ch); count++)
4654 f.Seek(-1, current);
4658 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4660 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4661 position = def.loc.end.pos + count;
4664 // In case of detaching methods in the _class, simply rename the method
4665 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4667 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4668 f.DeleteBytes(movedFuncIdLen);
4670 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4673 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4674 function == def.function)
4676 // In case of attaching methods in the _class, simply rename the method
4677 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4678 position = function.loc.start.pos + movedFuncIdPos;
4679 f.DeleteBytes(movedFuncIdLen);
4680 if(method.dataType.thisClass)
4681 f.Printf("%s::", method.dataType.thisClass.string);
4682 f.Puts(method.name);
4683 position += movedFuncIdLen;
4688 DeleteJunkBefore(f, def.loc.start.pos, &position);
4689 if(def.type == memberAccessClassDef)
4692 firstObject = false;
4702 f.Seek(def.loc.end.pos - position, current);
4703 position = def.loc.end.pos;
4706 // Output attached methods
4707 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4709 DeleteJunkBefore(f, position, &position);
4710 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4713 // ********** INSTANCES ***************
4714 for(; object; object = object.next)
4716 if(!object.instCode)
4718 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4722 DeleteJunkBefore(f, position, &position);
4724 // ****************** METHODS ***********************
4725 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4727 // If detaching an instance method
4728 if(selected != classObject)
4730 int newLen = strlen(methodName);
4733 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4734 // Tab selection left
4737 for(c = 0; text[c]; )
4740 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4741 memmove(text+start, text+start+i, textSize+1-start-i);
4744 for(; text[c] && text[c] != '\n'; c++);
4750 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4751 textSize += newLen - movedFuncIdLen;
4752 memcpy(text + movedFuncIdPos, methodName, newLen);
4759 if(methodAction == actionAddMethod && selected == classObject)
4761 Method method = this.method;
4763 if(!method.dataType)
4764 method.dataType = ProcessTypeString(method.dataTypeString, false);
4766 // ADDING METHOD HERE
4768 Type dataType = method.dataType;
4769 Type returnType = dataType.returnType;
4771 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4775 OutputType(f, returnType, false);
4778 if(dataType.thisClass && !dataType.classObjectType)
4780 if(dataType.thisClass.shortName)
4781 f.Printf(dataType.thisClass.shortName);
4783 f.Printf(dataType.thisClass.string);
4786 f.Printf(method.name);
4788 for(param = dataType.params.first; param; param = param.next)
4790 OutputType(f, param, true);
4795 f.Printf(" %c\n\n", OpenBracket);
4797 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4799 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4800 f.Printf(" return true;\n");
4801 else if(returnType && returnType.kind != voidType)
4802 f.Printf(" return 0;\n");
4807 if(returnType.kind != voidType)
4808 f.Printf("return ");
4810 char * name = ((Specifier)classDef.baseSpecs->first).name;
4811 Symbol _class = FindClass(name);
4812 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4814 for(param = dataType.params.first; param; param = param.next)
4816 if(param.prev) f.Printf(", ");
4817 if(param.kind != voidType)
4818 f.Printf(param.name);
4823 f.Printf(" %c", CloseBracket);
4827 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4839 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4840 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4844 codeModified = false;
4845 formModified = false;
4847 moveAttached = false;
4852 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4855 ClassFunction function = null;
4858 ObjectInfo object = this.selected;
4860 if(object && object == this.oClass)
4862 ClassDefinition classDef = object.oClass.classDefinition;
4864 if(classDef && classDef.definitions)
4866 for(def = classDef.definitions->first; def; def = def.next)
4868 if(def.type == functionClassDef && def.function.declarator)
4870 if(!strcmp(def.function.declarator.symbol.string, methodName))
4872 function = def.function;
4877 else if(def.type == defaultPropertiesClassDef)
4881 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4883 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4884 if(ident && !ident.next)
4886 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4890 propLoc = propDef.loc;
4893 ClassDefinition classDef = object.oClass.classDefinition;
4895 if(classDef.definitions)
4897 for(def = classDef.definitions->first; def; def = def.next)
4899 if(def.type == functionClassDef)
4901 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4903 function = def.function;
4922 Instantiation inst = object.instCode;
4924 // Check here to see if the method already exists, no need to call ModifyCode in that case
4925 if(inst && inst.members)
4927 MembersInit members;
4928 for(members = inst.members->first; members; members = members.next)
4930 switch(members.type)
4932 case dataMembersInit:
4934 if(members.dataMembers)
4937 for(member = members.dataMembers->first; member; member = member.next)
4939 Identifier ident = member.identifiers ? member.identifiers->first : null;
4940 if(ident && !ident.next)
4942 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4946 propLoc = member.loc;
4949 ClassDefinition classDef = object.oClass.classDefinition;
4951 if(classDef.definitions)
4953 for(def = classDef.definitions->first; def; def = def.next)
4955 if(def.type == functionClassDef)
4957 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
4959 function = def.function;
4968 // TODO: Fix memory leak
4969 function = ClassFunction
4971 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
4983 case methodMembersInit:
4985 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
4987 function = members.function;
4999 if(functionPtr) *functionPtr = function;
5003 void GoToMethod(char * methodName /*Method method*/)
5007 ObjectInfo object = selected;
5008 EditBoxStream f { editBox = editBox };
5009 ClassFunction function = null;
5010 bool atChar = false;
5014 Location propLoc = { {0,0,-1} };
5017 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5018 if(function && function.body)
5021 f.Seek(function.body.loc.start.pos+1, current);
5031 f.Seek(-1, current);
5036 else if(!isspace(ch))
5038 f.Seek(-1, current);
5044 else if(propLoc.start.pos > -1)
5046 f.Seek(propLoc.start.pos, current);
5049 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5051 if(function || propLoc.start.pos > -1)
5053 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5054 editBox.CenterOnCursor();
5055 SetState(normal, false, 0);
5058 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5060 FreeClassFunction(function);
5066 void FindCompatibleMethods(Method method, OldList compatible)
5068 ClassDefinition classDef = this.oClass.classDefinition;
5069 if(classDef && classDef.definitions)
5072 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5075 Symbol classSym { };
5076 Symbol selectedClass;
5077 if(this.selected == this.oClass)
5078 selectedClass = classSym;
5080 selectedClass = FindClass(this.selected.instance._class.name);
5082 regClass.name = classDef._class.name;
5083 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5084 for(def = classDef.definitions->first; def; def = def.next)
5086 if(def.type == functionClassDef && def.function.declarator)
5088 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5090 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5093 Type type = def.function.declarator.symbol.type;
5094 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5096 compatible.Add(OldLink { data = def.function });
5102 if(this.oClass && this.oClass.instance)
5104 classSym.registered = regClass;
5105 //classSym.registered = this.oClass.oClass;
5107 for(_class = regClass.base; _class; _class = _class.base)
5110 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5112 // TODO: Understand why these functions popup in attach list
5113 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5115 if(!testMethod.dataType)
5116 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5118 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5119 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5120 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5122 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5123 // ClassFunction function { };
5124 FunctionDefinition function { };
5126 function.declarator = Declarator { };
5127 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5128 excludedSymbols.Add(function.declarator.symbol);
5130 compatible.Add(OldLink { data = function });
5141 void AddMethod(Method method)
5145 char methodName[1024];
5146 strcpy(methodName, method.name);
5147 if(!FindMethod(methodName, null, null))
5149 methodAction = actionAddMethod;
5150 this.method = method;
5154 GoToMethod(methodName);
5158 void DeleteMethod(ClassFunction function)
5162 methodAction = actionDeleteMethod;
5163 this.function = function;
5171 void AttachMethod(Method method, ClassFunction function)
5175 // If it's an instance we'll ask if we want to move it inside...
5176 if(!function.attached.count && function.body)
5178 // Find the function in the _class to check if it's a virtual function
5179 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5180 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5181 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5183 for(def = this.classDefinition.first; def; def = def.next)
5185 if(def.type == functionClassDef)
5187 if(def.function == function)
5192 if(!method || method.type != virtualMethod)
5195 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5196 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5198 moveAttached = true;
5203 methodAction = actionAttachMethod;
5204 this.method = method;
5205 this.function = function;
5212 void ReAttachMethod(Method method, ClassFunction function)
5216 // If it's an instance we'll ask if we want to move it inside...
5217 if(!function.attached.count && function.body)
5219 // Find the function in the _class to check if it's a virtual function
5220 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5221 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5222 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5224 for(def = this.classDefinition.first; def; def = def.next)
5226 if(def.type == functionClassDef)
5228 if(def.function == function)
5233 if(!method || method.type != virtualMethod)
5236 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5237 if(MessageBox { type = yesNo, master = parent, text = title,
5238 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5240 moveAttached = true;
5245 methodAction = actionReattachMethod;
5246 this.method = method;
5247 this.function = function;
5254 void DetachMethod(Method method, ClassFunction function, int type)
5262 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5263 master = sheet, text = $"Name detached method", background = formColor
5267 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5268 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5272 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5273 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5277 dialog, anchor = { left = 5, right = 5, top = 5 }
5279 sprintf(methodName, "%s_%s", selected.name, method.name);
5280 nameBox.contents = methodName;
5282 result = dialog.Modal() == ok;
5283 strcpy(methodName, nameBox.contents);
5288 // If the method is not attached, move it outside
5291 // Add this class to the methodName
5292 char name[1024] = "";
5294 if(this.selected != this.oClass && !method.dataType.thisClass)
5296 strcat(name, this.selected.instance._class.name);
5298 strcat(name, this.methodName);
5299 strcpy(this.methodName, name);
5301 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5303 strcat(name, method.dataType.thisClass.string);
5305 strcat(name, this.methodName);
5306 strcpy(this.methodName, name);
5309 this.moveAttached = true;
5312 this.methodAction = actionDetachMethod;
5313 this.method = method;
5314 this.function = function;
5321 void AddObject(Instance instance, ObjectInfo * object)
5325 //*object = _class.instances.Add(sizeof(ObjectInfo));
5326 *object = ObjectInfo { };
5327 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5328 (*object).oClass = oClass;
5329 (*object).instance = instance;
5334 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5336 // if(strcmp(name, this.oClass.instance.name))
5339 for(check = oClass.instances.first; check; check = check.next)
5340 if(!check.deleted && check.name && !strcmp(name, check.name))
5344 (*object).name = CopyString(name);
5349 toolBox.controlClass = null;
5353 //sheet.AddObject(*object, (*object).name, TypeData, true);
5358 void EnsureUpToDate()
5360 if(sheet && codeModified)
5364 void SelectObject(ObjectInfo object)
5367 oClass = object ? object.oClass : null;
5369 designer.SelectObject(object, object ? object.instance : null);
5372 void SelectObjectFromDesigner(ObjectInfo object)
5375 sheet.SelectObject(object);
5378 void EnumerateObjects(Sheet sheet)
5382 for(oClass = classes.first; oClass; oClass = oClass.next)
5388 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5389 for(object = oClass.instances.first; object; object = object.next)
5390 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5393 sheet.SelectObject(selected);
5398 designer.AddObject();
5401 void DeleteObject(ObjectInfo object)
5403 delete object.instance;
5404 object.deleted = true;
5405 object.modified = true;
5406 object.oClass.modified = true;
5408 if(selected == object)
5410 bool looped = false;
5411 ObjectInfo select = object;
5415 select = select.prev;
5419 select = object.oClass.instances.last;
5426 sheet.SelectObject(select ? select : oClass);
5429 if(!object.instCode && object.oClass != object)
5432 oClass.instances.Delete(object);
5435 if(sheet.codeEditor == this)
5436 sheet.DeleteObject(object);
5439 void RenameObject(ObjectInfo object, char * name)
5443 // Validate the name:
5444 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5445 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5448 for(c = 0; name[c]; c++)
5449 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5457 object.name = (name && name[0]) ? CopyString(name) : null;
5459 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5463 void DesignerModifiedObject()
5465 sheet.ListProperties(false);
5469 void ListSubMembers(Type member)
5473 for(subMember = member.members.first; subMember; subMember = subMember.next)
5477 DataRow row = membersList.AddString(subMember.name);
5478 row.icon = icons[typeData];
5482 ListSubMembers(subMember);
5487 void ListSubDataMembers(DataMember member, bool isPrivate)
5489 DataMember subMember;
5490 for(subMember = member.members.first; subMember; subMember = subMember.next)
5492 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5496 DataRow row = membersList.AddString(subMember.name);
5497 BitmapResource bitmap = null;
5498 if(!subMember.dataType)
5499 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5501 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5503 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5506 bitmap = { bitmapName };
5507 membersList.AddResource(bitmap);
5510 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5514 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5520 void ListClassMembers(Class whatClass, bool methodsOnly)
5523 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5524 bool isPrivate = false;
5526 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5528 Method method, methodIt;
5530 DataMember memberIt;
5532 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5534 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5535 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5537 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5539 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5541 DataRow row = membersList.FindString(method.name);
5544 row = membersList.AddString(method.name);
5546 if(!method.dataType)
5547 method.dataType = ProcessTypeString(method.dataTypeString, false);
5549 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5557 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5561 if(memberIt.isProperty)
5563 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5565 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5569 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5571 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5574 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5580 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5582 if(member.isProperty)
5584 Property prop = (Property) member;
5585 if(!membersList.FindString(prop.name))
5587 DataRow row = membersList.AddString(prop.name);
5588 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5591 else if(member.name && !membersList.FindString(member.name))
5593 DataRow row = membersList.AddString(member.name);
5595 BitmapResource bitmap = null;
5596 if(!member.dataType)
5597 member.dataType = ProcessTypeString(member.dataTypeString, false);
5599 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5601 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5604 bitmap = { bitmapName };
5605 membersList.AddResource(bitmap);
5608 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5611 ListSubDataMembers(member, member.memberAccess == privateAccess);
5615 if(_class.inheritanceAccess == privateAccess)
5618 if(_class.module != privateModule) break;
5623 void ListClassMembersMatch(Class whatClass, Type methodType)
5626 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5627 bool isPrivate = false;
5629 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5635 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5637 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5639 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5641 if(!method.dataType)
5642 method.dataType = ProcessTypeString(method.dataTypeString, false);
5644 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5646 DataRow row = membersList.FindString(method.name);
5649 row = membersList.AddString(method.name);
5650 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5656 if(_class.inheritanceAccess == privateAccess)
5659 if(_class.module != privateModule) break;
5664 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5667 bool isPrivate = false;
5668 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5674 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5676 if(method.type == virtualMethod)
5678 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5680 DataRow row = membersList.FindString(method.name);
5683 row = membersList.AddString(method.name);
5685 if(!method.dataType)
5686 method.dataType = ProcessTypeString(method.dataTypeString, false);
5688 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5694 for(member = _class.membersAndProperties.first; member; member = member.next)
5696 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5698 if(member.isProperty)
5700 Property prop = (Property)member;
5702 DataRow row = membersList.AddString(prop.name);
5703 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5706 else if(member.name && (!curString || strcmp(curString, member.name)))
5708 DataRow row = membersList.AddString(member.name);
5710 BitmapResource bitmap = null;
5711 if(!member.dataType)
5712 member.dataType = ProcessTypeString(member.dataTypeString, false);
5714 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5716 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5719 bitmap = { bitmapName };
5720 membersList.AddResource(bitmap);
5723 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5726 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5729 if(_class.inheritanceAccess == privateAccess)
5732 if(_class.module != privateModule) break;
5737 void ListMembers(Type type)
5739 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5743 if(type.kind == classType)
5746 ListClassMembers(type._class.registered, false);
5751 for(member = type.members.first; member; member = member.next)
5755 DataRow row = membersList.AddString(member.name);
5756 row.icon = icons[typeData];
5758 else if(member.kind == structType || member.kind == unionType)
5759 ListSubMembers(member);
5765 void ListModule(Module mainModule, int recurse, bool listClasses)
5768 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5769 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5770 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5771 for(module = mainModule.application.allModules.first; module; module = module.next)
5773 if(ModuleVisibility(mainModule, module))
5774 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5778 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5785 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5787 Class _class = link.data;
5788 if(_class.type != systemClass)
5790 DataRow row = membersList.AddString(_class.name);
5791 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5796 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5798 DefinedExpression definedExp = link.data;
5799 DataRow row = membersList.AddString(link /*definedExp*/.name);
5800 row.icon = icons[typeData];
5803 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5805 GlobalFunction function = link.data;
5806 DataRow row = membersList.AddString(link /*function*/.name);
5807 row.icon = icons[typeMethod];
5811 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5813 if(recurse != 2 && listClasses)
5815 if(!membersList.FindString(ns->name))
5817 DataRow row = membersList.AddString(ns->name);
5818 row.icon = icons[typeNameSpace];
5823 ListNameSpace(ns, 2, listClasses);
5827 void ListEnumValues(Class _class)
5829 List<Class> classes { };
5830 for(; _class && _class.type == enumClass; _class = _class.base)
5831 classes.Insert(null, _class);
5832 for(_class : classes)
5834 EnumClassData enumeration = (EnumClassData)_class.data;
5836 for(item = enumeration.values.first; item; item = item.next)
5838 DataRow row = membersList.AddString(item.name);
5839 row.icon = icons[typeEnumValue];
5845 bool ListEnumsModule(Module mainModule, Type dest)
5847 bool result = false;
5849 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5850 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5851 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5852 for(module = mainModule.application.allModules.first; module; module = module.next)
5854 if(ModuleVisibility(mainModule, module))
5855 result |= ListEnums(module.publicNameSpace, dest);
5860 void ListNameSpaceByString(Module mainModule, char * string)
5862 NameSpace * nameSpace;
5864 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5865 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5866 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5867 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5868 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5869 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5870 for(module = mainModule.application.allModules.first; module; module = module.next)
5872 if(ModuleVisibility(mainModule, module))
5874 nameSpace = FindNameSpace(module.publicNameSpace, string);
5875 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5880 bool ListEnums(NameSpace nameSpace, Type dest)
5883 bool result = false;
5885 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5887 Class _class = link.data;
5888 if(_class.type == enumClass && (dest.kind != classType || !dest._class || dest._class.registered != _class))
5890 OldList conversions { };
5892 type.kind = classType;
5893 type._class = FindClass(_class.name);
5894 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5896 ListEnumValues(_class);
5899 conversions.Free(null);
5903 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5905 result |= ListEnums(nameSpace, dest);
5910 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5914 for(c = 0; (ch = name[c]); c++)
5916 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5918 NameSpace * newSpace;
5919 char * spaceName = new char[c - start + 1];
5920 memcpy(spaceName, name + start, c - start);
5921 spaceName[c-start] = '\0';
5922 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5926 nameSpace = newSpace;
5935 return (NameSpace *)nameSpace;
5938 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5940 bool listedEnums = false;
5941 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5942 bool listClasses = true;
5944 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5946 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5947 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5948 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5950 if(exp.type == identifierExp)
5951 id = realIdentifier;
5953 if(id && id._class && !id._class.name)
5955 listClasses = false;
5958 else if(id && id._class && id._class.name)
5962 Class _class = id.classSym.registered;
5963 if(_class && _class.type == enumClass)
5965 ListEnumValues(_class);
5968 ListClassMembers(id.classSym.registered, true);
5973 else if(id && colons)
5975 ListNameSpaceByString(this.privateModule, id.string);
5980 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
5982 listedEnums = ListEnumsModule(this.privateModule, destType);
5985 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
5987 ListEnumValues(destType._class.registered);
5990 ListClassPropertiesAndVirtual(insideClass, null);
5994 else if(destType && destType.kind == enumType)
5998 for(value = destType.members.first; value; value = value.next)
6000 DataRow row = membersList.AddString(value.name);
6001 row.icon = icons[typeEnumValue];
6005 ListClassPropertiesAndVirtual(insideClass, null);
6009 else if(insideClass && !enumOnly)
6011 ListClassPropertiesAndVirtual(insideClass, string);
6014 if(listedEnums && string && string[0])
6016 DataRow row = membersList.FindSubString(string);
6018 listedEnums = false;
6021 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6023 ListClassMembersMatch(GetThisClass(), exp.destType);
6025 else if(!insideClass && !enumOnly && !listedEnums)
6028 Symbol symbol = null;
6032 ListClassMembers(GetThisClass(), false);
6035 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6037 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6039 // Don't list enum values?
6040 //if(symbol.type.kind != TypeEnum)
6041 DataRow row = membersList.FindString(symbol.string);
6044 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6046 row = membersList.AddString(symbol.string);
6047 if(symbol.type && symbol.type.kind == functionType)
6048 row.icon = icons[typeMethod];
6049 else if(symbol.type && symbol.type.kind == enumType)
6051 row.icon = icons[typeEnumValue];
6055 BitmapResource bitmap = null;
6056 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6058 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6061 bitmap = { bitmapName };
6062 membersList.AddResource(bitmap);
6065 row.icon = bitmap ? bitmap : icons[typeData];
6072 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6074 DataRow row = membersList.FindString(symbol.string);
6077 row = membersList.AddString(symbol.string);
6078 if(symbol.type.kind == functionType)
6079 row.icon = icons[typeMethod];
6080 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6082 row.icon = icons[typeClass];
6086 row.icon = icons[typeDataType];
6093 ListModule(this.privateModule, 1, listClasses);
6094 // TODO: Implement this with name space
6098 for(data = globalData.first; data; data = data.next)
6100 DataRow row = membersList.FindString(data.name);
6102 data.dataType = ProcessTypeString(data.dataTypeString, false);
6105 row = membersList.AddString(data.name);
6107 if(data.dataType && data.dataType.kind == TypeEnum)
6109 row.icon = icons[typeEnumValue];
6113 BitmapResource bitmap = null;
6114 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6116 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6119 bitmap = { bitmapName };
6120 membersList.AddResource(bitmap);
6123 row.icon = bitmap ? bitmap : icons[typeData];
6131 DataRow row = membersList.AddString("Min");
6132 row.icon = icons[typeMethod];
6134 row = membersList.AddString("Max");
6135 row.icon = icons[typeMethod];
6137 row = membersList.AddString("Abs");
6138 row.icon = icons[typeMethod];
6140 row = membersList.AddString("Sgn");
6141 row.icon = icons[typeMethod];
6147 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6149 EditBoxStream f { editBox = editBox };
6154 updatingCode = true;
6156 if(!method.dataType)
6157 method.dataType = ProcessTypeString(method.dataTypeString, false);
6159 DeleteJunkBefore(f, function.loc.start.pos, &position);
6160 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6162 // ADDING METHOD HERE
6164 Type dataType = method.dataType;
6165 Type returnType = dataType.returnType;
6167 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6173 if(extraIndent) f.Printf(" ");
6175 OutputType(f, returnType, false);
6179 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6181 if(dataType.thisClass.shortName)
6182 f.Printf(dataType.thisClass.shortName);
6184 f.Printf(dataType.thisClass.string);
6187 f.Printf(method.name);
6189 for(param = dataType.params.first; param; param = param.next)
6191 // Decided not to write void...
6192 if(param.kind != voidType)
6194 OutputType(f, param, true);
6200 if(extraIndent) f.Printf(" ");
6201 f.Printf(" %c\n", OpenBracket);
6203 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6209 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6210 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6212 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6214 if(extraIndent) f.Printf(" ");
6215 f.Printf(" return true;\n");
6217 else if(returnType && returnType.kind != voidType)
6219 if(extraIndent) f.Printf(" ");
6220 f.Printf(" return 0;\n");
6225 if(extraIndent) f.Printf(" ");
6227 if(returnType.kind != voidType)
6228 f.Printf("return ");
6229 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6230 for(param = dataType.params.first; param; param = param.next)
6232 if(param.prev) f.Printf(", ");
6233 if(param.kind != voidType)
6234 f.Printf(param.name);
6240 if(extraIndent) f.Printf(" ");
6241 f.Printf(" %c", CloseBracket);
6246 if(extraIndent) { x1 += 3; x2 += 3; }
6247 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6249 this.updatingCode = false;
6253 // Return false if we overrided a function and don't want to run params listing
6254 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6256 bool didOverride = false;
6257 EditLine line = editBox.line;
6258 char * text = line.text;
6259 int lineNum, charPos;
6260 Expression exp = null;
6263 //Identifier id = null;
6264 Expression memberExp = null;
6265 Identifier realIdentifier = null;
6267 if(!privateModule) return !didOverride;
6269 insideFunction = null;
6271 charPos = editBox.charPos + 1;
6272 if(!membersListShown)
6277 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6279 EditBoxStream f { editBox = editBox };
6281 updatingCode = true;
6282 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6286 if(!f.Seek(-1, current))
6289 if(!isspace(ch)) break;
6290 f.Seek(-1, current);
6292 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6294 lineNum = editBox.lineNumber + 1;
6295 charPos = editBox.charPos + 1;
6297 updatingCode = false;
6300 if(!membersListShown)
6302 memberExp = FindExpTree(ast, lineNum, charPos);
6303 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6308 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6310 EditBoxStream f { editBox = editBox };
6313 updatingCode = true;
6315 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6318 if(ch == '}' || ch == ',' || ch == ')')
6320 f.Seek(-1, current);
6328 if(!f.Seek(-1, current))
6331 if(!isspace(ch)) break;
6332 f.Seek(-1, current);
6336 f.Seek(-1, current);
6338 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6340 lineNum = editBox.lineNumber + 1;
6341 charPos = editBox.charPos + 1;
6343 updatingCode = false;
6346 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6351 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6352 lineNum = editBox.lineNumber + 1;
6353 charPos = editBox.charPos/* + 1*/;
6357 char tempString[1024];
6358 char * string = null;
6359 CodePosition idStart, idEnd;
6361 if(membersListShown)
6363 char * buffer = membersLine.text;
6365 bool firstChar = true;
6367 string = tempString;
6369 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6371 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6372 if(!isSpace) firstChar = false;
6374 string[len++] = buffer[c];
6378 else //if(realIdentifier)//if(id)
6381 char * buffer = id.string;
6383 bool firstChar = true;
6385 string = tempString;
6386 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6388 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6389 if(!isSpace) firstChar = false;
6391 string[len++] = buffer[c];
6397 EditLine editLine = editBox.line;
6398 bool firstChar = true;
6401 string = tempString;
6402 for(y = lineNum-1; y >= 0; y--)
6404 char * buffer = editLine.text;
6405 int lineCount = editLine.count;
6406 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6408 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6413 idEnd.charPos = x + 2;
6418 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6421 idEnd.charPos = x + 2;
6428 if(!isalnum(buffer[x]) && buffer[x] != '_')
6434 memmove(string+1, string, len++);
6435 string[0] = buffer[x];
6439 //if(done || firstChar)
6440 if(done || !firstChar)
6442 editLine = editLine.prev;
6445 if(!strcmp(string, "case"))
6451 else if(!strcmp(string, "return"))
6457 else if(!strcmp(string, "delete"))
6463 else if(!strcmp(string, "new"))
6469 else if(!strcmp(string, "renew"))
6477 idStart.charPos = x + 1;
6478 idStart.line = y + 1;
6481 if(!membersListShown)
6483 membersList.Clear();
6484 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6486 Type type = memberExp.member.exp.expType;
6487 if(pointer == 2 && type)
6489 if(type.kind == pointerType || type.kind == arrayType)
6498 ListSymbols(exp, enumOnly, string, realIdentifier);
6500 membersList.Sort(null, 1);
6505 // Virtual function override
6506 Identifier id = GetDeclId(insideFunction.declarator);
6507 char * string = id ? id.string : null;
6509 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6512 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6513 insideFunction = null;
6516 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6521 if(!didOverride) //insideFunction)
6523 rowCount = membersList.rowCount;
6526 DataRow row = string ? membersList.FindSubString(string) : null;
6527 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6529 char * newString = row.string;
6530 if(!membersListShown)
6532 membersLoc.start.line = idStart.line-1;
6533 membersLoc.start.charPos = idStart.charPos-1;
6534 //membersLoc.end = membersLoc.start;
6535 membersLoc.end.charPos = idEnd.charPos-1;
6536 membersLoc.end.line = idEnd.line-1;
6537 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6538 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6543 membersList.Destroy(0);
6544 membersListShown = false;
6547 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6549 line, membersLoc.start.line, membersLoc.start.charPos,
6550 line, membersLoc.end.line, membersLoc.end.charPos);
6551 editBox.PutS(newString);
6557 row = membersList.FindSubStringi(string);
6559 membersList.currentRow = row;
6560 membersList.currentRow.selected = false;
6563 membersList.currentRow = row;
6565 if(!membersListShown)
6569 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6570 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6571 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6572 editBox.GetCaretPosition(caret);
6573 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6575 membersList.master = this;
6577 caret.y += editBox.GetCaretSize();
6579 membersList.Create();
6582 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6583 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6584 Window parent = membersList.parent;
6586 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6588 y -= editBox.GetCaretSize() + membersList.size.h;
6589 membersAbove = true;
6592 membersAbove = false;
6594 membersList.position = { x, y };
6598 membersLoc.start.line = lineNum - 1;
6600 if(string && string[0])
6602 membersLoc.start.charPos = idStart.charPos-1;
6603 membersLoc.end = membersLoc.start;
6604 //membersLoc.end.charPos = id.loc.end.charPos-1;
6605 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6609 membersLoc.start.charPos = charPos;
6610 membersLoc.end = membersLoc.start;
6611 membersLoc.end.charPos = charPos;
6613 membersListShown = true;
6615 // Hack to keep caret shown
6616 editBox.GetCaretPosition(caret);
6617 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6620 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6626 SetCurrentContext(globalContext);
6629 return !didOverride;
6632 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6634 EditLine line = editBox.line;
6635 char * text = line.text;
6636 int lineNum, charPos;
6637 Expression exp = null;
6641 charPos = editBox.charPos + 1;
6644 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6646 EditBoxStream f { editBox = editBox };
6649 updatingCode = true;
6650 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6653 if(ch == '}' || ch == ',' || ch == ')')
6655 f.Seek(-1, current);
6663 if(!f.Seek(-1, current))
6666 if(!isspace(ch)) break;
6667 f.Seek(-1, current);
6671 f.Seek(-1, current);
6673 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6675 lineNum = editBox.lineNumber + 1;
6676 charPos = editBox.charPos + 1;
6678 updatingCode = false;
6681 charPos = Min(charPos, l1.count + 1);
6683 FindParamsTree(ast, lineNum, charPos);
6685 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6686 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6688 ::functionType = null;
6689 ::instanceType = null;
6692 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6693 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6697 Window parent = paramsList.parent;
6699 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6702 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6703 // ( Dummy exp: always ends up with same memory)
6705 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6706 editBox.GetCaretPosition(paramsPosition);
6707 this.paramsPosition.y += editBox.GetCaretSize();
6710 FreeType(this.functionType);
6711 FreeType(this.instanceType);
6713 this.functionType = ::functionType;
6714 this.instanceType = ::instanceType;
6716 if(this.functionType) this.functionType.refCount++;
6717 if(this.instanceType) this.instanceType.refCount++;
6719 this.paramsID = ::paramsID;
6720 functionExp = paramsInsideExp;
6722 paramsList.master = this;
6724 paramsList.Create();
6726 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6727 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6729 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6731 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6735 paramsAbove = false;
6736 if(x + paramsList.size.w > parent.clientSize.w)
6738 x = parent.clientSize.w - paramsList.size.w;
6742 paramsList.position = { x, y };
6744 // Hack to keep caret shown
6747 editBox.GetCaretPosition(caret);
6748 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6751 this.paramsShown = true;
6753 else if((!::functionType && !::instanceType) || reposition)
6755 paramsList.Destroy(0);
6756 paramsShown = false;
6758 FreeType(this.functionType);
6759 FreeType(this.instanceType);
6760 this.functionType = null;
6761 this.instanceType = null;
6765 SetCurrentContext(globalContext);
6773 designer.visible = true;
6774 designer.Activate();
6780 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6782 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };