Skip to content

Commit

Permalink
Merge pull request #106 from Diaskhan/bug/fix_messagebox
Browse files Browse the repository at this point in the history
fix MessageBox focus
  • Loading branch information
anovik authored Oct 13, 2024
2 parents a2c2dcd + 166aefb commit 6f276ed
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
6 changes: 4 additions & 2 deletions src/SmartCommander/ViewModels/CopyMoveViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ public CopyMoveViewModel(bool copy, string text, string directory)

public bool IsCopying { get; set; }

public string Text { get;set;}
public string Text { get; set; }

public string Directory { get; set; }

public string CopyText => IsCopying? string.Format(Resources.CopyTo, Text) :
public string CopyText => IsCopying ? string.Format(Resources.CopyTo, Text) :
string.Format(Resources.MoveTo, Text);

public ReactiveCommand<Window, Unit> OKCommand { get; }
public ReactiveCommand<Window, Unit> CancelCommand { get; }

public void SaveClose(Window window)
{
IsCopying = true;
window?.Close(this);
}

public void Close(Window window)
{
IsCopying = false;
window?.Close(this);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/SmartCommander/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public async Task Copy()
string.Format(Resources.ItemsNumber, SelectedPane.CurrentItems.Count);
var copy = new CopyMoveViewModel(true, text, SecondPane.CurrentDirectory);
var result = await ShowCopyDialog.Handle(copy);
if (result != null)
if (result != null && result.IsCopying)
{
var duplicates = Utils.GetDuplicates(SelectedPane.CurrentItems, SecondPane.CurrentDirectory);

Expand Down Expand Up @@ -461,7 +461,7 @@ public async Task Move()
string.Format(Resources.ItemsNumber, SelectedPane.CurrentItems.Count);
var copy = new CopyMoveViewModel(false, text, SecondPane.CurrentDirectory);
var result = await ShowCopyDialog.Handle(copy);
if (result != null)
if (result != null && result.IsCopying)
{
var duplicates = Utils.GetDuplicates(SelectedPane.CurrentItems, SecondPane.CurrentDirectory);

Expand Down
30 changes: 15 additions & 15 deletions src/SmartCommander/Views/CopyMoveWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
Icon="/Assets/main.ico"
CanResize="False"
Title="SmartCommander">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Margin="10" Text="{Binding CopyText}" TextWrapping="Wrap"></TextBlock>
<TextBlock Margin="10" Grid.Row="1" Text="{Binding Directory}"></TextBlock>
<StackPanel Margin="10" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Margin="5" Command="{Binding OKCommand}" CommandParameter="{Binding $parent[Window]}"
Content="{x:Static assets:Resources.OK}"></Button>
<Button Margin="5" Command="{Binding CancelCommand}" CommandParameter="{Binding $parent[Window]}"
Content="{x:Static assets:Resources.Cancel}"></Button>
</StackPanel>
</Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Margin="10" Text="{Binding CopyText}" TextWrapping="Wrap"></TextBlock>
<TextBlock Margin="10" Grid.Row="1" Text="{Binding Directory}"></TextBlock>
<StackPanel Margin="10" Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Margin="5" Command="{Binding OKCommand}" CommandParameter="{Binding $parent[Window]}"
Content="{x:Static assets:Resources.OK}" IsDefault="True"></Button>
<Button Margin="5" Command="{Binding CancelCommand}" CommandParameter="{Binding $parent[Window]}"
Content="{x:Static assets:Resources.Cancel}" IsCancel="True"></Button>
</StackPanel>
</Grid>
</Window>
8 changes: 4 additions & 4 deletions src/SmartCommander/Views/MvvmMessageBoxEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Show(Window owner)
{
var messageBoxWindow = MsBox.Avalonia.MessageBoxManager
.GetMessageBoxStandard(caption, messageBoxText + Environment.NewLine, button, icon);
var result = await messageBoxWindow.ShowAsPopupAsync(owner);
var result = await messageBoxWindow.ShowWindowDialogAsync(owner);
resultAction?.Invoke(result, parameter);
});
}
Expand All @@ -59,12 +59,12 @@ public void ShowInput(Window owner)
MinWidth = 300,
InputParams = new InputParams() { },
ButtonDefinitions = new[] {
new ButtonDefinition {Name = Resources.OK},
new ButtonDefinition {Name = Resources.Cancel, IsCancel = true, IsDefault = true}
new ButtonDefinition {Name = Resources.OK, IsDefault = true},
new ButtonDefinition {Name = Resources.Cancel, IsCancel = true}
},
WindowStartupLocation = WindowStartupLocation.CenterOwner
});
var result = await messageBoxWindow.ShowAsPopupAsync(owner);
var result = await messageBoxWindow.ShowWindowDialogAsync(owner);
resultInputAction?.Invoke(result == Resources.OK ? messageBoxWindow.InputValue : "");
});
}
Expand Down

0 comments on commit 6f276ed

Please sign in to comment.