110 lines
3.8 KiB
C#
110 lines
3.8 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using CodeMerger.ViewModels;
|
|
using ICSharpCode.AvalonEdit;
|
|
using ICSharpCode.AvalonEdit.Highlighting;
|
|
|
|
namespace CodeMerger
|
|
{
|
|
public partial class MainWindow : Window
|
|
{
|
|
private MainWindowViewModel _viewModel;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
|
|
_viewModel = new MainWindowViewModel();
|
|
DataContext = _viewModel;
|
|
}
|
|
|
|
private void txtOriginalCode_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
ConfigureTextEditor(txtOriginalCode);
|
|
}
|
|
|
|
private void txtLLMCode_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
ConfigureTextEditor(txtLLMCode);
|
|
}
|
|
|
|
private void txtMergedCode_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
ConfigureTextEditor(txtMergedCode);
|
|
}
|
|
|
|
private void ConfigureTextEditor(TextEditor editor)
|
|
{
|
|
editor.Options.EnableHyperlinks = false;
|
|
editor.Options.EnableEmailHyperlinks = false;
|
|
editor.Options.EnableVirtualSpace = false;
|
|
editor.Options.ShowSpaces = false;
|
|
editor.Options.ShowTabs = false;
|
|
editor.Options.ShowEndOfLine = false;
|
|
editor.Options.ShowColumnRuler = false;
|
|
editor.Options.EnableRectangularSelection = true;
|
|
editor.Options.EnableTextDragDrop = true;
|
|
editor.WordWrap = true;
|
|
|
|
// Configurar syntax highlighting para C#
|
|
editor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("C#");
|
|
|
|
// Configurar indentación con tabulaciones
|
|
editor.Options.ConvertTabsToSpaces = false;
|
|
editor.Options.IndentationSize = 4;
|
|
}
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
// Guardar configuración antes de cerrar
|
|
_viewModel.Settings.Save();
|
|
}
|
|
|
|
private void GridSplitter_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
|
|
{
|
|
// Actualizar anchos de columnas en el ViewModel
|
|
var columnDefinitions = EditorsGrid.ColumnDefinitions;
|
|
_viewModel.FirstColumnWidth = columnDefinitions[1].ActualWidth;
|
|
_viewModel.SecondColumnWidth = columnDefinitions[3].ActualWidth;
|
|
_viewModel.ThirdColumnWidth = columnDefinitions[5].ActualWidth;
|
|
}
|
|
|
|
private void TextEditor_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
{
|
|
// Seleccionar palabra completa al hacer doble clic
|
|
var editor = sender as TextEditor;
|
|
if (editor != null)
|
|
{
|
|
var position = editor.TextArea.Caret.Position;
|
|
var document = editor.Document;
|
|
var line = document.GetLineByOffset(position.Offset);
|
|
var lineText = document.GetText(line);
|
|
|
|
// Obtener palabra bajo el cursor
|
|
var offsetInLine = position.Offset - line.Offset;
|
|
int wordStart = offsetInLine;
|
|
int wordEnd = offsetInLine;
|
|
|
|
// Encontrar inicio de palabra
|
|
while (wordStart > 0 && IsWordPart(lineText[wordStart - 1]))
|
|
wordStart--;
|
|
|
|
// Encontrar fin de palabra
|
|
while (wordEnd < lineText.Length && IsWordPart(lineText[wordEnd]))
|
|
wordEnd++;
|
|
|
|
// Seleccionar palabra
|
|
if (wordEnd > wordStart)
|
|
{
|
|
editor.Select(line.Offset + wordStart, wordEnd - wordStart);
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool IsWordPart(char c)
|
|
{
|
|
return char.IsLetterOrDigit(c) || c == '_';
|
|
}
|
|
}
|
|
} |