Skip to content

Commit 05ba928

Browse files
committed
button for change theme
1 parent 2dbfbdc commit 05ba928

File tree

13 files changed

+141
-113
lines changed

13 files changed

+141
-113
lines changed

SimpleStateMachineNodeEditor/Helpers/Enums/Theme.cs renamed to SimpleStateMachineNodeEditor/Helpers/Enums/Themes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SimpleStateMachineNodeEditor.Helpers.Enums
66
{
7-
public enum Theme
7+
public enum Themes
88
{
99
noCorrect = 0,
1010
Light,

SimpleStateMachineNodeEditor/README.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Ctrl + Y = Redo
1010
Ctrl + N = Add Node
1111
Ctrl + LMB on Canvas = Start Select
1212
Ctrl + LMB on Connector = Create Loop
13+
������� ������� ��������� ���������
14+
LMB on Node = Select Node
15+
Ctrl + LMB on Node = Select Node
16+
Ctrl + LMB on Transition = Select Transition
1317
LMB on Connector = Start create Connect
1418
Alt + LMB on Connector = Move Connector in Node
1519
Alt + LMB on Canvas = Start Cut

SimpleStateMachineNodeEditor/View/MainWindow.xaml.cs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void SetupBinding()
7272
this.OneWayBind(this.ViewModel, x => x.CountDebug, x => x.LabelDebug.Content, value => value.ToString() + " Debug").DisposeWith(disposable);
7373

7474

75-
this.BindCommand(this.ViewModel, x => x.CommandChangeTheme, x => x.ButtonChangeTheme).DisposeWith(disposable);
75+
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandChangeTheme, x => x.ButtonChangeTheme).DisposeWith(disposable);
7676

7777
this.BindCommand(this.ViewModel, x => x.CommandCopySchemeName, x => x.ItemCopySchemeName).DisposeWith(disposable);
7878
this.BindCommand(this.ViewModel, x => x.NodesCanvas.CommandSelectAll, x => x.ItemSelectAll).DisposeWith(disposable);
@@ -124,6 +124,7 @@ private void SetupSubscriptions()
124124
this.WhenAnyValue(x => x.ViewModel.NodesCanvas.SchemePath).Subscribe(value=> UpdateSchemeName(value)).DisposeWith(disposable);
125125
this.WhenAnyValue(x => x.NodesCanvas.ViewModel.NeedExit).Where(x=>x).Subscribe(_ => this.Close()).DisposeWith(disposable);
126126
this.WhenAnyValue(x => x.ViewModel.CountError).Buffer(2, 1).Where(x => x[1] > x[0]).Subscribe(_ => ShowError()).DisposeWith(disposable);
127+
this.WhenAnyValue(x => x.ViewModel.NodesCanvas.Theme).Subscribe(_ => UpdateButton()).DisposeWith(disposable);
127128
});
128129
}
129130
private void UpdateSchemeName(string newName)
@@ -198,20 +199,31 @@ private void ButtonMaxClick(RoutedEventArgs e)
198199
StateNormalMaximaze();
199200
}
200201
private void StateNormalMaximaze()
202+
{
203+
this.WindowState = (this.WindowState == WindowState.Normal) ? WindowState.Maximized : WindowState.Normal;
204+
UpdateButton();
205+
}
206+
private void UpdateButton()
201207
{
202208
if (this.WindowState == WindowState.Normal)
203209
{
204-
this.WindowState = WindowState.Maximized;
205-
this.ButtonMaxRectangle.Fill = System.Windows.Application.Current.Resources["IconRestore"] as DrawingBrush;
206-
this.ButtonMaxRectangle.ToolTip = "Maximize";
210+
StateNormal();
207211
}
208212
else
209213
{
210-
this.WindowState = WindowState.Normal;
211-
this.ButtonMaxRectangle.Fill = System.Windows.Application.Current.Resources["IconMaximize"] as DrawingBrush;
212-
this.ButtonMaxRectangle.ToolTip = "Restore down";
214+
StateMaximize();
213215
}
214216
}
217+
private void StateMaximize()
218+
{
219+
this.ButtonMaxRectangle.Fill = Application.Current.Resources["IconRestore"] as DrawingBrush;
220+
this.ButtonMaxRectangle.ToolTip = "Maximize";
221+
}
222+
private void StateNormal()
223+
{
224+
this.ButtonMaxRectangle.Fill = Application.Current.Resources["IconMaximize"] as DrawingBrush;
225+
this.ButtonMaxRectangle.ToolTip = "Restore down";
226+
}
215227
private void HeaderClick(MouseButtonEventArgs e)
216228
{
217229
if (e.OriginalSource is DockPanel)
@@ -231,7 +243,8 @@ private void HeaderClick(MouseButtonEventArgs e)
231243
Left = point.X - (RestoreBounds.Width / 2);
232244

233245
Top = point.Y - (this.Header.ActualHeight / 2);
234-
WindowState = WindowState.Normal;
246+
StateNormal();
247+
this.WindowState = WindowState.Normal;
235248
}
236249

