"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "subprojects/groovy-console/src/main/groovy/groovy/console/ui/view/MacOSXMenuBar.groovy" between
apache-groovy-src-3.0.8.zip and apache-groovy-src-3.0.9.zip

About: Groovy is an agile dynamic (scripting) language for the Java Platform. It has features similar to those of Python, Ruby, Perl, and Smalltalk. Source release.

MacOSXMenuBar.groovy  (apache-groovy-src-3.0.8):MacOSXMenuBar.groovy  (apache-groovy-src-3.0.9)
skipping to change at line 21 skipping to change at line 21
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package groovy.console.ui.view package groovy.console.ui.view
import groovy.transform.Field
import org.codehaus.groovy.vmplugin.VMPluginFactory import org.codehaus.groovy.vmplugin.VMPluginFactory
def handler = false // install handlers for JDK9+
def jdk9plus = VMPluginFactory.getPlugin().getVersion() > 8 final String JDK9PLUS_SCRIPT = """
// TODO Desktop handlers are supposed to work cross platform, should we do versi
on check at a higher layer
// TODO there is also an open files handler, should we also be using that?
if (!handler) {
try {
handler = build(jdk9plus ? """
import java.awt.Desktop import java.awt.Desktop
def handler = Desktop.getDesktop() def handler = Desktop.getDesktop()
handler.setAboutHandler(controller.&showAbout) handler.setAboutHandler(controller.&showAbout)
handler.setQuitHandler(controller.&exitDesktop) handler.setQuitHandler(controller.&exitDesktop)
handler.setPreferencesHandler(controller.&preferences) handler.setPreferencesHandler(controller.&preferences)
handler handler
""" : """ """
// install handlers for JDK <= 8, if the "macOS Runtime Support for Java" (MRJ)
is present
final String MRJ_SCRIPT = """
package groovy.console.ui package groovy.console.ui
import com.apple.mrj.* import com.apple.mrj.*
class ConsoleMacOsSupport implements MRJQuitHandler, MRJAboutHandler, MRJPrefsHa ndler { class ConsoleMacOsSupport implements MRJQuitHandler, MRJAboutHandler, MRJPrefsHa ndler {
def quitHandler def quitHandler
def aboutHandler def aboutHandler
def prefHandler def prefHandler
skipping to change at line 66 skipping to change at line 65
prefHandler() prefHandler()
} }
} }
def handler = new ConsoleMacOsSupport(quitHandler:controller.&exit, aboutHandler :controller.&showAbout, prefHandler:controller.&preferences) def handler = new ConsoleMacOsSupport(quitHandler:controller.&exit, aboutHandler :controller.&showAbout, prefHandler:controller.&preferences)
MRJApplicationUtils.registerAboutHandler(handler) MRJApplicationUtils.registerAboutHandler(handler)
MRJApplicationUtils.registerQuitHandler(handler) MRJApplicationUtils.registerQuitHandler(handler)
MRJApplicationUtils.registerPrefsHandler(handler) MRJApplicationUtils.registerPrefsHandler(handler)
return handler return handler
""", new GroovyClassLoader(this.class.classLoader)) """
} catch (Exception se) {
// usually an AccessControlException, sometimes applets and JNLP won't l // install handlers for JDK <= 8, if the "Apple AWT Extension" (EAWT) is present
et final String EAWT_SCRIPT = """
// you access MRJ classes. package groovy.console.ui
// However, in any exceptional case back out and use the BasicMenuBar
se.printStackTrace() import com.apple.eawt.*
import com.apple.eawt.AppEvent.*
class ConsoleMacOsSupport implements QuitHandler, AboutHandler, PreferencesHandl
er {
def quitHandler
def aboutHandler
def prefHandler
@Override
public void handleAbout(AboutEvent ev) {
aboutHandler()
}
@Override
public void handleQuitRequestWith(QuitEvent ev, QuitResponse resp) {
// Console.exit() returns false, if the user chose to stay around
if (quitHandler()) {
resp.performQuit()
} else {
resp.cancelQuit()
}
}
@Override
public void handlePreferences(PreferencesEvent ev) {
prefHandler()
}
}
def handler = new ConsoleMacOsSupport(quitHandler:controller.&exit, aboutHandler
:controller.&showAbout, prefHandler:controller.&preferences)
def application = Application.getApplication()
application.setQuitHandler(handler)
application.setAboutHandler(handler)
application.setPreferencesHandler(handler)
return handler
"""
def jdk9plus = VMPluginFactory.getPlugin().getVersion() > 8
// JDK <= 8 only
def macOsRuntimeForJavaPresent = classExists('com.apple.mrj.MRJApplicationUtils'
)
&& classExists('com.apple.mrj.MRJQuitHandler')
&& classExists('com.apple.mrj.MRJAboutHandler')
&& classExists('com.apple.mrj.MRJPrefsHandler')
// JDK <= 8 only
def appleAwtExtensionPresent = classExists('com.apple.eawt.Application')
&& classExists('com.apple.eawt.QuitHandler')
&& classExists('com.apple.eawt.AboutHandler')
&& classExists('com.apple.eawt.PreferencesHandler')
// TODO Desktop handlers are supposed to work cross platform, should we do versi
on check at a higher layer
// TODO there is also an open files handler, should we also be using that?
try {
// select handler version
def scriptSource = jdk9plus ? JDK9PLUS_SCRIPT :
macOsRuntimeForJavaPresent ? MRJ_SCRIPT :
appleAwtExtensionPresent ? EAWT_SCRIPT :
null
@Field
static boolean handlersInstalled = false
if (scriptSource) {
if (!handlersInstalled) {
build(scriptSource, new GroovyClassLoader(MacOSXMenuBar.class.classL
oader))
handlersInstalled = true
}
// else just skip handler installation and continue with the rest of the
script
} else {
build(BasicMenuBar) build(BasicMenuBar)
return return
} }
} catch (Exception se) {
// usually an AccessControlException, sometimes applets and JNLP won't let
// you access MRJ classes.
// However, in any exceptional case back out and use the BasicMenuBar
se.printStackTrace()
build(BasicMenuBar)
return
} }
menuBar { menuBar {
menu(text: 'File', mnemonic: 'F') { menu(text: 'File', mnemonic: 'F') {
menuItem(newFileAction, icon:null) menuItem(newFileAction, icon:null)
menuItem(newWindowAction, icon:null) menuItem(newWindowAction, icon:null)
menuItem(openAction, icon:null) menuItem(openAction, icon:null)
separator() separator()
menuItem(saveAction, icon:null) menuItem(saveAction, icon:null)
menuItem(saveAsAction, icon:null) menuItem(saveAsAction, icon:null)
skipping to change at line 151 skipping to change at line 225
menuItem(listClasspath) menuItem(listClasspath)
menuItem(clearClassloader) menuItem(clearClassloader)
separator() separator()
menuItem(inspectLastAction, icon:null) menuItem(inspectLastAction, icon:null)
menuItem(inspectVariablesAction, icon:null) menuItem(inspectVariablesAction, icon:null)
menuItem(inspectAstAction, icon:null) menuItem(inspectAstAction, icon:null)
menuItem(inspectCstAction, icon:null) menuItem(inspectCstAction, icon:null)
menuItem(inspectTokensAction, icon:null) menuItem(inspectTokensAction, icon:null)
} }
} }
static classExists(String className) {
try {
MacOSXMenuBar.class.classLoader.loadClass(className)
true
} catch (ClassNotFoundException ignored) {
false
}
}
 End of changes. 6 change blocks. 
16 lines changed or deleted 95 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)