Append biggerFont, smallerFont and resetFont actions to find panel

This commit is contained in:
1024jp 2018-08-05 14:24:32 +09:00
parent 736ff1d518
commit 3393f8222a
3 changed files with 60 additions and 3 deletions

View File

@ -2,6 +2,15 @@
Change Log
==========================
3.5.0-beta.3 (unreleased)
--------------------------
### New Features
- Let the input fields in the find panel accept text scaling commands, such as “Bigger”, “Smaller” and “Reset to Default”.
3.5.0-beta.2 (264)
--------------------------

View File

@ -66,7 +66,7 @@
<rect key="frame" x="0.0" y="0.0" width="460" height="146"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView focusRingType="exterior" verticalHuggingPriority="249" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8gM-hc-HhV">
<scrollView focusRingType="exterior" verticalHuggingPriority="249" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" minMagnification="1" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8gM-hc-HhV">
<rect key="frame" x="20" y="82" width="420" height="44"/>
<clipView key="contentView" id="vCs-g9-nGi" customClass="FindPanelTextClipView" customModule="CotEditor" customModuleProvider="target">
<rect key="frame" x="1" y="1" width="418" height="42"/>
@ -110,7 +110,7 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
<scrollView focusRingType="exterior" verticalHuggingPriority="249" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AIf-o5-KHg">
<scrollView focusRingType="exterior" verticalHuggingPriority="249" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" minMagnification="1" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AIf-o5-KHg">
<rect key="frame" x="20" y="28" width="420" height="44"/>
<clipView key="contentView" id="vJP-0z-fPc" customClass="FindPanelTextClipView" customModule="CotEditor" customModuleProvider="target">
<rect key="frame" x="1" y="1" width="418" height="42"/>

View File

@ -25,7 +25,7 @@
import Cocoa
final class FindPanelFieldViewController: NSViewController, NSTextViewDelegate {
final class FindPanelFieldViewController: NSViewController, NSTextViewDelegate, NSUserInterfaceValidations {
// MARK: Private Properties
@ -125,6 +125,54 @@ final class FindPanelFieldViewController: NSViewController, NSTextViewDelegate {
// MARK: Action Messages
func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
guard let action = item.action else { return false }
switch action {
case #selector(smallerFont):
guard let scrollView = self.findTextView?.enclosingScrollView else { return false }
return scrollView.magnification > scrollView.minMagnification
case #selector(biggerFont):
guard let scrollView = self.findTextView?.enclosingScrollView else { return false }
return scrollView.magnification < scrollView.maxMagnification
default:
break
}
return true
}
/// scale up
@IBAction func biggerFont(_ sender: Any?) {
for textView in [self.findTextView, self.replacementTextView] {
textView?.enclosingScrollView?.animator().magnification += 0.2
}
}
/// scale down
@IBAction func smallerFont(_ sender: Any?) {
for textView in [self.findTextView, self.replacementTextView] {
textView?.enclosingScrollView?.animator().magnification -= 0.2
}
}
/// reset scale and font to default
@IBAction func resetFont(_ sender: Any?) {
for textView in [self.findTextView, self.replacementTextView] {
textView?.enclosingScrollView?.animator().magnification = 1.0
}
}
/// show regular expression reference as popover
@IBAction func showRegexHelp(_ sender: Any?) {