Skip to content

Commit

Permalink
always on atop an button tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
whomwah committed Dec 19, 2013
1 parent 9df56ad commit f842655
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 22 deletions.
14 changes: 12 additions & 2 deletions app/_buttons/vote_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ def initWithVote vote
init.tap do |button|
@vote = vote
button.translatesAutoresizingMaskIntoConstraints = false
button.setBezelStyle(NSRegularSquareBezelStyle)
button.setBezelStyle(NSTexturedSquareBezelStyle)
button.setButtonType(NSMomentaryPushButton)
button.setTitle vote ? "+" : "-"

paragraph = NSMutableParagraphStyle.new
paragraph.setAlignment(NSCenterTextAlignment)

txt = vote ? "Vote Up" : "Vote Down"
txt = txt.attrd({
'NSFont' => NSFont.fontWithName("Lucida Grande", size:10),
'NSParagraphStyle' => paragraph
})

button.setAttributedTitle(txt)
button.setAction "register_vote:"
end
end
Expand Down
36 changes: 26 additions & 10 deletions app/_views/vote_buttons_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,49 @@ class VoteButtonsView < NSView

def init
super.tap do |v|
v.translatesAutoresizingMaskIntoConstraints = false

views_dictionary = {
"up_vote_button" => up_vote_button,
"down_vote_button" => down_vote_button
"up_vote_button" => up_vote_button,
"down_vote_button" => down_vote_button
}

metrics_dict = {
"butt_w" => 80,
"butt_h" => 22,
"butt_space" => 5,
}

views_dictionary.each do |key, view|
v.addSubview(view)
end
v.translatesAutoresizingMaskIntoConstraints = false

constraints = []
constraints += NSLayoutConstraint.constraintsWithVisualFormat(
"H:|[up_vote_button(==35)]|",
"H:|[up_vote_button(==butt_w)]|",
options:0,
metrics:nil,
metrics:metrics_dict,
views:views_dictionary
)
constraints += NSLayoutConstraint.constraintsWithVisualFormat(
"H:|[down_vote_button(==35)]|",
"H:|[down_vote_button(==butt_w)]|",
options:0,
metrics:nil,
metrics:metrics_dict,
views:views_dictionary
)
constraints += NSLayoutConstraint.constraintsWithVisualFormat(
"V:|[up_vote_button]-4-[down_vote_button]|",
options:NSLayoutFormatAlignAllCenterX,
metrics:nil,
"V:|-butt_space-[up_vote_button(==butt_h)]",
options:NSLayoutFormatAlignAllRight,
metrics:metrics_dict,
views:views_dictionary
)
constraints += NSLayoutConstraint.constraintsWithVisualFormat(
"V:[down_vote_button(==butt_h)]-butt_space-|",
options:NSLayoutFormatAlignAllRight,
metrics:metrics_dict,
views:views_dictionary
)

