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;
123 bool ignoreBreakpoints:1;
125 bool oldImplementation:1;
128 class EditFileDialog : FileDialog
132 if(!ide.projectView && ideSettings.ideFileDialogLocation)
133 currentDirectory = ideSettings.ideFileDialogLocation;
134 return FileDialog::OnCreate();
138 EditFileDialog codeEditorFileDialog
140 type = multiOpen, text = $"Open",
141 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType);
142 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
145 EditFileDialog codeEditorFormFileDialog
147 type = open, text = $"Open Project",
148 types = fileTypes.array, sizeTypes = fileTypes.count * sizeof(FileType),
149 filters = fileFilters.array, sizeFilters = fileFilters.count * sizeof(FileFilter)
152 define OpenBracket = '{';
153 define CloseBracket = '}';
158 actionDeleteMethod = 2,
159 actionDetachMethod = 3,
160 actionAttachMethod = 4,
161 actionReattachMethod = 5
164 //extern StatusField pos, ovr, caps, num;
165 //extern Class thisClass;
171 bool parseError = false;
176 Expression ctxInsideExp;
177 Expression paramsInsideExp;
178 ClassFunction insideFunction;
186 /****************************************************************************
188 ****************************************************************************/
190 static void OutputString(File f, char * string)
193 for(c = 0; string[c]; c++)
195 if(string[c] == '\"')
197 else if(string[c] == '\\')
199 else if(string[c] == '\n')
210 void OutputType(File f, Type type, bool outputName)
220 if(!type.isSigned) f.Printf("unsigned ");
224 if(!type.isSigned) f.Printf("unsigned ");
228 if(!type.isSigned) f.Printf("unsigned ");
232 if(!type.isSigned) f.Printf("unsigned ");
236 if(!type.isSigned) f.Printf("unsigned ");
247 if(type._class && !strcmp(type._class.string, "class"))
249 switch(type.classObjectType)
252 f.Printf("any_object");
255 f.Printf("typed_object");
262 // ADD CODE TO DECIDE WHETHER TO OUTPUT FULLY QUAlIFIED OR NOT:
263 f.Printf(type._class.shortName ? type._class.shortName : type._class.string);
273 OutputType(f, type.type, false);
276 OutputType(f, type.type, false);
295 if(type.kind == arrayType)
298 f.Printf("%d", type.arraySize);
304 void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
310 f.Seek(pos - *position, current);
312 // Try to delete spaces and \n before...
318 /*else if(ch == '\n')
320 // Look for // comments on the line before
321 EditBox editBox = f.editBox;
322 EditLine line = editBox.line;
329 for(c = 0; text[c]; c++)
338 if(text[c] == '/' && last == '/')
350 f.DeleteBytes(before);
355 void GetLocText(EditBox editBox, File f, int position, Location loc, char ** text, int * size, int pad, int linePad)
360 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
362 // Cut & Paste function
368 f.Seek(loc.start.pos - position, current);
370 x1 = editBox.charPos;
371 y1 = editBox.lineNumber;
372 f.Seek(loc.end.pos - loc.start.pos, current);
374 x2 = editBox.charPos;
375 y2 = editBox.lineNumber;
376 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
378 *size = editBox.SelSize();
379 *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
380 editBox.GetSel(*text, false);
383 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
384 f.Printf(""); // Make the stream point to where the editbox is
387 void Code_FixProperty(Property prop, Instance object)
389 Designer::FixProperty(prop, object);
392 bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
395 if(prop.dataTypeString && (!prop.IsSet || prop.IsSet(selected.instance)))
397 Class dataType = prop.dataTypeClass;
400 dataType = prop.dataTypeClass = eSystem_FindClass(test._class.module, prop.dataTypeString);
402 if(dataType && dataType._vTbl && dataType.type == structClass)
404 void * dataForm = new0 byte[dataType.structSize];
405 void * dataTest = new0 byte[dataType.structSize];
407 ((void (*)(void *, void *))(void *)prop.Get)(selected.instance, dataForm);
408 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
410 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
412 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
418 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
420 void * dataForm, * dataTest;
421 bool isEditBoxContents = false;
422 bool freeDataForm = false, freeDataTest = false;
424 // Because contents property is broken for mutiline EditBox at the moment
425 if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox"))
426 isEditBoxContents = true;
428 if(isEditBoxContents && ((EditBox)selected.instance).multiLine)
430 dataForm = ((EditBox)selected.instance).multiLineContents;
434 dataForm = ((void *(*)(void *))(void *)prop.Get)(selected.instance);
435 if(isEditBoxContents && ((EditBox)test).multiLine)
437 dataTest = ((EditBox)test).multiLineContents;
441 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
443 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
445 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
449 if(freeDataForm) delete dataForm;
450 if(freeDataTest) delete dataTest;
452 else if(dataType && dataType._vTbl)
454 DataValue dataForm, dataTest;
456 GetProperty(prop, selected.instance, &dataForm);
457 GetProperty(prop, test, &dataTest);
459 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
461 SetProperty(prop, test, dataForm);
463 // In case setting on test unset on real instance (e.g. isDefault)
464 if(strcmp(prop.name, "name"))
466 GetProperty(prop, selected.instance, &dataTest);
467 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
468 SetProperty(prop, selected.instance, dataForm);
477 bool Code_IsPropertyDisabled(ObjectInfo selected, char * name)
479 bool disabled = false;
480 if(selected.oClass == selected)
483 if(selected.classDefinition)
485 for(def = selected.classDefinition.definitions->first; def; def = def.next)
487 if(def.type == defaultPropertiesClassDef)
490 for(prop = def.defProperties->first; prop; prop = prop.next)
492 if(prop.identifiers && prop.identifiers->first)
494 Identifier id = prop.identifiers->first;
495 if(prop.variable && !strcmp(id.string, name))
507 else if(selected.instCode)
510 if(selected.instCode.members)
512 for(members = selected.instCode.members->first; members; members = members.next)
514 if(members.type == dataMembersInit && members.dataMembers)
517 for(prop = members.dataMembers->first; prop; prop = prop.next)
519 if(prop.identifiers && prop.identifiers->first)
521 Identifier id = prop.identifiers->first;
522 if(prop.variable && !strcmp(id.string, name))
537 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
542 method.dataType = ProcessTypeString(method.dataTypeString, false);
543 if(!method.dataType.thisClass && !isForm)
546 method.dataType.thisClass = selectedClass;
548 //result = MatchTypes(method.dataType, type, null, regClass, regClass, false);
549 result = MatchTypes(type, method.dataType, null, regClass, regClass, false, true, true, false);
551 method.dataType.thisClass = null;
555 bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo object)
557 bool confirmation = true;
558 Statement body = function.body;
559 // Check if it contains any code
560 if((!body.compound.declarations || !body.compound.declarations->count) && (!body.compound.statements || body.compound.statements->count <= 1))
562 Class moduleClass = eSystem_FindClass(object.instance._class.module, "Module");
563 Statement stmt = body.compound.statements ? body.compound.statements->first : null;
564 Type dataType = method.dataType;
565 Type returnType = dataType.returnType;
566 Expression exp = null;
569 method.dataType = ProcessTypeString(method.dataTypeString, false);
571 confirmation = false;
573 // Check if default function should be calling base class:
574 if(object.instance._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
576 if(returnType.kind != voidType)
578 if(!stmt || stmt.type != returnStmt || !stmt.expressions || stmt.expressions->count != 1)
582 exp = stmt.expressions->first;
583 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
585 if( (exp.type != identifierExp || strcmp(exp.identifier.string, "true")) &&
586 (exp.type != constantExp || strcmp(exp.constant, "1")))
591 if(exp.type != constantExp || strcmp(exp.constant, "0"))
606 if(returnType.kind != voidType)
608 if(stmt.type == returnStmt && stmt.expressions && stmt.expressions->count == 1)
609 exp = stmt.expressions->first;
611 else if(stmt.type == expressionStmt && stmt.expressions && stmt.expressions->count == 1)
612 exp = stmt.expressions->first;
615 if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
619 Identifier id = exp.call.exp.identifier;
620 Class base = object.instance._class;
621 if(!id._class || (id._class.name && !strcmp(id._class.name, base.name)) || strcmp(id.string, method.name))
625 Expression arg = exp.call.arguments ? exp.call.arguments->first : null;
626 if(!arg || arg.type != identifierExp || strcmp("this", arg.identifier.string))
632 for(param = dataType.params.first; param; param = param.next)
634 if(!arg || arg.type != identifierExp || strcmp(param.name, arg.identifier.string))
639 arg = arg ?arg.next : null;
646 return !confirmation;
649 class CodeEditor : Window
651 background = marginColor;
652 borderStyle = sizableDeep;
657 isActiveClient = true;
658 anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
661 // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
662 // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
664 SheetType sheetSelected;
669 Context globalContext { };
670 OldList excludedSymbols { offset = (uint)&((Symbol)0).left };
683 MethodAction methodAction;
685 ClassFunction function;
687 char methodName[1024];
692 bool membersListShown;
695 EditLine membersLine;
697 Type functionType, instanceType;
701 Point paramsPosition;
702 Expression functionExp;
705 BitmapResource icons[CodeObjectType];
707 FontResource boldFont { $"Tahoma", 8.25f, bold = true, window = this };
708 FontResource normalFont { $"Tahoma", 8.25f, window = this };
710 Module privateModule;
711 NameSpace globalData;
714 OpenedFileInfo openedFileInfo;
716 FontResource font { codeFont.faceName, codeFont.size };
717 saveDialog = codeEditorFileDialog;
719 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
722 int maxLineNumberLength;
724 property bool parsing { get { return editBox.syntaxHighlighting && !noParsing && !ide.noParsing; } };
726 void ProcessCaretMove(EditBox editBox, int line, int charPos)
729 ObjectInfo classItem;
731 // OnActivateClient is called after OnActivate
734 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
737 if(sheet.codeEditor != this) return;
741 for(classItem = classes.first; classItem; classItem = classItem.next)
743 ClassDefinition classDef = classItem.classDefinition;
744 if(classDef && classDef.loc.Inside(line, charPos))
751 for(object = classItem.instances.first; object; object = object.next)
755 if(object.instCode.loc.Inside(line, charPos))
760 sheet.SelectObject(object);
762 sheet.SelectObject(classItem);
767 //sheet.SelectObject(null);
771 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
775 expectingMove = false;
781 if(line-1 != membersLoc.start.line)
785 char * buffer = membersLine.text;
788 if(charPos - 1 < membersLoc.start.charPos)
790 else if(charPos - 1 > membersLoc.end.charPos)
792 char * buffer = membersLine.text;
793 //if(membersList.currentRow)
797 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
798 if(buffer[c] != ' ' && buffer[c] != '\t')
800 if(c < charPos && buffer[c])
807 membersList.Destroy(0);
808 membersListShown = false;
812 bool back = codeModified;
813 codeModified = false;
815 InvokeParameters(false, false, false);
816 /*if(membersListShown)
817 InvokeAutoComplete(false, 0, true);*/
824 watch(modifiedDocument)
826 ProjectView projectView = ide.projectView;
829 char buffer[MAX_LOCATION];
830 char * fullPath = GetSlashPathBuffer(buffer, fileName);
831 Array<ProjectNode> nodes = ide.workspace.GetAllProjectNodes(fullPath, false);
835 node.modified = modifiedDocument;
836 projectView.Update(null);
845 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
846 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
847 tabKey = true, smartHome = true;
848 tabSelection = true, /*maxLineSize = 65536, */parent = this, hasHorzScroll = true, hasVertScroll = true;
849 selectionColor = selectionColor, selectionText = selectionText,
850 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
851 font = font, borderStyle = none;
852 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
854 bool OnMouseOver(int x, int y, Modifiers mods)
856 CodeEditor editor = (CodeEditor)master;
857 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
862 void NotifyCaretMove(EditBox editBox, int line, int charPos)
864 // Update Line Numbers
866 int oldLine = lastLine;
867 display.FontExtent(font.font, " ", 1, null, &spaceH);
869 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
873 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
878 if(ide.activeClient == this)
879 ProcessCaretMove(editBox, line, charPos);
881 openedFileInfo.CaretMove(line, charPos);
884 void NotifyOvrToggle(EditBox editBox, bool overwrite)
886 ide.UpdateStateLight(ide.ovr, overwrite);
889 void NotifyUpdate(EditBox editBox)
896 designer.modifiedDocument = true;
899 modifiedDocument = true;
902 bool NotifyUnsetModified(EditBox editBox)
904 modifiedDocument = false;
908 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
910 if(!loadingFile && after.y != before.y)
912 ProjectView projectView = ide.projectView;
913 if(projectView && fileName)
916 // HOW WE MIGHT WANT TO DO IT:
917 char * text = before.line.text;
918 for(c = before.x-1; c>= 0; c--)
919 if(!isspace(text[c]))
921 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
923 // HOW VISUAL STUDIO DOES IT:
925 char * text = after.line.text;
926 for(c = after.line.count-1; c>= 0; c--)
927 if(!isspace(text[c]))
929 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
932 Update({ 0, 0, editBox.position.x, clientSize.h });
940 for(oClass = classes.first; oClass; oClass = oClass.next)
943 for(object = oClass.instances.first; object; object = object.next)
947 object.instCode.loc.start.AdjustAdd(before, after);
948 object.instCode.loc.end.AdjustAdd(before, after);
953 oClass.classDefinition.loc.start.AdjustAdd(before, after);
954 oClass.classDefinition.loc.end.AdjustAdd(before, after);
960 expectingMove = true;
964 if(before.y != after.y)
968 char * buffer = membersLine.text;
970 bool firstChar = true;
971 bool addedChar = false;
977 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
979 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
981 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
982 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
991 membersLoc.start.charPos++;
996 string[len++] = buffer[c];
1000 row = membersList.currentRow;
1001 if(row && row.selected)
1005 membersLoc.start.charPos--;
1013 row = membersList.FindSubString(string);
1015 membersList.currentRow = row;
1018 row = membersList.FindSubStringi(string);
1020 membersList.currentRow = row;
1021 membersList.currentRow.selected = false;
1024 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
1028 row = membersList.currentRow;
1031 // Accept current string if hiding typing char
1032 if(hide && row && row.selected)
1034 char * string = row.string;
1035 int len = strlen(string);
1036 membersLoc.end.charPos -= after.x - before.x;
1037 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1038 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
1039 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1040 editBox.PutS(string);
1041 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
1043 after.x += membersLoc.start.charPos + len - before.x;
1044 before.x = membersLoc.start.charPos + len;
1049 membersList.Destroy(0);
1050 membersListShown = false;
1053 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
1055 EditLine line = editBox.line;
1056 char * text = line.text;
1057 char ch = text[after.x-1];
1058 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1062 // Can we call invoke auto complete here instead?
1072 // Force caret update already...
1073 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1074 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1076 editBox.GetCaretPosition(&caret);
1080 // Go back in the buffer until no space before
1082 codeModified = true;
1086 EditBoxStream f { editBox = editBox };
1090 if(text[after.x-1] == '>')
1096 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1100 if(!f.Seek(-1, current))
1103 if(!isspace(ch)) break;
1104 f.Seek(-1, current);
1106 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1108 line = editBox.lineNumber + 1;
1109 charPos = editBox.charPos + 1;
1113 exp = FindExpTree(ast, line, charPos);
1117 Type type = exp.expType;
1119 if(type && text[after.x-1] != '.')
1121 if(type.kind == TypePointer || type.kind == TypeArray)
1127 membersList.Clear();
1130 if(membersList.rowCount)
1132 membersList.Sort(null, 1);
1133 membersList.master = this;
1135 caret.y += editBox.GetCaretSize();
1138 membersList.Create();
1141 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1142 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1143 Window parent = membersList.parent;
1145 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1147 y -= editBox.GetCaretSize() + membersList.GetHeight();
1148 membersAbove = true;
1151 membersAbove = false;
1153 membersList.position = { x, y };
1157 membersLoc.start.line = line - 1;
1158 membersLoc.start.charPos = oldCharPos;
1159 membersLoc.end = membersLoc.start;
1160 membersListShown = true;
1165 SetCurrentContext(globalContext);
1167 codeModified = true;
1168 skipModified = true;
1169 if(text[after.x-1] == ':')
1170 InvokeAutoComplete(false, 0, false);
1171 else if(text[after.x-1] == '.')
1172 InvokeAutoComplete(false, 1, false);
1173 else if(text[after.x-1] == '>')
1174 InvokeAutoComplete(false, 2, false);
1175 skipModified = false;
1177 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1179 codeModified = true;
1180 skipModified = true;
1182 if(InvokeAutoComplete(true, 0, false))
1184 if(ch == '(' || ch == OpenBracket)
1185 InvokeParameters(true, true, false);
1187 InvokeParameters(this.functionType ? false : true, false, false);
1190 // InvokeAutoComplete(true, 0, false);
1191 skipModified = false;
1193 else if(ch == ')' || ch == '}' || ch == ';')
1195 codeModified = true;
1196 skipModified = true;
1198 InvokeParameters(false, true, false);
1199 skipModified = false;
1203 bool back = codeModified;
1204 codeModified = false;
1206 InvokeParameters(false, false, true);
1207 if(membersListShown)
1208 InvokeAutoComplete(false, 0, true);
1209 codeModified = back;
1214 bool back = codeModified;
1215 codeModified = false;
1218 InvokeParameters(false, false, true);
1219 /*if(membersListShown)
1220 InvokeAutoComplete(false, 0, true);*/
1222 codeModified = back;
1229 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1231 if(!loadingFile && after.y != before.y)
1233 ProjectView projectView = ide.projectView;
1234 if(projectView && fileName)
1235 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1236 Update({ 0, 0, editBox.position.x, clientSize.h });
1244 for(oClass = classes.first; oClass; oClass = oClass.next)
1248 for(object = oClass.instances.first; object; object = object.next)
1252 loc = &object.instCode.loc;
1254 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1255 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1257 object.instCode = null;
1261 loc->start.AdjustDelete(before, after);
1262 loc->end.AdjustDelete(before, after);
1266 if(oClass.classDefinition)
1268 loc = &oClass.classDefinition.loc;
1269 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1270 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1272 oClass.classDefinition = null;
1276 loc->start.AdjustDelete(before, after);
1277 loc->end.AdjustDelete(before, after);
1282 if(membersListShown)
1285 if(pasteOperation || before.y != after.y)
1289 char * buffer = membersLine.text;
1291 bool firstChar = true;
1295 if(before.x >= membersLoc.start.charPos)
1297 for(c = membersLoc.start.charPos; c<before.x && len < sizeof(string)-1; c++)
1299 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1300 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1305 if(!isSpace) firstChar = false;
1308 string[len++] = buffer[c];
1313 // If deleting spaces before...
1314 for(c = before.x; c<membersLoc.start.charPos; c++)
1316 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1324 membersLoc.start.charPos = before.x;
1327 if(membersLoc.end.charPos >= after.x)
1329 for(c = after.x; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1331 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1332 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1337 if(!isSpace) firstChar = false;
1340 string[len++] = buffer[c];
1348 membersLoc.end.charPos -= after.x - before.x;
1352 row = membersList.FindSubString(string);
1355 row = membersList.FindSubStringi(string);
1357 membersList.currentRow = row;
1358 membersList.currentRow.selected = false;
1361 membersList.currentRow = row;
1363 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1368 membersList.Destroy(0);
1369 membersListShown = false;
1375 InvokeParameters(false, false);
1383 bool NotifyDropped(EditBox editBox, int x, int y)
1385 char * controlClass = toolBox.controlClass;
1386 if(controlClass && controlClass[0])
1390 ObjectInfo classObject;
1392 editBox.GoToLineNum(y);
1393 x = Min(x, editBox.line.count);
1394 editBox.GoToPosition(editBox.line, y, x);
1395 // Note: Uncommented this to drag objects after the member instance on which they are dropped
1396 editBox.NotifyCaretMove(this, editBox, y+1, x+1);
1398 classObject = selected ? selected.oClass : null;
1400 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1401 selected = classObject.instances.last;
1404 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1407 AddObject(control, &object);
1409 designer.CreateObject(control, object, false, classObject.instance);
1410 // designer.PostCreateObject(control, object, false, classObject.instance);
1411 designer.DroppedObject(control, object, false, classObject.instance);
1413 sheet.AddObject(object, object.name, typeData /* className*/, true);
1416 //codeModified = true;
1423 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1425 if(key == ctrlSpace)
1427 membersList.Destroy(0);
1428 membersListShown = false;
1429 InvokeAutoComplete(false, 0, false);
1432 else if(key == Key { space, ctrl = true, shift = true })
1433 InvokeParameters(false, true, false);
1434 else if(key == escape)
1435 ide.RepositionWindows(true);
1436 else if(key == ctrlF7)
1440 ProjectNode node = ide.projectView.GetNodeForCompilationFromWindow(this, false, null, null);
1444 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1445 $"It can't be compiled.");
1446 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1455 bool OnKeyDown(Key key, unichar ch)
1457 CodeEditor editor = (CodeEditor)master;
1458 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1460 if(editor.membersListShown)
1462 editor.membersList.Destroy(0);
1463 editor.membersListShown = false;
1466 if(editor.paramsShown)
1468 editor.paramsList.Destroy(0);
1469 editor.paramsShown = false;
1470 FreeType(editor.functionType);
1471 FreeType(editor.instanceType);
1473 editor.functionType = null;
1474 editor.instanceType = null;
1475 editor.paramsID = -1;
1479 return EditBox::OnKeyDown(key, ch);
1482 void OnVScroll(ScrollBarAction action, int position, Key key)
1484 if(anchor.left.distance)
1486 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1489 EditBox::OnVScroll(action, position, key);
1491 CodeEditor ce = (CodeEditor)parent;
1492 if(ce.openedFileInfo)
1493 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1497 void OnHScroll(ScrollBarAction action, int position, Key key)
1499 EditBox::OnHScroll(action, position, key);
1501 CodeEditor ce = (CodeEditor)parent;
1502 if(ce.openedFileInfo)
1503 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1510 fullRowSelect = false,
1513 borderStyle = bevel;
1514 // size = { 200, 400 };
1516 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1518 DataRow row = listBox.currentRow;
1521 char * string = row.string;
1523 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1525 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1526 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1527 editBox.PutS(string);
1530 membersListShown = false;
1535 bool OnKeyDown(Key key, unichar ch)
1537 CodeEditor editor = (CodeEditor) master;
1538 if(key == escape || key == leftAlt || key == rightAlt ||
1539 (key.ctrl && key.code != left && key.code != right &&
1540 key.code != leftShift && key.code != rightShift && key.code != space))
1543 if(editor.paramsShown)
1547 editor.paramsList.Destroy(0);
1548 editor.paramsShown = false;
1550 if(editor.membersListShown)
1554 editor.membersList.Destroy(0);
1555 editor.membersListShown = false;
1558 FreeType(editor.functionType);
1559 editor.functionType = null;
1561 FreeType(editor.instanceType);
1562 editor.instanceType = null;
1564 editor.paramsID = -1;
1569 return editor.editBox.OnKeyDown(key, ch);
1573 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1575 CodeEditor editor = (CodeEditor)master;
1576 Window rw = previous ? previous.rootWindow : null;
1577 if(!active && rw != editor.paramsList)
1580 editor.membersListShown = false;
1582 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1585 bool OnKeyHit(Key key, unichar ch)
1587 CodeEditor editor = (CodeEditor) master;
1591 case enter: case tab:
1593 DataRow row = currentRow;
1594 if(row && row.selected)
1596 char * string = row.string;
1598 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1599 editor.editBox.Delete(
1600 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1601 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1602 editor.editBox.PutS(string);
1605 editor.membersListShown = false;
1608 editor.editBox.OnKeyHit(key, ch);
1618 return ListBox::OnKeyHit(key, ch);
1624 // If before . or after
1625 //listBox.Destroy(true);
1626 result = editor.editBox.OnKeyHit(key, ch);
1641 clickThrough = true,
1643 borderStyle = contour,
1645 background = { 255,255,225 },
1647 OnKeyDown = membersList.OnKeyDown;
1649 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1651 CodeEditor editor = (CodeEditor)master;
1652 Window rw = previous ? previous.rootWindow : null;
1653 if(!active && previous != editor.editBox && rw != editor.membersList)
1656 editor.paramsShown = false;
1658 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1661 bool OnKeyHit(Key key, unichar ch)
1663 CodeEditor editor = (CodeEditor)master;
1665 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1668 bool result = true; editor.editBox.OnKeyHit(key, ch);
1669 return (!created) ? false : result;
1676 void OnRedraw(Surface surface)
1678 CodeEditor editor = (CodeEditor) master;
1679 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1681 Type methodType = null;
1685 int functionW, nameW = 0;
1687 int spaceW, spaceH, commaW, commaWB, parW;
1689 int maxW = 0, lineW = 0;
1695 Font font = editor.normalFont.font;
1696 Font boldFont = editor.boldFont.font;
1697 Display display = this.display;
1699 if(!type) { return; };
1701 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1703 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1704 display.FontExtent(font, ", ", 2, &commaW, null);
1705 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1706 display.FontExtent(font, ")", 1, &parW, null);
1709 if(editor.functionType)
1711 PrintType(type.returnType, string, true, true);
1712 display.FontExtent(font, string, strlen(string), &functionW, null);
1714 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1715 totalW = nameW + functionW + 2 * parW;
1719 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1720 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1721 if(instanceName && type.kind != functionType)
1722 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1723 totalW = functionW + nameW;
1724 surface.TextFont(boldFont);
1727 surface.WriteText(x, y, string, strlen(string));
1728 x += functionW + spaceW;
1730 if(editor.functionType)
1733 surface.WriteText(x, y, type.name, strlen(type.name));
1735 surface.WriteText(x, y, "(", 1);
1738 if(methodType && !methodType.staticMethod && methodType.methodClass)
1742 if(id == editor.paramsID)
1743 surface.TextFont(boldFont);
1745 if(methodType.methodClass)
1746 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1750 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1751 width += ((id == editor.paramsID) ? commaWB : commaW);
1756 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1761 x = 2 + nameW + spaceW + functionW + parW;
1765 if(methodType.methodClass)
1766 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1769 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1771 surface.WriteText(x, y, ",", 1);
1772 x += ((id == editor.paramsID) ? commaWB : commaW);
1780 if(id == editor.paramsID)
1781 surface.TextFont(font);
1785 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1787 for(param = type.params.first; param; param = param.next)
1789 char paramString[1024];
1792 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1793 surface.TextFont(boldFont);
1796 PrintType(param, paramString, true, true);
1797 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1799 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1804 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1809 x = 2 + nameW + spaceW + functionW + parW;
1813 surface.WriteText(x, y, paramString, strlen(paramString));
1817 surface.WriteText(x, y, ",", 1);
1818 x += ((id == editor.paramsID) ? commaWB : commaW);
1826 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1827 surface.TextFont(font);
1832 surface.WriteText(x, y, ")", 1);
1834 else if(instanceName && type.kind != functionType)
1836 surface.WriteText(x, y, instanceName, strlen(instanceName));
1840 bool OnResizing(int * w, int * h)
1842 CodeEditor editor = (CodeEditor) master;
1843 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1845 Type methodType = null;
1849 int functionW = 0, nameW = 0;
1851 int spaceW, spaceH, commaW, commaWB, parW;
1853 int maxW = 0, lineW = 0;
1858 Font font = editor.normalFont.font;
1859 Font boldFont = editor.boldFont.font;
1860 Display display = this.display;
1862 if(type.kind == TypeKind::methodType)
1865 ProcessMethodType(type.method);
1866 type = type.method.dataType;
1869 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1870 display.FontExtent(font, ", ", 2, &commaW, null);
1871 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1872 display.FontExtent(font, ")", 1, &parW, null);
1875 if(editor.functionType && type)
1877 PrintType(type.returnType, string, true, true);
1878 display.FontExtent(font, string, strlen(string), &functionW, null);
1880 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1881 totalW = nameW + spaceW + functionW + 2 * parW;
1885 PrintType(type, string, false, true); // /*true);
1886 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1887 if(instanceName && type.kind != functionType)
1888 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1889 totalW = functionW + nameW + spaceW;
1892 if(editor.functionType)
1898 if(methodType.methodClass)
1899 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1900 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1901 width += ((id == editor.paramsID) ? commaWB : commaW);
1906 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1919 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1921 for(param = type.params.first; param; param = param.next)
1923 char paramString[1024];
1927 PrintType(param, paramString, true, true);
1928 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1930 width += ((id == editor.paramsID) ? commaWB : commaW);
1935 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1952 *w = realW + totalW + 4;
1958 Menu fileMenu { menu, $"File", f };
1959 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1960 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1962 Menu debugMenu { menu, $"Debug", d };
1963 MenuItem debugRunToCursor { debugMenu, $"Run To Cursor", c, ctrlF10, id = RTCMenuBits { false, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1964 MenuItem debugSkipRunToCursor { debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true }, id = RTCMenuBits { true, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1965 MenuItem debugRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level", l, altF10, id = RTCMenuBits { false, true, false }, NotifySelect = RTCMenu_NotifySelect; };
1966 MenuItem debugSkipRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level Skipping Breakpoints", g, Key { f10, shift = true, alt = true }, id = RTCMenuBits { true, true, false }, NotifySelect = RTCMenu_NotifySelect; };
1968 MenuItem debugBpRunToCursor { debugMenu, $"BP Run To Cursor"/*, c, ctrlF10*/, id = RTCMenuBits { false, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1969 MenuItem debugBpSkipRunToCursor { debugMenu, $"BP Run To Cursor Skipping Breakpoints"/*, u, Key { f10, ctrl = true, shift = true }*/, id = RTCMenuBits { true, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1970 MenuItem debugBpRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level"/*, l, altF10*/, id = RTCMenuBits { false, true, true }, NotifySelect = RTCMenu_NotifySelect; };
1971 MenuItem debugBpSkipRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level Skipping Breakpoints"/*, g, Key { f10, shift = true, alt = true }*/, id = RTCMenuBits { true, true, true }, NotifySelect = RTCMenu_NotifySelect; };
1973 bool RTCMenu_NotifySelect(MenuItem selection, Modifiers mods)
1975 ProjectView projectView = ide.projectView;
1976 if(!projectView.buildInProgress)
1978 RTCMenuBits bits = (RTCMenuBits)selection.id;
1979 int line = editBox.lineNumber + 1;
1982 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1983 ProjectConfig config = projectView.project.config;
1984 int bitDepth = ide.workspace.bitDepth;
1985 bool useValgrind = ide.workspace.useValgrind;
1986 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, bits.ignoreBreakpoints, bits.atSameLevel, bits.oldImplementation);
1992 MenuDivider { debugMenu };
1993 MenuItem debugToggleBreakpoint
1995 debugMenu, $"Toggle Breakpoint", t, f9;
1996 bool NotifySelect(MenuItem selection, Modifiers mods)
1998 ProjectView projectView = ide.projectView;
1999 if(projectView && fileName)
2001 int line = editBox.lineNumber + 1;
2002 ide.debugger.ToggleBreakpoint(fileName, line);
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 if(modifiedDocument)
2042 OnFileModified({ modified = true }, null);
2044 debugClosing = false;
2047 if(designer && !designer.closing)
2049 if(designer.visible)
2056 //Window formEditor = designer;
2057 //formEditor.Destroy(0);
2060 ide.AdjustFileMenus();
2065 void OnDestroy(void)
2067 ObjectInfo oClass, next;
2068 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2070 FreeType(this.functionType);
2071 FreeType(this.instanceType);
2076 designer.codeEditor = null;
2077 designer.Destroy(0);
2081 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2083 ObjectInfo object, next;
2085 for(object = oClass.instances.first; object; object = next)
2090 Designer::DestroyObject(object.instance);
2091 delete object.instance;
2093 sheet.DeleteObject(object);
2095 oClass.instances.Delete(object);
2099 Designer::DestroyObject(oClass.instance);
2100 delete oClass.instance;
2102 sheet.DeleteObject(oClass);
2104 classes.Delete(oClass);
2107 if(windowClass && windowClass.data)
2108 UnapplySkin(windowClass);
2112 if(sheet.codeEditor == this)
2114 sheet.codeEditor = null;
2115 toolBox.codeEditor = null;
2121 ProjectView projectView = ide.projectView;
2124 ProjectNode node = projectView.GetNodeFromWindow(this, null, true, false, null);
2125 if(node && node.modified)
2127 node.modified = false;
2128 projectView.Update(null);
2134 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2136 // 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
2138 if(directActivation)
2139 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2141 if(active && directActivation)
2145 openedFileInfo.Activate();
2149 Location * loc = null;
2150 UpdateFormCode(); // To ensure update when modifying properties...
2152 // Got to the right spot in code so we don't lose our form selection...
2155 if(selected.instCode)
2156 loc = &selected.instCode.loc;
2157 else if(selected.classDefinition)
2158 loc = &selected.classDefinition.loc;
2160 line = editBox.lineNumber + 1;
2161 charPos = editBox.charPos + 1;
2166 if(selected && !loc->Inside(line, charPos))
2168 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2169 line = editBox.lineNumber + 1;
2170 charPos = editBox.charPos + 1;
2172 else if(selected && selected.classDefinition)
2175 for(object = selected.instances.first; object; object = object.next)
2179 if(object.instCode.loc.Inside(line, charPos))
2185 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2186 line = editBox.lineNumber + 1;
2187 charPos = editBox.charPos + 1;
2192 ProcessCaretMove(editBox, line, charPos);
2197 if(membersListShown)
2199 membersList.Destroy(0);
2200 membersListShown = false;
2204 paramsList.Destroy(0);
2205 paramsShown = false;
2206 FreeType(functionType);
2207 FreeType(instanceType);
2209 functionType = null;
2210 instanceType = null;
2217 bool OnSaveFile(char * fileName)
2224 f = FileOpen(fileName, write);
2227 if(!ide.projectView)
2228 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2232 this.fileName = fileName; // Put this here because the form designer will check for it...
2233 designer.fileName = fileName;
2234 designer.modifiedDocument = false;
2237 if(editBox.syntaxHighlighting)
2239 // Nuke trailing spaces
2242 for(line = editBox.firstLine; line; line = line.next, y++)
2244 String buffer = line.text;
2245 int count = line.count, i = count-1;
2246 while(i > 0 && isspace(buffer[i])) i--;
2248 editBox.Delete(line, y, i, line, y, count);
2252 editBox.Save(f, false);
2253 modifiedDocument = false;
2261 bool OnFileModified(FileChange fileChange, char * param)
2263 bool reload = false;
2264 if(visible == false && inUseDebug == true)
2265 ide.debugger.WatchesReleaseCodeEditor();
2270 sprintf(message, $"The document %s was modified by another application.\n"
2271 "Would you like to reload it and lose your changes?", fileName);
2272 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2273 contents = message }.Modal() == yes)
2279 File f = FileOpen(fileName, read);
2282 int lineNumber, charPos, len;
2286 updatingCode = true;
2287 lineNumber = editBox.lineNumber;
2288 charPos = editBox.charPos;
2289 scroll = editBox.scroll;
2292 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2293 len = strlen(editBox.line.text);
2294 editBox.GoToLineNum(lineNumber);
2295 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2296 editBox.scroll = scroll;
2297 updatingCode = false;
2298 loadingFile = false;
2300 codeModified = true;
2304 designer.modifiedDocument = false;
2306 modifiedDocument = false;
2314 void OnRedraw(Surface surface)
2317 surface.SetBackground(marginColor);
2318 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2319 if(ideSettings.showLineNumbers)
2321 int currentLineNumber;
2323 char lineFormat[16];
2327 surface.textOpacity = false;
2328 surface.font = font.font;
2329 surface.TextExtent(" ", 1, null, &spaceH);
2330 currentLineNumber = editBox.scroll.y / spaceH + 1;
2331 sprintf(lineFormat, " %%%du", maxLineNumberLength);
2333 surface.SetForeground(lineNumbersColor);
2334 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2336 // Highlight current line
2337 if(editBox.lineNumber == currentLineNumber - 1)
2339 surface.SetBackground(selectedMarginColor);
2340 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2341 surface.SetBackground(marginColor);
2343 sprintf(lineText, lineFormat, currentLineNumber);
2344 if(currentLineNumber <= editBox.numLines)
2345 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
2346 currentLineNumber++;
2350 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2352 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2353 int lineCursor, lineTopFrame, breakpointLines[128];
2354 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2355 Debugger debugger = ide.debugger;
2356 BitmapResource bmpRes;
2358 boxH = clientSize.h;
2359 scrollY = editBox.scroll.y;
2360 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2362 bpOnCursor = bpOnTopFrame = false;
2363 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2366 for(i = 0; i < count; i++)
2368 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2370 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2371 if(breakpointLines[i] == lineCursor)
2373 if(breakpointLines[i] == lineTopFrame)
2374 bpOnTopFrame = true;
2377 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2379 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2382 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2383 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2384 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2386 if(editBox.anchor.left.distance)
2388 if(editBox.horzScroll && editBox.horzScroll.visible)
2390 surface.SetBackground(control);
2391 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2396 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2401 lineY = (line - 1) * lineH;
2402 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2404 Bitmap bitmap = resource.bitmap;
2406 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2413 char ext[MAX_EXTENSION];
2414 char * fileName = property::fileName;
2416 if(SearchString(fileName, 0, "Makefile", false, true))
2417 editBox.useTab = true;
2418 designer.fileName = fileName;
2422 GetExtension(fileName, ext);
2424 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2425 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2426 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2427 editBox.syntaxHighlighting = true;
2429 editBox.syntaxHighlighting = false;
2431 if(parsing && !strcmpi(ext, "ec"))
2433 codeModified = true;
2437 maxLineNumberLength = 0;
2442 bool UpdateMarginSize()
2444 if(ideSettings.showLineNumbers)
2446 int numLen = Max(4, nofdigits(editBox.numLines));
2448 maxLineNumberLength = numLen;
2449 display.FontExtent(font.font, "0", 1, &digitWidth, null);
2450 editBox.anchor = Anchor
2452 left = editBox.syntaxHighlighting * 20 + ideSettings.showLineNumbers * (maxLineNumberLength+2) * digitWidth,
2453 right = 0, top = 0, bottom = 0
2458 maxLineNumberLength = 0;
2459 editBox.anchor = Anchor
2461 left = editBox.syntaxHighlighting * 20,
2462 right = 0, top = 0, bottom = 0
2474 bool LoadFile(char * filePath)
2476 File f = FileOpen(filePath, read);
2479 // Added this here...
2480 fileName = filePath;
2482 updatingCode = true;
2484 updatingCode = false;
2485 loadingFile = false;
2494 void AdjustDebugMenus()
2496 bool unavailable = ide.areDebugMenusUnavailable;
2497 bool isNotNotRunning = unavailable || ide.isDebuggerRunning;
2498 bool isNotStopped = unavailable || !ide.isDebuggerStopped;
2499 bool noBreakpointToggle = ide.isBreakpointTogglingUnavailable;
2501 debugRunToCursor.disabled = isNotNotRunning;
2502 debugSkipRunToCursor.disabled = isNotNotRunning;
2503 debugRunToCursorAtSameLevel.disabled = isNotStopped;
2504 debugSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2506 debugBpRunToCursor.disabled = isNotNotRunning;
2507 debugBpSkipRunToCursor.disabled = isNotNotRunning;
2508 debugBpRunToCursorAtSameLevel.disabled = isNotStopped;
2509 debugBpSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2511 debugToggleBreakpoint.disabled = noBreakpointToggle;
2517 ProjectView projectView = ide.projectView;
2520 designer.fileName = fileName;
2526 sprintf(title, $"Untitled %d", documentID);
2527 // designer.fileName = CopyString(title);
2528 designer.fileName = title;
2533 for(c = 0; c < CodeObjectType::enumSize; c++)
2534 icons[c] = BitmapResource { iconNames[c], window = this };
2536 codeModified = true;
2548 selected.modified = true;
2549 selected.oClass.modified = true;
2551 designer.modifiedDocument = true;
2552 modifiedDocument = true;
2553 formModified = true;
2556 /****************************************************************************
2558 ****************************************************************************/
2566 this.defines.Free(FreeModuleDefine);
2567 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2569 FreeExcludedSymbols(this.excludedSymbols);
2570 FreeContext(this.globalContext);
2572 FreeGlobalData(&this.globalData);
2573 FindCtx_Terminate();
2574 FindParams_Terminate();
2576 if(GetGlobalContext() == globalContext)
2578 SetGlobalData(null);
2579 SetGlobalContext(null);
2580 SetExcludedSymbols(null);
2581 SetTopContext(null);
2582 SetCurrentContext(null);
2585 SetPrivateModule(null);
2588 if(this.privateModule)
2590 FreeTypeData(this.privateModule);
2591 delete this.privateModule;
2592 this.privateModule = null;
2598 static bool reentrant = false;
2603 char * selectedClassName = null, * selectedName = null;
2604 int selectedPos = 0;
2605 Designer backDesigner;
2606 char oldWorkDir[MAX_LOCATION];
2607 char mainModuleName[MAX_FILENAME] = "";
2609 ImportedModule module;
2610 char extension[MAX_EXTENSION];
2611 PathBackup pathBackup { };
2613 Time parseCodeStart = GetTime();
2614 Time startTime, startFindClass;
2616 findClassTotalTime = 0;
2617 checkTypeTotalTime = 0;
2618 externalImportTotalTime = 0;
2619 findClassIgnoreNSTotalTime = 0;
2620 findSymbolTotalTime = 0;
2621 //ResetClassFindTime();
2625 // 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)
2626 if(reentrant) return;
2633 selectedClassName = CopyString(oClass.name);
2634 if(selected != oClass)
2636 ObjectInfo object = this.selected;
2637 selectedName = CopyString(object.name);
2641 for(check = this.oClass.instances.first; check; check = check.next)
2653 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2655 FindCtx_Terminate();
2656 FindParams_Terminate();
2658 SetGlobalData(&globalData);
2659 SetGlobalContext(globalContext);
2660 SetExcludedSymbols(&excludedSymbols);
2661 SetTopContext(globalContext);
2662 SetCurrentContext(globalContext);
2663 SetDefines(&defines);
2664 SetImports(&imports);
2665 SetCurrentNameSpace(null);
2668 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2669 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2670 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2671 "/I T:\\ecere\\include /E %s", argv[1]);
2675 ChangeWorkingDir("e:\\ec");
2676 sprintf(command, "gcc -x c -E -");
2677 fileInput = DualPipeOpen({ output = true, input = true }, command);
2678 SetFileInput(fileInput);
2683 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2685 fileInput.Write(buffer, 1, count);
2690 fileInput.CloseOutput();
2694 // TOCHECK: COULDN'T WE CALL FreeParser here?
2696 FreeType(this.functionType);
2697 FreeType(this.instanceType);
2698 this.functionType = null;
2699 this.instanceType = null;
2702 sheet.SelectObject(null);
2708 // We don't want the designer to be notified of selection when deleting rows...
2709 backDesigner = designer;
2714 ObjectInfo _class, next;
2716 for(_class = classes.first; _class; _class = next)
2722 for(;object = _class.instances.first;)
2726 Designer::DestroyObject(object.instance);
2727 delete object.instance;
2729 sheet.DeleteObject(object);
2731 _class.instances.Delete(object);
2735 Designer::DestroyObject(_class.instance);
2736 delete _class.instance;
2738 sheet.DeleteObject(_class);
2740 classes.Delete(_class);
2746 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2747 if(windowClass && windowClass.data)
2748 UnapplySkin(windowClass);
2751 designer = backDesigner;
2754 fileInput = editFile = EditBoxStream { editBox = editBox };
2755 SetFileInput(fileInput);
2763 defines.Free(FreeModuleDefine);
2764 imports.Free(FreeModuleImport);
2766 FreeContext(this.globalContext);
2767 FreeExcludedSymbols(this.excludedSymbols);
2770 FreeGlobalData(&this.globalData);
2772 if(this.privateModule)
2774 FreeTypeData(this.privateModule);
2775 delete this.privateModule;
2779 startTime = GetTime();
2780 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2782 printf("classes.count: %d\n", globalContext.classes.count);
2787 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2788 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2791 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2793 SetPrivateModule(privateModule);
2796 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2797 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2798 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2799 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2800 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2803 fileName = this.fileName;
2805 if(ide.workspace && ide.workspace.projects && fileName)
2807 for(p : ide.workspace.projects)
2809 char path[MAX_LOCATION];
2811 MakePathRelative(fileName, p.topNode.path, path);
2812 MakeSlashPath(path);
2814 pn = p.topNode.FindWithPath(path, false);
2823 project = ide.project;
2825 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2827 ChangeWorkingDir(project.topNode.path);
2829 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2831 GetLastDirectory(fileName, mainModuleName);
2832 GetExtension(mainModuleName, extension);
2834 SetBuildingEcereCom(false);
2835 SetBuildingEcereComModule(false);
2837 // TODO: Get symbolsDir from project settings instead...
2840 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2841 ProjectConfig config = project.config;
2842 int bitDepth = ide.workspace.bitDepth;
2843 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2844 SetSymbolsDir(objDir.dir);
2845 ide.SetPath(true, compiler, config, bitDepth);
2849 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2850 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2854 switch(GetRuntimePlatform())
2856 case win32: SetSymbolsDir("obj/debug.win32"); break;
2857 case tux: SetSymbolsDir("obj/debug.linux"); break;
2858 case apple: SetSymbolsDir("obj/debug.apple"); break;
2860 SetIncludeDirs(null);
2861 SetSysIncludeDirs(null);
2865 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2867 // TODO FIX for configless project
2868 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2870 for(item : ide.project.config.options.preprocessorDefinitions)
2872 if(!strcmp(item, "BUILDING_ECERE_COM"))
2874 SetBuildingEcereCom(true);
2881 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2882 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2883 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2884 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2885 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2886 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2887 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2888 strcmpi(mainModuleName, "Mutex.ec")))
2890 SetBuildingEcereComModule(true);
2893 // Predeclare all classes
2895 char symFile[MAX_FILENAME];
2896 char symLocation[MAX_LOCATION];
2897 ImportedModule module, next;
2899 GetLastDirectory(fileName, symFile);
2900 ChangeExtension(symFile, "sym", symFile);
2902 strcpy(symLocation, GetSymbolsDir());
2903 PathCat(symLocation, symFile);
2905 // if(!GetEcereImported() && !GetBuildingEcereCom())
2906 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2909 startTime = GetTime();
2911 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2913 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2918 startTime = GetTime();
2920 // LoadSymbols(symLocation, normalImport, true);
2921 LoadSymbols(symLocation, preDeclImport, false);
2923 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2926 for(module = defines.first; module; module = next)
2929 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2932 defines.Delete(module);
2937 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2939 SetDefaultDeclMode(privateAccess);
2940 SetDeclMode(privateAccess);
2944 SetDefaultDeclMode(defaultAccess);
2945 SetDeclMode(defaultAccess);
2948 StripExtension(mainModuleName);
2949 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2950 defines.AddName(module);
2953 // SetYydebug(true);
2958 startTime = GetTime();
2959 startFindClass = checkTypeTotalTime;
2963 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2965 CheckDataRedefinitions();
2968 SetIncludeDirs(null);
2969 SetSysIncludeDirs(null);
2980 startTime = GetTime();
2982 PrePreProcessClassDefinitions();
2983 ComputeModuleClasses(privateModule);
2984 PreProcessClassDefinitions();
2985 ProcessClassDefinitions();
2987 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2988 startTime = GetTime();
2993 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2994 startTime = GetTime();
2996 ProcessInstantiations();
2998 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
3001 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
3003 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
3004 if(!windowClass || windowClass.internalDecl)
3007 startTime = GetTime();
3009 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
3010 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
3011 eModule_Load(this.privateModule, "ecere", privateAccess);
3013 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
3016 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
3018 if(windowClass && windowClass.data)
3019 ApplySkin(windowClass, app.currentSkin.name, null);
3023 startTime = GetTime();
3025 for(external = ast->first; external; external = external.next)
3027 if(external.type == classExternal)
3029 ClassDefinition _class = external._class;
3030 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
3032 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
3035 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
3037 Instance instance = eInstance_New(regClass);
3038 ObjectInfo classObject
3040 name = CopyString(_class._class.name);
3041 instance = instance;
3042 classDefinition = _class;
3043 oClass = classObject;
3046 classes.Add(classObject);
3050 // Moved this at bottom so that the file dialog doesn't show up in eCom
3051 designer.CreateObject(instance, classObject, true, null);
3052 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
3054 if(_class.definitions)
3058 for(def = _class.definitions->first; def; def = def.next)
3062 case defaultPropertiesClassDef:
3065 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3067 Identifier id = propDef.identifiers->first;
3070 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3073 Class propertyClass = prop.dataTypeClass;
3075 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3076 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3078 Expression computed;
3079 bool variable = true;
3081 FreeType(propDef.initializer.exp.destType);
3082 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3083 ProcessExpressionType(propDef.initializer.exp);
3085 computed = CopyExpression(propDef.initializer.exp);
3086 ComputeExpression(computed);
3087 if(computed.isConstant)
3089 switch(computed.type)
3092 if(propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3094 String temp = new char[strlen(computed.string)+1];
3095 ReadString(temp, computed.string);
3096 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3099 if(!propDef.initializer.exp.intlString)
3101 Map<String, bool> i18nStrings = classObject.i18nStrings;
3103 classObject.i18nStrings = i18nStrings = { };
3104 i18nStrings[prop.name] = false;
3110 if((propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass) && !id.next)
3114 if(computed.instance._class && computed.instance._class.symbol &&
3115 computed.instance._class.symbol.registered &&
3116 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3118 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3120 // This was saved in the control and shouldn't be freed by FreeExpression...
3121 // (Not doing this anymore, incrementing refCount in pass15 instead)
3122 /*if(propertyClass.type == normalClass)
3123 computed.instance.data = null;*/
3131 Operand value = GetOperand(computed);
3132 DataValue valueData;
3133 valueData.i64 = value.i64;
3134 SetProperty(prop, instance, valueData);
3141 propDef.variable = true;
3142 FreeExpression(computed);
3147 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3148 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3149 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3152 // Maintain a list in FunctionDefinition of who is attached to it
3153 for(def = _class.definitions->first; def; def = def.next)
3155 if(def.type == functionClassDef)
3157 ClassFunction function = def.function;
3158 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3160 function.attached.Add(OldLink { data = method });
3170 case declarationClassDef:
3172 Declaration decl = def.decl;
3175 case instDeclaration:
3177 Instantiation inst = decl.inst;
3178 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3179 if(instClass && eClass_GetDesigner(instClass))
3181 Instance control = eInstance_New(instClass);
3186 oClass = classObject;
3190 classObject.instances.Add(object);
3192 // TOCHECK: Why is this needed now?
3193 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3194 def.object = object;
3196 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3198 designer.CreateObject(control, object, false, classObject.instance);
3199 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3209 // Second pass, process instantiation members
3211 for(def = _class.definitions->first; def; def = def.next)
3215 case declarationClassDef:
3217 Declaration decl = def.decl;
3220 case instDeclaration:
3222 Instantiation inst = decl.inst;
3223 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3224 if(instClass && eClass_GetDesigner(instClass))
3227 object = object ? object.next : classObject.instances.first;
3228 control = object.instance;
3232 MembersInit members;
3233 for(members = inst.members->first; members; members = members.next)
3235 switch(members.type)
3237 case dataMembersInit:
3239 if(members.dataMembers)
3242 DataMember curMember = null;
3243 Class curClass = null;
3244 DataMember subMemberStack[256];
3245 int subMemberStackPos = 0;
3247 for(member = members.dataMembers->first; member; member = member.next)
3250 Identifier ident = member.identifiers ? member.identifiers->first : null;
3253 DataMember _subMemberStack[256];
3254 int _subMemberStackPos = 0;
3255 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3259 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3261 if(thisMember && thisMember.memberAccess == publicAccess)
3263 curMember = thisMember;
3264 curClass = curMember._class;
3265 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3266 subMemberStackPos = _subMemberStackPos;
3272 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3273 if(curMember) found = true;
3275 if(found && curMember.isProperty)
3277 Property prop = (Property) curMember;
3278 Class propertyClass = prop.dataTypeClass;
3279 bool variable = false;
3281 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3283 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3285 FreeType(member.initializer.exp.destType);
3286 member.initializer.exp.destType = MkClassType(propertyClass.name);
3289 Expression computed;
3291 ProcessExpressionType(member.initializer.exp);
3293 computed = CopyExpression(member.initializer.exp);
3296 bool isClass = propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass;
3299 /*char debugExpString[4096];
3300 debugExpString[0] = '\0';
3301 PrintExpression(member.initializer.exp, debugExpString);*/
3303 ComputeExpression(computed);
3305 switch(computed.type)
3308 if(isClass && computed.isConstant && computed.instance.data)
3310 if(computed.instance._class && computed.instance._class.symbol &&
3311 computed.instance._class.symbol.registered &&
3312 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3314 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3316 // This was saved in the control and shouldn't be freed by FreeExpression...
3317 // (Not doing this anymore, incrementing refCount in pass15 instead)
3318 /*if(propertyClass.type == normalClass)
3319 computed.instance.data = null;*/
3325 if(isClass && eClass_GetDesigner(propertyClass))
3328 char * name = computed.identifier.string;
3329 if(!strcmp(name, "this"))
3332 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3338 for(check = classObject.instances.first; check; check = check.next)
3339 if(check.name && !strcmp(name, check.name))
3342 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3352 if(computed.member.exp.type == identifierExp)
3354 char * name = computed.member.exp.identifier.string;
3356 if(!strcmp(name, "this"))
3358 char * name = computed.member.member.string;
3360 for(check = classObject.instances.first; check; check = check.next)
3361 if(check.name && !strcmp(name, check.name))
3364 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3371 for(check = classObject.instances.first; check; check = check.next)
3373 if(check.name && !strcmp(name, check.name))
3375 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3378 DataValue value { };
3379 GetProperty(getProperty, check.instance, &value);
3380 SetProperty(prop, control, value);
3391 if(propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3393 String temp = new char[strlen(computed.string)+1];
3394 ReadString(temp, computed.string);
3395 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3398 if(!member.initializer.exp.intlString)
3400 Map<String, bool> i18nStrings = object.i18nStrings;
3402 object.i18nStrings = i18nStrings = { };
3403 i18nStrings[prop.name] = false;
3410 if(computed.isConstant)
3412 if((!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *")))
3414 if(!strcmp(propertyClass.dataTypeString, "float"))
3415 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3416 else if(!strcmp(propertyClass.dataTypeString, "double"))
3417 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3419 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3427 FreeExpression(computed);
3431 member.variable = true;
3433 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3434 member.initializer.exp.type == memberExp) // identifierExp
3436 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3437 if(method && method.type == virtualMethod)
3440 // Maintain a list in FunctionDefinition of who is attached to it
3441 for(def = _class.definitions->first; def; def = def.next)
3443 if(def.type == functionClassDef)
3445 ClassFunction function = def.function;
3446 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3447 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3449 function.attached.Add(OldLink { data = method });
3450 // Reference this particular instance?
3465 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3476 //designer.CreateObject(instance, classObject, true, null);
3477 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3479 designer.PostCreateObject(instance, classObject, true, null);
3481 //instance.state = Hidden;
3482 //instance.Create();
3483 //instance.SetState(Normal, true, 0);
3492 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3496 // Restore Selection
3497 if(selectedClassName)
3500 for(oClass = classes.first; oClass; oClass = oClass.next)
3502 if(!strcmp(oClass.name, selectedClassName))
3504 this.oClass = oClass;
3508 delete selectedClassName;
3517 for(check = this.oClass.instances.first; check; check = check.next)
3519 if(check.name && !strcmp(check.name, selectedName))
3521 this.selected = check;
3527 if(this.oClass.instances.first)
3528 this.selected = this.oClass.instances.first;
3530 this.selected = this.oClass;
3533 else if(selectedPos == -1 || !this.oClass.instances.count)
3534 this.selected = this.oClass;
3540 if(selectedPos > this.oClass.instances.count)
3542 for(check = this.oClass.instances.first; check; check = check.next)
3544 if(selectedPos == pos++)
3546 this.selected = check;
3554 this.oClass = classes.first;
3555 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3557 delete selectedName;
3558 SetSymbolsDir(null);
3560 if(sheet.codeEditor == this)
3561 sheet.SelectObject(selected);
3564 codeModified = false;
3566 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3569 InvokeParameters(false, false, false);
3572 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3578 ChangeWorkingDir(oldWorkDir);
3580 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3581 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3582 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3583 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3584 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3586 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3588 if(inUseDebug && ide.projectView)
3589 ide.debugger.EvaluateWatches();
3594 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3597 Window control = (Window)object.instance;
3598 ObjectInfo classObject = object.oClass;
3600 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3602 if(!strcmp(_class.name, "DesignerBase")) return;
3604 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3606 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3607 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3609 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3610 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3612 Class dataType = prop.dataTypeClass;
3614 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3618 if(dataType.type == structClass)
3620 void * dataForm = new0 byte[dataType.structSize];
3621 void * dataTest = new0 byte[dataType.structSize];
3623 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3624 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3626 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3628 char tempString[1024] = "";
3630 bool needClass = true;
3634 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3636 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3638 eClass_FindNextMember(_class, curClass, curMember, null, null);
3639 if(*curMember != (DataMember)prop)
3640 f.Printf("%s = ", prop.name);
3642 *curMember = (DataMember)prop;
3643 *curClass = curMember->_class;
3646 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3648 f.Printf("%s", string);
3655 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3657 void * dataForm, * dataTest;
3658 bool isEditBoxContents = false;
3659 bool freeDataForm = false, freeDataTest = false;
3661 // Because contents property is broken for mutiline EditBox at the moment
3662 if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox"))
3663 isEditBoxContents = true;
3665 if(isEditBoxContents && ((EditBox)control).multiLine)
3667 dataForm = ((EditBox)control).multiLineContents;
3668 freeDataForm = true;
3671 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3672 if(isEditBoxContents && ((EditBox)test).multiLine)
3674 dataTest = ((EditBox)test).multiLineContents;
3675 freeDataTest = true;
3678 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3680 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3682 char tempString[1024] = "";
3687 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3689 eClass_FindNextMember(_class, curClass, curMember, null, null);
3690 if(*curMember != (DataMember)prop)
3691 f.Printf("%s = ", prop.name);
3692 *curMember = (DataMember)prop;
3693 *curClass = curMember->_class;
3695 if(eClass_GetDesigner(dataType))
3697 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3698 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3699 f.Printf("this", prop.name);
3702 //ObjectInfo classObject;
3703 //for(classObject = classes.first; classObject; classObject = classObject.next)
3707 for(object = classObject.instances.first; object; object = object.next)
3709 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3711 f.Printf("%s", object.name);
3718 bool needClass = true;
3719 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3720 f.Printf("%s", string);
3727 bool needClass = true;
3728 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3730 if(!strcmp(dataType.dataTypeString, "char *"))
3732 Map<String, bool> i18nStrings = object.i18nStrings;
3734 if(i18nStrings && i18nStrings.GetAtPosition(prop.name, false))
3737 f.Printf("%s\"", i18n ? "$" : "");
3738 OutputString(f, string);
3742 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3744 f.Printf("%s", string);
3747 *lastIsMethod = false;
3750 if(freeDataForm) delete dataForm;
3751 if(freeDataTest) delete dataTest;
3755 DataValue dataForm, dataTest;
3757 GetProperty(prop, control, &dataForm);
3758 GetProperty(prop, test, &dataTest);
3760 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3763 char tempString[1024] = "";
3764 SetProperty(prop, test, dataForm);
3766 if(dataType.type != bitClass)
3768 bool needClass = true;
3770 if(dataType.type == enumClass)
3773 Class enumClass = eSystem_FindClass(privateModule, "enum");
3774 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3776 for(value = e.values.first; value; value = value.next)
3778 if((int)value.data == dataForm.i)
3780 string = value.name;
3786 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3788 if(string && string[0])
3793 eClass_FindNextMember(_class, curClass, curMember, null, null);
3794 if(*curMember != (DataMember)prop)
3795 f.Printf("%s = ", prop.name);
3796 *curMember = (DataMember)prop;
3797 *curClass = curMember->_class;
3799 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3800 f.Printf("%sf", string);
3802 f.Printf("%s", string);
3806 else if(dataType.type == bitClass)
3808 bool needClass = true;
3810 if(*prev) f.Printf(", ");
3812 eClass_FindNextMember(_class, curClass, curMember, null, null);
3813 if(*curMember != (DataMember)prop)
3814 f.Printf("%s = ", prop.name);
3815 *curMember = (DataMember)prop;
3816 *curClass = curMember->_class;
3818 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3820 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3822 f.Printf("%s", string);
3824 *lastIsMethod = false;
3834 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3836 Instantiation inst = object.instCode;
3837 Window control = (Window)object.instance;
3839 bool methodPresent = false;
3841 bool lastIsMethod = true;
3842 ObjectInfo classObject = object.oClass;
3848 // Instance removed, delete it
3849 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3851 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3852 position = inst.loc.end.pos + 1;
3856 bool multiLine = false;
3859 // Check if it's an unnamed instance
3862 f.Seek(inst.nameLoc.start.pos - position, current);
3863 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3864 position = inst.nameLoc.end.pos;
3866 f.Printf(object.name);
3871 if(isspace(ch) && ch != '\n')
3873 f.Seek(-1, current);
3881 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3883 f.Seek(pos - position, current);
3888 f.Seek(-1, current);
3897 f.Puts(object.name);
3902 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3903 methodPresent = true;
3911 if(ch == OpenBracket)
3917 // TODO: Simplify this?
3926 f.Seek(-1, current);
3927 DeleteJunkBefore(f, position, &position);
3939 if(ch == '\n') { toDelete = count; count = 0; }
3940 else if(isspace(ch)) count++;
3943 f.Seek(-1, current);
3947 toDelete += count - 6;
3957 f.Seek(-toDelete-count, current);
3958 f.DeleteBytes(toDelete);
3959 f.Seek(count, current);
3962 DeleteJunkBefore(f, position, &position);
3964 // Removed this here as it was adding trailing spaces when adding a method
3969 for(c = 0; c<toAdd; c++)
3976 methodPresent = multiLine;
3978 //if(!prev) -- always false
3979 f.Printf(methodPresent ? "\n " : " ");
3984 // Instance not there, create a brand new one
3985 DeleteJunkBefore(f, position, &position);
3986 f.Printf(*firstObject ? "\n\n" : "\n");
3987 *firstObject = false;
3989 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3990 methodPresent = true;
3995 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3997 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
4002 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
4004 f.Printf(" %s %c ", control._class.name, OpenBracket);
4010 Instance test = eInstance_New(control._class);
4011 DataMember curMember = null;
4012 Class curClass = null;
4015 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
4019 // Attach Method here
4020 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
4022 if(prev) f.Printf(", ");
4023 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
4028 if(inst && !object.deleted)
4030 MembersInit members;
4031 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
4033 DeleteJunkBefore(f, position, &position);
4035 // Instance already there, clear out the properties
4036 for(members = inst.members ? inst.members->first : null; members; members = members.next)
4038 if(members.type == dataMembersInit)
4042 if(members.dataMembers)
4044 bool keptMember = false;
4045 MemberInit lastKept = null;
4047 for(member = members.dataMembers->first; member; member = member.next)
4049 Identifier ident = member.identifiers ? member.identifiers->first : null;
4050 bool deleted = false;
4052 // For now delete if it's not a method
4053 if(!member.variable) // && ident)
4055 if(!ident || !ident.next)
4057 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
4060 f.Seek(member.loc.start.pos - position, current);
4061 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4062 position = member.loc.end.pos;
4067 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
4068 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
4069 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4071 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
4072 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
4074 f.Seek(member.loc.start.pos - position, current);
4075 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4076 position = member.loc.end.pos;
4088 //f.Seek(member.loc.start.pos - position, current);
4089 //position = member.loc.start.pos;
4090 DeleteJunkBefore(f, member.loc.start.pos, &position);
4091 if(prev) f.Printf(", ");
4092 else if(keptMember) f.Printf(" ");
4097 if(!keptMember || !members.next)
4102 if(keptMember && lastKept != members.dataMembers->last)
4107 f.Seek(-1, current);
4113 f.Seek(-1, current);
4116 else if(!isspace(ch))
4118 f.Seek(-2, current);
4123 f.DeleteBytes(count);
4126 f.Seek(members.loc.end.pos - position, current);
4131 f.Seek(-1, current);
4133 position = members.loc.end.pos + 1;
4137 f.Seek(-1, current);
4138 position = members.loc.end.pos;
4144 lastIsMethod = false;
4149 DeleteJunkBefore(f, position, &position);
4152 if(lastKept != members.dataMembers->last)
4157 f.Seek(-1, current);
4163 f.Seek(-1, current);
4166 else if(!isspace(ch))
4168 f.Seek(-2, current);
4173 f.DeleteBytes(count);
4177 f.Seek(members.loc.end.pos - position, current);
4178 position = members.loc.end.pos;
4182 lastIsMethod = true;
4185 lastIsMethod = false;
4191 f.Seek(members.loc.end.pos - position, current);
4192 position = members.loc.end.pos;
4194 lastIsMethod = true;
4197 else if(members.type == methodMembersInit)
4199 if(this.methodAction == actionDeleteMethod && members.function == function);
4201 methodPresent = true;
4203 // Delete instance method here
4204 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4205 members.function == function)
4207 if(this.moveAttached && !*text)
4208 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4210 DeleteJunkBefore(f, members.loc.start.pos, &position);
4211 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4212 position = members.loc.end.pos + 1;
4217 DeleteJunkBefore(f, position, &position);
4221 DeleteJunkBefore(f, members.loc.start.pos, &position);
4222 lastIsMethod = true;
4226 f.Seek(members.loc.end.pos - position, current);
4227 position = members.loc.end.pos;
4229 DeleteJunkBefore(f, position, &position);
4238 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4240 Method method = this.method;
4241 DeleteJunkBefore(f, position, &position);
4247 if(!method.dataType)
4248 method.dataType = ProcessTypeString(method.dataTypeString, false);
4251 Type dataType = method.dataType;
4252 Type returnType = dataType.returnType;
4255 if(this.moveAttached)
4257 // Move function here:
4258 int newLen = strlen(method.name);
4263 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4265 // First change name of function
4266 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4267 *textSize += newLen - movedFuncIdLen;
4268 memcpy(*text + movedFuncIdPos, method.name, newLen);
4270 // Second, tab right
4273 for(c = 0; (*text)[c]; )
4276 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4279 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4280 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4284 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4294 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4296 // ADDING METHOD HERE
4298 OutputType(f, returnType, false);
4301 if(dataType.thisClass)
4303 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4305 if(dataType.thisClass.shortName)
4306 f.Printf(dataType.thisClass.shortName);
4308 f.Printf(dataType.thisClass.string);
4312 f.Printf(method.name);
4314 for(param = dataType.params.first; param; param = param.next)
4316 OutputType(f, param, true);
4321 f.Printf(" %c\n\n", OpenBracket);
4323 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4325 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4326 f.Printf(" return true;\n");
4327 else if(returnType.kind != voidType)
4328 f.Printf(" return 0;\n");
4333 if(returnType.kind != voidType)
4334 f.Printf("return ");
4335 f.Printf("%s::%s(", control._class.name, method.name);
4336 for(param = dataType.params.first; param; param = param.next)
4338 if(param.prev) f.Printf(", ");
4339 if(param.kind != voidType)
4340 f.Printf(param.name);
4344 f.Printf(" %c\n", CloseBracket);
4350 if(!object.instCode)
4351 f.Printf(methodPresent ? " %c;" : "%c;", CloseBracket);
4352 else if(!object.deleted)
4354 // Turn this into a multiline instance when adding a method
4355 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4357 f.Printf(methodPresent ? "\n " : " ");
4359 f.Seek(inst.loc.end.pos + 1 - position, current);
4360 position = inst.loc.end.pos + 1;
4365 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4368 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4370 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4372 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4374 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4375 if(prop && prop.isProperty && !prop.conversion)
4377 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4378 (!prop.IsSet || prop.IsSet(classObject.instance)))
4380 Class dataType = prop.dataTypeClass;
4381 char tempString[1024] = "";
4383 bool specify = false;
4386 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4387 if(member && member._class == regClass)
4391 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4393 if(dataType && dataType.type == structClass)
4395 void * dataForm = new0 byte[dataType.structSize];
4396 void * dataTest = new0 byte[dataType.structSize];
4398 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4399 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4401 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4403 bool needClass = true;
4405 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4406 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4408 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4410 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4415 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4417 void * dataForm, * dataTest;
4418 bool isEditBoxContents = false;
4419 bool freeDataForm = false, freeDataTest = false;
4421 // Because contents property is broken for mutiline EditBox at the moment
4422 if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox"))
4423 isEditBoxContents = true;
4425 if(isEditBoxContents && ((EditBox)classObject.instance).multiLine)
4427 dataForm = ((EditBox)classObject.instance).multiLineContents;
4428 freeDataForm = true;
4431 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4432 if(isEditBoxContents && ((EditBox)test).multiLine)
4434 dataTest = ((EditBox)test).multiLineContents;
4435 freeDataTest = true;
4438 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4440 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4442 char tempString[1024] = "";
4444 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4446 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4448 // Shouldn't go here ...
4449 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4453 bool needClass = true;
4455 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4457 if(!strcmp(dataType.dataTypeString, "char *"))
4459 Map<String, bool> i18nStrings = classObject.i18nStrings;
4461 if(i18nStrings && i18nStrings.GetAtPosition(prop.name, false))
4464 f.Printf("\n %s%s = %s\"", specify ? "property::" : "", prop.name, i18n ? "$" : "");
4465 OutputString(f, string);
4469 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4471 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4474 if(freeDataForm) delete dataForm;
4475 if(freeDataTest) delete dataTest;
4479 DataValue dataForm, dataTest;
4481 GetProperty(prop, classObject.instance, &dataForm);
4482 GetProperty(prop, test, &dataTest);
4484 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4486 SetProperty(prop, test, dataForm);
4487 if(dataType.type == bitClass)
4489 bool needClass = true;
4490 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4492 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4494 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4498 bool needClass = true;
4499 if(dataType.type == enumClass)
4502 Class enumClass = eSystem_FindClass(privateModule, "enum");
4503 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4505 for(value = e.values.first; value; value = value.next)
4507 if((int)value.data == dataForm.i)
4509 string = value.name;
4515 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4516 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4517 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4519 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4528 void UpdateFormCode()
4531 if(!parsing) return;
4538 else if(formModified)
4540 EditBoxStream f { editBox = editBox };
4544 Identifier movedFuncId;
4545 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4546 ObjectInfo classObject;
4552 movedFuncId = GetDeclId(function.declarator);
4553 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4554 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4557 for(classObject = classes.first; classObject; classObject = classObject.next)
4560 ClassDefinition classDef = classObject.classDefinition;
4561 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4564 bool firstObject = true;
4565 ObjectInfo object = classObject.instances.first;
4566 bool lastIsDecl = false;
4568 if(!classObject.modified) continue;
4570 test = eInstance_New(regClass);
4573 // Put it in the same desktop window...
4574 designer.PrepareTestObject(test);
4576 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4577 //f.Printf("%c\n\n", OpenBracket);
4579 // Change the _class name
4580 f.Seek(classDef.nameLoc.start.pos - position, current);
4581 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4582 f.Printf(classObject.name);
4583 position = classDef.nameLoc.end.pos;
4586 // Go to block start, delete all until no white space, put \n
4590 f.Seek(classDef.blockStart.end.pos - position, current);
4591 position = classDef.blockStart.end.pos;
4593 for(; f.Getc(&ch); count++)
4597 f.Seek(-1, current);
4607 f.Seek(-count, current);
4609 f.DeleteBytes(count-back);
4611 position += count-back;
4614 // Output properties
4615 OutputClassProperties(classObject.instance._class, classObject, f, test);
4617 for(def = classDef.definitions->first; def; def = def.next)
4621 case defaultPropertiesClassDef:
4623 bool keptMember = false;
4625 MemberInit lastKept = null;
4628 DeleteJunkBefore(f, def.loc.start.pos, &position);
4630 // This was adding blank spaces between comment and properties -- What was it for?
4633 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4635 Identifier ident = propDef.identifiers->first;
4636 bool deleted = false;
4638 // For now delete if it's a prop
4639 if(!propDef.variable && ident)
4643 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4646 f.Seek(propDef.loc.start.pos - position, current);
4647 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4648 position = propDef.loc.end.pos;
4653 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4654 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4656 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4657 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4659 f.Seek(propDef.loc.start.pos - position, current);
4660 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4661 position = propDef.loc.end.pos;
4679 f.Seek(def.loc.end.pos - position - 1, current);
4684 f.Seek(-1, current);
4687 position = def.loc.end.pos;
4691 if(lastKept != def.defProperties->last)
4696 f.Seek(-1, current);
4702 f.Seek(-1, current);
4705 else if(!isspace(ch))
4707 f.Seek(-2, current);
4712 f.DeleteBytes(count);
4716 f.Seek(def.loc.end.pos - position, current);
4717 position = def.loc.end.pos;
4722 case declarationClassDef:
4724 Declaration decl = def.decl;
4726 if(decl.type == instDeclaration)
4728 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4730 while(def.object && object != def.object)
4732 if(object /*&& ((ObjectInfo)def.object).modified*/)
4733 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4734 object = object.next;
4737 DeleteJunkBefore(f, def.loc.start.pos, &position);
4738 f.Printf(firstObject ? "\n\n " : "\n ");
4739 firstObject = false;
4741 if(def.object && ((ObjectInfo)def.object).modified)
4742 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4744 object = object ? object.next : null;
4748 DeleteJunkBefore(f, def.loc.start.pos, &position);
4749 f.Printf(firstObject ? "\n\n " : "\n ");
4750 firstObject = false;
4756 DeleteJunkBefore(f, def.loc.start.pos, &position);
4757 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4762 case functionClassDef:
4764 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4765 if(!def.function.body) continue;
4769 DeleteJunkBefore(f, def.loc.start.pos, &position);
4772 // Delete _class methods
4773 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4774 def.function == function)
4779 if(moveAttached && !text)
4781 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4784 f.Seek(def.loc.end.pos - position, current);
4785 for(; f.Getc(&ch); count++)
4789 f.Seek(-1, current);
4793 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4795 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4796 position = def.loc.end.pos + count;
4799 // In case of detaching methods in the _class, simply rename the method
4800 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4802 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4803 f.DeleteBytes(movedFuncIdLen);
4805 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4808 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4809 function == def.function)
4811 // In case of attaching methods in the _class, simply rename the method
4812 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4813 position = function.loc.start.pos + movedFuncIdPos;
4814 f.DeleteBytes(movedFuncIdLen);
4815 if(method.dataType.thisClass)
4816 f.Printf("%s::", method.dataType.thisClass.string);
4817 f.Puts(method.name);
4818 position += movedFuncIdLen;
4823 DeleteJunkBefore(f, def.loc.start.pos, &position);
4824 if(def.type == memberAccessClassDef)
4827 firstObject = false;
4837 f.Seek(def.loc.end.pos - position, current);
4838 position = def.loc.end.pos;
4841 // Output attached methods
4842 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4844 DeleteJunkBefore(f, position, &position);
4845 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4848 // ********** INSTANCES ***************
4849 for(; object; object = object.next)
4851 if(!object.instCode)
4853 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4857 DeleteJunkBefore(f, position, &position);
4859 // ****************** METHODS ***********************
4860 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4862 // If detaching an instance method
4863 if(selected != classObject)
4865 int newLen = strlen(methodName);
4868 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4869 // Tab selection left
4872 for(c = 0; text[c]; )
4875 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4876 memmove(text+start, text+start+i, textSize+1-start-i);
4879 for(; text[c] && text[c] != '\n'; c++);
4885 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4886 textSize += newLen - movedFuncIdLen;
4887 memcpy(text + movedFuncIdPos, methodName, newLen);
4894 if(methodAction == actionAddMethod && selected == classObject)
4896 Method method = this.method;
4898 if(!method.dataType)
4899 method.dataType = ProcessTypeString(method.dataTypeString, false);
4901 // ADDING METHOD HERE
4903 Type dataType = method.dataType;
4904 Type returnType = dataType.returnType;
4906 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4910 OutputType(f, returnType, false);
4913 if(dataType.thisClass && !dataType.classObjectType)
4915 if(dataType.thisClass.shortName)
4916 f.Printf(dataType.thisClass.shortName);
4918 f.Printf(dataType.thisClass.string);
4921 f.Printf(method.name);
4923 for(param = dataType.params.first; param; param = param.next)
4925 OutputType(f, param, true);
4930 f.Printf(" %c\n\n", OpenBracket);
4932 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4934 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4935 f.Printf(" return true;\n");
4936 else if(returnType && returnType.kind != voidType)
4937 f.Printf(" return 0;\n");
4942 if(returnType.kind != voidType)
4943 f.Printf("return ");
4945 char * name = ((Specifier)classDef.baseSpecs->first).name;
4946 Symbol _class = FindClass(name);
4947 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4949 for(param = dataType.params.first; param; param = param.next)
4951 if(param.prev) f.Printf(", ");
4952 if(param.kind != voidType)
4953 f.Printf(param.name);
4958 f.Printf(" %c", CloseBracket);
4962 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4974 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4975 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4979 codeModified = false;
4980 formModified = false;
4982 moveAttached = false;
4987 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4990 ClassFunction function = null;
4993 ObjectInfo object = this.selected;
4995 if(object && object == this.oClass)
4997 ClassDefinition classDef = object.oClass.classDefinition;
4999 if(classDef && classDef.definitions)
5001 for(def = classDef.definitions->first; def; def = def.next)
5003 if(def.type == functionClassDef && def.function.declarator)
5005 if(!strcmp(def.function.declarator.symbol.string, methodName))
5007 function = def.function;
5012 else if(def.type == defaultPropertiesClassDef)
5016 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
5018 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
5019 if(ident && !ident.next)
5021 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
5025 propLoc = propDef.loc;
5028 ClassDefinition classDef = object.oClass.classDefinition;
5030 if(classDef.definitions)
5032 for(def = classDef.definitions->first; def; def = def.next)
5034 if(def.type == functionClassDef)
5036 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
5038 function = def.function;
5057 Instantiation inst = object.instCode;
5059 // Check here to see if the method already exists, no need to call ModifyCode in that case
5060 if(inst && inst.members)
5062 MembersInit members;
5063 for(members = inst.members->first; members; members = members.next)
5065 switch(members.type)
5067 case dataMembersInit:
5069 if(members.dataMembers)
5072 for(member = members.dataMembers->first; member; member = member.next)
5074 Identifier ident = member.identifiers ? member.identifiers->first : null;
5075 if(ident && !ident.next)
5077 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
5081 propLoc = member.loc;
5084 ClassDefinition classDef = object.oClass.classDefinition;
5086 if(classDef.definitions)
5088 for(def = classDef.definitions->first; def; def = def.next)
5090 if(def.type == functionClassDef)
5092 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
5094 function = def.function;
5103 // TODO: Fix memory leak
5104 function = ClassFunction
5106 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5118 case methodMembersInit:
5120 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5122 function = members.function;
5134 if(functionPtr) *functionPtr = function;
5138 void GoToMethod(char * methodName /*Method method*/)
5142 ObjectInfo object = selected;
5143 EditBoxStream f { editBox = editBox };
5144 ClassFunction function = null;
5145 bool atChar = false;
5149 Location propLoc = { {0,0,-1} };
5152 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5153 if(function && function.body)
5156 f.Seek(function.body.loc.start.pos+1, current);
5166 f.Seek(-1, current);
5171 else if(!isspace(ch))
5173 f.Seek(-1, current);
5179 else if(propLoc.start.pos > -1)
5181 f.Seek(propLoc.start.pos, current);
5184 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5186 if(function || propLoc.start.pos > -1)
5188 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5189 editBox.CenterOnCursor();
5190 SetState(normal, false, 0);
5193 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5195 FreeClassFunction(function);
5201 void FindCompatibleMethods(Method method, OldList compatible)
5203 ClassDefinition classDef = this.oClass.classDefinition;
5204 if(classDef && classDef.definitions)
5207 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5210 Symbol classSym { };
5211 Symbol selectedClass;
5212 if(this.selected == this.oClass)
5213 selectedClass = classSym;
5215 selectedClass = FindClass(this.selected.instance._class.name);
5217 regClass.name = classDef._class.name;
5218 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5219 for(def = classDef.definitions->first; def; def = def.next)
5221 if(def.type == functionClassDef && def.function.declarator)
5223 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5225 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5228 Type type = def.function.declarator.symbol.type;
5229 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5231 compatible.Add(OldLink { data = def.function });
5237 if(this.oClass && this.oClass.instance)
5239 classSym.registered = regClass;
5240 //classSym.registered = this.oClass.oClass;
5242 for(_class = regClass.base; _class; _class = _class.base)
5245 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5247 // TODO: Understand why these functions popup in attach list
5248 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5250 if(!testMethod.dataType)
5251 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5253 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5254 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5255 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5257 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5258 // ClassFunction function { };
5259 FunctionDefinition function { };
5261 function.declarator = Declarator { };
5262 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5263 excludedSymbols.Add(function.declarator.symbol);
5265 compatible.Add(OldLink { data = function });
5276 void AddMethod(Method method)
5280 char methodName[1024];
5281 strcpy(methodName, method.name);
5282 if(!FindMethod(methodName, null, null))
5284 methodAction = actionAddMethod;
5285 this.method = method;
5289 GoToMethod(methodName);
5293 void DeleteMethod(ClassFunction function)
5297 methodAction = actionDeleteMethod;
5298 this.function = function;
5306 void AttachMethod(Method method, ClassFunction function)
5310 // If it's an instance we'll ask if we want to move it inside...
5311 if(!function.attached.count && function.body)
5313 // Find the function in the _class to check if it's a virtual function
5314 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5315 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5316 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5318 for(def = this.classDefinition.first; def; def = def.next)
5320 if(def.type == functionClassDef)
5322 if(def.function == function)
5327 if(!method || method.type != virtualMethod)
5330 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5331 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5333 moveAttached = true;
5338 methodAction = actionAttachMethod;
5339 this.method = method;
5340 this.function = function;
5347 void ReAttachMethod(Method method, ClassFunction function)
5351 // If it's an instance we'll ask if we want to move it inside...
5352 if(!function.attached.count && function.body)
5354 // Find the function in the _class to check if it's a virtual function
5355 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5356 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5357 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5359 for(def = this.classDefinition.first; def; def = def.next)
5361 if(def.type == functionClassDef)
5363 if(def.function == function)
5368 if(!method || method.type != virtualMethod)
5371 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5372 if(MessageBox { type = yesNo, master = parent, text = title,
5373 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5375 moveAttached = true;
5380 methodAction = actionReattachMethod;
5381 this.method = method;
5382 this.function = function;
5389 void DetachMethod(Method method, ClassFunction function, int type)
5397 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5398 master = sheet, text = $"Name detached method", background = formColor
5402 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5403 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5407 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5408 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5412 dialog, anchor = { left = 5, right = 5, top = 5 }
5414 sprintf(methodName, "%s_%s", selected.name, method.name);
5415 nameBox.contents = methodName;
5417 result = dialog.Modal() == ok;
5418 strcpy(methodName, nameBox.contents);
5423 // If the method is not attached, move it outside
5426 // Add this class to the methodName
5427 char name[1024] = "";
5429 if(this.selected != this.oClass && !method.dataType.thisClass)
5431 strcat(name, this.selected.instance._class.name);
5433 strcat(name, this.methodName);
5434 strcpy(this.methodName, name);
5436 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5438 strcat(name, method.dataType.thisClass.string);
5440 strcat(name, this.methodName);
5441 strcpy(this.methodName, name);
5444 this.moveAttached = true;
5447 this.methodAction = actionDetachMethod;
5448 this.method = method;
5449 this.function = function;
5456 void AddObject(Instance instance, ObjectInfo * object)
5460 //*object = _class.instances.Add(sizeof(ObjectInfo));
5461 *object = ObjectInfo { };
5462 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5463 (*object).oClass = oClass;
5464 (*object).instance = instance;
5469 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5471 // if(strcmp(name, this.oClass.instance.name))
5474 for(check = oClass.instances.first; check; check = check.next)
5475 if(!check.deleted && check.name && !strcmp(name, check.name))
5479 (*object).name = CopyString(name);
5484 toolBox.controlClass = null;
5488 //sheet.AddObject(*object, (*object).name, TypeData, true);
5493 void EnsureUpToDate()
5495 if(sheet && codeModified && parsing)
5499 void SelectObject(ObjectInfo object)
5502 oClass = object ? object.oClass : null;
5504 designer.SelectObject(object, object ? object.instance : null);
5507 void SelectObjectFromDesigner(ObjectInfo object)
5510 sheet.SelectObject(object);
5513 void EnumerateObjects(Sheet sheet)
5517 for(oClass = classes.first; oClass; oClass = oClass.next)
5523 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5524 for(object = oClass.instances.first; object; object = object.next)
5525 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5528 sheet.SelectObject(selected);
5533 designer.AddObject();
5536 void DeleteObject(ObjectInfo object)
5538 delete object.instance;
5539 object.deleted = true;
5540 object.modified = true;
5541 object.oClass.modified = true;
5542 if(object.i18nStrings)
5544 Map<String, bool> i18nStrings = object.i18nStrings;
5548 if(selected == object)
5550 bool looped = false;
5551 ObjectInfo select = object;
5555 select = select.prev;
5559 select = object.oClass.instances.last;
5566 sheet.SelectObject(select ? select : oClass);
5569 if(!object.instCode && object.oClass != object)
5572 oClass.instances.Delete(object);
5575 if(sheet.codeEditor == this)
5576 sheet.DeleteObject(object);
5579 void RenameObject(ObjectInfo object, char * name)
5583 // Validate the name:
5584 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5585 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5588 for(c = 0; name[c]; c++)
5589 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5597 object.name = (name && name[0]) ? CopyString(name) : null;
5599 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5603 void DesignerModifiedObject()
5605 sheet.ListProperties(false);
5609 void ListSubMembers(Type member)
5613 for(subMember = member.members.first; subMember; subMember = subMember.next)
5617 DataRow row = membersList.AddString(subMember.name);
5618 row.icon = icons[typeData];
5622 ListSubMembers(subMember);
5627 void ListSubDataMembers(DataMember member, bool isPrivate)
5629 DataMember subMember;
5630 for(subMember = member.members.first; subMember; subMember = subMember.next)
5632 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5636 DataRow row = membersList.AddString(subMember.name);
5637 BitmapResource bitmap = null;
5638 if(!subMember.dataType)
5639 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5641 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5643 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5646 bitmap = { bitmapName };
5647 membersList.AddResource(bitmap);
5650 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5654 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5660 void ListClassMembers(Class whatClass, bool methodsOnly)
5663 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5664 bool isPrivate = false;
5666 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5668 Method method, methodIt;
5670 DataMember memberIt;
5672 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5674 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5675 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5677 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5679 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5681 DataRow row = membersList.FindString(method.name);
5684 row = membersList.AddString(method.name);
5686 if(!method.dataType)
5687 method.dataType = ProcessTypeString(method.dataTypeString, false);
5689 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5697 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5701 if(memberIt.isProperty)
5703 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5705 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5709 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5711 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5714 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5720 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5722 if(member.isProperty)
5724 Property prop = (Property) member;
5725 if(!membersList.FindString(prop.name))
5727 DataRow row = membersList.AddString(prop.name);
5728 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5731 else if(member.name && !membersList.FindString(member.name))
5733 DataRow row = membersList.AddString(member.name);
5735 BitmapResource bitmap = null;
5736 if(!member.dataType)
5737 member.dataType = ProcessTypeString(member.dataTypeString, false);
5739 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5741 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5744 bitmap = { bitmapName };
5745 membersList.AddResource(bitmap);
5748 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5751 ListSubDataMembers(member, member.memberAccess == privateAccess);
5755 if(_class.inheritanceAccess == privateAccess)
5758 if(_class.module != privateModule) break;
5763 void ListClassMembersMatch(Class whatClass, Type methodType)
5766 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5767 bool isPrivate = false;
5769 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5775 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5777 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5779 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5781 if(!method.dataType)
5782 method.dataType = ProcessTypeString(method.dataTypeString, false);
5784 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5786 DataRow row = membersList.FindString(method.name);
5789 row = membersList.AddString(method.name);
5790 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5796 if(_class.inheritanceAccess == privateAccess)
5799 if(_class.module != privateModule) break;
5804 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5807 bool isPrivate = false;
5808 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5814 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5816 if(method.type == virtualMethod)
5818 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5820 DataRow row = membersList.FindString(method.name);
5823 row = membersList.AddString(method.name);
5825 if(!method.dataType)
5826 method.dataType = ProcessTypeString(method.dataTypeString, false);
5828 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5834 for(member = _class.membersAndProperties.first; member; member = member.next)
5836 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5838 if(member.isProperty)
5840 Property prop = (Property)member;
5842 DataRow row = membersList.AddString(prop.name);
5843 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5846 else if(member.name && (!curString || strcmp(curString, member.name)))
5848 DataRow row = membersList.AddString(member.name);
5850 BitmapResource bitmap = null;
5851 if(!member.dataType)
5852 member.dataType = ProcessTypeString(member.dataTypeString, false);
5854 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5856 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5859 bitmap = { bitmapName };
5860 membersList.AddResource(bitmap);
5863 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5866 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5869 if(_class.inheritanceAccess == privateAccess)
5872 if(_class.module != privateModule) break;
5877 void ListMembers(Type type)
5879 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5883 if(type.kind == classType)
5886 ListClassMembers(type._class.registered, false);
5891 for(member = type.members.first; member; member = member.next)
5895 DataRow row = membersList.AddString(member.name);
5896 row.icon = icons[typeData];
5898 else if(member.kind == structType || member.kind == unionType)
5899 ListSubMembers(member);
5905 void ListModule(Module mainModule, int recurse, bool listClasses)
5908 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5909 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5910 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5911 for(module = mainModule.application.allModules.first; module; module = module.next)
5913 if(ModuleVisibility(mainModule, module))
5914 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5918 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5925 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5927 Class _class = link.data;
5928 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5930 DataRow row = membersList.AddString(_class.name);
5931 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5936 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5938 DefinedExpression definedExp = link.data;
5939 DataRow row = membersList.AddString(link /*definedExp*/.name);
5940 row.icon = icons[typeData];
5943 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5945 GlobalFunction function = link.data;
5946 DataRow row = membersList.AddString(link /*function*/.name);
5947 row.icon = icons[typeMethod];
5951 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5953 if(recurse != 2 && listClasses)
5955 if(!membersList.FindString(ns->name))
5957 DataRow row = membersList.AddString(ns->name);
5958 row.icon = icons[typeNameSpace];
5963 ListNameSpace(ns, 2, listClasses);
5967 void ListEnumValues(Class _class)
5969 List<Class> classes { };
5970 for(; _class && _class.type == enumClass; _class = _class.base)
5971 classes.Insert(null, _class);
5972 for(_class : classes)
5974 EnumClassData enumeration = (EnumClassData)_class.data;
5976 for(item = enumeration.values.first; item; item = item.next)
5978 DataRow row = membersList.AddString(item.name);
5979 row.icon = icons[typeEnumValue];
5985 bool ListEnumsModule(Module mainModule, Type dest)
5987 bool result = false;
5989 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5990 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5991 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5992 for(module = mainModule.application.allModules.first; module; module = module.next)
5994 if(ModuleVisibility(mainModule, module))
5995 result |= ListEnums(module.publicNameSpace, dest);
6000 void ListNameSpaceByString(Module mainModule, char * string)
6002 NameSpace * nameSpace;
6004 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
6005 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6006 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
6007 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6008 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
6009 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6010 for(module = mainModule.application.allModules.first; module; module = module.next)
6012 if(ModuleVisibility(mainModule, module))
6014 nameSpace = FindNameSpace(module.publicNameSpace, string);
6015 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6020 bool ListEnums(NameSpace nameSpace, Type dest)
6023 bool result = false;
6025 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
6027 Class _class = link.data;
6028 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *"))) && !dest.classObjectType)) &&
6029 dest.kind != pointerType && dest.kind != ellipsisType)
6031 OldList conversions { };
6033 type.kind = classType;
6034 type._class = FindClass(_class.name);
6035 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
6037 ListEnumValues(_class);
6040 conversions.Free(null);
6044 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
6046 result |= ListEnums(nameSpace, dest);
6051 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
6055 for(c = 0; (ch = name[c]); c++)
6057 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
6059 NameSpace * newSpace;
6060 char * spaceName = new char[c - start + 1];
6061 memcpy(spaceName, name + start, c - start);
6062 spaceName[c-start] = '\0';
6063 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
6067 nameSpace = newSpace;
6076 return (NameSpace *)nameSpace;
6079 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
6081 bool listedEnums = false;
6082 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
6083 bool listClasses = true;
6085 if(exp && (exp.type == identifierExp || exp.type == memberExp))
6087 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
6088 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
6089 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
6091 if(exp.type == identifierExp)
6092 id = realIdentifier;
6094 if(id && id._class && !id._class.name)
6096 listClasses = false;
6099 else if(id && id._class && id._class.name)
6103 Class _class = id.classSym.registered;
6104 if(_class && _class.type == enumClass)
6106 ListEnumValues(_class);
6109 ListClassMembers(id.classSym.registered, true);
6114 else if(id && colons)
6116 ListNameSpaceByString(this.privateModule, id.string);
6121 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6123 listedEnums = ListEnumsModule(this.privateModule, destType);
6126 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6128 ListEnumValues(destType._class.registered);
6131 ListClassPropertiesAndVirtual(insideClass, null);
6135 else if(destType && destType.kind == enumType)
6139 for(value = destType.members.first; value; value = value.next)
6141 DataRow row = membersList.AddString(value.name);
6142 row.icon = icons[typeEnumValue];
6146 ListClassPropertiesAndVirtual(insideClass, null);
6150 else if(insideClass && !enumOnly)
6152 ListClassPropertiesAndVirtual(insideClass, string);
6155 if(listedEnums && string && string[0])
6157 DataRow row = membersList.FindSubString(string);
6159 listedEnums = false;
6162 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6164 ListClassMembersMatch(GetThisClass(), exp.destType);
6166 else if(!insideClass && !enumOnly && !listedEnums)
6169 Symbol symbol = null;
6173 ListClassMembers(GetThisClass(), false);
6176 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6178 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6180 // Don't list enum values?
6181 //if(symbol.type.kind != TypeEnum)
6182 DataRow row = membersList.FindString(symbol.string);
6185 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6187 row = membersList.AddString(symbol.string);
6188 if(symbol.type && symbol.type.kind == functionType)
6189 row.icon = icons[typeMethod];
6190 else if(symbol.type && symbol.type.kind == enumType)
6192 row.icon = icons[typeEnumValue];
6196 BitmapResource bitmap = null;
6197 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6199 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6202 bitmap = { bitmapName };
6203 membersList.AddResource(bitmap);
6206 row.icon = bitmap ? bitmap : icons[typeData];
6213 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6215 DataRow row = membersList.FindString(symbol.string);
6218 row = membersList.AddString(symbol.string);
6219 if(symbol.type.kind == functionType)
6220 row.icon = icons[typeMethod];
6221 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6223 row.icon = icons[typeClass];
6227 row.icon = icons[typeDataType];
6234 ListModule(this.privateModule, 1, listClasses);
6235 // TODO: Implement this with name space
6239 for(data = globalData.first; data; data = data.next)
6241 DataRow row = membersList.FindString(data.name);
6243 data.dataType = ProcessTypeString(data.dataTypeString, false);
6246 row = membersList.AddString(data.name);
6248 if(data.dataType && data.dataType.kind == TypeEnum)
6250 row.icon = icons[typeEnumValue];
6254 BitmapResource bitmap = null;
6255 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6257 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6260 bitmap = { bitmapName };
6261 membersList.AddResource(bitmap);
6264 row.icon = bitmap ? bitmap : icons[typeData];
6272 DataRow row = membersList.AddString("Min");
6273 row.icon = icons[typeMethod];
6275 row = membersList.AddString("Max");
6276 row.icon = icons[typeMethod];
6278 row = membersList.AddString("Abs");
6279 row.icon = icons[typeMethod];
6281 row = membersList.AddString("Sgn");
6282 row.icon = icons[typeMethod];
6288 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6290 EditBoxStream f { editBox = editBox };
6295 updatingCode = true;
6297 if(!method.dataType)
6298 method.dataType = ProcessTypeString(method.dataTypeString, false);
6300 DeleteJunkBefore(f, function.loc.start.pos, &position);
6301 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6303 // ADDING METHOD HERE
6305 Type dataType = method.dataType;
6306 Type returnType = dataType.returnType;
6308 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6314 if(extraIndent) f.Printf(" ");
6316 OutputType(f, returnType, false);
6320 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6322 if(dataType.thisClass.shortName)
6323 f.Printf(dataType.thisClass.shortName);
6325 f.Printf(dataType.thisClass.string);
6328 f.Printf(method.name);
6330 for(param = dataType.params.first; param; param = param.next)
6332 // Decided not to write void...
6333 if(param.kind != voidType)
6335 OutputType(f, param, true);
6341 if(extraIndent) f.Printf(" ");
6342 f.Printf(" %c\n", OpenBracket);
6344 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6350 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6351 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6353 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6355 if(extraIndent) f.Printf(" ");
6356 f.Printf(" return true;\n");
6358 else if(returnType && returnType.kind != voidType)
6360 if(extraIndent) f.Printf(" ");
6361 f.Printf(" return 0;\n");
6366 if(extraIndent) f.Printf(" ");
6368 if(returnType.kind != voidType)
6369 f.Printf("return ");
6370 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6371 for(param = dataType.params.first; param; param = param.next)
6373 if(param.prev) f.Printf(", ");
6374 if(param.kind != voidType)
6375 f.Printf(param.name);
6381 if(extraIndent) f.Printf(" ");
6382 f.Printf(" %c", CloseBracket);
6387 if(extraIndent) { x1 += 3; x2 += 3; }
6388 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6390 this.updatingCode = false;
6394 // Return false if we overrided a function and don't want to run params listing
6395 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6397 bool didOverride = false;
6398 EditLine line = editBox.line;
6399 char * text = line.text;
6400 int lineNum, charPos;
6401 Expression exp = null;
6404 //Identifier id = null;
6405 Expression memberExp = null;
6406 Identifier realIdentifier = null;
6408 if(!parsing) return true;
6409 if(!privateModule) return !didOverride;
6411 insideFunction = null;
6413 charPos = editBox.charPos + 1;
6414 if(!membersListShown)
6419 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6421 EditBoxStream f { editBox = editBox };
6423 updatingCode = true;
6424 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6428 if(!f.Seek(-1, current))
6431 if(!isspace(ch)) break;
6432 f.Seek(-1, current);
6434 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6436 lineNum = editBox.lineNumber + 1;
6437 charPos = editBox.charPos + 1;
6439 updatingCode = false;
6442 if(!membersListShown)
6444 memberExp = FindExpTree(ast, lineNum, charPos);
6445 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6450 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6452 EditBoxStream f { editBox = editBox };
6455 updatingCode = true;
6457 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6460 if(ch == '}' || ch == ',' || ch == ')')
6462 f.Seek(-1, current);
6470 if(!f.Seek(-1, current))
6473 if(!isspace(ch)) break;
6474 f.Seek(-1, current);
6478 f.Seek(-1, current);
6480 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6482 lineNum = editBox.lineNumber + 1;
6483 charPos = editBox.charPos + 1;
6485 updatingCode = false;
6488 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6493 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6494 lineNum = editBox.lineNumber + 1;
6495 charPos = editBox.charPos/* + 1*/;
6499 char tempString[1024];
6500 char * string = null;
6501 CodePosition idStart, idEnd;
6503 if(membersListShown)
6505 char * buffer = membersLine.text;
6507 bool firstChar = true;
6509 string = tempString;
6511 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6513 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6514 if(!isSpace) firstChar = false;
6516 string[len++] = buffer[c];
6520 else //if(realIdentifier)//if(id)
6523 char * buffer = id.string;
6525 bool firstChar = true;
6527 string = tempString;
6528 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6530 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6531 if(!isSpace) firstChar = false;
6533 string[len++] = buffer[c];
6539 EditLine editLine = editBox.line;
6540 bool firstChar = true;
6543 string = tempString;
6544 for(y = lineNum-1; y >= 0; y--)
6546 char * buffer = editLine.text;
6547 int lineCount = editLine.count;
6548 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6550 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6555 idEnd.charPos = x + 2;
6560 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6563 idEnd.charPos = x + 2;
6570 if(!isalnum(buffer[x]) && buffer[x] != '_')
6576 memmove(string+1, string, len++);
6577 string[0] = buffer[x];
6581 //if(done || firstChar)
6582 if(done || !firstChar)
6584 editLine = editLine.prev;
6587 if(!strcmp(string, "case"))
6593 else if(!strcmp(string, "return"))
6599 else if(!strcmp(string, "delete"))
6605 else if(!strcmp(string, "new"))
6611 else if(!strcmp(string, "renew"))
6619 idStart.charPos = x + 1;
6620 idStart.line = y + 1;
6623 if(!membersListShown)
6625 membersList.Clear();
6626 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6628 Type type = memberExp.member.exp.expType;
6629 if(pointer == 2 && type)
6631 if(type.kind == pointerType || type.kind == arrayType)
6640 ListSymbols(exp, enumOnly, string, realIdentifier);
6642 membersList.Sort(null, 1);
6647 // Virtual function override
6648 Identifier id = GetDeclId(insideFunction.declarator);
6649 char * string = id ? id.string : null;
6651 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6654 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6655 insideFunction = null;
6658 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6663 if(!didOverride) //insideFunction)
6665 rowCount = membersList.rowCount;
6668 DataRow row = string ? membersList.FindSubString(string) : null;
6669 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6671 char * newString = row.string;
6672 if(!membersListShown)
6674 membersLoc.start.line = idStart.line-1;
6675 membersLoc.start.charPos = idStart.charPos-1;
6676 //membersLoc.end = membersLoc.start;
6677 membersLoc.end.charPos = idEnd.charPos-1;
6678 membersLoc.end.line = idEnd.line-1;
6679 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6680 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6685 membersList.Destroy(0);
6686 membersListShown = false;
6689 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6691 line, membersLoc.start.line, membersLoc.start.charPos,
6692 line, membersLoc.end.line, membersLoc.end.charPos);
6693 editBox.PutS(newString);
6699 row = membersList.FindSubStringi(string);
6701 membersList.currentRow = row;
6702 membersList.currentRow.selected = false;
6705 membersList.currentRow = row;
6707 if(!membersListShown)
6711 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6712 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6713 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6714 editBox.GetCaretPosition(caret);
6715 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6717 membersList.master = this;
6719 caret.y += editBox.GetCaretSize();
6721 membersList.Create();
6724 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6725 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6726 Window parent = membersList.parent;
6728 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6730 y -= editBox.GetCaretSize() + membersList.size.h;
6731 membersAbove = true;
6734 membersAbove = false;
6736 membersList.position = { x, y };
6740 membersLoc.start.line = lineNum - 1;
6742 if(string && string[0])
6744 membersLoc.start.charPos = idStart.charPos-1;
6745 membersLoc.end = membersLoc.start;
6746 //membersLoc.end.charPos = id.loc.end.charPos-1;
6747 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6751 membersLoc.start.charPos = charPos;
6752 membersLoc.end = membersLoc.start;
6753 membersLoc.end.charPos = charPos;
6755 membersListShown = true;
6757 // Hack to keep caret shown
6758 editBox.GetCaretPosition(caret);
6759 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6762 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6768 SetCurrentContext(globalContext);
6771 return !didOverride;
6774 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6776 EditLine line = editBox.line;
6777 char * text = line.text;
6778 int lineNum, charPos;
6779 Expression exp = null;
6783 if(!parsing) return;
6785 charPos = editBox.charPos + 1;
6788 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6790 EditBoxStream f { editBox = editBox };
6793 updatingCode = true;
6794 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6797 if(ch == '}' || ch == ',' || ch == ')')
6799 f.Seek(-1, current);
6807 if(!f.Seek(-1, current))
6810 if(!isspace(ch)) break;
6811 f.Seek(-1, current);
6815 f.Seek(-1, current);
6817 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6819 lineNum = editBox.lineNumber + 1;
6820 charPos = editBox.charPos + 1;
6822 updatingCode = false;
6825 charPos = Min(charPos, l1.count + 1);
6827 FindParamsTree(ast, lineNum, charPos);
6829 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6830 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6832 ::functionType = null;
6833 ::instanceType = null;
6836 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6837 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6841 Window parent = paramsList.parent;
6843 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6846 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6847 // ( Dummy exp: always ends up with same memory)
6849 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6850 editBox.GetCaretPosition(paramsPosition);
6851 this.paramsPosition.y += editBox.GetCaretSize();
6854 FreeType(this.functionType);
6855 FreeType(this.instanceType);
6857 this.functionType = ::functionType;
6858 this.instanceType = ::instanceType;
6860 if(this.functionType) this.functionType.refCount++;
6861 if(this.instanceType) this.instanceType.refCount++;
6863 this.paramsID = ::paramsID;
6864 functionExp = paramsInsideExp;
6866 paramsList.master = this;
6868 paramsList.Create();
6870 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6871 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6873 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6875 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6879 paramsAbove = false;
6880 if(x + paramsList.size.w > parent.clientSize.w)
6882 x = parent.clientSize.w - paramsList.size.w;
6886 paramsList.position = { x, y };
6888 // Hack to keep caret shown
6891 editBox.GetCaretPosition(caret);
6892 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6895 this.paramsShown = true;
6897 else if((!::functionType && !::instanceType) || reposition)
6899 paramsList.Destroy(0);
6900 paramsShown = false;
6902 FreeType(this.functionType);
6903 FreeType(this.instanceType);
6904 this.functionType = null;
6905 this.instanceType = null;
6909 SetCurrentContext(globalContext);
6917 designer.visible = true;
6918 designer.Activate();
6924 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6926 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };
6931 static int nofdigits(int v)
6933 if(v == MININT) return 10 + 1;
6934 if(v < 0) return nofdigits(-v) + 1;