Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Xcode Extension: Possible to enable / disable Rules to be apply #211

Merged

Conversation

VinceBurn
Copy link
Contributor

Add a UI to allow user to select the rules they want to apply in Xcode
Configure a group domain for NSUserDefaults sharing between application & extension
Apply the user selected rules to both Xcode extension method

Still TODO:

  • Add test to new method in Rules.swift
  • Add test for RulesStore.swift

@VinceBurn VinceBurn changed the title Xcode Extension: Possible to enable / disable Rules to be apply WIP: Xcode Extension: Possible to enable / disable Rules to be apply Jan 29, 2018
if #available(OSX 10.13, *) {
tableView.usesAutomaticRowHeights = true
} else {
tableView.rowHeight = 30
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


class RuleViewModel {
let name: String
var isEnable: Bool {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change this to isEnabled - it's more grammatical.


init(_ store: UserDefaults? = UserDefaults(suiteName: UserDefaults.groupDomain)) {
guard let store = store else {
fatalError("The UserDefaults Store is invalid")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under what circumstances would this fail? It doesn't seem right to use fatalError if it's not a programmer error.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that UserDefaults.init is a failable constructor, but it's a bit misleading for the RulesStore init to take an optional store since it's not actually optional.

Maybe something like this would be better?

static var defaultSuite: UserDefaults = {
    guard let defaults = UserDefaults(suiteName: UserDefaults.groupDomain) else {
        fatalError("The UserDefaults Store is invalid")
    }
    return defaults
}()

init(_ store: UserDefaults = RulesStore.defaultSuite) { ... }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good, I was also not happy with that

Copy link
Owner

@nicklockwood nicklockwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me. I'll let @tonyarnold cast an eye over it if he has time, as he knows more about Mac app development idioms.

@nicklockwood
Copy link
Owner

FYI, the test failures are nothing to worry about - it's just because I was lazy and hard-coded the file counts. Just update the counts to fix them.

Copy link
Contributor

@tonyarnold tonyarnold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is good and works as advertised 👍 - thank you!

The UI could be more consistently/standardly spaced, but we can fix that once the functionality is merged.

I've made a few comments here, the rest are inline in the code:

  • I'm not a fan of making NSUserInterfaceItemIdentifier expressible by string - AppKit lets us use properly-typed identifiers and names. I'd suggest using something to generate extensions on NSUserInterfaceItemIdentifier to vend the various identifiers, or doing so by hand. I have a project that will scan an AppKit project and generate these for you - you just need to ensure that you've set reasonable IDs within the storyboards/XIBs: https://github.com/tonyarnold/resourceror
  • I don't think the separate XIB is necessary for the table view cell - you can set this up within the storyboard.
  • Source formatting is a bit off in some of these classes. It seems like you're using tabs and spaces - I believe the project uses spaces.


required init?(coder: NSCoder) {
super.init(coder: coder)
title = "Rules"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary - set the title of the view controller from within the Storyboard.

<!--Rules View Controller-->
<scene sceneID="v8f-un-92m">
<objects>
<viewController storyboardIdentifier="RulesViewController_sid" id="9ZR-Qg-hHT" customClass="RulesViewController" customModule="SwiftFormat_for_Xcode" customModuleProvider="target" sceneMemberID="viewController">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you set the view controller's "Presentation" to "Single" within the storyboard - we only want one of these per-app.


@IBOutlet var tableView: NSTableView! {
didSet {
tableView.dataSource = self
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These all seem like items that could be wired up or configured from within the Storyboard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it could be done in the Storyboard, but I don't think I can do the register nib in the storyboard. And I don't like to have those config split between storyboard and code. I can move it if you insist.

@VinceBurn
Copy link
Contributor Author

Hi @tonyarnold

I don't think the separate XIB is necessary for the table view cell - you can set this up within the storyboard.

I'm not sure how you do the equivalent of the table view register nib method from the storyboard. I'm not use to AppKit.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 83.732% when pulling 641246c on VinceBurn:feature/user-selected-rules into 16d7432 on nicklockwood:master.

@tonyarnold
Copy link
Contributor

I'm happy with what's here - thank you for taking my feedback on board @VinceBurn.

There are a few items I'd like to change a bit, but I reckon we merge as-is.

@nicklockwood if you can hold off on releasing an update with this in it until I've had a chance to submit a follow-up PR, I have some time to look at this today/tomorrow.

@nicklockwood nicklockwood merged commit 889482d into nicklockwood:master Feb 1, 2018
@nicklockwood
Copy link
Owner

@VinceBurn awesome work, thanks for doing this 👍

@VinceBurn VinceBurn deleted the feature/user-selected-rules branch February 1, 2018 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants