3 // *** Color Schemes ***
5 // *** The Old Color Scheme that was causing me auras and ophtalmic migraines -- Uncomment at your own risk! ***
7 FontResource panelFont { $"Courier New", 10 };
8 FontResource codeFont { $"Courier New", 10 };
9 Color selectionColor = Color { 10, 36, 106 };
10 Color selectionText = white;
11 Color viewsBackground = white;
12 Color viewsText = black;
13 Color outputBackground = white;
14 Color outputText = black;
15 Color projectViewBackground = white;
16 Color projectViewText = black;
17 Color codeEditorBG = white;
18 Color codeEditorFG = black;
19 Color marginColor = Color {230, 230, 230};
20 Color selectedMarginColor = Color {200, 200, 200};
21 Color lineNumbersColor = Color {60, 60, 60};
22 SyntaxColorScheme colorScheme
24 keywordColors = [ blue, blue ];
25 commentColor = dimGray;
26 charLiteralColor = crimson;
27 stringLiteralColor = crimson;
28 preprocessorColor = green;
33 // The new nice dark scheme -- so peaceful on my brain
35 FontResource panelFont { $"Courier New", 10 };
36 FontResource codeFont { $"Courier New", 10 };
38 FontResource panelFont { $"Consolas", 12 };
39 FontResource codeFont { $"Consolas", 12 };
41 Color selectionColor = lightYellow;
42 Color selectionText = Color { 30, 40, 50 };
43 Color viewsBackground = Color { 30, 40, 50 };
44 Color viewsText = lightGray;
45 Color outputBackground = black;
46 Color outputText = lime;
47 Color projectViewBackground = Color { 30, 40, 50 };
48 Color projectViewText = lightGray;
49 Color codeEditorBG = black;
50 Color codeEditorFG = ivory;
51 Color marginColor = Color {24, 24, 24};
52 Color selectedMarginColor = Color {64, 64, 64};
53 Color lineNumbersColor = Color {160, 160, 160};
54 SyntaxColorScheme colorScheme
56 keywordColors = [ skyBlue, skyBlue ];
57 commentColor = Color { 125, 125, 125 };
58 charLiteralColor = Color { 245, 50, 245 };
59 stringLiteralColor = Color { 245, 50, 245 };
60 preprocessorColor = { 120, 220, 140 };
61 numberColor = Color { 0, 192, 192 };
64 // *********************
70 // UNTIL IMPLEMENTED IN GRAMMAR
71 #define ACCESS_CLASSDATA(_class, baseClass) \
72 (_class ? ((void *)(((char *)_class.data) + baseClass.offsetClass)) : null)
75 extern int __attribute__((__stdcall__)) __ecereDll_Load_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
76 extern int __attribute__((__stdcall__)) __ecereDll_Unload_ecere(struct __ecereNameSpace__ecere__com__Instance * module);
79 static Array<FileFilter> fileFilters
81 { $"C/C++/eC Files (*.ec, *.eh, *.c, *.cpp, *.cc, *.cxx, *.h, *.hpp, *.hh, *.hxx)", "ec, eh, c, cpp, cc, cxx, h, hpp, hh, hxx" },
82 { $"Header Files for C/C++ (*.eh, *.h, *.hpp, *.hh, *.hxx)", "eh, h, hpp, hh, hxx" },
83 { $"C/C++/eC Source Files (*.ec, *.c, *.cpp, *.cc, *.cxx)", "ec, c, cpp, cc, cxx" },
84 { $"Text files (*.txt)", "txt" },
85 { $"All files", null }
88 static Array<FileType> fileTypes
90 { $"eC Source Code", "ec", whenNoneGiven },
91 { $"Text Files", "txt", never }
94 static char * iconNames[] =
96 "<:ecere>constructs/class.png",
97 "<:ecere>constructs/data.png",
98 "<:ecere>constructs/method.png",
99 "<:ecere>constructs/event.png",
100 "<:ecere>constructs/property.png",
101 "<:ecere>constructs/namespace.png",
102 "<:ecere>constructs/dataType.png",
103 "<:ecere>constructs/enumValue.png",
104 "<:ecere>constructs/dataPrivate.png",
105 "<:ecere>constructs/methodPrivate.png",
106 "<:ecere>constructs/propertyPrivate.png"
109 enum SheetType { methods, properties };
111 extern int __ecereVMethodID_class_OnEdit;
112 extern int __ecereVMethodID_class_OnDisplay;
113 extern int __ecereVMethodID_class_OnGetString;
114 extern int __ecereVMethodID_class_OnFree;
115 extern int __ecereVMethodID_class_OnCompare;
116 extern int __ecereVMethodID_class_OnCopy;
117 extern int __ecereVMethodID_class_OnSaveEdit;
118 extern int __ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad;
120 class EditFileDialog : FileDialog
124 if(!ide.projectView && ideSettings.ideFileDialogLocation)
125 currentDirectory = ideSettings.ideFileDialogLocation;
126 return FileDialog::OnCreate();
130 EditFileDialog codeEditorFileDialog
132 type = multiOpen, text = $"Open",
133 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType);
134 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
137 EditFileDialog codeEditorFormFileDialog
139 type = open, text = $"Open Project",
140 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType),
141 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
144 define OpenBracket = '{';
145 define CloseBracket = '}';
150 actionDeleteMethod = 2,
151 actionDetachMethod = 3,
152 actionAttachMethod = 4,
153 actionReattachMethod = 5
156 //extern StatusField pos, ovr, caps, num;
157 //extern Class thisClass;
163 bool parseError = false;
168 Expression ctxInsideExp;
169 Expression paramsInsideExp;
170 ClassFunction insideFunction;
178 /****************************************************************************
180 ****************************************************************************/
182 static void OutputString(File f, char * string)
185 for(c = 0; string[c]; c++)
187 if(string[c] == '\"')
189 else if(string[c] == '\\')
196 void OutputType(File f, Type type, bool outputName)
206 if(!type.isSigned) f.Printf("unsigned ");
210 if(!type.isSigned) f.Printf("unsigned ");
214 if(!type.isSigned) f.Printf("unsigned ");
218 if(!type.isSigned) f.Printf("unsigned ");
222 if(!type.isSigned) f.Printf("unsigned ");
233 if(type._class && !strcmp(type._class.string, "class"))
235 switch(type.classObjectType)
238 f.Printf("any_object");
241 f.Printf("typed_object");
248 // ADD CODE TO DECIDE WHETHER TO OUTPUT FULLY QUAlIFIED OR NOT:
249 f.Printf(type._class.shortName ? type._class.shortName : type._class.string);
259 OutputType(f, type.type, false);
262 OutputType(f, type.type, false);
281 if(type.kind == arrayType)
284 f.Printf("%d", type.arraySize);
290 void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
296 f.Seek(pos - *position, current);
298 // Try to delete spaces and \n before...
304 /*else if(ch == '\n')
306 // Look for // comments on the line before
307 EditBox editBox = f.editBox;
308 EditLine line = editBox.line;
315 for(c = 0; text[c]; c++)
324 if(text[c] == '/' && last == '/')
336 f.DeleteBytes(before);
341 void GetLocText(EditBox editBox, File f, int position, Location loc, char ** text, int * size, int pad, int linePad)
346 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
348 // Cut & Paste function
354 f.Seek(loc.start.pos - position, current);
356 x1 = editBox.charPos;
357 y1 = editBox.lineNumber;
358 f.Seek(loc.end.pos - loc.start.pos, current);
360 x2 = editBox.charPos;
361 y2 = editBox.lineNumber;
362 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
364 *size = editBox.SelSize();
365 *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
366 editBox.GetSel(*text, false);
369 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
370 f.Printf(""); // Make the stream point to where the editbox is
373 void Code_FixProperty(Property prop, Instance object)
375 Designer::FixProperty(prop, object);
378 bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
381 if(prop.dataTypeString && (!prop.IsSet || prop.IsSet(selected.instance)))
383 Class dataType = prop.dataTypeClass;
386 dataType = prop.dataTypeClass = eSystem_FindClass(test._class.module, prop.dataTypeString);
388 if(dataType && dataType._vTbl && dataType.type == structClass)
390 void * dataForm = new0 byte[dataType.structSize];
391 void * dataTest = new0 byte[dataType.structSize];
393 ((void (*)(void *, void *))(void *)prop.Get)(selected.instance, dataForm);
394 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
396 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
398 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
404 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
406 void * dataForm, * dataTest;
408 dataForm = ((void *(*)(void *))(void *)prop.Get)(selected.instance);
409 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
411 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
413 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
417 else if(dataType && dataType._vTbl)
419 DataValue dataForm, dataTest;
421 GetProperty(prop, selected.instance, &dataForm);
422 GetProperty(prop, test, &dataTest);
424 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
426 SetProperty(prop, test, dataForm);
428 // In case setting on test unset on real instance (e.g. isDefault)
429 if(strcmp(prop.name, "name"))
431 GetProperty(prop, selected.instance, &dataTest);
432 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
433 SetProperty(prop, selected.instance, dataForm);
442 bool Code_IsPropertyDisabled(ObjectInfo selected, char * name)
444 bool disabled = false;
445 if(selected.oClass == selected)
448 if(selected.classDefinition)
450 for(def = selected.classDefinition.definitions->first; def; def = def.next)
452 if(def.type == defaultPropertiesClassDef)
455 for(prop = def.defProperties->first; prop; prop = prop.next)
457 if(prop.identifiers && prop.identifiers->first)
459 Identifier id = prop.identifiers->first;
460 if(prop.variable && !strcmp(id.string, name))
472 else if(selected.instCode)
475 if(selected.instCode.members)
477 for(members = selected.instCode.members->first; members; members = members.next)
479 if(members.type == dataMembersInit && members.dataMembers)
482 for(prop = members.dataMembers->first; prop; prop = prop.next)
484 if(prop.identifiers && prop.identifiers->first)
486 Identifier id = prop.identifiers->first;
487 if(prop.variable && !strcmp(id.string, name))
502 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
507 method.dataType = ProcessTypeString(method.dataTypeString, false);
508 if(!method.dataType.thisClass && !isForm)
511 method.dataType.thisClass = selectedClass;
513 //result = MatchTypes(method.dataType, type, null, regClass, regClass, false);
514 result = MatchTypes(type, method.dataType, null, regClass, regClass, false, true, true, false);
516 method.dataType.thisClass = null;
520 bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo object)
522 bool confirmation = true;
523 Statement body = function.body;
524 // Check if it contains any code
525 if((!body.compound.declarations || !body.compound.declarations->count) && (!body.compound.statements || body.compound.statements->count <= 1))
527 Class moduleClass = eSystem_FindClass(object.instance._class.module, "Module");
528 Statement stmt = body.compound.statements ? body.compound.statements->first : null;
529 Type dataType = method.dataType;
530 Type returnType = dataType.returnType;
531 Expression exp = null;
534 method.dataType = ProcessTypeString(method.dataTypeString, false);
536 confirmation = false;
538 // Check if default function should be calling base class:
539 if(object.instance._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
541 if(returnType.kind != voidType)
543 if(!stmt || stmt.type != returnStmt || !stmt.expressions || stmt.expressions->count != 1)
547 exp = stmt.expressions->first;
548 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
550 if( (exp.type != identifierExp || strcmp(exp.identifier.string, "true")) &&
551 (exp.type != constantExp || strcmp(exp.constant, "1")))
556 if(exp.type != constantExp || strcmp(exp.constant, "0"))
571 if(returnType.kind != voidType)
573 if(stmt.type == returnStmt && stmt.expressions && stmt.expressions->count == 1)
574 exp = stmt.expressions->first;
576 else if(stmt.type == expressionStmt && stmt.expressions && stmt.expressions->count == 1)
577 exp = stmt.expressions->first;
580 if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
584 Identifier id = exp.call.exp.identifier;
585 Class base = object.instance._class;
586 if(!id._class || (id._class.name && !strcmp(id._class.name, base.name)) || strcmp(id.string, method.name))
590 Expression arg = exp.call.arguments ? exp.call.arguments->first : null;
591 if(!arg || arg.type != identifierExp || strcmp("this", arg.identifier.string))
597 for(param = dataType.params.first; param; param = param.next)
599 if(!arg || arg.type != identifierExp || strcmp(param.name, arg.identifier.string))
604 arg = arg ?arg.next : null;
611 return !confirmation;
614 class CodeEditor : Window
616 background = marginColor;
617 borderStyle = sizableDeep;
622 isActiveClient = true;
623 anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
626 // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
627 // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
629 SheetType sheetSelected;
634 Context globalContext { };
635 OldList excludedSymbols { offset = (uint)&((Symbol)0).left };
648 MethodAction methodAction;
650 ClassFunction function;
652 char methodName[1024];
657 bool membersListShown;
660 EditLine membersLine;
662 Type functionType, instanceType;
666 Point paramsPosition;
667 Expression functionExp;
670 BitmapResource icons[CodeObjectType];
672 FontResource boldFont { $"Tahoma", 8.25f, bold = true, window = this };
673 FontResource normalFont { $"Tahoma", 8.25f, window = this };
675 Module privateModule;
676 NameSpace globalData;
679 OpenedFileInfo openedFileInfo;
681 FontResource font { codeFont.faceName, codeFont.size };
682 saveDialog = codeEditorFileDialog;
684 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
688 property bool parsing { get { return editBox.syntaxHighlighting && !noParsing && !ide.noParsing; } };
690 void ProcessCaretMove(EditBox editBox, int line, int charPos)
693 ObjectInfo classItem;
695 // OnActivateClient is called after OnActivate
698 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
701 if(sheet.codeEditor != this) return;
705 for(classItem = classes.first; classItem; classItem = classItem.next)
707 ClassDefinition classDef = classItem.classDefinition;
708 if(classDef && classDef.loc.Inside(line, charPos))
715 for(object = classItem.instances.first; object; object = object.next)
719 if(object.instCode.loc.Inside(line, charPos))
724 sheet.SelectObject(object);
726 sheet.SelectObject(classItem);
731 //sheet.SelectObject(null);
735 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
739 expectingMove = false;
745 if(line-1 != membersLoc.start.line)
749 char * buffer = membersLine.text;
752 if(charPos - 1 < membersLoc.start.charPos)
754 else if(charPos - 1 > membersLoc.end.charPos)
756 char * buffer = membersLine.text;
757 //if(membersList.currentRow)
761 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
762 if(buffer[c] != ' ' && buffer[c] != '\t')
764 if(c < charPos && buffer[c])
771 membersList.Destroy(0);
772 membersListShown = false;
776 bool back = codeModified;
777 codeModified = false;
779 InvokeParameters(false, false, false);
780 /*if(membersListShown)
781 InvokeAutoComplete(false, 0, true);*/
788 watch(modifiedDocument)
790 ProjectView projectView = ide.projectView;
793 ProjectNode node = projectView.GetNodeFromWindow(this, null, false);
796 node.modified = modifiedDocument;
797 projectView.Update(null);
805 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
806 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
807 tabKey = true, smartHome = true;
808 tabSelection = true, /*maxLineSize = 65536, */parent = this, hasHorzScroll = true, hasVertScroll = true;
809 selectionColor = selectionColor, selectionText = selectionText,
810 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
811 font = font, borderStyle = none;
812 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
814 bool OnMouseOver(int x, int y, Modifiers mods)
816 CodeEditor editor = (CodeEditor)master;
817 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
822 void NotifyCaretMove(EditBox editBox, int line, int charPos)
824 // Update Line Numbers
826 int oldLine = lastLine;
827 display.FontExtent(font.font, " ", 1, null, &spaceH);
829 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
833 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
838 if(ide.activeClient == this)
839 ProcessCaretMove(editBox, line, charPos);
841 openedFileInfo.CaretMove(line, charPos);
844 void NotifyOvrToggle(EditBox editBox, bool overwrite)
846 ide.ovr.color = overwrite ? black : Color { 128, 128, 128 };
849 void NotifyUpdate(EditBox editBox)
856 designer.modifiedDocument = true;
859 modifiedDocument = true;
862 bool NotifyUnsetModified(EditBox editBox)
864 modifiedDocument = false;
868 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
870 if(!loadingFile && after.y != before.y)
872 ProjectView projectView = ide.projectView;
873 if(projectView && fileName)
876 // HOW WE MIGHT WANT TO DO IT:
877 char * text = before.line.text;
878 for(c = before.x-1; c>= 0; c--)
879 if(!isspace(text[c]))
881 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
883 // HOW VISUAL STUDIO DOES IT:
885 char * text = after.line.text;
886 for(c = after.line.count-1; c>= 0; c--)
887 if(!isspace(text[c]))
889 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
892 Update({ 0, 0, editBox.position.x, clientSize.h });
899 for(oClass = classes.first; oClass; oClass = oClass.next)
902 for(object = oClass.instances.first; object; object = object.next)
906 object.instCode.loc.start.AdjustAdd(before, after);
907 object.instCode.loc.end.AdjustAdd(before, after);
912 oClass.classDefinition.loc.start.AdjustAdd(before, after);
913 oClass.classDefinition.loc.end.AdjustAdd(before, after);
919 expectingMove = true;
923 if(before.y != after.y)
927 char * buffer = membersLine.text;
929 bool firstChar = true;
930 bool addedChar = false;
936 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
938 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
940 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
941 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
950 membersLoc.start.charPos++;
955 string[len++] = buffer[c];
959 row = membersList.currentRow;
960 if(row && row.selected)
964 membersLoc.start.charPos--;
972 row = membersList.FindSubString(string);
974 membersList.currentRow = row;
977 row = membersList.FindSubStringi(string);
979 membersList.currentRow = row;
980 membersList.currentRow.selected = false;
983 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
987 row = membersList.currentRow;
990 // Accept current string if hiding typing char
991 if(hide && row && row.selected)
993 char * string = row.string;
994 int len = strlen(string);
995 membersLoc.end.charPos -= after.x - before.x;
996 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
997 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
998 membersLine, membersLoc.end.line, membersLoc.end.charPos);
999 editBox.PutS(string);
1000 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
1002 after.x += membersLoc.start.charPos + len - before.x;
1003 before.x = membersLoc.start.charPos + len;
1008 membersList.Destroy(0);
1009 membersListShown = false;
1012 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
1014 EditLine line = editBox.line;
1015 char * text = line.text;
1016 char ch = text[after.x-1];
1017 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1021 // Can we call invoke auto complete here instead?
1031 // Force caret update already...
1032 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1033 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1035 editBox.GetCaretPosition(&caret);
1039 // Go back in the buffer until no space before
1041 codeModified = true;
1045 EditBoxStream f { editBox = editBox };
1049 if(text[after.x-1] == '>')
1055 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1059 if(!f.Seek(-1, current))
1062 if(!isspace(ch)) break;
1063 f.Seek(-1, current);
1065 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1067 line = editBox.lineNumber + 1;
1068 charPos = editBox.charPos + 1;
1072 exp = FindExpTree(ast, line, charPos);
1076 Type type = exp.expType;
1078 if(type && text[after.x-1] != '.')
1080 if(type.kind == TypePointer || type.kind == TypeArray)
1086 membersList.Clear();
1089 if(membersList.rowCount)
1091 membersList.Sort(null, 1);
1092 membersList.master = this;
1094 caret.y += editBox.GetCaretSize();
1097 membersList.Create();
1100 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1101 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1102 Window parent = membersList.parent;
1104 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1106 y -= editBox.GetCaretSize() + membersList.GetHeight();
1107 membersAbove = true;
1110 membersAbove = false;
1112 membersList.position = { x, y };
1116 membersLoc.start.line = line - 1;
1117 membersLoc.start.charPos = oldCharPos;
1118 membersLoc.end = membersLoc.start;
1119 membersListShown = true;
1124 SetCurrentContext(globalContext);
1126 codeModified = true;
1127 skipModified = true;
1128 if(text[after.x-1] == ':')
1129 InvokeAutoComplete(false, 0, false);
1130 else if(text[after.x-1] == '.')
1131 InvokeAutoComplete(false, 1, false);
1132 else if(text[after.x-1] == '>')
1133 InvokeAutoComplete(false, 2, false);
1134 skipModified = false;
1136 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1138 codeModified = true;
1139 skipModified = true;
1141 if(InvokeAutoComplete(true, 0, false))
1143 if(ch == '(' || ch == OpenBracket)
1144 InvokeParameters(true, true, false);
1146 InvokeParameters(this.functionType ? false : true, false, false);
1149 // InvokeAutoComplete(true, 0, false);
1150 skipModified = false;
1152 else if(ch == ')' || ch == '}' || ch == ';')
1154 codeModified = true;
1155 skipModified = true;
1157 InvokeParameters(false, true, false);
1158 skipModified = false;
1162 bool back = codeModified;
1163 codeModified = false;
1165 InvokeParameters(false, false, true);
1166 if(membersListShown)
1167 InvokeAutoComplete(false, 0, true);
1168 codeModified = back;
1173 bool back = codeModified;
1174 codeModified = false;
1177 InvokeParameters(false, false, true);
1178 /*if(membersListShown)
1179 InvokeAutoComplete(false, 0, true);*/
1181 codeModified = back;
1188 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1190 if(!loadingFile && after.y != before.y)
1192 ProjectView projectView = ide.projectView;
1193 if(projectView && fileName)
1194 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1195 Update({ 0, 0, editBox.position.x, clientSize.h });
1202 for(oClass = classes.first; oClass; oClass = oClass.next)
1206 for(object = oClass.instances.first; object; object = object.next)
1210 loc = &object.instCode.loc;
1212 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1213 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1215 object.instCode = null;
1219 loc->start.AdjustDelete(before, after);
1220 loc->end.AdjustDelete(before, after);
1224 if(oClass.classDefinition)
1226 loc = &oClass.classDefinition.loc;
1227 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1228 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1230 oClass.classDefinition = null;
1234 loc->start.AdjustDelete(before, after);
1235 loc->end.AdjustDelete(before, after);
1240 if(membersListShown)
1243 if(pasteOperation || before.y != after.y)
1247 char * buffer = membersLine.text;
1249 bool firstChar = true;
1253 if(before.x >= membersLoc.start.charPos)
1255 for(c = membersLoc.start.charPos; c<before.x && len < sizeof(string)-1; c++)
1257 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1258 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1263 if(!isSpace) firstChar = false;
1266 string[len++] = buffer[c];
1271 // If deleting spaces before...
1272 for(c = before.x; c<membersLoc.start.charPos; c++)
1274 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1282 membersLoc.start.charPos = before.x;
1285 if(membersLoc.end.charPos >= after.x)
1287 for(c = after.x; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1289 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1290 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1295 if(!isSpace) firstChar = false;
1298 string[len++] = buffer[c];
1306 membersLoc.end.charPos -= after.x - before.x;
1310 row = membersList.FindSubString(string);
1313 row = membersList.FindSubStringi(string);
1315 membersList.currentRow = row;
1316 membersList.currentRow.selected = false;
1319 membersList.currentRow = row;
1321 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1326 membersList.Destroy(0);
1327 membersListShown = false;
1333 InvokeParameters(false, false);
1341 bool NotifyDropped(EditBox editBox, int x, int y)
1343 char * controlClass = toolBox.controlClass;
1344 if(controlClass && controlClass[0])
1348 ObjectInfo classObject;
1350 //editBox.NotifyCaretMove(this, editBox, y, x);
1351 editBox.GoToLineNum(y);
1352 editBox.GoToPosition(editBox.line, y, x);
1354 classObject = selected ? selected.oClass : null;
1356 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1357 selected = classObject.instances.last;
1360 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1363 AddObject(control, &object);
1365 designer.CreateObject(control, object, false, classObject.instance);
1366 // designer.PostCreateObject(control, object, false, classObject.instance);
1367 designer.DroppedObject(control, object, false, classObject.instance);
1369 sheet.AddObject(object, object.name, typeData /* className*/, true);
1372 //codeModified = true;
1379 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1381 if(key == Key { space, ctrl = true })
1383 membersList.Destroy(0);
1384 membersListShown = false;
1385 InvokeAutoComplete(false, 0, false);
1388 else if(key == Key { space, ctrl = true, shift = true })
1389 InvokeParameters(false, true, false);
1390 else if(key == escape)
1391 ide.RepositionWindows(true);
1392 else if(key == ctrlF7)
1396 ProjectNode node = ide.projectView.GetNodeFromWindow(this, null, false);
1398 node = ide.projectView.GetNodeFromWindow(this, null, true);
1402 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1403 $"It can't be compiled.");
1404 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1413 bool OnKeyDown(Key key, unichar ch)
1415 CodeEditor editor = (CodeEditor)master;
1416 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1418 if(editor.membersListShown)
1420 editor.membersList.Destroy(0);
1421 editor.membersListShown = false;
1424 if(editor.paramsShown)
1426 editor.paramsList.Destroy(0);
1427 editor.paramsShown = false;
1428 FreeType(editor.functionType);
1429 FreeType(editor.instanceType);
1431 editor.functionType = null;
1432 editor.instanceType = null;
1433 editor.paramsID = -1;
1437 return EditBox::OnKeyDown(key, ch);
1440 void OnVScroll(ScrollBarAction action, int position, Key key)
1442 if(anchor.left.distance)
1444 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1447 EditBox::OnVScroll(action, position, key);
1449 CodeEditor ce = (CodeEditor)parent;
1450 if(ce.openedFileInfo)
1451 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1455 void OnHScroll(ScrollBarAction action, int position, Key key)
1457 EditBox::OnHScroll(action, position, key);
1459 CodeEditor ce = (CodeEditor)parent;
1460 if(ce.openedFileInfo)
1461 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1468 fullRowSelect = false,
1471 borderStyle = bevel;
1472 // size = { 200, 400 };
1474 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1476 DataRow row = listBox.currentRow;
1479 char * string = row.string;
1481 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1483 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1484 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1485 editBox.PutS(string);
1488 membersListShown = false;
1493 bool OnKeyDown(Key key, unichar ch)
1495 CodeEditor editor = (CodeEditor) master;
1496 if(key == escape || key == leftAlt || key == rightAlt ||
1497 (key.ctrl && key.code != left && key.code != right &&
1498 key.code != leftShift && key.code != rightShift && key.code != space))
1500 if(editor.paramsShown)
1501 editor.paramsList.Destroy(0);
1502 if(editor.membersListShown)
1503 editor.membersList.Destroy(0);
1505 editor.paramsShown = false;
1506 FreeType(editor.functionType);
1507 FreeType(editor.instanceType);
1509 editor.functionType = null;
1510 editor.instanceType = null;
1511 editor.paramsID = -1;
1513 editor.membersListShown = false;
1517 return editor.editBox.OnKeyDown(key, ch);
1521 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1523 CodeEditor editor = (CodeEditor)master;
1527 editor.membersListShown = false;
1529 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1532 bool OnKeyHit(Key key, unichar ch)
1534 CodeEditor editor = (CodeEditor) master;
1538 case enter: case tab:
1540 DataRow row = currentRow;
1541 if(row && row.selected)
1543 char * string = row.string;
1545 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1546 editor.editBox.Delete(
1547 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1548 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1549 editor.editBox.PutS(string);
1552 editor.membersListShown = false;
1555 editor.editBox.OnKeyHit(key, ch);
1565 return ListBox::OnKeyHit(key, ch);
1571 // If before . or after
1572 //listBox.Destroy(true);
1573 result = editor.editBox.OnKeyHit(key, ch);
1588 clickThrough = true,
1590 borderStyle = contour,
1592 background = { 255,255,225 },
1594 OnKeyDown = membersList.OnKeyDown;
1596 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1598 CodeEditor editor = (CodeEditor)master;
1602 editor.membersListShown = false;
1604 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1607 bool OnKeyHit(Key key, unichar ch)
1609 CodeEditor editor = (CodeEditor)master;
1611 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1614 bool result = true; editor.editBox.OnKeyHit(key, ch);
1615 return (!created) ? false : result;
1622 void OnRedraw(Surface surface)
1624 CodeEditor editor = (CodeEditor) master;
1625 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1627 Type methodType = null;
1631 int functionW, nameW = 0;
1633 int spaceW, spaceH, commaW, commaWB, parW;
1635 int maxW = 0, lineW = 0;
1641 Font font = editor.normalFont.font;
1642 Font boldFont = editor.boldFont.font;
1643 Display display = this.display;
1645 if(!type) { return; };
1647 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1649 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1650 display.FontExtent(font, ", ", 2, &commaW, null);
1651 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1652 display.FontExtent(font, ")", 1, &parW, null);
1655 if(editor.functionType)
1657 PrintType(type.returnType, string, true, true);
1658 display.FontExtent(font, string, strlen(string), &functionW, null);
1660 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1661 totalW = nameW + functionW + 2 * parW;
1665 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1666 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1667 if(instanceName && type.kind != functionType)
1668 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1669 totalW = functionW + nameW;
1670 surface.TextFont(boldFont);
1673 surface.WriteText(x, y, string, strlen(string));
1674 x += functionW + spaceW;
1676 if(editor.functionType)
1679 surface.WriteText(x, y, type.name, strlen(type.name));
1681 surface.WriteText(x, y, "(", 1);
1684 if(methodType && !methodType.staticMethod && methodType.methodClass)
1688 if(id == editor.paramsID)
1689 surface.TextFont(boldFont);
1691 if(methodType.methodClass)
1692 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1696 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1697 width += ((id == editor.paramsID) ? commaWB : commaW);
1702 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1707 x = 2 + nameW + spaceW + functionW + parW;
1711 if(methodType.methodClass)
1712 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1715 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1717 surface.WriteText(x, y, ",", 1);
1718 x += ((id == editor.paramsID) ? commaWB : commaW);
1726 if(id == editor.paramsID)
1727 surface.TextFont(font);
1731 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1733 for(param = type.params.first; param; param = param.next)
1735 char paramString[1024];
1738 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1739 surface.TextFont(boldFont);
1742 PrintType(param, paramString, true, true);
1743 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1745 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1750 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1755 x = 2 + nameW + spaceW + functionW + parW;
1759 surface.WriteText(x, y, paramString, strlen(paramString));
1763 surface.WriteText(x, y, ",", 1);
1764 x += ((id == editor.paramsID) ? commaWB : commaW);
1772 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1773 surface.TextFont(font);
1778 surface.WriteText(x, y, ")", 1);
1780 else if(instanceName && type.kind != functionType)
1782 surface.WriteText(x, y, instanceName, strlen(instanceName));
1786 bool OnResizing(int * w, int * h)
1788 CodeEditor editor = (CodeEditor) master;
1789 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1791 Type methodType = null;
1795 int functionW = 0, nameW = 0;
1797 int spaceW, spaceH, commaW, commaWB, parW;
1799 int maxW = 0, lineW = 0;
1804 Font font = editor.normalFont.font;
1805 Font boldFont = editor.boldFont.font;
1806 Display display = this.display;
1808 if(type.kind == TypeKind::methodType)
1811 ProcessMethodType(type.method);
1812 type = type.method.dataType;
1815 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1816 display.FontExtent(font, ", ", 2, &commaW, null);
1817 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1818 display.FontExtent(font, ")", 1, &parW, null);
1821 if(editor.functionType && type)
1823 PrintType(type.returnType, string, true, true);
1824 display.FontExtent(font, string, strlen(string), &functionW, null);
1826 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1827 totalW = nameW + spaceW + functionW + 2 * parW;
1831 PrintType(type, string, false, true); // /*true);
1832 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1833 if(instanceName && type.kind != functionType)
1834 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1835 totalW = functionW + nameW + spaceW;
1838 if(editor.functionType)
1844 if(methodType.methodClass)
1845 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1846 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1847 width += ((id == editor.paramsID) ? commaWB : commaW);
1852 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1865 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1867 for(param = type.params.first; param; param = param.next)
1869 char paramString[1024];
1873 PrintType(param, paramString, true, true);
1874 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1876 width += ((id == editor.paramsID) ? commaWB : commaW);
1881 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1898 *w = realW + totalW + 4;
1904 Menu fileMenu { menu, $"File", f }; // MenuPlacement?
1905 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1906 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1908 Menu debugMenu { menu, $"Debug", d }; // MenuPlacement?
1909 MenuItem debugRunToCursor
1911 debugMenu, $"Run To Cursor", c, Key { f10, ctrl = true };
1912 bool NotifySelect(MenuItem selection, Modifiers mods)
1914 ProjectView projectView = ide.projectView;
1915 if(!projectView.buildInProgress)
1917 int line = editBox.lineNumber + 1;
1920 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1921 ProjectConfig config = projectView.project.config;
1922 int bitDepth = ide.workspace.bitDepth;
1923 ide.debugger.RunToCursor(compiler, config, bitDepth, fileName, line, false, false);
1930 MenuItem debugSkipRunToCursor
1932 debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true };
1933 bool NotifySelect(MenuItem selection, Modifiers mods)
1935 ProjectView projectView = ide.projectView;
1936 int line = editBox.lineNumber + 1;
1939 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1940 ProjectConfig config = projectView.project.config;
1941 int bitDepth = ide.workspace.bitDepth;
1942 ide.debugger.RunToCursor(compiler, config, bitDepth, fileName, line, true, false);
1948 MenuItem debugSkipRunToCursorAtSameLevel
1950 debugMenu, $"Run To Cursor At Same Level Skipping Breakpoints", u, Key { f10, alt = true };
1951 bool NotifySelect(MenuItem selection, Modifiers mods)
1953 ProjectView projectView = ide.projectView;
1954 int line = editBox.lineNumber + 1;
1957 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1958 ProjectConfig config = projectView.project.config;
1959 int bitDepth = ide.workspace.bitDepth;
1960 ide.debugger.RunToCursor(compiler, config, bitDepth, fileName, line, true, true);
1966 MenuDivider { debugMenu };
1967 MenuItem debugToggleBreakpoint
1969 debugMenu, $"Toggle Breakpoint", t, f9;
1970 bool NotifySelect(MenuItem selection, Modifiers mods)
1972 ProjectView projectView = ide.projectView;
1973 if(projectView && fileName)
1975 int line = editBox.lineNumber + 1;
1976 char name[MAX_LOCATION];
1978 // TOFIX: This only looks at the filename...
1979 GetLastDirectory(fileName, name);
1980 if(ide && ide.workspace)
1982 for(p : ide.workspace.projects)
1984 if(p.topNode.Find(name, false))
1992 for(p : ide.workspace.projects)
1994 if(IsPathInsideOf(fileName, p.topNode.path))
2002 ide.debugger.ToggleBreakpoint(fileName, line, prj);
2012 //MenuItem viewDesignerItem, viewProperties, viewMethods;
2016 designer.parent = parent;
2019 toolBox = ((IDEWorkSpace)master).toolBox;
2021 // Debugger bug here: value of toolBox appears as 0
2023 sheet = ((IDEWorkSpace)master).sheet;
2028 bool OnClose(bool parentClosing)
2032 if(ide.workspace && fileName)
2033 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2034 if(inUseDebug && !debugClosing)
2036 debugClosing = true;
2038 if(CloseConfirmation(false))
2041 OnFileModified({ modified = true }, null);
2043 debugClosing = false;
2046 if(designer && !designer.closing)
2048 if(designer.visible)
2055 //Window formEditor = designer;
2056 //formEditor.Destroy(0);
2059 ide.AdjustFileMenus();
2064 void OnDestroy(void)
2066 ObjectInfo oClass, next;
2067 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2069 FreeType(this.functionType);
2070 FreeType(this.instanceType);
2075 designer.codeEditor = null;
2076 designer.Destroy(0);
2080 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2082 ObjectInfo object, next;
2084 for(object = oClass.instances.first; object; object = next)
2089 Designer::DestroyObject(object.instance);
2090 delete object.instance;
2092 sheet.DeleteObject(object);
2094 oClass.instances.Delete(object);
2098 Designer::DestroyObject(oClass.instance);
2099 delete oClass.instance;
2101 sheet.DeleteObject(oClass);
2103 classes.Delete(oClass);
2106 if(windowClass && windowClass.data)
2107 UnapplySkin(windowClass);
2111 if(sheet.codeEditor == this)
2113 sheet.codeEditor = null;
2114 toolBox.codeEditor = null;
2120 ProjectView projectView = ide.projectView;
2123 ProjectNode node = projectView.GetNodeFromWindow(this, null, false);
2124 if(node && node.modified)
2126 node.modified = false;
2127 projectView.Update(null);
2133 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2135 // 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
2137 if(directActivation)
2138 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2140 if(active && directActivation)
2142 AdjustDebugMenus(ide.areDebugMenusUnavailable, ide.isBreakpointTogglingUnavailable, ide.isDebuggerExecuting);
2144 openedFileInfo.Activate();
2148 Location * loc = null;
2149 UpdateFormCode(); // To ensure update when modifying properties...
2151 // Got to the right spot in code so we don't lose our form selection...
2154 if(selected.instCode)
2155 loc = &selected.instCode.loc;
2156 else if(selected.classDefinition)
2157 loc = &selected.classDefinition.loc;
2159 line = editBox.lineNumber + 1;
2160 charPos = editBox.charPos + 1;
2165 if(selected && !loc->Inside(line, charPos))
2167 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2168 line = editBox.lineNumber + 1;
2169 charPos = editBox.charPos + 1;
2171 else if(selected && selected.classDefinition)
2174 for(object = selected.instances.first; object; object = object.next)
2178 if(object.instCode.loc.Inside(line, charPos))
2184 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2185 line = editBox.lineNumber + 1;
2186 charPos = editBox.charPos + 1;
2191 ProcessCaretMove(editBox, line, charPos);
2197 bool OnSaveFile(char * fileName)
2204 f = FileOpen(fileName, write);
2207 if(!ide.projectView)
2208 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2212 this.fileName = fileName; // Put this here because the form designer will check for it...
2213 designer.fileName = fileName;
2214 designer.modifiedDocument = false;
2216 editBox.Save(f, false);
2217 modifiedDocument = false;
2225 bool OnFileModified(FileChange fileChange, char * param)
2227 bool reload = false;
2228 if(visible == false && inUseDebug == true)
2234 sprintf(message, $"The document %s was modified by another application.\n"
2235 "Would you like to reload it and lose your changes?", fileName);
2236 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2237 contents = message }.Modal() == yes)
2243 File f = FileOpen(fileName, read);
2246 int lineNumber, charPos, len;
2250 updatingCode = true;
2251 lineNumber = editBox.lineNumber;
2252 charPos = editBox.charPos;
2253 scroll = editBox.scroll;
2256 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2257 len = strlen(editBox.line.text);
2258 editBox.GoToLineNum(lineNumber);
2259 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2260 editBox.scroll = scroll;
2261 updatingCode = false;
2262 loadingFile = false;
2264 codeModified = true;
2268 designer.modifiedDocument = false;
2270 modifiedDocument = false;
2278 void OnRedraw(Surface surface)
2281 surface.SetBackground(marginColor);
2282 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2283 if(ideSettings.showLineNumbers)
2285 int currentLineNumber;
2290 surface.textOpacity = false;
2291 surface.font = font.font;
2292 surface.TextExtent(" ", 1, null, &spaceH);
2293 currentLineNumber = editBox.scroll.y / spaceH + 1;
2295 surface.SetForeground(lineNumbersColor);
2296 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2298 // Highlight current line
2299 if(editBox.lineNumber == currentLineNumber - 1)
2301 surface.SetBackground(selectedMarginColor);
2302 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2303 surface.SetBackground(marginColor);
2305 sprintf(lineText,"%5u ", currentLineNumber % 100000);
2306 if(currentLineNumber <= editBox.numLines)
2307 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,6);
2309 currentLineNumber++;
2313 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2315 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2316 int lineCursor, lineTopFrame, breakpointLines[128];
2317 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2318 Debugger debugger = ide.debugger;
2319 BitmapResource bmpRes;
2321 boxH = clientSize.h;
2322 scrollY = editBox.scroll.y;
2323 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2325 bpOnCursor = bpOnTopFrame = false;
2326 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2329 for(i = 0; i < count; i++)
2331 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2333 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2334 if(breakpointLines[i] == lineCursor)
2336 if(breakpointLines[i] == lineTopFrame)
2337 bpOnTopFrame = true;
2340 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2342 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2345 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2346 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2347 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2349 if(editBox.anchor.left.distance)
2351 if(editBox.horzScroll && editBox.horzScroll.visible)
2353 surface.SetBackground(control);
2354 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2359 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2364 lineY = (line - 1) * lineH;
2365 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2367 Bitmap bitmap = resource.bitmap;
2369 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2376 char ext[MAX_EXTENSION];
2377 char * fileName = property::fileName;
2379 if(SearchString(fileName, 0, "Makefile", false, true))
2380 editBox.useTab = true;
2381 designer.fileName = fileName;
2385 GetExtension(fileName, ext);
2387 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2388 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2389 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2390 editBox.syntaxHighlighting = true;
2392 editBox.syntaxHighlighting = false;
2394 if(parsing && !strcmpi(ext, "ec"))
2396 codeModified = true;
2402 display.FontExtent(font.font, " ", 1, &spaceW, null);
2403 editBox.anchor = Anchor
2405 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2406 right = 0, top = 0, bottom = 0
2415 display.FontExtent(font.font, " ", 1, &spaceW, null);
2416 editBox.anchor = Anchor
2418 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2419 right = 0, top = 0, bottom = 0
2424 bool LoadFile(char * filePath)
2426 File f = FileOpen(filePath, read);
2429 // Added this here...
2430 fileName = filePath;
2432 updatingCode = true;
2434 updatingCode = false;
2435 loadingFile = false;
2444 void AdjustDebugMenus(bool unavailable, bool bpNoToggle, bool executing)
2446 debugRunToCursor.disabled = unavailable || executing;
2447 debugSkipRunToCursor.disabled = unavailable || executing;
2448 debugSkipRunToCursorAtSameLevel.disabled = unavailable || executing;
2449 debugToggleBreakpoint.disabled = bpNoToggle;
2455 ProjectView projectView = ide.projectView;
2458 designer.fileName = fileName;
2464 sprintf(title, $"Untitled %d", documentID);
2465 // designer.fileName = CopyString(title);
2466 designer.fileName = title;
2469 AdjustDebugMenus(ide.areDebugMenusUnavailable, ide.isBreakpointTogglingUnavailable, ide.isDebuggerExecuting);
2471 for(c = 0; c < CodeObjectType::enumSize; c++)
2472 icons[c] = BitmapResource { iconNames[c], window = this };
2474 codeModified = true;
2486 selected.modified = true;
2487 selected.oClass.modified = true;
2489 designer.modifiedDocument = true;
2490 modifiedDocument = true;
2491 formModified = true;
2494 /****************************************************************************
2496 ****************************************************************************/
2504 this.defines.Free(FreeModuleDefine);
2505 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2507 FreeExcludedSymbols(this.excludedSymbols);
2508 FreeContext(this.globalContext);
2510 FreeGlobalData(&this.globalData);
2511 FindCtx_Terminate();
2512 FindParams_Terminate();
2514 if(GetGlobalContext() == globalContext)
2516 SetGlobalData(null);
2517 SetGlobalContext(null);
2518 SetExcludedSymbols(null);
2519 SetTopContext(null);
2520 SetCurrentContext(null);
2523 SetPrivateModule(null);
2526 if(this.privateModule)
2528 FreeTypeData(this.privateModule);
2529 delete this.privateModule;
2530 this.privateModule = null;
2536 static bool reentrant = false;
2541 char * selectedClassName = null, * selectedName = null;
2542 int selectedPos = 0;
2543 Designer backDesigner;
2544 char oldWorkDir[MAX_LOCATION];
2545 char mainModuleName[MAX_FILENAME] = "";
2547 ImportedModule module;
2548 char extension[MAX_EXTENSION];
2549 PathBackup pathBackup { };
2551 Time parseCodeStart = GetTime();
2552 Time startTime, startFindClass;
2554 findClassTotalTime = 0;
2555 checkTypeTotalTime = 0;
2556 externalImportTotalTime = 0;
2557 findClassIgnoreNSTotalTime = 0;
2558 findSymbolTotalTime = 0;
2559 //ResetClassFindTime();
2563 // 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)
2564 if(reentrant) return;
2571 selectedClassName = CopyString(oClass.name);
2572 if(selected != oClass)
2574 ObjectInfo object = this.selected;
2575 selectedName = CopyString(object.name);
2579 for(check = this.oClass.instances.first; check; check = check.next)
2591 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2593 FindCtx_Terminate();
2594 FindParams_Terminate();
2596 SetGlobalData(&globalData);
2597 SetGlobalContext(globalContext);
2598 SetExcludedSymbols(&excludedSymbols);
2599 SetTopContext(globalContext);
2600 SetCurrentContext(globalContext);
2601 SetDefines(&defines);
2602 SetImports(&imports);
2603 SetCurrentNameSpace(null);
2606 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2607 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2608 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2609 "/I T:\\ecere\\include /E %s", argv[1]);
2613 ChangeWorkingDir("e:\\ec");
2614 sprintf(command, "gcc -x c -E -");
2615 fileInput = DualPipeOpen({ output = true, input = true }, command);
2616 SetFileInput(fileInput);
2621 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2623 fileInput.Write(buffer, 1, count);
2628 fileInput.CloseOutput();
2632 // TOCHECK: COULDN'T WE CALL FreeParser here?
2634 FreeType(this.functionType);
2635 FreeType(this.instanceType);
2636 this.functionType = null;
2637 this.instanceType = null;
2640 sheet.SelectObject(null);
2646 // We don't want the designer to be notified of selection when deleting rows...
2647 backDesigner = designer;
2652 ObjectInfo _class, next;
2654 for(_class = classes.first; _class; _class = next)
2660 for(;object = _class.instances.first;)
2664 Designer::DestroyObject(object.instance);
2665 delete object.instance;
2667 sheet.DeleteObject(object);
2669 _class.instances.Delete(object);
2673 Designer::DestroyObject(_class.instance);
2674 delete _class.instance;
2676 sheet.DeleteObject(_class);
2678 classes.Delete(_class);
2684 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2685 if(windowClass && windowClass.data)
2686 UnapplySkin(windowClass);
2689 designer = backDesigner;
2692 fileInput = editFile = EditBoxStream { editBox = editBox };
2693 SetFileInput(fileInput);
2701 defines.Free(FreeModuleDefine);
2702 imports.Free(FreeModuleImport);
2704 FreeContext(this.globalContext);
2705 FreeExcludedSymbols(this.excludedSymbols);
2708 FreeGlobalData(&this.globalData);
2710 if(this.privateModule)
2712 FreeTypeData(this.privateModule);
2713 delete this.privateModule;
2717 startTime = GetTime();
2718 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2720 printf("classes.count: %d\n", globalContext.classes.count);
2725 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2726 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2729 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2731 SetPrivateModule(privateModule);
2734 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2735 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2736 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2737 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2738 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2741 fileName = this.fileName;
2743 if(ide.workspace && ide.workspace.projects && fileName)
2745 for(p : ide.workspace.projects)
2747 char path[MAX_LOCATION];
2749 MakePathRelative(fileName, p.topNode.path, path);
2750 MakeSlashPath(path);
2752 pn = p.topNode.FindWithPath(path, false);
2761 project = ide.project;
2763 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2765 ChangeWorkingDir(project.topNode.path);
2767 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2769 GetLastDirectory(fileName, mainModuleName);
2770 GetExtension(mainModuleName, extension);
2772 SetBuildingEcereCom(false);
2773 SetBuildingEcereComModule(false);
2775 // TODO: Get symbolsDir from project settings instead...
2778 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2779 ProjectConfig config = project.config;
2780 int bitDepth = ide.workspace.bitDepth;
2781 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2782 SetSymbolsDir(objDir.dir);
2783 ide.SetPath(true, compiler, config, bitDepth);
2787 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2788 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2792 switch(GetRuntimePlatform())
2794 case win32: SetSymbolsDir("obj/debug.win32"); break;
2795 case tux: SetSymbolsDir("obj/debug.linux"); break;
2796 case apple: SetSymbolsDir("obj/debug.apple"); break;
2798 SetIncludeDirs(null);
2799 SetSysIncludeDirs(null);
2803 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2805 // TODO FIX for configless project
2806 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2808 for(item : ide.project.config.options.preprocessorDefinitions)
2810 if(!strcmp(item, "BUILDING_ECERE_COM"))
2812 SetBuildingEcereCom(true);
2819 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2820 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2821 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2822 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2823 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2824 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2825 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2826 strcmpi(mainModuleName, "Mutex.ec")))
2828 SetBuildingEcereComModule(true);
2831 // Predeclare all classes
2833 char symFile[MAX_FILENAME];
2834 char symLocation[MAX_LOCATION];
2835 ImportedModule module, next;
2837 GetLastDirectory(fileName, symFile);
2838 ChangeExtension(symFile, "sym", symFile);
2840 strcpy(symLocation, GetSymbolsDir());
2841 PathCat(symLocation, symFile);
2843 // if(!GetEcereImported() && !GetBuildingEcereCom())
2844 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2847 startTime = GetTime();
2849 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2851 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2856 startTime = GetTime();
2858 // LoadSymbols(symLocation, normalImport, true);
2859 LoadSymbols(symLocation, preDeclImport, false);
2861 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2864 for(module = defines.first; module; module = next)
2867 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2870 defines.Delete(module);
2875 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2877 SetDefaultDeclMode(privateAccess);
2878 SetDeclMode(privateAccess);
2882 SetDefaultDeclMode(defaultAccess);
2883 SetDeclMode(defaultAccess);
2886 StripExtension(mainModuleName);
2887 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2888 defines.AddName(module);
2891 // SetYydebug(true);
2896 startTime = GetTime();
2897 startFindClass = checkTypeTotalTime;
2901 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2903 CheckDataRedefinitions();
2906 SetIncludeDirs(null);
2907 SetSysIncludeDirs(null);
2918 startTime = GetTime();
2920 PrePreProcessClassDefinitions();
2921 ComputeModuleClasses(privateModule);
2922 PreProcessClassDefinitions();
2923 ProcessClassDefinitions();
2925 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2926 startTime = GetTime();
2931 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2932 startTime = GetTime();
2934 ProcessInstantiations();
2936 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2939 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2941 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2942 if(!windowClass || windowClass.internalDecl)
2945 startTime = GetTime();
2947 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2948 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2949 eModule_Load(this.privateModule, "ecere", privateAccess);
2951 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2954 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2956 if(windowClass && windowClass.data)
2957 ApplySkin(windowClass, app.currentSkin.name, null);
2961 startTime = GetTime();
2963 for(external = ast->first; external; external = external.next)
2965 if(external.type == classExternal)
2967 ClassDefinition _class = external._class;
2968 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2970 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2973 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2975 Instance instance = eInstance_New(regClass);
2976 ObjectInfo classObject
2978 name = CopyString(_class._class.name);
2979 instance = instance;
2980 classDefinition = _class;
2981 oClass = classObject;
2984 classes.Add(classObject);
2988 // Moved this at bottom so that the file dialog doesn't show up in eCom
2989 designer.CreateObject(instance, classObject, true, null);
2990 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
2992 if(_class.definitions)
2996 for(def = _class.definitions->first; def; def = def.next)
3000 case defaultPropertiesClassDef:
3003 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3005 Identifier id = propDef.identifiers->first;
3008 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3011 Class propertyClass = prop.dataTypeClass;
3013 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3014 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3016 FreeType(propDef.initializer.exp.destType);
3017 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3018 ProcessExpressionType(propDef.initializer.exp);
3020 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
3022 Expression computed = CopyExpression(propDef.initializer.exp);
3023 ComputeExpression(computed);
3025 if(computed.isConstant && computed.type == instanceExp && !id.next)
3029 if(computed.instance._class && computed.instance._class.symbol &&
3030 computed.instance._class.symbol.registered &&
3031 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3033 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3035 // This was saved in the control and shouldn't be freed by FreeExpression...
3036 if(propertyClass.type == normalClass)
3037 computed.instance.data = null;
3041 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3042 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3044 String temp = new char[strlen(computed.string)+1];
3045 ReadString(temp, computed.string);
3046 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3050 propDef.variable = true;
3052 FreeExpression(computed);
3056 Expression computed = CopyExpression(propDef.initializer.exp);
3057 ComputeExpression(computed);
3058 if(computed.isConstant)
3060 //if(computed.type == memberExp) computed = computed.member.exp;
3062 if(computed.type == constantExp)
3064 Operand value = GetOperand(computed);
3065 DataValue valueData;
3066 valueData.i64 = value.i64;
3067 SetProperty(prop, instance, valueData);
3069 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3071 String temp = new char[strlen(computed.string)+1];
3072 ReadString(temp, computed.string);
3073 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3078 propDef.variable = true;
3080 FreeExpression(computed);
3084 propDef.variable = true;
3088 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3089 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3090 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3093 // Maintain a list in FunctionDefinition of who is attached to it
3094 for(def = _class.definitions->first; def; def = def.next)
3096 if(def.type == functionClassDef)
3098 ClassFunction function = def.function;
3099 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3101 function.attached.Add(OldLink { data = method });
3111 case declarationClassDef:
3113 Declaration decl = def.decl;
3116 case instDeclaration:
3118 Instantiation inst = decl.inst;
3119 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3120 if(instClass && eClass_GetDesigner(instClass))
3122 Instance control = eInstance_New(instClass);
3127 oClass = classObject;
3131 classObject.instances.Add(object);
3133 // TOCHECK: Why is this needed now?
3134 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3135 def.object = object;
3137 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3139 designer.CreateObject(control, object, false, classObject.instance);
3140 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3150 // Second pass, process instantiation members
3152 for(def = _class.definitions->first; def; def = def.next)
3156 case declarationClassDef:
3158 Declaration decl = def.decl;
3161 case instDeclaration:
3163 Instantiation inst = decl.inst;
3164 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3165 if(instClass && eClass_GetDesigner(instClass))
3168 object = object ? object.next : classObject.instances.first;
3169 control = object.instance;
3173 MembersInit members;
3174 for(members = inst.members->first; members; members = members.next)
3176 switch(members.type)
3178 case dataMembersInit:
3180 if(members.dataMembers)
3183 DataMember curMember = null;
3184 Class curClass = null;
3185 DataMember subMemberStack[256];
3186 int subMemberStackPos = 0;
3188 for(member = members.dataMembers->first; member; member = member.next)
3191 Identifier ident = member.identifiers ? member.identifiers->first : null;
3194 DataMember _subMemberStack[256];
3195 int _subMemberStackPos = 0;
3196 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3200 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3202 if(thisMember && thisMember.memberAccess == publicAccess)
3204 curMember = thisMember;
3205 curClass = curMember._class;
3206 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3207 subMemberStackPos = _subMemberStackPos;
3213 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3214 if(curMember) found = true;
3216 if(found && curMember.isProperty)
3218 Property prop = (Property) curMember;
3219 Class propertyClass = prop.dataTypeClass;
3221 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3223 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3225 FreeType(member.initializer.exp.destType);
3226 member.initializer.exp.destType = MkClassType(propertyClass.name);
3229 ProcessExpressionType(member.initializer.exp);
3231 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3233 Expression computed;
3235 /*char debugExpString[4096];
3236 debugExpString[0] = '\0';
3237 PrintExpression(member.initializer.exp, debugExpString);*/
3239 computed = CopyExpression(member.initializer.exp);
3242 ComputeExpression(computed);
3244 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3246 if(computed.instance.data)
3248 if(computed.instance._class && computed.instance._class.symbol &&
3249 computed.instance._class.symbol.registered &&
3250 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3252 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3254 // This was saved in the control and shouldn't be freed by FreeExpression...
3255 if(propertyClass.type == normalClass)
3256 computed.instance.data = null;
3260 else if(computed.type == identifierExp)
3262 member.variable = true;
3264 if(eClass_GetDesigner(propertyClass))
3267 char * name = computed.identifier.string;
3268 if(!strcmp(name, "this"))
3271 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3272 member.variable = false;
3277 for(check = classObject.instances.first; check; check = check.next)
3278 if(check.name && !strcmp(name, check.name))
3281 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3282 member.variable = false;
3288 else if(computed.type == memberExp)
3290 member.variable = true;
3291 if(computed.member.exp.type == identifierExp)
3293 char * name = computed.member.exp.identifier.string;
3294 if(!strcmp(name, "this"))
3296 char * name = computed.member.member.string;
3299 for(check = classObject.instances.first; check; check = check.next)
3300 if(check.name && !strcmp(name, check.name))
3303 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3304 member.variable = false;
3312 for(check = classObject.instances.first; check; check = check.next)
3314 if(check.name && !strcmp(name, check.name))
3316 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3319 DataValue value { };
3320 GetProperty(getProperty, check.instance, &value);
3321 SetProperty(prop, control, value);
3322 member.variable = false;
3330 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3331 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3333 String temp = new char[strlen(computed.string)+1];
3334 ReadString(temp, computed.string);
3335 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3339 member.variable = true;
3341 FreeExpression(computed);
3346 Expression computed = CopyExpression(member.initializer.exp);
3349 ComputeExpression(computed);
3350 if(computed.isConstant)
3352 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3354 if(!strcmp(propertyClass.dataTypeString, "float"))
3355 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3356 else if(!strcmp(propertyClass.dataTypeString, "double"))
3357 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3359 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3361 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3363 String temp = new char[strlen(computed.string)+1];
3364 ReadString(temp, computed.string);
3365 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3370 member.variable = true;
3372 FreeExpression(computed);
3378 member.variable = true;
3380 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3381 member.initializer.exp.type == memberExp) // identifierExp
3383 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3384 if(method && method.type == virtualMethod)
3387 // Maintain a list in FunctionDefinition of who is attached to it
3388 for(def = _class.definitions->first; def; def = def.next)
3390 if(def.type == functionClassDef)
3392 ClassFunction function = def.function;
3393 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3394 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3396 function.attached.Add(OldLink { data = method });
3397 // Reference this particular instance?
3412 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3423 //designer.CreateObject(instance, classObject, true, null);
3424 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3426 designer.PostCreateObject(instance, classObject, true, null);
3428 //instance.state = Hidden;
3429 //instance.Create();
3430 //instance.SetState(Normal, true, 0);
3439 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3443 // Restore Selection
3444 if(selectedClassName)
3447 for(oClass = classes.first; oClass; oClass = oClass.next)
3449 if(!strcmp(oClass.name, selectedClassName))
3451 this.oClass = oClass;
3455 delete selectedClassName;
3464 for(check = this.oClass.instances.first; check; check = check.next)
3466 if(check.name && !strcmp(check.name, selectedName))
3468 this.selected = check;
3474 if(this.oClass.instances.first)
3475 this.selected = this.oClass.instances.first;
3477 this.selected = this.oClass;
3480 else if(selectedPos == -1 || !this.oClass.instances.count)
3481 this.selected = this.oClass;
3487 if(selectedPos > this.oClass.instances.count)
3489 for(check = this.oClass.instances.first; check; check = check.next)
3491 if(selectedPos == pos++)
3493 this.selected = check;
3501 this.oClass = classes.first;
3502 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3504 delete selectedName;
3505 SetSymbolsDir(null);
3507 if(sheet.codeEditor == this)
3508 sheet.SelectObject(selected);
3511 codeModified = false;
3513 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3516 InvokeParameters(false, false, false);
3519 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3525 ChangeWorkingDir(oldWorkDir);
3527 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3528 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3529 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3530 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3531 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3533 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3535 if(inUseDebug && ide.projectView)
3536 ide.debugger.EvaluateWatches();
3541 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3544 Window control = (Window)object.instance;
3545 ObjectInfo classObject = object.oClass;
3547 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3549 if(!strcmp(_class.name, "DesignerBase")) return;
3551 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3553 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3554 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3556 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3557 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3559 Class dataType = prop.dataTypeClass;
3561 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3565 if(dataType.type == structClass)
3567 void * dataForm = new0 byte[dataType.structSize];
3568 void * dataTest = new0 byte[dataType.structSize];
3570 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3571 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3573 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3575 char tempString[1024] = "";
3577 bool needClass = true;
3581 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3583 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3585 eClass_FindNextMember(_class, curClass, curMember, null, null);
3586 if(*curMember != (DataMember)prop)
3587 f.Printf("%s = ", prop.name);
3589 *curMember = (DataMember)prop;
3590 *curClass = curMember->_class;
3593 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3595 f.Printf("%s", string);
3602 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3604 void * dataForm, * dataTest;
3606 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3607 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3609 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3611 char tempString[1024] = "";
3616 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3618 eClass_FindNextMember(_class, curClass, curMember, null, null);
3619 if(*curMember != (DataMember)prop)
3620 f.Printf("%s = ", prop.name);
3621 *curMember = (DataMember)prop;
3622 *curClass = curMember->_class;
3624 if(eClass_GetDesigner(dataType))
3626 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3627 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3628 f.Printf("this", prop.name);
3631 //ObjectInfo classObject;
3632 //for(classObject = classes.first; classObject; classObject = classObject.next)
3636 for(object = classObject.instances.first; object; object = object.next)
3638 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3640 f.Printf("%s", object.name);
3647 bool needClass = true;
3648 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3649 f.Printf("%s", string);
3656 bool needClass = true;
3657 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3659 if(!strcmp(dataType.dataTypeString, "char *"))
3662 OutputString(f, string);
3666 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3668 f.Printf("%s", string);
3671 *lastIsMethod = false;
3676 DataValue dataForm, dataTest;
3678 GetProperty(prop, control, &dataForm);
3679 GetProperty(prop, test, &dataTest);
3681 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3684 char tempString[1024] = "";
3685 SetProperty(prop, test, dataForm);
3687 if(dataType.type != bitClass)
3689 bool needClass = true;
3691 if(dataType.type == enumClass)
3694 Class enumClass = eSystem_FindClass(privateModule, "enum");
3695 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3697 for(value = e.values.first; value; value = value.next)
3699 if((int)value.data == dataForm.i)
3701 string = value.name;
3707 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3709 if(string && string[0])
3714 eClass_FindNextMember(_class, curClass, curMember, null, null);
3715 if(*curMember != (DataMember)prop)
3716 f.Printf("%s = ", prop.name);
3717 *curMember = (DataMember)prop;
3718 *curClass = curMember->_class;
3720 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3721 f.Printf("%sf", string);
3723 f.Printf("%s", string);
3727 else if(dataType.type == bitClass)
3729 bool needClass = true;
3731 if(*prev) f.Printf(", ");
3733 eClass_FindNextMember(_class, curClass, curMember, null, null);
3734 if(*curMember != (DataMember)prop)
3735 f.Printf("%s = ", prop.name);
3736 *curMember = (DataMember)prop;
3737 *curClass = curMember->_class;
3739 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3741 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3743 f.Printf("%s", string);
3745 *lastIsMethod = false;
3755 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3757 Instantiation inst = object.instCode;
3758 Window control = (Window)object.instance;
3760 bool methodPresent = false;
3762 bool lastIsMethod = true;
3763 ObjectInfo classObject = object.oClass;
3769 // Instance removed, delete it
3770 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3772 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3773 position = inst.loc.end.pos + 1;
3777 bool multiLine = false;
3780 // Check if it's an unnamed instance
3783 f.Seek(inst.nameLoc.start.pos - position, current);
3784 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3785 position = inst.nameLoc.end.pos;
3787 f.Printf(object.name);
3792 if(isspace(ch) && ch != '\n')
3794 f.Seek(-1, current);
3802 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3804 f.Seek(pos - position, current);
3809 f.Seek(-1, current);
3818 f.Puts(object.name);
3823 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3824 methodPresent = true;
3832 if(ch == OpenBracket)
3838 // TODO: Simplify this?
3847 f.Seek(-1, current);
3859 if(ch == '\n') { toDelete = count; count = 0; }
3860 else if(isspace(ch)) count++;
3863 f.Seek(-1, current);
3867 toDelete += count - 6;
3877 f.Seek(-toDelete-count, current);
3878 f.DeleteBytes(toDelete);
3879 f.Seek(count, current);
3884 for(c = 0; c<toAdd; c++)
3890 methodPresent = multiLine;
3893 f.Printf(methodPresent ? "\n " : " ");
3899 // Instance not there, create a brand new one
3900 DeleteJunkBefore(f, position, &position);
3901 f.Printf(*firstObject ? "\n\n" : "\n");
3902 *firstObject = false;
3904 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3905 methodPresent = true;
3910 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3912 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3917 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3919 f.Printf(" %s %c ", control._class.name, OpenBracket);
3925 Instance test = eInstance_New(control._class);
3926 DataMember curMember = null;
3927 Class curClass = null;
3930 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3934 // Attach Method here
3935 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3937 if(prev) f.Printf(", ");
3938 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3943 if(inst && !object.deleted)
3945 MembersInit members;
3946 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3948 DeleteJunkBefore(f, position, &position);
3950 // Instance already there, clear out the properties
3951 for(members = inst.members->first; members; members = members.next)
3953 if(members.type == dataMembersInit)
3957 if(members.dataMembers)
3959 bool keptMember = false;
3960 MemberInit lastKept = null;
3962 for(member = members.dataMembers->first; member; member = member.next)
3964 Identifier ident = member.identifiers ? member.identifiers->first : null;
3965 bool deleted = false;
3967 // For now delete if it's not a method
3968 if(!member.variable) // && ident)
3970 if(!ident || !ident.next)
3972 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3975 f.Seek(member.loc.start.pos - position, current);
3976 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3977 position = member.loc.end.pos;
3982 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3983 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3984 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
3986 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
3987 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
3989 f.Seek(member.loc.start.pos - position, current);
3990 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3991 position = member.loc.end.pos;
4003 //f.Seek(member.loc.start.pos - position, current);
4004 //position = member.loc.start.pos;
4005 DeleteJunkBefore(f, member.loc.start.pos, &position);
4006 if(prev) f.Printf(", ");
4007 else if(keptMember) f.Printf(" ");
4012 if(!keptMember || !members.next)
4017 if(keptMember && lastKept != members.dataMembers->last)
4022 f.Seek(-1, current);
4028 f.Seek(-1, current);
4031 else if(!isspace(ch))
4033 f.Seek(-2, current);
4038 f.DeleteBytes(count);
4041 f.Seek(members.loc.end.pos - position, current);
4046 f.Seek(-1, current);
4048 position = members.loc.end.pos + 1;
4052 f.Seek(-1, current);
4053 position = members.loc.end.pos;
4059 lastIsMethod = false;
4064 DeleteJunkBefore(f, position, &position);
4067 if(lastKept != members.dataMembers->last)
4072 f.Seek(-1, current);
4078 f.Seek(-1, current);
4081 else if(!isspace(ch))
4083 f.Seek(-2, current);
4088 f.DeleteBytes(count);
4092 f.Seek(members.loc.end.pos - position, current);
4093 position = members.loc.end.pos;
4097 lastIsMethod = true;
4100 lastIsMethod = false;
4106 f.Seek(members.loc.end.pos - position, current);
4107 position = members.loc.end.pos;
4109 lastIsMethod = true;
4112 else if(members.type == methodMembersInit)
4114 if(this.methodAction == actionDeleteMethod && members.function == function);
4116 methodPresent = true;
4118 // Delete instance method here
4119 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4120 members.function == function)
4122 if(this.moveAttached && !*text)
4123 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4125 DeleteJunkBefore(f, members.loc.start.pos, &position);
4126 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4127 position = members.loc.end.pos + 1;
4132 DeleteJunkBefore(f, position, &position);
4136 DeleteJunkBefore(f, members.loc.start.pos, &position);
4137 lastIsMethod = true;
4141 f.Seek(members.loc.end.pos - position, current);
4142 position = members.loc.end.pos;
4144 DeleteJunkBefore(f, position, &position);
4153 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4155 Method method = this.method;
4156 DeleteJunkBefore(f, position, &position);
4162 if(!method.dataType)
4163 method.dataType = ProcessTypeString(method.dataTypeString, false);
4166 Type dataType = method.dataType;
4167 Type returnType = dataType.returnType;
4170 if(this.moveAttached)
4172 // Move function here:
4173 int newLen = strlen(method.name);
4178 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4180 // First change name of function
4181 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4182 *textSize += newLen - movedFuncIdLen;
4183 memcpy(*text + movedFuncIdPos, method.name, newLen);
4185 // Second, tab right
4188 for(c = 0; (*text)[c]; )
4191 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4194 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4195 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4199 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4209 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4211 // ADDING METHOD HERE
4213 OutputType(f, returnType, false);
4216 if(dataType.thisClass)
4218 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4220 if(dataType.thisClass.shortName)
4221 f.Printf(dataType.thisClass.shortName);
4223 f.Printf(dataType.thisClass.string);
4227 f.Printf(method.name);
4229 for(param = dataType.params.first; param; param = param.next)
4231 OutputType(f, param, true);
4236 f.Printf(" %c\n\n", OpenBracket);
4238 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4240 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4241 f.Printf(" return true;\n");
4242 else if(returnType.kind != voidType)
4243 f.Printf(" return 0;\n");
4248 if(returnType.kind != voidType)
4249 f.Printf("return ");
4250 f.Printf("%s::%s(", control._class.name, method.name);
4251 for(param = dataType.params.first; param; param = param.next)
4253 if(param.prev) f.Printf(", ");
4254 if(param.kind != voidType)
4255 f.Printf(param.name);
4259 f.Printf(" %c\n", CloseBracket);
4265 if(!object.instCode)
4268 f.Printf(" %c;\n", CloseBracket);
4270 f.Printf("%c;\n", CloseBracket);
4272 else if(!object.deleted)
4274 // Turn this into a multiline instance when adding a method
4275 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4277 f.Printf(methodPresent ? "\n " : " ");
4279 f.Seek(inst.loc.end.pos + 1 - position, current);
4280 position = inst.loc.end.pos + 1;
4285 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4288 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4290 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4292 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4294 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4295 if(prop && prop.isProperty && !prop.conversion)
4297 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4298 (!prop.IsSet || prop.IsSet(classObject.instance)))
4300 Class dataType = prop.dataTypeClass;
4301 char tempString[1024] = "";
4303 bool specify = false;
4306 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4307 if(member && member._class == regClass)
4311 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4313 if(dataType && dataType.type == structClass)
4315 void * dataForm = new0 byte[dataType.structSize];
4316 void * dataTest = new0 byte[dataType.structSize];
4318 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4319 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4321 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4323 bool needClass = true;
4325 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4326 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
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);
4335 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4337 void * dataForm, * dataTest;
4339 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4340 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4342 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4344 char tempString[1024] = "";
4346 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4348 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4350 // Shouldn't go here ...
4351 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4355 bool needClass = true;
4357 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4359 if(!strcmp(dataType.dataTypeString, "char *"))
4361 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4362 OutputString(f, string);
4366 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4368 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4374 DataValue dataForm, dataTest;
4376 GetProperty(prop, classObject.instance, &dataForm);
4377 GetProperty(prop, test, &dataTest);
4379 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4381 SetProperty(prop, test, dataForm);
4382 if(dataType.type == bitClass)
4384 bool needClass = true;
4385 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4387 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4389 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4393 bool needClass = true;
4394 if(dataType.type == enumClass)
4397 Class enumClass = eSystem_FindClass(privateModule, "enum");
4398 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4400 for(value = e.values.first; value; value = value.next)
4402 if((int)value.data == dataForm.i)
4404 string = value.name;
4410 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4411 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4412 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4414 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4423 void UpdateFormCode()
4426 if(!parsing) return;
4433 else if(formModified)
4435 EditBoxStream f { editBox = editBox };
4439 Identifier movedFuncId;
4440 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4441 ObjectInfo classObject;
4447 movedFuncId = GetDeclId(function.declarator);
4448 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4449 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4452 for(classObject = classes.first; classObject; classObject = classObject.next)
4455 ClassDefinition classDef = classObject.classDefinition;
4456 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4459 bool firstObject = true;
4460 ObjectInfo object = classObject.instances.first;
4461 bool lastIsDecl = false;
4463 if(!classObject.modified) continue;
4465 test = eInstance_New(regClass);
4468 // Put it in the same desktop window...
4469 designer.PrepareTestObject(test);
4471 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4472 //f.Printf("%c\n\n", OpenBracket);
4474 // Change the _class name
4475 f.Seek(classDef.nameLoc.start.pos - position, current);
4476 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4477 f.Printf(classObject.name);
4478 position = classDef.nameLoc.end.pos;
4481 // Go to block start, delete all until no white space, put \n
4485 f.Seek(classDef.blockStart.end.pos - position, current);
4486 position = classDef.blockStart.end.pos;
4488 for(; f.Getc(&ch); count++)
4492 f.Seek(-1, current);
4502 f.Seek(-count, current);
4504 f.DeleteBytes(count-back);
4506 position += count-back;
4509 // Output properties
4510 OutputClassProperties(classObject.instance._class, classObject, f, test);
4512 for(def = classDef.definitions->first; def; def = def.next)
4516 case defaultPropertiesClassDef:
4518 bool keptMember = false;
4520 MemberInit lastKept = null;
4523 DeleteJunkBefore(f, def.loc.start.pos, &position);
4526 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4528 Identifier ident = propDef.identifiers->first;
4529 bool deleted = false;
4531 // For now delete if it's a prop
4532 if(!propDef.variable && ident)
4536 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4539 f.Seek(propDef.loc.start.pos - position, current);
4540 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4541 position = propDef.loc.end.pos;
4546 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4547 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4549 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4550 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4552 f.Seek(propDef.loc.start.pos - position, current);
4553 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4554 position = propDef.loc.end.pos;
4572 f.Seek(def.loc.end.pos - position - 1, current);
4577 f.Seek(-1, current);
4580 position = def.loc.end.pos;
4584 if(lastKept != def.defProperties->last)
4589 f.Seek(-1, current);
4595 f.Seek(-1, current);
4598 else if(!isspace(ch))
4600 f.Seek(-2, current);
4605 f.DeleteBytes(count);
4609 f.Seek(def.loc.end.pos - position, current);
4610 position = def.loc.end.pos;
4615 case declarationClassDef:
4617 Declaration decl = def.decl;
4619 if(decl.type == instDeclaration)
4621 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4623 while(def.object && object != def.object)
4625 if(object /*&& ((ObjectInfo)def.object).modified*/)
4626 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4627 object = object.next;
4630 DeleteJunkBefore(f, def.loc.start.pos, &position);
4631 f.Printf(firstObject ? "\n\n " : "\n ");
4632 firstObject = false;
4634 if(def.object && ((ObjectInfo)def.object).modified)
4635 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4637 object = object ? object.next : null;
4641 DeleteJunkBefore(f, def.loc.start.pos, &position);
4642 f.Printf(firstObject ? "\n\n " : "\n ");
4643 firstObject = false;
4649 DeleteJunkBefore(f, def.loc.start.pos, &position);
4650 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4655 case functionClassDef:
4657 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4658 if(!def.function.body) continue;
4662 DeleteJunkBefore(f, def.loc.start.pos, &position);
4665 // Delete _class methods
4666 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4667 def.function == function)
4672 if(moveAttached && !text)
4674 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4677 f.Seek(def.loc.end.pos - position, current);
4678 for(; f.Getc(&ch); count++)
4682 f.Seek(-1, current);
4686 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4688 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4689 position = def.loc.end.pos + count;
4692 // In case of detaching methods in the _class, simply rename the method
4693 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4695 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4696 f.DeleteBytes(movedFuncIdLen);
4698 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4701 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4702 function == def.function)
4704 // In case of attaching methods in the _class, simply rename the method
4705 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4706 position = function.loc.start.pos + movedFuncIdPos;
4707 f.DeleteBytes(movedFuncIdLen);
4708 if(method.dataType.thisClass)
4709 f.Printf("%s::", method.dataType.thisClass.string);
4710 f.Puts(method.name);
4711 position += movedFuncIdLen;
4716 DeleteJunkBefore(f, def.loc.start.pos, &position);
4717 if(def.type == memberAccessClassDef)
4720 firstObject = false;
4730 f.Seek(def.loc.end.pos - position, current);
4731 position = def.loc.end.pos;
4734 // Output attached methods
4735 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4737 DeleteJunkBefore(f, position, &position);
4738 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4741 // ********** INSTANCES ***************
4742 for(; object; object = object.next)
4744 if(!object.instCode)
4746 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4750 DeleteJunkBefore(f, position, &position);
4752 // ****************** METHODS ***********************
4753 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4755 // If detaching an instance method
4756 if(selected != classObject)
4758 int newLen = strlen(methodName);
4761 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4762 // Tab selection left
4765 for(c = 0; text[c]; )
4768 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4769 memmove(text+start, text+start+i, textSize+1-start-i);
4772 for(; text[c] && text[c] != '\n'; c++);
4778 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4779 textSize += newLen - movedFuncIdLen;
4780 memcpy(text + movedFuncIdPos, methodName, newLen);
4787 if(methodAction == actionAddMethod && selected == classObject)
4789 Method method = this.method;
4791 if(!method.dataType)
4792 method.dataType = ProcessTypeString(method.dataTypeString, false);
4794 // ADDING METHOD HERE
4796 Type dataType = method.dataType;
4797 Type returnType = dataType.returnType;
4799 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4803 OutputType(f, returnType, false);
4806 if(dataType.thisClass && !dataType.classObjectType)
4808 if(dataType.thisClass.shortName)
4809 f.Printf(dataType.thisClass.shortName);
4811 f.Printf(dataType.thisClass.string);
4814 f.Printf(method.name);
4816 for(param = dataType.params.first; param; param = param.next)
4818 OutputType(f, param, true);
4823 f.Printf(" %c\n\n", OpenBracket);
4825 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4827 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4828 f.Printf(" return true;\n");
4829 else if(returnType && returnType.kind != voidType)
4830 f.Printf(" return 0;\n");
4835 if(returnType.kind != voidType)
4836 f.Printf("return ");
4838 char * name = ((Specifier)classDef.baseSpecs->first).name;
4839 Symbol _class = FindClass(name);
4840 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4842 for(param = dataType.params.first; param; param = param.next)
4844 if(param.prev) f.Printf(", ");
4845 if(param.kind != voidType)
4846 f.Printf(param.name);
4851 f.Printf(" %c", CloseBracket);
4855 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4867 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4868 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4872 codeModified = false;
4873 formModified = false;
4875 moveAttached = false;
4880 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4883 ClassFunction function = null;
4886 ObjectInfo object = this.selected;
4888 if(object && object == this.oClass)
4890 ClassDefinition classDef = object.oClass.classDefinition;
4892 if(classDef && classDef.definitions)
4894 for(def = classDef.definitions->first; def; def = def.next)
4896 if(def.type == functionClassDef && def.function.declarator)
4898 if(!strcmp(def.function.declarator.symbol.string, methodName))
4900 function = def.function;
4905 else if(def.type == defaultPropertiesClassDef)
4909 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4911 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4912 if(ident && !ident.next)
4914 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4918 propLoc = propDef.loc;
4921 ClassDefinition classDef = object.oClass.classDefinition;
4923 if(classDef.definitions)
4925 for(def = classDef.definitions->first; def; def = def.next)
4927 if(def.type == functionClassDef)
4929 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4931 function = def.function;
4950 Instantiation inst = object.instCode;
4952 // Check here to see if the method already exists, no need to call ModifyCode in that case
4953 if(inst && inst.members)
4955 MembersInit members;
4956 for(members = inst.members->first; members; members = members.next)
4958 switch(members.type)
4960 case dataMembersInit:
4962 if(members.dataMembers)
4965 for(member = members.dataMembers->first; member; member = member.next)
4967 Identifier ident = member.identifiers ? member.identifiers->first : null;
4968 if(ident && !ident.next)
4970 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4974 propLoc = member.loc;
4977 ClassDefinition classDef = object.oClass.classDefinition;
4979 if(classDef.definitions)
4981 for(def = classDef.definitions->first; def; def = def.next)
4983 if(def.type == functionClassDef)
4985 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
4987 function = def.function;
4996 // TODO: Fix memory leak
4997 function = ClassFunction
4999 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5011 case methodMembersInit:
5013 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5015 function = members.function;
5027 if(functionPtr) *functionPtr = function;
5031 void GoToMethod(char * methodName /*Method method*/)
5035 ObjectInfo object = selected;
5036 EditBoxStream f { editBox = editBox };
5037 ClassFunction function = null;
5038 bool atChar = false;
5042 Location propLoc = { {0,0,-1} };
5045 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5046 if(function && function.body)
5049 f.Seek(function.body.loc.start.pos+1, current);
5059 f.Seek(-1, current);
5064 else if(!isspace(ch))
5066 f.Seek(-1, current);
5072 else if(propLoc.start.pos > -1)
5074 f.Seek(propLoc.start.pos, current);
5077 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5079 if(function || propLoc.start.pos > -1)
5081 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5082 editBox.CenterOnCursor();
5083 SetState(normal, false, 0);
5086 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5088 FreeClassFunction(function);
5094 void FindCompatibleMethods(Method method, OldList compatible)
5096 ClassDefinition classDef = this.oClass.classDefinition;
5097 if(classDef && classDef.definitions)
5100 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5103 Symbol classSym { };
5104 Symbol selectedClass;
5105 if(this.selected == this.oClass)
5106 selectedClass = classSym;
5108 selectedClass = FindClass(this.selected.instance._class.name);
5110 regClass.name = classDef._class.name;
5111 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5112 for(def = classDef.definitions->first; def; def = def.next)
5114 if(def.type == functionClassDef && def.function.declarator)
5116 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5118 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5121 Type type = def.function.declarator.symbol.type;
5122 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5124 compatible.Add(OldLink { data = def.function });
5130 if(this.oClass && this.oClass.instance)
5132 classSym.registered = regClass;
5133 //classSym.registered = this.oClass.oClass;
5135 for(_class = regClass.base; _class; _class = _class.base)
5138 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5140 // TODO: Understand why these functions popup in attach list
5141 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5143 if(!testMethod.dataType)
5144 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5146 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5147 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5148 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5150 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5151 // ClassFunction function { };
5152 FunctionDefinition function { };
5154 function.declarator = Declarator { };
5155 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5156 excludedSymbols.Add(function.declarator.symbol);
5158 compatible.Add(OldLink { data = function });
5169 void AddMethod(Method method)
5173 char methodName[1024];
5174 strcpy(methodName, method.name);
5175 if(!FindMethod(methodName, null, null))
5177 methodAction = actionAddMethod;
5178 this.method = method;
5182 GoToMethod(methodName);
5186 void DeleteMethod(ClassFunction function)
5190 methodAction = actionDeleteMethod;
5191 this.function = function;
5199 void AttachMethod(Method method, ClassFunction function)
5203 // If it's an instance we'll ask if we want to move it inside...
5204 if(!function.attached.count && function.body)
5206 // Find the function in the _class to check if it's a virtual function
5207 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5208 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5209 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5211 for(def = this.classDefinition.first; def; def = def.next)
5213 if(def.type == functionClassDef)
5215 if(def.function == function)
5220 if(!method || method.type != virtualMethod)
5223 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5224 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5226 moveAttached = true;
5231 methodAction = actionAttachMethod;
5232 this.method = method;
5233 this.function = function;
5240 void ReAttachMethod(Method method, ClassFunction function)
5244 // If it's an instance we'll ask if we want to move it inside...
5245 if(!function.attached.count && function.body)
5247 // Find the function in the _class to check if it's a virtual function
5248 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5249 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5250 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5252 for(def = this.classDefinition.first; def; def = def.next)
5254 if(def.type == functionClassDef)
5256 if(def.function == function)
5261 if(!method || method.type != virtualMethod)
5264 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5265 if(MessageBox { type = yesNo, master = parent, text = title,
5266 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5268 moveAttached = true;
5273 methodAction = actionReattachMethod;
5274 this.method = method;
5275 this.function = function;
5282 void DetachMethod(Method method, ClassFunction function, int type)
5290 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5291 master = sheet, text = $"Name detached method", background = formColor
5295 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5296 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5300 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5301 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5305 dialog, anchor = { left = 5, right = 5, top = 5 }
5307 sprintf(methodName, "%s_%s", selected.name, method.name);
5308 nameBox.contents = methodName;
5310 result = dialog.Modal() == ok;
5311 strcpy(methodName, nameBox.contents);
5316 // If the method is not attached, move it outside
5319 // Add this class to the methodName
5320 char name[1024] = "";
5322 if(this.selected != this.oClass && !method.dataType.thisClass)
5324 strcat(name, this.selected.instance._class.name);
5326 strcat(name, this.methodName);
5327 strcpy(this.methodName, name);
5329 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5331 strcat(name, method.dataType.thisClass.string);
5333 strcat(name, this.methodName);
5334 strcpy(this.methodName, name);
5337 this.moveAttached = true;
5340 this.methodAction = actionDetachMethod;
5341 this.method = method;
5342 this.function = function;
5349 void AddObject(Instance instance, ObjectInfo * object)
5353 //*object = _class.instances.Add(sizeof(ObjectInfo));
5354 *object = ObjectInfo { };
5355 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5356 (*object).oClass = oClass;
5357 (*object).instance = instance;
5362 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5364 // if(strcmp(name, this.oClass.instance.name))
5367 for(check = oClass.instances.first; check; check = check.next)
5368 if(!check.deleted && check.name && !strcmp(name, check.name))
5372 (*object).name = CopyString(name);
5377 toolBox.controlClass = null;
5381 //sheet.AddObject(*object, (*object).name, TypeData, true);
5386 void EnsureUpToDate()
5388 if(sheet && codeModified && parsing)
5392 void SelectObject(ObjectInfo object)
5395 oClass = object ? object.oClass : null;
5397 designer.SelectObject(object, object ? object.instance : null);
5400 void SelectObjectFromDesigner(ObjectInfo object)
5403 sheet.SelectObject(object);
5406 void EnumerateObjects(Sheet sheet)
5410 for(oClass = classes.first; oClass; oClass = oClass.next)
5416 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5417 for(object = oClass.instances.first; object; object = object.next)
5418 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5421 sheet.SelectObject(selected);
5426 designer.AddObject();
5429 void DeleteObject(ObjectInfo object)
5431 delete object.instance;
5432 object.deleted = true;
5433 object.modified = true;
5434 object.oClass.modified = true;
5436 if(selected == object)
5438 bool looped = false;
5439 ObjectInfo select = object;
5443 select = select.prev;
5447 select = object.oClass.instances.last;
5454 sheet.SelectObject(select ? select : oClass);
5457 if(!object.instCode && object.oClass != object)
5460 oClass.instances.Delete(object);
5463 if(sheet.codeEditor == this)
5464 sheet.DeleteObject(object);
5467 void RenameObject(ObjectInfo object, char * name)
5471 // Validate the name:
5472 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5473 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5476 for(c = 0; name[c]; c++)
5477 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5485 object.name = (name && name[0]) ? CopyString(name) : null;
5487 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5491 void DesignerModifiedObject()
5493 sheet.ListProperties(false);
5497 void ListSubMembers(Type member)
5501 for(subMember = member.members.first; subMember; subMember = subMember.next)
5505 DataRow row = membersList.AddString(subMember.name);
5506 row.icon = icons[typeData];
5510 ListSubMembers(subMember);
5515 void ListSubDataMembers(DataMember member, bool isPrivate)
5517 DataMember subMember;
5518 for(subMember = member.members.first; subMember; subMember = subMember.next)
5520 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5524 DataRow row = membersList.AddString(subMember.name);
5525 BitmapResource bitmap = null;
5526 if(!subMember.dataType)
5527 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5529 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5531 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5534 bitmap = { bitmapName };
5535 membersList.AddResource(bitmap);
5538 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5542 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5548 void ListClassMembers(Class whatClass, bool methodsOnly)
5551 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5552 bool isPrivate = false;
5554 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5556 Method method, methodIt;
5558 DataMember memberIt;
5560 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5562 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5563 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5565 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5567 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5569 DataRow row = membersList.FindString(method.name);
5572 row = membersList.AddString(method.name);
5574 if(!method.dataType)
5575 method.dataType = ProcessTypeString(method.dataTypeString, false);
5577 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5585 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5589 if(memberIt.isProperty)
5591 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5593 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5597 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5599 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5602 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5608 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5610 if(member.isProperty)
5612 Property prop = (Property) member;
5613 if(!membersList.FindString(prop.name))
5615 DataRow row = membersList.AddString(prop.name);
5616 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5619 else if(member.name && !membersList.FindString(member.name))
5621 DataRow row = membersList.AddString(member.name);
5623 BitmapResource bitmap = null;
5624 if(!member.dataType)
5625 member.dataType = ProcessTypeString(member.dataTypeString, false);
5627 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5629 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5632 bitmap = { bitmapName };
5633 membersList.AddResource(bitmap);
5636 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5639 ListSubDataMembers(member, member.memberAccess == privateAccess);
5643 if(_class.inheritanceAccess == privateAccess)
5646 if(_class.module != privateModule) break;
5651 void ListClassMembersMatch(Class whatClass, Type methodType)
5654 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5655 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.memberAccess == publicAccess || method._class.module == privateModule)
5667 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5669 if(!method.dataType)
5670 method.dataType = ProcessTypeString(method.dataTypeString, false);
5672 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5674 DataRow row = membersList.FindString(method.name);
5677 row = membersList.AddString(method.name);
5678 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5684 if(_class.inheritanceAccess == privateAccess)
5687 if(_class.module != privateModule) break;
5692 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5695 bool isPrivate = false;
5696 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5702 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5704 if(method.type == virtualMethod)
5706 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5708 DataRow row = membersList.FindString(method.name);
5711 row = membersList.AddString(method.name);
5713 if(!method.dataType)
5714 method.dataType = ProcessTypeString(method.dataTypeString, false);
5716 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5722 for(member = _class.membersAndProperties.first; member; member = member.next)
5724 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5726 if(member.isProperty)
5728 Property prop = (Property)member;
5730 DataRow row = membersList.AddString(prop.name);
5731 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5734 else if(member.name && (!curString || strcmp(curString, member.name)))
5736 DataRow row = membersList.AddString(member.name);
5738 BitmapResource bitmap = null;
5739 if(!member.dataType)
5740 member.dataType = ProcessTypeString(member.dataTypeString, false);
5742 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5744 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5747 bitmap = { bitmapName };
5748 membersList.AddResource(bitmap);
5751 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5754 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5757 if(_class.inheritanceAccess == privateAccess)
5760 if(_class.module != privateModule) break;
5765 void ListMembers(Type type)
5767 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5771 if(type.kind == classType)
5774 ListClassMembers(type._class.registered, false);
5779 for(member = type.members.first; member; member = member.next)
5783 DataRow row = membersList.AddString(member.name);
5784 row.icon = icons[typeData];
5786 else if(member.kind == structType || member.kind == unionType)
5787 ListSubMembers(member);
5793 void ListModule(Module mainModule, int recurse, bool listClasses)
5796 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5797 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5798 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5799 for(module = mainModule.application.allModules.first; module; module = module.next)
5801 if(ModuleVisibility(mainModule, module))
5802 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5806 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5813 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5815 Class _class = link.data;
5816 if(_class.type != systemClass)
5818 DataRow row = membersList.AddString(_class.name);
5819 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5824 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5826 DefinedExpression definedExp = link.data;
5827 DataRow row = membersList.AddString(link /*definedExp*/.name);
5828 row.icon = icons[typeData];
5831 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5833 GlobalFunction function = link.data;
5834 DataRow row = membersList.AddString(link /*function*/.name);
5835 row.icon = icons[typeMethod];
5839 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5841 if(recurse != 2 && listClasses)
5843 if(!membersList.FindString(ns->name))
5845 DataRow row = membersList.AddString(ns->name);
5846 row.icon = icons[typeNameSpace];
5851 ListNameSpace(ns, 2, listClasses);
5855 void ListEnumValues(Class _class)
5857 List<Class> classes { };
5858 for(; _class && _class.type == enumClass; _class = _class.base)
5859 classes.Insert(null, _class);
5860 for(_class : classes)
5862 EnumClassData enumeration = (EnumClassData)_class.data;
5864 for(item = enumeration.values.first; item; item = item.next)
5866 DataRow row = membersList.AddString(item.name);
5867 row.icon = icons[typeEnumValue];
5873 bool ListEnumsModule(Module mainModule, Type dest)
5875 bool result = false;
5877 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5878 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5879 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5880 for(module = mainModule.application.allModules.first; module; module = module.next)
5882 if(ModuleVisibility(mainModule, module))
5883 result |= ListEnums(module.publicNameSpace, dest);
5888 void ListNameSpaceByString(Module mainModule, char * string)
5890 NameSpace * nameSpace;
5892 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5893 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5894 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5895 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5896 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5897 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5898 for(module = mainModule.application.allModules.first; module; module = module.next)
5900 if(ModuleVisibility(mainModule, module))
5902 nameSpace = FindNameSpace(module.publicNameSpace, string);
5903 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5908 bool ListEnums(NameSpace nameSpace, Type dest)
5911 bool result = false;
5913 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5915 Class _class = link.data;
5916 if(_class.type == enumClass && (dest.kind != classType || !dest._class || dest._class.registered != _class))
5918 OldList conversions { };
5920 type.kind = classType;
5921 type._class = FindClass(_class.name);
5922 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5924 ListEnumValues(_class);
5927 conversions.Free(null);
5931 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5933 result |= ListEnums(nameSpace, dest);
5938 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5942 for(c = 0; (ch = name[c]); c++)
5944 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5946 NameSpace * newSpace;
5947 char * spaceName = new char[c - start + 1];
5948 memcpy(spaceName, name + start, c - start);
5949 spaceName[c-start] = '\0';
5950 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5954 nameSpace = newSpace;
5963 return (NameSpace *)nameSpace;
5966 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5968 bool listedEnums = false;
5969 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5970 bool listClasses = true;
5972 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5974 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5975 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5976 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5978 if(exp.type == identifierExp)
5979 id = realIdentifier;
5981 if(id && id._class && !id._class.name)
5983 listClasses = false;
5986 else if(id && id._class && id._class.name)
5990 Class _class = id.classSym.registered;
5991 if(_class && _class.type == enumClass)
5993 ListEnumValues(_class);
5996 ListClassMembers(id.classSym.registered, true);
6001 else if(id && colons)
6003 ListNameSpaceByString(this.privateModule, id.string);
6008 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6010 listedEnums = ListEnumsModule(this.privateModule, destType);
6013 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6015 ListEnumValues(destType._class.registered);
6018 ListClassPropertiesAndVirtual(insideClass, null);
6022 else if(destType && destType.kind == enumType)
6026 for(value = destType.members.first; value; value = value.next)
6028 DataRow row = membersList.AddString(value.name);
6029 row.icon = icons[typeEnumValue];
6033 ListClassPropertiesAndVirtual(insideClass, null);
6037 else if(insideClass && !enumOnly)
6039 ListClassPropertiesAndVirtual(insideClass, string);
6042 if(listedEnums && string && string[0])
6044 DataRow row = membersList.FindSubString(string);
6046 listedEnums = false;
6049 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6051 ListClassMembersMatch(GetThisClass(), exp.destType);
6053 else if(!insideClass && !enumOnly && !listedEnums)
6056 Symbol symbol = null;
6060 ListClassMembers(GetThisClass(), false);
6063 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6065 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6067 // Don't list enum values?
6068 //if(symbol.type.kind != TypeEnum)
6069 DataRow row = membersList.FindString(symbol.string);
6072 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6074 row = membersList.AddString(symbol.string);
6075 if(symbol.type && symbol.type.kind == functionType)
6076 row.icon = icons[typeMethod];
6077 else if(symbol.type && symbol.type.kind == enumType)
6079 row.icon = icons[typeEnumValue];
6083 BitmapResource bitmap = null;
6084 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6086 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6089 bitmap = { bitmapName };
6090 membersList.AddResource(bitmap);
6093 row.icon = bitmap ? bitmap : icons[typeData];
6100 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6102 DataRow row = membersList.FindString(symbol.string);
6105 row = membersList.AddString(symbol.string);
6106 if(symbol.type.kind == functionType)
6107 row.icon = icons[typeMethod];
6108 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6110 row.icon = icons[typeClass];
6114 row.icon = icons[typeDataType];
6121 ListModule(this.privateModule, 1, listClasses);
6122 // TODO: Implement this with name space
6126 for(data = globalData.first; data; data = data.next)
6128 DataRow row = membersList.FindString(data.name);
6130 data.dataType = ProcessTypeString(data.dataTypeString, false);
6133 row = membersList.AddString(data.name);
6135 if(data.dataType && data.dataType.kind == TypeEnum)
6137 row.icon = icons[typeEnumValue];
6141 BitmapResource bitmap = null;
6142 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6144 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6147 bitmap = { bitmapName };
6148 membersList.AddResource(bitmap);
6151 row.icon = bitmap ? bitmap : icons[typeData];
6159 DataRow row = membersList.AddString("Min");
6160 row.icon = icons[typeMethod];
6162 row = membersList.AddString("Max");
6163 row.icon = icons[typeMethod];
6165 row = membersList.AddString("Abs");
6166 row.icon = icons[typeMethod];
6168 row = membersList.AddString("Sgn");
6169 row.icon = icons[typeMethod];
6175 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6177 EditBoxStream f { editBox = editBox };
6182 updatingCode = true;
6184 if(!method.dataType)
6185 method.dataType = ProcessTypeString(method.dataTypeString, false);
6187 DeleteJunkBefore(f, function.loc.start.pos, &position);
6188 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6190 // ADDING METHOD HERE
6192 Type dataType = method.dataType;
6193 Type returnType = dataType.returnType;
6195 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6201 if(extraIndent) f.Printf(" ");
6203 OutputType(f, returnType, false);
6207 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6209 if(dataType.thisClass.shortName)
6210 f.Printf(dataType.thisClass.shortName);
6212 f.Printf(dataType.thisClass.string);
6215 f.Printf(method.name);
6217 for(param = dataType.params.first; param; param = param.next)
6219 // Decided not to write void...
6220 if(param.kind != voidType)
6222 OutputType(f, param, true);
6228 if(extraIndent) f.Printf(" ");
6229 f.Printf(" %c\n", OpenBracket);
6231 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6237 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6238 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6240 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6242 if(extraIndent) f.Printf(" ");
6243 f.Printf(" return true;\n");
6245 else if(returnType && returnType.kind != voidType)
6247 if(extraIndent) f.Printf(" ");
6248 f.Printf(" return 0;\n");
6253 if(extraIndent) f.Printf(" ");
6255 if(returnType.kind != voidType)
6256 f.Printf("return ");
6257 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6258 for(param = dataType.params.first; param; param = param.next)
6260 if(param.prev) f.Printf(", ");
6261 if(param.kind != voidType)
6262 f.Printf(param.name);
6268 if(extraIndent) f.Printf(" ");
6269 f.Printf(" %c", CloseBracket);
6274 if(extraIndent) { x1 += 3; x2 += 3; }
6275 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6277 this.updatingCode = false;
6281 // Return false if we overrided a function and don't want to run params listing
6282 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6284 bool didOverride = false;
6285 EditLine line = editBox.line;
6286 char * text = line.text;
6287 int lineNum, charPos;
6288 Expression exp = null;
6291 //Identifier id = null;
6292 Expression memberExp = null;
6293 Identifier realIdentifier = null;
6295 if(!parsing) return true;
6296 if(!privateModule) return !didOverride;
6298 insideFunction = null;
6300 charPos = editBox.charPos + 1;
6301 if(!membersListShown)
6306 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6308 EditBoxStream f { editBox = editBox };
6310 updatingCode = true;
6311 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6315 if(!f.Seek(-1, current))
6318 if(!isspace(ch)) break;
6319 f.Seek(-1, current);
6321 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6323 lineNum = editBox.lineNumber + 1;
6324 charPos = editBox.charPos + 1;
6326 updatingCode = false;
6329 if(!membersListShown)
6331 memberExp = FindExpTree(ast, lineNum, charPos);
6332 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6337 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6339 EditBoxStream f { editBox = editBox };
6342 updatingCode = true;
6344 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6347 if(ch == '}' || ch == ',' || ch == ')')
6349 f.Seek(-1, current);
6357 if(!f.Seek(-1, current))
6360 if(!isspace(ch)) break;
6361 f.Seek(-1, current);
6365 f.Seek(-1, current);
6367 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6369 lineNum = editBox.lineNumber + 1;
6370 charPos = editBox.charPos + 1;
6372 updatingCode = false;
6375 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6380 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6381 lineNum = editBox.lineNumber + 1;
6382 charPos = editBox.charPos/* + 1*/;
6386 char tempString[1024];
6387 char * string = null;
6388 CodePosition idStart, idEnd;
6390 if(membersListShown)
6392 char * buffer = membersLine.text;
6394 bool firstChar = true;
6396 string = tempString;
6398 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6400 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6401 if(!isSpace) firstChar = false;
6403 string[len++] = buffer[c];
6407 else //if(realIdentifier)//if(id)
6410 char * buffer = id.string;
6412 bool firstChar = true;
6414 string = tempString;
6415 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6417 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6418 if(!isSpace) firstChar = false;
6420 string[len++] = buffer[c];
6426 EditLine editLine = editBox.line;
6427 bool firstChar = true;
6430 string = tempString;
6431 for(y = lineNum-1; y >= 0; y--)
6433 char * buffer = editLine.text;
6434 int lineCount = editLine.count;
6435 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6437 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6442 idEnd.charPos = x + 2;
6447 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6450 idEnd.charPos = x + 2;
6457 if(!isalnum(buffer[x]) && buffer[x] != '_')
6463 memmove(string+1, string, len++);
6464 string[0] = buffer[x];
6468 //if(done || firstChar)
6469 if(done || !firstChar)
6471 editLine = editLine.prev;
6474 if(!strcmp(string, "case"))
6480 else if(!strcmp(string, "return"))
6486 else if(!strcmp(string, "delete"))
6492 else if(!strcmp(string, "new"))
6498 else if(!strcmp(string, "renew"))
6506 idStart.charPos = x + 1;
6507 idStart.line = y + 1;
6510 if(!membersListShown)
6512 membersList.Clear();
6513 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6515 Type type = memberExp.member.exp.expType;
6516 if(pointer == 2 && type)
6518 if(type.kind == pointerType || type.kind == arrayType)
6527 ListSymbols(exp, enumOnly, string, realIdentifier);
6529 membersList.Sort(null, 1);
6534 // Virtual function override
6535 Identifier id = GetDeclId(insideFunction.declarator);
6536 char * string = id ? id.string : null;
6538 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6541 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6542 insideFunction = null;
6545 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6550 if(!didOverride) //insideFunction)
6552 rowCount = membersList.rowCount;
6555 DataRow row = string ? membersList.FindSubString(string) : null;
6556 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6558 char * newString = row.string;
6559 if(!membersListShown)
6561 membersLoc.start.line = idStart.line-1;
6562 membersLoc.start.charPos = idStart.charPos-1;
6563 //membersLoc.end = membersLoc.start;
6564 membersLoc.end.charPos = idEnd.charPos-1;
6565 membersLoc.end.line = idEnd.line-1;
6566 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6567 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6572 membersList.Destroy(0);
6573 membersListShown = false;
6576 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6578 line, membersLoc.start.line, membersLoc.start.charPos,
6579 line, membersLoc.end.line, membersLoc.end.charPos);
6580 editBox.PutS(newString);
6586 row = membersList.FindSubStringi(string);
6588 membersList.currentRow = row;
6589 membersList.currentRow.selected = false;
6592 membersList.currentRow = row;
6594 if(!membersListShown)
6598 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6599 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6600 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6601 editBox.GetCaretPosition(caret);
6602 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6604 membersList.master = this;
6606 caret.y += editBox.GetCaretSize();
6608 membersList.Create();
6611 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6612 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6613 Window parent = membersList.parent;
6615 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6617 y -= editBox.GetCaretSize() + membersList.size.h;
6618 membersAbove = true;
6621 membersAbove = false;
6623 membersList.position = { x, y };
6627 membersLoc.start.line = lineNum - 1;
6629 if(string && string[0])
6631 membersLoc.start.charPos = idStart.charPos-1;
6632 membersLoc.end = membersLoc.start;
6633 //membersLoc.end.charPos = id.loc.end.charPos-1;
6634 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6638 membersLoc.start.charPos = charPos;
6639 membersLoc.end = membersLoc.start;
6640 membersLoc.end.charPos = charPos;
6642 membersListShown = true;
6644 // Hack to keep caret shown
6645 editBox.GetCaretPosition(caret);
6646 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6649 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6655 SetCurrentContext(globalContext);
6658 return !didOverride;
6661 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6663 EditLine line = editBox.line;
6664 char * text = line.text;
6665 int lineNum, charPos;
6666 Expression exp = null;
6670 if(!parsing) return;
6672 charPos = editBox.charPos + 1;
6675 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6677 EditBoxStream f { editBox = editBox };
6680 updatingCode = true;
6681 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6684 if(ch == '}' || ch == ',' || ch == ')')
6686 f.Seek(-1, current);
6694 if(!f.Seek(-1, current))
6697 if(!isspace(ch)) break;
6698 f.Seek(-1, current);
6702 f.Seek(-1, current);
6704 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6706 lineNum = editBox.lineNumber + 1;
6707 charPos = editBox.charPos + 1;
6709 updatingCode = false;
6712 charPos = Min(charPos, l1.count + 1);
6714 FindParamsTree(ast, lineNum, charPos);
6716 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6717 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6719 ::functionType = null;
6720 ::instanceType = null;
6723 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6724 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6728 Window parent = paramsList.parent;
6730 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6733 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6734 // ( Dummy exp: always ends up with same memory)
6736 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6737 editBox.GetCaretPosition(paramsPosition);
6738 this.paramsPosition.y += editBox.GetCaretSize();
6741 FreeType(this.functionType);
6742 FreeType(this.instanceType);
6744 this.functionType = ::functionType;
6745 this.instanceType = ::instanceType;
6747 if(this.functionType) this.functionType.refCount++;
6748 if(this.instanceType) this.instanceType.refCount++;
6750 this.paramsID = ::paramsID;
6751 functionExp = paramsInsideExp;
6753 paramsList.master = this;
6755 paramsList.Create();
6757 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6758 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6760 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6762 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6766 paramsAbove = false;
6767 if(x + paramsList.size.w > parent.clientSize.w)
6769 x = parent.clientSize.w - paramsList.size.w;
6773 paramsList.position = { x, y };
6775 // Hack to keep caret shown
6778 editBox.GetCaretPosition(caret);
6779 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6782 this.paramsShown = true;
6784 else if((!::functionType && !::instanceType) || reposition)
6786 paramsList.Destroy(0);
6787 paramsShown = false;
6789 FreeType(this.functionType);
6790 FreeType(this.instanceType);
6791 this.functionType = null;
6792 this.instanceType = null;
6796 SetCurrentContext(globalContext);
6804 designer.visible = true;
6805 designer.Activate();
6811 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6813 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };