Example #1
0
        private void InitializePortsList(Gtk.TreeView portsList)
        {
            var viewModel = DataContext as SerialPortSelectorViewModel;

            var column = new Gtk.TreeViewColumn()
            {
                Title = SerialPortSelectorViewModel.PortColumnTitle
            };
            var cellRenderer = new Gtk.CellRendererText();

            column.PackStart(cellRenderer, true);
            column.SetCellDataFunc(cellRenderer, (l, c, m, i) => VisualHelpers.CellTextColumnRenderer <SerialPortViewModel>(l, c, m, i, p => p.PortName));
            ////column.Sizing = Gtk.TreeViewColumnSizing.Fixed;
            ////column.FixedWidth = Properties.Settings.Default.MenuLayoutLongNameColWidth;
            ////column.Resizable = true;
            portsList.AppendColumn(column);

            portsList.Selection.Changed       += HandleSelectedPortChanged;
            portsList.Selection.SelectFunction = ShouldSelectPort;

            var serialPortsModel = new Gtk.ListStore(typeof(SerialPortViewModel));

            serialPortsModel.SynchronizeCollection(viewModel.AvailableSerialPorts);

            // TODO: Disable ports appropriately -- see ShouldSelect
            // TODO: Customize renderer somehow for disabled items to draw differently --
            // Tinkering with CellRendererText.Foreground does not work as desired.
            portsList.Model = serialPortsModel;

            viewModel.AvailableSerialPorts.CollectionChanged += HandleAvailablePortsChanged;
        }
Example #2
0
        /// <summary>
        /// Shows a modal dialog.
        /// </summary>
        /// <param name="dialog">The dialog to show.</param>
        /// <param name="alwaysClose">If set to <c>true</c> always close the dialog as soon as a response is known.</param>
        /// <param name="closeForResponses">If <paramref name="alwaysClose"/> is <c>false</c>, only the provided values will exit the dialog run loop.</param>
        /// <returns>A value indicating whether the dialog was cancelled (<c>false</c>), aborted (<c>null</c>) or approved (<c>true</c>).</returns>
        /// <remarks>Dialogs with 'sub-functions' should always use a response value of Gtk.ResponseType.None. Other explicit values
        /// may be ignored -- that is, only specific values will exit the dialog if the <paramref name="closeForResponses"/> argument
        /// is non-empty and <paramref name="alwaysClose"/> is <c>false</c>. If alwaysClose is false and no response values for close are
        /// provided, it is a Bad Thing and you shouldn't do that.</remarks>
        public static bool?ShowDialog(this Gtk.Dialog dialog, bool alwaysClose, params Gtk.ResponseType[] closeForResponses)
        {
            bool?accepted = null;
            var  result   = Gtk.ResponseType.None;

            do
            {
                result = (Gtk.ResponseType)dialog.Run();
                if (result != Gtk.ResponseType.None)
                {
                    switch (result)
                    {
                    case Gtk.ResponseType.Reject:
                    case Gtk.ResponseType.Cancel:
                    case Gtk.ResponseType.Close:
                    case Gtk.ResponseType.No:
                        accepted = false;
                        break;

                    case Gtk.ResponseType.Accept:
                    case Gtk.ResponseType.Apply:
                    case Gtk.ResponseType.Help:
                    case Gtk.ResponseType.Yes:
                    case Gtk.ResponseType.Ok:
                        accepted = true;
                        break;

                    default:
                        break;
                    }
                }
            }while (!alwaysClose && ((closeForResponses == null) || !closeForResponses.Contains(result)));
            VisualHelpers.Close(dialog);
            return(accepted);
        }
