public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
            {
                if (value is Exception ex)
                {
                    if (context.TryGetService(out IUIService uiService))
                    {
                        uiService.ShowError(ex);
                    }
                    else
                    {
                        string message = ex.Message;
                        if (message is null || message.Length == 0)
                        {
                            message = ex.ToString();
                        }

                        RTLAwareMessageBox.Show(
                            null,
                            message,
                            SR.PropertyGridExceptionInfo,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error,
                            MessageBoxDefaultButton.Button1,
                            0);
                    }
                }

                return(value);
            }
            /// <summary>
            ///      Edits the given object value using the editor style provided by
            ///      GetEditorStyle.  A service provider is provided so that any
            ///      required editing services can be obtained.
            /// </summary>
            public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
            {
                Exception except = value as Exception;

                if (except != null)
                {
                    IUIService uis = null;

                    if (context != null)
                    {
                        uis = (IUIService)context.GetService(typeof(IUIService));
                    }

                    if (uis != null)
                    {
                        uis.ShowError(except);
                    }
                    else
                    {
                        string message = except.Message;
                        if (message == null || message.Length == 0)
                        {
                            message = except.ToString();
                        }

                        RTLAwareMessageBox.Show(null, message, SR.PropertyGridExceptionInfo,
                                                MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0);
                    }
                }
                return(value);
            }
Esempio n. 3
0
            public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
            {
                Exception ex = value as Exception;

                if (ex != null)
                {
                    IUIService service = null;
                    if (context != null)
                    {
                        service = (IUIService)context.GetService(typeof(IUIService));
                    }
                    if (service != null)
                    {
                        service.ShowError(ex);
                        return(value);
                    }
                    string message = ex.Message;
                    if ((message == null) || (message.Length == 0))
                    {
                        message = ex.ToString();
                    }
                    RTLAwareMessageBox.Show(null, message, System.Windows.Forms.SR.GetString("PropertyGridExceptionInfo"), MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1, 0);
                }
                return(value);
            }
Esempio n. 4
0
        public static void ShowWarning(IServiceProvider serviceProvider, string message)
        {
            if (serviceProvider != null)
            {
                IUIService uiService = (IUIService)serviceProvider.GetService(typeof(IUIService));
                if (uiService != null)
                {
                    uiService.ShowError(message);
                    return;
                }
            }

            RTLAwareMessageBox.Show(null, message, Strings.UIHelper_WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, 0);
        }
 private void LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     try
     {
         if (e.Link.Enabled)
         {
             ((DesignerVerb)e.Link.LinkData).Invoke();
         }
     }
     catch (Exception exception)
     {
         RTLAwareMessageBox.Show(this, exception.Message, System.Windows.Forms.SR.GetString("PBRSErrorTitle"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, 0);
     }
 }
Esempio n. 6
0
        private void LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            try
            {
                if (!e.Link.Enabled)
                {
                    return;
                }

                ((DesignerVerb)e.Link.LinkData).Invoke();
            }
            catch (Exception ex)
            {
                RTLAwareMessageBox.Show(this, ex.Message, SR.PBRSErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning,
                                        MessageBoxDefaultButton.Button1, 0);
            }
        }
Esempio n. 7
0
            private void ButtonSave_click(object source, EventArgs e)
            {
                try
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.FileName = SR.BinaryEditorFileName;
                    sfd.Title    = SR.BinaryEditorSaveFile;
                    sfd.Filter   = SR.BinaryEditorAllFiles + " (*.*)|*.*";

                    DialogResult result = sfd.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        _byteViewer.SaveToFile(sfd.FileName);
                    }
                }
                catch (IOException x)
                {
                    RTLAwareMessageBox.Show(null, string.Format(SR.BinaryEditorFileError, x.Message),
                                            SR.BinaryEditorTitle, MessageBoxButtons.OK,
                                            MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0);
                }
            }
