Skip to content

Commit

Permalink
Fix so Errors / Syntax Errors dialogs can only be opened by supported…
Browse files Browse the repository at this point in the history
… contexts
  • Loading branch information
halvarsson committed Apr 27, 2024
1 parent 750304f commit dd82c73
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions EditorContext/EditorContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public abstract class EditorContext
public bool CanFormat = false;
public bool CanAutocomplete = false;
public bool CanRun = false;
public bool CanSyntaxHighlight = false;
public ConcurrentDictionary<Point, string> Errors = new ConcurrentDictionary<Point, string>();
public ConcurrentDictionary<Point, string> ColumnErrors = new ConcurrentDictionary<Point, string>();
public Dictionary<Point, Terminal.Gui.Color> pointColorDict = new Dictionary<Point, Terminal.Gui.Color>();
Expand Down
1 change: 1 addition & 0 deletions EditorContext/JSONEditorContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public JSONEditorContext(int TabWidth)
{
_tabWidth = TabWidth;
CanFormat = true;
CanSyntaxHighlight = true;
}
public Terminal.Gui.Color GetColor(JsonToken token)
{
Expand Down
3 changes: 2 additions & 1 deletion EditorContext/PowerShellEditorContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public PowerShellEditorContext(int TabWidth, Runspace Runspace)

CanAutocomplete = true;
CanRun = true;

CanSyntaxHighlight = true;

// verify that psscriptanalyzer is available for formatting
using (var powerShell = PowerShell.Create(RunspaceMode.CurrentRunspace))
{
Expand Down
3 changes: 3 additions & 0 deletions EditorTextView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class EditorTextView : TextView
private EditorContext editorContext;
public bool CanFormat = false;
public bool CanRun = false;
public bool CanSyntaxHighlight = false;
public LanguageEnum _language = LanguageEnum.Powershell;
public EditorTextView(Runspace runspace)
{
Expand Down Expand Up @@ -51,11 +52,13 @@ public void SetLanguage(LanguageEnum language)
{
CanFormat = editorContext.CanFormat;
CanRun = editorContext.CanRun;
CanSyntaxHighlight = editorContext.CanSyntaxHighlight;
}
else
{
CanFormat = false;
CanRun = false;
CanSyntaxHighlight = false;
}
}
public void Format()
Expand Down
4 changes: 2 additions & 2 deletions ShowEditorCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ protected override void ProcessRecord()
}),
new MenuBarItem("_View", new []
{
new MenuItem("Errors", "", () => ErrorDialog.Show(_runspace)),
new MenuItem("Syntax Errors", "", () => SyntaxErrorDialog.Show(textEditor.Errors)),
new MenuItem("Errors", "", () => { if (textEditor._language == LanguageEnum.Powershell) ErrorDialog.Show(_runspace); }),
new MenuItem("Syntax Errors", "", () => { if (textEditor.CanSyntaxHighlight) SyntaxErrorDialog.Show(textEditor.Errors); }),
//new MenuItem("History", "", () => HistoryDialog.Show(_runspace))
}),
new MenuBarItem("_Debug", new []
Expand Down

0 comments on commit dd82c73

Please sign in to comment.