Skip to content

Commit

Permalink
- Adds ability to scan and insert documents / photos just in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
glushchenko committed Apr 3, 2022
1 parent 4a43c25 commit e8d300b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 11 deletions.
30 changes: 19 additions & 11 deletions FSNotes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@
D7793C731F211C6000CA39B7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7793C721F211C6000CA39B7 /* AppDelegate.swift */; };
D7793C751F211C6000CA39B7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7793C741F211C6000CA39B7 /* ViewController.swift */; };
D779C7BB1F415C0300FADEE1 /* PrefsWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D779C7BA1F415BE300FADEE1 /* PrefsWindowController.swift */; };
D77AD7FC27F9D1C90077BD45 /* Data+.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77AD7FB27F9D1C90077BD45 /* Data+.swift */; };
D77AD7FD27F9D1C90077BD45 /* Data+.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77AD7FB27F9D1C90077BD45 /* Data+.swift */; };
D77AD7FE27F9D1C90077BD45 /* Data+.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77AD7FB27F9D1C90077BD45 /* Data+.swift */; };
D77AD7FF27F9D1C90077BD45 /* Data+.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77AD7FB27F9D1C90077BD45 /* Data+.swift */; };
D77B9E9B20DE53E0003FAA27 /* archive.png in Resources */ = {isa = PBXBuildFile; fileRef = D77B9E9A20DE53E0003FAA27 /* archive.png */; };
D77B9E9C20DE53E1003FAA27 /* archive.png in Resources */ = {isa = PBXBuildFile; fileRef = D77B9E9A20DE53E0003FAA27 /* archive.png */; };
D77CC041216A608500582B97 /* EditorScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77CC040216A608500582B97 /* EditorScrollView.swift */; };
Expand All @@ -519,7 +523,6 @@
D78678CC2093AE10001A6620 /* UndoData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D78678CA2093AE10001A6620 /* UndoData.swift */; };
D7892AD12493C27800B3DDAE /* CoreNote.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7DCFECC2108C7850059B37B /* CoreNote.swift */; };
D78C6CBF246D7B78007AF7F2 /* wikilink.png in Resources */ = {isa = PBXBuildFile; fileRef = D78C6CBE246D7B78007AF7F2 /* wikilink.png */; };
D78DC70D2478415200C5BB43 /* MPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D730829123084340003185D1 /* MPreviewView.swift */; };
D78DC70F2479838E00C5BB43 /* edit_preview_controller.png in Resources */ = {isa = PBXBuildFile; fileRef = D78DC70E2479838E00C5BB43 /* edit_preview_controller.png */; };
D78DC7112479878800C5BB43 /* preview_editor_controller.png in Resources */ = {isa = PBXBuildFile; fileRef = D78DC7102479878800C5BB43 /* preview_editor_controller.png */; };
D78DC71E247AE47D00C5BB43 /* plus.png in Resources */ = {isa = PBXBuildFile; fileRef = D78DC712247AE46D00C5BB43 /* plus.png */; };
Expand Down Expand Up @@ -1389,6 +1392,7 @@
D7793C791F211C6000CA39B7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
D7793C7C1F211C6000CA39B7 /* FSNotes.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = FSNotes.entitlements; sourceTree = "<group>"; };
D779C7BA1F415BE300FADEE1 /* PrefsWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefsWindowController.swift; sourceTree = "<group>"; };
D77AD7FB27F9D1C90077BD45 /* Data+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+.swift"; sourceTree = "<group>"; };
D77B9E9A20DE53E0003FAA27 /* archive.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = archive.png; sourceTree = "<group>"; };
D77CC040216A608500582B97 /* EditorScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorScrollView.swift; sourceTree = "<group>"; };
D77E05282463124300AD7772 /* StorageType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageType.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1749,6 +1753,7 @@
D796EB40251E127300CE5C80 /* NSPasteboard+.swift */,
D7680FB125D02B2C00810DA8 /* FileManager+.swift */,
D792DD9527A6D71C006ADC01 /* String+Punycode.swift */,
D77AD7FB27F9D1C90077BD45 /* Data+.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -2162,7 +2167,6 @@
D75E341122462442006AD1C1 /* FSNotes Info (Notarized).plist */,
D7793C7C1F211C6000CA39B7 /* FSNotes.entitlements */,
D78D20D41F934C05006DBBC3 /* FSNotes (CloudKit).entitlements */,
D730829123084340003185D1 /* MPreviewView.swift */,
);
path = FSNotes;
sourceTree = "<group>";
Expand Down Expand Up @@ -2302,6 +2306,7 @@
2799407B218484C900727B20 /* TitleBarView.swift */,
D7153E082285EC6100A2C20F /* TitleTextField.swift */,
D768D75B245ED6470028F344 /* VerticallyAlignedTextFieldCell.swift */,
D730829123084340003185D1 /* MPreviewView.swift */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -3708,6 +3713,7 @@
D75E33AB22462442006AD1C1 /* ViewController+Print.swift in Sources */,
D75E33AC22462442006AD1C1 /* FileWatcherEvent.swift in Sources */,
D75E33AD22462442006AD1C1 /* NSAttributedStringKey+.swift in Sources */,
D77AD7FE27F9D1C90077BD45 /* Data+.swift in Sources */,
D75E33AE22462442006AD1C1 /* PreviewTextField.swift in Sources */,
D75E33AF22462442006AD1C1 /* SortBy.swift in Sources */,
D75E33B022462442006AD1C1 /* NotesTableView.swift in Sources */,
Expand Down Expand Up @@ -3873,6 +3879,7 @@
D71AA0222143A4A8004AFD2A /* MoveViewController.swift in Sources */,
D7F6CFF02056AC22008C584A /* LanguageViewController.swift in Sources */,
D7CDE9DE216178DE00DC5978 /* AppearanceType.swift in Sources */,
D77AD7FF27F9D1C90077BD45 /* Data+.swift in Sources */,
D7BDFE5D201F677B00897A58 /* UserDefaultsManagement.swift in Sources */,
D7E6D9D42080862F003ECAFC /* SidebarItemType.swift in Sources */,
D780207C231FA147007F14DC /* CodeTextProcessor.swift in Sources */,
Expand All @@ -3894,7 +3901,6 @@
D7B4AC612471253100F3888A /* NoteMeta.swift in Sources */,
6F13BB7920FEE6070005E120 /* UIFont+.swift in Sources */,
D78115632153B36C004FA1CA /* Buttons.swift in Sources */,
D78DC70D2478415200C5BB43 /* MPreviewView.swift in Sources */,
D73673A820D10CF2000BA61D /* CloudDriveManager.swift in Sources */,
D7EDEDFD21920402000B8C1A /* NoteCellView+.swift in Sources */,
D767938B201F21F5000F7BBF /* ViewController.swift in Sources */,
Expand Down Expand Up @@ -3994,6 +4000,7 @@
D772C8842217362C007E440B /* ViewController+Print.swift in Sources */,
D7DD5A8A1F88D50000CE947E /* FileWatcherEvent.swift in Sources */,
D7487FED2174E62B00D09383 /* NSAttributedStringKey+.swift in Sources */,
D77AD7FC27F9D1C90077BD45 /* Data+.swift in Sources */,
D7CE196C1FA4BA5E004BF8EE /* PreviewTextField.swift in Sources */,
D7679376201F0BFD000F7BBF /* SortBy.swift in Sources */,
D7A415141F2FBDA00099B82C /* NotesTableView.swift in Sources */,
Expand Down Expand Up @@ -4114,6 +4121,7 @@
D772C8852217362C007E440B /* ViewController+Print.swift in Sources */,
D7E81C381F925B5F00416A91 /* Storage.swift in Sources */,
D7487FEC2174E62B00D09383 /* NSAttributedStringKey+.swift in Sources */,
D77AD7FD27F9D1C90077BD45 /* Data+.swift in Sources */,
D7679377201F0BFD000F7BBF /* SortBy.swift in Sources */,
D7E81C391F925B5F00416A91 /* FileWatcherEvent.swift in Sources */,
D7B024A82019BCF3008544C3 /* NoteAttribute.swift in Sources */,
Expand Down Expand Up @@ -4534,7 +4542,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 518;
CURRENT_PROJECT_VERSION = 519;
DEVELOPMENT_TEAM = 866P6MTE92;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -4547,7 +4555,7 @@
INFOPLIST_FILE = "FSNotes Info (Notarized).plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 5.3.7;
MARKETING_VERSION = 5.3.8;
PRODUCT_BUNDLE_IDENTIFIER = co.fluder.FSNotes;
PRODUCT_NAME = FSNotes;
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -4569,7 +4577,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 518;
CURRENT_PROJECT_VERSION = 519;
DEPLOYMENT_LOCATION = NO;
DEVELOPMENT_TEAM = 866P6MTE92;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
Expand All @@ -4583,7 +4591,7 @@
INFOPLIST_FILE = "FSNotes Info (Notarized).plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 5.3.7;
MARKETING_VERSION = 5.3.8;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = co.fluder.FSNotes;
PRODUCT_NAME = FSNotes;
Expand Down Expand Up @@ -4900,7 +4908,7 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 518;
CURRENT_PROJECT_VERSION = 519;
DEVELOPMENT_TEAM = 866P6MTE92;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
ENABLE_NS_ASSERTIONS = NO;
Expand All @@ -4912,7 +4920,7 @@
INFOPLIST_FILE = FSNotes/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 5.3.7;
MARKETING_VERSION = 5.3.8;
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = co.fluder.FSNotes;
PRODUCT_NAME = FSNotes;
Expand All @@ -4934,7 +4942,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 518;
CURRENT_PROJECT_VERSION = 519;
DEPLOYMENT_LOCATION = NO;
DEVELOPMENT_TEAM = 866P6MTE92;
EMBED_ASSET_PACKS_IN_PRODUCT_BUNDLE = YES;
Expand All @@ -4947,7 +4955,7 @@
INFOPLIST_FILE = FSNotes/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 5.3.7;
MARKETING_VERSION = 5.3.8;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = co.fluder.FSNotes;
PRODUCT_NAME = FSNotes;
Expand Down
29 changes: 29 additions & 0 deletions FSNotes/View/EditTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,35 @@ class EditTextView: NSTextView, NSTextFinderClient, NSSharingServicePickerDelega
}
}

