2022-07-30 17:15:38 +00:00
|
|
|
;;; sclang-widgets.el --- Widget definitions for SCLang -*- coding: utf-8; lexical-binding: t -*-
|
2009-01-02 19:06:25 +00:00
|
|
|
|
2022-07-30 17:15:38 +00:00
|
|
|
;; Copyright (C) 2005 Free Software Foundation, Inc.
|
2009-01-02 19:06:25 +00:00
|
|
|
|
2019-12-12 09:37:11 +00:00
|
|
|
;; Author: Mario Lang <mlang@blind.guru>
|
2009-01-02 19:06:25 +00:00
|
|
|
|
|
|
|
;; This file is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
;; This 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 General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to
|
2009-09-26 06:17:48 +00:00
|
|
|
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2009-04-20 08:38:27 +00:00
|
|
|
;; Boston, MA 02110-1301, USA.
|
2009-01-02 19:06:25 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
2009-09-26 06:17:48 +00:00
|
|
|
;;
|
2022-07-30 17:15:38 +00:00
|
|
|
;; Widget definitions for SCLang
|
2009-01-02 19:06:25 +00:00
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2019-12-26 10:12:53 +00:00
|
|
|
(require 'cl-lib)
|
2021-08-09 16:05:52 +00:00
|
|
|
(require 'sclang-util)
|
|
|
|
(require 'sclang-language)
|
|
|
|
(require 'sclang-interp)
|
2009-01-02 19:06:25 +00:00
|
|
|
|
2022-07-30 17:15:38 +00:00
|
|
|
(require 'widget)
|
|
|
|
(require 'wid-edit)
|
|
|
|
|
2009-01-02 19:06:25 +00:00
|
|
|
(defvar sclang-widgets nil)
|
|
|
|
(make-variable-buffer-local 'sclang-widgets)
|
|
|
|
|
|
|
|
;; Button (not used yet)
|
|
|
|
|
|
|
|
(define-widget 'sclang-button 'item
|
|
|
|
"A button."
|
|
|
|
:create #'sclang-widget-button-create
|
|
|
|
:action #'sclang-widget-button-action)
|
|
|
|
|
|
|
|
(defun sclang-widget-button-create (widget)
|
|
|
|
"Create WIDGET at point in the current buffer."
|
|
|
|
(widget-specify-insert
|
|
|
|
(let ((from (point))
|
2022-07-30 17:15:38 +00:00
|
|
|
button-begin button-end)
|
|
|
|
(setq button-begin from)
|
2009-01-02 19:06:25 +00:00
|
|
|
(insert (widget-get-indirect widget :button-prefix))
|
|
|
|
|
|
|
|
(princ (nth (widget-get widget :value) (widget-get widget :states)) (current-buffer))
|
|
|
|
|
|
|
|
(insert (widget-get-indirect widget :button-suffix))
|
2022-07-30 17:15:38 +00:00
|
|
|
(setq button-end from)
|
2009-01-02 19:06:25 +00:00
|
|
|
|
|
|
|
;; Specify button, and insert value.
|
|
|
|
(and button-begin button-end
|
2022-07-30 17:15:38 +00:00
|
|
|
(widget-specify-button widget button-begin button-end)))
|
2009-01-02 19:06:25 +00:00
|
|
|
(let ((from (point-min-marker))
|
2022-07-30 17:15:38 +00:00
|
|
|
(to (point-max-marker)))
|
2009-01-02 19:06:25 +00:00
|
|
|
(set-marker-insertion-type from t)
|
|
|
|
(set-marker-insertion-type to nil)
|
|
|
|
(widget-put widget :from from)
|
|
|
|
(widget-put widget :to to)))
|
|
|
|
(widget-clear-undo))
|
|
|
|
|
2022-07-30 17:15:38 +00:00
|
|
|
(defun sclang-widget-button-action (widget _event)
|
|
|
|
"Set button action for WIDGET."
|
2009-01-02 19:06:25 +00:00
|
|
|
(widget-value-set widget
|
2022-07-30 17:15:38 +00:00
|
|
|
(if (>= (widget-get widget :value) (1- (length (widget-get widget :states))))
|
|
|
|
0
|
|
|
|
(1+ (widget-get widget :value))))
|
2009-01-02 19:06:25 +00:00
|
|
|
(sclang-eval-string
|
|
|
|
(sclang-format "EmacsWidget.idmap[%o].valueFromEmacs(%o)"
|
2022-07-30 17:15:38 +00:00
|
|
|
(widget-get widget :id) (widget-get widget :value))))
|
2009-01-02 19:06:25 +00:00
|
|
|
|
|
|
|
(sclang-set-command-handler
|
|
|
|
'_widgetSetStates
|
|
|
|
(lambda (arg)
|
2019-12-26 10:12:53 +00:00
|
|
|
(cl-multiple-value-bind (buffer id states value) arg
|
2009-01-02 19:06:25 +00:00
|
|
|
(with-current-buffer (get-buffer buffer)
|
2019-12-26 10:12:53 +00:00
|
|
|
(let ((widget (cdr (cl-find id sclang-widgets :key 'car))))
|
2022-07-30 17:15:38 +00:00
|
|
|
(widget-put widget :states states)
|
|
|
|
(widget-value-set widget value)
|
|
|
|
value)))))
|
2009-01-02 19:06:25 +00:00
|
|
|
|
|
|
|
(define-widget 'sclang-slider 'default
|
|
|
|
"Slider widget."
|
|
|
|
:size 20
|
|
|
|
:create #'sclang-widget-slider-create
|
|
|
|
:button-prefix "["
|
|
|
|
:button-suffix "]"
|
|
|
|
:value 0.5
|
|
|
|
:value-get #'widget-value-value-get
|
|
|
|
:value-set #'sclang-widget-slider-value-set
|
|
|
|
:action (lambda (widget event)
|
2022-07-30 17:15:38 +00:00
|
|
|
(let ((pos (if event (posn-point (event-start event)) (point))))
|
|
|
|
(widget-value-set widget (/ (float (- pos (widget-get widget :from))) (widget-get widget :size))))))
|
2009-01-02 19:06:25 +00:00
|
|
|
|
|
|
|
(defun sclang-widget-slider-create (widget)
|
|
|
|
"Create WIDGET at point in the current buffer."
|
|
|
|
(widget-specify-insert
|
|
|
|
(let ((from (point))
|
2022-07-30 17:15:38 +00:00
|
|
|
(inhibit-redisplay t)
|
|
|
|
button-begin button-end)
|
|
|
|
(setq button-begin from)
|
2009-01-02 19:06:25 +00:00
|
|
|
(insert (widget-get-indirect widget :button-prefix))
|
|
|
|
|
|
|
|
(insert-char ?- (widget-get widget :size))
|
|
|
|
(backward-char (1+ (widget-put widget :current-pos (- (widget-get widget :size) (round (* (widget-get widget :value) (widget-get widget :size)))))))
|
|
|
|
(delete-char 1) (insert "|")
|
|
|
|
(goto-char (point-max))
|
|
|
|
(insert (widget-get-indirect widget :button-suffix))
|
|
|
|
(setq button-end (point))
|
|
|
|
|
|
|
|
;; Specify button
|
|
|
|
(and button-begin button-end
|
2022-07-30 17:15:38 +00:00
|
|
|
(widget-specify-button widget button-begin button-end)))
|
2009-01-02 19:06:25 +00:00
|
|
|
(let ((from (point-min-marker))
|
2022-07-30 17:15:38 +00:00
|
|
|
(to (point-max-marker)))
|
2009-01-02 19:06:25 +00:00
|
|
|
(set-marker-insertion-type from t)
|
|
|
|
(set-marker-insertion-type to nil)
|
|
|
|
(widget-put widget :from from)
|
|
|
|
(widget-put widget :to to)))
|
|
|
|
(widget-clear-undo))
|
|
|
|
|
|
|
|
(defun sclang-widget-slider-value-set (widget value)
|
2022-07-30 17:15:38 +00:00
|
|
|
"Set slider WIDGET to VALUE."
|
2009-01-02 19:06:25 +00:00
|
|
|
(save-excursion
|
|
|
|
(let ((inhibit-read-only t))
|
|
|
|
(goto-char (widget-get widget :from))
|
|
|
|
(forward-char (widget-get widget :current-pos))
|
|
|
|
(insert "-") (delete-char 1)
|
|
|
|
(widget-put widget :value value)
|
|
|
|
(goto-char (widget-get widget :from))
|
|
|
|
(let ((n (round (* value (widget-get widget :size)))))
|
2022-07-30 17:15:38 +00:00
|
|
|
(widget-put widget :current-pos n)
|
|
|
|
(forward-char n)
|
|
|
|
(insert "|") (delete-char 1)))))
|
2009-01-02 19:06:25 +00:00
|
|
|
|
|
|
|
;; Class Tree
|
|
|
|
|
|
|
|
(require 'tree-widget)
|
|
|
|
(define-widget 'sclang-class-tree 'tree-widget
|
|
|
|
"Widget for displaying the SCLang Class Tree."
|
|
|
|
:dynargs #'sclang-widget-class-tree-dynargs)
|
|
|
|
|
|
|
|
(defun sclang-widget-class-tree-dynargs (widget)
|
2022-07-30 17:15:38 +00:00
|
|
|
"Class tree WIDGET."
|
2009-01-02 19:06:25 +00:00
|
|
|
(sclang-eval-sync (sclang-format "EmacsClassTree.dynargs(%o)"
|
2022-07-30 17:15:38 +00:00
|
|
|
(widget-get widget :tag))))
|
2009-01-02 19:06:25 +00:00
|
|
|
|
|
|
|
(define-widget 'sclang-file-position 'item
|
|
|
|
"File position link for the SCLang Class Tree widget."
|
|
|
|
:format "%[%t%]\n"
|
|
|
|
:action (lambda (widget event)
|
2022-07-30 17:15:38 +00:00
|
|
|
(find-file-other-window (widget-get widget :filename))
|
|
|
|
(goto-char (widget-get widget :char-pos))))
|
2009-01-02 19:06:25 +00:00
|
|
|
|
|
|
|
(defun sclang-class-tree (class-name)
|
|
|
|
"Display a tree-view of the sub-classes and methods of CLASS-NAME."
|
|
|
|
(interactive
|
|
|
|
(list (sclang-read-symbol "Class: " "Object" #'sclang-class-name-p)))
|
|
|
|
(sclang-eval-string (format "EmacsClassBrowser(%s)" class-name)))
|
|
|
|
|
2022-07-30 17:15:38 +00:00
|
|
|
|
2009-01-02 19:06:25 +00:00
|
|
|
(provide 'sclang-widgets)
|
2022-07-30 17:15:38 +00:00
|
|
|
|
2009-01-02 19:06:25 +00:00
|
|
|
;;; sclang-widgets.el ends here
|