Esempio n. 8
0
        public unsafe override bool EditComponent(ITypeDescriptorContext context, object obj, IWin32Window parent)
        {
            IntPtr handle = (parent == null ? IntPtr.Zero : parent.Handle);

            // try to get the page guid
            if (obj is Oleaut32.IPerPropertyBrowsing)
            {
                // check for a property page
                Guid    guid = Guid.Empty;
                HRESULT hr   = ((Oleaut32.IPerPropertyBrowsing)obj).MapPropertyToPage(Ole32.DispatchID.MEMBERID_NIL, &guid);
                if (hr == HRESULT.S_OK & !guid.Equals(Guid.Empty))
                {
                    IntPtr pUnk = Marshal.GetIUnknownForObject(obj);
                    try
                    {
                        Oleaut32.OleCreatePropertyFrame(
                            new HandleRef(parent, handle),
                            0,
                            0,
                            "PropertyPages",
                            1,
                            &pUnk,
                            1,
                            &guid,
                            (uint)Application.CurrentCulture.LCID,
                            0,
                            IntPtr.Zero);
                        return(true);
                    }
                    finally
                    {
                        Marshal.Release(pUnk);
                    }
                }
            }

            if (obj is ISpecifyPropertyPages ispp)
            {
                try
                {
                    var     uuids = new CAUUID();
                    HRESULT hr    = ispp.GetPages(&uuids);
                    if (!hr.Succeeded() || uuids.cElems == 0)
                    {
                        return(false);
                    }

                    IntPtr pUnk = Marshal.GetIUnknownForObject(obj);
                    try
                    {
                        Oleaut32.OleCreatePropertyFrame(
                            new HandleRef(parent, handle),
                            0,
                            0,
                            "PropertyPages",
                            1,
                            &pUnk,
                            uuids.cElems,
                            uuids.pElems,
                            (uint)Application.CurrentCulture.LCID,
                            0,
                            IntPtr.Zero);
                        return(true);
                    }
                    finally
                    {
                        Marshal.Release(pUnk);
                        if (uuids.pElems != null)
                        {
                            Marshal.FreeCoTaskMem((IntPtr)uuids.pElems);
                        }
                    }
                }
                catch (Exception ex)
                {
                    string errString = SR.ErrorPropertyPageFailed;

                    IUIService uiSvc = (context != null) ? ((IUIService)context.GetService(typeof(IUIService))) : null;

                    if (uiSvc == null)
                    {
                        RTLAwareMessageBox.Show(null, errString, SR.PropertyGridTitle,
                                                MessageBoxButtons.OK, MessageBoxIcon.Error,
                                                MessageBoxDefaultButton.Button1, 0);
                    }
                    else if (ex != null)
                    {
                        uiSvc.ShowError(ex, errString);
                    }
                    else
                    {
                        uiSvc.ShowError(errString);
                    }
                }
            }

            return(false);
        }
