Skip to content

Commit 4e7d407

Browse files
committed
Extract editor settings
1 parent 3d9b899 commit 4e7d407

File tree

10 files changed

+195
-107
lines changed

10 files changed

+195
-107
lines changed

Examples/Nodify.MinimalExample/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<Application.Resources>
77
<ResourceDictionary>
88
<ResourceDictionary.MergedDictionaries>
9-
<nodifier:NodifyLoader />
109
<ResourceDictionary Source="pack://application:,,,/Nodify;component/Themes/Dark.xaml" />
10+
<nodifier:NodifyLoader />
1111
<ResourceDictionary>
1212
<Style TargetType="CheckBox" BasedOn="{StaticResource {x:Type CheckBox}}">
1313
<Style.Setters>

Examples/Nodify.MinimalExample/MinimalApp.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public CustomGraphNode(IGraph graph) : base(graph)
3333

3434
public class MinimalApp
3535
{
36-
public Graph Graph { get; } = new Graph();
36+
public GraphEditor Graph { get; } = new GraphEditor();
3737
private static readonly Random _random = new Random();
3838

3939
public MinimalApp()
@@ -122,7 +122,14 @@ public void AlignSelection()
122122

123123
public void AddComment()
124124
{
125-
Graph.AddComment("This is a comment sorounding all nodes", Graph.Elements);
125+
if (Graph.SelectedElements.Count > 0)
126+
{
127+
Graph.AddComment(string.Empty, Graph.SelectedElements);
128+
}
129+
else
130+
{
131+
Graph.AddComment("This is a comment sorounding all nodes", Graph.Elements);
132+
}
126133
}
127134

128135
public void FocusRandomNode()

Examples/Nodify.MinimalExample/Toolkit/BlueprintGraph.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public interface IBlueprintGraph : IGraph
88
void Disconnect(IGraphNode node);
99
}
1010

11-
public class BlueprintGraph : Graph, IBlueprintGraph
11+
public class BlueprintGraph : GraphEditor, IBlueprintGraph
1212
{
1313
private readonly IPendingConnection _pendingConnection;
1414
public override IPendingConnection PendingConnection => _pendingConnection;
Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,82 @@
11
using Nodify;
2+
using Stylet;
23

34
namespace Nodifier
45
{
5-
public static class EditorSettings
6+
public interface IEditorSettings
67
{
8+
double MinViewportZoom { get; set; }
9+
double MaxViewportZoom { get; set; }
10+
11+
double GridSnapSize { get; set; }
12+
13+
bool DisableZooming { get; set; }
14+
bool DisablePanning { get; set; }
15+
bool DisableAutoPanning { get; set; }
16+
bool EnableRealtimeSelection { get; set; }
17+
bool ShowGridLines { get; set; }
18+
}
19+
20+
public class EditorSettings : PropertyChangedBase, IEditorSettings
21+
{
22+
private double _minViewportZoom = 0.1d;
23+
public double MinViewportZoom
24+
{
25+
get => _minViewportZoom;
26+
set => SetAndNotify(ref _minViewportZoom, value);
27+
}
28+
29+
private double _maxViewportZoom = 2d;
30+
public double MaxViewportZoom
31+
{
32+
get => _maxViewportZoom;
33+
set => SetAndNotify(ref _maxViewportZoom, value);
34+
}
35+
36+
private double _gridSnapSize;
37+
public double GridSnapSize
38+
{
39+
get => _gridSnapSize;
40+
set => SetAndNotify(ref _gridSnapSize, value);
41+
}
42+
43+
private bool _disableZooming;
44+
public bool DisableZooming
45+
{
46+
get => _disableZooming;
47+
set => SetAndNotify(ref _disableZooming, value);
48+
}
49+
50+
private bool _disablePanning;
51+
public bool DisablePanning
52+
{
53+
get => _disablePanning;
54+
set => SetAndNotify(ref _disablePanning, value);
55+
}
56+
57+
private bool _disableAutoPanning;
58+
public bool DisableAutoPanning
59+
{
60+
get => _disableAutoPanning;
61+
set => SetAndNotify(ref _disableAutoPanning, value);
62+
}
63+
64+
private bool _enableRealtimeSelection = true;
65+
public bool EnableRealtimeSelection
66+
{
67+
get => _enableRealtimeSelection;
68+
set => SetAndNotify(ref _enableRealtimeSelection, value);
69+
}
70+
71+
private bool _showGridLines = true;
72+
public bool ShowGridLines
73+
{
74+
get => _showGridLines;
75+
set => SetAndNotify(ref _showGridLines, value);
76+
}
77+
78+
#region Global Settings
79+
780
public static double HandleRightClickAfterPanningThreshold
881
{
982
get => NodifyEditor.HandleRightClickAfterPanningThreshold;
@@ -69,5 +142,7 @@ public static double OptimizeRenderingZoomOutPercent
69142
get => NodifyEditor.OptimizeRenderingZoomOutPercent;
70143
set => NodifyEditor.OptimizeRenderingZoomOutPercent = value;
71144
}
145+
146+
#endregion
72147
}
73148
}

Nodifier/Graph/Graph.Editor.cs

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public enum Alignment
1717
Center
1818
}
1919

