wip II
[sdk] / ide / src / designer / CodeEditor.ec
index 98077bf..8704e27 100644 (file)
@@ -31,13 +31,13 @@ SyntaxColorScheme colorScheme
 */
 
 // The new nice dark scheme -- so peaceful on my brain
-
+/*
 FontResource panelFont { $"Courier New", 10 };
 FontResource codeFont { $"Courier New", 10 };
-/*
+*/
 FontResource panelFont { $"Consolas", 12 };
 FontResource codeFont { $"Consolas", 12 };
-*/
+
 Color selectionColor = lightYellow;
 Color selectionText = Color { 30, 40, 50 };
 Color viewsBackground = Color { 30, 40, 50 };
@@ -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()
@@ -685,7 +693,7 @@ class CodeEditor : Window
 
    bool noParsing;
 
-   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)
    {
@@ -790,7 +798,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;
@@ -1378,7 +1386,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,9 +1401,9 @@ 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;
@@ -1497,37 +1505,48 @@ class CodeEditor : Window
             (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 
             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)
       {
@@ -1593,16 +1612,17 @@ class CodeEditor : Window
       
       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)
       {
@@ -1901,50 +1921,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 +1965,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 +2004,8 @@ class CodeEditor : Window
             if(CloseConfirmation(false))
             {
                visible = false;
-               OnFileModified({ modified = true }, null);
+               if(modifiedDocument)
+                  OnFileModified({ modified = true }, null);
             }
             debugClosing = false;
             return false;
@@ -2102,7 +2087,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 +2106,7 @@ class CodeEditor : Window
       */
       if(active && directActivation)
       {
+         AdjustDebugMenus();
          if(openedFileInfo)
             openedFileInfo.Activate();
          if(designer)
@@ -2172,6 +2158,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;
    }
 
@@ -2197,7 +2202,7 @@ class CodeEditor : Window
          editBox.Save(f, false);
          modifiedDocument = false;
          
-         delete(f);
+         delete f;
          return true;
       }
       return false;
@@ -2207,7 +2212,7 @@ class CodeEditor : Window
    {
       bool reload = false;
       if(visible == false && inUseDebug == true)
-         reload = true;
+         ide.debugger.WatchesReleaseCodeEditor();
       else
       {
          char message[2048];
@@ -2250,7 +2255,7 @@ class CodeEditor : Window
             }
             modifiedDocument = false;
 
-            delete(f);
+            delete f;
          }
       }
       return true;
@@ -2364,16 +2369,20 @@ 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;
          {
             int spaceW;
             display.FontExtent(font.font, " ", 1, &spaceW, null);
@@ -2412,18 +2421,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 +2464,7 @@ class CodeEditor : Window
          designer.fileName = title;
       }
 
-      DebugMenusDisabled();
+      AdjustDebugMenus();
 
       for(c = 0; c < CodeObjectType::enumSize; c++)
          icons[c] = BitmapResource { iconNames[c], window = this };
@@ -4401,7 +4422,7 @@ class CodeEditor : Window
    {
       if(!this) return;
       if(!parsing) return;
-         
+
       updatingCode++;
       if(codeModified)
       {
@@ -5790,7 +5811,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 +5911,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 { };