diff --git a/QnA GUI.xcodeproj/project.pbxproj b/QnA GUI.xcodeproj/project.pbxproj
index ea582ab..725f709 100644
--- a/QnA GUI.xcodeproj/project.pbxproj
+++ b/QnA GUI.xcodeproj/project.pbxproj
@@ -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";
@@ -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";
diff --git a/QnA/AppDelegate.swift b/QnA/AppDelegate.swift
index d4b0c21..4ba5d34 100644
--- a/QnA/AppDelegate.swift
+++ b/QnA/AppDelegate.swift
@@ -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) {
diff --git a/QnA/Base.lproj/Main.storyboard b/QnA/Base.lproj/Main.storyboard
index b9eea1a..f0b0fe3 100644
--- a/QnA/Base.lproj/Main.storyboard
+++ b/QnA/Base.lproj/Main.storyboard
@@ -679,9 +679,8 @@
-
+
-
@@ -700,10 +699,10 @@
-
+
-
+
@@ -717,7 +716,7 @@
-
+
@@ -754,15 +753,15 @@
-
+
-
+
-
+
@@ -773,11 +772,11 @@
-
+
-
+
diff --git a/QnA/PrefsViewController.swift b/QnA/PrefsViewController.swift
index e3dcfcb..1e99d8b 100644
--- a/QnA/PrefsViewController.swift
+++ b/QnA/PrefsViewController.swift
@@ -9,10 +9,13 @@
import Cocoa
class PrefsViewController: NSViewController {
-
+
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
}
+ override func viewWillAppear() {
+ super.viewWillAppear()
+ }
}
diff --git a/QnA/QnA.swift b/QnA/QnA.swift
index ef3b641..11c6449 100644
--- a/QnA/QnA.swift
+++ b/QnA/QnA.swift
@@ -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 {
@@ -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
diff --git a/QnA/ViewController.swift b/QnA/ViewController.swift
index c70d3ef..ab734c2 100644
--- a/QnA/ViewController.swift
+++ b/QnA/ViewController.swift
@@ -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)
}
@@ -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"
@@ -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
@@ -113,7 +122,6 @@ class ViewController: NSViewController {
}
// Get unquoted string from text bar
-
let newQuery:String = queryBar.stringValue
// Log new string
@@ -121,6 +129,7 @@ class ViewController: NSViewController {
// Remove temp file
deleteFile()
+
// Write query to temp file
writeToFile(queryText: newQuery)
@@ -132,8 +141,6 @@ class ViewController: NSViewController {
// Set text view to output
setqueryOutput(shelloutput)
-
-
}
func setqueryOutput(_ text: String = "") {