Skip to content

Commit e0a43ad

Browse files
authored
Merge pull request #14 from niki-timofe/v2-migrating-to-table
v2 migrating to table Changing text field to table layout in menu item
2 parents 76c03b4 + bcf7b4a commit e0a43ad

File tree

5 files changed

+101
-76
lines changed

5 files changed

+101
-76
lines changed

NarodMonWidget.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
112ECCB21DC4DB0500E221A3 /* WeatherView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 112ECCB11DC4DB0500E221A3 /* WeatherView.swift */; };
1110
11A4E6701DC24A0B001470BF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11A4E66F1DC24A0B001470BF /* AppDelegate.swift */; };
1211
11A4E6721DC24A0B001470BF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 11A4E6711DC24A0B001470BF /* Assets.xcassets */; };
1312
11A4E6751DC24A0B001470BF /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 11A4E6731DC24A0B001470BF /* MainMenu.xib */; };
@@ -16,7 +15,6 @@
1615
/* End PBXBuildFile section */
1716

1817
/* Begin PBXFileReference section */
19-
112ECCB11DC4DB0500E221A3 /* WeatherView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeatherView.swift; sourceTree = "<group>"; };
2018
11A4E66C1DC24A0B001470BF /* NarodMonWidget.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NarodMonWidget.app; sourceTree = BUILT_PRODUCTS_DIR; };
2119
11A4E66F1DC24A0B001470BF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2220
11A4E6711DC24A0B001470BF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -62,7 +60,6 @@
6260
11A4E66F1DC24A0B001470BF /* AppDelegate.swift */,
6361
11A4E6711DC24A0B001470BF /* Assets.xcassets */,
6462
11A4E6731DC24A0B001470BF /* MainMenu.xib */,
65-
112ECCB11DC4DB0500E221A3 /* WeatherView.swift */,
6663
11A4E6801DC252AE001470BF /* NarodMonAPI.swift */,
6764
11A4E67E1DC24F40001470BF /* StatusMenuController.swift */,
6865
11A4E6761DC24A0B001470BF /* Info.plist */,
@@ -170,7 +167,6 @@
170167
11A4E67F1DC24F40001470BF /* StatusMenuController.swift in Sources */,
171168
11A4E6811DC252AE001470BF /* NarodMonAPI.swift in Sources */,
172169
11A4E6701DC24A0B001470BF /* AppDelegate.swift in Sources */,
173-
112ECCB21DC4DB0500E221A3 /* WeatherView.swift in Sources */,
174170
);
175171
runOnlyForDeploymentPostprocessing = 0;
176172
};
Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16E154a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
44
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11762"/>
55
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -17,7 +17,7 @@
1717
<customObject id="MIc-jK-RNp" customClass="StatusMenuController" customModule="NarodMonWidget" customModuleProvider="target">
1818
<connections>
1919
<outlet property="statusMenu" destination="wAj-RY-mUf" id="7js-na-PVc"/>
20-
<outlet property="weatherView" destination="sT5-qx-W03" id="xD9-Bu-gip"/>
20+
<outlet property="updateMenuItem" destination="ccc-Rz-wju" id="N6P-38-kC1"/>
2121
</connections>
2222
</customObject>
2323
<menu id="wAj-RY-mUf">
@@ -31,7 +31,7 @@
3131
<menuItem title="Weather" id="6rQ-gp-sD7">
3232
<modifierMask key="keyEquivalentModifierMask"/>
3333
<connections>
34-
<outlet property="view" destination="sT5-qx-W03" id="bp1-4W-HnG"/>
34+
<outlet property="view" destination="ngT-QE-PSM" id="N8z-SF-mmx"/>
3535
</connections>
3636
</menuItem>
3737
<menuItem isSeparatorItem="YES" id="I6O-iu-YTW"/>
@@ -43,33 +43,71 @@
4343
</items>
4444
<point key="canvasLocation" x="75" y="145"/>
4545
</menu>
46-
<scrollView horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" id="Sw7-fe-Eoh">
47-
<rect key="frame" x="0.0" y="0.0" width="151" height="45"/>
48-
<autoresizingMask key="autoresizingMask"/>
49-
<clipView key="contentView" id="KEO-HK-EM0">
50-
<rect key="frame" x="1" y="1" width="149" height="43"/>
51-
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
52-
<subviews>
53-
<textView editable="NO" selectable="NO" drawsBackground="NO" importsGraphics="NO" richText="NO" horizontallyResizable="YES" findStyle="panel" quoteSubstitution="YES" dashSubstitution="YES" smartInsertDelete="YES" id="sT5-qx-W03" customClass="WeatherView" customModule="NarodMonWidget" customModuleProvider="target">
54-
<rect key="frame" x="0.0" y="0.0" width="149" height="43"/>
55-
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" heightSizable="YES"/>
56-
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
57-
<size key="minSize" width="149" height="43"/>
58-
<size key="maxSize" width="463" height="10000000"/>
59-
<color key="insertionPointColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
60-
</textView>
61-
</subviews>
62-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
63-
</clipView>
64-
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="YES" id="3m9-QC-4GZ">
65-
<rect key="frame" x="-100" y="-100" width="87" height="18"/>
66-
<autoresizingMask key="autoresizingMask"/>
67-
</scroller>
68-
<scroller key="verticalScroller" verticalHuggingPriority="750" horizontal="NO" id="oxT-7l-Ji3">
69-
<rect key="frame" x="134" y="1" width="16" height="43"/>
70-
<autoresizingMask key="autoresizingMask"/>
71-
</scroller>
72-
<point key="canvasLocation" x="74.5" y="257.5"/>
73-
</scrollView>
46+
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="firstColumnOnly" selectionHighlightStyle="none" columnReordering="NO" columnResizing="NO" multipleSelection="NO" emptySelection="NO" autosaveColumns="NO" typeSelect="NO" id="ngT-QE-PSM">
47+
<rect key="frame" x="0.0" y="0.0" width="222" height="19"/>
48+
<autoresizingMask key="autoresizingMask" flexibleMinX="YES"/>
49+
<size key="intercellSpacing" width="0.0" height="2"/>
50+
<color key="backgroundColor" name="windowBackgroundColor" catalog="System" colorSpace="catalog"/>
51+
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
52+
<tableColumns>
53+
<tableColumn identifier="" width="20" minWidth="10" maxWidth="3.4028234663852886e+38" id="YnU-kN-B1W">
54+
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left">
55+
<font key="font" metaFont="smallSystem"/>
56+
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
57+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
58+
</tableHeaderCell>
59+
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" alignment="left" title="Text Cell" id="RMl-lx-jqK">
60+
<font key="font" metaFont="system"/>
61+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
62+
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
63+
</textFieldCell>
64+
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
65+
</tableColumn>
66+
<tableColumn identifier="name" editable="NO" width="97" minWidth="60" maxWidth="3.4028234663852886e+38" id="RpR-yF-FMR">
67+
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left">
68+
<font key="font" metaFont="smallSystem"/>
69+
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
70+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
71+
</tableHeaderCell>
72+
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" alignment="left" title="Text Cell" usesSingleLineMode="YES" id="v0n-Br-gA2">
73+
<font key="font" metaFont="system"/>
74+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
75+
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
76+
</textFieldCell>
77+
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES"/>
78+
</tableColumn>
79+
<tableColumn identifier="value" editable="NO" width="55" minWidth="5" maxWidth="3.4028234663852886e+38" id="DyW-eg-Mgv">
80+
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="right">
81+
<font key="font" metaFont="smallSystem"/>
82+
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
83+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
84+
</tableHeaderCell>
85+
<textFieldCell key="dataCell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" alignment="right" title="0.0" id="AK6-sS-X2l">
86+
<font key="font" metaFont="system"/>
87+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
88+
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
89+
</textFieldCell>
90+
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES"/>
91+
</tableColumn>
92+
<tableColumn identifier="type" editable="NO" width="50" minWidth="5" maxWidth="3.4028234663852886e+38" id="v7x-Zt-bMW">
93+
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left">
94+
<font key="font" metaFont="smallSystem"/>
95+
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
96+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
97+
</tableHeaderCell>
98+
<textFieldCell key="dataCell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" alignment="left" title="d" id="X6i-ck-j92">
99+
<font key="font" metaFont="system"/>
100+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
101+
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
102+
</textFieldCell>
103+
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES"/>
104+
</tableColumn>
105+
</tableColumns>
106+
<connections>
107+
<outlet property="dataSource" destination="MIc-jK-RNp" id="4Z8-gW-esI"/>
108+
<outlet property="delegate" destination="MIc-jK-RNp" id="5jw-O3-Opf"/>
109+
</connections>
110+
<point key="canvasLocation" x="106.5" y="380.5"/>
111+
</tableView>
74112
</objects>
75113
</document>

