@@ -14,6 +14,7 @@ import (
1414 "github.com/yorukot/superfile/src/config/icon"
1515 "github.com/yorukot/superfile/src/internal/common"
1616 "github.com/yorukot/superfile/src/internal/ui/metadata"
17+ "github.com/yorukot/superfile/src/internal/ui/notify"
1718 "github.com/yorukot/superfile/src/internal/utils"
1819
1920 "github.com/barasher/go-exiftool"
@@ -278,7 +279,7 @@ func (m *model) handleKeyInput(msg tea.KeyMsg) tea.Cmd {
278279 "filePanel.focusType" , m .fileModel .filePanels [m .filePanelFocusIndex ].focusType ,
279280 "filePanel.panelMode" , m .fileModel .filePanels [m .filePanelFocusIndex ].panelMode ,
280281 "typingModal.open" , m .typingModal .open ,
281- "warnModal .open" , m .warnModal . open ,
282+ "notifyModel .open" , m .notifyModel . IsOpen () ,
282283 "promptModal.open" , m .promptModal .IsOpen (),
283284 "fileModel.renaming" , m .fileModel .renaming ,
284285 "searchBar.focussed" , m .fileModel .filePanels [m .filePanelFocusIndex ].searchBar .Focused (),
@@ -291,21 +292,18 @@ func (m *model) handleKeyInput(msg tea.KeyMsg) tea.Cmd {
291292 return nil
292293 }
293294 var cmd tea.Cmd
294- quitSuperfile := false
295295 switch {
296296 case m .typingModal .open :
297297 m .typingModalOpenKey (msg .String ())
298298 case m .promptModal .IsOpen ():
299299 // Ignore keypress. It will be handled in Update call via
300300 // updateFilePanelState
301+ // TODO: Convert that to async via tea.Cmd
301302
302- case m .nofigyModel .IsOpen ():
303- cmd = m .notifyModelOpenKey (msg .String ())
304303 // Handles all warn models except the warn model for confirming to quit
305- case m .warnModal .open :
306- cmd = m .warnModalOpenKey (msg .String ())
307- case m .notifyModal .open :
308- m .notifyModalOpenKey (msg .String ())
304+ case m .notifyModel .IsOpen ():
305+ cmd = m .notifyModelOpenKey (msg .String ())
306+
309307 // If renaming a object
310308 case m .fileModel .renaming :
311309 cmd = m .renamingKey (msg .String ())
@@ -322,9 +320,6 @@ func (m *model) handleKeyInput(msg tea.KeyMsg) tea.Cmd {
322320 // If help menu is open
323321 case m .helpMenu .open :
324322 m .helpMenuKey (msg .String ())
325- // If asking to confirm quiting
326- case m .modelQuitState == confirmToQuit :
327- quitSuperfile = m .confirmToQuitSuperfile (msg .String ())
328323
329324 case slices .Contains (common .Hotkeys .Quit , msg .String ()):
330325 m .modelQuitState = quitInitiated
@@ -338,12 +333,13 @@ func (m *model) handleKeyInput(msg tea.KeyMsg) tea.Cmd {
338333 if m .modelQuitState == quitInitiated {
339334 if m .processBarModel .HasRunningProcesses () {
340335 // Dont quit now, get a confirmation first.
336+ m .modelQuitState = quitConfirmationInitiated
341337 m .warnModalForQuit ()
342338 return cmd
343339 }
344- quitSuperfile = true
340+ m . modelQuitState = quitConfirmationReceived
345341 }
346- if quitSuperfile {
342+ if m . modelQuitState == quitConfirmationReceived {
347343 m .quitSuperfile ()
348344 return tea .Quit
349345 }
@@ -447,9 +443,9 @@ func (m *model) updateCurrentFilePanelDir(path string) error {
447443
448444// Triggers a warn for confirm quiting
449445func (m * model ) warnModalForQuit () {
450- m .modelQuitState = confirmToQuit
451- m . warnModal . title = "Confirm to quit superfile"
452- m . warnModal . content = "You still have files being processed. Are you sure you want to exit?"
446+ m .notifyModel = notify . New ( true , "Confirm to quit superfile" ,
447+ "You still have files being processed. Are you sure you want to exit?" ,
448+ notify . QuitAction )
453449}
454450
455451// Implement View function for bubble tea model to handle visualization.
@@ -542,29 +538,13 @@ func (m *model) View() string {
542538 return stringfunction .PlaceOverlay (overlayX , overlayY , typingModal , finalRender )
543539 }
544540
545- if m .warnModal .open {
546- warnModal := m .warnModalRender ()
547- overlayX := m .fullWidth / 2 - common .ModalWidth / 2
548- overlayY := m .fullHeight / 2 - common .ModalHeight / 2
549- return stringfunction .PlaceOverlay (overlayX , overlayY , warnModal , finalRender )
550- }
551-
552- if m .notifyModal .open {
553- notifyModal := m .notifyModalRender ()
541+ if m .notifyModel .IsOpen () {
542+ notifyModal := m .notifyModel .Render ()
554543 overlayX := m .fullWidth / 2 - common .ModalWidth / 2
555544 overlayY := m .fullHeight / 2 - common .ModalHeight / 2
556545 return stringfunction .PlaceOverlay (overlayX , overlayY , notifyModal , finalRender )
557546 }
558547
559- // This is also a render for warnmodal, but its being driven via a different flag
560- // we should also drive it via warnModal.open
561- if m .modelQuitState == confirmToQuit {
562- warnModal := m .warnModalRender ()
563- overlayX := m .fullWidth / 2 - common .ModalWidth / 2
564- overlayY := m .fullHeight / 2 - common .ModalHeight / 2
565- return stringfunction .PlaceOverlay (overlayX , overlayY , warnModal , finalRender )
566- }
567-
568548 return finalRender
569549}
570550
0 commit comments