Skip to content

Commit

Permalink
Setup print alignment control by code
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Aug 13, 2023
1 parent 534e8c2 commit 9ad010e
Show file tree
Hide file tree
Showing 36 changed files with 142 additions and 610 deletions.
32 changes: 18 additions & 14 deletions CotEditor/Base.lproj/PrintPane.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="22146" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="4if-cg-44c">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="22152" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="4if-cg-44c">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22146"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22152"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -67,9 +67,9 @@
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="Jap-f3-ehL">
<font key="font" metaFont="system"/>
<segments>
<segment toolTip="Align Left" image="arrow.backward.to.line" catalog="system" width="22"/>
<segment toolTip="Center" image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment toolTip="Align Right" image="arrow.forward.to.line" catalog="system" width="22"/>
<segment image="arrow.backward.to.line" catalog="system" width="22"/>
<segment image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment image="arrow.forward.to.line" catalog="system" width="22"/>
</segments>
</segmentedCell>
<connections>
Expand Down Expand Up @@ -106,9 +106,9 @@
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="90p-SJ-bXq">
<font key="font" metaFont="system"/>
<segments>
<segment toolTip="Align Left" image="arrow.backward.to.line" catalog="system" width="22"/>
<segment toolTip="Center" image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment toolTip="Align Right" image="arrow.forward.to.line" catalog="system" width="22">
<segment image="arrow.backward.to.line" catalog="system" width="22"/>
<segment image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment image="arrow.forward.to.line" catalog="system" width="22">
<nil key="label"/>
</segment>
</segments>
Expand Down Expand Up @@ -186,9 +186,9 @@
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="Pjk-d8-E4v">
<font key="font" metaFont="system"/>
<segments>
<segment toolTip="Align Left" image="arrow.backward.to.line" catalog="system" width="22"/>
<segment toolTip="Center" image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment toolTip="Align Right" image="arrow.forward.to.line" catalog="system" width="22">
<segment image="arrow.backward.to.line" catalog="system" width="22"/>
<segment image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment image="arrow.forward.to.line" catalog="system" width="22">
<nil key="label"/>
</segment>
</segments>
Expand Down Expand Up @@ -227,9 +227,9 @@
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="Zgh-yF-xd2">
<font key="font" metaFont="system"/>
<segments>
<segment toolTip="Align Left" image="arrow.backward.to.line" catalog="system" width="22"/>
<segment toolTip="Center" image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment toolTip="Align Right" image="arrow.forward.to.line" catalog="system" width="22">
<segment image="arrow.backward.to.line" catalog="system" width="22"/>
<segment image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment image="arrow.forward.to.line" catalog="system" width="22">
<nil key="label"/>
</segment>
</segments>
Expand Down Expand Up @@ -421,9 +421,13 @@
</view>
<connections>
<outlet property="colorPopUpButton" destination="ito-FV-Lxm" id="TmH-AS-ZMV"/>
<outlet property="primaryFooterAlignmentControl" destination="WDk-Zl-PJd" id="Ym7-Dr-jYi"/>
<outlet property="primaryFooterPopUpButton" destination="zgD-wy-VQk" id="jld-k6-Hov"/>
<outlet property="primaryHeaderAlignmentControl" destination="fiR-qP-3Z4" id="YGG-l9-3TK"/>
<outlet property="primaryHeaderPopUpButton" destination="5Bt-cy-Umw" id="QNX-kM-tiv"/>
<outlet property="secondaryFooterAlignmentControl" destination="Ili-wb-NLt" id="fY5-sB-NZM"/>
<outlet property="secondaryFooterPopUpButton" destination="nPF-cF-nDP" id="lQL-DV-jUw"/>
<outlet property="secondaryHeaderAlignmentControl" destination="kOZ-e4-wvP" id="7eX-8V-WqM"/>
<outlet property="secondaryHeaderPopUpButton" destination="8BQ-TU-mOj" id="Ssi-Nc-spn"/>
</connections>
</viewController>
Expand Down
32 changes: 18 additions & 14 deletions CotEditor/Base.lproj/PrintPanelAccessory.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="22146" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="bU7-R8-ocO">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="22152" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="bU7-R8-ocO">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22146"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22152"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -135,9 +135,9 @@
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="wZK-fo-Sky">
<font key="font" metaFont="system"/>
<segments>
<segment toolTip="Align Left" image="arrow.backward.to.line" catalog="system" width="22"/>
<segment toolTip="Center" image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment toolTip="Align Right" image="arrow.forward.to.line" catalog="system" width="22" tag="2">
<segment image="arrow.backward.to.line" catalog="system" width="22"/>
<segment image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment image="arrow.forward.to.line" catalog="system" width="22" tag="2">
<nil key="label"/>
</segment>
</segments>
Expand All @@ -161,9 +161,9 @@
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="phR-yp-SWP">
<font key="font" metaFont="system"/>
<segments>
<segment toolTip="Align Left" image="arrow.backward.to.line" catalog="system" width="22"/>
<segment toolTip="Center" image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment toolTip="Align Right" image="arrow.forward.to.line" catalog="system" width="22" tag="2">
<segment image="arrow.backward.to.line" catalog="system" width="22"/>
<segment image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment image="arrow.forward.to.line" catalog="system" width="22" tag="2">
<nil key="label"/>
</segment>
</segments>
Expand Down Expand Up @@ -199,9 +199,9 @@
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="Qh8-SW-Qcm">
<font key="font" metaFont="system"/>
<segments>
<segment toolTip="Align Left" image="arrow.backward.to.line" catalog="system" width="22"/>
<segment toolTip="Center" image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment toolTip="Align Right" image="arrow.forward.to.line" catalog="system" width="22" tag="2">
<segment image="arrow.backward.to.line" catalog="system" width="22"/>
<segment image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment image="arrow.forward.to.line" catalog="system" width="22" tag="2">
<nil key="label"/>
</segment>
</segments>
Expand Down Expand Up @@ -249,9 +249,9 @@
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="2gN-eY-bmu">
<font key="font" metaFont="system"/>
<segments>
<segment toolTip="Align Left" image="arrow.backward.to.line" catalog="system" width="22"/>
<segment toolTip="Center" image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment toolTip="Align Right" image="arrow.forward.to.line" catalog="system" width="22" tag="2">
<segment image="arrow.backward.to.line" catalog="system" width="22"/>
<segment image="arrow.right.and.line.vertical.and.arrow.left" catalog="system" width="24" selected="YES" tag="1"/>
<segment image="arrow.forward.to.line" catalog="system" width="22" tag="2">
<nil key="label"/>
</segment>
</segments>
Expand Down Expand Up @@ -409,9 +409,13 @@
</view>
<connections>
<outlet property="colorPopUpButton" destination="bRC-3n-rin" id="O2m-OW-cSE"/>
<outlet property="primaryFooterAlignmentControl" destination="qqp-Os-uMO" id="omG-Pa-ez3"/>
<outlet property="primaryFooterPopUpButton" destination="JEM-Eg-bfM" id="kMp-RR-37R"/>
<outlet property="primaryHeaderAlignmentControl" destination="Y6C-KD-Qlx" id="ONp-r7-x6L"/>
<outlet property="primaryHeaderPopUpButton" destination="f1I-iq-7Ha" id="Td8-ON-0Jk"/>
<outlet property="secondaryFooterAlignmentControl" destination="t3D-7C-ObH" id="26D-it-QSf"/>
<outlet property="secondaryFooterPopUpButton" destination="BMN-9W-V2O" id="OAn-UN-6UG"/>
<outlet property="secondaryHeaderAlignmentControl" destination="zau-Af-OBf" id="6pC-2g-4XK"/>
<outlet property="secondaryHeaderPopUpButton" destination="lW8-WA-sUW" id="6RF-ye-0xv"/>
</connections>
</viewController>
Expand Down
22 changes: 21 additions & 1 deletion CotEditor/Sources/DefaultOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ enum AppearanceMode: Int {
}


