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;
1969 if(ide && ide.workspace)
1971 for(p : ide.workspace.projects)
1973 if(p.topNode.FindByFullPath(fileName, false))
1981 for(p : ide.workspace.projects)
1983 if(IsPathInsideOf(fileName, p.topNode.path))
1991 ide.debugger.ToggleBreakpoint(fileName, line, prj);
2001 //MenuItem viewDesignerItem, viewProperties, viewMethods;
2005 designer.parent = parent;
2008 toolBox = ((IDEWorkSpace)master).toolBox;
2010 // Debugger bug here: value of toolBox appears as 0
2012 sheet = ((IDEWorkSpace)master).sheet;
2017 bool OnClose(bool parentClosing)
2021 if(ide.workspace && fileName)
2022 ide.workspace.UpdateOpenedFileInfo(fileName, closed);
2023 if(inUseDebug && !debugClosing)
2025 debugClosing = true;
2027 if(CloseConfirmation(false))
2030 if(modifiedDocument)
2031 OnFileModified({ modified = true }, null);
2033 debugClosing = false;
2036 if(designer && !designer.closing)
2038 if(designer.visible)
2045 //Window formEditor = designer;
2046 //formEditor.Destroy(0);
2049 ide.AdjustFileMenus();
2054 void OnDestroy(void)
2056 ObjectInfo oClass, next;
2057 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2059 FreeType(this.functionType);
2060 FreeType(this.instanceType);
2065 designer.codeEditor = null;
2066 designer.Destroy(0);
2070 for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
2072 ObjectInfo object, next;
2074 for(object = oClass.instances.first; object; object = next)
2079 Designer::DestroyObject(object.instance);
2080 delete object.instance;
2082 sheet.DeleteObject(object);
2084 oClass.instances.Delete(object);
2088 Designer::DestroyObject(oClass.instance);
2089 delete oClass.instance;
2091 sheet.DeleteObject(oClass);
2093 classes.Delete(oClass);
2096 if(windowClass && windowClass.data)
2097 UnapplySkin(windowClass);
2101 if(sheet.codeEditor == this)
2103 sheet.codeEditor = null;
2104 toolBox.codeEditor = null;
2110 ProjectView projectView = ide.projectView;
2113 ProjectNode node = projectView.GetNodeFromWindow(this, null, false, false);
2114 if(node && node.modified)
2116 node.modified = false;
2117 projectView.Update(null);
2123 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool directActivation)
2125 // 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
2127 if(directActivation)
2128 ide.RepositionWindows(false); // Moved this up before as resizing causes NotifyCaretMove to be called on all editors
2130 if(active && directActivation)
2134 openedFileInfo.Activate();
2138 Location * loc = null;
2139 UpdateFormCode(); // To ensure update when modifying properties...
2141 // Got to the right spot in code so we don't lose our form selection...
2144 if(selected.instCode)
2145 loc = &selected.instCode.loc;
2146 else if(selected.classDefinition)
2147 loc = &selected.classDefinition.loc;
2149 line = editBox.lineNumber + 1;
2150 charPos = editBox.charPos + 1;
2155 if(selected && !loc->Inside(line, charPos))
2157 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2158 line = editBox.lineNumber + 1;
2159 charPos = editBox.charPos + 1;
2161 else if(selected && selected.classDefinition)
2164 for(object = selected.instances.first; object; object = object.next)
2168 if(object.instCode.loc.Inside(line, charPos))
2174 editBox.GoToPosition(null, loc->start.line - 1, loc->start.charPos - 1);
2175 line = editBox.lineNumber + 1;
2176 charPos = editBox.charPos + 1;
2181 ProcessCaretMove(editBox, line, charPos);
2186 if(membersListShown)
2188 membersList.Destroy(0);
2189 membersListShown = false;
2193 paramsList.Destroy(0);
2194 paramsShown = false;
2195 FreeType(functionType);
2196 FreeType(instanceType);
2198 functionType = null;
2199 instanceType = null;
2206 bool OnSaveFile(char * fileName)
2213 f = FileOpen(fileName, write);
2216 if(!ide.projectView)
2217 ide.ChangeFileDialogsDirectory(codeEditorFileDialog.currentDirectory, true);
2221 this.fileName = fileName; // Put this here because the form designer will check for it...
2222 designer.fileName = fileName;
2223 designer.modifiedDocument = false;
2225 editBox.Save(f, false);
2226 modifiedDocument = false;
2234 bool OnFileModified(FileChange fileChange, char * param)
2236 bool reload = false;
2237 if(visible == false && inUseDebug == true)
2243 sprintf(message, $"The document %s was modified by another application.\n"
2244 "Would you like to reload it and lose your changes?", fileName);
2245 if(MessageBox { type = yesNo, master = /*parent = */parent, text = $"Document has been modified",
2246 contents = message }.Modal() == yes)
2252 File f = FileOpen(fileName, read);
2255 int lineNumber, charPos, len;
2259 updatingCode = true;
2260 lineNumber = editBox.lineNumber;
2261 charPos = editBox.charPos;
2262 scroll = editBox.scroll;
2265 lineNumber = lineNumber < editBox.numLines ? lineNumber : editBox.numLines - 1;
2266 len = strlen(editBox.line.text);
2267 editBox.GoToLineNum(lineNumber);
2268 editBox.GoToPosition(editBox.line, lineNumber, charPos <= len ? charPos - 1 : (len ? len - 1 : 0));
2269 editBox.scroll = scroll;
2270 updatingCode = false;
2271 loadingFile = false;
2273 codeModified = true;
2277 designer.modifiedDocument = false;
2279 modifiedDocument = false;
2287 void OnRedraw(Surface surface)
2290 surface.SetBackground(marginColor);
2291 surface.Area(0, 0, editBox.anchor.left.distance, clientSize.h - 1);
2292 if(ideSettings.showLineNumbers)
2294 int currentLineNumber;
2299 surface.textOpacity = false;
2300 surface.font = font.font;
2301 surface.TextExtent(" ", 1, null, &spaceH);
2302 currentLineNumber = editBox.scroll.y / spaceH + 1;
2304 surface.SetForeground(lineNumbersColor);
2305 for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
2307 // Highlight current line
2308 if(editBox.lineNumber == currentLineNumber - 1)
2310 surface.SetBackground(selectedMarginColor);
2311 surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
2312 surface.SetBackground(marginColor);
2314 sprintf(lineText,"%5u ", currentLineNumber % 100000);
2315 if(currentLineNumber <= editBox.numLines)
2316 surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,6);
2318 currentLineNumber++;
2322 if(editBox.syntaxHighlighting && fileName && ide.projectView)
2324 bool error, bpOnCursor, bpOnTopFrame, breakpointEnabled[128];
2325 int lineCursor, lineTopFrame, breakpointLines[128];
2326 int count, i, lineH, boxH, scrollY; //, firstLine; firstLine = editBox.firstLine;
2327 Debugger debugger = ide.debugger;
2328 BitmapResource bmpRes;
2330 boxH = clientSize.h;
2331 scrollY = editBox.scroll.y;
2332 displaySystem.FontExtent(editBox.font.font, " ", 1, null, &lineH);
2334 bpOnCursor = bpOnTopFrame = false;
2335 count = debugger.GetMarginIconsLineNumbers(fileName, breakpointLines, breakpointEnabled, 128, &error, &lineCursor, &lineTopFrame);
2338 for(i = 0; i < count; i++)
2340 if(breakpointLines[i] == lineCursor || breakpointLines[i] == lineTopFrame)
2342 bmpRes = breakpointEnabled[i] ? ide.bmpBpHalf : ide.bmpBpHalfDisabled;
2343 if(breakpointLines[i] == lineCursor)
2345 if(breakpointLines[i] == lineTopFrame)
2346 bpOnTopFrame = true;
2349 bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
2351 DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
2354 DrawLineMarginIcon(surface, error ? ide.bmpCursorError : ide.bmpCursor, lineCursor, lineH, scrollY, boxH);
2355 bmpRes = bpOnTopFrame ? (error ? ide.bmpTopFrameHalfError : ide.bmpTopFrameHalf) : (error ? ide.bmpTopFrameError : ide.bmpTopFrame);
2356 DrawLineMarginIcon(surface, bmpRes, lineTopFrame, lineH, scrollY, boxH);
2358 if(editBox.anchor.left.distance)
2360 if(editBox.horzScroll && editBox.horzScroll.visible)
2362 surface.SetBackground(control);
2363 surface.Area(0, editBox.clientSize.h, editBox.anchor.left.distance, clientSize.h - 1);
2368 void DrawLineMarginIcon(Surface surface, BitmapResource resource, int line, int lineH, int scrollY, int boxH)
2373 lineY = (line - 1) * lineH;
2374 if(lineY + lineH > scrollY && lineY /*+ lineH*/ < scrollY + boxH)
2376 Bitmap bitmap = resource.bitmap;
2378 surface.Blit(bitmap, 0, lineY - scrollY + (lineH - bitmap.height) / 2 + 1, 0, 0, bitmap.width, bitmap.height);
2385 char ext[MAX_EXTENSION];
2386 char * fileName = property::fileName;
2388 if(SearchString(fileName, 0, "Makefile", false, true))
2389 editBox.useTab = true;
2390 designer.fileName = fileName;
2394 GetExtension(fileName, ext);
2396 if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
2397 !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
2398 !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
2399 editBox.syntaxHighlighting = true;
2401 editBox.syntaxHighlighting = false;
2403 if(parsing && !strcmpi(ext, "ec"))
2405 codeModified = true;
2411 display.FontExtent(font.font, " ", 1, &spaceW, null);
2412 editBox.anchor = Anchor
2414 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2415 right = 0, top = 0, bottom = 0
2424 display.FontExtent(font.font, " ", 1, &spaceW, null);
2425 editBox.anchor = Anchor
2427 left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
2428 right = 0, top = 0, bottom = 0
2433 bool LoadFile(char * filePath)
2435 File f = FileOpen(filePath, read);
2438 // Added this here...
2439 fileName = filePath;
2441 updatingCode = true;
2443 updatingCode = false;
2444 loadingFile = false;
2453 void AdjustDebugMenus()
2455 bool unavailable = ide.areDebugMenusUnavailable;
2456 bool isNotNotRunning = unavailable || ide.isDebuggerRunning;
2457 bool isNotStopped = unavailable || !ide.isDebuggerStopped;
2458 bool noBreakpointToggle = ide.isBreakpointTogglingUnavailable;
2460 debugRunToCursor.disabled = isNotNotRunning;
2461 debugSkipRunToCursor.disabled = isNotNotRunning;
2462 debugRunToCursorAtSameLevel.disabled = isNotStopped;
2463 debugSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2465 debugBpRunToCursor.disabled = isNotNotRunning;
2466 debugBpSkipRunToCursor.disabled = isNotNotRunning;
2467 debugBpRunToCursorAtSameLevel.disabled = isNotStopped;
2468 debugBpSkipRunToCursorAtSameLevel.disabled = isNotStopped;
2470 debugToggleBreakpoint.disabled = noBreakpointToggle;
2476 ProjectView projectView = ide.projectView;
2479 designer.fileName = fileName;
2485 sprintf(title, $"Untitled %d", documentID);
2486 // designer.fileName = CopyString(title);
2487 designer.fileName = title;
2492 for(c = 0; c < CodeObjectType::enumSize; c++)
2493 icons[c] = BitmapResource { iconNames[c], window = this };
2495 codeModified = true;
2507 selected.modified = true;
2508 selected.oClass.modified = true;
2510 designer.modifiedDocument = true;
2511 modifiedDocument = true;
2512 formModified = true;
2515 /****************************************************************************
2517 ****************************************************************************/
2525 this.defines.Free(FreeModuleDefine);
2526 this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created
2528 FreeExcludedSymbols(this.excludedSymbols);
2529 FreeContext(this.globalContext);
2531 FreeGlobalData(&this.globalData);
2532 FindCtx_Terminate();
2533 FindParams_Terminate();
2535 if(GetGlobalContext() == globalContext)
2537 SetGlobalData(null);
2538 SetGlobalContext(null);
2539 SetExcludedSymbols(null);
2540 SetTopContext(null);
2541 SetCurrentContext(null);
2544 SetPrivateModule(null);
2547 if(this.privateModule)
2549 FreeTypeData(this.privateModule);
2550 delete this.privateModule;
2551 this.privateModule = null;
2557 static bool reentrant = false;
2562 char * selectedClassName = null, * selectedName = null;
2563 int selectedPos = 0;
2564 Designer backDesigner;
2565 char oldWorkDir[MAX_LOCATION];
2566 char mainModuleName[MAX_FILENAME] = "";
2568 ImportedModule module;
2569 char extension[MAX_EXTENSION];
2570 PathBackup pathBackup { };
2572 Time parseCodeStart = GetTime();
2573 Time startTime, startFindClass;
2575 findClassTotalTime = 0;
2576 checkTypeTotalTime = 0;
2577 externalImportTotalTime = 0;
2578 findClassIgnoreNSTotalTime = 0;
2579 findSymbolTotalTime = 0;
2580 //ResetClassFindTime();
2584 // 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)
2585 if(reentrant) return;
2592 selectedClassName = CopyString(oClass.name);
2593 if(selected != oClass)
2595 ObjectInfo object = this.selected;
2596 selectedName = CopyString(object.name);
2600 for(check = this.oClass.instances.first; check; check = check.next)
2612 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
2614 FindCtx_Terminate();
2615 FindParams_Terminate();
2617 SetGlobalData(&globalData);
2618 SetGlobalContext(globalContext);
2619 SetExcludedSymbols(&excludedSymbols);
2620 SetTopContext(globalContext);
2621 SetCurrentContext(globalContext);
2622 SetDefines(&defines);
2623 SetImports(&imports);
2624 SetCurrentNameSpace(null);
2627 sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl "
2628 "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" "
2629 "/I \"C:\\Program Files\\Microsoft Visual Studio\\VC98\\Include\" "
2630 "/I T:\\ecere\\include /E %s", argv[1]);
2634 ChangeWorkingDir("e:\\ec");
2635 sprintf(command, "gcc -x c -E -");
2636 fileInput = DualPipeOpen({ output = true, input = true }, command);
2637 SetFileInput(fileInput);
2642 uint count = editFile.Read(buffer, 1, sizeof(buffer));
2644 fileInput.Write(buffer, 1, count);
2649 fileInput.CloseOutput();
2653 // TOCHECK: COULDN'T WE CALL FreeParser here?
2655 FreeType(this.functionType);
2656 FreeType(this.instanceType);
2657 this.functionType = null;
2658 this.instanceType = null;
2661 sheet.SelectObject(null);
2667 // We don't want the designer to be notified of selection when deleting rows...
2668 backDesigner = designer;
2673 ObjectInfo _class, next;
2675 for(_class = classes.first; _class; _class = next)
2681 for(;object = _class.instances.first;)
2685 Designer::DestroyObject(object.instance);
2686 delete object.instance;
2688 sheet.DeleteObject(object);
2690 _class.instances.Delete(object);
2694 Designer::DestroyObject(_class.instance);
2695 delete _class.instance;
2697 sheet.DeleteObject(_class);
2699 classes.Delete(_class);
2705 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2706 if(windowClass && windowClass.data)
2707 UnapplySkin(windowClass);
2710 designer = backDesigner;
2713 fileInput = editFile = EditBoxStream { editBox = editBox };
2714 SetFileInput(fileInput);
2722 defines.Free(FreeModuleDefine);
2723 imports.Free(FreeModuleImport);
2725 FreeContext(this.globalContext);
2726 FreeExcludedSymbols(this.excludedSymbols);
2729 FreeGlobalData(&this.globalData);
2731 if(this.privateModule)
2733 FreeTypeData(this.privateModule);
2734 delete this.privateModule;
2738 startTime = GetTime();
2739 printf("Cleaning up took %.3f seconds\n", startTime - parseCodeStart);
2741 printf("classes.count: %d\n", globalContext.classes.count);
2746 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2747 SetTargetBits(ide.workspace.bitDepth ? ide.workspace.bitDepth : GetHostBits());
2750 this.privateModule = __ecere_COM_Initialize(false | ((GetTargetBits() == sizeof(uintptr) *8) ? 0 : GetTargetBits() == 64 ? 2 : 4), 1, null);
2752 SetPrivateModule(privateModule);
2755 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint"), type = ProcessTypeString("unsigned int", false) });
2756 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint64"), type = ProcessTypeString("unsigned int64", false) });
2757 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint32"), type = ProcessTypeString("unsigned int", false) });
2758 globalContext.types.Add((BTNode)Symbol { string = CopyString("uint16"), type = ProcessTypeString("unsigned short", false) });
2759 globalContext.types.Add((BTNode)Symbol { string = CopyString("byte"), type = ProcessTypeString("unsigned char", false) });
2762 fileName = this.fileName;
2764 if(ide.workspace && ide.workspace.projects && fileName)
2766 for(p : ide.workspace.projects)
2768 char path[MAX_LOCATION];
2770 MakePathRelative(fileName, p.topNode.path, path);
2771 MakeSlashPath(path);
2773 pn = p.topNode.FindWithPath(path, false);
2782 project = ide.project;
2784 GetWorkingDir(oldWorkDir, MAX_LOCATION);
2786 ChangeWorkingDir(project.topNode.path);
2788 SetSomeSourceFileStack(fileName ? fileName : "", 0); //strcpy(sourceFileStack[0], fileName ? fileName : "");
2790 GetLastDirectory(fileName, mainModuleName);
2791 GetExtension(mainModuleName, extension);
2793 SetBuildingEcereCom(false);
2794 SetBuildingEcereComModule(false);
2796 // TODO: Get symbolsDir from project settings instead...
2799 CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
2800 ProjectConfig config = project.config;
2801 int bitDepth = ide.workspace.bitDepth;
2802 DirExpression objDir = project.GetObjDir(compiler, config, bitDepth);
2803 SetSymbolsDir(objDir.dir);
2804 ide.SetPath(true, compiler, config, bitDepth);
2808 // SetIncludeDirs(ide.projectView.project.config.includeDirs);
2809 // SetSysIncludeDirs(ide.ideSettings.systemDirs[includes]);
2813 switch(GetRuntimePlatform())
2815 case win32: SetSymbolsDir("obj/debug.win32"); break;
2816 case tux: SetSymbolsDir("obj/debug.linux"); break;
2817 case apple: SetSymbolsDir("obj/debug.apple"); break;
2819 SetIncludeDirs(null);
2820 SetSysIncludeDirs(null);
2824 if(ide.projectView && ide.projectView.IsModuleInProject(this.fileName))
2826 // TODO FIX for configless project
2827 if(ide.project.config && ide.project.config.options && ide.project.config.options.preprocessorDefinitions)
2829 for(item : ide.project.config.options.preprocessorDefinitions)
2831 if(!strcmp(item, "BUILDING_ECERE_COM"))
2833 SetBuildingEcereCom(true);
2840 if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
2841 strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
2842 strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
2843 strcmpi(mainModuleName, "Array.ec") && strcmpi(mainModuleName, "AVLTree.ec") &&
2844 strcmpi(mainModuleName, "BuiltInContainer.ec") && strcmpi(mainModuleName, "Container.ec") &&
2845 strcmpi(mainModuleName, "CustomAVLTree.ec") && strcmpi(mainModuleName, "LinkList.ec") &&
2846 strcmpi(mainModuleName, "List.ec") && strcmpi(mainModuleName, "Map.ec") &&
2847 strcmpi(mainModuleName, "Mutex.ec")))
2849 SetBuildingEcereComModule(true);
2852 // Predeclare all classes
2854 char symFile[MAX_FILENAME];
2855 char symLocation[MAX_LOCATION];
2856 ImportedModule module, next;
2858 GetLastDirectory(fileName, symFile);
2859 ChangeExtension(symFile, "sym", symFile);
2861 strcpy(symLocation, GetSymbolsDir());
2862 PathCat(symLocation, symFile);
2864 // if(!GetEcereImported() && !GetBuildingEcereCom())
2865 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2868 startTime = GetTime();
2870 eModule_LoadStrict(privateModule, "ecereCOM", privateAccess);
2872 printf("Loading ecereCOM took %.3f seconds\n", GetTime() - startTime);
2877 startTime = GetTime();
2879 // LoadSymbols(symLocation, normalImport, true);
2880 LoadSymbols(symLocation, preDeclImport, false);
2882 printf("Loading symbols took %.3f seconds\n", GetTime() - startTime);
2885 for(module = defines.first; module; module = next)
2888 if(module.type == moduleDefinition && strcmpi(module.name, mainModuleName))
2891 defines.Delete(module);
2896 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2898 SetDefaultDeclMode(privateAccess);
2899 SetDeclMode(privateAccess);
2903 SetDefaultDeclMode(defaultAccess);
2904 SetDeclMode(defaultAccess);
2907 StripExtension(mainModuleName);
2908 module = ImportedModule { name = CopyString(mainModuleName), type = moduleDefinition };
2909 defines.AddName(module);
2912 // SetYydebug(true);
2917 startTime = GetTime();
2918 startFindClass = checkTypeTotalTime;
2922 printf("ParseEc took %.3f seconds, out of which %.3f seconds were in CheckType\n", GetTime() - startTime, checkTypeTotalTime - startFindClass);
2924 CheckDataRedefinitions();
2927 SetIncludeDirs(null);
2928 SetSysIncludeDirs(null);
2939 startTime = GetTime();
2941 PrePreProcessClassDefinitions();
2942 ComputeModuleClasses(privateModule);
2943 PreProcessClassDefinitions();
2944 ProcessClassDefinitions();
2946 printf("Initial Passes took %.3f seconds\n", GetTime() - startTime);
2947 startTime = GetTime();
2952 printf("ComputeDataTypes took %.3f seconds\n", GetTime() - startTime);
2953 startTime = GetTime();
2955 ProcessInstantiations();
2957 printf("ProcessInstantiations took %.3f seconds\n", GetTime() - startTime);
2960 if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
2962 Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2963 if(!windowClass || windowClass.internalDecl)
2966 startTime = GetTime();
2968 // *** COMMENTED THIS OUT DUE TO ecereCOM issues
2969 // eModule_Load(this.privateModule.application.allModules.first ? this.privateModule.application.allModules.first : this.privateModule, "ecere", privateAccess);
2970 eModule_Load(this.privateModule, "ecere", privateAccess);
2972 printf("Loading ecere.dll took %.3f seconds\n", GetTime() - startTime);
2975 windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window");
2977 if(windowClass && windowClass.data)
2978 ApplySkin(windowClass, app.currentSkin.name, null);
2982 startTime = GetTime();
2984 for(external = ast->first; external; external = external.next)
2986 if(external.type == classExternal)
2988 ClassDefinition _class = external._class;
2989 if(_class.baseSpecs && _class.baseSpecs->first && ((Specifier)_class.baseSpecs->first).type == nameSpecifier ) // classSpecifier
2991 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)_class.baseSpecs->first).name);
2994 if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
2996 Instance instance = eInstance_New(regClass);
2997 ObjectInfo classObject
2999 name = CopyString(_class._class.name);
3000 instance = instance;
3001 classDefinition = _class;
3002 oClass = classObject;
3005 classes.Add(classObject);
3009 // Moved this at bottom so that the file dialog doesn't show up in eCom
3010 designer.CreateObject(instance, classObject, true, null);
3011 sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, typeClass, false);
3013 if(_class.definitions)
3017 for(def = _class.definitions->first; def; def = def.next)
3021 case defaultPropertiesClassDef:
3024 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
3026 Identifier id = propDef.identifiers->first;
3029 Property prop = eClass_FindProperty(regClass, id.string, this.privateModule);
3032 Class propertyClass = prop.dataTypeClass;
3034 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3035 if(prop.compiled && prop.Set && prop.Get && propertyClass && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp)
3037 FreeType(propDef.initializer.exp.destType);
3038 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
3039 ProcessExpressionType(propDef.initializer.exp);
3041 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
3043 Expression computed = CopyExpression(propDef.initializer.exp);
3044 ComputeExpression(computed);
3046 if(computed.isConstant && computed.type == instanceExp && !id.next)
3050 if(computed.instance._class && computed.instance._class.symbol &&
3051 computed.instance._class.symbol.registered &&
3052 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3054 ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
3056 // This was saved in the control and shouldn't be freed by FreeExpression...
3057 if(propertyClass.type == normalClass)
3058 computed.instance.data = null;
3062 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3063 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3065 String temp = new char[strlen(computed.string)+1];
3066 ReadString(temp, computed.string);
3067 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3071 propDef.variable = true;
3073 FreeExpression(computed);
3077 Expression computed = CopyExpression(propDef.initializer.exp);
3078 ComputeExpression(computed);
3079 if(computed.isConstant)
3081 //if(computed.type == memberExp) computed = computed.member.exp;
3083 if(computed.type == constantExp)
3085 Operand value = GetOperand(computed);
3086 DataValue valueData;
3087 valueData.i64 = value.i64;
3088 SetProperty(prop, instance, valueData);
3090 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3092 String temp = new char[strlen(computed.string)+1];
3093 ReadString(temp, computed.string);
3094 ((void (*)(void *, void *))(void *)prop.Set)(instance, temp);
3099 propDef.variable = true;
3101 FreeExpression(computed);
3105 propDef.variable = true;
3109 Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
3110 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
3111 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
3114 // Maintain a list in FunctionDefinition of who is attached to it
3115 for(def = _class.definitions->first; def; def = def.next)
3117 if(def.type == functionClassDef)
3119 ClassFunction function = def.function;
3120 if(!strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
3122 function.attached.Add(OldLink { data = method });
3132 case declarationClassDef:
3134 Declaration decl = def.decl;
3137 case instDeclaration:
3139 Instantiation inst = decl.inst;
3140 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3141 if(instClass && eClass_GetDesigner(instClass))
3143 Instance control = eInstance_New(instClass);
3148 oClass = classObject;
3152 classObject.instances.Add(object);
3154 // TOCHECK: Why is this needed now?
3155 object.name = CopyString((inst.exp.type == memberExp) ? inst.exp.member.member.string : inst.exp.identifier.string);
3156 def.object = object;
3158 // if(object.name) { symbol = eList_Add(&curContext.symbols, sizeof(Symbol)); symbol.string = object.name; symbol.type = MkClassType(instClass.name); }
3160 designer.CreateObject(control, object, false, classObject.instance);
3161 sheet.AddObject(object, object.name ? object.name : inst._class.name, typeData, false);
3171 // Second pass, process instantiation members
3173 for(def = _class.definitions->first; def; def = def.next)
3177 case declarationClassDef:
3179 Declaration decl = def.decl;
3182 case instDeclaration:
3184 Instantiation inst = decl.inst;
3185 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3186 if(instClass && eClass_GetDesigner(instClass))
3189 object = object ? object.next : classObject.instances.first;
3190 control = object.instance;
3194 MembersInit members;
3195 for(members = inst.members->first; members; members = members.next)
3197 switch(members.type)
3199 case dataMembersInit:
3201 if(members.dataMembers)
3204 DataMember curMember = null;
3205 Class curClass = null;
3206 DataMember subMemberStack[256];
3207 int subMemberStackPos = 0;
3209 for(member = members.dataMembers->first; member; member = member.next)
3212 Identifier ident = member.identifiers ? member.identifiers->first : null;
3215 DataMember _subMemberStack[256];
3216 int _subMemberStackPos = 0;
3217 DataMember thisMember = (DataMember)eClass_FindDataMember(instClass, ident.string, privateModule, _subMemberStack, &_subMemberStackPos);
3221 thisMember = (DataMember)eClass_FindProperty(instClass, ident.string, privateModule);
3223 if(thisMember && thisMember.memberAccess == publicAccess)
3225 curMember = thisMember;
3226 curClass = curMember._class;
3227 memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
3228 subMemberStackPos = _subMemberStackPos;
3234 eClass_FindNextMember(instClass, &curClass, (DataMember *)&curMember, subMemberStack, &subMemberStackPos);
3235 if(curMember) found = true;
3237 if(found && curMember.isProperty)
3239 Property prop = (Property) curMember;
3240 Class propertyClass = prop.dataTypeClass;
3242 propertyClass = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3244 if(prop.compiled && prop.Set && prop.Get && propertyClass && member.initializer && member.initializer.type == expInitializer && member.initializer.exp)
3246 FreeType(member.initializer.exp.destType);
3247 member.initializer.exp.destType = MkClassType(propertyClass.name);
3250 ProcessExpressionType(member.initializer.exp);
3252 if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
3254 Expression computed;
3256 /*char debugExpString[4096];
3257 debugExpString[0] = '\0';
3258 PrintExpression(member.initializer.exp, debugExpString);*/
3260 computed = CopyExpression(member.initializer.exp);
3263 ComputeExpression(computed);
3265 if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
3267 if(computed.instance.data)
3269 if(computed.instance._class && computed.instance._class.symbol &&
3270 computed.instance._class.symbol.registered &&
3271 eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
3273 ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
3275 // This was saved in the control and shouldn't be freed by FreeExpression...
3276 if(propertyClass.type == normalClass)
3277 computed.instance.data = null;
3281 else if(computed.type == identifierExp)
3283 member.variable = true;
3285 if(eClass_GetDesigner(propertyClass))
3288 char * name = computed.identifier.string;
3289 if(!strcmp(name, "this"))
3292 ((void (*)(void *, void *))(void *)prop.Set)(control, instance);
3293 member.variable = false;
3298 for(check = classObject.instances.first; check; check = check.next)
3299 if(check.name && !strcmp(name, check.name))
3302 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3303 member.variable = false;
3309 else if(computed.type == memberExp)
3311 member.variable = true;
3312 if(computed.member.exp.type == identifierExp)
3314 char * name = computed.member.exp.identifier.string;
3315 if(!strcmp(name, "this"))
3317 char * name = computed.member.member.string;
3320 for(check = classObject.instances.first; check; check = check.next)
3321 if(check.name && !strcmp(name, check.name))
3324 ((void (*)(void *, void *))(void *)prop.Set)(control, check.instance);
3325 member.variable = false;
3333 for(check = classObject.instances.first; check; check = check.next)
3335 if(check.name && !strcmp(name, check.name))
3337 Property getProperty = eClass_FindProperty(check.instance._class, computed.member.member.string, this.privateModule);
3340 DataValue value { };
3341 GetProperty(getProperty, check.instance, &value);
3342 SetProperty(prop, control, value);
3343 member.variable = false;
3351 // MOVED THIS UP NOW THAT char * IS A NORMAL CLASS
3352 else if(computed.isConstant && computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3354 String temp = new char[strlen(computed.string)+1];
3355 ReadString(temp, computed.string);
3356 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3360 member.variable = true;
3362 FreeExpression(computed);
3367 Expression computed = CopyExpression(member.initializer.exp);
3370 ComputeExpression(computed);
3371 if(computed.isConstant)
3373 if(computed.type == constantExp && (!propertyClass.dataTypeString || strcmp(propertyClass.dataTypeString, "char *"))) //(strcmp(propertyClass.name, "char *") && (strcmp(propertyClass.name, "String"))))
3375 if(!strcmp(propertyClass.dataTypeString, "float"))
3376 ((void (*)(void *, float))(void *)prop.Set)(control, (float)strtod(computed.constant, null));
3377 else if(!strcmp(propertyClass.dataTypeString, "double"))
3378 ((void (*)(void *, double))(void *)prop.Set)(control, strtod(computed.constant, null));
3380 ((void (*)(void *, int))(void *)prop.Set)(control, strtol(computed.constant, null, 0));
3382 else if(computed.type == stringExp && propertyClass.dataTypeString && strstr(propertyClass.dataTypeString, "char *"))
3384 String temp = new char[strlen(computed.string)+1];
3385 ReadString(temp, computed.string);
3386 ((void (*)(void *, void *))(void *)prop.Set)(control, temp);
3391 member.variable = true;
3393 FreeExpression(computed);
3399 member.variable = true;
3401 else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
3402 member.initializer.exp.type == memberExp) // identifierExp
3404 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
3405 if(method && method.type == virtualMethod)
3408 // Maintain a list in FunctionDefinition of who is attached to it
3409 for(def = _class.definitions->first; def; def = def.next)
3411 if(def.type == functionClassDef)
3413 ClassFunction function = def.function;
3414 Identifier id = (member.initializer.exp.type == memberExp) ? member.initializer.exp.member.member : member.initializer.exp.identifier;
3415 if(function.declarator && !strcmp(function.declarator.symbol.string, id.string))
3417 function.attached.Add(OldLink { data = method });
3418 // Reference this particular instance?
3433 designer.PostCreateObject(object.instance, object, false, classObject.instance);
3444 //designer.CreateObject(instance, classObject, true, null);
3445 //sheet.AddObject(classObject, classObject.name ? classObject.name : _class._class.name, classType, false);
3447 designer.PostCreateObject(instance, classObject, true, null);
3449 //instance.state = Hidden;
3450 //instance.Create();
3451 //instance.SetState(Normal, true, 0);
3460 printf("Class/Instance Processing took %.3f seconds\n", GetTime() - startTime);
3464 // Restore Selection
3465 if(selectedClassName)
3468 for(oClass = classes.first; oClass; oClass = oClass.next)
3470 if(!strcmp(oClass.name, selectedClassName))
3472 this.oClass = oClass;
3476 delete selectedClassName;
3485 for(check = this.oClass.instances.first; check; check = check.next)
3487 if(check.name && !strcmp(check.name, selectedName))
3489 this.selected = check;
3495 if(this.oClass.instances.first)
3496 this.selected = this.oClass.instances.first;
3498 this.selected = this.oClass;
3501 else if(selectedPos == -1 || !this.oClass.instances.count)
3502 this.selected = this.oClass;
3508 if(selectedPos > this.oClass.instances.count)
3510 for(check = this.oClass.instances.first; check; check = check.next)
3512 if(selectedPos == pos++)
3514 this.selected = check;
3522 this.oClass = classes.first;
3523 this.selected = (this.oClass && this.oClass.instances.first) ? this.oClass.instances.first : this.oClass;
3525 delete selectedName;
3526 SetSymbolsDir(null);
3528 if(sheet.codeEditor == this)
3529 sheet.SelectObject(selected);
3532 codeModified = false;
3534 // TESTING THIS TO NOT GET EMPTY PARAMETERS
3537 InvokeParameters(false, false, false);
3540 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
3546 ChangeWorkingDir(oldWorkDir);
3548 printf("Total FindClass time is %.3f seconds, out of which %.3f is in Ignore NS\n\n", findClassTotalTime, findClassIgnoreNSTotalTime);
3549 printf("Total CheckType time is %.3f seconds\n\n", checkTypeTotalTime);
3550 printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
3551 printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
3552 // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
3554 printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
3556 if(inUseDebug && ide.projectView)
3557 ide.debugger.EvaluateWatches();
3562 void UpdateInstanceCodeClass(Class _class, ObjectInfo object, EditBoxStream f, Instance test, bool * prev, bool * lastIsMethod, DataMember * curMember, Class * curClass)
3565 Window control = (Window)object.instance;
3566 ObjectInfo classObject = object.oClass;
3568 if(_class.base && _class.base.type != systemClass) UpdateInstanceCodeClass(_class.base, object, f, test, prev, lastIsMethod, curMember, curClass);
3570 if(!strcmp(_class.name, "DesignerBase")) return;
3572 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
3574 Property prop = eClass_FindProperty(object.instance._class, propIt.name, privateModule);
3575 if(prop && prop.isProperty && !prop.conversion && eClass_FindProperty(object.instance._class, prop.name, privateModule))
3577 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(object, prop.name) &&
3578 prop.compiled && (!prop.IsSet || prop.IsSet(control)))
3580 Class dataType = prop.dataTypeClass;
3582 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
3586 if(dataType.type == structClass)
3588 void * dataForm = new0 byte[dataType.structSize];
3589 void * dataTest = new0 byte[dataType.structSize];
3591 ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
3592 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
3594 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3596 char tempString[1024] = "";
3598 bool needClass = true;
3602 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3604 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3606 eClass_FindNextMember(_class, curClass, curMember, null, null);
3607 if(*curMember != (DataMember)prop)
3608 f.Printf("%s = ", prop.name);
3610 *curMember = (DataMember)prop;
3611 *curClass = curMember->_class;
3614 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3616 f.Printf("%s", string);
3623 else if(dataType.type == normalClass || dataType.type == noHeadClass)
3625 void * dataForm, * dataTest;
3627 dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
3628 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
3630 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
3632 char tempString[1024] = "";
3637 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
3639 eClass_FindNextMember(_class, curClass, curMember, null, null);
3640 if(*curMember != (DataMember)prop)
3641 f.Printf("%s = ", prop.name);
3642 *curMember = (DataMember)prop;
3643 *curClass = curMember->_class;
3645 if(eClass_GetDesigner(dataType))
3647 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
3648 //if(!strcmp(classObject.instance._class.name, dataType.name) && classObject.instance == dataForm)
3649 f.Printf("this", prop.name);
3652 //ObjectInfo classObject;
3653 //for(classObject = classes.first; classObject; classObject = classObject.next)
3657 for(object = classObject.instances.first; object; object = object.next)
3659 if(!object.deleted && eClass_IsDerived(object.instance._class, dataType) && object.instance == dataForm && object.name)
3661 f.Printf("%s", object.name);
3668 bool needClass = true;
3669 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3670 f.Printf("%s", string);
3677 bool needClass = true;
3678 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
3680 if(!strcmp(dataType.dataTypeString, "char *"))
3683 OutputString(f, string);
3687 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3689 f.Printf("%s", string);
3692 *lastIsMethod = false;
3697 DataValue dataForm, dataTest;
3699 GetProperty(prop, control, &dataForm);
3700 GetProperty(prop, test, &dataTest);
3702 if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
3705 char tempString[1024] = "";
3706 SetProperty(prop, test, dataForm);
3708 if(dataType.type != bitClass)
3710 bool needClass = true;
3712 if(dataType.type == enumClass)
3715 Class enumClass = eSystem_FindClass(privateModule, "enum");
3716 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
3718 for(value = e.values.first; value; value = value.next)
3720 if((int)value.data == dataForm.i)
3722 string = value.name;
3728 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
3730 if(string && string[0])
3735 eClass_FindNextMember(_class, curClass, curMember, null, null);
3736 if(*curMember != (DataMember)prop)
3737 f.Printf("%s = ", prop.name);
3738 *curMember = (DataMember)prop;
3739 *curClass = curMember->_class;
3741 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
3742 f.Printf("%sf", string);
3744 f.Printf("%s", string);
3748 else if(dataType.type == bitClass)
3750 bool needClass = true;
3752 if(*prev) f.Printf(", ");
3754 eClass_FindNextMember(_class, curClass, curMember, null, null);
3755 if(*curMember != (DataMember)prop)
3756 f.Printf("%s = ", prop.name);
3757 *curMember = (DataMember)prop;
3758 *curClass = curMember->_class;
3760 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm.ui, tempString, null, &needClass);
3762 f.Printf("%c %s %c", /*dataType.name, */OpenBracket, string, CloseBracket);
3764 f.Printf("%s", string);
3766 *lastIsMethod = false;
3776 int UpdateInstanceCode(EditBoxStream f, int position, Class regClass, ObjectInfo object, bool * firstObject, char ** text, int * textSize, int movedFuncIdLen, int movedFuncIdPos)
3778 Instantiation inst = object.instCode;
3779 Window control = (Window)object.instance;
3781 bool methodPresent = false;
3783 bool lastIsMethod = true;
3784 ObjectInfo classObject = object.oClass;
3790 // Instance removed, delete it
3791 DeleteJunkBefore(f, inst.loc.start.pos, &position);
3793 f.DeleteBytes(inst.loc.end.pos - inst.loc.start.pos + 1);
3794 position = inst.loc.end.pos + 1;
3798 bool multiLine = false;
3801 // Check if it's an unnamed instance
3804 f.Seek(inst.nameLoc.start.pos - position, current);
3805 f.DeleteBytes(inst.nameLoc.end.pos - inst.nameLoc.start.pos);
3806 position = inst.nameLoc.end.pos;
3808 f.Printf(object.name);
3813 if(isspace(ch) && ch != '\n')
3815 f.Seek(-1, current);
3823 int pos = inst.loc.start.pos; // + strlen(inst._class.name);
3825 f.Seek(pos - position, current);
3830 f.Seek(-1, current);
3839 f.Puts(object.name);
3844 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3845 methodPresent = true;
3853 if(ch == OpenBracket)
3859 // TODO: Simplify this?
3868 f.Seek(-1, current);
3880 if(ch == '\n') { toDelete = count; count = 0; }
3881 else if(isspace(ch)) count++;
3884 f.Seek(-1, current);
3888 toDelete += count - 6;
3898 f.Seek(-toDelete-count, current);
3899 f.DeleteBytes(toDelete);
3900 f.Seek(count, current);
3905 for(c = 0; c<toAdd; c++)
3911 methodPresent = multiLine;
3914 f.Printf(methodPresent ? "\n " : " ");
3920 // Instance not there, create a brand new one
3921 DeleteJunkBefore(f, position, &position);
3922 f.Printf(*firstObject ? "\n\n" : "\n");
3923 *firstObject = false;
3925 if((this.methodAction == actionAddMethod || this.moveAttached) && this.selected == object)
3926 methodPresent = true;
3931 f.Printf(" %s %s\n %c\n ", control._class.name, object.name, OpenBracket);
3933 f.Printf(" %s\n %c\n ", control._class.name, OpenBracket);
3938 f.Printf(" %s %s %c ", control._class.name, object.name, OpenBracket);
3940 f.Printf(" %s %c ", control._class.name, OpenBracket);
3946 Instance test = eInstance_New(control._class);
3947 DataMember curMember = null;
3948 Class curClass = null;
3951 UpdateInstanceCodeClass(control._class, object, f, test, &prev, &lastIsMethod, &curMember, &curClass);
3955 // Attach Method here
3956 if((this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod) && !this.moveAttached && this.selected == object)
3958 if(prev) f.Printf(", ");
3959 f.Printf("%s = %s", this.method.name, function.declarator.symbol.string);
3964 if(inst && !object.deleted)
3966 MembersInit members;
3967 Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
3969 DeleteJunkBefore(f, position, &position);
3971 // Instance already there, clear out the properties
3972 for(members = inst.members->first; members; members = members.next)
3974 if(members.type == dataMembersInit)
3978 if(members.dataMembers)
3980 bool keptMember = false;
3981 MemberInit lastKept = null;
3983 for(member = members.dataMembers->first; member; member = member.next)
3985 Identifier ident = member.identifiers ? member.identifiers->first : null;
3986 bool deleted = false;
3988 // For now delete if it's not a method
3989 if(!member.variable) // && ident)
3991 if(!ident || !ident.next)
3993 Property prop = ident ? eClass_FindProperty(instClass, ident.string, this.privateModule) : null;
3996 f.Seek(member.loc.start.pos - position, current);
3997 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
3998 position = member.loc.end.pos;
4003 Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
4004 if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
4005 member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4007 if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
4008 (this.methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, member.initializer.exp.identifier.string)))
4010 f.Seek(member.loc.start.pos - position, current);
4011 f.DeleteBytes(member.loc.end.pos - member.loc.start.pos);
4012 position = member.loc.end.pos;
4024 //f.Seek(member.loc.start.pos - position, current);
4025 //position = member.loc.start.pos;
4026 DeleteJunkBefore(f, member.loc.start.pos, &position);
4027 if(prev) f.Printf(", ");
4028 else if(keptMember) f.Printf(" ");
4033 if(!keptMember || !members.next)
4038 if(keptMember && lastKept != members.dataMembers->last)
4043 f.Seek(-1, current);
4049 f.Seek(-1, current);
4052 else if(!isspace(ch))
4054 f.Seek(-2, current);
4059 f.DeleteBytes(count);
4062 f.Seek(members.loc.end.pos - position, current);
4067 f.Seek(-1, current);
4069 position = members.loc.end.pos + 1;
4073 f.Seek(-1, current);
4074 position = members.loc.end.pos;
4080 lastIsMethod = false;
4085 DeleteJunkBefore(f, position, &position);
4088 if(lastKept != members.dataMembers->last)
4093 f.Seek(-1, current);
4099 f.Seek(-1, current);
4102 else if(!isspace(ch))
4104 f.Seek(-2, current);
4109 f.DeleteBytes(count);
4113 f.Seek(members.loc.end.pos - position, current);
4114 position = members.loc.end.pos;
4118 lastIsMethod = true;
4121 lastIsMethod = false;
4127 f.Seek(members.loc.end.pos - position, current);
4128 position = members.loc.end.pos;
4130 lastIsMethod = true;
4133 else if(members.type == methodMembersInit)
4135 if(this.methodAction == actionDeleteMethod && members.function == function);
4137 methodPresent = true;
4139 // Delete instance method here
4140 if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
4141 members.function == function)
4143 if(this.moveAttached && !*text)
4144 GetLocText(editBox, f, position, &function.loc, text, textSize, Max((int)strlen(this.methodName) - movedFuncIdLen,0), 0);
4146 DeleteJunkBefore(f, members.loc.start.pos, &position);
4147 f.DeleteBytes(members.loc.end.pos - members.loc.start.pos + 1);
4148 position = members.loc.end.pos + 1;
4153 DeleteJunkBefore(f, position, &position);
4157 DeleteJunkBefore(f, members.loc.start.pos, &position);
4158 lastIsMethod = true;
4162 f.Seek(members.loc.end.pos - position, current);
4163 position = members.loc.end.pos;
4165 DeleteJunkBefore(f, position, &position);
4174 if((this.methodAction == actionAddMethod || (this.moveAttached && (this.methodAction == actionAttachMethod || this.methodAction == actionReattachMethod))) && this.selected == object)
4176 Method method = this.method;
4177 DeleteJunkBefore(f, position, &position);
4183 if(!method.dataType)
4184 method.dataType = ProcessTypeString(method.dataTypeString, false);
4187 Type dataType = method.dataType;
4188 Type returnType = dataType.returnType;
4191 if(this.moveAttached)
4193 // Move function here:
4194 int newLen = strlen(method.name);
4199 GetLocText(editBox, f, position, &function.loc, text, textSize, Max(newLen - movedFuncIdLen, 0), 3);
4201 // First change name of function
4202 memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
4203 *textSize += newLen - movedFuncIdLen;
4204 memcpy(*text + movedFuncIdPos, method.name, newLen);
4206 // Second, tab right
4209 for(c = 0; (*text)[c]; )
4212 for(i = c; (*text)[i] && (*text)[i] != '\n'; i++);
4215 memmove((*text)+c+3, (*text)+c, *textSize+1-c);
4216 (*text)[c] = (*text)[c+1] = (*text)[c+2] = ' ';
4220 for(; (*text)[c] && (*text)[c] != '\n'; c++);
4230 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4232 // ADDING METHOD HERE
4234 OutputType(f, returnType, false);
4237 if(dataType.thisClass)
4239 if(!eClass_IsDerived(regClass, dataType.thisClass.registered) && !dataType.classObjectType) // Just fixed this... was backwards.
4241 if(dataType.thisClass.shortName)
4242 f.Printf(dataType.thisClass.shortName);
4244 f.Printf(dataType.thisClass.string);
4248 f.Printf(method.name);
4250 for(param = dataType.params.first; param; param = param.next)
4252 OutputType(f, param, true);
4257 f.Printf(" %c\n\n", OpenBracket);
4259 if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4261 if(returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4262 f.Printf(" return true;\n");
4263 else if(returnType.kind != voidType)
4264 f.Printf(" return 0;\n");
4269 if(returnType.kind != voidType)
4270 f.Printf("return ");
4271 f.Printf("%s::%s(", control._class.name, method.name);
4272 for(param = dataType.params.first; param; param = param.next)
4274 if(param.prev) f.Printf(", ");
4275 if(param.kind != voidType)
4276 f.Printf(param.name);
4280 f.Printf(" %c\n", CloseBracket);
4286 if(!object.instCode)
4289 f.Printf(" %c;\n", CloseBracket);
4291 f.Printf("%c;\n", CloseBracket);
4293 else if(!object.deleted)
4295 // Turn this into a multiline instance when adding a method
4296 DeleteJunkBefore(f, inst.loc.end.pos-1, &position);
4298 f.Printf(methodPresent ? "\n " : " ");
4300 f.Seek(inst.loc.end.pos + 1 - position, current);
4301 position = inst.loc.end.pos + 1;
4306 void OutputClassProperties(Class _class, ObjectInfo classObject, EditBoxStream f, Instance test)
4309 Class regClass = eSystem_FindClass(privateModule, classObject.name);
4311 if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
4313 for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
4315 Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
4316 if(prop && prop.isProperty && !prop.conversion)
4318 if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
4319 (!prop.IsSet || prop.IsSet(classObject.instance)))
4321 Class dataType = prop.dataTypeClass;
4322 char tempString[1024] = "";
4324 bool specify = false;
4327 member = eClass_FindDataMember(regClass, prop.name, privateModule, null, null);
4328 if(member && member._class == regClass)
4332 dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
4334 if(dataType && dataType.type == structClass)
4336 void * dataForm = new0 byte[dataType.structSize];
4337 void * dataTest = new0 byte[dataType.structSize];
4339 ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
4340 ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
4342 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4344 bool needClass = true;
4346 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4347 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4349 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4351 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4356 else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
4358 void * dataForm, * dataTest;
4360 dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
4361 dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
4363 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
4365 char tempString[1024] = "";
4367 ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
4369 if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
4371 // Shouldn't go here ...
4372 f.Printf("\n %s%s = this;", specify ? "property::" : "", prop.name);
4376 bool needClass = true;
4378 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
4380 if(!strcmp(dataType.dataTypeString, "char *"))
4382 f.Printf("\n %s%s = \"", specify ? "property::" : "", prop.name);
4383 OutputString(f, string);
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);
4395 DataValue dataForm, dataTest;
4397 GetProperty(prop, classObject.instance, &dataForm);
4398 GetProperty(prop, test, &dataTest);
4400 if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
4402 SetProperty(prop, test, dataForm);
4403 if(dataType.type == bitClass)
4405 bool needClass = true;
4406 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4408 f.Printf("\n %s%s = %c %s %c;", specify ? "property::" : "", prop.name, /*dataType.name, */OpenBracket, string, CloseBracket);
4410 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4414 bool needClass = true;
4415 if(dataType.type == enumClass)
4418 Class enumClass = eSystem_FindClass(privateModule, "enum");
4419 EnumClassData e = ACCESS_CLASSDATA(dataType, enumClass);
4421 for(value = e.values.first; value; value = value.next)
4423 if((int)value.data == dataForm.i)
4425 string = value.name;
4431 string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
4432 if(!strcmp(dataType.dataTypeString, "float") && strchr(string, '.'))
4433 f.Printf("\n %s%s = %sf;", specify ? "property::" : "", prop.name, string);
4435 f.Printf("\n %s%s = %s;", specify ? "property::" : "", prop.name, string);
4444 void UpdateFormCode()
4447 if(!parsing) return;
4454 else if(formModified)
4456 EditBoxStream f { editBox = editBox };
4460 Identifier movedFuncId;
4461 int movedFuncIdLen = 0, movedFuncIdPos = 0;
4462 ObjectInfo classObject;
4468 movedFuncId = GetDeclId(function.declarator);
4469 movedFuncIdLen = movedFuncId.loc.end.pos - movedFuncId.loc.start.pos;
4470 movedFuncIdPos = movedFuncId.loc.start.pos - function.loc.start.pos;
4473 for(classObject = classes.first; classObject; classObject = classObject.next)
4476 ClassDefinition classDef = classObject.classDefinition;
4477 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
4480 bool firstObject = true;
4481 ObjectInfo object = classObject.instances.first;
4482 bool lastIsDecl = false;
4484 if(!classObject.modified) continue;
4486 test = eInstance_New(regClass);
4489 // Put it in the same desktop window...
4490 designer.PrepareTestObject(test);
4492 //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
4493 //f.Printf("%c\n\n", OpenBracket);
4495 // Change the _class name
4496 f.Seek(classDef.nameLoc.start.pos - position, current);
4497 f.DeleteBytes(classDef.nameLoc.end.pos - classDef.nameLoc.start.pos);
4498 f.Printf(classObject.name);
4499 position = classDef.nameLoc.end.pos;
4502 // Go to block start, delete all until no white space, put \n
4506 f.Seek(classDef.blockStart.end.pos - position, current);
4507 position = classDef.blockStart.end.pos;
4509 for(; f.Getc(&ch); count++)
4513 f.Seek(-1, current);
4523 f.Seek(-count, current);
4525 f.DeleteBytes(count-back);
4527 position += count-back;
4530 // Output properties
4531 OutputClassProperties(classObject.instance._class, classObject, f, test);
4533 for(def = classDef.definitions->first; def; def = def.next)
4537 case defaultPropertiesClassDef:
4539 bool keptMember = false;
4541 MemberInit lastKept = null;
4544 DeleteJunkBefore(f, def.loc.start.pos, &position);
4547 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4549 Identifier ident = propDef.identifiers->first;
4550 bool deleted = false;
4552 // For now delete if it's a prop
4553 if(!propDef.variable && ident)
4557 Property prop = eClass_FindProperty(regClass, ident.string, this.privateModule);
4560 f.Seek(propDef.loc.start.pos - position, current);
4561 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4562 position = propDef.loc.end.pos;
4567 Method method = eClass_FindMethod(regClass, ident.string, this.privateModule);
4568 if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4570 if(((methodAction == actionDetachMethod || methodAction == actionReattachMethod) && method == this.method && selected == classObject) ||
4571 (methodAction == actionDeleteMethod && !strcmp(function.declarator.symbol.string, propDef.initializer.exp.identifier.string)))
4573 f.Seek(propDef.loc.start.pos - position, current);
4574 f.DeleteBytes(propDef.loc.end.pos - propDef.loc.start.pos);
4575 position = propDef.loc.end.pos;
4593 f.Seek(def.loc.end.pos - position - 1, current);
4598 f.Seek(-1, current);
4601 position = def.loc.end.pos;
4605 if(lastKept != def.defProperties->last)
4610 f.Seek(-1, current);
4616 f.Seek(-1, current);
4619 else if(!isspace(ch))
4621 f.Seek(-2, current);
4626 f.DeleteBytes(count);
4630 f.Seek(def.loc.end.pos - position, current);
4631 position = def.loc.end.pos;
4636 case declarationClassDef:
4638 Declaration decl = def.decl;
4640 if(decl.type == instDeclaration)
4642 if(def.object/* && ((ObjectInfo)def.object).modified*/)
4644 while(def.object && object != def.object)
4646 if(object /*&& ((ObjectInfo)def.object).modified*/)
4647 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4648 object = object.next;
4651 DeleteJunkBefore(f, def.loc.start.pos, &position);
4652 f.Printf(firstObject ? "\n\n " : "\n ");
4653 firstObject = false;
4655 if(def.object && ((ObjectInfo)def.object).modified)
4656 position = UpdateInstanceCode(f, position, regClass, def.object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4658 object = object ? object.next : null;
4662 DeleteJunkBefore(f, def.loc.start.pos, &position);
4663 f.Printf(firstObject ? "\n\n " : "\n ");
4664 firstObject = false;
4670 DeleteJunkBefore(f, def.loc.start.pos, &position);
4671 f.Printf(lastIsDecl ? "\n " : "\n\n ");
4676 case functionClassDef:
4678 // TESTING IF THIS IS GOOD ENOUGH FOR GENERATED FUNCTION...
4679 if(!def.function.body) continue;
4683 DeleteJunkBefore(f, def.loc.start.pos, &position);
4686 // Delete _class methods
4687 if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
4688 def.function == function)
4693 if(moveAttached && !text)
4695 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max((int)strlen(methodName) - movedFuncIdLen,0), 3);
4698 f.Seek(def.loc.end.pos - position, current);
4699 for(; f.Getc(&ch); count++)
4703 f.Seek(-1, current);
4707 f.Seek(def.loc.start.pos - def.loc.end.pos - count, current);
4709 f.DeleteBytes(def.loc.end.pos - def.loc.start.pos + count);
4710 position = def.loc.end.pos + count;
4713 // In case of detaching methods in the _class, simply rename the method
4714 if(methodAction == actionDetachMethod && moveAttached && selected == classObject && function == def.function)
4716 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4717 f.DeleteBytes(movedFuncIdLen);
4719 position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
4722 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
4723 function == def.function)
4725 // In case of attaching methods in the _class, simply rename the method
4726 f.Seek(function.loc.start.pos + movedFuncIdPos - position, current);
4727 position = function.loc.start.pos + movedFuncIdPos;
4728 f.DeleteBytes(movedFuncIdLen);
4729 if(method.dataType.thisClass)
4730 f.Printf("%s::", method.dataType.thisClass.string);
4731 f.Puts(method.name);
4732 position += movedFuncIdLen;
4737 DeleteJunkBefore(f, def.loc.start.pos, &position);
4738 if(def.type == memberAccessClassDef)
4741 firstObject = false;
4751 f.Seek(def.loc.end.pos - position, current);
4752 position = def.loc.end.pos;
4755 // Output attached methods
4756 if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && !moveAttached)
4758 DeleteJunkBefore(f, position, &position);
4759 f.Printf("\n %s = %s;\n", method.name, function.declarator.symbol.string);
4762 // ********** INSTANCES ***************
4763 for(; object; object = object.next)
4765 if(!object.instCode)
4767 position = UpdateInstanceCode(f, position, regClass, object, &firstObject, &text, &textSize, movedFuncIdLen, movedFuncIdPos);
4771 DeleteJunkBefore(f, position, &position);
4773 // ****************** METHODS ***********************
4774 if(methodAction == actionDetachMethod && moveAttached && classObject == oClass)
4776 // If detaching an instance method
4777 if(selected != classObject)
4779 int newLen = strlen(methodName);
4782 GetLocText(editBox, f, position, &function.loc, &text, &textSize, Max(newLen - movedFuncIdLen,0), 0);
4783 // Tab selection left
4786 for(c = 0; text[c]; )
4789 for(i = 0; i<3 && text[c] == ' '; i++, c++);
4790 memmove(text+start, text+start+i, textSize+1-start-i);
4793 for(; text[c] && text[c] != '\n'; c++);
4799 memmove(text + movedFuncIdPos + newLen, text + movedFuncIdPos + movedFuncIdLen, textSize - movedFuncIdPos - movedFuncIdLen + 1);
4800 textSize += newLen - movedFuncIdLen;
4801 memcpy(text + movedFuncIdPos, methodName, newLen);
4808 if(methodAction == actionAddMethod && selected == classObject)
4810 Method method = this.method;
4812 if(!method.dataType)
4813 method.dataType = ProcessTypeString(method.dataTypeString, false);
4815 // ADDING METHOD HERE
4817 Type dataType = method.dataType;
4818 Type returnType = dataType.returnType;
4820 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
4824 OutputType(f, returnType, false);
4827 if(dataType.thisClass && !dataType.classObjectType)
4829 if(dataType.thisClass.shortName)
4830 f.Printf(dataType.thisClass.shortName);
4832 f.Printf(dataType.thisClass.string);
4835 f.Printf(method.name);
4837 for(param = dataType.params.first; param; param = param.next)
4839 OutputType(f, param, true);
4844 f.Printf(" %c\n\n", OpenBracket);
4846 if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
4848 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
4849 f.Printf(" return true;\n");
4850 else if(returnType && returnType.kind != voidType)
4851 f.Printf(" return 0;\n");
4856 if(returnType.kind != voidType)
4857 f.Printf("return ");
4859 char * name = ((Specifier)classDef.baseSpecs->first).name;
4860 Symbol _class = FindClass(name);
4861 f.Printf("%s::%s(", (_class && _class.registered) ? _class.registered.name : name, method.name);
4863 for(param = dataType.params.first; param; param = param.next)
4865 if(param.prev) f.Printf(", ");
4866 if(param.kind != voidType)
4867 f.Printf(param.name);
4872 f.Printf(" %c", CloseBracket);
4876 DeleteJunkBefore(f, classDef.loc.end.pos-1, &position);
4888 // TOFIX: Patch for a glitch where clicking at the end of the view seems one line off. No idea what could be going on?
4889 editBox.OnVScroll(setRange, editBox.scroll.y, 0);
4893 codeModified = false;
4894 formModified = false;
4896 moveAttached = false;
4901 int FindMethod(char * methodName /*Method method*/, ClassFunction*functionPtr, Location propLoc)
4904 ClassFunction function = null;
4907 ObjectInfo object = this.selected;
4909 if(object && object == this.oClass)
4911 ClassDefinition classDef = object.oClass.classDefinition;
4913 if(classDef && classDef.definitions)
4915 for(def = classDef.definitions->first; def; def = def.next)
4917 if(def.type == functionClassDef && def.function.declarator)
4919 if(!strcmp(def.function.declarator.symbol.string, methodName))
4921 function = def.function;
4926 else if(def.type == defaultPropertiesClassDef)
4930 for(propDef = def.defProperties->first; propDef; propDef = propDef.next)
4932 Identifier ident = propDef.identifiers ? propDef.identifiers->first : null;
4933 if(ident && !ident.next)
4935 if(!strcmp(ident.string, methodName) && propDef.initializer && propDef.initializer.type == expInitializer && propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
4939 propLoc = propDef.loc;
4942 ClassDefinition classDef = object.oClass.classDefinition;
4944 if(classDef.definitions)
4946 for(def = classDef.definitions->first; def; def = def.next)
4948 if(def.type == functionClassDef)
4950 if(!strcmp(def.function.declarator.symbol.string, propDef.initializer.exp.identifier.string))
4952 function = def.function;
4971 Instantiation inst = object.instCode;
4973 // Check here to see if the method already exists, no need to call ModifyCode in that case
4974 if(inst && inst.members)
4976 MembersInit members;
4977 for(members = inst.members->first; members; members = members.next)
4979 switch(members.type)
4981 case dataMembersInit:
4983 if(members.dataMembers)
4986 for(member = members.dataMembers->first; member; member = member.next)
4988 Identifier ident = member.identifiers ? member.identifiers->first : null;
4989 if(ident && !ident.next)
4991 if(!strcmp(ident.string, methodName) && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && member.initializer.exp.type == memberExp /*ExpIdentifier*/)
4995 propLoc = member.loc;
4998 ClassDefinition classDef = object.oClass.classDefinition;
5000 if(classDef.definitions)
5002 for(def = classDef.definitions->first; def; def = def.next)
5004 if(def.type == functionClassDef)
5006 if(def.function.declarator && !strcmp(def.function.declarator.symbol.string, member.initializer.exp.identifier.string))
5008 function = def.function;
5017 // TODO: Fix memory leak
5018 function = ClassFunction
5020 declarator = Declarator { symbol = Symbol { string = CopyString(member.initializer.exp.member.member ? member.initializer.exp.member.member.string : "") } }
5032 case methodMembersInit:
5034 if(members.function.declarator && !strcmp(members.function.declarator.symbol.string, methodName))
5036 function = members.function;
5048 if(functionPtr) *functionPtr = function;
5052 void GoToMethod(char * methodName /*Method method*/)
5056 ObjectInfo object = selected;
5057 EditBoxStream f { editBox = editBox };
5058 ClassFunction function = null;
5059 bool atChar = false;
5063 Location propLoc = { {0,0,-1} };
5066 if(FindMethod(methodName, &function, &propLoc) == 1 && object != this.oClass) indent = 9;
5067 if(function && function.body)
5070 f.Seek(function.body.loc.start.pos+1, current);
5080 f.Seek(-1, current);
5085 else if(!isspace(ch))
5087 f.Seek(-1, current);
5093 else if(propLoc.start.pos > -1)
5095 f.Seek(propLoc.start.pos, current);
5098 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
5100 if(function || propLoc.start.pos > -1)
5102 editBox.SetSelPos(l1, y1, atChar ? x1 : indent, l2, y2, atChar ? x2 : indent);
5103 editBox.CenterOnCursor();
5104 SetState(normal, false, 0);
5107 if(function && function.declarator && function.declarator.symbol && !function.declarator.symbol.type)
5109 FreeClassFunction(function);
5115 void FindCompatibleMethods(Method method, OldList compatible)
5117 ClassDefinition classDef = this.oClass.classDefinition;
5118 if(classDef && classDef.definitions)
5121 Class baseClass = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5124 Symbol classSym { };
5125 Symbol selectedClass;
5126 if(this.selected == this.oClass)
5127 selectedClass = classSym;
5129 selectedClass = FindClass(this.selected.instance._class.name);
5131 regClass.name = classDef._class.name;
5132 regClass.base = eSystem_FindClass(this.privateModule, ((Specifier)classDef.baseSpecs->first).name);
5133 for(def = classDef.definitions->first; def; def = def.next)
5135 if(def.type == functionClassDef && def.function.declarator)
5137 Method vMethod = eClass_FindMethod(baseClass, def.function.declarator.symbol.string, this.privateModule);
5139 vMethod = eClass_FindMethod(this.selected.instance._class, def.function.declarator.symbol.string, this.privateModule);
5142 Type type = def.function.declarator.symbol.type;
5143 if(CheckCompatibleMethod(method, type, regClass, this.selected == this.oClass, FindClass(this.selected.instance._class.name)))
5145 compatible.Add(OldLink { data = def.function });
5151 if(this.oClass && this.oClass.instance)
5153 classSym.registered = regClass;
5154 //classSym.registered = this.oClass.oClass;
5156 for(_class = regClass.base; _class; _class = _class.base)
5159 for(testMethod = (Method)_class.methods.first; testMethod; testMethod = (Method)((BTNode)testMethod).next)
5161 // TODO: Understand why these functions popup in attach list
5162 if(testMethod.type != virtualMethod /*&& testMethod.function != Window_OnGetString && testMethod.function != Window_OnGetDataFromString*/)
5164 if(!testMethod.dataType)
5165 testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
5167 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5168 if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
5169 //if(CheckCompatibleMethod(method, testMethod.dataType, ®Class, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
5171 // TODO: Fix memory leak, Figure out if it should be ClassFunction or FunctionDefinition
5172 // ClassFunction function { };
5173 FunctionDefinition function { };
5175 function.declarator = Declarator { };
5176 function.declarator.symbol = Symbol { string = CopyString(testMethod.name) };
5177 excludedSymbols.Add(function.declarator.symbol);
5179 compatible.Add(OldLink { data = function });
5190 void AddMethod(Method method)
5194 char methodName[1024];
5195 strcpy(methodName, method.name);
5196 if(!FindMethod(methodName, null, null))
5198 methodAction = actionAddMethod;
5199 this.method = method;
5203 GoToMethod(methodName);
5207 void DeleteMethod(ClassFunction function)
5211 methodAction = actionDeleteMethod;
5212 this.function = function;
5220 void AttachMethod(Method method, ClassFunction function)
5224 // If it's an instance we'll ask if we want to move it inside...
5225 if(!function.attached.count && function.body)
5227 // Find the function in the _class to check if it's a virtual function
5228 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5229 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5230 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5232 for(def = this.classDefinition.first; def; def = def.next)
5234 if(def.type == functionClassDef)
5236 if(def.function == function)
5241 if(!method || method.type != virtualMethod)
5244 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5245 if(MessageBox { type = yesNo, master = parent, text = title, contents = $"Method is unused. Move method inside instance?"}.Modal() == yes)
5247 moveAttached = true;
5252 methodAction = actionAttachMethod;
5253 this.method = method;
5254 this.function = function;
5261 void ReAttachMethod(Method method, ClassFunction function)
5265 // If it's an instance we'll ask if we want to move it inside...
5266 if(!function.attached.count && function.body)
5268 // Find the function in the _class to check if it's a virtual function
5269 Class regClass = eSystem_FindClass(this.privateModule, ((Specifier)this.oClass.classDefinition.baseSpecs->first).name);
5270 Method method = eClass_FindMethod(regClass, function.declarator.symbol.string, this.privateModule);
5271 /* LATER we'll need to check for public/virtual properties etc, for now only checked if virtual in base _class
5273 for(def = this.classDefinition.first; def; def = def.next)
5275 if(def.type == functionClassDef)
5277 if(def.function == function)
5282 if(!method || method.type != virtualMethod)
5285 sprintf(title, $"Attach %s", function.declarator.symbol.string);
5286 if(MessageBox { type = yesNo, master = parent, text = title,
5287 contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
5289 moveAttached = true;
5294 methodAction = actionReattachMethod;
5295 this.method = method;
5296 this.function = function;
5303 void DetachMethod(Method method, ClassFunction function, int type)
5311 hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
5312 master = sheet, text = $"Name detached method", background = formColor
5316 dialog, anchor = { horz = 45, top = 30 }, size = { 80 }, text = $"Cancel", hotKey = escape,
5317 id = DialogResult::cancel, NotifyClicked = ButtonCloseDialog
5321 dialog, anchor = { horz = -45, top = 30 }, size = { 80 }, text = $"OK", isDefault = true,
5322 id = DialogResult::ok, NotifyClicked = ButtonCloseDialog
5326 dialog, anchor = { left = 5, right = 5, top = 5 }
5328 sprintf(methodName, "%s_%s", selected.name, method.name);
5329 nameBox.contents = methodName;
5331 result = dialog.Modal() == ok;
5332 strcpy(methodName, nameBox.contents);
5337 // If the method is not attached, move it outside
5340 // Add this class to the methodName
5341 char name[1024] = "";
5343 if(this.selected != this.oClass && !method.dataType.thisClass)
5345 strcat(name, this.selected.instance._class.name);
5347 strcat(name, this.methodName);
5348 strcpy(this.methodName, name);
5350 else if(method.dataType.thisClass && (this.selected == this.oClass || !eClass_IsDerived(this.oClass.instance._class, method.dataType.thisClass.registered)))
5352 strcat(name, method.dataType.thisClass.string);
5354 strcat(name, this.methodName);
5355 strcpy(this.methodName, name);
5358 this.moveAttached = true;
5361 this.methodAction = actionDetachMethod;
5362 this.method = method;
5363 this.function = function;
5370 void AddObject(Instance instance, ObjectInfo * object)
5374 //*object = _class.instances.Add(sizeof(ObjectInfo));
5375 *object = ObjectInfo { };
5376 oClass.instances.Insert((selected.oClass == selected) ? null : selected, *object);
5377 (*object).oClass = oClass;
5378 (*object).instance = instance;
5383 sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
5385 // if(strcmp(name, this.oClass.instance.name))
5388 for(check = oClass.instances.first; check; check = check.next)
5389 if(!check.deleted && check.name && !strcmp(name, check.name))
5393 (*object).name = CopyString(name);
5398 toolBox.controlClass = null;
5402 //sheet.AddObject(*object, (*object).name, TypeData, true);
5407 void EnsureUpToDate()
5409 if(sheet && codeModified && parsing)
5413 void SelectObject(ObjectInfo object)
5416 oClass = object ? object.oClass : null;
5418 designer.SelectObject(object, object ? object.instance : null);
5421 void SelectObjectFromDesigner(ObjectInfo object)
5424 sheet.SelectObject(object);
5427 void EnumerateObjects(Sheet sheet)
5431 for(oClass = classes.first; oClass; oClass = oClass.next)
5437 sheet.AddObject(oClass, oClass.name ? oClass.name : oClass.instance._class.name, typeClass, false);
5438 for(object = oClass.instances.first; object; object = object.next)
5439 sheet.AddObject(object, object.name ? object.name : object.instance._class.name, typeData, false);
5442 sheet.SelectObject(selected);
5447 designer.AddObject();
5450 void DeleteObject(ObjectInfo object)
5452 delete object.instance;
5453 object.deleted = true;
5454 object.modified = true;
5455 object.oClass.modified = true;
5457 if(selected == object)
5459 bool looped = false;
5460 ObjectInfo select = object;
5464 select = select.prev;
5468 select = object.oClass.instances.last;
5475 sheet.SelectObject(select ? select : oClass);
5478 if(!object.instCode && object.oClass != object)
5481 oClass.instances.Delete(object);
5484 if(sheet.codeEditor == this)
5485 sheet.DeleteObject(object);
5488 void RenameObject(ObjectInfo object, char * name)
5492 // Validate the name:
5493 if(object != oClass && (!name || !name[0])) valid = true; // What's this one again?
5494 else if(name[0] && (isalpha(name[0]) || name[0] == '_'))
5497 for(c = 0; name[c]; c++)
5498 if(!isalnum(name[c]) && name[c] != '_' && name[c] != '_')
5506 object.name = (name && name[0]) ? CopyString(name) : null;
5508 sheet.RenameObject(object, object.name ? object.name : object.instance._class.name);
5512 void DesignerModifiedObject()
5514 sheet.ListProperties(false);
5518 void ListSubMembers(Type member)
5522 for(subMember = member.members.first; subMember; subMember = subMember.next)
5526 DataRow row = membersList.AddString(subMember.name);
5527 row.icon = icons[typeData];
5531 ListSubMembers(subMember);
5536 void ListSubDataMembers(DataMember member, bool isPrivate)
5538 DataMember subMember;
5539 for(subMember = member.members.first; subMember; subMember = subMember.next)
5541 if((subMember.memberAccess == publicAccess && !isPrivate) || subMember._class.module == privateModule)
5545 DataRow row = membersList.AddString(subMember.name);
5546 BitmapResource bitmap = null;
5547 if(!subMember.dataType)
5548 subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
5550 if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
5552 char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
5555 bitmap = { bitmapName };
5556 membersList.AddResource(bitmap);
5559 row.icon = bitmap ? bitmap : icons[(subMember.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5563 ListSubDataMembers(subMember, isPrivate || member.memberAccess == privateAccess);
5569 void ListClassMembers(Class whatClass, bool methodsOnly)
5572 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5573 bool isPrivate = false;
5575 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5577 Method method, methodIt;
5579 DataMember memberIt;
5581 for(methodIt = (Method)_class.methods.first; methodIt; methodIt = (Method)((BTNode)methodIt).next)
5583 method = eClass_FindMethod(whatClass, methodIt.name, privateModule);
5584 if(methodIt.memberAccess == privateAccess && method && method.memberAccess == publicAccess)
5586 if(method && method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5588 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5590 DataRow row = membersList.FindString(method.name);
5593 row = membersList.AddString(method.name);
5595 if(!method.dataType)
5596 method.dataType = ProcessTypeString(method.dataTypeString, false);
5598 row.icon = icons[(method.type == virtualMethod && method.dataType && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5606 for(memberIt = _class.membersAndProperties.first; memberIt; memberIt = memberIt.next)
5610 if(memberIt.isProperty)
5612 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5614 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5618 member = eClass_FindDataMember(whatClass, memberIt.name, privateModule, null, null);
5620 member = (DataMember)eClass_FindProperty(whatClass, memberIt.name, privateModule);
5623 if(memberIt.memberAccess == privateAccess && member && member.memberAccess == publicAccess)
5629 if(member && (member.memberAccess == publicAccess || member._class.module == privateModule))
5631 if(member.isProperty)
5633 Property prop = (Property) member;
5634 if(!membersList.FindString(prop.name))
5636 DataRow row = membersList.AddString(prop.name);
5637 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5640 else if(member.name && !membersList.FindString(member.name))
5642 DataRow row = membersList.AddString(member.name);
5644 BitmapResource bitmap = null;
5645 if(!member.dataType)
5646 member.dataType = ProcessTypeString(member.dataTypeString, false);
5648 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5650 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5653 bitmap = { bitmapName };
5654 membersList.AddResource(bitmap);
5657 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5660 ListSubDataMembers(member, member.memberAccess == privateAccess);
5664 if(_class.inheritanceAccess == privateAccess)
5667 if(_class.module != privateModule) break;
5672 void ListClassMembersMatch(Class whatClass, Type methodType)
5675 Class baseClass = eSystem_FindClass(this.privateModule, "class");
5676 bool isPrivate = false;
5678 for(_class = whatClass; _class && _class.type != systemClass; _class = _class.base)
5684 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5686 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5688 if(method._class.type != systemClass && !eClass_FindMethod(baseClass, method.name, this.privateModule))
5690 if(!method.dataType)
5691 method.dataType = ProcessTypeString(method.dataTypeString, false);
5693 if(MatchTypes(method.dataType, methodType, null, whatClass, /*null, */whatClass, false, true, false, false))
5695 DataRow row = membersList.FindString(method.name);
5698 row = membersList.AddString(method.name);
5699 row.icon = icons[(method.type == virtualMethod && method.dataType.thisClass) ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5705 if(_class.inheritanceAccess == privateAccess)
5708 if(_class.module != privateModule) break;
5713 void ListClassPropertiesAndVirtual(Class whatClass, String curString)
5716 bool isPrivate = false;
5717 for(_class = whatClass; _class /*&& _class.type != systemClass*/; _class = _class.base)
5723 for(method = (Method)_class.methods.first; method; method = (Method)((BTNode)method).next)
5725 if(method.type == virtualMethod)
5727 if(method.memberAccess == publicAccess || method._class.module == privateModule)
5729 DataRow row = membersList.FindString(method.name);
5732 row = membersList.AddString(method.name);
5734 if(!method.dataType)
5735 method.dataType = ProcessTypeString(method.dataTypeString, false);
5737 row.icon = icons[method.dataType.thisClass ? typeEvent : ((method.memberAccess == publicAccess && !isPrivate) ? typeMethod : typeMethodPrivate)];
5743 for(member = _class.membersAndProperties.first; member; member = member.next)
5745 if(member.memberAccess == publicAccess || member._class.module == privateModule)
5747 if(member.isProperty)
5749 Property prop = (Property)member;
5751 DataRow row = membersList.AddString(prop.name);
5752 row.icon = icons[(member.memberAccess == publicAccess && !isPrivate) ? typeProperty : typePropertyPrivate];
5755 else if(member.name && (!curString || strcmp(curString, member.name)))
5757 DataRow row = membersList.AddString(member.name);
5759 BitmapResource bitmap = null;
5760 if(!member.dataType)
5761 member.dataType = ProcessTypeString(member.dataTypeString, false);
5763 if(member.dataType && member.dataType.kind == classType && member.dataType._class)
5765 char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
5768 bitmap = { bitmapName };
5769 membersList.AddResource(bitmap);
5772 row.icon = bitmap ? bitmap : icons[(member.memberAccess == publicAccess && !isPrivate) ? typeData : typeDataPrivate];
5775 ListSubDataMembers(member, member.memberAccess == privateAccess || isPrivate);
5778 if(_class.inheritanceAccess == privateAccess)
5781 if(_class.module != privateModule) break;
5786 void ListMembers(Type type)
5788 if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
5792 if(type.kind == classType)
5795 ListClassMembers(type._class.registered, false);
5800 for(member = type.members.first; member; member = member.next)
5804 DataRow row = membersList.AddString(member.name);
5805 row.icon = icons[typeData];
5807 else if(member.kind == structType || member.kind == unionType)
5808 ListSubMembers(member);
5814 void ListModule(Module mainModule, int recurse, bool listClasses)
5817 ListNameSpace(mainModule.application.systemNameSpace, 1, listClasses);
5818 ListNameSpace(mainModule.application.privateNameSpace, 1, listClasses);
5819 ListNameSpace(mainModule.application.publicNameSpace, 1, listClasses);
5820 for(module = mainModule.application.allModules.first; module; module = module.next)
5822 if(ModuleVisibility(mainModule, module))
5823 ListNameSpace(module.publicNameSpace, recurse, listClasses);
5827 void ListNameSpace(NameSpace nameSpace, int recurse, bool listClasses)
5834 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5836 Class _class = link.data;
5837 if(_class.type != systemClass && !_class.templateClass) // Omit templatized classes
5839 DataRow row = membersList.AddString(_class.name);
5840 row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
5845 for(link = (BTNamedLink)nameSpace.defines.first; link; link = (BTNamedLink)((BTNode)link).next )
5847 DefinedExpression definedExp = link.data;
5848 DataRow row = membersList.AddString(link /*definedExp*/.name);
5849 row.icon = icons[typeData];
5852 for(link = (BTNamedLink)nameSpace.functions.first; link; link = (BTNamedLink)((BTNode)link).next)
5854 GlobalFunction function = link.data;
5855 DataRow row = membersList.AddString(link /*function*/.name);
5856 row.icon = icons[typeMethod];
5860 for(ns = (NameSpace *)nameSpace.nameSpaces.first; ns; ns = (NameSpace *)((BTNode)ns).next)
5862 if(recurse != 2 && listClasses)
5864 if(!membersList.FindString(ns->name))
5866 DataRow row = membersList.AddString(ns->name);
5867 row.icon = icons[typeNameSpace];
5872 ListNameSpace(ns, 2, listClasses);
5876 void ListEnumValues(Class _class)
5878 List<Class> classes { };
5879 for(; _class && _class.type == enumClass; _class = _class.base)
5880 classes.Insert(null, _class);
5881 for(_class : classes)
5883 EnumClassData enumeration = (EnumClassData)_class.data;
5885 for(item = enumeration.values.first; item; item = item.next)
5887 DataRow row = membersList.AddString(item.name);
5888 row.icon = icons[typeEnumValue];
5894 bool ListEnumsModule(Module mainModule, Type dest)
5896 bool result = false;
5898 result |= ListEnums(mainModule.application.systemNameSpace, dest);
5899 result |= ListEnums(mainModule.application.privateNameSpace, dest);
5900 result |= ListEnums(mainModule.application.publicNameSpace, dest);
5901 for(module = mainModule.application.allModules.first; module; module = module.next)
5903 if(ModuleVisibility(mainModule, module))
5904 result |= ListEnums(module.publicNameSpace, dest);
5909 void ListNameSpaceByString(Module mainModule, char * string)
5911 NameSpace * nameSpace;
5913 nameSpace = FindNameSpace(mainModule.application.systemNameSpace, string);
5914 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5915 nameSpace = FindNameSpace(mainModule.application.privateNameSpace, string);
5916 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5917 nameSpace = FindNameSpace(mainModule.application.publicNameSpace, string);
5918 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5919 for(module = mainModule.application.allModules.first; module; module = module.next)
5921 if(ModuleVisibility(mainModule, module))
5923 nameSpace = FindNameSpace(module.publicNameSpace, string);
5924 if(nameSpace) ListNameSpace(nameSpace, 0, true);
5929 bool ListEnums(NameSpace nameSpace, Type dest)
5932 bool result = false;
5934 for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
5936 Class _class = link.data;
5937 if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *"))) && !dest.classObjectType)) &&
5938 dest.kind != pointerType && dest.kind != ellipsisType)
5940 OldList conversions { };
5942 type.kind = classType;
5943 type._class = FindClass(_class.name);
5944 if(MatchTypes(type, dest, &conversions, null, null, true, false, false, false))
5946 ListEnumValues(_class);
5949 conversions.Free(null);
5953 for(nameSpace = (NameSpace *)nameSpace.nameSpaces.first; nameSpace != null; nameSpace = (NameSpace *)((BTNode)nameSpace).next)
5955 result |= ListEnums(nameSpace, dest);
5960 NameSpace * FindNameSpace(NameSpace nameSpace, char * name)
5964 for(c = 0; (ch = name[c]); c++)
5966 if(ch == '.' || (ch == ':' && name[c+1] == ':'))
5968 NameSpace * newSpace;
5969 char * spaceName = new char[c - start + 1];
5970 memcpy(spaceName, name + start, c - start);
5971 spaceName[c-start] = '\0';
5972 newSpace = (NameSpace *)nameSpace.nameSpaces.FindString(spaceName);
5976 nameSpace = newSpace;
5985 return (NameSpace *)nameSpace;
5988 void ListSymbols(Expression exp, bool enumOnly, char * string, Identifier realIdentifier)
5990 bool listedEnums = false;
5991 Type destType = (exp && exp.destType && !exp.destType.truth) ? exp.destType : null;
5992 bool listClasses = true;
5994 if(exp && (exp.type == identifierExp || exp.type == memberExp))
5996 // TOCHECK: This memberExp check wasn't here... Some stuff isn't quite done
5997 Identifier id = (exp.type == memberExp) ? exp.member.member : exp.identifier;
5998 char * colons = id ? RSearchString(id.string, "::", strlen(id.string), true, false) : null;
6000 if(exp.type == identifierExp)
6001 id = realIdentifier;
6003 if(id && id._class && !id._class.name)
6005 listClasses = false;
6008 else if(id && id._class && id._class.name)
6012 Class _class = id.classSym.registered;
6013 if(_class && _class.type == enumClass)
6015 ListEnumValues(_class);
6018 ListClassMembers(id.classSym.registered, true);
6023 else if(id && colons)
6025 ListNameSpaceByString(this.privateModule, id.string);
6030 if(this.privateModule && destType && (destType.kind != pointerType || destType.type.kind != voidType) && destType.kind != ellipsisType)
6032 listedEnums = ListEnumsModule(this.privateModule, destType);
6035 if(destType && destType.kind == classType && destType._class.registered && destType._class.registered.type == enumClass)
6037 ListEnumValues(destType._class.registered);
6040 ListClassPropertiesAndVirtual(insideClass, null);
6044 else if(destType && destType.kind == enumType)
6048 for(value = destType.members.first; value; value = value.next)
6050 DataRow row = membersList.AddString(value.name);
6051 row.icon = icons[typeEnumValue];
6055 ListClassPropertiesAndVirtual(insideClass, null);
6059 else if(insideClass && !enumOnly)
6061 ListClassPropertiesAndVirtual(insideClass, string);
6064 if(listedEnums && string && string[0])
6066 DataRow row = membersList.FindSubString(string);
6068 listedEnums = false;
6071 if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
6073 ListClassMembersMatch(GetThisClass(), exp.destType);
6075 else if(!insideClass && !enumOnly && !listedEnums)
6078 Symbol symbol = null;
6082 ListClassMembers(GetThisClass(), false);
6085 for(ctx = listClasses ? GetCurrentContext() : GetTopContext(); ctx != GetTopContext().parent && !symbol; ctx = ctx.parent)
6087 for(symbol = (Symbol)ctx.symbols.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6089 // Don't list enum values?
6090 //if(symbol.type.kind != TypeEnum)
6091 DataRow row = membersList.FindString(symbol.string);
6094 if(GetBuildingEcereComModule() && symbol.type && symbol.type.kind == functionType && eSystem_FindFunction(privateModule, symbol.string))
6096 row = membersList.AddString(symbol.string);
6097 if(symbol.type && symbol.type.kind == functionType)
6098 row.icon = icons[typeMethod];
6099 else if(symbol.type && symbol.type.kind == enumType)
6101 row.icon = icons[typeEnumValue];
6105 BitmapResource bitmap = null;
6106 if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
6108 char * bitmapName = (char *)eClass_GetProperty(symbol.type._class.registered, "icon");
6111 bitmap = { bitmapName };
6112 membersList.AddResource(bitmap);
6115 row.icon = bitmap ? bitmap : icons[typeData];
6122 for(symbol = (Symbol)ctx.types.first; symbol; symbol = (Symbol)((BTNode)symbol).next)
6124 DataRow row = membersList.FindString(symbol.string);
6127 row = membersList.AddString(symbol.string);
6128 if(symbol.type.kind == functionType)
6129 row.icon = icons[typeMethod];
6130 else if(symbol.type.kind == classType && (!symbol.type._class.registered || (symbol.type._class.registered.type != unitClass && symbol.type._class.registered.type != enumClass)))
6132 row.icon = icons[typeClass];
6136 row.icon = icons[typeDataType];
6143 ListModule(this.privateModule, 1, listClasses);
6144 // TODO: Implement this with name space
6148 for(data = globalData.first; data; data = data.next)
6150 DataRow row = membersList.FindString(data.name);
6152 data.dataType = ProcessTypeString(data.dataTypeString, false);
6155 row = membersList.AddString(data.name);
6157 if(data.dataType && data.dataType.kind == TypeEnum)
6159 row.icon = icons[typeEnumValue];
6163 BitmapResource bitmap = null;
6164 if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
6166 char * bitmapName = (char *)eClass_GetProperty(data.dataType._class.registered, "icon");
6169 bitmap = { bitmapName };
6170 membersList.AddResource(bitmap);
6173 row.icon = bitmap ? bitmap : icons[typeData];
6181 DataRow row = membersList.AddString("Min");
6182 row.icon = icons[typeMethod];
6184 row = membersList.AddString("Max");
6185 row.icon = icons[typeMethod];
6187 row = membersList.AddString("Abs");
6188 row.icon = icons[typeMethod];
6190 row = membersList.AddString("Sgn");
6191 row.icon = icons[typeMethod];
6197 void OverrideVirtualFunction(ClassFunction function, Method method, Class _class, bool isInstance, bool extraIndent)
6199 EditBoxStream f { editBox = editBox };
6204 updatingCode = true;
6206 if(!method.dataType)
6207 method.dataType = ProcessTypeString(method.dataTypeString, false);
6209 DeleteJunkBefore(f, function.loc.start.pos, &position);
6210 f.DeleteBytes(function.loc.end.pos - function.loc.start.pos - 1);
6212 // ADDING METHOD HERE
6214 Type dataType = method.dataType;
6215 Type returnType = dataType.returnType;
6217 Class moduleClass = eSystem_FindClass(this.privateModule, "Module");
6223 if(extraIndent) f.Printf(" ");
6225 OutputType(f, returnType, false);
6229 if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
6231 if(dataType.thisClass.shortName)
6232 f.Printf(dataType.thisClass.shortName);
6234 f.Printf(dataType.thisClass.string);
6237 f.Printf(method.name);
6239 for(param = dataType.params.first; param; param = param.next)
6241 // Decided not to write void...
6242 if(param.kind != voidType)
6244 OutputType(f, param, true);
6250 if(extraIndent) f.Printf(" ");
6251 f.Printf(" %c\n", OpenBracket);
6253 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6259 (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
6260 (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
6262 if(returnType && returnType.kind == classType && !strcmp(returnType._class.string, "bool"))
6264 if(extraIndent) f.Printf(" ");
6265 f.Printf(" return true;\n");
6267 else if(returnType && returnType.kind != voidType)
6269 if(extraIndent) f.Printf(" ");
6270 f.Printf(" return 0;\n");
6275 if(extraIndent) f.Printf(" ");
6277 if(returnType.kind != voidType)
6278 f.Printf("return ");
6279 f.Printf("%s::%s(", isInstance ? _class.name : _class.base.name, method.name);
6280 for(param = dataType.params.first; param; param = param.next)
6282 if(param.prev) f.Printf(", ");
6283 if(param.kind != voidType)
6284 f.Printf(param.name);
6290 if(extraIndent) f.Printf(" ");
6291 f.Printf(" %c", CloseBracket);
6296 if(extraIndent) { x1 += 3; x2 += 3; }
6297 editBox.SetSelPos(l1, y1, x1 + 6, l2, y2, x2 + 6);
6299 this.updatingCode = false;
6303 // Return false if we overrided a function and don't want to run params listing
6304 bool InvokeAutoComplete(bool enumOnly, int pointer, bool caretMove)
6306 bool didOverride = false;
6307 EditLine line = editBox.line;
6308 char * text = line.text;
6309 int lineNum, charPos;
6310 Expression exp = null;
6313 //Identifier id = null;
6314 Expression memberExp = null;
6315 Identifier realIdentifier = null;
6317 if(!parsing) return true;
6318 if(!privateModule) return !didOverride;
6320 insideFunction = null;
6322 charPos = editBox.charPos + 1;
6323 if(!membersListShown)
6328 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6330 EditBoxStream f { editBox = editBox };
6332 updatingCode = true;
6333 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6337 if(!f.Seek(-1, current))
6340 if(!isspace(ch)) break;
6341 f.Seek(-1, current);
6343 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6345 lineNum = editBox.lineNumber + 1;
6346 charPos = editBox.charPos + 1;
6348 updatingCode = false;
6351 if(!membersListShown)
6353 memberExp = FindExpTree(ast, lineNum, charPos);
6354 if(memberExp && (memberExp.type == TypeKind::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6359 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6361 EditBoxStream f { editBox = editBox };
6364 updatingCode = true;
6366 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6369 if(ch == '}' || ch == ',' || ch == ')')
6371 f.Seek(-1, current);
6379 if(!f.Seek(-1, current))
6382 if(!isspace(ch)) break;
6383 f.Seek(-1, current);
6387 f.Seek(-1, current);
6389 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6391 lineNum = editBox.lineNumber + 1;
6392 charPos = editBox.charPos + 1;
6394 updatingCode = false;
6397 realIdentifier = FindCtxTree(ast, lineNum, charPos);
6402 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6403 lineNum = editBox.lineNumber + 1;
6404 charPos = editBox.charPos/* + 1*/;
6408 char tempString[1024];
6409 char * string = null;
6410 CodePosition idStart, idEnd;
6412 if(membersListShown)
6414 char * buffer = membersLine.text;
6416 bool firstChar = true;
6418 string = tempString;
6420 for(c = membersLoc.start.charPos; c<membersLoc.end.charPos; c++)
6422 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6423 if(!isSpace) firstChar = false;
6425 string[len++] = buffer[c];
6429 else //if(realIdentifier)//if(id)
6432 char * buffer = id.string;
6434 bool firstChar = true;
6436 string = tempString;
6437 for(c = 0; c<= charPos - id.loc.start.charPos; c++)
6439 bool isSpace = (buffer[c] == ' ' || buffer[c] == '\t');
6440 if(!isSpace) firstChar = false;
6442 string[len++] = buffer[c];
6448 EditLine editLine = editBox.line;
6449 bool firstChar = true;
6452 string = tempString;
6453 for(y = lineNum-1; y >= 0; y--)
6455 char * buffer = editLine.text;
6456 int lineCount = editLine.count;
6457 for(x = (y == lineNum-1) ? (Min(charPos, lineCount) - 1 ): lineCount-1; x >= 0; x--)
6459 bool isSpace = (buffer[x] == ' ' || buffer[x] == '\t');
6464 idEnd.charPos = x + 2;
6469 // TESTING THIS CODE HERE FOR NOT CONSIDERING bool when doing ctrl-space past it
6472 idEnd.charPos = x + 2;
6479 if(!isalnum(buffer[x]) && buffer[x] != '_')
6485 memmove(string+1, string, len++);
6486 string[0] = buffer[x];
6490 //if(done || firstChar)
6491 if(done || !firstChar)
6493 editLine = editLine.prev;
6496 if(!strcmp(string, "case"))
6502 else if(!strcmp(string, "return"))
6508 else if(!strcmp(string, "delete"))
6514 else if(!strcmp(string, "new"))
6520 else if(!strcmp(string, "renew"))
6528 idStart.charPos = x + 1;
6529 idStart.line = y + 1;
6532 if(!membersListShown)
6534 membersList.Clear();
6535 if(memberExp && (memberExp.type == ExpressionType::memberExp || memberExp.type == pointerExp) && !memberExp.addedThis)
6537 Type type = memberExp.member.exp.expType;
6538 if(pointer == 2 && type)
6540 if(type.kind == pointerType || type.kind == arrayType)
6549 ListSymbols(exp, enumOnly, string, realIdentifier);
6551 membersList.Sort(null, 1);
6556 // Virtual function override
6557 Identifier id = GetDeclId(insideFunction.declarator);
6558 char * string = id ? id.string : null;
6560 Method method = eClass_FindMethod(GetThisClass(), string, this.privateModule);
6563 if(method.type != virtualMethod || (!insideInstance && method._class == GetThisClass()))
6564 insideFunction = null;
6567 OverrideVirtualFunction(insideFunction, method, GetThisClass(), insideInstance, insideInstance && insideClass);
6572 if(!didOverride) //insideFunction)
6574 rowCount = membersList.rowCount;
6577 DataRow row = string ? membersList.FindSubString(string) : null;
6578 if(row && !membersList.FindSubStringAfter(row, string) && !caretMove)
6580 char * newString = row.string;
6581 if(!membersListShown)
6583 membersLoc.start.line = idStart.line-1;
6584 membersLoc.start.charPos = idStart.charPos-1;
6585 //membersLoc.end = membersLoc.start;
6586 membersLoc.end.charPos = idEnd.charPos-1;
6587 membersLoc.end.line = idEnd.line-1;
6588 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6589 //membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6594 membersList.Destroy(0);
6595 membersListShown = false;
6598 editBox.GoToPosition(membersLine, membersLoc.start.line, membersLoc.start.charPos);
6600 line, membersLoc.start.line, membersLoc.start.charPos,
6601 line, membersLoc.end.line, membersLoc.end.charPos);
6602 editBox.PutS(newString);
6608 row = membersList.FindSubStringi(string);
6610 membersList.currentRow = row;
6611 membersList.currentRow.selected = false;
6614 membersList.currentRow = row;
6616 if(!membersListShown)
6620 // TESTING THESE ADDITIONS TO THE IF SO THAT CARET ISNT MOVED IF NOT ON TOP OF A WORD
6621 if(string && string[0] && lineNum == idStart.line && charPos >= idStart.charPos-1 && charPos <= idEnd.charPos-1)
6622 editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
6623 editBox.GetCaretPosition(caret);
6624 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6626 membersList.master = this;
6628 caret.y += editBox.GetCaretSize();
6630 membersList.Create();
6633 int x = caret.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6634 int y = caret.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6635 Window parent = membersList.parent;
6637 if(!paramsAbove && (paramsShown || y + membersList.size.h > parent.clientSize.h))
6639 y -= editBox.GetCaretSize() + membersList.size.h;
6640 membersAbove = true;
6643 membersAbove = false;
6645 membersList.position = { x, y };
6649 membersLoc.start.line = lineNum - 1;
6651 if(string && string[0])
6653 membersLoc.start.charPos = idStart.charPos-1;
6654 membersLoc.end = membersLoc.start;
6655 //membersLoc.end.charPos = id.loc.end.charPos-1;
6656 membersLoc.end.charPos = idStart.charPos + strlen(string)-1; //end.charPos-1;
6660 membersLoc.start.charPos = charPos;
6661 membersLoc.end = membersLoc.start;
6662 membersLoc.end.charPos = charPos;
6664 membersListShown = true;
6666 // Hack to keep caret shown
6667 editBox.GetCaretPosition(caret);
6668 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6671 membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
6677 SetCurrentContext(globalContext);
6680 return !didOverride;
6683 void InvokeParameters(bool exact, bool reposition, bool caretMove)
6685 EditLine line = editBox.line;
6686 char * text = line.text;
6687 int lineNum, charPos;
6688 Expression exp = null;
6692 if(!parsing) return;
6694 charPos = editBox.charPos + 1;
6697 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6699 EditBoxStream f { editBox = editBox };
6702 updatingCode = true;
6703 editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
6706 if(ch == '}' || ch == ',' || ch == ')')
6708 f.Seek(-1, current);
6716 if(!f.Seek(-1, current))
6719 if(!isspace(ch)) break;
6720 f.Seek(-1, current);
6724 f.Seek(-1, current);
6726 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6728 lineNum = editBox.lineNumber + 1;
6729 charPos = editBox.charPos + 1;
6731 updatingCode = false;
6734 charPos = Min(charPos, l1.count + 1);
6736 FindParamsTree(ast, lineNum, charPos);
6738 // Not sure about this == ExpCall... paramsInsideExp doesn't seem to necessarily be a ExpCall
6739 if(exact && ((::functionType && paramsInsideExp.type == callExp && paramsInsideExp.call.exp.loc.end.charPos != charPos-1) /*|| instanceType*/))
6741 ::functionType = null;
6742 ::instanceType = null;
6745 //if((::functionType || ::instanceType) && (!paramsShown || insideExp != functionExp || ::paramsID != this.paramsID))
6746 if((::functionType || ::instanceType) && (!paramsShown || true /*paramsInsideExp.destType != functionExp.destType */|| ::paramsID != this.paramsID))
6750 Window parent = paramsList.parent;
6752 if(this.functionType != ::functionType || this.instanceType != ::instanceType)
6755 if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
6756 // ( Dummy exp: always ends up with same memory)
6758 editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
6759 editBox.GetCaretPosition(paramsPosition);
6760 this.paramsPosition.y += editBox.GetCaretSize();
6763 FreeType(this.functionType);
6764 FreeType(this.instanceType);
6766 this.functionType = ::functionType;
6767 this.instanceType = ::instanceType;
6769 if(this.functionType) this.functionType.refCount++;
6770 if(this.instanceType) this.instanceType.refCount++;
6772 this.paramsID = ::paramsID;
6773 functionExp = paramsInsideExp;
6775 paramsList.master = this;
6777 paramsList.Create();
6779 x = paramsPosition.x + editBox.absPosition.x - app.desktop.absPosition.x - editBox.scroll.x;
6780 y = paramsPosition.y + editBox.absPosition.y - app.desktop.absPosition.y - editBox.scroll.y;
6782 if(!this.membersAbove && ( this.membersListShown || y + paramsList.size.h > parent.clientSize.h) )
6784 y -= editBox.GetCaretSize() + paramsList.clientSize.h;
6788 paramsAbove = false;
6789 if(x + paramsList.size.w > parent.clientSize.w)
6791 x = parent.clientSize.w - paramsList.size.w;
6795 paramsList.position = { x, y };
6797 // Hack to keep caret shown
6800 editBox.GetCaretPosition(caret);
6801 editBox.SetCaret(caret.x, caret.y, editBox.GetCaretSize());
6804 this.paramsShown = true;
6806 else if((!::functionType && !::instanceType) || reposition)
6808 paramsList.Destroy(0);
6809 paramsShown = false;
6811 FreeType(this.functionType);
6812 FreeType(this.instanceType);
6813 this.functionType = null;
6814 this.instanceType = null;
6818 SetCurrentContext(globalContext);
6826 designer.visible = true;
6827 designer.Activate();
6833 CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
6835 CodeEditor document { state = state, parent = parent, modifiedDocument = modified };