Fix scene and script selection not aborting when pressing C-g (#90)

* abort run if user cancels (C-g) a scene/script selection.

* removed todo
This commit is contained in:
RichieHH
2020-09-09 17:14:27 +02:00
committed by GitHub
parent 1031e6f87e
commit dde7ffa735
3 changed files with 19 additions and 13 deletions

View File

@@ -102,20 +102,26 @@ When run with prefix argument, it offers extra debug options to choose from."
(defun gdscript-godot-run-current-scene () (defun gdscript-godot-run-current-scene ()
"Run the current script file in Godot Engine. Use the universal prefix (C-u) to force a scene select." "Run the current script file in Godot Engine. Use the universal prefix (C-u) to force a scene select."
(interactive) (interactive)
(gdscript-godot--run-command (gdscript-godot--select-scene current-prefix-arg))) (let ((scene (gdscript-godot--select-scene current-prefix-arg)))
(when scene
(gdscript-godot--run-command scene))))
(defun gdscript-godot-run-current-scene-debug () (defun gdscript-godot-run-current-scene-debug ()
"Run the current script file in Godot Engine. "Run the current script file in Godot Engine.
When run with prefix argument, it offers extra debug options to choose from." When run with prefix argument, it offers extra debug options to choose from."
(interactive) (interactive)
(gdscript-godot--debug-options-handler debug-options (let ((scene (gdscript-godot--select-scene current-prefix-arg)))
(gdscript-godot--run-command "-d" debug-options (gdscript-godot--select-scene)))) (when scene
(gdscript-godot--debug-options-handler debug-options
(gdscript-godot--run-command "-d" debug-options scene)))))
(defun gdscript-godot-edit-current-scene () (defun gdscript-godot-edit-current-scene ()
"Run the current script file in Godot Engine." "Run the current script file in Godot Engine."
(interactive) (interactive)
(gdscript-godot--run-command "-e" (gdscript-godot--select-scene current-prefix-arg))) (let ((scene (gdscript-godot--select-scene current-prefix-arg)))
(when scene
(gdscript-godot--run-command "-e" scene))))
(defun gdscript-godot--select-scene (&optional select-scene) (defun gdscript-godot--select-scene (&optional select-scene)
"Select scene to run" "Select scene to run"

View File

@@ -46,12 +46,13 @@ If current buffer is not visiting scene file return nil."
(when (file-exists-p scene-name) scene-name)))) (when (file-exists-p scene-name) scene-name))))
(defun gdscript-project--select-scene () (defun gdscript-project--select-scene ()
"Find all scenes files and let user choose one." "Find all scenes files and let user choose one. Return `nil' if user cancels selection."
(message "selecting scene") (message "selecting scene")
(let* ((rl (gdscript-util--find-project-configuration-file)) (let* ((rl (gdscript-util--find-project-configuration-file))
(scene-list (mapcar (lambda (x) (file-relative-name x rl)) (directory-files-recursively rl ".*.tscn" t))) (scene-list (mapcar (lambda (x) (file-relative-name x rl)) (directory-files-recursively rl ".*.tscn" t)))
(prompt (format "Select scene to run" (buffer-name)))) (prompt (format "Select scene to run" (buffer-name)))
(gdscript-util--read scene-list prompt))) (selected-scene (gdscript-util--read scene-list prompt)))
selected-scene))
(defun gdscript-project--current-buffer-script () (defun gdscript-project--current-buffer-script ()
"Return the name of current script. "Return the name of current script.
@@ -70,7 +71,7 @@ If current buffer is not visiting script file return nil."
(unwind-protect (unwind-protect
(let* ((prompt (format "Buffer %s is not script file, select script to run" (buffer-name))) (let* ((prompt (format "Buffer %s is not script file, select script to run" (buffer-name)))
(script-name (gdscript-util--read gdscript-project--script-list prompt))) (script-name (gdscript-util--read gdscript-project--script-list prompt)))
(gdscript-godot--run-script script-name)) (when script-name (gdscript-godot--run-script script-name)))
(when hydra-open (gdscript-hydra--menu/body))))) (when hydra-open (gdscript-hydra--menu/body)))))
(defun gdscript-project--ag-cleanup () (defun gdscript-project--ag-cleanup ()

View File

@@ -142,11 +142,9 @@ For example:
(defun gdscript-util--read (items &optional prompt) (defun gdscript-util--read (items &optional prompt)
"Let's choose single item from ITEMS from mini-buffer. "Let's choose single item from ITEMS from mini-buffer.
PROMPT is prompt for read command. Return `nil' if user aborts."
PROMPT is prompt for read command." (let* ((p (if prompt prompt "Options"))
(message "gdscript util read") (result (cond ((and (featurep 'projectile) )
(let ((p (if prompt prompt "Options")))
(cond ((and (featurep 'projectile) )
(projectile-completing-read (format "%s: " p) items)) (projectile-completing-read (format "%s: " p) items))
((fboundp 'ivy-read) ((fboundp 'ivy-read)
(ivy-read (format "%s: " p) items)) (ivy-read (format "%s: " p) items))
@@ -154,6 +152,7 @@ PROMPT is prompt for read command."
(ido-completing-read (format "%s: " p) items)) (ido-completing-read (format "%s: " p) items))
(t (t
(completing-read (format "%s (hit TAB to auto-complete): " p) items nil t))))) (completing-read (format "%s (hit TAB to auto-complete): " p) items nil t)))))
(if quit-flag nil result)))
(provide 'gdscript-utils) (provide 'gdscript-utils)