Fix ctrl + s keyboard shortcut for scripting files in the backoffice of Umbraco 7

  • Tuesday, September 1, 2015 11:24 PM EST
  • Last Edited: Tuesday, September 1, 2015 11:51 PM EST

For Umbraco 7.2.8, the old macroscript files (.cshtml) from umbraco 6 and below are no longer advised to be used. But if you have no time to change all your macroscripts to partial views just yet, you can just show the folder in your backoffice. You can enable this by locating the element with the alias "python"  in the Config/trees.config file and uncomment.

This should be the line of code:

<add application="developer" alias="python" title="Scripting Files" type="umbraco.loadPython, umbraco" iconClosed="folder.gif" iconOpen="folder_o.gif" sortOrder="5" />

 Once you have it enabled, the files should show in your back office.

Now, the main reason I am writing this article is because the ctrl+s keyboard shortcut doesn't work anymore. Fortunately, I had the time to look for a hack-fix for this inconvenience. Change the jquery code in Umbraco/Developer/Python/editPython.aspx

<script type="text/javascript">
(function ($) {
    $(document).ready(function () {
        var editor = new Umbraco.Editors.EditMacroScripts({
            nameTxtBox: $('#<%= pythonFileName.ClientID %>'),
            originalFileName: '<%= pythonFileName.Text %>',
            saveButton: $("#<%= ((Control)SaveButton).ClientID %>"),
            editorSourceElement: $('#<%= pythonFileName.ClientID %>'),
            skipTestingCheckBox: $("#<%= SkipTesting.ClientID %>"),
        });
        editor.init();
    });
    $(document).on('keydown', function(e){
        if(e.ctrlKey && e.which === 83){ 
            $("#<%= ((Control)SaveButton).ClientID %>").trigger( "click" );
            e.preventDefault();
            return false;
        }
    });
})(jQuery);
</script>

You need to get comment out or delete the line UmbClientMgr.appActions().bindSaveShortCut(); for this to work. We are getting rid of the old functionality and creating our own jQuery function to capture the ctrl + s event.

comments powered by Disqus