diff options
author | Dan Gudmundsson <[email protected]> | 2011-12-09 13:28:55 +0100 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2011-12-09 13:28:55 +0100 |
commit | 4743d3991ee56e5989563dde61bce91d625a05f4 (patch) | |
tree | dab48b92ab721f6a54ed666ddc375a3bfd2e73f3 /lib/observer/src/observer_lib.erl | |
parent | e3bcbd4451cdb1dd0a826810a898c2d0e9fa390d (diff) | |
parent | 9a4f23a450541fe5ed9dc1cd35b32b8621736949 (diff) | |
download | otp-4743d3991ee56e5989563dde61bce91d625a05f4.tar.gz otp-4743d3991ee56e5989563dde61bce91d625a05f4.tar.bz2 otp-4743d3991ee56e5989563dde61bce91d625a05f4.zip |
Merge branch 'dgud/observer/gui/OTP-4779'
* dgud/observer/gui/OTP-4779:
[observer] Add basic documentation
[observer] Do not start polling tables until user view them
[observer] Move rpc calls to runtime tools
[observer] Added an application viewer
[observer] Remove unused time from process view
[observer] Change process_info stack to be listctrl
[observer] Fix listctrl colum size calculation
[observer] Add more trace functionality
[observer] Use standard popup menu
Diffstat (limited to 'lib/observer/src/observer_lib.erl')
-rw-r--r-- | lib/observer/src/observer_lib.erl | 70 |
1 files changed, 64 insertions, 6 deletions
diff --git a/lib/observer/src/observer_lib.erl b/lib/observer/src/observer_lib.erl index 90c270e977..967baa5c7a 100644 --- a/lib/observer/src/observer_lib.erl +++ b/lib/observer/src/observer_lib.erl @@ -19,11 +19,12 @@ -module(observer_lib). -export([get_wx_parent/1, - display_info_dialog/1, + display_info_dialog/1, user_term/3, interval_dialog/4, start_timer/1, stop_timer/1, display_info/2, fill_info/2, update_info/2, to_str/1, create_menus/3, create_menu_item/3, - create_attrs/0 + create_attrs/0, + set_listctrl_col_size/2 ]). -include_lib("wx/include/wx.hrl"). @@ -195,6 +196,7 @@ to_str(No) when is_integer(No) -> to_str(Term) -> io_lib:format("~w", [Term]). +create_menus([], _MenuBar, _Type) -> ok; create_menus(Menus, MenuBar, Type) -> Add = fun({Tag, Ms}, Index) -> create_menu(Tag, Ms, Index, MenuBar, Type) @@ -239,15 +241,21 @@ create_menu(Name, MenuItems, Index, MenuBar, _Type) -> create_menu_item(#create_menu{id = ?wxID_HELP=Id}, Menu, Index) -> wxMenu:insert(Menu, Index, Id), Index+1; -create_menu_item(#create_menu{id = Id, text = Text, type = Type, check = Check}, Menu, Index) -> +create_menu_item(#create_menu{id=Id, text=Text, help=Help, type=Type, check=Check}, + Menu, Index) -> + Opts = case Help of + [] -> []; + _ -> [{help, Help}] + end, case Type of append -> - wxMenu:insert(Menu, Index, Id, [{text, Text}]); + wxMenu:insert(Menu, Index, Id, + [{text, Text}|Opts]); check -> - wxMenu:insertCheckItem(Menu, Index, Id, Text), + wxMenu:insertCheckItem(Menu, Index, Id, Text, Opts), wxMenu:check(Menu, Id, Check); radio -> - wxMenu:insertRadioItem(Menu, Index, Id, Text), + wxMenu:insertRadioItem(Menu, Index, Id, Text, Opts), wxMenu:check(Menu, Id, Check); separator -> wxMenu:insertSeparator(Menu, Index) @@ -295,3 +303,53 @@ create_box(Panel, Data) -> wxSizer:add(Box, Right), wxSizer:addSpacer(Box, 30), {Box, InfoFields}. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +set_listctrl_col_size(LCtrl, Total) -> + wx:batch(fun() -> calc_last(LCtrl, Total) end). + +calc_last(LCtrl, _Total) -> + Cols = wxListCtrl:getColumnCount(LCtrl), + {Total, _} = wxWindow:getClientSize(LCtrl), + SBSize = scroll_size(LCtrl), + Last = lists:foldl(fun(I, Last) -> + Last - wxListCtrl:getColumnWidth(LCtrl, I) + end, Total-SBSize, lists:seq(0, Cols - 2)), + Size = max(150, Last), + wxListCtrl:setColumnWidth(LCtrl, Cols-1, Size). + +scroll_size(LCtrl) -> + case os:type() of + {win32, nt} -> 0; + {unix, darwin} -> + %% I can't figure out is there is a visible scrollbar + %% Always make room for it + wxSystemSettings:getMetric(?wxSYS_VSCROLL_X); + _ -> + case wxWindow:hasScrollbar(LCtrl, ?wxVERTICAL) of + true -> wxSystemSettings:getMetric(?wxSYS_VSCROLL_X); + false -> 0 + end + end. + + +user_term(Parent, Title, Default) -> + Dialog = wxTextEntryDialog:new(Parent, Title, [{value, Default}]), + case wxTextEntryDialog:showModal(Dialog) of + ?wxID_OK -> + Str = wxTextEntryDialog:getValue(Dialog), + wxTextEntryDialog:destroy(Dialog), + parse_string(Str); + ?wxID_CANCEL -> + wxTextEntryDialog:destroy(Dialog) + end. + +parse_string(Str) -> + try + {ok, Tokens, _} = erl_scan:string(Str), + erl_parse:parse_term(Tokens) + catch _:{badmatch, {error, {_, _, Err}}} -> + {error, ["Parse error: ", Err]}; + _Err -> + {error, ["Syntax error in: ", Str]} + end. |