Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/04/14 13:08:49 (10 years ago)
Author:
mleitner
Message:

Improve context menu replace performance by disabling repaint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs

    r10934 r10938  
    3636    private bool notOwnEvent = true;
    3737    private bool isSearching = false;
     38    private bool isReplacing = false;
    3839    private bool updateOnMouseUp = false;
    3940    private SearchAndReplaceDialog findAndReplaceDialog;
     
    8081    protected override void dataGridView_SelectionChanged(object sender, EventArgs e) {
    8182      if (Content != null) {
    82         if (!isSearching) {
     83        if (!isSearching && !isReplacing) {
    8384
    8485          if (Control.MouseButtons == MouseButtons.Left) {
     
    373374    private void Replace(IDictionary<int, IList<int>> cells) {
    374375      if (findAndReplaceDialog != null) {
    375         switch (findAndReplaceDialog.GetReplaceAction()) {
    376           case ReplaceAction.Value:
    377             Content.ManipulationLogic.ReplaceIndicesByValue(cells, findAndReplaceDialog.GetReplaceText());
    378             break;
    379           case ReplaceAction.Average:
    380             Content.ManipulationLogic.ReplaceIndicesByAverageValue(cells, false);
    381             break;
    382           case ReplaceAction.Median:
    383             Content.ManipulationLogic.ReplaceIndicesByMedianValue(cells, false);
    384             break;
    385           case ReplaceAction.Random:
    386             Content.ManipulationLogic.ReplaceIndicesByRandomValue(cells, false);
    387             break;
    388           case ReplaceAction.MostCommon:
    389             Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(cells, false);
    390             break;
    391           case ReplaceAction.Interpolation:
    392             Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(cells);
    393             break;
    394         }
     376        ReplaceTransaction(() => {
     377          switch (findAndReplaceDialog.GetReplaceAction()) {
     378            case ReplaceAction.Value:
     379              Content.ManipulationLogic.ReplaceIndicesByValue(cells, findAndReplaceDialog.GetReplaceText());
     380              break;
     381            case ReplaceAction.Average:
     382              Content.ManipulationLogic.ReplaceIndicesByAverageValue(cells, false);
     383              break;
     384            case ReplaceAction.Median:
     385              Content.ManipulationLogic.ReplaceIndicesByMedianValue(cells, false);
     386              break;
     387            case ReplaceAction.Random:
     388              Content.ManipulationLogic.ReplaceIndicesByRandomValue(cells, false);
     389              break;
     390            case ReplaceAction.MostCommon:
     391              Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(cells, false);
     392              break;
     393            case ReplaceAction.Interpolation:
     394              Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(cells);
     395              break;
     396          }
     397        });
    395398      }
    396399    }
     
    522525    }
    523526
     527    private void StartReplacing() {
     528      isReplacing = true;
     529      SuspendRepaint();
     530    }
     531
     532    private void StopReplacing() {
     533      isReplacing = false;
     534      ResumeRepaint(true);
     535    }
     536
     537    private void ReplaceTransaction(Action action) {
     538      StartReplacing();
     539      action();
     540      StopReplacing();
     541    }
     542
    524543    private void ReplaceWithAverage_Column_Click(object sender, EventArgs e) {
    525       Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), false);
     544      ReplaceTransaction(() => {
     545        Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), false);
     546      });
    526547    }
    527548    private void ReplaceWithAverage_Selection_Click(object sender, EventArgs e) {
    528       Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), true);
     549      ReplaceTransaction(() => {
     550        Content.ManipulationLogic.ReplaceIndicesByAverageValue(GetSelectedCells(), true);
     551      });
    529552    }
    530553
    531554    private void ReplaceWithMedian_Column_Click(object sender, EventArgs e) {
    532       Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), false);
     555      ReplaceTransaction(() => {
     556        Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), false);
     557      });
    533558    }
    534559    private void ReplaceWithMedian_Selection_Click(object sender, EventArgs e) {
    535       Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), true);
     560      ReplaceTransaction(() => {
     561        Content.ManipulationLogic.ReplaceIndicesByMedianValue(GetSelectedCells(), true);
     562      });
    536563    }
    537564
    538565    private void ReplaceWithRandom_Column_Click(object sender, EventArgs e) {
    539       Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), false);
     566      ReplaceTransaction(() => {
     567        Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), false);
     568      });
    540569    }
    541570    private void ReplaceWithRandom_Selection_Click(object sender, EventArgs e) {
    542       Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), true);
     571      ReplaceTransaction(() => {
     572        Content.ManipulationLogic.ReplaceIndicesByRandomValue(GetSelectedCells(), true);
     573      });
    543574    }
    544575
    545576    private void ReplaceWithMostCommon_Column_Click(object sender, EventArgs e) {
    546       Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), false);
     577      ReplaceTransaction(() => {
     578        Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), false);
     579      });
    547580    }
    548581    private void ReplaceWithMostCommon_Selection_Click(object sender, EventArgs e) {
    549       Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), true);
     582      ReplaceTransaction(() => {
     583        Content.ManipulationLogic.ReplaceIndicesByMostCommonValue(GetSelectedCells(), true);
     584      });
    550585    }
    551586
    552587    private void ReplaceWithInterpolation_Column_Click(object sender, EventArgs e) {
    553       Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(GetSelectedCells());
     588      ReplaceTransaction(() => {
     589        Content.ManipulationLogic.ReplaceIndicesByLinearInterpolationOfNeighbours(GetSelectedCells());
     590      });
    554591    }
    555592
    556593    private void ReplaceWithSmoothing_Selection_Click(object sender, EventArgs e) {
    557       Content.ManipulationLogic.ReplaceIndicesBySmoothing(GetSelectedCells());
     594      ReplaceTransaction(() => {
     595        Content.ManipulationLogic.ReplaceIndicesBySmoothing(GetSelectedCells());
     596      });
    558597    }
    559598
Note: See TracChangeset for help on using the changeset viewer.