Skip to content

Commit

Permalink
Implemented right click context menu to terminate application.
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Fischer committed Oct 2, 2015
1 parent 1408b04 commit 9414d7b
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 7 deletions.
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ECF208B81BAF2DE6000D3C2C"
BuildableName = "MuteUnmuteMic.app"
BlueprintName = "MuteUnmuteMic"
ReferencedContainer = "container:MuteUnmuteMic.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ECF208B81BAF2DE6000D3C2C"
BuildableName = "MuteUnmuteMic.app"
BlueprintName = "MuteUnmuteMic"
ReferencedContainer = "container:MuteUnmuteMic.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ECF208B81BAF2DE6000D3C2C"
BuildableName = "MuteUnmuteMic.app"
BlueprintName = "MuteUnmuteMic"
ReferencedContainer = "container:MuteUnmuteMic.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "ECF208B81BAF2DE6000D3C2C"
BuildableName = "MuteUnmuteMic.app"
BlueprintName = "MuteUnmuteMic"
ReferencedContainer = "container:MuteUnmuteMic.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>MuteUnmuteMic.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>ECF208B81BAF2DE6000D3C2C</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
1 change: 1 addition & 0 deletions MuteUnmuteMic/AppDelegate.h
Expand Up @@ -2,6 +2,7 @@

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (weak, nonatomic) IBOutlet NSMenu *menu;

@end

36 changes: 32 additions & 4 deletions MuteUnmuteMic/AppDelegate.m
Expand Up @@ -13,13 +13,36 @@ @interface AppDelegate ()
@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[self initDefaults];
[self configureStatusBar];
}

- (void)initDefaults {
muted = NO;
}

- (void)configureStatusBar {
NSStatusBar *statusBar = [NSStatusBar systemStatusBar];

menuItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
menuItem.highlightMode = YES;
menuItem.image = [NSImage imageNamed:@"mic_on"];
menuItem = [statusBar statusItemWithLength:NSVariableStatusItemLength];
[menuItem setToolTip:@"MuteUnmuteMic by CocoaHeads Brazil"];
[menuItem setImage:[NSImage imageNamed:@"mic_on"]];
[menuItem setHighlightMode:YES];

[menuItem setTarget:self];
[menuItem setAction:@selector(toggleMute)];
[menuItem setAction:@selector(menuItemClicked:)];
[menuItem.button sendActionOn:NSLeftMouseUpMask|NSRightMouseUpMask];
}

- (void)menuItemClicked:(id)sender {
NSEvent *event = [[NSApplication sharedApplication] currentEvent];

if ((event.modifierFlags & NSControlKeyMask) || (event.type == NSRightMouseUp)) {
[self showMenu];
} else {
[self toggleMute];
}

}

- (void)toggleMute {
Expand All @@ -35,4 +58,9 @@ - (void)toggleMute {
menuItem.image = [NSImage imageNamed:imageName];
}

- (void)showMenu {
[menuItem popUpStatusItemMenu:self.menu];
}


@end
24 changes: 21 additions & 3 deletions MuteUnmuteMic/Base.lproj/MainMenu.xib
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9046" systemVersion="14E46" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8191"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9046"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand All @@ -11,7 +11,25 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
<connections>
<outlet property="menu" destination="d1i-xa-wlo" id="2UA-gw-tWj"/>
</connections>
</customObject>
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<menu id="d1i-xa-wlo">
<items>
<menuItem title="Quit" id="kX5-as-WCF">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="terminate:" target="-1" id="yi0-uA-sG0"/>
</connections>
</menuItem>
</items>
<connections>
<outlet property="delegate" destination="Voe-Tx-rLC" id="30G-NN-Naz"/>
</connections>
<point key="canvasLocation" x="-268" y="-315.5"/>
</menu>
</objects>
</document>

0 comments on commit 9414d7b

Please sign in to comment.