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] == '\\')
204 void OutputType(File f, Type type, bool outputName)
214 if(!type.isSigned) f.Printf("unsigned ");
218 if(!type.isSigned) f.Printf("unsigned ");
222 if(!type.isSigned) f.Printf("unsigned ");
226 if(!type.isSigned) f.Printf("unsigned ");
230 if(!type.isSigned) f.Printf("unsigned ");
241 if(type._class && !strcmp(type._class.string, "class"))
243 switch(type.classObjectType)
246 f.Printf("any_object");
249 f.Printf("typed_object");
256 // ADD CODE TO DECIDE WHETHER TO OUTPUT FULLY QUAlIFIED OR NOT:
257 f.Printf(type._class.shortName ? type._class.shortName : type._class.string);
267 OutputType(f, type.type, false);
270 OutputType(f, type.type, false);
289 if(type.kind == arrayType)
292 f.Printf("%d", type.arraySize);
298 void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
304 f.Seek(pos - *position, current);
306 // Try to delete spaces and \n before...
312 /*else if(ch == '\n')
314 // Look for // comments on the line before
315 EditBox editBox = f.editBox;
316 EditLine line = editBox.line;
323 for(c = 0; text[c]; c++)
332 if(text[c] == '/' && last == '/')
344 f.DeleteBytes(before);
349 void GetLocText(EditBox editBox, File f, int position, Location loc, char ** text, int * size, int pad, int linePad)
354 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
356 // Cut & Paste function
362 f.Seek(loc.start.pos - position, current);
364 x1 = editBox.charPos;
365 y1 = editBox.lineNumber;
366 f.Seek(loc.end.pos - loc.start.pos, current);
368 x2 = editBox.charPos;
369 y2 = editBox.lineNumber;
370 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
372 *size = editBox.SelSize();
373 *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
374 editBox.GetSel(*text, false);
377 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
378 f.Printf(""); // Make the stream point to where the editbox is
381 void Code_FixProperty(Property prop, Instance object)
383 Designer::FixProperty(prop, object);
386 bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
389 if(prop.dataTypeString && (!prop.IsSet || prop.IsSet(selected.instance)))
391 Class dataType = prop.dataTypeClass;
394 dataType = prop.dataTypeClass = eSystem_FindClass(test._class.module, prop.dataTypeString);
396 if(dataType && dataType._vTbl && dataType.type == structClass)
398 void * dataForm = new0 byte[dataType.structSize];
399 void * dataTest = new0 byte[dataType.structSize];
401 ((void (*)(void *, void *))(void *)prop.Get)(selected.instance, dataForm);
402 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
404 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
406 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
412 else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
414 void * dataForm, * dataTest;
416 dataForm = ((void *(*)(void *))(void *)prop.Get)(selected.instance);
417 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
419 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
421 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
425 else if(dataType && dataType._vTbl)
427 DataValue dataForm, dataTest;
429 GetProperty(prop, selected.instance, &dataForm);
430 GetProperty(prop, test, &dataTest);
432 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
434 SetProperty(prop, test, dataForm);
436 // In case setting on test unset on real instance (e.g. isDefault)
437 if(strcmp(prop.name, "name"))
439 GetProperty(prop, selected.instance, &dataTest);
440 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
441 SetProperty(prop, selected.instance, dataForm);
450 bool Code_IsPropertyDisabled(ObjectInfo selected, char * name)
452 bool disabled = false;
453 if(selected.oClass == selected)
456 if(selected.classDefinition)
458 for(def = selected.classDefinition.definitions->first; def; def = def.next)
460 if(def.type == defaultPropertiesClassDef)
463 for(prop = def.defProperties->first; prop; prop = prop.next)
465 if(prop.identifiers && prop.identifiers->first)
467 Identifier id = prop.identifiers->first;
468 if(prop.variable && !strcmp(id.string, name))
480 else if(selected.instCode)
483 if(selected.instCode.members)
485 for(members = selected.instCode.members->first; members; members = members.next)
487 if(members.type == dataMembersInit && members.dataMembers)
490 for(prop = members.dataMembers->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))
510 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
515 method.dataType = ProcessTypeString(method.dataTypeString, false);
516 if(!method.dataType.thisClass && !isForm)
519 method.dataType.thisClass = selectedClass;
521 //result = MatchTypes(method.dataType, type, null, regClass, regClass, false);
522 result = MatchTypes(type, method.dataType, null, regClass, regClass, false, true, true, false);
524 method.dataType.thisClass = null;
528 bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo object)
530 bool confirmation = true;
531 Statement body = function.body;
532 // Check if it contains any code
533 if((!body.compound.declarations || !body.compound.declarations->count) && (!body.compound.statements || body.compound.statements->count <= 1))
535 Class moduleClass = eSystem_FindClass(object.instance._class.module, "Module");
536 Statement stmt = body.compound.statements ? body.compound.statements->first : null;
537 Type dataType = method.dataType;
538 Type returnType = dataType.returnType;
539 Expression exp = null;
542 method.dataType = ProcessTypeString(method.dataTypeString, false);
544 confirmation = false;
546 // Check if default function should be calling base class:
547 if(object.instance._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
549 if(returnType.kind != voidType)
551 if(!stmt || stmt.type != returnStmt || !stmt.expressions || stmt.expressions->count != 1)
555 exp = stmt.expressions->first;
556 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
558 if( (exp.type != identifierExp || strcmp(exp.identifier.string, "true")) &&
559 (exp.type != constantExp || strcmp(exp.constant, "1")))
564 if(exp.type != constantExp || strcmp(exp.constant, "0"))
579 if(returnType.kind != voidType)
581 if(stmt.type == returnStmt && stmt.expressions && stmt.expressions->count == 1)
582 exp = stmt.expressions->first;
584 else if(stmt.type == expressionStmt && stmt.expressions && stmt.expressions->count == 1)
585 exp = stmt.expressions->first;
588 if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
592 Identifier id = exp.call.exp.identifier;
593 Class base = object.instance._class;
594 if(!id._class || (id._class.name && !strcmp(id._class.name, base.name)) || strcmp(id.string, method.name))
598 Expression arg = exp.call.arguments ? exp.call.arguments->first : null;
599 if(!arg || arg.type != identifierExp || strcmp("this", arg.identifier.string))
605 for(param = dataType.params.first; param; param = param.next)
607 if(!arg || arg.type != identifierExp || strcmp(param.name, arg.identifier.string))
612 arg = arg ?arg.next : null;
619 return !confirmation;
622 class CodeEditor : Window
624 background = marginColor;
625 borderStyle = sizableDeep;
630 isActiveClient = true;
631 anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
634 // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
635 // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
637 SheetType sheetSelected;
642 Context globalContext { };
643 OldList excludedSymbols { offset = (uint)&((Symbol)0).left };
656 MethodAction methodAction;
658 ClassFunction function;
660 char methodName[1024];
665 bool membersListShown;
668 EditLine membersLine;
670 Type functionType, instanceType;
674 Point paramsPosition;
675 Expression functionExp;
678 BitmapResource icons[CodeObjectType];
680 FontResource boldFont { $"Tahoma", 8.25f, bold = true, window = this };
681 FontResource normalFont { $"Tahoma", 8.25f, window = this };
683 Module privateModule;
684 NameSpace globalData;
687 OpenedFileInfo openedFileInfo;
689 FontResource font { codeFont.faceName, codeFont.size };
690 saveDialog = codeEditorFileDialog;
692 Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
696 property bool parsing { get { return editBox.syntaxHighlighting && !noParsing && !ide.noParsing; } };
698 void ProcessCaretMove(EditBox editBox, int line, int charPos)
701 ObjectInfo classItem;
703 // OnActivateClient is called after OnActivate
706 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
709 if(sheet.codeEditor != this) return;
713 for(classItem = classes.first; classItem; classItem = classItem.next)
715 ClassDefinition classDef = classItem.classDefinition;
716 if(classDef && classDef.loc.Inside(line, charPos))
723 for(object = classItem.instances.first; object; object = object.next)
727 if(object.instCode.loc.Inside(line, charPos))
732 sheet.SelectObject(object);
734 sheet.SelectObject(classItem);
739 //sheet.SelectObject(null);
743 sprintf(temp, $"Ln %d, Col %d", line, editBox.column + 1);
747 expectingMove = false;
753 if(line-1 != membersLoc.start.line)
757 char * buffer = membersLine.text;
760 if(charPos - 1 < membersLoc.start.charPos)
762 else if(charPos - 1 > membersLoc.end.charPos)
764 char * buffer = membersLine.text;
765 //if(membersList.currentRow)
769 for(c = membersLoc.start.charPos; c<=charPos && buffer[c]; c++)
770 if(buffer[c] != ' ' && buffer[c] != '\t')
772 if(c < charPos && buffer[c])
779 membersList.Destroy(0);
780 membersListShown = false;
784 bool back = codeModified;
785 codeModified = false;
787 InvokeParameters(false, false, false);
788 /*if(membersListShown)
789 InvokeAutoComplete(false, 0, true);*/
796 watch(modifiedDocument)
798 ProjectView projectView = ide.projectView;
801 ProjectNode node = projectView.GetNodeFromWindow(this, null, true, false);
804 node.modified = modifiedDocument;
805 projectView.Update(null);
813 textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
814 freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
815 tabKey = true, smartHome = true;
816 tabSelection = true, /*maxLineSize = 65536, */parent = this, hasHorzScroll = true, hasVertScroll = true;
817 selectionColor = selectionColor, selectionText = selectionText,
818 background = codeEditorBG, foreground = codeEditorFG, syntaxColorScheme = colorScheme,
819 font = font, borderStyle = none;
820 anchor = Anchor { left = 0, right = 0, top = 0, bottom = 0 };
822 bool OnMouseOver(int x, int y, Modifiers mods)
824 CodeEditor editor = (CodeEditor)master;
825 if(editor.designer && editor.designer.isDragging && !mods.isSideEffect)
830 void NotifyCaretMove(EditBox editBox, int line, int charPos)
832 // Update Line Numbers
834 int oldLine = lastLine;
835 display.FontExtent(font.font, " ", 1, null, &spaceH);
837 Box box { 0, (Min(oldLine,oldLine)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(oldLine, oldLine))*spaceH-1 - editBox.scroll.y };
841 Box box { 0, (Min(line,line)-1) * spaceH - editBox.scroll.y, editBox.anchor.left.distance, (Max(line, line))*spaceH-1 - editBox.scroll.y };
846 if(ide.activeClient == this)
847 ProcessCaretMove(editBox, line, charPos);
849 openedFileInfo.CaretMove(line, charPos);
852 void NotifyOvrToggle(EditBox editBox, bool overwrite)
854 ide.ovr.color = overwrite ? black : Color { 128, 128, 128 };
857 void NotifyUpdate(EditBox editBox)
864 designer.modifiedDocument = true;
867 modifiedDocument = true;
870 bool NotifyUnsetModified(EditBox editBox)
872 modifiedDocument = false;
876 bool NotifyCharsAdded(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
878 if(!loadingFile && after.y != before.y)
880 ProjectView projectView = ide.projectView;
881 if(projectView && fileName)
884 // HOW WE MIGHT WANT TO DO IT:
885 char * text = before.line.text;
886 for(c = before.x-1; c>= 0; c--)
887 if(!isspace(text[c]))
889 ide.debugger.MoveIcons(fileName, before.y + (((!pasteOperation && c > -1) || !after.line.count) ? 1 : 0), after.y - before.y, false);
891 // HOW VISUAL STUDIO DOES IT:
893 char * text = after.line.text;
894 for(c = after.line.count-1; c>= 0; c--)
895 if(!isspace(text[c]))
897 ide.debugger.MoveIcons(fileName, before.y + ((c < 0) ? 1 : 0), after.y - before.y, false);
900 Update({ 0, 0, editBox.position.x, clientSize.h });
907 for(oClass = classes.first; oClass; oClass = oClass.next)
910 for(object = oClass.instances.first; object; object = object.next)
914 object.instCode.loc.start.AdjustAdd(before, after);
915 object.instCode.loc.end.AdjustAdd(before, after);
920 oClass.classDefinition.loc.start.AdjustAdd(before, after);
921 oClass.classDefinition.loc.end.AdjustAdd(before, after);
927 expectingMove = true;
931 if(before.y != after.y)
935 char * buffer = membersLine.text;
937 bool firstChar = true;
938 bool addedChar = false;
944 membersLoc.end.charPos += after.x - Max(membersLoc.start.charPos, before.x);
946 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
948 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
949 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar)) //|| membersList.currentRow
958 membersLoc.start.charPos++;
963 string[len++] = buffer[c];
967 row = membersList.currentRow;
968 if(row && row.selected)
972 membersLoc.start.charPos--;
980 row = membersList.FindSubString(string);
982 membersList.currentRow = row;
985 row = membersList.FindSubStringi(string);
987 membersList.currentRow = row;
988 membersList.currentRow.selected = false;
991 membersList.SetScrollPosition(0, (row.index) * membersList.rowHeight);
995 row = membersList.currentRow;
998 // Accept current string if hiding typing char
999 if(hide && row && row.selected)
1001 char * string = row.string;
1002 int len = strlen(string);
1003 membersLoc.end.charPos -= after.x - before.x;
1004 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1005 editBox.Delete(membersLine, membersLoc.start.line, membersLoc.start.charPos,
1006 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1007 editBox.PutS(string);
1008 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos + len + 1 /*after.x - before.x*/);
1010 after.x += membersLoc.start.charPos + len - before.x;
1011 before.x = membersLoc.start.charPos + len;
1016 membersList.Destroy(0);
1017 membersListShown = false;
1020 if(/*after.x - before.x == 1 && */after.y == before.y && !membersListShown)
1022 EditLine line = editBox.line;
1023 char * text = line.text;
1024 char ch = text[after.x-1];
1025 if(ch == '.' || (ch == '>' && after.x-1 > 0 && text[after.x-1-1] == '-') || (ch == ':' && after.x-1 > 0 && text[after.x-1-1] == ':'))
1029 // Can we call invoke auto complete here instead?
1039 // Force caret update already...
1040 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1041 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1043 editBox.GetCaretPosition(&caret);
1047 // Go back in the buffer until no space before
1049 codeModified = true;
1053 EditBoxStream f { editBox = editBox };
1057 if(text[after.x-1] == '>')
1063 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
1067 if(!f.Seek(-1, current))
1070 if(!isspace(ch)) break;
1071 f.Seek(-1, current);
1073 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
1075 line = editBox.lineNumber + 1;
1076 charPos = editBox.charPos + 1;
1080 exp = FindExpTree(ast, line, charPos);
1084 Type type = exp.expType;
1086 if(type && text[after.x-1] != '.')
1088 if(type.kind == TypePointer || type.kind == TypeArray)
1094 membersList.Clear();
1097 if(membersList.rowCount)
1099 membersList.Sort(null, 1);
1100 membersList.master = this;
1102 caret.y += editBox.GetCaretSize();
1105 membersList.Create();
1108 int x = caret.x + editBox.GetAbsX() - app.desktop.GetAbsX() - editBox.GetScrollX();
1109 int y = caret.y + editBox.GetAbsY() - app.desktop.GetAbsY() - editBox.GetScrollY();
1110 Window parent = membersList.parent;
1112 if(!paramsAbove && (paramsShown || y + membersList.GetHeight() > parent.GetClientHeight()))
1114 y -= editBox.GetCaretSize() + membersList.GetHeight();
1115 membersAbove = true;
1118 membersAbove = false;
1120 membersList.position = { x, y };
1124 membersLoc.start.line = line - 1;
1125 membersLoc.start.charPos = oldCharPos;
1126 membersLoc.end = membersLoc.start;
1127 membersListShown = true;
1132 SetCurrentContext(globalContext);
1134 codeModified = true;
1135 skipModified = true;
1136 if(text[after.x-1] == ':')
1137 InvokeAutoComplete(false, 0, false);
1138 else if(text[after.x-1] == '.')
1139 InvokeAutoComplete(false, 1, false);
1140 else if(text[after.x-1] == '>')
1141 InvokeAutoComplete(false, 2, false);
1142 skipModified = false;
1144 else if(ch == '(' || ch == OpenBracket || ch == ',' || ch == '=' || ch == '?' || ch == ':')
1146 codeModified = true;
1147 skipModified = true;
1149 if(InvokeAutoComplete(true, 0, false))
1151 if(ch == '(' || ch == OpenBracket)
1152 InvokeParameters(true, true, false);
1154 InvokeParameters(this.functionType ? false : true, false, false);
1157 // InvokeAutoComplete(true, 0, false);
1158 skipModified = false;
1160 else if(ch == ')' || ch == '}' || ch == ';')
1162 codeModified = true;
1163 skipModified = true;
1165 InvokeParameters(false, true, false);
1166 skipModified = false;
1170 bool back = codeModified;
1171 codeModified = false;
1173 InvokeParameters(false, false, true);
1174 if(membersListShown)
1175 InvokeAutoComplete(false, 0, true);
1176 codeModified = back;
1181 bool back = codeModified;
1182 codeModified = false;
1185 InvokeParameters(false, false, true);
1186 /*if(membersListShown)
1187 InvokeAutoComplete(false, 0, true);*/
1189 codeModified = back;
1196 bool NotifyCharsDeleted(EditBox editBox, BufferLocation before, BufferLocation after, bool pasteOperation)
1198 if(!loadingFile && after.y != before.y)
1200 ProjectView projectView = ide.projectView;
1201 if(projectView && fileName)
1202 ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
1203 Update({ 0, 0, editBox.position.x, clientSize.h });
1210 for(oClass = classes.first; oClass; oClass = oClass.next)
1214 for(object = oClass.instances.first; object; object = object.next)
1218 loc = &object.instCode.loc;
1220 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1221 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1223 object.instCode = null;
1227 loc->start.AdjustDelete(before, after);
1228 loc->end.AdjustDelete(before, after);
1232 if(oClass.classDefinition)
1234 loc = &oClass.classDefinition.loc;
1235 if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
1236 (after.y+1 > loc->end.line || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
1238 oClass.classDefinition = null;
1242 loc->start.AdjustDelete(before, after);
1243 loc->end.AdjustDelete(before, after);
1248 if(membersListShown)
1251 if(pasteOperation || before.y != after.y)
1255 char * buffer = membersLine.text;
1257 bool firstChar = true;
1261 if(before.x >= membersLoc.start.charPos)
1263 for(c = membersLoc.start.charPos; c<before.x && len < sizeof(string)-1; c++)
1265 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1266 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1271 if(!isSpace) firstChar = false;
1274 string[len++] = buffer[c];
1279 // If deleting spaces before...
1280 for(c = before.x; c<membersLoc.start.charPos; c++)
1282 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1290 membersLoc.start.charPos = before.x;
1293 if(membersLoc.end.charPos >= after.x)
1295 for(c = after.x; c<membersLoc.end.charPos && len < sizeof(string)-1; c++)
1297 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
1298 if(!isalnum(buffer[c]) && buffer[c] != '_' && (!isSpace || !firstChar))
1303 if(!isSpace) firstChar = false;
1306 string[len++] = buffer[c];
1314 membersLoc.end.charPos -= after.x - before.x;
1318 row = membersList.FindSubString(string);
1321 row = membersList.FindSubStringi(string);
1323 membersList.currentRow = row;
1324 membersList.currentRow.selected = false;
1327 membersList.currentRow = row;
1329 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
1334 membersList.Destroy(0);
1335 membersListShown = false;
1341 InvokeParameters(false, false);
1349 bool NotifyDropped(EditBox editBox, int x, int y)
1351 char * controlClass = toolBox.controlClass;
1352 if(controlClass && controlClass[0])
1356 ObjectInfo classObject;
1358 //editBox.NotifyCaretMove(this, editBox, y, x);
1359 editBox.GoToLineNum(y);
1360 editBox.GoToPosition(editBox.line, y, x);
1362 classObject = selected ? selected.oClass : null;
1364 if((!selected || selected == classObject) && classObject && classObject.instances.first)
1365 selected = classObject.instances.last;
1368 control = eInstance_New(eSystem_FindClass(privateModule, controlClass));
1371 AddObject(control, &object);
1373 designer.CreateObject(control, object, false, classObject.instance);
1374 // designer.PostCreateObject(control, object, false, classObject.instance);
1375 designer.DroppedObject(control, object, false, classObject.instance);
1377 sheet.AddObject(object, object.name, typeData /* className*/, true);
1380 //codeModified = true;
1387 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
1389 if(key == ctrlSpace)
1391 membersList.Destroy(0);
1392 membersListShown = false;
1393 InvokeAutoComplete(false, 0, false);
1396 else if(key == Key { space, ctrl = true, shift = true })
1397 InvokeParameters(false, true, false);
1398 else if(key == escape)
1399 ide.RepositionWindows(true);
1400 else if(key == ctrlF7)
1404 ProjectNode node = ide.projectView.GetNodeFromWindow(this, null, true, false);
1406 node = ide.projectView.GetNodeFromWindow(this, null, true, true);
1410 s = PrintString($"The ", fileName, $" file is not part of any project.\n",
1411 $"It can't be compiled.");
1412 MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
1421 bool OnKeyDown(Key key, unichar ch)
1423 CodeEditor editor = (CodeEditor)master;
1424 if(key == escape /*|| key == leftAlt || key == rightAlt || (key.ctrl && key.code != left && key.code != right && key.code != leftShift && key.code != rightShift && key.code != space)*/)
1426 if(editor.membersListShown)
1428 editor.membersList.Destroy(0);
1429 editor.membersListShown = false;
1432 if(editor.paramsShown)
1434 editor.paramsList.Destroy(0);
1435 editor.paramsShown = false;
1436 FreeType(editor.functionType);
1437 FreeType(editor.instanceType);
1439 editor.functionType = null;
1440 editor.instanceType = null;
1441 editor.paramsID = -1;
1445 return EditBox::OnKeyDown(key, ch);
1448 void OnVScroll(ScrollBarAction action, int position, Key key)
1450 if(anchor.left.distance)
1452 Box box { 0, 0, anchor.left.distance-1, parent.clientSize.h - 1 };
1455 EditBox::OnVScroll(action, position, key);
1457 CodeEditor ce = (CodeEditor)parent;
1458 if(ce.openedFileInfo)
1459 ce.openedFileInfo.ScrollChange({ scroll.x, position });
1463 void OnHScroll(ScrollBarAction action, int position, Key key)
1465 EditBox::OnHScroll(action, position, key);
1467 CodeEditor ce = (CodeEditor)parent;
1468 if(ce.openedFileInfo)
1469 ce.openedFileInfo.ScrollChange({ position, scroll.y });
1476 fullRowSelect = false,
1479 borderStyle = bevel;
1480 // size = { 200, 400 };
1482 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
1484 DataRow row = listBox.currentRow;
1487 char * string = row.string;
1489 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
1491 membersLine, membersLoc.start.line, membersLoc.start.charPos,
1492 membersLine, membersLoc.end.line, membersLoc.end.charPos);
1493 editBox.PutS(string);
1496 membersListShown = false;
1501 bool OnKeyDown(Key key, unichar ch)
1503 CodeEditor editor = (CodeEditor) master;
1504 if(key == escape || key == leftAlt || key == rightAlt ||
1505 (key.ctrl && key.code != left && key.code != right &&
1506 key.code != leftShift && key.code != rightShift && key.code != space))
1509 if(editor.paramsShown)
1513 editor.paramsList.Destroy(0);
1514 editor.paramsShown = false;
1516 if(editor.membersListShown)
1520 editor.membersList.Destroy(0);
1521 editor.membersListShown = false;
1524 FreeType(editor.functionType);
1525 editor.functionType = null;
1527 FreeType(editor.instanceType);
1528 editor.instanceType = null;
1530 editor.paramsID = -1;
1535 return editor.editBox.OnKeyDown(key, ch);
1539 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1541 CodeEditor editor = (CodeEditor)master;
1542 Window rw = previous ? previous.rootWindow : null;
1543 if(!active && rw != editor.paramsList)
1546 editor.membersListShown = false;
1548 return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
1551 bool OnKeyHit(Key key, unichar ch)
1553 CodeEditor editor = (CodeEditor) master;
1557 case enter: case tab:
1559 DataRow row = currentRow;
1560 if(row && row.selected)
1562 char * string = row.string;
1564 editor.editBox.GoToPosition(editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos);
1565 editor.editBox.Delete(
1566 editor.membersLine, editor.membersLoc.start.line, editor.membersLoc.start.charPos,
1567 editor.membersLine, editor.membersLoc.end.line, editor.membersLoc.end.charPos);
1568 editor.editBox.PutS(string);
1571 editor.membersListShown = false;
1574 editor.editBox.OnKeyHit(key, ch);
1584 return ListBox::OnKeyHit(key, ch);
1590 // If before . or after
1591 //listBox.Destroy(true);
1592 result = editor.editBox.OnKeyHit(key, ch);
1607 clickThrough = true,
1609 borderStyle = contour,
1611 background = { 255,255,225 },
1613 OnKeyDown = membersList.OnKeyDown;
1615 /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
1617 CodeEditor editor = (CodeEditor)master;
1618 Window rw = previous ? previous.rootWindow : null;
1619 if(!active && previous != editor.editBox && rw != editor.membersList)
1622 editor.paramsShown = false;
1624 return Window::OnActivate(active, previous, goOnWithActivation, direct);
1627 bool OnKeyHit(Key key, unichar ch)
1629 CodeEditor editor = (CodeEditor)master;
1631 if(!editor.membersListShown || editor.membersList.OnKeyHit(key, ch))
1634 bool result = true; editor.editBox.OnKeyHit(key, ch);
1635 return (!created) ? false : result;
1642 void OnRedraw(Surface surface)
1644 CodeEditor editor = (CodeEditor) master;
1645 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1647 Type methodType = null;
1651 int functionW, nameW = 0;
1653 int spaceW, spaceH, commaW, commaWB, parW;
1655 int maxW = 0, lineW = 0;
1661 Font font = editor.normalFont.font;
1662 Font boldFont = editor.boldFont.font;
1663 Display display = this.display;
1665 if(!type) { return; };
1667 if(type.kind == TypeKind::methodType) { methodType = type; type = type.method.dataType; }
1669 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1670 display.FontExtent(font, ", ", 2, &commaW, null);
1671 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1672 display.FontExtent(font, ")", 1, &parW, null);
1675 if(editor.functionType)
1677 PrintType(type.returnType, string, true, true);
1678 display.FontExtent(font, string, strlen(string), &functionW, null);
1680 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1681 totalW = nameW + functionW + 2 * parW;
1685 PrintType(type, string, (type.kind == functionType) ? true : false, true); // true);
1686 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1687 if(instanceName && type.kind != functionType)
1688 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1689 totalW = functionW + nameW;
1690 surface.TextFont(boldFont);
1693 surface.WriteText(x, y, string, strlen(string));
1694 x += functionW + spaceW;
1696 if(editor.functionType)
1699 surface.WriteText(x, y, type.name, strlen(type.name));
1701 surface.WriteText(x, y, "(", 1);
1704 if(methodType && !methodType.staticMethod && methodType.methodClass)
1708 if(id == editor.paramsID)
1709 surface.TextFont(boldFont);
1711 if(methodType.methodClass)
1712 surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
1716 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1717 width += ((id == editor.paramsID) ? commaWB : commaW);
1722 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1727 x = 2 + nameW + spaceW + functionW + parW;
1731 if(methodType.methodClass)
1732 surface.WriteText(x, y, methodType.methodClass.name, strlen(methodType.methodClass.name));
1735 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1737 surface.WriteText(x, y, ",", 1);
1738 x += ((id == editor.paramsID) ? commaWB : commaW);
1746 if(id == editor.paramsID)
1747 surface.TextFont(font);
1751 if(!methodType || (methodType.staticMethod || !methodType.methodClass) || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1753 for(param = type.params.first; param; param = param.next)
1755 char paramString[1024];
1758 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1759 surface.TextFont(boldFont);
1762 PrintType(param, paramString, true, true);
1763 surface.TextExtent(paramString, strlen(paramString), &tw, null);
1765 if(param.next) width += ((id == editor.paramsID) ? commaWB : commaW);
1770 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1775 x = 2 + nameW + spaceW + functionW + parW;
1779 surface.WriteText(x, y, paramString, strlen(paramString));
1783 surface.WriteText(x, y, ",", 1);
1784 x += ((id == editor.paramsID) ? commaWB : commaW);
1792 if(id == editor.paramsID || (param.kind == ellipsisType && id < editor.paramsID && editor.paramsID != -1))
1793 surface.TextFont(font);
1798 surface.WriteText(x, y, ")", 1);
1800 else if(instanceName && type.kind != functionType)
1802 surface.WriteText(x, y, instanceName, strlen(instanceName));
1806 bool OnResizing(int * w, int * h)
1808 CodeEditor editor = (CodeEditor) master;
1809 Type type = editor.functionType ? editor.functionType : editor.instanceType;
1811 Type methodType = null;
1815 int functionW = 0, nameW = 0;
1817 int spaceW, spaceH, commaW, commaWB, parW;
1819 int maxW = 0, lineW = 0;
1824 Font font = editor.normalFont.font;
1825 Font boldFont = editor.boldFont.font;
1826 Display display = this.display;
1828 if(type.kind == TypeKind::methodType)
1831 ProcessMethodType(type.method);
1832 type = type.method.dataType;
1835 display.FontExtent(boldFont, " ", 1, &spaceW, &spaceH);
1836 display.FontExtent(font, ", ", 2, &commaW, null);
1837 display.FontExtent(boldFont, ", ", 2, &commaWB, null);
1838 display.FontExtent(font, ")", 1, &parW, null);
1841 if(editor.functionType && type)
1843 PrintType(type.returnType, string, true, true);
1844 display.FontExtent(font, string, strlen(string), &functionW, null);
1846 display.FontExtent(font, type.name, strlen(type.name), &nameW, null);
1847 totalW = nameW + spaceW + functionW + 2 * parW;
1851 PrintType(type, string, false, true); // /*true);
1852 display.FontExtent(boldFont, string, strlen(string), &functionW, null);
1853 if(instanceName && type.kind != functionType)
1854 display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
1855 totalW = functionW + nameW + spaceW;
1858 if(editor.functionType)
1864 if(methodType.methodClass)
1865 display.FontExtent((id == editor.paramsID) ? boldFont : font, methodType.methodClass.name, strlen(methodType.methodClass.name), &width, null);
1866 if(type.params.first && (((Type)type.params.first).kind != voidType || type.params.count > 1))
1867 width += ((id == editor.paramsID) ? commaWB : commaW);
1872 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1885 if(!methodType || methodType.staticMethod || !type.params.first || ((Type)type.params.first).kind != voidType || type.params.count > 1)
1887 for(param = type.params.first; param; param = param.next)
1889 char paramString[1024];
1893 PrintType(param, paramString, true, true);
1894 display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
1896 width += ((id == editor.paramsID) ? commaWB : commaW);
1901 if(lineW && ((height && lineW + width > maxW) || (totalW + lineW + width + 20 > availW)))
1918 *w = realW + totalW + 4;
1924 Menu fileMenu { menu, $"File", f };
1925 MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
1926 MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
1928 Menu debugMenu { menu, $"Debug", d };
1929 MenuItem debugRunToCursor { debugMenu, $"Run To Cursor", c, ctrlF10, id = RTCMenuBits { false, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1930 MenuItem debugSkipRunToCursor { debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true }, id = RTCMenuBits { true, false, false }, NotifySelect = RTCMenu_NotifySelect; };
1931 MenuItem debugRunToCursorAtSameLevel { debugMenu, $"Run To Cursor At Same Level", l, altF10, id = RTCMenuBits { false, true, false }, NotifySelect = RTCMenu_NotifySelect; };
1932 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; };
1934 MenuItem debugBpRunToCursor { debugMenu, $"BP Run To Cursor"/*, c, ctrlF10*/, id = RTCMenuBits { false, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1935 MenuItem debugBpSkipRunToCursor { debugMenu, $"BP Run To Cursor Skipping Breakpoints"/*, u, Key { f10, ctrl = true, shift = true }*/, id = RTCMenuBits { true, false, true }, NotifySelect = RTCMenu_NotifySelect; };
1936 MenuItem debugBpRunToCursorAtSameLevel { debugMenu, $"BP Run To Cursor At Same Level"/*, l, altF10*/, id = RTCMenuBits { false, true, true }, NotifySelect = RTCMenu_NotifySelect; };
1937 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; };
1939 bool RTCMenu_NotifySelect(MenuItem selection, Modifiers mods)
1941 ProjectView projectView = ide.projectView;
1942 if(!projectView.buildInProgress)
1944 RTCMenuBits bits = (RTCMenuBits)selection.id;
1945 int line = editBox.lineNumber + 1;
1948 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
1949 ProjectConfig config = projectView.project.config;
1950 int bitDepth = ide.workspace.bitDepth;
1951 bool useValgrind = ide.workspace.useValgrind;
1952 ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, bits.ignoreBreakpoints, bits.atSameLevel, bits.oldImplementation);
1958 MenuDivider { debugMenu };
1959 MenuItem debugToggleBreakpoint
1961 debugMenu, $"Toggle Breakpoint", t, f9;
1962 bool NotifySelect(MenuItem selection, Modifiers mods)
1964 ProjectView projectView = ide.projectView;
1965 if(projectView && fileName)
1967 int line = editBox.lineNumber + 1;
1968 ide.debugger.ToggleBreakpoint(fileName, line);
1978 //MenuItem viewDesignerItem, viewProperties, viewMethods;
1982 designer.parent = parent;
1985 toolBox = ((IDEWorkSpace)master).toolBox;
1987 // Debugger bug here: value of toolBox appears as 0
1989 sheet = ((IDEWorkSpace)master).sheet;
1994 bool OnClose(bool parentClosing)
1998 if(ide.workspace && fileName)
1999 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2000 if(inUseDebug && !debugClosing)
2002 debugClosing = true;
2004 if(CloseConfirmation(false))
2007 if(modifiedDocument)
2008 OnFileModified({ modified = true }, null);
2010 debugClosing = false;
2013 if(designer && !designer.closing)
2015 if(designer.visible)
2022 //Window formEditor = designer;
2023 //formEditor.Destroy(0);
2026 ide.AdjustFileMenus();
2031 void OnDestroy(void)
2033 ObjectInfo oClass, next;
2034 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2036 FreeType(this.functionType);
2037 FreeType(this.instanceType);
2042 designer.codeEditor = null;
2043 designer.Destroy(0);
2047 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2049 ObjectInfo object, next;
2051 for(object = oClass.instances.first; object; object = next)
2056 Designer::DestroyObject(object.instance);
2057 delete object.instance;
2059 sheet.DeleteObject(object);
2061 oClass.instances.Delete(object);
2065 Designer::DestroyObject(oClass.instance);
2066 delete oClass.instance;
2068 sheet.DeleteObject(oClass);
2070 classes.Delete(oClass);
2073 if(windowClass && windowClass.data)
2074 UnapplySkin(windowClass);
2078 if(sheet.codeEditor == this)
2080 sheet.codeEditor = null;
2081 toolBox.codeEditor = null;
2087 ProjectView projectView = ide.projectView;
2090 ProjectNode node = projectView.GetNodeFromWindow(this, null, false, false);
2091 if(node && node.modified)
2093 node.modified = false;
2094 projectView.Update(null);
2100 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2102 // 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
2104 if(directActivation)
2105 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2107 if(active && directActivation)
2111 openedFileInfo.Activate();
2115 Location * loc = null;
2116 UpdateFormCode(); // To ensure update when modifying properties...
2118 // Got to the right spot in code so we don't lose our form selection...
2121 if(selected.instCode)
2122 loc = &selected.instCode.loc;
2123 else if(selected.classDefinition)
2124 loc = &selected.classDefinition.loc;
2126 line = editBox.lineNumber + 1;
2127 charPos = editBox.charPos + 1;
2132 if(selected && !loc->Inside(line, charPos))
2134 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2135 line = editBox.lineNumber + 1;
2136 charPos = editBox.charPos + 1;
2138 else if(selected && selected.classDefinition)
2141 for(object = selected.instances.first; object; object = object.next)
2145 if(object.instCode.loc.Inside(line, charPos))
2151 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2152 line = editBox.lineNumber + 1;
2153 charPos = editBox.charPos + 1;
2158 ProcessCaretMove(editBox, line, charPos);
2163 if(membersListShown)
2165 membersList.Destroy(0);
2166 membersListShown = false;
2170 paramsList.Destroy(0);
2171 paramsShown = false;
2172 FreeType(functionType);
2173 FreeType(instanceType);
2175 functionType = null;
2176 instanceType = null;
2183 bool OnSaveFile(char * fileName)
2190 f = FileOpen(fileName, write);
2193 if(!ide.projectView)
2194 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2198 this.fileName = fileName; // Put this here because the form designer will check for it...
2199 designer.fileName = fileName;
2200 designer.modifiedDocument = false;
2202 editBox.Save(f, false);
2203 modifiedDocument = false;
2211 bool OnFileModified(FileChange fileChange, char * param)
2213 bool reload = false;
2214 if(visible == false && inUseDebug == true)
2215 ide.debugger.WatchesReleaseCodeEditor();
2220 sprintf(message, $"The document %s was modified by another application.\n"
2221 "Would you like to reload it and lose your changes?", fileName);
2222 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2223 contents = message }.Modal() == yes)
2229 File f = FileOpen(fileName, read);
2232 int lineNumber, charPos, len;
2236 updatingCode = true;
2237 lineNumber = editBox.lineNumber;
2238 charPos = editBox.charPos;
2239 scroll = editBox.scroll;
2242 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2243 len = strlen(editBox.line.text);
2244 editBox.GoToLineNum(lineNumber);
2245 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2246 editBox.scroll = scroll;
2247 updatingCode = false;
2248 loadingFile = false;
2250 codeModified = true;
2254 designer.modifiedDocument = false;
2256 modifiedDocument = false;
2264 void OnRedraw(Surface surface)
2267 surface.SetBackground(marginColor);
2268 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2269 if(ideSettings.showLineNumbers)
2271 int currentLineNumber;
2276 surface.textOpacity = false;
2277 surface.font = font.font;
2278 surface.TextExtent(" ", 1, null, &spaceH);
2279 currentLineNumber = editBox.scroll.y / spaceH + 1;
2281 surface.SetForeground(lineNumbersColor);
2282 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2284 // Highlight current line
2285 if(editBox.lineNumber == currentLineNumber - 1)
2287 surface.SetBackground(selectedMarginColor);
2288 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2289 surface.SetBackground(marginColor);
2291 sprintf(lineText,"%5u ", currentLineNumber % 100000);
2292 if(currentLineNumber <= editBox.numLines)
2293 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,6);
2295 currentLineNumber++;
2299 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2301 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2302 int lineCursor, lineTopFrame, breakpointLines[128];
2303 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2304 Debugger debugger = ide.debugger;
2305 BitmapResource bmpRes;
2307 boxH = clientSize.h;
2308 scrollY = editBox.scroll.y;
2309 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2311 bpOnCursor = bpOnTopFrame = false;
2312 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2315 for(i = 0; i < count; i++)
2317 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2319 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2320 if(breakpointLines[i] == lineCursor)
2322 if(breakpointLines[i] == lineTopFrame)
2323 bpOnTopFrame = true;
2326 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2328 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2331 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2332 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2333 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2335 if(editBox.anchor.left.distance)
2337 if(editBox.horzScroll && editBox.horzScroll.visible)
2339 surface.SetBackground(control);
2340 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2345 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2350 lineY = (line - 1) * lineH;
2351 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2353 Bitmap bitmap = resource.bitmap;
2355 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2362 char ext[MAX_EXTENSION];
2363 char * fileName = property::fileName;
2365 if(SearchString(fileName, 0, "Makefile", false, true))
2366 editBox.useTab = true;
2367 designer.fileName = fileName;
2371 GetExtension(fileName, ext);
2373 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2374 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2375 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2376 editBox.syntaxHighlighting = true;
2378 editBox.syntaxHighlighting = false;
2380 if(parsing && !strcmpi(ext, "ec"))
2382 codeModified = true;
2388 display.FontExtent(font.font, " ", 1, &spaceW, null);
2389 editBox.anchor = Anchor
2391 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2392 right = 0, top = 0, bottom = 0
2401 display.FontExtent(font.font, " ", 1, &spaceW, null);
2402 editBox.anchor = Anchor
2404 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2405 right = 0, top = 0, bottom = 0
2410 bool LoadFile(char * filePath)
2412 File f = FileOpen(filePath, read);
2415 // Added this here...
2416 fileName = filePath;
2418 updatingCode = true;
2420 updatingCode = false;
2421 loadingFile = false;
2430 void AdjustDebugMenus()
2432 bool unavailable = ide.areDebugMenusUnavailable;
2433 bool isNotNotRunning = unavailable || ide.isDebuggerRunning;
2434 bool isNotStopped = unavailable || !ide.isDebuggerStopped;
2435 bool noBreakpointToggle = ide.isBreakpointTogglingUnavailable;
2437 debugRunToCursor.disabled = isNotNotRunning;
2438 debugSkipRunToCursor.disabled = isNotNotRunning;
2439 debugRunToCursorAtSameLevel.disabled = isNotStopped;
2440 debugSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2442 debugBpRunToCursor.disabled = isNotNotRunning;
2443 debugBpSkipRunToCursor.disabled = isNotNotRunning;
2444 debugBpRunToCursorAtSameLevel.disabled = isNotStopped;
2445 debugBpSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2447 debugToggleBreakpoint.disabled = noBreakpointToggle;
2453 ProjectView projectView = ide.projectView;
2456 designer.fileName = fileName;
2462 sprintf(title, $"Untitled %d", documentID);
2463 // designer.fileName = CopyString(title);
2464 designer.fileName = title;
2469 for(c = 0; c < CodeObjectType::enumSize; c++)
2470 icons[c] = BitmapResource { iconNames[c], window = this };
2472 codeModified = true;
2484 selected.modified = true;
2485 selected.oClass.modified = true;
2487 designer.modifiedDocument = true;
2488 modifiedDocument = true;
2489 formModified = true;
2492 /****************************************************************************
2494 ****************************************************************************/
2502 this.defines.Free(FreeModuleDefine);
2503 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2505 FreeExcludedSymbols(this.excludedSymbols);
2506 FreeContext(this.globalContext);
2508 FreeGlobalData(&this.globalData);
2509 FindCtx_Terminate();
2510 FindParams_Terminate();
2512 if(GetGlobalContext() == globalContext)
2514 SetGlobalData(null);
2515 SetGlobalContext(null);
2516 SetExcludedSymbols(null);
2517 SetTopContext(null);
2518 SetCurrentContext(null);
2521 SetPrivateModule(null);
2524 if(this.privateModule)
2526 FreeTypeData(this.privateModule);
2527 delete this.privateModule;
2528 this.privateModule = null;
2534 static bool reentrant = false;
2539 char * selectedClassName = null, * selectedName = null;
2540 int selectedPos = 0;
2541 Designer backDesigner;
2542 char oldWorkDir[MAX_LOCATION];
2543 char mainModuleName[MAX_FILENAME] = "";
2545 ImportedModule module;
2546 char extension[MAX_EXTENSION];
2547 PathBackup pathBackup { };
2549 Time parseCodeStart = GetTime();
2550 Time startTime, startFindClass;
2552 findClassTotalTime = 0;
2553 checkTypeTotalTime = 0;
2554 externalImportTotalTime = 0;
2555 findClassIgnoreNSTotalTime = 0;
2556 findSymbolTotalTime = 0;
2557 //ResetClassFindTime();
2561 // 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)
2562 if(reentrant) return;
2569 selectedClassName = CopyString(oClass.name);
2570 if(selected != oClass)
2572 ObjectInfo object = this.selected;
2573 selectedName = CopyString(object.name);
2577 for(check = this.oClass.instances.first; check; check = check.next)
2589 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2591 FindCtx_Terminate();
2592 FindParams_Terminate();
2594 SetGlobalData(&globalData);
2595 SetGlobalContext(globalContext);
2596 SetExcludedSymbols(&excludedSymbols);
2597 SetTopContext(globalContext);
2598 SetCurrentContext(globalContext);
2599 SetDefines(&defines);
2600 SetImports(&imports);
2601 SetCurrentNameSpace(null);
2604 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2605 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2606 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2607 "/I T:\\ecere\\include /E %s", argv[1]);
2611 ChangeWorkingDir("e:\\ec");
2612 sprintf(command, "gcc -x c -E -");
2613 fileInput = DualPipeOpen({ output = true, input = true }, command);
2614 SetFileInput(fileInput);
2619 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2621 fileInput.Write(buffer, 1, count);
2626 fileInput.CloseOutput();
2630 // TOCHECK: COULDN'T WE CALL FreeParser here?
2632 FreeType(this.functionType);
2633 FreeType(this.instanceType);
2634 this.functionType = null;
2635 this.instanceType = null;
2638 sheet.SelectObject(null);
2644 // We don't want the designer to be notified of selection when deleting rows...
2645 backDesigner = designer;
2650 ObjectInfo _class, next;
2652 for(_class = classes.first; _class; _class = next)
2658 for(;object = _class.instances.first;)
2662 Designer::DestroyObject(object.instance);
2663 delete object.instance;
2665 sheet.DeleteObject(object);
2667 _class.instances.Delete(object);
2671 Designer::DestroyObject(_class.instance);
2672 delete _class.instance;
2674 sheet.DeleteObject(_class);
2676 classes.Delete(_class);
2682 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2683 if(windowClass && windowClass.data)
2684 UnapplySkin(windowClass);
2687 designer = backDesigner;
2690 fileInput = editFile = EditBoxStream { editBox = editBox };
2691 SetFileInput(fileInput);
2699 defines.Free(FreeModuleDefine);
2700 imports.Free(FreeModuleImport);
2702 FreeContext(this.globalContext);
2703 FreeExcludedSymbols(this.excludedSymbols);
2706 FreeGlobalData(&this.globalData);
2708 if(this.privateModule)
2710 FreeTypeData(this.privateModule);
2711 delete this.privateModule;
2715 startTime = GetTime();
2716 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2718 printf("classes.count: %d\n", globalContext.classes.count);
2723 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2724 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2727 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2729 SetPrivateModule(privateModule);
2732 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2733 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2734 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2735 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2736 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2739 fileName = this.fileName;
2741 if(ide.workspace && ide.workspace.projects && fileName)
2743 for(p : ide.workspace.projects)
2745 char path[MAX_LOCATION];
2747 MakePathRelative(fileName, p.topNode.path, path);
2748 MakeSlashPath(path);
2750 pn = p.topNode.FindWithPath(path, false);
2759 project = ide.project;
2761 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2763 ChangeWorkingDir(project.topNode.path);
2765 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2767 GetLastDirectory(fileName, mainModuleName);
2768 GetExtension(mainModuleName, extension);
2770 SetBuildingEcereCom(false);
2771 SetBuildingEcereComModule(false);
2773 // TODO: Get symbolsDir from project settings instead...
2776 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2777 ProjectConfig config = project.config;
2778 int bitDepth = ide.workspace.bitDepth;
2779 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2780 SetSymbolsDir(objDir.dir);
2781 ide.SetPath(true, compiler, config, bitDepth);
2785 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2786 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2790 switch(GetRuntimePlatform())
2792 case win32: SetSymbolsDir("obj/debug.win32"); break;
2793 case tux: SetSymbolsDir("obj/debug.linux"); break;
2794 case apple: SetSymbolsDir("obj/debug.apple"); break;
2796 SetIncludeDirs(null);
2797 SetSysIncludeDirs(null);
2801 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2803 // TODO FIX for configless project
2804 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2806 for(item : ide.project.config.options.preprocessorDefinitions)
2808 if(!strcmp(item, "BUILDING_ECERE_COM"))
2810 SetBuildingEcereCom(true);
2817 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2818 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2819 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2820 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2821 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2822 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2823 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2824 strcmpi(mainModuleName, "Mutex.ec")))
2826 SetBuildingEcereComModule(true);
2829 // Predeclare all classes
2831 char symFile[MAX_FILENAME];
2832 char symLocation[MAX_LOCATION];
2833 ImportedModule module, next;
2835 GetLastDirectory(fileName, symFile);
2836 ChangeExtension(symFile, "sym", symFile);
2838 strcpy(symLocation, GetSymbolsDir());
2839 PathCat(symLocation, symFile);
2841 // if(!GetEcereImported() && !GetBuildingEcereCom())
2842 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2845 startTime = GetTime();
2847 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2849 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2854 startTime = GetTime();
2856 // LoadSymbols(symLocation, normalImport, true);
2857 LoadSymbols(symLocation, preDeclImport, false);
2859 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2862 for(module = defines.first; module; module = next)
2865 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2868 defines.Delete(module);
2873 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2875 SetDefaultDeclMode(privateAccess);
2876 SetDeclMode(privateAccess);
2880 SetDefaultDeclMode(defaultAccess);
2881 SetDeclMode(defaultAccess);
2884 StripExtension(mainModuleName);
2885 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2886 defines.AddName(module);
2889 // SetYydebug(true);
2894 startTime = GetTime();
2895 startFindClass = checkTypeTotalTime;
2899 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2901 CheckDataRedefinitions();
2904 SetIncludeDirs(null);
2905 SetSysIncludeDirs(null);
2916 startTime = GetTime();
2918 PrePreProcessClassDefinitions();
2919 ComputeModuleClasses(privateModule);
2920 PreProcessClassDefinitions();
2921 ProcessClassDefinitions();
2923 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2924 startTime = GetTime();
2929 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2930 startTime = GetTime();
2932 ProcessInstantiations();
2934 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2937 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2939 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2940 if(!windowClass || windowClass.internalDecl)
2943 startTime = GetTime();
2945 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2946 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2947 eModule_Load(this.privateModule, "ecere", privateAccess);
2949 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2952 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2954 if(windowClass && windowClass.data)
2955 ApplySkin(windowClass, app.currentSkin.name, null);
2959 startTime = GetTime();
2961 for(external = ast->first; external; external = external.next)
2963 if(external.type == classExternal)
2965 ClassDefinition _class = external._class;
2966 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2968 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2971 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2973 Instance instance = eInstance_New(regClass);
2974 ObjectInfo classObject
2976 name = CopyString(_class._class.name);
2977 instance = instance;
2978 classDefinition = _class;
2979 oClass = classObject;
2982 classes.Add(classObject);
2986 // Moved this at bottom so that the file dialog doesn't show up in eCom
2987 designer.CreateObject(instance, classObject, true, null);
2988 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
2990 if(_class.definitions)
2994 for(def = _class.definitions->first; def; def = def.next)
2998 case defaultPropertiesClassDef:
3001 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3003 Identifier id = propDef.identifiers->first;
3006 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3009 Class propertyClass = prop.dataTypeClass;
3011 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3012 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3014 FreeType(propDef.initializer.exp.destType);
3015 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3016 ProcessExpressionType(propDef.initializer.exp);
3018 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
3020 Expression computed = CopyExpression(propDef.initializer.exp);
3021 ComputeExpression(computed);
3023 if(computed.isConstant && computed.type == instanceExp && !id.next)
3027 if(computed.instance._class && computed.instance._class.symbol &&
3028 computed.instance._class.symbol.registered &&
3029 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3031 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3033 // This was saved in the control and shouldn't be freed by FreeExpression...
3034 // (Not doing this anymore, incrementing refCount in pass15 instead)
3035 /*if(propertyClass.type == normalClass)
3036 computed.instance.data = null;*/
3040 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3041 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3043 String temp = new char[strlen(computed.string)+1];
3044 ReadString(temp, computed.string);
3045 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3049 propDef.variable = true;
3051 FreeExpression(computed);
3055 Expression computed = CopyExpression(propDef.initializer.exp);
3056 ComputeExpression(computed);
3057 if(computed.isConstant)
3059 //if(computed.type == memberExp) computed = computed.member.exp;
3061 if(computed.type == constantExp)
3063 Operand value = GetOperand(computed);
3064 DataValue valueData;
3065 valueData.i64 = value.i64;
3066 SetProperty(prop, instance, valueData);
3068 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3070 String temp = new char[strlen(computed.string)+1];
3071 ReadString(temp, computed.string);
3072 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3077 propDef.variable = true;
3079 FreeExpression(computed);
3083 propDef.variable = true;
3087 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3088 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3089 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3092 // Maintain a list in FunctionDefinition of who is attached to it
3093 for(def = _class.definitions->first; def; def = def.next)
3095 if(def.type == functionClassDef)
3097 ClassFunction function = def.function;
3098 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3100 function.attached.Add(OldLink { data = method });
3110 case declarationClassDef:
3112 Declaration decl = def.decl;
3115 case instDeclaration:
3117 Instantiation inst = decl.inst;
3118 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3119 if(instClass && eClass_GetDesigner(instClass))
3121 Instance control = eInstance_New(instClass);
3126 oClass = classObject;
3130 classObject.instances.Add(object);
3132 // TOCHECK: Why is this needed now?
3133 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3134 def.object = object;
3136 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3138 designer.CreateObject(control, object, false, classObject.instance);
3139 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3149 // Second pass, process instantiation members
3151 for(def = _class.definitions->first; def; def = def.next)
3155 case declarationClassDef:
3157 Declaration decl = def.decl;
3160 case instDeclaration:
3162 Instantiation inst = decl.inst;
3163 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3164 if(instClass && eClass_GetDesigner(instClass))
3167 object = object ? object.next : classObject.instances.first;
3168 control = object.instance;
3172 MembersInit members;
3173 for(members = inst.members->first; members; members = members.next)
3175 switch(members.type)
3177 case dataMembersInit:
3179 if(members.dataMembers)
3182 DataMember curMember = null;
3183 Class curClass = null;
3184 DataMember subMemberStack[256];
3185 int subMemberStackPos = 0;
3187 for(member = members.dataMembers->first; member; member = member.next)
3190 Identifier ident = member.identifiers ? member.identifiers->first : null;
3193 DataMember _subMemberStack[256];
3194 int _subMemberStackPos = 0;
3195 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3199 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3201 if(thisMember && thisMember.memberAccess == publicAccess)
3203 curMember = thisMember;
3204 curClass = curMember._class;
3205 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3206 subMemberStackPos = _subMemberStackPos;
3212 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3213 if(curMember) found = true;
3215 if(found && curMember.isProperty)
3217 Property prop = (Property) curMember;
3218 Class propertyClass = prop.dataTypeClass;
3220 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3222 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3224 FreeType(member.initializer.exp.destType);
3225 member.initializer.exp.destType = MkClassType(propertyClass.name);
3228 ProcessExpressionType(member.initializer.exp);
3230 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3232 Expression computed;
3234 /*char debugExpString[4096];
3235 debugExpString[0] = '\0';
3236 PrintExpression(member.initializer.exp, debugExpString);*/
3238 computed = CopyExpression(member.initializer.exp);
3241 ComputeExpression(computed);
3243 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3245 if(computed.instance.data)
3247 if(computed.instance._class && computed.instance._class.symbol &&
3248 computed.instance._class.symbol.registered &&
3249 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3251 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3253 // This was saved in the control and shouldn't be freed by FreeExpression...
3254 // (Not doing this anymore, incrementing refCount in pass15 instead)
3255 /*if(propertyClass.type == normalClass)
3256 computed.instance.data = null;*/
3260 else if(computed.type == identifierExp)
3262 member.variable = true;
3264 if(eClass_GetDesigner(propertyClass))
3267 char * name = computed.identifier.string;
3268 if(!strcmp(name, "this"))
3271 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3272 member.variable = false;
3277 for(check = classObject.instances.first; check; check = check.next)
3278 if(check.name && !strcmp(name, check.name))
3281 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3282 member.variable = false;
3288 else if(computed.type == memberExp)
3290 member.variable = true;
3291 if(computed.member.exp.type == identifierExp)
3293 char * name = computed.member.exp.identifier.string;
3294 if(!strcmp(name, "this"))
3296 char * name = computed.member.member.string;
3299 for(check = classObject.instances.first; check; check = check.next)
3300 if(check.name && !strcmp(name, check.name))
3303 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3304 member.variable = false;
3312 for(check = classObject.instances.first; check; check = check.next)
3314 if(check.name && !strcmp(name, check.name))
3316 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3319 DataValue value { };
3320 GetProperty(getProperty, check.instance, &value);
3321 SetProperty(prop, control, value);
3322 member.variable = false;
3330 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3331 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3333 String temp = new char[strlen(computed.string)+1];
3334 ReadString(temp, computed.string);
3335 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3339 member.variable = true;
3341 FreeExpression(computed);
3346 Expression computed = CopyExpression(member.initializer.exp);
3349 ComputeExpression(computed);
3350 if(computed.isConstant)
3352 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3354 if(!strcmp(propertyClass.dataTypeString, "float"))
3355 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3356 else if(!strcmp(propertyClass.dataTypeString, "double"))
3357 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3359 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3361 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3363 String temp = new char[strlen(computed.string)+1];
3364 ReadString(temp, computed.string);
3365 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3370 member.variable = true;
3372 FreeExpression(computed);
3378 member.variable = true;
3380 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3381 member.initializer.exp.type == memberExp) // identifierExp
3383 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3384 if(method && method.type == virtualMethod)
3387 // Maintain a list in FunctionDefinition of who is attached to it
3388 for(def = _class.definitions->first; def; def = def.next)
3390 if(def.type == functionClassDef)
3392 ClassFunction function = def.function;
3393 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3394 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3396 function.attached.Add(OldLink { data = method });
3397 // Reference this particular instance?
3412 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3423 //designer.CreateObject(instance, classObject, true, null);
3424 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3426 designer.PostCreateObject(instance, classObject, true, null);
3428 //instance.state = Hidden;
3429 //instance.Create();
3430 //instance.SetState(Normal, true, 0);
3439 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3443 // Restore Selection
3444 if(selectedClassName)
3447 for(oClass = classes.first; oClass; oClass = oClass.next)
3449 if(!strcmp(oClass.name, selectedClassName))
3451 this.oClass = oClass;
3455 delete selectedClassName;
3464 for(check = this.oClass.instances.first; check; check = check.next)
3466 if(check.name && !strcmp(check.name, selectedName))
3468 this.selected = check;
3474 if(this.oClass.instances.first)
3475 this.selected = this.oClass.instances.first;
3477 this.selected = this.oClass;
3480 else if(selectedPos == -1 || !this.oClass.instances.count)
3481 this.selected = this.oClass;
3487 if(selectedPos > this.oClass.instances.count)
3489 for(check = this.oClass.instances.first; check; check = check.next)
3491 if(selectedPos == pos++)
3493 this.selected = check;
3501 this.oClass = classes.first;
3502 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3504 delete selectedName;
3505 SetSymbolsDir(null);
3507 if(sheet.codeEditor == this)
3508 sheet.SelectObject(selected);
3511 codeModified = false;
3513 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3516 InvokeParameters(false, false, false);
3519 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3525 ChangeWorkingDir(oldWorkDir);
3527 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3528 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3529 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3530 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3531 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3533 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3535 if(inUseDebug && ide.projectView)
3536 ide.debugger.EvaluateWatches();
3541 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3544 Window control = (Window)object.instance;
3545 ObjectInfo classObject = object.oClass;
3547 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3549 if(!strcmp(_class.name, "DesignerBase")) return;
3551 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3553 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3554 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3556 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3557 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3559 Class dataType = prop.dataTypeClass;
3561 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3565 if(dataType.type == structClass)
3567 void * dataForm = new0 byte[dataType.structSize];
3568 void * dataTest = new0 byte[dataType.structSize];
3570 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3571 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3573 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3575 char tempString[1024] = "";
3577 bool needClass = true;
3581 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3583 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3585 eClass_FindNextMember(_class, curClass, curMember, null, null);
3586 if(*curMember != (DataMember)prop)
3587 f.Printf("%s = ", prop.name);
3589 *curMember = (DataMember)prop;
3590 *curClass = curMember->_class;
3593 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3595 f.Printf("%s", string);
3602 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3604 void * dataForm, * dataTest;
3606 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3607 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3609 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3611 char tempString[1024] = "";
3616 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3618 eClass_FindNextMember(_class, curClass, curMember, null, null);
3619 if(*curMember != (DataMember)prop)
3620 f.Printf("%s = ", prop.name);
3621 *curMember = (DataMember)prop;
3622 *curClass = curMember->_class;
3624 if(eClass_GetDesigner(dataType))
3626 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3627 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3628 f.Printf("this", prop.name);
3631 //ObjectInfo classObject;
3632 //for(classObject = classes.first; classObject; classObject = classObject.next)
3636 for(object = classObject.instances.first; object; object = object.next)
3638 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3640 f.Printf("%s", object.name);
3647 bool needClass = true;
3648 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3649 f.Printf("%s", string);
3656 bool needClass = true;
3657 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3659 if(!strcmp(dataType.dataTypeString, "char *"))
3662 OutputString(f, string);
3666 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3668 f.Printf("%s", string);
3671 *lastIsMethod = false;
3676 DataValue dataForm, dataTest;
3678 GetProperty(prop, control, &dataForm);
3679 GetProperty(prop, test, &dataTest);
3681 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3684 char tempString[1024] = "";
3685 SetProperty(prop, test, dataForm);
3687 if(dataType.type != bitClass)
3689 bool needClass = true;
3691 if(dataType.type == enumClass)
3694 Class enumClass = eSystem_FindClass(privateModule, "enum");
3695 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3697 for(value = e.values.first; value; value = value.next)
3699 if((int)value.data == dataForm.i)
3701 string = value.name;
3707 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3709 if(string && string[0])
3714 eClass_FindNextMember(_class, curClass, curMember, null, null);
3715 if(*curMember != (DataMember)prop)
3716 f.Printf("%s = ", prop.name);
3717 *curMember = (DataMember)prop;
3718 *curClass = curMember->_class;
3720 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3721 f.Printf("%sf", string);
3723 f.Printf("%s", string);
3727 else if(dataType.type == bitClass)
3729 bool needClass = true;
3731 if(*prev) f.Printf(", ");
3733 eClass_FindNextMember(_class, curClass, curMember, null, null);
3734 if(*curMember != (DataMember)prop)
3735 f.Printf("%s = ", prop.name);
3736 *curMember = (DataMember)prop;
3737 *curClass = curMember->_class;
3739 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3741 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3743 f.Printf("%s", string);
3745 *lastIsMethod = false;
3755 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3757 Instantiation inst = object.instCode;
3758 Window control = (Window)object.instance;
3760 bool methodPresent = false;
3762 bool lastIsMethod = true;
3763 ObjectInfo classObject = object.oClass;
3769 // Instance removed, delete it
3770 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3772 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3773 position = inst.loc.end.pos + 1;
3777 bool multiLine = false;
3780 // Check if it's an unnamed instance
3783 f.Seek(inst.nameLoc.start.pos - position, current);
3784 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3785 position = inst.nameLoc.end.pos;
3787 f.Printf(object.name);
3792 if(isspace(ch) && ch != '\n')
3794 f.Seek(-1, current);
3802 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3804 f.Seek(pos - position, current);
3809 f.Seek(-1, current);
3818 f.Puts(object.name);
3823 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3824 methodPresent = true;
3832 if(ch == OpenBracket)
3838 // TODO: Simplify this?
3847 f.Seek(-1, current);
3859 if(ch == '\n') { toDelete = count; count = 0; }
3860 else if(isspace(ch)) count++;
3863 f.Seek(-1, current);
3867 toDelete += count - 6;
3877 f.Seek(-toDelete-count, current);
3878 f.DeleteBytes(toDelete);
3879 f.Seek(count, current);
3884 for(c = 0; c<toAdd; c++)
3890 methodPresent = multiLine;
3893 f.Printf(methodPresent ? "\n " : " ");
3899 // Instance not there, create a brand new one
3900 DeleteJunkBefore(f, position, &position);
3901 f.Printf(*firstObject ? "\n\n" : "\n");
3902 *firstObject = false;
3904 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3905 methodPresent = true;
3910 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3912 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3917 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3919 f.Printf(" %s %c ", control._class.name, OpenBracket);
3925 Instance test = eInstance_New(control._class);
3926 DataMember curMember = null;
3927 Class curClass = null;
3930 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3934 // Attach Method here
3935 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3937 if(prev) f.Printf(", ");
3938 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3943 if(inst && !object.deleted)
3945 MembersInit members;
3946 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3948 DeleteJunkBefore(f, position, &position);
3950 // Instance already there, clear out the properties
3951 for(members = inst.members->first; members; members = members.next)
3953 if(members.type == dataMembersInit)
3957 if(members.dataMembers)
3959 bool keptMember = false;
3960 MemberInit lastKept = null;
3962 for(member = members.dataMembers->first; member; member = member.next)
3964 Identifier ident = member.identifiers ? member.identifiers->first : null;
3965 bool deleted = false;
3967 // For now delete if it's not a method
3968 if(!member.variable) // && ident)
3970 if(!ident || !ident.next)
3972 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3975 f.Seek(member.loc.start.pos - position, current);
3976 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3977 position = member.loc.end.pos;
3982 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3983 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3984 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
3986 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
3987 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
3989 f.Seek(member.loc.start.pos - position, current);
3990 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3991 position = member.loc.end.pos;
4003 //f.Seek(member.loc.start.pos - position, current);
4004 //position = member.loc.start.pos;
4005 DeleteJunkBefore(f, member.loc.start.pos, &position);
4006 if(prev) f.Printf(", ");
4007 else if(keptMember) f.Printf(" ");
4012 if(!keptMember || !members.next)
4017 if(keptMember && lastKept != members.dataMembers->last)
4022 f.Seek(-1, current);
4028 f.Seek(-1, current);
4031 else if(!isspace(ch))
4033 f.Seek(-2, current);
4038 f.DeleteBytes(count);
4041 f.Seek(members.loc.end.pos - position, current);
4046 f.Seek(-1, current);
4048 position = members.loc.end.pos + 1;
4052 f.Seek(-1, current);
4053 position = members.loc.end.pos;
4059 lastIsMethod = false;
4064 DeleteJunkBefore(f, position, &position);
4067 if(lastKept != members.dataMembers->last)
4072 f.Seek(-1, current);
4078 f.Seek(-1, current);
4081 else if(!isspace(ch))
4083 f.Seek(-2, current);
4088 f.DeleteBytes(count);
4092 f.Seek(members.loc.end.pos - position, current);
4093 position = members.loc.end.pos;
4097 lastIsMethod = true;
4100 lastIsMethod = false;
4106 f.Seek(members.loc.end.pos - position, current);
4107 position = members.loc.end.pos;
4109 lastIsMethod = true;
4112 else if(members.type == methodMembersInit)
4114 if(this.methodAction == actionDeleteMethod && members.function == function);
4116 methodPresent = true;
4118 // Delete instance method here
4119 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4120 members.function == function)
4122 if(this.moveAttached && !*text)
4123 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4125 DeleteJunkBefore(f, members.loc.start.pos, &position);
4126 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4127 position = members.loc.end.pos + 1;
4132 DeleteJunkBefore(f, position, &position);
4136 DeleteJunkBefore(f, members.loc.start.pos, &position);
4137 lastIsMethod = true;
4141 f.Seek(members.loc.end.pos - position, current);
4142 position = members.loc.end.pos;
4144 DeleteJunkBefore(f, position, &position);
4153 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4155 Method method = this.method;
4156 DeleteJunkBefore(f, position, &position);
4162 if(!method.dataType)
4163 method.dataType = ProcessTypeString(method.dataTypeString, false);
4166 Type dataType = method.dataType;
4167 Type returnType = dataType.returnType;
4170 if(this.moveAttached)
4172 // Move function here:
4173 int newLen = strlen(method.name);
4178 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4180 // First change name of function
4181 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4182 *textSize += newLen - movedFuncIdLen;
4183 memcpy(*text + movedFuncIdPos, method.name, newLen);
4185 // Second, tab right
4188 for(c = 0; (*text)[c]; )
4191 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4194 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4195 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4199 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4209 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4211 // ADDING METHOD HERE
4213 OutputType(f, returnType, false);
4216 if(dataType.thisClass)
4218 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4220 if(dataType.thisClass.shortName)
4221 f.Printf(dataType.thisClass.shortName);
4223 f.Printf(dataType.thisClass.string);
4227 f.Printf(method.name);
4229 for(param = dataType.params.first; param; param = param.next)
4231 OutputType(f, param, true);
4236 f.Printf(" %c\n\n", OpenBracket);
4238 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4240 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4241 f.Printf(" return true;\n");
4242 else if(returnType.kind != voidType)
4243 f.Printf(" return 0;\n");
4248 if(returnType.kind != voidType)
4249 f.Printf("return ");
4250 f.Printf("%s::%s(", control._class.name, method.name);
4251 for(param = dataType.params.first; param; param = param.next)
4253 if(param.prev) f.Printf(", ");
4254 if(param.kind != voidType)
4255 f.Printf(param.name);
4259 f.Printf(" %c\n", CloseBracket);
4265 if(!object.instCode)
4268 f.Printf(" %c;\n", CloseBracket);
4270 f.Printf("%c;\n", CloseBracket);
4272 else if(!object.deleted)
4274 // Turn this into a multiline instance when adding a method
4275 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4277 f.Printf(methodPresent ? "\n " : " ");
4279 f.Seek(inst.loc.end.pos + 1 - position, current);
4280 position = inst.loc.end.pos + 1;
4285 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4288 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4290 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4292 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4294 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4295 if(prop && prop.isProperty && !prop.conversion)
4297 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4298 (!prop.IsSet || prop.IsSet(classObject.instance)))
4300 Class dataType = prop.dataTypeClass;
4301 char tempString[1024] = "";
4303 bool specify = false;
4306 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4307 if(member && member._class == regClass)
4311 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4313 if(dataType && dataType.type == structClass)
4315 void * dataForm = new0 byte[dataType.structSize];
4316 void * dataTest = new0 byte[dataType.structSize];
4318 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4319 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4321 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4323 bool needClass = true;
4325 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4326 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4328 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4330 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4335 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4337 void * dataForm, * dataTest;
4339 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4340 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4342 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4344 char tempString[1024] = "";
4346 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4348 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4350 // Shouldn't go here ...
4351 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4355 bool needClass = true;
4357 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4359 if(!strcmp(dataType.dataTypeString, "char *"))
4361 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4362 OutputString(f, string);
4366 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4368 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4374 DataValue dataForm, dataTest;
4376 GetProperty(prop, classObject.instance, &dataForm);
4377 GetProperty(prop, test, &dataTest);
4379 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4381 SetProperty(prop, test, dataForm);
4382 if(dataType.type == bitClass)
4384 bool needClass = true;
4385 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4387 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4389 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4393 bool needClass = true;
4394 if(dataType.type == enumClass)
4397 Class enumClass = eSystem_FindClass(privateModule, "enum");
4398 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4400 for(value = e.values.first; value; value = value.next)
4402 if((int)value.data == dataForm.i)
4404 string = value.name;
4410 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4411 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4412 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4414 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4423 void UpdateFormCode()
4426 if(!parsing) return;
4433 else if(formModified)
4435 EditBoxStream f { editBox = editBox };
4439 Identifier movedFuncId;
4440 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4441 ObjectInfo classObject;
4447 movedFuncId = GetDeclId(function.declarator);
4448 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4449 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4452 for(classObject = classes.first; classObject; classObject = classObject.next)
4455 ClassDefinition classDef = classObject.classDefinition;
4456 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4459 bool firstObject = true;
4460 ObjectInfo object = classObject.instances.first;
4461 bool lastIsDecl = false;
4463 if(!classObject.modified) continue;
4465 test = eInstance_New(regClass);
4468 // Put it in the same desktop window...
4469 designer.PrepareTestObject(test);
4471 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4472 //f.Printf("%c\n\n", OpenBracket);
4474 // Change the _class name
4475 f.Seek(classDef.nameLoc.start.pos - position, current);
4476 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4477 f.Printf(classObject.name);
4478 position = classDef.nameLoc.end.pos;
4481 // Go to block start, delete all until no white space, put \n
4485 f.Seek(classDef.blockStart.end.pos - position, current);
4486 position = classDef.blockStart.end.pos;
4488 for(; f.Getc(&ch); count++)
4492 f.Seek(-1, current);
4502 f.Seek(-count, current);
4504 f.DeleteBytes(count-back);
4506 position += count-back;
4509 // Output properties
4510 OutputClassProperties(classObject.instance._class, classObject, f, test);
4512 for(def = classDef.definitions->first; def; def = def.next)
4516 case defaultPropertiesClassDef:
4518 bool keptMember = false;
4520 MemberInit lastKept = null;
4523 DeleteJunkBefore(f, def.loc.start.pos, &position);
4526 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4528 Identifier ident = propDef.identifiers->first;
4529 bool deleted = false;
4531 // For now delete if it's a prop
4532 if(!propDef.variable && ident)
4536 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4539 f.Seek(propDef.loc.start.pos - position, current);
4540 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4541 position = propDef.loc.end.pos;
4546 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4547 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4549 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4550 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4552 f.Seek(propDef.loc.start.pos - position, current);
4553 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4554 position = propDef.loc.end.pos;
4572 f.Seek(def.loc.end.pos - position - 1, current);
4577 f.Seek(-1, current);
4580 position = def.loc.end.pos;
4584 if(lastKept != def.defProperties->last)
4589 f.Seek(-1, current);
4595 f.Seek(-1, current);
4598 else if(!isspace(ch))
4600 f.Seek(-2, current);
4605 f.DeleteBytes(count);
4609 f.Seek(def.loc.end.pos - position, current);
4610 position = def.loc.end.pos;
4615 case declarationClassDef:
4617 Declaration decl = def.decl;
4619 if(decl.type == instDeclaration)
4621 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4623 while(def.object && object != def.object)
4625 if(object /*&& ((ObjectInfo)def.object).modified*/)
4626 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4627 object = object.next;
4630 DeleteJunkBefore(f, def.loc.start.pos, &position);
4631 f.Printf(firstObject ? "\n\n " : "\n ");
4632 firstObject = false;
4634 if(def.object && ((ObjectInfo)def.object).modified)
4635 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4637 object = object ? object.next : null;
4641 DeleteJunkBefore(f, def.loc.start.pos, &position);
4642 f.Printf(firstObject ? "\n\n " : "\n ");
4643 firstObject = false;
4649 DeleteJunkBefore(f, def.loc.start.pos, &position);
4650 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4655 case functionClassDef:
4657 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4658 if(!def.function.body) continue;
4662 DeleteJunkBefore(f, def.loc.start.pos, &position);
4665 // Delete _class methods
4666 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4667 def.function == function)
4672 if(moveAttached && !text)
4674 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4677 f.Seek(def.loc.end.pos - position, current);
4678 for(; f.Getc(&ch); count++)
4682 f.Seek(-1, current);
4686 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4688 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4689 position = def.loc.end.pos + count;
4692 // In case of detaching methods in the _class, simply rename the method
4693 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4695 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4696 f.DeleteBytes(movedFuncIdLen);
4698 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4701 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4702 function == def.function)
4704 // In case of attaching methods in the _class, simply rename the method
4705 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4706 position = function.loc.start.pos + movedFuncIdPos;
4707 f.DeleteBytes(movedFuncIdLen);
4708 if(method.dataType.thisClass)
4709 f.Printf("%s::", method.dataType.thisClass.string);
4710 f.Puts(method.name);
4711 position += movedFuncIdLen;
4716 DeleteJunkBefore(f, def.loc.start.pos, &position);
4717 if(def.type == memberAccessClassDef)
4720 firstObject = false;
4730 f.Seek(def.loc.end.pos - position, current);
4731 position = def.loc.end.pos;
4734 // Output attached methods
4735 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4737 DeleteJunkBefore(f, position, &position);
4738 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4741 // ********** INSTANCES ***************
4742 for(; object; object = object.next)
4744 if(!object.instCode)
4746 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4750 DeleteJunkBefore(f, position, &position);
4752 // ****************** METHODS ***********************
4753 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4755 // If detaching an instance method
4756 if(selected != classObject)
4758 int newLen = strlen(methodName);
4761 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4762 // Tab selection left
4765 for(c = 0; text[c]; )
4768 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4769 memmove(text+start, text+start+i, textSize+1-start-i);
4772 for(; text[c] && text[c] != '\n'; c++);
4778 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4779 textSize += newLen - movedFuncIdLen;
4780 memcpy(text + movedFuncIdPos, methodName, newLen);
4787 if(methodAction == actionAddMethod && selected == classObject)
4789 Method method = this.method;
4791 if(!method.dataType)
4792 method.dataType = ProcessTypeString(method.dataTypeString, false);
4794 // ADDING METHOD HERE
4796 Type dataType = method.dataType;
4797 Type returnType = dataType.returnType;
4799 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4803 OutputType(f, returnType, false);
4806 if(dataType.thisClass && !dataType.classObjectType)
4808 if(dataType.thisClass.shortName)
4809 f.Printf(dataType.thisClass.shortName);
4811 f.Printf(dataType.thisClass.string);
4814 f.Printf(method.name);
4816 for(param = dataType.params.first; param; param = param.next)
4818 OutputType(f, param, true);
4823 f.Printf(" %c\n\n", OpenBracket);
4825 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4827 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4828 f.Printf(" return true;\n");
4829 else if(returnType && returnType.kind != voidType)
4830 f.Printf(" return 0;\n");
4835 if(returnType.kind != voidType)
4836 f.Printf("return ");
4838 char * name = ((Specifier)classDef.baseSpecs->first).name;
4839 Symbol _class = FindClass(name);
4840 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4842 for(param = dataType.params.first; param; param = param.next)
4844 if(param.prev) f.Printf(", ");
4845 if(param.kind != voidType)
4846 f.Printf(param.name);
4851 f.Printf(" %c", CloseBracket);
4855 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4867 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4868 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4872 codeModified = false;
4873 formModified = false;
4875 moveAttached = false;
4880 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4883 ClassFunction function = null;
4886 ObjectInfo object = this.selected;
4888 if(object && object == this.oClass)
4890 ClassDefinition classDef = object.oClass.classDefinition;
4892 if(classDef && classDef.definitions)
4894 for(def = classDef.definitions->first; def; def = def.next)
4896 if(def.type == functionClassDef && def.function.declarator)
4898 if(!strcmp(def.function.declarator.symbol.string, methodName))
4900 function = def.function;
4905 else if(def.type == defaultPropertiesClassDef)
4909 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4911 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4912 if(ident && !ident.next)
4914 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4918 propLoc = propDef.loc;
4921 ClassDefinition classDef = object.oClass.classDefinition;
4923 if(classDef.definitions)
4925 for(def = classDef.definitions->first; def; def = def.next)
4927 if(def.type == functionClassDef)
4929 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4931 function = def.function;
4950 Instantiation inst = object.instCode;
4952 // Check here to see if the method already exists, no need to call ModifyCode in that case
4953 if(inst && inst.members)
4955 MembersInit members;
4956 for(members = inst.members->first; members; members = members.next)
4958 switch(members.type)
4960 case dataMembersInit:
4962 if(members.dataMembers)
4965 for(member = members.dataMembers->first; member; member = member.next)
4967 Identifier ident = member.identifiers ? member.identifiers->first : null;
4968 if(ident && !ident.next)
4970 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4974 propLoc = member.loc;
4977 ClassDefinition classDef = object.oClass.classDefinition;
4979 if(classDef.definitions)
4981 for(def = classDef.definitions->first; def; def = def.next)
4983 if(def.type == functionClassDef)
4985 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
4987 function = def.function;
4996 // TODO: Fix memory leak
4997 function = ClassFunction
4999 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5011 case methodMembersInit:
5013 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5015 function = members.function;
5027 if(functionPtr) *functionPtr = function;
5031 void GoToMethod(char * methodName /*Method method*/)
5035 ObjectInfo object = selected;
5036 EditBoxStream f { editBox = editBox };
5037 ClassFunction function = null;
5038 bool atChar = false;
5042 Location propLoc = { {0,0,-1} };
5045 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5046 if(function && function.body)
5049 f.Seek(function.body.loc.start.pos+1, current);
5059 f.Seek(-1, current);
5064 else if(!isspace(ch))
5066 f.Seek(-1, current);
5072 else if(propLoc.start.pos > -1)
5074 f.Seek(propLoc.start.pos, current);
5077 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5079 if(function || propLoc.start.pos > -1)
5081 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5082 editBox.CenterOnCursor();
5083 SetState(normal, false, 0);
5086 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5088 FreeClassFunction(function);
5094 void FindCompatibleMethods(Method method, OldList compatible)
5096 ClassDefinition classDef = this.oClass.classDefinition;
5097 if(classDef && classDef.definitions)
5100 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5103 Symbol classSym { };
5104 Symbol selectedClass;
5105 if(this.selected == this.oClass)
5106 selectedClass = classSym;
5108 selectedClass = FindClass(this.selected.instance._class.name);
5110 regClass.name = classDef._class.name;
5111 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5112 for(def = classDef.definitions->first; def; def = def.next)
5114 if(def.type == functionClassDef && def.function.declarator)
5116 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5118 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5121 Type type = def.function.declarator.symbol.type;
5122 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5124 compatible.Add(OldLink { data = def.function });
5130 if(this.oClass && this.oClass.instance)
5132 classSym.registered = regClass;
5133 //classSym.registered = this.oClass.oClass;
5135 for(_class = regClass.base; _class; _class = _class.base)
5138 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5140 // TODO: Understand why these functions popup in attach list
5141 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5143 if(!testMethod.dataType)
5144 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5146 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5147 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5148 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5150 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5151 // ClassFunction function { };
5152 FunctionDefinition function { };
5154 function.declarator = Declarator { };
5155 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5156 excludedSymbols.Add(function.declarator.symbol);
5158 compatible.Add(OldLink { data = function });
5169 void AddMethod(Method method)
5173 char methodName[1024];
5174 strcpy(methodName, method.name);
5175 if(!FindMethod(methodName, null, null))
5177 methodAction = actionAddMethod;
5178 this.method = method;
5182 GoToMethod(methodName);
5186 void DeleteMethod(ClassFunction function)
5190 methodAction = actionDeleteMethod;
5191 this.function = function;
5199 void AttachMethod(Method method, ClassFunction function)
5203 // If it's an instance we'll ask if we want to move it inside...
5204 if(!function.attached.count && function.body)
5206 // Find the function in the _class to check if it's a virtual function
5207 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5208 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5209 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5211 for(def = this.classDefinition.first; def; def = def.next)
5213 if(def.type == functionClassDef)
5215 if(def.function == function)
5220 if(!method || method.type != virtualMethod)
5223 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5224 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5226 moveAttached = true;
5231 methodAction = actionAttachMethod;
5232 this.method = method;
5233 this.function = function;
5240 void ReAttachMethod(Method method, ClassFunction function)
5244 // If it's an instance we'll ask if we want to move it inside...
5245 if(!function.attached.count && function.body)
5247 // Find the function in the _class to check if it's a virtual function
5248 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5249 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5250 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5252 for(def = this.classDefinition.first; def; def = def.next)
5254 if(def.type == functionClassDef)
5256 if(def.function == function)
5261 if(!method || method.type != virtualMethod)
5264 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5265 if(MessageBox { type = yesNo, master = parent, text = title,
5266 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5268 moveAttached = true;
5273 methodAction = actionReattachMethod;
5274 this.method = method;
5275 this.function = function;
5282 void DetachMethod(Method method, ClassFunction function, int type)
5290 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5291 master = sheet, text = $"Name detached method", background = formColor
5295 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5296 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5300 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5301 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5305 dialog, anchor = { left = 5, right = 5, top = 5 }
5307 sprintf(methodName, "%s_%s", selected.name, method.name);
5308 nameBox.contents = methodName;
5310 result = dialog.Modal() == ok;
5311 strcpy(methodName, nameBox.contents);
5316 // If the method is not attached, move it outside
5319 // Add this class to the methodName
5320 char name[1024] = "";
5322 if(this.selected != this.oClass && !method.dataType.thisClass)
5324 strcat(name, this.selected.instance._class.name);
5326 strcat(name, this.methodName);
5327 strcpy(this.methodName, name);
5329 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5331 strcat(name, method.dataType.thisClass.string);
5333 strcat(name, this.methodName);
5334 strcpy(this.methodName, name);
5337 this.moveAttached = true;
5340 this.methodAction = actionDetachMethod;
5341 this.method = method;
5342 this.function = function;
5349 void AddObject(Instance instance, ObjectInfo * object)
5353 //*object = _class.instances.Add(sizeof(ObjectInfo));
5354 *object = ObjectInfo { };
5355 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5356 (*object).oClass = oClass;
5357 (*object).instance = instance;
5362 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5364 // if(strcmp(name, this.oClass.instance.name))
5367 for(check = oClass.instances.first; check; check = check.next)
5368 if(!check.deleted && check.name && !strcmp(name, check.name))
5372 (*object).name = CopyString(name);
5377 toolBox.controlClass = null;
5381 //sheet.AddObject(*object, (*object).name, TypeData, true);
5386 void EnsureUpToDate()
5388 if(sheet && codeModified && parsing)
5392 void SelectObject(ObjectInfo object)
5395 oClass = object ? object.oClass : null;
5397 designer.SelectObject(object, object ? object.instance : null);
5400 void SelectObjectFromDesigner(ObjectInfo object)
5403 sheet.SelectObject(object);
5406 void EnumerateObjects(Sheet sheet)
5410 for(oClass = classes.first; oClass; oClass = oClass.next)
5416 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5417 for(object = oClass.instances.first; object; object = object.next)
5418 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5421 sheet.SelectObject(selected);
5426 designer.AddObject();
5429 void DeleteObject(ObjectInfo object)
5431 delete object.instance;
5432 object.deleted = true;
5433 object.modified = true;
5434 object.oClass.modified = true;
5436 if(selected == object)
5438 bool looped = false;
5439 ObjectInfo select = object;
5443 select = select.prev;
5447 select = object.oClass.instances.last;
5454 sheet.SelectObject(select ? select : oClass);
5457 if(!object.instCode && object.oClass != object)
5460 oClass.instances.Delete(object);
5463 if(sheet.codeEditor == this)
5464 sheet.DeleteObject(object);
5467 void RenameObject(ObjectInfo object, char * name)
5471 // Validate the name:
5472 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5473 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5476 for(c = 0; name[c]; c++)
5477 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5485 object.name = (name && name[0]) ? CopyString(name) : null;
5487 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5491 void DesignerModifiedObject()
5493 sheet.ListProperties(false);
5497 void ListSubMembers(Type member)
5501 for(subMember = member.members.first; subMember; subMember = subMember.next)
5505 DataRow row = membersList.AddString(subMember.name);
5506 row.icon = icons[typeData];
5510 ListSubMembers(subMember);
5515 void ListSubDataMembers(DataMember member, bool isPrivate)
5517 DataMember subMember;
5518 for(subMember = member.members.first; subMember; subMember = subMember.next)
5520 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5524 DataRow row = membersList.AddString(subMember.name);
5525 BitmapResource bitmap = null;
5526 if(!subMember.dataType)
5527 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5529 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5531 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5534 bitmap = { bitmapName };
5535 membersList.AddResource(bitmap);
5538 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5542 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5548 void ListClassMembers(Class whatClass, bool methodsOnly)
5551 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5552 bool isPrivate = false;
5554 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5556 Method method, methodIt;
5558 DataMember memberIt;
5560 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5562 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5563 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5565 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5567 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5569 DataRow row = membersList.FindString(method.name);
5572 row = membersList.AddString(method.name);
5574 if(!method.dataType)
5575 method.dataType = ProcessTypeString(method.dataTypeString, false);
5577 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5585 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5589 if(memberIt.isProperty)
5591 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5593 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5597 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5599 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5602 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5608 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5610 if(member.isProperty)
5612 Property prop = (Property) member;
5613 if(!membersList.FindString(prop.name))
5615 DataRow row = membersList.AddString(prop.name);
5616 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5619 else if(member.name && !membersList.FindString(member.name))
5621 DataRow row = membersList.AddString(member.name);
5623 BitmapResource bitmap = null;
5624 if(!member.dataType)
5625 member.dataType = ProcessTypeString(member.dataTypeString, false);
5627 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5629 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5632 bitmap = { bitmapName };
5633 membersList.AddResource(bitmap);
5636 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5639 ListSubDataMembers(member, member.memberAccess == privateAccess);
5643 if(_class.inheritanceAccess == privateAccess)
5646 if(_class.module != privateModule) break;
5651 void ListClassMembersMatch(Class whatClass, Type methodType)
5654 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5655 bool isPrivate = false;
5657 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5663 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5665 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5667 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5669 if(!method.dataType)
5670 method.dataType = ProcessTypeString(method.dataTypeString, false);
5672 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5674 DataRow row = membersList.FindString(method.name);
5677 row = membersList.AddString(method.name);
5678 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5684 if(_class.inheritanceAccess == privateAccess)
5687 if(_class.module != privateModule) break;
5692 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5695 bool isPrivate = false;
5696 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5702 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5704 if(method.type == virtualMethod)
5706 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5708 DataRow row = membersList.FindString(method.name);
5711 row = membersList.AddString(method.name);
5713 if(!method.dataType)
5714 method.dataType = ProcessTypeString(method.dataTypeString, false);
5716 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5722 for(member = _class.membersAndProperties.first; member; member = member.next)
5724 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5726 if(member.isProperty)
5728 Property prop = (Property)member;
5730 DataRow row = membersList.AddString(prop.name);
5731 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5734 else if(member.name && (!curString || strcmp(curString, member.name)))
5736 DataRow row = membersList.AddString(member.name);
5738 BitmapResource bitmap = null;
5739 if(!member.dataType)
5740 member.dataType = ProcessTypeString(member.dataTypeString, false);
5742 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5744 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5747 bitmap = { bitmapName };
5748 membersList.AddResource(bitmap);
5751 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5754 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5757 if(_class.inheritanceAccess == privateAccess)
5760 if(_class.module != privateModule) break;
5765 void ListMembers(Type type)
5767 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5771 if(type.kind == classType)
5774 ListClassMembers(type._class.registered, false);
5779 for(member = type.members.first; member; member = member.next)
5783 DataRow row = membersList.AddString(member.name);
5784 row.icon = icons[typeData];
5786 else if(member.kind == structType || member.kind == unionType)
5787 ListSubMembers(member);
5793 void ListModule(Module mainModule, int recurse, bool listClasses)
5796 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5797 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5798 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5799 for(module = mainModule.application.allModules.first; module; module = module.next)
5801 if(ModuleVisibility(mainModule, module))
5802 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5806 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5813 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5815 Class _class = link.data;
5816 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5818 DataRow row = membersList.AddString(_class.name);
5819 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5824 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5826 DefinedExpression definedExp = link.data;
5827 DataRow row = membersList.AddString(link /*definedExp*/.name);
5828 row.icon = icons[typeData];
5831 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5833 GlobalFunction function = link.data;
5834 DataRow row = membersList.AddString(link /*function*/.name);
5835 row.icon = icons[typeMethod];
5839 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5841 if(recurse != 2 && listClasses)
5843 if(!membersList.FindString(ns->name))
5845 DataRow row = membersList.AddString(ns->name);
5846 row.icon = icons[typeNameSpace];
5851 ListNameSpace(ns, 2, listClasses);
5855 void ListEnumValues(Class _class)
5857 List<Class> classes { };
5858 for(; _class && _class.type == enumClass; _class = _class.base)
5859 classes.Insert(null, _class);
5860 for(_class : classes)
5862 EnumClassData enumeration = (EnumClassData)_class.data;
5864 for(item = enumeration.values.first; item; item = item.next)
5866 DataRow row = membersList.AddString(item.name);
5867 row.icon = icons[typeEnumValue];
5873 bool ListEnumsModule(Module mainModule, Type dest)
5875 bool result = false;
5877 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5878 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5879 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5880 for(module = mainModule.application.allModules.first; module; module = module.next)
5882 if(ModuleVisibility(mainModule, module))
5883 result |= ListEnums(module.publicNameSpace, dest);
5888 void ListNameSpaceByString(Module mainModule, char * string)
5890 NameSpace * nameSpace;
5892 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5893 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5894 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5895 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5896 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5897 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5898 for(module = mainModule.application.allModules.first; module; module = module.next)
5900 if(ModuleVisibility(mainModule, module))
5902 nameSpace = FindNameSpace(module.publicNameSpace, string);
5903 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5908 bool ListEnums(NameSpace nameSpace, Type dest)
5911 bool result = false;
5913 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5915 Class _class = link.data;
5916 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *"))) && !dest.classObjectType)) &&
5917 dest.kind != pointerType && dest.kind != ellipsisType)
5919 OldList conversions { };
5921 type.kind = classType;
5922 type._class = FindClass(_class.name);
5923 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5925 ListEnumValues(_class);
5928 conversions.Free(null);
5932 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5934 result |= ListEnums(nameSpace, dest);
5939 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5943 for(c = 0; (ch = name[c]); c++)
5945 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5947 NameSpace * newSpace;
5948 char * spaceName = new char[c - start + 1];
5949 memcpy(spaceName, name + start, c - start);
5950 spaceName[c-start] = '\0';
5951 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5955 nameSpace = newSpace;
5964 return (NameSpace *)nameSpace;
5967 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5969 bool listedEnums = false;
5970 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5971 bool listClasses = true;
5973 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5975 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5976 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5977 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
5979 if(exp.type == identifierExp)
5980 id = realIdentifier;
5982 if(id && id._class && !id._class.name)
5984 listClasses = false;
5987 else if(id && id._class && id._class.name)
5991 Class _class = id.classSym.registered;
5992 if(_class && _class.type == enumClass)
5994 ListEnumValues(_class);
5997 ListClassMembers(id.classSym.registered, true);
6002 else if(id && colons)
6004 ListNameSpaceByString(this.privateModule, id.string);
6009 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6011 listedEnums = ListEnumsModule(this.privateModule, destType);
6014 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6016 ListEnumValues(destType._class.registered);
6019 ListClassPropertiesAndVirtual(insideClass, null);
6023 else if(destType && destType.kind == enumType)
6027 for(value = destType.members.first; value; value = value.next)
6029 DataRow row = membersList.AddString(value.name);
6030 row.icon = icons[typeEnumValue];
6034 ListClassPropertiesAndVirtual(insideClass, null);
6038 else if(insideClass && !enumOnly)
6040 ListClassPropertiesAndVirtual(insideClass, string);
6043 if(listedEnums && string && string[0])
6045 DataRow row = membersList.FindSubString(string);
6047 listedEnums = false;
6050 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6052 ListClassMembersMatch(GetThisClass(), exp.destType);
6054 else if(!insideClass && !enumOnly && !listedEnums)
6057 Symbol symbol = null;
6061 ListClassMembers(GetThisClass(), false);
6064 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6066 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6068 // Don't list enum values?
6069 //if(symbol.type.kind != TypeEnum)
6070 DataRow row = membersList.FindString(symbol.string);
6073 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6075 row = membersList.AddString(symbol.string);
6076 if(symbol.type && symbol.type.kind == functionType)
6077 row.icon = icons[typeMethod];
6078 else if(symbol.type && symbol.type.kind == enumType)
6080 row.icon = icons[typeEnumValue];
6084 BitmapResource bitmap = null;
6085 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6087 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6090 bitmap = { bitmapName };
6091 membersList.AddResource(bitmap);
6094 row.icon = bitmap ? bitmap : icons[typeData];
6101 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6103 DataRow row = membersList.FindString(symbol.string);
6106 row = membersList.AddString(symbol.string);
6107 if(symbol.type.kind == functionType)
6108 row.icon = icons[typeMethod];
6109 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6111 row.icon = icons[typeClass];
6115 row.icon = icons[typeDataType];
6122 ListModule(this.privateModule, 1, listClasses);
6123 // TODO: Implement this with name space
6127 for(data = globalData.first; data; data = data.next)
6129 DataRow row = membersList.FindString(data.name);
6131 data.dataType = ProcessTypeString(data.dataTypeString, false);
6134 row = membersList.AddString(data.name);
6136 if(data.dataType && data.dataType.kind == TypeEnum)
6138 row.icon = icons[typeEnumValue];
6142 BitmapResource bitmap = null;
6143 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6145 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6148 bitmap = { bitmapName };
6149 membersList.AddResource(bitmap);
6152 row.icon = bitmap ? bitmap : icons[typeData];
6160 DataRow row = membersList.AddString("Min");
6161 row.icon = icons[typeMethod];
6163 row = membersList.AddString("Max");
6164 row.icon = icons[typeMethod];
6166 row = membersList.AddString("Abs");
6167 row.icon = icons[typeMethod];
6169 row = membersList.AddString("Sgn");
6170 row.icon = icons[typeMethod];
6176 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6178 EditBoxStream f { editBox = editBox };
6183 updatingCode = true;
6185 if(!method.dataType)
6186 method.dataType = ProcessTypeString(method.dataTypeString, false);
6188 DeleteJunkBefore(f, function.loc.start.pos, &position);
6189 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6191 // ADDING METHOD HERE
6193 Type dataType = method.dataType;
6194 Type returnType = dataType.returnType;
6196 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6202 if(extraIndent) f.Printf(" ");
6204 OutputType(f, returnType, false);
6208 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6210 if(dataType.thisClass.shortName)
6211 f.Printf(dataType.thisClass.shortName);
6213 f.Printf(dataType.thisClass.string);
6216 f.Printf(method.name);
6218 for(param = dataType.params.first; param; param = param.next)
6220 // Decided not to write void...
6221 if(param.kind != voidType)
6223 OutputType(f, param, true);
6229 if(extraIndent) f.Printf(" ");
6230 f.Printf(" %c\n", OpenBracket);
6232 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6238 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6239 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6241 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6243 if(extraIndent) f.Printf(" ");
6244 f.Printf(" return true;\n");
6246 else if(returnType && returnType.kind != voidType)
6248 if(extraIndent) f.Printf(" ");
6249 f.Printf(" return 0;\n");
6254 if(extraIndent) f.Printf(" ");
6256 if(returnType.kind != voidType)
6257 f.Printf("return ");
6258 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6259 for(param = dataType.params.first; param; param = param.next)
6261 if(param.prev) f.Printf(", ");
6262 if(param.kind != voidType)
6263 f.Printf(param.name);
6269 if(extraIndent) f.Printf(" ");
6270 f.Printf(" %c", CloseBracket);
6275 if(extraIndent) { x1 += 3; x2 += 3; }
6276 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6278 this.updatingCode = false;
6282 // Return false if we overrided a function and don't want to run params listing
6283 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6285 bool didOverride = false;
6286 EditLine line = editBox.line;
6287 char * text = line.text;
6288 int lineNum, charPos;
6289 Expression exp = null;
6292 //Identifier id = null;
6293 Expression memberExp = null;
6294 Identifier realIdentifier = null;
6296 if(!parsing) return true;
6297 if(!privateModule) return !didOverride;
6299 insideFunction = null;
6301 charPos = editBox.charPos + 1;
6302 if(!membersListShown)
6307 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6309 EditBoxStream f { editBox = editBox };
6311 updatingCode = true;
6312 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6316 if(!f.Seek(-1, current))
6319 if(!isspace(ch)) break;
6320 f.Seek(-1, current);
6322 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6324 lineNum = editBox.lineNumber + 1;
6325 charPos = editBox.charPos + 1;
6327 updatingCode = false;
6330 if(!membersListShown)
6332 memberExp = FindExpTree(ast, lineNum, charPos);
6333 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6338 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6340 EditBoxStream f { editBox = editBox };
6343 updatingCode = true;
6345 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6348 if(ch == '}' || ch == ',' || ch == ')')
6350 f.Seek(-1, current);
6358 if(!f.Seek(-1, current))
6361 if(!isspace(ch)) break;
6362 f.Seek(-1, current);
6366 f.Seek(-1, current);
6368 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6370 lineNum = editBox.lineNumber + 1;
6371 charPos = editBox.charPos + 1;
6373 updatingCode = false;
6376 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6381 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6382 lineNum = editBox.lineNumber + 1;
6383 charPos = editBox.charPos/* + 1*/;
6387 char tempString[1024];
6388 char * string = null;
6389 CodePosition idStart, idEnd;
6391 if(membersListShown)
6393 char * buffer = membersLine.text;
6395 bool firstChar = true;
6397 string = tempString;
6399 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6401 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6402 if(!isSpace) firstChar = false;
6404 string[len++] = buffer[c];
6408 else //if(realIdentifier)//if(id)
6411 char * buffer = id.string;
6413 bool firstChar = true;
6415 string = tempString;
6416 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6418 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6419 if(!isSpace) firstChar = false;
6421 string[len++] = buffer[c];
6427 EditLine editLine = editBox.line;
6428 bool firstChar = true;
6431 string = tempString;
6432 for(y = lineNum-1; y >= 0; y--)
6434 char * buffer = editLine.text;
6435 int lineCount = editLine.count;
6436 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6438 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6443 idEnd.charPos = x + 2;
6448 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6451 idEnd.charPos = x + 2;
6458 if(!isalnum(buffer[x]) && buffer[x] != '_')
6464 memmove(string+1, string, len++);
6465 string[0] = buffer[x];
6469 //if(done || firstChar)
6470 if(done || !firstChar)
6472 editLine = editLine.prev;
6475 if(!strcmp(string, "case"))
6481 else if(!strcmp(string, "return"))
6487 else if(!strcmp(string, "delete"))
6493 else if(!strcmp(string, "new"))
6499 else if(!strcmp(string, "renew"))
6507 idStart.charPos = x + 1;
6508 idStart.line = y + 1;
6511 if(!membersListShown)
6513 membersList.Clear();
6514 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6516 Type type = memberExp.member.exp.expType;
6517 if(pointer == 2 && type)
6519 if(type.kind == pointerType || type.kind == arrayType)
6528 ListSymbols(exp, enumOnly, string, realIdentifier);
6530 membersList.Sort(null, 1);
6535 // Virtual function override
6536 Identifier id = GetDeclId(insideFunction.declarator);
6537 char * string = id ? id.string : null;
6539 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6542 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6543 insideFunction = null;
6546 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6551 if(!didOverride) //insideFunction)
6553 rowCount = membersList.rowCount;
6556 DataRow row = string ? membersList.FindSubString(string) : null;
6557 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6559 char * newString = row.string;
6560 if(!membersListShown)
6562 membersLoc.start.line = idStart.line-1;
6563 membersLoc.start.charPos = idStart.charPos-1;
6564 //membersLoc.end = membersLoc.start;
6565 membersLoc.end.charPos = idEnd.charPos-1;
6566 membersLoc.end.line = idEnd.line-1;
6567 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6568 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6573 membersList.Destroy(0);
6574 membersListShown = false;
6577 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6579 line, membersLoc.start.line, membersLoc.start.charPos,
6580 line, membersLoc.end.line, membersLoc.end.charPos);
6581 editBox.PutS(newString);
6587 row = membersList.FindSubStringi(string);
6589 membersList.currentRow = row;
6590 membersList.currentRow.selected = false;
6593 membersList.currentRow = row;
6595 if(!membersListShown)
6599 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6600 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6601 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6602 editBox.GetCaretPosition(caret);
6603 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6605 membersList.master = this;
6607 caret.y += editBox.GetCaretSize();
6609 membersList.Create();
6612 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6613 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6614 Window parent = membersList.parent;
6616 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6618 y -= editBox.GetCaretSize() + membersList.size.h;
6619 membersAbove = true;
6622 membersAbove = false;
6624 membersList.position = { x, y };
6628 membersLoc.start.line = lineNum - 1;
6630 if(string && string[0])
6632 membersLoc.start.charPos = idStart.charPos-1;
6633 membersLoc.end = membersLoc.start;
6634 //membersLoc.end.charPos = id.loc.end.charPos-1;
6635 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6639 membersLoc.start.charPos = charPos;
6640 membersLoc.end = membersLoc.start;
6641 membersLoc.end.charPos = charPos;
6643 membersListShown = true;
6645 // Hack to keep caret shown
6646 editBox.GetCaretPosition(caret);
6647 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6650 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6656 SetCurrentContext(globalContext);
6659 return !didOverride;
6662 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6664 EditLine line = editBox.line;
6665 char * text = line.text;
6666 int lineNum, charPos;
6667 Expression exp = null;
6671 if(!parsing) return;
6673 charPos = editBox.charPos + 1;
6676 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6678 EditBoxStream f { editBox = editBox };
6681 updatingCode = true;
6682 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6685 if(ch == '}' || ch == ',' || ch == ')')
6687 f.Seek(-1, current);
6695 if(!f.Seek(-1, current))
6698 if(!isspace(ch)) break;
6699 f.Seek(-1, current);
6703 f.Seek(-1, current);
6705 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6707 lineNum = editBox.lineNumber + 1;
6708 charPos = editBox.charPos + 1;
6710 updatingCode = false;
6713 charPos = Min(charPos, l1.count + 1);
6715 FindParamsTree(ast, lineNum, charPos);
6717 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6718 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6720 ::functionType = null;
6721 ::instanceType = null;
6724 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6725 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6729 Window parent = paramsList.parent;
6731 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6734 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6735 // ( Dummy exp: always ends up with same memory)
6737 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6738 editBox.GetCaretPosition(paramsPosition);
6739 this.paramsPosition.y += editBox.GetCaretSize();
6742 FreeType(this.functionType);
6743 FreeType(this.instanceType);
6745 this.functionType = ::functionType;
6746 this.instanceType = ::instanceType;
6748 if(this.functionType) this.functionType.refCount++;
6749 if(this.instanceType) this.instanceType.refCount++;
6751 this.paramsID = ::paramsID;
6752 functionExp = paramsInsideExp;
6754 paramsList.master = this;
6756 paramsList.Create();
6758 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6759 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6761 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6763 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6767 paramsAbove = false;
6768 if(x + paramsList.size.w > parent.clientSize.w)
6770 x = parent.clientSize.w - paramsList.size.w;
6774 paramsList.position = { x, y };
6776 // Hack to keep caret shown
6779 editBox.GetCaretPosition(caret);
6780 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6783 this.paramsShown = true;
6785 else if((!::functionType && !::instanceType) || reposition)
6787 paramsList.Destroy(0);
6788 paramsShown = false;
6790 FreeType(this.functionType);
6791 FreeType(this.instanceType);
6792 this.functionType = null;
6793 this.instanceType = null;
6797 SetCurrentContext(globalContext);
6805 designer.visible = true;
6806 designer.Activate();
6812 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6814 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };