Skip to content

Commit

Permalink
Updating to version 1.7! Fixes Tool tip and adds QnA path to title ba…
Browse files Browse the repository at this point in the history
…r. Added a preferences window that will hold something in the future. Better containerize QnA module by moving code into method. Adding ability to check multiple paths for QnA binary, will make it a preference...I hope.
  • Loading branch information
rustymyers committed Feb 18, 2021
1 parent 5ee4084 commit 9cc2c7b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 61 deletions.
8 changes: 4 additions & 4 deletions QnA GUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.6;
CURRENT_PROJECT_VERSION = 1.7;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = QnA/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.6;
MARKETING_VERSION = 1.7;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = edu.psu.QnAGUI;
PRODUCT_NAME = "QnA GUI";
Expand All @@ -293,12 +293,12 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.6;
CURRENT_PROJECT_VERSION = 1.7;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = QnA/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 1.6;
MARKETING_VERSION = 1.7;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = edu.psu.QnAGUI;
PRODUCT_NAME = "QnA GUI";
Expand Down
29 changes: 0 additions & 29 deletions QnA/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,8 @@ import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var runQueryMenuItem: NSMenuItem!

var qnaPath = String()
var qna_file_paths:[String] = ["/Library/BESAgent/BESAgent.app/Contents/MacOS/QnA","QnA","/usr/local/bin/QnA"]

func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
NSLog("Starting App")

// Create a FileManager instance
let fileManager = FileManager.default

// Check if file exists, given its path
for qna_test_Path in qna_file_paths {
// Example: http://stackoverflow.com/questions/30097521/messagebox-from-daemon-in-swift-os-x
if fileManager.fileExists(atPath: qna_test_Path) {
print("File exists: \(qna_test_Path)")
qnaPath = qna_test_Path
return
} else {
print("File not found: \(qna_test_Path)")
}
}
if qnaPath == "" {
let alert:NSAlert = NSAlert();
alert.messageText = "Missing QnA Binary";
alert.informativeText = "QnA GUI.app could not find the QnA binary! Please install and try again.";
alert.runModal();
exit(3)

} else {
print("We found qna! \(qnaPath)")
}
}

func applicationWillTerminate(_ aNotification: Notification) {
Expand Down
20 changes: 10 additions & 10 deletions QnA/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,8 @@
<scene sceneID="eCI-99-Wa3">
<objects>
<windowController id="vpE-RH-5bo" sceneMemberID="viewController">
<window key="window" title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="d57-cT-UOY">
<window key="window" title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="d57-cT-UOY" userLabel="Preferences">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="425" y="462" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1025"/>
<view key="contentView" id="YqJ-jr-2db">
Expand All @@ -700,10 +699,10 @@
</objects>
<point key="canvasLocation" x="-499" y="250"/>
</scene>
<!--View Controller-->
<!--Prefs View Controller-->
<scene sceneID="kbL-px-ltG">
<objects>
<viewController id="UJN-os-FEQ" sceneMemberID="viewController">
<viewController id="UJN-os-FEQ" customClass="PrefsViewController" customModule="QnA_GUI" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="1hd-Jm-aqO">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
Expand All @@ -717,7 +716,7 @@
<scene sceneID="R2V-B0-nI4">
<objects>
<windowController id="B8D-0N-5wS" sceneMemberID="viewController">
<window key="window" title="QnA GUI" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA" userLabel="QnA GUI">
<window key="window" title="QnA GUI" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="IQv-IB-iLA">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="186" y="565" width="480" height="270"/>
Expand Down Expand Up @@ -754,15 +753,15 @@
<scrollView horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UmQ-5g-f30">
<rect key="frame" x="20" y="20" width="590" height="269"/>
<clipView key="contentView" drawsBackground="NO" id="cCe-bG-ojG">
<rect key="frame" x="1" y="1" width="573" height="267"/>
<rect key="frame" x="1" y="1" width="588" height="267"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView importsGraphics="NO" verticallyResizable="YES" usesFontPanel="YES" findStyle="panel" continuousSpellChecking="YES" allowsUndo="YES" usesRuler="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" spellingCorrection="YES" smartInsertDelete="YES" id="X8r-Um-0gH">
<rect key="frame" x="0.0" y="0.0" width="573" height="267"/>
<rect key="frame" x="0.0" y="0.0" width="588" height="267"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="573" height="267"/>
<size key="minSize" width="588" height="267"/>
<size key="maxSize" width="590" height="10000000"/>
<color key="insertionPointColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
</textView>
Expand All @@ -773,11 +772,11 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="XAK-nL-jgc">
<rect key="frame" x="574" y="1" width="15" height="267"/>
<rect key="frame" x="573" y="1" width="16" height="267"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Nin-oG-onR">
<button toolTip="QnAPATH" verticalHuggingPriority="750" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Nin-oG-onR">
<rect key="frame" x="546" y="290" width="71" height="32"/>
<buttonCell key="cell" type="push" title="Query" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Oui-TC-uyF">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand Down Expand Up @@ -810,6 +809,7 @@ DQ
</connections>
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<userDefaultsController representsSharedInstance="YES" id="hQW-nX-Zie"/>
</objects>
<point key="canvasLocation" x="150" y="688.5"/>
</scene>
Expand Down
5 changes: 4 additions & 1 deletion QnA/PrefsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import Cocoa

class PrefsViewController: NSViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
}
override func viewWillAppear() {
super.viewWillAppear()
}

}
31 changes: 28 additions & 3 deletions QnA/QnA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,35 @@ import Foundation
import os

