MCPcopy
hub / github.com/SurgeDM/Surge / updateExtensionConfirmation

Method updateExtensionConfirmation

internal/tui/update_input.go:137–190  ·  view source on GitHub ↗
(msg tea.KeyPressMsg)

Source from the content-addressed store, hash-verified

135}
136
137func (m RootModel) updateExtensionConfirmation(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
138 if key.Matches(msg, m.keys.Extension.Browse) && m.focusedInput == 2 {
139 originalPath := m.inputs[2].Value()
140 browseDir := strings.TrimSpace(originalPath)
141 if browseDir == "" {
142 browseDir = m.PWD
143 }
144 return m, m.openDirectoryPicker(FilePickerOriginExtension, originalPath, browseDir, false, true)
145 }
146
147 if key.Matches(msg, m.keys.Extension.Next) || key.Matches(msg, m.keys.Extension.Prev) {
148 m.blurAllInputs()
149 if m.focusedInput == 2 {
150 m.focusedInput = 3
151 } else {
152 m.focusedInput = 2
153 }
154 m.inputs[m.focusedInput].Focus()
155 return m, nil
156 }
157
158 if key.Matches(msg, m.keys.Extension.Confirm) {
159 m.pendingPath = strings.TrimSpace(m.inputs[2].Value())
160 m.pendingFilename = strings.TrimSpace(m.inputs[3].Value())
161 m.pendingIsDefaultPath = m.isDefaultDownloadPath(m.pendingPath)
162 if m.pendingPath == "" {
163 m.pendingIsDefaultPath = true
164 m.pendingPath = m.defaultDownloadPath()
165 }
166
167 if d := m.checkForDuplicate(m.pendingURL); d != nil {
168 utils.Debug("Duplicate download detected after confirmation: %s", m.pendingURL)
169 m.duplicateInfo = d.Filename
170 m.state = DuplicateWarningState
171 return m, nil
172 }
173
174 m.state = DashboardState
175 updated, cmd := m.startDownload(m.pendingURL, m.pendingMirrors, m.pendingHeaders, m.pendingPath, m.pendingIsDefaultPath, m.pendingFilename, "")
176 nextModel, nextCmd := updated.showNextPendingRequest()
177 return nextModel, tea.Batch(cmd, nextCmd)
178 }
179
180 if key.Matches(msg, m.keys.Extension.Cancel) {
181 m.filepickerOrigin = FilePickerOriginNone
182 m.blurAllInputs()
183 m.state = DashboardState
184 return m.showNextPendingRequest()
185 }
186
187 var cmd tea.Cmd
188 m.inputs[m.focusedInput], cmd = m.inputs[m.focusedInput].Update(msg)
189 return m, cmd
190}

Callers 1

UpdateMethod · 0.95

Calls 9

openDirectoryPickerMethod · 0.95
blurAllInputsMethod · 0.95
isDefaultDownloadPathMethod · 0.95
defaultDownloadPathMethod · 0.95
checkForDuplicateMethod · 0.95
startDownloadMethod · 0.95
DebugFunction · 0.92
UpdateMethod · 0.45

Tested by

no test coverage detected