20-
public partial class Graph : PropertyChangedBase, IEditor, IViewAware
20+
public partial class GraphEditor : PropertyChangedBase, IEditor, IViewAware
2121
{
2222
private NodifyEditor? _editor;
2323
protected NodifyEditor Editor => _editor ?? throw new InvalidOperationException($"No editor attached. Please implement {nameof(INodifyEditorAware)} in the view and wait for initialization.");
@@ -33,7 +33,8 @@ public partial class Graph : PropertyChangedBase, IEditor, IViewAware
3333
{ Alignment.Center, EditorCommands.Alignment.Center }
3434
};
3535

36-
public event EventHandler Initialized;
36+
public event EventHandler? Initialized;
37+
public IEditorSettings Settings { get; } = new EditorSettings();
3738

3839
private Point _viewportLocation;
3940
public Point ViewportLocation
@@ -56,55 +57,6 @@ public double ViewportZoom
5657
set => SetAndNotify(ref _viewportZoom, value);
5758
}
5859

59-
private double _minViewportZoom = 0.1d;
60-
public double MinViewportZoom
61-
{
62-
get => _minViewportZoom;
63-
set => SetAndNotify(ref _minViewportZoom, value);
64-
}
65-
66-
private double _maxViewportZoom = 2d;
67-
public double MaxViewportZoom
68-
{
69-
get => _maxViewportZoom;
70-
set => SetAndNotify(ref _maxViewportZoom, value);
71-
}
72-
73-
private double _gridSnapSize;
74-
public double GridSnapSize
75-
{
76-
get => _gridSnapSize;
77-
set => SetAndNotify(ref _gridSnapSize, value);
78-
}
79-
80-
private bool _disableZooming;
81-
public bool DisableZooming
82-
{
83-
get => _disableZooming;
84-
set => SetAndNotify(ref _disableZooming, value);
85-
}
86-
87-
private bool _disablePanning;
88-
public bool DisablePanning
89-
{
90-
get => _disablePanning;
91-
set => SetAndNotify(ref _disablePanning, value);
92-
}
93-
94-
private bool _disableAutoPanning;
95-
public bool DisableAutoPanning
96-
{
97-
get => _disableAutoPanning;
98-
set => SetAndNotify(ref _disableAutoPanning, value);
99-
}
100-
101-
private bool _enableRealtimeSelection = true;
102-
public bool EnableRealtimeSelection
103-
{
104-
get => _enableRealtimeSelection;
105-
set => SetAndNotify(ref _enableRealtimeSelection, value);
106-
}
107-
10860
void IViewAware.AttachView(UIElement view)
10961
{
11062
if (view is INodifyEditorAware editorAware)

Nodifier/Graph/Graph.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Nodifier
88
{
9-
public partial class Graph : IGraph
9+
public partial class GraphEditor : IGraph
1010
{
1111
protected readonly BindableCollection<IGraphElement> _elements = new BindableCollection<IGraphElement>();
1212
public IReadOnlyCollection<IGraphElement> Elements => _elements;
@@ -19,7 +19,7 @@ public partial class Graph : IGraph
1919

2020
public virtual IPendingConnection PendingConnection { get; }
2121

22-
public Graph()
22+
public GraphEditor()
2323
{
2424
PendingConnection = new PendingConnection(this);
2525
}

Nodifier/Graph/GraphExtensions.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ public static void FocusLocation(this IEditor graph, double x, double y)
1717
graph.FocusLocation(new Point(x, y));
1818
}
1919

20-
public static void AddComment(this IGraph graph, string text, IEnumerable<IGraphElement> nodes)
20+
public static CommentNode AddComment(this IGraph graph, string text, IEnumerable<IGraphElement> nodes)
2121
{
2222
var bounds = nodes.GetBoundingBox();
23-
graph.AddElement(new CommentNode(graph)
23+
var comment = new CommentNode(graph)
2424
{
2525
Location = bounds.Location,
2626
CommentSize = bounds.Size,
2727
Title = text
28-
});
28+
};
29+
graph.AddElement(comment);
30+
return comment;
2931
}
3032

3133
private static (Point Location, Size Size) GetBoundingBox(this IEnumerable<IGraphElement> nodes)

Nodifier/Graph/GraphView.xaml

Lines changed: 73 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,84 @@
99
xmlns:s="https://github.com/canton7/Stylet"
1010
mc:Ignorable="d"
1111
d:DesignHeight="450" d:DesignWidth="800"
12-
d:DataContext="{d:DesignInstance Type=vm:Graph, IsDesignTimeCreatable=False}">
13-
<nodify:NodifyEditor ItemsSource="{Binding Elements}"
12+
d:DataContext="{d:DesignInstance Type=vm:GraphEditor, IsDesignTimeCreatable=False}">
13+
<UserControl.Resources>
14+
<GeometryDrawing x:Key="SmallGridGeometry"
15+
Geometry="M0,0 L0,1 0.03,1 0.03,0.03 1,0.03 1,0 Z"
16+
Brush="{DynamicResource NodifyEditor.SelectionRectangleBackgroundBrush}" />
17+
18+
<GeometryDrawing x:Key="LargeGridGeometry"
19+
Geometry="M0,0 L0,1 0.015,1 0.015,0.015 1,0.015 1,0 Z"
20+
Brush="{DynamicResource NodifyEditor.SelectionRectangleBackgroundBrush}" />
21+
22+
<DrawingBrush x:Key="SmallGridLinesDrawingBrush"
23+
TileMode="Tile"
24+
ViewportUnits="Absolute"
25+
Viewport="0 0 20 20"
26+
Transform="{Binding ViewportTransform, ElementName=EditorInstance}"
27+
Drawing="{StaticResource SmallGridGeometry}" />
28+
29+
<DrawingBrush x:Key="LargeGridLinesDrawingBrush"
30+
TileMode="Tile"
31+
ViewportUnits="Absolute"
32+
Opacity="0.5"
33+
Viewport="0 0 100 100"
34+
Transform="{Binding ViewportTransform, ElementName=EditorInstance}"
35+
Drawing="{StaticResource LargeGridGeometry}" />
36+
</UserControl.Resources>
37+
38+
<Grid Background="{StaticResource NodifyEditor.BackgroundBrush}">
39+
<nodify:NodifyEditor ItemsSource="{Binding Elements}"
1440
SelectedItems="{Binding SelectedElements}"
1541
Connections="{Binding Connections}"
1642
PendingConnection="{Binding PendingConnection}"
1743
ViewportLocation="{Binding ViewportLocation}"
1844
ViewportSize="{Binding ViewportSize, Mode=OneWayToSource}"
1945
ViewportZoom="{Binding ViewportZoom}"
20-
DisablePanning="{Binding DisablePanning}"
21-
DisableZooming="{Binding DisableZooming}"
22-
DisableAutoPanning="{Binding DisableAutoPanning}"
23-
MinViewportZoom="{Binding MinViewportZoom}"
24-
MaxViewportZoom="{Binding MaxViewportZoom}"
25-
GridCellSize="{Binding GridSnapSize}"
26-
EnableRealtimeSelection="{Binding EnableRealtimeSelection}"
46+
DisablePanning="{Binding Settings.DisablePanning}"
47+
DisableZooming="{Binding Settings.DisableZooming}"
48+
DisableAutoPanning="{Binding Settings.DisableAutoPanning}"
49+
MinViewportZoom="{Binding Settings.MinViewportZoom}"
50+
MaxViewportZoom="{Binding Settings.MaxViewportZoom}"
51+
GridCellSize="{Binding Settings.GridSnapSize}"
52+
EnableRealtimeSelection="{Binding Settings.EnableRealtimeSelection}"
2753
x:Name="EditorInstance">
28-
<nodify:NodifyEditor.ItemContainerStyle>
29-
<Style TargetType="nodify:ItemContainer">
30-
<Setter Property="Location" Value="{Binding Location, Mode=TwoWay}" />
31-
<Setter Property="ActualSize" Value="{Binding Size, Mode=OneWayToSource}" />
32-
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
33-
<Setter Property="IsSelectable" Value="{Binding IsSelectable}" />
34-
<Setter Property="IsDraggable" Value="{Binding IsDraggable}" />
35-
</Style>
36-
</nodify:NodifyEditor.ItemContainerStyle>
37-
<nodify:NodifyEditor.ItemTemplate>
38-
<DataTemplate>
39-
<ContentControl s:View.Model="{Binding}" />
40-
</DataTemplate>
41-
</nodify:NodifyEditor.ItemTemplate>
42-
<nodify:NodifyEditor.PendingConnectionTemplate>
43-
<DataTemplate>
44-
<ContentControl s:View.Model="{Binding}" />
45-
</DataTemplate>
46-
</nodify:NodifyEditor.PendingConnectionTemplate>
47-
<nodify:NodifyEditor.ConnectionTemplate>
48-
<DataTemplate>
49-
<ContentControl s:View.Model="{Binding}" />
50-
</DataTemplate>
51-
</nodify:NodifyEditor.ConnectionTemplate>
52-
</nodify:NodifyEditor>
54+
<nodify:NodifyEditor.Style>
55+
<Style TargetType="{x:Type nodify:NodifyEditor}" BasedOn="{StaticResource {x:Type nodify:NodifyEditor}}">
56+
<Style.Triggers>
57+
<DataTrigger Binding="{Binding Settings.ShowGridLines}" Value="True">
58+
<Setter Property="Background" Value="{StaticResource SmallGridLinesDrawingBrush}" />
59+
</DataTrigger>
60+
</Style.Triggers>
61+
</Style>
62+
</nodify:NodifyEditor.Style>
63+
<nodify:NodifyEditor.ItemContainerStyle>
64+
<Style TargetType="nodify:ItemContainer">
65+
<Setter Property="Location" Value="{Binding Location, Mode=TwoWay}" />
66+
<Setter Property="ActualSize" Value="{Binding Size, Mode=OneWayToSource}" />
67+
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
68+
<Setter Property="IsSelectable" Value="{Binding IsSelectable}" />
69+
<Setter Property="IsDraggable" Value="{Binding IsDraggable}" />
70+
</Style>
71+
</nodify:NodifyEditor.ItemContainerStyle>
72+
<nodify:NodifyEditor.ItemTemplate>
73+
<DataTemplate>
74+
<ContentControl s:View.Model="{Binding}" />
75+
</DataTemplate>
76+
</nodify:NodifyEditor.ItemTemplate>
77+
<nodify:NodifyEditor.PendingConnectionTemplate>
78+
<DataTemplate>
79+
<ContentControl s:View.Model="{Binding}" />
80+
</DataTemplate>
81+
</nodify:NodifyEditor.PendingConnectionTemplate>
82+
<nodify:NodifyEditor.ConnectionTemplate>
83+
<DataTemplate>
84+
<ContentControl s:View.Model="{Binding}" />
85+
</DataTemplate>
86+
</nodify:NodifyEditor.ConnectionTemplate>
87+
</nodify:NodifyEditor>
88+
89+
<Grid Background="{StaticResource LargeGridLinesDrawingBrush}"
90+
Panel.ZIndex="-2" />
91+
</Grid>
5392
</UserControl>

Nodifier/Graph/IEditor.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,8 @@ public interface IEditor
88
Point ViewportLocation { get; set; }
99
Size ViewportSize { get; }
1010
double ViewportZoom { get; set; }
11-
double MinViewportZoom { get; set; }
12-
double MaxViewportZoom { get; set; }
1311

14-
double GridSnapSize { get; set; }
15-
16-
bool DisableZooming { get; set; }
17-
bool DisablePanning { get; set; }
18-
bool DisableAutoPanning { get; set; }
19-
bool EnableRealtimeSelection { get; set; }
12+
IEditorSettings Settings { get; }
2013

2114
void FocusLocation(Point location);
2215
void ZoomIn();

0 commit comments

Comments
 (0)