arendvw / ScriptParasite

A component that allows editting of C# definitions in external editors
21 stars 5 forks source link

Make double click open the specified folder in explorer #11

Open dilomo opened 3 years ago

dilomo commented 3 years ago

Make double click open the specified folder in explorer in a similar way double click opens the script window? I think this would be really useful change but not sure how it can be done for mac as well.

arendvw commented 3 years ago

Great idea, let's do this. I'm quite busy these weeks, so it may take some time.

dilomo commented 3 years ago

I made it work, maybe has to be tested but I could not fork because on my system there is not GUI.Cs namespace for some reason. Here is the code. You can just copy paste in main component and it will work:

public override void CreateAttributes()
        {
            m_attributes = new DetectDoubleClick(this);
        }

        public void OpenFileBrowesr()
        {
            OperatingSystem os = Environment.OSVersion;
            PlatformID pid = os.Platform;
            switch (pid)
            {
                case PlatformID.Win32NT:
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.WinCE:
                    //"I'm on windows!"
                    if (Directory.Exists(Folder))
                    {
                        ProcessStartInfo startInfo = new ProcessStartInfo
                        {
                            Arguments = Folder,
                            FileName = "explorer.exe"
                        };

                        Process.Start(startInfo);
                    } else
                    {
                        System.Windows.Forms.MessageBox.Show($"{0} directory does not exist! Double click cannot open explorer.");
                    }
                    break;
                case PlatformID.Unix:
                    //"I'm a linux box!"
                    break;
                case PlatformID.MacOSX:
                    //"I'm a mac!"
                    break;
                default:
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Unknonw OS. Double click to open is disabled");
                    break;
            }
        }

        public class DetectDoubleClick : Grasshopper.Kernel.Attributes.GH_ComponentAttributes
        {
            public DetectDoubleClick(IGH_Component component) : base(component)
            {
            }

            public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e)
            {
                (Owner as ScriptParasiteComponent)?.OpenFileBrowesr();
                return GH_ObjectResponse.Handled;
            }
        }
arendvw commented 2 years ago

Cool, I've copied your implementation some time ago, and simplified it a bit. It's a bit busy, but I'll try to push a new version somewhere this week.

dilomo commented 2 years ago

Actually I just found this implementation online somewhere so its totally fine.. Just didt know what to do for the macOS part and we can delete unix for sure.