Exemplo n.º 1
0
 /// <summary>
 /// Defines the method to be called when the action is invoked.
 /// </summary>
 /// <param name="parameter">Data used by the action. If the action does not require data to be passed, this object can be set to null.</param>
 public override void Execute(object parameter)
 {
     if (CanExecute(parameter))
     {
         Excel view = parameter as Excel;
         try
         {
             view.SuspendFloatingObjectsInvalidate();
             SaveState();
             List <SpreadChart>    list  = new List <SpreadChart>();
             List <Picture>        list2 = new List <Picture>();
             List <FloatingObject> list3 = new List <FloatingObject>();
             foreach (string str in _movingExtent.Names)
             {
                 SpreadChart    chart        = _worksheet.FindChart(str);
                 Picture        picture      = _worksheet.FindPicture(str);
                 FloatingObject obj2         = _worksheet.FindFloatingObject(str);
                 FloatingObject pastedObject = null;
                 if (chart != null)
                 {
                     SpreadChart item = chart.Clone() as SpreadChart;
                     pastedObject     = item;
                     item.Location    = new Point(chart.Location.X + _movingExtent.OffsetX, chart.Location.Y + _movingExtent.OffsetY);
                     item.Size        = chart.Size;
                     item.Name        = Dt.Cells.UndoRedo.GenerateNameHelper.GenerateChartName(_worksheet);
                     chart.IsSelected = false;
                     item.IsSelected  = true;
                     list.Add(item);
                     view.ActiveSheet.Charts.Add(item);
                 }
                 if (picture != null)
                 {
                     Picture picture2 = picture.Clone() as Picture;
                     pastedObject        = picture2;
                     picture2.Location   = new Point(picture.Location.X + _movingExtent.OffsetX, picture.Location.Y + _movingExtent.OffsetY);
                     picture2.Size       = picture.Size;
                     picture2.Name       = Dt.Cells.UndoRedo.GenerateNameHelper.GeneratePictureName(_worksheet);
                     picture.IsSelected  = false;
                     picture2.IsSelected = true;
                     list2.Add(picture2);
                     view.ActiveSheet.Pictures.Add(picture2);
                 }
                 if (obj2 != null)
                 {
                     FloatingObject obj4 = obj2.Clone() as FloatingObject;
                     pastedObject    = obj4;
                     obj4.Location   = new Point(obj2.Location.X + _movingExtent.OffsetX, obj2.Location.Y + _movingExtent.OffsetY);
                     obj4.Size       = obj2.Size;
                     obj4.Name       = Dt.Cells.UndoRedo.GenerateNameHelper.GenerateFloatingObjectName(_worksheet);
                     obj2.IsSelected = false;
                     obj4.IsSelected = true;
                     list3.Add(obj4);
                     view.ActiveSheet.FloatingObjects.Add(obj4);
                 }
                 if (pastedObject != null)
                 {
                     view.RaiseFloatingObjectPasted(_worksheet, pastedObject);
                 }
             }
             if (list.Count > 0)
             {
                 _savedCharts = list.ToArray();
             }
             if (list2.Count > 0)
             {
                 _savedPictures = list2.ToArray();
             }
             if (list3.Count > 0)
             {
                 _savedObjects = list3.ToArray();
             }
         }
         finally
         {
             view.ResumeFloatingObjectsInvalidate();
         }
         view.InvalidateFloatingObjectLayout();
     }
 }