Exemple #1
0
        protected void OnElementSelected(object controller, ElementEventArgs args)
        {
            ElementProperties                elementProperties   = null;
            IFlowSharpCodeEditorService      csCodeEditorService = ServiceManager.Get <IFlowSharpCodeEditorService>();
            IFlowSharpScintillaEditorService editorService       = ServiceManager.Get <IFlowSharpScintillaEditorService>();

            if (args.Element != null)
            {
                GraphicElement el = args.Element;
                System.Diagnostics.Trace.WriteLine("*** ON ELEMENT SELECTED " + el.Id.ToString());
                elementProperties = el.CreateProperties();

                if (!String.IsNullOrEmpty(csCodeEditorService.Filename))
                {
                    // Save last position.
                    int curpos = csCodeEditorService.GetPosition();
                    fileCaretPos[csCodeEditorService.Filename] = curpos;
                    System.Diagnostics.Trace.WriteLine("*** " + csCodeEditorService.Filename + " => SET CURRENT POS: " + curpos);
                }

                string code;
                el.Json.TryGetValue("Code", out code);
                csCodeEditorService.SetText("C#", code ?? String.Empty);

                string fn = el.Id.ToString();               // Use something that is unique for this shape's code.
                System.Diagnostics.Trace.WriteLine("*** " + fn + " => SET ID");
                csCodeEditorService.Filename = fn;

                // Set the last known position if we have one.
                int pos;

                if (fileCaretPos.TryGetValue(fn, out pos))
                {
                    System.Diagnostics.Trace.WriteLine("*** " + fn + " => SET PREVIOUS POS: " + pos);
                    csCodeEditorService.SetPosition(pos);
                }
                else
                {
                    // A newly seen document, set the caret to pos 0 so the editor doesn't retain
                    // the previous scrollbar location.
                    csCodeEditorService.SetPosition(0);
                }

                el.Json.TryGetValue("python", out code);
                editorService.SetText("python", code ?? String.Empty);
            }
            else
            {
                csCodeEditorService.SetText("C#", String.Empty);
                editorService.SetText("python", String.Empty);
            }
        }
Exemple #2
0
        public override void FinishedInitialization()
        {
            base.FinishedInitialization();
            IFlowSharpService                fss = ServiceManager.Get <IFlowSharpService>();
            IFlowSharpCodeEditorService      ces = ServiceManager.Get <IFlowSharpCodeEditorService>();
            IFlowSharpScintillaEditorService ses = ServiceManager.Get <IFlowSharpScintillaEditorService>();

            fss.FlowSharpInitialized += OnFlowSharpInitialized;
            fss.ContentResolver      += OnContentResolver;
            fss.NewCanvas            += OnNewCanvas;
            ces.TextChanged          += OnCSharpEditorServiceTextChanged;
            ses.TextChanged          += OnScintillaEditorServiceTextChanged;
            InitializeEditorsMenu();
        }
Exemple #3
0
        protected void CreateEditor(string language)
        {
            Control             docEditor      = null;
            IDockingFormService dockingService = ServiceManager.Get <IDockingFormService>();
            Control             d = FindDocument(dockingService, FlowSharpCodeServiceInterfaces.Constants.META_CSHARP_EDITOR);

            if (d == null)
            {
                d = FindDocument(dockingService, FlowSharpCodeServiceInterfaces.Constants.META_SCINTILLA_EDITOR);

                if (d == null)
                {
                    d = FindDocument(dockingService, FlowSharpServiceInterfaces.Constants.META_CANVAS);

                    if (d == null)
                    {
                        docEditor = dockingService.CreateDocument(DockState.Document, language + " Editor", FlowSharpCodeServiceInterfaces.Constants.META_SCINTILLA_EDITOR);
                    }
                    else
                    {
                        docEditor = dockingService.CreateDocument(d, DockAlignment.Bottom, language + " Editor", FlowSharpCodeServiceInterfaces.Constants.META_SCINTILLA_EDITOR, 0.50);
                    }
                }
                else
                {
                    docEditor = dockingService.CreateDocument(d, DockState.Document, language + " Editor", FlowSharpCodeServiceInterfaces.Constants.META_SCINTILLA_EDITOR);
                }
            }
            else
            {
                docEditor = dockingService.CreateDocument(d, DockState.Document, language + " Editor", FlowSharpCodeServiceInterfaces.Constants.META_SCINTILLA_EDITOR);
            }

            // Panel dock = dockingService.DockPanel;
            // Interestingly, this uses the current document page, which, I guess because the C# editor was created first, means its using that pane.
            //Control pyDocEditor = dockingService.CreateDocument(DockState.Document, "Python Editor", FlowSharpCodeServiceInterfaces.Constants.META_PYTHON_EDITOR);
            Control pnlCodeEditor = new Panel()
            {
                Dock = DockStyle.Fill, Tag = language
            };

            docEditor.Controls.Add(pnlCodeEditor);
            ((IDockDocument)docEditor).Metadata += "," + language;      // Add language to metadata so we know what editor to create.

            IFlowSharpScintillaEditorService scintillaEditorService = ServiceManager.Get <IFlowSharpScintillaEditorService>();

            scintillaEditorService.CreateEditor(pnlCodeEditor, language);
        }