@objc enum AlignmentType: Int, DefaultInitializable {
@objc enum AlignmentType: Int, CaseIterable, DefaultInitializable {

static let defaultValue: Self = .right

Expand All @@ -119,4 +119,24 @@ enum AppearanceMode: Int {
case .right: String(localized: "Right")
}
}


var help: String {

switch self {
case .left: String(localized: "Align Left")
case .center: String(localized: "Center")
case .right: String(localized: "Align Right")
}
}


var symbolName: String {

switch self {
case .left: "arrow.backward.to.line"
case .center: "arrow.right.and.line.vertical.and.arrow.left"
case .right: "arrow.forward.to.line"
}
}
}
17 changes: 15 additions & 2 deletions CotEditor/Sources/PrintInfoType+UI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// CotEditor
// https://coteditor.com
//
// Created by imanishi on 2023/08/04.
// Created by 1024jp on 2023-08-04.
//
// ---------------------------------------------------------------------------
//
// © 2023 CotEditor Project
// © 2023 1024jp
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,3 +42,16 @@ extension PrintInfoType {
return item
}
}


extension AlignmentType {

static func setup(segmentedControl: NSSegmentedControl) {

for type in self.allCases {
segmentedControl.setToolTip(type.help, forSegment: type.rawValue)
segmentedControl.setTag(type.rawValue, forSegment: type.rawValue)
segmentedControl.setImage(NSImage(systemSymbolName: type.symbolName, accessibilityDescription: type.help), forSegment: type.rawValue)
}
}
}
10 changes: 10 additions & 0 deletions CotEditor/Sources/PrintPaneController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ final class PrintPaneController: NSViewController {
@IBOutlet private weak var primaryFooterPopUpButton: NSPopUpButton?
@IBOutlet private weak var secondaryFooterPopUpButton: NSPopUpButton?

@IBOutlet private weak var primaryHeaderAlignmentControl: NSSegmentedControl?
@IBOutlet private weak var secondaryHeaderAlignmentControl: NSSegmentedControl?
@IBOutlet private weak var primaryFooterAlignmentControl: NSSegmentedControl?
@IBOutlet private weak var secondaryFooterAlignmentControl: NSSegmentedControl?



// MARK: -
Expand All @@ -54,6 +59,11 @@ final class PrintPaneController: NSViewController {
contentKey: .primaryFooterContent, enablingKey: .printFooter)
self.setup(popUpButton: self.secondaryFooterPopUpButton!,
contentKey: .secondaryFooterContent, enablingKey: .printFooter)

AlignmentType.setup(segmentedControl: self.primaryHeaderAlignmentControl!)
AlignmentType.setup(segmentedControl: self.secondaryHeaderAlignmentControl!)
AlignmentType.setup(segmentedControl: self.primaryFooterAlignmentControl!)
AlignmentType.setup(segmentedControl: self.secondaryFooterAlignmentControl!)
}

