示例#1
0
        /// <summary>
        /// Get name of an image file.
        /// </summary>
        private string GetImageFileName(RunMode mode)
        {
            string path;

            if (mode == RunMode.Interactive)
            {
                var dialog = new Eto.Forms.OpenFileDialog();

                string[] all = { ".bmp", ".gif", ".jpg", ".jpeg", ".png", ".tif", ".tiff" };
                dialog.Filters.Add(new Eto.Forms.FileFilter("All image files", all));

                dialog.Filters.Add(new Eto.Forms.FileFilter("Bitmap", ".bmp"));
                dialog.Filters.Add(new Eto.Forms.FileFilter("GIF", ".gif"));

                string[] jpeg = { ".jpg", ".jpe", ".jpeg" };
                dialog.Filters.Add(new Eto.Forms.FileFilter("JPEG", jpeg));
                dialog.Filters.Add(new Eto.Forms.FileFilter("PNG", ".png"));

                string[] tiff = { ".tif", ".tiff" };
                dialog.Filters.Add(new Eto.Forms.FileFilter("TIFF", tiff));

                var res = dialog.ShowDialog(RhinoEtoApp.MainWindow);
                if (res != Eto.Forms.DialogResult.Ok)
                {
                    return(null);
                }

                path = dialog.FileName;
            }
            else
            {
                var gs = new GetString();
                gs.SetCommandPrompt("Name of image file to open");
                gs.Get();
                if (gs.CommandResult() != Result.Success)
                {
                    return(null);
                }

                path = gs.StringResult();
            }

            if (!string.IsNullOrEmpty(path))
            {
                path = path.Trim();
            }

            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            if (!File.Exists(path))
            {
                RhinoApp.WriteLine("The specified file cannot be found.");
                return(null);
            }

            return(path);
        }
示例#2
0
        void OpenFile()
        {
            var ofd = new Eto.Forms.OpenFileDialog();

            ofd.Filters.Add(new Eto.Forms.FileFilter("Rhino 3dm", ".3dm"));
            if (ofd.ShowDialog(this) == Eto.Forms.DialogResult.Ok)
            {
                Title = $"Rhino.Inside ({ofd.FileName})";
                Rhino.RhinoDoc.Open(ofd.FileName, out bool alreadyOpen);
                _viewportControl.Viewport.ZoomExtents();
                _viewportControl.Refresh();
            }
        }
            public SetDefinitionForm(string currentPath)
            {
                Path = currentPath;

                Title = "Set Definition";

                bool windows = Rhino.Runtime.HostUtils.RunningOnWindows;

                DefaultButton = new Eto.Forms.Button {
                    Text = windows ? "OK" : "Apply"
                };
                DefaultButton.Click += (sender, e) => Close(true);
                AbortButton          = new Eto.Forms.Button {
                    Text = "C&ancel"
                };
                AbortButton.Click += (sender, e) => Close(false);
                var buttons = new Eto.Forms.TableLayout();

                if (windows)
                {
                    buttons.Spacing = new Eto.Drawing.Size(5, 5);
                    buttons.Rows.Add(new Eto.Forms.TableRow(null, DefaultButton, AbortButton));
                }
                else
                {
                    buttons.Rows.Add(new Eto.Forms.TableRow(null, AbortButton, DefaultButton));
                }
                var textbox = new Eto.Forms.TextBox();

                textbox.Size            = new Eto.Drawing.Size(250, -1);
                textbox.PlaceholderText = "URL or Path";
                if (!string.IsNullOrWhiteSpace(Path))
                {
                    textbox.Text = Path;
                }
                var filePickButton = new Rhino.UI.Controls.ImageButton();

                filePickButton.Image  = Rhino.Resources.Assets.Rhino.Eto.Bitmaps.TryGet(Rhino.Resources.ResourceIds.FolderopenPng, new Eto.Drawing.Size(24, 24));
                filePickButton.Click += (sender, e) =>
                {
                    var dlg = new Eto.Forms.OpenFileDialog();
                    dlg.Filters.Add(new Eto.Forms.FileFilter("Grasshopper Document", ".gh", ".ghx"));
                    if (dlg.ShowDialog(this) == Eto.Forms.DialogResult.Ok)
                    {
                        textbox.Text = dlg.FileName;
                    }
                };
                var locationRow = new Eto.Forms.StackLayout {
                    Orientation = Eto.Forms.Orientation.Horizontal,
                    Spacing     = buttons.Spacing.Width,
                    Items       = { textbox, filePickButton }
                };

                Content = new Eto.Forms.TableLayout
                {
                    Padding = new Eto.Drawing.Padding(10),
                    Spacing = new Eto.Drawing.Size(5, 5),
                    Rows    =
                    {
                        new Eto.Forms.TableRow {
                            ScaleHeight = true, Cells ={ locationRow          }
                        },
                        buttons
                    }
                };
                Closed += (s, e) => { Path = textbox.Text; };
            }