431 Commits

Author SHA1 Message Date
Allan Odgaard
fb165589c3 Change layout constraints to allow superview with zero width
I occasionally see log entries saying that the constraints cannot be resolved, and it appears to be because the superview has a width of zero.
2020-05-14 15:43:24 +07:00
Allan Odgaard
e62db9386e Call NSMenu’s numberOfItems instead of itemArray.count 2020-05-14 09:52:38 +07:00
Allan Odgaard
ad1cc8abd8 Deliver all NSUserDefaultsDidChangeNotification in main queue
This is easier than ensuring that we do not update user defaults from a background thread.
2020-05-14 09:52:38 +07:00
Allan Odgaard
8e6791324a Let app delegate handle workaround for “Move to Active Space” behavior
I don’t think the default behavior ever makes sense, so we are applying the change to all windows instead of handling it on a one-by-one basis.
2020-05-13 18:50:02 +07:00
Allan Odgaard
0caa4eb12a Improve the folder pop-up submenu for Find in Folder
The submenu now show the immediate children in the first submenu, with parents below these items, although without adding submenus to the parents.

Also show ⌘↑ for the first parent, to improve discoverability of this key equivalent.
2020-05-13 18:50:02 +07:00
Allan Odgaard
01bf868832 Go back to visual formal language for laying out the Find dialog
Now that we use OakTransitionViewController for toggling the results view, using a stack view provides no real benefits, and are in some ways a little bit more opaque, for example the hugging priority weirdness and what width constraints are setup by the view.
2020-05-10 20:07:31 +07:00
Allan Odgaard
e9c4ea57dd Move initialization of view controllers from helper method to init
These view controllers are used in other methods, so we were basically relying on the order of which methods were called, which is not good design.
2020-05-10 20:07:31 +07:00
Allan Odgaard
3d1f4c82df Only install event monitor when results outline view is visible 2020-05-10 20:07:31 +07:00
Allan Odgaard
bd7e306b91 Use OakTransitionViewController to show/hide find results 2020-05-10 20:07:31 +07:00
Allan Odgaard
53da62f33d Fix issue with ⌘F not bringing find dialog to active space
The problem is that we use ⌘F and ⇧⌘F as key equivalents both in the Edit → Find submenu and in the “where” pop-up button’s menu, but as they previously had different action methods, the system would only allow the key to trigger one of these items (and remove the key from the other, as part of menu validation).

Normally not an issue, but when the find dialog is in another space, it appears menu validation would not update the Find → Edit submenu items to get the key equivalents, even though these would be “first responders”.

By using same action method for both Find → Edit submenu items and the “where” pop-up menu items, we avoid the key equivalents being removed from any of the two menus.
2020-05-10 20:07:31 +07:00
Allan Odgaard
9bfae1aada Use FFSearchTarget instead of find_tags enumeration
This avoids the need to map between the two enumeration constants, although we handle some of the constants before passing them to the find singleton, so the code has not yet been updated to remove the redundant mappings.
2020-05-10 20:07:31 +07:00
Allan Odgaard
09ee4d49a7 Use MBMenuBuilder to construct “where” pop-up menu in Find dialog 2020-05-10 20:07:31 +07:00
Allan Odgaard
83874a965c Use NSLayoutPriorityDefaultHigh-1 as hugging priority for stack views
When set to NSLayoutPriorityDefaultHigh then it is able to compress text fields. The text field does set content compression resistance to NSLayoutPriorityDefaultHigh, but for reasons I do not understand, this is not enough to keep it from being compressed by the stack view.

The reason I do not understand this is that even with a high hugging priority, we should not make views smaller than their fittingSize, but it appears the stack view will do that.

