Skip to content

Commit

Permalink
Merge pull request #22 from takenet/feature/dark_mode_lime_console
Browse files Browse the repository at this point in the history
[FEATURE] Implement Dark Mode and solving Json Field Bugs
  • Loading branch information
andreminelli authored Sep 29, 2020
2 parents 4618d83 + a536bf1 commit 93ab696
Show file tree
Hide file tree
Showing 17 changed files with 422 additions and 271 deletions.
1 change: 1 addition & 0 deletions src/Lime.Client.TestConsole/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<Setter Property="BorderThickness" Value="0" />
<Setter Property="TextWrapping" Value="Wrap" />
<Setter Property="FontFamily" Value="Courier New" />
<Setter Property="Background" Value="Transparent" />
</Style>

<vm:MainViewModel x:Key="MainViewModel" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,44 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace Lime.Client.TestConsole.Converters
{
public class DataOperationToBrushConverter : IValueConverter
public class DataOperationToBrushConverter : IMultiValueConverter
{

private readonly SolidColorBrush LightDarkMode = (SolidColorBrush)(new BrushConverter().ConvertFrom("#424242"));
private readonly SolidColorBrush NormalDarkMode = (SolidColorBrush)(new BrushConverter().ConvertFrom("#212121"));

#region IValueConverter Members

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is DataOperation)
var direction = values[0];
var darkMode = values[1];

if (direction is DataOperation && ((DataOperation)direction) == DataOperation.Receive)
{
if (((DataOperation)value) == DataOperation.Receive)
if (darkMode is Style)
{
return new SolidColorBrush(Colors.LightGray);
}
return NormalDarkMode;
}

return new SolidColorBrush(Colors.LightGray);
}

if (darkMode is Style)
{
return LightDarkMode;
}

