Commit 8e68c323d7
Unsigned
Layout: unified · split
internal/selection_menu.go +66 −61
| @@ -428,64 +428,69 @@ func RofiSelect(options map[string]string, addanimeopt bool) (SelectionOption, e | |||
| 428 | 428 | ||
| 429 | // DynamicSelect displays a simple selection prompt without extra features | 429 | // DynamicSelect displays a simple selection prompt without extra features |
| 430 | func DynamicSelect(options map[string]string, addnewoption bool) (SelectionOption, error) { | 430 | func DynamicSelect(options map[string]string, addnewoption bool) (SelectionOption, error) { |
| 431 | if GetGlobalConfig().RofiSelection { | 431 | if GetGlobalConfig().RofiSelection { |
| 432 | return RofiSelect(options, addnewoption) | 432 | return RofiSelect(options, addnewoption) |
| 433 | } | 433 | } |
| 434 | 434 | ||
| 435 | // Create a slice to maintain order | 435 | // Create a slice to maintain order |
| 436 | var orderedOptions []SelectionOption | 436 | var orderedOptions []SelectionOption |
| 437 | 437 | ||
| 438 | // If this is a category selection (contains menu items), use the ordered keys | 438 | // If this is a category selection (contains menu items), use the ordered keys |
| 439 | if _, hasMenu := options["ALL"]; hasMenu { | 439 | if _, hasMenu := options["ALL"]; hasMenu { |
| 440 | // Get ordered keys from the options map | 440 | // Get the menu order from config |
| 441 | for key, value := range options { | 441 | menuOrder := strings.Split(GetGlobalConfig().MenuOrder, ",") |
| 442 | orderedOptions = append(orderedOptions, SelectionOption{ | 442 | |
| 443 | Key: key, | 443 | // Add options in the specified order |
| 444 | Label: value, | 444 | for _, key := range menuOrder { |
| 445 | }) | 445 | if value, exists := options[key]; exists { |
| 446 | } | 446 | orderedOptions = append(orderedOptions, SelectionOption{ |
| 447 | } else { | 447 | Key: key, |
| 448 | // For other selections, maintain alphabetical order | 448 | Label: value, |
| 449 | for key, value := range options { | 449 | }) |
| 450 | orderedOptions = append(orderedOptions, SelectionOption{ | 450 | } |
| 451 | Key: key, | 451 | } |
| 452 | Label: value, | 452 | } else { |
| 453 | }) | 453 | // For other selections, maintain alphabetical order |
| 454 | } | 454 | for key, value := range options { |
| 455 | } | 455 | orderedOptions = append(orderedOptions, SelectionOption{ |
| 456 | 456 | Key: key, | |
| 457 | model := &Model{ | 457 | Label: value, |
| 458 | options: options, | 458 | }) |
| 459 | filteredKeys: orderedOptions, | 459 | } |
| 460 | addNewOption: addnewoption, | 460 | } |
| 461 | } | 461 | |
| 462 | 462 | model := &Model{ | |
| 463 | if addnewoption { | 463 | options: options, |
| 464 | model.filteredKeys = append(model.filteredKeys, SelectionOption{ | 464 | filteredKeys: orderedOptions, |
| 465 | Label: "Add new anime", | 465 | addNewOption: addnewoption, |
| 466 | Key: "add_new", | 466 | } |
| 467 | }) | 467 | |
| 468 | } | 468 | if addnewoption { |
| 469 | 469 | model.filteredKeys = append(model.filteredKeys, SelectionOption{ | |
| 470 | model.filteredKeys = append(model.filteredKeys, SelectionOption{ | 470 | Label: "Add new anime", |
| 471 | Label: "Quit", | 471 | Key: "add_new", |
| 472 | Key: "-1", | 472 | }) |
| 473 | }) | 473 | } |
| 474 | 474 | ||
| 475 | p := tea.NewProgram(model) | 475 | model.filteredKeys = append(model.filteredKeys, SelectionOption{ |
| 476 | 476 | Label: "Quit", | |
| 477 | finalModel, err := p.Run() | 477 | Key: "-1", |
| 478 | if err != nil { | 478 | }) |
| 479 | return SelectionOption{}, err | 479 | |
| 480 | } | 480 | p := tea.NewProgram(model) |
| 481 | 481 | ||
| 482 | finalSelectionModel, ok := finalModel.(*Model) | 482 | finalModel, err := p.Run() |
| 483 | if !ok { | 483 | if err != nil { |
| 484 | return SelectionOption{}, fmt.Errorf("unexpected model type") | 484 | return SelectionOption{}, err |
| 485 | } | 485 | } |
| 486 | 486 | ||
| 487 | if finalSelectionModel.selected < len(finalSelectionModel.filteredKeys) { | 487 | finalSelectionModel, ok := finalModel.(*Model) |
| 488 | return finalSelectionModel.filteredKeys[finalSelectionModel.selected], nil | 488 | if !ok { |
| 489 | } | 489 | return SelectionOption{}, fmt.Errorf("unexpected model type") |
| 490 | return SelectionOption{}, nil | 490 | } |
| 491 | }\ No newline at end of file | 491 | |
| 492 | if finalSelectionModel.selected < len(finalSelectionModel.filteredKeys) { | ||
| 493 | return finalSelectionModel.filteredKeys[finalSelectionModel.selected], nil | ||
| 494 | } | ||
| 495 | return SelectionOption{}, nil | ||
| 496 | } | ||