Skip to content

Commit

Permalink
Fixed some issue with commands visibility
Browse files Browse the repository at this point in the history
Fixed typo #42
Added callback #43
  • Loading branch information
AmenJlili committed May 14, 2024
1 parent 4fe965d commit e3f1898
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,56 @@ namespace BlueByte.SOLIDWORKS.PDMProfessional.SDK.Attributes
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class MenuAttribute : Attribute
{
/// <summary>
/// Creates a command menu.
/// </summary>
/// <param name="iD">ID of the command.</param>
/// <param name="menuCaption">Text that will appear in the menu.</param>
/// <param name="flags">Where the menu will appear.</param>
/// <param name="statusBarHelp">Help message that will appear in the status bar.</param>
/// <param name="toolTip">Help message that appear in the Windows tooltip.</param>
/// <param name="toolButtonIndex">Index of the command button.</param>
/// <param name="toolbarImageID">ID of the toolbar image.</param>
public MenuAttribute(int iD, string menuCaption, int flags = 0, string statusBarHelp = "", string toolTip = "", int toolButtonIndex = -1, int toolbarImageID = 0)
/// <summary>
/// Creates a command menu.
/// </summary>
/// <param name="ID">ID of the command.</param>
/// <param name="menuCaption">Text that will appear in the menu.</param>
/// <param name="flags">Where the menu will appear.</param>
/// <param name="statusBarHelp">Help message that will appear in the status bar.</param>
/// <param name="toolTip">Help message that appear in the Windows tooltip.</param>
/// <param name="toolButtonIndex">Index of the command button.</param>
/// <param name="toolbarImageID">ID of the toolbar image.</param>
public MenuAttribute(int ID, string menuCaption, int flags = 0, string statusBarHelp = "", string toolTip = "", int toolButtonIndex = -1, int toolbarImageID = 0)
{
ID = iD;
this.ID = ID;
MenuCaption = menuCaption;
Flags = flags;
StatusBarHelp = statusBarHelp;
Tooltip = toolTip;
ToolButtonIndex = toolButtonIndex;

ToolbarImageID = toolbarImageID;
}


/// <summary>
/// Creates a command menu.
/// </summary>
/// <param name="ID">ID of the command.</param>
/// <param name="menuCaption">Text that will appear in the menu.</param>
/// <param name="flags">Where the menu will appear.</param>
/// <param name="callback">Callback</param>
public MenuAttribute(int ID, string menuCaption, int flags = 0, string callback = "")
{
this.ID = ID;
MenuCaption = menuCaption;
Flags = flags;
StatusBarHelp = menuCaption;
Tooltip = menuCaption;
ToolButtonIndex = -1;
ToolbarImageID = 0;
this.Callback = callback;
}


/// <summary>
/// Gets or sets the callback.
/// </summary>
/// <value>
/// The callback.
/// </value>
/// <remarks>This is not implemented yet.</remarks>
public string Callback { get; set; }



/// <summary>
/// ID of the command.
Expand Down
41 changes: 23 additions & 18 deletions src/BlueByte.SOLIDWORKS.PDMProfessional.SDK/Core/AddInBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,12 @@ public void AttachDebugger()
{
var information = new StringBuilder();
information.AppendLine();
information.AppendLine($"Process name = { process.ProcessName}");
information.AppendLine($"Command Id = { process.Id}");
information.AppendLine($"Command type = { poCmd.meCmdType.ToString()}");
information.AppendLine($"Host Name = { process.ProcessName}");
information.AppendLine($"Host Id = { process.Id}");
information.AppendLine($"Command Type = { poCmd.meCmdType.ToString()}");
information.AppendLine($"Command Id = { poCmd.mlCmdID.ToString()}");
information.AppendLine($"Parent Handle= { poCmd.mlParentWnd}");
information.AppendLine($"Comments = { poCmd.mbsComment}");

if (MessageBox.Show($"Attach Debugger? {information.ToString()}", $"{Identity.Name} - {Identity.Version}", MessageBoxButtons.OKCancel) == DialogResult.OK)
Debugger.Launch();
Expand Down Expand Up @@ -882,30 +885,31 @@ public virtual void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IE
{
if (commandVisibility.CommandID == MenuAtt.ID)
{
var add = false;
var userandgroups = commandVisibility.HideFromTheseUserOrGroupNames;
if (userandgroups != null)
{
var add = false;


// only add command if usergroups does not contain username or groups users is a member of.
if ((userandgroups.Contains(userName) || userandgroups.Where(x => groupNames.Contains(x)).Count() > 0) == false)
add = true;
}

var permissions = commandVisibility.OnlyShowToUsersWithThesePermissions;

// if there are permissions check if currently logged in user has the right permissions
if (permissions != default(EdmSysPerm))
{
var hasAllPermissions = currentlyLoggedInUser.HasSysRightEx(permissions);
if (hasAllPermissions)
add = true;
}


if (add)
poCmdMgr.AddCmd(MenuAtt.ID, MenuAtt.MenuCaption, (int)MenuAtt.Flags, MenuAtt.StatusBarHelp, MenuAtt.Tooltip, MenuAtt.ToolButtonIndex, MenuAtt.ToolbarImageID);
var permissions = commandVisibility.OnlyShowToUsersWithThesePermissions;

// if there are permissions check if currently logged in user has the right permissions
if (permissions != default(EdmSysPerm))
{
var hasAllPermissions = currentlyLoggedInUser.HasSysRightEx(permissions);
if (hasAllPermissions)
add = true;
}


if (add)
poCmdMgr.AddCmd(MenuAtt.ID, MenuAtt.MenuCaption, (int)MenuAtt.Flags, MenuAtt.StatusBarHelp, MenuAtt.Tooltip, MenuAtt.ToolButtonIndex, MenuAtt.ToolbarImageID);

}
}
}
Expand Down Expand Up @@ -1023,13 +1027,14 @@ public virtual void OnCmd(ref EdmCmd poCmd, ref EdmCmdData[] ppoData)
case EdmCmdType.EdmCmd_TaskLaunchButton:
OnTaskLaunchButton(ref poCmd, ref ppoData);
break;

default:
break;
}
}
}



/// <summary>
/// Fires when task details are initialized
/// </summary>
Expand Down

0 comments on commit e3f1898

Please sign in to comment.