[feat:] implemented a basic editor for the wiki
This commit is contained in:
@@ -19,6 +19,7 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
private WikiService _wikiService;
|
private WikiService _wikiService;
|
||||||
public Uri filePath;
|
public Uri filePath;
|
||||||
|
private string _selectedWikiFilePath;
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
@@ -230,6 +231,7 @@ public partial class MainWindow : Window
|
|||||||
{
|
{
|
||||||
if (NavTree.SelectedItem is TreeViewItem t && t.Tag is WikiItem item && !item.IsFolder)
|
if (NavTree.SelectedItem is TreeViewItem t && t.Tag is WikiItem item && !item.IsFolder)
|
||||||
{
|
{
|
||||||
|
_selectedWikiFilePath = item.Path;
|
||||||
var text = await _wikiService.LoadFileContentAsync(item.Path);
|
var text = await _wikiService.LoadFileContentAsync(item.Path);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -246,9 +248,14 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
EditButton.IsEnabled = true;
|
EditButton.IsEnabled = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_selectedWikiFilePath = null;
|
||||||
|
EditButton.IsEnabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PopulateNavTree()
|
public void PopulateNavTree()
|
||||||
{
|
{
|
||||||
var roots = _wikiService.GetRootItems();
|
var roots = _wikiService.GetRootItems();
|
||||||
var nodes = new List<TreeViewItem>();
|
var nodes = new List<TreeViewItem>();
|
||||||
@@ -446,7 +453,16 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
private async void EditButton_Click(object? sender, RoutedEventArgs e)
|
private async void EditButton_Click(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
await MessageBox.Show(this, "Edit feature is currently disabled.", "Edit Disabled");
|
if (string.IsNullOrWhiteSpace(_selectedWikiFilePath))
|
||||||
|
{
|
||||||
|
await MessageBox.Show(this, "Bitte wählen Sie zunächst eine Wiki-Datei aus.", "Keine Datei ausgewählt");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorWindow ew = new(_selectedWikiFilePath);
|
||||||
|
ew.Show();
|
||||||
|
|
||||||
|
//await MessageBox.Show(this, "Edit feature is currently disabled.", "Edit Disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshCustomerItems(int index = 0)
|
public void RefreshCustomerItems(int index = 0)
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
<Window xmlns="https://github.com/avaloniaui"
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
x:Class="Logof_Client.Wiki.EditorWindow"
|
x:Class="Logof_Client.Wiki.EditorWindow"
|
||||||
Title="Wiki Editor (disabled)" Width="400" Height="150">
|
Title="Wiki Editor" MinWidth="600" MinHeight="350" WindowState="Maximized">
|
||||||
<Grid>
|
<Grid>
|
||||||
<TextBlock Margin="12" TextWrapping="Wrap">Coming soon.</TextBlock>
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="50" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<StackPanel Grid.Row="0" 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" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
@@ -1,17 +1,59 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
|
||||||
namespace Logof_Client.Wiki;
|
namespace Logof_Client.Wiki;
|
||||||
|
|
||||||
public partial class EditorWindow : Window
|
public partial class EditorWindow : Window
|
||||||
{
|
{
|
||||||
private void InitializeComponent()
|
public string filename = "";
|
||||||
{
|
|
||||||
Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public EditorWindow()
|
public EditorWindow(string filename = "")
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
this.filename = filename;
|
||||||
|
if (!string.IsNullOrWhiteSpace(filename) && File.Exists(filename))
|
||||||
|
{
|
||||||
|
var content = TbContent;
|
||||||
|
if (content != null) content.Text = File.ReadAllText(this.filename);
|
||||||
|
Title = "Wiki Editor - " + filename;
|
||||||
|
}
|
||||||
|
else if (!string.IsNullOrWhiteSpace(filename))
|
||||||
|
{
|
||||||
|
MessageBox.Show(null, "Die Datei existiert nicht", "Fehler");
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BtnSave_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.WriteAllText(filename, TbContent.Text);
|
||||||
|
MainWindow._instance.PopulateNavTree();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(null,
|
||||||
|
"Es ist ein Fehler aufgetreten. Bitte senden Sie ihn über git.mypapercloud.de/fierke/logofclient ein:\n" +
|
||||||
|
ex.StackTrace, "Fehler");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BtnSaveAs_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
MessageBox.Show(null,
|
||||||
|
"Feature noch nicht implemetiert.\nErstelle neue Dateien unter " + Global._instance.wiki_storage_path,
|
||||||
|
"Fehler");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void BtnDelete_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var result = await MessageBox.Show(null, "Sicher?", "Sicher?", MessageBoxButton.YesNo);
|
||||||
|
if (result == MessageBoxResult.No) return;
|
||||||
|
File.Delete(filename);
|
||||||
|
MainWindow._instance.PopulateNavTree();
|
||||||
|
Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user