This repository was archived by the owner on Jun 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +49
-5
lines changed
Expand file tree Collapse file tree 4 files changed +49
-5
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,9 @@ public CommentViewModelDesigner()
3131 public ReactiveCommand < object > BeginCreate { get ; }
3232 public ReactiveCommand < object > CancelCreate { get ; }
3333 public ReactiveCommand < Unit > CommitCreate { get ; }
34+ public ReactiveCommand < object > BeginEdit { get ; }
35+ public ReactiveCommand < object > CancelEdit { get ; }
36+ public ReactiveCommand < Unit > CommitEdit { get ; }
3437 public ReactiveCommand < object > OpenOnGitHub { get ; }
3538 public ReactiveCommand < object > Delete { get ; }
3639 }
Original file line number Diff line number Diff line change @@ -66,6 +66,13 @@ protected CommentViewModel(
6666
6767 Delete = ReactiveCommand . Create ( canDelete ) ;
6868
69+ var canEdit = this . WhenAnyValue (
70+ x => x . EditState ,
71+ x => x == CommentEditState . None && user . Login . Equals ( currentUser . Login ) ) ;
72+
73+ BeginEdit = ReactiveCommand . Create ( canEdit ) ;
74+ BeginEdit . Subscribe ( DoBeginEdit ) ;
75+
6976 var canCreate = this . WhenAnyValue (
7077 x => x . EditState ,
7178 x => x == CommentEditState . Placeholder ||
@@ -110,6 +117,15 @@ protected void AddErrorHandler<T>(ReactiveCommand<T> command)
110117 command . ThrownExceptions . Subscribe ( x => ErrorMessage = x . Message ) ;
111118 }
112119
120+ void DoBeginEdit ( object unused )
121+ {
122+ if ( state != CommentEditState . Editing )
123+ {
124+ undoBody = Body ;
125+ EditState = CommentEditState . Editing ;
126+ }
127+ }
128+
113129 void DoBeginCreate ( object unused )
114130 {
115131 if ( state != CommentEditState . Creating )
@@ -221,6 +237,15 @@ public DateTimeOffset UpdatedAt
221237 /// <inheritdoc/>
222238 public ReactiveCommand < Unit > CommitCreate { get ; }
223239
240+ /// <inheritdoc/>
241+ public ReactiveCommand < object > BeginEdit { get ; }
242+
243+ /// <inheritdoc/>
244+ public ReactiveCommand < object > CancelEdit { get ; }
245+
246+ /// <inheritdoc/>
247+ public ReactiveCommand < Unit > CommitEdit { get ; }
248+
224249 /// <inheritdoc/>
225250 public ReactiveCommand < object > OpenOnGitHub { get ; }
226251
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ public enum CommentEditState
1010 {
1111 None ,
1212 Creating ,
13+ Editing ,
1314 Placeholder ,
1415 }
1516
@@ -70,20 +71,35 @@ public interface ICommentViewModel : IViewModel
7071 ICommentThreadViewModel Thread { get ; }
7172
7273 /// <summary>
73- /// Gets a command which will begin editing of the comment.
74+ /// Gets a command which will begin the creation of the comment.
7475 /// </summary>
7576 ReactiveCommand < object > BeginCreate { get ; }
7677
7778 /// <summary>
78- /// Gets a command which will cancel editing of the comment.
79+ /// Gets a command which will cancel the creation of the comment.
7980 /// </summary>
8081 ReactiveCommand < object > CancelCreate { get ; }
8182
8283 /// <summary>
83- /// Gets a command which will commit edits to the comment.
84+ /// Gets a command which will commit the creation of the comment.
8485 /// </summary>
8586 ReactiveCommand < Unit > CommitCreate { get ; }
8687
88+ /// <summary>
89+ /// Gets a command which will begin editing of the comment.
90+ /// </summary>
91+ ReactiveCommand < object > BeginEdit { get ; }
92+
93+ /// <summary>
94+ /// Gets a command which will cancel editing of the comment.
95+ /// </summary>
96+ ReactiveCommand < object > CancelEdit { get ; }
97+
98+ /// <summary>
99+ /// Gets a command which will commit edits to the comment.
100+ /// </summary>
101+ ReactiveCommand < Unit > CommitEdit { get ; }
102+
87103 /// <summary>
88104 /// Gets a command to open the comment in a browser.
89105 /// </summary>
Original file line number Diff line number Diff line change 1212 xmlns : views =" clr-namespace:GitHub.InlineReviews.Views"
1313 mc : Ignorable =" d" d : DesignWidth =" 300" >
1414 <d : DesignProperties .DataContext>
15- <sample : CommentViewModelDesigner EditState =" None " >
15+ <sample : CommentViewModelDesigner EditState =" Creating " >
1616 <sample : CommentViewModelDesigner .Body>
1717 You can use a `CompositeDisposable` type here, it's designed to handle disposables in an optimal way (you can just call `Dispose()` on it and it will handle disposing everything it holds).
1818 </sample : CommentViewModelDesigner .Body>
7979 HorizontalAlignment =" Right"
8080 DockPanel.Dock=" Right" />
8181 <ui : GitHubActionLink Content =" Edit"
82- Command =" {Binding BeginCreate }"
82+ Command =" {Binding BeginEdit }"
8383 Foreground =" {DynamicResource GitHubVsToolWindowText}"
8484 Opacity =" 0.75"
8585 HorizontalAlignment =" Right"
You can’t perform that action at this time.
0 commit comments