v.addConstraints constraints
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/_windows/jukebox_control_window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def build_views
views:views_dictionary
)
constraints += NSLayoutConstraint.constraintsWithVisualFormat(
"V:|-10-[vote_buttons]-10-|",
"V:|-5-[vote_buttons]-5-|",
options:0,
metrics:nil,
views:views_dictionary
Expand Down
21 changes: 21 additions & 0 deletions app/controllers/jukebox_control_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,31 @@ def setup(jukebox)
build_window
end

def windowDidBecomeMain(notification)
choose_window_level
end

def windowDidResignMain(notification)
choose_window_level
end

private

def choose_window_level
if window_on_top?
window.setLevel(NSFloatingWindowLevel)
else
window.setLevel(NSNormalWindowLevel)
end
end

def window_on_top?
Persistence.get("alwaysOnTop")
end

def build_window
@window ||= JukeboxControlWindow.build
@window.delegate = self
@window.nowplaying_controller.view.refresh(jukebox)
@window.title = "Jukebox Control"
self.setWindow(@window)
Expand Down
34 changes: 25 additions & 9 deletions resources/Preferences.xib
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
<customObject id="-3" userLabel="Application"/>
<window title="KyanBar Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" wantsToBeColor="NO" appearanceType="aqua" animationBehavior="default" id="1" customClass="NSPanel">
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
<rect key="contentRect" x="196" y="240" width="411" height="161"/>
<rect key="contentRect" x="196" y="240" width="411" height="192"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1418"/>
<view key="contentView" id="2">
<rect key="frame" x="0.0" y="0.0" width="411" height="161"/>
<rect key="frame" x="0.0" y="0.0" width="411" height="192"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="kuZ-hG-CA5">
<rect key="frame" x="18" y="121" width="225" height="18"/>
<rect key="frame" x="18" y="152" width="225" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Automatically check for updates" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="LJO-ap-bIT">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
Expand All @@ -31,7 +31,7 @@
</connections>
</button>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0uH-RX-QUa">
<rect key="frame" x="247" y="117" width="147" height="26"/>
<rect key="frame" x="247" y="148" width="147" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" id="xWA-OK-Enm">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -51,7 +51,7 @@
</connections>
</popUpButton>
<textField appearanceType="aqua" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Sub-b7-u3Z">
<rect key="frame" x="95" y="56" width="296" height="22"/>
<rect key="frame" x="95" y="87" width="296" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="please enter your username" drawsBackground="YES" usesSingleLineMode="YES" id="dIB-uO-xig">
<font key="font" metaFont="cellTitle"/>
Expand All @@ -67,7 +67,7 @@
</connections>
</textField>
<textField appearanceType="aqua" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XP5-qN-yfl">
<rect key="frame" x="18" y="59" width="71" height="17"/>
<rect key="frame" x="18" y="90" width="71" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Username:" id="DVI-ra-6GF">
<font key="font" metaFont="system"/>
Expand All @@ -76,7 +76,7 @@
</textFieldCell>
</textField>
<textField appearanceType="aqua" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hmg-Bs-OzK">
<rect key="frame" x="18" y="28" width="71" height="17"/>
<rect key="frame" x="18" y="59" width="71" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Password:" id="GPB-VN-ixZ">
<font key="font" metaFont="system"/>
Expand All @@ -85,7 +85,7 @@
</textFieldCell>
</textField>
<textField appearanceType="aqua" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Zil-wr-w1V">
<rect key="frame" x="20" y="86" width="373" height="17"/>
<rect key="frame" x="20" y="117" width="373" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Jukebox Settings" id="ktu-b0-Q4o">
<font key="font" size="11" name="LucidaGrande"/>
Expand All @@ -94,7 +94,7 @@
</textFieldCell>
</textField>
<secureTextField appearanceType="aqua" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hdl-x6-f9B">
<rect key="frame" x="95" y="25" width="296" height="22"/>
<rect key="frame" x="95" y="56" width="296" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<secureTextFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="please enter your password" drawsBackground="YES" usesSingleLineMode="YES" id="8Oy-Um-Mo3">
<font key="font" metaFont="cellTitle"/>
Expand All @@ -112,6 +112,22 @@
</binding>
</connections>
</secureTextField>
<button appearanceType="aqua" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Jae-Oz-Ju1">
<rect key="frame" x="93" y="32" width="375" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Jukebox remote window always on top" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="GD4-Yt-sPK">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" size="11" name="LucidaGrande"/>
</buttonCell>
<connections>
<binding destination="62v-zO-hda" name="value" keyPath="values.alwaysOnTop" id="AqM-cy-iM1">
<dictionary key="options">
<bool key="NSValidatesImmediately" value="YES"/>
<bool key="NSConditionallySetsEnabled" value="NO"/>
</dictionary>
</binding>
</connections>
</button>
</subviews>
</view>
<connections>
Expand Down

0 comments on commit f842655

Please sign in to comment.