-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from AvaloniaUI/feature/template-cell-edit
Implement edit mode for template cells.
- Loading branch information
Showing
22 changed files
with
347 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/Avalonia.Controls.TreeDataGrid/Models/TreeDataGrid/ICellOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Avalonia.Media; | ||
|
||
namespace Avalonia.Controls.Models.TreeDataGrid | ||
{ | ||
public interface ICellOptions | ||
{ | ||
/// <summary> | ||
/// Gets the gesture(s) that will cause the cell to enter edit mode. | ||
/// </summary> | ||
BeginEditGestures BeginEditGestures { get; } | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Avalonia.Controls.TreeDataGrid/Models/TreeDataGrid/ITemplateCellOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Avalonia.Media; | ||
|
||
namespace Avalonia.Controls.Models.TreeDataGrid | ||
{ | ||
public interface ITemplateCellOptions : ICellOptions | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 18 additions & 4 deletions
22
src/Avalonia.Controls.TreeDataGrid/Models/TreeDataGrid/TemplateCell.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,34 @@ | ||
| ||
using System; | ||
using System.ComponentModel; | ||
using Avalonia.Controls.Templates; | ||
|
||
namespace Avalonia.Controls.Models.TreeDataGrid | ||
{ | ||
public class TemplateCell : ICell | ||
public class TemplateCell : ICell, IEditableObject | ||
{ | ||
public TemplateCell(object? value, Func<Control, IDataTemplate> getCellTemplate) | ||
private ITemplateCellOptions? _options; | ||
|
||
public TemplateCell( | ||
object? value, | ||
Func<Control, IDataTemplate> getCellTemplate, | ||
Func<Control, IDataTemplate>? getCellEditingTemplate, | ||
ITemplateCellOptions? options) | ||
{ | ||
GetCellTemplate = getCellTemplate; | ||
GetCellEditingTemplate = getCellEditingTemplate; | ||
Value = value; | ||
_options = options; | ||
} | ||
|
||
public bool CanEdit => false; | ||
public bool SingleTapEdit => false; | ||
public bool CanEdit => GetCellEditingTemplate is not null; | ||
public BeginEditGestures EditGestures => _options?.BeginEditGestures ?? BeginEditGestures.Default; | ||
public Func<Control, IDataTemplate> GetCellTemplate { get; } | ||
public Func<Control, IDataTemplate>? GetCellEditingTemplate { get; } | ||
public object? Value { get; } | ||
|
||
void IEditableObject.BeginEdit() => (Value as IEditableObject)?.BeginEdit(); | ||
void IEditableObject.CancelEdit() => (Value as IEditableObject)?.CancelEdit(); | ||
void IEditableObject.EndEdit() => (Value as IEditableObject)?.EndEdit(); | ||
} | ||
} |
Oops, something went wrong.