| 800 | //============================================================================= |
| 801 | |
| 802 | static int GetInsertIndex(FScanner& sc, DMenuDescriptor* desc) |
| 803 | { |
| 804 | bool before = sc.CheckString("BEFORE"); |
| 805 | bool after = sc.CheckString("AFTER"); |
| 806 | |
| 807 | int insertIndex = -1; |
| 808 | |
| 809 | if (before || after) |
| 810 | { |
| 811 | // Find an existing menu item to use as insertion point |
| 812 | sc.MustGetString(); |
| 813 | |
| 814 | int n = desc->mItems.Size(); |
| 815 | for (int i = 0; i < n; i++) |
| 816 | { |
| 817 | auto item = desc->mItems[i]; |
| 818 | |
| 819 | if (item->mAction == sc.String) |
| 820 | { |
| 821 | insertIndex = before ? i : i + 1; |
| 822 | break; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | // Inserting after the last item is the same as inserting at the end |
| 827 | if (insertIndex == n) insertIndex = -1; |
| 828 | |
| 829 | // Don't error out if we haven't found a suitable item |
| 830 | // to avoid backwards compatibility issues. |
| 831 | } |
| 832 | |
| 833 | return insertIndex; |
| 834 | } |
| 835 | |
| 836 | //============================================================================= |
| 837 | // |
no test coverage detected