File 2224-observer-Keep-port-selection-after-refresh.patch of Package erlang

From 346427338d7559c88ec38d60a372c72bf692b5fa Mon Sep 17 00:00:00 2001
From: Dan Gudmundsson <dgud@erlang.org>
Date: Mon, 20 Mar 2017 14:41:40 +0100
Subject: [PATCH 2/5] observer: Keep port selection after refresh

---
 lib/observer/src/observer_port_wx.erl | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/lib/observer/src/observer_port_wx.erl b/lib/observer/src/observer_port_wx.erl
index c21d2705c..c87238d82 100644
--- a/lib/observer/src/observer_port_wx.erl
+++ b/lib/observer/src/observer_port_wx.erl
@@ -115,7 +115,7 @@ init([Notebook, Parent]) ->
 handle_event(#wx{id=?ID_REFRESH},
 	     State = #state{node=Node, grid=Grid, opt=Opt}) ->
     Ports0 = get_ports(Node),
-    Ports = update_grid(Grid, Opt, Ports0),
+    Ports = update_grid(Grid, sel(State), Opt, Ports0),
     {noreply, State#state{ports=Ports}};
 
 handle_event(#wx{obj=Obj, event=#wxClose{}}, #state{open_wins=Opened} = State) ->
@@ -134,7 +134,7 @@ handle_event(#wx{event=#wxList{type=command_list_col_click, col=Col}},
 	      NewKey -> Opt0#opt{sort_key=NewKey}
 	  end,
     Ports0 = get_ports(Node),
-    Ports = update_grid(Grid, Opt, Ports0),
+    Ports = update_grid(Grid, sel(State), Opt, Ports0),
     wxWindow:setFocus(Grid),
     {noreply, State#state{opt=Opt, ports=Ports}};
 
@@ -269,7 +269,7 @@ handle_cast(Event, _State) ->
 handle_info({portinfo_open, PortIdStr},
 	    State = #state{node=Node, grid=Grid, opt=Opt, open_wins=Opened}) ->
     Ports0 = get_ports(Node),
-    Ports = update_grid(Grid, Opt, Ports0),
+    Ports = update_grid(Grid, sel(State), Opt, Ports0),
     Port = lists:keyfind(PortIdStr, #port.id_str, Ports),
     NewOpened =
         case Port of
@@ -288,14 +288,14 @@ handle_info(refresh_interval, State = #state{node=Node, grid=Grid, opt=Opt,
             %% no change
             {noreply, State};
         Ports0 ->
-            Ports = update_grid(Grid, Opt, Ports0),
+            Ports = update_grid(Grid, sel(State), Opt, Ports0),
             {noreply, State#state{ports=Ports}}
     end;
 
 handle_info({active, Node}, State = #state{parent=Parent, grid=Grid, opt=Opt,
 					   timer=Timer0}) ->
     Ports0 = get_ports(Node),
-    Ports = update_grid(Grid, Opt, Ports0),
+    Ports = update_grid(Grid, sel(State), Opt, Ports0),
     wxWindow:setFocus(Grid),
     create_menus(Parent),
     Timer = observer_lib:start_timer(Timer0),
@@ -511,9 +511,9 @@ filter_monitor_info() ->
 	    [Pid || {process, Pid} <- Ms]
     end.
 
-update_grid(Grid, Opt, Ports) ->
-    wx:batch(fun() -> update_grid2(Grid, Opt, Ports) end).
-update_grid2(Grid, #opt{sort_key=Sort,sort_incr=Dir}, Ports) ->
+update_grid(Grid, Sel, Opt, Ports) ->
+    wx:batch(fun() -> update_grid2(Grid, Sel, Opt, Ports) end).
+update_grid2(Grid, Sel, #opt{sort_key=Sort,sort_incr=Dir}, Ports) ->
     wxListCtrl:deleteAllItems(Grid),
     Update =
 	fun(#port{id = Id,
@@ -533,6 +533,12 @@ update_grid2(Grid, #opt{sort_key=Sort,sort_incr=Dir}, Ports) ->
 							 observer_lib:to_str(Val))
 			      end,
 			      [{0,Id},{1,Connected},{2,Name},{3,Ctrl},{4,Slot}]),
+                case lists:member(Id, Sel) of
+                    true ->
+                        wxListCtrl:setItemState(Grid, Row, 16#FFFF, ?wxLIST_STATE_SELECTED);
+                    false ->
+                        wxListCtrl:setItemState(Grid, Row, 0, ?wxLIST_STATE_SELECTED)
+                end,
 		Row + 1
 	end,
     PortInfo = case Dir of
@@ -542,6 +548,8 @@ update_grid2(Grid, #opt{sort_key=Sort,sort_incr=Dir}, Ports) ->
     lists:foldl(Update, 0, PortInfo),
     PortInfo.
 
+sel(#state{grid=Grid, ports=Ports}) ->
+    [Id || #port{id=Id} <- get_selected_items(Grid, Ports)].
 
 get_selected_items(Grid, Data) ->
     get_indecies(get_selected_items(Grid, -1, []), Data).
-- 
2.12.2

openSUSE Build Service is sponsored by