2012-03-17 02:18:09 +00:00
using System ;
2014-05-24 13:19:24 +00:00
using System.Collections.Generic ;
2012-03-17 02:18:09 +00:00
using System.Linq ;
2013-04-16 01:25:30 +00:00
using System.Text ;
2014-01-25 20:27:51 +00:00
using System.Windows.Forms ;
2012-03-17 02:18:09 +00:00
2014-05-24 13:19:24 +00:00
using BizHawk.Client.Common ;
2013-11-03 03:54:37 +00:00
namespace BizHawk.Client.EmuHawk
2012-03-17 02:18:09 +00:00
{
2013-10-28 19:13:01 +00:00
public partial class LuaFunctionsForm : Form
2012-03-17 02:18:09 +00:00
{
2019-12-22 15:28:05 +00:00
private readonly LuaDocumentation _docs ;
2013-11-17 15:55:13 +00:00
private readonly Sorting _columnSort = new Sorting ( ) ;
2014-05-24 13:19:24 +00:00
2019-11-30 17:28:56 +00:00
private List < LibraryFunction > _functionList = new List < LibraryFunction > ( ) ;
2015-02-05 00:04:05 +00:00
private List < LibraryFunction > _filteredList = new List < LibraryFunction > ( ) ;
2019-12-22 15:28:05 +00:00
public LuaFunctionsForm ( LuaDocumentation docs )
{
_docs = docs ;
InitializeComponent ( ) ;
FunctionView . RetrieveVirtualItem + = FunctionView_QueryItemText ;
}
2015-02-05 00:04:05 +00:00
private void GenerateFilteredList ( )
2014-05-24 13:19:24 +00:00
{
2015-02-05 00:04:05 +00:00
if ( ! string . IsNullOrWhiteSpace ( FilterBox . Text ) )
2014-05-24 13:19:24 +00:00
{
2019-11-30 17:28:56 +00:00
_filteredList = _functionList
2019-03-18 14:06:37 +00:00
. Where ( f = > $"{f.Library}.{f.Name}" . ToLowerInvariant ( ) . Contains ( FilterBox . Text . ToLowerInvariant ( ) ) )
2015-02-05 00:04:05 +00:00
. ToList ( ) ;
}
else
{
2019-11-30 17:28:56 +00:00
_filteredList = _functionList . ToList ( ) ;
2014-05-24 13:19:24 +00:00
}
}
2012-03-17 02:18:09 +00:00
private void LuaFunctionList_Load ( object sender , EventArgs e )
2012-07-12 02:03:46 +00:00
{
2019-12-22 15:28:05 +00:00
_functionList = _docs
2017-05-19 16:05:21 +00:00
. OrderBy ( l = > l . Library )
. ThenBy ( l = > l . Name )
2014-06-03 01:21:49 +00:00
. ToList ( ) ;
2014-05-24 13:19:24 +00:00
UpdateList ( ) ;
FilterBox . Focus ( ) ;
2014-06-05 00:23:05 +00:00
ToWikiMarkupButton . Visible = VersionInfo . DeveloperBuild ;
2014-05-24 13:19:24 +00:00
}
2019-10-19 19:26:45 +00:00
private void FunctionView_QueryItemText ( object sender , RetrieveVirtualItemEventArgs e )
2014-05-24 13:19:24 +00:00
{
2019-10-19 19:26:45 +00:00
var entry = _filteredList [ e . ItemIndex ] ;
e . Item = new ListViewItem ( entry . ReturnType ) ;
e . Item . SubItems . Add ( entry . Library ) ;
e . Item . SubItems . Add ( entry . Name ) ;
e . Item . SubItems . Add ( entry . ParameterList ) ;
e . Item . SubItems . Add ( entry . Description ) ;
2012-03-17 02:18:09 +00:00
}
2012-07-12 02:03:46 +00:00
private void OrderColumn ( int column )
{
2013-11-17 15:55:13 +00:00
_columnSort . Column = column ;
if ( _columnSort . Descending )
2012-07-12 02:03:46 +00:00
{
switch ( column )
{
2014-01-25 20:27:51 +00:00
case 0 : // Return
2019-11-30 17:28:56 +00:00
_functionList = _functionList . OrderByDescending ( x = > x . ReturnType ) . ToList ( ) ;
2012-07-12 02:03:46 +00:00
break ;
2014-01-25 20:27:51 +00:00
case 1 : // Library
2019-11-30 17:28:56 +00:00
_functionList = _functionList . OrderByDescending ( x = > x . Library ) . ToList ( ) ;
2012-07-12 02:03:46 +00:00
break ;
2014-01-25 20:27:51 +00:00
case 2 : // Name
2019-11-30 17:28:56 +00:00
_functionList = _functionList . OrderByDescending ( x = > x . Name ) . ToList ( ) ;
2012-07-12 02:03:46 +00:00
break ;
2014-01-25 20:27:51 +00:00
case 3 : // Parameters
2019-11-30 17:28:56 +00:00
_functionList = _functionList . OrderByDescending ( x = > x . ParameterList ) . ToList ( ) ;
2012-07-12 02:03:46 +00:00
break ;
2014-01-25 20:27:51 +00:00
case 4 : // Description
2019-11-30 17:28:56 +00:00
_functionList = _functionList . OrderByDescending ( x = > x . Description ) . ToList ( ) ;
2014-01-25 20:27:51 +00:00
break ;
2012-07-12 02:03:46 +00:00
}
}
else
{
switch ( column )
{
2014-01-25 20:27:51 +00:00
case 0 : // Return
2019-11-30 17:28:56 +00:00
_functionList = _functionList . OrderBy ( x = > x . ReturnType ) . ToList ( ) ;
2012-07-12 02:03:46 +00:00
break ;
2014-01-25 20:27:51 +00:00
case 1 : // Library
2019-11-30 17:28:56 +00:00
_functionList = _functionList . OrderBy ( x = > x . Library ) . ToList ( ) ;
2012-07-12 02:03:46 +00:00
break ;
2014-01-25 20:27:51 +00:00
case 2 : // Name
2019-11-30 17:28:56 +00:00
_functionList = _functionList . OrderBy ( x = > x . Name ) . ToList ( ) ;
2012-07-12 02:03:46 +00:00
break ;
2014-01-25 20:27:51 +00:00
case 3 : // Parameters
2019-11-30 17:28:56 +00:00
_functionList = _functionList . OrderBy ( x = > x . ParameterList ) . ToList ( ) ;
2012-07-12 02:03:46 +00:00
break ;
2014-01-25 20:27:51 +00:00
case 4 : // Description
2019-11-30 17:28:56 +00:00
_functionList = _functionList . OrderBy ( x = > x . Description ) . ToList ( ) ;
2014-01-25 20:27:51 +00:00
break ;
2012-07-12 02:03:46 +00:00
}
}
2014-01-25 20:27:51 +00:00
2014-05-24 13:19:24 +00:00
UpdateList ( ) ;
2012-07-12 02:03:46 +00:00
}
2014-01-25 20:27:51 +00:00
private void Ok_Click ( object sender , EventArgs e )
2012-03-17 02:18:09 +00:00
{
2013-04-14 23:56:45 +00:00
Close ( ) ;
2012-03-17 02:18:09 +00:00
}
2012-07-12 02:03:46 +00:00
private void FunctionView_ColumnClick ( object sender , ColumnClickEventArgs e )
{
OrderColumn ( e . Column ) ;
}
2017-05-19 16:05:21 +00:00
private class Sorting
2012-07-12 02:03:46 +00:00
{
2013-11-17 15:55:13 +00:00
private int _column = 1 ;
2012-07-12 02:03:46 +00:00
public int Column
{
2019-10-29 13:23:40 +00:00
get = > _column ;
2012-07-12 02:03:46 +00:00
set
{
2013-11-17 15:55:13 +00:00
if ( _column = = value )
2012-07-12 02:03:46 +00:00
{
2019-10-29 13:23:40 +00:00
Descending ^ = true ;
2012-07-12 02:03:46 +00:00
}
2014-01-25 20:27:51 +00:00
2013-11-17 15:55:13 +00:00
_column = value ;
2012-07-12 02:03:46 +00:00
}
}
2019-10-29 13:23:40 +00:00
public bool Descending { get ; private set ; }
2012-07-12 02:03:46 +00:00
}
2013-04-16 01:25:30 +00:00
private void FunctionView_KeyDown ( object sender , KeyEventArgs e )
{
2014-01-25 20:27:51 +00:00
if ( e . KeyCode = = Keys . C & & e . Control & & ! e . Alt & & ! e . Shift ) // Copy
2013-04-16 01:25:30 +00:00
{
2019-11-16 17:24:33 +00:00
FunctionView_Copy ( null , null ) ;
2013-04-16 01:25:30 +00:00
}
}
2014-05-24 13:19:24 +00:00
2018-03-02 20:06:01 +00:00
private void FunctionView_Copy ( object sender , EventArgs e )
{
2019-10-19 19:26:45 +00:00
if ( FunctionView . SelectedIndices . Count = = 0 )
{
return ;
}
2019-11-16 17:24:33 +00:00
var sb = new StringBuilder ( ) ;
foreach ( int index in FunctionView . SelectedIndices )
2018-03-02 20:06:01 +00:00
{
2019-11-16 17:24:33 +00:00
var itm = _filteredList [ index ] ;
sb . Append ( $"//{itm.Library}.{itm.Name}{itm.ParameterList}" ) ; // comment style not an accident: the 'declaration' is not legal lua, so use of -- to comment it shouldn't suggest it. right?
if ( itm . Example ! = null )
{
sb . AppendLine ( ) ;
sb . AppendLine ( itm . Example ) ;
}
2018-03-02 20:06:01 +00:00
}
2018-03-14 01:04:34 +00:00
if ( sb . Length > 0 )
2019-10-29 13:23:40 +00:00
{
2018-03-14 01:04:34 +00:00
Clipboard . SetText ( sb . ToString ( ) ) ;
2019-10-29 13:23:40 +00:00
}
2018-03-02 20:06:01 +00:00
}
2014-05-24 13:19:24 +00:00
private void UpdateList ( )
{
2015-02-05 00:04:05 +00:00
GenerateFilteredList ( ) ;
2019-10-19 19:26:45 +00:00
FunctionView . VirtualListSize = _filteredList . Count ;
2014-05-24 13:19:24 +00:00
}
private void FilterBox_KeyUp ( object sender , KeyEventArgs e )
{
UpdateList ( ) ;
}
2014-06-05 00:23:05 +00:00
private void ToWikiMarkupButton_Click ( object sender , EventArgs e )
{
2019-12-22 15:28:05 +00:00
Clipboard . SetDataObject ( _docs . ToTASVideosWikiMarkup ( ) ) ;
2014-06-05 00:23:05 +00:00
}
2012-03-17 02:18:09 +00:00
}
}