Give the main frame visibility on events

This commit is contained in:
2025-03-31 13:58:48 +09:00
parent d4f2b3f2b0
commit 9aa2c2f79d
3 changed files with 128 additions and 98 deletions
+17 -21
View File
@@ -258,6 +258,9 @@ handle_event(E = #wx{event = #wxCommand{type = command_button_clicked},
State
end,
{noreply, NewState};
handle_event(#wx{event = Event = #wxStyledText{type = stc_styleneeded}, obj = Win}, State) ->
ok = style(State, Win, Event),
{noreply, State};
handle_event(#wx{event = #wxClose{}}, State = #s{frame = Frame, prefs = Prefs}) ->
Geometry =
case wxTopLevelWindow:isMaximized(Frame) of
@@ -293,6 +296,15 @@ terminate(Reason, State) ->
%%% Doers
style(#s{code = {Codebook, Pages}}, Win, Event) ->
case lists:keyfind(Win, #p.win, Pages) of
#p{code = STC} ->
tell("Received style event.~nWin: ~p~nEvent: ~p", [Win, Event]),
gd_sophia_editor:update(Event, STC);
false ->
tell("Received bogus style event.~nWin: ~p~nEvent: ~p", [Win, Event])
end.
clicked(State = #s{cons = {Consbook, Contracts}}, Name) ->
case wxNotebook:getSelection(Consbook) of
?wxNOT_FOUND ->
@@ -506,30 +518,13 @@ add_code_page2(State, {hash, Address}) ->
open_hash2(State, Address).
add_code_page(State = #s{tabs = TopBook, code = {Codebook, Pages}}, Location, Code) ->
% FIXME: One of these days we need to define the text area as a wxStyledTextCtrl and will
% have to contend with system theme issues (light/dark themese, namely)
% Leaving this little thing here to remind myself how any of that works later.
% The call below returns a wx_color4() type (not that we need alpha...).
% Color = wxSystemSettings:getColour(?wxSYS_COLOUR_WINDOW),
% tell("Color: ~p", [Color]),
Color = wxSystemSettings:getColour(?wxSYS_COLOUR_WINDOW),
tell("Color: ~p", [Color]),
Window = wxWindow:new(Codebook, ?wxID_ANY),
PageSz = wxBoxSizer:new(?wxHORIZONTAL),
CodeTxStyle = {style, ?wxTE_MULTILINE bor ?wxTE_PROCESS_TAB bor ?wxTE_DONTWRAP},
CodeTx = case ?editorMode of
plain -> wxTextCtrl:new(Window, ?wxID_ANY, [CodeTxStyle]);
sophia -> gd_sophia_editor:new(Window, ?wxID_ANY, [CodeTxStyle])
end,
TextAt = wxTextAttr:new(),
Mono = wxFont:new(10, ?wxMODERN, ?wxNORMAL, ?wxNORMAL, [{face, "Monospace"}]),
ok = wxTextAttr:setFont(TextAt, Mono),
case ?editorMode of
plain ->
true = wxTextCtrl:setDefaultStyle(CodeTx, TextAt),
ok = wxTextCtrl:setValue(CodeTx, Code);
sophia ->
gd_sophia_editor:set_text(CodeTx, Code)
end,
CodeTx = gd_sophia_editor:new(Window),
ok = gd_sophia_editor:set_text(CodeTx, Code),
_ = wxSizer:add(PageSz, CodeTx, zxw:flags(wide)),
@@ -541,6 +536,7 @@ add_code_page(State = #s{tabs = TopBook, code = {Codebook, Pages}}, Location, Co
{file, Path} -> filename:basename(Path);
{hash, Addr} -> Addr
end,
ok = wxStyledTextCtrl:connect(Window, stc_styleneeded),
true = wxNotebook:addPage(Codebook, Window, FileName, [{bSelect, true}]),
Page = #p{path = Location, win = Window, code = CodeTx},
NewPages = Pages ++ [Page],