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 = Min(before.line.count, 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 editMenu { menu, $"Edit", e };
1963 MenuDivider { editMenu };
1964 MenuItem clearTrailingSpacesItem
1966 editMenu, $"Clear trailing spaces", t, Key { t, ctrl = true, shift = true };
1968 bool NotifySelect(MenuItem selection, Modifiers mods)
1970 // Nuke trailing spaces
1973 editBox.recordUndoEvent = true;
1974 for(line = editBox.firstLine; line; line = line.next, y++)
1976 String buffer = line.text;
1977 int count = line.count, i = count-1;
1978 while(i >= 0 && isspace(buffer[i])) i--;
1980 editBox.Delete(line, y, i + 1, line, y, count);
1982 editBox.recordUndoEvent = false;
1987 Menu debugMenu { menu, $"Debug", d };
1988 MenuItem debugRunToCursor { debugMenu, $"Run To Cursor", c, ctrlF10, id = RTCMenuBits { false, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1989 MenuItem debugSkipRunToCursor { debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true }, id = RTCMenuBits { true, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1990 MenuItem debugRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level", l, altF10, id = RTCMenuBits { false, true, false }, NotifySelect = RTCMenu_NotifySelect; };
1991 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; };
1993 MenuItem debugBpRunToCursor { debugMenu, $"BP Run To Cursor"/*, c, ctrlF10*/, id = RTCMenuBits { false, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1994 MenuItem debugBpSkipRunToCursor { debugMenu, $"BP Run To Cursor Skipping Breakpoints"/*, u, Key { f10, ctrl = true, shift = true }*/, id = RTCMenuBits { true, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1995 MenuItem debugBpRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level"/*, l, altF10*/, id = RTCMenuBits { false, true, true }, NotifySelect = RTCMenu_NotifySelect; };
1996 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; };
1998 bool RTCMenu_NotifySelect(MenuItem selection, Modifiers mods)
2000 ProjectView projectView = ide.projectView;
2001 if(!projectView.buildInProgress)
2003 RTCMenuBits bits = (RTCMenuBits)selection.id;
2004 int line = editBox.lineNumber + 1;
2007 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2008 ProjectConfig config = projectView.project.config;
2009 int bitDepth = ide.workspace.bitDepth;
2010 bool useValgrind = ide.workspace.useValgrind;
2011 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, bits.ignoreBreakpoints, bits.atSameLevel, bits.oldImplementation);
2017 MenuDivider { debugMenu };
2018 MenuItem debugToggleBreakpoint
2020 debugMenu, $"Toggle Breakpoint", t, f9;
2021 bool NotifySelect(MenuItem selection, Modifiers mods)
2023 ProjectView projectView = ide.projectView;
2024 if(projectView && fileName)
2026 int line = editBox.lineNumber + 1;
2027 ide.debugger.ToggleBreakpoint(fileName, line);
2037 //MenuItem viewDesignerItem, viewProperties, viewMethods;
2041 designer.parent = parent;
2044 toolBox = ((IDEWorkSpace)master).toolBox;
2046 // Debugger bug here: value of toolBox appears as 0
2048 sheet = ((IDEWorkSpace)master).sheet;
2053 bool OnClose(bool parentClosing)
2057 if(ide.workspace && fileName)
2058 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2059 if(inUseDebug && !debugClosing)
2061 debugClosing = true;
2063 if(CloseConfirmation(false))
2066 if(modifiedDocument)
2067 OnFileModified({ modified = true }, null);
2069 debugClosing = false;
2072 if(designer && !designer.closing)
2074 if(designer.visible)
2081 //Window formEditor = designer;
2082 //formEditor.Destroy(0);
2085 ide.AdjustFileMenus();
2090 void OnDestroy(void)
2092 ObjectInfo oClass, next;
2093 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2095 FreeType(this.functionType);
2096 FreeType(this.instanceType);
2101 designer.codeEditor = null;
2102 designer.Destroy(0);
2106 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2108 ObjectInfo object, next;
2110 for(object = oClass.instances.first; object; object = next)
2115 Designer::DestroyObject(object.instance);
2116 delete object.instance;
2118 sheet.DeleteObject(object);
2120 oClass.instances.Delete(object);
2124 Designer::DestroyObject(oClass.instance);
2125 delete oClass.instance;
2127 sheet.DeleteObject(oClass);
2129 classes.Delete(oClass);
2132 if(windowClass && windowClass.data)
2133 UnapplySkin(windowClass);
2137 if(sheet.codeEditor == this)
2139 sheet.codeEditor = null;
2140 toolBox.codeEditor = null;
2146 ProjectView projectView = ide.projectView;
2149 ProjectNode node = projectView.GetNodeFromWindow(this, null, true, false, null);
2150 if(node && node.modified)
2152 node.modified = false;
2153 projectView.Update(null);
2159 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2161 // 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
2163 if(directActivation)
2164 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2166 if(active && directActivation)
2170 openedFileInfo.Activate();
2174 Location * loc = null;
2175 UpdateFormCode(); // To ensure update when modifying properties...
2177 // Got to the right spot in code so we don't lose our form selection...
2180 if(selected.instCode)
2181 loc = &selected.instCode.loc;
2182 else if(selected.classDefinition)
2183 loc = &selected.classDefinition.loc;
2185 line = editBox.lineNumber + 1;
2186 charPos = editBox.charPos + 1;
2191 if(selected && !loc->Inside(line, charPos))
2193 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2194 line = editBox.lineNumber + 1;
2195 charPos = editBox.charPos + 1;
2197 else if(selected && selected.classDefinition)
2200 for(object = selected.instances.first; object; object = object.next)
2204 if(object.instCode.loc.Inside(line, charPos))
2210 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2211 line = editBox.lineNumber + 1;
2212 charPos = editBox.charPos + 1;
2217 ProcessCaretMove(editBox, line, charPos);
2222 if(membersListShown)
2224 membersList.Destroy(0);
2225 membersListShown = false;
2229 paramsList.Destroy(0);
2230 paramsShown = false;
2231 FreeType(functionType);
2232 FreeType(instanceType);
2234 functionType = null;
2235 instanceType = null;
2242 bool OnSaveFile(char * fileName)
2249 f = FileOpen(fileName, write);
2252 if(!ide.projectView)
2253 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2257 this.fileName = fileName; // Put this here because the form designer will check for it...
2258 designer.fileName = fileName;
2259 designer.modifiedDocument = false;
2262 editBox.Save(f, false);
2263 modifiedDocument = false;
2271 bool OnFileModified(FileChange fileChange, char * param)
2273 bool reload = false;
2274 if(visible == false && inUseDebug == true)
2275 ide.debugger.WatchesReleaseCodeEditor();
2280 sprintf(message, $"The document %s was modified by another application.\n"
2281 "Would you like to reload it and lose your changes?", fileName);
2282 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2283 contents = message }.Modal() == yes)
2289 File f = FileOpen(fileName, read);
2292 int lineNumber, charPos, len;
2296 updatingCode = true;
2297 lineNumber = editBox.lineNumber;
2298 charPos = editBox.charPos;
2299 scroll = editBox.scroll;
2302 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2303 len = strlen(editBox.line.text);
2304 editBox.GoToLineNum(lineNumber);
2305 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2306 editBox.scroll = scroll;
2307 updatingCode = false;
2308 loadingFile = false;
2310 codeModified = true;
2314 designer.modifiedDocument = false;
2316 modifiedDocument = false;
2324 void OnRedraw(Surface surface)
2327 surface.SetBackground(marginColor);
2328 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2329 if(ideSettings.showLineNumbers)
2331 int currentLineNumber;
2333 char lineFormat[16];
2337 surface.textOpacity = false;
2338 surface.font = font.font;
2339 surface.TextExtent(" ", 1, null, &spaceH);
2340 currentLineNumber = editBox.scroll.y / spaceH + 1;
2341 sprintf(lineFormat, " %%%du", maxLineNumberLength);
2343 surface.SetForeground(lineNumbersColor);
2344 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2346 // Highlight current line
2347 if(editBox.lineNumber == currentLineNumber - 1)
2349 surface.SetBackground(selectedMarginColor);
2350 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2351 surface.SetBackground(marginColor);
2353 sprintf(lineText, lineFormat, currentLineNumber);
2354 if(currentLineNumber <= editBox.numLines)
2355 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
2356 currentLineNumber++;
2360 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2362 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2363 int lineCursor, lineTopFrame, breakpointLines[128];
2364 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2365 Debugger debugger = ide.debugger;
2366 BitmapResource bmpRes;
2368 boxH = clientSize.h;
2369 scrollY = editBox.scroll.y;
2370 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2372 bpOnCursor = bpOnTopFrame = false;
2373 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2376 for(i = 0; i < count; i++)
2378 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2380 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2381 if(breakpointLines[i] == lineCursor)
2383 if(breakpointLines[i] == lineTopFrame)
2384 bpOnTopFrame = true;
2387 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2389 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2392 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2393 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2394 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2396 if(editBox.anchor.left.distance)
2398 if(editBox.horzScroll && editBox.horzScroll.visible)
2400 surface.SetBackground(control);
2401 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2406 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2411 lineY = (line - 1) * lineH;
2412 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2414 Bitmap bitmap = resource.bitmap;
2416 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2423 char ext[MAX_EXTENSION];
2424 char * fileName = property::fileName;
2426 if(SearchString(fileName, 0, "Makefile", false, true))
2427 editBox.useTab = true;
2428 designer.fileName = fileName;
2432 GetExtension(fileName, ext);
2434 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2435 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2436 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2437 editBox.syntaxHighlighting = true;
2439 editBox.syntaxHighlighting = false;
2441 if(parsing && !strcmpi(ext, "ec"))
2443 codeModified = true;
2447 maxLineNumberLength = 0;
2452 bool UpdateMarginSize()
2454 if(ideSettings.showLineNumbers)
2456 int numLen = Max(4, nofdigits(editBox.numLines));
2458 maxLineNumberLength = numLen;
2459 display.FontExtent(font.font, "0", 1, &digitWidth, null);
2460 editBox.anchor = Anchor
2462 left = editBox.syntaxHighlighting * 20 + ideSettings.showLineNumbers * (maxLineNumberLength+2) * digitWidth,
2463 right = 0, top = 0, bottom = 0
2468 maxLineNumberLength = 0;
2469 editBox.anchor = Anchor
2471 left = editBox.syntaxHighlighting * 20,
2472 right = 0, top = 0, bottom = 0
2484 bool LoadFile(char * filePath)
2486 File f = FileOpen(filePath, read);
2489 // Added this here...
2490 fileName = filePath;
2492 updatingCode = true;
2494 updatingCode = false;
2495 loadingFile = false;
2504 void AdjustDebugMenus()
2506 bool unavailable = ide.areDebugMenusUnavailable;
2507 bool isNotNotRunning = unavailable || ide.isDebuggerRunning;
2508 bool isNotStopped = unavailable || !ide.isDebuggerStopped;
2509 bool noBreakpointToggle = ide.isBreakpointTogglingUnavailable;
2511 debugRunToCursor.disabled = isNotNotRunning;
2512 debugSkipRunToCursor.disabled = isNotNotRunning;
2513 debugRunToCursorAtSameLevel.disabled = isNotStopped;
2514 debugSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2516 debugBpRunToCursor.disabled = isNotNotRunning;
2517 debugBpSkipRunToCursor.disabled = isNotNotRunning;
2518 debugBpRunToCursorAtSameLevel.disabled = isNotStopped;
2519 debugBpSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2521 debugToggleBreakpoint.disabled = noBreakpointToggle;
2527 ProjectView projectView = ide.projectView;
2530 designer.fileName = fileName;
2536 sprintf(title, $"Untitled %d", documentID);
2537 // designer.fileName = CopyString(title);
2538 designer.fileName = title;
2543 for(c = 0; c < CodeObjectType::enumSize; c++)
2544 icons[c] = BitmapResource { iconNames[c], window = this };
2546 codeModified = true;
2558 selected.modified = true;
2559 selected.oClass.modified = true;
2561 designer.modifiedDocument = true;
2562 modifiedDocument = true;
2563 formModified = true;
2566 /****************************************************************************
2568 ****************************************************************************/
2571 SetCurrentNameSpace(null);
2577 this.defines.Free(FreeModuleDefine);
2578 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2580 FreeExcludedSymbols(this.excludedSymbols);
2581 FreeContext(this.globalContext);
2583 FreeGlobalData(&this.globalData);
2584 FindCtx_Terminate();
2585 FindParams_Terminate();
2587 if(GetGlobalContext() == globalContext)
2589 SetGlobalData(null);
2590 SetGlobalContext(null);
2591 SetExcludedSymbols(null);
2592 SetTopContext(null);
2593 SetCurrentContext(null);
2596 SetPrivateModule(null);
2599 if(this.privateModule)
2601 FreeTypeData(this.privateModule);
2602 delete this.privateModule;
2603 this.privateModule = null;
2609 static bool reentrant = false;
2614 char * selectedClassName = null, * selectedName = null;
2615 int selectedPos = 0;
2616 Designer backDesigner;
2617 char oldWorkDir[MAX_LOCATION];
2618 char mainModuleName[MAX_FILENAME] = "";
2620 ImportedModule module;
2621 char extension[MAX_EXTENSION];
2622 PathBackup pathBackup { };
2624 Time parseCodeStart = GetTime();
2625 Time startTime, startFindClass;
2627 findClassTotalTime = 0;
2628 checkTypeTotalTime = 0;
2629 externalImportTotalTime = 0;
2630 findClassIgnoreNSTotalTime = 0;
2631 findSymbolTotalTime = 0;
2632 //ResetClassFindTime();
2636 // 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)
2637 if(reentrant) return;
2644 selectedClassName = CopyString(oClass.name);
2645 if(selected != oClass)
2647 ObjectInfo object = this.selected;
2648 selectedName = CopyString(object.name);
2652 for(check = this.oClass.instances.first; check; check = check.next)
2664 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2666 FindCtx_Terminate();
2667 FindParams_Terminate();
2669 SetGlobalData(&globalData);
2670 SetGlobalContext(globalContext);
2671 SetExcludedSymbols(&excludedSymbols);
2672 SetTopContext(globalContext);
2673 SetCurrentContext(globalContext);
2674 SetDefines(&defines);
2675 SetImports(&imports);
2676 SetCurrentNameSpace(null);
2679 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2680 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2681 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2682 "/I T:\\ecere\\include /E %s", argv[1]);
2686 ChangeWorkingDir("e:\\ec");
2687 sprintf(command, "gcc -x c -E -");
2688 fileInput = DualPipeOpen({ output = true, input = true }, command);
2689 SetFileInput(fileInput);
2694 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2696 fileInput.Write(buffer, 1, count);
2701 fileInput.CloseOutput();
2705 // TOCHECK: COULDN'T WE CALL FreeParser here?
2707 FreeType(this.functionType);
2708 FreeType(this.instanceType);
2709 this.functionType = null;
2710 this.instanceType = null;
2713 sheet.SelectObject(null);
2719 // We don't want the designer to be notified of selection when deleting rows...
2720 backDesigner = designer;
2725 ObjectInfo _class, next;
2727 for(_class = classes.first; _class; _class = next)
2733 for(;object = _class.instances.first;)
2737 Designer::DestroyObject(object.instance);
2738 delete object.instance;
2740 sheet.DeleteObject(object);
2742 _class.instances.Delete(object);
2746 Designer::DestroyObject(_class.instance);
2747 delete _class.instance;
2749 sheet.DeleteObject(_class);
2751 classes.Delete(_class);
2757 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2758 if(windowClass && windowClass.data)
2759 UnapplySkin(windowClass);
2762 designer = backDesigner;
2765 fileInput = editFile = EditBoxStream { editBox = editBox };
2766 SetFileInput(fileInput);
2774 defines.Free(FreeModuleDefine);
2775 imports.Free(FreeModuleImport);
2777 FreeContext(this.globalContext);
2778 FreeExcludedSymbols(this.excludedSymbols);
2781 FreeGlobalData(&this.globalData);
2783 if(this.privateModule)
2785 FreeTypeData(this.privateModule);
2786 delete this.privateModule;
2790 startTime = GetTime();
2791 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2793 printf("classes.count: %d\n", globalContext.classes.count);
2798 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2799 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2802 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2804 SetPrivateModule(privateModule);
2807 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2808 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2809 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2810 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2811 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2814 fileName = this.fileName;
2816 if(ide.workspace && ide.workspace.projects && fileName)
2818 for(p : ide.workspace.projects)
2820 char path[MAX_LOCATION];
2822 MakePathRelative(fileName, p.topNode.path, path);
2823 MakeSlashPath(path);
2825 pn = p.topNode.FindWithPath(path, false);
2834 project = ide.project;
2836 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2838 ChangeWorkingDir(project.topNode.path);
2840 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2842 GetLastDirectory(fileName, mainModuleName);
2843 GetExtension(mainModuleName, extension);
2845 SetBuildingEcereCom(false);
2846 SetBuildingEcereComModule(false);
2848 // TODO: Get symbolsDir from project settings instead...
2851 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2852 ProjectConfig config = project.config;
2853 int bitDepth = ide.workspace.bitDepth;
2854 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2855 SetSymbolsDir(objDir.dir);
2856 ide.SetPath(true, compiler, config, bitDepth);
2860 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2861 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2865 switch(GetRuntimePlatform())
2867 case win32: SetSymbolsDir("obj/debug.win32"); break;
2868 case tux: SetSymbolsDir("obj/debug.linux"); break;
2869 case apple: SetSymbolsDir("obj/debug.apple"); break;
2871 SetIncludeDirs(null);
2872 SetSysIncludeDirs(null);
2876 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2878 // TODO FIX for configless project
2879 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2881 for(item : ide.project.config.options.preprocessorDefinitions)
2883 if(!strcmp(item, "BUILDING_ECERE_COM"))
2885 SetBuildingEcereCom(true);
2892 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2893 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2894 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2895 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2896 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2897 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2898 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2899 strcmpi(mainModuleName, "Mutex.ec")))
2901 SetBuildingEcereComModule(true);
2904 // Predeclare all classes
2906 char symFile[MAX_FILENAME];
2907 char symLocation[MAX_LOCATION];
2908 ImportedModule module, next;
2910 GetLastDirectory(fileName, symFile);
2911 ChangeExtension(symFile, "sym", symFile);
2913 strcpy(symLocation, GetSymbolsDir());
2914 PathCat(symLocation, symFile);
2916 // if(!GetEcereImported() && !GetBuildingEcereCom())
2917 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2920 startTime = GetTime();
2922 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2924 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2929 startTime = GetTime();
2931 // LoadSymbols(symLocation, normalImport, true);
2932 LoadSymbols(symLocation, preDeclImport, false);
2934 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2937 for(module = defines.first; module; module = next)
2940 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2943 defines.Delete(module);
2948 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2950 SetDefaultDeclMode(privateAccess);
2951 SetDeclMode(privateAccess);
2955 SetDefaultDeclMode(defaultAccess);
2956 SetDeclMode(defaultAccess);
2959 StripExtension(mainModuleName);
2960 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2961 defines.AddName(module);
2964 // SetYydebug(true);
2969 startTime = GetTime();
2970 startFindClass = checkTypeTotalTime;
2974 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2976 CheckDataRedefinitions();
2979 SetIncludeDirs(null);
2980 SetSysIncludeDirs(null);
2991 startTime = GetTime();
2993 PrePreProcessClassDefinitions();
2994 ComputeModuleClasses(privateModule);
2995 PreProcessClassDefinitions();
2996 ProcessClassDefinitions();
2998 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2999 startTime = GetTime();
3004 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
3005 startTime = GetTime();
3007 ProcessInstantiations();
3009 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
3012 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
3014 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
3015 if(!windowClass || windowClass.internalDecl)
3018 startTime = GetTime();
3020 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
3021 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
3022 eModule_Load(this.privateModule, "ecere", privateAccess);
3024 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
3027 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
3029 if(windowClass && windowClass.data)
3030 ApplySkin(windowClass, app.currentSkin.name, null);
3034 startTime = GetTime();
3036 for(external = ast->first; external; external = external.next)
3038 if(external.type == classExternal)
3040 ClassDefinition _class = external._class;
3041 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
3043 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
3046 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
3048 Instance instance = eInstance_New(regClass);
3049 ObjectInfo classObject
3051 name = CopyString(_class._class.name);
3052 instance = instance;
3053 classDefinition = _class;
3054 oClass = classObject;
3057 classes.Add(classObject);
3061 // Moved this at bottom so that the file dialog doesn't show up in eCom
3062 designer.CreateObject(instance, classObject, true, null);
3063 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
3065 if(_class.definitions)
3069 for(def = _class.definitions->first; def; def = def.next)
3073 case defaultPropertiesClassDef:
3076 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3078 Identifier id = propDef.identifiers->first;
3081 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3084 Class propertyClass = prop.dataTypeClass;
3086 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3087 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3089 Expression computed;
3090 bool variable = true;
3092 FreeType(propDef.initializer.exp.destType);
3093 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3094 ProcessExpressionType(propDef.initializer.exp);
3096 computed = CopyExpression(propDef.initializer.exp);
3097 ComputeExpression(computed);
3098 if(computed.isConstant)
3100 switch(computed.type)
3103 if(propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3105 String temp = new char[strlen(computed.string)+1];
3106 ReadString(temp, computed.string);
3107 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3110 if(!propDef.initializer.exp.intlString)
3112 Map<String, bool> i18nStrings = classObject.i18nStrings;
3114 classObject.i18nStrings = i18nStrings = { };
3115 i18nStrings[prop.name] = false;
3121 if((propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass) && !id.next)
3125 if(computed.instance._class && computed.instance._class.symbol &&
3126 computed.instance._class.symbol.registered &&
3127 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3129 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3131 // This was saved in the control and shouldn't be freed by FreeExpression...
3132 // (Not doing this anymore, incrementing refCount in pass15 instead)
3133 /*if(propertyClass.type == normalClass)
3134 computed.instance.data = null;*/
3142 Operand value = GetOperand(computed);
3143 DataValue valueData;
3144 valueData.i64 = value.i64;
3145 SetProperty(prop, instance, valueData);
3152 propDef.variable = true;
3153 FreeExpression(computed);
3158 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3159 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3160 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3163 // Maintain a list in FunctionDefinition of who is attached to it
3164 for(def = _class.definitions->first; def; def = def.next)
3166 if(def.type == functionClassDef)
3168 ClassFunction function = def.function;
3169 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3171 function.attached.Add(OldLink { data = method });
3181 case declarationClassDef:
3183 Declaration decl = def.decl;
3186 case instDeclaration:
3188 Instantiation inst = decl.inst;
3189 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3190 if(instClass && eClass_GetDesigner(instClass))
3192 Instance control = eInstance_New(instClass);
3197 oClass = classObject;
3201 classObject.instances.Add(object);
3203 // TOCHECK: Why is this needed now?
3204 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3205 def.object = object;
3207 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3209 designer.CreateObject(control, object, false, classObject.instance);
3210 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3220 // Second pass, process instantiation members
3222 for(def = _class.definitions->first; def; def = def.next)
3226 case declarationClassDef:
3228 Declaration decl = def.decl;
3231 case instDeclaration:
3233 Instantiation inst = decl.inst;
3234 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3235 if(instClass && eClass_GetDesigner(instClass))
3238 object = object ? object.next : classObject.instances.first;
3239 control = object.instance;
3243 MembersInit members;
3244 for(members = inst.members->first; members; members = members.next)
3246 switch(members.type)
3248 case dataMembersInit:
3250 if(members.dataMembers)
3253 DataMember curMember = null;
3254 Class curClass = null;
3255 DataMember subMemberStack[256];
3256 int subMemberStackPos = 0;
3258 for(member = members.dataMembers->first; member; member = member.next)
3261 Identifier ident = member.identifiers ? member.identifiers->first : null;
3264 DataMember _subMemberStack[256];
3265 int _subMemberStackPos = 0;
3266 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3270 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3272 if(thisMember && thisMember.memberAccess == publicAccess)
3274 curMember = thisMember;
3275 curClass = curMember._class;
3276 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3277 subMemberStackPos = _subMemberStackPos;
3283 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3284 if(curMember) found = true;
3286 if(found && curMember.isProperty)
3288 Property prop = (Property) curMember;
3289 Class propertyClass = prop.dataTypeClass;
3290 bool variable = false;
3292 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3294 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3296 FreeType(member.initializer.exp.destType);
3297 member.initializer.exp.destType = MkClassType(propertyClass.name);
3300 Expression computed;
3302 ProcessExpressionType(member.initializer.exp);
3304 computed = CopyExpression(member.initializer.exp);
3307 bool isClass = propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass;
3310 /*char debugExpString[4096];
3311 debugExpString[0] = '\0';
3312 PrintExpression(member.initializer.exp, debugExpString);*/
3314 ComputeExpression(computed);
3316 switch(computed.type)
3319 if(isClass && computed.isConstant && computed.instance.data)
3321 if(computed.instance._class && computed.instance._class.symbol &&
3322 computed.instance._class.symbol.registered &&
3323 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3325 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3327 // This was saved in the control and shouldn't be freed by FreeExpression...
3328 // (Not doing this anymore, incrementing refCount in pass15 instead)
3329 /*if(propertyClass.type == normalClass)
3330 computed.instance.data = null;*/
3336 if(isClass && eClass_GetDesigner(propertyClass))
3339 char * name = computed.identifier.string;
3340 if(!strcmp(name, "this"))
3343 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3349 for(check = classObject.instances.first; check; check = check.next)
3350 if(check.name && !strcmp(name, check.name))
3353 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3363 if(computed.member.exp.type == identifierExp)
3365 char * name = computed.member.exp.identifier.string;
3367 if(!strcmp(name, "this"))
3369 char * name = computed.member.member.string;
3371 for(check = classObject.instances.first; check; check = check.next)
3372 if(check.name && !strcmp(name, check.name))
3375 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3382 for(check = classObject.instances.first; check; check = check.next)
3384 if(check.name && !strcmp(name, check.name))
3386 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3389 DataValue value { };
3390 GetProperty(getProperty, check.instance, &value);
3391 SetProperty(prop, control, value);
3402 if(propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3404 String temp = new char[strlen(computed.string)+1];
3405 ReadString(temp, computed.string);
3406 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3409 if(!member.initializer.exp.intlString)
3411 Map<String, bool> i18nStrings = object.i18nStrings;
3413 object.i18nStrings = i18nStrings = { };
3414 i18nStrings[prop.name] = false;
3421 if(!isClass && computed.isConstant)
3423 if(!strcmp(propertyClass.dataTypeString, "float"))
3424 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3425 else if(!strcmp(propertyClass.dataTypeString, "double"))
3426 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3428 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3435 FreeExpression(computed);
3439 member.variable = true;
3441 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3442 member.initializer.exp.type == memberExp) // identifierExp
3444 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3445 if(method && method.type == virtualMethod)
3448 // Maintain a list in FunctionDefinition of who is attached to it
3449 for(def = _class.definitions->first; def; def = def.next)
3451 if(def.type == functionClassDef)
3453 ClassFunction function = def.function;
3454 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3455 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3457 function.attached.Add(OldLink { data = method });
3458 // Reference this particular instance?
3473 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3484 //designer.CreateObject(instance, classObject, true, null);
3485 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3487 designer.PostCreateObject(instance, classObject, true, null);
3489 //instance.state = Hidden;
3490 //instance.Create();
3491 //instance.SetState(Normal, true, 0);
3500 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3504 // Restore Selection
3505 if(selectedClassName)
3508 for(oClass = classes.first; oClass; oClass = oClass.next)
3510 if(!strcmp(oClass.name, selectedClassName))
3512 this.oClass = oClass;
3516 delete selectedClassName;
3525 for(check = this.oClass.instances.first; check; check = check.next)
3527 if(check.name && !strcmp(check.name, selectedName))
3529 this.selected = check;
3535 if(this.oClass.instances.first)
3536 this.selected = this.oClass.instances.first;
3538 this.selected = this.oClass;
3541 else if(selectedPos == -1 || !this.oClass.instances.count)
3542 this.selected = this.oClass;
3548 if(selectedPos > this.oClass.instances.count)
3550 for(check = this.oClass.instances.first; check; check = check.next)
3552 if(selectedPos == pos++)
3554 this.selected = check;
3562 this.oClass = classes.first;
3563 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3565 delete selectedName;
3566 SetSymbolsDir(null);
3568 if(sheet.codeEditor == this)
3569 sheet.SelectObject(selected);
3572 codeModified = false;
3574 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3577 InvokeParameters(false, false, false);
3580 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3586 ChangeWorkingDir(oldWorkDir);
3588 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3589 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3590 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3591 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3592 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3594 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3596 if(inUseDebug && ide.projectView)
3597 ide.debugger.EvaluateWatches();
3602 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3605 Window control = (Window)object.instance;
3606 ObjectInfo classObject = object.oClass;
3608 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3610 if(!strcmp(_class.name, "DesignerBase")) return;
3612 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3614 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3615 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3617 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3618 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3620 Class dataType = prop.dataTypeClass;
3622 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3626 if(dataType.type == structClass)
3628 void * dataForm = new0 byte[dataType.structSize];
3629 void * dataTest = new0 byte[dataType.structSize];
3631 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3632 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3634 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3636 char tempString[1024] = "";
3638 bool needClass = true;
3642 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3644 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3646 eClass_FindNextMember(_class, curClass, curMember, null, null);
3647 if(*curMember != (DataMember)prop)
3648 f.Printf("%s = ", prop.name);
3650 *curMember = (DataMember)prop;
3651 *curClass = curMember->_class;
3654 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3656 f.Printf("%s", string);
3663 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3665 void * dataForm, * dataTest;
3666 bool isEditBoxContents = false;
3667 bool freeDataForm = false, freeDataTest = false;
3669 // Because contents property is broken for mutiline EditBox at the moment
3670 if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox"))
3671 isEditBoxContents = true;
3673 if(isEditBoxContents && ((EditBox)control).multiLine)
3675 dataForm = ((EditBox)control).multiLineContents;
3676 freeDataForm = true;
3679 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3680 if(isEditBoxContents && ((EditBox)test).multiLine)
3682 dataTest = ((EditBox)test).multiLineContents;
3683 freeDataTest = true;
3686 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3688 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3690 char tempString[1024] = "";
3695 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3697 eClass_FindNextMember(_class, curClass, curMember, null, null);
3698 if(*curMember != (DataMember)prop)
3699 f.Printf("%s = ", prop.name);
3700 *curMember = (DataMember)prop;
3701 *curClass = curMember->_class;
3703 if(eClass_GetDesigner(dataType))
3705 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3706 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3707 f.Printf("this", prop.name);
3710 //ObjectInfo classObject;
3711 //for(classObject = classes.first; classObject; classObject = classObject.next)
3715 for(object = classObject.instances.first; object; object = object.next)
3717 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3719 f.Printf("%s", object.name);
3726 bool needClass = true;
3727 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3728 f.Printf("%s", string);
3735 bool needClass = true;
3736 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3738 if(!strcmp(dataType.dataTypeString, "char *"))
3740 Map<String, bool> i18nStrings = object.i18nStrings;
3742 if(i18nStrings && i18nStrings.GetAtPosition(prop.name, false))
3745 f.Printf("%s\"", i18n ? "$" : "");
3746 OutputString(f, string);
3750 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3752 f.Printf("%s", string);
3755 *lastIsMethod = false;
3758 if(freeDataForm) delete dataForm;
3759 if(freeDataTest) delete dataTest;
3763 DataValue dataForm, dataTest;
3765 GetProperty(prop, control, &dataForm);
3766 GetProperty(prop, test, &dataTest);
3768 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3771 char tempString[1024] = "";
3772 SetProperty(prop, test, dataForm);
3774 if(dataType.type != bitClass)
3776 bool needClass = true;
3778 if(dataType.type == enumClass)
3781 Class enumClass = eSystem_FindClass(privateModule, "enum");
3782 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3784 for(value = e.values.first; value; value = value.next)
3786 if((int)value.data == dataForm.i)
3788 string = value.name;
3794 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3796 if(string && string[0])
3801 eClass_FindNextMember(_class, curClass, curMember, null, null);
3802 if(*curMember != (DataMember)prop)
3803 f.Printf("%s = ", prop.name);
3804 *curMember = (DataMember)prop;
3805 *curClass = curMember->_class;
3807 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3808 f.Printf("%sf", string);
3810 f.Printf("%s", string);
3814 else if(dataType.type == bitClass)
3816 bool needClass = true;
3818 if(*prev) f.Printf(", ");
3820 eClass_FindNextMember(_class, curClass, curMember, null, null);
3821 if(*curMember != (DataMember)prop)
3822 f.Printf("%s = ", prop.name);
3823 *curMember = (DataMember)prop;
3824 *curClass = curMember->_class;
3826 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3828 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3830 f.Printf("%s", string);
3832 *lastIsMethod = false;
3842 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3844 Instantiation inst = object.instCode;
3845 Window control = (Window)object.instance;
3847 bool methodPresent = false;
3849 bool lastIsMethod = true;
3850 ObjectInfo classObject = object.oClass;
3856 // Instance removed, delete it
3857 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3859 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3860 position = inst.loc.end.pos + 1;
3864 bool multiLine = false;
3867 // Check if it's an unnamed instance
3870 f.Seek(inst.nameLoc.start.pos - position, current);
3871 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3872 position = inst.nameLoc.end.pos;
3874 f.Printf(object.name);
3879 if(isspace(ch) && ch != '\n')
3881 f.Seek(-1, current);
3889 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3891 f.Seek(pos - position, current);
3896 f.Seek(-1, current);
3905 f.Puts(object.name);
3910 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3911 methodPresent = true;
3919 if(ch == OpenBracket)
3925 // TODO: Simplify this?
3934 f.Seek(-1, current);
3935 DeleteJunkBefore(f, position, &position);
3947 if(ch == '\n') { toDelete = count; count = 0; }
3948 else if(isspace(ch)) count++;
3951 f.Seek(-1, current);
3955 toDelete += count - 6;
3965 f.Seek(-toDelete-count, current);
3966 f.DeleteBytes(toDelete);
3967 f.Seek(count, current);
3970 DeleteJunkBefore(f, position, &position);
3972 // Removed this here as it was adding trailing spaces when adding a method
3977 for(c = 0; c<toAdd; c++)
3984 methodPresent = multiLine;
3986 //if(!prev) -- always false
3987 f.Printf(methodPresent ? "\n " : " ");
3992 // Instance not there, create a brand new one
3993 DeleteJunkBefore(f, position, &position);
3994 f.Printf(*firstObject ? "\n\n" : "\n");
3995 *firstObject = false;
3997 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3998 methodPresent = true;
4003 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
4005 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
4010 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
4012 f.Printf(" %s %c ", control._class.name, OpenBracket);
4018 Instance test = eInstance_New(control._class);
4019 DataMember curMember = null;
4020 Class curClass = null;
4023 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
4027 // Attach Method here
4028 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
4030 if(prev) f.Printf(", ");
4031 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
4036 if(inst && !object.deleted)
4038 MembersInit members;
4039 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
4041 DeleteJunkBefore(f, position, &position);
4043 // Instance already there, clear out the properties
4044 for(members = inst.members ? inst.members->first : null; members; members = members.next)
4046 if(members.type == dataMembersInit)
4050 if(members.dataMembers)
4052 bool keptMember = false;
4053 MemberInit lastKept = null;
4055 for(member = members.dataMembers->first; member; member = member.next)
4057 Identifier ident = member.identifiers ? member.identifiers->first : null;
4058 bool deleted = false;
4060 // For now delete if it's not a method
4061 if(!member.variable) // && ident)
4063 if(!ident || !ident.next)
4065 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
4068 f.Seek(member.loc.start.pos - position, current);
4069 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4070 position = member.loc.end.pos;
4075 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
4076 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
4077 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4079 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
4080 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
4082 f.Seek(member.loc.start.pos - position, current);
4083 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4084 position = member.loc.end.pos;
4096 //f.Seek(member.loc.start.pos - position, current);
4097 //position = member.loc.start.pos;
4098 DeleteJunkBefore(f, member.loc.start.pos, &position);
4099 if(prev) f.Printf(", ");
4100 else if(keptMember) f.Printf(" ");
4105 if(!keptMember || !members.next)
4110 if(keptMember && lastKept != members.dataMembers->last)
4115 f.Seek(-1, current);
4121 f.Seek(-1, current);
4124 else if(!isspace(ch))
4126 f.Seek(-2, current);
4131 f.DeleteBytes(count);
4134 f.Seek(members.loc.end.pos - position, current);
4139 f.Seek(-1, current);
4141 position = members.loc.end.pos + 1;
4145 f.Seek(-1, current);
4146 position = members.loc.end.pos;
4152 lastIsMethod = false;
4157 DeleteJunkBefore(f, position, &position);
4160 if(lastKept != members.dataMembers->last)
4165 f.Seek(-1, current);
4171 f.Seek(-1, current);
4174 else if(!isspace(ch))
4176 f.Seek(-2, current);
4181 f.DeleteBytes(count);
4185 f.Seek(members.loc.end.pos - position, current);
4186 position = members.loc.end.pos;
4190 lastIsMethod = true;
4193 lastIsMethod = false;
4199 f.Seek(members.loc.end.pos - position, current);
4200 position = members.loc.end.pos;
4202 lastIsMethod = true;
4205 else if(members.type == methodMembersInit)
4207 if(this.methodAction == actionDeleteMethod && members.function == function);
4209 methodPresent = true;
4211 // Delete instance method here
4212 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4213 members.function == function)
4215 if(this.moveAttached && !*text)
4216 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4218 DeleteJunkBefore(f, members.loc.start.pos, &position);
4219 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4220 position = members.loc.end.pos + 1;
4225 DeleteJunkBefore(f, position, &position);
4229 DeleteJunkBefore(f, members.loc.start.pos, &position);
4230 lastIsMethod = true;
4234 f.Seek(members.loc.end.pos - position, current);
4235 position = members.loc.end.pos;
4237 DeleteJunkBefore(f, position, &position);
4246 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4248 Method method = this.method;
4249 DeleteJunkBefore(f, position, &position);
4255 if(!method.dataType)
4256 method.dataType = ProcessTypeString(method.dataTypeString, false);
4259 Type dataType = method.dataType;
4260 Type returnType = dataType.returnType;
4263 if(this.moveAttached)
4265 // Move function here:
4266 int newLen = strlen(method.name);
4271 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4273 // First change name of function
4274 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4275 *textSize += newLen - movedFuncIdLen;
4276 memcpy(*text + movedFuncIdPos, method.name, newLen);
4278 // Second, tab right
4281 for(c = 0; (*text)[c]; )
4284 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4287 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4288 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4292 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4302 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4304 // ADDING METHOD HERE
4306 OutputType(f, returnType, false);
4309 if(dataType.thisClass)
4311 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4313 if(dataType.thisClass.shortName)
4314 f.Printf(dataType.thisClass.shortName);
4316 f.Printf(dataType.thisClass.string);
4320 f.Printf(method.name);
4322 for(param = dataType.params.first; param; param = param.next)
4324 OutputType(f, param, true);
4329 f.Printf(" %c\n\n", OpenBracket);
4331 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4333 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4334 f.Printf(" return true;\n");
4335 else if(returnType.kind != voidType)
4336 f.Printf(" return 0;\n");
4341 if(returnType.kind != voidType)
4342 f.Printf("return ");
4343 f.Printf("%s::%s(", control._class.name, method.name);
4344 for(param = dataType.params.first; param; param = param.next)
4346 if(param.prev) f.Printf(", ");
4347 if(param.kind != voidType)
4348 f.Printf(param.name);
4352 f.Printf(" %c\n", CloseBracket);
4358 if(!object.instCode)
4359 f.Printf(methodPresent ? " %c;" : "%c;", CloseBracket);
4360 else if(!object.deleted)
4362 // Turn this into a multiline instance when adding a method
4363 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4365 f.Printf(methodPresent ? "\n " : " ");
4367 f.Seek(inst.loc.end.pos + 1 - position, current);
4368 position = inst.loc.end.pos + 1;
4373 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4376 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4378 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4380 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4382 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4383 if(prop && prop.isProperty && !prop.conversion)
4385 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4386 (!prop.IsSet || prop.IsSet(classObject.instance)))
4388 Class dataType = prop.dataTypeClass;
4389 char tempString[1024] = "";
4391 bool specify = false;
4394 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4395 if(member && member._class == regClass)
4399 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4401 if(dataType && dataType.type == structClass)
4403 void * dataForm = new0 byte[dataType.structSize];
4404 void * dataTest = new0 byte[dataType.structSize];
4406 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4407 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4409 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4411 bool needClass = true;
4413 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4414 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4416 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4418 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4423 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4425 void * dataForm, * dataTest;
4426 bool isEditBoxContents = false;
4427 bool freeDataForm = false, freeDataTest = false;
4429 // Because contents property is broken for mutiline EditBox at the moment
4430 if(!strcmp(prop.name, "contents") && !strcmp(prop._class.name, "EditBox"))
4431 isEditBoxContents = true;
4433 if(isEditBoxContents && ((EditBox)classObject.instance).multiLine)
4435 dataForm = ((EditBox)classObject.instance).multiLineContents;
4436 freeDataForm = true;
4439 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4440 if(isEditBoxContents && ((EditBox)test).multiLine)
4442 dataTest = ((EditBox)test).multiLineContents;
4443 freeDataTest = true;
4446 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4448 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4450 char tempString[1024] = "";
4452 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4454 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4456 // Shouldn't go here ...
4457 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4461 bool needClass = true;
4463 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4465 if(!strcmp(dataType.dataTypeString, "char *"))
4467 Map<String, bool> i18nStrings = classObject.i18nStrings;
4469 if(i18nStrings && i18nStrings.GetAtPosition(prop.name, false))
4472 f.Printf("\n %s%s = %s\"", specify ? "property::" : "", prop.name, i18n ? "$" : "");
4473 OutputString(f, string);
4477 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4479 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4482 if(freeDataForm) delete dataForm;
4483 if(freeDataTest) delete dataTest;
4487 DataValue dataForm, dataTest;
4489 GetProperty(prop, classObject.instance, &dataForm);
4490 GetProperty(prop, test, &dataTest);
4492 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4494 SetProperty(prop, test, dataForm);
4495 if(dataType.type == bitClass)
4497 bool needClass = true;
4498 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4500 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4502 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4506 bool needClass = true;
4507 if(dataType.type == enumClass)
4510 Class enumClass = eSystem_FindClass(privateModule, "enum");
4511 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4513 for(value = e.values.first; value; value = value.next)
4515 if((int)value.data == dataForm.i)
4517 string = value.name;
4523 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4524 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4525 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4527 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4536 void UpdateFormCode()
4539 if(!parsing) return;
4546 else if(formModified)
4548 EditBoxStream f { editBox = editBox };
4552 Identifier movedFuncId;
4553 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4554 ObjectInfo classObject;
4558 editBox.recordUndoEvent = true;
4562 movedFuncId = GetDeclId(function.declarator);
4563 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4564 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4567 for(classObject = classes.first; classObject; classObject = classObject.next)
4570 ClassDefinition classDef = classObject.classDefinition;
4571 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4574 bool firstObject = true;
4575 ObjectInfo object = classObject.instances.first;
4576 bool lastIsDecl = false;
4578 if(!classObject.modified) continue;
4580 test = eInstance_New(regClass);
4583 // Put it in the same desktop window...
4584 designer.PrepareTestObject(test);
4586 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4587 //f.Printf("%c\n\n", OpenBracket);
4589 // Change the _class name
4590 f.Seek(classDef.nameLoc.start.pos - position, current);
4591 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4592 f.Printf(classObject.name);
4593 position = classDef.nameLoc.end.pos;
4596 // Go to block start, delete all until no white space, put \n
4600 f.Seek(classDef.blockStart.end.pos - position, current);
4601 position = classDef.blockStart.end.pos;
4603 for(; f.Getc(&ch); count++)
4607 f.Seek(-1, current);
4617 f.Seek(-count, current);
4619 f.DeleteBytes(count-back);
4621 position += count-back;
4624 // Output properties
4625 OutputClassProperties(classObject.instance._class, classObject, f, test);
4627 for(def = classDef.definitions->first; def; def = def.next)
4631 case defaultPropertiesClassDef:
4633 bool keptMember = false;
4635 MemberInit lastKept = null;
4638 DeleteJunkBefore(f, def.loc.start.pos, &position);
4640 // This was adding blank spaces between comment and properties -- What was it for?
4643 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4645 Identifier ident = propDef.identifiers->first;
4646 bool deleted = false;
4648 // For now delete if it's a prop
4649 if(!propDef.variable && ident)
4653 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4656 f.Seek(propDef.loc.start.pos - position, current);
4657 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4658 position = propDef.loc.end.pos;
4663 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4664 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4666 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4667 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4669 f.Seek(propDef.loc.start.pos - position, current);
4670 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4671 position = propDef.loc.end.pos;
4689 f.Seek(def.loc.end.pos - position - 1, current);
4694 f.Seek(-1, current);
4697 position = def.loc.end.pos;
4701 if(lastKept != def.defProperties->last)
4706 f.Seek(-1, current);
4712 f.Seek(-1, current);
4715 else if(!isspace(ch))
4717 f.Seek(-2, current);
4722 f.DeleteBytes(count);
4726 f.Seek(def.loc.end.pos - position, current);
4727 position = def.loc.end.pos;
4732 case declarationClassDef:
4734 Declaration decl = def.decl;
4736 if(decl.type == instDeclaration)
4738 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4740 while(def.object && object != def.object)
4742 if(object /*&& ((ObjectInfo)def.object).modified*/)
4743 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4744 object = object.next;
4747 DeleteJunkBefore(f, def.loc.start.pos, &position);
4748 f.Printf(firstObject ? "\n\n " : "\n ");
4749 firstObject = false;
4751 if(def.object && ((ObjectInfo)def.object).modified)
4752 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4754 object = object ? object.next : null;
4758 DeleteJunkBefore(f, def.loc.start.pos, &position);
4759 f.Printf(firstObject ? "\n\n " : "\n ");
4760 firstObject = false;
4766 DeleteJunkBefore(f, def.loc.start.pos, &position);
4767 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4772 case functionClassDef:
4774 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4775 if(!def.function.body) continue;
4779 DeleteJunkBefore(f, def.loc.start.pos, &position);
4782 // Delete _class methods
4783 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4784 def.function == function)
4789 if(moveAttached && !text)
4791 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4794 f.Seek(def.loc.end.pos - position, current);
4795 for(; f.Getc(&ch); count++)
4799 f.Seek(-1, current);
4803 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4805 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4806 position = def.loc.end.pos + count;
4809 // In case of detaching methods in the _class, simply rename the method
4810 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4812 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4813 f.DeleteBytes(movedFuncIdLen);
4815 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4818 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4819 function == def.function)
4821 // In case of attaching methods in the _class, simply rename the method
4822 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4823 position = function.loc.start.pos + movedFuncIdPos;
4824 f.DeleteBytes(movedFuncIdLen);
4825 if(method.dataType.thisClass)
4826 f.Printf("%s::", method.dataType.thisClass.string);
4827 f.Puts(method.name);
4828 position += movedFuncIdLen;
4833 DeleteJunkBefore(f, def.loc.start.pos, &position);
4834 if(def.type == memberAccessClassDef)
4837 firstObject = false;
4847 f.Seek(def.loc.end.pos - position, current);
4848 position = def.loc.end.pos;
4851 // Output attached methods
4852 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4854 DeleteJunkBefore(f, position, &position);
4855 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4858 // ********** INSTANCES ***************
4859 for(; object; object = object.next)
4861 if(!object.instCode)
4863 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4867 DeleteJunkBefore(f, position, &position);
4869 // ****************** METHODS ***********************
4870 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4872 // If detaching an instance method
4873 if(selected != classObject)
4875 int newLen = strlen(methodName);
4878 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4879 // Tab selection left
4882 for(c = 0; text[c]; )
4885 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4886 memmove(text+start, text+start+i, textSize+1-start-i);
4889 for(; text[c] && text[c] != '\n'; c++);
4895 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4896 textSize += newLen - movedFuncIdLen;
4897 memcpy(text + movedFuncIdPos, methodName, newLen);
4904 if(methodAction == actionAddMethod && selected == classObject)
4906 Method method = this.method;
4908 if(!method.dataType)
4909 method.dataType = ProcessTypeString(method.dataTypeString, false);
4911 // ADDING METHOD HERE
4913 Type dataType = method.dataType;
4914 Type returnType = dataType.returnType;
4916 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4920 OutputType(f, returnType, false);
4923 if(dataType.thisClass && !dataType.classObjectType)
4925 if(dataType.thisClass.shortName)
4926 f.Printf(dataType.thisClass.shortName);
4928 f.Printf(dataType.thisClass.string);
4931 f.Printf(method.name);
4933 for(param = dataType.params.first; param; param = param.next)
4935 OutputType(f, param, true);
4940 f.Printf(" %c\n\n", OpenBracket);
4942 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4944 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4945 f.Printf(" return true;\n");
4946 else if(returnType && returnType.kind != voidType)
4947 f.Printf(" return 0;\n");
4952 if(returnType.kind != voidType)
4953 f.Printf("return ");
4955 char * name = ((Specifier)classDef.baseSpecs->first).name;
4956 Symbol _class = FindClass(name);
4957 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4959 for(param = dataType.params.first; param; param = param.next)
4961 if(param.prev) f.Printf(", ");
4962 if(param.kind != voidType)
4963 f.Printf(param.name);
4968 f.Printf(" %c", CloseBracket);
4972 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4978 editBox.recordUndoEvent = false;
4986 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4987 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4991 codeModified = false;
4992 formModified = false;
4994 moveAttached = false;
4999 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
5002 ClassFunction function = null;
5005 ObjectInfo object = this.selected;
5007 if(object && object == this.oClass)
5009 ClassDefinition classDef = object.oClass.classDefinition;
5011 if(classDef && classDef.definitions)
5013 for(def = classDef.definitions->first; def; def = def.next)
5015 if(def.type == functionClassDef && def.function.declarator)
5017 if(!strcmp(def.function.declarator.symbol.string, methodName))
5019 function = def.function;
5024 else if(def.type == defaultPropertiesClassDef)
5028 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
5030 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
5031 if(ident && !ident.next)
5033 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
5037 propLoc = propDef.loc;
5040 ClassDefinition classDef = object.oClass.classDefinition;
5042 if(classDef.definitions)
5044 for(def = classDef.definitions->first; def; def = def.next)
5046 if(def.type == functionClassDef)
5048 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
5050 function = def.function;
5069 Instantiation inst = object.instCode;
5071 // Check here to see if the method already exists, no need to call ModifyCode in that case
5072 if(inst && inst.members)
5074 MembersInit members;
5075 for(members = inst.members->first; members; members = members.next)
5077 switch(members.type)
5079 case dataMembersInit:
5081 if(members.dataMembers)
5084 for(member = members.dataMembers->first; member; member = member.next)
5086 Identifier ident = member.identifiers ? member.identifiers->first : null;
5087 if(ident && !ident.next)
5089 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
5093 propLoc = member.loc;
5096 ClassDefinition classDef = object.oClass.classDefinition;
5098 if(classDef.definitions)
5100 for(def = classDef.definitions->first; def; def = def.next)
5102 if(def.type == functionClassDef)
5104 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
5106 function = def.function;
5115 // TODO: Fix memory leak
5116 function = ClassFunction
5118 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5130 case methodMembersInit:
5132 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5134 function = members.function;
5146 if(functionPtr) *functionPtr = function;
5150 void GoToMethod(char * methodName /*Method method*/)
5154 ObjectInfo object = selected;
5155 EditBoxStream f { editBox = editBox };
5156 ClassFunction function = null;
5157 bool atChar = false;
5161 Location propLoc = { {0,0,-1} };
5164 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5165 if(function && function.body)
5168 f.Seek(function.body.loc.start.pos+1, current);
5178 f.Seek(-1, current);
5183 else if(!isspace(ch))
5185 f.Seek(-1, current);
5191 else if(propLoc.start.pos > -1)
5193 f.Seek(propLoc.start.pos, current);
5196 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5198 if(function || propLoc.start.pos > -1)
5200 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5201 editBox.CenterOnCursor();
5202 SetState(normal, false, 0);
5205 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5207 FreeClassFunction(function);
5213 void FindCompatibleMethods(Method method, OldList compatible)
5215 ClassDefinition classDef = this.oClass.classDefinition;
5216 if(classDef && classDef.definitions)
5219 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5222 Symbol classSym { };
5223 Symbol selectedClass;
5224 if(this.selected == this.oClass)
5225 selectedClass = classSym;
5227 selectedClass = FindClass(this.selected.instance._class.name);
5229 regClass.name = classDef._class.name;
5230 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5231 for(def = classDef.definitions->first; def; def = def.next)
5233 if(def.type == functionClassDef && def.function.declarator)
5235 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5237 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5240 Type type = def.function.declarator.symbol.type;
5241 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5243 compatible.Add(OldLink { data = def.function });
5249 if(this.oClass && this.oClass.instance)
5251 classSym.registered = regClass;
5252 //classSym.registered = this.oClass.oClass;
5254 for(_class = regClass.base; _class; _class = _class.base)
5257 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5259 // TODO: Understand why these functions popup in attach list
5260 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5262 if(!testMethod.dataType)
5263 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5265 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5266 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5267 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5269 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5270 // ClassFunction function { };
5271 FunctionDefinition function { };
5273 function.declarator = Declarator { };
5274 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5275 excludedSymbols.Add(function.declarator.symbol);
5277 compatible.Add(OldLink { data = function });
5288 void AddMethod(Method method)
5292 char methodName[1024];
5293 strcpy(methodName, method.name);
5294 if(!FindMethod(methodName, null, null))
5296 methodAction = actionAddMethod;
5297 this.method = method;
5301 GoToMethod(methodName);
5305 void DeleteMethod(ClassFunction function)
5309 methodAction = actionDeleteMethod;
5310 this.function = function;
5318 void AttachMethod(Method method, ClassFunction function)
5322 // If it's an instance we'll ask if we want to move it inside...
5323 if(!function.attached.count && function.body)
5325 // Find the function in the _class to check if it's a virtual function
5326 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5327 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5328 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5330 for(def = this.classDefinition.first; def; def = def.next)
5332 if(def.type == functionClassDef)
5334 if(def.function == function)
5339 if(!method || method.type != virtualMethod)
5342 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5343 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5345 moveAttached = true;
5350 methodAction = actionAttachMethod;
5351 this.method = method;
5352 this.function = function;
5359 void ReAttachMethod(Method method, ClassFunction function)
5363 // If it's an instance we'll ask if we want to move it inside...
5364 if(!function.attached.count && function.body)
5366 // Find the function in the _class to check if it's a virtual function
5367 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5368 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5369 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5371 for(def = this.classDefinition.first; def; def = def.next)
5373 if(def.type == functionClassDef)
5375 if(def.function == function)
5380 if(!method || method.type != virtualMethod)
5383 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5384 if(MessageBox { type = yesNo, master = parent, text = title,
5385 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5387 moveAttached = true;
5392 methodAction = actionReattachMethod;
5393 this.method = method;
5394 this.function = function;
5401 void DetachMethod(Method method, ClassFunction function, int type)
5409 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5410 master = sheet, text = $"Name detached method", background = formColor
5414 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5415 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5419 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5420 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5424 dialog, anchor = { left = 5, right = 5, top = 5 }
5426 sprintf(methodName, "%s_%s", selected.name, method.name);
5427 nameBox.contents = methodName;
5429 result = dialog.Modal() == ok;
5430 strcpy(methodName, nameBox.contents);
5435 // If the method is not attached, move it outside
5438 // Add this class to the methodName
5439 char name[1024] = "";
5441 if(this.selected != this.oClass && !method.dataType.thisClass)
5443 strcat(name, this.selected.instance._class.name);
5445 strcat(name, this.methodName);
5446 strcpy(this.methodName, name);
5448 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5450 strcat(name, method.dataType.thisClass.string);
5452 strcat(name, this.methodName);
5453 strcpy(this.methodName, name);
5456 this.moveAttached = true;
5459 this.methodAction = actionDetachMethod;
5460 this.method = method;
5461 this.function = function;
5468 void AddObject(Instance instance, ObjectInfo * object)
5472 //*object = _class.instances.Add(sizeof(ObjectInfo));
5473 *object = ObjectInfo { };
5474 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5475 (*object).oClass = oClass;
5476 (*object).instance = instance;
5481 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5483 // if(strcmp(name, this.oClass.instance.name))
5486 for(check = oClass.instances.first; check; check = check.next)
5487 if(!check.deleted && check.name && !strcmp(name, check.name))
5491 (*object).name = CopyString(name);
5496 toolBox.controlClass = null;
5500 //sheet.AddObject(*object, (*object).name, TypeData, true);
5505 void EnsureUpToDate()
5507 if(sheet && codeModified && parsing)
5511 void SelectObject(ObjectInfo object)
5514 oClass = object ? object.oClass : null;
5516 designer.SelectObject(object, object ? object.instance : null);
5519 void SelectObjectFromDesigner(ObjectInfo object)
5522 sheet.SelectObject(object);
5525 void EnumerateObjects(Sheet sheet)
5529 for(oClass = classes.first; oClass; oClass = oClass.next)
5535 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5536 for(object = oClass.instances.first; object; object = object.next)
5537 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5540 sheet.SelectObject(selected);
5545 designer.AddObject();
5548 void DeleteObject(ObjectInfo object)
5550 delete object.instance;
5551 object.deleted = true;
5552 object.modified = true;
5553 object.oClass.modified = true;
5554 if(object.i18nStrings)
5556 Map<String, bool> i18nStrings = object.i18nStrings;
5560 if(selected == object)
5562 bool looped = false;
5563 ObjectInfo select = object;
5567 select = select.prev;
5571 select = object.oClass.instances.last;
5578 sheet.SelectObject(select ? select : oClass);
5581 if(!object.instCode && object.oClass != object)
5584 oClass.instances.Delete(object);
5587 if(sheet.codeEditor == this)
5588 sheet.DeleteObject(object);
5591 void RenameObject(ObjectInfo object, char * name)
5595 // Validate the name:
5596 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5597 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5600 for(c = 0; name[c]; c++)
5601 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5609 object.name = (name && name[0]) ? CopyString(name) : null;
5611 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5615 void DesignerModifiedObject()
5617 sheet.ListProperties(false);
5621 void ListSubMembers(Type member)
5625 for(subMember = member.members.first; subMember; subMember = subMember.next)
5629 DataRow row = membersList.AddString(subMember.name);
5630 row.icon = icons[typeData];
5634 ListSubMembers(subMember);
5639 void ListSubDataMembers(DataMember member, bool isPrivate)
5641 DataMember subMember;
5642 for(subMember = member.members.first; subMember; subMember = subMember.next)
5644 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5648 DataRow row = membersList.AddString(subMember.name);
5649 BitmapResource bitmap = null;
5650 if(!subMember.dataType)
5651 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5653 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5655 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5658 bitmap = { bitmapName };
5659 membersList.AddResource(bitmap);
5662 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5666 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5672 void ListClassMembers(Class whatClass, bool methodsOnly)
5675 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5676 bool isPrivate = false;
5678 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5680 Method method, methodIt;
5682 DataMember memberIt;
5684 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5686 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5687 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5689 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5691 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5693 DataRow row = membersList.FindString(method.name);
5696 row = membersList.AddString(method.name);
5698 if(!method.dataType)
5699 method.dataType = ProcessTypeString(method.dataTypeString, false);
5701 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5709 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5713 if(memberIt.isProperty)
5715 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5717 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5721 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5723 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5726 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5732 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5734 if(member.isProperty)
5736 Property prop = (Property) member;
5737 if(!membersList.FindString(prop.name))
5739 DataRow row = membersList.AddString(prop.name);
5740 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5743 else if(member.name && !membersList.FindString(member.name))
5745 DataRow row = membersList.AddString(member.name);
5747 BitmapResource bitmap = null;
5748 if(!member.dataType)
5749 member.dataType = ProcessTypeString(member.dataTypeString, false);
5751 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5753 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5756 bitmap = { bitmapName };
5757 membersList.AddResource(bitmap);
5760 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5763 ListSubDataMembers(member, member.memberAccess == privateAccess);
5767 if(_class.inheritanceAccess == privateAccess)
5770 if(_class.module != privateModule) break;
5775 void ListClassMembersMatch(Class whatClass, Type methodType)
5778 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5779 bool isPrivate = false;
5781 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5787 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5789 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5791 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5793 if(!method.dataType)
5794 method.dataType = ProcessTypeString(method.dataTypeString, false);
5796 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5798 DataRow row = membersList.FindString(method.name);
5801 row = membersList.AddString(method.name);
5802 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5808 if(_class.inheritanceAccess == privateAccess)
5811 if(_class.module != privateModule) break;
5816 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5819 bool isPrivate = false;
5820 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5826 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5828 if(method.type == virtualMethod)
5830 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5832 DataRow row = membersList.FindString(method.name);
5835 row = membersList.AddString(method.name);
5837 if(!method.dataType)
5838 method.dataType = ProcessTypeString(method.dataTypeString, false);
5840 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5846 for(member = _class.membersAndProperties.first; member; member = member.next)
5848 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5850 if(member.isProperty)
5852 Property prop = (Property)member;
5854 DataRow row = membersList.AddString(prop.name);
5855 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5858 else if(member.name && (!curString || strcmp(curString, member.name)))
5860 DataRow row = membersList.AddString(member.name);
5862 BitmapResource bitmap = null;
5863 if(!member.dataType)
5864 member.dataType = ProcessTypeString(member.dataTypeString, false);
5866 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5868 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5871 bitmap = { bitmapName };
5872 membersList.AddResource(bitmap);
5875 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5878 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5881 if(_class.inheritanceAccess == privateAccess)
5884 if(_class.module != privateModule) break;
5889 void ListMembers(Type type)
5891 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5895 if(type.kind == classType)
5898 ListClassMembers(type._class.registered, false);
5903 for(member = type.members.first; member; member = member.next)
5907 DataRow row = membersList.AddString(member.name);
5908 row.icon = icons[typeData];
5910 else if(member.kind == structType || member.kind == unionType)
5911 ListSubMembers(member);
5917 void ListModule(Module mainModule, int recurse, bool listClasses)
5920 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5921 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5922 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5923 for(module = mainModule.application.allModules.first; module; module = module.next)
5925 if(ModuleVisibility(mainModule, module))
5926 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5930 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5937 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5939 Class _class = link.data;
5940 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5942 DataRow row = membersList.AddString(_class.name);
5943 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5948 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5950 DefinedExpression definedExp = link.data;
5951 DataRow row = membersList.AddString(link /*definedExp*/.name);
5952 row.icon = icons[typeData];
5955 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5957 GlobalFunction function = link.data;
5958 DataRow row = membersList.AddString(link /*function*/.name);
5959 row.icon = icons[typeMethod];
5963 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5965 if(recurse != 2 && listClasses)
5967 if(!membersList.FindString(ns->name))
5969 DataRow row = membersList.AddString(ns->name);
5970 row.icon = icons[typeNameSpace];
5975 ListNameSpace(ns, 2, listClasses);
5979 void ListEnumValues(Class _class)
5981 List<Class> classes { };
5982 for(; _class && _class.type == enumClass; _class = _class.base)
5983 classes.Insert(null, _class);
5984 for(_class : classes)
5986 EnumClassData enumeration = (EnumClassData)_class.data;
5988 for(item = enumeration.values.first; item; item = item.next)
5990 DataRow row = membersList.AddString(item.name);
5991 row.icon = icons[typeEnumValue];
5997 bool ListEnumsModule(Module mainModule, Type dest)
5999 bool result = false;
6001 result |= ListEnums(mainModule.application.systemNameSpace, dest);
6002 result |= ListEnums(mainModule.application.privateNameSpace, dest);
6003 result |= ListEnums(mainModule.application.publicNameSpace, dest);
6004 for(module = mainModule.application.allModules.first; module; module = module.next)
6006 if(ModuleVisibility(mainModule, module))
6007 result |= ListEnums(module.publicNameSpace, dest);
6012 void ListNameSpaceByString(Module mainModule, char * string)
6014 NameSpace * nameSpace;
6016 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
6017 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6018 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
6019 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6020 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
6021 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6022 for(module = mainModule.application.allModules.first; module; module = module.next)
6024 if(ModuleVisibility(mainModule, module))
6026 nameSpace = FindNameSpace(module.publicNameSpace, string);
6027 if(nameSpace) ListNameSpace(nameSpace, 0, true);
6032 bool ListEnums(NameSpace nameSpace, Type dest)
6035 bool result = false;
6037 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
6039 Class _class = link.data;
6040 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *"))) && !dest.classObjectType)) &&
6041 dest.kind != pointerType && dest.kind != ellipsisType)
6043 OldList conversions { };
6045 type.kind = classType;
6046 type._class = FindClass(_class.name);
6047 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
6049 ListEnumValues(_class);
6052 conversions.Free(null);
6056 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
6058 result |= ListEnums(nameSpace, dest);
6063 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
6067 for(c = 0; (ch = name[c]); c++)
6069 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
6071 NameSpace * newSpace;
6072 char * spaceName = new char[c - start + 1];
6073 memcpy(spaceName, name + start, c - start);
6074 spaceName[c-start] = '\0';
6075 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
6079 nameSpace = newSpace;
6088 return (NameSpace *)nameSpace;
6091 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
6093 bool listedEnums = false;
6094 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
6095 bool listClasses = true;
6097 if(exp && (exp.type == identifierExp || exp.type == memberExp))
6099 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
6100 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
6101 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
6103 if(exp.type == identifierExp)
6104 id = realIdentifier;
6106 if(id && id._class && !id._class.name)
6108 listClasses = false;
6111 else if(id && id._class && id._class.name)
6115 Class _class = id.classSym.registered;
6116 if(_class && _class.type == enumClass)
6118 ListEnumValues(_class);
6121 ListClassMembers(id.classSym.registered, true);
6126 else if(id && colons)
6128 ListNameSpaceByString(this.privateModule, id.string);
6133 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6135 listedEnums = ListEnumsModule(this.privateModule, destType);
6138 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6140 ListEnumValues(destType._class.registered);
6143 ListClassPropertiesAndVirtual(insideClass, null);
6147 else if(destType && destType.kind == enumType)
6151 for(value = destType.members.first; value; value = value.next)
6153 DataRow row = membersList.AddString(value.name);
6154 row.icon = icons[typeEnumValue];
6158 ListClassPropertiesAndVirtual(insideClass, null);
6162 else if(insideClass && !enumOnly)
6164 ListClassPropertiesAndVirtual(insideClass, string);
6167 if(listedEnums && string && string[0])
6169 DataRow row = membersList.FindSubString(string);
6171 listedEnums = false;
6174 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6176 ListClassMembersMatch(GetThisClass(), exp.destType);
6178 else if(!insideClass && !enumOnly && !listedEnums)
6181 Symbol symbol = null;
6185 ListClassMembers(GetThisClass(), false);
6188 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6190 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6192 // Don't list enum values?
6193 //if(symbol.type.kind != TypeEnum)
6194 DataRow row = membersList.FindString(symbol.string);
6197 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6199 row = membersList.AddString(symbol.string);
6200 if(symbol.type && symbol.type.kind == functionType)
6201 row.icon = icons[typeMethod];
6202 else if(symbol.type && symbol.type.kind == enumType)
6204 row.icon = icons[typeEnumValue];
6208 BitmapResource bitmap = null;
6209 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6211 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6214 bitmap = { bitmapName };
6215 membersList.AddResource(bitmap);
6218 row.icon = bitmap ? bitmap : icons[typeData];
6225 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6227 DataRow row = membersList.FindString(symbol.string);
6230 row = membersList.AddString(symbol.string);
6231 if(symbol.type.kind == functionType)
6232 row.icon = icons[typeMethod];
6233 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6235 row.icon = icons[typeClass];
6239 row.icon = icons[typeDataType];
6246 ListModule(this.privateModule, 1, listClasses);
6247 // TODO: Implement this with name space
6251 for(data = globalData.first; data; data = data.next)
6253 DataRow row = membersList.FindString(data.name);
6255 data.dataType = ProcessTypeString(data.dataTypeString, false);
6258 row = membersList.AddString(data.name);
6260 if(data.dataType && data.dataType.kind == TypeEnum)
6262 row.icon = icons[typeEnumValue];
6266 BitmapResource bitmap = null;
6267 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6269 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6272 bitmap = { bitmapName };
6273 membersList.AddResource(bitmap);
6276 row.icon = bitmap ? bitmap : icons[typeData];
6284 DataRow row = membersList.AddString("Min");
6285 row.icon = icons[typeMethod];
6287 row = membersList.AddString("Max");
6288 row.icon = icons[typeMethod];
6290 row = membersList.AddString("Abs");
6291 row.icon = icons[typeMethod];
6293 row = membersList.AddString("Sgn");
6294 row.icon = icons[typeMethod];
6300 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6302 EditBoxStream f { editBox = editBox };
6307 updatingCode = true;
6309 if(!method.dataType)
6310 method.dataType = ProcessTypeString(method.dataTypeString, false);
6312 DeleteJunkBefore(f, function.loc.start.pos, &position);
6313 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6315 // ADDING METHOD HERE
6317 Type dataType = method.dataType;
6318 Type returnType = dataType.returnType;
6320 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6326 if(extraIndent) f.Printf(" ");
6328 OutputType(f, returnType, false);
6332 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6334 if(dataType.thisClass.shortName)
6335 f.Printf(dataType.thisClass.shortName);
6337 f.Printf(dataType.thisClass.string);
6340 f.Printf(method.name);
6342 for(param = dataType.params.first; param; param = param.next)
6344 // Decided not to write void...
6345 if(param.kind != voidType)
6347 OutputType(f, param, true);
6353 if(extraIndent) f.Printf(" ");
6354 f.Printf(" %c\n", OpenBracket);
6356 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6362 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6363 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6365 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6367 if(extraIndent) f.Printf(" ");
6368 f.Printf(" return true;\n");
6370 else if(returnType && returnType.kind != voidType)
6372 if(extraIndent) f.Printf(" ");
6373 f.Printf(" return 0;\n");
6378 if(extraIndent) f.Printf(" ");
6380 if(returnType.kind != voidType)
6381 f.Printf("return ");
6382 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6383 for(param = dataType.params.first; param; param = param.next)
6385 if(param.prev) f.Printf(", ");
6386 if(param.kind != voidType)
6387 f.Printf(param.name);
6393 if(extraIndent) f.Printf(" ");
6394 f.Printf(" %c", CloseBracket);
6399 if(extraIndent) { x1 += 3; x2 += 3; }
6400 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6402 this.updatingCode = false;
6406 // Return false if we overrided a function and don't want to run params listing
6407 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6409 bool didOverride = false;
6410 EditLine line = editBox.line;
6411 char * text = line.text;
6412 int lineNum, charPos;
6413 Expression exp = null;
6416 //Identifier id = null;
6417 Expression memberExp = null;
6418 Identifier realIdentifier = null;
6420 if(!parsing) return true;
6421 if(!privateModule) return !didOverride;
6423 insideFunction = null;
6425 charPos = editBox.charPos + 1;
6426 if(!membersListShown)
6431 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6433 EditBoxStream f { editBox = editBox };
6435 updatingCode = true;
6436 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6440 if(!f.Seek(-1, current))
6443 if(!isspace(ch)) break;
6444 f.Seek(-1, current);
6446 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6448 lineNum = editBox.lineNumber + 1;
6449 charPos = editBox.charPos + 1;
6451 updatingCode = false;
6454 if(!membersListShown)
6456 memberExp = FindExpTree(ast, lineNum, charPos);
6457 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6462 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6464 EditBoxStream f { editBox = editBox };
6467 updatingCode = true;
6469 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6472 if(ch == '}' || ch == ',' || ch == ')')
6474 f.Seek(-1, current);
6482 if(!f.Seek(-1, current))
6485 if(!isspace(ch)) break;
6486 f.Seek(-1, current);
6490 f.Seek(-1, current);
6492 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6494 lineNum = editBox.lineNumber + 1;
6495 charPos = editBox.charPos + 1;
6497 updatingCode = false;
6500 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6505 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6506 lineNum = editBox.lineNumber + 1;
6507 charPos = editBox.charPos/* + 1*/;
6511 char tempString[1024];
6512 char * string = null;
6513 CodePosition idStart, idEnd;
6515 if(membersListShown)
6517 char * buffer = membersLine.text;
6519 bool firstChar = true;
6521 string = tempString;
6523 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6525 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6526 if(!isSpace) firstChar = false;
6528 string[len++] = buffer[c];
6532 else //if(realIdentifier)//if(id)
6535 char * buffer = id.string;
6537 bool firstChar = true;
6539 string = tempString;
6540 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6542 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6543 if(!isSpace) firstChar = false;
6545 string[len++] = buffer[c];
6551 EditLine editLine = editBox.line;
6552 bool firstChar = true;
6555 string = tempString;
6556 for(y = lineNum-1; y >= 0; y--)
6558 char * buffer = editLine.text;
6559 int lineCount = editLine.count;
6560 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6562 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6567 idEnd.charPos = x + 2;
6572 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6575 idEnd.charPos = x + 2;
6582 if(!isalnum(buffer[x]) && buffer[x] != '_')
6588 memmove(string+1, string, len++);
6589 string[0] = buffer[x];
6593 //if(done || firstChar)
6594 if(done || !firstChar)
6596 editLine = editLine.prev;
6599 if(!strcmp(string, "case"))
6605 else if(!strcmp(string, "return"))
6611 else if(!strcmp(string, "delete"))
6617 else if(!strcmp(string, "new"))
6623 else if(!strcmp(string, "renew"))
6631 idStart.charPos = x + 1;
6632 idStart.line = y + 1;
6635 if(!membersListShown)
6637 membersList.Clear();
6638 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6640 Type type = memberExp.member.exp.expType;
6641 if(pointer == 2 && type)
6643 if(type.kind == pointerType || type.kind == arrayType)
6652 ListSymbols(exp, enumOnly, string, realIdentifier);
6654 membersList.Sort(null, 1);
6659 // Virtual function override
6660 Identifier id = GetDeclId(insideFunction.declarator);
6661 char * string = id ? id.string : null;
6663 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6666 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6667 insideFunction = null;
6670 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6675 if(!didOverride) //insideFunction)
6677 rowCount = membersList.rowCount;
6680 DataRow row = string ? membersList.FindSubString(string) : null;
6681 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6683 char * newString = row.string;
6684 if(!membersListShown)
6686 membersLoc.start.line = idStart.line-1;
6687 membersLoc.start.charPos = idStart.charPos-1;
6688 //membersLoc.end = membersLoc.start;
6689 membersLoc.end.charPos = idEnd.charPos-1;
6690 membersLoc.end.line = idEnd.line-1;
6691 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6692 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6697 membersList.Destroy(0);
6698 membersListShown = false;
6701 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6703 line, membersLoc.start.line, membersLoc.start.charPos,
6704 line, membersLoc.end.line, membersLoc.end.charPos);
6705 editBox.PutS(newString);
6711 row = membersList.FindSubStringi(string);
6713 membersList.currentRow = row;
6714 membersList.currentRow.selected = false;
6717 membersList.currentRow = row;
6719 if(!membersListShown)
6723 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6724 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6725 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6726 editBox.GetCaretPosition(caret);
6727 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6729 membersList.master = this;
6731 caret.y += editBox.GetCaretSize();
6733 membersList.Create();
6736 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6737 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6738 Window parent = membersList.parent;
6740 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6742 y -= editBox.GetCaretSize() + membersList.size.h;
6743 membersAbove = true;
6746 membersAbove = false;
6748 membersList.position = { x, y };
6752 membersLoc.start.line = lineNum - 1;
6754 if(string && string[0])
6756 membersLoc.start.charPos = idStart.charPos-1;
6757 membersLoc.end = membersLoc.start;
6758 //membersLoc.end.charPos = id.loc.end.charPos-1;
6759 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6763 membersLoc.start.charPos = charPos;
6764 membersLoc.end = membersLoc.start;
6765 membersLoc.end.charPos = charPos;
6767 membersListShown = true;
6769 // Hack to keep caret shown
6770 editBox.GetCaretPosition(caret);
6771 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6774 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6780 SetCurrentContext(globalContext);
6783 return !didOverride;
6786 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6788 EditLine line = editBox.line;
6789 char * text = line.text;
6790 int lineNum, charPos;
6791 Expression exp = null;
6795 if(!parsing) return;
6797 charPos = editBox.charPos + 1;
6800 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6802 EditBoxStream f { editBox = editBox };
6805 updatingCode = true;
6806 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6809 if(ch == '}' || ch == ',' || ch == ')')
6811 f.Seek(-1, current);
6819 if(!f.Seek(-1, current))
6822 if(!isspace(ch)) break;
6823 f.Seek(-1, current);
6827 f.Seek(-1, current);
6829 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6831 lineNum = editBox.lineNumber + 1;
6832 charPos = editBox.charPos + 1;
6834 updatingCode = false;
6837 charPos = Min(charPos, l1.count + 1);
6839 FindParamsTree(ast, lineNum, charPos);
6841 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6842 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6844 ::functionType = null;
6845 ::instanceType = null;
6848 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6849 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6853 Window parent = paramsList.parent;
6855 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6858 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6859 // ( Dummy exp: always ends up with same memory)
6861 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6862 editBox.GetCaretPosition(paramsPosition);
6863 this.paramsPosition.y += editBox.GetCaretSize();
6866 FreeType(this.functionType);
6867 FreeType(this.instanceType);
6869 this.functionType = ::functionType;
6870 this.instanceType = ::instanceType;
6872 if(this.functionType) this.functionType.refCount++;
6873 if(this.instanceType) this.instanceType.refCount++;
6875 this.paramsID = ::paramsID;
6876 functionExp = paramsInsideExp;
6878 paramsList.master = this;
6880 paramsList.Create();
6882 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6883 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6885 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6887 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6891 paramsAbove = false;
6892 if(x + paramsList.size.w > parent.clientSize.w)
6894 x = parent.clientSize.w - paramsList.size.w;
6898 paramsList.position = { x, y };
6900 // Hack to keep caret shown
6903 editBox.GetCaretPosition(caret);
6904 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6907 this.paramsShown = true;
6909 else if((!::functionType && !::instanceType) || reposition)
6911 paramsList.Destroy(0);
6912 paramsShown = false;
6914 FreeType(this.functionType);
6915 FreeType(this.instanceType);
6916 this.functionType = null;
6917 this.instanceType = null;
6921 SetCurrentContext(globalContext);
6929 designer.visible = true;
6930 designer.Activate();
6936 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6938 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };
6943 static int nofdigits(int v)
6945 if(v == MININT) return 10 + 1;
6946 if(v < 0) return nofdigits(-v) + 1;