11 Commits

5 changed files with 144 additions and 19 deletions
+6 -2
View File
@@ -327,8 +327,12 @@
<Grid ColumnDefinitions="300,*">
<Border Grid.Column="0" Background="#FFF" BorderBrush="#DDD" BorderThickness="0,0,1,0">
<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" />
<Button Content="+ Ordner" x:Name="BtnWikiAddFolder"
Click="BtnWikiAddFolder_OnClick" />
</StackPanel>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<TreeView Name="NavTree" Margin="10" />
</ScrollViewer>
@@ -505,7 +509,7 @@
VerticalContentAlignment="Center" />
</StackPanel>
</Button>
<Button Background="#99963434" HorizontalAlignment="Stretch"
<Button Background="#99963434" HorizontalAlignment="Stretch" x:Name="BtnDeleteCustomer" Click="BtnDeleteCustomer_OnClick"
HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<LucideIcon Kind="Trash" Width="16" Height="16" Size="16" />
+120 -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 nodes = new List<TreeViewItem>();
foreach (var r in roots) nodes.Add(BuildNode(r));
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)
@@ -278,6 +286,63 @@ public partial class MainWindow : Window
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)
{
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)
{
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
{
File.WriteAllText(Path.Combine(Global._instance.wiki_storage_path, result), "");
PopulateNavTree();
var targetDirectory = GetSelectedWikiTargetDirectory();
Directory.CreateDirectory(targetDirectory);
var newFilePath = Path.Combine(targetDirectory, result);
File.WriteAllText(newFilePath, "");
PopulateNavTree(targetDirectory, newFilePath);
}
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)
{
if (LstCustomerAdressSets.SelectedItems.Count > 0)
@@ -1029,4 +1128,21 @@ public partial class MainWindow : Window
MessageBox.Show(this, ex.StackTrace, "Fehler");
}
}
private void BtnDeleteCustomer_OnClick(object? sender, RoutedEventArgs e)
{
if (LstSettingsCustomers.SelectedIndex == null || LstSettingsCustomers.SelectedIndex == -1) return;
foreach (var customer in Settings._instance.customers.customers)
if (customer.ID == Settings._instance.customers.current)
try
{
Settings._instance.customers.customers.Remove(customer);
break;
}
catch (Exception ex)
{
MessageBox.Show(this, "Unknown Error: " + ex.Message, "Error");
}
RefreshCustomerItems();
}
}
+2 -1
View File
@@ -37,7 +37,8 @@ public class CombineAddresses
/// <returns></returns>
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 (first.name == second.name &&
first.anrede == second.anrede &&
+3 -3
View File
@@ -2,16 +2,16 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Logof_Client.Wiki.EditorWindow"
Title="Wiki Editor" MinWidth="600" MinHeight="350" WindowState="Maximized">
<Grid>
<Grid Margin="10,0,10,10">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<StackPanel Grid.Row="0" Spacing="10" Orientation="Horizontal">
<Button x:Name="BtnSave" Content="Speichern" Click="BtnSave_OnClick" />
<Button x:Name="BtnSaveAs" Content="Speichern unter..." Click="BtnSaveAs_OnClick" />
<Button x:Name="BtnDelete" Content="Löschen" Click="BtnDelete_OnClick" />
</StackPanel>
<TextBox Grid.Row="1" x:Name="TbContent" />
<TextBox AcceptsTab="True" AcceptsReturn="True" Grid.Row="1" x:Name="TbContent" />
</Grid>
</Window>
+4
View File
@@ -52,7 +52,11 @@ public partial class EditorWindow : Window
{
var result = await MessageBox.Show(null, "Sicher?", "Sicher?", MessageBoxButton.YesNo);
if (result == MessageBoxResult.No) return;
try
{
File.Delete(filename);
} catch {}
MainWindow._instance.PopulateNavTree();
Close();
}