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
{
2013-11-17 15:55:13 +00:00
private readonly Sorting _columnSort = new Sorting ( ) ;
2014-05-24 13:19:24 +00:00
2014-06-03 00:34:41 +00:00
private List < LibraryFunction > FunctionList = new List < LibraryFunction > ( ) ;
2014-05-24 13:19:24 +00:00
2015-02-05 00:04:05 +00:00
private List < LibraryFunction > _filteredList = new List < LibraryFunction > ( ) ;
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
{
2015-02-05 00:04:05 +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
{
_filteredList = FunctionList . ToList ( ) ;
2014-05-24 13:19:24 +00:00
}
}
2013-10-28 19:13:01 +00:00
public LuaFunctionsForm ( )
2012-03-17 02:18:09 +00:00
{
InitializeComponent ( ) ;
2019-10-19 19:26:45 +00:00
FunctionView . RetrieveVirtualItem + = FunctionView_QueryItemText ;
2012-03-17 02:18:09 +00:00
}
private void LuaFunctionList_Load ( object sender , EventArgs e )
2012-07-12 02:03:46 +00:00
{
2014-06-03 01:21:49 +00:00
FunctionList = GlobalWin . Tools . LuaConsole . LuaImp . 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
2014-05-24 13:19:24 +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
2014-05-24 13:19:24 +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
2014-05-24 13:19:24 +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
2014-05-24 13:19:24 +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
2014-05-24 13:19:24 +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
2014-05-24 13:19:24 +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
2014-05-24 13:19:24 +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
2014-05-24 13:19:24 +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
2014-05-24 13:19:24 +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
2014-05-24 13:19:24 +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 ;
2014-01-25 20:27:51 +00:00
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
{
2014-01-25 20:27:51 +00:00
var indexes = FunctionView . SelectedIndices ;
2013-04-16 01:25:30 +00:00
2018-03-14 01:04:34 +00:00
//TODO - duplicated code with FunctionView_Copy
//also -- this list is more compact (the examples would fill space)
//it isn't clear whether we should copy the examples here. So maybe this should stay distinct (and more compact?)
2013-04-16 01:25:30 +00:00
if ( indexes . Count > 0 )
{
2014-01-25 20:27:51 +00:00
var sb = new StringBuilder ( ) ;
2013-04-16 01:25:30 +00:00
foreach ( int index in indexes )
{
2014-06-03 00:34:41 +00:00
var libraryFunction = GlobalWin . Tools . LuaConsole . LuaImp . Docs [ index ] ;
2014-01-25 20:27:51 +00:00
sb . Append ( libraryFunction . Library ) . Append ( '.' ) . Append ( libraryFunction . Name ) . Append ( "()\n" ) ;
2013-04-16 01:25:30 +00:00
}
if ( sb . Length > 0 )
2014-01-25 20:27:51 +00:00
Clipboard . SetDataObject ( sb . ToString ( ) ) ;
2013-04-16 01:25:30 +00:00
}
}
}
2014-05-24 13:19:24 +00:00
2018-03-14 01:04:34 +00:00
//FREVBHFYL?
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 ;
}
var itm = _filteredList [ FunctionView . SelectedIndices [ 0 ] ] ;
2018-03-14 01:04:34 +00:00
var sb = new StringBuilder ( $"//{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 )
2018-03-02 20:06:01 +00:00
{
2018-03-14 01:04:34 +00:00
sb . AppendLine ( ) ;
sb . Append ( 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 )
{
Clipboard . SetDataObject ( GlobalWin . Tools . LuaConsole . LuaImp . Docs . ToTASVideosWikiMarkup ( ) ) ;
}
2012-03-17 02:18:09 +00:00
}
}