dbg_ui_mon_win.erl

来自「OTP是开放电信平台的简称」· ERL 代码 · 共 564 行 · 第 1/2 页

ERL
564
字号
		   undefined ->		       if Row>?default_rows ->			       gs:config(Grid,[{rows,{1,Row}}]);			  true -> ok		       end,		       gs:gridline(Grid,[{row,Row}, {bw,5}, {fg,black},					 {font,dbg_ui_win:font(normal)},					 {click, true},					 {doubleclick, true}]);		   GSObj ->		       GSObj	       end,    Name2 = case Name of undefined -> ""; _ -> Name end,    FuncS = io_lib:format("~w:~w/~w", [Mod, Func, length(Args)]),    Info2 = case Info of {} -> ""; _ -> Info end,    Options = [{text, {1,Pid}}, {text, {2,FuncS}}, {text, {3,Name2}},	       {text, {4,Status}}, {text, {5,Info2}},	       {data, {gridline, Pid}}],    gs:config(GridLine, Options),    ProcInfo = #procInfo{pid=Pid, row=Row},    WinInfo#winInfo{processes=[ProcInfo|WinInfo#winInfo.processes],		    row=Row}.%%--------------------------------------------------------------------%% update_process(WinInfo, Pid, Status, Info)%%   WinInfo = #winInfo{}%%   Pid = pid()%%   Status = idle | running | break | exit%%   Info = {} | term()%%--------------------------------------------------------------------update_process(WinInfo, Pid, Status, Info) ->    {value, ProcInfo} = lists:keysearch(Pid, #procInfo.pid,					WinInfo#winInfo.processes),    Grid = WinInfo#winInfo.grid,    GridLine = gs:read(Grid, {obj_at_row, ProcInfo#procInfo.row}),        Info2 = case Info of {} -> ""; _ -> Info end,    gs:config(GridLine, [{text, {4,Status}}, {text, {5,Info2}}]).%%--------------------------------------------------------------------%% clear_processes(WinInfo) -> WinInfo%%   WinInfo = #winInfo{}%%--------------------------------------------------------------------clear_processes(WinInfo) ->    Grid = WinInfo#winInfo.grid,    Max = WinInfo#winInfo.row,    clear_processes(Grid, 2, Max),    gs:config(Grid,[{rows,{1,?default_rows}}]),    WinInfo#winInfo{row=1, focus=0, processes=[]}.clear_processes(Grid, Row, Max) when Row=<Max ->    GridLine = gs:read(Grid, {obj_at_row, Row}),    case gs:read(GridLine,{text,4}) of	"exit" -> 	    Pid = list_to_pid(gs:read(GridLine,{text,1})),	    dbg_ui_winman:clear_process(dbg_ui_trace:title(Pid));	_ -> 	    ok    end,	        Options = [{fg, black},	       {{text,1}, ""}, {{text,2},""}, {{text,3},""},	       {{text,4}, ""}, {{text,5},""},	       {data, []}],    gs:config(GridLine, Options),    clear_processes(Grid, Row+1, Max);clear_processes(_Grid, Row, Max) when Row>Max ->    done.%%--------------------------------------------------------------------%% add_break(WinInfo, Name, {Point, Options}) -> WinInfo%%   WinInfo = #winInfo{}%%   Name = atom()%%   Point = {Mod, Line}%%   Options = [Status, Action, Mods, Cond]%%     Status = active | inactive%%     Action = enable | disable | delete%%     Mods = null (not used)%%     Cond = null | {Mod, Func}%%--------------------------------------------------------------------add_break(WinInfo, Menu, {Point, Options}) ->    Break = dbg_ui_win:add_break(Menu, Point),    dbg_ui_win:update_break(Break, Options),    BreakInfo = #breakInfo{point=Point, break=Break},    WinInfo#winInfo{breaks=[BreakInfo|WinInfo#winInfo.breaks]}.%%--------------------------------------------------------------------%% update_break(WinInfo, {Point, Options})%%   WinInfo = #winInfo{}%%   Point = {Mod, Line}%%   Options = [Status, Action, Mods, Cond]%%     Status = active | inactive%%     Action = enable | disable | delete%%     Mods = null (not used)%%     Cond = null | {Mod, Func}%%--------------------------------------------------------------------update_break(WinInfo, {Point, Options}) ->    {value, BreakInfo} = lists:keysearch(Point, #breakInfo.point,					 WinInfo#winInfo.breaks),    dbg_ui_win:update_break(BreakInfo#breakInfo.break, Options).%%--------------------------------------------------------------------%% delete_break(WinInfo, Point) -> WinInfo%%   WinInfo = #winInfo{}%%   Point = {Mod, Line}%%--------------------------------------------------------------------delete_break(WinInfo, Point) ->    {value, BreakInfo} = lists:keysearch(Point, #breakInfo.point,					 WinInfo#winInfo.breaks),    dbg_ui_win:delete_break(BreakInfo#breakInfo.break),    WinInfo#winInfo{breaks=lists:keydelete(Point, #breakInfo.point,					   WinInfo#winInfo.breaks)}.%%--------------------------------------------------------------------%% clear_breaks(WinInfo) -> WinInfo%% clear_breaks(WinInfo, Mod) -> WinInfo%%   WinInfo = #winInfo{}%%--------------------------------------------------------------------clear_breaks(WinInfo) ->    lists:foreach(fun(BreakInfo) ->			  dbg_ui_win:delete_break(BreakInfo#breakInfo.break)		  end,		  WinInfo#winInfo.breaks),    WinInfo#winInfo{breaks=[]}.clear_breaks(WinInfo, Mod) ->    Fun =	fun(BreakInfo) ->		case BreakInfo#breakInfo.point of		    {Mod, _Line} ->			dbg_ui_win:delete_break(BreakInfo#breakInfo.break),			false;		    _ -> true		end	end,    Breaks = lists:filter(Fun, WinInfo#winInfo.breaks),    WinInfo#winInfo{breaks=Breaks}.    %%--------------------------------------------------------------------%% handle_event(GSEvent, WinInfo) -> Command%%   GSEvent = {gs, Id, Event, Data, Arg}%%   WinInfo = #winInfo{}%%   Command = ignore%%           | stopped%%           | {coords, {X,Y}}%%%%           | {shortcut, Key}%%           | MenuItem | {Menu, [MenuItem]}%%               MenuItem = Menu = atom()%%           | {break, Point, What}%%               What = delete | {status, Status} | {trigger, Trigger}%%           | {module, Mod, What}%%               What = view | delete%%%%           | {focus, Pid, WinInfo}%%           | default%%--------------------------------------------------------------------%% Window eventshandle_event({gs, _Id, configure, _Data, [W, H |_]}, WinInfo) ->    configure(WinInfo, {W, H}),    ignore;handle_event({gs, _Id, destroy, _Data, _Arg}, _WinInfo) ->    stopped;handle_event({gs, _Id, motion, _Data, [X,Y]}, WinInfo) ->    {LastX, LastY} = dbg_ui_win:motion(X, Y),    Win = WinInfo#winInfo.window,    {coords, {gs:read(Win, x)+LastX-5, gs:read(Win, y)+LastY-5}};%% Menus and keyboard shortcutshandle_event({gs, _Id, keypress, _Data, [Key,_,_,1]}, _WinInfo) when  Key/='Up', Key/='Down', Key/=p, Key/=n ->    {shortcut, Key};handle_event({gs, _Id, click, {dbg_ui_winman, Win}, _Arg}, _WinInfo) ->    dbg_ui_winman:raise(Win),    ignore;handle_event({gs, _Id, click, {menuitem, Name}, _Arg}, _WinInfo) ->    Name;handle_event({gs, _Id, click, {menu, Menu}, _Arg}, _WinInfo) ->    Names = dbg_ui_win:selected(Menu),    {Menu, Names};handle_event({gs, _Id, click, {break, Point, What}, _Arg}, _WinInfo) ->    {break, Point, What};handle_event({gs, _Id, click, {module, Mod, What}, _Arg}, _WinInfo) ->    {module, Mod, What};%% Listboxhandle_event({gs, _Id, doubleclick, listbox, [_Index, ModS|_]}, _WI) ->    {module, list_to_atom(ModS), view};%% Auto attach buttonshandle_event({gs, _Id, click, autoattach, _Arg}, WinInfo) ->    Names = lists:foldl(fun (Button, NamesAcc) ->				case gs:read(Button, select) of				    true ->					{text, Name} =					    gs:read(Button, label),					[list_to_atom(Name)|NamesAcc];				    false ->					NamesAcc				end			end,			[],			[WinInfo#winInfo.ebutton,			 WinInfo#winInfo.bbutton,			 WinInfo#winInfo.fbutton]),    {'Auto Attach', Names};%% Process gridhandle_event({gs, _Id, keypress, _Data, [Key|_]}, WinInfo) when  Key=='Up'; Key=='Down' ->    Dir = if Key=='Up' -> up; Key=='Down' -> down end,    Row = move(WinInfo, Dir),    if Row>1 ->	    WinInfo2 = highlight(WinInfo, Row),	    {value, #procInfo{pid=Pid}} =		lists:keysearch(Row, #procInfo.row, WinInfo#winInfo.processes),	    {focus, Pid, WinInfo2};       true ->	    ignore    end;handle_event({gs, _Id, click, {gridline, Pid}, [_Col,Row|_]}, WinInfo) ->    WinInfo2 = highlight(WinInfo, Row),    {focus, Pid, WinInfo2};handle_event({gs, _Id, doubleclick, _Data, _Arg}, _WinInfo) ->    default;handle_event(_GSEvent, _WinInfo) ->    ignore.move(WinInfo, Dir) ->    Row = WinInfo#winInfo.focus,    Last = WinInfo#winInfo.row,    if	Dir==up, Row>1 -> Row-1;	Dir==down, Row<Last -> Row+1;	true -> Row    end.highlight(WinInfo, Row) ->    Grid = WinInfo#winInfo.grid,    case WinInfo#winInfo.focus of	0 -> ignore;	Focus ->	    GridLine1 = gs:read(Grid, {obj_at_row, Focus}),	    gs:config(GridLine1, {fg, black})    end,    GridLine2 = gs:read(Grid, {obj_at_row, Row}),    gs:config(GridLine2, {fg, white}),    WinInfo#winInfo{focus=Row}.    %%====================================================================%% Internal functions%%====================================================================configure(WinInfo, {W, H}) ->    Grid = WinInfo#winInfo.grid,    NewW = W - (2*?PAD+?Wf),    Dx = NewW - gs:read(Grid, width),    Dy = H-42 - gs:read(Grid, height),    if	(Dx+Dy)=/=0 ->	    gs:config(Grid, [{width, NewW}, {height, H-30}]),	    Cols = calc_columnwidths(NewW),	    gs:config(Grid, Cols);	true ->	    ok    end.calc_columnwidths(Width) ->    W = if	    Width=<?Wg -> ?Wg;	    true -> Width	end,    First = lists:map(fun (X) -> round(X) end,		      [0.13*W, 0.27*W, 0.18*W, 0.18*W]),    Last = W - lists:sum(First) - 30,    {columnwidths, First++[Last]}.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?