new-inspector.lisp 16 KB
Newer Older
Dave Cooper's avatar
Dave Cooper committed
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
;;
;; Copyright 2002, 2009 Genworks International and Genworks BV 
;;
;; This source file is part of the General-purpose Declarative
;; Language project (GDL).
;;
;; This source file contains free software: you can redistribute it
;; and/or modify it under the terms of the GNU Affero General Public
;; License as published by the Free Software Foundation, either
;; version 3 of the License, or (at your option) any later version.
;; 
;; This source file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; Affero General Public License for more details.
;; 
;; You should have received a copy of the GNU Affero General Public
;; License along with this source file.  If not, see
;; <http://www.gnu.org/licenses/>.
;; 

#|
(in-package :tasty)



(defmacro ignore-errors-with-warning (&rest body)
  (let ((values (gensym))
	(error (gensym)))
    `(let* ((,values (multiple-value-list (ignore-errors ,@body)))
	    (,error (second ,values)))
       (if (and ,error (typep ,error 'error))
	   (progn (warn "~a" ,error)
		  (format nil "! ERROR: ~a !" ,error))
	 (apply #'values ,values)))))



(defun one-line (string)
  (replace-regexp* (replace-regexp* string (format nil "~%") " ") "'" "\\'" ))

(defparameter *suppress-%%-messages?* t)

;;
;; FLAG -- replace with abstract associative map
;;
(defparameter *internal-keywords*
  (list :query-plist :aggregate :all-mixins :background-color 
	:base64-encoded-root-path :bashee :beziers :bounding-bbox
	:check-sanity? :color-decimal :color-hex :color-palette :cookies-received
	:cookies-to-send :dash-pattern :dom-id :fill-color-decimal
	:fixed-url-prefix :header-plist :home-page :instance-id 
	:last-visited-root-path :left-handed? :local-bbox :local-box
	:local-center :local-left-handed? :local-orientation :main-view
	:obliqueness :parent-tree :plain-url? :possible-nils 
	:quantify-box :query-toplevel :refresh-toggle :remote-id :respondent 
	:return-object :root-path-string :target :time-instantiated 
	:time-last-touched :transitory-slots :tree-root 
	:url-encoded-root-path :use-local-box? :viewable-slots 
	:viewpoints :visible-children :vrml-center))

(define-object new-inspector (sheet-section) ;;(base-html-sheet)


  :input-slots
  ((node-root-path nil :settable) 
   root-object
   tree-toplevel
   tatu-root colors-default tree-type tree-node  
   display-controls-hash
   perform-action-function click-mode 
   (relative-font-size "-1")
   
   (js-to-eval "initInspectorTable();") ;; FLAG -- SvdE @ 090909 -- added slot to attach js for behavior inspector table
   
   (node (when (the root-object) (the root-object (follow-root-path (the node-root-path)))))

   (expand? (< (the depth) 1) :settable)
   (depth 0)
   
   )

  :computed-slots
  (   
   
   (show-settables? nil :settable)
   

   (messages-local (set-difference (the node (message-list :message-type :local))
				   (append (the node (message-list :message-type :local 
								   :category :methods))
					   (the node (message-list :message-type :local
								   :category :uncached-attributes)))))
   
   #+nil
   (messages (the (filter-messages
		   (set-difference (the :node (:message-list))
			       (append (the
					   :node
					 (:message-list :category :methods))
				       (the :node (:message-list
						   :category
						   :uncached-attributes)))))))
   
   (message-category-list (the :node (:message-list :return-category? t)))
   (message-local-list (the :node (:message-list :message-type :local))) 
   (message-list (the :node (:message-list)))
   (category-list (let (result)
		    (dolist (entry (the message-category-list) (nreverse result))
		      (if (not (member entry (the message-list)))
			  (push entry result)))))
   (type-list (let (result)
		(dolist (entry (the message-list) (nreverse result))
		  (if (member entry (the message-local-list))
		      (push :local result)
		    (push :global result)))))
   
   (message-triplets ;;message-category-type
    (mapcar #'list 
	    (the message-list)
	    (the category-list)
	    (the type-list)))
   
   (messages-to-be-filtered (append (the :node (:message-list :category :methods))
				    (the :node (:message-list :category :uncached-attributes))))
   
   (semi-filtered-message-triplets ;;message-category-type
    (let (result)
      (dolist (triplet (the message-triplets) (nreverse result))
	(if (equal (member (first triplet) (the messages-to-be-filtered)) nil)
	    (push triplet result)))))
   
   (filtered-message-triplets ;;message-category-type
    (the (filter-messages (the semi-filtered-message-triplets))))

   
   (check-links nil :settable)
   
   
   
   (main-view
    (with-cl-who-string ()
      (if (the node)
	  (str (the inspector-node-view))
	(str "No Object Instantiated"))))

   (inspector-node-view
    (with-cl-who-string ()
      ;; header first, conforming jquery ui style framework
      ((:div :class "header ui-widget-header")
       (str (the node strings-for-display)))
          ;;(esc (format nil "~s" (cons 'the (reverse (butlast (the node-root-path))))))
          ;;(unless (butlast (the node-root-path))
      ;;(htm " Root Object")))
      
      ;;
      ;;FLAG -- SvdE @ 090909 -- Removed (the node type), now available in normal slot table
      ;;
      #+nil
      ((:div :class "header")
       ((:span :class "ui-icon ui-icon-tag fltlft" :title "this Object is of type ..."))
       "type: "(esc (format nil "~s" (the node type))))
      ;; rest of the inspector below, inside an UL/LI list, with tables for prop-value
      ;; all conforming ui style framework
      ;;((:ul :id "inspector-root" :class "tasty-inspector") ;;"tasty-inspector") 
      ;; ((:li)
	;;
	;; FLAG 090908-JB: removing this arbitrary display code from the inspector for now
	;;

	((:table :class "inspector-table")
	 ((:thead)
	  (:tr
	   (:th "slot-name")
	   (:th "value")
	   (:th "slot-category")
	   (:th "slot-type")
	  ))
	 ((:tbody)
	  
	  ;;
	  ;; FLAG -- SvdE @ 090909 -- remove separate table for settable slots
	  ;;
	  #+nil
	  ((:tr :class "odd")
	   (:td (:span :class "ui-icon ui-icon-pencil"))
	   (:td "Settables")
	   (:td (str (the settables-form main-div)))
	   (:td "__global__")
	   )
	  ;;
	  ;; FLAG 090908-JB: this is old code from that builds the table
	  ;;


	  (let ((count 1))
	    (dolist (inspector-node (list-elements (the nodes)))
	      (let ((message (the-object inspector-node message)))
		(incf count)
		(htm ((:tr :class (if (evenp count) "even" "odd"))
		      (:td (str (the-object inspector-node message)))
		      (:td 
		       
		       ;;
		       ;; FLAG -- push everything to do with node into inspector-node
		       ;;
		       (let ((slot-status (if (the expand?) (the node (slot-status message)) :unbound)))
			 (case slot-status
			   (:unbound 
			    (htm ((:span :style "color: blue; font-style: italic; cursor: pointer;"
					 :onclick (the (gdl-ajax-call :function-key :message-evaluate
								      :arguments (list message))))
				  "Unbound")))

			   (otherwise 
			    (if (the-object inspector-node settable?)
				
				(str (the-object inspector-node input-field html-string))
			      
			      #+nil
			      (htm ((:input :type :text 
					    :name (base64-encode-safe (string message))
					    :value (the-object inspector-node value)
					    )))
					    ;;:onchange 
					   ;; (the (gdl-ajax-call :function-key :evaluate-slot
					;;			      :arguments (list ))))
							 
			      
				 
				 
			    (str (the-object inspector-node value-display)))))))
		      
		      
		      (:td (str (the-object inspector-node message-category)))
		      (:td (str (the-object inspector-node message-type))))))))))	  
	  ))
   
      
   )
  
  :hidden-objects
  ((nodes :type 'inspector-node 
	   :depth (1+ (the depth))
	   :sequence (:size (length (the filtered-message-triplets)));;(length (the messages)))
	   :respondent (the respondent)
	   :message (first (nth (the-child index) (the filtered-message-triplets)));;(nth (the-child index) (the messages))
	   :message-category (second (nth (the-child index) (the filtered-message-triplets)))
	   :message-type (third (nth (the-child index) (the filtered-message-triplets)))
	   :parent-node (the node)
	   :pass-down (
		       tatu-root root-object
		       tree-toplevel tatu-root colors-default 
		       tree-type tree-node display-controls-hash
		       perform-action-function click-mode  relative-font-size))

   (settables-form :type 'settables-form
		   :pass-down (show-settables?)))

  
  :functions
  (   
   
   (filter-messages 
    (message-triplets-list)
    (safe-sort
     (remove-if
      #'(lambda (triplet)
	  (or (member (first triplet) *internal-keywords*)
	      (and *suppress-%%-messages?*
		   (let ((string (string (first triplet))))
		     (and
		      (> (length string) 2)
		      (or (string-equal (subseq string 0 2) "$$")
			  (and (eql (aref string 0) #\%)
			       (or (eql (aref string 1) #\%)
				   (eql
				    (aref string (1- (length string)))
				    #\%)))))))))
      message-triplets-list)
     #'string<
     :key #'(lambda(triplet) (first triplet))))
   
   
   
   (perform-action!
    (object)
    (the tatu-root (perform-action! object)))
   
   (message-evaluate 
    (message) 
    ;;
    ;; FLAG -- note we have to bash the view-toggle because no bashing
    ;; is actually happening when we evaluate the message, so the view
    ;; does not update by itself.
    ;;
    (the toggle-view-toggle!) 
    
    (the (set-slot! :expand? t))
    
    (multiple-value-bind (value error) (ignore-errors (the node (evaluate message)))
      (let* ((error? (and error (typep error 'error))) (value (if  error? (format nil "ERROR: ~a" error) value)))
			 
	(when error? (the node (set-slot! message value))))))
   
   (set-object! (object) (the (set-slot! :node-root-path (the-object object root-path))))))








(define-object inspector-node (new-inspector)
  
  :input-slots ((message nil)
		(message-type nil)
		(message-category nil)
		;;
		;; FLAG -- SvdE @090909 -- is :settable-optional-input-slots the correct category? ta2 inspector used required-input-slots
		;;
		(settable? (if (equal (the message-category) :settable-optional-input-slots) t nil)) 
		parent-node
		root-object
		tatu-root
		click-mode
		(value (with-error-handling () (the parent-node (evaluate (the message))))))
  
  :computed-slots ((value-type (if (the 3d-vector?)
				   :gdl-3d-point
				   (typecase (the value)
				     (list (when (consp (the value)) :list))
				     (gdl::quantification :gdl-sequence)
				     (gdl::gdl-basis :gdl-atom))))


		   (value-cardinality (case (the value-type)
					(:list (length (the value)))
					(:gdl-sequence (the value number-of-elements))
					(otherwise 0)))

		   (truncated-sequence (unless (zerop (the value-cardinality))
					 (with-output-to-string (ss)
					   (let ((*print-length* 3))
					     (pprint (the value) ss)))))
		   
		   (expanded? nil :settable)

		   (clickable? (and (not (the expanded?))
				    (or (member (the value-type)
						(list :list :gdl-sequence :gdl-atom))
					(and (eql (the value-type) :gdl-3d-point)
					     (member (the click-mode)
						     (list :add-leaves
							   :add-leaves*
							   :add-node
							   :draw-leaves
							   :draw-node
							   :delete-leaves))))))

		   (3d-vector? (and (typep (the value) 'vector)
				    (= (length (the value)) 3)
				    (every #'floatp (the value))))
		   
		   (value-display
		    (let* ((value (the value))
			   (gdl-object? (eql (class-of (class-of value))
					     (find-class 'gdl-class))))
		      (with-cl-who-string ()
			((:span :style (format nil "color: ~a; ~a" 
					       (if (the clickable?) "blue" "black")
					       (if (the clickable?) "cursor: pointer;" ""))
				:onclick (case (the value-type)
					   (:gdl-atom
					      (the (gdl-ajax-call 
						    :function-key :perform-action!
						    :arguments (list value))))

					   (:gdl-3d-point
					      (print-variables (the clickable?)
							       (the click-mode))
					      (when (the clickable?)
						(the (gdl-ajax-call
						      :function-key :perform-action!
						      :arguments (list (the point))))))

					   ((:list :gdl-sequence)
					      (unless (the expanded?)
						(the (gdl-ajax-call
						      ;;:bashee self
						      :function-key :set-slot!
						      :arguments (list :expanded? t)))))))

			 (cond ((or (eql (the value-type) :list)
				    (eql (the value-type) :gdl-sequence))
				(if (the expanded?)
				    (htm ((:table :border 1)
					  (:tr (:td ((:span :style "color: blue; cursor: pointer;"
							    :onclick (the (gdl-ajax-call
									   :function-key :set-slot!
									   :arguments (list :expanded? nil))))
						     "X"))
					       (:td (str
						     (ecase (the value-type)
						       (:list "A List")
						       (:gdl-sequence "A GDL Sequence")))))
					  (let ((index -1))
					    (dolist (row (list-elements (the sequence-elements)))
					      (htm (:tr (:td (str (incf index)))
							(:td (str (the-object row value-display)))))))))
				    (htm (:pre (esc (the truncated-sequence))))))
			       (gdl-object? (htm (esc (format nil "~s" value))))
			       ((eql (the value-type) :gdl-3d-point)
				(htm (esc (the point strings-for-display))))
			       (t (htm (fmt "~s" value)))))))))

  :objects ((point :type (if (the 3d-vector?) 'point 'null-object)
		   :center (when (the 3d-vector?) (the value))
		   :strings-for-display (format nil "~s" (the value)))

	    (sequence-elements :type 'inspector-node
			       :sequence (:size (the value-cardinality))
			       :pass-down (root-object tatu-root click-mode)
			       :value (the (get-value-element (the-child index)))))
  :hidden-objects
  (
   (input-field :type 'text-form-control
		:hidden? nil
		:onchange (the (gdl-ajax-call :function-key :evaluate-input-field!
					      :arguments (list (the-child value))))
					      ;;(the (set-slot! :value (the-child value)));;
					      ;;(the (gdl-ajax-call :form-controls (the-child)))
		;;:onfocus (the-child onchange)
		:prompt nil
		:default (the value)
		:size 20)
   )

  :functions
  (
   ;;
   ;; FLAG! --SvdE @ 090909 Does not work correctly
   ;;
   (evaluate-input-field! 
    (input-value)
    (the inspector node (set-slot! (the message) input-value)))
			  
   
   (get-value-element
    (index)
    (case (the value-type)
      (:list (nth index (the value)))
      (:gdl-sequence (the value (get-member index)))))))



(define-object settables-form (base-html-sheet)
  
  :input-slots
  (show-settables?))



(define-lens (html-format settables-form)()
  :output-functions
467
  ((inner-html
Dave Cooper's avatar
Dave Cooper committed
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
    ()
    (with-cl-who ()
      (htm
       ((:span :style "cursor: pointer; color: blue; font-style: oblique;"
	       :onclick (the (gdl-ajax-call :function-key :set-slot!
					    :arguments (list :show-settables? (not (the show-settables?))))))
	(str (if (the show-settables?) "X" "Show Settables!"))))))))




(define-object viewable-link (base-html-sheet)
  :input-slots (node message)
  
  :computed-slots ((strings-for-display (format nil "~a" (the message))))
  
  :functions
  ((before-present!
    ()
    (ignore-errors-with-warning (the node (evaluate (the message)))))))


(define-lens (html-format viewable-link)()
  :output-functions
  ((main-sheet () (write-the return-object main-sheet))))



(define-object switch-viewables (base-html-sheet)

  :input-slots
  (return-object)
  
  :computed-slots
  ((show-viewables? nil :settable)
   (strings-for-display (if (the show-viewables?) "X" "Uncached Slots")))
  
  :functions
  ((before-present! () (the (set-slot! :show-viewables? (not (the show-viewables?)))))))


(define-lens (html-format switch-viewables)()
  :output-functions
  ((main-sheet () (write-the return-object main-sheet))))



|#