11/* eslint-disable no-invalid-this */
22define ( function ( require , exports , module ) {
3+ const Global = require ( "./global" ) ;
4+
35 /**
46 * This function is called when there are no available snippets to display
57 * this is called inside the 'showSnippetsList' function inside the snippetsList.js file
@@ -48,19 +50,22 @@ define(function (require, exports, module) {
4850 const $backToListMenuBtn = $ ( "#back-to-list-menu-btn" ) ;
4951 const $addNewSnippetBtn = $ ( "#add-new-snippet-btn" ) ;
5052 const $filterSnippetsPanel = $ ( "#filter-snippets-panel" ) ;
53+ const $toolbarTitle = $ ( ".toolbar-title" ) ;
5154
5255 $addSnippetMenu . removeClass ( "hidden" ) ;
5356 $snippetListMenu . addClass ( "hidden" ) ;
5457
5558 $backToListMenuBtn . removeClass ( "hidden" ) ;
5659 $addNewSnippetBtn . addClass ( "hidden" ) ;
5760 $filterSnippetsPanel . addClass ( "hidden" ) ;
61+
62+ $toolbarTitle . html ( 'Add Snippet <span id="snippets-count" class="snippets-count"></span>' ) ;
5863 }
5964
6065 /**
61- * This function is to show the snippets list menu
62- * this menu is loaded by default when user opens up the panel
63- * it displays the list of all the snippets available
66+ * This function is responsible to show the snippet list menu
67+ * snippet list menu is the menu which shows the list of all the snippets
68+ * this is called when user clicks on the back button from add snippet menu
6469 */
6570 function showSnippetListMenu ( ) {
6671 const $addSnippetMenu = $ ( "#custom-snippets-add-new" ) ;
@@ -69,6 +74,7 @@ define(function (require, exports, module) {
6974 const $backToListMenuBtn = $ ( "#back-to-list-menu-btn" ) ;
7075 const $addNewSnippetBtn = $ ( "#add-new-snippet-btn" ) ;
7176 const $filterSnippetsPanel = $ ( "#filter-snippets-panel" ) ;
77+ const $toolbarTitle = $ ( ".toolbar-title" ) ;
7278
7379 $addSnippetMenu . addClass ( "hidden" ) ;
7480 $editSnippetMenu . addClass ( "hidden" ) ;
@@ -78,29 +84,34 @@ define(function (require, exports, module) {
7884 $addNewSnippetBtn . removeClass ( "hidden" ) ;
7985 $filterSnippetsPanel . removeClass ( "hidden" ) ;
8086
87+ // add the snippet count in the toolbar (the no. of snippets added)
88+ const snippetCount = Global . SnippetHintsList . length ;
89+ $toolbarTitle . html ( `Custom Snippets <span id="snippets-count" class="snippets-count">(${ snippetCount } )</span>` ) ;
90+
8191 $ ( "#filter-snippets-input" ) . val ( "" ) ;
8292 }
8393
8494 /**
8595 * This function is responsible to show the edit snippet menu
8696 * edit snippet menu is the menu which allows users to edit an existing snippet
87- * this is called when user clicks on a snippet item (excluding delete button)
8897 */
8998 function showEditSnippetMenu ( ) {
90- const $addSnippetMenu = $ ( "#custom-snippets-add-new" ) ;
9199 const $editSnippetMenu = $ ( "#custom-snippets-edit" ) ;
92100 const $snippetListMenu = $ ( "#custom-snippets-list" ) ;
93101 const $backToListMenuBtn = $ ( "#back-to-list-menu-btn" ) ;
94102 const $addNewSnippetBtn = $ ( "#add-new-snippet-btn" ) ;
95103 const $filterSnippetsPanel = $ ( "#filter-snippets-panel" ) ;
104+ const $toolbarTitle = $ ( ".toolbar-title" ) ;
96105
97- $addSnippetMenu . addClass ( "hidden" ) ;
98106 $editSnippetMenu . removeClass ( "hidden" ) ;
99107 $snippetListMenu . addClass ( "hidden" ) ;
100108
101109 $backToListMenuBtn . removeClass ( "hidden" ) ;
102110 $addNewSnippetBtn . addClass ( "hidden" ) ;
103111 $filterSnippetsPanel . addClass ( "hidden" ) ;
112+
113+ // Update toolbar title
114+ $toolbarTitle . html ( 'Edit Snippet <span id="snippets-count" class="snippets-count"></span>' ) ;
104115 }
105116
106117 /**
@@ -154,6 +165,16 @@ define(function (require, exports, module) {
154165 $snippetsListHeader . addClass ( "hidden" ) ;
155166 }
156167
168+ /**
169+ * Initializes the toolbar title for the list view
170+ * This is called when the panel is first opened to ensure the snippet count is displayed
171+ */
172+ function initializeListViewToolbarTitle ( ) {
173+ const $toolbarTitle = $ ( ".toolbar-title" ) ;
174+ const snippetCount = Global . SnippetHintsList . length ;
175+ $toolbarTitle . html ( `Custom Snippets <span id="snippets-count" class="snippets-count">(${ snippetCount } )</span>` ) ;
176+ }
177+
157178 exports . showEmptySnippetMessage = showEmptySnippetMessage ;
158179 exports . showSnippetsList = showSnippetsList ;
159180 exports . clearSnippetsList = clearSnippetsList ;
@@ -163,4 +184,5 @@ define(function (require, exports, module) {
163184 exports . showDuplicateAbbreviationError = showDuplicateAbbreviationError ;
164185 exports . showSnippetsListHeader = showSnippetsListHeader ;
165186 exports . hideSnippetsListHeader = hideSnippetsListHeader ;
187+ exports . initializeListViewToolbarTitle = initializeListViewToolbarTitle ;
166188} ) ;
0 commit comments