Edit access modifier of everything in a NSView - swift

In my application I want to change the editable var at once for 3 nstextfields in a custom NSView. Is it possible to do that using only one line of code (turning something on and of in the NSView perhaps?) or do I have to change it for every object individually? Again all the nstextfields are 'grouped' in one NSView. Hiding the nsview is no option, because it will seem like the entire program is nearly empty.
I have (for example) 3 NSTextFields in a custom NSView and I want to change their edibility option for all of them at once (if that is possible). So that I don't have to do: 'textfield1.editable=false' three times

Use Cocoa Bindings:
Create a dynamic variable editable in the target class
dynamic var editable = true
In Interface Builder bind Editable of each text field to the target class , Model Key Path editable.
Now changing the value of the variable affects all text fields simultaneously.

Related

How to extend a widget to override some properties of it?

How do I override a widget in order to provide some custom modifications to one of its property.
For example: Let's say I want to create my own Text widget which will convert whole text to uppercase. I'll do something like:
class MyOwnText extends Text {
MyOwnText(String data) : super(data.toUpperCase());
}
But with this approach, I can't use other properties of Text in my own widget, style, for example. For that, I'll have to add style property in my class constructor like this:
MyOwnText(String data, {TextStyle style}) : super(data.toUpperCase(), style: style);
But Text has got around 12-13 properties, and just to override one, I need to define all of those properties and then their assertion. I'm sure I may not be doing something right. Can anyone please help?
Note: Neither I want to use extension methods nor some client side code. MyOwnText should be a Text.
I get what you wanted to achieve, but I do not recommend to do this.
Why?? - Because most of the class has private variable and they have their separate getter and setter which are expose to the outer front of the class.
Again, If you wanted to for design and func. then you should not extend the widget. Instead you can directly use those in your build method
Why?? - You can't inherit more than one class(Mixin is other way around here)
So ultimately you need to assign properties directly or you could use spread operator

Flutter - best approach to create TabledToggledButtons?

I would like my toggle buttons to be layout in a table, and not as a single row.
The number of toggle buttons is not static -
that is upon init I load a resource which contains a list of all the texts that should become the toggle buttons.
Looked at a number of approaches, each has its issues:
Create a list of ToggleButtons and a list of lists of bools to store the appropriate selected state as a data structure to divide the toggle buttons into a number of rows. The problem with this approach is in the implementation of the onPressed method - how to get a reference to the appropriate element in the list of lists of bools? Or in other words - how to get a reference to ToggleButtons object from within the onPressed method?
Use key property to pass the index of the current ToggleButtons. It is not intended for this purpose, so it is a bad practice, also again, there seems to be no straightforward way to access the key property from the onPressed method.
Extend the ToggleButtons class, and specifically override its build method. This is considered an anti-pattern in Flutter in general. Specifically In this approach, as we want all the functionality to remain the same, and change only the internal Row -> Table widget generation in the build method, it looks like we would have to duplicate all the code of this method, which is a bad idea as it might brake things as it changes in future versions of this widget
Create a table of checkbox / switch widgets as an alternative, which should work easily, but I want the look & feel of toggle buttons, not checkboxes or switches :)
I must be missing something simple!
After posting this I have a new idea :)
A table of FlatButtons! Will be probably possible to achieve similar UI to ToggleButtons. Will try it in a bit.
I would still love to hear other suggestions regarding ToggleButtons.
Try using SwitchListTile.
The entire list tile is interactive: tapping anywhere in the tile toggles the switch. Tapping and dragging the Switch also triggers the onChanged callback.
To ensure that onChanged correctly triggers, the state passed into value must be properly managed. This is typically done by invoking State.setState in onChanged to toggle the state value.
The value, onChanged, activeColor, activeThumbImage, and inactiveThumbImage properties of this widget are identical to the similarly-named properties on the Switch widget.
The title, subtitle, isThreeLine, and dense properties are like those of the same name on ListTile.
The selected property on this widget is similar to the ListTile.selected property, but the color used is that described by activeColor, if any, defaulting to the accent color of the current Theme. No effort is made to coordinate the selected state and the value state; to have the list tile appear selected when the switch is on, pass the same value to both.
The switch is shown on the right by default in left-to-right languages (i.e. in the ListTile.trailing slot) which can be changed using controlAffinity. The secondary widget is placed in the ListTile.leading slot.
To show the SwitchListTile as disabled, pass null as the onChanged callback.

Binding from tabbed view to SharedUserDefaultsController proxy makes view unusable

I need to create the GUI for setting my app preferences. Since I am not able to get multiple instances of the SharedUserDefaultsController in multiple storyboard scenes, I created a simple proxy for it. I'm trying to bind a text field content to a specific values of the SharedUserDefaultsController through the proxy which is represented in IB via an NSObject added to the scene that should contain the binding. For the binding I use self.defaults.values.default_key where default_key is a defined key in the StandardUserDefaults for my application.
When I try to show the view that contains the binding, though, it is not shown and the only displayed message in the console is
Missing placeholder for identifier UpstreamPlaceholder-37m-v1-XT6
What am I doing wrong? In the storyboard source there's no trace of that identifier. Here's the code of the SharedUserDefaultsControllerProxy class that I created:
import Cocoa
class SharedUserDefaultsControllerProxy: NSObject{
var defaults = NSUserDefaultsController.sharedUserDefaultsController()
override init() {
super.init()
}
}

GWT Editable Grid : How to replace cell widgets dynamically?

I have created editable grid in which I am adding all the cell widgets. Now I want to check for some condition and replace a cell or column with another cell widget. For example if I have defined a column of EditTextCell, based on a boolean condition I have to change that column to have selectioncells(combo box). How to achieve this?
There are three ways to do that:
Use a CompositeCell with an EditTextCell and a SelectionCell and override the render method of the CompositeCell to render either the EditTextCell or the SelectionCell based on a boolean flag that you store in your DTOthat is bound to the Cell.
Create a custom cell extending AbstractEditableCell for example (see this tutorial) and implement the functionality yourself. You can check out the code for SelectionCell and EditTextCell and copy most of it. In the render method you have to either display a dropdownlist or just a text based on the boolean flag.
Extend either EditTextCell or SelectionCell and implement the missing functionality. The advantage is that you can probably re-use some of the render methods and you don't have to write the complete render code yourself.

Read-only Properties view for Eclipse editor

I am creating an editor that has a tree view in a text Editor. I have a properties view attached to it so that on selection of each tree item, the properties of the item are displayed. For this each tree item is a class that implements IPropertySource. So the property values are obtained by overriding the methods (like getPropertyDescriptors, getPropertyValue, setPropertyValue and so on) of the IPropertySource class.
The property values are displayed correctly. However, I require the values in properties view to be read-only. Currently, the names are non-editable. But on selecting one of the rows of the property view, the value of that property is editable. How do I make all values of properties of the properties view read-only (non-editable)?
Thanks!
If you are using the standard property sheet page from Eclipse, it depends on the IPropertyDescriptor implementation returned by IPropertySource.getPropertyDescriptors whether and how your property is editable in the view.
If you have a look at the JavaDoc of IPropertyDescriptor, you can see the following:
Clients may implement this interface to provide specialized property
descriptors; however, there are standard implementations declared in this
package that take care of the most common cases:
* PropertyDescriptor - read-only property
* TextPropertyDescriptor - edits with a TextCellEditor
* CheckboxPropertyDescriptor - edits with a CheckboxCellEditor
* ComboBoxPropertyDescriptor - edits with a ComboBoxCellEditor
* ColorPropertyDescriptor - edits with a ColorCellEditor
So for your case returning the PropertyDescriptor should do the trick.