Implement jump to issue

This commit is contained in:
Matthias Neeracher 2015-07-11 02:58:26 +02:00 committed by Matthias Neeracher
parent 9fbd4b9d91
commit bc77af7a80
3 changed files with 107 additions and 22 deletions

View File

@ -28,6 +28,8 @@ func pushToFront(inout list: [String], front: String) {
class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePanelDelegate, ACEViewDelegate { class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePanelDelegate, ACEViewDelegate {
@IBOutlet weak var editor : ACEView! @IBOutlet weak var editor : ACEView!
@IBOutlet weak var auxEdit : ACEView!
@IBOutlet weak var editors : NSStackView!
@IBOutlet weak var outline : NSOutlineView! @IBOutlet weak var outline : NSOutlineView!
@IBOutlet weak var boardTool: NSPopUpButton! @IBOutlet weak var boardTool: NSPopUpButton!
@IBOutlet weak var progTool : NSPopUpButton! @IBOutlet weak var progTool : NSPopUpButton!
@ -53,6 +55,8 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
var printModDate : NSDate? var printModDate : NSDate?
var printRevision : String? var printRevision : String?
var printShowPanel = false var printShowPanel = false
var jumpingToIssue = false
var currentIssueLine = -1
let kVersionKey = "Version" let kVersionKey = "Version"
let kCurVersion = 1.0 let kCurVersion = 1.0
@ -115,6 +119,13 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
editor.setFontSize(fontSize) editor.setFontSize(fontSize)
editor.delegate = self editor.delegate = self
auxEdit.setShowPrintMargin(false)
auxEdit.setTheme(currentTheme)
auxEdit.setKeyboardHandler(keyboardHandler)
auxEdit.setFontSize(fontSize)
editors.setViews([editor], inGravity: .Top)
outline.setDataSource(files) outline.setDataSource(files)
files.apply() { node in files.apply() { node in
if let group = node as? ASFileGroup { if let group = node as? ASFileGroup {
@ -251,8 +262,9 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
let newText = NSString(contentsOfURL:url!, usedEncoding:&enc, error:nil) let newText = NSString(contentsOfURL:url!, usedEncoding:&enc, error:nil)
editor.setString((newText as? String) ?? "") editor.setString((newText as? String) ?? "")
editor.gotoLine(1000000000, column: 0, animated: true) editor.gotoLine(1000000000, column: 0, animated: true)
logModified = modified as! NSDate logModified = modified as! NSDate
logSize = size as! Int logSize = size as! Int
currentIssueLine = -1
} }
} }
} }
@ -448,6 +460,9 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
func outlineViewSelectionDidChange(notification: NSNotification) { func outlineViewSelectionDidChange(notification: NSNotification) {
willChangeValueForKey("hasSelection") willChangeValueForKey("hasSelection")
if !jumpingToIssue {
editors.setViews([], inGravity: .Bottom)
}
if outline.numberOfSelectedRows < 2 { if outline.numberOfSelectedRows < 2 {
selectNode(outline.itemAtRow(outline.selectedRow) as! ASFileNode?) selectNode(outline.itemAtRow(outline.selectedRow) as! ASFileNode?)
} }
@ -688,6 +703,64 @@ class ASProjDoc: NSDocument, NSOutlineViewDelegate, NSMenuDelegate, NSOpenSavePa
updateChangeCount(.ChangeDone) updateChangeCount(.ChangeDone)
} }
} }
// MARK: Issues
@IBAction func jumpToIssue(sender: AnyObject) {
let direction : Int = (sender as! NSMenuItem).tag
if editors.viewsInGravity(.Bottom).count == 0 {
editors.addView(auxEdit, inGravity: .Bottom)
let url = fileURL?.URLByDeletingLastPathComponent?.URLByAppendingPathComponent(files.buildLog.path)
if url == nil {
return
}
var enc : UInt = 0
auxEdit.setString(NSString(contentsOfURL:url!, usedEncoding:&enc, error:nil) as? String ?? "")
editor.setMode(.Text)
editor.alphaValue = 1.0
}
let buildLog = auxEdit.string().componentsSeparatedByString("\n")
let issueRe = NSRegularExpression(pattern: "(\\S+?):(\\d+):.*", options: nil, error: nil)!
currentIssueLine += direction
while currentIssueLine > -1 && currentIssueLine < buildLog.count {
let line = buildLog[currentIssueLine]
let range = NSMakeRange(0, count(line.utf16))
if let match = issueRe.firstMatchInString(line, options:.Anchored, range:range) {
let file = match.rangeAtIndex(1)
let lineTxt = match.rangeAtIndex(2)
let nsline = line as NSString
let lineNo = nsline.substringWithRange(lineTxt).toInt()!
let fileName = nsline.substringWithRange(file) as NSString
let fileURL : NSURL
if fileName.hasPrefix("../../") {
fileURL = files.dir.URLByAppendingPathComponent(fileName.substringFromIndex(6))
} else {
fileURL = NSURL(fileURLWithPath:fileName as String)!.URLByStandardizingPath!
}
jumpingToIssue = true
var resourceID : AnyObject?
fileURL.getResourceValue(&resourceID, forKey:NSURLFileResourceIdentifierKey, error:nil)
files.apply {(node) in
if let file = node as? ASFileItem {
var thisID : AnyObject?
file.url.getResourceValue(&thisID, forKey:NSURLFileResourceIdentifierKey, error:nil)
if thisID != nil && resourceID!.isEqual(thisID!) {
self.selectNodeInOutline(node)
self.editor.gotoLine(lineNo, column:0, animated:true)
}
}
}
jumpingToIssue = false
auxEdit.gotoLine(currentIssueLine+1, column:0, animated: true)
break
}
currentIssueLine += direction
}
}
// MARK: Build / Upload // MARK: Build / Upload

