cleaned all trailing white space from source files.
[sdk] / ide / src / designer / CodeEditor.ec
index 98077bf..a283f58 100644 (file)
@@ -91,7 +91,7 @@ static Array<FileType> fileTypes
    { $"Text Files", "txt", never }
 ] };
 
-static char * iconNames[] = 
+static char * iconNames[] =
 {
    "<:ecere>constructs/class.png",
    "<:ecere>constructs/data.png",
@@ -117,6 +117,14 @@ extern int __ecereVMethodID_class_OnCopy;
 extern int __ecereVMethodID_class_OnSaveEdit;
 extern int __ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad;
 
+class RTCMenuBits
+{
+public:
+   bool ignoreBreakpoints:1;
+   bool atSameLevel:1;
+   bool oldImplementation:1;
+};
+
 class EditFileDialog : FileDialog
 {
    bool OnCreate()
@@ -146,10 +154,10 @@ define CloseBracket = '}';
 
 enum MethodAction
 {
-   actionAddMethod = 1, 
-   actionDeleteMethod = 2, 
-   actionDetachMethod = 3, 
-   actionAttachMethod = 4, 
+   actionAddMethod = 1,
+   actionDeleteMethod = 2,
+   actionDetachMethod = 3,
+   actionAttachMethod = 4,
    actionReattachMethod = 5
 };
 
@@ -190,7 +198,7 @@ static void OutputString(File f, char * string)
          f.Puts("\\\\");
       else
          f.Putc(string[c]);
-   }                              
+   }
 }
 
 void OutputType(File f, Type type, bool outputName)
@@ -291,10 +299,10 @@ void DeleteJunkBefore(EditBoxStream f, int pos, int * position)
 {
    char ch;
    int before = 0;
-   
+
    if(position)
       f.Seek(pos - *position, current);
-                                                      
+
    // Try to delete spaces and \n before...
    f.Seek(-1, current);
    for(;f.Getc(&ch);)
@@ -346,7 +354,7 @@ void GetLocText(EditBox editBox, File f, int position, Location loc, char ** tex
    editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
 
    // Cut & Paste function
-   
+
    {
       EditLine l1, l2;
       int y1,x1,y2,x2;
@@ -365,7 +373,7 @@ void GetLocText(EditBox editBox, File f, int position, Location loc, char ** tex
       *text = new char[*size+1 + (y2-y1+1) * linePad + pad]; // Add pad for tabs and new name
       editBox.GetSel(*text, false);
    }
-   
+
    editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
    f.Printf(""); // Make the stream point to where the editbox is
 }
@@ -389,7 +397,7 @@ bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
       {
          void * dataForm = new0 byte[dataType.structSize];
          void * dataTest = new0 byte[dataType.structSize];
-   
+
          ((void (*)(void *, void *))(void *)prop.Get)(selected.instance, dataForm);
          ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
 
@@ -404,10 +412,10 @@ bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
       else if(dataType && dataType._vTbl && (dataType.type == normalClass || dataType.type == noHeadClass))
       {
          void * dataForm, * dataTest;
-   
+
          dataForm = ((void *(*)(void *))(void *)prop.Get)(selected.instance);
          dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
-   
+
          if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
          {
             ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
@@ -417,10 +425,10 @@ bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
       else if(dataType && dataType._vTbl)
       {
          DataValue dataForm, dataTest;
-   
+
          GetProperty(prop, selected.instance, &dataForm);
          GetProperty(prop, test, &dataTest);
-   
+
          if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
          {
             SetProperty(prop, test, dataForm);
@@ -433,7 +441,7 @@ bool Code_IsPropertyModified(Instance test, ObjectInfo selected, Property prop)
                   SetProperty(prop, selected.instance, dataForm);
             }
             result = true;
-         }                                          
+         }
       }
    }
    return result;
@@ -444,7 +452,7 @@ bool Code_IsPropertyDisabled(ObjectInfo selected, char * name)
    bool disabled = false;
    if(selected.oClass == selected)
    {
-      ClassDef def;                  
+      ClassDef def;
       if(selected.classDefinition)
       {
          for(def = selected.classDefinition.definitions->first; def; def = def.next)
@@ -501,7 +509,7 @@ bool Code_IsPropertyDisabled(ObjectInfo selected, char * name)
 
 static bool CheckCompatibleMethod(Method method, Type type, Class regClass, bool isForm, Symbol selectedClass)
 {
-   bool result = false;   
+   bool result = false;
    bool reset = false;
    if(!method.dataType)
       method.dataType = ProcessTypeString(method.dataTypeString, false);
@@ -534,7 +542,7 @@ bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo obje
          method.dataType = ProcessTypeString(method.dataTypeString, false);
 
       confirmation = false;
-     
+
       // Check if default function should be calling base class:
       if(object.instance._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
       {
@@ -561,7 +569,7 @@ bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo obje
          else
          {
             if(stmt)
-               confirmation = true;        
+               confirmation = true;
          }
       }
       else
@@ -578,7 +586,7 @@ bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo obje
          }
 
          if(!exp || exp.type != callExp || exp.call.exp.type != identifierExp)
-            confirmation = true;        
+            confirmation = true;
          else
          {
             Identifier id = exp.call.exp.identifier;
@@ -604,7 +612,7 @@ bool Code_IsFunctionEmpty(ClassFunction function, Method method, ObjectInfo obje
                      arg = arg ?arg.next : null;
                   }
                }
-            }                  
+            }
          }
       }
    }
@@ -622,8 +630,8 @@ class CodeEditor : Window
    isActiveClient = true;
    anchor = Anchor { left = 300, right = 150, top = 0, bottom = 0 };
    menu = Menu { };
-   
-   // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE); 
+
+   // eWindow_SetX(A_CASCADE); eWindow_SetY(A_CASCADE);
    // eWindow_SetWidth(A_RELATIVE|80); eWindow_SetHeight(A_RELATIVE|80);
 
    SheetType sheetSelected;
@@ -640,7 +648,7 @@ class CodeEditor : Window
    OldList classes;
    bool codeModified;
    bool formModified;
-   
+
    ObjectInfo selected;
    ObjectInfo oClass;
 
@@ -668,7 +676,7 @@ class CodeEditor : Window
    bool expectingMove;
 
    BitmapResource icons[CodeObjectType];
-   
+
    FontResource boldFont { $"Tahoma", 8.25f, bold = true, window = this };
    FontResource normalFont { $"Tahoma", 8.25f, window = this };
 
@@ -684,8 +692,9 @@ class CodeEditor : Window
    Designer designer { codeEditor = this, visible = false, saveDialog = codeEditorFormFileDialog };
 
    bool noParsing;
+   int maxLineNumberLength;
 
-   property bool parsing { get { return !noParsing && !ide.noParsing; } };
+   property bool parsing { get { return editBox.syntaxHighlighting && !noParsing && !ide.noParsing; } };
 
    void ProcessCaretMove(EditBox editBox, int line, int charPos)
    {
@@ -699,7 +708,7 @@ class CodeEditor : Window
          ide.pos.text = temp;
       }
       if(sheet.codeEditor != this) return;
