From fd5a39b1affb8396912a027d5c8eb8253b5e2ac4 Mon Sep 17 00:00:00 2001 From: Lukas Ochmann Date: Wed, 22 Feb 2017 10:50:23 +0100 Subject: [PATCH 1/3] Get filename of current file --- main.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/main.js b/main.js index 9d6d32b..b0246eb 100644 --- a/main.js +++ b/main.js @@ -1,24 +1,24 @@ /* * Copyright (c) 2012 Adobe Systems Incorporated. All rights reserved. - * + * * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. - * + * */ /*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */ @@ -43,11 +43,13 @@ define(function (require, exports, module) { var defaultDescription = "Gist created from Brackets"; - + function handleAction() { - + // Retrieve selection var selectedText = EditorManager.getCurrentFullEditor().getSelectedText(); + var FileName = EditorManager.getCurrentFullEditor().getFile().getBaseName(); + console.log(FileName); if (selectedText === "") { window.alert(EMPTY_MSG); @@ -67,7 +69,7 @@ define(function (require, exports, module) { var postdataString = JSON.stringify(postdata); - + // Send to github $.ajax({ @@ -93,5 +95,5 @@ define(function (require, exports, module) { var menu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU); menu.addMenuDivider(); menu.addMenuItem(MY_COMMAND_ID); - -}); \ No newline at end of file + +}); From c5c8b329c9fcd497c80169f4f91d6f81a94f1d42 Mon Sep 17 00:00:00 2001 From: LukasOchmann Date: Sat, 25 Feb 2017 10:53:41 +0100 Subject: [PATCH 2/3] Script use File-name --- main.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.js b/main.js index b0246eb..d5bd5ce 100644 --- a/main.js +++ b/main.js @@ -31,7 +31,8 @@ define(function (require, exports, module) { var CommandManager = brackets.getModule("command/CommandManager"), EditorManager = brackets.getModule("editor/EditorManager"), - Menus = brackets.getModule("command/Menus"); + Menus = brackets.getModule("command/Menus"), + FileUtils = brackets.getModule("file/FileUtils"); var SUCCESS_MSG = "Gist successfully created at:"; @@ -47,9 +48,8 @@ define(function (require, exports, module) { function handleAction() { // Retrieve selection - var selectedText = EditorManager.getCurrentFullEditor().getSelectedText(); - var FileName = EditorManager.getCurrentFullEditor().getFile().getBaseName(); - console.log(FileName); + var selectedText = EditorManager.getCurrentFullEditor().getSelectedText(), + fileName = FileUtils.getBaseName(EditorManager.getCurrentFullEditor().getFile().fullPath); if (selectedText === "") { window.alert(EMPTY_MSG); @@ -61,11 +61,11 @@ define(function (require, exports, module) { "description": defaultDescription, "public": true, "files": { - "mycode.js": { - "content": selectedText - } } }; + postdata.files[fileName] = { + "content": selectedText + } var postdataString = JSON.stringify(postdata); From 320df6131fd83aed66e7e2df4d2b263e5e969fb8 Mon Sep 17 00:00:00 2001 From: LukasOchmann Date: Sat, 25 Feb 2017 11:10:14 +0100 Subject: [PATCH 3/3] Fixed code-style --- main.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index d5bd5ce..5c5e098 100644 --- a/main.js +++ b/main.js @@ -63,9 +63,10 @@ define(function (require, exports, module) { "files": { } }; - postdata.files[fileName] = { - "content": selectedText - } + + postdata.files[fileName] = { + "content": selectedText + }; var postdataString = JSON.stringify(postdata);