Skip to content

Commit

Permalink
Merge pull request #8 from po-miyasaka/feature/1.0.8
Browse files Browse the repository at this point in the history
1.0.8
  • Loading branch information
po-miyasaka authored Jul 22, 2022
2 parents fcc6cb5 + ce2183b commit b884e6a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
8 changes: 4 additions & 4 deletions CopyHistory/CopyHistory.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
CODE_SIGN_ENTITLEMENTS = CopyHistory/CopyHistory.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 17;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = H6UU7923NK;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
Expand All @@ -285,7 +285,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 1.0.7;
MARKETING_VERSION = 1.0.8;
PRODUCT_BUNDLE_IDENTIFIER = "jp.po-miyasaka.CopyHistory.CopyHistory";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -301,7 +301,7 @@
CODE_SIGN_ENTITLEMENTS = CopyHistory/CopyHistory.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 17;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = H6UU7923NK;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
Expand All @@ -315,7 +315,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 1.0.7;
MARKETING_VERSION = 1.0.8;
PRODUCT_BUNDLE_IDENTIFIER = "jp.po-miyasaka.CopyHistory.CopyHistory";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
20 changes: 15 additions & 5 deletions CopyHistory/CopyHistory/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import WebKit

struct ContentView: View {
@StateObject var pasteboardService: PasteboardService = .build()
@AppStorage("isShowingKeyboardShortcuts") var isShowingKeyboardShortcuts = true
@FocusState var isFocus
@State var isAlertPresented: Bool = false
@State var focusedItemIndex: Int?
@AppStorage("isShowingKeyboardShortcuts") var isShowingKeyboardShortcuts = true
@AppStorage("isExpanded") var isExpanded: Bool = true
@AppStorage("isShowingRTF") var isShowingRTF: Bool = false
@AppStorage("isShowingHTML") var isShowingHTML: Bool = false
Expand Down Expand Up @@ -154,9 +154,13 @@ struct ContentView: View {
@ViewBuilder
func MainView() -> some View {
ScrollView {
Spacer() // there is a mysterious plain view at the top of the scrollview and it overlays this content. so this is put here
// there is a mysterious plain view at the top of the scrollview and it overlays this content. so this is put here
Spacer()
ScrollViewReader { proxy in
VStack(spacing: 0) { // This doesn't make ScrollView + ForEach make additional padding
LazyVStack(spacing: 0) {
// ・This doesn't make ScrollView + ForEach make additional padding, https://www.reddit.com/r/SwiftUI/comments/e607z3/swiftui_scrollview_foreach_padding_weird/
// ・Lazy improves performance the inclement search

ForEach(Array(zip(pasteboardService.copiedItems.indices, pasteboardService.copiedItems)), id: \.1.dataHash) { index, item in

Row(item: item,
Expand All @@ -173,6 +177,12 @@ struct ContentView: View {
isShowingRTF: $isShowingRTF,
isShowingHTML: $isShowingHTML)
.id(item.dataHash)
.onHover(perform: { hover in
if hover {
focusedItemIndex = index
}

})
}
}

Expand Down Expand Up @@ -372,10 +382,10 @@ struct Row: View, Equatable {
Group {
if let content = item.content, let image = NSImage(data: content) {
Image(nsImage: image).resizable().scaledToFit().frame(maxHeight: 300)
} else if isShowingRTF, item.contentTypeString?.contains("rtf") == true, let attributedString = item.attributeString {
} else if isShowingRTF, let attributedString = item.attributeString {
Text(AttributedString(attributedString))

} else if isShowingHTML, item.contentTypeString?.contains("html") == true, let attributedString = item.htmlString {
} else if isShowingHTML, let attributedString = item.htmlString {
Text(AttributedString(attributedString))
} else if let url = item.fileURL {
// TODO: why images disappear after first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
<attribute name="contentTypeString" attributeType="String"/>
<attribute name="dataHash" optional="YES" attributeType="String"/>
<attribute name="favorite" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="htmlStringCached" optional="YES" transient="YES" attributeType="Transformable" customClassName="NSAttributedString"/>
<attribute name="name" attributeType="String"/>
<attribute name="rawString" optional="YES" attributeType="String"/>
<attribute name="rtfStringCached" optional="YES" transient="YES" attributeType="Transformable" customClassName=".NSAttributedString"/>
<attribute name="updateDate" attributeType="Date" usesScalarValueType="NO"/>
</entity>
<elements>
<element name="CopiedItem" positionX="160" positionY="192" width="128" height="149"/>
<element name="CopiedItem" positionX="160" positionY="192" width="128" height="179"/>
</elements>
</model>
15 changes: 12 additions & 3 deletions CopyHistory/CopyHistory/PasteboardService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,24 @@ extension CopiedItem {
}

var attributeString: NSAttributedString? {
guard let content = content else { return nil }
if let att = rtfStringCached {
return att
}
guard contentTypeString?.contains("rtf") == true, let content = content else { return nil }

let attributeString = (try? NSAttributedString(data: content, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.rtf], documentAttributes: nil))
rtfStringCached = attributeString
return attributeString
}

var htmlString: NSAttributedString? {
guard let content = content else { return nil }
let attributeString = (try? NSAttributedString(data: content, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil))
if let att = htmlStringCached {
return att
}
guard contentTypeString?.contains("html") == true, let content = content else { return nil }

let attributeString = (try? NSAttributedString(data: content, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil))
htmlStringCached = attributeString
return attributeString
}

Expand Down

0 comments on commit b884e6a

Please sign in to comment.