@@ -53,32 +53,43 @@ final class PaginationCoordinator {
5353 let total = tab. pagination. totalRowCount, total > 0 else { return }
5454
5555 let tabId = tab. id
56- let alert = NSAlert ( )
57- alert. messageText = String ( localized: " Show All Rows " )
58- alert. informativeText = String (
59- format: String ( localized: " This will load all %@ rows on a single page. Large result sets use significant memory. Continue? " ) ,
60- total. formatted ( )
61- )
62- alert. alertStyle = . warning
63- alert. addButton ( withTitle: String ( localized: " Show All " ) )
64- alert. addButton ( withTitle: String ( localized: " Cancel " ) )
65-
66- let apply : ( ) -> Void = { [ weak self] in
56+ confirmLargeFetch (
57+ messageText: String ( localized: " Show All Rows " ) ,
58+ informativeText: String (
59+ format: String ( localized: " This will load all %@ rows on a single page. Large result sets use significant memory. Continue? " ) ,
60+ total. formatted ( )
61+ ) ,
62+ confirmTitle: String ( localized: " Show All " )
63+ ) { [ weak self] in
6764 guard let self,
6865 let tabIndex = parent. tabManager. tabs. firstIndex ( where: { $0. id == tabId } ) else { return }
6966 paginateAfterConfirmation ( tabIndex: tabIndex) { pagination in
7067 pagination. updatePageSize ( max ( total, 1 ) )
7168 pagination. goToFirstPage ( )
7269 }
7370 }
71+ }
72+
73+ private func confirmLargeFetch(
74+ messageText: String ,
75+ informativeText: String ,
76+ confirmTitle: String ,
77+ onConfirm: @escaping ( ) -> Void
78+ ) {
79+ let alert = NSAlert ( )
80+ alert. messageText = messageText
81+ alert. informativeText = informativeText
82+ alert. alertStyle = . warning
83+ alert. addButton ( withTitle: confirmTitle)
84+ alert. addButton ( withTitle: String ( localized: " Cancel " ) )
7485
7586 if let window = parent. contentWindow ?? NSApp . keyWindow {
7687 alert. beginSheetModal ( for: window) { response in
7788 guard response == . alertFirstButtonReturn else { return }
78- apply ( )
89+ onConfirm ( )
7990 }
8091 } else if alert. runModal ( ) == . alertFirstButtonReturn {
81- apply ( )
92+ onConfirm ( )
8293 }
8394 }
8495
@@ -159,22 +170,12 @@ final class PaginationCoordinator {
159170 message = String ( localized: " This will fetch all remaining rows. Large result sets use significant memory. Continue? " )
160171 }
161172
162- let alert = NSAlert ( )
163- alert. messageText = String ( localized: " Fetch All Rows " )
164- alert. informativeText = message
165- alert. alertStyle = . warning
166- alert. addButton ( withTitle: String ( localized: " Fetch All " ) )
167- alert. addButton ( withTitle: String ( localized: " Cancel " ) )
168-
169- let window = parent. contentWindow ?? NSApp . keyWindow
170- if let window {
171- alert. beginSheetModal ( for: window) { [ weak self] response in
172- guard let self, response == . alertFirstButtonReturn else { return }
173- performFetchAll ( tabId: tab. id, baseQuery: baseQuery)
174- }
175- } else {
176- let response = alert. runModal ( )
177- guard response == . alertFirstButtonReturn else { return }
173+ confirmLargeFetch (
174+ messageText: String ( localized: " Fetch All Rows " ) ,
175+ informativeText: message,
176+ confirmTitle: String ( localized: " Fetch All " )
177+ ) { [ weak self] in
178+ guard let self else { return }
178179 performFetchAll ( tabId: tab. id, baseQuery: baseQuery)
179180 }
180181 }
0 commit comments