From: Dmitry Kalyanov Date: Thu, 26 Mar 2009 19:22:55 +0000 (+0300) Subject: Added evaluation functionality to text editor demo X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=8927fda599218ae99deb82fcb1362c03123c51b6;p=cl-gtk2.git Added evaluation functionality to text editor demo --- diff --git a/gtk/demo/text-editor.glade b/gtk/demo/text-editor.glade index cbdae12..2a2929f 100644 --- a/gtk/demo/text-editor.glade +++ b/gtk/demo/text-editor.glade @@ -1,6 +1,6 @@ - + Text Editor @@ -202,6 +202,17 @@ + + + True + Eval + gtk-execute + + + + True + + False diff --git a/gtk/demo/text-editor.ui b/gtk/demo/text-editor.ui index 841b1d8..3200db5 100644 --- a/gtk/demo/text-editor.ui +++ b/gtk/demo/text-editor.ui @@ -1,5 +1,5 @@ - + @@ -185,6 +185,17 @@ + + + True + Eval + gtk-execute + + + + True + + False diff --git a/gtk/gtk.demo.lisp b/gtk/gtk.demo.lisp index 75f2bcd..be3a412 100644 --- a/gtk/gtk.demo.lisp +++ b/gtk/gtk.demo.lisp @@ -594,7 +594,17 @@ :logo-icon-name "accessories-text-editor"))) (dialog-run d) (object-destroy d))) - (quit (&rest args) (object-destroy window))) + (quit (&rest args) (object-destroy window)) + (cb-eval (&rest args) + (let ((buffer (text-view-buffer text-view))) + (multiple-value-bind (i1 i2) (text-buffer-get-selection-bounds buffer) + (when (and i1 i2) + (with-gtk-message-error-handler + (let* ((text (text-buffer-slice buffer i1 i2)) + (value (eval (read-from-string text))) + (value-str (format nil "~A" value))) + (text-buffer-delete buffer i1 i2) + (text-buffer-insert buffer value-str)))))))) (builder-connect-signals-simple builder `(("new" ,#'new) ("open" ,#'cb-open) ("save" ,#'save) @@ -604,7 +614,8 @@ ("paste" ,#'paste) ("delete" ,#'cb-delete) ("about" ,#'about) - ("quit" ,#'quit))) + ("quit" ,#'quit) + ("eval" ,#'cb-eval))) (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (gtk-main-quit))) (g-signal-connect (text-view-buffer text-view) "changed" (lambda (b) (declare (ignore b)) (setf modified-p t) (set-properties))) (widget-show window)