|
1 | | -using System.IO; |
| 1 | +using System; |
| 2 | +using System.IO; |
2 | 3 | using System.Threading.Tasks; |
3 | 4 | using System.Windows; |
4 | 5 | using System.Windows.Controls; |
5 | 6 | using System.Windows.Input; |
| 7 | +using MahApps.Metro.Controls.Dialogs; |
6 | 8 | using SPCode.Interop; |
7 | 9 | using SPCode.UI.Components; |
8 | 10 | using SPCode.Utils; |
| 11 | +using static SPCode.Interop.TranslationProvider; |
9 | 12 |
|
10 | 13 | namespace SPCode.UI |
11 | 14 | { |
12 | 15 | public partial class MainWindow |
13 | 16 | { |
14 | 17 | private async void ErrorResultGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) |
15 | 18 | { |
16 | | - var row = (ErrorDataGridRow)ErrorResultGrid.SelectedItem; |
17 | | - if (row == null) |
| 19 | + try |
18 | 20 | { |
19 | | - return; |
20 | | - } |
21 | | - |
22 | | - var editors = GetAllEditorElements(); |
23 | | - if (editors == null) |
24 | | - { |
25 | | - return; |
26 | | - } |
| 21 | + var row = (ErrorDataGridRow)ErrorResultGrid.SelectedItem; |
| 22 | + if (row == null) |
| 23 | + { |
| 24 | + return; |
| 25 | + } |
27 | 26 |
|
28 | | - // Create a file info with the supplied file |
29 | | - var fileName = row.File; |
30 | | - var fInfo = new FileInfo(fileName); |
| 27 | + var editors = GetAllEditorElements(); |
| 28 | + if (editors == null) |
| 29 | + { |
| 30 | + return; |
| 31 | + } |
31 | 32 |
|
32 | | - // If it doesn't exist, it's probably a local file relative to one of the scripts being compiled |
33 | | - if (!fInfo.Exists) |
34 | | - { |
35 | | - var exists = false; |
| 33 | + // Create a file info with the supplied file |
| 34 | + var fileName = row.File; |
| 35 | + var fInfo = new FileInfo(fileName); |
36 | 36 |
|
37 | | - // We're gonna search for the file containing the error |
38 | | - // inside every compiled scripts location |
39 | | - foreach (var script in ScriptsCompiled) |
| 37 | + // If it doesn't exist, it's probably a local file relative to one of the scripts being compiled |
| 38 | + if (!fInfo.Exists) |
40 | 39 | { |
41 | | - var scriptDirInfo = Path.GetDirectoryName(script); |
42 | | - fInfo = new FileInfo(scriptDirInfo + Path.DirectorySeparatorChar + fileName); |
43 | | - if (fInfo.Exists) |
| 40 | + var exists = false; |
| 41 | + |
| 42 | + // We're gonna search for the file containing the error |
| 43 | + // inside every compiled scripts location |
| 44 | + foreach (var script in ScriptsCompiled) |
| 45 | + { |
| 46 | + var scriptDirInfo = Path.GetDirectoryName(script); |
| 47 | + fInfo = new FileInfo(scriptDirInfo + Path.DirectorySeparatorChar + fileName); |
| 48 | + if (fInfo.Exists) |
| 49 | + { |
| 50 | + exists = true; |
| 51 | + break; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + if (!exists) |
44 | 56 | { |
45 | | - exists = true; |
46 | | - break; |
| 57 | + LoggingControl.LogAction($"Failed to select {fInfo.Name}:{row.Line} - unable to find file.", 2); |
| 58 | + return; |
47 | 59 | } |
48 | 60 | } |
49 | 61 |
|
50 | | - if (!exists) |
| 62 | + // Look for the file that has the error among those that are open |
| 63 | + foreach (var ed in editors) |
51 | 64 | { |
52 | | - LoggingControl.LogAction($"Failed to select {fInfo.Name}:{row.Line} - unable to find file.", 2); |
53 | | - return; |
| 65 | + if (ed.FullFilePath == fInfo.FullName) |
| 66 | + { |
| 67 | + await Task.Delay(50); |
| 68 | + GoToErrorLine(ed, row); |
| 69 | + } |
54 | 70 | } |
55 | | - } |
56 | 71 |
|
57 | | - // Look for the file that has the error among those that are open |
58 | | - foreach (var ed in editors) |
59 | | - { |
60 | | - if (ed.FullFilePath == fInfo.FullName) |
| 72 | + // If it's not opened, open it and go to the error line |
| 73 | + if (TryLoadSourceFile(fInfo.FullName, out var editor, true, false, true) && editor != null) |
61 | 74 | { |
62 | 75 | await Task.Delay(50); |
63 | | - GoToErrorLine(ed, row); |
| 76 | + GoToErrorLine(editor, row); |
64 | 77 | } |
65 | 78 | } |
66 | | - |
67 | | - // If it's not opened, open it and go to the error line |
68 | | - if (TryLoadSourceFile(fInfo.FullName, out var editor, true, false, true) && editor != null) |
| 79 | + catch (UnauthorizedAccessException ex) |
| 80 | + { |
| 81 | + await this.ShowMessageAsync(Translate("Error"), Translate("PermissionAccessError"), settings: MetroDialogOptions); |
| 82 | + } |
| 83 | + catch (Exception ex) |
69 | 84 | { |
70 | | - await Task.Delay(50); |
71 | | - GoToErrorLine(editor, row); |
| 85 | + LoggingControl.LogAction($"Could not go to error! {ex.Message}"); |
72 | 86 | } |
73 | 87 | } |
74 | 88 |
|
|
0 commit comments