Skip to content

Conversation

@meviktor
Copy link

Extending the current add-on with the feature of adding custom parameters (tags) to the menu items. Read the updated README.md for the high level description of the feature. I have added notes below which (hopefully) will help during the review.

AddMenuItem.cs (dialog)

  • Filling "the context selector combo box" by using the MenuItemContext enumeration.
    • Fixes a small bug: you were not able to select "Column" as the nem command / MenuItem's context
  • ValidateInputs: the "context combo box" is not empty anymore when the dialog pops up, so no need to check if it has a value set. Checking if the name combo box has some value entered.
  • Adding handlers for adding, editing, removing custom parameters.
  • GetArgumentNamesInUse: you cannot add a parameter with the same name twice. Names of "context levels" (OBJECT, SERVER, VIEW, etc.) are also not permitted (to avoid any conflicts when making replacements in the T-SQL script before executing).

OptionsDialogPage.cs

  • Running validation for MenuItems when the user presses OK on the Options grid of SSMS

SSMSObjectExplorerMenu.cs

  • Asking values of user-defined parameters before making replacements in the T-SQL script

MenuItem.cs

  • Extending with a list of user-definable parameters
  • Using MenuItemContext enumeration to determine the MenuItem's exact context in the Object Explorer
    • Fixes a small bug: now when adding/editing a MenuItem in the Options grid, the context can be selected from a dropdown list. This elminates a possible typo in the context name - it makes the command/MenuItem inaccessible from the right-click context menu in Object Explorer.
  • Preserving compatibility with the XML exports of the previous versions by adding the property ContextDescription
  • Adding validation for (runs through the user-defined parameters if any)

AddUserDefinedParameter.cs (dialog)

  • Dialog for adding/editing custom arguments
  • Parameter name: anything, except: names of "context levels" (OBJECT, SERVER, VIEW, etc.) - every parameter of a MenuItem must have a unique name

EnterUserDefinedArguments.cs (dialog)

  • It's a container of ArgumentControls (one for each parametAddMenuItem.cs (dialog)
  • Filling "the context selector combo box" by using the MenuItemContext enumeration.
    • Fixes a small bug: you were not able to select "Column" as the nem command / MenuItem's context
  • ValidateInputs: the "context combo box" is not empty anymore when the dialog pops up, so no need to check if it has a value set. Checking if the name combo box has some value entered.
  • Adding handlers for adding, editing, removing custom parameters.
  • GetArgumentNamesInUse: you cannot add a parameter with the same name twice. Names of "context levels" (OBJECT, SERVER, VIEW, etc.) are also not permitted (to avoid any conflicts when making replacements in the T-SQL script before executing).

OptionsDialogPage.cs

  • Running validation for MenuItems when the user presses OK on the Options grid of SSMS

SSMSObjectExplorerMenu.cs

  • Asking values of user-defined parameters before making replacements in the T-SQL script

MenuItem.cs

  • Extending with a list of user-definable parameters
  • Using MenuItemContext enumeration to determine the MenuItem's exact context in the Object Explorer
    • Fixes a small bug: now when adding/editing a MenuItem in the Options grid, the context can be selected from a dropdown list. This elminates a possible typo in the context name - it makes the command/MenuItem inaccessible from the right-click context menu in Object Explorer.
  • Preserving compatibility with the XML exports of the previous versions by adding the property ContextDescription
  • Adding validation for (runs through the user-defined parameters if any)

AddUserDefinedParameter.cs (dialog)

  • Dialog for adding/editing custom arguments
  • Parameter name: anything, except: names of "context levels" (OBJECT, SERVER, VIEW, etc.) - every parameter of a MenuItem must have a unique name

EnterUserDefinedArguments.cs (dialog)

  • It's a container of ArgumentControls (one for each parameter of a MenuItem)
  • This dialog is displayed to enter values for arguments, if any is defined for the MenuItem

ArgumentControl.cs (control)

  • Control for enetering parameter values
  • The input field and the validation criteria adapts to the parameter's (data) type (checkbox for bit, numeric updown for int, etc.)

EnumConverter.cs, MenuItemContextConverter.cs, UserDefinedArgumentTypeConverter.cs

  • Used to provide conversion between the values of the MenuItemContext, UserDefinedParameterType enumerations and their string representations (provided for each value in a DescriptionAttribute)
    • This conversion is used to display these strings in the Options Grid, when the user selects context for a MenuItem (from a dropdown list)er of a MenuItem)
  • This dialog is displayed to enter values for arguments, if any is defined for the MenuItem

ArgumentControl.cs (control)

  • Control for enetering parameter values
  • The input field and the validation criteria adapts to the parameter's (data) type (checkbox for bit, numeric updown for int, etc.)

