From 76ee1e289c4070d04de4ead5dec64daaa4088459 Mon Sep 17 00:00:00 2001 From: nightwing Date: Mon, 3 Aug 2015 23:28:18 +0400 Subject: [PATCH] add context menu for panels --- plugins/c9.ide.panels/area.js | 20 +++++++++++++++++++- plugins/c9.ide.panels/panel.js | 10 +++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/plugins/c9.ide.panels/area.js b/plugins/c9.ide.panels/area.js index 0ec93cd2..7b11cca2 100644 --- a/plugins/c9.ide.panels/area.js +++ b/plugins/c9.ide.panels/area.js @@ -1,5 +1,5 @@ define(function(require, module, exports) { - main.consumes = ["Plugin", "layout", "settings", "anims", "ui"]; + main.consumes = ["Plugin", "layout", "settings", "anims", "ui", "menus"]; main.provides = ["panels.Area"]; return main; @@ -8,6 +8,7 @@ define(function(require, module, exports) { var layout = imports.layout; var anims = imports.anims; var ui = imports.ui; + var menus = imports.menus; var settings = imports.settings; var uCaseFirst = require("c9/string").uCaseFirst; @@ -43,6 +44,23 @@ define(function(require, module, exports) { column.setWidth(CURWIDTH); column.setAttribute("class", where); + column.oncontextmenu = function(e) { + var menu = menus.get("Window").menu; + menu.display(e.x, e.y); + menu.childNodes.forEach(function(x) { + if (x.visible && !x.panel) { + x.hide(); + menu.on("prop.visible", function show(e) { + if (!e.value) { + menu.off("prop.visible", show); + x.show(); + } + }); + } + }); + return false; + }; + // Prevent scrolling column.$int.addEventListener("scroll", function(e){ column.$int.scrollTop = 0; diff --git a/plugins/c9.ide.panels/panel.js b/plugins/c9.ide.panels/panel.js index 588da214..1c71f1b4 100644 --- a/plugins/c9.ide.panels/panel.js +++ b/plugins/c9.ide.panels/panel.js @@ -46,8 +46,11 @@ define(function(require, module, exports) { area.enablePanel(plugin.name); else area.disablePanel(plugin.name); - } + }, }); + + mnuItem.panel = plugin; + menus.addItemByPath("Window/" + caption, mnuItem, index, plugin); panels.on("showPanel" + uCaseFirst(plugin.name), function(e) { @@ -206,9 +209,10 @@ define(function(require, module, exports) { caption: caption, auto: false, "class" : buttonCSSClass || "", - onmousedown: function(){ + onmousedown: function(e){ + if (e.htmlEvent && e.htmlEvent.button) return; panels.areas[where].toggle(plugin.name, autohide, true); - }, + } }); plugin.addElement(button); }