Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 569dad0

Browse files
committed
Add turtle, ntriples, sparql modes + Add tooltips on hover
1 parent 6569d00 commit 569dad0

File tree

5 files changed

+100
-15
lines changed

5 files changed

+100
-15
lines changed

Snip.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
796B093524D1B95B006904C4 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 796B093424D1B95B006904C4 /* Color.swift */; };
3939
796B093724D1BA1F006904C4 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 796B093624D1BA1F006904C4 /* Date.swift */; };
4040
797B92EC24FCDE2900071669 /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 797B92EB24FCDE2900071669 /* Colors.xcassets */; };
41+
798AA66725500FE300CBDC9C /* Tooltip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 798AA66625500FE300CBDC9C /* Tooltip.swift */; };
4142
79956A4224E5463300B823E1 /* API.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79956A4124E5463300B823E1 /* API.swift */; };
4243
79956A4424E5772200B823E1 /* Endpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79956A4324E5772200B823E1 /* Endpoint.swift */; };
4344
79956A4724E57AC700B823E1 /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79956A4624E57AC700B823E1 /* Dictionary.swift */; };
@@ -117,6 +118,7 @@
117118
796B093424D1B95B006904C4 /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
118119
796B093624D1BA1F006904C4 /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; };
119120
797B92EB24FCDE2900071669 /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = "<group>"; };
121+
798AA66625500FE300CBDC9C /* Tooltip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tooltip.swift; sourceTree = "<group>"; };
120122
79956A4124E5463300B823E1 /* API.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = API.swift; sourceTree = "<group>"; };
121123
79956A4324E5772200B823E1 /* Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Endpoint.swift; sourceTree = "<group>"; };
122124
79956A4624E57AC700B823E1 /* Dictionary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dictionary.swift; sourceTree = "<group>"; };
@@ -415,6 +417,7 @@
415417
79F07A2824D3050500469324 /* ImageButton.swift */,
416418
791AC9C424DAE45D00CAB87C /* DeferView.swift */,
417419
79284D6C2507DE7F00210E61 /* PagerView.swift */,
420+
798AA66625500FE300CBDC9C /* Tooltip.swift */,
418421
);
419422
path = Misc;
420423
sourceTree = "<group>";
@@ -585,6 +588,7 @@
585588
79BC1D3324D17124008FD16E /* Sidebar.swift in Sources */,
586589
79A6F64C24D20B8C0037C5FF /* CodeMirrorViewController.swift in Sources */,
587590
79BC1D2024D16E67008FD16E /* AppDelegate.swift in Sources */,
591+
798AA66725500FE300CBDC9C /* Tooltip.swift in Sources */,
588592
79A6F64824D206EE0037C5FF /* CodeViewConstants.swift in Sources */,
589593
79A6F65324D2B9D40037C5FF /* String.swift in Sources */,
590594
791AC9C524DAE45D00CAB87C /* DeferView.swift in Sources */,
@@ -784,7 +788,7 @@
784788
CODE_SIGN_IDENTITY = "Mac Developer";
785789
CODE_SIGN_STYLE = Manual;
786790
COMBINE_HIDPI_IMAGES = YES;
787-
CURRENT_PROJECT_VERSION = 8;
791+
CURRENT_PROJECT_VERSION = 9;
788792
DEVELOPMENT_ASSET_PATHS = "\"Snip/Preview Content\"";
789793
DEVELOPMENT_TEAM = 7XBGRFP286;
790794
ENABLE_HARDENED_RUNTIME = YES;
@@ -795,7 +799,7 @@
795799
"@executable_path/../Frameworks",
796800
);
797801
MACOSX_DEPLOYMENT_TARGET = 10.15;
798-
MARKETING_VERSION = 1.3;
802+
MARKETING_VERSION = 1.4;
799803
PRODUCT_BUNDLE_IDENTIFIER = com.pictarine.Snip;
800804
PRODUCT_NAME = "$(TARGET_NAME)";
801805
PROVISIONING_PROFILE_SPECIFIER = "Snip DEBUG";
@@ -811,7 +815,7 @@
811815
CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application";
812816
CODE_SIGN_STYLE = Manual;
813817
COMBINE_HIDPI_IMAGES = YES;
814-
CURRENT_PROJECT_VERSION = 8;
818+
CURRENT_PROJECT_VERSION = 9;
815819
DEVELOPMENT_ASSET_PATHS = "\"Snip/Preview Content\"";
816820
DEVELOPMENT_TEAM = 7XBGRFP286;
817821
ENABLE_HARDENED_RUNTIME = YES;
@@ -822,7 +826,7 @@
822826
"@executable_path/../Frameworks",
823827
);
824828
MACOSX_DEPLOYMENT_TARGET = 10.15;
825-
MARKETING_VERSION = 1.3;
829+
MARKETING_VERSION = 1.4;
826830
PRODUCT_BUNDLE_IDENTIFIER = com.pictarine.Snip;
827831
PRODUCT_NAME = "$(TARGET_NAME)";
828832
PROVISIONING_PROFILE_SPECIFIER = "Snip APPSTORE";

