Skip to content

Commit

Permalink
Added Merge feature #12
Browse files Browse the repository at this point in the history
This is the right one
Selecting multiple sessions now displays a different context menu, with the ability to merge those sessions
  • Loading branch information
AlexPerathoner committed Mar 1, 2021
1 parent bd0dcae commit 7a08173
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 19 deletions.
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "icons8-merge-2.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "icons8-merge-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "icons8-merge.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -10,6 +10,7 @@
<connections>
<outlet property="alwaysAutoUpdateOutlet" destination="DGi-XX-0tF" id="8Ra-bb-2kA"/>
<outlet property="ignoringPinnedTabsOutlet" destination="ixg-Wq-9Mi" id="Fel-pF-UPX"/>
<outlet property="multipleSelectionMenu" destination="2eF-mR-PQe" id="hrg-7Z-XgF"/>
<outlet property="searchField" destination="DvB-ZS-o0O" id="BAo-7i-hZN"/>
<outlet property="settingsMenu" destination="jCy-Qq-tCj" id="IwS-x7-duU"/>
<outlet property="singleSelectionMenu" destination="Wud-45-Yjp" id="5iA-sz-goo"/>
Expand Down Expand Up @@ -227,12 +228,24 @@
</items>
<point key="canvasLocation" x="148" y="130"/>
</menu>
<menu title="settingsMenu" autoenablesItems="NO" id="2eF-mR-PQe">
<items>
<menuItem title="Merge" image="icons8-merge" id="yjx-i9-ezS">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="mergeMenuItem:" target="-2" id="qqD-HT-bOj"/>
</connections>
</menuItem>
</items>
<point key="canvasLocation" x="120" y="499"/>
</menu>
</objects>
<resources>
<image name="NSStatusPartiallyAvailable" width="16" height="16"/>
<image name="icons8-delete" width="16" height="16"/>
<image name="icons8-edit" width="16" height="16"/>
<image name="icons8-export" width="16" height="16"/>
<image name="icons8-merge" width="16" height="16"/>
<image name="icons8-restart" width="16" height="16"/>
<image name="icons8-secure" width="16" height="16"/>
<image name="icons8-synchronize" width="16" height="16"/>
Expand Down
Expand Up @@ -34,6 +34,7 @@ class SafariExtensionViewController: SFSafariExtensionViewController, NSControlT
var deleteTimer: Timer?

// MARK: menus
@IBOutlet var multipleSelectionMenu: NSMenu!
@IBOutlet var singleSelectionMenu: NSMenu!


Expand Down Expand Up @@ -167,4 +168,14 @@ class SafariExtensionViewController: SFSafariExtensionViewController, NSControlT
}


@IBAction func mergeMenuItem(_ sender: Any) {
let indexes = tableView.selectedRowIndexes
let firstIndex = Array(tableView.selectedRowIndexes).first!

let selectedSessions = indexes.map{sessions[$0]}
for _ in selectedSessions {
sessions.remove(at: firstIndex)
}
sessions.insert(merge(s: selectedSessions), at: firstIndex)
}
}
@@ -0,0 +1,31 @@
//
// SafariExtensionViewControllerMerge.swift
// Sessions Extension
//
// Created by Alex Perathoner on 28/02/2021.
// Copyright © 2021 Alex Perathoner. All rights reserved.
//

import Cocoa

extension SafariExtensionViewController {

func merge(s: [Session]) -> Session {
var sessions = s
let firstSess = sessions.removeFirst()
var urls: [URL] = []
for page in firstSess.pages {
urls.append(page.url)
}
for item in sessions {
for page in item.pages {
if(!urls.contains(page.url)) {
firstSess.pages.append(page)
}
}
}
return firstSess
}


}
Expand Up @@ -17,6 +17,7 @@ extension SafariExtensionViewController: NSTableViewDelegate, NSTableViewDataSou
tableView.menu?.autoenablesItems = true
tableView.registerForDraggedTypes([dragDropType])
tableView.singleMenu = singleSelectionMenu
tableView.multipleMenu = multipleSelectionMenu
}


Expand Down
Expand Up @@ -10,11 +10,14 @@ import Cocoa

