Make styled text control when loading

This commit is contained in:
Jarvis Carroll 2025-08-22 15:22:39 +10:00
parent 2952822a8f
commit dc0b620a4c

View File

@ -929,6 +929,24 @@ save(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}})
end
end.
make_plain_text_control(Parent) ->
CodeTxStyle = {style, ?wxTE_MULTILINE
bor ?wxTE_PROCESS_TAB
bor ?wxTE_DONTWRAP
bor ?wxTE_READONLY},
CodeTx = wxTextCtrl:new(Parent, ?wxID_ANY, [CodeTxStyle]),
Mono = wxFont:new(10, ?wxMODERN, ?wxNORMAL, ?wxNORMAL, [{face, "Monospace"}]),
TextAt = wxTextAttr:new(),
ok = wxTextAttr:setFont(TextAt, Mono),
true = wxTextCtrl:setDefaultStyle(CodeTx, TextAt),
CodeTx.
make_source_text_control(Parent) ->
case ?editorMode of
plain -> make_plain_text_control(Parent);
sophia -> gd_sophia_editor:new(Parent)
end.
get_source(Widget) ->
case ?editorMode of
plain -> wxTextCtrl:getValue(Widget);
@ -940,7 +958,6 @@ set_source(Widget, Src) ->
plain -> wxTextCtrl:setValue(Widget, Src);
sophia -> gd_sophia_editor:set_text(Widget, Src)
end.
% TODO: Break this down -- tons of things in here recur.
rename(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}}) ->
@ -1079,15 +1096,7 @@ load3(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j
PageSz = wxBoxSizer:new(?wxVERTICAL),
ProgSz = wxBoxSizer:new(?wxHORIZONTAL),
CodeSz = wxStaticBoxSizer:new(?wxVERTICAL, Window, [{label, J("Contract Source")}]),
CodeTxStyle = {style, ?wxTE_MULTILINE
bor ?wxTE_PROCESS_TAB
bor ?wxTE_DONTWRAP
bor ?wxTE_READONLY},
CodeTx = wxTextCtrl:new(Window, ?wxID_ANY, [CodeTxStyle]),
Mono = wxFont:new(10, ?wxMODERN, ?wxNORMAL, ?wxNORMAL, [{face, "Monospace"}]),
TextAt = wxTextAttr:new(),
ok = wxTextAttr:setFont(TextAt, Mono),
true = wxTextCtrl:setDefaultStyle(CodeTx, TextAt),
CodeTx = make_source_text_control(Window),
ok = set_source(CodeTx, Source),
_ = wxSizer:add(CodeSz, CodeTx, zxw:flags(wide)),
ScrollWin = wxScrolledWindow:new(Window),