Snip/Components/CodeViewer/CodeActionsTopBar.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ struct CodeActionsTopBar: View {
3333
self.viewModel.onRename($0)
3434
})
3535
)
36-
.font(Font.custom("HelveticaNeue", size: 20))
37-
.foregroundColor(themeTextColor)
38-
.frame(maxHeight: .infinity)
39-
.textFieldStyle(PlainTextFieldStyle())
36+
.font(Font.custom("HelveticaNeue", size: 20))
37+
.foregroundColor(themeTextColor)
38+
.frame(maxHeight: .infinity)
39+
.textFieldStyle(PlainTextFieldStyle())
4040

4141
if syncManager.isAuthenticated {
4242
ZStack {
@@ -51,7 +51,7 @@ struct CodeActionsTopBar: View {
5151
.animation(Animation.easeOut(duration: 1).repeatForever(autoreverses: false))
5252
.onAppear() {
5353
self.moveRightLeft.toggle()
54-
}
54+
}
5555
}
5656
}
5757
else {
@@ -63,7 +63,8 @@ struct CodeActionsTopBar: View {
6363
.fill(viewModel.syncState == .local ? Color.RED_500 : Color.green)
6464
.frame(width: 8, height: 8)
6565
.offset(x: 7, y: 6)
66-
)
66+
)
67+
.tooltip("Add to Gist")
6768
}
6869

6970
}
@@ -73,6 +74,7 @@ struct CodeActionsTopBar: View {
7374
ImageButton(imageName: "ic_open",
7475
action: viewModel.openRemoteURL,
7576
content: { EmptyView() })
77+
.tooltip("Open snippet post")
7678
}
7779

7880
if viewModel.onPreviewToggle != nil {
@@ -83,26 +85,31 @@ struct CodeActionsTopBar: View {
8385
DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
8486
self.isPreviewEnabled.toggle()
8587
}
86-
},
88+
},
8789
content: { EmptyView() })
90+
.tooltip("Show/Hide preview")
8891
}
8992

9093
ImageButton(imageName: viewModel.isSnipFavorite ? "ic_fav_selected" : "ic_fav",
9194
action: viewModel.onToggleFavorite,
9295
content: { EmptyView() })
96+
.tooltip("Add to favorites")
9397
ImageButton(imageName: "ic_delete",
9498
action: viewModel.onDelete,
9599
content: { EmptyView() })
100+
.tooltip("Delete snippet")
96101
ImageButton(imageName: "ic_share",
97102
action: {
98103
self.showSharingActions = true
99-
},
104+
},
100105
content: {
101106
SharingsPicker(isPresented: self.$showSharingActions, sharingItems: ["\(self.viewModel.snipCode) \n\n - Shared via Snip https://cutt.ly/snip"])
102-
})
107+
})
108+
.tooltip("Share snippet")
103109
ImageButton(imageName: "ic_info",
104110
action: { self.showInfos.toggle() },
105111
content: { EmptyView() })
112+
.tooltip("Snippet info")
106113
.popover(
107114
isPresented: self.$showInfos,
108115
arrowEdge: .bottom
@@ -115,7 +122,7 @@ struct CodeActionsTopBar: View {
115122
Text("Last updated \(self.viewModel.snipLastUpdate.dateAndTimetoString())")
116123
.padding(.top)
117124
}.padding(16)
118-
}
125+
}
119126

120127
}
121128
.background(themeSecondaryColor.opacity(0.4))
@@ -170,7 +177,7 @@ final class CodeActionsViewModel: ObservableObject {
170177

171178
func openRemoteURL() {
172179
guard let sourceURL = remoteURL,
173-
let url = URL(string: sourceURL) else { return }
180+
let url = URL(string: sourceURL) else { return }
174181
NSWorkspace.shared.open(url)
175182
}
176183
}

