Beispiel #1
0
 private void DoDragDrop(MouseEventArgs e, IDragableCommandModel cmd)
 {
     ////_isDragging = true;
     DataObject      data = new DataObject(typeof(IDragableCommandModel), cmd);
     DragDropEffects de   = DragDrop.DoDragDrop(this, data, DragDropEffects.Copy);
     ////_isDragging = false;
 }
Beispiel #2
0
        protected override void OnPreviewMouseMove(MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed && !_isDragging)
            {
                CommandButton selectedItem = this.SelectedItem as CommandButton;
                if (selectedItem == null)
                {
                    return;
                }

                IDragableCommandModel cmd = selectedItem.CommandModel as IDragableCommandModel;
                if (cmd == null)
                {
                    return;
                }

                Point position = e.GetPosition(null);

                if (Math.Abs(position.X - _startPoint.X) > SystemParameters.MinimumHorizontalDragDistance ||
                    Math.Abs(position.Y - _startPoint.Y) > SystemParameters.MinimumVerticalDragDistance)
                {
                    DoDragDrop(e, cmd);
                    this.SelectedIndex = -1;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Handles the Drop event of the canvas.
        /// When a IDragableCommand, which represents an item from a ribbon gallery, is dropped on the canvas, its OnDragDropExecute is called.
        /// </summary>
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);

            IDragableCommandModel cmd = (IDragableCommandModel)e.Data.GetData(typeof(IDragableCommandModel));

            if (cmd != null)
            {
                cmd.OnDragDropExecute(e.GetPosition(_itemsControl));
                e.Handled = true;
                return;
            }

            string fileName = IsSingleFile(e);

            if (fileName != null)
            {
                //Check if the datamodel is ready
                if (!(_CanvasViewModel._DocumentViewModel.dm_DocumentDataModel.State == DataModel.ModelState.Ready ||
                      _CanvasViewModel._DocumentViewModel.dm_DocumentDataModel.State == DataModel.ModelState.Invalid))
                {
                    return;
                }

                Application.Current.MainWindow.Activate();
                if (!_CanvasViewModel._DocumentViewModel.QuerySaveChanges())
                {
                    return;
                }

                try
                {
                    // Open the document.
                    _CanvasViewModel._DocumentViewModel.LoadFile(fileName);
                }
                catch (Exception ex)
                {
                    ExceptionManager.Register(ex,
                                              "Operation aborted.",
                                              "An error occured while opening the file " + fileName + ".");

                    ExceptionManager.ShowErrorDialog(true);
                }
                return;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Handles the Drop event of the canvas.
        /// When a IDragableCommand, which represents an item from a ribbon gallery, is dropped on the canvas, its OnDragDropExecute is called.
        /// </summary>
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);

            if (this.mPart_ItemsControl == null)
            {
                return;
            }

            if (e.Data.GetDataPresent(typeof(IDragableCommandModel)))
            {
                IDragableCommandModel cmd = (IDragableCommandModel)e.Data.GetData(typeof(IDragableCommandModel));

                cmd.OnDragDropExecute(e.GetPosition(this.mPart_ItemsControl));
                e.Handled = true;
                return;
            }

            if (e.Data.GetDataPresent(typeof(MiniUML.Framework.helpers.DragObject)))
            {
                try
                {
                    MiniUML.Framework.helpers.DragObject dragObject = (MiniUML.Framework.helpers.DragObject)e.Data.GetData(typeof(MiniUML.Framework.helpers.DragObject));

                    IDragableCommandModel c = dragObject.ObjectInstance as IDragableCommandModel;

                    if (c == null)
                    {
                        return;
                    }

                    Point p = e.GetPosition(this.mPart_ItemsControl);

                    if (p != null)
                    {
                        c.OnDragDropExecute(p);
                    }

                    return;
                }
                catch (Exception ex)
                {
                    Msg.Show(ex, "Drag & Drop operation aborted on error",
                             "An erro occurred", MsgBoxButtons.OK);
                }
            }

            string fileName = this.IsSingleFile(e);

            if (fileName != null)
            {
                // Check if the datamodel is ready
                if (!(this.CanvasViewModel.DocumentViewModel.dm_DocumentDataModel.State == DataModel.ModelState.Ready ||
                      this.CanvasViewModel.DocumentViewModel.dm_DocumentDataModel.State == DataModel.ModelState.Invalid))
                {
                    return;
                }

                Application.Current.MainWindow.Activate();

                if (this.CanvasViewModel.DocumentViewModel.QuerySaveChanges() == false)
                {
                    return;
                }

                try
                {
                    // Open the document.
                    CanvasViewModel.DocumentViewModel.LoadFile(fileName);
                }
                catch (Exception ex)
                {
                    Msg.Show(ex, string.Format(MiniUML.Framework.Local.Strings.STR_OpenFILE_MSG, fileName),
                             MiniUML.Framework.Local.Strings.STR_OpenFILE_MSG_CAPTION, MsgBoxButtons.OK);
                }

                return;
            }
        }