blob: a4a04d8a18f2e82a0c5463e122d91b5277e24f21 (
plain) (
blame)
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
|
;;; slack-selectable.el --- -*- lexical-binding: t; -*-
;; Copyright (C) 2018
;; Author: <yuya373@yuya373>
;; Keywords:
;; This program 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 3 of the License, or
;; (at your option) any later version.
;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'eieio)
(require 'slack-util)
(defclass slack-selectable ()
(
;; one of users, channels, conversations, external or static
(data-source :initarg :data_source :type string :initform "static")
(options :initarg :options :initform nil)
(option-groups :initarg :option_groups :initform nil)
(selected-options :initarg :selected_options :type (or null list) :initform '())
))
(defclass slack-selectable-option ()
((text :initarg :text :type string)
(value :initarg :value :type string)))
(defclass slack-selectable-option-group ()
((text :initarg :text :type string)
(options :initarg :options :initform nil)))
(defmethod slack-selectable-text ((this slack-selectable-option))
(oref this text))
(defmethod slack-selectable-text ((this slack-selectable-option-group))
(oref this text))
(defmethod slack-selectable-select-from-static-data-source ((this slack-selectable))
(cl-labels
((select-option (options)
(select (slack-selectable-prompt this)
(mapcar #'(lambda (option)
(cons (slack-selectable-text option)
(oref option value)))
options)))
(select-option-group
(option-groups)
(slack-if-let*
((text (select (slack-selectable-prompt this)
(mapcar #'(lambda (option-group)
(slack-selectable-text option-group))
option-groups))))
(find-option text option-groups)))
(find-option (text options)
(cl-find-if #'(lambda (option)
(string= text (slack-selectable-text option)))
options))
(select (prompt options)
(funcall slack-completing-read-function
prompt
options
nil t)))
(with-slots (options option-groups) this
(slack-if-let*
((options (if option-groups
(oref (select-option-group option-groups)
options)
options))
(option-text (select-option options)))
(find-option option-text options)))))
(provide 'slack-selectable)
;;; slack-selectable.el ends here
|