1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%
-module(pman_module_info).
%% Window with module information (View->Module Info...)
%% External exports
-export([start/1]).
%% Record for keeping the loop state for the
%% module info process.
-record(state, {topwin, % GS identifier for top window
editor, % GS identifier for editor
module, % Name of the viewed module
parent}). % Pid of the parent
start(Module) ->
Self = self(),
spawn_link(fun() -> init(Module, Self) end).
init(Module, Parent) ->
process_flag(trap_exit, true),
GS = gs:start([{kernel,true}]),
Font = pman_win:font(GS),
WinTitle = lists:flatten(io_lib:format("Pman - Module Info: ~p",
[Module])),
WinOptions = [{title,WinTitle}, {width,550}, {height, 400},
{configure,true}, {keypress,true}, {destroy,true}],
TopWindow = gse:window(GS, WinOptions),
%% File menu
MenuBar = gse:menubar(TopWindow, []),
MBFile = gse:menubutton(MenuBar, [{label,{text," File "}},
{font,Font}, {underline, 1}]),
MenuFile = gse:menu(MBFile, []),
gse:named_menuitem('Save buffer', MenuFile,
[{label,{text,"Save buffer..."}},
{font,Font}, {underline,0}]),
gse:named_menuitem('Close', MenuFile,
[{label,{text,"Close"}},
{font,Font}, {underline,0}]),
%% Output part of window
Editor = gse:editor(TopWindow,
[{font,Font},
{x,3}, {y,40}, {width,546}, {height,348}]),
gse:config(Editor, [{keypress,true},
{insert,{'end',pman_win:module_data(Module)}}]),
gse:config(Editor, [{enable,false},
{vscroll,right}, {hscroll,bottom},
{wrap,none}]),
gse:map(TopWindow),
State = #state{topwin=TopWindow, editor=Editor, module=Module,
parent=Parent},
loop(State).
loop(State) ->
receive
%% Die if the parent dies
{'EXIT', Pid, _Reason} when Pid==State#state.parent ->
gse:destroy(State#state.topwin);
%% Ignore other exit signals (from file dialog window)
{'EXIT', _Pid, _Reason} ->
loop(State);
%% Window closed
{gs, _TopWindow, destroy, [], []} ->
ok;
%% Window resized or moved
{gs, _TopWindow, configure ,_Data, [W,H,_X,_Y|_]} ->
gs:config(State#state.editor, [{width,W-3}, {height,H-40}]),
loop(State);
%% Close - destroy window and exit process
{gs, 'Close', click, _Data, _Args} ->
gse:destroy(State#state.topwin),
ok;
%% Save Buffer - make filename and save buffer to file
{gs, 'Save buffer', click, _Data, _Args} ->
save_buffer(State),
loop(State);
%% Keyboard accelerator commands
{gs, _, keypress, [], [c,_,0,1]} -> % 'Close'
gse:destroy(State#state.topwin),
ok;
{gs, _, keypress, [], [s,_,0,1]} -> % 'Save buffer'
save_buffer(State),
loop(State);
{gs, _, keypress, _Data, _Args} ->
loop(State)
end.
save_buffer(State) ->
DefaultFile = atom_to_list(State#state.module) ++ ".module_info",
Result = tool_utils:file_dialog([{type,save}, {file,DefaultFile}]),
case Result of
%% User selected a file, now save the result
{ok, File, _Dir} ->
gs:config(State#state.editor, {save,File}),
Msg = "Module information saved in file\n" ++ File,
tool_utils:notify(State#state.topwin, Msg);
%% File dialog was cancelled in some way.
{error, _Reason} ->
ignore
end.
|