Added showing of ActiveFilepath and made things line up
This commit is contained in:
parent
cb06af6065
commit
5f1d7ef530
@ -59,5 +59,22 @@ namespace XSDVisualiser.Desktop.ViewModels
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<SchemaNode> VisibleRootElements => SelectedRootElement != null ? [SelectedRootElement] : RootElements;
|
public IEnumerable<SchemaNode> VisibleRootElements => SelectedRootElement != null ? [SelectedRootElement] : RootElements;
|
||||||
|
|
||||||
|
private string? _currentFilePath;
|
||||||
|
public string? CurrentFilePath
|
||||||
|
{
|
||||||
|
get => _currentFilePath;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (string.Equals(_currentFilePath, value, StringComparison.Ordinal)) return;
|
||||||
|
_currentFilePath = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
OnPropertyChanged(nameof(CurrentFileName));
|
||||||
|
OnPropertyChanged(nameof(CurrentDirectory));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string? CurrentFileName => string.IsNullOrEmpty(_currentFilePath) ? null : System.IO.Path.GetFileName(_currentFilePath);
|
||||||
|
public string? CurrentDirectory => string.IsNullOrEmpty(_currentFilePath) ? null : System.IO.Path.GetDirectoryName(_currentFilePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,13 +2,22 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
x:Class="XSDVisualiser.Desktop.Views.HeaderView"
|
x:Class="XSDVisualiser.Desktop.Views.HeaderView"
|
||||||
x:CompileBindings="False">
|
x:CompileBindings="False">
|
||||||
<DockPanel LastChildFill="False">
|
<Grid RowDefinitions="Auto" ColumnDefinitions="Auto,*,Auto,Auto" MinHeight="44">
|
||||||
<TextBlock Text="XSD Visualiser" FontSize="20" FontWeight="SemiBold" Margin="0,0,12,0" DockPanel.Dock="Left"/>
|
<TextBlock Grid.Column="0"
|
||||||
|
Text="XSD Visualiser"
|
||||||
|
FontSize="20"
|
||||||
|
FontWeight="SemiBold"
|
||||||
|
Margin="0,0,12,0"
|
||||||
|
VerticalAlignment="Center"/>
|
||||||
|
|
||||||
<AutoCompleteBox Width="320" Margin="0,0,12,0" Watermark="Search and choose a root element"
|
<AutoCompleteBox Grid.Column="1"
|
||||||
|
Margin="0,0,12,0"
|
||||||
|
Watermark="Search and choose a root element"
|
||||||
ItemsSource="{Binding RootElements}"
|
ItemsSource="{Binding RootElements}"
|
||||||
FilterMode="Contains"
|
FilterMode="Contains"
|
||||||
MinimumPrefixLength="0">
|
MinimumPrefixLength="0"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
VerticalAlignment="Center">
|
||||||
<AutoCompleteBox.ItemTemplate>
|
<AutoCompleteBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<TextBlock Text="{Binding .}"/>
|
<TextBlock Text="{Binding .}"/>
|
||||||
@ -19,6 +28,35 @@
|
|||||||
</AutoCompleteBox.SelectedItem>
|
</AutoCompleteBox.SelectedItem>
|
||||||
</AutoCompleteBox>
|
</AutoCompleteBox>
|
||||||
|
|
||||||
<Button Content="Open XSD and parse" x:Name="OpenBtn" Width="220"/>
|
<Button Grid.Column="2"
|
||||||
</DockPanel>
|
Content="Open XSD and parse"
|
||||||
|
x:Name="OpenBtn"
|
||||||
|
Width="220"
|
||||||
|
VerticalAlignment="Center"/>
|
||||||
|
|
||||||
|
<Border Grid.Column="3"
|
||||||
|
Background="{DynamicResource PanelBackgroundBrush}"
|
||||||
|
BorderBrush="{DynamicResource PanelBorderBrush}"
|
||||||
|
BorderThickness="1"
|
||||||
|
CornerRadius="6"
|
||||||
|
Padding="8"
|
||||||
|
Margin="12,0,0,0"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
IsVisible="{Binding CurrentFilePath, Converter={x:Static ObjectConverters.IsNotNull}}"
|
||||||
|
ToolTip.Tip="{Binding CurrentFilePath}">
|
||||||
|
<Border.ContextMenu>
|
||||||
|
<ContextMenu>
|
||||||
|
<MenuItem Header="Copy path" Click="OnCopyPathClick"/>
|
||||||
|
<MenuItem Header="Open containing folder" Click="OnOpenContainingFolderClick"/>
|
||||||
|
</ContextMenu>
|
||||||
|
</Border.ContextMenu>
|
||||||
|
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||||
|
<TextBlock Text="File:" Foreground="{DynamicResource SubtleTextBrush}"/>
|
||||||
|
<StackPanel MaxWidth="520">
|
||||||
|
<TextBlock Text="{Binding CurrentFileName}" FontWeight="SemiBold" TextTrimming="CharacterEllipsis"/>
|
||||||
|
<TextBlock Text="{Binding CurrentDirectory}" Foreground="{DynamicResource SubtleTextBrush}" TextTrimming="CharacterEllipsis"/>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@ -66,7 +66,14 @@ public partial class HeaderView : UserControl
|
|||||||
{
|
{
|
||||||
var parser = new XsdSchemaParser();
|
var parser = new XsdSchemaParser();
|
||||||
var model = parser.Parse(path);
|
var model = parser.Parse(path);
|
||||||
Dispatcher.UIThread.Post(() => hostWindow.DataContext = new MainWindowViewModel(model));
|
Dispatcher.UIThread.Post(() =>
|
||||||
|
{
|
||||||
|
var vm = new MainWindowViewModel(model)
|
||||||
|
{
|
||||||
|
CurrentFilePath = path
|
||||||
|
};
|
||||||
|
hostWindow.DataContext = vm;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -74,4 +81,67 @@ public partial class HeaderView : UserControl
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void OnCopyPathClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var vm = DataContext as MainWindowViewModel;
|
||||||
|
var path = vm?.CurrentFilePath;
|
||||||
|
if (string.IsNullOrWhiteSpace(path)) return;
|
||||||
|
|
||||||
|
var topLevel = TopLevel.GetTopLevel(this);
|
||||||
|
if (topLevel?.Clipboard != null)
|
||||||
|
{
|
||||||
|
await topLevel.Clipboard.SetTextAsync(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnOpenContainingFolderClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var vm = DataContext as MainWindowViewModel;
|
||||||
|
var path = vm?.CurrentFilePath;
|
||||||
|
if (string.IsNullOrWhiteSpace(path)) return;
|
||||||
|
var dir = System.IO.Path.GetDirectoryName(path);
|
||||||
|
if (string.IsNullOrWhiteSpace(dir) || !System.IO.Directory.Exists(dir)) return;
|
||||||
|
TryOpenFolder(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TryOpenFolder(string dir)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (OperatingSystem.IsWindows())
|
||||||
|
{
|
||||||
|
var psi = new System.Diagnostics.ProcessStartInfo("explorer.exe", dir)
|
||||||
|
{
|
||||||
|
UseShellExecute = true
|
||||||
|
};
|
||||||
|
System.Diagnostics.Process.Start(psi);
|
||||||
|
}
|
||||||
|
else if (OperatingSystem.IsMacOS())
|
||||||
|
{
|
||||||
|
System.Diagnostics.Process.Start("open", dir);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Linux
|
||||||
|
System.Diagnostics.Process.Start("xdg-open", dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var psi = new System.Diagnostics.ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = dir,
|
||||||
|
UseShellExecute = true
|
||||||
|
};
|
||||||
|
System.Diagnostics.Process.Start(psi);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user