Example #3
0
        private void InitializeBaudRates(Gtk.ComboBox baudRates)
        {
            var viewModel = DataContext as SerialPortSelectorViewModel;

            _baudRateLabel.Text = SerialPortSelectorViewModel.BaudRateLabel;

            Gtk.CellRenderer cellRenderer = new Gtk.CellRendererCombo(); // { Xalign = 0, Xpad = 4 };
            baudRates.PackStart(cellRenderer, false);
            ////baudRates.PackEnd(cellRenderer, true);
            baudRates.SetCellDataFunc(cellRenderer, (l, e, m, i) => VisualHelpers.CellTextRenderer <BaudRateViewModel>(l, e, m, i, c => c.BaudRate.ToString()));

            var baudRatesModel = new Gtk.ListStore(typeof(BaudRateViewModel));

            baudRatesModel.SynchronizeCollection(viewModel.BaudRates);
            baudRates.Model = baudRatesModel;

            if (viewModel.DefaultBaudRate > 0)
            {
                var defaultBaudRate = viewModel.BaudRates.FirstOrDefault(b => b.BaudRate == viewModel.DefaultBaudRate);
                var activeItemIndex = viewModel.BaudRates.IndexOf(defaultBaudRate);
                baudRates.Active = activeItemIndex;
            }

            baudRates.Changed += HandleSelectedBaudRateChanged;
            INTV.Shared.ComponentModel.CommandManager.InvalidateRequerySuggested();
        }
Example #4
0
        private static OSMessageBoxResult PlatformShowCore(string message, string title, System.Exception exception, OSMessageBoxButton buttons, Dictionary <OSMessageBoxButton, string> customButtonLabels, OSMessageBoxIcon icon, OSMessageBoxResult defaultResult, System.Action <OSMessageBoxResult> onComplete)
        {
            var result = OSMessageBoxResult.None;

            if (onComplete == null)
            {
                INTV.Shared.Utility.OSDispatcher.Current.InvokeOnMainDispatcher(() =>
                {
                    var nativeButtons = Gtk.ButtonsType.Ok;
                    switch (buttons)
                    {
                    case OSMessageBoxButton.OK:
                    case OSMessageBoxButton.YesNo:
                        nativeButtons = (Gtk.ButtonsType)buttons;
                        break;

                    case OSMessageBoxButton.YesNoCancel:
                        nativeButtons = Gtk.ButtonsType.None;         // we'll add buttons below
                        break;
                    }

                    var parent = Gtk.Window.ListToplevels().FirstOrDefault(w => w.IsActive || w.IsFocus);
                    if (parent == null)
                    {
                        parent = INTV.Shared.Utility.SingleInstanceApplication.Instance.MainWindow;
                    }

                    using (var messageBox = new Gtk.MessageDialog(parent, Gtk.DialogFlags.Modal, (Gtk.MessageType)icon, nativeButtons, "{0}", message))
                    {
                        messageBox.Title           = title;
                        messageBox.MessageType     = (Gtk.MessageType)icon;
                        messageBox.DefaultResponse = (Gtk.ResponseType)defaultResult;
                        switch (buttons)
                        {
                        case OSMessageBoxButton.OK:
                        case OSMessageBoxButton.YesNo:
                            break;

                        case OSMessageBoxButton.YesNoCancel:
                            messageBox.AddButton(Resources.Strings.YesButton_Text, Gtk.ResponseType.Yes);
                            messageBox.AddButton(Resources.Strings.NoButton_Text, Gtk.ResponseType.No);
                            messageBox.AddButton(Resources.Strings.CancelButtonText, Gtk.ResponseType.Cancel);
                            break;
                        }
                        result = (OSMessageBoxResult)messageBox.Run();
                        VisualHelpers.Close(messageBox);
                    }
                });
            }
            else
            {
                INTV.Shared.Utility.SingleInstanceApplication.MainThreadDispatcher.BeginInvoke(() =>
                {
                    result = ShowCore(message, title, exception, null, buttons, customButtonLabels, icon, defaultResult, null);
                    onComplete(result);
                });
            }

            return(result);
        }
Example #5
0
        /// <summary>
        /// Shows the dialog.
        /// </summary>
        /// <param name="closeButtonText">Close button text; if <c>null</c> or empty, the default is used.</param>
        /// <returns>A nullable value; if <c>true</c> the OK or equivalent was clicked; if <c>false</c>,
        /// the dialog was cancelled.</returns>
        public bool?ShowDialog(string closeButtonText)
        {
            bool?result = null;

            OSDispatcher.Current.InvokeOnMainDispatcher(() =>
            {
                if (!string.IsNullOrEmpty(closeButtonText))
                {
                    ViewModel.CloseDialogButtonText = closeButtonText;
                }
                result = VisualHelpers.ShowDialog(this);
            });
            return(result);
        }