237250
this.DragMove();

SimpleStateMachineNodeEditor/View/ViewLeftConnector.xaml.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,16 @@ private void SetupBinding()
5656

5757
this.OneWayBind(this.ViewModel, x => x.TextEnable, x => x.TextBoxElement.IsEnabled).DisposeWith(disposable);
5858

59-
// Доступен ли переход для создания соединия
6059
this.OneWayBind(this.ViewModel, x => x.FormEnable, x => x.EllipseElement.IsEnabled).DisposeWith(disposable);
6160

6261
this.OneWayBind(this.ViewModel, x => x.Foreground, x => x.TextBoxElement.Foreground).DisposeWith(disposable);
6362

64-
// Цвет рамки, вокруг перехода
6563
this.OneWayBind(this.ViewModel, x => x.FormStroke, x => x.EllipseElement.Stroke).DisposeWith(disposable);
6664

67-
// Цвет перехода
6865
this.OneWayBind(this.ViewModel, x => x.FormFill, x => x.EllipseElement.Fill).DisposeWith(disposable);
6966

70-
// Отображается ли переход
7167
this.OneWayBind(this.ViewModel, x => x.Visible, x => x.LeftConnector.Visibility).DisposeWith(disposable);
7268

73-
//// При изменении размера, позиции или zoom узла
74-
//this.WhenAnyValue(x => x.ViewModel.Node.Size, x => x.ViewModel.Node.Point1.Value, x => x.ViewModel.Node.NodesCanvas.Scale.Scales.Value)
75-
//.Subscribe(_ => UpdatePosition()).DisposeWith(disposable);
76-
77-
7869
});
7970
}
8071
#endregion SetupBinding

SimpleStateMachineNodeEditor/View/ViewNodesCanvas.xaml.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public ViewNodesCanvas()
5353
InitializeComponent();
5454
ViewModel = new ViewModelNodesCanvas();
5555
SetupCommands();
56+
SetupSubscriptions();
5657
SetupBinding();
5758
SetupEvents();
5859

@@ -103,23 +104,22 @@ private void SetupCommands()
103104

