Kimmax / Flash-dl

Flash(Youtube) Downloader using SYMM
GNU General Public License v2.0
0 stars 0 forks source link

AppendText idea #9

Closed ghost closed 8 years ago

ghost commented 8 years ago

What do you think of below for color and text handling i have implemented this in my other project

private void AppendText(string message, Color color)
        {
            AppendText("System", message, color);
        }

        private void AppendText(string sender, string message)
        {
            AppendText(sender, message, Colors.Black);
        }

        private void AppendText(string sender, string message, Color color)
        {
            var senderTextRange = new TextRange(TextBoxConsole.Document.ContentEnd, TextBoxConsole.Document.ContentEnd)
            {
                Text = string.Format("{0}: {1}", sender, message)
            };
            // Colorize the sender and make it bold
            senderTextRange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(color));
            senderTextRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);

            // Add a new line and reset styles
            var resetTextRange = new TextRange(TextBoxConsole.Document.ContentEnd, TextBoxConsole.Document.ContentEnd)
            {
                Text = Environment.NewLine
            };
            resetTextRange.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Normal);

            // Scroll to end of chat text if ScrollLock isn't on
            var scrollLock = (((ushort)GetKeyState(0x91)) & 0xffff) != 0;
            if (!scrollLock)
            {
                TextBoxConsole.ScrollToEnd();
            }
        }
Kimmax commented 8 years ago

Looks good altought I would change

private void AppendText(string message, Color color)
{
    AppendText("System", message, color);
}

 private void AppendText(string sender, string message)
 {
     AppendText(sender, message, Colors.Black);
 }

to

 private void AppendText(string sender = "System", string message, Color color = Colors.Black)
 {
     AppendText(sender, message, color);
 }
ghost commented 8 years ago

:) is that not the same thing haha sorry had no coffee today

ghost commented 8 years ago

Ofcause we going to take out sender part i just pulled that from my other repro