114 lines
3.7 KiB
C#
114 lines
3.7 KiB
C#
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Media;
|
|
using DocumentFormat.OpenXml.VariantTypes;
|
|
using Microsoft.Win32;
|
|
|
|
namespace CodeMerger.Controls
|
|
{
|
|
public partial class SimpleMergeLogControl : UserControl
|
|
{
|
|
private static readonly SolidColorBrush InfoBrush = Brushes.Black;
|
|
private static readonly SolidColorBrush WarningBrush = Brushes.Orange;
|
|
private static readonly SolidColorBrush ErrorBrush = Brushes.Red;
|
|
private static readonly SolidColorBrush AddedBrush = Brushes.Green;
|
|
private static readonly SolidColorBrush ReplacedBrush = Brushes.Blue;
|
|
|
|
public SimpleMergeLogControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void LogInfo(string message)
|
|
{
|
|
AppendText($"[INFO] {message}", InfoBrush);
|
|
}
|
|
|
|
public void LogWarning(string message)
|
|
{
|
|
AppendText($"[WARNING] {message}", WarningBrush);
|
|
}
|
|
|
|
public void LogError(string message)
|
|
{
|
|
AppendText($"[ERROR] {message}", ErrorBrush);
|
|
}
|
|
|
|
public void LogMergeDetails(string mergeLog)
|
|
{
|
|
AppendText("--- MERGE DETAILS ---", InfoBrush);
|
|
|
|
// Procesar log de merge y colorear según el tipo
|
|
foreach (var line in mergeLog.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries))
|
|
{
|
|
if (line.StartsWith("ADDED:"))
|
|
{
|
|
AppendText(line, AddedBrush);
|
|
}
|
|
else if (line.StartsWith("REPLACED:"))
|
|
{
|
|
AppendText(line, ReplacedBrush);
|
|
}
|
|
else if (line.StartsWith("ERROR:"))
|
|
{
|
|
AppendText(line, ErrorBrush);
|
|
}
|
|
else
|
|
{
|
|
AppendText(line, InfoBrush);
|
|
}
|
|
}
|
|
|
|
AppendText("---------------------", InfoBrush);
|
|
}
|
|
|
|
private void AppendText(string text, Brush color)
|
|
{
|
|
Application.Current.Dispatcher.Invoke(() =>
|
|
{
|
|
var paragraph = new Paragraph();
|
|
paragraph.Inlines.Add(new Run(text) { Foreground = color });
|
|
rtbLog.Document.Blocks.Add(paragraph);
|
|
|
|
// Auto-scroll al final
|
|
rtbLog.ScrollToEnd();
|
|
});
|
|
}
|
|
|
|
private void ClearLog_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
rtbLog.Document.Blocks.Clear();
|
|
}
|
|
|
|
private void CopyLog_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
Clipboard.SetText(new TextRange(rtbLog.Document.ContentStart, rtbLog.Document.ContentEnd).Text);
|
|
LogInfo("Log copiado al portapapeles");
|
|
}
|
|
|
|
private void SaveLog_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
SaveFileDialog saveFileDialog = new SaveFileDialog
|
|
{
|
|
Filter = "Archivos de texto (*.txt)|*.txt|Todos los archivos (*.*)|*.*",
|
|
FileName = "CodeMerger_Log.txt"
|
|
};
|
|
|
|
if (saveFileDialog.ShowDialog() == true)
|
|
{
|
|
try
|
|
{
|
|
string text = new TextRange(rtbLog.Document.ContentStart, rtbLog.Document.ContentEnd).Text;
|
|
System.IO.File.WriteAllText(saveFileDialog.FileName, text);
|
|
LogInfo($"Log guardado en: {saveFileDialog.FileName}");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogError($"Error al guardar el log: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |