public void OnLostFocus(DiffViewEventArgs <RichTextBox> e)
 {
     foreach (var rtb in e.Container.ResolveAll <RichTextBox>())
     {
         rtb.Height = 30d;
     }
 }
        public void OnViewportMoved(DiffViewEventArgs <Rectangle> e)
        {
            var row = Grid.GetRow(e.Sender);
            var col = Grid.GetColumn(e.Sender);

            e.Container.Resolve <FastGridControl>(Key).Scroll(row, col, row, col);
        }
 public void OnPostExecuteDiff(DiffViewEventArgs <FastGridControl> e)
 {
     foreach (var textBox in e.Container.ResolveAll <RichTextBox>())
     {
         textBox.Document.Blocks.FirstOrDefault()?.ContentStart.Paragraph.Inlines.Clear();
     }
 }
        public void OnSelectedCellChanged(DiffViewEventArgs <FastGridControl> e)
        {
            var dataGrid = e.Container.Resolve <FastGridControl>(Key);

            if (e.Sender == dataGrid)
            {
                return;
            }

            var targetCell = new FastGridCellAddress(e.Sender.CurrentCell.Row, e.Sender.CurrentCell.Column);

            if (!targetCell.Equals(dataGrid.CurrentCell))
            {
                if (dataGrid.Model == null)
                {
                    return;
                }

                if (dataGrid.Model.RowCount < targetCell.Row || dataGrid.Model.ColumnCount < targetCell.Column)
                {
                    return;
                }

                dataGrid.CurrentCell = targetCell;

                if (e.Sender.GetSelectedModelCells().Aggregate(false, (r, c) => r |= dataGrid.AddSelectedCell(c)))
                {
                    dataGrid.InvalidateAll();
                }
            }

            var valuteTextBox = e.Container.ResolveAll <RichTextBox>();
        }
        public void OnFileSettingUpdated(DiffViewEventArgs <FastGridControl> e, FileSetting fileSetting)
        {
            if (e.Sender != e.Container.Resolve <FastGridControl>(Key))
            {
                return;
            }

            if (fileSetting != null)
            {
                var model = e.Sender.Model as DiffGridModel;
                if (model != null)
                {
                    model.SetColumnHeader(fileSetting.ColumnHeaderIndex);
                    if (string.IsNullOrEmpty(fileSetting.RowHeaderName))
                    {
                        model.SetRowHeader(fileSetting.RowHeaderIndex);
                    }
                    else
                    {
                        model.SetRowHeader(fileSetting.RowHeaderName);
                    }
                }

                e.Sender.MaxRowHeaderWidth = fileSetting.MaxRowHeaderWidth;
            }
        }
Exemple #6
0
        private void Window_ContentRendered(object sender, EventArgs e)
        {
            var args = new DiffViewEventArgs <FastGridControl>(MergeDataGrid, container);

            DataGridEventDispatcher.Instance.DispatchDisplayFormatChangeEvent(args, false);
            DataGridEventDispatcher.Instance.DispatchPostExecuteDiffEvent(args);
        }
        public void OnModelUpdated(DiffViewEventArgs <FastGridControl> e)
        {
            var dataGrid = e.Container.Resolve <FastGridControl>(Key);

            if (e.Sender.Model == null || e.Sender != dataGrid)
            {
                return;
            }

            var locationGrid = e.Container.Resolve <Grid>(Key);

            if (locationGrid == null)
            {
                return;
            }

            var rowCount = e.Sender.Model.RowCount - e.Sender.Model.GetHiddenRows(e.Sender).Count;
            var colCount = e.Sender.Model.ColumnCount;

            UpdateLocationGridDefinisions(locationGrid, locationGrid.RenderSize, rowCount, colCount);

            var viewport = e.Container.Resolve <Rectangle>(Key);

            RecalculateViewport(viewport, e.Sender);

            var colorMap = CreateColorMap(e.Sender);

            UpdateLocationGridColors(locationGrid, colorMap, viewport);

            e.Sender.NotifyRefresh();
        }