-      
+
       if(!updatingCode)
       {
          for(classItem = classes.first; classItem; classItem = classItem.next)
@@ -790,7 +799,7 @@ class CodeEditor : Window
       ProjectView projectView = ide.projectView;
       if(projectView)
       {
-         ProjectNode node = projectView.GetNodeFromWindow(this, null, false);
+         ProjectNode node = projectView.GetNodeFromWindow(this, null, true, false);
          if(node)
          {
             node.modified = modifiedDocument;
@@ -803,7 +812,7 @@ class CodeEditor : Window
    EditBox editBox
    {
       textVertScroll = true, multiLine = true, /*lineNumbers = ideSettings.showLineNumbers,*/
-      freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling, 
+      freeCaret = ideSettings.useFreeCaret, caretFollowsScrolling = ideSettings.caretFollowsScrolling,
       tabKey = true, smartHome = true;
       tabSelection = true, /*maxLineSize = 65536, */parent = this, hasHorzScroll = true, hasVertScroll = true;
       selectionColor = selectionColor, selectionText = selectionText,
@@ -890,6 +899,7 @@ class CodeEditor : Window
                */
             }
             Update({ 0, 0, editBox.position.x, clientSize.h });
+            UpdateMarginSize();
          }
 
          if(!updatingCode)
@@ -943,7 +953,7 @@ class CodeEditor : Window
                            hide = true;
                            break;
                         }
-                        if(!isSpace) 
+                        if(!isSpace)
                            firstChar = false;
                         else if(firstChar)
                         {
@@ -1034,14 +1044,14 @@ class CodeEditor : Window
 
                      editBox.GetCaretPosition(&caret);
 
-                     
+
 
                      // Go back in the buffer until no space before
                      //yydebug = true;
                      codeModified = true;
                      EnsureUpToDate();
                      SetYydebug(false);
-                     { 
+                     {
                         EditBoxStream f { editBox = editBox };
                         oldCharPos = x1;
                         x1--;
@@ -1111,7 +1121,7 @@ class CodeEditor : Window
 
                               membersList.position = { x, y };
                            }
-         
+
                            membersLine = l1;
                            membersLoc.start.line = line - 1;
                            membersLoc.start.charPos = oldCharPos;
@@ -1151,13 +1161,13 @@ class CodeEditor : Window
                   }
                   else if(ch == ')' || ch == '}' || ch == ';')
                   {
-                     codeModified = true;               
+                     codeModified = true;
                      skipModified = true;
                      if(paramsShown)
                         InvokeParameters(false, true, false);
                      skipModified = false;
                   }
-                  else 
+                  else
                   {
                      bool back = codeModified;
                      codeModified = false;
@@ -1193,6 +1203,7 @@ class CodeEditor : Window
             if(projectView && fileName)
                ide.debugger.MoveIcons(fileName, before.y + 1, before.y - after.y, before.x == 0);
             Update({ 0, 0, editBox.position.x, clientSize.h });
+            UpdateMarginSize();
          }
 
          if(!updatingCode)
@@ -1209,7 +1220,7 @@ class CodeEditor : Window
                   {
                      loc = &object.instCode.loc;
 
-                     if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) && 
+                     if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
                         (after.y+1 > loc->end.line    || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
                      {
                         object.instCode = null;
@@ -1224,7 +1235,7 @@ class CodeEditor : Window
                if(oClass.classDefinition)
                {
                   loc = &oClass.classDefinition.loc;
-                  if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) && 
+                  if((before.y+1 < loc->start.line || (before.y+1 == loc->start.line && before.x+1 <= loc->start.charPos)) &&
                      (after.y+1 > loc->end.line    || (after.y+1 == loc->end.line && after.x+1 >= loc->end.charPos)))
                   {
                      oClass.classDefinition = null;
@@ -1367,7 +1378,7 @@ class CodeEditor : Window
                designer.DroppedObject(control, object, false, classObject.instance);
 
                sheet.AddObject(object, object.name, typeData /* className*/, true);
-               
+
                UpdateFormCode();
                //codeModified = true;
                EnsureUpToDate();
@@ -1378,7 +1389,7 @@ class CodeEditor : Window
 
       bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
       {
-         if(key == Key { space, ctrl = true })
+         if(key == ctrlSpace)
          {
             membersList.Destroy(0);
             membersListShown = false;
@@ -1393,13 +1404,13 @@ class CodeEditor : Window
          {
             if(ide.projectView)
             {
-               ProjectNode node = ide.projectView.GetNodeFromWindow(this, null, false);
+               ProjectNode node = ide.projectView.GetNodeFromWindow(this, null, true, false);
                if(!node)
-                  node = ide.projectView.GetNodeFromWindow(this, null, true);
+                  node = ide.projectView.GetNodeFromWindow(this, null, true, true);
                if(!node)
                {
                   char * s;
-                  s = PrintString($"The ", fileName, $" file is not part of any project.\n", 
+                  s = PrintString($"The ", fileName, $" file is not part of any project.\n",
                      $"It can't be compiled.");
                   MessageBox { type = ok, /*parent = ide, */master = ide, text = $"File not in project error", contents = s }.Modal();
                   delete s;
@@ -1493,41 +1504,52 @@ class CodeEditor : Window
       bool OnKeyDown(Key key, unichar ch)
       {
          CodeEditor editor = (CodeEditor) master;
-         if(key == escape || key == leftAlt || key == rightAlt || 
-            (key.ctrl && key.code != left && key.code != right && 
+         if(key == escape || key == leftAlt || key == rightAlt ||
+            (key.ctrl && key.code != left && key.code != right &&
              key.code != leftShift && key.code != rightShift && key.code != space))
          {
+            bool result = true;
             if(editor.paramsShown)
+            {
+               if(key == escape)
+                  result = false;
                editor.paramsList.Destroy(0);
+               editor.paramsShown = false;
+            }
             if(editor.membersListShown)
+            {
+               if(key == escape)
+                  result = false;
                editor.membersList.Destroy(0);
+               editor.membersListShown = false;
+            }
 
-            editor.paramsShown = false;
             FreeType(editor.functionType);
-            FreeType(editor.instanceType);
-
             editor.functionType = null;
+
+            FreeType(editor.instanceType);
             editor.instanceType = null;
+
             editor.paramsID = -1;
 
-            editor.membersListShown = false;
-            return true;
+            return result;
          }
-         else 
+         else
             return editor.editBox.OnKeyDown(key, ch);
          return false;
       }
 
-      bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
+      /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
       {
          CodeEditor editor = (CodeEditor)master;
-         if(!active)
+         Window rw = previous ? previous.rootWindow : null;
+         if(!active && rw != editor.paramsList)
          {
             Destroy(0);
             editor.membersListShown = false;
          }
          return ListBox::OnActivate(active, previous, goOnWithActivation, direct);
-      }
+      }*/
 
       bool OnKeyHit(Key key, unichar ch)
       {
@@ -1583,26 +1605,27 @@ class CodeEditor : Window
 
    Window paramsList
    {
-      master = this, 
+      master = this,
       interim = true,
       clickThrough = true,
       autoCreate = false,
       borderStyle = contour,
       cursor = null,
       background = { 255,255,225 },
-      
+
       OnKeyDown = membersList.OnKeyDown;
 
-      bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
+      /*bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
       {
          CodeEditor editor = (CodeEditor)master;
-         if(!active)
+         Window rw = previous ? previous.rootWindow : null;
+         if(!active && previous != editor.editBox && rw != editor.membersList)
          {
             Destroy(0);
-            editor.membersListShown = false;
+            editor.paramsShown = false;
          }
          return Window::OnActivate(active, previous, goOnWithActivation, direct);
-      }
+      }*/
 
       bool OnKeyHit(Key key, unichar ch)
       {
@@ -1668,7 +1691,7 @@ class CodeEditor : Window
                display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
             totalW = functionW + nameW;
             surface.TextFont(boldFont);
-         }   
+         }
 
          surface.WriteText(x, y, string, strlen(string));
          x += functionW + spaceW;
@@ -1687,7 +1710,7 @@ class CodeEditor : Window
 
                if(id == editor.paramsID)
                   surface.TextFont(boldFont);
-               
+
                if(methodType.methodClass)
                   surface.TextExtent(methodType.methodClass.name, strlen(methodType.methodClass.name), &tw, null);
 
@@ -1716,7 +1739,7 @@ class CodeEditor : Window
                {
                   surface.WriteText(x, y, ",", 1);
                   x += ((id ==  editor.paramsID) ? commaWB : commaW);
-               }      
+               }
 
                lineW += width;
 
@@ -1762,7 +1785,7 @@ class CodeEditor : Window
                   {
                      surface.WriteText(x, y, ",", 1);
                      x += ((id ==  editor.paramsID) ? commaWB : commaW);
-                  }      
+                  }
 
                   lineW += width;
 
@@ -1834,7 +1857,7 @@ class CodeEditor : Window
                display.FontExtent(boldFont, instanceName, strlen(instanceName), &nameW, null);
             totalW = functionW + nameW + spaceW;
          }
-            
+
          if(editor.functionType)
          {
             if(methodType)
@@ -1872,7 +1895,7 @@ class CodeEditor : Window
                   paramString[0] = 0;
                   PrintType(param, paramString, true, true);
                   display.FontExtent((id == editor.paramsID || param.kind == ellipsisType) ? boldFont : font, paramString, strlen(paramString), &width, null);
-                  if(param.next) 
+                  if(param.next)
                      width += ((id == editor.paramsID) ? commaWB : commaW);
 
                   if(!height)
@@ -1901,50 +1924,40 @@ class CodeEditor : Window
       }
    };
 
-   Menu fileMenu { menu, $"File", f };  // MenuPlacement?
+   Menu fileMenu { menu, $"File", f };
    MenuItem { fileMenu, $"Save", s, Key { s, ctrl = true }, NotifySelect = MenuFileSave };
    MenuItem { fileMenu, $"Save As...", a, NotifySelect = MenuFileSaveAs };
 
-   Menu debugMenu { menu, $"Debug", d };  // MenuPlacement?
-   MenuItem debugRunToCursor
-   {
-      debugMenu, $"Run To Cursor", c, Key { f10, ctrl = true };
-      bool NotifySelect(MenuItem selection, Modifiers mods)
-      {
-         ProjectView projectView = ide.projectView;
-         if(!projectView.buildInProgress)
-         {
-            int line = editBox.lineNumber + 1;
-            if(projectView)
-            {
-               CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
-               ProjectConfig config = projectView.project.config;
-               int bitDepth = ide.workspace.bitDepth;
-               ide.debugger.RunToCursor(compiler, config, bitDepth, fileName, line, false);
-               delete compiler;
-            }
-         }
-         return true;
-      }
-   };
-   MenuItem debugSkipRunToCursor
+   Menu debugMenu { menu, $"Debug", d };
+   MenuItem debugRunToCursor                { debugMenu, $"Run To Cursor", c, ctrlF10,                                                                  id = RTCMenuBits { false, false, false }, NotifySelect = RTCMenu_NotifySelect; };
+   MenuItem debugSkipRunToCursor            { debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true },              id = RTCMenuBits { true,  false, false }, NotifySelect = RTCMenu_NotifySelect; };
+   MenuItem debugRunToCursorAtSameLevel     { debugMenu, $"Run To Cursor At Same Level", l, altF10,                                                     id = RTCMenuBits { false, true,  false }, NotifySelect = RTCMenu_NotifySelect; };
+   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; };
+#if 0
+   MenuItem debugBpRunToCursor                { debugMenu, $"BP Run To Cursor"/*, c, ctrlF10*/,                                                                  id = RTCMenuBits { false, false, true  }, NotifySelect = RTCMenu_NotifySelect; };
+   MenuItem debugBpSkipRunToCursor            { debugMenu, $"BP Run To Cursor Skipping Breakpoints"/*, u, Key { f10, ctrl = true, shift = true }*/,              id = RTCMenuBits { true,  false, true  }, NotifySelect = RTCMenu_NotifySelect; };
+   MenuItem debugBpRunToCursorAtSameLevel     { debugMenu, $"BP Run To Cursor At Same Level"/*, l, altF10*/,                                                     id = RTCMenuBits { false, true,  true  }, NotifySelect = RTCMenu_NotifySelect; };
+   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; };
+#endif
+   bool RTCMenu_NotifySelect(MenuItem selection, Modifiers mods)
    {
-      debugMenu, $"Run To Cursor Skipping Breakpoints", u, Key { f10, ctrl = true, shift = true };
-      bool NotifySelect(MenuItem selection, Modifiers mods)
+      ProjectView projectView = ide.projectView;
+      if(!projectView.buildInProgress)
       {
-         ProjectView projectView = ide.projectView;
+         RTCMenuBits bits = (RTCMenuBits)selection.id;
          int line = editBox.lineNumber + 1;
          if(projectView)
          {
             CompilerConfig compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
             ProjectConfig config = projectView.project.config;
             int bitDepth = ide.workspace.bitDepth;
-            ide.debugger.RunToCursor(compiler, config, bitDepth, fileName, line, true);
+            bool useValgrind = ide.workspace.useValgrind;
+            ide.debugger.RunToCursor(compiler, config, bitDepth, useValgrind, fileName, line, bits.ignoreBreakpoints, bits.atSameLevel, bits.oldImplementation);
             delete compiler;
          }
-         return true;
       }
-   };
+      return true;
+   }
    MenuDivider { debugMenu };
    MenuItem debugToggleBreakpoint
    {
@@ -1955,33 +1968,7 @@ class CodeEditor : Window
          if(projectView && fileName)
          {
             int line = editBox.lineNumber + 1;
-            char name[MAX_LOCATION];
-            Project prj = null;
-            // TOFIX: This only looks at the filename...
-            GetLastDirectory(fileName, name);
-            if(ide && ide.workspace)
-            {
-               for(p : ide.workspace.projects)
-               {
-                  if(p.topNode.Find(name, false))
-                  {
-                     prj = p;
-                     break;
-                  }
-               }
-               if(!prj)
-               {
-                  for(p : ide.workspace.projects)
-                  {
-                     if(IsPathInsideOf(fileName, p.topNode.path))
-                     {
-                        prj = p;
-                        break;
-                     }
-                  }
-               }
-            }
-            ide.debugger.ToggleBreakpoint(fileName, line, prj);
+            ide.debugger.ToggleBreakpoint(fileName, line);
             Update(null);
          }
          return true;
@@ -2020,7 +2007,8 @@ class CodeEditor : Window
             if(CloseConfirmation(false))
             {
                visible = false;
-               OnFileModified({ modified = true }, null);
+               if(modifiedDocument)
+                  OnFileModified({ modified = true }, null);
             }
             debugClosing = false;
             return false;
@@ -2062,7 +2050,7 @@ class CodeEditor : Window
       for(oClass = (classes).first, next = oClass ? oClass.next : null; oClass; oClass = next, next = next ? (next.next) : null)
       {
          ObjectInfo object, next;
-         
+
          for(object = oClass.instances.first; object; object = next)
          {
             next = object.next;
@@ -2102,7 +2090,7 @@ class CodeEditor : Window
          ProjectView projectView = ide.projectView;
          if(projectView)
          {
-            ProjectNode node = projectView.GetNodeFromWindow(this, null, false);
+            ProjectNode node = projectView.GetNodeFromWindow(this, null, false, false);
             if(node && node.modified)
             {
                node.modified = false;
@@ -2121,6 +2109,7 @@ class CodeEditor : Window
       */
       if(active && directActivation)
       {
+         AdjustDebugMenus();
          if(openedFileInfo)
             openedFileInfo.Activate();
          if(designer)
@@ -2172,6 +2161,25 @@ class CodeEditor : Window
             ProcessCaretMove(editBox, line, charPos);
          }
       }
+      if(!active)
+      {
+         if(membersListShown)
+         {
+            membersList.Destroy(0);
+            membersListShown = false;
+         }
+         if(paramsShown)
+         {
+            paramsList.Destroy(0);
+            paramsShown = false;
+            FreeType(functionType);
+            FreeType(instanceType);
+
+            functionType = null;
+            instanceType = null;
+            paramsID = -1;
+         }
+      }
       return true;
    }
 
@@ -2196,8 +2204,8 @@ class CodeEditor : Window
          }
          editBox.Save(f, false);
          modifiedDocument = false;
-         
-         delete(f);
+
+         delete f;
          return true;
       }
       return false;
@@ -2207,7 +2215,7 @@ class CodeEditor : Window
    {
       bool reload = false;
       if(visible == false && inUseDebug == true)
-         reload = true;
+         ide.debugger.WatchesReleaseCodeEditor();
       else
       {
          char message[2048];
@@ -2250,7 +2258,7 @@ class CodeEditor : Window
             }
             modifiedDocument = false;
 
-            delete(f);
+            delete f;
          }
       }
       return true;
@@ -2265,6 +2273,7 @@ class CodeEditor : Window
       {
          int currentLineNumber;
          int i;
+         char lineFormat[16];
          char lineText[256];
          int spaceH;
 
@@ -2272,6 +2281,7 @@ class CodeEditor : Window
          surface.font = font.font;
          surface.TextExtent(" ", 1, null, &spaceH);
          currentLineNumber = editBox.scroll.y / spaceH + 1;
+         sprintf(lineFormat, " %%%du", maxLineNumberLength);
 
          surface.SetForeground(lineNumbersColor);
          for(i = 0; i < editBox.clientSize.h - 4; i += spaceH)
@@ -2283,10 +2293,9 @@ class CodeEditor : Window
                surface.Area(0, i, editBox.anchor.left.distance, i+spaceH-1);
                surface.SetBackground(marginColor);
             }
-            sprintf(lineText,"%5u ", currentLineNumber % 100000);
+            sprintf(lineText, lineFormat, currentLineNumber);
             if(currentLineNumber <= editBox.numLines)
-               surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,6);
-            
+               surface.WriteText(editBox.syntaxHighlighting * 20, i+1,lineText,maxLineNumberLength+1);
             currentLineNumber++;
          }
       }
@@ -2319,7 +2328,7 @@ class CodeEditor : Window
                }
                else
                   bmpRes = breakpointEnabled[i] ? ide.bmpBp : ide.bmpBpDisabled;
-               
+
                DrawLineMarginIcon(surface, bmpRes, breakpointLines[i], lineH, scrollY, boxH);
             }
          }
