| 1 | using System.Linq; |
| 2 | using CommunityToolkit.Mvvm.Input; |
| 3 | |
| 4 | namespace CascadeIDE.Features.Documents; |
| 5 | |
| 6 | /// <summary>Relay: вкладки документов и группы.</summary> |
| 7 | public sealed partial class DocumentsWorkspaceViewModel |
| 8 | { |
| 9 | [RelayCommand] |
| 10 | private void ActivateDocument(string? filePath) |
| 11 | { |
| 12 | if (string.IsNullOrWhiteSpace(filePath)) |
| 13 | return; |
| 14 | var doc = OpenDocuments.FirstOrDefault(d => string.Equals(d.FilePath, filePath, StringComparison.OrdinalIgnoreCase)); |
| 15 | if (doc is null) |
| 16 | OpenOrActivateDocument(filePath); |
| 17 | else |
| 18 | ActivateDocumentInternal(doc); |
| 19 | } |
| 20 | |
| 21 | [RelayCommand] |
| 22 | private void CloseDocument(string? filePath) |
| 23 | { |
| 24 | if (string.IsNullOrWhiteSpace(filePath)) |
| 25 | return; |
| 26 | CloseDocumentByPath(filePath); |
| 27 | } |
| 28 | |
| 29 | [RelayCommand] |
| 30 | private void TogglePinDocument(string? filePath) |
| 31 | { |
| 32 | if (string.IsNullOrWhiteSpace(filePath)) |
| 33 | return; |
| 34 | var doc = OpenDocuments.FirstOrDefault(d => string.Equals(d.FilePath, filePath, StringComparison.OrdinalIgnoreCase)); |
| 35 | if (doc is not null) |
| 36 | doc.IsPinned = !doc.IsPinned; |
| 37 | } |
| 38 | |
| 39 | [RelayCommand] |
| 40 | private void MoveDocumentToGroup1(string? filePath) => MoveDocumentToGroup(filePath, 1); |
| 41 | |
| 42 | [RelayCommand] |
| 43 | private void MoveDocumentToGroup2(string? filePath) => MoveDocumentToGroup(filePath, 2); |
| 44 | |
| 45 | [RelayCommand] |
| 46 | private void MoveDocumentToGroup3(string? filePath) => MoveDocumentToGroup(filePath, 3); |
| 47 | |
| 48 | [RelayCommand(CanExecute = nameof(CanReopenClosedDocument))] |
| 49 | private void ReopenClosedDocument() => ReopenLastClosedDocument(); |
| 50 | |
| 51 | private void MoveDocumentToGroup(string? filePath, int groupIndex) |
| 52 | { |
| 53 | if (string.IsNullOrWhiteSpace(filePath)) |
| 54 | return; |
| 55 | var doc = OpenDocuments.FirstOrDefault(d => string.Equals(d.FilePath, filePath, StringComparison.OrdinalIgnoreCase)); |
| 56 | if (doc is not null) |
| 57 | MoveDocumentToGroupInternal(doc, groupIndex); |
| 58 | } |
| 59 | |
| 60 | private void NotifyReopenClosedCanExecuteChanged() => |
| 61 | ReopenClosedDocumentCommand.NotifyCanExecuteChanged(); |
| 62 | } |
| 63 | |