@@ -26,7 +26,7 @@ namespace TerminalGuiDesigner.UI;
2626/// application. Hooks key and mouse events and mounts as a sub-view whatever file
2727/// the user opens.
2828/// </summary>
29- public class Editor : Toplevel
29+ public class Editor : Toplevel , IErrorReporter
3030{
3131 private KeyMap keyMap ;
3232 private readonly KeyboardManager keyboardManager ;
@@ -61,6 +61,11 @@ public class Editor : Toplevel
6161 /// </summary>
6262 public static bool Quiet = false ;
6363
64+ /// <summary>
65+ /// Start your message with this if you want it to be visually highlighted as bad.
66+ /// </summary>
67+ public const string Error = "Error" ;
68+
6469 /// <summary>
6570 /// Initializes a new instance of the <see cref="Editor"/> class.
6671 /// </summary>
@@ -77,7 +82,10 @@ public Editor()
7782 LoadKeyMap ( ) ;
7883
7984 this . keyboardManager = new KeyboardManager ( this . keyMap ) ;
80- this . mouseManager = new MouseManager ( ) ;
85+ this . mouseManager = new MouseManager ( )
86+ {
87+ ErrorReporter = this
88+ } ;
8189 this . Closing += this . Editor_Closing ;
8290
8391 this . BuildRootMenu ( ) ;
@@ -293,6 +301,13 @@ protected override void OnDrawComplete(DrawContext? context)
293301 // and have a designable view focused
294302 if ( toDisplay != null )
295303 {
304+ var before = GetCurrentAttribute ( ) ;
305+
306+ if ( toDisplay . StartsWith ( Error ) )
307+ {
308+ SetAttribute ( new Attribute ( Color . Red , Color . Black ) ) ;
309+ }
310+
296311 // write its name in the lower right
297312 int y = this . GetContentSize ( ) . Height - 1 ;
298313 int right = bounds . Width - 1 ;
@@ -303,6 +318,8 @@ protected override void OnDrawComplete(DrawContext? context)
303318 {
304319 this . AddRune ( right - len + i , y , runes [ i ] ) ;
305320 }
321+
322+ SetAttribute ( before ) ;
306323 }
307324 }
308325
@@ -1151,10 +1168,31 @@ private void Delete()
11511168 if ( SelectionManager . Instance . Selected . Any ( ) )
11521169 {
11531170 var cmd = new DeleteViewOperation ( SelectionManager . Instance . Selected . ToArray ( ) ) ;
1171+
1172+
1173+ if ( cmd . IsImpossible && cmd . PreventDeleting . Any ( ) )
1174+ {
1175+ ShowErrorThatViewIsUsedByOthers ( cmd . PreventDeleting ) ;
1176+ return ;
1177+ }
1178+
11541179 OperationManager . Instance . Do ( cmd ) ;
11551180 }
11561181 }
11571182
1183+ public void ShowErrorThatViewIsUsedByOthers ( Design [ ] usedBy )
1184+ {
1185+ if ( usedBy . Length == 1 )
1186+ {
1187+ flashMessage = $ "{ Error } , view referenced by " + usedBy [ 0 ] . FieldName ;
1188+ }
1189+ else
1190+ {
1191+ flashMessage = $ "{ Error } , view referenced by { usedBy . Length } views";
1192+ }
1193+ this . SetNeedsDraw ( ) ;
1194+ }
1195+
11581196 private void DoForSelectedViews ( Func < Design , Operation > operationFunc , bool allowOnRoot = false )
11591197 {
11601198 if ( this . viewBeingEdited == null )
@@ -1469,4 +1507,4 @@ private void ShowEditProperties(Design d)
14691507 var edit = new EditDialog ( d ) ;
14701508 Application . Run ( edit , this . ErrorHandler ) ;
14711509 }
1472- }
1510+ }
0 commit comments