Browse Source

Implemented send buttons

CPKreuz 3 years ago
parent
commit
a77f098fe2

+ 2 - 2
PixiEditor/Views/Dialogs/CrashReportDialog.xaml

@@ -13,8 +13,8 @@
         Width="480" Height="180">
 
     <WindowChrome.WindowChrome>
-        <WindowChrome CaptionHeight="35"  GlassFrameThickness="0.1"
-                      ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}"/>
+        <WindowChrome CaptionHeight="32" GlassFrameThickness="0.1"
+                      ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
     </WindowChrome.WindowChrome>
 
     <Window.CommandBindings>

+ 0 - 2
PixiEditor/Views/Dialogs/CrashReportDialog.xaml.cs

@@ -21,11 +21,9 @@ namespace PixiEditor.Views.Dialogs
             e.CanExecute = true;
         }
 
-
         private void CommandBinding_Executed_Close(object sender, ExecutedRoutedEventArgs e)
         {
             SystemCommands.CloseWindow(this);
         }
-
     }
 }

+ 11 - 7
PixiEditor/Views/Dialogs/SendCrashReportWindow.xaml

@@ -20,10 +20,15 @@
     </Window.Resources>
 
     <WindowChrome.WindowChrome>
-        <WindowChrome CaptionHeight="35"  GlassFrameThickness="0.1"
-                      ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}"/>
+        <WindowChrome CaptionHeight="32"  GlassFrameThickness="0.1"
+                      ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
     </WindowChrome.WindowChrome>
 
+    <Window.CommandBindings>
+        <CommandBinding Command="{x:Static SystemCommands.CloseWindowCommand}" CanExecute="CommandBinding_CanExecute"
+                        Executed="CommandBinding_Executed_Close" />
+    </Window.CommandBindings>
+
     <StackPanel>
         <dial:DialogTitleBar TitleText="Send crash report" CloseCommand="{x:Static SystemCommands.CloseWindowCommand}" />
         <StackPanel Margin="10">
@@ -34,12 +39,11 @@
             </StackPanel>
             <TextBlock TextAlignment="Center">You can report your crash report here:</TextBlock>
             <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
-                <Button Click="OpenHyperlink" Tag="">GitHub</Button>
-                <Button Click="OpenHyperlink" Tag="">Discord</Button>
-                <Button Click="OpenHyperlink" Tag="">E-Mail</Button>
+                <Button Click="OpenHyperlink" Tag="github">GitHub</Button>
+                <Button Click="OpenHyperlink" Tag="discord">Discord</Button>
+                <Button Click="OpenHyperlink" Tag="email">E-Mail</Button>
             </StackPanel>
-            <TextBlock TextAlignment="Center" FontSize="8"
-                       TextWrapping="Wrap" Foreground="#DDD">The report contains all documents that were opened when the crash happenend</TextBlock>
+            <TextBlock TextWrapping="Wrap" FontSize="8">The report might contain the doucments that were opened when the crash happened</TextBlock>
         </StackPanel>
     </StackPanel>
 </Window>

+ 67 - 11
PixiEditor/Views/Dialogs/SendCrashReportWindow.xaml.cs

@@ -1,18 +1,12 @@
 using PixiEditor.Helpers;
 using PixiEditor.Models.DataHolders;
 using System;
-using System.Collections.Generic;
-using System.Linq;
+using System.IO;
 using System.Text;
-using System.Threading.Tasks;
+using System.Web;
 using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
 using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Shapes;
 
 namespace PixiEditor.Views.Dialogs
 {
@@ -21,6 +15,8 @@ namespace PixiEditor.Views.Dialogs
     /// </summary>
     public partial class SendCrashReportWindow : Window
     {
+        const string DiscordInviteLink = "https://discord.gg/eh8gx6vNEp";
+
         private readonly CrashReport report;
 
         public SendCrashReportWindow(CrashReport report)
@@ -29,6 +25,16 @@ namespace PixiEditor.Views.Dialogs
             InitializeComponent();
         }
 
+        private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
+        {
+            e.CanExecute = true;
+        }
+
+        private void CommandBinding_Executed_Close(object sender, ExecutedRoutedEventArgs e)
+        {
+            SystemCommands.CloseWindow(this);
+        }
+
         private void CopyToClipboard(object sender, RoutedEventArgs e)
         {
             Clipboard.SetFileDropList(new() { report.FilePath });
@@ -36,15 +42,65 @@ namespace PixiEditor.Views.Dialogs
 
         private void OpenInExplorer(object sender, RoutedEventArgs e)
         {
-            ProcessHelpers.ShellExecute(report.FilePath);
+            string tempPath = Path.Combine(
+                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
+                "PixiEditor",
+                "crash_logs",
+                "to-copy");
+
+            DirectoryInfo info = Directory.CreateDirectory(tempPath);
+
+            foreach (var file in info.EnumerateFiles())
+            {
+                file.Delete();
+            }
+
+            File.Copy(report.FilePath, Path.Combine(tempPath, Path.GetFileName(report.FilePath)), true);
+
+            ProcessHelpers.ShellExecute(tempPath);
         }
 
         private void OpenHyperlink(object sender, RoutedEventArgs e)
         {
             var button = sender as Button;
+            var tag = button.Tag as string;
+
+            string body = HttpUtility.UrlEncode($"** IMPORTANT: Drop the \"{Path.GetFileName(report.FilePath)}\" file in here **");
+
+            var result = tag switch
+            {
+                "github" => GetGitHubLink(),
+                "discord" => DiscordInviteLink,
+                "email" => GetMailtoLink(),
+                _ => throw new NotImplementedException()
+            };
+
+            OpenInExplorer(null, null);
+            ProcessHelpers.ShellExecute(result);
+
+            string GetGitHubLink()
+            {
+                StringBuilder builder = new();
+
+                builder.Append("https://github.com/PixiEditor/PixiEditor/issues/new?title=");
+                builder.Append(HttpUtility.UrlEncode($"Crash Report"));
+                builder.Append("&body=");
+                builder.Append(body);
+
+                return builder.ToString();
+            }
+
+            string GetMailtoLink()
+            {
+                StringBuilder builder = new();
+
+                builder.Append("mailto:[email protected]?subject=");
+                builder.Append(HttpUtility.UrlEncode($"Crash Report"));
+                builder.Append("&body=");
+                builder.Append(body);
 
-            CopyToClipboard(null, null);
-            ProcessHelpers.ShellExecute(button.Tag as string);
+                return builder.ToString();
+            }
         }
     }
 }