@@ -14,6 +14,27 @@ public static class ContextMenuPaginationExtensions
1414 {
1515 private static readonly ConditionalWeakTable < ContextMenu , PaginationInfo > _paginationInfosByContextMenu = [ ] ;
1616
17+ internal static Func < int > GetDefaultMaxItems { get ; set ; } = static ( ) => 14 ;
18+
19+ internal static Func < bool > GetLimitContextMenuItems { get ; set ; } = static ( ) => true ;
20+
21+ /// <summary>
22+ /// Gets the current default maximum number of non-pagination items to show per page, not including the paging buttons.<br/>
23+ /// This means that up to <c>value + 2</c> non-pagination items will be displayed without pagination.
24+ /// </summary>
25+ /// <remarks>
26+ /// This value may change between calls.
27+ /// </remarks>
28+ public static int DefaultMaxItems => GetDefaultMaxItems ( ) ;
29+
30+ /// <summary>
31+ /// Gets whether the number of items in the context menu should be limited and pagination buttons added for anything beyond that.
32+ /// </summary>
33+ /// <remarks>
34+ /// This value may change between calls.
35+ /// </remarks>
36+ public static bool LimitContextMenuItems => GetLimitContextMenuItems ( ) ;
37+
1738 /// <inheritdoc cref="AddPagination(ContextMenu, int, int, out ContextMenuItem, out ContextMenuItem)"/>
1839 public static void AddPagination ( this ContextMenu contextMenu , int maxItems , int currentPage = 0 )
1940 => contextMenu . AddPagination ( maxItems , currentPage , out _ , out _ ) ;
@@ -43,6 +64,75 @@ public static void AddPagination(this ContextMenu contextMenu, int maxItems, int
4364 throw new InvalidOperationException ( "Failed to add pagination!" ) ;
4465 }
4566
67+ /// <remarks>
68+ /// This version automatically uses the <see cref="DefaultMaxItems">DefaultMaxItems</see> for pagination, if wanted by the user.
69+ /// </remarks>
70+ /// <inheritdoc cref="AddPagination(ContextMenu, int, int, out ContextMenuItem, out ContextMenuItem)"/>
71+ public static void AddDefaultPagination ( this ContextMenu contextMenu , int currentPage = 0 )
72+ {
73+ if ( LimitContextMenuItems )
74+ contextMenu . AddPagination ( DefaultMaxItems , currentPage , out _ , out _ ) ;
75+ }
76+
77+ /// <remarks>
78+ /// This version automatically uses the <see cref="DefaultMaxItems">DefaultMaxItems</see> for pagination, if wanted by the user.
79+ /// </remarks>
80+ /// <inheritdoc cref="AddPagination(ContextMenu, int, int, out ContextMenuItem, out ContextMenuItem)"/>
81+ public static void AddDefaultPagination ( this ContextMenu contextMenu , int currentPage ,
82+ out ContextMenuItem ? back , out ContextMenuItem ? forward )
83+ {
84+ back = null ;
85+ forward = null ;
86+
87+ if ( LimitContextMenuItems )
88+ contextMenu . AddPagination ( DefaultMaxItems , currentPage , out back , out forward ) ;
89+ }
90+
91+ /// <remarks>
92+ /// This version automatically uses the <see cref="DefaultMaxItems">DefaultMaxItems</see> for pagination, if wanted by the user.
93+ /// </remarks>
94+ /// <inheritdoc cref="TryAddPagination(ContextMenu, int, int)"/>
95+ public static bool TryAddDefaultPagination ( this ContextMenu contextMenu , int currentPage = 0 )
96+ {
97+ if ( ! LimitContextMenuItems )
98+ return false ;
99+
100+ return contextMenu . TryAddPagination ( DefaultMaxItems , currentPage ) ;
101+ }
102+
103+ /// <remarks>
104+ /// This version automatically uses the <see cref="DefaultMaxItems">DefaultMaxItems</see> for pagination, if wanted by the user.
105+ /// </remarks>
106+ /// <inheritdoc cref="TryAddPagination(ContextMenu, int, int, out ContextMenuItem?, out ContextMenuItem?)"/>
107+ public static bool TryAddDefaultPagination ( this ContextMenu contextMenu , int currentPage ,
108+ [ NotNullWhen ( true ) ] out ContextMenuItem ? back , [ NotNullWhen ( true ) ] out ContextMenuItem ? forward )
109+ {
110+ back = null ;
111+ forward = null ;
112+
113+ if ( ! LimitContextMenuItems )
114+ return false ;
115+
116+ return contextMenu . TryAddPagination ( DefaultMaxItems , currentPage , out back , out forward ) ;
117+ }
118+
119+ /// <remarks>
120+ /// This version automatically uses the <see cref="DefaultMaxItems">DefaultMaxItems</see> for pagination, if wanted by the user.
121+ /// </remarks>
122+ /// <inheritdoc cref="TryAddPagination(ContextMenu, ref int, ref int, bool, out ContextMenuItem?, out ContextMenuItem?)"/>
123+ public static bool TryAddDefaultPagination ( this ContextMenu contextMenu , out int maxItems , ref int currentPage , bool forceNew ,
124+ [ NotNullWhen ( true ) ] out ContextMenuItem ? back , [ NotNullWhen ( true ) ] out ContextMenuItem ? forward )
125+ {
126+ back = null ;
127+ forward = null ;
128+ maxItems = DefaultMaxItems ;
129+
130+ if ( ! LimitContextMenuItems )
131+ return false ;
132+
133+ return contextMenu . TryAddPagination ( ref maxItems , ref currentPage , forceNew , out back , out forward ) ;
134+ }
135+
46136 /// <summary>
47137 /// Tries to add pagination with the given configuration to this context menu.<br/>
48138 /// If there already is pagination, nothing happens.
@@ -60,7 +150,7 @@ public static bool TryAddPagination(this ContextMenu contextMenu, int maxItems,
60150 /// <param name="currentPage">The page that should be shown from the start. Can be any integer value, even negative.</param>
61151 /// <inheritdoc cref="TryAddPagination(ContextMenu, ref int, ref int, bool, out ContextMenuItem?, out ContextMenuItem?)"/>
62152 public static bool TryAddPagination ( this ContextMenu contextMenu , int maxItems , int currentPage ,
63- [ NotNullWhen ( true ) ] out ContextMenuItem ? back , [ NotNullWhen ( true ) ] out ContextMenuItem ? forward )
153+ [ NotNullWhen ( true ) ] out ContextMenuItem ? back , [ NotNullWhen ( true ) ] out ContextMenuItem ? forward )
64154 => contextMenu . TryAddPagination ( ref maxItems , ref currentPage , false , out back , out forward ) ;
65155
66156 /// <summary>
0 commit comments