From 778209ffe4e5a6bb8f76bb29e7e674350fe6f1d7 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 24 Mar 2014 16:28:07 -0700 Subject: [PATCH 1/3] fix bug in Menu.removeMenu() for trees of menus --- examples/menuExample.js | 5 +++++ interface/src/Menu.cpp | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/menuExample.js b/examples/menuExample.js index 3b18021302..874d95ec31 100644 --- a/examples/menuExample.js +++ b/examples/menuExample.js @@ -32,6 +32,7 @@ function setupMenus() { Menu.addSeparator("Foo","Removable Tools"); Menu.addMenuItem("Foo","Remove Foo item 4"); Menu.addMenuItem("Foo","Remove Foo"); + Menu.addMenuItem("Foo","Remove Bar-Spam"); Menu.addMenu("Bar"); Menu.addMenuItem("Bar","Bar item 1", "b"); @@ -91,6 +92,10 @@ function menuItemEvent(menuItem) { if (menuItem == "Remove Foo") { Menu.removeMenu("Foo"); } + if (menuItem == "Remove Bar-Spam") { + Menu.removeMenu("Bar > Spam"); + } + if (menuItem == "Remove Spam item 2") { Menu.removeMenuItem("Bar > Spam", "Spam item 2"); } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 6eb03021b3..7adef1be1c 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -1414,9 +1414,8 @@ void Menu::removeMenu(const QString& menuName) { if (action) { QString finalMenuPart; QMenu* parent = getMenuParent(menuName, finalMenuPart); - if (parent) { - removeAction(parent, finalMenuPart); + parent->removeAction(action); } else { QMenuBar::removeAction(action); } From 03c2ec9376be4ded6e857d314c5ff847a49de3ac Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 24 Mar 2014 16:28:45 -0700 Subject: [PATCH 2/3] add example of selecting the audio device from a menu --- examples/selectAudioDevice.js | 118 ++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 examples/selectAudioDevice.js diff --git a/examples/selectAudioDevice.js b/examples/selectAudioDevice.js new file mode 100644 index 0000000000..882aec87cc --- /dev/null +++ b/examples/selectAudioDevice.js @@ -0,0 +1,118 @@ +// +// audioDeviceExample.js +// hifi +// +// Created by Brad Hefta-Gaub on 3/22/14 +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// +// This is an example script that demonstrates use of the Menu object +// + +if (typeof String.prototype.startsWith != 'function') { + String.prototype.startsWith = function (str){ + return this.slice(0, str.length) == str; + }; +} + +if (typeof String.prototype.endsWith != 'function') { + String.prototype.endsWith = function (str){ + return this.slice(-str.length) == str; + }; +} + +if (typeof String.prototype.trimStartsWith != 'function') { + String.prototype.trimStartsWith = function (str){ + if (this.startsWith(str)) { + return this.substr(str.length); + } + return this; + }; +} + +if (typeof String.prototype.trimEndsWith != 'function') { + String.prototype.trimEndsWith = function (str){ + if (this.endsWith(str)) { + return this.substr(0,this.length - str.length); + } + return this; + }; +} + +var selectedInputMenu = ""; +var selectedOutputMenu = ""; + +function setupAudioMenus() { + Menu.addMenu("Tools > Audio"); + Menu.addSeparator("Tools > Audio","Output Audio Device"); + + var outputDevices = AudioDevice.getOutputDevices(); + var selectedOutputDevice = AudioDevice.getOutputDevice(); + + for(var i = 0; i < outputDevices.length; i++) { + var thisDeviceSelected = (outputDevices[i] == selectedOutputDevice); + var menuItem = "Use " + outputDevices[i] + " for Output"; + Menu.addMenuItem({ + menuName: "Tools > Audio", + menuItemName: menuItem, + isCheckable: true, + isChecked: thisDeviceSelected + }); + if (thisDeviceSelected) { + selectedOutputMenu = menuItem; + } + } + + Menu.addSeparator("Tools > Audio","Input Audio Device"); + + var inputDevices = AudioDevice.getInputDevices(); + var selectedInputDevice = AudioDevice.getInputDevice(); + + for(var i = 0; i < inputDevices.length; i++) { + var thisDeviceSelected = (inputDevices[i] == selectedInputDevice); + var menuItem = "Use " + inputDevices[i] + " for Input"; + Menu.addMenuItem({ + menuName: "Tools > Audio", + menuItemName: menuItem, + isCheckable: true, + isChecked: thisDeviceSelected + }); + if (thisDeviceSelected) { + selectedInputMenu = menuItem; + } + } +} + +setupAudioMenus(); + +function scriptEnding() { + print("scriptEnding()"); + //Menu.removeMenuItem("Tools > Audio"); + Menu.removeMenu("Tools > Audio"); + //Menu.removeMenu("Tools"); + print("DONE... scriptEnding()"); +} +Script.scriptEnding.connect(scriptEnding); + + +function menuItemEvent(menuItem) { + if (menuItem.startsWith("Use ")) { + if (menuItem.endsWith(" for Output")) { + var selectedDevice = menuItem.trimStartsWith("Use ").trimEndsWith(" for Output"); + print("output audio selection..." + selectedDevice); + Menu.setIsOptionChecked(selectedOutputMenu, false); + selectedOutputMenu = menuItem; + Menu.setIsOptionChecked(selectedOutputMenu, true); + AudioDevice.setOutputDevice(selectedDevice); + + } else if (menuItem.endsWith(" for Input")) { + var selectedDevice = menuItem.trimStartsWith("Use ").trimEndsWith(" for Input"); + print("input audio selection..." + selectedDevice); + Menu.setIsOptionChecked(selectedInputMenu, false); + selectedInputMenu = menuItem; + Menu.setIsOptionChecked(selectedInputMenu, true); + AudioDevice.setInputDevice(selectedDevice); + } + } +} + +Menu.menuItemEvent.connect(menuItemEvent); From 547ea047e3609da3544bd6b30411861c0e13ebd3 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 24 Mar 2014 16:33:12 -0700 Subject: [PATCH 3/3] cleanup extra debug --- examples/selectAudioDevice.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/selectAudioDevice.js b/examples/selectAudioDevice.js index 882aec87cc..958ca7babf 100644 --- a/examples/selectAudioDevice.js +++ b/examples/selectAudioDevice.js @@ -85,11 +85,7 @@ function setupAudioMenus() { setupAudioMenus(); function scriptEnding() { - print("scriptEnding()"); - //Menu.removeMenuItem("Tools > Audio"); Menu.removeMenu("Tools > Audio"); - //Menu.removeMenu("Tools"); - print("DONE... scriptEnding()"); } Script.scriptEnding.connect(scriptEnding);