ide/CodeEditor: Customizable color scheme support
[sdk] / ide / src / panels / OutputView.ec
index fcef578..db7e1a3 100644 (file)
@@ -15,23 +15,23 @@ class OutputView : Window
    borderStyle = sizable;
    hasClose = true;
    mergeMenus = false;
-   text = "Output";
+   text = $"Output";
    menu = Menu { };
    anchor = Anchor { left = 0, right = 0, bottom = 0 };
    size.h = 240;
-   background = activeBorder;
+   background = formColor;
 
-   virtual void OnGotoError(char * line);
-   virtual void OnCodeLocationParseAndGoTo(char * line);
+   virtual void OnGotoError(const char * line, bool noParsing);
+   virtual void OnCodeLocationParseAndGoTo(const char * line);
 
-   FindDialog findDialog { master = this, editBox = buildBox, isModal = true, autoCreate = false, text = "Find" };
+   FindDialog findDialog { master = this, editBox = buildBox, isModal = true, autoCreate = false, text = $"Find" };
 
    Button buildBtn
    {
-      this, inactive = true, text = "Build", bevelOver = true, isRadio = true, bitmap = null, checked = true;
+      this, inactive = true, text = $"Build", bevelOver = true, isRadio = true, bitmap = null, checked = true;
       size = { 99, 20 };
       anchor = { left = 0, top = 1 };
-      font = { "Tahoma", 8.25f, bold = true };
+      font = { $"Tahoma", 8.25f, bold = true };
 
       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
       {
@@ -39,10 +39,10 @@ class OutputView : Window
          return true;
       }
    };
-   
+
    Button debugBtn
    {
-      this, inactive = true, text = "Debug", bevelOver = true, isRadio = true, bitmap = null;
+      this, inactive = true, text = $"Debug", bevelOver = true, isRadio = true, bitmap = null;
       size = { 99, 20 };
       anchor = { left = 100, top = 1 };
 
@@ -52,10 +52,10 @@ class OutputView : Window
          return true;
       }
    };
