From 5b868a0b7f02df145ef2fd2fe72cf42144c7dc37 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 19 Nov 2015 14:39:03 +0100 Subject: Register "New text file" meu entry in "+" menu Register an entry to create a new text file in the file app's "+" menu. After file creation, automatically open the editor. --- js/editor.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'js') diff --git a/js/editor.js b/js/editor.js index 341357b..11372e4 100644 --- a/js/editor.js +++ b/js/editor.js @@ -561,8 +561,46 @@ var Files_Texteditor = { }; +Files_Texteditor.NewFileMenuPlugin = { + + attach: function(menu) { + var fileList = menu.fileList; + + // only attach to main file list, public view is not supported yet + if (fileList.id !== 'files') { + return; + } + + // register the new menu entry + menu.addMenuEntry({ + id: 'file', + displayName: t('files_texteditor', 'Text file'), + templateName: t('files_texteditor', 'New text file.txt'), + iconClass: 'icon-filetype-text', + fileType: 'file', + actionHandler: function(name) { + var dir = fileList.getCurrentDirectory(); + // first create the file + fileList.createFile(name).then(function() { + // once the file got successfully created, + // open the editor + Files_Texteditor._onEditorTrigger( + name, + { + fileList: fileList, + dir: dir + } + ); + }); + } + }); + } +}; + OCA.Files_Texteditor = Files_Texteditor; +OC.Plugins.register('OCA.Files.NewFileMenu', Files_Texteditor.NewFileMenuPlugin); + $(document).ready(function () { $('#editor').remove(); OCA.Files_Texteditor.initialize($('
')); -- cgit v1.2.3