override func readSelection(from pboard: NSPasteboard, type: NSPasteboard.PasteboardType) -> Bool {
guard let note = EditTextView.note else { return false }

if var data = pboard.data(forType: type) {
var ext = "pdf"

if !data.isPDF {
ext = "jpg"
let image = NSImage(data: data)
if let imageData = image?.jpgData {
data = imageData
}
}

EditTextView.shouldForceRescan = true
saveClipboard(data: data, note: note, ext: ext)
saveTextStorageContent(to: note)
note.save()

if let container = textContainer {
textStorage?.sizeAttachmentImages(container: container)
}

return true
}

return false
}

override func writeSelection(to pboard: NSPasteboard, type: NSPasteboard.PasteboardType) -> Bool {

guard let storage = textStorage else { return false }
Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions FSNotesCore/Shared/Extensions/Data+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Data+.swift
// FSNotes
//
// Created by Александр on 03.04.2022.
// Copyright © 2022 Oleksandr Glushchenko. All rights reserved.
//

import Foundation

extension Data {
var isPDF: Bool {
guard self.count >= 1024 else { return false }
let pdfHeader = Data(bytes: "%PDF", count: 4)
return self.range(of: pdfHeader, options: [], in: Range(NSRange(location: 0, length: 1024))) != nil
}
}

0 comments on commit e8d300b

Please sign in to comment.