104105
this.BindCommand(this.ViewModel, x => x.CommandCollapseUpSelected, x => x.ItemCollapsUp).DisposeWith(disposable);
105106
this.BindCommand(this.ViewModel, x => x.CommandExpandDownSelected, x => x.ItemExpandDown).DisposeWith(disposable);
106-
107-
108-
109-
this.WhenAnyValue(x => x.ViewModel.Selector.Size).WithoutParameter().InvokeCommand(ViewModel,x=>x.CommandSelectorIntersect).DisposeWith(disposable);
110-
this.WhenAnyValue(x => x.ViewModel.Cutter.EndPoint).WithoutParameter().InvokeCommand(ViewModel, x => x.CommandCutterIntersect).DisposeWith(disposable);
111-
112-
this.WhenAnyValue(x => x.ViewModel.JPEGPath).Where(x=>!string.IsNullOrEmpty(x)).Subscribe(value=> SaveCanvasToImage(value, ImageFormats.JPEG)).DisposeWith(disposable);
113-
114-
115-
116107
});
117108
}
118109
#endregion Setup Commands
119-
private void Test(Point point)
120-
{
110+
#region Setup Subscriptions
121111

112+
private void SetupSubscriptions()
113+
{
114+
this.WhenActivated(disposable =>
115+
{
116+
this.WhenAnyValue(x => x.ViewModel.Selector.Size).WithoutParameter().InvokeCommand(ViewModel, x => x.CommandSelectorIntersect).DisposeWith(disposable);
117+
this.WhenAnyValue(x => x.ViewModel.Cutter.EndPoint).WithoutParameter().InvokeCommand(ViewModel, x => x.CommandCutterIntersect).DisposeWith(disposable);
118+
this.WhenAnyValue(x => x.ViewModel.JPEGPath).Where(x => !string.IsNullOrEmpty(x)).Subscribe(value => SaveCanvasToImage(value, ImageFormats.JPEG)).DisposeWith(disposable);
119+
});
122120
}
121+
122+
#endregion Setup Subscriptions
123123
#region Setup Events
124124
private void SetupEvents()
125125
{

SimpleStateMachineNodeEditor/View/ViewRightConnector.xaml.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,11 @@ private void SetupSubcriptions()
8585
{
8686
this.WhenActivated(disposable =>
8787
{
88-
89-
//this.WhenAnyValue(x => x.ViewModel.Node.Size, x => x.ViewModel.Node.Point1.Value, x => x.ViewModel.Node.NodesCanvas.Scale.Scales.Value)
90-
// .Subscribe(_ => UpdatePositionConnectPoin()).DisposeWith(disposable);
9188
this.WhenAnyValue(x => x.EllipseElement.IsMouseOver).Subscribe(value => OnEventMouseOver(value)).DisposeWith(disposable);
9289
});
9390
}
94-
9591
#endregion Setup Subcriptions
92+
9693
#region SetupEvents
9794

9895
private void SetupEvents()

SimpleStateMachineNodeEditor/ViewModel/Connect/ViewModelConnect.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private void SetupSubscriptions()
4747
this.WhenAnyValue(x => x.FromConnector.Node.IsCollapse).Subscribe(value => UpdateSubscriptionForPosition(value));
4848
this.WhenAnyValue(x => x.ToConnector.PositionConnectPoint).Subscribe(value => EndPointUpdate(value));
4949
this.WhenAnyValue(x => x.FromConnector.Selected).Subscribe(value => Select(value));
50+
this.WhenAnyValue(x => x.NodesCanvas.Theme).Subscribe(_ => Select(this.FromConnector.Selected));
5051
}
5152
private void UpdateSubscriptionForPosition(bool nodeIsCollapse)
5253
{
@@ -71,7 +72,7 @@ private void Initial(ViewModelNodesCanvas viewModelNodesCanvas, ViewModelConnect
7172
private void Select(bool value)
7273
{
7374
//this.StrokeDashArray = value ? new DoubleCollection() { 10, 3 } : null;
74-
this.Stroke = value ? Application.Current.Resources["ColorSelectedElement"].Cast<SolidColorBrush>(): Application.Current.Resources["ColorConnect"].Cast<SolidColorBrush>();
75+
this.Stroke = Application.Current.Resources[value ? "ColorSelectedElement": "ColorConnect"] as SolidColorBrush;
7576
}
7677
private void ToConnectChanged()
7778
{

SimpleStateMachineNodeEditor/ViewModel/Connector/ViewModelConnector.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public partial class ViewModelConnector : ReactiveObject
2020
[Reactive] public bool TextEnable { get; set; } = false;
2121
[Reactive] public bool? Visible { get; set; } = true;
2222
[Reactive] public bool FormEnable { get; set; } = true;
23-
[Reactive] public Brush FormStroke { get; set; } = Application.Current.Resources["ColorNodesCanvasBackground"] as SolidColorBrush;
24-
[Reactive] public Brush FormFill { get; set; } = Application.Current.Resources["ColorConnector"] as SolidColorBrush;
25-
[Reactive] public Brush Foreground { get; set; } = Application.Current.Resources["ColorConnectorForeground"] as SolidColorBrush;
23+
[Reactive] public Brush FormStroke { get; set; }
24+
[Reactive] public Brush FormFill { get; set; }
25+
[Reactive] public Brush Foreground { get; set; }
2626
[Reactive] public double FormStrokeThickness { get; set; } = 1;
2727
[Reactive] public ViewModelNode Node { get; set; }
2828
[Reactive] public ViewModelConnect Connect { get; set; }
@@ -44,9 +44,9 @@ public ViewModelConnector(ViewModelNodesCanvas nodesCanvas, ViewModelNode viewMo
4444
private void SetupSubscriptions()
4545
{
4646
this.WhenAnyValue(x => x.Selected).Subscribe(value => Select(value));
47-
47+
this.WhenAnyValue(x => x.NodesCanvas.Theme).Subscribe(_ => UpdateResources());
4848

49-
if(this.Name!="Input")
49+
if (this.Name!="Input")
5050
{
5151
if (this.Name != "Output")
5252
{
@@ -81,6 +81,15 @@ private void UpdatePositionOnWidthChange(double value)
8181
{
8282
this.PositionConnectPoint = this.PositionConnectPoint.Addition(value, 0);
8383
}
84+
private void UpdateResources()
85+
{
86+
Select(this.Selected);
87+
if (this.ItsLoop)
88+
{
89+
ToLoop();
90+
}
91+
}
92+
8493

8594
#endregion Setup Subscriptions
8695
public XElement ToXElement()

SimpleStateMachineNodeEditor/ViewModel/Connector/ViewModelConnectorCommands.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ private void SetAsLoop()
5656
{
5757
if (this == Node.Output)
5858
return;
59+
ToLoop();
60+
ItsLoop = true;
61+
Node.CommandAddEmptyConnector.ExecuteWithSubscribe();
62+
}
63+
private void ToLoop()
64+
{
5965
this.FormStrokeThickness = 0;
6066
this.FormFill = Application.Current.Resources["IconLoop"] as DrawingBrush;
61-
62-
Node.CommandAddEmptyConnector.ExecuteWithSubscribe();
6367
}
6468
private void ConnectPointDrag()
6569
{
@@ -144,9 +148,9 @@ private void ValidateName(string newName)
144148

145149
private void Select(bool value)
146150
{
147-
148-
this.Foreground = value ? Application.Current.Resources["ColorSelectedElement"] as SolidColorBrush : Application.Current.Resources["ColorConnectorForeground"] as SolidColorBrush;
149-
this.FormFill = value ? Application.Current.Resources["ColorSelectedElement"] as SolidColorBrush : Application.Current.Resources["ColorConnector"] as SolidColorBrush;
151+
this.FormStroke = Application.Current.Resources["ColorNodesCanvasBackground"] as SolidColorBrush;
152+
this.Foreground = Application.Current.Resources[this.Selected ? "ColorSelectedElement" : "ColorConnectorForeground"] as SolidColorBrush;
153+
this.FormFill = Application.Current.Resources[this.Selected ? "ColorSelectedElement" : "ColorConnector"] as SolidColorBrush;
150154
}
151155
private void Select(SelectMode selectMode)
152156
{

SimpleStateMachineNodeEditor/ViewModel/MainWindow/ViewModelMainWindow.cs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ public class ViewModelMainWindow : ReactiveObject
2626
[Reactive] public int CountInformation { get; set; }
2727
[Reactive] public int CountDebug { get; set; }
2828

29-
public Theme CurrentTheme { get; set; } = Theme.Dark;
30-
static Dictionary<Theme, string> themesPaths = new Dictionary<Theme, string>()
31-
{
32-
{Theme.Dark, @"Styles\Themes\Dark.xaml" },
33-
{Theme.Light, @"Styles\Themes\Light.xaml"},
34-
};
35-
3629
private IDisposable ConnectToMessages;
3730
public double MaxHeightMessagePanel = 150;
3831

@@ -82,12 +75,12 @@ bool CheckForDisplay(TypeMessage typeMessage)
8275

8376
public ReactiveCommand<string, Unit> CommandCopyError { get; set; }
8477
public ReactiveCommand<Unit, Unit> CommandCopySchemeName{ get; set; }
85-
public ReactiveCommand<Unit, Unit> CommandChangeTheme { get; set; }
78+
8679
private void SetupCommands()
8780
{
8881
CommandCopyError = ReactiveCommand.Create<string>(CopyError);
8982
CommandCopySchemeName = ReactiveCommand.Create(CopySchemeName);
90-
CommandChangeTheme = ReactiveCommand.Create(ChangeTheme);
83+
9184
}
9285

9386
private void CopyError(string errrorText)
@@ -98,34 +91,6 @@ private void CopySchemeName()
9891
{
9992
Clipboard.SetText(this.NodesCanvas.SchemePath);
10093
}
101-
private void ChangeTheme()
102-
{
103-
if (CurrentTheme == Theme.Dark)
104-
{
105-
SetTheme(Theme.Light);
106-
}
107-
else if (CurrentTheme == Theme.Light)
108-
{
109-
SetTheme(Theme.Dark);
110-
}
111-
112-
}
113-
private void SetTheme(Theme theme)
114-
{
115-
Application.Current.Resources.Clear();
116-
var uri = new Uri(themesPaths[theme], UriKind.RelativeOrAbsolute);
117-
ResourceDictionary resourceDict = Application.LoadComponent(uri) as ResourceDictionary;
118-
Application.Current.Resources.MergedDictionaries.Add(resourceDict);
119-
CurrentTheme = theme;
120-
LoadIcons();
121-
}
122-
private void LoadIcons()
123-
{
124-
string path = @"Icons\Icons.xaml";
125-
var uri = new Uri(path, UriKind.RelativeOrAbsolute);
126-
ResourceDictionary resourceDict = Application.LoadComponent(uri) as ResourceDictionary;
127-
Application.Current.Resources.MergedDictionaries.Add(resourceDict);
128-
}
12994
private void UpdateCountMessages()
13095
{
13196
var counts = NodesCanvas.Messages.GroupBy(x => x.TypeMessage).ToDictionary(x => x.Key, x => x.Count());

0 commit comments

Comments
 (0)