Exemple #8
0
        public MergeWindow(DiffView diffView, DiffGridModel model, string dstFilePath, string mergeFilePath, string currentSheetName, FileSetting fileSetting)
        {
            InitializeComponent();
            InitializeContainer();
            InitializeEventListeners();

            if (diffView == null)
            {
                this.Close();
            }

            App.Instance.OnSettingUpdated += OnApplicationSettingUpdated;

            _diffView         = diffView;
            _dstFilePath      = dstFilePath;
            _mergeFilePath    = mergeFilePath;
            _currentSheetName = currentSheetName;

            var args = new DiffViewEventArgs <FastGridControl>(null, container, TargetType.First);

            DataGridEventDispatcher.Instance.DispatchPreExecuteDiffEvent(args);

            ReadWorkBook();

            // MergeDataGrid.Model = new SheetGridModel(excelSheet);
            MergeDataGrid.Model = model;

            args = new DiffViewEventArgs <FastGridControl>(MergeDataGrid, container);
            DataGridEventDispatcher.Instance.DispatchFileSettingUpdateEvent(args, fileSetting);

            InitCurrentCell();
        }
        public void OnMouseWheel(DiffViewEventArgs <Grid> e, MouseWheelEventArgs me)
        {
            if (e.Sender != e.Container.Resolve <Grid>(Key))
            {
                return;
            }

            var viewport = e.Container.Resolve <Rectangle>(Key);

            var rowSpan    = Grid.GetRowSpan(viewport);
            var currentRow = Grid.GetRow(viewport);
            var row        = currentRow - (Math.Sign(me.Delta) * rowSpan / 2);
            var last       = Math.Max((e.Sender.RowDefinitions.Count) - Grid.GetRowSpan(viewport), 0);

            row = Math.Max(row, 0);
            row = Math.Min(row, last);

            Grid.SetRow(viewport, row);

            if (currentRow != row)
            {
                var args = new DiffViewEventArgs <Rectangle>(viewport, e.Container);
                ViewportEventDispatcher.Instance.DispatchMoveEvent(args);
            }
        }
 public void OnScrolled(DiffViewEventArgs <RichTextBox> e, ScrollChangedEventArgs se)
 {
     foreach (var rtb in e.Container.ResolveAll <RichTextBox>())
     {
         rtb.ScrollToVerticalOffset(se.VerticalOffset);
         rtb.ScrollToHorizontalOffset(se.HorizontalOffset);
     }
 }
 public void OnRowHeaderReset(DiffViewEventArgs <FastGridControl> e)
 {
     foreach (var grid in e.Container.ResolveAll <FastGridControl>())
     {
         (grid.Model as DiffGridModel).SetRowHeader(-1);
         grid.NotifyRefresh();
     }
 }
Exemple #12
0
 private void LocationGrid_MouseMove(object sender, MouseEventArgs e)
 {
     if (e.LeftButton == MouseButtonState.Pressed)
     {
         var args = new DiffViewEventArgs <Grid>(sender as Grid, container);
         LocationGridEventDispatcher.Instance.DispatchMouseDownEvent(args, e);
     }
 }
        public void OnRowHeaderChanged(DiffViewEventArgs <FastGridControl> e)
        {
            var column = e.Sender.CurrentCell.Column;

            foreach (var grid in e.Container.ResolveAll <FastGridControl>())
            {
                (grid.Model as DiffGridModel).SetRowHeader(column);
                grid.NotifyRefresh();
            }
        }
        public void OnSizeChanged(DiffViewEventArgs <FastGridControl> e, SizeChangedEventArgs se)
        {
            var dataGrid = e.Container.Resolve <FastGridControl>(Key);

            if (dataGrid == null || dataGrid != e.Sender)
            {
                return;
            }

            RecalculateViewport(e.Container.Resolve <Rectangle>(Key), dataGrid);
        }
Exemple #15
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            var args = new DiffViewEventArgs <FastGridControl>(null, container, TargetType.First);

            DataGridEventDispatcher.Instance.DispatchParentLoadEvent(args);

            ExecuteDiff(isStartup: true);

            // In order to enable Ctrl + F immediately after startup.
            ToolExpander.IsExpanded = false;
        }