return new SolidColorBrush(Colors.White);
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
Expand Down
19 changes: 14 additions & 5 deletions src/Lime.Client.TestConsole/Converters/IsErrorToBrushConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,36 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace Lime.Client.TestConsole.Converters
{
public class IsErrorToBrushConverter : IValueConverter
public class IsErrorToBrushConverter : IMultiValueConverter
{
#region IValueConverter Members

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool &&
((bool)value))
var isError = values[0];
var darkMode = values[1];

if (isError is bool &&
(bool)isError)
{
return new SolidColorBrush(Colors.Red);
}

if (darkMode is Style)
{
return new SolidColorBrush(Colors.White);
}

return new SolidColorBrush(Colors.Black);
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
Expand Down
22 changes: 14 additions & 8 deletions src/Lime.Client.TestConsole/Converters/IsRawToBrushConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,35 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;

namespace Lime.Client.TestConsole.Converters
{
public class IsRawToBrushConverter : IValueConverter
public class IsRawToBrushConverter : IMultiValueConverter
{
#region IValueConverter Members

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is bool)
var isRaw = values[0];
var darkMode = values[1];

if (isRaw is bool && (bool)isRaw)
{
return new SolidColorBrush(Colors.Red);
}

if (darkMode is Style)
{
if ((bool)value)
{
return new SolidColorBrush(Colors.Red);
}
return new SolidColorBrush(Colors.White);
}

return new SolidColorBrush(Colors.Black);
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
Expand Down
4 changes: 4 additions & 0 deletions src/Lime.Client.TestConsole/Lime.Client.TestConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="Views\DarkModeDictionary.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\EnvelopeView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ public async Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewM
{
Envelope = notification
};

sessionViewModel.InputJson = notificationEnvelopeViewModel.Json;

if (sessionViewModel.SendCommand.CanExecute(null))
{
await sessionViewModel.SendCommand.ExecuteAsync(null);
await sessionViewModel.SendCommand.ExecuteAsync(notificationEnvelopeViewModel.Json);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ public async Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewM
Envelope = notification
};

sessionViewModel.InputJson = notificationEnvelopeViewModel.Json;

if (sessionViewModel.SendCommand.CanExecute(null))
{
await sessionViewModel.SendCommand.ExecuteAsync(null);
await sessionViewModel.SendCommand.ExecuteAsync(notificationEnvelopeViewModel.Json);
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/Lime.Client.TestConsole/Macros/ReplyPingMacro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ public async Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewM
Envelope = commandResponse
};

sessionViewModel.InputJson = commandEnvelopeViewModel.Json;

if (sessionViewModel.SendCommand.CanExecute(null))
{
await sessionViewModel.SendCommand.ExecuteAsync(null);
await sessionViewModel.SendCommand.ExecuteAsync(commandEnvelopeViewModel.Json);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Lime.Client.TestConsole/Macros/SendTemplateMacroBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ public async Task ProcessAsync(EnvelopeViewModel envelopeViewModel, SessionViewM
var template = sessionViewModel.Templates.FirstOrDefault(t => t.Name.Equals(TemplateName, StringComparison.OrdinalIgnoreCase));
if (template != null)
{
sessionViewModel.InputJson = template.JsonTemplate;
if (sessionViewModel.SendCommand.CanExecute(null))
{
await sessionViewModel.SendCommand.ExecuteAsync(null);
await sessionViewModel.SendCommand.ExecuteAsync(template.JsonTemplate);
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/Lime.Client.TestConsole/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vw="clr-namespace:Lime.Client.TestConsole.Views"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
mc:Ignorable="d"
DataContext="{StaticResource MainViewModel}"
d:DataContext="{d:DesignData /DesignData/MainDesignData.xaml}"
Title="{Binding Title}" Height="600" Width="800" Icon="lime.ico">

<i:Interaction.Triggers>
<i:EventTrigger EventName="Closing">
<i:InvokeCommandAction Command="{Binding ClosingCommand}" />
Expand All @@ -17,7 +19,9 @@
<i:InvokeCommandAction Command="{Binding ClosedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>

<vw:SessionView DataContext="{Binding SelectedSession}" />


<Grid>
<vw:SessionView x:Name="SessionView" DataContext="{Binding SelectedSession}" Grid.Row="1" />
</Grid>

</Window>
15 changes: 1 addition & 14 deletions src/Lime.Client.TestConsole/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows;

namespace Lime.Client.TestConsole
{
Expand Down
4 changes: 2 additions & 2 deletions src/Lime.Client.TestConsole/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.7.0.0")]
[assembly: AssemblyFileVersion("0.7.0.0")]
[assembly: AssemblyVersion("0.10.0.0")]
[assembly: AssemblyFileVersion("0.10.0.0")]
8 changes: 5 additions & 3 deletions src/Lime.Client.TestConsole/ViewModels/SessionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ public string InputJson
}
}

public string JsonToSend { get; set; }

private string _host;

private Uri _hostUri;
Expand Down Expand Up @@ -731,7 +733,7 @@ private bool CanParse()

public AsyncCommand SendCommand { get; private set; }

private async Task SendAsync()
private async Task SendAsync(object parameter)
{
var times = 0;

Expand All @@ -753,11 +755,11 @@ await ExecuteAsync(async () =>
{
AddStatusMessage("Sending...");

var inputJson = InputJson;
var inputJson = parameter.ToString();

if (ParseBeforeSend)
{
inputJson = ParseInput(InputJson, Variables);
inputJson = ParseInput(inputJson, Variables);
}

var timeoutCancellationToken = _operationTimeout.ToCancellationToken();
Expand Down
75 changes: 75 additions & 0 deletions src/Lime.Client.TestConsole/Views/DarkModeDictionary.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vw="clr-namespace:Lime.Client.TestConsole.Views"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
mc:Ignorable="d"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" >

<SolidColorBrush x:Key="DarkModeColor">#2D2D2D</SolidColorBrush>
<SolidColorBrush x:Key="DarkModeDataGridHeader">#18191A</SolidColorBrush>

<Style x:Key="darkMode" TargetType="Control">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Background" Value="{DynamicResource DarkModeColor}"></Setter>
<Style.Resources>
<Style TargetType="Label">
<Setter Property="Foreground" Value="White"></Setter>
</Style>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="White"></Setter>
</Style>
<Style TargetType="CheckBox">
<Setter Property="Foreground" Value="White"></Setter>
</Style>
<Style TargetType="TextBox">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="CaretBrush" Value="White"></Setter>
<Setter Property="Background" Value="Transparent"></Setter>
</Style>
<Style TargetType="xctk:WatermarkTextBox">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="CaretBrush" Value="White"></Setter>
<Setter Property="Background" Value="Transparent"></Setter>
</Style>
<Style TargetType="ListBox">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Background" Value="Transparent"></Setter>
</Style>
<Style TargetType="xctk:IntegerUpDown">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Background" Value="Transparent"></Setter>
</Style>
<Style TargetType="MenuItem">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Background" Value="Transparent"></Setter>
</Style>
<Style TargetType="DataGridRow">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Background" Value="{DynamicResource DarkModeColor}"></Setter>
</Style>
<Style TargetType="StackPanel">
<Setter Property="Background" Value="Transparent"></Setter>
</Style>
<Style TargetType="StatusBar">
<Setter Property="Background" Value="Transparent"></Setter>
</Style>
<Style TargetType="GridSplitter">
<Setter Property="Background" Value="Transparent"></Setter>
</Style>
<Style TargetType="Button">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="Margin" Value="0,0,5,0" />
<Setter Property="Padding" Value="15,2" />
</Style>
<Style TargetType="DataGridColumnHeader">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="Background" Value="{DynamicResource DarkModeDataGridHeader}"></Setter>
</Style>
</Style.Resources>
</Style>
</ResourceDictionary>
22 changes: 17 additions & 5 deletions src/Lime.Client.TestConsole/Views/EnvelopeView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DataContext="{d:DesignData /DesignData/EnvelopeDesignData.xaml}"
d:DesignHeight="200" d:DesignWidth="500">
<TextBox Background="{Binding Direction, Converter={StaticResource DataOperationToBrushConverter}}"
Foreground="{Binding IsRaw, Converter={StaticResource IsRawToBrushConverter}}"
Text="{Binding Json}"
Style="{StaticResource ReadOnlyTextBox}" />
d:DesignHeight="200" d:DesignWidth="500"
Name="UcEnvelopesView">

<TextBox Text="{Binding Json}" Style="{StaticResource ReadOnlyTextBox}">
<TextBox.Background>
<MultiBinding Converter="{StaticResource DataOperationToBrushConverter}">
<Binding Path="Direction"></Binding>
<Binding ElementName="EnvelopesListBox" Path="Style"></Binding>
</MultiBinding>
</TextBox.Background>
<TextBox.Foreground>
<MultiBinding Converter="{StaticResource IsRawToBrushConverter}">
<Binding Path="IsRaw"></Binding>
<Binding ElementName="EnvelopesListBox" Path="Style"></Binding>
</MultiBinding>
</TextBox.Foreground>
</TextBox>
</UserControl>
Loading

0 comments on commit 93ab696

Please sign in to comment.