EnumConverter.cs, MenuItemContextConverter.cs, UserDefinedArgumentTypeConverter.cs

  • Used to provide conversion between the values of the MenuItemContext, UserDefinedParameterType enumerations and their string representations (provided for each value in a DescriptionAttribute)
    • This conversion is used to display these strings in the Options Grid, when the user selects context for a MenuItem (from a dropdown list)

…enuItem window with controls for adding user-defined arguments.
…Fixing data binding in AddOrEditUserDefinedArgument dialog.
- Renaming everything (types, variables) contains "argument", "arg" to "parameter", "param".
- Moving extensions under own folder/namespace.
- Fix for  AddMenuItem dialog: not saved user-defined parameters with the command.
AddMenuItem: passing parameters coming from (execution) context as part of parameter names in use.
AddUserDefinedParameter: refactored validation. Modified exception message in Parameter getter.
OptionsDialogPage: adding validation for MenuItems when user clicks OK on Options page. Changes will be discarded if user clicks on Cancel or closes the Options page.
SSMSObjectExplorerMenu: replacing user-defined parameters in T-SQL script of the MenuItem/command.
Utils: fix context parameter names.
Extensions: added ReplaceRange extension method. Removed unnecessary empty lines.
UIExtensions: added ToUserDefinedArgument extension method.
MenuItem: added validation.
UserDefinedArgument added.
ArgumentControl: new control for entering value for a user-defined parameter.
EnterUserDefinedArgument: new dialog for entering parameter values before executing the T-SQL script of the MenuItem/command.
- AddMenuItem: making user-defined parameter listview larger & resizeable. Increasing window & control sizes.
- AddUserDefinedParameter: displaying window in center of parent, modify sytle.
- EnterUserDefinedArgument: displaying window in center of parent, modify sytle. Auto-sized flowLayoutPanel.
…ow issues:

- "Server/Database/Table/Column" could not be selected on the AddMenuItem dialog as the new command's context.
- In the Options grid, Context property of the command/menu item could be edited via a text box. This was error prone - in case of a typo, the command disappeared from the Object Explorer context menu. Now it can be selected from a dropdown.
…up. Allowin editing parameters on the AddMenuItem dialog.
- displaying the full path in the Context field of the exported XML
- accepting string containing the full path to parse the appropriate MenuItemContext value.
Minor UI changes.
Fix the issue when validation threw an exception in case the user did not enter anything for parameter name (UserDefinedParameter.cs)
namespace SSMSObjectExplorerMenu.enums
{
[Flags]
public enum MenuItemContext
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a feature breaking change. The original list of menu item contexts displayed in the drop down in the Add Menu Item window was non-exhaustive. The current context was added at runtime to the dropdown and set at the current value. This change limits where, at what context, menu items can be added.

_valueControl = textBox;
}

private void Init_Int() => _valueControl = new NumericUpDown();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug. Does not allow the user to insert a negative value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, I'll fix this one.


namespace SSMSObjectExplorerMenu.enums
{
public enum UserDefinedParameterType : byte
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature request. Could we please add DateTime as another option.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can add it. It does not seem much extra work.


namespace SSMSObjectExplorerMenu
{
public partial class EnterUserDefinedArguments : Form
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug. Form will need to be resizable to handle case where many parameters are defined

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current way this form works is:

  • In the dialog, there is a container (a FlowLayoutPanel) which holds the inputs for the arguments
  • This input has a default height of 50px. It grows automatically, until it reaches height of 200px. If there are more elements, this container will have a vertical scrollbar - so, you can scroll down for the rest of the elements.
    What kind of behavior would you suggest instead the above one?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simply make the form resizable and achor the flow panel to resize with form.

namespace SSMSObjectExplorerMenu
{
public partial class EnterUserDefinedArguments : Form
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug. Parameter controls are too wide, forcing the horizontal scroll bar to always be displayed.

Copy link
Author

@meviktor meviktor Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, interesting... I see no horizontal scrollbar. However, when I provide a long parameter name, the end of it is just not visible. To be honest, that's why I introduced the NAME_MAX_LENGTH constant in UserDefinedParameter.cs file. Maybe I should reduce the maximum length limit further.
Anyway, I will look into this and try to reproduce this horizontal scrollbar issue you mentioned.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how it renders for me
image

namespace SSMSObjectExplorerMenu.objects
{
[TypeConverter(typeof(ExpandableObjectConverter))]
public class UserDefinedParameter
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature request. Option to set a default/initial value when configuring menu item parameters

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This crossed my mind also during development... would you do it mandatory to specify a default value each parameter, or it would be just an option?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either is fine. Making it mandatory might make the coding easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants