Commits

Anonymous committed f098e6a

I did a code review on John Daniel's ShellHere code and offered some changes/feedback. He has subsequently revised his code and improved things.

I noticed Murky used some of his code, but omitted the double-terminal window creation corner-case. So I have put that back in.

I have also added the new improved changes which include no longer needing to sleep for the terminal to come up.

  • Participants
  • Parent commits cc411a4

Comments (0)

Files changed (1)

File Source/RepoController_Actions.m

     // Terminal
     // Code from John Daniel - ShellHere
     TerminalApplication * terminal = [SBApplication applicationWithBundleIdentifier: @"com.apple.Terminal"];
+	BOOL terminalWasRunning = [terminal isRunning];
+	
+    // Get the Terminal windows.
+    SBElementArray * terminalWindows = [terminal windows];
     
+    TerminalTab * currentTab = nil;
+    
+    // If there is only a single window with a single tab, Terminal may 
+    // have been just launched. If so, I want to use the new window.
+	// (This prevents two windows from being created.)
+    if(!terminalWasRunning) {
+        for(TerminalWindow * terminalWindow in terminalWindows) {
+		    SBElementArray * windowTabs = [terminalWindow tabs];
+            for(TerminalTab * tab in windowTabs) {
+                currentTab = tab;
+            }
+        }
+    }
+	
     // Create a "cd" command.
     NSString * command = [NSString stringWithFormat: @"cd %@; clear", [[fileURL path] stringByStandardizingPath]];
-    [terminal doScript: command in: nil];
-    
-    // Wait for "a while" for the script to run and get a new window.
-    // I wish there was a better way to do this.
-    [NSThread sleepForTimeInterval: 0.1];
+    [terminal doScript: command in: currentTab];
     
     // Activate the Terminal. Hopefully, the new window is already open and
     // is will be brought to the front.