public FileWindowResult ShowSaveFileWindow(string name, string path, FileType fileType)
        {
            var saveWindow = NSSavePanel.SavePanel;

            saveWindow.AllowsOtherFileTypes     = false;
            saveWindow.ExtensionHidden          = true;
            saveWindow.CanCreateDirectories     = true;
            saveWindow.CanSelectHiddenExtension = false;

            saveWindow.AllowedFileTypes     = FileTypeConverter(fileType);
            saveWindow.NameFieldStringValue = name;

            var tf = NSTextField.CreateLabel("text file (*.txt)");

            saveWindow.AccessoryView = tf;

            if (!string.IsNullOrEmpty(path))
            {
                saveWindow.DirectoryUrl = new NSUrl(path, true);
            }

            if (saveWindow.RunModal() == Convert.ToInt32(NSModalResponse.OK))
            {
                return(new FileWindowResult(true, saveWindow.Url.Path));
            }

            return(new FileWindowResult(false));
        }
        public override NSTouchBarItem MakeItem(NSTouchBar touchBar, string identifier)
        {
            var item = new NSCustomTouchBarItem(identifier);

            switch (Array.IndexOf(DefaultIdentifiers, identifier))
            {
            case 0:
                item.View = new NSImageView {
                    Image = GetImage(), ImageScaling = NSImageScale.ProportionallyDown
                };
                break;

            case 1:
                item.View = NSButton.CreateButton(NSImage.ImageNamed(NSImageName.TouchBarPlayTemplate), () => NSWorkspace.SharedWorkspace.OpenUrl(url));
                break;

            case 2:
                // trim title
                var start   = result.IndexOf('「');
                var end     = result.IndexOf('」');
                var summary = result.Substring(0, start) + " " + result.Substring(end + 1);
                item.View = NSTextField.CreateLabel(summary);
                break;

            default:
                break;
            }
            return(item);
        }
        public string ShowSaveFileWindow(string name, string path)
        {
            var saveWindow = NSSavePanel.SavePanel;

            saveWindow.AllowsOtherFileTypes     = false;
            saveWindow.ExtensionHidden          = true;
            saveWindow.CanCreateDirectories     = true;
            saveWindow.CanSelectHiddenExtension = false;

            saveWindow.AllowedFileTypes = new string[] {
                "xlsx"
            };

            saveWindow.NameFieldStringValue = name;

            var tf = NSTextField.CreateLabel("xlsx");

            saveWindow.AccessoryView = tf;

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

            if (saveWindow.RunModal() == Convert.ToInt32(NSModalResponse.OK))
            {
                return(saveWindow.Url.Path);
            }

            return(null);
        }
        NSView CreateTreeNodeView(IViewTreeNode node)
        {
            var view = (NSTextField)treeView.MakeView("view", this);

            if (view == null)
            {
                view      = NSTextField.CreateLabel("");
                view.Font = NSFont.SystemFontOfSize(NSFont.SmallSystemFontSize);
            }
            view.StringValue = node.Text;
            return(view);
        }
Example #5
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            var flags  = NSWindowStyle.Titled | NSWindowStyle.Closable | NSWindowStyle.Miniaturizable | NSWindowStyle.Resizable | NSWindowStyle.FullSizeContentView;
            var window = new NSWindow(new CGRect(x: 0, y: 0, width: 480, height: 300), flags, NSBackingStore.Buffered, deferCreation: false);

            window.WillClose += delegate {
                window.ContentView = NSTextField.CreateLabel("CLOSING");
                GC.Collect();
            };
            window.Center();

            window.ContentView = new NSHostingView(new ClickButton());

            window.MakeKeyAndOrderFront(this);
        }
