Skip to content

Commit

Permalink
Refactoring table
Browse files Browse the repository at this point in the history
Context menu is now showed programatically (it's a surprise tool that will help us later)
  • Loading branch information
AlexPerathoner committed Mar 1, 2021
1 parent ca843ed commit bd0dcae
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<outlet property="ignoringPinnedTabsOutlet" destination="ixg-Wq-9Mi" id="Fel-pF-UPX"/>
<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"/>
<outlet property="tableView" destination="tww-Ty-4mM" id="CcK-Cj-jdK"/>
<outlet property="view" destination="c22-O7-iKe" id="vwT-Xx-Aiz"/>
</connections>
Expand All @@ -38,7 +39,7 @@
<rect key="frame" x="1" y="1" width="201" height="185"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" alternatingRowBackgroundColors="YES" columnReordering="NO" columnResizing="NO" multipleSelection="NO" autosaveColumns="NO" rowHeight="22" rowSizeStyle="automatic" viewBased="YES" id="tww-Ty-4mM">
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" alternatingRowBackgroundColors="YES" columnReordering="NO" columnResizing="NO" autosaveColumns="NO" rowHeight="22" rowSizeStyle="automatic" viewBased="YES" id="tww-Ty-4mM" customClass="TableView" customModule="Sessions_Extension" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="201" height="185"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<size key="intercellSpacing" width="3" height="0.0"/>
Expand Down Expand Up @@ -97,7 +98,6 @@
<action trigger="doubleAction" selector="tableDoubleClick:" target="-2" id="vXJ-BG-tqz"/>
<outlet property="dataSource" destination="nim-kw-0YV" id="KWE-PI-oek"/>
<outlet property="delegate" destination="nim-kw-0YV" id="IH6-iH-nx4"/>
<outlet property="menu" destination="Wud-45-Yjp" id="hv3-Cj-LIb"/>
</connections>
</tableView>
</subviews>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SafariExtensionViewController: SFSafariExtensionViewController, NSControlT
}
var filteredSessions = [Session]()
// MARK: table
@IBOutlet weak var tableView: NSTableView!
@IBOutlet weak var tableView: TableView!
let dragDropType = NSPasteboard.PasteboardType.string

// MARK: searchfield
Expand All @@ -33,6 +33,10 @@ class SafariExtensionViewController: SFSafariExtensionViewController, NSControlT
var statusImage: NSImageView?
var deleteTimer: Timer?

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


override func viewDidLoad() {
super.viewDidLoad()
setupTable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extension SafariExtensionViewController: NSTableViewDelegate, NSTableViewDataSou
tableView.dataSource = self
tableView.menu?.autoenablesItems = true
tableView.registerForDraggedTypes([dragDropType])
tableView.singleMenu = singleSelectionMenu
}


Expand Down
20 changes: 20 additions & 0 deletions Sessions Extension/SafariExtensionViewController/TableView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// TableView.swift
// Sessions Extension
//
// Created by Alex Perathoner on 28/02/2021.
// Copyright © 2021 Alex Perathoner. All rights reserved.
//

import Cocoa

class TableView: NSTableView {
weak var singleMenu: 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)

}
}
4 changes: 4 additions & 0 deletions Sessions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
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 */; };
FA6513AF23047CF300DA8665 /* e52-512.png in Resources */ = {isa = PBXBuildFile; fileRef = FA6513AE23047CF300DA8665 /* e52-512.png */; };
FAAED80F258E119E0014F264 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAED80D258E11960014F264 /* Constants.swift */; };
FAAED811258E14C00014F264 /* SafariExtensionViewControllerTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAED810258E14C00014F264 /* SafariExtensionViewControllerTable.swift */; };
Expand Down Expand Up @@ -60,6 +61,7 @@
/* Begin PBXFileReference section */
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>"; };
FA6513AE23047CF300DA8665 /* e52-512.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "e52-512.png"; sourceTree = "<group>"; };
FA6513B02304C13200DA8665 /* Todo.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Todo.md; sourceTree = "<group>"; };
FAAED80D258E11960014F264 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -118,6 +120,7 @@
FAAED815258E18DB0014F264 /* SafariExtensionViewControllerSupport.swift */,
FAAED812258E16330014F264 /* SafariExtensionViewControllerSearchField.swift */,
FAAED810258E14C00014F264 /* SafariExtensionViewControllerTable.swift */,
FA5187E225ED664F004D0F39 /* TableView.swift */,
);
path = SafariExtensionViewController;
sourceTree = "<group>";
Expand Down Expand Up @@ -332,6 +335,7 @@
FAAEE342230474D70022C8BC /* SafariExtensionViewController.swift in Sources */,
FA23E1D2259A5610000E54DA /* SafariExtensionViewControllerAutoUpdate.swift in Sources */,
FAAED818258E18F20014F264 /* SafariExtensionViewControllerExport.swift in Sources */,
FA5187E325ED664F004D0F39 /* TableView.swift in Sources */,
FABDCBD62309EE88001B240C /* Session.swift in Sources */,
FA200145238C8D65006B31C0 /* WebPage.swift in Sources */,
FABDCBD1230755A2001B240C /* XML.swift in Sources */,
Expand Down

0 comments on commit bd0dcae

Please sign in to comment.