@@ -2364,37 +2373,48 @@ class CodeEditor : Window
       if(fileName)
       {
          GetExtension(fileName, ext);
+
+         if(!strcmpi(ext, "ec") || !strcmpi(ext, "eh") || !strcmpi(ext, "c") || !strcmpi(ext, "h") || !strcmpi(ext, "cpp") ||
+               !strcmpi(ext, "hpp") || !strcmpi(ext, "cxx") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cc") || !strcmpi(ext, "hh") ||
+               !strcmpi(ext, "m") || !strcmpi(ext, "mm") || !strcmpi(ext, "cs") || !strcmpi(ext, "java") || !strcmpi(ext, "y") || !strcmpi(ext, "l"))
+            editBox.syntaxHighlighting = true;
+         else
+            editBox.syntaxHighlighting = false;
+
          if(parsing && !strcmpi(ext, "ec"))
          {
             codeModified = true;
             EnsureUpToDate();
          }
 
-         if(!strcmpi(ext, "ec") || !strcmpi(ext, "c") || !strcmpi(ext, "cc") || !strcmpi(ext, "cpp") || !strcmpi(ext, "eh") || !strcmpi(ext, "hh") || !strcmpi(ext, "hpp") || !strcmpi(ext, "h") || !strcmpi(ext, "hxx") || !strcmpi(ext, "cxx"))
-            editBox.syntaxHighlighting = true;
-         else
-            editBox.syntaxHighlighting = false;
+         UpdateMarginSize();
+      }
+   };
+
+   bool UpdateMarginSize()
+   {
+      static int lineCount = -1;
+      if(editBox.numLines != lineCount)
+      {
+         int digitWidth;
+         lineCount = editBox.numLines;
+         if(nofdigits(lineCount) != maxLineNumberLength)
          {
-            int spaceW;
-            display.FontExtent(font.font, " ", 1, &spaceW, null);
+            maxLineNumberLength = nofdigits(lineCount);
+            display.FontExtent(font.font, "0", 1, &digitWidth, null);
             editBox.anchor = Anchor
             {
-               left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
+               left = editBox.syntaxHighlighting * 20 + (ideSettings.showLineNumbers ? ((maxLineNumberLength+2) * digitWidth) : 0),
                right = 0, top = 0, bottom = 0
             };
          }
       }
-   };
+      return true;
+   }
 
    bool OnPostCreate()
    {
-      int spaceW;
-      display.FontExtent(font.font, " ", 1, &spaceW, null);
-      editBox.anchor = Anchor
-      {
-         left = (editBox.syntaxHighlighting ? 20 : 0) + (ideSettings.showLineNumbers ? (6 * spaceW) : 0),
-         right = 0, top = 0, bottom = 0
-      };
+      UpdateMarginSize();
       return true;
    }
 
