Skip to content

Commit dde7ffa

Browse files
authored
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
1 parent 1031e6f commit dde7ffa

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

gdscript-godot.el

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,26 @@ When run with prefix argument, it offers extra debug options to choose from."
102102
(defun gdscript-godot-run-current-scene ()
103103
"Run the current script file in Godot Engine. Use the universal prefix (C-u) to force a scene select."
104104
(interactive)
105-
(gdscript-godot--run-command (gdscript-godot--select-scene current-prefix-arg)))
105+
(let ((scene (gdscript-godot--select-scene current-prefix-arg)))
106+
(when scene
107+
(gdscript-godot--run-command scene))))
106108

107109
(defun gdscript-godot-run-current-scene-debug ()
108110
"Run the current script file in Godot Engine.
109111
110112
When run with prefix argument, it offers extra debug options to choose from."
111113
(interactive)
112-
(gdscript-godot--debug-options-handler debug-options
113-
(gdscript-godot--run-command "-d" debug-options (gdscript-godot--select-scene))))
114+
(let ((scene (gdscript-godot--select-scene current-prefix-arg)))
115+
(when scene
116+
(gdscript-godot--debug-options-handler debug-options
117+
(gdscript-godot--run-command "-d" debug-options scene)))))
114118

115119
(defun gdscript-godot-edit-current-scene ()
116120
"Run the current script file in Godot Engine."
117121
(interactive)
118-
(gdscript-godot--run-command "-e" (gdscript-godot--select-scene current-prefix-arg)))
122+
(let ((scene (gdscript-godot--select-scene current-prefix-arg)))
123+
(when scene
124+
(gdscript-godot--run-command "-e" scene))))
119125

120126
(defun gdscript-godot--select-scene (&optional select-scene)
121127
"Select scene to run"

gdscript-project.el

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ If current buffer is not visiting scene file return nil."
4646
(when (file-exists-p scene-name) scene-name))))
4747

4848
(defun gdscript-project--select-scene ()
49-
"Find all scenes files and let user choose one."
49+
"Find all scenes files and let user choose one. Return `nil' if user cancels selection."
5050
(message "selecting scene")
5151
(let* ((rl (gdscript-util--find-project-configuration-file))
5252
(scene-list (mapcar (lambda (x) (file-relative-name x rl)) (directory-files-recursively rl ".*.tscn" t)))
53-
(prompt (format "Select scene to run" (buffer-name))))
54-
(gdscript-util--read scene-list prompt)))
53+
(prompt (format "Select scene to run" (buffer-name)))
54+
(selected-scene (gdscript-util--read scene-list prompt)))
55+
selected-scene))
5556

5657
(defun gdscript-project--current-buffer-script ()
5758
"Return the name of current script.
@@ -70,7 +71,7 @@ If current buffer is not visiting script file return nil."
7071
(unwind-protect
7172
(let* ((prompt (format "Buffer %s is not script file, select script to run" (buffer-name)))
7273
(script-name (gdscript-util--read gdscript-project--script-list prompt)))
73-
(gdscript-godot--run-script script-name))
74+
(when script-name (gdscript-godot--run-script script-name)))
7475
(when hydra-open (gdscript-hydra--menu/body)))))
7576

7677
(defun gdscript-project--ag-cleanup ()

gdscript-utils.el

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,17 @@ For example:
142142

143143
(defun gdscript-util--read (items &optional prompt)
144144
"Let's choose single item from ITEMS from mini-buffer.
145-
146-
PROMPT is prompt for read command."
147-
(message "gdscript util read")
148-
(let ((p (if prompt prompt "Options")))
149-
(cond ((and (featurep 'projectile) )
145+
PROMPT is prompt for read command. Return `nil' if user aborts."
146+
(let* ((p (if prompt prompt "Options"))
147+
(result (cond ((and (featurep 'projectile) )
150148
(projectile-completing-read (format "%s: " p) items))
151149
((fboundp 'ivy-read)
152150
(ivy-read (format "%s: " p) items))
153151
((fboundp 'ido-completing-read)
154152
(ido-completing-read (format "%s: " p) items))
155153
(t
156154
(completing-read (format "%s (hit TAB to auto-complete): " p) items nil t)))))
155+
(if quit-flag nil result)))
157156

158157
(provide 'gdscript-utils)
159158

0 commit comments

Comments
 (0)