Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Disable scripts menu items when focus is not on a text editor.

  • Loading branch information...
commit 65c31a95492092e868e8bde8f2d1efd651320087 1 parent 7410f7d
@tom-seddon tom-seddon authored
Showing with 31 additions and 11 deletions.
  1. +31 −11 À La Carte Projects/XCFixin_UserScripts/XCFixin_UserScripts.m
View
42 À La Carte Projects/XCFixin_UserScripts/XCFixin_UserScripts.m
@@ -22,19 +22,23 @@
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-static NSTextView *FindIDETextView(void)
+static NSTextView *FindIDETextView(BOOL log)
{
NSWindow *mainWindow=[[NSApplication sharedApplication] mainWindow];
if(!mainWindow)
{
- NSLog(@"Can't find IDE text view - no main window.\n");
+ if(log)
+ NSLog(@"Can't find IDE text view - no main window.\n");
+
return nil;
}
Class DVTCompletingTextView=objc_getClass("DVTCompletingTextView");
if(!DVTCompletingTextView)
{
- NSLog(@"Can't find IDE text view - DVTCompletingTextView class unavailable.\n");
+ if(log)
+ NSLog(@"Can't find IDE text view - DVTCompletingTextView class unavailable.\n");
+
return nil;
}
@@ -51,7 +55,9 @@
if(!textView)
{
- NSLog(@"Can't find IDE text view - no DVTCompletingTextView in the responder chain.\n");
+ if(log)
+ NSLog(@"Can't find IDE text view - no DVTCompletingTextView in the responder chain.\n");
+
return nil;
}
@@ -145,7 +151,7 @@ -(void)run
{
NSLog(@"%s: path=%@\n",__FUNCTION__,fileName_);
- NSTextView *textView=FindIDETextView();
+ NSTextView *textView=FindIDETextView(YES);
if(!textView)
{
NSLog(@"Not running scripts - can't find IDE text view.\n");
@@ -397,7 +403,9 @@ -(void)dealloc
////////////////////////////////////////////////////////////////////////////////
@interface XCFixin_ScriptsHandler:NSObject
-
+{
+ NSMenuItem *refreshMenuItem_;
+}
@end
////////////////////////////////////////////////////////////////////////////////
@@ -596,9 +604,10 @@ -(void)refreshScriptsMenu
[scriptsMenu addItem:[NSMenuItem separatorItem]];
}
- [[scriptsMenu addItemWithTitle:@"Refresh"
- action:@selector(refreshScriptsMenuAction:)
- keyEquivalent:@""] setTarget:self];
+ refreshMenuItem_=[scriptsMenu addItemWithTitle:@"Refresh"
+ action:@selector(refreshScriptsMenuAction:)
+ keyEquivalent:@""];
+ [refreshMenuItem_ setTarget:self];
}
////////////////////////////////////////////////////////////////////////////////
@@ -654,8 +663,19 @@ -(BOOL)install
-(BOOL)validateMenuItem:(NSMenuItem *)menuItem
{
- NSLog(@"%s: title=\"%@\"\n",__FUNCTION__,[menuItem title]);
- return YES;
+ if(menuItem==refreshMenuItem_)
+ {
+ // `Refresh' is always enabled.
+ return YES;
+ }
+
+ if(FindIDETextView(NO))
+ {
+ // Script items are enabled if the focus is on a text editor.
+ return YES;
+ }
+
+ return NO;
}
////////////////////////////////////////////////////////////////////////////////
Please sign in to comment.
Something went wrong with that request. Please try again.