View File

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7702" systemVersion="14F4" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies> <dependencies>
<development version="6200" identifier="xcode"/> <development version="6200" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7702"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7702"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies> </dependencies>
<objects> <objects>
<customObject id="-2" userLabel="File's Owner" customClass="ASProjDoc" customModule="AVRsack"> <customObject id="-2" userLabel="File's Owner" customClass="ASProjDoc" customModule="AVRsack">
<connections> <connections>
<outlet property="auxEdit" destination="Kfh-Ag-J3X" id="D7H-fk-9rL"/>
<outlet property="boardTool" destination="xO5-xB-HHj" id="xzX-eY-Ofe"/> <outlet property="boardTool" destination="xO5-xB-HHj" id="xzX-eY-Ofe"/>
<outlet property="editor" destination="Nhg-qn-6A8" id="eUR-Gk-IBw"/> <outlet property="editor" destination="Nhg-qn-6A8" id="gcr-ED-Eil"/>
<outlet property="editors" destination="M6t-Fu-HMa" id="Bpq-O7-xMr"/>
<outlet property="outline" destination="nij-C2-Fna" id="sVi-eL-hqZ"/> <outlet property="outline" destination="nij-C2-Fna" id="sVi-eL-hqZ"/>
<outlet property="portTool" destination="4rZ-U5-AH6" id="8Nb-iI-pJH"/> <outlet property="portTool" destination="4rZ-U5-AH6" id="8Nb-iI-pJH"/>
<outlet property="printView" destination="HFe-2c-jeW" id="dh0-q5-QVW"/>
<outlet property="progTool" destination="08n-xg-fNl" id="959-as-OtP"/> <outlet property="progTool" destination="08n-xg-fNl" id="959-as-OtP"/>
<outlet property="window" destination="xOd-HO-29H" id="JIz-fz-R2o"/> <outlet property="window" destination="xOd-HO-29H" id="JIz-fz-R2o"/>
</connections> </connections>
@ -33,10 +33,10 @@
<rect key="frame" x="0.0" y="0.0" width="1001" height="500"/> <rect key="frame" x="0.0" y="0.0" width="1001" height="500"/>
<subviews> <subviews>
<box autoresizesSubviews="NO" title="Box" boxType="custom" borderType="none" titlePosition="noTitle" id="0X4-Im-JAh"> <box autoresizesSubviews="NO" title="Box" boxType="custom" borderType="none" titlePosition="noTitle" id="0X4-Im-JAh">
<rect key="frame" x="0.0" y="0.0" width="229" height="500"/> <rect key="frame" x="0.0" y="0.0" width="228.5" height="500"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView"> <view key="contentView">
<rect key="frame" x="0.0" y="0.0" width="229" height="500"/> <rect key="frame" x="0.0" y="0.0" width="228.5" height="500"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<scrollView misplaced="YES" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ObX-J0-NIB"> <scrollView misplaced="YES" autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ObX-J0-NIB">
@ -125,17 +125,11 @@
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/> <color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
<color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> <color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</box> </box>
<customView id="Nhg-qn-6A8" customClass="ACEView"> <stackView orientation="vertical" alignment="centerX" spacing="2" horizontalHuggingPriority="249" verticalHuggingPriority="249" fixedFrame="YES" id="M6t-Fu-HMa">
<rect key="frame" x="230" y="0.0" width="771" height="500"/> <rect key="frame" x="229.5" y="0.0" width="771.5" height="500"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<constraints> </stackView>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="100" id="dHZ-ac-XrM"/>
</constraints>
</customView>
</subviews> </subviews>
<constraints>
<constraint firstItem="0X4-Im-JAh" firstAttribute="width" relation="lessThanOrEqual" secondItem="Nhg-qn-6A8" secondAttribute="width" multiplier="0.25" constant="50" id="A29-q0-dcn"/>
</constraints>
<holdingPriorities> <holdingPriorities>
<real value="250"/> <real value="250"/>
<real value="250"/> <real value="250"/>
@ -280,9 +274,16 @@
<point key="canvasLocation" x="408" y="438"/> <point key="canvasLocation" x="408" y="438"/>
</window> </window>
<userDefaultsController representsSharedInstance="YES" id="fpc-q0-yYy"/> <userDefaultsController representsSharedInstance="YES" id="fpc-q0-yYy"/>
<customView id="HFe-2c-jeW" customClass="ACEView"> <customView misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Nhg-qn-6A8" customClass="ACEView">
<rect key="frame" x="0.0" y="0.0" width="163" height="96"/> <constraints>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <constraint firstAttribute="width" relation="greaterThanOrEqual" constant="100" id="dHZ-ac-XrM"/>
</constraints>
</customView>
<customView misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Kfh-Ag-J3X" customClass="ACEView">
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="100" id="bnV-eX-5lg"/>
<constraint firstAttribute="height" constant="100" id="s9M-vL-e15"/>
</constraints>
</customView> </customView>
</objects> </objects>
<resources> <resources>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7702" systemVersion="14F4" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies> <dependencies>
<development version="6200" identifier="xcode"/> <development version="6200" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7702"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7702"/>
@ -375,6 +375,17 @@ CA
</connections> </connections>
</menuItem> </menuItem>
<menuItem isSeparatorItem="YES" id="qYd-6T-XvV"/> <menuItem isSeparatorItem="YES" id="qYd-6T-XvV"/>
<menuItem title="Jump to Next Issue" tag="1" keyEquivalent="'" id="7s3-uG-LWo">
<connections>
<action selector="jumpToIssue:" target="-1" id="0Ql-DF-4Yw"/>
</connections>
</menuItem>
<menuItem title="Jump to Previous Issue" tag="-1" keyEquivalent="&quot;" id="qEF-oa-KMu">
<connections>
<action selector="jumpToIssue:" target="-1" id="hlw-Mu-L20"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="qtx-oJ-5yi"/>
<menuItem title="Show Toolbar" keyEquivalent="t" id="snW-S8-Cw5"> <menuItem title="Show Toolbar" keyEquivalent="t" id="snW-S8-Cw5">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/> <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections> <connections>