Only one stack view actually contained a text field, and we already used a priority lower than NSLayoutPriorityDefaultHigh, so this commit does not change anything, but to play it safe, we should probably avoid NSLayoutPriorityDefaultHigh for stack views.
2020-05-10 20:07:30 +07:00
Allan Odgaard
66c3e67e5b Ensure empty string is used when find dialog text field is empty
The system will return ‘nil’ for empty text field, which was causing the replace preview in the find dialog to not show any replacements, and if doing actual replacements, 0xFFFF would be inserted for replacements.
2020-05-04 19:20:04 +07:00
Allan Odgaard
cb4c12681e Use NSNotificationName as type of all our notification names 2020-05-04 19:20:04 +07:00
Allan Odgaard
f0b48ba736 Fix a few double trailing semi-colons 2020-05-04 19:20:04 +07:00
Allan Odgaard
244da7a269 Find in Folder: Allow navigating Recent Places with ⌘[ / ⌘]
The pop-up menu will show shortcut keys next to the items that the keys will trigger, although we are re-purposing File Browser → Back / Forward for these actions, so it is worth considering moving them to the View menu.
2020-04-30 13:28:24 +07:00
Allan Odgaard
a3c3296276 Find in Folder: Only add to “Recent Places” when a search is executed
Also add “file browser items” to Recent Places when a single folder is selected.
2020-04-30 13:28:24 +07:00
Allan Odgaard
e541250309 Add object type information when using OakHistoryList 2020-04-30 13:28:24 +07:00
Allan Odgaard
8aef07575c Use NSByteCountFormatter instead of text::format_size 2020-04-30 13:28:24 +07:00
Allan Odgaard
187522b6c4 Add missing implementation of isVisible property 2020-04-29 08:02:02 +07:00
Allan Odgaard
81553fc565 Don’t keep local copy of find/replace string in Find singleton
Instead we access the FFTextFieldViewController’s stringValue directly.
2020-04-29 08:02:02 +07:00
Allan Odgaard
795876cba3 Make FFTextFieldViewController’s stringValue a public property 2020-04-29 08:02:02 +07:00
Allan Odgaard
8e4f595785 Avoid setting nil as cell’s string value 2020-04-29 08:02:02 +07:00
Allan Odgaard
2ee95e5eba Remove booleans to track if find/replace strings have been updated 2020-04-29 08:02:02 +07:00
Allan Odgaard
5f3fb0672e Move handling of NSPopover to FFTextFieldViewController 2020-04-29 08:02:02 +07:00
Allan Odgaard
395dea49ab Let FFTextFieldViewController bind to NSTextField and update size
Contrary to a previous finding, the NSTextField doesn’t always resize when the content changes, and controlTextDidChange: is only sent when the string is edited by the user (via the field editor), so we must use bindings to be notified about *all* changes.
2020-04-29 08:02:02 +07:00
Allan Odgaard
05f711d256 Change a few NSLayoutConstraint instances to instead use layout anchors 2020-04-29 08:02:02 +07:00
Allan Odgaard
56f872432d Merge Find singleton with FindWindowController
Currently find window is created during initialization, we should delay that to be when first requested (loadWindow).

Furthermore, some code might be moved out of the FindWindowController, for example more logic related to search results might be moved to the search results view controller.
2020-04-29 08:02:02 +07:00
Allan Odgaard
445765237c Status string property wrappers no longer maintain their own copy 2020-04-29 08:02:02 +07:00
Allan Odgaard
7a30a3ed53 Use layout anchors to set fixed width/height of various views 2020-04-29 08:02:02 +07:00
Allan Odgaard
3f3277f747 Change how we setup grid view 2020-04-29 08:02:02 +07:00
Allan Odgaard
5d60fe2d62 Move FFTextFieldViewController to its own file 2020-04-29 08:02:02 +07:00
Allan Odgaard
86681c36a0 Introduce FFTextFieldViewController
This encapsulates syntax highlight, history, and auto-resize behavior.

We currently do not call updateIntrinsicContentSizeToEncompassString: when changing the content, but it appears to be unnecessary. It might actually be that with auto-layout, there is no longer any need for repeatedly updating the intrinsic height of the control manually.

But leaving things (more or less) as-is for now.
2020-04-29 08:02:02 +07:00
Allan Odgaard
cf5bce8bf0 Remove outlineView property from FFResultsViewController 2020-04-29 08:02:02 +07:00
Allan Odgaard
9980e9afda Refactor FindWindowController: Remove a lot of properties
The rule of thumb is that we only want to use a property for things that are set more than once (so we may want KVO), or part of public API.
2020-04-29 08:02:02 +07:00
Allan Odgaard
0ab5b06417 Set nextKeyView property for FFResultsViewController’s view
This allows using the root view in a key view loop, rather than needing to know which subview is appropriate.
2020-04-29 08:02:02 +07:00
Allan Odgaard
2112a26116 Let our table cell view observe all outline views for looser coupling
The motivation is not having to know about the interface of the view controller that creates the instance.

It does have performance disadvantages in that collapsing or expanding items in *any* outline view will now trigger notification callbacks for our table header cell views.

In practice though expanding/collapsing is not a common action, and the chance of this being done, while the find window has so many results as to impact performance, is probably small (it’s only the header cells that register for this notification).

That said, it would be good to find a better solution.
2020-04-29 08:02:02 +07:00
Allan Odgaard
191a435382 Move FindWindowController to Find singleton implementation file
These two classes should be merged.
2020-04-29 08:02:02 +07:00
Allan Odgaard
b5008a9849 Manually set the canEditGlob and canReplaceInDocument properties
This is so that properties bound to these will update immediately (before window resize).
2020-04-29 08:02:02 +07:00
Allan Odgaard
0ba3c2da18 Update find window title and “where” pop-up before resizing window
Ideally we would also change the enabled state of the “matching” text field, but this is currently handled via bindings, so we cannot fix that without either delaying resizing until next event loop cycle, or by manually updating the canEditGlob property.
2020-04-29 08:02:02 +07:00
Allan Odgaard
5d8c131a1a Animate resize of find window (and switch to using NSStackView) 2020-04-29 08:02:02 +07:00
Allan Odgaard
e3c3d6ecd1 Use a NSStackView for action buttons in find window 2020-04-29 08:02:02 +07:00
Allan Odgaard
f4e16da198 Use NSGridView to layout most controls in the find window 2020-04-29 08:02:02 +07:00
Allan Odgaard
12de85b5c0 Use NSStackView for find results
The motivation here is simply to get a view that can resize down to zero height.
2020-04-29 08:02:02 +07:00
Allan Odgaard
e5bfaecdb5 Use NSStackView for find window’s status bar and move to view controller
The main advantage is that we can let the stack view handle showing and hiding of the stop button and progress indicator.

The height of the status bar (text field) is now fixed at 16 pt. The reason we have to fix it is that we are using a button for the status bar (so that the user can click toggle between showing number of files and number of bytes searched), but a button with an empty string reports a different fittingSize than one with a non-empty string.

Therefore without a fixed height, we need to ensure status bar never gets set to an empty string, which we did before, but I think it is nicer to simply fix the height of the status bar.

Also because the progress indicator and stop buttons might actually be slightly taller than the status bar used to be.
2020-04-29 08:02:02 +07:00
Allan Odgaard
78f7fb9c6f Observe the view frame instead of window frame, to learn about changes
The window frame may change before the view has bene laid out to the new window size.
2020-04-29 08:02:02 +07:00
Allan Odgaard
7321369b76 Instead of checking utf8::is_valid(str) we check if to_ns(str) fails
Since 2.0-rc.1 we have received 70 crash reports pointing to nil string being passed to the NSAttributedString initializer.

I’m almost inclined to think that NSString construction fails for other reasons than the data not being valid UTF-8, since both excerpt and replace string, are already passed as an NSString.

When to_ns fails we show a “Please file a bug report!” message on red background in the find window, since I would like to know why this situation arise.
2020-04-29 08:02:02 +07:00
Allan Odgaard
db2cbc3068 Accept std::string instead of NSString in attributed string builder
Since virtually all calls to ‘append’ wraps the std::string with ‘to_ns’, we might as well move the wrapping to the function, as this is not public API.
2020-04-29 08:02:02 +07:00
Allan Odgaard
b514114ec7 Access most system singletons using dot syntax
These are identified by having a prefix of shared, default, or standard in the class method.
2020-04-23 12:25:11 +07:00