Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions SnippetsLibrary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
B82561F726E8C9840040A67E /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82561F626E8C9840040A67E /* SearchBar.swift */; };
B82561FB26E8CA040040A67E /* SnippetFileCardViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82561FA26E8C9FF0040A67E /* SnippetFileCardViewModel.swift */; };
B82561FC26E8CA040040A67E /* SnippetFileCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82561F926E8C9FF0040A67E /* SnippetFileCardView.swift */; };
B825620026E8CB8C0040A67E /* TextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82561FF26E8CB8C0040A67E /* TextView.swift */; };
B825620226E8D14A0040A67E /* NSTableView+BackgroundColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B825620126E8D14A0040A67E /* NSTableView+BackgroundColor.swift */; };
B825621326E968380040A67E /* SnippetDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B825621226E968380040A67E /* SnippetDetailsView.swift */; };
B84BFEA626F56A6A007E5109 /* CrashlyticsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84BFEA526F56A6A007E5109 /* CrashlyticsService.swift */; };
Expand All @@ -60,6 +59,10 @@
B8B6DE7E26EE4BB500E49C57 /* SnippetsParserService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B6DE7D26EE4BB500E49C57 /* SnippetsParserService.swift */; };
B8B6DE8126EE546800E49C57 /* DependencyContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B6DE8026EE546800E49C57 /* DependencyContainer.swift */; };
B8B6DE8326EE608500E49C57 /* SnippetPlist.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B6DE8226EE608500E49C57 /* SnippetPlist.swift */; };
B8C8755926FD2AB600DE4474 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B88D4A3526F4E34900164BF5 /* GoogleService-Info.plist */; };
B8CE1CAB26FD4193004AD5D5 /* DisabledCommandGroupButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8CE1CAA26FD4193004AD5D5 /* DisabledCommandGroupButton.swift */; };
B8CE1CAE26FD431E004AD5D5 /* URLFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8CE1CAD26FD431E004AD5D5 /* URLFactory.swift */; };
B8CE1CB026FD43B5004AD5D5 /* URLType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8CE1CAF26FD43B5004AD5D5 /* URLType.swift */; };
B8EB5AD526F005CC00BE3EF6 /* CustomCodeTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8EB5AD426F005CC00BE3EF6 /* CustomCodeTheme.swift */; };
B8EB5AD926F0061A00BE3EF6 /* SnippetFileCardViewState.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8EB5AD826F0061A00BE3EF6 /* SnippetFileCardViewState.swift */; };
B8EB5ADB26F0076C00BE3EF6 /* PlistCodingKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8EB5ADA26F0076C00BE3EF6 /* PlistCodingKeys.swift */; };
Expand Down Expand Up @@ -122,7 +125,6 @@
B82561F626E8C9840040A67E /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = "<group>"; };
B82561F926E8C9FF0040A67E /* SnippetFileCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetFileCardView.swift; sourceTree = "<group>"; };
B82561FA26E8C9FF0040A67E /* SnippetFileCardViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetFileCardViewModel.swift; sourceTree = "<group>"; };
B82561FF26E8CB8C0040A67E /* TextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextView.swift; sourceTree = "<group>"; };
B825620126E8D14A0040A67E /* NSTableView+BackgroundColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSTableView+BackgroundColor.swift"; sourceTree = "<group>"; };
B825621226E968380040A67E /* SnippetDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetDetailsView.swift; sourceTree = "<group>"; };
B84BFEA526F56A6A007E5109 /* CrashlyticsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashlyticsService.swift; sourceTree = "<group>"; };
Expand All @@ -148,6 +150,9 @@
B8B6DE7D26EE4BB500E49C57 /* SnippetsParserService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetsParserService.swift; sourceTree = "<group>"; };
B8B6DE8026EE546800E49C57 /* DependencyContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyContainer.swift; sourceTree = "<group>"; };
B8B6DE8226EE608500E49C57 /* SnippetPlist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetPlist.swift; sourceTree = "<group>"; };
B8CE1CAA26FD4193004AD5D5 /* DisabledCommandGroupButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisabledCommandGroupButton.swift; sourceTree = "<group>"; };
B8CE1CAD26FD431E004AD5D5 /* URLFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLFactory.swift; sourceTree = "<group>"; };
B8CE1CAF26FD43B5004AD5D5 /* URLType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLType.swift; sourceTree = "<group>"; };
B8EB5AD426F005CC00BE3EF6 /* CustomCodeTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCodeTheme.swift; sourceTree = "<group>"; };
B8EB5AD826F0061A00BE3EF6 /* SnippetFileCardViewState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetFileCardViewState.swift; sourceTree = "<group>"; };
B8EB5ADA26F0076C00BE3EF6 /* PlistCodingKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlistCodingKeys.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -304,8 +309,8 @@
B82561D826E8223B0040A67E /* VisualEffectView.swift */,
B82561DD26E822A80040A67E /* RecentSnippetCardView.swift */,
B82561F626E8C9840040A67E /* SearchBar.swift */,
B82561FF26E8CB8C0040A67E /* TextView.swift */,
B8F95B0626EEAEB200335D77 /* SnippetDropCellView.swift */,
B8CE1CAA26FD4193004AD5D5 /* DisabledCommandGroupButton.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -424,6 +429,7 @@
B8B6DE7C26EE4B9400E49C57 /* Services */ = {
isa = PBXGroup;
children = (
B8CE1CAC26FD430D004AD5D5 /* URLFactory */,
B88D7A5F26F797DE00B114F6 /* UserDefaults */,
B856D65226F2A27300F60D09 /* Firebase */,
B8EB5AE926F00B6F00BE3EF6 /* SnippetParser */,
Expand All @@ -439,6 +445,14 @@
path = Dependencies;
sourceTree = "<group>";
};
B8CE1CAC26FD430D004AD5D5 /* URLFactory */ = {
isa = PBXGroup;
children = (
B8CE1CAD26FD431E004AD5D5 /* URLFactory.swift */,
);
path = URLFactory;
sourceTree = "<group>";
};
B8EB5AD726F0061000BE3EF6 /* Enums */ = {
isa = PBXGroup;
children = (
Expand All @@ -452,6 +466,7 @@
B88BB45726F564C200747631 /* UserActivityLevel.swift */,
B88BB45926F564D100747631 /* UserActivityLogType.swift */,
B8190DF726FA388500E3994C /* SnippetType.swift */,
B8CE1CAF26FD43B5004AD5D5 /* URLType.swift */,
);
path = Enums;
sourceTree = "<group>";
Expand Down Expand Up @@ -614,7 +629,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B8162F2226FB76F900FB0A9E /* GoogleService-Info.plist in Resources */,
B8C8755926FD2AB600DE4474 /* GoogleService-Info.plist in Resources */,
B82561BB26E81D580040A67E /* Preview Assets.xcassets in Resources */,
B82561B826E81D580040A67E /* Assets.xcassets in Resources */,
);
Expand Down Expand Up @@ -703,20 +718,22 @@
B84BFEA926F57018007E5109 /* System.swift in Sources */,
B8B6DE7B26ED9A3300E49C57 /* SnippetDetailsViewModel.swift in Sources */,
B84BFEA626F56A6A007E5109 /* CrashlyticsService.swift in Sources */,
B8CE1CB026FD43B5004AD5D5 /* URLType.swift in Sources */,
B82561D626E821F20040A67E /* StartViewRecentSnippetsView.swift in Sources */,
B82561D126E821770040A67E /* ActiveAppView.swift in Sources */,
B88BB45A26F564D100747631 /* UserActivityLogType.swift in Sources */,
B82561DC26E822840040A67E /* View+Visibility.swift in Sources */,
B856D65526F2A29600F60D09 /* DatabaseService.swift in Sources */,
B8EB5AD526F005CC00BE3EF6 /* CustomCodeTheme.swift in Sources */,
B8CE1CAE26FD431E004AD5D5 /* URLFactory.swift in Sources */,
B8B6DE8126EE546800E49C57 /* DependencyContainer.swift in Sources */,
B8EB5AE826F00B4300BE3EF6 /* SnippetsParserServiceError.swift in Sources */,
B8EB5AE426F00A7000BE3EF6 /* SnippetPlatform.swift in Sources */,
B825620026E8CB8C0040A67E /* TextView.swift in Sources */,
B8B6DE7E26EE4BB500E49C57 /* SnippetsParserService.swift in Sources */,
B82561B426E81D570040A67E /* SnippetsLibraryApp.swift in Sources */,
B88BB45626F55DDB00747631 /* LogsService.swift in Sources */,
B88D7A6326F7A5C000B114F6 /* SnippetPlist+Dictonary.swift in Sources */,
B8CE1CAB26FD4193004AD5D5 /* DisabledCommandGroupButton.swift in Sources */,
B85D1A9D26FA8EA50053FF3C /* SnippetsLibraryListSectionView.swift in Sources */,
B82561E626E8C5490040A67E /* Mocks.swift in Sources */,
);
Expand Down
1 change: 0 additions & 1 deletion SnippetsLibrary/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {

func applicationDidFinishLaunching(_ notification: Notification) {
FirebaseApp.configure()
DIContainer.crashlyticsService.logNonFatalError(.unableToCreateSnippet)
return
}

Expand Down
31 changes: 23 additions & 8 deletions SnippetsLibrary/Application/SnippetsLibraryApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import SwiftUI
@main
struct SnippetsLibraryApp: App {

private enum Constants {
static let userGuidesUrlString = "https://github.com/tryboxx/SnippetsLibrary/blob/main/README.md"
}

// MARK: - Stored Properties

@Environment(\.scenePhase) var scenePhase
Expand All @@ -23,6 +19,7 @@ struct SnippetsLibraryApp: App {

@State private var activeAppView: ActiveAppView? = nil
@State private var activeAppSheet: AppSheet? = nil
@State private var shouldBeDisabled = false

// MARK: - Views

Expand All @@ -31,6 +28,9 @@ struct SnippetsLibraryApp: App {
showActiveAppView()
}
.windowStyle(HiddenTitleBarWindowStyle())
.onChange(of: activeAppView) {
shouldBeDisabled = ($0 == .snippetsLibrary(nil))
}
.commands {
CommandGroup(replacing: .newItem) {
Button("Add New Code Snippet...") {
Expand All @@ -48,7 +48,10 @@ struct SnippetsLibraryApp: App {
activeAppView = .importSnippet
}

Button("Open Snippets Library...") {
DisabledCommandGroupButton(
text: "Open Snippets Library...",
shouldBeDisabled: $shouldBeDisabled
) {
activeAppView = .snippetsLibrary(nil)
}
}
Expand All @@ -59,10 +62,17 @@ struct SnippetsLibraryApp: App {
}

Button("Show User Guides") {
guard let url = URL(string: Constants.userGuidesUrlString) else { return }

openURL(url)
openURL(url: DIContainer.urlFactory.getURL(withType: .userGuides))
}
}

CommandGroup(replacing: .windowList) {
Button("Developer Documentation") {
openURL(url: DIContainer.urlFactory.getURL(withType: .docs))
}
.keyboardShortcut(
"0",
modifiers: [.command, .shift])
}
}
}
Expand Down Expand Up @@ -114,4 +124,9 @@ struct SnippetsLibraryApp: App {
service?.perform(withItems: ["Please describe your problem here..."])
}

private func openURL(url: URL?) {
guard let safeURL = url else { return }
openURL(safeURL)
}

}

This file was deleted.

1 change: 1 addition & 0 deletions SnippetsLibrary/Dependencies/DependencyContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class DependencyContainer {
// MARK: - Services

lazy var snippetsParserService: SnippetsParserService = SnippetsParserServiceImpl()
lazy var urlFactory: URLFactory = URLFactoryImpl()

lazy var databaseService: DatabaseService = DatabaseServiceImpl(
logsService: logsService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct SnippetDetailsView: View {

// MARK: - Stored Properties

@Environment(\.colorScheme) var colorScheme
@Environment (\.presentationMode) var presentationMode

@ObservedObject private(set) var viewModel: SnippetDetailsViewModel
Expand Down Expand Up @@ -52,10 +53,10 @@ struct SnippetDetailsView: View {
text: $viewModel.snippet.content,
customization: SourceCodeTextEditor.Customization(
didChangeText: { _ in },
insertionPointColor: { .white },
insertionPointColor: { colorScheme == .dark ? .white : .black },
lexerForSource: { _ in SwiftLexer() },
textViewDidBeginEditing: { _ in },
theme: { CustomCodeTheme() }
theme: { CustomCodeTheme(colorScheme: colorScheme) }
),
shouldBecomeFirstResponder: false
)
Expand Down
32 changes: 32 additions & 0 deletions SnippetsLibrary/Services/URLFactory/URLFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// URLFactory.swift
// SnippetsLibrary
//
// Created by Krzysztof Łowiec on 23/09/2021.
//

import Foundation

protocol URLFactory {
func getURL(withType type: URLType) -> URL?
}

final class URLFactoryImpl: URLFactory {

private enum Constants {
static let userGuidesUrlString = "https://github.com/tryboxx/SnippetsLibrary/blob/main/README.md"
static let developerDocumentationUrlString = "https://github.com/tryboxx/SnippetsLibrary/wiki"
}

// MARK: - Methods

internal func getURL(withType type: URLType) -> URL? {
switch type {
case .userGuides:
return URL(string: Constants.userGuidesUrlString)
case .docs:
return URL(string: Constants.developerDocumentationUrlString)
}
}

}
61 changes: 47 additions & 14 deletions SnippetsLibrary/Supporting Files/CustomCodeTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,65 @@ import Sourceful

struct CustomCodeTheme: SourceCodeTheme {

private enum Constants {
static let backgroundDarkColor = NSColor(red: 41/255, green: 42/255, blue: 48/255, alpha: 1.0)
static let plainTypeLightColor = NSColor(red: 2/255, green: 2/255, blue: 2/255, alpha: 1.0)
static let plainTypeDarkColor = NSColor(red: 223/255, green: 223/255, blue: 224/255, alpha: 1.0)
static let numberTypeLightColor = NSColor(red: 40/255, green: 41/255, blue: 208/255, alpha: 1.0)
static let numberTypeDarkColor = NSColor(red: 214/255, green: 202/255, blue: 134/255, alpha: 1.0)
static let stringTypeLightColor = NSColor(red: 192/255, green: 62/255, blue: 41/255, alpha: 1.0)
static let stringTypeDarkColor = NSColor(red: 239/255, green: 136/255, blue: 118/255, alpha: 1.0)
static let identifierTypeLightColor = NSColor(red: 121/255, green: 82/255, blue: 178/255, alpha: 1.0)
static let identifierTypeDarkColor = NSColor(red: 171/255, green: 131/255, blue: 228/255, alpha: 1.0)
static let keywordTypeLightColor = NSColor(red: 160/255, green: 69/255, blue: 160/255, alpha: 1.0)
static let keywordTypeDarkColor = NSColor(red: 238/255, green: 130/255, blue: 176/255, alpha: 1.0)
static let commentColor = NSColor(red: 129/255.0, green: 140/255.0, blue: 150/255.0, alpha: 1.0)

static let font = NSFont.monospacedSystemFont(ofSize: 15, weight: .regular)
static let gutterStyle = GutterStyle(backgroundColor: NSColor.clear, minimumWidth: 0)
}

// MARK: - Stored Properties

private var colorScheme: ColorScheme = .dark

private static var lineNumbersColor: NSColor = .clear
public let lineNumbersStyle: LineNumbersStyle? = nil
public let gutterStyle: GutterStyle = GutterStyle(backgroundColor: Color.clear, minimumWidth: 0)
public let font = NSFont.monospacedSystemFont(ofSize: 15, weight: .regular)

public let backgroundColor = Color(red: 41/255.0, green: 42/255, blue: 48/255, alpha: 1.0)
internal let lineNumbersStyle: LineNumbersStyle? = nil
internal let gutterStyle: GutterStyle = Constants.gutterStyle
internal let font = Constants.font

// MARK: - Computed Properties

internal var backgroundColor: NSColor {
return colorScheme == .dark ? Constants.backgroundDarkColor : NSColor.white
}

// MARK: - Initialization

init(colorScheme: ColorScheme) {
self.colorScheme = colorScheme
}

// MARK: - Methods

public func color(for syntaxColorType: SourceCodeTokenType) -> NSColor {
func color(for syntaxColorType: SourceCodeTokenType) -> NSColor {
switch syntaxColorType {
case .plain:
return Color(red: 223/255, green: 223/255, blue: 224/255, alpha: 1.0)
return colorScheme == .dark ? Constants.plainTypeDarkColor : Constants.plainTypeLightColor
case .number:
return Color(red: 214/255, green: 202/255, blue: 134/255, alpha: 1.0)
return colorScheme == .dark ? Constants.numberTypeDarkColor : Constants.numberTypeLightColor
case .string:
return Color(red: 239/255, green: 136/255, blue: 118/255, alpha: 1.0)
return colorScheme == .dark ? Constants.stringTypeDarkColor : Constants.stringTypeLightColor
case .identifier:
return Color(red: 171/255, green: 131/255, blue: 228/255, alpha: 1.0)
return colorScheme == .dark ? Constants.identifierTypeDarkColor : Constants.identifierTypeLightColor
case .keyword:
return Color(red: 238/255, green: 130/255, blue: 176/255, alpha: 1.0)
return colorScheme == .dark ? Constants.keywordTypeDarkColor : Constants.keywordTypeLightColor
case .comment:
return Color(red: 129/255.0, green: 140/255.0, blue: 150/255.0, alpha: 1.0)
return Constants.commentColor
case .editorPlaceholder:
return .gray
return colorScheme == .dark ? .gray : .lightGray
}
}

public init() {}

}
13 changes: 13 additions & 0 deletions SnippetsLibrary/Supporting Files/Enums/URLType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// URLType.swift
// SnippetsLibrary
//
// Created by Krzysztof Łowiec on 23/09/2021.
//

import Foundation

enum URLType {
case userGuides
case docs
}
Loading