Skip to content

Commit

Permalink
#50 rtb
Browse files Browse the repository at this point in the history
  • Loading branch information
tym32167 committed Nov 20, 2016
1 parent 04ff039 commit ee9e8ca
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Prism.Wpf.6.2.0\lib\net45\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
Expand All @@ -75,6 +77,7 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
<Reference Include="WindowsFormsIntegration" />
<Reference Include="Xceed.Wpf.AvalonDock, Version=2.9.0.0, Culture=neutral, PublicKeyToken=3e4669d2f30244f4, processorArchitecture=MSIL">
<HintPath>..\packages\Extended.Wpf.Toolkit.2.9\lib\net40\Xceed.Wpf.AvalonDock.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -107,6 +110,10 @@
<Compile Include="Boxes\ColoredTextControl.xaml.cs">
<DependentUpon>ColoredTextControl.xaml</DependentUpon>
</Compile>
<Compile Include="Boxes\IColoredTextControl.cs" />
<Compile Include="Boxes\RTBControl.xaml.cs">
<DependentUpon>RTBControl.xaml</DependentUpon>
</Compile>
<Compile Include="ChatModuleInit.cs" />
<Compile Include="Boxes\ChatHistory.xaml.cs">
<DependentUpon>ChatHistory.xaml</DependentUpon>
Expand All @@ -127,6 +134,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Boxes\RTBControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Chat\ChatControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
7 changes: 5 additions & 2 deletions src/Arma3BE.Client.Modules.ChatModule/Boxes/ChatHistory.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
<Button Content="Search" Command="{Binding FilterCommand}" />
</ToolBar>

<boxes:ColoredTextControl x:Name="textControl" IsAutoScroll="True" Grid.Row="1">
</boxes:ColoredTextControl>
<!--<boxes:ColoredTextControl x:Name="textControl" IsAutoScroll="True" Grid.Row="1">
</boxes:ColoredTextControl>-->

<boxes:RTBControl x:Name="textControl" IsAutoScroll="True" Grid.Row="1">
</boxes:RTBControl>

</Grid>
</xctk:BusyIndicator>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Arma3BE.Client.Modules.ChatModule.Models;
using Arma3BE.Server.Models;
using System.ComponentModel;
using System.Linq;
using System.Windows;

