34
35:- module(pce_nedit, []). 36:- use_module(library(pce)). 37:- use_module(library(pce_meta)). 38
39:- multifile
40 prolog_edit:locate/3, 41 prolog_edit:locate/2,
42 prolog_edit:select_location/3. 43
44
45 48
49prolog_edit:(locate(ClassName, class(ClassName), Location) :-
50 locate(class(ClassName), Location)).
51
52prolog_edit:locate(class(ClassName), Location) :- 53 atom(ClassName),
54 get(@pce, convert, ClassName, class, Class),
55 \+ get(Class, creator, built_in),
56 source(Class, Location).
57prolog_edit:locate(SourceLoc, [file(File)|Extra]) :-
58 object(SourceLoc),
59 send(SourceLoc, instance_of, source_location),
60 get(SourceLoc, file_name, File),
61 ( get(SourceLoc, line_no, Line),
62 Line \== @nil
63 -> Extra = [line(Line)]
64 ; Extra = []
65 ).
66prolog_edit:locate(Object, Location) :- 67 source(Object, Location).
68prolog_edit:locate(Object, Location) :- 69 object(Object),
70 get(Object, class, Class),
71 source(Class, Location).
72prolog_edit:locate(send(Receiver, Selector), Location) :-
73 receiver_class(Receiver, Class),
74 ( implements(Class, send(Selector), Method),
75 source(Method, Location)
76 ; method_source(Class, send(Selector), Location)
77 ).
78prolog_edit:locate(get(Receiver, Selector), Location) :-
79 receiver_class(Receiver, Class),
80 ( implements(Class, get(Selector), Method),
81 source(Method, Location)
82 ; method_source(Class, get(Selector), Location)
83 ).
84prolog_edit:(locate(->(Receiver, Selector), Location) :- !,
85 locate(send(Receiver, Selector), Location)).
86prolog_edit:(locate(<-(Receiver, Selector), Location) :- !,
87 locate(get(Receiver, Selector), Location)).
88
89source(Object, [file(Path)|T]) :-
90 object(Object),
91 send(Object, has_get_method, source),
92 get(Object, source, Loc),
93 Loc \== @nil,
94 get(Loc, file_name, FileName),
95 absolute_file_name(FileName, Path),
96 get(Loc, line_no, Line),
97 ( integer(Line)
98 -> T = [line(Line)]
99 ; T = []
100 ).
101
102receiver_class(Object, Class) :-
103 object(Object),
104 !,
105 get(Object, class_name, Class).
106receiver_class(Class, Class).
107
108method_source(ClassName, send(Selector), [file(File),line(Line)]) :-
109 var(ClassName),
110 pce_principal:pce_lazy_send_method(Selector, ClassName, Binder),
111 arg(4, Binder, source_location(File, Line)),
112 \+ get(@classes, member, ClassName, _).
113method_source(ClassName, get(Selector), [file(File),line(Line)]) :-
114 var(ClassName),
115 pce_principal:pce_lazy_get_method(Selector, ClassName, Binder),
116 arg(4, Binder, source_location(File, Line)),
117 \+ get(@classes, member, ClassName, _).
118
119
120 123
125
126prolog_edit:select_location(Pairs, _Spec, Location) :-
127 Pairs \= [_], 128 object(@event),
129 send(@event, instance_of, event), 130 !,
131 ( Pairs == []
132 -> send(@event?receiver, report, error, 'No match'),
133 Location = [] 134 ; get(@event?receiver, frame, Frame),
135 new(D, dialog('Select object to edit')),
136 send(D, append, label(title, 'Click object to edit')),
137 length(Pairs, Len),
138 LBH is min(Len, 10),
139 send(D, append, new(LB, list_browser(@default, 30, LBH))),
140 fill_browser(Pairs, 1, LB),
141 send(LB, select_message, message(D, return, LB?selection?object)),
142 send(D, append,
143 new(C, button(cancel, message(D, destroy)))),
144 send(C, alignment, right),
145 send(D, resize_message, message(D, layout, @arg2)),
146 send(D, modal, transient),
147 send(D, transient_for, Frame),
148 ( get(D, confirm_centered, Frame?area?center, Rval)
149 -> send(D, destroy),
150 Location = Rval
151 ; Location = []
152 )
153 ).
154
155fill_browser([], _, _).
156fill_browser([Location-Spec|T], N, LB) :-
157 message_to_string(edit(target(Location-Spec, N)), Label),
158 send(LB, append,
159 dict_item(Label, object := prolog(Location))),
160 NN is N + 1,
161 fill_browser(T, NN, LB)