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)
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 || !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 ****************************************************************************/
2472 this.defines.Free(FreeModuleDefine);
2473 this.imports.Free(FreeModuleImport);
2480 FreeExcludedSymbols(this.excludedSymbols);
2481 FreeContext(this.globalContext);
2483 FreeGlobalData(&this.globalData);
2485 if(GetGlobalContext() == globalContext)
2487 SetGlobalData(null);
2488 SetGlobalContext(null);
2489 SetExcludedSymbols(null);
2490 SetTopContext(null);
2491 SetCurrentContext(null);
2494 SetPrivateModule(null);
2497 if(this.privateModule)
2499 FreeTypeData(this.privateModule);
2500 delete this.privateModule;
2501 this.privateModule = null;
2507 static bool reentrant = false;
2512 char * selectedClassName = null, * selectedName = null;
2513 int selectedPos = 0;
2514 Designer backDesigner;
2515 char oldWorkDir[MAX_LOCATION];
2516 char mainModuleName[MAX_FILENAME] = "";
2518 ImportedModule module;
2519 char extension[MAX_EXTENSION];
2521 Time parseCodeStart = GetTime();
2522 Time startTime, startFindClass;
2524 findClassTotalTime = 0;
2525 checkTypeTotalTime = 0;
2526 externalImportTotalTime = 0;
2527 findClassIgnoreNSTotalTime = 0;
2528 findSymbolTotalTime = 0;
2529 //ResetClassFindTime();
2533 // 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)
2534 if(reentrant) return;
2541 selectedClassName = CopyString(oClass.name);
2542 if(selected != oClass)
2544 ObjectInfo object = this.selected;
2545 selectedName = CopyString(object.name);
2549 for(check = this.oClass.instances.first; check; check = check.next)
2561 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2563 defines.Free(FreeModuleDefine);
2564 imports.Free(FreeModuleImport);
2566 SetGlobalData(&globalData);
2567 SetGlobalContext(globalContext);
2568 SetExcludedSymbols(&excludedSymbols);
2569 SetTopContext(globalContext);
2570 SetCurrentContext(globalContext);
2571 SetDefines(&defines);
2572 SetImports(&imports);
2573 SetCurrentNameSpace(null);
2576 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2577 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2578 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2579 "/I T:\\ecere\\include /E %s", argv[1]);
2583 ChangeWorkingDir("e:\\ec");
2584 sprintf(command, "gcc -x c -E -");
2585 fileInput = DualPipeOpen({ output = true, input = true }, command);
2586 SetFileInput(fileInput);
2591 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2593 fileInput.Write(buffer, 1, count);
2598 fileInput.CloseOutput();
2602 // TOCHECK: COULDN'T WE CALL FreeParser here?
2604 this.functionType = null;
2605 this.instanceType = null;
2608 sheet.SelectObject(null);
2614 // We don't want the designer to be notified of selection when deleting rows...
2615 backDesigner = designer;
2620 ObjectInfo _class, next;
2622 for(_class = classes.first; _class; _class = next)
2628 for(;object = _class.instances.first;)
2632 Designer::DestroyObject(object.instance);
2633 delete object.instance;
2635 sheet.DeleteObject(object);
2637 _class.instances.Delete(object);
2641 Designer::DestroyObject(_class.instance);
2642 delete _class.instance;
2644 sheet.DeleteObject(_class);
2646 classes.Delete(_class);
2652 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2653 if(windowClass && windowClass.data)
2654 UnapplySkin(windowClass);
2657 designer = backDesigner;
2660 fileInput = editFile = EditBoxStream { editBox = editBox };
2661 SetFileInput(fileInput);
2670 FreeContext(this.globalContext);
2671 FreeExcludedSymbols(this.excludedSymbols);
2674 FreeGlobalData(&this.globalData);
2676 if(this.privateModule)
2678 FreeTypeData(this.privateModule);
2679 delete this.privateModule;
2683 startTime = GetTime();
2684 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2686 printf("classes.count: %d\n", globalContext.classes.count);
2691 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2692 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2695 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2697 SetPrivateModule(privateModule);
2700 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2701 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2702 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2703 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2704 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2707 fileName = this.fileName;
2709 if(ide.workspace && ide.workspace.projects && fileName)
2711 for(p : ide.workspace.projects)
2713 char path[MAX_LOCATION];
2715 MakePathRelative(fileName, p.topNode.path, path);
2716 MakeSlashPath(path);
2718 pn = p.topNode.FindWithPath(path, false);
2727 project = ide.project;
2729 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2731 ChangeWorkingDir(project.topNode.path);
2733 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2735 GetLastDirectory(fileName, mainModuleName);
2736 GetExtension(mainModuleName, extension);
2738 SetBuildingEcereCom(false);
2739 SetBuildingEcereComModule(false);
2741 // TODO: Get symbolsDir from project settings instead...
2744 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2745 ProjectConfig config = project.config;
2746 int bitDepth = ide.workspace.bitDepth;
2747 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2748 SetSymbolsDir(objDir.dir);
2751 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2752 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2756 switch(GetRuntimePlatform())
2758 case win32: SetSymbolsDir("obj/debug.win32"); break;
2759 case tux: SetSymbolsDir("obj/debug.linux"); break;
2760 case apple: SetSymbolsDir("obj/debug.apple"); break;
2762 SetIncludeDirs(null);
2763 SetSysIncludeDirs(null);
2767 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2769 // TODO FIX for configless project
2770 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2772 for(item : ide.project.config.options.preprocessorDefinitions)
2774 if(!strcmp(item, "BUILDING_ECERE_COM"))
2776 SetBuildingEcereCom(true);
2783 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2784 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2785 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2786 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2787 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2788 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2789 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2790 strcmpi(mainModuleName, "Mutex.ec")))
2792 SetBuildingEcereComModule(true);
2795 // Predeclare all classes
2797 char symFile[MAX_FILENAME];
2798 char symLocation[MAX_LOCATION];
2799 ImportedModule module, next;
2801 GetLastDirectory(fileName, symFile);
2802 ChangeExtension(symFile, "sym", symFile);
2804 strcpy(symLocation, GetSymbolsDir());
2805 PathCat(symLocation, symFile);
2807 // if(!GetEcereImported() && !GetBuildingEcereCom())
2808 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2811 startTime = GetTime();
2813 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2815 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2820 startTime = GetTime();
2822 // LoadSymbols(symLocation, normalImport, true);
2823 LoadSymbols(symLocation, preDeclImport, false);
2825 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2828 for(module = defines.first; module; module = next)
2831 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2834 defines.Delete(module);
2839 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2841 SetDefaultDeclMode(privateAccess);
2842 SetDeclMode(privateAccess);
2846 SetDefaultDeclMode(defaultAccess);
2847 SetDeclMode(defaultAccess);
2850 StripExtension(mainModuleName);
2851 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2852 defines.AddName(module);
2855 // SetYydebug(true);
2860 startTime = GetTime();
2861 startFindClass = checkTypeTotalTime;
2865 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2867 CheckDataRedefinitions();
2870 SetIncludeDirs(null);
2871 SetSysIncludeDirs(null);
2882 startTime = GetTime();
2884 PrePreProcessClassDefinitions();
2885 ComputeModuleClasses(privateModule);
2886 PreProcessClassDefinitions();
2887 ProcessClassDefinitions();
2889 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2890 startTime = GetTime();
2895 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2896 startTime = GetTime();
2898 ProcessInstantiations();
2900 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2903 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2905 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2906 if(!windowClass || windowClass.internalDecl)
2909 startTime = GetTime();
2911 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2912 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2913 eModule_Load(this.privateModule, "ecere", privateAccess);
2915 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2918 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2920 if(windowClass && windowClass.data)
2921 ApplySkin(windowClass, app.currentSkin.name, null);
2925 startTime = GetTime();
2927 for(external = ast->first; external; external = external.next)
2929 if(external.type == classExternal)
2931 ClassDefinition _class = external._class;
2932 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2934 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2937 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2939 Instance instance = eInstance_New(regClass);
2940 ObjectInfo classObject
2942 name = CopyString(_class._class.name);
2943 instance = instance;
2944 classDefinition = _class;
2945 oClass = classObject;
2948 classes.Add(classObject);
2952 // Moved this at bottom so that the file dialog doesn't show up in eCom
2953 designer.CreateObject(instance, classObject, true, null);
2954 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
2956 if(_class.definitions)
2960 for(def = _class.definitions->first; def; def = def.next)
2964 case defaultPropertiesClassDef:
2967 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
2969 Identifier id = propDef.identifiers->first;
2972 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
2975 Class propertyClass = prop.dataTypeClass;
2977 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
2978 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
2980 FreeType(propDef.initializer.exp.destType);
2981 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
2982 ProcessExpressionType(propDef.initializer.exp);
2984 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
2986 Expression computed = CopyExpression(propDef.initializer.exp);
2987 ComputeExpression(computed);
2989 if(computed.isConstant && computed.type == instanceExp && !id.next)
2993 if(computed.instance._class && computed.instance._class.symbol &&
2994 computed.instance._class.symbol.registered &&
2995 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
2997 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
2999 // This was saved in the control and shouldn't be freed by FreeExpression...
3000 if(propertyClass.type == normalClass)
3001 computed.instance.data = null;
3005 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3006 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3008 String temp = new char[strlen(computed.string)+1];
3009 ReadString(temp, computed.string);
3010 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3014 propDef.variable = true;
3016 FreeExpression(computed);
3020 Expression computed = CopyExpression(propDef.initializer.exp);
3021 ComputeExpression(computed);
3022 if(computed.isConstant)
3024 //if(computed.type == memberExp) computed = computed.member.exp;
3026 if(computed.type == constantExp)
3028 Operand value = GetOperand(computed);
3029 DataValue valueData;
3030 valueData.i64 = value.i64;
3031 SetProperty(prop, instance, valueData);
3033 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3035 String temp = new char[strlen(computed.string)+1];
3036 ReadString(temp, computed.string);
3037 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3042 propDef.variable = true;
3044 FreeExpression(computed);
3048 propDef.variable = true;
3052 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3053 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3054 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3057 // Maintain a list in FunctionDefinition of who is attached to it
3058 for(def = _class.definitions->first; def; def = def.next)
3060 if(def.type == functionClassDef)
3062 ClassFunction function = def.function;
3063 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3065 function.attached.Add(OldLink { data = method });
3075 case declarationClassDef:
3077 Declaration decl = def.decl;
3080 case instDeclaration:
3082 Instantiation inst = decl.inst;
3083 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3084 if(instClass && eClass_GetDesigner(instClass))
3086 Instance control = eInstance_New(instClass);
3091 oClass = classObject;
3095 classObject.instances.Add(object);
3097 // TOCHECK: Why is this needed now?
3098 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3099 def.object = object;
3101 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3103 designer.CreateObject(control, object, false, classObject.instance);
3104 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3114 // Second pass, process instantiation members
3116 for(def = _class.definitions->first; def; def = def.next)
3120 case declarationClassDef:
3122 Declaration decl = def.decl;
3125 case instDeclaration:
3127 Instantiation inst = decl.inst;
3128 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3129 if(instClass && eClass_GetDesigner(instClass))
3132 object = object ? object.next : classObject.instances.first;
3133 control = object.instance;
3137 MembersInit members;
3138 for(members = inst.members->first; members; members = members.next)
3140 switch(members.type)
3142 case dataMembersInit:
3144 if(members.dataMembers)
3147 DataMember curMember = null;
3148 Class curClass = null;
3149 DataMember subMemberStack[256];
3150 int subMemberStackPos = 0;
3152 for(member = members.dataMembers->first; member; member = member.next)
3155 Identifier ident = member.identifiers ? member.identifiers->first : null;
3158 DataMember _subMemberStack[256];
3159 int _subMemberStackPos = 0;
3160 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3164 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3166 if(thisMember && thisMember.memberAccess == publicAccess)
3168 curMember = thisMember;
3169 curClass = curMember._class;
3170 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3171 subMemberStackPos = _subMemberStackPos;
3177 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3178 if(curMember) found = true;
3180 if(found && curMember.isProperty)
3182 Property prop = (Property) curMember;
3183 Class propertyClass = prop.dataTypeClass;
3185 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3187 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3189 FreeType(member.initializer.exp.destType);
3190 member.initializer.exp.destType = MkClassType(propertyClass.name);
3193 ProcessExpressionType(member.initializer.exp);
3195 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3197 Expression computed;
3199 /*char debugExpString[4096];
3200 debugExpString[0] = '\0';
3201 PrintExpression(member.initializer.exp, debugExpString);*/
3203 computed = CopyExpression(member.initializer.exp);
3206 ComputeExpression(computed);
3208 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3210 if(computed.instance.data)
3212 if(computed.instance._class && computed.instance._class.symbol &&
3213 computed.instance._class.symbol.registered &&
3214 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3216 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3218 // This was saved in the control and shouldn't be freed by FreeExpression...
3219 if(propertyClass.type == normalClass)
3220 computed.instance.data = null;
3224 else if(computed.type == identifierExp)
3226 member.variable = true;
3228 if(eClass_GetDesigner(propertyClass))
3231 char * name = computed.identifier.string;
3232 if(!strcmp(name, "this"))
3235 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3236 member.variable = false;
3241 for(check = classObject.instances.first; check; check = check.next)
3242 if(check.name && !strcmp(name, check.name))
3245 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3246 member.variable = false;
3252 else if(computed.type == memberExp)
3254 member.variable = true;
3255 if(computed.member.exp.type == identifierExp)
3257 char * name = computed.member.exp.identifier.string;
3258 if(!strcmp(name, "this"))
3260 char * name = computed.member.member.string;
3263 for(check = classObject.instances.first; check; check = check.next)
3264 if(check.name && !strcmp(name, check.name))
3267 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3268 member.variable = false;
3276 for(check = classObject.instances.first; check; check = check.next)
3278 if(check.name && !strcmp(name, check.name))
3280 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3283 DataValue value { };
3284 GetProperty(getProperty, check.instance, &value);
3285 SetProperty(prop, control, value);
3286 member.variable = false;
3294 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3295 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3297 String temp = new char[strlen(computed.string)+1];
3298 ReadString(temp, computed.string);
3299 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3303 member.variable = true;
3305 FreeExpression(computed);
3310 Expression computed = CopyExpression(member.initializer.exp);
3313 ComputeExpression(computed);
3314 if(computed.isConstant)
3316 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3318 if(!strcmp(propertyClass.dataTypeString, "float"))
3319 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3320 else if(!strcmp(propertyClass.dataTypeString, "double"))
3321 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3323 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3325 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3327 String temp = new char[strlen(computed.string)+1];
3328 ReadString(temp, computed.string);
3329 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3334 member.variable = true;
3336 FreeExpression(computed);
3342 member.variable = true;
3344 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3345 member.initializer.exp.type == memberExp) // identifierExp
3347 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3348 if(method && method.type == virtualMethod)
3351 // Maintain a list in FunctionDefinition of who is attached to it
3352 for(def = _class.definitions->first; def; def = def.next)
3354 if(def.type == functionClassDef)
3356 ClassFunction function = def.function;
3357 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3358 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3360 function.attached.Add(OldLink { data = method });
3361 // Reference this particular instance?
3376 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3387 //designer.CreateObject(instance, classObject, true, null);
3388 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3390 designer.PostCreateObject(instance, classObject, true, null);
3392 //instance.state = Hidden;
3393 //instance.Create();
3394 //instance.SetState(Normal, true, 0);
3403 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3407 // Restore Selection
3408 if(selectedClassName)
3411 for(oClass = classes.first; oClass; oClass = oClass.next)
3413 if(!strcmp(oClass.name, selectedClassName))
3415 this.oClass = oClass;
3419 delete selectedClassName;
3428 for(check = this.oClass.instances.first; check; check = check.next)
3430 if(check.name && !strcmp(check.name, selectedName))
3432 this.selected = check;
3438 if(this.oClass.instances.first)
3439 this.selected = this.oClass.instances.first;
3441 this.selected = this.oClass;
3444 else if(selectedPos == -1 || !this.oClass.instances.count)
3445 this.selected = this.oClass;
3451 if(selectedPos > this.oClass.instances.count)
3453 for(check = this.oClass.instances.first; check; check = check.next)
3455 if(selectedPos == pos++)
3457 this.selected = check;
3465 this.oClass = classes.first;
3466 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3468 delete selectedName;
3469 SetSymbolsDir(null);
3471 if(sheet.codeEditor == this)
3472 sheet.SelectObject(selected);
3475 codeModified = false;
3477 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3480 InvokeParameters(false, false, false);
3483 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3489 ChangeWorkingDir(oldWorkDir);
3491 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3492 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3493 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3494 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3495 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3497 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3499 if(inUseDebug && ide.projectView)
3500 ide.debugger.EvaluateWatches();
3503 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3506 Window control = (Window)object.instance;
3507 ObjectInfo classObject = object.oClass;
3509 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3511 if(!strcmp(_class.name, "DesignerBase")) return;
3513 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3515 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3516 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3518 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3519 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3521 Class dataType = prop.dataTypeClass;
3523 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3527 if(dataType.type == structClass)
3529 void * dataForm = new0 byte[dataType.structSize];
3530 void * dataTest = new0 byte[dataType.structSize];
3532 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3533 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3535 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3537 char tempString[1024] = "";
3539 bool needClass = true;
3543 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3545 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3547 eClass_FindNextMember(_class, curClass, curMember, null, null);
3548 if(*curMember != (DataMember)prop)
3549 f.Printf("%s = ", prop.name);
3551 *curMember = (DataMember)prop;
3552 *curClass = curMember->_class;
3555 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3557 f.Printf("%s", string);
3564 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3566 void * dataForm, * dataTest;
3568 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3569 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3571 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3573 char tempString[1024] = "";
3578 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3580 eClass_FindNextMember(_class, curClass, curMember, null, null);
3581 if(*curMember != (DataMember)prop)
3582 f.Printf("%s = ", prop.name);
3583 *curMember = (DataMember)prop;
3584 *curClass = curMember->_class;
3586 if(eClass_GetDesigner(dataType))
3588 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3589 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3590 f.Printf("this", prop.name);
3593 //ObjectInfo classObject;
3594 //for(classObject = classes.first; classObject; classObject = classObject.next)
3598 for(object = classObject.instances.first; object; object = object.next)
3600 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3602 f.Printf("%s", object.name);
3609 bool needClass = true;
3610 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3611 f.Printf("%s", string);
3618 bool needClass = true;
3619 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3621 if(!strcmp(dataType.dataTypeString, "char *"))
3624 OutputString(f, string);
3628 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3630 f.Printf("%s", string);
3633 *lastIsMethod = false;
3638 DataValue dataForm, dataTest;
3640 GetProperty(prop, control, &dataForm);
3641 GetProperty(prop, test, &dataTest);
3643 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3646 char tempString[1024] = "";
3647 SetProperty(prop, test, dataForm);
3649 if(dataType.type != bitClass)
3651 bool needClass = true;
3653 if(dataType.type == enumClass)
3656 Class enumClass = eSystem_FindClass(privateModule, "enum");
3657 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3659 for(value = e.values.first; value; value = value.next)
3661 if((int)value.data == dataForm.i)
3663 string = value.name;
3669 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3671 if(string && string[0])
3676 eClass_FindNextMember(_class, curClass, curMember, null, null);
3677 if(*curMember != (DataMember)prop)
3678 f.Printf("%s = ", prop.name);
3679 *curMember = (DataMember)prop;
3680 *curClass = curMember->_class;
3682 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3683 f.Printf("%sf", string);
3685 f.Printf("%s", string);
3689 else if(dataType.type == bitClass)
3691 bool needClass = true;
3693 if(*prev) f.Printf(", ");
3695 eClass_FindNextMember(_class, curClass, curMember, null, null);
3696 if(*curMember != (DataMember)prop)
3697 f.Printf("%s = ", prop.name);
3698 *curMember = (DataMember)prop;
3699 *curClass = curMember->_class;
3701 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3703 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3705 f.Printf("%s", string);
3707 *lastIsMethod = false;
3717 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3719 Instantiation inst = object.instCode;
3720 Window control = (Window)object.instance;
3722 bool methodPresent = false;
3724 bool lastIsMethod = true;
3725 ObjectInfo classObject = object.oClass;
3731 // Instance removed, delete it
3732 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3734 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3735 position = inst.loc.end.pos + 1;
3739 bool multiLine = false;
3742 // Check if it's an unnamed instance
3745 f.Seek(inst.nameLoc.start.pos - position, current);
3746 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3747 position = inst.nameLoc.end.pos;
3749 f.Printf(object.name);
3754 if(isspace(ch) && ch != '\n')
3756 f.Seek(-1, current);
3764 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3766 f.Seek(pos - position, current);
3771 f.Seek(-1, current);
3780 f.Puts(object.name);
3785 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3786 methodPresent = true;
3794 if(ch == OpenBracket)
3800 // TODO: Simplify this?
3809 f.Seek(-1, current);
3821 if(ch == '\n') { toDelete = count; count = 0; }
3822 else if(isspace(ch)) count++;
3825 f.Seek(-1, current);
3829 toDelete += count - 6;
3839 f.Seek(-toDelete-count, current);
3840 f.DeleteBytes(toDelete);
3841 f.Seek(count, current);
3846 for(c = 0; c<toAdd; c++)
3852 methodPresent = multiLine;
3855 f.Printf(methodPresent ? "\n " : " ");
3861 // Instance not there, create a brand new one
3862 DeleteJunkBefore(f, position, &position);
3863 f.Printf(*firstObject ? "\n\n" : "\n");
3864 *firstObject = false;
3866 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3867 methodPresent = true;
3872 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3874 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3879 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3881 f.Printf(" %s %c ", control._class.name, OpenBracket);
3887 Instance test = eInstance_New(control._class);
3888 DataMember curMember = null;
3889 Class curClass = null;
3892 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3896 // Attach Method here
3897 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3899 if(prev) f.Printf(", ");
3900 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3905 if(inst && !object.deleted)
3907 MembersInit members;
3908 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3910 DeleteJunkBefore(f, position, &position);
3912 // Instance already there, clear out the properties
3913 for(members = inst.members->first; members; members = members.next)
3915 if(members.type == dataMembersInit)
3919 if(members.dataMembers)
3921 bool keptMember = false;
3922 MemberInit lastKept = null;
3924 for(member = members.dataMembers->first; member; member = member.next)
3926 Identifier ident = member.identifiers ? member.identifiers->first : null;
3927 bool deleted = false;
3929 // For now delete if it's not a method
3930 if(!member.variable) // && ident)
3932 if(!ident || !ident.next)
3934 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3937 f.Seek(member.loc.start.pos - position, current);
3938 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3939 position = member.loc.end.pos;
3944 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3945 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3946 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
3948 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
3949 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
3951 f.Seek(member.loc.start.pos - position, current);
3952 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3953 position = member.loc.end.pos;
3965 //f.Seek(member.loc.start.pos - position, current);
3966 //position = member.loc.start.pos;
3967 DeleteJunkBefore(f, member.loc.start.pos, &position);
3968 if(prev) f.Printf(", ");
3969 else if(keptMember) f.Printf(" ");
3974 if(!keptMember || !members.next)
3979 if(keptMember && lastKept != members.dataMembers->last)
3984 f.Seek(-1, current);
3990 f.Seek(-1, current);
3993 else if(!isspace(ch))
3995 f.Seek(-2, current);
4000 f.DeleteBytes(count);
4003 f.Seek(members.loc.end.pos - position, current);
4008 f.Seek(-1, current);
4010 position = members.loc.end.pos + 1;
4014 f.Seek(-1, current);
4015 position = members.loc.end.pos;
4021 lastIsMethod = false;
4026 DeleteJunkBefore(f, position, &position);
4029 if(lastKept != members.dataMembers->last)
4034 f.Seek(-1, current);
4040 f.Seek(-1, current);
4043 else if(!isspace(ch))
4045 f.Seek(-2, current);
4050 f.DeleteBytes(count);
4054 f.Seek(members.loc.end.pos - position, current);
4055 position = members.loc.end.pos;
4059 lastIsMethod = true;
4062 lastIsMethod = false;
4068 f.Seek(members.loc.end.pos - position, current);
4069 position = members.loc.end.pos;
4071 lastIsMethod = true;
4074 else if(members.type == methodMembersInit)
4076 if(this.methodAction == actionDeleteMethod && members.function == function);
4078 methodPresent = true;
4080 // Delete instance method here
4081 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4082 members.function == function)
4084 if(this.moveAttached && !*text)
4085 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4087 DeleteJunkBefore(f, members.loc.start.pos, &position);
4088 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4089 position = members.loc.end.pos + 1;
4094 DeleteJunkBefore(f, position, &position);
4098 DeleteJunkBefore(f, members.loc.start.pos, &position);
4099 lastIsMethod = true;
4103 f.Seek(members.loc.end.pos - position, current);
4104 position = members.loc.end.pos;
4106 DeleteJunkBefore(f, position, &position);
4115 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4117 Method method = this.method;
4118 DeleteJunkBefore(f, position, &position);
4124 if(!method.dataType)
4125 method.dataType = ProcessTypeString(method.dataTypeString, false);
4128 Type dataType = method.dataType;
4129 Type returnType = dataType.returnType;
4132 if(this.moveAttached)
4134 // Move function here:
4135 int newLen = strlen(method.name);
4140 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4142 // First change name of function
4143 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4144 *textSize += newLen - movedFuncIdLen;
4145 memcpy(*text + movedFuncIdPos, method.name, newLen);
4147 // Second, tab right
4150 for(c = 0; (*text)[c]; )
4153 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4156 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4157 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4161 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4171 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4173 // ADDING METHOD HERE
4175 OutputType(f, returnType, false);
4178 if(dataType.thisClass)
4180 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4182 if(dataType.thisClass.shortName)
4183 f.Printf(dataType.thisClass.shortName);
4185 f.Printf(dataType.thisClass.string);
4189 f.Printf(method.name);
4191 for(param = dataType.params.first; param; param = param.next)
4193 OutputType(f, param, true);
4198 f.Printf(" %c\n\n", OpenBracket);
4200 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4202 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4203 f.Printf(" return true;\n");
4204 else if(returnType.kind != voidType)
4205 f.Printf(" return 0;\n");
4210 if(returnType.kind != voidType)
4211 f.Printf("return ");
4212 f.Printf("%s::%s(", control._class.name, method.name);
4213 for(param = dataType.params.first; param; param = param.next)
4215 if(param.prev) f.Printf(", ");
4216 if(param.kind != voidType)
4217 f.Printf(param.name);
4221 f.Printf(" %c\n", CloseBracket);
4227 if(!object.instCode)
4230 f.Printf(" %c;\n", CloseBracket);
4232 f.Printf("%c;\n", CloseBracket);
4234 else if(!object.deleted)
4236 // Turn this into a multiline instance when adding a method
4237 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4239 f.Printf(methodPresent ? "\n " : " ");
4241 f.Seek(inst.loc.end.pos + 1 - position, current);
4242 position = inst.loc.end.pos + 1;
4247 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4250 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4252 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4254 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4256 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4257 if(prop && prop.isProperty && !prop.conversion)
4259 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4260 (!prop.IsSet || prop.IsSet(classObject.instance)))
4262 Class dataType = prop.dataTypeClass;
4263 char tempString[1024] = "";
4265 bool specify = false;
4268 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4269 if(member && member._class == regClass)
4273 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4275 if(dataType && dataType.type == structClass)
4277 void * dataForm = new0 byte[dataType.structSize];
4278 void * dataTest = new0 byte[dataType.structSize];
4280 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4281 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4283 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4285 bool needClass = true;
4287 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4288 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4290 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4292 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4297 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4299 void * dataForm, * dataTest;
4301 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4302 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4304 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4306 char tempString[1024] = "";
4308 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4310 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4312 // Shouldn't go here ...
4313 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4317 bool needClass = true;
4319 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4321 if(!strcmp(dataType.dataTypeString, "char *"))
4323 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4324 OutputString(f, string);
4328 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4330 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4336 DataValue dataForm, dataTest;
4338 GetProperty(prop, classObject.instance, &dataForm);
4339 GetProperty(prop, test, &dataTest);
4341 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4343 SetProperty(prop, test, dataForm);
4344 if(dataType.type == bitClass)
4346 bool needClass = true;
4347 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4349 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4351 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4355 bool needClass = true;
4356 if(dataType.type == enumClass)
4359 Class enumClass = eSystem_FindClass(privateModule, "enum");
4360 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4362 for(value = e.values.first; value; value = value.next)
4364 if((int)value.data == dataForm.i)
4366 string = value.name;
4372 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4373 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4374 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4376 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4385 void UpdateFormCode()
4394 else if(formModified)
4396 EditBoxStream f { editBox = editBox };
4400 Identifier movedFuncId;
4401 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4402 ObjectInfo classObject;
4408 movedFuncId = GetDeclId(function.declarator);
4409 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4410 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4413 for(classObject = classes.first; classObject; classObject = classObject.next)
4416 ClassDefinition classDef = classObject.classDefinition;
4417 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4420 bool firstObject = true;
4421 ObjectInfo object = classObject.instances.first;
4422 bool lastIsDecl = false;
4424 if(!classObject.modified) continue;
4426 test = eInstance_New(regClass);
4429 // Put it in the same desktop window...
4430 designer.PrepareTestObject(test);
4432 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4433 //f.Printf("%c\n\n", OpenBracket);
4435 // Change the _class name
4436 f.Seek(classDef.nameLoc.start.pos - position, current);
4437 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4438 f.Printf(classObject.name);
4439 position = classDef.nameLoc.end.pos;
4442 // Go to block start, delete all until no white space, put \n
4446 f.Seek(classDef.blockStart.end.pos - position, current);
4447 position = classDef.blockStart.end.pos;
4449 for(; f.Getc(&ch); count++)
4453 f.Seek(-1, current);
4463 f.Seek(-count, current);
4465 f.DeleteBytes(count-back);
4467 position += count-back;
4470 // Output properties
4471 OutputClassProperties(classObject.instance._class, classObject, f, test);
4473 for(def = classDef.definitions->first; def; def = def.next)
4477 case defaultPropertiesClassDef:
4479 bool keptMember = false;
4481 MemberInit lastKept = null;
4484 DeleteJunkBefore(f, def.loc.start.pos, &position);
4487 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4489 Identifier ident = propDef.identifiers->first;
4490 bool deleted = false;
4492 // For now delete if it's a prop
4493 if(!propDef.variable && ident)
4497 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4500 f.Seek(propDef.loc.start.pos - position, current);
4501 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4502 position = propDef.loc.end.pos;
4507 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4508 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4510 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4511 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4513 f.Seek(propDef.loc.start.pos - position, current);
4514 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4515 position = propDef.loc.end.pos;
4533 f.Seek(def.loc.end.pos - position - 1, current);
4538 f.Seek(-1, current);
4541 position = def.loc.end.pos;
4545 if(lastKept != def.defProperties->last)
4550 f.Seek(-1, current);
4556 f.Seek(-1, current);
4559 else if(!isspace(ch))
4561 f.Seek(-2, current);
4566 f.DeleteBytes(count);
4570 f.Seek(def.loc.end.pos - position, current);
4571 position = def.loc.end.pos;
4576 case declarationClassDef:
4578 Declaration decl = def.decl;
4580 if(decl.type == instDeclaration)
4582 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4584 while(def.object && object != def.object)
4586 if(object /*&& ((ObjectInfo)def.object).modified*/)
4587 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4588 object = object.next;
4591 DeleteJunkBefore(f, def.loc.start.pos, &position);
4592 f.Printf(firstObject ? "\n\n " : "\n ");
4593 firstObject = false;
4595 if(def.object && ((ObjectInfo)def.object).modified)
4596 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4598 object = object ? object.next : null;
4602 DeleteJunkBefore(f, def.loc.start.pos, &position);
4603 f.Printf(firstObject ? "\n\n " : "\n ");
4604 firstObject = false;
4610 DeleteJunkBefore(f, def.loc.start.pos, &position);
4611 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4616 case functionClassDef:
4618 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4619 if(!def.function.body) continue;
4623 DeleteJunkBefore(f, def.loc.start.pos, &position);
4626 // Delete _class methods
4627 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4628 def.function == function)
4633 if(moveAttached && !text)
4635 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4638 f.Seek(def.loc.end.pos - position, current);
4639 for(; f.Getc(&ch); count++)
4643 f.Seek(-1, current);
4647 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4649 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4650 position = def.loc.end.pos + count;
4653 // In case of detaching methods in the _class, simply rename the method
4654 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4656 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4657 f.DeleteBytes(movedFuncIdLen);
4659 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4662 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4663 function == def.function)
4665 // In case of attaching methods in the _class, simply rename the method
4666 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4667 position = function.loc.start.pos + movedFuncIdPos;
4668 f.DeleteBytes(movedFuncIdLen);
4669 if(method.dataType.thisClass)
4670 f.Printf("%s::", method.dataType.thisClass.string);
4671 f.Puts(method.name);
4672 position += movedFuncIdLen;
4677 DeleteJunkBefore(f, def.loc.start.pos, &position);
4678 if(def.type == memberAccessClassDef)
4681 firstObject = false;
4691 f.Seek(def.loc.end.pos - position, current);
4692 position = def.loc.end.pos;
4695 // Output attached methods
4696 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4698 DeleteJunkBefore(f, position, &position);
4699 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4702 // ********** INSTANCES ***************
4703 for(; object; object = object.next)
4705 if(!object.instCode)
4707 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4711 DeleteJunkBefore(f, position, &position);
4713 // ****************** METHODS ***********************
4714 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4716 // If detaching an instance method
4717 if(selected != classObject)
4719 int newLen = strlen(methodName);
4722 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4723 // Tab selection left
4726 for(c = 0; text[c]; )
4729 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4730 memmove(text+start, text+start+i, textSize+1-start-i);
4733 for(; text[c] && text[c] != '\n'; c++);
4739 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4740 textSize += newLen - movedFuncIdLen;
4741 memcpy(text + movedFuncIdPos, methodName, newLen);
4748 if(methodAction == actionAddMethod && selected == classObject)
4750 Method method = this.method;
4752 if(!method.dataType)
4753 method.dataType = ProcessTypeString(method.dataTypeString, false);
4755 // ADDING METHOD HERE
4757 Type dataType = method.dataType;
4758 Type returnType = dataType.returnType;
4760 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4764 OutputType(f, returnType, false);
4767 if(dataType.thisClass && !dataType.classObjectType)
4769 if(dataType.thisClass.shortName)
4770 f.Printf(dataType.thisClass.shortName);
4772 f.Printf(dataType.thisClass.string);
4775 f.Printf(method.name);
4777 for(param = dataType.params.first; param; param = param.next)
4779 OutputType(f, param, true);
4784 f.Printf(" %c\n\n", OpenBracket);
4786 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4788 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4789 f.Printf(" return true;\n");
4790 else if(returnType && returnType.kind != voidType)
4791 f.Printf(" return 0;\n");
4796 if(returnType.kind != voidType)
4797 f.Printf("return ");
4799 char * name = ((Specifier)classDef.baseSpecs->first).name;
4800 Symbol _class = FindClass(name);
4801 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4803 for(param = dataType.params.first; param; param = param.next)
4805 if(param.prev) f.Printf(", ");
4806 if(param.kind != voidType)
4807 f.Printf(param.name);
4812 f.Printf(" %c", CloseBracket);
4816 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4828 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4829 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4833 codeModified = false;
4834 formModified = false;
4836 moveAttached = false;
4841 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4844 ClassFunction function = null;
4847 ObjectInfo object = this.selected;
4849 if(object && object == this.oClass)
4851 ClassDefinition classDef = object.oClass.classDefinition;
4853 if(classDef && classDef.definitions)
4855 for(def = classDef.definitions->first; def; def = def.next)
4857 if(def.type == functionClassDef && def.function.declarator)
4859 if(!strcmp(def.function.declarator.symbol.string, methodName))
4861 function = def.function;
4866 else if(def.type == defaultPropertiesClassDef)
4870 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4872 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4873 if(ident && !ident.next)
4875 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4879 propLoc = propDef.loc;
4882 ClassDefinition classDef = object.oClass.classDefinition;
4884 if(classDef.definitions)
4886 for(def = classDef.definitions->first; def; def = def.next)
4888 if(def.type == functionClassDef)
4890 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4892 function = def.function;
4911 Instantiation inst = object.instCode;
4913 // Check here to see if the method already exists, no need to call ModifyCode in that case
4914 if(inst && inst.members)
4916 MembersInit members;
4917 for(members = inst.members->first; members; members = members.next)
4919 switch(members.type)
4921 case dataMembersInit:
4923 if(members.dataMembers)
4926 for(member = members.dataMembers->first; member; member = member.next)
4928 Identifier ident = member.identifiers ? member.identifiers->first : null;
4929 if(ident && !ident.next)
4931 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4935 propLoc = member.loc;
4938 ClassDefinition classDef = object.oClass.classDefinition;
4940 if(classDef.definitions)
4942 for(def = classDef.definitions->first; def; def = def.next)
4944 if(def.type == functionClassDef)
4946 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
4948 function = def.function;
4957 // TODO: Fix memory leak
4958 function = ClassFunction
4960 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
4972 case methodMembersInit:
4974 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
4976 function = members.function;
4988 if(functionPtr) *functionPtr = function;
4992 void GoToMethod(char * methodName /*Method method*/)
4996 ObjectInfo object = selected;
4997 EditBoxStream f { editBox = editBox };
4998 ClassFunction function = null;
4999 bool atChar = false;
5003 Location propLoc = { {0,0,-1} };
5006 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5007 if(function && function.body)
5010 f.Seek(function.body.loc.start.pos+1, current);
5020 f.Seek(-1, current);
5025 else if(!isspace(ch))
5027 f.Seek(-1, current);
5033 else if(propLoc.start.pos > -1)
5035 f.Seek(propLoc.start.pos, current);
5038 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5040 if(function || propLoc.start.pos > -1)
5042 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5043 editBox.CenterOnCursor();
5044 SetState(normal, false, 0);
5047 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5049 FreeClassFunction(function);
5055 void FindCompatibleMethods(Method method, OldList compatible)
5057 ClassDefinition classDef = this.oClass.classDefinition;
5058 if(classDef && classDef.definitions)
5061 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5064 Symbol classSym { };
5065 Symbol selectedClass;
5066 if(this.selected == this.oClass)
5067 selectedClass = classSym;
5069 selectedClass = FindClass(this.selected.instance._class.name);
5071 regClass.name = classDef._class.name;
5072 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5073 for(def = classDef.definitions->first; def; def = def.next)
5075 if(def.type == functionClassDef && def.function.declarator)
5077 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5079 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5082 Type type = def.function.declarator.symbol.type;
5083 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5085 compatible.Add(OldLink { data = def.function });
5091 if(this.oClass && this.oClass.instance)
5093 classSym.registered = regClass;
5094 //classSym.registered = this.oClass.oClass;
5096 for(_class = regClass.base; _class; _class = _class.base)
5099 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5101 // TODO: Understand why these functions popup in attach list
5102 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5104 if(!testMethod.dataType)
5105 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5107 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5108 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5109 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5111 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5112 // ClassFunction function { };
5113 FunctionDefinition function { };
5115 function.declarator = Declarator { };
5116 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5117 excludedSymbols.Add(function.declarator.symbol);
5119 compatible.Add(OldLink { data = function });
5130 void AddMethod(Method method)
5134 char methodName[1024];
5135 strcpy(methodName, method.name);
5136 if(!FindMethod(methodName, null, null))
5138 methodAction = actionAddMethod;
5139 this.method = method;
5143 GoToMethod(methodName);
5147 void DeleteMethod(ClassFunction function)
5151 methodAction = actionDeleteMethod;
5152 this.function = function;
5160 void AttachMethod(Method method, ClassFunction function)
5164 // If it's an instance we'll ask if we want to move it inside...
5165 if(!function.attached.count && function.body)
5167 // Find the function in the _class to check if it's a virtual function
5168 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5169 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5170 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5172 for(def = this.classDefinition.first; def; def = def.next)
5174 if(def.type == functionClassDef)
5176 if(def.function == function)
5181 if(!method || method.type != virtualMethod)
5184 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5185 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5187 moveAttached = true;
5192 methodAction = actionAttachMethod;
5193 this.method = method;
5194 this.function = function;
5201 void ReAttachMethod(Method method, ClassFunction function)
5205 // If it's an instance we'll ask if we want to move it inside...
5206 if(!function.attached.count && function.body)
5208 // Find the function in the _class to check if it's a virtual function
5209 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5210 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5211 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5213 for(def = this.classDefinition.first; def; def = def.next)
5215 if(def.type == functionClassDef)
5217 if(def.function == function)
5222 if(!method || method.type != virtualMethod)
5225 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5226 if(MessageBox { type = yesNo, master = parent, text = title,
5227 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5229 moveAttached = true;
5234 methodAction = actionReattachMethod;
5235 this.method = method;
5236 this.function = function;
5243 void DetachMethod(Method method, ClassFunction function, int type)
5251 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5252 master = sheet, text = $"Name detached method", background = formColor
5256 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5257 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5261 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5262 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5266 dialog, anchor = { left = 5, right = 5, top = 5 }
5268 sprintf(methodName, "%s_%s", selected.name, method.name);
5269 nameBox.contents = methodName;
5271 result = dialog.Modal() == ok;
5272 strcpy(methodName, nameBox.contents);
5277 // If the method is not attached, move it outside
5280 // Add this class to the methodName
5281 char name[1024] = "";
5283 if(this.selected != this.oClass && !method.dataType.thisClass)
5285 strcat(name, this.selected.instance._class.name);
5287 strcat(name, this.methodName);
5288 strcpy(this.methodName, name);
5290 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5292 strcat(name, method.dataType.thisClass.string);
5294 strcat(name, this.methodName);
5295 strcpy(this.methodName, name);
5298 this.moveAttached = true;
5301 this.methodAction = actionDetachMethod;
5302 this.method = method;
5303 this.function = function;
5310 void AddObject(Instance instance, ObjectInfo * object)
5314 //*object = _class.instances.Add(sizeof(ObjectInfo));
5315 *object = ObjectInfo { };
5316 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5317 (*object).oClass = oClass;
5318 (*object).instance = instance;
5323 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5325 // if(strcmp(name, this.oClass.instance.name))
5328 for(check = oClass.instances.first; check; check = check.next)
5329 if(!check.deleted && check.name && !strcmp(name, check.name))
5333 (*object).name = CopyString(name);
5338 toolBox.controlClass = null;
5342 //sheet.AddObject(*object, (*object).name, TypeData, true);
5347 void EnsureUpToDate()
5349 if(sheet && codeModified)
5353 void SelectObject(ObjectInfo object)
5356 oClass = object ? object.oClass : null;
5358 designer.SelectObject(object, object ? object.instance : null);
5361 void SelectObjectFromDesigner(ObjectInfo object)
5364 sheet.SelectObject(object);
5367 void EnumerateObjects(Sheet sheet)
5371 for(oClass = classes.first; oClass; oClass = oClass.next)
5377 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5378 for(object = oClass.instances.first; object; object = object.next)
5379 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5382 sheet.SelectObject(selected);
5387 designer.AddObject();
5390 void DeleteObject(ObjectInfo object)
5392 delete object.instance;
5393 object.deleted = true;
5394 object.modified = true;
5395 object.oClass.modified = true;
5397 if(selected == object)
5399 bool looped = false;
5400 ObjectInfo select = object;
5404 select = select.prev;
5408 select = object.oClass.instances.last;
5415 sheet.SelectObject(select ? select : oClass);
5418 if(!object.instCode && object.oClass != object)
5421 oClass.instances.Delete(object);
5424 if(sheet.codeEditor == this)
5425 sheet.DeleteObject(object);
5428 void RenameObject(ObjectInfo object, char * name)
5432 // Validate the name:
5433 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5434 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5437 for(c = 0; name[c]; c++)
5438 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5446 object.name = (name && name[0]) ? CopyString(name) : null;
5448 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5452 void DesignerModifiedObject()
5454 sheet.ListProperties(false);
5458 void ListSubMembers(Type member)
5462 for(subMember = member.members.first; subMember; subMember = subMember.next)
5466 DataRow row = membersList.AddString(subMember.name);
5467 row.icon = icons[typeData];
5471 ListSubMembers(subMember);
5476 void ListSubDataMembers(DataMember member, bool isPrivate)
5478 DataMember subMember;
5479 for(subMember = member.members.first; subMember; subMember = subMember.next)
5481 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5485 DataRow row = membersList.AddString(subMember.name);
5486 BitmapResource bitmap = null;
5487 if(!subMember.dataType)
5488 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5490 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5492 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5495 bitmap = { bitmapName };
5496 membersList.AddResource(bitmap);
5499 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5503 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5509 void ListClassMembers(Class whatClass, bool methodsOnly)
5512 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5513 bool isPrivate = false;
5515 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5517 Method method, methodIt;
5519 DataMember memberIt;
5521 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5523 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5524 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5526 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5528 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5530 DataRow row = membersList.FindString(method.name);
5533 row = membersList.AddString(method.name);
5535 if(!method.dataType)
5536 method.dataType = ProcessTypeString(method.dataTypeString, false);
5538 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5546 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5550 if(memberIt.isProperty)
5552 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5554 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5558 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5560 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5563 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5569 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5571 if(member.isProperty)
5573 Property prop = (Property) member;
5574 if(!membersList.FindString(prop.name))
5576 DataRow row = membersList.AddString(prop.name);
5577 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5580 else if(member.name && !membersList.FindString(member.name))
5582 DataRow row = membersList.AddString(member.name);
5584 BitmapResource bitmap = null;
5585 if(!member.dataType)
5586 member.dataType = ProcessTypeString(member.dataTypeString, false);
5588 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5590 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5593 bitmap = { bitmapName };
5594 membersList.AddResource(bitmap);
5597 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5600 ListSubDataMembers(member, member.memberAccess == privateAccess);
5604 if(_class.inheritanceAccess == privateAccess)
5607 if(_class.module != privateModule) break;
5612 void ListClassMembersMatch(Class whatClass, Type methodType)
5615 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5616 bool isPrivate = false;
5618 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5624 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5626 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5628 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5630 if(!method.dataType)
5631 method.dataType = ProcessTypeString(method.dataTypeString, false);
5633 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5635 DataRow row = membersList.FindString(method.name);
5638 row = membersList.AddString(method.name);
5639 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5645 if(_class.inheritanceAccess == privateAccess)
5648 if(_class.module != privateModule) break;
5653 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5656 bool isPrivate = false;
5657 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5663 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5665 if(method.type == virtualMethod)
5667 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5669 DataRow row = membersList.FindString(method.name);
5672 row = membersList.AddString(method.name);
5674 if(!method.dataType)
5675 method.dataType = ProcessTypeString(method.dataTypeString, false);
5677 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5683 for(member = _class.membersAndProperties.first; member; member = member.next)
5685 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5687 if(member.isProperty)
5689 Property prop = (Property)member;
5691 DataRow row = membersList.AddString(prop.name);
5692 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5695 else if(member.name && (!curString || strcmp(curString, member.name)))
5697 DataRow row = membersList.AddString(member.name);
5699 BitmapResource bitmap = null;
5700 if(!member.dataType)
5701 member.dataType = ProcessTypeString(member.dataTypeString, false);
5703 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5705 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5708 bitmap = { bitmapName };
5709 membersList.AddResource(bitmap);
5712 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5715 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5718 if(_class.inheritanceAccess == privateAccess)
5721 if(_class.module != privateModule) break;
5726 void ListMembers(Type type)
5728 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5732 if(type.kind == classType)
5735 ListClassMembers(type._class.registered, false);
5740 for(member = type.members.first; member; member = member.next)
5744 DataRow row = membersList.AddString(member.name);
5745 row.icon = icons[typeData];
5747 else if(member.kind == structType || member.kind == unionType)
5748 ListSubMembers(member);
5754 void ListModule(Module mainModule, int recurse, bool listClasses)
5757 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5758 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5759 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5760 for(module = mainModule.application.allModules.first; module; module = module.next)
5762 if(ModuleVisibility(mainModule, module))
5763 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5767 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5774 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5776 Class _class = link.data;
5777 if(_class.type != systemClass)
5779 DataRow row = membersList.AddString(_class.name);
5780 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5785 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5787 DefinedExpression definedExp = link.data;
5788 DataRow row = membersList.AddString(link /*definedExp*/.name);
5789 row.icon = icons[typeData];
5792 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5794 GlobalFunction function = link.data;
5795 DataRow row = membersList.AddString(link /*function*/.name);
5796 row.icon = icons[typeMethod];
5800 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5802 if(recurse != 2 && listClasses)
5804 if(!membersList.FindString(ns->name))
5806 DataRow row = membersList.AddString(ns->name);
5807 row.icon = icons[typeNameSpace];
5812 ListNameSpace(ns, 2, listClasses);
5816 void ListEnumValues(Class _class)
5818 List<Class> classes { };
5819 for(; _class && _class.type == enumClass; _class = _class.base)
5820 classes.Insert(null, _class);
5821 for(_class : classes)
5823 EnumClassData enumeration = (EnumClassData)_class.data;
5825 for(item = enumeration.values.first; item; item = item.next)
5827 DataRow row = membersList.AddString(item.name);
5828 row.icon = icons[typeEnumValue];
5834 bool ListEnumsModule(Module mainModule, Type dest)
5836 bool result = false;
5838 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5839 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5840 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5841 for(module = mainModule.application.allModules.first; module; module = module.next)
5843 if(ModuleVisibility(mainModule, module))
5844 result |= ListEnums(module.publicNameSpace, dest);
5849 void ListNameSpaceByString(Module mainModule, char * string)
5851 NameSpace * nameSpace;
5853 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5854 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5855 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5856 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5857 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5858 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5859 for(module = mainModule.application.allModules.first; module; module = module.next)
5861 if(ModuleVisibility(mainModule, module))
5863 nameSpace = FindNameSpace(module.publicNameSpace, string);
5864 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5869 bool ListEnums(NameSpace nameSpace, Type dest)
5872 bool result = false;
5874 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5876 Class _class = link.data;
5877 if(_class.type == enumClass && (dest.kind != classType || !dest._class || dest._class.registered != _class))
5879 OldList conversions { };
5881 type.kind = classType;
5882 type._class = FindClass(_class.name);
5883 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5885 ListEnumValues(_class);
5888 conversions.Free(null);
5892 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5894 result |= ListEnums(nameSpace, dest);
5899 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5903 for(c = 0; (ch = name[c]); c++)
5905 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5907 NameSpace * newSpace;
5908 char * spaceName = new char[c - start + 1];
5909 memcpy(spaceName, name + start, c - start);
5910 spaceName[c-start] = '\0';
5911 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5915 nameSpace = newSpace;
5924 return (NameSpace *)nameSpace;
5927 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5929 bool listedEnums = false;
5930 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5931 bool listClasses = true;
5933 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5935 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5936 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5937 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5939 if(exp.type == identifierExp)
5940 id = realIdentifier;
5942 if(id && id._class && !id._class.name)
5944 listClasses = false;
5947 else if(id && id._class && id._class.name)
5951 Class _class = id.classSym.registered;
5952 if(_class && _class.type == enumClass)
5954 ListEnumValues(_class);
5957 ListClassMembers(id.classSym.registered, true);
5962 else if(id && colons)
5964 ListNameSpaceByString(this.privateModule, id.string);
5969 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
5971 listedEnums = ListEnumsModule(this.privateModule, destType);
5974 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
5976 ListEnumValues(destType._class.registered);
5979 ListClassPropertiesAndVirtual(insideClass, null);
5983 else if(destType && destType.kind == enumType)
5987 for(value = destType.members.first; value; value = value.next)
5989 DataRow row = membersList.AddString(value.name);
5990 row.icon = icons[typeEnumValue];
5994 ListClassPropertiesAndVirtual(insideClass, null);
5998 else if(insideClass && !enumOnly)
6000 ListClassPropertiesAndVirtual(insideClass, string);
6003 if(listedEnums && string && string[0])
6005 DataRow row = membersList.FindSubString(string);
6007 listedEnums = false;
6010 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6012 ListClassMembersMatch(GetThisClass(), exp.destType);
6014 else if(!insideClass && !enumOnly && !listedEnums)
6017 Symbol symbol = null;
6021 ListClassMembers(GetThisClass(), false);
6024 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6026 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6028 // Don't list enum values?
6029 //if(symbol.type.kind != TypeEnum)
6030 DataRow row = membersList.FindString(symbol.string);
6033 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6035 row = membersList.AddString(symbol.string);
6036 if(symbol.type && symbol.type.kind == functionType)
6037 row.icon = icons[typeMethod];
6038 else if(symbol.type && symbol.type.kind == enumType)
6040 row.icon = icons[typeEnumValue];
6044 BitmapResource bitmap = null;
6045 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6047 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6050 bitmap = { bitmapName };
6051 membersList.AddResource(bitmap);
6054 row.icon = bitmap ? bitmap : icons[typeData];
6061 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6063 DataRow row = membersList.FindString(symbol.string);
6066 row = membersList.AddString(symbol.string);
6067 if(symbol.type.kind == functionType)
6068 row.icon = icons[typeMethod];
6069 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6071 row.icon = icons[typeClass];
6075 row.icon = icons[typeDataType];
6082 ListModule(this.privateModule, 1, listClasses);
6083 // TODO: Implement this with name space
6087 for(data = globalData.first; data; data = data.next)
6089 DataRow row = membersList.FindString(data.name);
6091 data.dataType = ProcessTypeString(data.dataTypeString, false);
6094 row = membersList.AddString(data.name);
6096 if(data.dataType && data.dataType.kind == TypeEnum)
6098 row.icon = icons[typeEnumValue];
6102 BitmapResource bitmap = null;
6103 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6105 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6108 bitmap = { bitmapName };
6109 membersList.AddResource(bitmap);
6112 row.icon = bitmap ? bitmap : icons[typeData];
6120 DataRow row = membersList.AddString("Min");
6121 row.icon = icons[typeMethod];
6123 row = membersList.AddString("Max");
6124 row.icon = icons[typeMethod];
6126 row = membersList.AddString("Abs");
6127 row.icon = icons[typeMethod];
6129 row = membersList.AddString("Sgn");
6130 row.icon = icons[typeMethod];
6136 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6138 EditBoxStream f { editBox = editBox };
6143 updatingCode = true;
6145 if(!method.dataType)
6146 method.dataType = ProcessTypeString(method.dataTypeString, false);
6148 DeleteJunkBefore(f, function.loc.start.pos, &position);
6149 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6151 // ADDING METHOD HERE
6153 Type dataType = method.dataType;
6154 Type returnType = dataType.returnType;
6156 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6162 if(extraIndent) f.Printf(" ");
6164 OutputType(f, returnType, false);
6168 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6170 if(dataType.thisClass.shortName)
6171 f.Printf(dataType.thisClass.shortName);
6173 f.Printf(dataType.thisClass.string);
6176 f.Printf(method.name);
6178 for(param = dataType.params.first; param; param = param.next)
6180 // Decided not to write void...
6181 if(param.kind != voidType)
6183 OutputType(f, param, true);
6189 if(extraIndent) f.Printf(" ");
6190 f.Printf(" %c\n", OpenBracket);
6192 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6198 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6199 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6201 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6203 if(extraIndent) f.Printf(" ");
6204 f.Printf(" return true;\n");
6206 else if(returnType && returnType.kind != voidType)
6208 if(extraIndent) f.Printf(" ");
6209 f.Printf(" return 0;\n");
6214 if(extraIndent) f.Printf(" ");
6216 if(returnType.kind != voidType)
6217 f.Printf("return ");
6218 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6219 for(param = dataType.params.first; param; param = param.next)
6221 if(param.prev) f.Printf(", ");
6222 if(param.kind != voidType)
6223 f.Printf(param.name);
6229 if(extraIndent) f.Printf(" ");
6230 f.Printf(" %c", CloseBracket);
6235 if(extraIndent) { x1 += 3; x2 += 3; }
6236 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6238 this.updatingCode = false;
6242 // Return false if we overrided a function and don't want to run params listing
6243 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6245 bool didOverride = false;
6246 EditLine line = editBox.line;
6247 char * text = line.text;
6248 int lineNum, charPos;
6249 Expression exp = null;
6252 //Identifier id = null;
6253 Expression memberExp = null;
6254 Identifier realIdentifier = null;
6256 if(!privateModule) return !didOverride;
6258 insideFunction = null;
6260 charPos = editBox.charPos + 1;
6261 if(!membersListShown)
6266 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6268 EditBoxStream f { editBox = editBox };
6270 updatingCode = true;
6271 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6275 if(!f.Seek(-1, current))
6278 if(!isspace(ch)) break;
6279 f.Seek(-1, current);
6281 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6283 lineNum = editBox.lineNumber + 1;
6284 charPos = editBox.charPos + 1;
6286 updatingCode = false;
6289 if(!membersListShown)
6291 memberExp = FindExpTree(ast, lineNum, charPos);
6292 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6297 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6299 EditBoxStream f { editBox = editBox };
6302 updatingCode = true;
6304 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6307 if(ch == '}' || ch == ',' || ch == ')')
6309 f.Seek(-1, current);
6317 if(!f.Seek(-1, current))
6320 if(!isspace(ch)) break;
6321 f.Seek(-1, current);
6325 f.Seek(-1, current);
6327 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6329 lineNum = editBox.lineNumber + 1;
6330 charPos = editBox.charPos + 1;
6332 updatingCode = false;
6335 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6340 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6341 lineNum = editBox.lineNumber + 1;
6342 charPos = editBox.charPos/* + 1*/;
6346 char tempString[1024];
6347 char * string = null;
6348 CodePosition idStart, idEnd;
6350 if(membersListShown)
6352 char * buffer = membersLine.text;
6354 bool firstChar = true;
6356 string = tempString;
6358 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6360 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6361 if(!isSpace) firstChar = false;
6363 string[len++] = buffer[c];
6367 else //if(realIdentifier)//if(id)
6370 char * buffer = id.string;
6372 bool firstChar = true;
6374 string = tempString;
6375 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6377 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6378 if(!isSpace) firstChar = false;
6380 string[len++] = buffer[c];
6386 EditLine editLine = editBox.line;
6387 bool firstChar = true;
6390 string = tempString;
6391 for(y = lineNum-1; y >= 0; y--)
6393 char * buffer = editLine.text;
6394 int lineCount = editLine.count;
6395 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6397 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6402 idEnd.charPos = x + 2;
6407 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6410 idEnd.charPos = x + 2;
6417 if(!isalnum(buffer[x]) && buffer[x] != '_')
6423 memmove(string+1, string, len++);
6424 string[0] = buffer[x];
6428 //if(done || firstChar)
6429 if(done || !firstChar)
6431 editLine = editLine.prev;
6434 if(!strcmp(string, "case"))
6440 else if(!strcmp(string, "return"))
6446 else if(!strcmp(string, "delete"))
6452 else if(!strcmp(string, "new"))
6458 else if(!strcmp(string, "renew"))
6466 idStart.charPos = x + 1;
6467 idStart.line = y + 1;
6470 if(!membersListShown)
6472 membersList.Clear();
6473 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6475 Type type = memberExp.member.exp.expType;
6476 if(pointer == 2 && type)
6478 if(type.kind == pointerType || type.kind == arrayType)
6487 ListSymbols(exp, enumOnly, string, realIdentifier);
6489 membersList.Sort(null, 1);
6494 // Virtual function override
6495 Identifier id = GetDeclId(insideFunction.declarator);
6496 char * string = id ? id.string : null;
6498 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6501 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6502 insideFunction = null;
6505 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6510 if(!didOverride) //insideFunction)
6512 rowCount = membersList.rowCount;
6515 DataRow row = string ? membersList.FindSubString(string) : null;
6516 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6518 char * newString = row.string;
6519 if(!membersListShown)
6521 membersLoc.start.line = idStart.line-1;
6522 membersLoc.start.charPos = idStart.charPos-1;
6523 //membersLoc.end = membersLoc.start;
6524 membersLoc.end.charPos = idEnd.charPos-1;
6525 membersLoc.end.line = idEnd.line-1;
6526 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6527 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6532 membersList.Destroy(0);
6533 membersListShown = false;
6536 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6538 line, membersLoc.start.line, membersLoc.start.charPos,
6539 line, membersLoc.end.line, membersLoc.end.charPos);
6540 editBox.PutS(newString);
6546 row = membersList.FindSubStringi(string);
6548 membersList.currentRow = row;
6549 membersList.currentRow.selected = false;
6552 membersList.currentRow = row;
6554 if(!membersListShown)
6558 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6559 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6560 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6561 editBox.GetCaretPosition(caret);
6562 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6564 membersList.master = this;
6566 caret.y += editBox.GetCaretSize();
6568 membersList.Create();
6571 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6572 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6573 Window parent = membersList.parent;
6575 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6577 y -= editBox.GetCaretSize() + membersList.size.h;
6578 membersAbove = true;
6581 membersAbove = false;
6583 membersList.position = { x, y };
6587 membersLoc.start.line = lineNum - 1;
6589 if(string && string[0])
6591 membersLoc.start.charPos = idStart.charPos-1;
6592 membersLoc.end = membersLoc.start;
6593 //membersLoc.end.charPos = id.loc.end.charPos-1;
6594 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6598 membersLoc.start.charPos = charPos;
6599 membersLoc.end = membersLoc.start;
6600 membersLoc.end.charPos = charPos;
6602 membersListShown = true;
6604 // Hack to keep caret shown
6605 editBox.GetCaretPosition(caret);
6606 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6609 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6615 SetCurrentContext(globalContext);
6618 return !didOverride;
6621 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6623 EditLine line = editBox.line;
6624 char * text = line.text;
6625 int lineNum, charPos;
6626 Expression exp = null;
6630 charPos = editBox.charPos + 1;
6633 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6635 EditBoxStream f { editBox = editBox };
6638 updatingCode = true;
6639 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6642 if(ch == '}' || ch == ',' || ch == ')')
6644 f.Seek(-1, current);
6652 if(!f.Seek(-1, current))
6655 if(!isspace(ch)) break;
6656 f.Seek(-1, current);
6660 f.Seek(-1, current);
6662 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6664 lineNum = editBox.lineNumber + 1;
6665 charPos = editBox.charPos + 1;
6667 updatingCode = false;
6670 charPos = Min(charPos, l1.count + 1);
6672 FindParamsTree(ast, lineNum, charPos);
6674 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6675 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6677 ::functionType = null;
6678 ::instanceType = null;
6681 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6682 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6686 Window parent = paramsList.parent;
6688 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6691 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6692 // ( Dummy exp: always ends up with same memory)
6694 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6695 editBox.GetCaretPosition(paramsPosition);
6696 this.paramsPosition.y += editBox.GetCaretSize();
6699 FreeType(this.functionType);
6700 FreeType(this.instanceType);
6702 this.functionType = ::functionType;
6703 this.instanceType = ::instanceType;
6705 if(this.functionType) this.functionType.refCount++;
6706 if(this.instanceType) this.instanceType.refCount++;
6708 this.paramsID = ::paramsID;
6709 functionExp = paramsInsideExp;
6711 paramsList.master = this;
6713 paramsList.Create();
6715 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6716 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6718 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6720 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6724 paramsAbove = false;
6725 if(x + paramsList.size.w > parent.clientSize.w)
6727 x = parent.clientSize.w - paramsList.size.w;
6731 paramsList.position = { x, y };
6733 // Hack to keep caret shown
6736 editBox.GetCaretPosition(caret);
6737 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6740 this.paramsShown = true;
6742 else if((!::functionType && !::instanceType) || reposition)
6744 paramsList.Destroy(0);
6745 paramsShown = false;
6747 FreeType(this.functionType);
6748 FreeType(this.instanceType);
6749 this.functionType = null;
6750 this.instanceType = null;
6754 SetCurrentContext(globalContext);
6762 designer.visible = true;
6763 designer.Activate();
6769 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6771 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };