|
| @@ -388,21 +388,8 @@ type paletteDecision struct { |
| 388 | | // decidePaletteInput takes paletteMu, applies data to the attachment's palette, | 388 | | // decidePaletteInput takes paletteMu, applies data to the attachment's palette, |
| 389 | | // and returns the action to run after unlocking. | 389 | | // and returns the action to run after unlocking. |
| 390 | | func decidePaletteInput(ac *attachedClient, data []byte) paletteDecision { | 390 | | func decidePaletteInput(ac *attachedClient, data []byte) paletteDecision { |
| 391 | - | var cmd command.Command | 391 | + | // decision holds the executed selection; execute reports one was made. |
| 392 | - | var sessionTarget palette.Result | 392 | + | var decision paletteDecision |
| 393 | - | var hasSessionTarget bool | | | |
| 394 | - | var importedSourceKey, importedEntryKey string | | | |
| 395 | - | var hasImportedTarget bool | | | |
| 396 | - | var routeTarget protocol.RouteNavigationAction | | | |
| 397 | - | var hasRouteTarget bool | | | |
| 398 | - | var createDestination palette.Result | | | |
| 399 | - | var hasCreateDestination bool | | | |
| 400 | - | var args []string | | | |
| 401 | - | var routeSnapshot protocol.RecentRouteSnapshot | | | |
| 402 | - | var generation uint64 | | | |
| 403 | - | var rawQuery string | | | |
| 404 | - | var cancelInventoryInteraction uint64 | | | |
| 405 | - | var hasCancelInventory bool | | | |
| 406 | | changed, cancel, execute, chooseDestination := false, false, false, false | 393 | | changed, cancel, execute, chooseDestination := false, false, false, false |
| 407 | | | 394 | | |
| 408 | | ac.overlays.paletteMu.Lock() | 395 | | ac.overlays.paletteMu.Lock() |
|
| @@ -456,40 +443,35 @@ func decidePaletteInput(ac *attachedClient, data []byte) paletteDecision { |
| 456 | | chooseDestination = true | 443 | | chooseDestination = true |
| 457 | | return | 444 | | return |
| 458 | | } | 445 | | } |
| 459 | - | rawQuery = ac.overlays.palette.Query() | 446 | + | next := paletteDecision{rawQuery: ac.overlays.palette.Query(), generation: ac.overlays.paletteGeneration} |
| 460 | - | if selectedCommand, ok := selected.Command(); ok { | 447 | + | if cmd, ok := selected.Command(); ok { |
| 461 | - | cmd = selectedCommand | 448 | + | next.kind, next.cmd = paletteDecisionCommand, cmd |
| 462 | | if cmd.Arguments != command.ArgumentsNone { | 449 | | if cmd.Arguments != command.ArgumentsNone { |
| 463 | - | action, valid := palette.ParseAction([]palette.Result{selected}, rawQuery) | 450 | + | action, valid := palette.ParseAction([]palette.Result{selected}, next.rawQuery) |
| 464 | | if valid { | 451 | | if valid { |
| 465 | - | args = action.Args | 452 | + | next.args = action.Args |
| 466 | | } else if cmd.Arguments == command.ArgumentsRequired { | 453 | | } else if cmd.Arguments == command.ArgumentsRequired { |
| 467 | | changed = true | 454 | | changed = true |
| 468 | | return | 455 | | return |
| 469 | | } | 456 | | } |
| 470 | | } | 457 | | } |
| 471 | | if cmd.ContextHint == command.ContextHintRecentSessions { | 458 | | if cmd.ContextHint == command.ContextHintRecentSessions { |
| 472 | - | routeSnapshot = ac.overlays.paletteRouteSnapshot | 459 | + | next.routeSnapshot = ac.overlays.paletteRouteSnapshot |
| 473 | - | routeSnapshot.Entries = append([]protocol.RecentRouteEntry(nil), routeSnapshot.Entries...) | 460 | + | next.routeSnapshot.Entries = append([]protocol.RecentRouteEntry(nil), next.routeSnapshot.Entries...) |
| 474 | | } | 461 | | } |
| 475 | | } else if sourceKey, entryKey, ok := selected.ImportedSessionKey(); ok { | 462 | | } else if sourceKey, entryKey, ok := selected.ImportedSessionKey(); ok { |
| 476 | - | importedSourceKey = sourceKey | 463 | + | next.kind, next.importedSourceKey, next.importedEntryKey = paletteDecisionImportedSession, sourceKey, entryKey |
| 477 | - | importedEntryKey = entryKey | | | |
| 478 | - | hasImportedTarget = true | | | |
| 479 | | } else if action, ok := selected.RouteNavigationAction(); ok { | 464 | | } else if action, ok := selected.RouteNavigationAction(); ok { |
| 480 | - | routeTarget = action | 465 | + | next.kind, next.routeTarget = paletteDecisionRouteNavigation, action |
| 481 | - | hasRouteTarget = true | | | |
| 482 | | } else if _, _, _, _, _, ok := selected.CreateSessionDestination(); ok { | 466 | | } else if _, _, _, _, _, ok := selected.CreateSessionDestination(); ok { |
| 483 | - | createDestination = selected | 467 | + | next.kind, next.createDestination = paletteDecisionCreateDestination, selected |
| 484 | - | hasCreateDestination = true | | | |
| 485 | | } else if _, ok := selected.SessionTarget(); ok { | 468 | | } else if _, ok := selected.SessionTarget(); ok { |
| 486 | - | sessionTarget = selected | 469 | + | next.kind, next.sessionTarget = paletteDecisionSessionTarget, selected |
| 487 | - | hasSessionTarget = true | | | |
| 488 | | } else { | 470 | | } else { |
| 489 | | changed = true | 471 | | changed = true |
| 490 | | return | 472 | | return |
| 491 | | } | 473 | | } |
| 492 | - | generation = ac.overlays.paletteGeneration | 474 | + | decision = next |
| 493 | | execute = true | 475 | | execute = true |
| 494 | | }, | 476 | | }, |
| 495 | | }) | 477 | | }) |
|
| @@ -515,41 +497,22 @@ func decidePaletteInput(ac *attachedClient, data []byte) paletteDecision { |
| 515 | | } | 497 | | } |
| 516 | | } | 498 | | } |
| 517 | | if cancel { | 499 | | if cancel { |
| 518 | - | cancelInventoryInteraction, hasCancelInventory = takePaletteInventoryClose(ac.overlays) | 500 | + | cancelled := paletteDecision{kind: paletteDecisionCancel} |
| | | 501 | + | cancelled.cancelInventoryInteraction, cancelled.hasCancelInventory = takePaletteInventoryClose(ac.overlays) |
| 519 | | ac.clearPaletteLocked() | 502 | | ac.clearPaletteLocked() |
| | | 503 | + | ac.overlays.paletteMu.Unlock() |
| | | 504 | + | return cancelled |
| 520 | | } | 505 | | } |
| 521 | | ac.overlays.paletteMu.Unlock() | 506 | | ac.overlays.paletteMu.Unlock() |
| 522 | | | 507 | | |
| 523 | | switch { | 508 | | switch { |
| 524 | - | case cancel: | 509 | + | case execute: |
| 525 | - | return paletteDecision{kind: paletteDecisionCancel, cancelInventoryInteraction: cancelInventoryInteraction, hasCancelInventory: hasCancelInventory} | 510 | + | return decision |
| 526 | - | case !execute && changed: | 511 | + | case changed: |
| 527 | | return paletteDecision{kind: paletteDecisionRedraw} | 512 | | return paletteDecision{kind: paletteDecisionRedraw} |
| 528 | - | case !execute: | | | |
| 529 | - | return paletteDecision{} | | | |
| 530 | - | } | | | |
| 531 | - | decision := paletteDecision{generation: generation, rawQuery: rawQuery} | | | |
| 532 | - | switch { | | | |
| 533 | - | case hasCreateDestination: | | | |
| 534 | - | decision.kind = paletteDecisionCreateDestination | | | |
| 535 | - | decision.createDestination = createDestination | | | |
| 536 | - | case hasImportedTarget: | | | |
| 537 | - | decision.kind = paletteDecisionImportedSession | | | |
| 538 | - | decision.importedSourceKey = importedSourceKey | | | |
| 539 | - | decision.importedEntryKey = importedEntryKey | | | |
| 540 | - | case hasRouteTarget: | | | |
| 541 | - | decision.kind = paletteDecisionRouteNavigation | | | |
| 542 | - | decision.routeTarget = routeTarget | | | |
| 543 | - | case hasSessionTarget: | | | |
| 544 | - | decision.kind = paletteDecisionSessionTarget | | | |
| 545 | - | decision.sessionTarget = sessionTarget | | | |
| 546 | | default: | 513 | | default: |
| 547 | - | decision.kind = paletteDecisionCommand | 514 | + | return paletteDecision{} |
| 548 | - | decision.cmd = cmd | | | |
| 549 | - | decision.args = args | | | |
| 550 | - | decision.routeSnapshot = routeSnapshot | | | |
| 551 | | } | 515 | | } |
| 552 | - | return decision | | | |
| 553 | | } | 516 | | } |
| 554 | | | 517 | | |
| 555 | | func (d *Daemon) handlePaletteInput(ac *attachedClient, data []byte, effects ...*attachmentEffect) { | 518 | | func (d *Daemon) handlePaletteInput(ac *attachedClient, data []byte, effects ...*attachmentEffect) { |