3 Commits

3 changed files with 118 additions and 14 deletions
+5 -1
View File
@@ -327,8 +327,12 @@
<Grid ColumnDefinitions="300,*"> <Grid ColumnDefinitions="300,*">
<Border Grid.Column="0" Background="#FFF" BorderBrush="#DDD" BorderThickness="0,0,1,0"> <Border Grid.Column="0" Background="#FFF" BorderBrush="#DDD" BorderThickness="0,0,1,0">
<StackPanel> <StackPanel>
<Button Content="+ Hinzufügen" Margin="10" x:Name="BtnWikiAddFile" <StackPanel Spacing="10" Orientation="Horizontal" Margin="10">
<Button Content="+ Datei" x:Name="BtnWikiAddFile"
Click="BtnWikiAddFile_OnClick" /> Click="BtnWikiAddFile_OnClick" />
<Button Content="+ Ordner" x:Name="BtnWikiAddFolder"
Click="BtnWikiAddFolder_OnClick" />
</StackPanel>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<TreeView Name="NavTree" Margin="10" /> <TreeView Name="NavTree" Margin="10" />
</ScrollViewer> </ScrollViewer>
+103 -4
View File
@@ -260,12 +260,20 @@ public partial class MainWindow : Window
} }
} }
public void PopulateNavTree() public void PopulateNavTree(string? expandToPath = null, string? selectPath = null)
{ {
var roots = _wikiService.GetRootItems(); var roots = _wikiService.GetRootItems();
var nodes = new List<TreeViewItem>(); var nodes = new List<TreeViewItem>();
foreach (var r in roots) nodes.Add(BuildNode(r)); foreach (var r in roots) nodes.Add(BuildNode(r));
NavTree.ItemsSource = nodes; NavTree.ItemsSource = nodes;
if (!string.IsNullOrWhiteSpace(expandToPath))
ExpandAndFindNode(nodes, expandToPath, out _);
if (!string.IsNullOrWhiteSpace(selectPath) &&
ExpandAndFindNode(nodes, selectPath, out var selectedNode) &&
selectedNode != null)
NavTree.SelectedItem = selectedNode;
} }
private TreeViewItem BuildNode(WikiItem item) private TreeViewItem BuildNode(WikiItem item)
@@ -278,6 +286,63 @@ public partial class MainWindow : Window
return node; return node;
} }
private string GetSelectedWikiTargetDirectory()
{
var wikiRoot = Global._instance.wiki_storage_path;
if (NavTree.SelectedItem is TreeViewItem treeItem && treeItem.Tag is WikiItem selectedItem)
{
if (selectedItem.IsFolder) return selectedItem.Path;
var parentDir = Path.GetDirectoryName(selectedItem.Path);
if (!string.IsNullOrWhiteSpace(parentDir)) return parentDir;
}
return wikiRoot;
}
private static bool PathsEqual(string left, string right)
{
var normalizedLeft = Path.GetFullPath(left)
.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
var normalizedRight = Path.GetFullPath(right)
.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
var comparison = OperatingSystem.IsWindows()
? StringComparison.OrdinalIgnoreCase
: StringComparison.Ordinal;
return string.Equals(normalizedLeft, normalizedRight, comparison);
}
private bool ExpandAndFindNode(IEnumerable<TreeViewItem> nodes, string targetPath, out TreeViewItem? foundNode)
{
foreach (var node in nodes)
if (TryExpandToPath(node, targetPath, out foundNode))
return true;
foundNode = null;
return false;
}
private bool TryExpandToPath(TreeViewItem node, string targetPath, out TreeViewItem? foundNode)
{
if (node.Tag is WikiItem item && PathsEqual(item.Path, targetPath))
{
foundNode = node;
return true;
}
foreach (var childRaw in node.Items)
if (childRaw is TreeViewItem childNode &&
TryExpandToPath(childNode, targetPath, out foundNode))
{
node.IsExpanded = true;
return true;
}
foundNode = null;
return false;
}
private void OpenFolderButton_Click(object? sender, RoutedEventArgs e) private void OpenFolderButton_Click(object? sender, RoutedEventArgs e)
{ {
var path = Global._instance.wiki_storage_path; var path = Global._instance.wiki_storage_path;
@@ -991,11 +1056,21 @@ public partial class MainWindow : Window
private async void BtnWikiAddFile_OnClick(object? sender, RoutedEventArgs e) private async void BtnWikiAddFile_OnClick(object? sender, RoutedEventArgs e)
{ {
var result = await NamingWindow.Show(this); var result = await NamingWindow.Show(this);
if (result != null) if (string.IsNullOrWhiteSpace(result)) return;
result = result.Trim();
if (!result.EndsWith(".md", StringComparison.OrdinalIgnoreCase)) result += ".md";
if (!Directory.Exists(Global._instance.wiki_storage_path))
Directory.CreateDirectory(Global._instance.wiki_storage_path);
try try
{ {
File.WriteAllText(Path.Combine(Global._instance.wiki_storage_path, result), ""); var targetDirectory = GetSelectedWikiTargetDirectory();
PopulateNavTree(); Directory.CreateDirectory(targetDirectory);
var newFilePath = Path.Combine(targetDirectory, result);
File.WriteAllText(newFilePath, "");
PopulateNavTree(targetDirectory, newFilePath);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -1003,6 +1078,30 @@ public partial class MainWindow : Window
} }
} }
private async void BtnWikiAddFolder_OnClick(object? sender, RoutedEventArgs e)
{
var result = await NamingWindow.Show(this);
if (string.IsNullOrWhiteSpace(result)) return;
result = result.Trim();
if (!Directory.Exists(Global._instance.wiki_storage_path))
Directory.CreateDirectory(Global._instance.wiki_storage_path);
try
{
var targetDirectory = GetSelectedWikiTargetDirectory();
var newFolderPath = Path.Combine(targetDirectory, result);
Directory.CreateDirectory(newFolderPath);
PopulateNavTree(targetDirectory, newFolderPath);
}
catch (Exception ex)
{
MessageBox.Show(this, ex.StackTrace, "Fehler");
}
}
private async void MnIAdSetRename_OnClick(object? sender, RoutedEventArgs e) private async void MnIAdSetRename_OnClick(object? sender, RoutedEventArgs e)
{ {
if (LstCustomerAdressSets.SelectedItems.Count > 0) if (LstCustomerAdressSets.SelectedItems.Count > 0)
+2 -1
View File
@@ -37,7 +37,8 @@ public class CombineAddresses
/// <returns></returns> /// <returns></returns>
public bool CompareAddresses(KasPerson first, KasPerson second, bool only_refsid = false) public bool CompareAddresses(KasPerson first, KasPerson second, bool only_refsid = false)
{ {
if (first.refsid == second.refsid) return true; // A refsid of 0 means "missing", so it must not collapse unrelated entries.
if (first.refsid != 0 && second.refsid != 0 && first.refsid == second.refsid) return true;
if (!only_refsid) if (!only_refsid)
if (first.name == second.name && if (first.name == second.name &&
first.anrede == second.anrede && first.anrede == second.anrede &&