Example #1
0
 /// <summary>
 /// Removes the specific command flyout
 /// </summary>
 /// <param name="flyout">The command flyout to remove</param>
 public void RemoveCommandFlyout(CommandManagerFlyout flyout)
 {
     lock (mCommandFlyouts)
     {
         BaseObject.RemoveFlyoutGroup(flyout.UserId);
     }
 }
Example #2
0
        /// <summary>
        /// Create a command group flyout containing a list of <see cref="CommandManagerItem"/> items
        /// </summary>
        /// <param name="title">Name of the flyout to create</param>
        /// <param name="items">The command items to add</param>
        /// <param name="pathFormat">The icon list absolute path based on a string format of the absolute path to the icon list images, replacing {0} with the size.
        ///     For example C:\Folder\myiconlist{0}.png</param>
        /// <param name="tooltip">Tool tip for the new flyout</param>
        /// <param name="hint">Text displayed in SOLIDWORKS status bar when a user's mouse pointer is over the flyout</param>
        /// <returns></returns>
        public CommandManagerFlyout CreateFlyoutGroup(string title, List <CommandManagerItem> items, string pathFormat, string tooltip = "", string hint = "")
        {
            #region Icons

            // Make sure the path format contains "{0}"
            if (pathFormat == null || !pathFormat.Contains("{0}"))
            {
                throw new SolidDnaException(SolidDnaErrors.CreateError(
                                                SolidDnaErrorTypeCode.SolidWorksCommandManager,
                                                SolidDnaErrorCode.SolidWorksCommandGroupInvalidPathFormatError,
                                                Localization.GetString("ErrorSolidWorksCommandGroupIconListInvalidPathError")));
            }

            var iconListPaths = new Dictionary <int, string>();

            // Fill the dictionary with all paths that exist
            foreach (var iconSize in mIconSizes)
            {
                var path = string.Format(pathFormat, iconSize);
                if (File.Exists(path))
                {
                    iconListPaths.Add(iconSize, path);
                }
            }

            // Get icon paths
            var icons = iconListPaths.Values.ToArray();

            #endregion

            // Create unique callback Id
            var callbackId = Guid.NewGuid().ToString("N");

            // Attempt to create the command flyout
            var unsafeCommandFlyout = BaseObject.CreateFlyoutGroup2(
                mFlyoutIdCount,
                title,
                tooltip,
                hint,
                icons,
                icons,
                $"Callback({callbackId})",
                null);

            // Create managed object
            var flyout = new CommandManagerFlyout(
                unsafeCommandFlyout,
                mFlyoutIdCount++,
                callbackId,
                items,
                title,
                hint, tooltip);

            // Return it
            return(flyout);
        }