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

Commit

Permalink
Add turtle, ntriples, sparql modes + Add tooltips on hover
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallino16 committed Nov 2, 2020
1 parent 6569d00 commit 569dad0
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 15 deletions.
12 changes: 8 additions & 4 deletions Snip.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
796B093524D1B95B006904C4 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 796B093424D1B95B006904C4 /* Color.swift */; };
796B093724D1BA1F006904C4 /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 796B093624D1BA1F006904C4 /* Date.swift */; };
797B92EC24FCDE2900071669 /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 797B92EB24FCDE2900071669 /* Colors.xcassets */; };
798AA66725500FE300CBDC9C /* Tooltip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 798AA66625500FE300CBDC9C /* Tooltip.swift */; };
79956A4224E5463300B823E1 /* API.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79956A4124E5463300B823E1 /* API.swift */; };
79956A4424E5772200B823E1 /* Endpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79956A4324E5772200B823E1 /* Endpoint.swift */; };
79956A4724E57AC700B823E1 /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79956A4624E57AC700B823E1 /* Dictionary.swift */; };
Expand Down Expand Up @@ -117,6 +118,7 @@
796B093424D1B95B006904C4 /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
796B093624D1BA1F006904C4 /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; };
797B92EB24FCDE2900071669 /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = "<group>"; };
798AA66625500FE300CBDC9C /* Tooltip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tooltip.swift; sourceTree = "<group>"; };
79956A4124E5463300B823E1 /* API.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = API.swift; sourceTree = "<group>"; };
79956A4324E5772200B823E1 /* Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Endpoint.swift; sourceTree = "<group>"; };
79956A4624E57AC700B823E1 /* Dictionary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dictionary.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -415,6 +417,7 @@
79F07A2824D3050500469324 /* ImageButton.swift */,
791AC9C424DAE45D00CAB87C /* DeferView.swift */,
79284D6C2507DE7F00210E61 /* PagerView.swift */,
798AA66625500FE300CBDC9C /* Tooltip.swift */,
);
path = Misc;
sourceTree = "<group>";
Expand Down Expand Up @@ -585,6 +588,7 @@
79BC1D3324D17124008FD16E /* Sidebar.swift in Sources */,
79A6F64C24D20B8C0037C5FF /* CodeMirrorViewController.swift in Sources */,
79BC1D2024D16E67008FD16E /* AppDelegate.swift in Sources */,
798AA66725500FE300CBDC9C /* Tooltip.swift in Sources */,
79A6F64824D206EE0037C5FF /* CodeViewConstants.swift in Sources */,
79A6F65324D2B9D40037C5FF /* String.swift in Sources */,
791AC9C524DAE45D00CAB87C /* DeferView.swift in Sources */,
Expand Down Expand Up @@ -784,7 +788,7 @@
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 9;
DEVELOPMENT_ASSET_PATHS = "\"Snip/Preview Content\"";
DEVELOPMENT_TEAM = 7XBGRFP286;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -795,7 +799,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.3;
MARKETING_VERSION = 1.4;
PRODUCT_BUNDLE_IDENTIFIER = com.pictarine.Snip;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "Snip DEBUG";
Expand All @@ -811,7 +815,7 @@
CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 8;
CURRENT_PROJECT_VERSION = 9;
DEVELOPMENT_ASSET_PATHS = "\"Snip/Preview Content\"";
DEVELOPMENT_TEAM = 7XBGRFP286;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -822,7 +826,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.3;
MARKETING_VERSION = 1.4;
PRODUCT_BUNDLE_IDENTIFIER = com.pictarine.Snip;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "Snip APPSTORE";
Expand Down
29 changes: 18 additions & 11 deletions Snip/Components/CodeViewer/CodeActionsTopBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ struct CodeActionsTopBar: View {
self.viewModel.onRename($0)
})
)
.font(Font.custom("HelveticaNeue", size: 20))
.foregroundColor(themeTextColor)
.frame(maxHeight: .infinity)
.textFieldStyle(PlainTextFieldStyle())
.font(Font.custom("HelveticaNeue", size: 20))
.foregroundColor(themeTextColor)
.frame(maxHeight: .infinity)
.textFieldStyle(PlainTextFieldStyle())

if syncManager.isAuthenticated {
ZStack {
Expand All @@ -51,7 +51,7 @@ struct CodeActionsTopBar: View {
.animation(Animation.easeOut(duration: 1).repeatForever(autoreverses: false))
.onAppear() {
self.moveRightLeft.toggle()
}
}
}
}
else {
Expand All @@ -63,7 +63,8 @@ struct CodeActionsTopBar: View {
.fill(viewModel.syncState == .local ? Color.RED_500 : Color.green)
.frame(width: 8, height: 8)
.offset(x: 7, y: 6)
)
)
.tooltip("Add to Gist")
}

}
Expand All @@ -73,6 +74,7 @@ struct CodeActionsTopBar: View {
ImageButton(imageName: "ic_open",
action: viewModel.openRemoteURL,
content: { EmptyView() })
.tooltip("Open snippet post")
}

if viewModel.onPreviewToggle != nil {
Expand All @@ -83,26 +85,31 @@ struct CodeActionsTopBar: View {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
self.isPreviewEnabled.toggle()
}
},
},
content: { EmptyView() })
.tooltip("Show/Hide preview")
}

