-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscript_table.clj
104 lines (91 loc) · 5.04 KB
/
script_table.clj
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
(ns burp-clj.script-table
(:require [seesaw.core :as gui]
[seesaw.bind :as bind]
[seesaw.table :as table]
[seesaw.border :as border]
[burp-clj.state :as state]
[seesaw.mig :refer [mig-panel]]
[seesaw.swingx :as guix]
[burp-clj.extender :as extender]
[burp-clj.helper :as helper]
[burp-clj.utils :as utils]
[burp-clj.scripts :as script]
[burp-clj.i18n :as i18n]
[taoensso.timbre :as log]
[burp-clj.table-util :as table-util]))
(def script-cols-info (when-not *compile-files*
[{:key :running
:text (i18n/ptr :script-list-form/col-enable)
:class Boolean}
{:key :name
:text (i18n/ptr :script-list-form/col-name)
:class String}
{:key :version
:text (i18n/ptr :script-list-form/col-version)
:class String}
]))
(defn make-scripts-model
[scripts-info]
(table/table-model :columns script-cols-info
:rows scripts-info))
(defn fix-script-info
"修正script info,添加key"
[k info]
(assoc info :script-key k))
(defn make-table []
(let [tbl (guix/table-x :id :script-table
:popup (gui/popup
:items [(gui/menu-item
:text (i18n/ptr :script-list-form/menu-reload)
:listen [:action (fn [e]
(let [tbl (-> (gui/to-root e)
(gui/select [:#script-table]))
row (gui/selection tbl)]
(when row
(-> (table/value-at tbl row)
:script-key
script/reload-script!))))])])
:model (make-scripts-model [])
:listen [:mouse-clicked (fn [e]
(let [tbl (gui/to-widget e)
p (.getPoint e)
row (.rowAtPoint tbl p)
col (.columnAtPoint tbl p)]
(when (and (>= row 0)
(= 0 col))
(let [row (.convertRowIndexToModel tbl row)
info (table/value-at tbl row)]
(if (:running info)
(script/disable-script! (:script-key info))
(script/enable-script! (:script-key info)))
(helper/switch-clojure-plugin-tab)))))])
unload (atom false)]
(-> (.getTableHeader tbl)
(.setReorderingAllowed false))
(script/reg-scripts-unload-callback #(reset! unload true))
(script/reg-script-add-callback (fn [k info]
(when-not @unload
(log/info :script-table "add script:" k)
(gui/invoke-later
(->> (fix-script-info k info)
(table/add! tbl))))))
(script/reg-scripts-clear-callback (fn []
(when-not @unload
(log/info :script-table "clear all.")
(gui/invoke-later
(table/clear! tbl)))))
(script/reg-script-state-change-callback (fn [k info]
(when-not @unload
(log/info :script-table "update script:" k)
(gui/invoke-later
(table-util/update-by! tbl
#(= k (:script-key %1))
(fn [_]
(fix-script-info k info)))))))
(gui/scrollable tbl)))
(comment
(utils/show-ui (make-table))
(require '[seesaw.dev :as dev])
(dev/show-events (gui/table))
(dev/show-options (gui/table))
)