Skip to content

Commit 2e88746

Browse files
committed
Merge branch 'main' of https://github.com/tryboxx/SnippetsLibrary into main
2 parents ddddc38 + 074ec61 commit 2e88746

File tree

12 files changed

+179
-106
lines changed

12 files changed

+179
-106
lines changed

SnippetsLibrary.xcodeproj/project.pbxproj

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
B82561F726E8C9840040A67E /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82561F626E8C9840040A67E /* SearchBar.swift */; };
3636
B82561FB26E8CA040040A67E /* SnippetFileCardViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82561FA26E8C9FF0040A67E /* SnippetFileCardViewModel.swift */; };
3737
B82561FC26E8CA040040A67E /* SnippetFileCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82561F926E8C9FF0040A67E /* SnippetFileCardView.swift */; };
38-
B825620026E8CB8C0040A67E /* TextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82561FF26E8CB8C0040A67E /* TextView.swift */; };
3938
B825620226E8D14A0040A67E /* NSTableView+BackgroundColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B825620126E8D14A0040A67E /* NSTableView+BackgroundColor.swift */; };
4039
B825621326E968380040A67E /* SnippetDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B825621226E968380040A67E /* SnippetDetailsView.swift */; };
4140
B84BFEA626F56A6A007E5109 /* CrashlyticsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B84BFEA526F56A6A007E5109 /* CrashlyticsService.swift */; };
@@ -60,6 +59,10 @@
6059
B8B6DE7E26EE4BB500E49C57 /* SnippetsParserService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B6DE7D26EE4BB500E49C57 /* SnippetsParserService.swift */; };
6160
B8B6DE8126EE546800E49C57 /* DependencyContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B6DE8026EE546800E49C57 /* DependencyContainer.swift */; };
6261
B8B6DE8326EE608500E49C57 /* SnippetPlist.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B6DE8226EE608500E49C57 /* SnippetPlist.swift */; };
62+
B8C8755926FD2AB600DE4474 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B88D4A3526F4E34900164BF5 /* GoogleService-Info.plist */; };
63+
B8CE1CAB26FD4193004AD5D5 /* DisabledCommandGroupButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8CE1CAA26FD4193004AD5D5 /* DisabledCommandGroupButton.swift */; };
64+
B8CE1CAE26FD431E004AD5D5 /* URLFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8CE1CAD26FD431E004AD5D5 /* URLFactory.swift */; };
65+
B8CE1CB026FD43B5004AD5D5 /* URLType.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8CE1CAF26FD43B5004AD5D5 /* URLType.swift */; };
6366
B8EB5AD526F005CC00BE3EF6 /* CustomCodeTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8EB5AD426F005CC00BE3EF6 /* CustomCodeTheme.swift */; };
6467
B8EB5AD926F0061A00BE3EF6 /* SnippetFileCardViewState.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8EB5AD826F0061A00BE3EF6 /* SnippetFileCardViewState.swift */; };
6568
B8EB5ADB26F0076C00BE3EF6 /* PlistCodingKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8EB5ADA26F0076C00BE3EF6 /* PlistCodingKeys.swift */; };
@@ -122,7 +125,6 @@
122125
B82561F626E8C9840040A67E /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = "<group>"; };
123126
B82561F926E8C9FF0040A67E /* SnippetFileCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetFileCardView.swift; sourceTree = "<group>"; };
124127
B82561FA26E8C9FF0040A67E /* SnippetFileCardViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetFileCardViewModel.swift; sourceTree = "<group>"; };
125-
B82561FF26E8CB8C0040A67E /* TextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextView.swift; sourceTree = "<group>"; };
126128
B825620126E8D14A0040A67E /* NSTableView+BackgroundColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSTableView+BackgroundColor.swift"; sourceTree = "<group>"; };
127129
B825621226E968380040A67E /* SnippetDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetDetailsView.swift; sourceTree = "<group>"; };
128130
B84BFEA526F56A6A007E5109 /* CrashlyticsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashlyticsService.swift; sourceTree = "<group>"; };
@@ -148,6 +150,9 @@
148150
B8B6DE7D26EE4BB500E49C57 /* SnippetsParserService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetsParserService.swift; sourceTree = "<group>"; };
149151
B8B6DE8026EE546800E49C57 /* DependencyContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyContainer.swift; sourceTree = "<group>"; };
150152
B8B6DE8226EE608500E49C57 /* SnippetPlist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetPlist.swift; sourceTree = "<group>"; };
153+
B8CE1CAA26FD4193004AD5D5 /* DisabledCommandGroupButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisabledCommandGroupButton.swift; sourceTree = "<group>"; };
154+
B8CE1CAD26FD431E004AD5D5 /* URLFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLFactory.swift; sourceTree = "<group>"; };
155+
B8CE1CAF26FD43B5004AD5D5 /* URLType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLType.swift; sourceTree = "<group>"; };
151156
B8EB5AD426F005CC00BE3EF6 /* CustomCodeTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomCodeTheme.swift; sourceTree = "<group>"; };
152157
B8EB5AD826F0061A00BE3EF6 /* SnippetFileCardViewState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnippetFileCardViewState.swift; sourceTree = "<group>"; };
153158
B8EB5ADA26F0076C00BE3EF6 /* PlistCodingKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlistCodingKeys.swift; sourceTree = "<group>"; };
@@ -304,8 +309,8 @@
304309
B82561D826E8223B0040A67E /* VisualEffectView.swift */,
305310
B82561DD26E822A80040A67E /* RecentSnippetCardView.swift */,
306311
B82561F626E8C9840040A67E /* SearchBar.swift */,
307-
B82561FF26E8CB8C0040A67E /* TextView.swift */,
308312
B8F95B0626EEAEB200335D77 /* SnippetDropCellView.swift */,
313+
B8CE1CAA26FD4193004AD5D5 /* DisabledCommandGroupButton.swift */,
309314
);
310315
path = Views;
311316
sourceTree = "<group>";
@@ -424,6 +429,7 @@
424429
B8B6DE7C26EE4B9400E49C57 /* Services */ = {
425430
isa = PBXGroup;
426431
children = (
432+
B8CE1CAC26FD430D004AD5D5 /* URLFactory */,
427433
B88D7A5F26F797DE00B114F6 /* UserDefaults */,
428434
B856D65226F2A27300F60D09 /* Firebase */,
429435
B8EB5AE926F00B6F00BE3EF6 /* SnippetParser */,
@@ -439,6 +445,14 @@
439445
path = Dependencies;
440446
sourceTree = "<group>";
441447
};
448+
B8CE1CAC26FD430D004AD5D5 /* URLFactory */ = {
449+
isa = PBXGroup;
450+
children = (
451+
B8CE1CAD26FD431E004AD5D5 /* URLFactory.swift */,
452+
);
453+
path = URLFactory;
454+
sourceTree = "<group>";
455+
};
442456
B8EB5AD726F0061000BE3EF6 /* Enums */ = {
443457
isa = PBXGroup;
444458
children = (
@@ -452,6 +466,7 @@
452466
B88BB45726F564C200747631 /* UserActivityLevel.swift */,
453467
B88BB45926F564D100747631 /* UserActivityLogType.swift */,
454468
B8190DF726FA388500E3994C /* SnippetType.swift */,
469+
B8CE1CAF26FD43B5004AD5D5 /* URLType.swift */,
455470
);
456471
path = Enums;
457472
sourceTree = "<group>";
@@ -614,7 +629,7 @@
614629
isa = PBXResourcesBuildPhase;
615630
buildActionMask = 2147483647;
616631
files = (
617-
B8162F2226FB76F900FB0A9E /* GoogleService-Info.plist in Resources */,
632+
B8C8755926FD2AB600DE4474 /* GoogleService-Info.plist in Resources */,
618633
B82561BB26E81D580040A67E /* Preview Assets.xcassets in Resources */,
619634
B82561B826E81D580040A67E /* Assets.xcassets in Resources */,
620635
);
@@ -703,20 +718,22 @@
703718
B84BFEA926F57018007E5109 /* System.swift in Sources */,
704719
B8B6DE7B26ED9A3300E49C57 /* SnippetDetailsViewModel.swift in Sources */,
705720
B84BFEA626F56A6A007E5109 /* CrashlyticsService.swift in Sources */,
721+
B8CE1CB026FD43B5004AD5D5 /* URLType.swift in Sources */,
706722
B82561D626E821F20040A67E /* StartViewRecentSnippetsView.swift in Sources */,
707723
B82561D126E821770040A67E /* ActiveAppView.swift in Sources */,
708724
B88BB45A26F564D100747631 /* UserActivityLogType.swift in Sources */,
709725
B82561DC26E822840040A67E /* View+Visibility.swift in Sources */,
710726
B856D65526F2A29600F60D09 /* DatabaseService.swift in Sources */,
711727
B8EB5AD526F005CC00BE3EF6 /* CustomCodeTheme.swift in Sources */,
728+
B8CE1CAE26FD431E004AD5D5 /* URLFactory.swift in Sources */,
712729
B8B6DE8126EE546800E49C57 /* DependencyContainer.swift in Sources */,
713730
B8EB5AE826F00B4300BE3EF6 /* SnippetsParserServiceError.swift in Sources */,
714731
B8EB5AE426F00A7000BE3EF6 /* SnippetPlatform.swift in Sources */,
715-
B825620026E8CB8C0040A67E /* TextView.swift in Sources */,
716732
B8B6DE7E26EE4BB500E49C57 /* SnippetsParserService.swift in Sources */,
717733
B82561B426E81D570040A67E /* SnippetsLibraryApp.swift in Sources */,
718734
B88BB45626F55DDB00747631 /* LogsService.swift in Sources */,
719735
B88D7A6326F7A5C000B114F6 /* SnippetPlist+Dictonary.swift in Sources */,
736+
B8CE1CAB26FD4193004AD5D5 /* DisabledCommandGroupButton.swift in Sources */,
720737
B85D1A9D26FA8EA50053FF3C /* SnippetsLibraryListSectionView.swift in Sources */,
721738
B82561E626E8C5490040A67E /* Mocks.swift in Sources */,
722739
);

SnippetsLibrary/Application/AppDelegate.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
1212

1313
func applicationDidFinishLaunching(_ notification: Notification) {
1414
FirebaseApp.configure()
15-
DIContainer.crashlyticsService.logNonFatalError(.unableToCreateSnippet)
1615
return
1716
}
1817

SnippetsLibrary/Application/SnippetsLibraryApp.swift

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import SwiftUI
1010
@main
1111
struct SnippetsLibraryApp: App {
1212

13-
private enum Constants {
14-
static let userGuidesUrlString = "https://github.com/tryboxx/SnippetsLibrary/blob/main/README.md"
15-
}
16-
1713
// MARK: - Stored Properties
1814

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

2420
@State private var activeAppView: ActiveAppView? = nil
2521
@State private var activeAppSheet: AppSheet? = nil
22+
@State private var shouldBeDisabled = false
2623

2724
// MARK: - Views
2825

@@ -31,6 +28,9 @@ struct SnippetsLibraryApp: App {
3128
showActiveAppView()
3229
}
3330
.windowStyle(HiddenTitleBarWindowStyle())
31+
.onChange(of: activeAppView) {
32+
shouldBeDisabled = ($0 == .snippetsLibrary(nil))
33+
}
3434
.commands {
3535
CommandGroup(replacing: .newItem) {
3636
Button("Add New Code Snippet...") {
@@ -48,7 +48,10 @@ struct SnippetsLibraryApp: App {
4848
activeAppView = .importSnippet
4949
}
5050

51-
Button("Open Snippets Library...") {
51+
DisabledCommandGroupButton(
52+
text: "Open Snippets Library...",
53+
shouldBeDisabled: $shouldBeDisabled
54+
) {
5255
activeAppView = .snippetsLibrary(nil)
5356
}
5457
}
@@ -59,10 +62,17 @@ struct SnippetsLibraryApp: App {
5962
}
6063

6164
Button("Show User Guides") {
62-
guard let url = URL(string: Constants.userGuidesUrlString) else { return }
63-
64-
openURL(url)
65+
openURL(url: DIContainer.urlFactory.getURL(withType: .userGuides))
66+
}
67+
}
68+
69+
CommandGroup(replacing: .windowList) {
70+
Button("Developer Documentation") {
71+
openURL(url: DIContainer.urlFactory.getURL(withType: .docs))
6572
}
73+
.keyboardShortcut(
74+
"0",
75+
modifiers: [.command, .shift])
6676
}
6777
}
6878
}
@@ -114,4 +124,9 @@ struct SnippetsLibraryApp: App {
114124
service?.perform(withItems: ["Please describe your problem here..."])
115125
}
116126

127+
private func openURL(url: URL?) {
128+
guard let safeURL = url else { return }
129+
openURL(safeURL)
130+
}
131+
117132
}

SnippetsLibrary/Assets.xcassets/Colors/Color.colorset/Contents.json

Lines changed: 0 additions & 38 deletions
This file was deleted.

SnippetsLibrary/Dependencies/DependencyContainer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ final class DependencyContainer {
1414
// MARK: - Services
1515

1616
lazy var snippetsParserService: SnippetsParserService = SnippetsParserServiceImpl()
17+
lazy var urlFactory: URLFactory = URLFactoryImpl()
1718

1819
lazy var databaseService: DatabaseService = DatabaseServiceImpl(
1920
logsService: logsService,

SnippetsLibrary/Modules/SnippetDetails/SnippetDetailsView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct SnippetDetailsView: View {
2222

2323
// MARK: - Stored Properties
2424

25+
@Environment(\.colorScheme) var colorScheme
2526
@Environment (\.presentationMode) var presentationMode
2627

2728
@ObservedObject private(set) var viewModel: SnippetDetailsViewModel
@@ -52,10 +53,10 @@ struct SnippetDetailsView: View {
5253
text: $viewModel.snippet.content,
5354
customization: SourceCodeTextEditor.Customization(
5455
didChangeText: { _ in },
55-
insertionPointColor: { .white },
56+
insertionPointColor: { colorScheme == .dark ? .white : .black },
5657
lexerForSource: { _ in SwiftLexer() },
5758
textViewDidBeginEditing: { _ in },
58-
theme: { CustomCodeTheme() }
59+
theme: { CustomCodeTheme(colorScheme: colorScheme) }
5960
),
6061
shouldBecomeFirstResponder: false
6162
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// URLFactory.swift
3+
// SnippetsLibrary
4+
//
5+
// Created by Krzysztof Łowiec on 23/09/2021.
6+
//
7+
8+
import Foundation
9+
10+
protocol URLFactory {
11+
func getURL(withType type: URLType) -> URL?
12+
}
13+
14+
final class URLFactoryImpl: URLFactory {
15+
16+
private enum Constants {
17+
static let userGuidesUrlString = "https://github.com/tryboxx/SnippetsLibrary/blob/main/README.md"
18+
static let developerDocumentationUrlString = "https://github.com/tryboxx/SnippetsLibrary/wiki"
19+
}
20+
21+
// MARK: - Methods
22+
23+
internal func getURL(withType type: URLType) -> URL? {
24+
switch type {
25+
case .userGuides:
26+
return URL(string: Constants.userGuidesUrlString)
27+
case .docs:
28+
return URL(string: Constants.developerDocumentationUrlString)
29+
}
30+
}
31+
32+
}

SnippetsLibrary/Supporting Files/CustomCodeTheme.swift

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,65 @@ import Sourceful
1010

1111
struct CustomCodeTheme: SourceCodeTheme {
1212

13+
private enum Constants {
14+
static let backgroundDarkColor = NSColor(red: 41/255, green: 42/255, blue: 48/255, alpha: 1.0)
15+
static let plainTypeLightColor = NSColor(red: 2/255, green: 2/255, blue: 2/255, alpha: 1.0)
16+
static let plainTypeDarkColor = NSColor(red: 223/255, green: 223/255, blue: 224/255, alpha: 1.0)
17+
static let numberTypeLightColor = NSColor(red: 40/255, green: 41/255, blue: 208/255, alpha: 1.0)
18+
static let numberTypeDarkColor = NSColor(red: 214/255, green: 202/255, blue: 134/255, alpha: 1.0)
19+
static let stringTypeLightColor = NSColor(red: 192/255, green: 62/255, blue: 41/255, alpha: 1.0)
20+
static let stringTypeDarkColor = NSColor(red: 239/255, green: 136/255, blue: 118/255, alpha: 1.0)
21+
static let identifierTypeLightColor = NSColor(red: 121/255, green: 82/255, blue: 178/255, alpha: 1.0)
22+
static let identifierTypeDarkColor = NSColor(red: 171/255, green: 131/255, blue: 228/255, alpha: 1.0)
23+
static let keywordTypeLightColor = NSColor(red: 160/255, green: 69/255, blue: 160/255, alpha: 1.0)
24+
static let keywordTypeDarkColor = NSColor(red: 238/255, green: 130/255, blue: 176/255, alpha: 1.0)
25+
static let commentColor = NSColor(red: 129/255.0, green: 140/255.0, blue: 150/255.0, alpha: 1.0)
26+
27+
static let font = NSFont.monospacedSystemFont(ofSize: 15, weight: .regular)
28+
static let gutterStyle = GutterStyle(backgroundColor: NSColor.clear, minimumWidth: 0)
29+
}
30+
31+
// MARK: - Stored Properties
32+
33+
private var colorScheme: ColorScheme = .dark
34+
1335
private static var lineNumbersColor: NSColor = .clear
14-
public let lineNumbersStyle: LineNumbersStyle? = nil
15-
public let gutterStyle: GutterStyle = GutterStyle(backgroundColor: Color.clear, minimumWidth: 0)
16-
public let font = NSFont.monospacedSystemFont(ofSize: 15, weight: .regular)
1736

18-
public let backgroundColor = Color(red: 41/255.0, green: 42/255, blue: 48/255, alpha: 1.0)
37+
internal let lineNumbersStyle: LineNumbersStyle? = nil
38+
internal let gutterStyle: GutterStyle = Constants.gutterStyle
39+
internal let font = Constants.font
40+
41+
// MARK: - Computed Properties
42+
43+
internal var backgroundColor: NSColor {
44+
return colorScheme == .dark ? Constants.backgroundDarkColor : NSColor.white
45+
}
46+
47+
// MARK: - Initialization
48+
49+
init(colorScheme: ColorScheme) {
50+
self.colorScheme = colorScheme
51+
}
52+
53+
// MARK: - Methods
1954

20-
public func color(for syntaxColorType: SourceCodeTokenType) -> NSColor {
55+
func color(for syntaxColorType: SourceCodeTokenType) -> NSColor {
2156
switch syntaxColorType {
2257
case .plain:
23-
return Color(red: 223/255, green: 223/255, blue: 224/255, alpha: 1.0)
58+
return colorScheme == .dark ? Constants.plainTypeDarkColor : Constants.plainTypeLightColor
2459
case .number:
25-
return Color(red: 214/255, green: 202/255, blue: 134/255, alpha: 1.0)
60+
return colorScheme == .dark ? Constants.numberTypeDarkColor : Constants.numberTypeLightColor
2661
case .string:
27-
return Color(red: 239/255, green: 136/255, blue: 118/255, alpha: 1.0)
62+
return colorScheme == .dark ? Constants.stringTypeDarkColor : Constants.stringTypeLightColor
2863
case .identifier:
29-
return Color(red: 171/255, green: 131/255, blue: 228/255, alpha: 1.0)
64+
return colorScheme == .dark ? Constants.identifierTypeDarkColor : Constants.identifierTypeLightColor
3065
case .keyword:
31-
return Color(red: 238/255, green: 130/255, blue: 176/255, alpha: 1.0)
66+
return colorScheme == .dark ? Constants.keywordTypeDarkColor : Constants.keywordTypeLightColor
3267
case .comment:
33-
return Color(red: 129/255.0, green: 140/255.0, blue: 150/255.0, alpha: 1.0)
68+
return Constants.commentColor
3469
case .editorPlaceholder:
35-
return .gray
70+
return colorScheme == .dark ? .gray : .lightGray
3671
}
3772
}
3873

39-
public init() {}
40-
4174
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// URLType.swift
3+
// SnippetsLibrary
4+
//
5+
// Created by Krzysztof Łowiec on 23/09/2021.
6+
//
7+
8+
import Foundation
9+
10+
enum URLType {
11+
case userGuides
12+
case docs
13+
}

0 commit comments

Comments
 (0)