NarodMonWidget/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<key>CFBundleShortVersionString</key>
2020
<string>2.0.0</string>
2121
<key>CFBundleVersion</key>
22-
<string>144</string>
22+
<string>227</string>
2323
<key>LSApplicationCategoryType</key>
2424
<string>public.app-category.weather</string>
2525
<key>LSMinimumSystemVersion</key>

NarodMonWidget/StatusMenuController.swift

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@ import Cocoa
1010

1111
class StatusMenuController: NSObject, NarodMonAPIDelegate {
1212
@IBOutlet weak var statusMenu: NSMenu!
13-
@IBOutlet weak var weatherView: WeatherView!
13+
@IBOutlet weak var updateMenuItem: NSMenuItem!
14+
@IBOutlet weak var readingsTable: NSTableView!
1415

1516
let statusItem = NSStatusBar.system().statusItem(withLength: NSVariableStatusItemLength)
1617

17-
var weatherMenuItem: NSMenuItem!
1818
var narodMonAPI: NarodMonAPI!
1919
var sensorsList: [Int:Type] = [:]
2020
var updateTimer: Timer!
21+
22+
var results = [Int:Float]()
23+
var counters = [Int:Float]()
2124

2225
override func awakeFromNib() {
2326
narodMonAPI = NarodMonAPI(delegate: self)
2427
statusItem.title = "~"
2528
statusItem.menu = statusMenu
26-
27-
weatherView.textContainerInset = NSSize(width: 16, height: 0)
2829
}
2930

3031
@IBAction func updateBtnAction(_ sender: NSMenuItem) {
@@ -49,11 +50,6 @@ class StatusMenuController: NSObject, NarodMonAPIDelegate {
4950
}
5051

5152
func gotSensorsValues(rdgs: [Reading]) {
52-
var inTitle = ""
53-
54-
var results = [Int:Float]()
55-
var counters = [Int:Float]()
56-
5753
for reading in rdgs {
5854
if let result = results[sensorsList[reading.sensor]!.id] {
5955
results.updateValue(result + reading.value,
@@ -73,19 +69,8 @@ class StatusMenuController: NSObject, NarodMonAPIDelegate {
7369
results[1]! / counters[1]!,
7470
narodMonAPI.types[1].unit)
7571

76-
for type in Array(results.keys).sorted() {
77-
inTitle += String(format: "%@: %.1f%@\n",
78-
narodMonAPI.types[type].name,
79-
results[type]! / counters[type]!,
80-
narodMonAPI.types[type].unit)
81-
}
82-
inTitle = inTitle.substring(to: inTitle.index(before: inTitle.endIndex))
83-
84-
weatherView.textStorage?.mutableString.setString(inTitle)
85-
var frame = weatherView.frame
86-
frame.size.width = weatherView.attributedString().size().width + 42
87-
weatherView.frame = frame
88-
72+
let updateTime = Calendar.current.dateComponents([.hour, .minute], from: Date())
73+
updateMenuItem.title = String(format: "Обновить (%d:%d)", updateTime.hour!, updateTime.minute!)
8974
}
9075

9176
func performUpdateValues() -> Void {
@@ -115,3 +100,27 @@ class StatusMenuController: NSObject, NarodMonAPIDelegate {
115100
NSApplication.shared().terminate(self)
116101
}
117102
}
103+
104+
extension StatusMenuController: NSTableViewDataSource, NSTableViewDelegate {
105+
func numberOfRows(in tableView: NSTableView) -> Int {
106+
return (results.count)
107+
}
108+
109+
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any?{
110+
var result = ""
111+
112+
let type = Array(results.keys).sorted()[row]
113+
114+
let columnIdentifier = tableColumn?.identifier
115+
if columnIdentifier == "type" {
116+
result = narodMonAPI.types[type].unit
117+
}
118+
if columnIdentifier == "name" {
119+
result = narodMonAPI.types[type].name
120+
}
121+
if columnIdentifier == "value" {
122+
result = String(format:"%.1f", results[type]! / counters[type]!)
123+
}
124+
return result
125+
}
126+
}

NarodMonWidget/WeatherView.swift

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)