From 770b6bb909151d25d247605815abfe6bbe948fb4 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Thu, 24 Nov 2016 21:07:50 +0100 Subject: [PATCH] GH-351 Add Copyable protocol and let FileItem implement it --- VimR.xcodeproj/project.pbxproj | 4 ++++ VimR/BasicTypes.swift | 13 +++++++++++++ VimR/FileItem.swift | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 VimR/BasicTypes.swift diff --git a/VimR.xcodeproj/project.pbxproj b/VimR.xcodeproj/project.pbxproj index 4021c327..0573b2cf 100644 --- a/VimR.xcodeproj/project.pbxproj +++ b/VimR.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 1929B0E0C3BC59F52713D5A2 /* FoundationCommons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B9AF20D7BD6E5C975128 /* FoundationCommons.swift */; }; 1929B165820D7177743B537A /* Component.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B39DA7AC4A9B62D7CD39 /* Component.swift */; }; 1929B1E05C116514C1D3A384 /* CocoaCategories.m in Sources */ = {isa = PBXBuildFile; fileRef = 1929B5C3F2F1CA4113DABFFD /* CocoaCategories.m */; }; + 1929B3CEE0C1A1850E9CCE2F /* BasicTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B2FBE11048569391E092 /* BasicTypes.swift */; }; 1929B3F5743967125F357C9F /* Matcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BEEB33113B0E33C3830F /* Matcher.swift */; }; 1929B462CD4935AFF6D69457 /* FileItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B7CB4863F80230C32D3C /* FileItem.swift */; }; 1929B53876E6952D378C2B30 /* ScoredFileItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BDF9EBAF1D9D44399045 /* ScoredFileItem.swift */; }; @@ -238,6 +239,7 @@ /* Begin PBXFileReference section */ 1929B15B7EDC9B0F40E5E95C /* Logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Logging.h; sourceTree = ""; }; 1929B1A51F076E088EF4CCA4 /* server_globals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = server_globals.h; sourceTree = ""; }; + 1929B2FBE11048569391E092 /* BasicTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicTypes.swift; sourceTree = ""; }; 1929B39DA7AC4A9B62D7CD39 /* Component.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Component.swift; sourceTree = ""; }; 1929B3A98687DF171307AAC8 /* FileItemService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileItemService.swift; sourceTree = ""; }; 1929B5C3F2F1CA4113DABFFD /* CocoaCategories.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CocoaCategories.m; sourceTree = ""; }; @@ -637,6 +639,7 @@ 1929B9AF20D7BD6E5C975128 /* FoundationCommons.swift */, 4BB1BEA81D48773200463C29 /* RxSwiftCommons.swift */, 4B6A70951D6100E300E12030 /* SwiftCommons.swift */, + 1929B2FBE11048569391E092 /* BasicTypes.swift */, ); name = Commons; sourceTree = ""; @@ -1098,6 +1101,7 @@ 4BB409EE1DDA77E9005F39A2 /* ProxyWorkspaceBar.swift in Sources */, 4BAD84E81D7CA8FC00A79CC3 /* OpenQuicklyFilterOperation.swift in Sources */, 1929B0E0C3BC59F52713D5A2 /* FoundationCommons.swift in Sources */, + 1929B3CEE0C1A1850E9CCE2F /* BasicTypes.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/VimR/BasicTypes.swift b/VimR/BasicTypes.swift new file mode 100644 index 00000000..7b68b6d4 --- /dev/null +++ b/VimR/BasicTypes.swift @@ -0,0 +1,13 @@ +/** + * Tae Won Ha - http://taewon.de - @hataewon + * See LICENSE + */ + +import Foundation + +protocol Copyable { + + associatedtype InstanceType + + func copy() -> InstanceType +} diff --git a/VimR/FileItem.swift b/VimR/FileItem.swift index ab4c2598..a1cb6c52 100644 --- a/VimR/FileItem.swift +++ b/VimR/FileItem.swift @@ -12,7 +12,9 @@ class Token: Equatable { } } -class FileItem : CustomStringConvertible, Hashable { +class FileItem : CustomStringConvertible, Hashable, Copyable { + + typealias InstanceType = FileItem static func ==(left: FileItem, right: FileItem) -> Bool { return left.url == right.url @@ -50,6 +52,17 @@ class FileItem : CustomStringConvertible, Hashable { self.isPackage = url.isPackage } + fileprivate init(url: URL, dir: Bool, hidden: Bool, package: Bool) { + self.url = url + self.isDir = dir + self.isHidden = hidden + self.isPackage = package + } + + func copy() -> FileItem { + return FileItem(url: self.url, dir: self.isDir, hidden: self.isHidden, package: self.isPackage) + } + func removeChild(withUrl url: URL) { guard let idx = self.children.index(where: { $0.url == url }) else { return