@@ -2403,7 +2423,7 @@ class CodeEditor : Window
       File f = FileOpen(filePath, read);
       if(f)
       {
-         // Added this here... 
+         // Added this here...
          fileName = filePath;
          loadingFile = true;
          updatingCode = true;
@@ -2412,18 +2432,30 @@ class CodeEditor : Window
          loadingFile = false;
          Create();
 
-         delete(f);
+         delete f;
          return true;
       }
       return false;
    }
 
-   void DebugMenusDisabled()
+   void AdjustDebugMenus()
    {
-      bool debugMenusDisabled = ide.GetDebugMenusDisabled();
-      debugRunToCursor.disabled = debugMenusDisabled;
-      debugSkipRunToCursor.disabled = debugMenusDisabled;
-      debugToggleBreakpoint.disabled = debugMenusDisabled;
+      bool unavailable = ide.areDebugMenusUnavailable;
+      bool isNotNotRunning    = unavailable || ide.isDebuggerRunning;
+      bool isNotStopped       = unavailable || !ide.isDebuggerStopped;
+      bool noBreakpointToggle = ide.isBreakpointTogglingUnavailable;
+
+      debugRunToCursor.disabled                = isNotNotRunning;
+      debugSkipRunToCursor.disabled            = isNotNotRunning;
+      debugRunToCursorAtSameLevel.disabled     = isNotStopped;
+      debugSkipRunToCursorAtSameLevel.disabled = isNotStopped;
+#if 0
+      debugBpRunToCursor.disabled                = isNotNotRunning;
+      debugBpSkipRunToCursor.disabled            = isNotNotRunning;
+      debugBpRunToCursorAtSameLevel.disabled     = isNotStopped;
+      debugBpSkipRunToCursorAtSameLevel.disabled = isNotStopped;
+#endif
+      debugToggleBreakpoint.disabled           = noBreakpointToggle;
    }
 
    CodeEditor()
@@ -2443,7 +2475,7 @@ class CodeEditor : Window
          designer.fileName = title;
       }
 
-      DebugMenusDisabled();
+      AdjustDebugMenus();
 
       for(c = 0; c < CodeObjectType::enumSize; c++)
          icons[c] = BitmapResource { iconNames[c], window = this };
@@ -2561,7 +2593,7 @@ class CodeEditor : Window
                }
             }
          }
-         else 
+         else
             selectedPos = -1;
       }
 
@@ -2627,13 +2659,13 @@ class CodeEditor : Window
       if(this.oClass)
       {
          ObjectInfo _class, next;
-         
+
          for(_class = classes.first; _class; _class = next)
          {
             ObjectInfo object;
 
             next = _class.next;
-            
+
             for(;object = _class.instances.first;)
             {
                if(object.instance)
@@ -2736,7 +2768,7 @@ class CodeEditor : Window
       }
       if(!project)
          project = ide.project;
-         
+
       GetWorkingDir(oldWorkDir, MAX_LOCATION);
       if(project)
          ChangeWorkingDir(project.topNode.path);
@@ -2771,7 +2803,7 @@ class CodeEditor : Window
             case win32: SetSymbolsDir("obj/debug.win32"); break;
             case tux:   SetSymbolsDir("obj/debug.linux"); break;
             case apple: SetSymbolsDir("obj/debug.apple"); break;
-         }         
+         }
          SetIncludeDirs(null);
          SetSysIncludeDirs(null);
       }
@@ -2792,7 +2824,7 @@ class CodeEditor : Window
                }
             }
          }