Exemple #16
0
 public virtual void Dispatch(Action <TListener> action, DiffViewEventArgs <TSender> e)
 {
     if (e.TargetType == TargetType.All)
     {
         Listeners.ForEach(l => action(l));
     }
     else if (e.TargetType == TargetType.First && Listeners.Any())
     {
         action(Listeners.First());
     }
 }
        public void OnScrolled(DiffViewEventArgs <FastGridControl> e)
        {
            var dataGrid = e.Container.Resolve <FastGridControl>(Key);

            if (dataGrid == null || dataGrid == e.Sender)
            {
                return;
            }

            SyncScroll(e.Sender, dataGrid);
            RecalculateViewport(e.Container.Resolve <Rectangle>(Key), dataGrid);
        }
        public void OnHoverRowChanged(DiffViewEventArgs <FastGridControl> e, HoverRowChangedEventArgs he)
        {
            foreach (var grid in e.Container.ResolveAll <FastGridControl>())
            {
                if (e.Sender == grid)
                {
                    continue;
                }

                grid.SetHoverRow(he.Cell);
            }
        }
        public void OnColumnWidthChanged(DiffViewEventArgs <FastGridControl> e, ColumnWidthChangedEventArgs ce)
        {
            foreach (var grid in e.Container.ResolveAll <FastGridControl>())
            {
                if (grid == e.Sender)
                {
                    continue;
                }

                grid.ResizeColumn(ce.NewWidth, ce.Column);
            }
        }
        public void OnGotFocus(DiffViewEventArgs <RichTextBox> e)
        {
            var margin         = 10;
            var textHeightList = e.Container.ResolveAll <RichTextBox>().Select(rtb => CalculateTextBoxHeight(rtb) + margin);

            var height = Math.Min(textHeightList.Max(), App.Instance.MainWindow.Height / 3);

            foreach (var rtb in e.Container.ResolveAll <RichTextBox>())
            {
                rtb.Height = height;
            }
        }
        public void OnPreExecuteDiff(DiffViewEventArgs <FastGridControl> e)
        {
            foreach (var grid in e.Container.ResolveAll <FastGridControl>())
            {
                grid.Model = null;
                grid.ScrollIntoView(FastGridCellAddress.Empty);
                grid.FirstVisibleColumnScrollIndex = 0;
                grid.FirstVisibleRowScrollIndex    = 0;
                grid.InitializeComponent();
            }

            DataGridEventDispatcher.Instance.DispatchApplicationSettingUpdateEvent(e);
        }
Exemple #22
0
        private void DataGrid_SelectedCellsChanged(object sender, FastWpfGrid.SelectionChangedEventArgs e)
        {
            var grid = copyTargetGrid = sender as FastGridControl;

            if (grid == null)
            {
                return;
            }

            copyTargetGrid = grid;

            var args = new DiffViewEventArgs <FastGridControl>(sender as FastGridControl, container);

            DataGridEventDispatcher.Instance.DispatchSelectedCellChangeEvent(args);

            if (!SrcDataGrid.CurrentCell.Row.HasValue || !DstDataGrid.CurrentCell.Row.HasValue)
            {
                return;
            }

            if (!SrcDataGrid.CurrentCell.Column.HasValue || !DstDataGrid.CurrentCell.Column.HasValue)
            {
                return;
            }

            if (SrcDataGrid.Model == null || DstDataGrid.Model == null)
            {
                return;
            }

            var srcValue =
                (SrcDataGrid.Model as DiffGridModel).GetCellText(SrcDataGrid.CurrentCell.Row.Value, SrcDataGrid.CurrentCell.Column.Value, true);
            var dstValue =
                (DstDataGrid.Model as DiffGridModel).GetCellText(DstDataGrid.CurrentCell.Row.Value, DstDataGrid.CurrentCell.Column.Value, true);

            UpdateValueDiff(srcValue, dstValue);

            if (App.Instance.Setting.AlwaysExpandCellDiff)
            {
                var a = new DiffViewEventArgs <RichTextBox>(null, container, TargetType.First);
                ValueTextBoxEventDispatcher.Instance.DispatchGotFocusEvent(a);
            }

            int?row    = DstDataGrid.CurrentCell.Row;
            int?column = DstDataGrid.CurrentCell.Column;

            if (mergeWindow != null)
            {
                mergeWindow.SetCurrentCell(row, column);
            }
        }
