Author Topic: Two problems with r8232  (Read 17637 times)

Offline ouch

  • Almost regular
  • **
  • Posts: 223
Re: Two problems with r8232
« Reply #15 on: August 15, 2012, 09:10:55 pm »
I suffered from the grey plague as well... :) Simply hitting the "Reset Defaults" button and saving the changes seemed to fix the conf file. The only thing I change from the defaults is changing the comment colors to grey. That grey-ish blue color messes with my brain... lol

oh, and I'm all for making progress on the lexers, so I say keep the changes even if it breaks everything.
« Last Edit: August 15, 2012, 09:13:11 pm by ouch »

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Two problems with r8232
« Reply #16 on: August 16, 2012, 03:32:40 am »
This patch should fix (almost) all custom color scheme loading problems.  It also adds evaluation of back-ticked expressions during define collection, and enables preprocessor interpretation by default (it is fine if this last part is left out, however, having tested it on both Windows and Linux now, I think most users would likely prefer it on).
Code
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp (revision 8236)
+++ src/sdk/cbeditor.cpp (working copy)
@@ -1576,7 +1576,7 @@
     ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
 
     // Interpret #if/#else/#endif to grey out code that is not active
-    control->SetProperty(_T("lexer.cpp.track.preprocessor"), mgr->ReadBool(_T("/track_preprocessor"), false) ? _T("1") : _T("0"));
+    control->SetProperty(_T("lexer.cpp.track.preprocessor"), mgr->ReadBool(_T("/track_preprocessor"), true) ? _T("1") : _T("0"));
 
     // code folding
     if (mgr->ReadBool(_T("/folding/show_folds"), true))
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp (revision 8236)
+++ src/sdk/editormanager.cpp (working copy)
@@ -3045,8 +3045,8 @@
 {
     cbProject* prj = Manager::Get()->GetProjectManager()->GetActiveProject();
     if (   !prj
-        || !Manager::Get()->GetConfigManager(wxT("editor"))->ReadBool(wxT("/track_preprocessor"), false)
-        || !Manager::Get()->GetConfigManager(wxT("editor"))->ReadBool(wxT("/collect_prj_defines"), false) )
+        || !Manager::Get()->GetConfigManager(wxT("editor"))->ReadBool(wxT("/track_preprocessor"),  true)
+        || !Manager::Get()->GetConfigManager(wxT("editor"))->ReadBool(wxT("/collect_prj_defines"), true) )
     {
         event.Skip();
         return;
@@ -3067,13 +3067,39 @@
         lst = &prj->GetFilesList();
         id  = prj->GetCompilerID();
     }
+    Compiler* comp = CompilerFactory::GetCompiler(id); // get global flags
+    if (comp)
+        AppendArray(comp->GetCompilerOptions(), compilerFlags);
 
     wxArrayString defines;
     for (size_t i = 0; i < compilerFlags.Count(); ++i)
     {
-        if (   (compilerFlags[i].Left(2) == wxT("-D"))
-            || (compilerFlags[i].Left(2) == wxT("/D")) )
+        if (   compilerFlags[i].StartsWith(wxT("-D"))
+            || compilerFlags[i].StartsWith(wxT("/D")) )
+        {
             defines.Add(compilerFlags[i].Mid(2));
+        }
+        else if (   compilerFlags[i].StartsWith(wxT("`"))
+                 && compilerFlags[i].EndsWith(wxT("`"))  )
+        {
+            wxArrayString out;
+            long ret = 0;
+            {
+                wxLogNull logNo; // no need to warn if execution fails
+                ret = wxExecute(compilerFlags[i].Mid(1, compilerFlags[i].Length() - 2), out);
+            }
+            if (ret == 0)
+            {
+                out = GetArrayFromString(out[0], wxT(" ")); // pkg-config gives only single line output
+                AppendArray(out, compilerFlags); // append for processing
+            }
+        }
+        else if (   compilerFlags[i] == wxT("-ansi")
+                 || compilerFlags[i] == wxT("-std=c90")
+                 || compilerFlags[i] == wxT("-std=c++98"))
+        {
+            defines.Add(wxT("__STRICT_ANSI__"));
+        }
     }
 
     defines.Add(wxT("__cplusplus"));
Index: src/sdk/editorcolourset.cpp
===================================================================
--- src/sdk/editorcolourset.cpp (revision 8236)
+++ src/sdk/editorcolourset.cpp (working copy)
@@ -658,7 +658,22 @@
             tmpKey << key << _T("/style") << wxString::Format(_T("%d"), i);
 
             if (cfg->Exists(tmpKey + _T("/name")))