Example #6
0
        /// <inheritdoc/>
        public override FileBrowserDialogResult ShowDialog()
        {
            var fileChooserAction = IsFolderBrowser ? Gtk.FileChooserAction.SelectFolder : Gtk.FileChooserAction.Open;
            var buttons           = new object[] { Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Open, Gtk.ResponseType.Accept };

            using (var dialog = new Gtk.FileChooserDialog(Title, SingleInstanceApplication.Instance.MainWindow, fileChooserAction, buttons))
            {
                dialog.SelectMultiple = Multiselect;
                foreach (var filter in _filters)
                {
                    var fileFilter = new Gtk.FileFilter()
                    {
                        Name = filter.Key
                    };
                    fileFilter.AddCustom(Gtk.FileFilterFlags.Filename, info => FileFilter(dialog, info));
                    dialog.AddFilter(fileFilter);
                }

                var response = (Gtk.ResponseType)dialog.Run();
                _files = dialog.Filenames;
                VisualHelpers.Close(dialog);
                var dialogResult = FileBrowserDialogResult.None;
                switch (response)
                {
                case Gtk.ResponseType.Accept:
                    dialogResult = FileBrowserDialogResult.Ok;
                    break;

                case Gtk.ResponseType.Cancel:
                    dialogResult = FileBrowserDialogResult.Cancel;
                    break;

                default:
                    break;
                }
                return(dialogResult);
            }
        }