override func viewWillAppear() {
Expand Down
10 changes: 10 additions & 0 deletions CotEditor/Sources/PrintPanelAccessoryController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ final class PrintPanelAccessoryController: NSViewController, NSPrintPanelAccesso
@IBOutlet private weak var primaryFooterPopUpButton: NSPopUpButton?
@IBOutlet private weak var secondaryFooterPopUpButton: NSPopUpButton?

@IBOutlet private weak var primaryHeaderAlignmentControl: NSSegmentedControl?
@IBOutlet private weak var secondaryHeaderAlignmentControl: NSSegmentedControl?
@IBOutlet private weak var primaryFooterAlignmentControl: NSSegmentedControl?
@IBOutlet private weak var secondaryFooterAlignmentControl: NSSegmentedControl?



// MARK: -
Expand All @@ -84,6 +89,11 @@ final class PrintPanelAccessoryController: NSViewController, NSPrintPanelAccesso
self.setup(popUpButton: self.secondaryHeaderPopUpButton!, contentKey: #keyPath(secondaryHeaderContent), enablingKey: #keyPath(printsHeader))
self.setup(popUpButton: self.primaryFooterPopUpButton!, contentKey: #keyPath(primaryFooterContent), enablingKey: #keyPath(printsFooter))
self.setup(popUpButton: self.secondaryFooterPopUpButton!, contentKey: #keyPath(secondaryFooterContent), enablingKey: #keyPath(printsFooter))

AlignmentType.setup(segmentedControl: self.primaryHeaderAlignmentControl!)
AlignmentType.setup(segmentedControl: self.secondaryHeaderAlignmentControl!)
AlignmentType.setup(segmentedControl: self.primaryFooterAlignmentControl!)
AlignmentType.setup(segmentedControl: self.secondaryFooterAlignmentControl!)
}


Expand Down
5 changes: 5 additions & 0 deletions CotEditor/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@


/* MARK: PrintAccessoryViewController */
// Segmented control tooltips
"Align Left" = "Linksbündig ausrichten";
"Center" = "Zentrieren";
"Align Right" = "Rechtsbündig ausrichten";

// Summary item names
"Font Size" = "Schriftgröße";
"Color" = "Farbe";
Expand Down
Loading

0 comments on commit 9ad010e

Please sign in to comment.