Skip to content

Commit

Permalink
Merge pull request #7 from ololx/develop
Browse files Browse the repository at this point in the history
Fix fatal error: Can not remove last element from an empty collection
  • Loading branch information
ololx authored Sep 13, 2021
2 parents 9465196 + 259f7b7 commit a7a6c2f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

- Refactor application.

## [0.8.1] - 2021-09-13

### Fixed

- Fix a bug that led to fatal error: `Can't remove last element from an empty collection`.

### Added

- Added the ability to create links from the `Finder` menu without selected objects.

## [0.8.0] - 2021-09-02

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The Quick Symlink is a `Finder extension` which provides a `contextual menu item` for the symbolic links creation on macOS.

[![status](https://img.shields.io/badge/status-active-active?style=flat-square)](BADGES_GUIDE.md#status) [![version](https://img.shields.io/badge/version-0.8.0-informational?style=flat-square)](BADGES_GUIDE.md#version) [![oss lifecycle](https://img.shields.io/badge/oss_lifecycle-active-important?style=flat-square)](BADGES_GUIDE.md#oss-lifecycle) [![maintenance](https://img.shields.io/badge/maintenance-yes-informational?style=flat-square)](BADGES_GUIDE.md#maintenance) [![last release](https://img.shields.io/badge/last_release-September_02,_2021-informational?style=flat-square)](BADGES_GUIDE.md#release-date) [![last commit](https://img.shields.io/badge/last_commit-September_10,_2021-informational?style=flat-square)](BADGES_GUIDE.md#commit-date)
[![status](https://img.shields.io/badge/status-active-active?style=flat-square)](BADGES_GUIDE.md#status) [![version](https://img.shields.io/badge/version-0.8.1-informational?style=flat-square)](BADGES_GUIDE.md#version) [![oss lifecycle](https://img.shields.io/badge/oss_lifecycle-active-important?style=flat-square)](BADGES_GUIDE.md#oss-lifecycle) [![maintenance](https://img.shields.io/badge/maintenance-yes-informational?style=flat-square)](BADGES_GUIDE.md#maintenance) [![last release](https://img.shields.io/badge/last_release-September_13,_2021-informational?style=flat-square)](BADGES_GUIDE.md#release-date) [![last commit](https://img.shields.io/badge/last_commit-September_13,_2021-informational?style=flat-square)](BADGES_GUIDE.md#commit-date)

[![license](https://img.shields.io/badge/license-MIT-informational?style=flat-square)](LICENSE) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-square)](CODE_OF_CONDUCT.md)

Expand Down
5 changes: 0 additions & 5 deletions commons/link/FileLinkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,8 @@ public class SoftLinkManager: FileLinkManager {
public class HardLinkManager: FileLinkManager {

public func linkWith(of: URL!, with: URL!) {

let pasteboard = NSPasteboard.general;
pasteboard.declareTypes([NSPasteboard.PasteboardType.string], owner: nil);

do {
try FileManager.default.linkItem(at: of, to: with);

} catch let error as NSError {
NSLog("FileManager.createSymbolicLink() failed to create file: %@", error.description as NSString);
}
Expand Down
10 changes: 8 additions & 2 deletions commons/link/action/CopyPathAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@ public class CopyPathAction: QuickSymlinkAction {

public func execute() {
//Get all selected path
guard let target = self.finderController.selectedItemURLs() else {
guard var target = self.finderController.selectedItemURLs() else {
NSLog("FinderSync() failed to obtain targeted URLs: %@");

return;
}

if (target.isEmpty) {
target.append(self.finderController.targetedURL()!);
}

// Append all selected paths to string
var paths = ""
for path in target {
paths.append(contentsOf: path.relativePath);
paths.append(";");
}
paths.removeLast();
if (!paths.isEmpty) {
paths.removeLast();
}

//Copy path list to clipboard
let pasteboard = NSPasteboard.init(name: NSPasteboard.Name.init(rawValue: "qs"));
Expand Down
6 changes: 6 additions & 0 deletions commons/link/action/CreateLinkAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@ public class CreateLinkAction: QuickSymlinkAction {
let targetPath = self.fileLinkManager.getTargetPath(path, to: path.deletingLastPathComponent());
self.fileLinkManager.linkWith(of: path, with: targetPath);
}

if (target.isEmpty) {
let path = self.finderController.targetedURL()!;
let targetPath = self.fileLinkManager.getTargetPath(path, to: path);
self.fileLinkManager.linkWith(of: path, with: targetPath);
}
}
}
2 changes: 1 addition & 1 deletion quick-symlink-tests/ResourcePathTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ResourcePathTest: XCTestCase {
XCTAssert(relativePath.toUriString() == "./../..", "The relative path is wrong");
}

func test_relativize_whenCurrentDirectoryAndOtherDirectoryAreNestedToGeneralDirectoryy_thenReturnPathWithJumpsAboveOtherDirectoryAndPartOfCurrentDirectory() {
func test_relativize_whenCurrentDirectoryAndOtherDirectoryAreNestedToGeneralDirectory_thenReturnPathWithJumpsAboveOtherDirectoryAndPartOfCurrentDirectory() {
let currentUri: URL = URL.init(string: "/a/b/c1/d1")!;
let otherUri: URL = URL.init(string: "/a/b/c2/d2")!;

Expand Down
2 changes: 2 additions & 0 deletions quick-symlink.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
A316477826B7B403001DD969 /* CreateLinkAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = A316477626B7B403001DD969 /* CreateLinkAction.swift */; };
A31904A426E104FA00D7F69D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A31904A326E104FA00D7F69D /* Assets.xcassets */; };
A32EE8E0265D4D05008648AA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A32EE8DF265D4D05008648AA /* Assets.xcassets */; };
A34185F126EF767900224992 /* FileLinkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A36F9B0526DFAC27009E95CE /* FileLinkManager.swift */; };
A345C9BF26A0B200004FBF0F /* QuickSymlinkAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = A345C9BE26A0B200004FBF0F /* QuickSymlinkAction.swift */; };
A345C9C226A0B30F004FBF0F /* CopyPathAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = A345C9C126A0B30F004FBF0F /* CopyPathAction.swift */; };
A345C9C526A0B49C004FBF0F /* PasteLinkAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = A345C9C426A0B49C004FBF0F /* PasteLinkAction.swift */; };
Expand Down Expand Up @@ -439,6 +440,7 @@
buildActionMask = 2147483647;
files = (
A307B43026D257C5002EEF58 /* ResourcePath.swift in Sources */,
A34185F126EF767900224992 /* FileLinkManager.swift in Sources */,
A307B42F26D2563B002EEF58 /* ResourcePathTest.swift in Sources */,
A307B43126D257CA002EEF58 /* Path.swift in Sources */,
);
Expand Down

0 comments on commit a7a6c2f

Please sign in to comment.