-         
+
          if(!(strcmpi(mainModuleName, "instance.ec") && strcmpi(mainModuleName, "BinaryTree.ec") &&
             strcmpi(mainModuleName, "dataTypes.ec") && strcmpi(mainModuleName, "OldList.ec") &&
             strcmpi(mainModuleName, "String.ec") && strcmpi(mainModuleName, "BTNode.ec") &&
@@ -2816,7 +2848,7 @@ class CodeEditor : Window
 
             strcpy(symLocation, GetSymbolsDir());
             PathCat(symLocation, symFile);
-            
+
             // if(!GetEcereImported() && !GetBuildingEcereCom())
             if(!strcmp(extension, "ec") || !strcmp(extension, "eh"))
             {
@@ -2882,7 +2914,7 @@ class CodeEditor : Window
 
       SetIncludeDirs(null);
       SetSysIncludeDirs(null);
-      
+
       delete editFile;
       fileInput = null;
       SetFileInput(null);
@@ -2890,7 +2922,7 @@ class CodeEditor : Window
       if(GetAST())
       {
          ast = GetAST();
-         
+
 #ifdef _TIMINGS
          startTime = GetTime();
 #endif
@@ -2950,7 +2982,7 @@ class CodeEditor : Window
                      if(eClass_GetDesigner(regClass) && !GetBuildingEcereComModule())
                      {
                         Instance instance = eInstance_New(regClass);
-                        ObjectInfo classObject 
+                        ObjectInfo classObject
                         {
                            name = CopyString(_class._class.name);
                            instance = instance;
@@ -2993,7 +3025,7 @@ class CodeEditor : Window
                                                 FreeType(propDef.initializer.exp.destType);
                                                 propDef.initializer.exp.destType = MkClassType(propertyClass.name);
                                                 ProcessExpressionType(propDef.initializer.exp);
-                                             
+
                                                 if(propertyClass.type == structClass || propertyClass.type == noHeadClass || propertyClass.type == normalClass)
                                                 {
                                                    Expression computed = CopyExpression(propDef.initializer.exp);
@@ -3004,14 +3036,15 @@ class CodeEditor : Window
                                                       if(prop.Set)
                                                       {
                                                          if(computed.instance._class && computed.instance._class.symbol &&
-                                                            computed.instance._class.symbol.registered && 
+                                                            computed.instance._class.symbol.registered &&
                                                             eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
                                                          {
                                                             ((void (*)(void *, void *))(void *)prop.Set)(instance, computed.instance.data);
 
                                                             // This was saved in the control and shouldn't be freed by FreeExpression...
-                                                            if(propertyClass.type == normalClass)
-                                                               computed.instance.data = null;
+                                                            // (Not doing this anymore, incrementing refCount in pass15 instead)
+                                                            /*if(propertyClass.type == normalClass)
+                                                               computed.instance.data = null;*/
                                                          }
                                                       }
                                                    }
@@ -3025,7 +3058,7 @@ class CodeEditor : Window
                                                    }
                                                    else
                                                       propDef.variable = true;
-                                                   
+
                                                    FreeExpression(computed);
                                                 }
                                                 else
@@ -3063,7 +3096,7 @@ class CodeEditor : Window
                                           else
                                           {
                                              Method method = eClass_FindMethod(regClass, id.string, this.privateModule);
-                                             if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer && 
+                                             if(method && method.type == virtualMethod && propDef.initializer && propDef.initializer.type == expInitializer &&
                                                 propDef.initializer.exp && propDef.initializer.exp.type == identifierExp)
                                              {
                                                 ClassDef def;
@@ -3079,7 +3112,7 @@ class CodeEditor : Window
                                                       }
                                                    }
                                                 }
-                                             }                                          
+                                             }
                                           }
                                        }
                                     }
@@ -3143,8 +3176,8 @@ class CodeEditor : Window
                                           {
                                              Instance control;
                                              object = object ? object.next : classObject.instances.first;
-                                             control = object.instance;                                             
-                                             
+                                             control = object.instance;
+
                                              if(inst.members)
                                              {
                                                 MembersInit members;
@@ -3204,7 +3237,7 @@ class CodeEditor : Window
                                                                      if(propertyClass)
                                                                      {
                                                                         ProcessExpressionType(member.initializer.exp);
-                                       
+
                                                                         if(propertyClass.type == structClass || propertyClass.type == normalClass || propertyClass.type == noHeadClass)
                                                                         {
                                                                            Expression computed;
@@ -3217,20 +3250,21 @@ class CodeEditor : Window
                                                                            if(computed)
                                                                            {
                                                                               ComputeExpression(computed);
-                                                                              
+
                                                                               if(computed.type == instanceExp && computed.isConstant && computed.isConstant)
                                                                               {
                                                                                  if(computed.instance.data)
                                                                                  {
                                                                                     if(computed.instance._class && computed.instance._class.symbol &&
-                                                                                       computed.instance._class.symbol.registered && 
+                                                                                       computed.instance._class.symbol.registered &&
                                                                                        eClass_IsDerived(computed.instance._class.symbol.registered, propertyClass))
                                                                                     {
                                                                                        ((void (*)(void *, void *))(void *)prop.Set)(control, computed.instance.data);
 
                                                                                        // This was saved in the control and shouldn't be freed by FreeExpression...
-                                                                                       if(propertyClass.type == normalClass)
-                                                                                          computed.instance.data = null;
+                                                                                       // (Not doing this anymore, incrementing refCount in pass15 instead)
+                                                                                       /*if(propertyClass.type == normalClass)
+                                                                                          computed.instance.data = null;*/
                                                                                     }
                                                                                  }
                                                                               }
@@ -3354,7 +3388,7 @@ class CodeEditor : Window
                                                                   else
                                                                      member.variable = true;
                                                                }
-                                                               else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && 
+                                                               else if(ident && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
                                                                   member.initializer.exp.type == memberExp) // identifierExp
                                                                {
                                                                   Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
@@ -3383,7 +3417,7 @@ class CodeEditor : Window
                                                          break;
                                                       }
                                                    }
-                                                }                                          
+                                                }
                                              }
 
                                              designer.PostCreateObject(object.instance, object, false, classObject.instance);
