<commit_before>(ns conexp.gui.draw.control.file-exporter
  (:require [conexp.gui.draw.control.util :refer :all]
            [conexp.gui.draw.scenes :refer :all]
            [conexp.gui.util :refer :all]
            [seesaw.core :refer [listen]])
  (:import java.io.File
           [javax.swing JButton JFileChooser]
           javax.swing.filechooser.FileNameExtensionFilter))

;;;

(defn- get-file-extension
  "Returns file extension of given file."
  [^File file]
  (let [name (.getName file),
        idx  (.lastIndexOf name ".")]
    (if-not (= -1 idx)
      (.toLowerCase (.substring name (+ 1 idx)))
      nil)))

(defn export-as-file
  "Installs a file exporter."
  [frame scn buttons]
  (let [^JButton save-button (make-button buttons "Export to File"),
        ^JFileChooser fc (JFileChooser.),
        jpg-filter (FileNameExtensionFilter. "JPEG Files" (into-array ["jpg" "jpeg"])),
        gif-filter (FileNameExtensionFilter. "GIF Files"  (into-array ["gif"])),
        png-filter (FileNameExtensionFilter. "PNG Files"  (into-array ["png"]))]
    (doto fc
      (.addChoosableFileFilter jpg-filter)
      (.addChoosableFileFilter gif-filter)
      (.addChoosableFileFilter png-filter))
    (listen save-button :action
            (fn [_]
              (let [retVal (.showSaveDialog fc frame)]
                (when (= retVal JFileChooser/APPROVE_OPTION)
                  (let [^File file (.getSelectedFile fc)]
                    (with-swing-error-msg frame "Error while saving"
                      (save-image scn file (get-file-extension file)))))))))
  nil)

;;;

nil<commit_msg>GUI: Added tikz to Filechooser<commit_after>(ns conexp.gui.draw.control.file-exporter
  (:require [conexp.gui.draw.control.util :refer :all]
            [conexp.gui.draw.scenes :refer :all]
            [conexp.gui.util :refer :all]
            [seesaw.core :refer [listen]]
            [conexp.gui.draw.scene-layouts :refer :all]
            [conexp.gui.draw.scenes :refer :all]
            [conexp.io.layouts :refer :all])
  (:import java.io.File
           [javax.swing JButton JFileChooser]
           javax.swing.filechooser.FileNameExtensionFilter))

;;;

(defn- get-file-extension
  "Returns file extension of given file."
  [^File file]
  (let [name (.getName file),
        idx  (.lastIndexOf name ".")]
    (if-not (= -1 idx)
      (.toLowerCase (.substring name (+ 1 idx)))
      nil)))

(defn export-as-file
  "Installs a file exporter."
  [frame scn buttons]
  (let [^JButton save-button (make-button buttons "Export to File"),
        ^JFileChooser fc (JFileChooser.),
        jpg-filter (FileNameExtensionFilter. "JPEG Files" (into-array ["jpg" "jpeg"])),
        gif-filter (FileNameExtensionFilter. "GIF Files"  (into-array ["gif"])),
        tikz-filter (FileNameExtensionFilter. "TIKZ Files" (into-array ["tikz"]))
        png-filter (FileNameExtensionFilter. "PNG Files"  (into-array ["png"]))]
    (doto fc
      (.addChoosableFileFilter jpg-filter)
      (.addChoosableFileFilter gif-filter)
      (.addChoosableFileFilter tikz-filter)
      (.addChoosableFileFilter png-filter))
    (listen save-button :action
            (fn [_]
              (let [retVal (.showSaveDialog fc frame)]
                (when (= retVal JFileChooser/APPROVE_OPTION)
                  (let [^File file (.getSelectedFile fc)]
                    (with-swing-error-msg frame "Error while saving"
                      (if (= "tikz" (get-file-extension file))
                        (write-layout :tikz (get-layout-from-scene scn) (.getAbsolutePath file))
                          (save-image scn file (get-file-extension file))))))))))
  nil)

;;;

nil
{'fraction_non_alphanumeric': 0.13968775677896467, 'fraction_numerical': 0.0010955902492467817, 'mean_word_length': 2.4003724394785846, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6958338', 'n_tokens_mistral': 1208, 'n_tokens_neox': 1151, 'n_words': 276}