|
1 | 1 | # TODO: Consider extracting functions shared between dialogs to own module |
2 | 2 | from collections.abc import Callable |
3 | 3 | from crystal.browser.entitytree import ResourceGroupNode, RootResourceNode |
| 4 | +from crystal.browser.new_group_info import NewGroupDialogInfo |
4 | 5 | from crystal.browser.new_root_url import ( |
5 | 6 | fields_hide_hint_when_focused, NewRootUrlDialog, |
6 | 7 | ) |
|
32 | 33 |
|
33 | 34 | class NewGroupDialog: |
34 | 35 | _INITIAL_URL_PATTERN_WIDTH = NewRootUrlDialog._INITIAL_URL_WIDTH |
35 | | - _MAX_VISIBLE_PREVIEW_URLS = 100 |
| 36 | + _MAX_VISIBLE_PREVIEW_URLS = NewGroupDialogInfo._MAX_VISIBLE_PREVIEW_URLS |
36 | 37 |
|
37 | 38 | # === Init === |
38 | 39 |
|
@@ -458,30 +459,7 @@ def _update_preview_urls(self) -> None: |
458 | 459 |
|
459 | 460 | @classmethod |
460 | 461 | def _calculate_preview_urls(cls, project: Project, url_pattern: str) -> list[str]: |
461 | | - url_pattern_re = ResourceGroup.create_re_for_url_pattern(url_pattern) |
462 | | - literal_prefix = ResourceGroup.literal_prefix_for_url_pattern(url_pattern) |
463 | | - |
464 | | - url_pattern_is_literal = (len(literal_prefix) == len(url_pattern)) |
465 | | - if url_pattern_is_literal: |
466 | | - member = project.get_resource(literal_prefix) |
467 | | - if member is None: |
468 | | - (matching_urls, approx_match_count) = ([], 0) |
469 | | - else: |
470 | | - (matching_urls, approx_match_count) = ([member.url], 1) |
471 | | - else: |
472 | | - (matching_urls, approx_match_count) = project.urls_matching_pattern( |
473 | | - url_pattern_re, literal_prefix, limit=cls._MAX_VISIBLE_PREVIEW_URLS) |
474 | | - |
475 | | - if len(matching_urls) == 0: |
476 | | - return [] |
477 | | - else: |
478 | | - more_count = approx_match_count - len(matching_urls) |
479 | | - more_items = ( |
480 | | - [f'... about {more_count:n} more'] |
481 | | - if more_count != 0 |
482 | | - else [] |
483 | | - ) |
484 | | - return matching_urls + more_items |
| 462 | + return NewGroupDialogInfo._calculate_preview_urls(project, url_pattern) |
485 | 463 |
|
486 | 464 | # === Events === |
487 | 465 |
|
|
0 commit comments