@@ -3437,7 +3471,7 @@ class CodeEditor : Window
          {
             ObjectInfo check;
             int pos = 0;
-         
+
             for(check = this.oClass.instances.first; check; check = check.next)
             {
                if(check.name && !strcmp(check.name, selectedName))
@@ -3506,7 +3540,7 @@ class CodeEditor : Window
       printf("Total MkExternalImport time is %.3f seconds\n\n", externalImportTotalTime);
       printf("Total FindSymbol time is %.3f seconds\n\n", findSymbolTotalTime);
       // printf("Total Class Members Find time is %.3f seconds\n\n", GetClassFindTime());
-      
+
       printf("Whole ParseCode function took %.3f seconds\n\n", GetTime() - parseCodeStart);
 #endif
       if(inUseDebug && ide.projectView)
@@ -3536,17 +3570,17 @@ class CodeEditor : Window
                Class dataType = prop.dataTypeClass;
                if(!dataType)
                   dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
-         
+
                if(dataType)
                {
                   if(dataType.type == structClass)
                   {
                      void * dataForm = new0 byte[dataType.structSize];
                      void * dataTest = new0 byte[dataType.structSize];
-               
+
                      ((void (*)(void *, void *))(void *)prop.Get)(control, dataForm);
                      ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
-               
+
                      if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
                      {
                         char tempString[1024] = "";
@@ -3554,11 +3588,11 @@ class CodeEditor : Window
                         bool needClass = true;
                         if(*prev)
                            f.Printf(", ");
-                  
+
                         ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
-                  
+
                         string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
-                        
+
                         eClass_FindNextMember(_class, curClass, curMember, null, null);
                         if(*curMember != (DataMember)prop)
                            f.Printf("%s = ", prop.name);
@@ -3579,19 +3613,19 @@ class CodeEditor : Window
                   else if(dataType.type == normalClass || dataType.type == noHeadClass)
                   {
                      void * dataForm, * dataTest;
-               
+
                      dataForm = ((void *(*)(void *))(void *)prop.Get)(control);
                      dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
-               
+
                      if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
                      {
                         char tempString[1024] = "";
                         char * string = "";
                         if(*prev)
                            f.Printf(", ");
-                  
+
                         ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
-                  
+
                         eClass_FindNextMember(_class, curClass, curMember, null, null);
                         if(*curMember != (DataMember)prop)
                            f.Printf("%s = ", prop.name);
@@ -3651,16 +3685,16 @@ class CodeEditor : Window
                   else
                   {
                      DataValue dataForm, dataTest;
-               
+
                      GetProperty(prop, control, &dataForm);
                      GetProperty(prop, test, &dataTest);
-               
+
                      if((prop.IsSet && !prop.IsSet(test)) || ((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
                      {
                         char * string;
                         char tempString[1024] = "";
                         SetProperty(prop, test, dataForm);
-                  
+
                         if(dataType.type != bitClass)
                         {
                            bool needClass = true;
@@ -3682,7 +3716,7 @@ class CodeEditor : Window
                            }
                            else
                               string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, &dataForm, tempString, null, &needClass);
-                     
+
                            if(string && string[0])
                            {
                               if(*prev)
@@ -3738,7 +3772,7 @@ class CodeEditor : Window
       Class _class;
       bool lastIsMethod = true;
       ObjectInfo classObject = object.oClass;
-      
+
       if(inst)
       {
          if(object.deleted)
@@ -3780,7 +3814,7 @@ class CodeEditor : Window
                char ch;
                f.Seek(pos - position, current);
                while(f.Getc(&ch))
-               {  
+               {
                   if(isspace(ch))
                   {
                      f.Seek(-1, current);
@@ -3841,12 +3875,12 @@ class CodeEditor : Window
                         position--;
                         if(count > 6)
                         {
-                           toDelete += count - 6; 
+                           toDelete += count - 6;
                            count = 6;
                         }
-                        else 
+                        else
                            toAdd = 6 - count;
-                        break;                              
+                        break;
                      }
                   }
                   if(toDelete)
@@ -3871,7 +3905,7 @@ class CodeEditor : Window
 
          }
       }
-      else 
+      else
       {
          // Instance not there, create a brand new one
          DeleteJunkBefore(f, position, &position);
@@ -3923,7 +3957,7 @@ class CodeEditor : Window
          Class instClass = eSystem_FindClass(this.privateModule, inst._class.name);
 
          DeleteJunkBefore(f, position, &position);
-         
+
          // Instance already there, clear out the properties
          for(members = inst.members->first; members; members = members.next)
          {
@@ -3957,7 +3991,7 @@ class CodeEditor : Window
                            else
                            {
                               Method method = eClass_FindMethod(instClass, ident.string, this.privateModule);
-                              if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp && 
+                              if(method && method.type == virtualMethod && member.initializer && member.initializer.type == expInitializer && member.initializer.exp &&
                                  member.initializer.exp.type == memberExp /*ExpIdentifier*/)
                               {
                                  if(((this.methodAction == actionDetachMethod || this.methodAction == actionReattachMethod) && this.method == method && this.selected == object) ||
@@ -3968,7 +4002,7 @@ class CodeEditor : Window
                                     position = member.loc.end.pos;
                                     deleted = true;
                                  }
-                              }                                          
+                              }
                            }
                         }
                      }
@@ -3980,12 +4014,12 @@ class CodeEditor : Window
                         //f.Seek(member.loc.start.pos - position, current);
                         //position = member.loc.start.pos;
                         DeleteJunkBefore(f, member.loc.start.pos, &position);
-                        if(prev) f.Printf(", "); 
+                        if(prev) f.Printf(", ");
                         else if(keptMember) f.Printf(" ");
                         prev = false;
                      }
-                  } 
-               
+                  }
+
                   if(!keptMember || !members.next)
                   {
                      char ch = 0;
@@ -4017,7 +4051,7 @@ class CodeEditor : Window
 
                      f.Seek(members.loc.end.pos - position, current);
                      f.Getc(&ch);
-            
+
                      if(ch == ';')
                      {
                         f.Seek(-1, current);
@@ -4075,7 +4109,7 @@ class CodeEditor : Window
                      */
                      prev = true;
                      lastIsMethod = false;
-                     
+
                   }
                }
                else
@@ -4093,7 +4127,7 @@ class CodeEditor : Window
                   methodPresent = true;
 
                // Delete instance method here
-               if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) && 
+               if((this.methodAction == actionDeleteMethod || (this.methodAction == actionDetachMethod && this.moveAttached)) &&
                   members.function == function)
                {
                   if(this.moveAttached && !*text)
@@ -4112,7 +4146,7 @@ class CodeEditor : Window
 
                   DeleteJunkBefore(f, members.loc.start.pos, &position);
                   lastIsMethod = true;
-                  f.Printf("\n\n      ");               
+                  f.Printf("\n\n      ");
                }
 
                f.Seek(members.loc.end.pos - position, current);
@@ -4158,7 +4192,7 @@ class CodeEditor : Window
                   memmove(*text + movedFuncIdPos + newLen, *text + movedFuncIdPos + movedFuncIdLen, *textSize - movedFuncIdPos - movedFuncIdLen + 1);
                   *textSize += newLen - movedFuncIdLen;
                   memcpy(*text + movedFuncIdPos, method.name, newLen);
-                                          
+
                   // Second, tab right
                   {
                      int c;
@@ -4188,7 +4222,7 @@ class CodeEditor : Window
                   // ADDING METHOD HERE
                   f.Printf("\n      ");
                   OutputType(f, returnType, false);
-            
+
                   f.Printf(" ");
                   if(dataType.thisClass)
                   {
@@ -4209,7 +4243,7 @@ class CodeEditor : Window
                      if(param.next)
                         f.Printf(", ");
                   }
-                  f.Printf(")\n");                  
+                  f.Printf(")\n");
                   f.Printf("      %c\n\n", OpenBracket);
 
                   if(control._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
@@ -4263,15 +4297,15 @@ class CodeEditor : Window
    {
       Property propIt;
       Class regClass = eSystem_FindClass(privateModule, classObject.name);
-     
+
       if(_class.base && _class.base.type != systemClass) OutputClassProperties(_class.base, classObject, f, test);
-      
+
       for(propIt = _class.membersAndProperties.first; propIt; propIt = propIt.next)
       {
          Property prop = eClass_FindProperty(selected.instance._class, propIt.name, privateModule);
          if(prop && prop.isProperty && !prop.conversion)
          {
-            if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) && 
+            if(prop.Set && prop.Get && prop.dataTypeString && strcmp(prop.name, "name") && !Code_IsPropertyDisabled(classObject, prop.name) &&
                (!prop.IsSet || prop.IsSet(classObject.instance)))
             {
                Class dataType = prop.dataTypeClass;
@@ -4286,19 +4320,19 @@ class CodeEditor : Window
 
                if(!dataType)
                   dataType = prop.dataTypeClass = eSystem_FindClass(this.privateModule, prop.dataTypeString);
-            
+
                if(dataType && dataType.type == structClass)
                {
                   void * dataForm = new0 byte[dataType.structSize];
                   void * dataTest = new0 byte[dataType.structSize];
-               
+
                   ((void (*)(void *, void *))(void *)prop.Get)(classObject.instance, dataForm);
                   ((void (*)(void *, void *))(void *)prop.Get)(test, dataTest);
 
                   if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
                   {
                      bool needClass = true;
-                     
+
                      string = ((char * (*)(void *, void *, void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, dataForm, tempString, null, &needClass);
                      ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
                      if(needClass)
@@ -4312,16 +4346,16 @@ class CodeEditor : Window
                else if(dataType && (dataType.type == normalClass || dataType.type == noHeadClass))
                {
                   void * dataForm, * dataTest;
-               
+
                   dataForm = ((void *(*)(void *))(void *)prop.Get)(classObject.instance);
                   dataTest = ((void *(*)(void *))(void *)prop.Get)(test);
-               
+
                   if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, dataForm, dataTest))
                   {
                      char tempString[1024] = "";
                      char * string;
                      ((void (*)(void *, void *))(void *)prop.Set)(test, dataForm);
-                  
+
                      if(eClass_IsDerived(classObject.instance._class, dataType) && classObject.instance == dataForm)
                      {
                         // Shouldn't go here ...
@@ -4349,10 +4383,10 @@ class CodeEditor : Window
                else if(dataType)
                {
                   DataValue dataForm, dataTest;
-               
+
                   GetProperty(prop, classObject.instance, &dataForm);
                   GetProperty(prop, test, &dataTest);
-               
+
                   if(((int (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCompare])(dataType, &dataForm, &dataTest))
                   {
                      SetProperty(prop, test, dataForm);
@@ -4390,7 +4424,7 @@ class CodeEditor : Window
                         else if(string[0])
                            f.Printf("\n   %s%s = %s;", specify ? "property::" : "", prop.name, string);
                      }
-                  }                                          
+                  }
                }
             }
          }
@@ -4401,7 +4435,7 @@ class CodeEditor : Window
    {
       if(!this) return;
       if(!parsing) return;
-         
+
       updatingCode++;
       if(codeModified)
       {
@@ -4413,7 +4447,7 @@ class CodeEditor : Window
          int position = 0;
          char * text = null;
          int textSize;
-         Identifier movedFuncId; 
+         Identifier movedFuncId;
          int movedFuncIdLen = 0, movedFuncIdPos = 0;
          ObjectInfo classObject;
 
@@ -4444,7 +4478,7 @@ class CodeEditor : Window
 
             // Put it in the same desktop window...
             designer.PrepareTestObject(test);
-            
+
             //f.Printf("class %s : %s\n", classObject.name, classObject.oClass.name);
             //f.Printf("%c\n\n", OpenBracket);
 
@@ -4461,7 +4495,7 @@ class CodeEditor : Window
                int back = 0;
                f.Seek(classDef.blockStart.end.pos - position, current);
                position = classDef.blockStart.end.pos;
-               
+
                for(; f.Getc(&ch); count++)
                {
                   if(!isspace(ch))
@@ -4469,15 +4503,15 @@ class CodeEditor : Window
                      f.Seek(-1, current);
                      break;
                   }
-               
+
                   if(ch == '\n')
                      back = 0;
                   else
                      back++;
                }
-            
+
                f.Seek(-count, current);
-            
+
                f.DeleteBytes(count-back);
                //f.Printf("\n");
                position += count-back;
@@ -4495,7 +4529,7 @@ class CodeEditor : Window
                      bool keptMember = false;
                      MemberInit propDef;
                      MemberInit lastKept = null;
-                     
+
                      lastIsDecl = false;
                      DeleteJunkBefore(f, def.loc.start.pos, &position);
                      f.Printf("\n   ");
@@ -4531,7 +4565,7 @@ class CodeEditor : Window
                                        position = propDef.loc.end.pos;
                                        deleted = true;
                                     }
-                                 }                                          
+                                 }
                               }
                            }
                         }
@@ -4541,14 +4575,14 @@ class CodeEditor : Window
                            lastKept = propDef;
                         }
                      }
-                  
+
                      if(!keptMember)
                      {
                         char ch = 0;
                         int count = 0;
                         f.Seek(def.loc.end.pos - position - 1, current);
                         f.Getc(&ch);
-                        
+
                         if(ch == ';')
                         {
                            f.Seek(-1, current);
@@ -4562,7 +4596,7 @@ class CodeEditor : Window
                         {
                            char ch;
                            int count = 0;
-                           
+
                            f.Seek(-1, current);
                            for(;f.Getc(&ch);)
                            {
@@ -4585,7 +4619,7 @@ class CodeEditor : Window
                         {
                            f.Seek(def.loc.end.pos - position, current);
                            position = def.loc.end.pos;
-                        }                
+                        }
                      }
                      break;
                   }
@@ -4640,7 +4674,7 @@ class CodeEditor : Window
                      f.Printf("\n\n   ");
 
                      // Delete _class methods
-                     if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) && 
+                     if((methodAction == actionDeleteMethod || (moveAttached && selected != classObject)) &&
                         def.function == function)
                      {
                         char ch;
@@ -4675,7 +4709,7 @@ class CodeEditor : Window
                         position = function.loc.start.pos + movedFuncIdPos + movedFuncIdLen;
                      }
 
-                     if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached && 
+                     if((methodAction == actionAttachMethod || methodAction == actionReattachMethod) && selected == classObject && moveAttached &&
                         function == def.function)
                      {
                         // In case of attaching methods in the _class, simply rename the method
@@ -4697,7 +4731,7 @@ class CodeEditor : Window
                         firstObject = false;
                         lastIsDecl = true;
                      }
-                     else           
+                     else
                      {
                         f.Printf("\n   ");
                         lastIsDecl = false;
@@ -4714,7 +4748,7 @@ class CodeEditor : Window
                DeleteJunkBefore(f, position, &position);
                f.Printf("\n   %s = %s;\n", method.name, function.declarator.symbol.string);
             }
-            
+
             // ********** INSTANCES ***************
             for(; object; object = object.next)
             {
@@ -4778,7 +4812,7 @@ class CodeEditor : Window
                   f.Printf("\n\n");
                   f.Printf("   ");
                   OutputType(f, returnType, false);
-               
+
                   f.Printf(" ");
                   if(dataType.thisClass && !dataType.classObjectType)
                   {
@@ -4796,7 +4830,7 @@ class CodeEditor : Window
                      if(param.next)
                         f.Printf(", ");
                   }
-                  f.Printf(")\n");                  
+                  f.Printf(")\n");
                   f.Printf("   %c\n\n", OpenBracket);
 
                   if(test._class._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad]) // Temp Check for DefaultFunction
@@ -4861,7 +4895,7 @@ class CodeEditor : Window
       if(methodName)
       {
          ObjectInfo object = this.selected;
-         
+
          if(object && object == this.oClass)
          {
             ClassDefinition classDef = object.oClass.classDefinition;
@@ -5119,7 +5153,7 @@ class CodeEditor : Window
                   {
                      if(!testMethod.dataType)
                         testMethod.dataType = ProcessTypeString(testMethod.dataTypeString, false);
-                        
+
                      //if(CheckCompatibleMethod(method, testMethod.dataType, &regClass, false, selectedClass)) // this.selected == this.oClass, selectedClass))
                      if(CheckCompatibleMethod(method, testMethod.dataType, this.oClass.instance._class, false, selectedClass)) // this.selected == this.oClass, selectedClass))
                      //if(CheckCompatibleMethod(method, testMethod.dataType, &regClass, this.selected == this.oClass, FindClass(this.oClass.oClass.name)))
@@ -5155,7 +5189,7 @@ class CodeEditor : Window
             this.method = method;
             ModifyCode();
          }
-         UpdateFormCode();         
+         UpdateFormCode();
          GoToMethod(methodName);
       }
    }
@@ -5167,7 +5201,7 @@ class CodeEditor : Window
          methodAction = actionDeleteMethod;
          this.function = function;
          ModifyCode();
-         UpdateFormCode(); 
+         UpdateFormCode();
 
          Update(null);
       }
@@ -5209,7 +5243,7 @@ class CodeEditor : Window
          this.method = method;
          this.function = function;
          ModifyCode();
-         UpdateFormCode(); 
+         UpdateFormCode();
          Update(null);
       }
    }
@@ -5239,7 +5273,7 @@ class CodeEditor : Window
             {
                char title[1024];
                sprintf(title, $"Attach %s", function.declarator.symbol.string);
-               if(MessageBox { type = yesNo, master = parent, text = title, 
+               if(MessageBox { type = yesNo, master = parent, text = title,
                   contents = $"Method is unused. Move method inside instance?" }.Modal() == yes)
                {
                   moveAttached = true;
@@ -5251,7 +5285,7 @@ class CodeEditor : Window
          this.method = method;
          this.function = function;
          ModifyCode();
-         UpdateFormCode(); 
+         UpdateFormCode();
          Update(null);
       }
    }
@@ -5264,7 +5298,7 @@ class CodeEditor : Window
       {
          Window dialog
          {
-            hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 }, 
+            hasClose = true, borderStyle = sizable, minClientSize = { 300, 55 },
             master = sheet, text = $"Name detached method", background = formColor
          };
          Button cancelButton
@@ -5310,7 +5344,7 @@ class CodeEditor : Window
                strcat(name, this.methodName);
                strcpy(this.methodName, name);
             }
-            
+
             this.moveAttached = true;
          }
 
@@ -5318,7 +5352,7 @@ class CodeEditor : Window
          this.method = method;
          this.function = function;
          ModifyCode();
-         UpdateFormCode(); 
+         UpdateFormCode();
          Update(null);
       }
    }
@@ -5338,11 +5372,11 @@ class CodeEditor : Window
          ObjectInfo check;
          sprintf(name, "%c%s%d", tolower(instance._class.name[0]), instance._class.name+1, id);
 
-         // if(strcmp(name, this.oClass.instance.name)) 
-         
+         // if(strcmp(name, this.oClass.instance.name))
+
          {
             for(check = oClass.instances.first; check; check = check.next)
-               if(!check.deleted && check.name && !strcmp(name, check.name)) 
+               if(!check.deleted && check.name && !strcmp(name, check.name))
                   break;
             if(!check)
             {
@@ -5350,7 +5384,7 @@ class CodeEditor : Window
                break;
             }
          }
-      }            
+      }
       toolBox.controlClass = null;
 
       ModifyCode();
