├── .gitignore ├── LICENSE ├── README.md ├── TagConverter.xcodeproj └── project.pbxproj ├── TagConverter ├── AppDelegate.swift ├── Application Services │ ├── DirectoryLister.swift │ ├── DirectoryReader.swift │ ├── FileExistenceChecker.swift │ ├── HashtagConverter.swift │ └── NoteFactory.swift ├── Info.plist ├── TagConverter.entitlements ├── UI │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ └── MainMenu.xib │ ├── ConversionProgressViewController.swift │ ├── ConversionViewController.swift │ ├── MainWindowController.swift │ ├── MainWindowController.xib │ ├── NoteTableCellView.swift │ └── NotesViewController.swift └── Util │ ├── Collection+safeSubscript.swift │ ├── FileManager+DirectoryLister.swift │ └── FileManager+FileExistenceChecker.swift ├── TagConverterTests ├── DirectoryReaderTests.swift ├── ErrorHelpers.swift ├── FileManager+DirectoryListerTests.swift ├── FileManager+ExistenceTests.swift ├── Info.plist ├── StringLineSplitTests.swift └── TemporaryFilesHelpers.swift └── assets ├── download.png └── screenshot.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | .build/ 41 | 42 | # CocoaPods 43 | # 44 | # We recommend against adding the Pods directory to your .gitignore. However 45 | # you should judge for yourself, the pros and cons are mentioned at: 46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 47 | # 48 | # Pods/ 49 | 50 | # Carthage 51 | # 52 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 53 | # Carthage/Checkouts 54 | 55 | Carthage/Build 56 | 57 | # fastlane 58 | # 59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 60 | # screenshots whenever they are needed. 61 | # For more information about the recommended setup visit: 62 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 63 | 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Zettelkasten Method 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tag Converter 2 | 3 | Convert Finder/Spotlight metadata tags to `#hashtags`, putting them inside the files. 4 | 5 | This tool will take a directory of files, scan for Finder tags, and then allow you to add the tags into the body of the files. The Finder tag "Inbox" will be added as `#inbox` if it is not present in the string contents of the file already. 6 | 7 | Can be used to make tags from DEVONthink or nvALT work with [_The Archive_](https://zettelkasten.de/the-archive/) and similar plain-text editors, like Sublime Text 3. 8 | 9 | [![Download latest release](assets/download.png "Download latest release")](https://github.com/Zettelkasten-Method/macOS-Tag-Converter/releases/latest) 10 | 11 | - **Warning:** Will perform changes in-place. Keep a backup of the original if in doubt! 12 | - Requires macOS 10.11 or later. 13 | 14 | ![](assets/screenshot.png) 15 | 16 | ## License 17 | 18 | Copyright © 2018 Christian Tietze. Distributed under the MIT License. 19 | 20 | See the [LICENSE](/LICENSE) file for details. 21 | -------------------------------------------------------------------------------- /TagConverter.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 50C4F0EC205BABDB00A75FB1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F0EB205BABDB00A75FB1 /* AppDelegate.swift */; }; 11 | 50C4F0EE205BABDB00A75FB1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 50C4F0ED205BABDB00A75FB1 /* Assets.xcassets */; }; 12 | 50C4F0F1205BABDB00A75FB1 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50C4F0EF205BABDB00A75FB1 /* MainMenu.xib */; }; 13 | 50C4F10B205BAD9200A75FB1 /* MainWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F109205BAD9200A75FB1 /* MainWindowController.swift */; }; 14 | 50C4F10C205BAD9200A75FB1 /* MainWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50C4F10A205BAD9200A75FB1 /* MainWindowController.xib */; }; 15 | 50C4F118205BB2F300A75FB1 /* DirectoryReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F117205BB2F300A75FB1 /* DirectoryReader.swift */; }; 16 | 50C4F11A205BB4A700A75FB1 /* FileManager+DirectoryLister.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F119205BB4A700A75FB1 /* FileManager+DirectoryLister.swift */; }; 17 | 50C4F11C205BB4E100A75FB1 /* FileExistenceChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F11B205BB4E100A75FB1 /* FileExistenceChecker.swift */; }; 18 | 50C4F11E205BB4FD00A75FB1 /* FileManager+FileExistenceChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F11D205BB4FD00A75FB1 /* FileManager+FileExistenceChecker.swift */; }; 19 | 50C4F120205BB53E00A75FB1 /* DirectoryLister.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F11F205BB53E00A75FB1 /* DirectoryLister.swift */; }; 20 | 50C4F122205BB7AB00A75FB1 /* NoteFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F121205BB7AB00A75FB1 /* NoteFactory.swift */; }; 21 | 50C4F124205BB84F00A75FB1 /* FileManager+DirectoryListerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F123205BB84F00A75FB1 /* FileManager+DirectoryListerTests.swift */; }; 22 | 50C4F126205BB87C00A75FB1 /* TemporaryFilesHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F125205BB87C00A75FB1 /* TemporaryFilesHelpers.swift */; }; 23 | 50C4F128205BC00600A75FB1 /* ErrorHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F127205BC00600A75FB1 /* ErrorHelpers.swift */; }; 24 | 50C4F12A205BC04F00A75FB1 /* FileManager+ExistenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F129205BC04F00A75FB1 /* FileManager+ExistenceTests.swift */; }; 25 | 50C4F12C205BC07000A75FB1 /* DirectoryReaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F12B205BC07000A75FB1 /* DirectoryReaderTests.swift */; }; 26 | 50C4F12E205BF2BC00A75FB1 /* NotesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F12D205BF2BC00A75FB1 /* NotesViewController.swift */; }; 27 | 50C4F130205BF4F100A75FB1 /* Collection+safeSubscript.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F12F205BF4F100A75FB1 /* Collection+safeSubscript.swift */; }; 28 | 50C4F132205BF5B700A75FB1 /* NoteTableCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F131205BF5B700A75FB1 /* NoteTableCellView.swift */; }; 29 | 50C4F134205BFE6F00A75FB1 /* ConversionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F133205BFE6F00A75FB1 /* ConversionViewController.swift */; }; 30 | 50C4F139205C0D0100A75FB1 /* HashtagConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F138205C0D0100A75FB1 /* HashtagConverter.swift */; }; 31 | 50C4F13B205C132900A75FB1 /* ConversionProgressViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F13A205C132900A75FB1 /* ConversionProgressViewController.swift */; }; 32 | 50C4F13D205C1F7200A75FB1 /* StringLineSplitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50C4F13C205C1F7200A75FB1 /* StringLineSplitTests.swift */; }; 33 | /* End PBXBuildFile section */ 34 | 35 | /* Begin PBXContainerItemProxy section */ 36 | 50C4F0F9205BABDB00A75FB1 /* PBXContainerItemProxy */ = { 37 | isa = PBXContainerItemProxy; 38 | containerPortal = 50C4F0E0205BABDB00A75FB1 /* Project object */; 39 | proxyType = 1; 40 | remoteGlobalIDString = 50C4F0E7205BABDB00A75FB1; 41 | remoteInfo = TagConverter; 42 | }; 43 | /* End PBXContainerItemProxy section */ 44 | 45 | /* Begin PBXFileReference section */ 46 | 50C4F0E8205BABDB00A75FB1 /* TagConverter.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TagConverter.app; sourceTree = BUILT_PRODUCTS_DIR; }; 47 | 50C4F0EB205BABDB00A75FB1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 48 | 50C4F0ED205BABDB00A75FB1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 49 | 50C4F0F0205BABDB00A75FB1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 50 | 50C4F0F2205BABDB00A75FB1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | 50C4F0F3205BABDB00A75FB1 /* TagConverter.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TagConverter.entitlements; sourceTree = ""; }; 52 | 50C4F0F8205BABDB00A75FB1 /* TagConverterTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TagConverterTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | 50C4F0FE205BABDB00A75FB1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 54 | 50C4F109205BAD9200A75FB1 /* MainWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainWindowController.swift; sourceTree = ""; }; 55 | 50C4F10A205BAD9200A75FB1 /* MainWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainWindowController.xib; sourceTree = ""; }; 56 | 50C4F117205BB2F300A75FB1 /* DirectoryReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectoryReader.swift; sourceTree = ""; }; 57 | 50C4F119205BB4A700A75FB1 /* FileManager+DirectoryLister.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+DirectoryLister.swift"; sourceTree = ""; }; 58 | 50C4F11B205BB4E100A75FB1 /* FileExistenceChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileExistenceChecker.swift; sourceTree = ""; }; 59 | 50C4F11D205BB4FD00A75FB1 /* FileManager+FileExistenceChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+FileExistenceChecker.swift"; sourceTree = ""; }; 60 | 50C4F11F205BB53E00A75FB1 /* DirectoryLister.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectoryLister.swift; sourceTree = ""; }; 61 | 50C4F121205BB7AB00A75FB1 /* NoteFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteFactory.swift; sourceTree = ""; }; 62 | 50C4F123205BB84F00A75FB1 /* FileManager+DirectoryListerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+DirectoryListerTests.swift"; sourceTree = ""; }; 63 | 50C4F125205BB87C00A75FB1 /* TemporaryFilesHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TemporaryFilesHelpers.swift; sourceTree = ""; }; 64 | 50C4F127205BC00600A75FB1 /* ErrorHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorHelpers.swift; sourceTree = ""; }; 65 | 50C4F129205BC04F00A75FB1 /* FileManager+ExistenceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+ExistenceTests.swift"; sourceTree = ""; }; 66 | 50C4F12B205BC07000A75FB1 /* DirectoryReaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectoryReaderTests.swift; sourceTree = ""; }; 67 | 50C4F12D205BF2BC00A75FB1 /* NotesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotesViewController.swift; sourceTree = ""; }; 68 | 50C4F12F205BF4F100A75FB1 /* Collection+safeSubscript.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+safeSubscript.swift"; sourceTree = ""; }; 69 | 50C4F131205BF5B700A75FB1 /* NoteTableCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteTableCellView.swift; sourceTree = ""; }; 70 | 50C4F133205BFE6F00A75FB1 /* ConversionViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversionViewController.swift; sourceTree = ""; }; 71 | 50C4F138205C0D0100A75FB1 /* HashtagConverter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HashtagConverter.swift; sourceTree = ""; }; 72 | 50C4F13A205C132900A75FB1 /* ConversionProgressViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversionProgressViewController.swift; sourceTree = ""; }; 73 | 50C4F13C205C1F7200A75FB1 /* StringLineSplitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringLineSplitTests.swift; sourceTree = ""; }; 74 | 50C4F13E205C246000A75FB1 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 75 | 50C4F13F205C246000A75FB1 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; 76 | /* End PBXFileReference section */ 77 | 78 | /* Begin PBXFrameworksBuildPhase section */ 79 | 50C4F0E5205BABDB00A75FB1 /* Frameworks */ = { 80 | isa = PBXFrameworksBuildPhase; 81 | buildActionMask = 2147483647; 82 | files = ( 83 | ); 84 | runOnlyForDeploymentPostprocessing = 0; 85 | }; 86 | 50C4F0F5205BABDB00A75FB1 /* Frameworks */ = { 87 | isa = PBXFrameworksBuildPhase; 88 | buildActionMask = 2147483647; 89 | files = ( 90 | ); 91 | runOnlyForDeploymentPostprocessing = 0; 92 | }; 93 | /* End PBXFrameworksBuildPhase section */ 94 | 95 | /* Begin PBXGroup section */ 96 | 50C4F0DF205BABDB00A75FB1 = { 97 | isa = PBXGroup; 98 | children = ( 99 | 50C4F13E205C246000A75FB1 /* README.md */, 100 | 50C4F13F205C246000A75FB1 /* LICENSE */, 101 | 50C4F0EA205BABDB00A75FB1 /* TagConverter */, 102 | 50C4F0FB205BABDB00A75FB1 /* TagConverterTests */, 103 | 50C4F0E9205BABDB00A75FB1 /* Products */, 104 | ); 105 | sourceTree = ""; 106 | }; 107 | 50C4F0E9205BABDB00A75FB1 /* Products */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | 50C4F0E8205BABDB00A75FB1 /* TagConverter.app */, 111 | 50C4F0F8205BABDB00A75FB1 /* TagConverterTests.xctest */, 112 | ); 113 | name = Products; 114 | sourceTree = ""; 115 | }; 116 | 50C4F0EA205BABDB00A75FB1 /* TagConverter */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 50C4F0EB205BABDB00A75FB1 /* AppDelegate.swift */, 120 | 50C4F137205C0B5200A75FB1 /* Application Services */, 121 | 50C4F135205C0B3D00A75FB1 /* UI */, 122 | 50C4F136205C0B4900A75FB1 /* Util */, 123 | 50C4F0F2205BABDB00A75FB1 /* Info.plist */, 124 | 50C4F0F3205BABDB00A75FB1 /* TagConverter.entitlements */, 125 | ); 126 | path = TagConverter; 127 | sourceTree = ""; 128 | }; 129 | 50C4F0FB205BABDB00A75FB1 /* TagConverterTests */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | 50C4F12B205BC07000A75FB1 /* DirectoryReaderTests.swift */, 133 | 50C4F123205BB84F00A75FB1 /* FileManager+DirectoryListerTests.swift */, 134 | 50C4F129205BC04F00A75FB1 /* FileManager+ExistenceTests.swift */, 135 | 50C4F13C205C1F7200A75FB1 /* StringLineSplitTests.swift */, 136 | 50C4F125205BB87C00A75FB1 /* TemporaryFilesHelpers.swift */, 137 | 50C4F127205BC00600A75FB1 /* ErrorHelpers.swift */, 138 | 50C4F0FE205BABDB00A75FB1 /* Info.plist */, 139 | ); 140 | path = TagConverterTests; 141 | sourceTree = ""; 142 | }; 143 | 50C4F135205C0B3D00A75FB1 /* UI */ = { 144 | isa = PBXGroup; 145 | children = ( 146 | 50C4F109205BAD9200A75FB1 /* MainWindowController.swift */, 147 | 50C4F10A205BAD9200A75FB1 /* MainWindowController.xib */, 148 | 50C4F133205BFE6F00A75FB1 /* ConversionViewController.swift */, 149 | 50C4F13A205C132900A75FB1 /* ConversionProgressViewController.swift */, 150 | 50C4F12D205BF2BC00A75FB1 /* NotesViewController.swift */, 151 | 50C4F131205BF5B700A75FB1 /* NoteTableCellView.swift */, 152 | 50C4F0ED205BABDB00A75FB1 /* Assets.xcassets */, 153 | 50C4F0EF205BABDB00A75FB1 /* MainMenu.xib */, 154 | ); 155 | path = UI; 156 | sourceTree = ""; 157 | }; 158 | 50C4F136205C0B4900A75FB1 /* Util */ = { 159 | isa = PBXGroup; 160 | children = ( 161 | 50C4F12F205BF4F100A75FB1 /* Collection+safeSubscript.swift */, 162 | 50C4F119205BB4A700A75FB1 /* FileManager+DirectoryLister.swift */, 163 | 50C4F11D205BB4FD00A75FB1 /* FileManager+FileExistenceChecker.swift */, 164 | ); 165 | path = Util; 166 | sourceTree = ""; 167 | }; 168 | 50C4F137205C0B5200A75FB1 /* Application Services */ = { 169 | isa = PBXGroup; 170 | children = ( 171 | 50C4F117205BB2F300A75FB1 /* DirectoryReader.swift */, 172 | 50C4F121205BB7AB00A75FB1 /* NoteFactory.swift */, 173 | 50C4F11F205BB53E00A75FB1 /* DirectoryLister.swift */, 174 | 50C4F11B205BB4E100A75FB1 /* FileExistenceChecker.swift */, 175 | 50C4F138205C0D0100A75FB1 /* HashtagConverter.swift */, 176 | ); 177 | path = "Application Services"; 178 | sourceTree = ""; 179 | }; 180 | /* End PBXGroup section */ 181 | 182 | /* Begin PBXNativeTarget section */ 183 | 50C4F0E7205BABDB00A75FB1 /* TagConverter */ = { 184 | isa = PBXNativeTarget; 185 | buildConfigurationList = 50C4F101205BABDB00A75FB1 /* Build configuration list for PBXNativeTarget "TagConverter" */; 186 | buildPhases = ( 187 | 50C4F0E4205BABDB00A75FB1 /* Sources */, 188 | 50C4F0E5205BABDB00A75FB1 /* Frameworks */, 189 | 50C4F0E6205BABDB00A75FB1 /* Resources */, 190 | ); 191 | buildRules = ( 192 | ); 193 | dependencies = ( 194 | ); 195 | name = TagConverter; 196 | productName = TagConverter; 197 | productReference = 50C4F0E8205BABDB00A75FB1 /* TagConverter.app */; 198 | productType = "com.apple.product-type.application"; 199 | }; 200 | 50C4F0F7205BABDB00A75FB1 /* TagConverterTests */ = { 201 | isa = PBXNativeTarget; 202 | buildConfigurationList = 50C4F104205BABDB00A75FB1 /* Build configuration list for PBXNativeTarget "TagConverterTests" */; 203 | buildPhases = ( 204 | 50C4F0F4205BABDB00A75FB1 /* Sources */, 205 | 50C4F0F5205BABDB00A75FB1 /* Frameworks */, 206 | 50C4F0F6205BABDB00A75FB1 /* Resources */, 207 | ); 208 | buildRules = ( 209 | ); 210 | dependencies = ( 211 | 50C4F0FA205BABDB00A75FB1 /* PBXTargetDependency */, 212 | ); 213 | name = TagConverterTests; 214 | productName = TagConverterTests; 215 | productReference = 50C4F0F8205BABDB00A75FB1 /* TagConverterTests.xctest */; 216 | productType = "com.apple.product-type.bundle.unit-test"; 217 | }; 218 | /* End PBXNativeTarget section */ 219 | 220 | /* Begin PBXProject section */ 221 | 50C4F0E0205BABDB00A75FB1 /* Project object */ = { 222 | isa = PBXProject; 223 | attributes = { 224 | LastSwiftUpdateCheck = 0920; 225 | LastUpgradeCheck = 0920; 226 | ORGANIZATIONNAME = "Christian Tietze"; 227 | TargetAttributes = { 228 | 50C4F0E7205BABDB00A75FB1 = { 229 | CreatedOnToolsVersion = 9.2; 230 | ProvisioningStyle = Automatic; 231 | SystemCapabilities = { 232 | com.apple.Sandbox = { 233 | enabled = 0; 234 | }; 235 | }; 236 | }; 237 | 50C4F0F7205BABDB00A75FB1 = { 238 | CreatedOnToolsVersion = 9.2; 239 | ProvisioningStyle = Automatic; 240 | TestTargetID = 50C4F0E7205BABDB00A75FB1; 241 | }; 242 | }; 243 | }; 244 | buildConfigurationList = 50C4F0E3205BABDB00A75FB1 /* Build configuration list for PBXProject "TagConverter" */; 245 | compatibilityVersion = "Xcode 8.0"; 246 | developmentRegion = en; 247 | hasScannedForEncodings = 0; 248 | knownRegions = ( 249 | en, 250 | Base, 251 | ); 252 | mainGroup = 50C4F0DF205BABDB00A75FB1; 253 | productRefGroup = 50C4F0E9205BABDB00A75FB1 /* Products */; 254 | projectDirPath = ""; 255 | projectRoot = ""; 256 | targets = ( 257 | 50C4F0E7205BABDB00A75FB1 /* TagConverter */, 258 | 50C4F0F7205BABDB00A75FB1 /* TagConverterTests */, 259 | ); 260 | }; 261 | /* End PBXProject section */ 262 | 263 | /* Begin PBXResourcesBuildPhase section */ 264 | 50C4F0E6205BABDB00A75FB1 /* Resources */ = { 265 | isa = PBXResourcesBuildPhase; 266 | buildActionMask = 2147483647; 267 | files = ( 268 | 50C4F0EE205BABDB00A75FB1 /* Assets.xcassets in Resources */, 269 | 50C4F10C205BAD9200A75FB1 /* MainWindowController.xib in Resources */, 270 | 50C4F0F1205BABDB00A75FB1 /* MainMenu.xib in Resources */, 271 | ); 272 | runOnlyForDeploymentPostprocessing = 0; 273 | }; 274 | 50C4F0F6205BABDB00A75FB1 /* Resources */ = { 275 | isa = PBXResourcesBuildPhase; 276 | buildActionMask = 2147483647; 277 | files = ( 278 | ); 279 | runOnlyForDeploymentPostprocessing = 0; 280 | }; 281 | /* End PBXResourcesBuildPhase section */ 282 | 283 | /* Begin PBXSourcesBuildPhase section */ 284 | 50C4F0E4205BABDB00A75FB1 /* Sources */ = { 285 | isa = PBXSourcesBuildPhase; 286 | buildActionMask = 2147483647; 287 | files = ( 288 | 50C4F11E205BB4FD00A75FB1 /* FileManager+FileExistenceChecker.swift in Sources */, 289 | 50C4F13B205C132900A75FB1 /* ConversionProgressViewController.swift in Sources */, 290 | 50C4F132205BF5B700A75FB1 /* NoteTableCellView.swift in Sources */, 291 | 50C4F139205C0D0100A75FB1 /* HashtagConverter.swift in Sources */, 292 | 50C4F118205BB2F300A75FB1 /* DirectoryReader.swift in Sources */, 293 | 50C4F122205BB7AB00A75FB1 /* NoteFactory.swift in Sources */, 294 | 50C4F10B205BAD9200A75FB1 /* MainWindowController.swift in Sources */, 295 | 50C4F120205BB53E00A75FB1 /* DirectoryLister.swift in Sources */, 296 | 50C4F12E205BF2BC00A75FB1 /* NotesViewController.swift in Sources */, 297 | 50C4F130205BF4F100A75FB1 /* Collection+safeSubscript.swift in Sources */, 298 | 50C4F11C205BB4E100A75FB1 /* FileExistenceChecker.swift in Sources */, 299 | 50C4F11A205BB4A700A75FB1 /* FileManager+DirectoryLister.swift in Sources */, 300 | 50C4F134205BFE6F00A75FB1 /* ConversionViewController.swift in Sources */, 301 | 50C4F0EC205BABDB00A75FB1 /* AppDelegate.swift in Sources */, 302 | ); 303 | runOnlyForDeploymentPostprocessing = 0; 304 | }; 305 | 50C4F0F4205BABDB00A75FB1 /* Sources */ = { 306 | isa = PBXSourcesBuildPhase; 307 | buildActionMask = 2147483647; 308 | files = ( 309 | 50C4F12C205BC07000A75FB1 /* DirectoryReaderTests.swift in Sources */, 310 | 50C4F13D205C1F7200A75FB1 /* StringLineSplitTests.swift in Sources */, 311 | 50C4F12A205BC04F00A75FB1 /* FileManager+ExistenceTests.swift in Sources */, 312 | 50C4F126205BB87C00A75FB1 /* TemporaryFilesHelpers.swift in Sources */, 313 | 50C4F124205BB84F00A75FB1 /* FileManager+DirectoryListerTests.swift in Sources */, 314 | 50C4F128205BC00600A75FB1 /* ErrorHelpers.swift in Sources */, 315 | ); 316 | runOnlyForDeploymentPostprocessing = 0; 317 | }; 318 | /* End PBXSourcesBuildPhase section */ 319 | 320 | /* Begin PBXTargetDependency section */ 321 | 50C4F0FA205BABDB00A75FB1 /* PBXTargetDependency */ = { 322 | isa = PBXTargetDependency; 323 | target = 50C4F0E7205BABDB00A75FB1 /* TagConverter */; 324 | targetProxy = 50C4F0F9205BABDB00A75FB1 /* PBXContainerItemProxy */; 325 | }; 326 | /* End PBXTargetDependency section */ 327 | 328 | /* Begin PBXVariantGroup section */ 329 | 50C4F0EF205BABDB00A75FB1 /* MainMenu.xib */ = { 330 | isa = PBXVariantGroup; 331 | children = ( 332 | 50C4F0F0205BABDB00A75FB1 /* Base */, 333 | ); 334 | name = MainMenu.xib; 335 | sourceTree = ""; 336 | }; 337 | /* End PBXVariantGroup section */ 338 | 339 | /* Begin XCBuildConfiguration section */ 340 | 50C4F0FF205BABDB00A75FB1 /* Debug */ = { 341 | isa = XCBuildConfiguration; 342 | buildSettings = { 343 | ALWAYS_SEARCH_USER_PATHS = NO; 344 | CLANG_ANALYZER_NONNULL = YES; 345 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 346 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 347 | CLANG_CXX_LIBRARY = "libc++"; 348 | CLANG_ENABLE_MODULES = YES; 349 | CLANG_ENABLE_OBJC_ARC = YES; 350 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 351 | CLANG_WARN_BOOL_CONVERSION = YES; 352 | CLANG_WARN_COMMA = YES; 353 | CLANG_WARN_CONSTANT_CONVERSION = YES; 354 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 355 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 356 | CLANG_WARN_EMPTY_BODY = YES; 357 | CLANG_WARN_ENUM_CONVERSION = YES; 358 | CLANG_WARN_INFINITE_RECURSION = YES; 359 | CLANG_WARN_INT_CONVERSION = YES; 360 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 361 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 362 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 363 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 364 | CLANG_WARN_STRICT_PROTOTYPES = YES; 365 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 366 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 367 | CLANG_WARN_UNREACHABLE_CODE = YES; 368 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 369 | CODE_SIGN_IDENTITY = "Mac Developer"; 370 | COPY_PHASE_STRIP = NO; 371 | DEBUG_INFORMATION_FORMAT = dwarf; 372 | ENABLE_STRICT_OBJC_MSGSEND = YES; 373 | ENABLE_TESTABILITY = YES; 374 | GCC_C_LANGUAGE_STANDARD = gnu11; 375 | GCC_DYNAMIC_NO_PIC = NO; 376 | GCC_NO_COMMON_BLOCKS = YES; 377 | GCC_OPTIMIZATION_LEVEL = 0; 378 | GCC_PREPROCESSOR_DEFINITIONS = ( 379 | "DEBUG=1", 380 | "$(inherited)", 381 | ); 382 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 383 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 384 | GCC_WARN_UNDECLARED_SELECTOR = YES; 385 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 386 | GCC_WARN_UNUSED_FUNCTION = YES; 387 | GCC_WARN_UNUSED_VARIABLE = YES; 388 | MACOSX_DEPLOYMENT_TARGET = 10.11; 389 | MTL_ENABLE_DEBUG_INFO = YES; 390 | ONLY_ACTIVE_ARCH = YES; 391 | SDKROOT = macosx; 392 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 393 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 394 | }; 395 | name = Debug; 396 | }; 397 | 50C4F100205BABDB00A75FB1 /* Release */ = { 398 | isa = XCBuildConfiguration; 399 | buildSettings = { 400 | ALWAYS_SEARCH_USER_PATHS = NO; 401 | CLANG_ANALYZER_NONNULL = YES; 402 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 403 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 404 | CLANG_CXX_LIBRARY = "libc++"; 405 | CLANG_ENABLE_MODULES = YES; 406 | CLANG_ENABLE_OBJC_ARC = YES; 407 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 408 | CLANG_WARN_BOOL_CONVERSION = YES; 409 | CLANG_WARN_COMMA = YES; 410 | CLANG_WARN_CONSTANT_CONVERSION = YES; 411 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 412 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 413 | CLANG_WARN_EMPTY_BODY = YES; 414 | CLANG_WARN_ENUM_CONVERSION = YES; 415 | CLANG_WARN_INFINITE_RECURSION = YES; 416 | CLANG_WARN_INT_CONVERSION = YES; 417 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 418 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 419 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 420 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 421 | CLANG_WARN_STRICT_PROTOTYPES = YES; 422 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 423 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 424 | CLANG_WARN_UNREACHABLE_CODE = YES; 425 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 426 | CODE_SIGN_IDENTITY = "Mac Developer"; 427 | COPY_PHASE_STRIP = NO; 428 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 429 | ENABLE_NS_ASSERTIONS = NO; 430 | ENABLE_STRICT_OBJC_MSGSEND = YES; 431 | GCC_C_LANGUAGE_STANDARD = gnu11; 432 | GCC_NO_COMMON_BLOCKS = YES; 433 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 434 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 435 | GCC_WARN_UNDECLARED_SELECTOR = YES; 436 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 437 | GCC_WARN_UNUSED_FUNCTION = YES; 438 | GCC_WARN_UNUSED_VARIABLE = YES; 439 | MACOSX_DEPLOYMENT_TARGET = 10.11; 440 | MTL_ENABLE_DEBUG_INFO = NO; 441 | SDKROOT = macosx; 442 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 443 | }; 444 | name = Release; 445 | }; 446 | 50C4F102205BABDB00A75FB1 /* Debug */ = { 447 | isa = XCBuildConfiguration; 448 | buildSettings = { 449 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 450 | CODE_SIGN_STYLE = Automatic; 451 | COMBINE_HIDPI_IMAGES = YES; 452 | DEVELOPMENT_TEAM = FRMDA3XRGC; 453 | INFOPLIST_FILE = TagConverter/Info.plist; 454 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 455 | PRODUCT_BUNDLE_IDENTIFIER = de.christiantietze.TagConverter; 456 | PRODUCT_NAME = "$(TARGET_NAME)"; 457 | SWIFT_VERSION = 4.0; 458 | }; 459 | name = Debug; 460 | }; 461 | 50C4F103205BABDB00A75FB1 /* Release */ = { 462 | isa = XCBuildConfiguration; 463 | buildSettings = { 464 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 465 | CODE_SIGN_STYLE = Automatic; 466 | COMBINE_HIDPI_IMAGES = YES; 467 | DEVELOPMENT_TEAM = FRMDA3XRGC; 468 | INFOPLIST_FILE = TagConverter/Info.plist; 469 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 470 | PRODUCT_BUNDLE_IDENTIFIER = de.christiantietze.TagConverter; 471 | PRODUCT_NAME = "$(TARGET_NAME)"; 472 | SWIFT_VERSION = 4.0; 473 | }; 474 | name = Release; 475 | }; 476 | 50C4F105205BABDB00A75FB1 /* Debug */ = { 477 | isa = XCBuildConfiguration; 478 | buildSettings = { 479 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 480 | BUNDLE_LOADER = "$(TEST_HOST)"; 481 | CODE_SIGN_STYLE = Automatic; 482 | COMBINE_HIDPI_IMAGES = YES; 483 | DEVELOPMENT_TEAM = FRMDA3XRGC; 484 | INFOPLIST_FILE = TagConverterTests/Info.plist; 485 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 486 | PRODUCT_BUNDLE_IDENTIFIER = de.christiantietze.TagConverterTests; 487 | PRODUCT_NAME = "$(TARGET_NAME)"; 488 | SWIFT_VERSION = 4.0; 489 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TagConverter.app/Contents/MacOS/TagConverter"; 490 | }; 491 | name = Debug; 492 | }; 493 | 50C4F106205BABDB00A75FB1 /* Release */ = { 494 | isa = XCBuildConfiguration; 495 | buildSettings = { 496 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 497 | BUNDLE_LOADER = "$(TEST_HOST)"; 498 | CODE_SIGN_STYLE = Automatic; 499 | COMBINE_HIDPI_IMAGES = YES; 500 | DEVELOPMENT_TEAM = FRMDA3XRGC; 501 | INFOPLIST_FILE = TagConverterTests/Info.plist; 502 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 503 | PRODUCT_BUNDLE_IDENTIFIER = de.christiantietze.TagConverterTests; 504 | PRODUCT_NAME = "$(TARGET_NAME)"; 505 | SWIFT_VERSION = 4.0; 506 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TagConverter.app/Contents/MacOS/TagConverter"; 507 | }; 508 | name = Release; 509 | }; 510 | /* End XCBuildConfiguration section */ 511 | 512 | /* Begin XCConfigurationList section */ 513 | 50C4F0E3205BABDB00A75FB1 /* Build configuration list for PBXProject "TagConverter" */ = { 514 | isa = XCConfigurationList; 515 | buildConfigurations = ( 516 | 50C4F0FF205BABDB00A75FB1 /* Debug */, 517 | 50C4F100205BABDB00A75FB1 /* Release */, 518 | ); 519 | defaultConfigurationIsVisible = 0; 520 | defaultConfigurationName = Release; 521 | }; 522 | 50C4F101205BABDB00A75FB1 /* Build configuration list for PBXNativeTarget "TagConverter" */ = { 523 | isa = XCConfigurationList; 524 | buildConfigurations = ( 525 | 50C4F102205BABDB00A75FB1 /* Debug */, 526 | 50C4F103205BABDB00A75FB1 /* Release */, 527 | ); 528 | defaultConfigurationIsVisible = 0; 529 | defaultConfigurationName = Release; 530 | }; 531 | 50C4F104205BABDB00A75FB1 /* Build configuration list for PBXNativeTarget "TagConverterTests" */ = { 532 | isa = XCConfigurationList; 533 | buildConfigurations = ( 534 | 50C4F105205BABDB00A75FB1 /* Debug */, 535 | 50C4F106205BABDB00A75FB1 /* Release */, 536 | ); 537 | defaultConfigurationIsVisible = 0; 538 | defaultConfigurationName = Release; 539 | }; 540 | /* End XCConfigurationList section */ 541 | }; 542 | rootObject = 50C4F0E0205BABDB00A75FB1 /* Project object */; 543 | } 544 | -------------------------------------------------------------------------------- /TagConverter/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Cocoa 4 | 5 | @NSApplicationMain 6 | class AppDelegate: NSObject, NSApplicationDelegate { 7 | 8 | lazy var windowController: MainWindowController = MainWindowController() 9 | lazy var directoryReader: DirectoryReader = { 10 | return DirectoryReader( 11 | errorHandler: { NSAlert(error: $0).runModal() }, 12 | output: self.windowController) 13 | }() 14 | lazy var converter: HashtagConverter = HashtagConverter(output: self.windowController) 15 | 16 | func applicationDidFinishLaunching(_ aNotification: Notification) { 17 | 18 | windowController.directoryPickerHandler = { [weak directoryReader] in 19 | directoryReader?.process(directoryURL: $0) 20 | } 21 | windowController.conversionHandler = { [weak converter] in 22 | converter?.process(conversion: $0) 23 | } 24 | 25 | windowController.showWindow(nil) 26 | } 27 | 28 | func applicationWillTerminate(_ aNotification: Notification) { 29 | } 30 | 31 | func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { 32 | windowController.showWindow(nil) 33 | return true 34 | } 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /TagConverter/Application Services/DirectoryLister.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import struct Foundation.URL 4 | 5 | protocol DirectoryLister { 6 | /// - throws: `DirectoryListingError` 7 | func filesInDirectory(at url: URL) throws -> [URL] 8 | } 9 | 10 | enum DirectoryListingError: Error { 11 | case notADirectory(URL) 12 | case listingFailed(wrapped: Error) 13 | } 14 | -------------------------------------------------------------------------------- /TagConverter/Application Services/DirectoryReader.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Foundation 4 | 5 | protocol DirectoryReaderOutput { 6 | func display(path: String) 7 | func display(notes: [Note]) 8 | } 9 | 10 | struct Note: Equatable { 11 | let url: URL 12 | let filename: String 13 | let tags: [String] 14 | var hasTags: Bool { return tags.isNotEmpty } 15 | } 16 | 17 | func ==(lhs: Note, rhs: Note) -> Bool { 18 | 19 | return lhs.url == rhs.url 20 | && lhs.filename == rhs.filename 21 | && lhs.tags == rhs.tags 22 | } 23 | 24 | class DirectoryReader { 25 | 26 | let lister: DirectoryLister 27 | let noteFactory: NoteFactory 28 | let output: DirectoryReaderOutput 29 | let errorHandler: (Error) -> Void 30 | 31 | init( 32 | lister: DirectoryLister = FileManager.default, 33 | noteFactory: NoteFactory = NoteFactory(), 34 | errorHandler: @escaping (Error) -> Void, 35 | output: DirectoryReaderOutput) { 36 | 37 | self.lister = lister 38 | self.noteFactory = noteFactory 39 | self.errorHandler = errorHandler 40 | self.output = output 41 | } 42 | 43 | func process(directoryURL: URL) { 44 | do { 45 | let fileURLs = try lister.filesInDirectory(at: directoryURL) 46 | let notes = fileURLs 47 | .sorted { $0.filename < $1.filename } 48 | .map(noteFactory.note(url:)) 49 | output.display(path: directoryURL.path) 50 | output.display(notes: notes) 51 | } catch { 52 | errorHandler(error) 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /TagConverter/Application Services/FileExistenceChecker.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Foundation 4 | 5 | protocol FileExistenceChecker { 6 | func existence(atUrl url: URL) -> FileExistence 7 | } 8 | 9 | enum FileExistence: Equatable { 10 | case none 11 | case file 12 | case directory 13 | } 14 | 15 | func ==(lhs: FileExistence, rhs: FileExistence) -> Bool { 16 | 17 | switch (lhs, rhs) { 18 | case (.none, .none), 19 | (.file, .file), 20 | (.directory, .directory): 21 | return true 22 | 23 | default: return false 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /TagConverter/Application Services/HashtagConverter.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Foundation 4 | 5 | protocol HashtagConverterOutput { 6 | func displayProgress(current: Int, total: Int) 7 | func finishConversion(errors: [Error]) 8 | } 9 | 10 | struct Conversion { 11 | let notes: [Note] 12 | let insertMissingHashtagsOnly: Bool 13 | let hashtagPlacement: HashtagPlacement 14 | } 15 | 16 | enum HashtagPlacement { 17 | case append 18 | case atLine(Int) 19 | } 20 | 21 | class HashtagConverter { 22 | let noteConverter: NoteConverter 23 | let output: HashtagConverterOutput 24 | 25 | init( 26 | noteConverter: NoteConverter = NoteConverter(), 27 | output: HashtagConverterOutput) { 28 | 29 | self.noteConverter = noteConverter 30 | self.output = output 31 | } 32 | 33 | func process(conversion: Conversion) { 34 | let total = conversion.notes.count 35 | 36 | DispatchQueue.global(qos: .utility).async { 37 | var errors: [Error] = [] 38 | for (index, note) in conversion.notes.enumerated() { 39 | do { 40 | try self.noteConverter.process(note: note, conversion: conversion) 41 | } catch { 42 | errors.append(error) 43 | } 44 | DispatchQueue.main.async { self.output.displayProgress(current: index, total: total) } 45 | } 46 | DispatchQueue.main.async { self.output.finishConversion(errors: errors) } 47 | } 48 | } 49 | } 50 | 51 | class NoteConverter { 52 | func process(note: Note, conversion: Conversion) throws { 53 | 54 | guard note.hasTags else { return } 55 | 56 | var encoding: String.Encoding = .utf8 57 | var content = try String(contentsOf: note.url, usedEncoding: &encoding) 58 | let hashtags = note.tags.map { "#\($0)" } 59 | 60 | let haystack = content.lowercased() 61 | let missingHashtags: [String] = hashtags.filter { !haystack.contains($0.lowercased()) } 62 | 63 | guard missingHashtags.isNotEmpty else { return } 64 | 65 | let hashtagLine = missingHashtags.joined(separator: " ") 66 | 67 | switch conversion.hashtagPlacement { 68 | case .append: content = content + "\n\n\(hashtagLine)\n" 69 | case .atLine(let lineNumber): 70 | let (before, after) = split(string: content, lineNumber: max(lineNumber, 1) - 1) 71 | content = before + "\(hashtagLine)\n" + after 72 | } 73 | 74 | try content.write(to: note.url, atomically: false, encoding: encoding) 75 | } 76 | } 77 | 78 | func split(string: String, lineNumber: Int) -> (String, String) { 79 | 80 | var top: [String] = [] 81 | var bottom: [String] = [] 82 | 83 | var i = 0 84 | var collectToTop = true 85 | string.enumerateLines { (line, _) in 86 | if i == lineNumber { collectToTop = false } 87 | if collectToTop { 88 | top.append(line) 89 | } else { 90 | bottom.append(line) 91 | } 92 | i += 1 93 | } 94 | 95 | // Append empty line if there was a split in order to end the top with a `\n` 96 | if top.isNotEmpty && bottom.isNotEmpty { top.append("") } 97 | 98 | return (top.joined(separator: "\n"), 99 | bottom.joined(separator: "\n")) 100 | } 101 | -------------------------------------------------------------------------------- /TagConverter/Application Services/NoteFactory.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Foundation 4 | 5 | protocol TagReader { 6 | func tags(url: URL) -> [String] 7 | } 8 | 9 | class NoteFactory { 10 | let tagReader: TagReader 11 | 12 | init(tagReader: TagReader = MetadataTagReader()) { 13 | self.tagReader = tagReader 14 | } 15 | 16 | func note(url: URL) -> Note { 17 | return Note(url: url, 18 | filename: url.filename, 19 | tags: tagReader.tags(url: url)) 20 | } 21 | } 22 | 23 | class MetadataTagReader: TagReader { 24 | func tags(url: URL) -> [String] { 25 | guard let item = NSMetadataItem(url: url) else { return [] } 26 | guard let tags = item.value(forAttribute: "kMDItemUserTags") as? [String] else { return [] } 27 | return tags 28 | } 29 | } 30 | 31 | extension URL { 32 | /// File name without path extension of the last path component. 33 | var filename: String { 34 | return (self.lastPathComponent as NSString) 35 | .deletingPathExtension 36 | // Favor simple characters over combined grapheme clusters 37 | .precomposedStringWithCanonicalMapping 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /TagConverter/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSApplicationCategoryType 24 | public.app-category.productivity 25 | LSMinimumSystemVersion 26 | $(MACOSX_DEPLOYMENT_TARGET) 27 | NSHumanReadableCopyright 28 | Copyright © 2018 Christian Tietze. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /TagConverter/TagConverter.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /TagConverter/UI/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /TagConverter/UI/Base.lproj/MainMenu.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | Default 534 | 535 | 536 | 537 | 538 | 539 | 540 | Left to Right 541 | 542 | 543 | 544 | 545 | 546 | 547 | Right to Left 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | Default 559 | 560 | 561 | 562 | 563 | 564 | 565 | Left to Right 566 | 567 | 568 | 569 | 570 | 571 | 572 | Right to Left 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | -------------------------------------------------------------------------------- /TagConverter/UI/ConversionProgressViewController.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Cocoa 4 | 5 | class ConversionProgressViewController: NSViewController, HashtagConverterOutput { 6 | 7 | @IBOutlet var progressWindow: NSWindow! 8 | @IBOutlet var hostingWindow: NSWindow! 9 | 10 | @IBOutlet weak var progressIndicator: NSProgressIndicator! 11 | @IBOutlet weak var progressLabel: NSTextField! 12 | 13 | var isDisplayingProgress: Bool = false { 14 | didSet { 15 | showOrHideSheet() 16 | } 17 | } 18 | 19 | private func showOrHideSheet() { 20 | if isDisplayingProgress { 21 | hostingWindow.beginSheet(progressWindow, completionHandler: nil) 22 | } else { 23 | hostingWindow.endSheet(progressWindow) 24 | } 25 | } 26 | 27 | func displayProgress(current: Int, total: Int) { 28 | 29 | isDisplayingProgress = true 30 | closeButton.isEnabled = false 31 | 32 | updateProgress(current: current, total: total) 33 | } 34 | 35 | /// Cache used to display the final state. 36 | private var lastTotal = 0 37 | 38 | private func updateProgress(current: Int, total: Int) { 39 | lastTotal = total 40 | 41 | progressIndicator.maxValue = Double(total) 42 | progressIndicator.doubleValue = Double(current) 43 | 44 | progressLabel.stringValue = "Processing \(current) / \(total) Files" 45 | } 46 | 47 | @IBOutlet var resultTextView: NSTextView! 48 | 49 | func finishConversion(errors: [Error]) { 50 | 51 | updateProgress(current: lastTotal, total: lastTotal) 52 | 53 | resultTextView.string = { 54 | if errors.isNotEmpty { 55 | return errors 56 | .map(String.init(describing:)) 57 | .joined(separator: "\n\n") 58 | } else { 59 | return "Everything worked like a charm." 60 | } 61 | }() 62 | 63 | closeButton.isEnabled = true 64 | progressWindow.makeFirstResponder(closeButton) 65 | } 66 | 67 | @IBOutlet weak var closeButton: NSButton! 68 | 69 | @IBAction func close(_ sender: Any) { 70 | isDisplayingProgress = false 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /TagConverter/UI/ConversionViewController.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Cocoa 4 | 5 | class ConversionViewController: NSViewController { 6 | 7 | var conversionHandler: ((Conversion) -> Void)? 8 | 9 | override func viewDidLoad() { 10 | super.viewDidLoad() 11 | 12 | insertMissingHashtagsOnly = true 13 | 14 | appendHashtagsRadioButton.state = .on 15 | hashtagPlacement = .append 16 | updateLinePlacementControls() 17 | disableControlsWithoutData() 18 | } 19 | 20 | 21 | // MARK: Conversion 22 | 23 | /// Local cache of displayed notes 24 | private var notes: [Note] = [] 25 | 26 | func display(notes: [Note]) { 27 | self.notes = notes 28 | 29 | disableControlsWithoutData() 30 | } 31 | 32 | private func disableControlsWithoutData() { 33 | 34 | let isEnabled = notes.isNotEmpty 35 | 36 | insertMissingHashtagsCheckbox.isEnabled = isEnabled 37 | appendHashtagsRadioButton.isEnabled = isEnabled 38 | insertAtLineRadioButton.isEnabled = isEnabled 39 | lineStepper.isEnabled = isEnabled 40 | lineTextField.isEnabled = isEnabled 41 | convertButton.isEnabled = isEnabled 42 | updateLinePlacementControls() 43 | } 44 | 45 | @IBOutlet weak var convertButton: NSButton! 46 | 47 | @IBAction func convert(_ sender: Any) { 48 | 49 | guard confirmed() else { return } 50 | 51 | let conversion = Conversion( 52 | notes: notes, 53 | insertMissingHashtagsOnly: insertMissingHashtagsOnly, 54 | hashtagPlacement: hashtagPlacement) 55 | conversionHandler?(conversion) 56 | } 57 | 58 | private func confirmed() -> Bool { 59 | 60 | let confirmationAlert = NSAlert() 61 | confirmationAlert.alertStyle = .warning 62 | confirmationAlert.messageText = "Overwrite files?" 63 | confirmationAlert.informativeText = "The conversion will write directly to your original files. Make a backup!" 64 | confirmationAlert.addButton(withTitle: "Overwrite My Files") 65 | confirmationAlert.addButton(withTitle: "Cancel") 66 | 67 | let response = confirmationAlert.runModal() 68 | 69 | return response == .alertFirstButtonReturn 70 | } 71 | 72 | 73 | // MARK: Insert Missing Hashtags Only 74 | 75 | @IBOutlet weak var insertMissingHashtagsCheckbox: NSButton! 76 | 77 | var insertMissingHashtagsOnly = true 78 | 79 | @IBAction func changeInsertMissingHashtagsOnly(_ sender: Any) { 80 | guard let button = sender as? NSButton else { return } 81 | insertMissingHashtagsOnly = (button.state == .on) 82 | } 83 | 84 | 85 | // MARK: Hashtag placement 86 | 87 | @IBOutlet weak var appendHashtagsRadioButton: NSButton! 88 | @IBOutlet weak var insertAtLineRadioButton: NSButton! 89 | 90 | var hashtagPlacement: HashtagPlacement = .append 91 | 92 | @IBOutlet weak var lineTextField: NSTextField! 93 | @IBOutlet weak var lineStepper: NSStepper! 94 | 95 | @objc dynamic var lineNumber: Int = 1 { 96 | didSet { 97 | hashtagPlacement = .atLine(lineNumber) 98 | } 99 | } 100 | 101 | @IBAction func changeHashtagPlacement(_ sender: Any) { 102 | self.hashtagPlacement = { 103 | if insertAtLineRadioButton.state == .on { 104 | return .atLine(lineNumber) 105 | } else { 106 | return .append 107 | } 108 | }() 109 | 110 | updateLinePlacementControls() 111 | } 112 | 113 | private func updateLinePlacementControls() { 114 | 115 | let isPlacingAtLine: Bool = { 116 | if case .atLine = hashtagPlacement { return true } 117 | return false 118 | }() 119 | 120 | lineTextField.isEnabled = isPlacingAtLine 121 | lineStepper.isEnabled = isPlacingAtLine 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /TagConverter/UI/MainWindowController.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Cocoa 4 | 5 | class MainWindowController: NSWindowController, DirectoryReaderOutput, HashtagConverterOutput { 6 | 7 | @IBOutlet weak var notesViewController: NotesViewController! 8 | @IBOutlet weak var conversionViewController: ConversionViewController! 9 | @IBOutlet weak var conversionProgressViewController: ConversionProgressViewController! 10 | 11 | convenience init() { 12 | self.init(windowNibName: .mainWindow) 13 | } 14 | 15 | override func windowDidLoad() { 16 | super.windowDidLoad() 17 | window?.isMovableByWindowBackground = true 18 | directoryPathLabel.isHidden = true 19 | conversionViewController.conversionHandler = conversionHandler 20 | } 21 | 22 | @IBOutlet weak var directoryPathLabel: NSTextField! 23 | @IBOutlet weak var changeDirectoryButton: NSButton! 24 | var directoryPickerHandler: ((URL) -> Void)? 25 | var conversionHandler: ((Conversion) -> Void)? { 26 | didSet { 27 | guard isWindowLoaded else { return } 28 | conversionViewController.conversionHandler = conversionHandler 29 | } 30 | } 31 | 32 | @IBAction func changeDirectory(_ sender: Any) { 33 | 34 | guard let directoryURL = userPickedDirectory() else { return } 35 | directoryPickerHandler?(directoryURL) 36 | } 37 | 38 | func display(path: String) { 39 | directoryPathLabel.isHidden = false 40 | directoryPathLabel.stringValue = path 41 | } 42 | 43 | func display(notes: [Note]) { 44 | notesViewController.display(notes: notes) 45 | conversionViewController.display(notes: notes) 46 | } 47 | 48 | func displayProgress(current: Int, total: Int) { 49 | conversionProgressViewController.displayProgress(current: current, total: total) 50 | } 51 | 52 | func finishConversion(errors: [Error]) { 53 | conversionProgressViewController.finishConversion(errors: errors) 54 | } 55 | } 56 | 57 | func userPickedDirectory() -> URL? { 58 | 59 | let panel = NSOpenPanel() 60 | panel.directoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first 61 | panel.canChooseFiles = false 62 | panel.canChooseDirectories = true 63 | panel.canCreateDirectories = true 64 | panel.allowsMultipleSelection = false 65 | panel.title = "Choose Directory to Convert" 66 | 67 | let response = panel.runModal() 68 | 69 | guard response == .OK else { return nil } 70 | 71 | return panel.urls.first 72 | } 73 | 74 | extension NSNib.Name { 75 | static var mainWindow: NSNib.Name { return .init(rawValue: "MainWindowController") } 76 | } 77 | -------------------------------------------------------------------------------- /TagConverter/UI/MainWindowController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 131 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 158 | 168 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 213 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 319 | 320 | 321 | 322 | 323 | 324 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | -------------------------------------------------------------------------------- /TagConverter/UI/NoteTableCellView.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Cocoa 4 | 5 | class NoteTableCellView: NSTableCellView { 6 | /// Last displayed `Note`. 7 | private(set) var note: Note? 8 | 9 | /// The default implementation sets the `note` property 10 | /// and colors the text view disabled when no tags are present. 11 | func display(note: Note) { 12 | self.note = note 13 | self.textField?.textColor = note.hasTags ? nil : NSColor.disabledControlTextColor 14 | } 15 | } 16 | 17 | class FilenameTableCellView: NoteTableCellView { 18 | override func display(note: Note) { 19 | super.display(note: note) 20 | textField?.stringValue = note.filename 21 | } 22 | } 23 | 24 | class TagsTableCellView: NoteTableCellView { 25 | override func display(note: Note) { 26 | super.display(note: note) 27 | textField?.stringValue = note.tags.joined(separator: ", ") 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /TagConverter/UI/NotesViewController.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Cocoa 4 | 5 | class NotesViewController: NSViewController, NSTableViewDelegate, NSTableViewDataSource { 6 | 7 | @IBOutlet weak var tableView: NSTableView! 8 | @IBOutlet weak var showTaggedFilesCheckbox: NSButton! 9 | 10 | override func viewDidLoad() { 11 | super.viewDidLoad() 12 | } 13 | 14 | // MARK: Model 15 | 16 | func display(notes: [Note]) { 17 | self.allNotes = notes 18 | } 19 | 20 | /// All model values. 21 | private var allNotes: [Note] = [] { 22 | didSet { 23 | filterTaggedNotesIfNeeded() 24 | } 25 | } 26 | 27 | /// Filtered model values. 28 | private var displayedNotes: [Note] = [] { 29 | didSet { 30 | guard isViewLoaded else { return } 31 | tableView.reloadData() 32 | } 33 | } 34 | 35 | var isShowingTaggedFiles: Bool = false { 36 | didSet { 37 | filterTaggedNotesIfNeeded() 38 | } 39 | } 40 | 41 | private func filterTaggedNotesIfNeeded() { 42 | guard isShowingTaggedFiles else { 43 | displayedNotes = allNotes 44 | return 45 | } 46 | 47 | displayedNotes = allNotes.filter { $0.hasTags } 48 | } 49 | 50 | @IBAction func changeShowTaggedFiles(_ sender: Any) { 51 | self.isShowingTaggedFiles = (showTaggedFilesCheckbox.state == .on) 52 | } 53 | 54 | 55 | // MARK: Table View Population 56 | 57 | func numberOfRows(in tableView: NSTableView) -> Int { 58 | return displayedNotes.count 59 | } 60 | 61 | func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { 62 | 63 | guard let note = displayedNotes[safe: row] else { return nil } 64 | guard let cellView = noteTableCellView(tableView: tableView, tableColumn: tableColumn) else { return nil } 65 | 66 | cellView.display(note: note) 67 | 68 | return cellView 69 | } 70 | 71 | func tableView(_ tableView: NSTableView, shouldSelectRow row: Int) -> Bool { 72 | return displayedNotes[safe: row]?.hasTags ?? false 73 | } 74 | 75 | private func noteTableCellView(tableView: NSTableView, tableColumn: NSTableColumn?) -> NoteTableCellView? { 76 | 77 | switch tableColumn?.identifier { 78 | case .some(.filenameColumn): 79 | return tableView.makeView(withIdentifier: .filenameCellView, owner: self) as? FilenameTableCellView 80 | 81 | case .some(.tagsColumn): 82 | return tableView.makeView(withIdentifier: .tagsCellView, owner: self) as? TagsTableCellView 83 | 84 | case .none, 85 | .some(_): 86 | return nil 87 | } 88 | } 89 | } 90 | 91 | extension Array { 92 | var isNotEmpty: Bool { return !isEmpty } 93 | } 94 | 95 | extension NSUserInterfaceItemIdentifier { 96 | 97 | static var filenameColumn: NSUserInterfaceItemIdentifier { return .init("Filenames") } 98 | static var filenameCellView: NSUserInterfaceItemIdentifier { return .init("FilenameCell") } 99 | 100 | static var tagsColumn: NSUserInterfaceItemIdentifier { return .init("Tags") } 101 | static var tagsCellView: NSUserInterfaceItemIdentifier { return .init("TagsCell") } 102 | } 103 | -------------------------------------------------------------------------------- /TagConverter/Util/Collection+safeSubscript.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | extension Collection { 4 | subscript (safe index: Self.Index) -> Self.Iterator.Element? { 5 | return index < endIndex ? self[index] : nil 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /TagConverter/Util/FileManager+DirectoryLister.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Foundation 4 | 5 | extension FileManager: DirectoryLister { 6 | 7 | public func filesInDirectory(at url: URL) throws -> [URL] { 8 | 9 | guard existence(atUrl: url) == .directory 10 | else { throw DirectoryListingError.notADirectory(url) } 11 | 12 | let contents: [URL] 13 | 14 | do { 15 | contents = try contentsOfDirectory( 16 | at: url, 17 | includingPropertiesForKeys: [.isDirectoryKey], 18 | options: [.skipsSubdirectoryDescendants, .skipsPackageDescendants]) 19 | } catch { 20 | throw DirectoryListingError.listingFailed(wrapped: error) 21 | } 22 | 23 | return contents.filter { !$0.hasDirectoryPath } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /TagConverter/Util/FileManager+FileExistenceChecker.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Foundation 4 | 5 | extension FileManager: FileExistenceChecker { 6 | func existence(atUrl url: URL) -> FileExistence { 7 | 8 | var isDirectory: ObjCBool = false 9 | let exists = self.fileExists(atPath: url.path, isDirectory: &isDirectory) 10 | 11 | switch (exists, isDirectory.boolValue) { 12 | case (false, _): return .none 13 | case (true, false): return .file 14 | case (true, true): return .directory 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TagConverterTests/DirectoryReaderTests.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import XCTest 4 | @testable import TagConverter 5 | 6 | class DirectoryReaderTests: XCTestCase { 7 | 8 | class DirectoryListerDouble: DirectoryLister { 9 | var testFiles: [URL] = [] 10 | var testThrows: Error? 11 | var didRequestFilesInDirectory: URL? 12 | func filesInDirectory(at url: URL) throws -> [URL] { 13 | didRequestFilesInDirectory = url 14 | 15 | if let error = testThrows { 16 | throw error 17 | } 18 | 19 | return testFiles 20 | } 21 | } 22 | 23 | class NoteFactoryDouble: NoteFactory { 24 | var testNote: Note = Note(url: URL(fileURLWithPath: "irrelevant"), filename: "irrelevant", tags: []) 25 | var didRequestNote = false 26 | var requestedURLs: [URL] = [] 27 | override func note(url: URL) -> Note { 28 | didRequestNote = true 29 | requestedURLs.append(url) 30 | return testNote 31 | } 32 | } 33 | 34 | class DirectoryReaderOutputDouble: DirectoryReaderOutput { 35 | var didDisplayNotes: [Note]? 36 | func display(notes: [Note]) { 37 | didDisplayNotes = notes 38 | } 39 | 40 | var didDisplayPath: String? 41 | func display(path: String) { 42 | didDisplayPath = path 43 | } 44 | } 45 | 46 | var service: DirectoryReader! 47 | 48 | var listerDouble: DirectoryListerDouble! 49 | var noteFactoryDouble: NoteFactoryDouble! 50 | var errorHandlerDouble: ErrorHandlerDouble! 51 | var outputDouble: DirectoryReaderOutputDouble! 52 | 53 | override func setUp() { 54 | super.setUp() 55 | listerDouble = DirectoryListerDouble() 56 | noteFactoryDouble = NoteFactoryDouble() 57 | errorHandlerDouble = ErrorHandlerDouble() 58 | outputDouble = DirectoryReaderOutputDouble() 59 | service = DirectoryReader( 60 | lister: listerDouble, 61 | noteFactory: noteFactoryDouble, 62 | errorHandler: errorHandlerDouble.handleError(error:), 63 | output: outputDouble) 64 | } 65 | 66 | override func tearDown() { 67 | service = nil 68 | listerDouble = nil 69 | noteFactoryDouble = nil 70 | errorHandlerDouble = nil 71 | outputDouble = nil 72 | super.tearDown() 73 | } 74 | 75 | var irrelevantURL: URL { return URL(fileURLWithPath: "irrelevant") } 76 | 77 | 78 | // MARK: - 79 | 80 | func testProcess_RequestsFilesInDirectory() { 81 | 82 | let url = URL(fileURLWithPath: "/the/requested/dir") 83 | 84 | service.process(directoryURL: url) 85 | 86 | XCTAssertEqual(listerDouble.didRequestFilesInDirectory, url) 87 | } 88 | 89 | 90 | // MARK: Dir Listing Error 91 | 92 | func testProcess_ListingThrows_DoesNotUseNoteFactory() { 93 | 94 | listerDouble.testThrows = TestError.irrelevant 95 | 96 | service.process(directoryURL: irrelevantURL) 97 | 98 | XCTAssertFalse(noteFactoryDouble.didRequestNote) 99 | } 100 | 101 | func testProcess_ListingThrows_DoesNotDisplayPath() { 102 | 103 | listerDouble.testThrows = TestError.irrelevant 104 | 105 | service.process(directoryURL: irrelevantURL) 106 | 107 | XCTAssertNil(outputDouble.didDisplayPath) 108 | } 109 | 110 | func testProcess_ListingThrows_DoesNotDisplayNotes() { 111 | 112 | listerDouble.testThrows = TestError.irrelevant 113 | 114 | service.process(directoryURL: irrelevantURL) 115 | 116 | XCTAssertNil(outputDouble.didDisplayNotes) 117 | } 118 | 119 | func testProcess_ListingThrows_DelegatesErrorToErrorHandler() { 120 | 121 | struct TheError: Error { } 122 | listerDouble.testThrows = TheError() 123 | 124 | service.process(directoryURL: irrelevantURL) 125 | 126 | XCTAssert(errorHandlerDouble.didHandleError is TheError) 127 | } 128 | 129 | 130 | // MARK: Empty Directory 131 | 132 | func testProcess_ListingReturnsEmptyDirectory_DoesNotUseNoteFactory() { 133 | 134 | listerDouble.testFiles = [] 135 | 136 | service.process(directoryURL: irrelevantURL) 137 | 138 | XCTAssertFalse(noteFactoryDouble.didRequestNote) 139 | } 140 | 141 | func testProcess_ListingReturnsEmptyDirectory_DisplaysPath() { 142 | 143 | let path = "/this/is/the/path" 144 | listerDouble.testFiles = [] 145 | 146 | service.process(directoryURL: URL(fileURLWithPath: path)) 147 | 148 | XCTAssertEqual(outputDouble.didDisplayPath, path) 149 | } 150 | 151 | func testProcess_ListingReturnsEmptyDirectory_DisplaysEmptyNotes() { 152 | 153 | listerDouble.testFiles = [] 154 | 155 | service.process(directoryURL: irrelevantURL) 156 | 157 | XCTAssertNotNil(outputDouble.didDisplayNotes) 158 | if let notes = outputDouble.didDisplayNotes { 159 | XCTAssertEqual(notes, []) 160 | } 161 | } 162 | 163 | func testProcess_ListingReturnsEmptyDirectory_DoesNotCallErrorHandler() { 164 | 165 | listerDouble.testFiles = [] 166 | 167 | service.process(directoryURL: irrelevantURL) 168 | 169 | XCTAssertNil(errorHandlerDouble.didHandleError) 170 | } 171 | 172 | 173 | // MARK: One File in Directory 174 | 175 | func testProcess_ListingReturnsOneURL_RequestsNoteFromFactory() { 176 | 177 | let singleURL = URL(fileURLWithPath: "the/path") 178 | listerDouble.testFiles = [singleURL] 179 | 180 | service.process(directoryURL: irrelevantURL) 181 | 182 | XCTAssert(noteFactoryDouble.didRequestNote) 183 | XCTAssertEqual(noteFactoryDouble.requestedURLs, [singleURL]) 184 | } 185 | 186 | func testProcess_ListingReturnsOneURL_DisplaysPath() { 187 | 188 | let path = "/this/is/the/path" 189 | listerDouble.testFiles = [irrelevantURL] 190 | 191 | service.process(directoryURL: URL(fileURLWithPath: path)) 192 | 193 | XCTAssertEqual(outputDouble.didDisplayPath, path) 194 | } 195 | 196 | func testProcess_ListingReturnsOneURL_DisplaysResultOfNoteFactory() { 197 | 198 | listerDouble.testFiles = [irrelevantURL] 199 | let note = Note(url: URL(fileURLWithPath: "the/file"), filename: "amazing name", tags: ["great", "tags"]) 200 | noteFactoryDouble.testNote = note 201 | 202 | service.process(directoryURL: irrelevantURL) 203 | 204 | XCTAssertNotNil(outputDouble.didDisplayNotes) 205 | if let notes = outputDouble.didDisplayNotes { 206 | XCTAssertEqual(notes, [note]) 207 | } 208 | } 209 | 210 | func testProcess_ListingReturnsOneURL_DoesNotCallErrorHandler() { 211 | 212 | listerDouble.testFiles = [irrelevantURL] 213 | 214 | service.process(directoryURL: irrelevantURL) 215 | 216 | XCTAssertNil(errorHandlerDouble.didHandleError) 217 | } 218 | 219 | 220 | // MARK: Many Files in Directory 221 | 222 | func testProcess_ListingReturns5URLs_RequestsSortedNotesFromFactory() { 223 | 224 | let unsortedURLs = [ 225 | URL(fileURLWithPath: "5"), 226 | URL(fileURLWithPath: "2"), 227 | URL(fileURLWithPath: "3"), 228 | URL(fileURLWithPath: "1"), 229 | URL(fileURLWithPath: "4") 230 | ] 231 | listerDouble.testFiles = unsortedURLs 232 | 233 | service.process(directoryURL: irrelevantURL) 234 | 235 | let sortedURLs = (1...5).map { URL(fileURLWithPath: String($0)) } 236 | XCTAssert(noteFactoryDouble.didRequestNote) 237 | XCTAssertEqual(noteFactoryDouble.requestedURLs, sortedURLs) 238 | } 239 | 240 | func testProcess_ListingReturns5URLs_DisplaysPath() { 241 | 242 | let path = "/the/original/path" 243 | listerDouble.testFiles = [irrelevantURL, irrelevantURL, irrelevantURL, irrelevantURL, irrelevantURL] 244 | 245 | service.process(directoryURL: URL(fileURLWithPath: path)) 246 | 247 | XCTAssertEqual(outputDouble.didDisplayPath, path) 248 | } 249 | 250 | func testProcess_ListingReturns5URLs_Displays5ResultOfNoteFactory() { 251 | 252 | let urls = (1...5).map { URL(fileURLWithPath: String($0)) } 253 | listerDouble.testFiles = urls 254 | let note = Note(url: URL(fileURLWithPath: "the/file"), filename: "amazing name", tags: ["great", "tags"]) 255 | noteFactoryDouble.testNote = note 256 | 257 | service.process(directoryURL: irrelevantURL) 258 | 259 | XCTAssertNotNil(outputDouble.didDisplayNotes) 260 | if let notes = outputDouble.didDisplayNotes { 261 | XCTAssertEqual(notes, [note, note, note, note, note]) 262 | } 263 | } 264 | 265 | func testProcess_ListingReturns5URLs_DoesNotCallErrorHandler() { 266 | 267 | listerDouble.testFiles = [irrelevantURL] 268 | 269 | service.process(directoryURL: irrelevantURL) 270 | 271 | XCTAssertNil(errorHandlerDouble.didHandleError) 272 | } 273 | 274 | } 275 | -------------------------------------------------------------------------------- /TagConverterTests/ErrorHelpers.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Foundation 4 | import XCTest 5 | 6 | func expectNoError(_ message: String = "Unexpected throw", file: StaticString = #file, line: UInt = #line, block: () throws -> Void) { 7 | 8 | do { 9 | try block() 10 | } catch { 11 | XCTFail("\(message) (\(error))", file: file, line: line) 12 | } 13 | } 14 | 15 | func ignoreError(block: () throws -> Void) { 16 | 17 | do { 18 | try block() 19 | } catch { 20 | // no op 21 | } 22 | } 23 | 24 | enum TestError: Error { 25 | case irrelevant 26 | } 27 | 28 | let irrelevantError = TestError.irrelevant 29 | 30 | class ErrorHandlerDouble { 31 | var didHandleError: Error? 32 | func handleError(error: Error) { 33 | didHandleError = error 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /TagConverterTests/FileManager+DirectoryListerTests.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import XCTest 4 | @testable import TagConverter 5 | 6 | class FileManager_DirectoryListerTests: XCTestCase { 7 | 8 | var directoryLister: DirectoryLister { return FileManager.default } 9 | 10 | func testFiles_NonexistingURL_Throws() { 11 | 12 | let url = generatedTempFileURL() 13 | 14 | do { 15 | _ = try directoryLister.filesInDirectory(at: url) 16 | XCTFail("expected to throw") 17 | } catch let error as DirectoryListingError { 18 | switch error { 19 | case .notADirectory(let errorURL): XCTAssertEqual(url, errorURL) 20 | default: XCTFail("wrong kind of error") 21 | } 22 | } catch { 23 | XCTFail("wrong kind of error") 24 | } 25 | } 26 | 27 | func testFiles_FileAtURL_Throws() { 28 | 29 | let url = createTempFileURL() 30 | 31 | do { 32 | _ = try directoryLister.filesInDirectory(at: url) 33 | XCTFail("expected to throw") 34 | } catch let error as DirectoryListingError { 35 | switch error { 36 | case .notADirectory(let errorURL): XCTAssertEqual(url, errorURL) 37 | default: XCTFail("wrong kind of error") 38 | } 39 | } catch { 40 | XCTFail("wrong kind of error") 41 | } 42 | } 43 | 44 | func testFiles_EmptyDirectory_ReturnsEmptyArray() { 45 | 46 | let url = createTempDirectory() 47 | 48 | var results: [URL]? 49 | expectNoError { 50 | results = try directoryLister.filesInDirectory(at: url) 51 | } 52 | 53 | XCTAssertNotNil(results) 54 | if let results = results { 55 | XCTAssert(results.isEmpty) 56 | } 57 | } 58 | 59 | func testFiles_FilesInDirectory_ReturnsURLs() { 60 | 61 | let directoryUrl = createTempDirectory() 62 | let firstFileUrl = directoryUrl.appendingPathComponent("file1") 63 | let secondFileUrl = directoryUrl.appendingPathComponent("file2") 64 | touch(url: firstFileUrl) 65 | touch(url: secondFileUrl) 66 | 67 | var results: [URL]? 68 | expectNoError { 69 | results = try directoryLister.filesInDirectory(at: directoryUrl) 70 | } 71 | 72 | XCTAssertNotNil(results) 73 | if let results = results?.map({ $0.resolvingSymlinksInPath() }) { 74 | XCTAssertEqual(results.count, 2) 75 | XCTAssert(results.contains(firstFileUrl)) 76 | XCTAssert(results.contains(secondFileUrl)) 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /TagConverterTests/FileManager+ExistenceTests.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import XCTest 4 | @testable import TagConverter 5 | 6 | class FileManager_ExistenceTests: XCTestCase { 7 | 8 | func testExistence_NonExistingFile() { 9 | 10 | let url = generatedTempFileURL() 11 | XCTAssertEqual(FileManager.default.existence(atUrl: url), FileExistence.none) 12 | } 13 | 14 | func testExistence_ExistingFile() { 15 | 16 | let url = generatedTempFileURL() 17 | 18 | guard let _ = try? "some content".write(to: url, atomically: false, encoding: .utf8) 19 | else { XCTFail("writing failed"); return } 20 | XCTAssertEqual(FileManager.default.existence(atUrl: url), FileExistence.file) 21 | } 22 | 23 | func testExistence_ExistingDirectory() { 24 | 25 | let url = createTempDirectory() 26 | XCTAssertEqual(FileManager.default.existence(atUrl: url), FileExistence.directory) 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /TagConverterTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /TagConverterTests/StringLineSplitTests.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import XCTest 4 | @testable import TagConverter 5 | 6 | class StringLineSplitTests: XCTestCase { 7 | 8 | func testEmptyString() { 9 | XCTAssertEqual(split(string: "", lineNumber: 0).0, "") 10 | XCTAssertEqual(split(string: "", lineNumber: 0).1, "") 11 | 12 | XCTAssertEqual(split(string: "", lineNumber: 1).0, "") 13 | XCTAssertEqual(split(string: "", lineNumber: 1).1, "") 14 | 15 | XCTAssertEqual(split(string: "", lineNumber: 10).0, "") 16 | XCTAssertEqual(split(string: "", lineNumber: 10).1, "") 17 | } 18 | 19 | func testStringWithoutLineBreak() { 20 | XCTAssertEqual(split(string: "hello", lineNumber: 0).0, "") 21 | XCTAssertEqual(split(string: "hello", lineNumber: 0).1, "hello") 22 | 23 | XCTAssertEqual(split(string: "hello", lineNumber: 1).0, "hello") 24 | XCTAssertEqual(split(string: "hello", lineNumber: 1).1, "") 25 | 26 | XCTAssertEqual(split(string: "hello", lineNumber: 10).0, "hello") 27 | XCTAssertEqual(split(string: "hello", lineNumber: 10).1, "") 28 | } 29 | 30 | func testStringWith2Lines() { 31 | XCTAssertEqual(split(string: "hello\nworld", lineNumber: 0).0, "") 32 | XCTAssertEqual(split(string: "hello\nworld", lineNumber: 0).1, "hello\nworld") 33 | 34 | XCTAssertEqual(split(string: "hello\nworld", lineNumber: 1).0, "hello\n") 35 | XCTAssertEqual(split(string: "hello\nworld", lineNumber: 1).1, "world") 36 | 37 | XCTAssertEqual(split(string: "hello\nworld", lineNumber: 2).0, "hello\nworld") 38 | XCTAssertEqual(split(string: "hello\nworld", lineNumber: 2).1, "") 39 | 40 | XCTAssertEqual(split(string: "hello\nworld", lineNumber: 10).0, "hello\nworld") 41 | XCTAssertEqual(split(string: "hello\nworld", lineNumber: 10).1, "") 42 | } 43 | 44 | func testStringWith3Lines() { 45 | XCTAssertEqual(split(string: "hello\nworld\n!", lineNumber: 0).0, "") 46 | XCTAssertEqual(split(string: "hello\nworld\n!", lineNumber: 0).1, "hello\nworld\n!") 47 | 48 | XCTAssertEqual(split(string: "hello\nworld\n!", lineNumber: 1).0, "hello\n") 49 | XCTAssertEqual(split(string: "hello\nworld\n!", lineNumber: 1).1, "world\n!") 50 | 51 | XCTAssertEqual(split(string: "hello\nworld\n!", lineNumber: 2).0, "hello\nworld\n") 52 | XCTAssertEqual(split(string: "hello\nworld\n!", lineNumber: 2).1, "!") 53 | 54 | XCTAssertEqual(split(string: "hello\nworld\n!", lineNumber: 3).0, "hello\nworld\n!") 55 | XCTAssertEqual(split(string: "hello\nworld\n!", lineNumber: 3).1, "") 56 | 57 | XCTAssertEqual(split(string: "hello\nworld\n!", lineNumber: 10).0, "hello\nworld\n!") 58 | XCTAssertEqual(split(string: "hello\nworld\n!", lineNumber: 10).1, "") 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /TagConverterTests/TemporaryFilesHelpers.swift: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Christian Tietze. All rights reserved. Distributed under the MIT License. 2 | 3 | import Foundation 4 | 5 | func touch(url: URL) { 6 | try! "".write(to: url, atomically: false, encoding: .utf8) 7 | } 8 | 9 | func generatedTempDirectoryURL() -> URL { 10 | 11 | let fileName = "minnv-temp-dir.\(UUID().uuidString)" 12 | return URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(fileName, isDirectory: true) 13 | } 14 | 15 | func createTempDirectory() -> URL { 16 | 17 | let fileUrl = generatedTempDirectoryURL() 18 | 19 | try! FileManager.default.createDirectory(at: fileUrl, withIntermediateDirectories: false, attributes: nil) 20 | 21 | return fileUrl 22 | } 23 | 24 | func generatedTempFileURL(ext: String? = nil) -> URL { 25 | 26 | let fileName = generatedFileName(ext: ext) 27 | let fileURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(fileName) 28 | 29 | return fileURL 30 | } 31 | 32 | func generatedFileName(ext: String? = nil) -> String { 33 | 34 | let fileExtension: String 35 | if let ext = ext { 36 | fileExtension = ".\(ext)" 37 | } else { 38 | fileExtension = "" 39 | } 40 | 41 | return "minnv-temp.\(UUID().uuidString)\(fileExtension)" 42 | } 43 | 44 | func createTempFileURL(content: String = "irrelevant content", ext: String? = nil) -> URL { 45 | 46 | let url = generatedTempFileURL(ext: ext) 47 | try! content.write(to: url, atomically: true, encoding: .utf8) 48 | return url 49 | } 50 | -------------------------------------------------------------------------------- /assets/download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zettelkasten-Method/macOS-Tag-Converter/06e5308c89c9628ba65a21513c8541bca832c729/assets/download.png -------------------------------------------------------------------------------- /assets/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zettelkasten-Method/macOS-Tag-Converter/06e5308c89c9628ba65a21513c8541bca832c729/assets/screenshot.png --------------------------------------------------------------------------------