Skip to content

Commit

Permalink
Support EAF send input message yes-or-no-p
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewZMD committed Mar 21, 2020
1 parent 08f3907 commit ce918f6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions core/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, module

def notify_print_message(self, file_path, success):
if success:
self.message_to_emacs.emit("Save as '{}' successfully.".format(file_path))
self.message_to_emacs.emit("Successfully saved current webpage as '{}'.".format(file_path))
else:
self.message_to_emacs.emit("Save as '{}' failed.".format(file_path))
self.message_to_emacs.emit("Failed to save current webpage as '{}'.".format(file_path))

def record_url(self, url):
self.request_url = url.toString()
Expand Down
4 changes: 2 additions & 2 deletions core/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ def resize_view(self):
def get_key_event_widgets(self):
return [self.buffer_widget]

def send_input_message(self, message, callback_type, input_type="string", input_content=""):
self.input_message.emit(self.buffer_id, message, callback_type, input_type, input_content)
def send_input_message(self, message, callback_tag, input_type="string", initial_content=""):
self.input_message.emit(self.buffer_id, message, callback_tag, input_type, initial_content)

def handle_input_message(self, result_type, result_content):
pass
Expand Down
22 changes: 12 additions & 10 deletions eaf.el
Original file line number Diff line number Diff line change
Expand Up @@ -1256,20 +1256,22 @@ of `eaf--buffer-app-name' inside the EAF buffer."
"com.lazycat.eaf" "input_message"
#'eaf--input-message)

(defun eaf--input-message (input-buffer-id interactive-string callback-type interactive_type input_content)
(defun eaf--input-message (input-buffer-id interactive-string callback-tag interactive-type initial-content)
"Handles input message INTERACTIVE-STRING on the Python side given INPUT-BUFFER-ID and CALLBACK-TYPE."
(let* ((input-message (eaf-read-input (concat "[EAF/" eaf--buffer-app-name "] " interactive-string) interactive_type input_content)))
(let* ((input-message (eaf-read-input (concat "[EAF/" eaf--buffer-app-name "] " interactive-string) interactive-type initial-content)))
(if input-message
(eaf-call "handle_input_message" input-buffer-id callback-type input-message)
(eaf-call "cancel_input_message" input-buffer-id callback-type))))
(eaf-call "handle_input_message" input-buffer-id callback-tag input-message)
(eaf-call "cancel_input_message" input-buffer-id callback-tag))))

(defun eaf-read-input (interactive-string interactive_type input_content)
"Like `read-string' which read an INTERACTIVE-STRING, but return nil if user execute `keyboard-quit' when input."
(defun eaf-read-input (interactive-string interactive-type initial-content)
"EAF's multi-purpose read-input function which read an INTERACTIVE-STRING with INITIAL-CONTENT, determines the function base on INTERACTIVE-TYPE."
(condition-case nil
(cond ((string-equal interactive_type "string")
(read-string interactive-string input_content))
((string-equal interactive_type "file")
(expand-file-name (read-file-name interactive-string))))
(cond ((string-equal interactive-type "string")
(read-string interactive-string initial-content))
((string-equal interactive-type "file")
(expand-file-name (read-file-name interactive-string)))
((string-equal interactive-type "yes-or-no")
(yes-or-no-p interactive-string)))
(quit nil)))

(defun eaf--open-internal (url app-name arguments)
Expand Down

0 comments on commit ce918f6

Please sign in to comment.