Ejemplo n.º 1
0
 unsafe void Api.IDropTarget.DragOver(int grfKeyState, POINT p, ref int effect)
 {
     if ((effect = _GetEffect(effect, grfKeyState)) != 0)
     {
         _GetDropPos(ref p, out _);
         var z = new Sci_DragDropData {
             x = p.x, y = p.y
         };
         _sci.Call(SCI_DRAGDROP, 1, &z);
     }
 }
Ejemplo n.º 2
0
        unsafe void _Drop(POINT xy, int effect)
        {
            _GetDropPos(ref xy, out int pos8);
            var z = new Sci_DragDropData {
                x = xy.x, y = xy.y
            };
            string s = null;
            var    b = new StringBuilder();
            int    what = 0, index = 0;

            if (_justText)
            {
                s = _data.text;
            }
            else
            {
                _sci.Call(SCI_DRAGDROP, 2, &z);                 //just hides the drag indicator and sets caret position

                if (_sci._fn.IsCodeFile)
                {
                    string mi = _data.scripts
                                                ? "1 string s = name;|2 string s = path;|3 script.run(path);|4 t[name] = o => script.run(path);"
                                                : "11 string s = path;|12 run.it(path);|13 t[name] = o => run.it(path);";
                    what = popupMenu.showSimple(mi);
                    if (what == 0)
                    {
                        return;
                    }
                }

                if (_data.scripts)
                {
                    var a = Panels.Files.TreeControl.DragDropFiles;
                    if (a != null)
                    {
                        foreach (var f in a)
                        {
                            _AppendScriptOrLink(f.ItemPath, f.Name, f);
                        }
                    }
                }
                else if (_data.files != null)
                {
                    foreach (var path in _data.files)
                    {
                        _AppendFileOrShell(path);
                    }
                }
                else if (_data.shell != null)
                {
                    _GetShell(_data.shell, out var shells, out var names);
                    if (shells != null)
                    {
                        for (int i = 0; i < shells.Length; i++)
                        {
                            _AppendFileOrShell(shells[i], names[i]);
                        }
                    }
                }
                else if (_data.linkName != null)
                {
                    _AppendScriptOrLink(_data.text, _GetLinkName(_data.linkName));
                }
                s = b.ToString();
            }

            if (!s.NE())
            {
                if (_justText)                   //a simple drag-drop inside scintilla or text-only from outside
                {
                    var s8 = Encoding.UTF8.GetBytes(s);
                    fixed(byte *p8 = s8)
                    {
                        z.text = p8;
                        z.len  = s8.Length;
                        if (0 == ((DragDropEffects)effect & DragDropEffects.Move))
                        {
                            z.copy = 1;
                        }
                        CodeInfo.Pasting(_sci);
                        _sci.Call(SCI_DRAGDROP, 2, &z);
                    }
                }
                else                     //file, script or URL
                {
                    InsertCode.Statements(s, ICSFlags.NoFocus);
                }
                if (!_sci.IsFocused && _sci.Hwnd.Window.IsActive)                  //note: don't activate window; let the drag source do it, eg Explorer activates on drag-enter.
                {
                    _sci._noModelEnsureCurrentSelected = true;                     //don't scroll treeview to currentfile
                    _sci.Focus();
                    _sci._noModelEnsureCurrentSelected = false;
                }
            }
            else
            {
                _sci.Call(SCI_DRAGDROP, 3);
            }

            void _AppendFileOrShell(string path, string name = null)
            {
                if (b.Length > 0)
                {
                    b.AppendLine();
                }
                var pi = new TUtil.PathInfo(path, name);

                b.Append(pi.FormatCode(what - 11, ++index));
            }

            void _AppendScriptOrLink(string path, string name, FileNode fn = null)
            {
                if (b.Length > 0)
                {
                    b.AppendLine();
                }
                if (what == 0)
                {
                    b.Append(path);
                }
                else
                {
                    if (what == 4)
                    {
                        name = name.RemoveSuffix(".cs");
                    }
                    name = name.Escape();

                    if (what is 4 or 13)
                    {
                        var t = InsertCodeUtil.GetNearestLocalVariableOfType("Au.toolbar", "Au.popupMenu");
                        b.Append($"{t?.Name ?? "t"}[\"{name}\"] = o => ");
                    }