namespace Arma3BE.Client.Modules.ChatModule.Boxes
Expand Down Expand Up @@ -34,6 +35,12 @@ private void Refresh()
{
textControl.ClearAll();

if (_model.Log.Count() > 10000)
{
MessageBox.Show(Window.GetWindow(this), "Too many results.", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}

foreach (var chatLog in _model.Log)
{
var mes = new ChatMessage { Date = chatLog.Date, Message = chatLog.Text };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Arma3BE.Client.Modules.ChatModule.Boxes
/// <summary>
/// Interaction logic for ColoredTextControl.xaml
/// </summary>
public partial class ColoredTextControl
public partial class ColoredTextControl : IColoredTextControl
{
private Paragraph _paragraph;

Expand Down
14 changes: 14 additions & 0 deletions src/Arma3BE.Client.Modules.ChatModule/Boxes/IColoredTextControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using Arma3BE.Server.Models;

namespace Arma3BE.Client.Modules.ChatModule.Boxes
{
public interface IColoredTextControl
{
bool IsAutoScroll { get; set; }

void AppendPlayerText(KeyValuePair<string, string> player, bool isIn);
void AppendText(ChatMessage message, string servername = null);
void ClearAll();
}
}
11 changes: 11 additions & 0 deletions src/Arma3BE.Client.Modules.ChatModule/Boxes/RTBControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<UserControl x:Class="Arma3BE.Client.Modules.ChatModule.Boxes.RTBControl"
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:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
mc:Ignorable="d" >
<WindowsFormsHost>
<forms:RichTextBox x:Name="rtb" ReadOnly="True"></forms:RichTextBox>
</WindowsFormsHost>
</UserControl>
106 changes: 106 additions & 0 deletions src/Arma3BE.Client.Modules.ChatModule/Boxes/RTBControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using Arma3BE.Client.Infrastructure.Extensions;
using Arma3BE.Client.Modules.ChatModule.Models;
using Arma3BE.Server.Models;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows;
using System.Windows.Controls;

namespace Arma3BE.Client.Modules.ChatModule.Boxes
{
/// <summary>
/// Interaction logic for RTBControl.xaml
/// </summary>
public partial class RTBControl : UserControl, IColoredTextControl
{
public static readonly DependencyProperty IsAutoScrollProperty =
DependencyProperty.Register("IsAutoScroll", typeof(bool), typeof(RTBControl),
new FrameworkPropertyMetadata(false));

public RTBControl()
{
InitializeComponent();

rtb.Font = new Font(rtb.Font.FontFamily, 12);
}


public bool IsAutoScroll
{
get { return (bool)GetValue(IsAutoScrollProperty); }
set { SetValue(IsAutoScrollProperty, value); }
}

public void AppendPlayerText(KeyValuePair<string, string> player, bool isIn)
{
}



[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam);
const int WM_USER = 0x400;
const int EM_HIDESELECTION = WM_USER + 63;

public void AppendText(ChatMessage message, string servername = null)
{
string text;

if (string.IsNullOrEmpty(servername))
{
text = $"[ {message.Date.UtcToLocalFromSettings():HH:mm:ss} ] {message.Message}\n";
}
else
{
text =
$"[{servername}] [ {message.Date.UtcToLocalFromSettings():yyyy-MM-dd HH:mm:ss} ] {message.Message}\n";
}

var color = ServerMonitorChatViewModel.GetMessageColor(message);
var wformsColor = Color.FromArgb(color.A, color.R, color.G, color.B);



var selection = rtb.SelectionStart;
var length = rtb.SelectionLength;


if (!IsAutoScroll)
{
SendMessage(rtb.Handle, EM_HIDESELECTION, 1, 0);
}


rtb.AppendText(text);

rtb.Select(rtb.TextLength - text.Length, text.Length);
rtb.SelectionColor = wformsColor;


if (message.Type != ChatMessage.MessageType.RCon && message.IsImportantMessage)
rtb.SelectionFont = new Font(rtb.SelectionFont, System.Drawing.FontStyle.Bold);

if (length != 0)
{
rtb.SelectionStart = selection;
rtb.SelectionLength = length;
}
else
{
rtb.Select(rtb.TextLength, 0);
}


if (!IsAutoScroll)
{
SendMessage(rtb.Handle, EM_HIDESELECTION, 0, 0);
}
}

public void ClearAll()
{
rtb.Clear();
}
}
}
8 changes: 6 additions & 2 deletions src/Arma3BE.Client.Modules.ChatModule/Chat/ChatControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<boxes:ColoredTextControl x:Name="textControl" IsAutoScroll="{Binding AutoScroll}" Grid.ColumnSpan="3">
</boxes:ColoredTextControl>
<!--<boxes:ColoredTextControl x:Name="textControl" IsAutoScroll="{Binding AutoScroll}" Grid.ColumnSpan="3">
</boxes:ColoredTextControl>-->

<boxes:RTBControl x:Name="textControl" IsAutoScroll="{Binding AutoScroll}" Grid.ColumnSpan="3">
</boxes:RTBControl>


<ComboBox Grid.Row="1" Grid.Column="0" Margin="2" ItemsSource="{Binding Players, Mode=OneWay}"
SelectedValue="{Binding SelectedPlayer, Mode=TwoWay}">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Arma3BE.Client.Infrastructure.Commands;
using Arma3BE.Client.Infrastructure.Extensions;
using Arma3BE.Client.Infrastructure.Models;
using Arma3BEClient.Libs.ModelCompact;
using Arma3BEClient.Libs.Repositories;
Expand All @@ -7,7 +8,6 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
using Arma3BE.Client.Infrastructure.Extensions;

namespace Arma3BE.Client.Modules.ChatModule.Models
{
Expand All @@ -22,17 +22,23 @@ public class ChatHistoryViewModel : ViewModelBase
return repo.GetServerInfo().OrderBy(x => x.Name).ToList();
}
});

public ChatHistoryViewModel(Guid serverId)
{
_serverId = serverId;

FilterCommand = new ActionCommand(async () =>
{
IsBusy = true;
await Task.Factory.StartNew(UpdateLog, TaskCreationOptions.LongRunning).ConfigureAwait(true);
OnPropertyChanged(nameof(Log));
IsBusy = false;
try
{
IsBusy = true;
await Task.Factory.StartNew(UpdateLog, TaskCreationOptions.LongRunning).ConfigureAwait(true);
OnPropertyChanged(nameof(Log));
}
finally
{
IsBusy = false;
}
});

SelectedServers = serverId.ToString();
Expand Down

0 comments on commit ee9e8ca

Please sign in to comment.