@@ -5416,9 +5450,9 @@ class CodeEditor : Window
          ObjectInfo select = object;
 
          for(;;)
-         {            
+         {
             select = select.prev;
-            if(!select) 
+            if(!select)
             {
                if(looped) break;
                select = object.oClass.instances.last;
@@ -5502,7 +5536,7 @@ class CodeEditor : Window
                BitmapResource bitmap = null;
                if(!subMember.dataType)
                   subMember.dataType = ProcessTypeString(subMember.dataTypeString, false);
-            
+
                if(subMember.dataType && subMember.dataType.kind == classType && subMember.dataType._class)
                {
                   char * bitmapName = (char *)eClass_GetProperty(subMember.dataType._class.registered, "icon");
@@ -5596,11 +5630,11 @@ class CodeEditor : Window
                   else if(member.name && !membersList.FindString(member.name))
                   {
                      DataRow row = membersList.AddString(member.name);
-               
+
                      BitmapResource bitmap = null;
                      if(!member.dataType)
                         member.dataType = ProcessTypeString(member.dataTypeString, false);
-               
+
                      if(member.dataType && member.dataType.kind == classType && member.dataType._class)
                      {
                         char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
@@ -5711,11 +5745,11 @@ class CodeEditor : Window
                else if(member.name && (!curString || strcmp(curString, member.name)))
                {
                   DataRow row = membersList.AddString(member.name);
-               
+
                   BitmapResource bitmap = null;
                   if(!member.dataType)
                      member.dataType = ProcessTypeString(member.dataTypeString, false);
-               
+
                   if(member.dataType && member.dataType.kind == classType && member.dataType._class)
                   {
                      char * bitmapName = (char *)eClass_GetProperty(member.dataType._class.registered, "icon");
@@ -5744,7 +5778,7 @@ class CodeEditor : Window
       if(type && (type.kind == classType || type.kind == structType || type.kind == unionType))
       {
          Class _class;
-         
+
          if(type.kind == classType)
          {
             if(type._class)
@@ -5790,7 +5824,7 @@ class CodeEditor : Window
          for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
          {
             Class _class = link.data;
-            if(_class.type != systemClass)
+            if(_class.type != systemClass && !_class.templateClass)  // Omit templatized classes
             {
                DataRow row = membersList.AddString(_class.name);
                row.icon = (_class.type == unitClass || _class.type == enumClass) ? icons[typeDataType] : icons[typeClass];
@@ -5890,7 +5924,8 @@ class CodeEditor : Window
       for(link = (BTNamedLink)nameSpace.classes.first; link; link = (BTNamedLink)((BTNode)link).next)
       {
          Class _class = link.data;
-         if(_class.type == enumClass && (dest.kind != classType || !dest._class || dest._class.registered != _class))
+         if(_class.type == enumClass && (dest.kind != classType || ((!dest._class || !dest._class.registered || (dest._class.registered != _class && strcmp(dest._class.registered.dataTypeString, "char *"))) && !dest.classObjectType)) &&
+            dest.kind != pointerType && dest.kind != ellipsisType)
          {
             OldList conversions { };
             Type type { };
@@ -6020,9 +6055,9 @@ class CodeEditor : Window
       {
          DataRow row = membersList.FindSubString(string);
          if(!row)
-            listedEnums = false;      
+            listedEnums = false;
       }
-      
+
       if(!insideClass && exp && exp.destType && exp.destType.kind == functionType && GetThisClass())
       {
          ListClassMembersMatch(GetThisClass(), exp.destType);
@@ -6033,7 +6068,7 @@ class CodeEditor : Window
          Symbol symbol = null;
          {
             if(GetThisClass())
-            { 
+            {
                ListClassMembers(GetThisClass(), false);
             }
 
@@ -6055,7 +6090,7 @@ class CodeEditor : Window
                      {
                         row.icon = icons[typeEnumValue];
                      }
-                     else 
+                     else
                      {
                         BitmapResource bitmap = null;
                         if(symbol.type && symbol.type.kind == classType && symbol.type._class && symbol.type._class)
@@ -6113,7 +6148,7 @@ class CodeEditor : Window
                      {
                         row.icon = icons[typeEnumValue];
                      }
-                     else 
+                     else
                      {
                         BitmapResource bitmap = null;
                         if(data.dataType && data.dataType.kind == classType && data.dataType._class && data.dataType._class)
@@ -6180,7 +6215,7 @@ class CodeEditor : Window
          OutputType(f, returnType, false);
 
          f.Printf(" ");
-         
+
          if(dataType.thisClass && !dataType.classObjectType && (!isInstance || !insideClass || !eClass_IsDerived(insideClass, dataType.thisClass.registered)))
          {
             if(dataType.thisClass.shortName)
@@ -6201,7 +6236,7 @@ class CodeEditor : Window
                   f.Printf(", ");
             }
          }
-         f.Printf(")\n");                  
+         f.Printf(")\n");
          if(extraIndent) f.Printf("   ");
          f.Printf("   %c\n", OpenBracket);
 
@@ -6209,7 +6244,7 @@ class CodeEditor : Window
 
          f.Printf("\n");
 
-         if(!_class || 
+         if(!_class ||
             (
                (isInstance ? _class : _class.base)._vTbl[method.vid] == moduleClass._vTbl[__ecereVMethodID___ecereNameSpace__ecere__com__Module_OnLoad] ||
                (isInstance ? _class : _class.base)._vTbl[method.vid] == DummyMethod)) // Temp Check for DefaultFunction
@@ -6281,7 +6316,7 @@ class CodeEditor : Window
       }
 
       editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
-      { 
+      {
          EditBoxStream f { editBox = editBox };
 
          updatingCode = true;
@@ -6312,7 +6347,7 @@ class CodeEditor : Window
          else if(!pointer)
          {
             editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
-            { 
+            {
                EditBoxStream f { editBox = editBox };
                char ch = 0;
 
@@ -6577,7 +6612,7 @@ class CodeEditor : Window
                         editBox.SetSelPos(l1, y1, idStart.charPos-1, l2, y2, idStart.charPos-1);
                      editBox.GetCaretPosition(caret);
                      editBox.SetSelPos(l1, y1, x1, l2, y2, x2);
-               
+
                      membersList.master = this;
 
                      caret.y += editBox.GetCaretSize();
@@ -6624,7 +6659,7 @@ class CodeEditor : Window
                   }
                   if(row)
                      membersList.SetScrollPosition(0, row.index * membersList.rowHeight);
-               }            
+               }
             }
          }
       }
@@ -6650,7 +6685,7 @@ class CodeEditor : Window
       EnsureUpToDate();
 
       editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
-      { 
+      {
          EditBoxStream f { editBox = editBox };
          char ch;
 
@@ -6685,7 +6720,7 @@ class CodeEditor : Window
          delete f;
          updatingCode = false;
       }
-      
+
       charPos = Min(charPos, l1.count + 1);
       if(!caretMove)
          FindParamsTree(ast, lineNum, charPos);
@@ -6707,7 +6742,7 @@ class CodeEditor : Window
          if(this.functionType != ::functionType || this.instanceType != ::instanceType)
             reposition = false;
 
-         if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition... 
+         if(!this.paramsShown || reposition || paramsInsideExp != functionExp || ::instanceType) // Added instanceType here, otherwise instance popups never reposition...
                                                                                                           // ( Dummy exp: always ends up with same memory)
          {
             editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false);
@@ -6791,3 +6826,38 @@ CodeEditor NewCodeEditor(Window parent, WindowState state, bool modified)
    document.Create();
    return document;
 }
+
+static int nofdigits(int v)
+{
+   if(v == MININT) return 10 + 1;
+   if(v < 0) return nofdigits(-v) + 1;
+   if(v >= 10000)
+   {
+      if(v >= 10000000)
+      {
+         if(v >= 100000000)
+         {
+            if(v >= 1000000000)
+               return 10;
+            return 9;
+         }
+         return 8;
+      }
+      if(v >= 100000)
+      {
+         if(v >= 1000000)
+            return 7;
+         return 6;
+      }
+      return 5;
+   }
+   if(v >= 100)
+   {
+      if(v >= 1000)
+         return 4;
+      return 3;
+   }
+   if(v >= 10)
+      return 2;
+   return 1;
+}