Changing syntax coloring in registry via script

Started by cssyphus, October 09, 2019, 01:27:09 PM

Previous topic - Next topic

cssyphus

I wanted to be able to switch quickly back/forth between two syntax coloring configurations, so wrote a quick script to do so. All works great, except for the background color. It remains what it was and must be changed manually. Am I missing something obvious?


Terminate(WinExist(`WinBatch Studio - `), ``, `First Close WinBatch Studio`)
goSub InitVars

If RegExistValue(_root, _Bg)
_Bg = RegQueryValue(_root, _Bg)
;terminate(1, ``, _Bg) --> This reports the correct value (manual edit of registry value to weird number is correctly reported)
if _Bg == _DkBg
RegSetValue(_root, _Bg, _LtBg)
RegSetValue(_root, _Cm, _LtCm)
RegSetValue(_root, _Tx, _LtTx)
RegSetValue(_root, _Kw, _LtKw)
RegSetValue(_root, _Qu, _LtQu)
RegSetValue(_root, _Ft, _LtFt)
RegSetDword(_root, _Sz, _LtSz)
elseif _bg == _LtBg
RegSetValue(_root, _Bg, _DkBg)
RegSetValue(_root, _Cm, _DkCm)
RegSetValue(_root, _Tx, _DkTx)
RegSetValue(_root, _Kw, _DkKw)
RegSetValue(_root, _Qu, _DkQu)
RegSetValue(_root, _Ft, _DkFt)
RegSetDword(_root, _Sz, _DkSz)
endif
EndIf

;XXXXXXXXX
EXIT ;XXXX
;XXXXXXXXX
:InitVars
_root = @REGCURRENT
_Bg = "Software\Wilson WindowWare\WinBatch Studio\Settings\File types\WIL Files[Background]"
_Cm = "Software\Wilson WindowWare\WinBatch Studio\Settings\File types\WIL Files[Comment]"
_Tx = "Software\Wilson WindowWare\WinBatch Studio\Settings\File types\WIL Files[Default Text]"
_Kw = "Software\Wilson WindowWare\WinBatch Studio\Settings\File types\WIL Files[Keyword]"
_Qu = "Software\Wilson WindowWare\WinBatch Studio\Settings\File types\WIL Files[Quote]"
_Ft = "Software\Wilson WindowWare\WinBatch Studio\Settings\File types\WIL Files[Font name]"
_Sz = "Software\Wilson WindowWare\WinBatch Studio\Settings\File types\WIL Files[Font size]"
_DkBg = `30,30,30` ;Background
_DkCm = `106,153,85` ;Comments
_DkTx = `212,212,212`;Default text
_DkKw = `86,156,214` ;Keywords
_DkQu = `209,105,105`;Strings (Quotes)
_DkFt = `Consolas` ;Font face
_DkSz = `11`
_LtBg = `255,255,255`
_LtCm = `0,128,0`
_LtTx = `0,0,0`
_LtKw = `0,0,255`
_LtQu = `255,0,0`
_LtFt = `Courier New` ;Font face
_LtSz = `12`
Return

td

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

cssyphus

I don't see [Font background] (or such) as one of the keys in the registry folder (hive? branch?). Below is a screenshot of the folder I am modifying.

https://imgur.com/a/lZdDAln

Note that when I change the values manually, using WinBatch Studio's [View] [Options] [Syntax coloring] [Current Colors] [Background] CHANGE button, the [Background] value is in this registry folder changed correctly (and the WBS editor background changes for that filetype). It is only the direct modification of the registry key that doesn't seem to "take" (that is, the script modifies every other key correctly, but the background key is not changed in the registry). Any further thoughts? If not, I'll figure out a workaround. Please don't go to any trouble trying to reproduce this - just pinging you for brainstorming, anything that leaps to mind.

By the way, I am using Windows 7 Home Premium with WinBatch 2018B.


td

First, I need to apologize for wasting your time with the "font" comment.  My only excuse is that with hundreds of thousands of lines of code scattered over multiple applications confusing one implementation with the other happens.  Actually, that is not a very good excuse.  There is no excuse for posting information to this forum without at least a minimal verification of the relevant facts.

What I do know is that WinBatch Studio does not automagically read the registry every time the chroma values change.  Some event must trigger the read.  For example, when you click the "Apply" or "OK" button in the  "Options" dialog, the main WBS thread calls the OnUpdate handler of each open view.  The handle reads the registry values and redraws the view window.  The redraw is the other step that must happen before a chroma change takes effect. 

I did a very simple test to check this.  First, I edited the background and comment colors in the registry while WBS was running with an open ".wbt" file in the top view.  I then triggered a redraw by pressing the right mouse button with the mouse cursor inside the bounding rectangle of the view.  This forced a redraw which change both the comment line color and the background color.

I guess this is just a long-winded way of saying that I can't tell you why you have what sounds like different results.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

cssyphus

Yeah, it's probably just a weirdness to my system, then.  I'll see what happens down the road when I am able to update to a new version. In the meantime, I'll use SendKeysTo() to create a workaround.

FWIW, my procedure was to first exit WBS, then run the script, then restart WBS. The Background value was the only one that would not change. I was hoping that perhaps there was something that I didn't know, but looks like it's just my system.

Many thanks for giving it some thought and telling me how it is designed to work.