20
20
%% Simple text viewer
22
22
%%------------------------------------------------------------
28
%%------------------------------------------------------------
32
24
-module(appmon_txt).
35
25
-export([start/0, start/1, print/1, fprint/1]).
37
27
%% gen_server stuff
38
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2]).
28
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
41
31
-define(LOADTXT, "Load file").
42
32
-define(SAVETXT, "Save file").
96
75
process_flag(trap_exit, true),
97
%%io:format("Starting editor w args: ~p~n", [Opts]),
102
%% after 6000 -> ok end,
105
terminate(Reason, State) ->
106
%%io:format("Terminating editor:~n", []),
81
terminate(_Reason, _State) ->
109
84
%%------------------------------------------------------------
110
85
%% gen server stuff
111
handle_call({add_txt, Txt}, From, State) ->
112
%%io:format("~p got call: ~p~n", [self(), Request]),
86
handle_call({add_txt, Txt}, _From, State) ->
113
87
do_insert_text(Txt),
114
88
scroll_to_last_line(),
115
89
{reply, ok, State};
116
handle_call({add_file, FileName}, From, State) ->
117
%%io:format("~p got call: ~p~n", [self(), Request]),
90
handle_call({add_file, FileName}, _From, State) ->
118
91
do_load_file(FileName),
119
92
{reply, ok, State};
120
handle_call(Request, From, State) ->
121
%%io:format("~p got call: ~p~n", [self(), Request]),
93
handle_call(_Request, _From, State) ->
122
94
{reply, ok, State}.
123
handle_cast(Request, State) ->
124
%%io:format("~p got cast: ~p~n", [self(), Request]),
95
handle_cast(_Request, State) ->
126
97
handle_info({gs, _, click, _, [?CLOSETXT|_]}, State) ->
127
%%d:d("handle_info: exit: Close button pressed~n", []),
128
98
{stop, normal, State};
129
99
handle_info({gs, _, click, _, [?LOADTXT|_]}, State) ->
134
104
{noreply, State};
136
106
handle_info({gs, _, destroy, _, _}, State) ->
137
%% ?D("handle_info: exit: window killed~n", []),
138
107
{stop, normal, State};
139
%%%handle_info({gs, _, click, _, [?HELPTXT|_]}, State) ->
140
%%% d:d("~p: help:~n", [node()]),
142
%%% {noreply, State};
143
%%%handle_info({gs, Id, click, {mode, Mode}, _}, State) ->
144
%%% %%io:format("handle_info: Setting mode: ~p~n", [Mode]),
145
%%% set_mode(Id, Mode),
146
%%% {noreply, State};
147
108
handle_info(Request, State) ->
148
109
io:format("~p got info: ~p~n", [self(), Request]),
149
110
print_status("Not implemented"),
213
171
H = gs:read(editor(), size),
214
172
R = gs:read(editor(), height),
216
%% io:format("Top: ~p, ~p - ~p~n", [TopRow, H, R]),
217
174
if TopRow > 0 -> gs:config(editor(), {vscrollpos, TopRow});
218
175
true -> gs:config(editor(), {vscrollpos, 0})
224
180
gs:config(editor(), {enable, false}).
229
183
gs:config(editor(), clear).
232
185
%%------------------------------------------------------------
233
186
%% Graphical stuff
264
217
FMB = gs:create(menubutton, MB, [{label, {text, "File"}}]),
265
218
FM = gs:create(menu, FMB, []),
266
%%gs:create(menuitem, FM, [{label, {text, ?LOADTXT}}]),
267
%%gs:create(menuitem, FM, [{label, {text, ?SAVETXT}}]),
268
%%gs:create(menuitem, FM, [{label, {text, ?SAVEASTXT}}]),
269
%%gs:create(menuitem, FM, [{itemtype, separator}]),
270
219
gs:create(menuitem, FM, [{label, {text, ?CLOSETXT}}]),
272
%% EMB = gs:create(menubutton, MB, [{label, {text, "Edit"}}]),
273
%% EM = gs:create(menu, EMB, []),
276
% HMB = gs:create(menubutton, MB, [{label, {text, "Help"}}, {side, right}]),
277
% HM = gs:create(menu, HMB, []),
278
% gs:create(menuitem, HM, [{label, {text, ?HELPTXT}}]),
280
221
gs:config(Win, {configure, true}),
284
%% io:format("Resizing to: ~p, ~p~n", [W, H]),
286
225
gs:config(editor(), [{width, W}, {height, H-label_h()-menu_h()}]),
288
226
gs:config(status(), [{y, H-label_h()}, {width, W}]),
293
229
%%------------------------------------------------------------
294
230
%% ui_list_dialog(
310
246
Win = gs:create(window, winroot(), [{title, Title},
311
247
{width, W},{height, H}]),
312
Ok = gs:create(button, Win, [{x, 10}, {y,10}, {width, 50}, {height, 20},
248
Ok = gs:create(button, Win, [{x, 10}, {y,10},
249
{width, 50}, {height, 20},
313
250
{label, {text, "Ok"}}]),
314
Cn = gs:create(button, Win, [{x, 70}, {y,10}, {width, 50}, {height, 20},
251
Cn = gs:create(button, Win, [{x, 70}, {y,10},
252
{width, 50}, {height, 20},
315
253
{label, {text, "Cancel"}}]),
317
gs:create(label, Win, [{x, 10}, {y, 50}, {width, 60}, {height, 20},
255
gs:create(label, Win, [{x, 10}, {y, 50},
256
{width, 60}, {height, 20},
318
257
{label, {text, LeadText}}]),
319
Box = gs:create(entry, Win, [{x, 10}, {y, 70}, {width, 160}, {height, 20},
258
Box = gs:create(entry, Win, [{x, 10}, {y, 70},
259
{width, 160}, {height, 20},
320
260
{keypress, true}]),
321
261
List = gs:create(listbox, Win, [{x, 10}, {y, 100}, {width, 180},
323
263
{items, TxtList}, {vscroll, right},
324
264
{hscroll, false}, {click, true},
325
{doubleclick, true}, {keypress, true}]),
326
267
gs:config(Win, {map, true}),
328
269
RetVal = ui_load_loop(Box, List, Ok, Cn),
339
280
ui_load_loop(Box, List, Ok, Cn);
340
281
{gs, Ok, click, _, _} ->
341
282
{ok, gs:read(Box, text)};
342
{gs, List, doubleclick, _, [Idx, Txt|_]} ->
283
{gs, List, doubleclick, _, [_Idx, Txt|_]} ->
344
{gs, List, click, _, [Idx, Txt|_]} ->
285
{gs, List, click, _, [_Idx, Txt|_]} ->
345
286
gs:config(Box, {text, Txt}),
346
287
ui_load_loop(Box, List, Ok, Cn);
354
292
%% The status row at the bottom of the window
355
293
set_status(Id) -> put(status_row, Id).
356
294
status() -> get(status_row).