예제 #1
0
        protected override void Initialize(IPadWindow window)
        {
            this.window = window;
            dragPad     = new FigmaDragAndDropContent();

            window.PadContentHidden += Container_PadHidden;
            window.PadContentShown  += Container_PadShown;

            widget = new Gtk.GtkNSViewHost(dragPad);

            widget.DragBegin += (o, args) => {
                if (!isDragging)
                {
                    DesignerSupport.DesignerSupport.Service.ToolboxService.DragSelectedItem(widget, args.Context);
                    isDragging = true;
                }
            };

            widget.DragDataGet += (object o, DragDataGetArgs args) => {
                if (selectedNode is IDragDataToolboxNode node)
                {
                    foreach (var format in node.Formats)
                    {
                        args.SelectionData.Set(Gdk.Atom.Intern(format, false), 8, node.GetData(format));
                    }
                }
            };

            widget.DragEnd += (o, args) => {
                isDragging = false;
            };

            dragPad.SelectCode += (sender, e) =>
            {
                if (!string.IsNullOrEmpty(e))
                {
                    var selected = new TextToolboxNode(e);
                    DesignerSupport.DesignerSupport.Service.ToolboxService.SelectItem(selected);
                    DesignerSupport.DesignerSupport.Service.ToolboxService.UseSelectedItem();
                }
            };

            dragPad.DragSourceSet += (s, e) => {
                targets = CreateDefaultTargeList();
                targets.AddTable(e);
            };

            dragPad.DragBegin += (object sender, EventArgs e) => {
                var code = dragPad.GetCode(dragPad.SelectedNode);
                selectedNode = new TextToolboxNode(code);
                DesignerSupport.DesignerSupport.Service.ToolboxService.SelectItem(selectedNode);

                Gtk.Drag.SourceUnset(widget);
                if (selectedNode is IDragDataToolboxNode node)
                {
                    foreach (var format in node.Formats)
                    {
                        targets.Add(format, 0, 0);
                    }
                }
                // Gtk.Application.CurrentEvent and other copied gdk_events seem to have a problem
                // when used as they use gdk_event_copy which seems to crash on de-allocating the private slice.
                IntPtr currentEvent = Components.GtkWorkarounds.GetCurrentEventHandle();
                Gtk.Drag.Begin(widget, targets, Gdk.DragAction.Copy | Gdk.DragAction.Move, 1, new Gdk.Event(currentEvent, false));

                // gtk_drag_begin does not store the event, so we're okay
                Components.GtkWorkarounds.FreeEvent(currentEvent);
            };

            widget.ShowAll();

            if (IdeApp.Workbench != null)
            {
                //IdeApp.Workbench.ActiveDocumentChanged += Workbench_ActiveDocumentChanged;
                IdeApp.Workbench.ActiveDocumentChanged += onActiveDocChanged;  // += new EventHandler(onActiveDocChanged);
                onActiveDocChanged(null, null);
            }
        }
예제 #2
0
        protected override void Initialize(IPadWindow window)
        {
            this.window = window;
            dragPad     = new FigmaDragAndDropContent();

            window.PadContentHidden += Container_PadHidden;
            window.PadContentShown  += Container_PadShown;

            widget           = GtkMacInterop.NSViewToGtkWidget(dragPad);
            widget.CanFocus  = true;
            widget.Sensitive = true;

            widget.DragBegin += (o, args) => {
                //if (!isDragging)
                //{
                //    var processedNode = dragPad.GetProcessedNode(dragPad.SelectedNode);
                //    selected = new TemplateToolboxNode(new Ide.CodeTemplates.CodeTemplate() { Code = processedNode.Code });
                //    CurrentConsumer.DragItem(selected, widget, args.Context);
                //    //DesignerSupport.Service.ToolboxService.DragSelectedItem(widget, args.Context);
                //    isDragging = true;
                //}
            };

            widget.DragEnd += (o, args) => {
                isDragging = false;
            };

            widget.Focused += (s, e) => {
                // toolbox
            };

            dragPad.SelectCode += (sender, e) =>
            {
                if (!string.IsNullOrEmpty(e))
                {
                    try
                    {
                        var editor   = IdeApp.Workbench.ActiveDocument.GetContent <ITextView>();
                        var position = editor.Caret.Position.BufferPosition.Position;
                        editor.TextBuffer.Insert(position, e);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            };

            dragPad.DragSourceSet += (s, e) => {
                targets = new Gtk.TargetList();
                targets.AddTable(e);
            };
            dragPad.DragBegin += (object sender, EventArgs e) => {
                if (!isDragging)
                {
                    Gtk.Drag.SourceUnset(widget);

                    // Gtk.Application.CurrentEvent and other copied gdk_events seem to have a problem
                    // when used as they use gdk_event_copy which seems to crash on de-allocating the private slice.
                    IntPtr currentEvent = Components.GtkWorkarounds.GetCurrentEventHandle();
                    Gtk.Drag.Begin(widget, targets, Gdk.DragAction.Copy | Gdk.DragAction.Move, 1, new Gdk.Event(currentEvent));

                    // gtk_drag_begin does not store the event, so we're okay
                    //Components.GtkWorkarounds.FreeEvent(currentEvent);
                }
            };

            widget.ShowAll();


            if (IdeApp.Workbench != null)
            {
                //IdeApp.Workbench.ActiveDocumentChanged += Workbench_ActiveDocumentChanged;
                IdeApp.Workbench.ActiveDocumentChanged += onActiveDocChanged;  // += new EventHandler(onActiveDocChanged);
                onActiveDocChanged(null, null);
            }
        }