First stab at supporting syntax highlighting via wxStyledTextCtrl
This commit is contained in:
+29
-6
@@ -15,6 +15,8 @@
|
||||
-include("$zx_include/zx_logger.hrl").
|
||||
-include("gd.hrl").
|
||||
|
||||
-define(editorMode, sophia).
|
||||
|
||||
% Widgets
|
||||
-record(w,
|
||||
{name = none :: atom() | {FunName :: binary(), call | dryr},
|
||||
@@ -514,12 +516,20 @@ add_code_page(State = #s{tabs = TopBook, code = {Codebook, Pages}}, Location, Co
|
||||
PageSz = wxBoxSizer:new(?wxHORIZONTAL),
|
||||
|
||||
CodeTxStyle = {style, ?wxTE_MULTILINE bor ?wxTE_PROCESS_TAB bor ?wxTE_DONTWRAP},
|
||||
CodeTx = wxTextCtrl:new(Window, ?wxID_ANY, [CodeTxStyle]),
|
||||
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),
|
||||
true = wxTextCtrl:setDefaultStyle(CodeTx, TextAt),
|
||||
ok = wxTextCtrl:setValue(CodeTx, Code),
|
||||
case ?editorMode of
|
||||
plain ->
|
||||
true = wxTextCtrl:setDefaultStyle(CodeTx, TextAt),
|
||||
ok = wxTextCtrl:setValue(CodeTx, Code);
|
||||
sophia ->
|
||||
gd_sophia_editor:set_text(CodeTx, Code)
|
||||
end,
|
||||
|
||||
_ = wxSizer:add(PageSz, CodeTx, zxw:flags(wide)),
|
||||
|
||||
@@ -910,7 +920,7 @@ save(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}})
|
||||
_ -> Name ++ ".aes"
|
||||
end,
|
||||
Path = filename:join(Dir, File),
|
||||
Source = wxTextCtrl:getValue(Widget),
|
||||
Source = get_source(Widget),
|
||||
case filelib:ensure_dir(Path) of
|
||||
ok ->
|
||||
case file:write_file(Path, Source) of
|
||||
@@ -938,6 +948,19 @@ save(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}})
|
||||
end
|
||||
end.
|
||||
|
||||
get_source(Widget) ->
|
||||
case ?editorMode of
|
||||
plain -> wxTextCtrl:getValue(Widget);
|
||||
sophia -> gd_sophia_editor:get_text(Widget)
|
||||
end.
|
||||
|
||||
set_source(Widget, Src) ->
|
||||
case ?editorMode of
|
||||
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}}) ->
|
||||
case wxNotebook:getSelection(Codebook) of
|
||||
@@ -968,7 +991,7 @@ rename(State = #s{frame = Frame, j = J, prefs = Prefs, code = {Codebook, Pages}}
|
||||
_ -> Name ++ ".aes"
|
||||
end,
|
||||
NewPath = filename:join(Dir, File),
|
||||
Source = wxTextCtrl:getValue(Widget),
|
||||
Source = get_source(Widget),
|
||||
case filelib:ensure_dir(NewPath) of
|
||||
ok ->
|
||||
case file:write_file(NewPath, Source) of
|
||||
@@ -1084,7 +1107,7 @@ load3(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j
|
||||
TextAt = wxTextAttr:new(),
|
||||
ok = wxTextAttr:setFont(TextAt, Mono),
|
||||
true = wxTextCtrl:setDefaultStyle(CodeTx, TextAt),
|
||||
ok = wxTextCtrl:setValue(CodeTx, Source),
|
||||
ok = set_source(CodeTx, Source),
|
||||
_ = wxSizer:add(CodeSz, CodeTx, zxw:flags(wide)),
|
||||
ScrollWin = wxScrolledWindow:new(Window),
|
||||
FunSz = wxStaticBoxSizer:new(?wxVERTICAL, ScrollWin, [{label, J("Function Interfaces")}]),
|
||||
|
||||
Reference in New Issue
Block a user