home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Quick Keyboard Navigation
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Anonymous" data-source="post: 2702"><p>For large lists it is convenient to use keyboard shortcuts to jump to an item in the list (like windows explorer). </p><p></p><p>To test this in media portal I added some code to the GUIListControl.cs and GUIThumbnailPanel.cs which handles all otherwise unhandled keys. </p><p>Maybe something like this can be added to the main code line? Well, here are the code snippets.</p><p></p><p>This is not much tested yet, but seems to work for 'My Music' and for me.</p><p></p><p>Thanks for MediaPortal,</p><p>Wog</p><p></p><p></p><p><strong>GUIThumbnailPanell.cs</strong>[code]</p><p> case Action.ActionType.ACTION_KEY_PRESSED : </p><p> // <WOG></p><p> { </p><p> OnJump( action.m_key.KeyChar );</p><p> m_bRefresh = true;</p><p> } </p><p> // </WOG></p><p> break;</p><p>[/code]</p><p>[code]</p><p> // <WOG></p><p> /// <summary></p><p> /// Implementation of the OnJump action. If an (unhandled) key is pressed, the action tries to find </p><p> /// an item which start with the same letter. If an item is found it changes selection to point to it. </p><p> /// </summary></p><p> protected static DateTime tsLastKeyStroke = DateTime.Now; // time stamp last key pressed</p><p> protected static double maxTimeSpan = 500.0; // max time between two strokes</p><p> protected static String sKey = ""; // jump string</p><p></p><p> protected void OnJump(int key)</p><p> {</p><p> if (m_iSelect != GUIListControl.ListType.CONTROL_LIST) </p><p> {</p><p> // don't do anything...</p><p> return;</p><p> }</p><p></p><p> // convert to lower case string. </p><p> // in case less than 0.5 seconds have been passed since the last keys troke, append the new character.</p><p> DateTime tsThisKeyStroke = DateTime.Now;</p><p> TimeSpan ts = tsThisKeyStroke - tsLastKeyStroke ;</p><p> tsLastKeyStroke = tsThisKeyStroke; </p><p> double ms = ts.TotalMilliseconds;</p><p> char cKey = (char) key;</p><p> if ( ms > maxTimeSpan )</p><p> {</p><p> sKey = "";</p><p> }</p><p> sKey += cKey.ToString().ToLower();</p><p></p><p> // search the next item starting with this letter</p><p></p><p> int startIndex = m_iCursorY * m_iColumns + m_iOffset + m_iCursorX;</p><p> for ( int idx = 1; idx < (int)m_vecItems.Count; idx++ )</p><p> {</p><p> int index = (startIndex + idx) % (int)m_vecItems.Count;</p><p> GUIListItem pItem = (GUIListItem)m_vecItems[index];</p><p> String strLabel = pItem.Label.ToLower();</p><p> if ( strLabel.StartsWith(sKey) )</p><p> {</p><p> m_iCursorX = index % m_iColumns;</p><p> int iOffsetY = index / m_iColumns;</p><p></p><p> // selection in currently displayed area -> just change selection</p><p> if (m_iOffset / m_iColumns <= iOffsetY && m_iOffset / m_iColumns + m_iRows > iOffsetY )</p><p> {</p><p> m_iCursorY = iOffsetY - m_iOffset / m_iColumns ;</p><p> // m_iOffset = m_iOffset; is unchanged...</p><p> } </p><p> else if ( iOffsetY < m_iRows )</p><p> {</p><p> // one of the first few items. start display with first line</p><p> m_iCursorY = iOffsetY;</p><p> m_iOffset = 0;</p><p> } </p><p> else if ( iOffsetY > (m_vecItems.Count + m_iRows - 1) / m_iColumns - m_iRows )</p><p> {</p><p> // one of the last few items.</p><p> int iOffRow = (m_vecItems.Count + m_iRows - 1) / m_iColumns - m_iRows ;</p><p> m_iOffset = iOffRow * m_iColumns;</p><p> m_iCursorY = iOffsetY - iOffRow;</p><p> }</p><p> else</p><p> {</p><p> // center it</p><p> int iOffRow = iOffsetY - m_iRows / 2;</p><p> m_iOffset = iOffRow * m_iColumns;</p><p> m_iCursorY = iOffsetY - iOffRow;</p><p> }</p><p></p><p> OnSelectionChanged();</p><p> return;</p><p> }</p><p> }</p><p> }</p><p> // </WOG>[/code]</p><p></p><p></p><p><strong>GUIListControl.cs</strong>[code]</p><p> case Action.ActionType.ACTION_KEY_PRESSED : </p><p> // <WOG></p><p> { </p><p> OnJump( action.m_key.KeyChar );</p><p> m_bRefresh = true;</p><p> } </p><p> // </WOG></p><p> break;</p><p>[/code]</p><p>[code]</p><p> // <WOG></p><p> /// <summary></p><p> /// Implementation of the OnJump action. If an overwise unhandled key is pressed, the action tries to find </p><p> /// an item which start with the same letter. If an item is found it changes selection to point to it. </p><p> /// </summary></p><p> protected static DateTime tsLastKeyStroke = DateTime.Now; // time stamp last key pressed</p><p> protected static double maxTimeSpan = 500.0; // max time between two strokes</p><p> protected static String sKey = ""; // jump string</p><p> </p><p> protected void OnJump(int key)</p><p> {</p><p></p><p> if (m_iSelect != ListType.CONTROL_LIST) </p><p> {</p><p> // don't do anything...</p><p> return;</p><p> }</p><p></p><p> // convert to lower case string. </p><p> // in case less than 0.5 seconds have been passed since the last keys troke, append the new character.</p><p> DateTime tsThisKeyStroke = DateTime.Now;</p><p> TimeSpan ts = tsThisKeyStroke - tsLastKeyStroke ;</p><p> tsLastKeyStroke = tsThisKeyStroke; </p><p> double ms = ts.TotalMilliseconds;</p><p> char cKey = (char) key;</p><p> if ( ms > maxTimeSpan )</p><p> {</p><p> sKey = "";</p><p> }</p><p> sKey += cKey.ToString().ToLower();</p><p> // search the next item starting with this letter</p><p></p><p> int startIndex = m_iOffset + m_iCursorY;</p><p> for ( int idx = 1; idx < (int)m_vecItems.Count; idx++ )</p><p> {</p><p> int index = (startIndex + idx) % (int)m_vecItems.Count;</p><p> GUIListItem pItem = (GUIListItem)m_vecItems[index];</p><p> String strLabel = pItem.Label.ToLower();</p><p> if ( strLabel.StartsWith(sKey) )</p><p> {</p><p> // selection in currently displayed area -> just change selection</p><p> if (m_iCursorY + idx < m_iItemsPerPage)</p><p> {</p><p> m_iCursorY += idx;</p><p> OnSelectionChanged();</p><p> return;</p><p> }</p><p> </p><p> // selection not visible. center displayed area aorund selected item</p><p> int iCursor = m_iItemsPerPage / 2;</p><p> int iOffset = index - iCursor;</p><p> if ( index < m_iItemsPerPage / 2 )</p><p> {</p><p> // one of the first few (m_iItemsPerPage / 2) items. start display with first</p><p> iCursor = index;</p><p> iOffset = 0;</p><p> } </p><p> else if ( index > m_vecItems.Count - m_iItemsPerPage )</p><p> {</p><p> // one of the last few items.</p><p> iOffset = m_vecItems.Count - m_iItemsPerPage;</p><p> iCursor = index - iOffset;</p><p> }</p><p></p><p> m_iCursorY = iCursor;</p><p> m_iOffset = iOffset;</p><p> OnSelectionChanged();</p><p> return;</p><p> }</p><p> }</p><p> }</p><p> // </WOG></p><p>[/code]</p></blockquote><p></p>
[QUOTE="Anonymous, post: 2702"] For large lists it is convenient to use keyboard shortcuts to jump to an item in the list (like windows explorer). To test this in media portal I added some code to the GUIListControl.cs and GUIThumbnailPanel.cs which handles all otherwise unhandled keys. Maybe something like this can be added to the main code line? Well, here are the code snippets. This is not much tested yet, but seems to work for 'My Music' and for me. Thanks for MediaPortal, Wog [b]GUIThumbnailPanell.cs[/b][code] case Action.ActionType.ACTION_KEY_PRESSED : // <WOG> { OnJump( action.m_key.KeyChar ); m_bRefresh = true; } // </WOG> break; [/code] [code] // <WOG> /// <summary> /// Implementation of the OnJump action. If an (unhandled) key is pressed, the action tries to find /// an item which start with the same letter. If an item is found it changes selection to point to it. /// </summary> protected static DateTime tsLastKeyStroke = DateTime.Now; // time stamp last key pressed protected static double maxTimeSpan = 500.0; // max time between two strokes protected static String sKey = ""; // jump string protected void OnJump(int key) { if (m_iSelect != GUIListControl.ListType.CONTROL_LIST) { // don't do anything... return; } // convert to lower case string. // in case less than 0.5 seconds have been passed since the last keys troke, append the new character. DateTime tsThisKeyStroke = DateTime.Now; TimeSpan ts = tsThisKeyStroke - tsLastKeyStroke ; tsLastKeyStroke = tsThisKeyStroke; double ms = ts.TotalMilliseconds; char cKey = (char) key; if ( ms > maxTimeSpan ) { sKey = ""; } sKey += cKey.ToString().ToLower(); // search the next item starting with this letter int startIndex = m_iCursorY * m_iColumns + m_iOffset + m_iCursorX; for ( int idx = 1; idx < (int)m_vecItems.Count; idx++ ) { int index = (startIndex + idx) % (int)m_vecItems.Count; GUIListItem pItem = (GUIListItem)m_vecItems[index]; String strLabel = pItem.Label.ToLower(); if ( strLabel.StartsWith(sKey) ) { m_iCursorX = index % m_iColumns; int iOffsetY = index / m_iColumns; // selection in currently displayed area -> just change selection if (m_iOffset / m_iColumns <= iOffsetY && m_iOffset / m_iColumns + m_iRows > iOffsetY ) { m_iCursorY = iOffsetY - m_iOffset / m_iColumns ; // m_iOffset = m_iOffset; is unchanged... } else if ( iOffsetY < m_iRows ) { // one of the first few items. start display with first line m_iCursorY = iOffsetY; m_iOffset = 0; } else if ( iOffsetY > (m_vecItems.Count + m_iRows - 1) / m_iColumns - m_iRows ) { // one of the last few items. int iOffRow = (m_vecItems.Count + m_iRows - 1) / m_iColumns - m_iRows ; m_iOffset = iOffRow * m_iColumns; m_iCursorY = iOffsetY - iOffRow; } else { // center it int iOffRow = iOffsetY - m_iRows / 2; m_iOffset = iOffRow * m_iColumns; m_iCursorY = iOffsetY - iOffRow; } OnSelectionChanged(); return; } } } // </WOG>[/code] [b]GUIListControl.cs[/b][code] case Action.ActionType.ACTION_KEY_PRESSED : // <WOG> { OnJump( action.m_key.KeyChar ); m_bRefresh = true; } // </WOG> break; [/code] [code] // <WOG> /// <summary> /// Implementation of the OnJump action. If an overwise unhandled key is pressed, the action tries to find /// an item which start with the same letter. If an item is found it changes selection to point to it. /// </summary> protected static DateTime tsLastKeyStroke = DateTime.Now; // time stamp last key pressed protected static double maxTimeSpan = 500.0; // max time between two strokes protected static String sKey = ""; // jump string protected void OnJump(int key) { if (m_iSelect != ListType.CONTROL_LIST) { // don't do anything... return; } // convert to lower case string. // in case less than 0.5 seconds have been passed since the last keys troke, append the new character. DateTime tsThisKeyStroke = DateTime.Now; TimeSpan ts = tsThisKeyStroke - tsLastKeyStroke ; tsLastKeyStroke = tsThisKeyStroke; double ms = ts.TotalMilliseconds; char cKey = (char) key; if ( ms > maxTimeSpan ) { sKey = ""; } sKey += cKey.ToString().ToLower(); // search the next item starting with this letter int startIndex = m_iOffset + m_iCursorY; for ( int idx = 1; idx < (int)m_vecItems.Count; idx++ ) { int index = (startIndex + idx) % (int)m_vecItems.Count; GUIListItem pItem = (GUIListItem)m_vecItems[index]; String strLabel = pItem.Label.ToLower(); if ( strLabel.StartsWith(sKey) ) { // selection in currently displayed area -> just change selection if (m_iCursorY + idx < m_iItemsPerPage) { m_iCursorY += idx; OnSelectionChanged(); return; } // selection not visible. center displayed area aorund selected item int iCursor = m_iItemsPerPage / 2; int iOffset = index - iCursor; if ( index < m_iItemsPerPage / 2 ) { // one of the first few (m_iItemsPerPage / 2) items. start display with first iCursor = index; iOffset = 0; } else if ( index > m_vecItems.Count - m_iItemsPerPage ) { // one of the last few items. iOffset = m_vecItems.Count - m_iItemsPerPage; iCursor = index - iOffset; } m_iCursorY = iCursor; m_iOffset = iOffset; OnSelectionChanged(); return; } } } // </WOG> [/code] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Quick Keyboard Navigation
Contact us
RSS
Top
Bottom