Esempio n. 9
0
        public override bool EditComponent(ITypeDescriptorContext context, object obj, IWin32Window parent)
        {
            IntPtr handle = (parent == null ? IntPtr.Zero : parent.Handle);

            // try to get the page guid
            if (obj is NativeMethods.IPerPropertyBrowsing)
            {
                // check for a property page
                Guid guid = Guid.Empty;
                int  hr   = ((NativeMethods.IPerPropertyBrowsing)obj).MapPropertyToPage(NativeMethods.MEMBERID_NIL, out guid);
                if (hr == NativeMethods.S_OK)
                {
                    if (!guid.Equals(Guid.Empty))
                    {
                        object o = obj;
                        SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(parent, handle), 0, 0, "PropertyPages", 1, ref o, 1, new Guid[] { guid }, Application.CurrentCulture.LCID, 0, IntPtr.Zero);
                        return(true);
                    }
                }
            }

            if (obj is NativeMethods.ISpecifyPropertyPages)
            {
                bool      failed = false;
                Exception failureException;

                try {
                    NativeMethods.tagCAUUID uuids = new NativeMethods.tagCAUUID();
                    try {
                        ((NativeMethods.ISpecifyPropertyPages)obj).GetPages(uuids);
                        if (uuids.cElems <= 0)
                        {
                            return(false);
                        }
                    }
                    catch {
                        return(false);
                    }
                    try {
                        object o = obj;
                        SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(parent, handle), 0, 0, "PropertyPages", 1, ref o, uuids.cElems, new HandleRef(uuids, uuids.pElems), Application.CurrentCulture.LCID, 0, IntPtr.Zero);
                        return(true);
                    }
                    finally {
                        if (uuids.pElems != IntPtr.Zero)
                        {
                            Marshal.FreeCoTaskMem(uuids.pElems);
                        }
                    }
                }
                catch (Exception ex1) {
                    failed           = true;
                    failureException = ex1;
                }

                if (failed)
                {
                    string errString = SR.ErrorPropertyPageFailed;

                    IUIService uiSvc = (context != null) ? ((IUIService)context.GetService(typeof(IUIService))) : null;

                    if (uiSvc == null)
                    {
                        RTLAwareMessageBox.Show(null, errString, SR.PropertyGridTitle,
                                                MessageBoxButtons.OK, MessageBoxIcon.Error,
                                                MessageBoxDefaultButton.Button1, 0);
                    }
                    else if (failureException != null)
                    {
                        uiSvc.ShowError(failureException, errString);
                    }
                    else
                    {
                        uiSvc.ShowError(errString);
                    }
                }
            }
            return(false);
        }
        public override bool EditComponent(ITypeDescriptorContext context, object obj, IWin32Window parent)
        {
            IntPtr handle = (parent == null) ? IntPtr.Zero : parent.Handle;

            if (obj is System.Windows.Forms.NativeMethods.IPerPropertyBrowsing)
            {
                Guid empty = Guid.Empty;
                if ((((System.Windows.Forms.NativeMethods.IPerPropertyBrowsing)obj).MapPropertyToPage(-1, out empty) == 0) && !empty.Equals(Guid.Empty))
                {
                    object pobjs  = obj;
                    Guid[] pClsid = new Guid[] { empty };
                    SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(parent, handle), 0, 0, "PropertyPages", 1, ref pobjs, 1, pClsid, Application.CurrentCulture.LCID, 0, IntPtr.Zero);
                    return(true);
                }
            }
            if (obj is System.Windows.Forms.NativeMethods.ISpecifyPropertyPages)
            {
                Exception exception;
                bool      flag = false;
                try
                {
                    System.Windows.Forms.NativeMethods.tagCAUUID pPages = new System.Windows.Forms.NativeMethods.tagCAUUID();
                    try
                    {
                        ((System.Windows.Forms.NativeMethods.ISpecifyPropertyPages)obj).GetPages(pPages);
                        if (pPages.cElems <= 0)
                        {
                            return(false);
                        }
                    }
                    catch
                    {
                        return(false);
                    }
                    try
                    {
                        object obj3 = obj;
                        SafeNativeMethods.OleCreatePropertyFrame(new HandleRef(parent, handle), 0, 0, "PropertyPages", 1, ref obj3, pPages.cElems, new HandleRef(pPages, pPages.pElems), Application.CurrentCulture.LCID, 0, IntPtr.Zero);
                        return(true);
                    }
                    finally
                    {
                        if (pPages.pElems != IntPtr.Zero)
                        {
                            Marshal.FreeCoTaskMem(pPages.pElems);
                        }
                    }
                }
                catch (Exception exception2)
                {
                    flag      = true;
                    exception = exception2;
                }
                if (flag)
                {
                    string     text    = System.Windows.Forms.SR.GetString("ErrorPropertyPageFailed");
                    IUIService service = (context != null) ? ((IUIService)context.GetService(typeof(IUIService))) : null;
                    if (service == null)
                    {
                        RTLAwareMessageBox.Show(null, text, System.Windows.Forms.SR.GetString("PropertyGridTitle"), MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1, 0);
                    }
                    else if (exception != null)
                    {
                        service.ShowError(exception, text);
                    }
                    else
                    {
                        service.ShowError(text);
                    }
                }
            }
            return(false);
        }