Source

GraphPad / GraphPad / MainWindow.xaml.cs

Full commit
Mark Heath 5cc1f5a 











Mark Heath a6f2c8c 
Mark Heath 5cc1f5a 










Mark Heath 972bd02 


Mark Heath 06341a0 












Mark Heath c6a2b9d 












Mark Heath 5cc1f5a 








Mark Heath 43b8164 
Mark Heath c6a2b9d 





Mark Heath 972bd02 
Mark Heath a27ba3f 

Mark Heath 43b8164 
Mark Heath 38ac1ad 
Mark Heath 972bd02 






Mark Heath 5cc1f5a 
using System;
using System.Linq;
using System.Text;
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 GraphPad.Logic;

namespace GraphPad
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            graphText.TextChanged += graphText_TextChanged;
            buttonGit.Click += buttonGit_Click;
            buttonMercurial.Click += buttonMercurial_Click;
        }

        void buttonMercurial_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new System.Windows.Forms.FolderBrowserDialog();
            dialog.Description = "Select Mercurial repository";
            var result = dialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                var builder = new MercurialGraphBuilder();
                var graph = builder.LoadGraph(dialog.SelectedPath);
                RedrawGraph(graph);
            }
        }

        void buttonGit_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new System.Windows.Forms.FolderBrowserDialog();
            dialog.Description = "Select git repository";
            var result = dialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                GitGraphBuilder gitBuilder = new GitGraphBuilder();
                var graph = gitBuilder.LoadGraph(dialog.SelectedPath);
                RedrawGraph(graph);
            }
        }

        void graphText_TextChanged(object sender, TextChangedEventArgs e)
        {
            RecreateGraph();
        }

        private void RecreateGraph()
        {
            GraphBuilder builder = new GraphBuilder();
            Graph graph = builder.GenerateGraph(graphText.Text);
            RedrawGraph(graph);
        }

        private void RedrawGraph(Graph graph)
        {
            GraphRenderer renderer = new GraphRenderer(graphCanvas, CreateCircleNodeControl, 40, 40);
            GraphLayoutEngine layout = new GraphLayoutEngine();
            layout.Layout(graph);
            renderer.Render(graph);
        }

        private static UserControl CreateCircleNodeControl(Node node)
        {
            var nodeControl = new CircularNodeControl();
            nodeControl.NodeName = node.Name;
            return nodeControl;
        }
    }
}