diff --git a/CodeColors.xcodeproj/project.pbxproj b/CodeColors.xcodeproj/project.pbxproj index ec251b4..f905c1d 100644 --- a/CodeColors.xcodeproj/project.pbxproj +++ b/CodeColors.xcodeproj/project.pbxproj @@ -413,13 +413,15 @@ ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_KEY_CFBundleDisplayName = "Code Colors"; - INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INFOPLIST_KEY_CFBundleDisplayName = "Code Colors "; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools"; + INFOPLIST_KEY_NSHumanReadableCopyright = "Quet Almahdi Morris"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.0; + MACOSX_DEPLOYMENT_TARGET = 12.2; + MARKETING_VERSION = oct2024; PRODUCT_BUNDLE_IDENTIFIER = com.oil3.CodeColors; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -442,13 +444,15 @@ ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_KEY_CFBundleDisplayName = "Code Colors"; - INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INFOPLIST_KEY_CFBundleDisplayName = "Code Colors "; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools"; + INFOPLIST_KEY_NSHumanReadableCopyright = "Quet Almahdi Morris"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.0; + MACOSX_DEPLOYMENT_TARGET = 12.2; + MARKETING_VERSION = oct2024; PRODUCT_BUNDLE_IDENTIFIER = com.oil3.CodeColors; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -468,12 +472,13 @@ INFOPLIST_FILE = QuickCodeColorLook/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = QuickCodeColorLook; INFOPLIST_KEY_LSApplicationCategoryType = ""; - INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INFOPLIST_KEY_NSHumanReadableCopyright = "Quet Almahdi Morris"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/../Frameworks", "@executable_path/../../../../Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = 12.2; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.oil3.CodeColors.QuickCodeColorLook; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -495,12 +500,13 @@ INFOPLIST_FILE = QuickCodeColorLook/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = QuickCodeColorLook; INFOPLIST_KEY_LSApplicationCategoryType = ""; - INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INFOPLIST_KEY_NSHumanReadableCopyright = "Quet Almahdi Morris"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/../Frameworks", "@executable_path/../../../../Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = 12.2; MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.oil3.CodeColors.QuickCodeColorLook; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/CodeColors.xcodeproj/xcuserdata/ssz.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/CodeColors.xcodeproj/xcuserdata/ssz.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 5d37613..bb246a6 100644 --- a/CodeColors.xcodeproj/xcuserdata/ssz.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/CodeColors.xcodeproj/xcuserdata/ssz.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,66 +3,4 @@ uuid = "60919A6F-13ED-4CF9-8607-2F6AA9EC1D1D" type = "1" version = "2.0"> - - - - - - - - - - - - - - diff --git a/CodeColors/CodeColors.entitlements b/CodeColors/CodeColors.entitlements index cdebbc7..3ffc83d 100644 --- a/CodeColors/CodeColors.entitlements +++ b/CodeColors/CodeColors.entitlements @@ -6,7 +6,7 @@ com.apple.security.application-groups - $(TeamIdentifierPrefix) + com.oil3.codecolors com.apple.security.files.user-selected.read-write diff --git a/CodeColors/CodeColorsApp.swift b/CodeColors/CodeColorsApp.swift index 4afd69d..93abc69 100644 --- a/CodeColors/CodeColorsApp.swift +++ b/CodeColors/CodeColorsApp.swift @@ -15,3 +15,8 @@ struct CodeColorsApp: App { } } } + + +// +// Copyright Almahdi Morris Quet 2024 +// diff --git a/CodeColors/SettingsView.swift b/CodeColors/SettingsView.swift index 5c75d85..70f5bf9 100644 --- a/CodeColors/SettingsView.swift +++ b/CodeColors/SettingsView.swift @@ -30,3 +30,5 @@ struct SettingsView: View { .frame(width: 400) } } + + diff --git a/CodeColors/SyntaxSettings.swift b/CodeColors/SyntaxSettings.swift index 0158596..ca8af45 100644 --- a/CodeColors/SyntaxSettings.swift +++ b/CodeColors/SyntaxSettings.swift @@ -3,7 +3,7 @@ import Combine class SyntaxSettings: ObservableObject { static let shared = SyntaxSettings() - private let userDefaults = UserDefaults(suiteName: "com.oil3.codecolors") + let userDefaults = UserDefaults(suiteName: "com.oil3.codecolors") @Published var syntaxColors: [String: Color] = [:] @@ -89,3 +89,8 @@ extension Color { #endif } } + + +// +// Copyright Almahdi Morris Quet 2024 +// diff --git a/QuickCodeColorLook/CodeContentLoader.swift b/QuickCodeColorLook/CodeContentLoader.swift index b42fbd8..b1a8f03 100644 --- a/QuickCodeColorLook/CodeContentLoader.swift +++ b/QuickCodeColorLook/CodeContentLoader.swift @@ -1,18 +1,20 @@ +// CodeContentLoader.swift + import SwiftUI import Combine class CodeContentLoader: ObservableObject { - @Published var attributedLines: [AttributedString] = [] + @Published var attributedContent: AttributedString = AttributedString() @Published var isLoading = false @Published var totalLines = 0 @Published var fileSize: Int64 = 0 private var shouldCancel = false - func loadFile(at url: URL, maxFileSize: Int64 = 5 * 1024 * 1024) { + func loadFile(at url: URL, maxFileSize: Int64 = 50 * 1024 * 1024) { self.isLoading = true self.shouldCancel = false - self.attributedLines = [] + self.attributedContent = AttributedString() // Check file size if let fileSize = try? url.resourceValues(forKeys: [.fileSizeKey]).fileSize { @@ -39,16 +41,30 @@ class CodeContentLoader: ObservableObject { reader.close() } + var lineNumber = 1 + while let line = reader.nextLine() { if self.shouldCancel { break } - let attributedLine = SyntaxHighlighter.highlightLine(line: line, fileExtension: fileExtension) + // Highlight the line + var attributedLine = SyntaxHighlighter.highlightLine(line: line, fileExtension: fileExtension) + + // Prepend line number +// var lineNumberString = AttributedString("\(lineNumber) ") + // lineNumberString.foregroundColor = .gray + + lineNumber += 1 + + // Combine line number and content +// lineNumberString.append(attributedLine) + // Append newline character + attributedLine.append(AttributedString("\n")) DispatchQueue.main.async { - self.attributedLines.append(attributedLine) - self.totalLines = self.attributedLines.count + self.attributedContent.append(attributedLine) + self.totalLines = lineNumber - 1 } } @@ -62,3 +78,6 @@ class CodeContentLoader: ObservableObject { shouldCancel = true } } +// +// Copyright Almahdi Morris Quet 2024 +// diff --git a/QuickCodeColorLook/Info.plist b/QuickCodeColorLook/Info.plist index bac22b6..c065e8f 100644 --- a/QuickCodeColorLook/Info.plist +++ b/QuickCodeColorLook/Info.plist @@ -12,6 +12,7 @@ public.python-script public.yaml + public.data public.xml public.json public.swift-source diff --git a/QuickCodeColorLook/LineReader.swift b/QuickCodeColorLook/LineReader.swift index 2c2a39b..e4850a0 100644 --- a/QuickCodeColorLook/LineReader.swift +++ b/QuickCodeColorLook/LineReader.swift @@ -60,3 +60,6 @@ class LineReader { close() } } +// +// Copyright Almahdi Morris Quet 2024 +// diff --git a/QuickCodeColorLook/PreviewProvider.swift b/QuickCodeColorLook/PreviewProvider.swift index 97a5a42..2da2c16 100644 --- a/QuickCodeColorLook/PreviewProvider.swift +++ b/QuickCodeColorLook/PreviewProvider.swift @@ -7,35 +7,24 @@ class PreviewProvider: QLPreviewProvider { func providePreview(for request: QLFilePreviewRequest, handler: @escaping (QLPreviewReply?, Error?) -> Void) { } } -struct ContentView: View { -@ObservedObject var loader: CodeContentLoader -@State private var fontSize: CGFloat = 12.0 +// ContentView.swift - var body: some View { - ScrollView { - LazyVStack(alignment: .leading, spacing: 0) { - ForEach(loader.attributedLines.indices, id: \.self) { index in - HStack(alignment: .top, spacing: 5) - { - Text("\(index + 1)") - .font(.system(size: fontSize, weight: .regular, design: .monospaced)) - .foregroundColor(.gray) - .frame(width: 40, alignment: .trailing) - .padding(.trailing, 5) - //need to fix so we can select multiple lines, and having line numbers without including them in the selection, while keeping lazy loading - Text(loader.attributedLines[index]) - .font(.system(size: fontSize, weight: .regular, design: .monospaced)) - } - .textSelection(.enabled) +import SwiftUI - } - } - .padding() +struct ContentView: View { + @ObservedObject var loader: CodeContentLoader + @State private var fontSize: CGFloat = 12.0 + + var body: some View { + ScrollView([.vertical, .horizontal]) { + Text(loader.attributedContent) + .font(.system(size: fontSize, weight: .regular, design: .monospaced)) + .textSelection(.enabled) + .padding() } .gesture(MagnificationGesture() .onChanged { value in self.fontSize = max(8.0, min(24.0, 12.0 * value)) }) } - } diff --git a/QuickCodeColorLook/QuickCodeColorLook.entitlements b/QuickCodeColorLook/QuickCodeColorLook.entitlements index cdebbc7..3ffc83d 100644 --- a/QuickCodeColorLook/QuickCodeColorLook.entitlements +++ b/QuickCodeColorLook/QuickCodeColorLook.entitlements @@ -6,7 +6,7 @@ com.apple.security.application-groups - $(TeamIdentifierPrefix) + com.oil3.codecolors com.apple.security.files.user-selected.read-write diff --git a/QuickCodeColorLook/SyntaxHighlighter.swift b/QuickCodeColorLook/SyntaxHighlighter.swift index f1f19c9..1b74ee9 100644 --- a/QuickCodeColorLook/SyntaxHighlighter.swift +++ b/QuickCodeColorLook/SyntaxHighlighter.swift @@ -5,7 +5,8 @@ struct SyntaxHighlighter { var attributedString = AttributedString() let lines = content.components(separatedBy: .newlines) let newline = AttributedString("\n") - + let userDefaults = UserDefaults(suiteName: "com.oil3.codecolors") + for line in lines { var lineAttributedString = AttributedString(line) applySyntaxHighlighting(to: &lineAttributedString, fileExtension: fileExtension) @@ -42,3 +43,6 @@ struct SyntaxHighlighter { } } } +// +// Copyright Almahdi Morris Quet 2024 +// diff --git a/QuickCodeColorLook/SyntaxRules.swift b/QuickCodeColorLook/SyntaxRules.swift index b6822a7..fe734fd 100644 --- a/QuickCodeColorLook/SyntaxRules.swift +++ b/QuickCodeColorLook/SyntaxRules.swift @@ -14,8 +14,13 @@ class SyntaxRules { ("\\b-?\\d+(?:\\.\\d+)?\\b", NSColor.orange), // Booleans ("\\b(?:True|False|true|false)\\b", NSColor.systemBlue), - // Comments (single line) - ("#.*", NSColor.green) + // Comments + ("#.*", NSColor.green), + ("\"\"\".*?\"\"\"", NSColor.green), + + // Python + ("\\b(def|class|if|else|elif|return|import|from|as|for|while|try|except|with|lambda|pass|break|continue|yield|assert|async|await)\\b", NSColor.systemPurple), + ] let swiftKeywords = [ @@ -25,7 +30,9 @@ class SyntaxRules { "is", "nil", "true", "false", "public", "private", "fileprivate", "internal", "open", "static", "extension", "protocol", "guard", "defer", "where", "associatedtype", "inout", "operator", "init", "super", "self", "Type", - "typealias", "Any", "dynamicType" + "typealias", "Any", "dynamicType", "return", "->", + "HStack", "VStack", "ScrollView", "LazyVStack", "LazyHStack", "View", "List", "Grid" + ] let swiftKeywordPattern = "\\b(\(swiftKeywords.joined(separator: "|")))\\b" @@ -39,7 +46,9 @@ class SyntaxRules { // Comments (single line) ("//.*", NSColor.green), // Comments (multi-line) - ("/\\*[^*]*\\*+(?:[^/*][^*]*\\*+)*/", NSColor.green) + ("/\\*[^*]*\\*+(?:[^/*][^*]*\\*+)*/", NSColor.green), + ("\"\"\".*?\"\"\"", NSColor.green), + ] let htmlRules: [(pattern: String, color: NSColor)] = [ diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..ecc973c Binary files /dev/null and b/logo.png differ