@@ -47,7 +47,6 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
47
47
}
48
48
let client : GithubClient
49
49
weak var viewController : UIViewController ?
50
- weak var editIssueTitleViewControllerDelegate : EditIssueTitleViewControllerDelegate ?
51
50
52
51
init ( model: IssueDetailsModel , client: GithubClient ) {
53
52
let button = IssueManageButton ( )
@@ -93,15 +92,7 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
93
92
if result. pullRequest {
94
93
actions. append ( . reviewers)
95
94
}
96
-
97
- let viewerCanUpdate =
98
- editIssueTitleViewControllerDelegate?
99
- . viewerCanUpdate
100
- ?? false
101
-
102
- if viewerCanUpdate {
103
- actions. append ( . editTitle)
104
- }
95
+ actions += [ . editTitle]
105
96
106
97
if result. labels. locked {
107
98
actions. append ( . unlock)
@@ -191,11 +182,15 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
191
182
case . milestone: strongSelf. presentContextMenu ( with: strongSelf. newMilestonesController ( ) )
192
183
case . assignees: strongSelf. presentContextMenu ( with: strongSelf. newPeopleController ( type: . assignee) )
193
184
case . reviewers: strongSelf. presentContextMenu ( with: strongSelf. newPeopleController ( type: . reviewer) )
185
+ case . editTitle:
186
+ strongSelf. presentContextMenu (
187
+ with: strongSelf. newEditTitleController ( ) ,
188
+ backgroundColor: . white
189
+ )
194
190
case . unlock: strongSelf. lock ( false )
195
191
case . lock: strongSelf. lock ( true )
196
192
case . reopen: strongSelf. close ( false )
197
193
case . close: strongSelf. close ( true )
198
- case . editTitle: strongSelf. presentEditTitleController ( )
199
194
}
200
195
}
201
196
}
@@ -220,6 +215,12 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
220
215
sourceView: sender
221
216
)
222
217
}
218
+
219
+ func newEditTitleController( ) -> UIViewController {
220
+ return EditIssueTitleViewController (
221
+ issueTitle: result? . title. string. allText ?? " "
222
+ )
223
+ }
223
224
224
225
func newLabelsController( ) -> UIViewController {
225
226
return LabelsViewController (
@@ -267,31 +268,22 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
267
268
)
268
269
}
269
270
270
- func presentContextMenu( with controller: UIViewController ) {
271
+ func presentContextMenu(
272
+ with controller: UIViewController ,
273
+ backgroundColor: UIColor = Styles . Colors. menuBackgroundColor. color
274
+ ) {
271
275
guard let viewController = self . viewController else { return }
272
276
ContextMenu . shared. show (
273
277
sourceViewController: viewController,
274
278
viewController: controller,
275
279
options: ContextMenu . Options (
276
280
containerStyle: ContextMenu . ContainerStyle (
277
- backgroundColor: Styles . Colors . menuBackgroundColor . color
281
+ backgroundColor: backgroundColor
278
282
)
279
283
) ,
280
284
delegate: self
281
285
)
282
286
}
283
-
284
- func presentEditTitleController( ) {
285
- guard let viewController = viewController else { return }
286
- guard let delegate = editIssueTitleViewControllerDelegate else { return }
287
- let controller = EditIssueTitleViewController (
288
- delegate: delegate
289
- )
290
- ContextMenu . shared. show (
291
- sourceViewController: viewController,
292
- viewController: controller
293
- )
294
- }
295
287
296
288
func close( _ doClose: Bool ) {
297
289
guard let previous = result else { return }
@@ -316,6 +308,19 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
316
308
)
317
309
Haptic . triggerNotification ( . success)
318
310
}
311
+
312
+ func didDismiss( controller: EditIssueTitleViewController ) {
313
+ guard let title = controller. setTitle,
314
+ let previous = result else { return }
315
+ client. setTitle (
316
+ previous: previous,
317
+ owner: model. owner,
318
+ repo: model. repo,
319
+ number: model. number,
320
+ title: title
321
+ )
322
+
323
+ }
319
324
320
325
func didDismiss( selected labels: [ RepositoryLabel ] ) {
321
326
guard let previous = result else { return }
@@ -367,9 +372,10 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate {
367
372
didDismiss ( controller: people)
368
373
} else if let labels = viewController as? LabelsViewController {
369
374
didDismiss ( selected: labels. selected)
375
+ } else if let editIssueTitle = viewController as? EditIssueTitleViewController {
376
+ didDismiss ( controller: editIssueTitle)
370
377
}
371
378
}
372
379
373
380
func contextMenuDidDismiss( viewController: UIViewController , animated: Bool ) { }
374
-
375
381
}
0 commit comments