ImageButton(imageName: viewModel.isSnipFavorite ? "ic_fav_selected" : "ic_fav",
action: viewModel.onToggleFavorite,
content: { EmptyView() })
.tooltip("Add to favorites")
ImageButton(imageName: "ic_delete",
action: viewModel.onDelete,
content: { EmptyView() })
.tooltip("Delete snippet")
ImageButton(imageName: "ic_share",
action: {
self.showSharingActions = true
},
},
content: {
SharingsPicker(isPresented: self.$showSharingActions, sharingItems: ["\(self.viewModel.snipCode) \n\n - Shared via Snip https://cutt.ly/snip"])
})
})
.tooltip("Share snippet")
ImageButton(imageName: "ic_info",
action: { self.showInfos.toggle() },
content: { EmptyView() })
.tooltip("Snippet info")
.popover(
isPresented: self.$showInfos,
arrowEdge: .bottom
Expand All @@ -115,7 +122,7 @@ struct CodeActionsTopBar: View {
Text("Last updated \(self.viewModel.snipLastUpdate.dateAndTimetoString())")
.padding(.top)
}.padding(16)
}
}

}
.background(themeSecondaryColor.opacity(0.4))
Expand Down Expand Up @@ -170,7 +177,7 @@ final class CodeActionsViewModel: ObservableObject {

func openRemoteURL() {
guard let sourceURL = remoteURL,
let url = URL(string: sourceURL) else { return }
let url = URL(string: sourceURL) else { return }
NSWorkspace.shared.open(url)
}
}
Expand Down
60 changes: 60 additions & 0 deletions Snip/Components/Misc/Tooltip.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Tooltip.swift
// Snip
//
// Created by Anthony Fernandez on 11/2/20.
// Copyright © 2020 pictarine. All rights reserved.
//

import Foundation
import SwiftUI


extension View {
func tooltip(_ tip: String) -> some View {
background(GeometryReader { childGeometry in
TooltipView(tip, geometry: childGeometry) {
self
}
})
}
}

private struct TooltipView<Content>: View where Content: View {
let content: () -> Content
let tip: String
let geometry: GeometryProxy

init(_ tip: String, geometry: GeometryProxy, @ViewBuilder content: @escaping () -> Content) {
self.content = content
self.tip = tip
self.geometry = geometry
}

var body: some View {
Tooltip(tip, content: content)
.frame(width: geometry.size.width, height: geometry.size.height)
}
}

private struct Tooltip<Content: View>: NSViewRepresentable {
typealias NSViewType = NSHostingView<Content>

init(_ text: String?, @ViewBuilder content: () -> Content) {
self.text = text
self.content = content()
}

let text: String?
let content: Content

func makeNSView(context _: Context) -> NSHostingView<Content> {
NSViewType(rootView: content)
}

func updateNSView(_ nsView: NSHostingView<Content>, context _: Context) {
nsView.rootView = content
nsView.toolTip = text
}
}

2 changes: 2 additions & 0 deletions Snip/Components/Sidebar/Sidebar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct Sidebar: View {
settings.isSettingsOpened.toggle()
}
}, content: { EmptyView() })
.tooltip("Settings")
Spacer()

Text(syncManager.connectedUser?.login ?? "")
Expand Down Expand Up @@ -68,6 +69,7 @@ struct Sidebar: View {
)

}
.tooltip("Connect to Gist from GitHub")
.alert(isPresented: $showingLogoutAlert) {
Alert(title: Text("Logout from Github"),
message: Text("Are you sure about that?"),
Expand Down
12 changes: 12 additions & 0 deletions Snip/Model/Mode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public enum CodeMode: String {
case lua
case markdown
case maths
case ntriples
case pascal
case perl
case php
Expand All @@ -148,10 +149,12 @@ public enum CodeMode: String {
case shell
case sql
case sqllite
case sparql
case mysql
case latex
case swift
case text
case turtle
case vb
case vue
case xml
Expand Down Expand Up @@ -191,6 +194,7 @@ public enum CodeMode: String {
CodeMode.lua.mode(),
CodeMode.markdown.mode(),
CodeMode.maths.mode(),
CodeMode.ntriples.mode(),
CodeMode.pascal.mode(),
CodeMode.perl.mode(),
CodeMode.php.mode(),
Expand All @@ -206,10 +210,12 @@ public enum CodeMode: String {
CodeMode.shell.mode(),
CodeMode.sql.mode(),
CodeMode.sqllite.mode(),
CodeMode.sparql.mode(),
CodeMode.mysql.mode(),
CodeMode.latex.mode(),
CodeMode.swift.mode(),
CodeMode.text.mode(),
CodeMode.turtle.mode(),
CodeMode.vb.mode(),
CodeMode.vue.mode(),
CodeMode.xml.mode(),
Expand Down Expand Up @@ -289,6 +295,8 @@ public enum CodeMode: String {
return Mode(name: "markdown", mimeType: "text/markdown")
case .maths:
return Mode(name: "maths", mimeType: "text/x-mathematica")
case .ntriples:
return Mode(name: "ntriples", mimeType: "application/n-triples")
case .pascal:
return Mode(name: "pascal", mimeType: "text/x-pascal")
case .perl:
Expand Down Expand Up @@ -319,6 +327,8 @@ public enum CodeMode: String {
return Mode(name: "sql", mimeType: "text/x-sql")
case .sqllite:
return Mode(name: "sqllite", mimeType: "text/x-sqlite")
case .sparql:
return Mode(name: "sparql", mimeType: "application/sparql-query")
case .mysql:
return Mode(name: "mysql", mimeType: "text/x-mysql")
case .latex:
Expand All @@ -327,6 +337,8 @@ public enum CodeMode: String {
return Mode(name: "swift", mimeType: "text/x-swift")
case .text:
return Mode(name: "text", mimeType: "text/plain-text")
case .turtle:
return Mode(name: "turtle", mimeType: "text/turtle")
case .vb:
return Mode(name: "vb", mimeType: "text/x-vb")
case .vue:
Expand Down

0 comments on commit 569dad0

Please sign in to comment.