Overriding the MonoDevelop.Ide.Commands.FileCommands.Save command with an addin

I can't seem to find any way to hook into the save command with an addin. I have tried using the attribute ([CommandHandler (FileCommands.Save)]) redefining the command at the /MonoDevelop/Ide/Commands path and a bunch of other things but none have worked. Is it possible to hook into the save command? If so, can you point me in the right direction?


  • MikeKrgerMikeKrger DEXamarin Team, Beta Xamurai

    Why do you want to override the save command ?

  • desarodesaro USMember

    So that I can fix the broken "remove trailing white space" option. MD is the only IDE I have ever seen that doesn't have a working option to remove extra white space. When you have a team with some folks using MD and others using Visual Studio, Sublime Text, Textmate, Atom, etc it gets annoying having commits with piles of trailing white space being removed all the time.

  • MikeKrgerMikeKrger DEXamarin Team, Beta Xamurai
    edited March 2014

    The option works differently than you think it does – it removes indent whitespaces while typing. That is generally the source of whitespaces in code files. Do you have other use cases ?

    I would suggest adding a trailing whitespace function to the formatting engine and let format on save do that job? Just removing all whitespaces at the end of the line may change c# program semantics. We had the problem inside verbatim strings where a 'dumb' remove all white spaces function changed a c# program.

  • desarodesaro USMember

    I've already made a separate menu item for save and save all that does a dumb white space removal. I personally wouldn't use a multiline verbatim string in a C# code file. Something like that is usually a red flag for the string being in the wrong place but that is just my personal practices and opinion. I've been using dumb white space removal in various script editors and bash scripts for years and have never ran into a single issue.

    I am guessing that since my original question wasn't answered it means there is no way to tie into the current save/saveall commands. That's fine. I can just swap key bindings and that will be a good enough solution for my particular use case since I always save with the keyboard shortcuts.

  • NateCookPersonalNateCookPersonal USUniversity ✭✭

    @MikeKrger turns out I have almost the exact same question. In my case I want to disable AutoFormatDocumentOnSave but just for certain file extensions. Was told that could be done via an add-in but so far cannot find a way to hook into SourceEditorView.Save. Is there a way to do something like this?

Sign In or Register to comment.