Modernize

This commit is contained in:
Matthias Neeracher 2024-10-15 01:37:02 +02:00
parent f334836fb2
commit 7e17c0601c
4 changed files with 32 additions and 5 deletions

View File

@ -539,7 +539,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx10.12;
SDKROOT = macosx10.13;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
@ -577,7 +577,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx10.12;
SDKROOT = macosx10.13;
};
name = Release;
};

View File

@ -85,6 +85,8 @@ class ASApplication: NSObject, NSApplicationDelegate, NSMenuDelegate {
let examplePath = arduinoURL.appendingPathComponent("Contents/Resources/Java/examples", isDirectory:true).path
ASSketchBook.addSketches(menu: menu, target: self, action: #selector(ASApplication.openExample(_:)), path: examplePath, sketches: &examples)
}
ASLibraries.instance().addContribLibraryExamplesToMenu(menu: menu, sketches: &examples)
ASLibraries.instance().addStandardLibraryExamplesToMenu(menu: menu, sketches: &examples)
case "Import Standard Library":
menu.removeAllItems()
ASLibraries.instance().addStandardLibrariesToMenu(menu: menu)

View File

@ -189,6 +189,31 @@ class ASLibraries : NSObject {
menuItem.tag = index
}
}
func addStandardLibraryExamplesToMenu(menu: NSMenu, sketches: inout [String]) {
addLibraryExamplesToMenu(library: standardLib, menu: menu, sketches: &sketches)
}
func addContribLibraryExamplesToMenu(menu: NSMenu, sketches: inout [String]) {
addLibraryExamplesToMenu(library: contribLib, menu: menu, sketches: &sketches)
}
func addLibraryExamplesToMenu(library: [String], menu: NSMenu, sketches: inout [String]) {
let fileManager = FileManager.default
let application = NSApplication.shared().delegate as! ASApplication
var hasSeparator = false
for (_,lib) in library.enumerated() {
let examplePath = (lib as NSString).appendingPathComponent("examples")
if fileManager.fileExists(atPath: examplePath) {
if !hasSeparator {
menu.addItem(NSMenuItem.separator())
hasSeparator = true
}
let menuItem = menu.addItem(withTitle: (lib as NSString).lastPathComponent, action: nil, keyEquivalent: "")
let submenu = NSMenu()
submenu.autoenablesItems = false
ASSketchBook.addSketches(menu: submenu, target: application, action: #selector(ASApplication.openExample(_:)), path: examplePath, sketches: &sketches)
menu.setSubmenu(submenu, for: menuItem)
}
}
}
@IBAction func importStandardLibrary(_ menuItem: AnyObject) {
if let tag = (menuItem as? NSMenuItem)?.tag {
NSApplication.shared().sendAction(#selector(ASProjDoc.importLibrary(_:)), to: nil, from: standardLib[tag])

View File

@ -78,9 +78,9 @@ def parseInoFiles
# Find protypes:
prototypes = contents.dup
# - Strip comments, quoted strings, and preprocessor directives
prototypes.gsub!(%r{'(?:[^']|\\')+'|"(?:[^"]|\\")*"|//.*?$|/\*.*?\*/|^\s*?#.*?$}m, ' ')
prototypes.gsub!(%r{'(?:\\'|[^'])+'|"(?:\\"|[^"])*"|//.*?$|/\*.*?\*/|^\s*?#.*?$}m, ' ')
# Collapse braces
while prototypes.sub!(/(\{)(?:[^{}]+|\{[^{}]*\})/m, '\1') do
while prototypes.sub!(/(\{)([^{}]+|\{[^{}]*\})/m, '\1') do
end
existingProto = {}
prototypes.scan(/[\w\[\]\*]+\s+[&\[\]\*\w\s]+\([&,\[\]\*\w\s]*\)(?=\s*;)/) {|p|
@ -92,7 +92,7 @@ def parseInoFiles
proto << p+";\n" unless existingProto[p]
}
contents.each_line do |line|
if line =~ /^\s*#include\s+[<"](.*)[">]\s*(#.*)?$/
if line =~ %r{^\s*#include\s+[<"](.*)[">]\s*(#.*|/\*.*?\*/\s*|//.*)?$}
addLibrary($1)
end
end