@@ -107,7 +107,7 @@ public partial class FileDialog : Dialog {
107
107
private MenuBar allowedTypeMenuBar ;
108
108
private MenuBarItem allowedTypeMenu ;
109
109
private MenuItem [ ] allowedTypeMenuItems ;
110
- private DataColumn filenameColumn ;
110
+ private int filenameColumn ;
111
111
112
112
/// <summary>
113
113
/// Event fired when user attempts to confirm a selection (or multi selection).
@@ -226,7 +226,7 @@ public FileDialog (IFileSystem fileSystem)
226
226
if ( this . tableView . SelectedRow <= 0 ) {
227
227
this . NavigateIf ( k , Key . CursorUp , this . tbPath ) ;
228
228
}
229
- if ( this . tableView . SelectedRow == this . tableView . Table . Rows . Count - 1 ) {
229
+ if ( this . tableView . SelectedRow == this . tableView . Table . Rows - 1 ) {
230
230
this . NavigateIf ( k , Key . CursorDown , this . btnToggleSplitterCollapse ) ;
231
231
}
232
232
@@ -318,7 +318,7 @@ public FileDialog (IFileSystem fileSystem)
318
318
this . sorter = new FileDialogSorter ( this , this . tableView ) ;
319
319
this . history = new FileDialogHistory ( this ) ;
320
320
321
- this . tableView . Table = this . dtFiles ;
321
+ this . tableView . Table = new DataTableSource ( this . dtFiles ) ;
322
322
323
323
this . tbPath . TextChanged += ( s , e ) => this . PathChanged ( ) ;
324
324
@@ -514,7 +514,7 @@ private void ClearFeedback ()
514
514
515
515
private void CycleToNextTableEntryBeginningWith ( KeyEventEventArgs keyEvent )
516
516
{
517
- if ( tableView . Table . Rows . Count == 0 ) {
517
+ if ( tableView . Table . Rows == 0 ) {
518
518
return ;
519
519
}
520
520
@@ -539,11 +539,10 @@ private void UpdateCollectionNavigator ()
539
539
{
540
540
tableView . EnsureValidSelection ( ) ;
541
541
var col = tableView . SelectedColumn ;
542
- var style = tableView . Style . GetColumnStyleIfAny ( tableView . Table . Columns [ col ] ) ;
542
+ var style = tableView . Style . GetColumnStyleIfAny ( col ) ;
543
543
544
544
545
- var collection = tableView
546
- . Table
545
+ var collection = dtFiles
547
546
. Rows
548
547
. Cast < DataRow > ( )
549
548
. Select ( ( o , idx ) => col == 0 ?
@@ -897,7 +896,7 @@ private void UpdateNavigationVisibility ()
897
896
898
897
private void TableView_SelectedCellChanged ( object sender , SelectedCellChangedEventArgs obj )
899
898
{
900
- if ( ! this . tableView . HasFocus || obj . NewRow == - 1 || obj . Table . Rows . Count == 0 ) {
899
+ if ( ! this . tableView . HasFocus || obj . NewRow == - 1 || obj . Table . Rows == 0 ) {
901
900
return ;
902
901
}
903
902
@@ -969,7 +968,7 @@ private void SetupTableColumns ()
969
968
this . dtFiles = new DataTable ( ) ;
970
969
971
970
var nameStyle = this . tableView . Style . GetOrCreateColumnStyle (
972
- filenameColumn = this . dtFiles . Columns . Add ( Style . FilenameColumnName , typeof ( int ) )
971
+ filenameColumn = this . dtFiles . Columns . Add ( Style . FilenameColumnName , typeof ( int ) ) . Ordinal
973
972
) ;
974
973
nameStyle . RepresentationGetter = ( i ) => {
975
974
@@ -989,11 +988,13 @@ private void SetupTableColumns ()
989
988
990
989
nameStyle . MinWidth = 50 ;
991
990
992
- var sizeStyle = this . tableView . Style . GetOrCreateColumnStyle ( this . dtFiles . Columns . Add ( Style . SizeColumnName , typeof ( int ) ) ) ;
991
+ var sizeStyle = this . tableView . Style . GetOrCreateColumnStyle (
992
+ this . dtFiles . Columns . Add ( Style . SizeColumnName , typeof ( int ) ) . Ordinal ) ;
993
993
sizeStyle . RepresentationGetter = ( i ) => this . State ? . Children [ ( int ) i ] . HumanReadableLength ?? string . Empty ;
994
994
nameStyle . MinWidth = 10 ;
995
995
996
- var dateModifiedStyle = this . tableView . Style . GetOrCreateColumnStyle ( this . dtFiles . Columns . Add ( Style . ModifiedColumnName , typeof ( int ) ) ) ;
996
+ var dateModifiedStyle = this . tableView . Style . GetOrCreateColumnStyle (
997
+ this . dtFiles . Columns . Add ( Style . ModifiedColumnName , typeof ( int ) ) . Ordinal ) ;
997
998
dateModifiedStyle . RepresentationGetter = ( i ) =>
998
999
{
999
1000
var s = this . State ? . Children [ ( int ) i ] ;
@@ -1006,7 +1007,8 @@ private void SetupTableColumns ()
1006
1007
1007
1008
dateModifiedStyle . MinWidth = 30 ;
1008
1009
1009
- var typeStyle = this . tableView . Style . GetOrCreateColumnStyle ( this . dtFiles . Columns . Add ( Style . TypeColumnName , typeof ( int ) ) ) ;
1010
+ var typeStyle = this . tableView . Style . GetOrCreateColumnStyle (
1011
+ this . dtFiles . Columns . Add ( Style . TypeColumnName , typeof ( int ) ) . Ordinal ) ;
1010
1012
typeStyle . RepresentationGetter = ( i ) => this . State ? . Children [ ( int ) i ] . Type ?? string . Empty ;
1011
1013
typeStyle . MinWidth = 6 ;
1012
1014
@@ -1237,7 +1239,7 @@ private void WriteStateToTableView ()
1237
1239
1238
1240
private void BuildRow ( int idx )
1239
1241
{
1240
- this . tableView . Table . Rows . Add ( idx , idx , idx , idx ) ;
1242
+ dtFiles . Rows . Add ( idx , idx , idx , idx ) ;
1241
1243
}
1242
1244
1243
1245
private ColorScheme ColorGetter ( TableView . CellColorGetterArgs args )
@@ -1277,7 +1279,7 @@ private IEnumerable<FileSystemInfoStats> MultiRowToStats ()
1277
1279
1278
1280
foreach ( var p in this . tableView . GetAllSelectedCells ( ) ) {
1279
1281
1280
- var add = this . State ? . Children [ ( int ) this . tableView . Table . Rows [ p . Y ] [ 0 ] ] ;
1282
+ var add = this . State ? . Children [ ( int ) this . tableView . Table [ p . Y , 0 ] ] ;
1281
1283
if ( add != null ) {
1282
1284
toReturn . Add ( add ) ;
1283
1285
}
@@ -1288,7 +1290,7 @@ private IEnumerable<FileSystemInfoStats> MultiRowToStats ()
1288
1290
}
1289
1291
private FileSystemInfoStats RowToStats ( int rowIndex )
1290
1292
{
1291
- return this . State ? . Children [ ( int ) this . tableView . Table . Rows [ rowIndex ] [ 0 ] ] ;
1293
+ return this . State ? . Children [ ( int ) this . tableView . Table [ rowIndex , 0 ] ] ;
1292
1294
}
1293
1295
private int ? StatsToRow ( IFileSystemInfo fileSystemInfo )
1294
1296
{
@@ -1299,7 +1301,7 @@ private FileSystemInfoStats RowToStats (int rowIndex)
1299
1301
1300
1302
// find the row number in our DataTable where the cell
1301
1303
// contains idx
1302
- var match = tableView . Table . Rows
1304
+ var match = dtFiles . Rows
1303
1305
. Cast < DataRow > ( )
1304
1306
. Select ( ( r , rIdx ) => new { row = r , rowIdx = rIdx } )
1305
1307
. Where ( t => ( int ) t . row [ 0 ] == idx )
@@ -1367,7 +1369,7 @@ private class FileDialogSorter {
1367
1369
private readonly FileDialog dlg ;
1368
1370
private TableView tableView ;
1369
1371
1370
- private DataColumn currentSort = null ;
1372
+ private int ? currentSort = null ;
1371
1373
private bool currentSortIsAsc = true ;
1372
1374
1373
1375
public FileDialogSorter ( FileDialog dlg , TableView tableView )
@@ -1378,17 +1380,17 @@ public FileDialogSorter (FileDialog dlg, TableView tableView)
1378
1380
// if user clicks the mouse in TableView
1379
1381
this . tableView . MouseClick += ( s , e ) => {
1380
1382
1381
- var clickedCell = this . tableView . ScreenToCell ( e . MouseEvent . X , e . MouseEvent . Y , out DataColumn clickedCol ) ;
1383
+ var clickedCell = this . tableView . ScreenToCell ( e . MouseEvent . X , e . MouseEvent . Y , out int ? clickedCol ) ;
1382
1384
1383
1385
if ( clickedCol != null ) {
1384
1386
if ( e . MouseEvent . Flags . HasFlag ( MouseFlags . Button1Clicked ) ) {
1385
1387
1386
1388
// left click in a header
1387
- this . SortColumn ( clickedCol ) ;
1389
+ this . SortColumn ( clickedCol . Value ) ;
1388
1390
} else if ( e . MouseEvent . Flags . HasFlag ( MouseFlags . Button3Clicked ) ) {
1389
1391
1390
1392
// right click in a header
1391
- this . ShowHeaderContextMenu ( clickedCol , e ) ;
1393
+ this . ShowHeaderContextMenu ( clickedCol . Value , e ) ;
1392
1394
}
1393
1395
} else {
1394
1396
if ( clickedCell != null && e . MouseEvent . Flags . HasFlag ( MouseFlags . Button3Clicked ) ) {
@@ -1406,10 +1408,14 @@ internal void ApplySort ()
1406
1408
{
1407
1409
var col = this . currentSort ;
1408
1410
1411
+ if ( col == null ) {
1412
+ return ;
1413
+ }
1414
+
1409
1415
// TODO: Consider preserving selection
1410
- this . tableView . Table . Rows . Clear ( ) ;
1416
+ dlg . dtFiles . Rows . Clear ( ) ;
1411
1417
1412
- var colName = col == null ? null : StripArrows ( col . ColumnName ) ;
1418
+ var colName = col == null ? null : StripArrows ( tableView . Table . ColumnNames [ col . Value ] ) ;
1413
1419
1414
1420
var stats = this . dlg . State ? . Children ?? new FileSystemInfoStats [ 0 ] ;
1415
1421
@@ -1438,13 +1444,13 @@ internal void ApplySort ()
1438
1444
this . dlg . BuildRow ( o . i ) ;
1439
1445
}
1440
1446
1441
- foreach ( DataColumn c in this . tableView . Table . Columns ) {
1447
+ foreach ( DataColumn c in dlg . dtFiles . Columns ) {
1442
1448
1443
1449
// remove any lingering sort indicator
1444
1450
c . ColumnName = StripArrows ( c . ColumnName ) ;
1445
1451
1446
1452
// add a new one if this the one that is being sorted
1447
- if ( c == col ) {
1453
+ if ( c . Ordinal == col ) {
1448
1454
c . ColumnName += this . currentSortIsAsc ? " (▲)" : " (▼)" ;
1449
1455
}
1450
1456
}
@@ -1458,13 +1464,13 @@ private static string StripArrows (string columnName)
1458
1464
return columnName . Replace ( " (▼)" , string . Empty ) . Replace ( " (▲)" , string . Empty ) ;
1459
1465
}
1460
1466
1461
- private void SortColumn ( DataColumn clickedCol )
1467
+ private void SortColumn ( int clickedCol )
1462
1468
{
1463
1469
this . GetProposedNewSortOrder ( clickedCol , out var isAsc ) ;
1464
1470
this . SortColumn ( clickedCol , isAsc ) ;
1465
1471
}
1466
1472
1467
- internal void SortColumn ( DataColumn col , bool isAsc )
1473
+ internal void SortColumn ( int col , bool isAsc )
1468
1474
{
1469
1475
// set a sort order
1470
1476
this . currentSort = col ;
@@ -1473,19 +1479,19 @@ internal void SortColumn (DataColumn col, bool isAsc)
1473
1479
this . ApplySort ( ) ;
1474
1480
}
1475
1481
1476
- private string GetProposedNewSortOrder ( DataColumn clickedCol , out bool isAsc )
1482
+ private string GetProposedNewSortOrder ( int clickedCol , out bool isAsc )
1477
1483
{
1478
1484
// work out new sort order
1479
1485
if ( this . currentSort == clickedCol && this . currentSortIsAsc ) {
1480
1486
isAsc = false ;
1481
- return $ "{ clickedCol . ColumnName } DESC";
1487
+ return $ "{ tableView . Table . ColumnNames [ clickedCol ] } DESC";
1482
1488
} else {
1483
1489
isAsc = true ;
1484
- return $ "{ clickedCol . ColumnName } ASC";
1490
+ return $ "{ tableView . Table . ColumnNames [ clickedCol ] } ASC";
1485
1491
}
1486
1492
}
1487
1493
1488
- private void ShowHeaderContextMenu ( DataColumn clickedCol , MouseEventEventArgs e )
1494
+ private void ShowHeaderContextMenu ( int clickedCol , MouseEventEventArgs e )
1489
1495
{
1490
1496
var sort = this . GetProposedNewSortOrder ( clickedCol , out var isAsc ) ;
1491
1497
@@ -1494,7 +1500,7 @@ private void ShowHeaderContextMenu (DataColumn clickedCol, MouseEventEventArgs e
1494
1500
e . MouseEvent . Y + 1 ,
1495
1501
new MenuBarItem ( new MenuItem [ ]
1496
1502
{
1497
- new MenuItem ( $ "Hide { StripArrows ( clickedCol . ColumnName ) } ", string . Empty , ( ) => this . HideColumn ( clickedCol ) ) ,
1503
+ new MenuItem ( $ "Hide { StripArrows ( tableView . Table . ColumnNames [ clickedCol ] ) } ", string . Empty , ( ) => this . HideColumn ( clickedCol ) ) ,
1498
1504
new MenuItem ( $ "Sort { StripArrows ( sort ) } ", string . Empty , ( ) => this . SortColumn ( clickedCol , isAsc ) ) ,
1499
1505
} )
1500
1506
) ;
@@ -1524,7 +1530,7 @@ private void ShowCellContextMenu (Point? clickedCell, MouseEventEventArgs e)
1524
1530
contextMenu . Show ( ) ;
1525
1531
}
1526
1532
1527
- private void HideColumn ( DataColumn clickedCol )
1533
+ private void HideColumn ( int clickedCol )
1528
1534
{
1529
1535
var style = this . tableView . Style . GetOrCreateColumnStyle ( clickedCol ) ;
1530
1536
style . Visible = false ;
0 commit comments