diff --git a/src/gd_con.erl b/src/gd_con.erl index 75c20e4..c9e40cb 100644 --- a/src/gd_con.erl +++ b/src/gd_con.erl @@ -38,15 +38,15 @@ mon = none :: none | reference()}). -record(s, - {version = 1 :: integer(), - window = none :: none | wx:wx_object(), - timer = none :: none | reference(), - tasks = [] :: [#ui{}], - selected = 0 :: non_neg_integer(), - wallet = none :: none | #wallet{}, - pass = none :: none | binary(), - prefs = #{} :: #{module() := term()}, - wallets = [] :: [#wr{}]}). + {version = 1 :: integer(), + window = none :: none | wx:wx_object(), + timer = none :: none | reference(), + tasks = [] :: [#ui{}], + selected = 0 :: non_neg_integer(), + wallet = none :: none | #wallet{}, + pass = none :: none | binary(), + prefs = #{} :: #{module() := term()}, + wallets = [] :: [#wr{}]}). -type state() :: #s{}. @@ -477,6 +477,9 @@ handle_cast(Unexpected, State) -> handle_info(tic, State) -> NewState = do_tic(State), {noreply, NewState}; +handle_info({show_ui, Name}, State) -> + NewState = do_show_ui(Name, State), + {noreply, NewState}; handle_info({'DOWN', Mon, process, PID, Info}, State) -> NewState = handle_down(Mon, PID, Info, State), {noreply, NewState}; @@ -486,6 +489,7 @@ handle_info(Unexpected, State) -> handle_down(Mon, PID, Info, State = #s{tasks = Tasks}) -> + tell("Handling down"), case lists:keytake(Mon, #ui.mon, Tasks) of {value, #ui{}, NewTasks} -> State#s{tasks = NewTasks}; @@ -531,7 +535,7 @@ do_show_ui(Name, State = #s{tasks = Tasks, prefs = Prefs}) -> Win = Name:start_link({TaskPrefs, TaskData}), PID = wx_object:get_pid(Win), Mon = monitor(process, PID), - ok = Name:to_front(Win), +% ok = Name:to_front(Win), UI = #ui{name = Name, pid = PID, wx = Win, mon = Mon}, State#s{tasks = [UI | Tasks]} end. @@ -1023,8 +1027,10 @@ do_open_wallet(Path, Phrase, State) -> State#s{pass = Pass, wallet = Recovered}; Error -> ok = gd_gui:trouble(Error), - New = default_wallet(), - State#s{wallet = New} + % FIXME: This is chaotically stupid. + tell("Sending myself the show_ui message"), + self() ! {show_ui, gd_v_wallman}, + State end. diff --git a/src/gd_v_wallman.erl b/src/gd_v_wallman.erl index 68bd09e..dd81ee1 100644 --- a/src/gd_v_wallman.erl +++ b/src/gd_v_wallman.erl @@ -120,12 +120,12 @@ init({Prefs, Manifest}) -> ok; Count > 1 -> true = wxFrame:show(Frame), - ok + wxFrame:raise(Frame) end, State = #s{wx = Wx, frame = Frame, lang = Lang, j = J, prefs = Prefs, - wallets = Manifest, - picker = Picker, - buttons = Buttons}, + wallets = Manifest, + picker = Picker, + buttons = Buttons}, {Frame, State}. @@ -136,8 +136,8 @@ handle_call(Unexpected, From, State) -> ok = log(warning, "Unexpected call from ~tp: ~tp~n", [From, Unexpected]), {noreply, State}. - handle_cast(to_front, State = #s{frame = Frame}) -> + ok = ensure_shown(Frame), ok = wxFrame:raise(Frame), {noreply, State}; handle_cast({show, Manifest}, State) -> @@ -185,9 +185,9 @@ handle_event(#wx{event = #wxCommand{type = command_button_clicked}, State = #s{wiz = {_, WizButtons}}) -> NewState = case lists:keyfind(ID, #w.id, WizButtons) of - #w{name = noob} -> wiz_noob_assist(State); - #w{name = l33t} -> close_wiz(State); - false -> State + #w{name = noob} -> wiz_noob_assist(State); + #w{name = l33t} -> close_wiz(State); + false -> State end, {noreply, NewState}; handle_event(#wx{event = #wxClose{}}, State = #s{wiz = {_, _}}) -> @@ -236,7 +236,8 @@ do_close(#s{frame = Frame, prefs = Prefs}) -> end, NewPrefs = maps:put(geometry, Geometry, Prefs), ok = gd_con:save(?MODULE, NewPrefs), - ok = wxWindow:destroy(Frame). + ok = wxWindow:destroy(Frame), + exit(normal). handle_button(Name, State) -> @@ -283,13 +284,14 @@ do_open3(Path, State = #s{frame = Frame, j = J}) -> ok = wxDialog:setSizer(Dialog, Sizer), ok = wxBoxSizer:layout(Sizer), ok = wxDialog:setSize(Dialog, {500, 130}), - ok = wxFrame:center(Dialog), + ok = wxDialog:center(Dialog), ok = wxStyledTextCtrl:setFocus(PassTx), case wxDialog:showModal(Dialog) of ?wxID_OK -> case wxTextCtrl:getValue(PassTx) of "" -> ok = wxDialog:destroy(Dialog), + ok = ensure_shown(Frame), State; Phrase -> ok = wxDialog:destroy(Dialog), @@ -299,6 +301,7 @@ do_open3(Path, State = #s{frame = Frame, j = J}) -> end; ?wxID_CANCEL -> ok = wxDialog:destroy(Dialog), + ok = ensure_shown(Frame), State end. @@ -307,7 +310,7 @@ do_wiz(State = #s{wx = WX, lang = Lang, wiz = none}) -> Trans = gd_jt:read_translations(?MODULE), J = gd_jt:j(Lang, Trans), - Frame = wxFrame:new(WX, ?wxID_ANY, J("Initializing Wallet")), + Wiz = wxFrame:new(WX, ?wxID_ANY, J("Initializing Wallet")), MainSz = wxBoxSizer:new(?wxVERTICAL), ButtonTemplates = @@ -316,7 +319,7 @@ do_wiz(State = #s{wx = WX, lang = Lang, wiz = none}) -> MakeButton = fun({Name, Label}) -> - B = wxButton:new(Frame, ?wxID_ANY, [{label, Label}]), + B = wxButton:new(Wiz, ?wxID_ANY, [{label, Label}]), #w{name = Name, id = wxButton:getId(B), wx = B} end, @@ -325,15 +328,16 @@ do_wiz(State = #s{wx = WX, lang = Lang, wiz = none}) -> Add = fun(#w{wx = Button}) -> wxBoxSizer:add(MainSz, Button, zxw:flags(wide)) end, ok = lists:foreach(Add, Buttons), - ok = wxFrame:setSizer(Frame, MainSz), + ok = wxFrame:setSizer(Wiz, MainSz), ok = wxSizer:layout(MainSz), - ok = wxFrame:connect(Frame, command_button_clicked), - ok = wxFrame:connect(Frame, close_window), - ok = wxFrame:setSize(Frame, {300, 300}), - ok = wxFrame:center(Frame), - true = wxFrame:show(Frame), - State#s{wiz = {Frame, Buttons}}. + ok = wxFrame:connect(Wiz, command_button_clicked), + ok = wxFrame:connect(Wiz, close_window), + ok = wxFrame:setSize(Wiz, {300, 300}), + ok = wxFrame:center(Wiz), + true = wxFrame:show(Wiz), + State#s{wiz = {Wiz, Buttons}}. + wiz_noob_assist(State = #s{j = J, wiz = {Wiz, _}}) -> DefaultDir = zx_lib:path(var, "otpr", "gajudesk"), @@ -342,8 +346,11 @@ wiz_noob_assist(State = #s{j = J, wiz = {Wiz, _}}) -> Name = io_lib:format(Form, [YY, MM, DD, Hr, Mn, Sc]), Path = filename:join(DefaultDir, Name ++ ".gaju"), case do_new2(Path, J, Wiz) of - ok -> do_close(State); - abort -> State + ok -> + ok = do_close(State), + State; + abort -> + State end. @@ -366,7 +373,9 @@ do_new(State = #s{frame = Frame, j = J, prefs = Prefs}) -> case do_new2(Path, J, Frame) of ok -> NewPrefs = maps:put(dir, Dir, Prefs), - do_close(State#s{prefs = NewPrefs}); + NewState = State#s{prefs = NewPrefs}, + ok = do_close(NewState), + NewState; abort -> State end; @@ -459,7 +468,9 @@ do_import(State = #s{frame = Frame, j = J, prefs = Prefs}) -> case do_import2(Dir, File, J, Frame) of ok -> NewPrefs = maps:put(dir, Dir, Prefs), - do_close(State#s{prefs = NewPrefs}); + NewState = State#s{prefs = NewPrefs}, + ok = do_close(NewState), + NewState; abort -> State end; @@ -561,3 +572,13 @@ do_drop(Selected, State = #s{j = J, frame = Frame, wallets = Wallets}) -> ok end, State. + + +ensure_shown(Frame) -> + case wxWindow:isShown(Frame) of + true -> + ok; + false -> + true = wxFrame:show(Frame), + ok + end.