Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
<StackPanel Orientation="Horizontal" Spacing="{StaticResource SpacingXsValue}">
<Button Classes="primary" Content="New" Command="{Binding NewDocumentCommand}"
ToolTip.Tip="New Document (Ctrl+N)" />
<Button Classes="secondary" Content="Open" Command="{Binding OpenDocumentCommand}" />
<Button Classes="secondary" Content="Save" Command="{Binding SaveDocumentCommand}" />
<Button Classes="secondary" Content="Open" Command="{Binding OpenDocumentCommand}"
ToolTip.Tip="Open Document (Ctrl+O)" />
<Button Classes="secondary" Content="Save" Command="{Binding SaveDocumentCommand}"
ToolTip.Tip="Save Document (Ctrl+S)" />
</StackPanel>
</Border>
</UserControl>
4 changes: 4 additions & 0 deletions src/TextForge.Desktop/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<Window.KeyBindings>
<KeyBinding Gesture="Ctrl+N"
Command="{Binding CommandBarViewModel.NewDocumentCommand}" />
<KeyBinding Gesture="Ctrl+O"
Command="{Binding CommandBarViewModel.OpenDocumentCommand}" />
<KeyBinding Gesture="Ctrl+S"
Command="{Binding CommandBarViewModel.SaveDocumentCommand}" />
</Window.KeyBindings>

<Grid RowDefinitions="Auto, *, Auto">
Expand Down
31 changes: 31 additions & 0 deletions tests/TextForge.Desktop.Tests/TopCommandBarViewModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Windows.Input;
using TextForge.Core.Presentation;
using TextForge.Desktop.ViewModels;
using Xunit;
Expand All @@ -13,10 +14,40 @@ public void NewDocumentCommand_ResetsDocumentStateInMainViewModel()
var mainVM = new MainWindowViewModel(mockPaletteProvider);
var commandBarVM = new TopCommandBarViewModel(mainVM);

Assert.IsAssignableFrom<ICommand>(commandBarVM.NewDocumentCommand);
commandBarVM.NewDocumentCommand.Execute(null);

Assert.Equal("Untitled.txt", mainVM.CurrentDocumentTitle);
Assert.False(mainVM.IsModified);
Assert.Equal("Created new document: Untitled.txt", mainVM.StatusMessage);
}

[Fact]
public void OpenDocumentCommand_UpdatesStatusMessageInMainViewModel()
{
var mockPaletteProvider = new TestModulePaletteProvider();
var mainVM = new MainWindowViewModel(mockPaletteProvider);
var commandBarVM = new TopCommandBarViewModel(mainVM);

Assert.IsAssignableFrom<ICommand>(commandBarVM.OpenDocumentCommand);
commandBarVM.OpenDocumentCommand.Execute(null);

Assert.Equal("Opening document...", mainVM.StatusMessage);
}

[Fact]
public void SaveDocumentCommand_ResetsModifiedAndUpdatesStatusMessageInMainViewModel()
{
var mockPaletteProvider = new TestModulePaletteProvider();
var mainVM = new MainWindowViewModel(mockPaletteProvider);
mainVM.CurrentDocumentTitle = "Report.txt";
mainVM.IsModified = true;
var commandBarVM = new TopCommandBarViewModel(mainVM);

Assert.IsAssignableFrom<ICommand>(commandBarVM.SaveDocumentCommand);
commandBarVM.SaveDocumentCommand.Execute(null);

Assert.False(mainVM.IsModified);
Assert.Equal("Saved Report.txt", mainVM.StatusMessage);
}
}
Loading