Exemple #23
0
        private void ResetColumnHeader_Click(object sender, RoutedEventArgs e)
        {
            var menuItem = sender as MenuItem;

            if (menuItem != null)
            {
                var dataGrid = ((ContextMenu)menuItem.Parent).PlacementTarget as FastGridControl;
                if (dataGrid != null)
                {
                    var args = new DiffViewEventArgs <FastGridControl>(dataGrid, container, TargetType.First);
                    DataGridEventDispatcher.Instance.DispatchColumnHeaderResetEvent(args);
                }
            }
        }
        public void OnFontSizeChanged(DiffViewEventArgs <FastGridControl> e, FontSizeChangedEventArgs fe)
        {
            foreach (var grid in e.Container.ResolveAll <FastGridControl>())
            {
                if (e.Sender == grid)
                {
                    continue;
                }

                grid.CellFontSize = fe.NewSize;
            }

            SyncRowHeight(e.Container);
        }
        public void OnMouseDown(DiffViewEventArgs <Grid> e, MouseEventArgs me)
        {
            if (e.Sender != e.Container.Resolve <Grid>(Key))
            {
                return;
            }

            var viewport = e.Container.Resolve <Rectangle>(Key);

            var rowSpan    = Grid.GetRowSpan(viewport);
            var currentRow = Grid.GetRow(viewport);

            var row = e.Sender.GetRow(me.GetPosition(e.Sender));

            if (!row.HasValue)
            {
                return;
            }

            while (row + rowSpan / 2 > e.Sender.RowDefinitions.Count)
            {
                row--;
            }

            Grid.SetRow(viewport, Math.Max(row.Value - rowSpan / 2, 0));

            var colSpan    = Grid.GetColumnSpan(viewport);
            var currentCol = Grid.GetColumn(viewport);

            var col = e.Sender.GetColumn(me.GetPosition(e.Sender));

            if (!col.HasValue)
            {
                return;
            }

            while (col + colSpan / 2 > e.Sender.ColumnDefinitions.Count)
            {
                col--;
            }

            Grid.SetColumn(viewport, Math.Max(col.Value - colSpan / 2, 0));

            if (currentRow != row || currentCol != col)
            {
                var args = new DiffViewEventArgs <Rectangle>(viewport, e.Container);
                ViewportEventDispatcher.Instance.DispatchMoveEvent(args);
            }
        }
Exemple #26
0
        private void ExecuteDiff(bool isStartup = false)
        {
            if (!File.Exists(SrcPathTextBox.Text) || !File.Exists(DstPathTextBox.Text))
            {
                return;
            }

            var args = new DiffViewEventArgs <FastGridControl>(null, container, TargetType.First);

            DataGridEventDispatcher.Instance.DispatchPreExecuteDiffEvent(args);

            var srcPath = SrcPathTextBox.Text;
            var dstPath = DstPathTextBox.Text;

            Debug.Assert(Path.GetExtension(srcPath) == Path.GetExtension(dstPath), $"Compared files should have the same extension.");

            var workbooks   = ReadWorkbooks();
            var srcWorkbook = workbooks.Item1;
            var dstWorkbook = workbooks.Item2;

            DstSheetCombobox.SelectedIndex = SrcSheetCombobox.SelectedIndex;

            // SrcSheetCombobox.SelectedIndex = diffConfig.SrcSheetIndex;
            // DstSheetCombobox.SelectedIndex = diffConfig.DstSheetIndex;

            srcSheetName = SrcSheetCombobox.SelectedItem.ToString();
            dstSheetName = DstSheetCombobox.SelectedItem.ToString();

            var srcSheet = srcWorkbook.Sheets[srcSheetName];
            var dstSheet = dstWorkbook.Sheets[dstSheetName];

            SourceSheet = srcSheet;
            DestSheet   = dstSheet;

            LeftWorkbook  = srcWorkbook;
            RightWorkbook = dstWorkbook;

            if (srcSheet.Rows.Count > 10000 || dstSheet.Rows.Count > 10000)
            {
                MessageBox.Show(Properties.Resources.Msg_WarnSize);
            }

            SheetDiff = ExecuteDiff(srcSheet, dstSheet);

            RefreshBySheet(isStartup);
        }