Example #7
0
 /// <summary>
 /// Shows a modal dialog.
 /// </summary>
 /// <param name="dialog">The dialog to show.</param>
 /// <returns>A value indicating whether the dialog was cancelled (<c>false</c>), aborted (<c>null</c>) or approved (<c>true</c>).</returns>
 /// <remarks>This function also handles the close button of the dialog, treating it as a 'cancel' operation.</remarks>
 public static bool?ShowDialog(this Gtk.Dialog dialog)
 {
     return(VisualHelpers.ShowDialog(dialog, true));
 }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="INTV.Shared.View.RomListView"/> class.
        /// </summary>
        /// <param name="viewModel">The data context for this visual.</param>
        public RomListView(RomListViewModel viewModel)
        {
            // TODO: Set up sorting!
            // TODO: DragDrop!
            DataContext = viewModel;
            this.Build();
            var treeView = _romListView;

            treeView.Selection.Mode = Gtk.SelectionMode.Multiple;
            treeView.HasTooltip     = true;
            treeView.EnableModelDragDest(RomListViewModel.DragDropTargetEntries, Gdk.DragAction.Private);
            treeView.EnableModelDragSource(Gdk.ModifierType.Button1Mask, RomListViewModel.DragDropSourceEntries, Gdk.DragAction.Copy);

            var column = new Gtk.TreeViewColumn();

            Gtk.CellRenderer cellRenderer = new Gtk.CellRendererPixbuf();
            column.PackStart(cellRenderer, true);
            column.SetCellDataFunc(cellRenderer, (l, c, m, i) => VisualHelpers.CellImageColumnRenderer <ProgramDescriptionViewModel>(l, c, m, i, p => p.RomFileStatusIcon));
            column.Sizing     = Gtk.TreeViewColumnSizing.Fixed;
            column.FixedWidth = 20;
            treeView.AppendColumn(column);

            column = new Gtk.TreeViewColumn()
            {
                Title = RomListViewModel.TitleHeader
            };
            cellRenderer = new Gtk.CellRendererText();
            column.PackStart(cellRenderer, true);
            column.SetCellDataFunc(cellRenderer, (l, c, m, i) => VisualHelpers.CellTextColumnRenderer <ProgramDescriptionViewModel>(l, c, m, i, p => p.Name));
            column.Sizing     = Gtk.TreeViewColumnSizing.Fixed;
            column.FixedWidth = Properties.Settings.Default.RomListNameColWidth;
            column.Resizable  = true;
            treeView.AppendColumn(column);

            column = new Gtk.TreeViewColumn()
            {
                Title = RomListViewModel.CompanyHeader
            };
            cellRenderer = new Gtk.CellRendererText();
            column.PackStart(cellRenderer, true);
            column.SetCellDataFunc(cellRenderer, (l, c, m, i) => VisualHelpers.CellTextColumnRenderer <ProgramDescriptionViewModel>(l, c, m, i, p => p.Vendor));
            column.Sizing     = Gtk.TreeViewColumnSizing.Fixed;
            column.FixedWidth = Properties.Settings.Default.RomListVendorColWidth;
            column.Resizable  = true;
            treeView.AppendColumn(column);

            column = new Gtk.TreeViewColumn()
            {
                Title = RomListViewModel.YearHeader
            };
            cellRenderer = new Gtk.CellRendererText();
            column.PackStart(cellRenderer, true);
            column.SetCellDataFunc(cellRenderer, (l, c, m, i) => VisualHelpers.CellTextColumnRenderer <ProgramDescriptionViewModel>(l, c, m, i, p => p.Year));
            column.Sizing     = Gtk.TreeViewColumnSizing.Fixed;
            column.FixedWidth = Properties.Settings.Default.RomListYearColWidth;
            column.Resizable  = true;
            treeView.AppendColumn(column);

            column = new Gtk.TreeViewColumn()
            {
                Title = RomListViewModel.FeaturesHeader
            };
            cellRenderer        = new Gtk.CellRendererPixbuf();
            cellRenderer.Xalign = 0;
            column.PackStart(cellRenderer, true);
            column.SetCellDataFunc(cellRenderer, (l, c, m, i) => VisualHelpers.CellImageColumnRenderer <ProgramDescriptionViewModel>(l, c, m, i, p => INTV.Shared.Converter.ProgramFeaturesToPixbufConverter.ConvertToPixbuf(p)));
            column.Sizing     = Gtk.TreeViewColumnSizing.Fixed;
            column.FixedWidth = Properties.Settings.Default.RomListFeaturesColWidth;
            column.Resizable  = true;
            treeView.AppendColumn(column);

            column = new Gtk.TreeViewColumn()
            {
                Title = RomListViewModel.RomFileHeader
            };
            cellRenderer = new Gtk.CellRendererText();
            column.PackStart(cellRenderer, true);
            column.SetCellDataFunc(cellRenderer, (l, c, m, i) => VisualHelpers.CellTextColumnRenderer <ProgramDescriptionViewModel>(l, c, m, i, p => p.Rom.RomPath));
            ////column.Sizing = Gtk.TreeViewColumnSizing.Fixed;
            ////column.FixedWidth = Properties.Settings.Default.RomListPathColWidth;
            column.Resizable = true;
            treeView.AppendColumn(column);

            treeView.QueryTooltip += HandleQueryTooltip;

            ////column = new Gtk.TreeViewColumn() { Title = "Manual" };
            ////cellRenderer = new Gtk.CellRendererText();
            ////column.PackStart(cellRenderer, true);
            ////column.SetCellDataFunc(cellRenderer, (l,c,m,i) =>VisualHelpers.CellTextColumnRenderer<ProgramDescriptionViewModel>(l,c,m,i, p => p.ManualPath));
            ////column.Sizing = Gtk.TreeViewColumnSizing.Fixed;
            ////column.FixedWidth = Properties.Settings.Default.RomListManualPathColWidth;;
            ////column.Resizable = true;
            ////treeView.AppendColumn(column);

            var romListStore = new Gtk.ListStore(typeof(ProgramDescriptionViewModel));

            romListStore.SynchronizeCollection(viewModel.Programs);
            treeView.Model = romListStore;

            // Hackish way to get the visibility right.
            HandleSettingsChanged(Properties.Settings.Default, new System.ComponentModel.PropertyChangedEventArgs(Properties.Settings.ShowRomDetailsSettingName));
            Properties.Settings.Default.PropertyChanged += HandleSettingsChanged;
            viewModel.Programs.CollectionChanged        += HandleProgramsChanged;
            viewModel.Model.ProgramStatusChanged        += HandleProgramStatusChanged;

            treeView.Selection.Changed += HandleSelectionChanged;
            ViewModel.CurrentSelection.CollectionChanged += HandleViewModelSelectionChanged;
        }
Example #9
0
 /// <inheritdoc/>
 protected override void OnResponse(Gtk.ResponseType response_id)
 {
     base.OnResponse(response_id);
     VisualHelpers.Close(this);
 }
Example #10
0
 /// <summary>
 /// For compatibility with the Mac version of the dialog.
 /// </summary>
 /// <returns>Returns <c>true</c> if the "OK" button was clicked.</returns>
 public bool?ShowDialog()
 {
     return(VisualHelpers.ShowDialog(this));
 }