@@ -465,64 +465,54 @@ fun CodeHighlightSketch.processWriteCommand(currentText: String, fileName: Strin
465
465
fun CodeHighlightSketch.processEditFileCommand (currentText : String ) {
466
466
val isAutoSketchMode = AutoSketchMode .getInstance(project).isEnable
467
467
468
- if (isAutoSketchMode) {
469
- val button = JButton (" Auto Executing..." , AutoDevIcons .LOADING ).apply {
468
+ val button = if (isAutoSketchMode) {
469
+ JButton (" Auto Executing..." , AutoDevIcons .LOADING ).apply {
470
470
isEnabled = false
471
471
preferredSize = JBUI .size(150 , 30 )
472
472
}
473
+ } else {
474
+ JButton (" Execute Edit File" , AllIcons .Actions .Execute ).apply {
475
+ preferredSize = JBUI .size(120 , 30 )
476
+ }
477
+ }
473
478
474
- val panel = JPanel ()
475
- panel.layout = BoxLayout (panel, BoxLayout .X_AXIS )
476
- panel.add(button)
477
- add(panel)
479
+ val panel = JPanel ().apply {
480
+ layout = BoxLayout (this , BoxLayout .X_AXIS )
481
+ add(button)
482
+ }
483
+ add(panel)
484
+
485
+ val executeCommand = {
486
+ button.isEnabled = false
487
+ button.text = if (isAutoSketchMode) " Auto Executing..." else " Executing..."
488
+ button.icon = AutoDevIcons .LOADING
478
489
479
490
AutoDevCoroutineScope .scope(project).launch {
480
491
executeEditFileCommand(project, currentText) { result ->
481
492
runInEdt {
482
- if (result != null && ! result.startsWith(" DEVINS_ERROR" )) {
483
- val diffSketch = DiffLangSketchProvider ().create(project, result)
484
- add(diffSketch.getComponent())
485
- button.text = " Executed"
486
- button.icon = AllIcons .Actions .Checked
487
- } else {
488
- button.text = " Failed"
489
- button.icon = AllIcons .General .Error
490
- AutoDevNotifications .warn(project, result ? : " Unknown error occurred" )
491
- }
493
+ handleExecutionResult(result, button)
492
494
}
493
495
}
494
496
}
497
+ }
498
+
499
+ if (isAutoSketchMode) {
500
+ executeCommand()
495
501
} else {
496
- val executeButton = JButton (" Execute Edit File" , AllIcons .Actions .Execute ).apply {
497
- preferredSize = JBUI .size(120 , 30 )
498
- addActionListener {
499
- this .isEnabled = false
500
- this .text = " Executing..."
501
- this .icon = AutoDevIcons .LOADING
502
-
503
- AutoDevCoroutineScope .scope(project).launch {
504
- executeEditFileCommand(project, currentText) { result ->
505
- runInEdt {
506
- if (result != null && ! result.startsWith(" DEVINS_ERROR" )) {
507
- val diffSketch = DiffLangSketchProvider ().create(project, result)
508
- add(diffSketch.getComponent())
509
- this @apply.text = " Executed"
510
- this @apply.icon = AllIcons .Actions .Checked
511
- } else {
512
- this @apply.text = " Failed"
513
- this @apply.icon = AllIcons .General .Error
514
- AutoDevNotifications .warn(project, result ? : " Unknown error occurred" )
515
- }
516
- }
517
- }
518
- }
519
- }
520
- }
502
+ button.addActionListener { executeCommand() }
503
+ }
504
+ }
521
505
522
- val panel = JPanel ()
523
- panel.layout = BoxLayout (panel, BoxLayout .X_AXIS )
524
- panel.add(executeButton)
525
- add(panel)
506
+ private fun CodeHighlightSketch.handleExecutionResult (result : String? , button : JButton ) {
507
+ if (result != null && ! result.startsWith(" DEVINS_ERROR" )) {
508
+ val diffSketch = DiffLangSketchProvider ().create(project, result)
509
+ add(diffSketch.getComponent())
510
+ button.text = " Executed"
511
+ button.icon = AllIcons .Actions .Checked
512
+ } else {
513
+ button.text = " Failed"
514
+ button.icon = AllIcons .General .Error
515
+ AutoDevNotifications .warn(project, result ? : " Unknown error occurred" )
526
516
}
527
517
}
528
518
0 commit comments