<commit_before>;;;; cocoa.lisp --- cocoa helper functions & data

(in-package :interface)

(defparameter *window* nil)

(defmacro on-main-thread (&rest actions)
  `(ccl::call-in-event-process
     #'(lambda ()
         ,@actions)))

(defun ns-to-lisp-string (ns-str)
  (if (and (not (eql (%null-ptr) ns-str)) (plusp (#/length ns-str)))
    (ccl::%get-utf-8-cstring (#/UTF8String ns-str))
    ""))

(defclass next-window (ns:ns-window) ()
  (:metaclass ns:+ns-object))<commit_msg>added view classes<commit_after>;;;; cocoa.lisp --- cocoa helper functions & data

(in-package :interface)

(defparameter *window* nil)
(defparameter *next-view* nil)

(defclass minibuffer-view (ns:ns-view)
  ((input-buffer :accessor input-buffer)
   (completion-table :accessor completion-table))
    (:metaclass ns:+ns-object))

(defmethod initialize-instance :after ((self minibuffer-view)
				       &key &allow-other-keys)
  (let ((input-field (make-instance 'ns:ns-text-field))
	(candidate-table (make-instance 'ns:ns-table-view)))
    (#/setTranslatesAutoresizingMaskIntoConstraints: self #$NO)
    (#/setTranslatesAutoresizingMaskIntoConstraints: input-field #$NO)
    (#/setTranslatesAutoresizingMaskIntoConstraints: candidate-table #$NO)
    (setf (input-buffer self) input-field)
    (setf (completion-table self) candidate-table)
    (#/addSubview: self input-field)
    (#/addSubview: self candidate-table)
    (constrain (= (center-x input-field) (center-x self)))
    (constrain (= (width input-field) (width self)))
    (constrain (= (top input-field) (top self)))
    (constrain (= (height input-field) 20))
    (constrain (= (top candidate-table) (bottom input-field)))
    (constrain (= (bottom candidate-table) (bottom self)))
    (constrain (= (width candidate-table) (width self)))))

(defclass fill-container-view (ns:ns-view)
  ((fill-view :accessor fill-view
		    :initarg :fill-view))
  (:default-initargs
   :fill-view nil)
  (:metaclass ns:+ns-object))

(defmethod initialize-instance :after ((self fill-container-view)
                                       &key (fill-view nil) &allow-other-keys)
  (when (view-p fill-view)
    (#/addSubview: self fill-view)
    (constrain-size-relative-to fill-view self :rel :=))
  (#/setTranslatesAutoresizingMaskIntoConstraints: self #$NO))

(defmethod set-fill-view ((self fill-container-view) view)
  (on-main-thread
   (when (fill-view self)
     (#/removeFromSuperview (fill-view self)))
   (#/addSubview: self view)
   (constrain-size-relative-to view self :rel :=))
  (setf (fill-view self) view))

(defclass next-view (ns:ns-view)
  ((%fill-container-view :accessor fill-container-view)
   (%minibuffer-view :accessor minibuffer-view)
   (minibuffer-height-constraint :accessor minibuffer-height-constraint))
  (:metaclass ns:+ns-object))

(defmethod initialize-instance :after ((self next-view)
				       &key &allow-other-keys)
  (let ((fvc (make-instance 'fill-container-view))
	(mb (make-instance 'minibuffer-view)))
    (#/addSubview: self fvc)
    (#/addSubview: self mb)
    (setf (fill-container-view self) fvc)
    (setf (minibuffer-view self) mb)
    (constrain (= (top fvc) (top self)))
    (constrain (= (width fvc) (width self)))
    (constrain (= (bottom fvc) (top mb)))
    (constrain (= (bottom mb) (bottom self)))
    (constrain (= (width mb) (width self)))
    (setf (minibuffer-height-constraint self)
	  (constrain (= (height mb) 100)))))

(defmethod hide-minibuffer ((self next-view))
    (#/setConstant: (minibuffer-height-constraint self) 0))

(defmethod show-minibuffer ((self next-view))
    (#/setConstant: (minibuffer-height-constraint self) 100))

(defmacro on-main-thread (&rest actions)
  `(ccl::call-in-event-process
     #'(lambda ()
         ,@actions)))

(defun ns-to-lisp-string (ns-str)
  (if (and (not (eql (%null-ptr) ns-str)) (plusp (#/length ns-str)))
    (ccl::%get-utf-8-cstring (#/UTF8String ns-str))
    ""))

(defclass next-window (ns:ns-window) ()
  (:metaclass ns:+ns-object))
{'fraction_non_alphanumeric': 0.17265644634330235, 'fraction_numerical': 0.003267152550892184, 'mean_word_length': 3.8536585365853657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5179810', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1371, 'n_words': 310}