2012-03-17 02:18:09 +00:00
using System ;
2014-05-24 13:19:24 +00:00
using System.Collections.Generic ;
using System.Drawing ;
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 ;
2018-03-02 20:06:01 +00:00
using BizHawk.Common ;
2014-05-24 13:19:24 +00:00
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
2015-07-22 17:13:30 +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 ( ) ;
2014-05-24 13:19:24 +00:00
FunctionView . QueryItemText + = FunctionView_QueryItemText ;
FunctionView . QueryItemBkColor + = FunctionView_QueryItemBkColor ;
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
}
private void FunctionView_QueryItemBkColor ( int index , int column , ref Color color )
{
2012-07-12 02:03:46 +00:00
}
2014-05-24 13:19:24 +00:00
private void FunctionView_QueryItemText ( int index , int column , out string text )
2012-03-17 02:18:09 +00:00
{
2017-05-10 11:45:23 +00:00
text = "" ;
2014-05-24 13:19:24 +00:00
2014-06-01 15:44:40 +00:00
try
2015-02-05 00:04:05 +00:00
{
if ( _filteredList . Any ( ) & & index < _filteredList . Count )
2014-06-01 15:44:40 +00:00
{
switch ( column )
{
case 0 :
2015-02-05 00:04:05 +00:00
text = _filteredList [ index ] . ReturnType ;
2014-06-01 15:44:40 +00:00
break ;
case 1 :
2015-02-05 00:04:05 +00:00
text = _filteredList [ index ] . Library ;
2014-06-01 15:44:40 +00:00
break ;
case 2 :
2015-02-05 00:04:05 +00:00
text = _filteredList [ index ] . Name ;
2014-06-01 15:44:40 +00:00
break ;
case 3 :
2015-02-05 00:04:05 +00:00
text = _filteredList [ index ] . ParameterList ;
2014-06-01 15:44:40 +00:00
break ;
case 4 :
2015-02-05 00:04:05 +00:00
text = _filteredList [ index ] . Description ;
2014-06-01 15:44:40 +00:00
break ;
}
}
}
catch
2014-05-24 13:19:24 +00:00
{
2014-06-01 15:44:40 +00:00
/* Eat it*/
2012-03-28 12:26:43 +00:00
}
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 bool _desc ;
private int _column = 1 ;
2012-07-12 02:03:46 +00:00
public int Column
{
2014-01-25 20:27:51 +00:00
get
{
return _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
{
2013-11-17 15:55:13 +00:00
_desc ^ = 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
}
}
public bool Descending
{
2013-11-17 16:43:12 +00:00
get { return _desc ; }
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 )
{
2018-03-14 01:04:34 +00:00
var itm = _filteredList [ FunctionView . selectedItem ] ;
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 )
Clipboard . SetText ( sb . ToString ( ) ) ;
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 ( ) ;
FunctionView . ItemCount = _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
}
}