|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
| 3 | +using System.IO; |
3 | 4 | using System.Threading.Tasks; |
4 | 5 |
|
5 | 6 | using Avalonia.Controls; |
@@ -150,6 +151,74 @@ public ContextMenu MakeContextMenu(Models.Stash stash) |
150 | 151 | return menu; |
151 | 152 | } |
152 | 153 |
|
| 154 | + public ContextMenu MakeContextMenuForChange(Models.Change change) |
| 155 | + { |
| 156 | + if (change == null) |
| 157 | + return null; |
| 158 | + |
| 159 | + var diffWithMerger = new MenuItem(); |
| 160 | + diffWithMerger.Header = App.Text("DiffWithMerger"); |
| 161 | + diffWithMerger.Icon = App.CreateMenuIcon("Icons.OpenWith"); |
| 162 | + diffWithMerger.Click += (_, ev) => |
| 163 | + { |
| 164 | + var toolType = Preference.Instance.ExternalMergeToolType; |
| 165 | + var toolPath = Preference.Instance.ExternalMergeToolPath; |
| 166 | + var opt = new Models.DiffOption($"{_selectedStash.SHA}^", _selectedStash.SHA, change); |
| 167 | + |
| 168 | + Task.Run(() => Commands.MergeTool.OpenForDiff(_repo.FullPath, toolType, toolPath, opt)); |
| 169 | + ev.Handled = true; |
| 170 | + }; |
| 171 | + |
| 172 | + var fullPath = Path.Combine(_repo.FullPath, change.Path); |
| 173 | + var explore = new MenuItem(); |
| 174 | + explore.Header = App.Text("RevealFile"); |
| 175 | + explore.Icon = App.CreateMenuIcon("Icons.Explore"); |
| 176 | + explore.IsEnabled = File.Exists(fullPath); |
| 177 | + explore.Click += (_, ev) => |
| 178 | + { |
| 179 | + Native.OS.OpenInFileManager(fullPath, true); |
| 180 | + ev.Handled = true; |
| 181 | + }; |
| 182 | + |
| 183 | + var resetToThisRevision = new MenuItem(); |
| 184 | + resetToThisRevision.Header = App.Text("ChangeCM.CheckoutThisRevision"); |
| 185 | + resetToThisRevision.Icon = App.CreateMenuIcon("Icons.File.Checkout"); |
| 186 | + resetToThisRevision.Click += (_, ev) => |
| 187 | + { |
| 188 | + new Commands.Checkout(_repo.FullPath).FileWithRevision(change.Path, $"{_selectedStash.SHA}"); |
| 189 | + ev.Handled = true; |
| 190 | + }; |
| 191 | + |
| 192 | + var copyPath = new MenuItem(); |
| 193 | + copyPath.Header = App.Text("CopyPath"); |
| 194 | + copyPath.Icon = App.CreateMenuIcon("Icons.Copy"); |
| 195 | + copyPath.Click += (_, ev) => |
| 196 | + { |
| 197 | + App.CopyText(change.Path); |
| 198 | + ev.Handled = true; |
| 199 | + }; |
| 200 | + |
| 201 | + var copyFileName = new MenuItem(); |
| 202 | + copyFileName.Header = App.Text("CopyFileName"); |
| 203 | + copyFileName.Icon = App.CreateMenuIcon("Icons.Copy"); |
| 204 | + copyFileName.Click += (_, e) => |
| 205 | + { |
| 206 | + App.CopyText(Path.GetFileName(change.Path)); |
| 207 | + e.Handled = true; |
| 208 | + }; |
| 209 | + |
| 210 | + var menu = new ContextMenu(); |
| 211 | + menu.Items.Add(diffWithMerger); |
| 212 | + menu.Items.Add(explore); |
| 213 | + menu.Items.Add(new MenuItem { Header = "-" }); |
| 214 | + menu.Items.Add(resetToThisRevision); |
| 215 | + menu.Items.Add(new MenuItem { Header = "-" }); |
| 216 | + menu.Items.Add(copyPath); |
| 217 | + menu.Items.Add(copyFileName); |
| 218 | + |
| 219 | + return menu; |
| 220 | + } |
| 221 | + |
153 | 222 | public void Clear() |
154 | 223 | { |
155 | 224 | if (PopupHost.CanCreatePopup()) |
|
0 commit comments