class TableView: NSTableView {
weak var singleMenu: NSMenu!

weak var multipleMenu: NSMenu!
override func rightMouseDown(with event: NSEvent) {
super.rightMouseDown(with: event)
let correctLocation = convert(event.locationInWindow, from: nil)
singleMenu.popUp(positioning: singleMenu.items.first, at: correctLocation, in: self)

if(self.numberOfSelectedRows > 1) {
multipleMenu.popUp(positioning: multipleMenu.items.first, at: correctLocation, in: self)
} else {
singleMenu.popUp(positioning: singleMenu.items.first, at: correctLocation, in: self)
}
}
}
4 changes: 4 additions & 0 deletions Sessions.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
FA1EC22A25ED93A2003E3F02 /* SafariExtensionViewControllerMerge.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA1EC22925ED93A1003E3F02 /* SafariExtensionViewControllerMerge.swift */; };
FA200145238C8D65006B31C0 /* WebPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA200144238C8D65006B31C0 /* WebPage.swift */; };
FA23E1D2259A5610000E54DA /* SafariExtensionViewControllerAutoUpdate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA23E1D1259A5610000E54DA /* SafariExtensionViewControllerAutoUpdate.swift */; };
FA5187E325ED664F004D0F39 /* TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5187E225ED664F004D0F39 /* TableView.swift */; };
Expand Down Expand Up @@ -59,6 +60,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
FA1EC22925ED93A1003E3F02 /* SafariExtensionViewControllerMerge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SafariExtensionViewControllerMerge.swift; sourceTree = "<group>"; };
FA200144238C8D65006B31C0 /* WebPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebPage.swift; sourceTree = "<group>"; };
FA23E1D1259A5610000E54DA /* SafariExtensionViewControllerAutoUpdate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafariExtensionViewControllerAutoUpdate.swift; sourceTree = "<group>"; };
FA5187E225ED664F004D0F39 /* TableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -120,6 +122,7 @@
FAAED815258E18DB0014F264 /* SafariExtensionViewControllerSupport.swift */,
FAAED812258E16330014F264 /* SafariExtensionViewControllerSearchField.swift */,
FAAED810258E14C00014F264 /* SafariExtensionViewControllerTable.swift */,
FA1EC22925ED93A1003E3F02 /* SafariExtensionViewControllerMerge.swift */,
FA5187E225ED664F004D0F39 /* TableView.swift */,
);
path = SafariExtensionViewController;
Expand Down Expand Up @@ -343,6 +346,7 @@
FAAED811258E14C00014F264 /* SafariExtensionViewControllerTable.swift in Sources */,
FAAEE340230474D70022C8BC /* SafariExtensionHandler.swift in Sources */,
FAE2486B23DB6E4300B82591 /* KeyPress.swift in Sources */,
FA1EC22A25ED93A2003E3F02 /* SafariExtensionViewControllerMerge.swift in Sources */,
FAD60F35258E557200AC2689 /* LoadableNib.swift in Sources */,
FAAED816258E18DB0014F264 /* SafariExtensionViewControllerSupport.swift in Sources */,
FAAED813258E16330014F264 /* SafariExtensionViewControllerSearchField.swift in Sources */,
Expand Down
Expand Up @@ -222,8 +222,8 @@
filePath = "Sessions Extension/SafariExtensionViewController/SafariExtensionViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "104"
endingLineNumber = "104"
startingLineNumber = "109"
endingLineNumber = "109"
landmarkName = "SafariExtensionViewController"
landmarkType = "3">
</BreakpointContent>
Expand Down Expand Up @@ -254,8 +254,8 @@
filePath = "Sessions Extension/SafariExtensionViewController/SafariExtensionViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "105"
endingLineNumber = "105"
startingLineNumber = "110"
endingLineNumber = "110"
landmarkName = "SafariExtensionViewController"
landmarkType = "3">
</BreakpointContent>
Expand All @@ -270,8 +270,8 @@
filePath = "Sessions Extension/SafariExtensionViewController/SafariExtensionViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "45"
endingLineNumber = "45"
startingLineNumber = "50"
endingLineNumber = "50"
landmarkName = "viewDidLoad()"
landmarkType = "7">
<Actions>
Expand Down Expand Up @@ -318,8 +318,8 @@
filePath = "Sessions Extension/SafariExtensionViewController/SafariExtensionViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "76"
endingLineNumber = "76"
startingLineNumber = "81"
endingLineNumber = "81"
landmarkName = "addSession(_:)"
landmarkType = "7">
<Locations>
Expand Down Expand Up @@ -366,8 +366,8 @@
filePath = "Sessions Extension/SafariExtensionViewController/SafariExtensionViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "77"
endingLineNumber = "77"
startingLineNumber = "82"
endingLineNumber = "82"
landmarkName = "addSession(_:)"
landmarkType = "7">
</BreakpointContent>
Expand Down Expand Up @@ -398,8 +398,8 @@
filePath = "Sessions Extension/SafariExtensionViewController/SafariExtensionViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "144"
endingLineNumber = "144"
startingLineNumber = "149"
endingLineNumber = "149"
landmarkName = "replaceMenuItem(_:)"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -416,8 +416,8 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "43"
endingLineNumber = "43"
landmarkName = "unknown"
landmarkType = "0">
landmarkName = "fireTimer(timer:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
Expand Down Expand Up @@ -448,8 +448,8 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "61"
endingLineNumber = "61"
landmarkName = "unknown"
landmarkType = "0">
landmarkName = "fireTimer(timer:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
Expand Down

0 comments on commit 7a08173

Please sign in to comment.