Example #6
0
        public override NSTouchBarItem MakeItem(NSTouchBar touchBar, string identifier)
        {
            var item = new NSCustomTouchBarItem(identifier);

            switch (Array.IndexOf(DefaultIdentifiers, identifier))
            {
            case 0:
                item.View = new NSImageView {
                    Image = GetImage(), ImageScaling = NSImageScale.ProportionallyDown
                };
                break;

            case 1:
                if (url == null)
                {
                    item.View = new NSImageView {
                        Image = NSImage.ImageNamed(NSImageName.Caution)
                    };
                }
                else
                {
                    item.View = NSButton.CreateButton(NSImage.ImageNamed(NSImageName.TouchBarPlayTemplate), () => NSWorkspace.SharedWorkspace.OpenUrl(url));
                }
                break;

            case 2:
                var view = new NSScrollView
                {
                    HasVerticalScroller   = false,
                    HasHorizontalScroller = true,
                    BorderType            = NSBorderType.NoBorder
                };
                item.View = view;

                // trim title
                var label = NSTextField.CreateLabel(result);
                var size  = label.AttributedStringValue.Size;
                label.SetBoundsOrigin(new CGPoint(0, (BarHeight - size.Height) / 2));
                label.SetFrameSize(new CGSize(size.Width + 8, BarHeight));
                view.DocumentView = label;
                break;

            default:
                break;
            }
            return(item);
        }
Example #7
0
        public MainWindow(CGRect contentRect, NSWindowStyle aStyle, NSBackingStore bufferingType, bool deferCreation) : base(contentRect, aStyle, bufferingType, deferCreation)
        {
            // Define the User Interface of the Window here
            Title = "Window From Code";

            // Create the content view for the window and make it fill the window
            ContentView = new NSView(Frame);

            // Add UI Elements to window
            ClickMeButton = NSButton.CreateButton("Click Me!", ButtonClicked);
            ClickMeButton.TranslatesAutoresizingMaskIntoConstraints = false;
            ContentView.AddSubview(ClickMeButton);

            ClickMeLabel = NSTextField.CreateLabel("Button has not been clicked yet.");
            ClickMeLabel.TranslatesAutoresizingMaskIntoConstraints = false;
            ContentView.AddSubview(ClickMeLabel);

            // Add constraints to window
            ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat(
                                           "V:|-[button]-[label]", NSLayoutFormatOptions.AlignAllLeading,
                                           "button", ClickMeButton, "label", ClickMeLabel));
            ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat(
                                           "H:|-[button]", NSLayoutFormatOptions.AlignAllFirstBaseline,
                                           "button", ClickMeButton));
            ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat(
                                           "H:|-[label]", NSLayoutFormatOptions.AlignAllFirstBaseline,
                                           "label", ClickMeLabel));

            var constraints = NSLayoutConstraint.FromVisualFormat(
                "H:[label]-|", NSLayoutFormatOptions.AlignAllFirstBaseline,
                "label", ClickMeLabel);

            ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat(
                                           "H:[button]-(>=std)-|", NSLayoutFormatOptions.AlignAllFirstBaseline,
                                           "button", ClickMeButton, "std", constraints[0].Constant));
            ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat(
                                           "H:[label]-(>=std)-|", NSLayoutFormatOptions.AlignAllFirstBaseline,
                                           "label", ClickMeLabel, "std", constraints[0].Constant));

            constraints = NSLayoutConstraint.FromVisualFormat(
                "V:[label]-|", NSLayoutFormatOptions.AlignAllLeft,
                "label", ClickMeLabel);
            ContentView.AddConstraints(NSLayoutConstraint.FromVisualFormat(
                                           "V:[label]-(>=std)-|", NSLayoutFormatOptions.AlignAllFirstBaseline,
                                           "label", ClickMeLabel, "std", constraints[0].Constant));
        }
Example #8
0
            public override NSView GetView(NSOutlineView outlineView, NSTableColumn tableColumn, NSObject item)
            {
                if (owner.OnCreateView != null)
                {
                    return(owner.OnCreateView(tableColumn, ((NSNodeItem)item).ModelNode));
                }
                var view = (NSTextField)outlineView.MakeView("defaultView", this);

                if (view == null)
                {
                    view = NSTextField.CreateLabel(item.ToString());
                }
                else
                {
                    view.StringValue = item.ToString();
                }
                return(view);
            }
Example #9
0
            public override NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, nint row)
            {
                var item = dataSource.items[(int)row];

                if (owner.OnCreateView != null)
                {
                    return(owner.OnCreateView(item, tableColumn));
                }
                var view = (NSTextField)tableView.MakeView("defaultView", this);

                if (view == null)
                {
                    view = NSTextField.CreateLabel(item.ToString());
                }
                else
                {
                    view.StringValue = item.ToString();
                }
                return(view);
            }