Exemple #4
0
        protected void OnContentResolver(object sender, ContentLoadedEventArgs e)
        {
            switch (e.Metadata.LeftOf(","))
            {
            case FlowSharpCodeServiceInterfaces.Constants.META_CSHARP_EDITOR:
                Panel pnlEditor = new Panel()
                {
                    Dock = DockStyle.Fill, Tag = FlowSharpCodeServiceInterfaces.Constants.META_CSHARP_EDITOR
                };
                e.DockContent.Controls.Add(pnlEditor);
                e.DockContent.Text = "C# Editor";
                IFlowSharpCodeEditorService csCodeEditorService = ServiceManager.Get <IFlowSharpCodeEditorService>();
                csCodeEditorService.CreateEditor(pnlEditor);
                csCodeEditorService.AddAssembly("Clifton.Core.dll");
                break;

            case FlowSharpCodeServiceInterfaces.Constants.META_OUTPUT:
                Panel pnlOutputWindow = new Panel()
                {
                    Dock = DockStyle.Fill, Tag = FlowSharpCodeServiceInterfaces.Constants.META_OUTPUT
                };
                e.DockContent.Controls.Add(pnlOutputWindow);
                e.DockContent.Text = "Output";
                IFlowSharpCodeOutputWindowService outputWindowService = ServiceManager.Get <IFlowSharpCodeOutputWindowService>();
                outputWindowService.CreateOutputWindow(pnlOutputWindow);
                break;

            case FlowSharpCodeServiceInterfaces.Constants.META_SCINTILLA_EDITOR:
                string language      = e.Metadata.RightOf(",");
                Panel  pnlCodeEditor = new Panel()
                {
                    Dock = DockStyle.Fill, Tag = language
                };
                e.DockContent.Controls.Add(pnlCodeEditor);
                e.DockContent.Text = language.CamelCase() + " Editor";

                IFlowSharpScintillaEditorService scintillaEditorService = ServiceManager.Get <IFlowSharpScintillaEditorService>();
                scintillaEditorService.CreateEditor(pnlCodeEditor, language);
                break;
            }
        }
Exemple #5
0
        protected void OnElementSelected(object controller, ElementEventArgs args)
        {
            ElementProperties                elementProperties   = null;
            IFlowSharpCodeEditorService      csCodeEditorService = ServiceManager.Get <IFlowSharpCodeEditorService>();
            IFlowSharpScintillaEditorService editorService       = ServiceManager.Get <IFlowSharpScintillaEditorService>();

            if (args.Element != null)
            {
                GraphicElement el = args.Element;
                elementProperties = el.CreateProperties();

                string code;
                el.Json.TryGetValue("Code", out code);
                csCodeEditorService.SetText("C#", code ?? String.Empty);

                el.Json.TryGetValue("python", out code);
                editorService.SetText("python", code ?? String.Empty);
            }
            else
            {
                csCodeEditorService.SetText("C#", String.Empty);
                editorService.SetText("python", String.Empty);
            }
        }