Exemplo n.º 1
0
        private string GetGizmoSettingsNodePath(bool appendWindowSettingsNodeName)
        {
            StringBuilder sb = new StringBuilder();

            if (this.CurrentGizmo != null)
            {
                // We have to use a '\' separator because that's what the registry and file settings stores support.
                const char Separator = '\\';

                GizmoInfo info = this.CurrentGizmo.Info;
                sb.Append(info.GizmoName);

                if (!info.IsSingleInstance)
                {
                    sb.Append(Separator);
                    sb.Append(this.CurrentGizmo.InstanceName);
                }

                if (appendWindowSettingsNodeName)
                {
                    sb.Append(Separator);
                    sb.Append("Window Placement");
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a gizmo using the specified type.
        /// </summary>
        /// <param name="dock">The dock that's hosting the gizmo.</param>
        /// <param name="type">A Gizmo-derived type.</param>
        /// <param name="instanceName">The instance name to use.</param>
        /// <param name="errors">A collection to add error message to if necessary.</param>
        /// <returns>A new gizmo instance if it was created successfully.
        /// Null if errors were added to the <paramref name="errors"/> collection.</returns>
        public static Gizmo Create(IDock dock, Type type, string instanceName, IList <string> errors)
        {
            Conditions.RequireReference(dock, () => dock);
            Conditions.RequireReference(type, () => type);

            Gizmo result = null;

            if (!type.IsSubclassOf(typeof(Gizmo)))
            {
                errors.Add("Type " + type.FullName + " does not derive from " + typeof(Gizmo).FullName);
            }
            else
            {
                GizmoInfo info = new GizmoInfo(type);
                if (info.IsSingleInstance && !string.IsNullOrEmpty(instanceName))
                {
                    errors.Add(info.GizmoName + " is a single instance gizmo, so an instance name isn't supported.");
                }
                else if (!info.IsSingleInstance && string.IsNullOrEmpty(instanceName))
                {
                    errors.Add(info.GizmoName + " is a multi-instance gizmo, so an instance name is required.");
                }
                else
                {
                    try
                    {
                        result              = (Gizmo)Activator.CreateInstance(type);
                        result.gizmoInfo    = info;
                        result.Dock         = dock;
                        result.InstanceName = instanceName;
                    }
                    catch (MissingMethodException ex)
                    {
                        errors.Add(ex.Message);
                    }
                    catch (TargetInvocationException ex)
                    {
                        errors.Add(ex.GetBaseException().Message);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        private bool TryGetShortcutInfo(out ShortcutInfo info)
        {
            string  errorMessage = null;
            Control focusControl = null;

            GizmoInfo gizmo        = this.gizmos.SelectedItem as GizmoInfo;
            string    instanceName = null;

            if (gizmo == null)
            {
                errorMessage = "You must select a gizmo.";
                focusControl = this.gizmos;
            }
            else
            {
                instanceName = this.instance.Text.Trim();
                if (!gizmo.IsSingleInstance && string.IsNullOrEmpty(instanceName))
                {
                    errorMessage = "You must specify an instance name.";
                    focusControl = this.instance;
                }
            }

            bool result = string.IsNullOrEmpty(errorMessage);

            if (result)
            {
                info = new ShortcutInfo(gizmo, gizmo.IsSingleInstance ? null : instanceName, this.showInTaskbar.IsChecked ?? false);
            }
            else
            {
                info = null;
                WindowsUtility.ShowError(this, errorMessage);
            }

            if (focusControl != null)
            {
                focusControl.Focus();
            }

            return(result);
        }
Exemplo n.º 4
0
 public ShortcutInfo(GizmoInfo gizmo, string instanceName, bool showInTaskbar)
 {
     this.Gizmo         = gizmo;
     this.InstanceName  = instanceName;
     this.ShowInTaskbar = showInTaskbar;
 }