-   
+
    Button findBtn
    {
-      this, inactive = true, text = "Find", bevelOver = true, isRadio = true, bitmap = null;
+      this, inactive = true, text = $"Find", bevelOver = true, isRadio = true, bitmap = null;
       size = { 99, 20 };
       anchor = { left = 200, top = 1 };
 
@@ -83,7 +83,7 @@ class OutputView : Window
 
    void SelectTab(OutputViewTab tab)
    {
-      Button activeBtn;
+      Button activeBtn = null;
       if(tab == build)
          activeBtn = buildBtn, activeBox = buildBox;
       else if(tab == debug)
@@ -94,77 +94,105 @@ class OutputView : Window
       else if(tab == gdb)
          activeBtn = gdbBtn, activeBox = gdbBox;
 #endif
-
-      activeBtn.checked = true;
-      activeBtn.font = { "Tahoma", 8.25f, bold = true };
-      if(buildBtn != activeBtn) buildBtn.font = null;
-      if(debugBtn != activeBtn) debugBtn.font = null;
-      if(findBtn != activeBtn) findBtn.font = null;
+      if(activeBtn && activeBox)
+      {
+         activeBtn.checked = true;
+         activeBtn.font = { $"Tahoma", 8.25f, bold = true };
+         if(buildBtn != activeBtn) buildBtn.font = null;
+         if(debugBtn != activeBtn) debugBtn.font = null;
+         if(findBtn != activeBtn) findBtn.font = null;
 #ifdef GDB_DEBUG_OUTPUT
-      if(gdbBtn != activeBtn) gdbBtn.font = null;
+         if(gdbBtn != activeBtn) gdbBtn.font = null;
 #endif
 
-      activeBox.visible = false;
-      activeBtn.Activate();      // Ensure proper cycling (until tab order?)
-      activeBox.visible = true;
-      activeBox.Activate();
-      findDialog.editBox = activeBox;
+         activeBox.visible = false;
+         activeBtn.Activate();      // Ensure proper cycling (until tab order?)
+         activeBox.visible = true;
+         activeBox.Activate();
+         findDialog.editBox = activeBox;
+      }
    }
 
    EditBox activeBox;
-   
+   activeBox = buildBox;
+
    LogBox buildBox
    {
       parent = this, freeCaret = true, autoEmpty = true, multiLine = true;
       readOnly = true, hasVertScroll = true, hasHorzScroll = true;
       anchor = Anchor { left = 0, right = 0, top = 23, bottom = 0 };
-      font = { panelFont.faceName, panelFont.size };
-      background = outputBackground;
-      foreground = outputText;
-      selectionColor = selectionColor, selectionText = selectionText;
-      
+      /*
+      font = { panelFont.faceName, panelFont.size, panelFont.bold, panelFont.italic };
+      background = colorScheme.outputBackground;
+      foreground = colorScheme.outputText;
+      selectionColor = colorScheme.selectionColor;
+      selectionText = colorScheme.selectionText;
+      */
+
       bool NotifyDoubleClick(EditBox editBox, EditLine line, Modifiers mods)
       {
-         OnGotoError(editBox.line.text);
-         return false; //true; // why not use true here? 
+         OnGotoError(editBox.line.text, mods.ctrl && mods.shift);
+         return false;
       }
 
       bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
       {
-         if((SmartKey)key == enter)
+         if(key.code == enter || key.code == keyPadEnter)
          {
-            OnGotoError(editBox.line.text);
+            OnGotoError(editBox.line.text, key.ctrl && key.shift);
             return false;
          }
          return true;
       }
    };
-   
+
    LogBox debugBox
    {
       parent = this, freeCaret = true, autoEmpty = true, multiLine = true;
       readOnly = true, hasVertScroll = true, hasHorzScroll = true, visible = false;
       anchor = Anchor { left = 0, right = 0, top = 23, bottom = 0 };
-      font = { panelFont.faceName, panelFont.size };
-      background = outputBackground;
-      foreground = outputText;
-      selectionColor = selectionColor, selectionText = selectionText;
+      /*
+      font = { panelFont.faceName, panelFont.size, panelFont.bold, panelFont.italic };
+      background = colorScheme.outputBackground;
+      foreground = colorScheme.outputText;
+      selectionColor = colorScheme.selectionColor;
+      selectionText = colorScheme.selectionText;
+      */
+
+      bool NotifyDoubleClick(EditBox editBox, EditLine line, Modifiers mods)
+      {
+         OnCodeLocationParseAndGoTo(editBox.line.text);
+         return false;
+      }
+
+      bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
+      {
+         if((SmartKey)key == enter)
+         {
+            OnCodeLocationParseAndGoTo(editBox.line.text);
+            return false;
+         }
+         return true;
+      }
    };
-   
+
    LogBox findBox
    {
       parent = this, freeCaret = true, autoEmpty = true, multiLine = true;
       readOnly = true, hasVertScroll = true, hasHorzScroll = true, visible = false;
       anchor = Anchor { left = 0, right = 0, top = 23, bottom = 0 };
-      font = { panelFont.faceName, panelFont.size };
-      background = outputBackground;
-      foreground = outputText;
-      selectionColor = selectionColor, selectionText = selectionText;
+      /*
+      font = { panelFont.faceName, panelFont.size, panelFont.bold, panelFont.italic };
+      background = colorScheme.outputBackground;
+      foreground = colorScheme.outputText;
+      selectionColor = colorScheme.selectionColor;
+      selectionText = colorScheme.selectionText;
+      */
 
       bool NotifyDoubleClick(EditBox editBox, EditLine line, Modifiers mods)
       {
          OnCodeLocationParseAndGoTo(editBox.line.text);
-         return false; //true;
+         return false;
       }
 
       bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
@@ -184,16 +212,20 @@ class OutputView : Window
       parent = this, freeCaret = true, autoEmpty = true, multiLine = true;
       readOnly = true, hasVertScroll = true, hasHorzScroll = true, visible = false;
       anchor = Anchor { left = 0, right = 0, top = 23, bottom = 0 };
-      font = { panelFont.faceName, panelFont.size };
+      font = { panelFont.faceName, panelFont.size, panelFont.bold, panelFont.italic };
+      background = colorScheme.outputBackground;
+      foreground = colorScheme.outputText;
+      selectionColor = colorScheme.selectionColor;
+      selectionText = colorScheme.selectionText;
    };
 #endif
-   
-   Menu editMenu { menu, "Edit", e };
+
+   Menu editMenu { menu, $"Edit", e };
 
    MenuItem item;
    MenuItem copyItem
    {
-      editMenu, "Copy", c, ctrlC;
+      editMenu, $"Copy", c, ctrlC;
       bool NotifySelect(MenuItem selection, Modifiers mods)
       {
          activeBox.Copy();
@@ -201,17 +233,17 @@ class OutputView : Window
       }
    };
    MenuDivider { editMenu };
-   MenuItem { editMenu, "Find Previous", e, Key { f3, shift = true }, NotifySelect = MenuEditFind, id = 0 };
-   MenuItem { editMenu, "Find Next", n, f3, NotifySelect = MenuEditFind, id = 1 };
-   MenuItem { editMenu, "Find", f, ctrlF, NotifySelect = MenuEditFind, id = 2 };
+   MenuItem { editMenu, $"Find Previous", e, Key { f3, shift = true }, NotifySelect = MenuEditFind, id = 0 };
+   MenuItem { editMenu, $"Find Next", n, f3, NotifySelect = MenuEditFind, id = 1 };
+   MenuItem { editMenu, $"Find", f, ctrlF, NotifySelect = MenuEditFind, id = 2 };
 
    bool MenuEditFind(MenuItem selection, Modifiers mods)
    {
-      int id = selection.id;
-      char * searchString = findDialog.searchString;
+      int64 id = selection.id;
+      const char * searchString = findDialog.searchString;
       if(id != 2 && searchString[0])
       {
-         activeBox.Find(searchString, findDialog.wholeWord, findDialog.matchCase, id);
+         activeBox.Find(searchString, findDialog.wholeWord, findDialog.matchCase, id != 0);
          return true;
       }
       findDialog.Create();
@@ -221,6 +253,7 @@ class OutputView : Window
    void Show()
    {
       visible = true;
+      ide.RepositionWindows(false);
       Activate();
    }
    void ShowClearSelectTab(OutputViewTab tab)
@@ -247,7 +280,7 @@ class OutputView : Window
       {
          case shiftTab:
          {
-            OutputViewTab switchTo;
+            OutputViewTab switchTo = build;
             if(activeBox == buildBox)
 #ifdef GDB_DEBUG_OUTPUT
                switchTo = gdb;
@@ -267,7 +300,7 @@ class OutputView : Window
          }
          case tab:
          {
-            OutputViewTab switchTo;
+            OutputViewTab switchTo = debug;
             if(activeBox == buildBox)
                switchTo = debug;
             else if(activeBox == debugBox)
@@ -290,54 +323,47 @@ class LogBox : EditBox
 {
    bool moved, logging, tell;
 
-   void Logf(char * format, ...)
+   void Logf(const char * format, ...)
    {
       char string[MAX_F_STRING*10];
-
       va_list args;
       va_start(args, format);
-      vsprintf(string, format, args);
+      vsnprintf(string, sizeof(string), format, args);
+      string[sizeof(string)-1] = 0;
       va_end(args);
 
       LogRaw(string);
    }
 
-   void LogSprintf(char * entry)
-   {
-      char string[MAX_F_STRING];
-      sprintf(string, entry);
-      LogRaw(string);
-   }
-
-   void LogRaw(char * entry)
+   void LogRaw(const char * entry)
    {
       // Cut the line longer than 1024 because Logf prints to a buffer (and we don't want to output crazy long lines either)
       //if(len > 1023) line[1023] = '\0';
-      int len = strlen(entry);
+      /* Fixed, but disabled this ... Not sure if there's any reason to keep it? The EditBox should be fine with long lines
+         and it's easier to copy commands and go to errors */
+      /*int len = strlen(entry);
       if(len > 1023)
       {
-         char backup[4];
          char * newStart, * start = entry;
-         
+
          while(len > 1023)
          {
+            char backup[3];
             newStart = start + 1020;
-            strncpy(backup, newStart, 4);
-            strncpy(newStart, " \\ \0", 4);
+            strncpy(backup, newStart, 3);
+            strncpy(newStart, "\n ", 3);
             Log(start);
-            strncpy(newStart, backup, 4);
+            strncpy(newStart, backup, 3);
             start = newStart;
             len = strlen(start);
          }
-         
-         //while((len = strlen(start)) > 1023)
-         
+         Log(start);
       }
-      else
+      else*/
          Log(entry);
    }
 
-   void Log(char * string)
+   void Log(const char * string)
    {
       int x1, y1, x2, y2;
       Point scrl;
@@ -365,19 +391,19 @@ class LogBox : EditBox
       logging = false;
    }
 
-   void Tellf(char * format, ...)
+   void Tellf(const char * format, ...)
    {
       char string[MAX_F_STRING*10];
-
       va_list args;
       va_start(args, format);
-      vsprintf(string, format, args);
+      vsnprintf(string, sizeof(string), format, args);
+      string[sizeof(string)-1] = 0;
       va_end(args);
 
       Tell(string);
    }
 
-   void Tell(char * string)
+   void Tell(const char * string)
    {
       Log(string);
       if(!moved)