-                opt->name = cfg->Read(tmpKey + _T("/name"));
+            {
+                wxString name = cfg->Read(tmpKey + _T("/name"));
+                for (size_t j = 0; opt->name != name && i + j < it->second.m_Colours.GetCount(); ++j) // search forwards first
+                {
+                    opt = it->second.m_Colours.Item(i + j);
+                }
+                for (int j = -1; opt->name != name && i + j >= 0; --j) // then search backwards if it was not found
+                {
+                    opt = it->second.m_Colours.Item(i + j);
+                }
+                if (opt->name != name)
+                {
+                    cfg->DeleteSubPath(tmpKey); // unknown key, clear it out
+                    continue;
+                }
+            }
             else
             {
                 // make sure we didn't create it accidentally
Index: src/sdk/editorconfigurationdlg.cpp
===================================================================
--- src/sdk/editorconfigurationdlg.cpp (revision 8236)
+++ src/sdk/editorconfigurationdlg.cpp (working copy)
@@ -140,8 +140,8 @@
     XRCCTRL(*this, "cmbViewWS",                   wxComboBox)->SetSelection(cfg->ReadInt(_T("/view_whitespace"),         0));
     XRCCTRL(*this, "rbTabText",                   wxRadioBox)->SetSelection(cfg->ReadBool(_T("/tab_text_relative"),      true)? 1 : 0);
 
-    XRCCTRL(*this, "chkTrackPreprocessor",        wxCheckBox)->SetValue(cfg->ReadBool(_T("/track_preprocessor"),         false));
-    XRCCTRL(*this, "chkCollectPrjDefines",        wxCheckBox)->SetValue(cfg->ReadBool(_T("/collect_prj_defines"),        false));
+    XRCCTRL(*this, "chkTrackPreprocessor",        wxCheckBox)->SetValue(cfg->ReadBool(_T("/track_preprocessor"),         true));
+    XRCCTRL(*this, "chkCollectPrjDefines",        wxCheckBox)->SetValue(cfg->ReadBool(_T("/collect_prj_defines"),        true));
     XRCCTRL(*this, "chkPlatDefines",              wxCheckBox)->SetValue(cfg->ReadBool(_T("/platform_defines"),           false));
     XRCCTRL(*this, "chkColoursWxSmith",           wxCheckBox)->SetValue(cfg->ReadBool(_T("/highlight_wxsmith"),          true));
 

BTW: Is there any reason that the syntax highlight preview looks correct, so the code is different
I have no idea how this happens (and I cannot reproduce it).

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Two problems with r8232
« Reply #17 on: August 16, 2012, 06:04:39 am »
This patch should fix (almost) all custom color scheme loading problems. [...]
Code
+                ret = wxExecute(compilerFlags[i].Mid(1, compilerFlags[i].Length() - 2), out);
An exec command every time? Couldn't this be at least cached? Maybe that should even be a function of the compiler... (not a specific one, but the compiler framework. Because the compile has to do it, too IIRC... (I want to avoid having duplicate code.)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Two problems with r8232
« Reply #18 on: August 16, 2012, 08:29:41 am »
Alpha: it is considered a good style separating changes in different patches/commits as this makes reviewing it easier. And it they are committed separately the svn blame will be more useful at a later time.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Two problems with r8232
« Reply #19 on: August 16, 2012, 01:22:23 pm »
Alpha: it is considered a good style separating changes in different patches/commits as this makes reviewing it easier. And it they are committed separately the svn blame will be more useful at a later time.
Huh? This patch is needed in one to work. There is nothing to separate, or what did you mean? Collecting preprocessor defines is needed fr the highlighting function to work correctly.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Two problems with r8232
« Reply #20 on: August 16, 2012, 03:36:58 pm »
This patch should fix (almost) all custom color scheme loading problems.
Never mind; it only worked by a fluke.
BTW: Is there any reason that the syntax highlight preview looks correct, so the code is different
I have no idea how this happens (and I cannot reproduce it).
I had misunderstood the way color schemes were loaded/saved.  Items with multiple indexes are actually saved once for each index, which is why the preview looked different than the actual code.  The preview reinitialized all the values, however the actual code loaded (in this case) style "Comment (normal)" into the second index (11) that I added to "Default".

An exec command every time? Couldn't this be at least cached? Maybe that should even be a function of the compiler... (not a specific one, but the compiler framework. Because the compile has to do it, too IIRC... (I want to avoid having duplicate code.)
Right; I just noticed this now makes switching build targets a little slow.
Making wxString ExpandBackticks(wxString& str) (from sdk/compilercommandgenerator.cpp) global (and BackticksMap m_Backticks) looks like a solution.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Two problems with r8232
« Reply #21 on: August 16, 2012, 04:41:24 pm »
This time, I think I got the loading function to work properly.  (The save function is currently unmodified, so file format is currently backwards compatible, but not as efficient as it could be.)  Execution is now cached in a globally accessible location.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Two problems with r8232
« Reply #22 on: August 16, 2012, 06:45:27 pm »
Huh? This patch is needed in one to work. There is nothing to separate, or what did you mean? Collecting preprocessor defines is needed fr the highlighting function to work correctly.
Sorry, but the patch explanation made me believe the patch can be applied in two steps and there are some optional parts.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Two problems with r8232
« Reply #23 on: August 16, 2012, 07:35:44 pm »
Huh? This patch is needed in one to work. There is nothing to separate, or what did you mean? Collecting preprocessor defines is needed fr the highlighting function to work correctly.
Sorry, but the patch explanation made me believe the patch can be applied in two steps and there are some optional parts.
My fault; I failed to describe the connection to the original patch (which inadvertently caused the problems).

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Two problems with r8232
« Reply #24 on: August 18, 2012, 06:54:55 pm »
In patch tracker so it does not get lost.