class QnA: NSObject {
let appDelegate = NSApplication.shared.delegate as! AppDelegate
var qnaPath = String()
//TODO make qna_file_paths a preference, ordered list of preference?
var qna_file_paths:[String] = ["/Library/BESAgent/BESAgent.app/Contents/MacOS/QnA","QnA","/usr/local/bin/QnA"]

func getQnAPath() -> String {
let qnaPath = appDelegate.qnaPath
return qnaPath
// Create a FileManager instance
let fileManager = FileManager.default

// Check if file exists, given its path
for qna_test_Path in qna_file_paths {
// Example: http://stackoverflow.com/questions/30097521/messagebox-from-daemon-in-swift-os-x
if fileManager.fileExists(atPath: qna_test_Path) {
print("File exists: \(qna_test_Path)")
self.qnaPath = qna_test_Path
break
} else {
print("File not found: \(qna_test_Path)")
self.qnaPath = ""
}
}
if self.qnaPath == "" {
let alert:NSAlert = NSAlert();
alert.messageText = "Missing QnA Binary";
alert.informativeText = "QnA GUI.app could not find the QnA binary! Please install and try again.";
alert.runModal();
exit(3)

}
return self.qnaPath
}

func shell(relevance: String) -> String {
Expand All @@ -24,6 +48,7 @@ class QnA: NSObject {

//NSLog("%@", relevance)
task.launchPath = getQnAPath()
//TODO Make -showtypes a preference?
task.arguments = ["-showtypes"]
task.standardInput = inpipe
task.standardOutput = outpipe
Expand Down
35 changes: 21 additions & 14 deletions QnA/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import Foundation
class ViewController: NSViewController {
// Create new QnA object
let qna = QnA.init()

let appDelegate = NSApplication.shared.delegate as! AppDelegate

lazy var window: NSWindow! = self.view.window

@IBAction func runQueryMenuItemSelected(_ sender: Any) {
queryButton(sender: appDelegate)
}
Expand All @@ -24,6 +26,7 @@ class ViewController: NSViewController {
@IBOutlet weak var queryBar: NSTextField!
@IBOutlet var queryOut: NSTextView!
@IBOutlet var queryButtonOutlet: NSButton!

//this is the file. we will write to and read from it
let tmpQueryFile = "/tmp/_qna_query.txt"

Expand All @@ -32,25 +35,31 @@ class ViewController: NSViewController {
deleteFile()
}
override func viewDidLoad() {
if #available(OSX 10.10, *) {
super.viewDidLoad()
} else {
// Fallback on earlier versions
}
super.viewDidLoad()

// Enable selection in query output window
queryOut.isEditable = false
// Set the tool top on the query button to qna binary path
queryButtonOutlet.toolTip = appDelegate.qnaPath


// Do any additional setup after loading the view.
queryBar.stringValue = readFile()

}

override func viewWillAppear() {
super.viewWillAppear()
let qnaPath = qna.getQnAPath()
window?.title = "QnA GUI (\(qnaPath))"
// Set the tool top on the query button to qna binary path
if queryButtonOutlet.toolTip != nil {
queryButtonOutlet.toolTip = qnaPath
} else {
NSLog("Can't set tooltip")
}
}

func readFile() -> String {
// https://stackoverflow.com/questions/37981375/nsfilehandle-updateatpath-how-can-i-update-file-instead-of-overwriting
//https://developer.apple.com/documentation/foundation/filehandle/1411131-init
// Turn our queryText string into data
// let data = queryText.data(using: String.Encoding.utf8, allowLossyConversion: false)!
// Create new filemanager
let filemanager = FileManager.default
// Check for the file at the path and create if it doesn't exist
Expand Down Expand Up @@ -113,14 +122,14 @@ class ViewController: NSViewController {
}

// Get unquoted string from text bar

let newQuery:String = queryBar.stringValue

// Log new string
NSLog("Sending query: %@", newQuery)

// Remove temp file
deleteFile()

// Write query to temp file
writeToFile(queryText: newQuery)

Expand All @@ -132,8 +141,6 @@ class ViewController: NSViewController {

// Set text view to output
setqueryOutput(shelloutput)


}

func setqueryOutput(_ text: String = "") {
Expand Down

0 comments on commit 9cc2c7b

Please sign in to comment.