예제 #1
0
        private void Dlg_Drop(object sender, DragEventArgs eDropEvent)
        {
            // init base code
            //base.OnDrop(eDropEvent);  // do not use this code does all needed

            //string[] dataFormats = eDropEvent.Data.GetFormats(true);

            // If the DataObject contains string data, extract it.
            if (eDropEvent.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] FileList = (string[])eDropEvent.Data.GetData(DataFormats.FileDrop, false);

                CreateShortCuts(FileList);
                PlaceShortcutsintoView();

                eDropEvent.Handled = true;
            }
            else if (eDropEvent.Data.GetDataPresent(SC_DROP_FORMAT))
            {
                ShortcutDropData sdd      = (ShortcutDropData)eDropEvent.Data.GetData(SC_DROP_FORMAT);
                Shortcut         s        = sdd._parent.Children[sdd._idx] as Shortcut;
                string[]         FileList = new string[] { s.lnkData.ShortcutAddress };

                // a drop onto the icon also sets off a drop onto a dialog - do not reproduce the icon
                var items = Shortcuts.Where(x => x.lnkData.ShortcutAddress == FileList[0]);
                if (items.Count() == 0)
                {
                    CreateShortCuts(FileList);
                    PlaceShortcutsintoView();

                    // remove the shortcut from the parent panel before pacing it here
                    ((KO_Dialog)sdd._parent.Parent).DeleteShortcut(s);
                    //MainPanel.Children.Add(s);
                }

                eDropEvent.Handled = true;
            }
            else
            {
                eDropEvent.Handled = false;
            }
        }
예제 #2
0
        private void SC_mouseMove(object sender, MouseEventArgs e)
        {
            // Get the current mouse position
            System.Windows.Point mousePos = e.GetPosition(null);
            Vector diff = startPoint - mousePos;

            if (e.LeftButton == MouseButtonState.Pressed &&
                (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                 Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                // Get the dragged item
                Shortcut sc = sender as Shortcut;
                if (MainPanel.Children.Contains(sc))
                {
                    // Can just pass its index or the whole object
                    //int sourceidx = MainPanel.Children.IndexOf(sc);
                    ShortcutDropData sdd = new ShortcutDropData(MainPanel.Children.IndexOf(sc), sc.Parent as UniformGrid);
                    //DataObject dragData = new DataObject(SC_DROP_FORMAT, sc);
                    DataObject dragData = new DataObject(SC_DROP_FORMAT, sdd); // sourceidx);
                    DragDrop.DoDragDrop(sc, dragData, DragDropEffects.Move);   //  DragDropEffects.Copy);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Drop an icon onto another switching the positions with each other
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SC_drop(object sender, DragEventArgs e)
        {
            try
            {
                //string[] dataFormats = e.Data.GetFormats(true);

                // If the DataObject contains the correct format, extract the info and move the icons
                if (e.Data.GetDataPresent(SC_DROP_FORMAT))
                {
                    ShortcutDropData sdd        = (ShortcutDropData)e.Data.GetData(SC_DROP_FORMAT);
                    Shortcut         TargetIcon = (Shortcut)e.OriginalSource;

                    if (sdd._parent == TargetIcon.Parent)
                    {
                        Shortcut SourceIcon = (Shortcut)MainPanel.Children[sdd._idx];

                        //Shortcut trg = (Shortcut)this.InputHitTest(e.GetPosition(this));
                        if (TargetIcon != SourceIcon)
                        {
                            // remove the shortcut from the list, the panel and destroy itself
                            if (SourceIcon != null && MainPanel.Children.Contains(SourceIcon))
                            {
                                // must be removed first before inserting it with new index
                                int Source_idx = MainPanel.Children.IndexOf(SourceIcon);
                                int Target_idx = MainPanel.Children.IndexOf(TargetIcon);

                                DeleteShortcut(TargetIcon);
                                MainPanel.Children.Insert(Source_idx, TargetIcon);
                                Shortcuts.Add(TargetIcon);

                                DeleteShortcut(SourceIcon);
                                MainPanel.Children.Insert(Target_idx, SourceIcon);
                                Shortcuts.Add(SourceIcon);

                                // delete the icon with the lowest index
                                //if (Source_idx > Target_idx)
                                //{
                                //    //DeleteShortcut(TargetIcon);
                                //    MainPanel.Children.Insert
                                //}
                                //else
                                //{
                                //    DeleteShortcut(SourceIcon);
                                //}

                                //if (MainPanel.Children.Count < Target_idx)
                                //    MainPanel.Children.Add(SourceIcon);
                                //else
                                //    MainPanel.Children.Insert(Target_idx, SourceIcon);

                                //if (MainPanel.Children.Count < Source_idx)
                                //    MainPanel.Children.Add(TargetIcon);
                                //else
                                //   MainPanel.Children.Insert(Source_idx, TargetIcon);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lnkio.WriteProgramLog(ex.Message);
                //throw new Exception(ex.Message);
            }
            //finally{}//throw new NotImplementedException();
        }