Exemple #27
0
        public void DataGrid_SelectedCellsChanged(object sender, FastWpfGrid.SelectionChangedEventArgs e)
        {
            var grid = copyTargetGrid = sender as FastGridControl;

            if (grid == null)
            {
                return;
            }

            copyTargetGrid = grid;

            var args = new DiffViewEventArgs <FastGridControl>(sender as FastGridControl, container);

            DataGridEventDispatcher.Instance.DispatchSelectedCellChangeEvent(args);


            if (!MergeDataGrid.CurrentCell.Row.HasValue)
            {
                return;
            }

            if (!MergeDataGrid.CurrentCell.Column.HasValue)
            {
                return;
            }

            if (MergeDataGrid.Model == null)
            {
                return;
            }

            var value = (MergeDataGrid.Model as DiffGridModel).GetCellText(MergeDataGrid.CurrentCell.Row.Value, MergeDataGrid.CurrentCell.Column.Value, true);

            UpdateValue(value);

            if (App.Instance.Setting.AlwaysExpandCellDiff)
            {
                var a = new DiffViewEventArgs <RichTextBox>(null, container, TargetType.First);
                ValueTextBoxEventDispatcher.Instance.DispatchGotFocusEvent(a);
            }

            if (_diffView != null)
            {
                _diffView.SetCurrentCell(MergeDataGrid.CurrentCell.Row, MergeDataGrid.CurrentCell.Column);
            }
        }
        public void OnParentLoaded(DiffViewEventArgs <FastGridControl> e)
        {
            foreach (var grid in e.Container.ResolveAll <FastGridControl>())
            {
                var a = new DiffViewEventArgs <FastGridControl>(grid, e.Container);

                grid.ScrolledModelRows += (sender, args)
                                          => DataGridEventDispatcher.Instance.DispatchScrollEvnet(a);
                grid.ScrolledModelColumns += (sender, args)
                                             => DataGridEventDispatcher.Instance.DispatchScrollEvnet(a);
                grid.ColumnWidthChanged += (sender, args)
                                           => DataGridEventDispatcher.Instance.DispatchColumnWidthChangeEvent(a, args);
                grid.HoverRowChanged += (sender, args)
                                        => DataGridEventDispatcher.Instance.DispatchHoverRowChangeEvent(a, args);
                grid.FontSizeChanged += (sender, args)
                                        => DataGridEventDispatcher.Instance.DispatchFontSizeChangeEvent(a, args);
            }
        }
Exemple #29
0
        private void RefreshBySheet(bool isStartup, bool edit = false)
        {
            SrcDataGrid.Model = new DiffGridModel(SheetDiff, DiffType.Source);
            DstDataGrid.Model = new DiffGridModel(SheetDiff, DiffType.Dest);

            var fileSettings   = FindFileSettings(isStartup);
            var srcFileSetting = fileSettings.Item1;
            var dstFileSetting = fileSettings.Item2;

            var args1 = new DiffViewEventArgs <FastGridControl>(null, container, TargetType.First);

            if (!edit)
            {
                var args = new DiffViewEventArgs <FastGridControl>(SrcDataGrid, container);
                DataGridEventDispatcher.Instance.DispatchFileSettingUpdateEvent(args, srcFileSetting);

                args = new DiffViewEventArgs <FastGridControl>(DstDataGrid, container);
                DataGridEventDispatcher.Instance.DispatchFileSettingUpdateEvent(args, dstFileSetting);


                DataGridEventDispatcher.Instance.DispatchDisplayFormatChangeEvent(args1, ShowOnlyDiffRadioButton.IsChecked.Value);
                DataGridEventDispatcher.Instance.DispatchPostExecuteDiffEvent(args1);

                var summary = SheetDiff.CreateSummary();
                GetViewModel().UpdateDiffSummary(summary);

                if (App.Instance.Setting.NotifyEqual && !summary.HasDiff)
                {
                    MessageBox.Show(Properties.Resources.Message_NoDiff);
                }
            }


            if (!App.Instance.KeepFileHistory)
            {
                App.Instance.UpdateRecentFiles(SrcPathTextBox.Text, DstPathTextBox.Text);
            }

            if (App.Instance.Setting.FocusFirstDiff)
            {
                MoveNextModifiedCell();
            }
        }
        public void OnDiffDisplayFormatChanged(DiffViewEventArgs <FastGridControl> e, bool onlyDiff)
        {
            foreach (var grid in e.Container.ResolveAll <FastGridControl>())
            {
                if (onlyDiff)
                {
                    (grid.Model as DiffGridModel)?.HideEqualRows();
                }
                else
                {
                    (grid.Model as DiffGridModel)?.ShowEqualRows();
                }

                var args = new DiffViewEventArgs <FastGridControl>(grid, e.Container);
                DataGridEventDispatcher.Instance.DispatchModelUpdateEvent(args);

                grid.FirstVisibleRowScrollIndex = 0;
            }

            SyncRowHeight(e.Container);
        }