Snip/Components/Misc/Tooltip.swift

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// Tooltip.swift
3+
// Snip
4+
//
5+
// Created by Anthony Fernandez on 11/2/20.
6+
// Copyright © 2020 pictarine. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import SwiftUI
11+
12+
13+
extension View {
14+
func tooltip(_ tip: String) -> some View {
15+
background(GeometryReader { childGeometry in
16+
TooltipView(tip, geometry: childGeometry) {
17+
self
18+
}
19+
})
20+
}
21+
}
22+
23+
private struct TooltipView<Content>: View where Content: View {
24+
let content: () -> Content
25+
let tip: String
26+
let geometry: GeometryProxy
27+
28+
init(_ tip: String, geometry: GeometryProxy, @ViewBuilder content: @escaping () -> Content) {
29+
self.content = content
30+
self.tip = tip
31+
self.geometry = geometry
32+
}
33+
34+
var body: some View {
35+
Tooltip(tip, content: content)
36+
.frame(width: geometry.size.width, height: geometry.size.height)
37+
}
38+
}
39+
40+
private struct Tooltip<Content: View>: NSViewRepresentable {
41+
typealias NSViewType = NSHostingView<Content>
42+
43+
init(_ text: String?, @ViewBuilder content: () -> Content) {
44+
self.text = text
45+
self.content = content()
46+
}
47+
48+
let text: String?
49+
let content: Content
50+
51+
func makeNSView(context _: Context) -> NSHostingView<Content> {
52+
NSViewType(rootView: content)
53+
}
54+
55+
func updateNSView(_ nsView: NSHostingView<Content>, context _: Context) {
56+
nsView.rootView = content
57+
nsView.toolTip = text
58+
}
59+
}
60+

Snip/Components/Sidebar/Sidebar.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct Sidebar: View {
4141
settings.isSettingsOpened.toggle()
4242
}
4343
}, content: { EmptyView() })
44+
.tooltip("Settings")
4445
Spacer()
4546

4647
Text(syncManager.connectedUser?.login ?? "")
@@ -68,6 +69,7 @@ struct Sidebar: View {
6869
)
6970

7071
}
72+
.tooltip("Connect to Gist from GitHub")
7173
.alert(isPresented: $showingLogoutAlert) {
7274
Alert(title: Text("Logout from Github"),
7375
message: Text("Are you sure about that?"),

Snip/Model/Mode.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public enum CodeMode: String {
133133
case lua
134134
case markdown
135135
case maths
136+
case ntriples
136137
case pascal
137138
case perl
138139
case php
@@ -148,10 +149,12 @@ public enum CodeMode: String {
148149
case shell
149150
case sql
150151
case sqllite
152+
case sparql
151153
case mysql
152154
case latex
153155
case swift
154156
case text
157+
case turtle
155158
case vb
156159
case vue
157160
case xml
@@ -191,6 +194,7 @@ public enum CodeMode: String {
191194
CodeMode.lua.mode(),
192195
CodeMode.markdown.mode(),
193196
CodeMode.maths.mode(),
197+
CodeMode.ntriples.mode(),
194198
CodeMode.pascal.mode(),
195199
CodeMode.perl.mode(),
196200
CodeMode.php.mode(),
@@ -206,10 +210,12 @@ public enum CodeMode: String {
206210
CodeMode.shell.mode(),
207211
CodeMode.sql.mode(),
208212
CodeMode.sqllite.mode(),
213+
CodeMode.sparql.mode(),
209214
CodeMode.mysql.mode(),
210215
CodeMode.latex.mode(),
211216
CodeMode.swift.mode(),
212217
CodeMode.text.mode(),
218+
CodeMode.turtle.mode(),
213219
CodeMode.vb.mode(),
214220
CodeMode.vue.mode(),
215221
CodeMode.xml.mode(),
@@ -289,6 +295,8 @@ public enum CodeMode: String {
289295
return Mode(name: "markdown", mimeType: "text/markdown")
290296
case .maths:
291297
return Mode(name: "maths", mimeType: "text/x-mathematica")
298+
case .ntriples:
299+
return Mode(name: "ntriples", mimeType: "application/n-triples")
292300
case .pascal:
293301
return Mode(name: "pascal", mimeType: "text/x-pascal")
294302
case .perl:
@@ -319,6 +327,8 @@ public enum CodeMode: String {
319327
return Mode(name: "sql", mimeType: "text/x-sql")
320328
case .sqllite:
321329
return Mode(name: "sqllite", mimeType: "text/x-sqlite")
330+
case .sparql:
331+
return Mode(name: "sparql", mimeType: "application/sparql-query")
322332
case .mysql:
323333
return Mode(name: "mysql", mimeType: "text/x-mysql")
324334
case .latex:
@@ -327,6 +337,8 @@ public enum CodeMode: String {
327337
return Mode(name: "swift", mimeType: "text/x-swift")
328338
case .text:
329339
return Mode(name: "text", mimeType: "text/plain-text")
340+
case .turtle:
341+
return Mode(name: "turtle", mimeType: "text/turtle")
330342
case .vb:
331343
return Mode(name: "vb", mimeType: "text/x-vb")
332344
case .vue:

0 commit comments

Comments
 (0)