Hi. I'm making a keybinding addin for Sql Server Management Studio
(SSMS) in visual studio 2005, and got everything working except when i
remove the last keybinding on a command. The problem only occurrs when
i try to remove the last binding, it works perfectly when i have two
bindings on one command object and remove one of them.
My code is:
string strSelectedCommand = "Edit.Copy";
string strBinding = "Global::Ctrl+C";
Command command = _applicationObject.Commands.Item(strSelectedCommand,
-1);
object[] bindings = (object[])command.Bindings;
object[] newbindings = new object[bindings.Length - 1];
int intCount = 0;
foreach (object binding in bindings) {
if (!binding.ToString().Equals(strBinding,
StringComparison.OrdinalIgnoreCase)) {
newbindings[intCount++] = binding;
}
}
command.Bindings = newbindings
/johan
Perhaps i should add that it's the serializing to the settings file in
the user directory that doesn't work when i try to remove the last
entry. c:\Documents and Settings\USER\Application Data\Microsoft
\Microsoft SQL Server\90\Tools\Shell\*.*
On Jul 9, 10:26 pm, sommar...@gmail.com wrote:
> Hi. I'm making a keybinding addin for Sql Server Management Studio
> (SSMS) in visual studio 2005, and got everything working except when i
[quoted text clipped - 20 lines]
>
> /johan
sommarlov@gmail.com - 11 Jul 2007 10:56 GMT
Oh, well... i found the solution myself. I found a reference to this
post http://forums.microsoft.com/msdn/showpost.aspx?postid=668348&siteid=1
that mentions a bug in VS2003 in put_Bindings method that doesn't
persists changed bindings. I used the following function when removing
the last keybinding on a command object.
private void PersistRandomCommand() {
foreach (Command command in _applicationObject.Commands) {
if (command.Name.Length > 0) {
object[] bindings = (object[])command.Bindings;
if (bindings.Length > 0) {
command.Bindings = bindings;
break;
}
}
}
}
Hope this helps someone else having the same problem as i had.
/Johan
On Jul 10, 11:52 am, sommar...@gmail.com wrote:
> Perhaps i should add that it's the serializing to the settings file in
> the user directory that doesn't work when i try to remove the last
[quoted text clipped - 29 lines]
>
> - Show quoted text -