How to change the selection color of a sidebar? - applescript-objc

Is there any way to change the selection color of a sidebar item?
For example the default color of macOS 10.14.x dark theme is blue, would it be possible to change this color?
I took a look here: Cocoa osx NSTableview change row highlight color
but I had difficulty translating to Applescript, thanks in advance.

Without a sample or MCVE project it is going to be tricky providing a drop-in solution. The topics and answers you linked to are overriding the NSTableView or NSTableRowView classes, so I can give you a generic solution for that. Subclassing in AppleScriptObjC can be a bit of a pain, depending on what you need to reference, but is fairly straightforward. Essentially you are putting a custom class in between the regular class and your application, where you can intercept the various standard method calls.
For a cell-based table view example, add a new empty file to your project by using the File > New > File... menu item. The name of the _file _isn't important (e.g. TableViewHighlight.applescript or whatever), the name of the script is what will be used by Xcode. Here I am using MyTableView for the class name and referencing a tableView outlet property from the AppDelegate:
script MyTableView -- the name of your custom class
property parent : class "NSTableView" -- the parent class to override
property tableView : a reference to current application's NSApp's delegate's tableView
property highlightColor : a reference to current application's NSColor's greenColor -- whatever
# set the row highlight color
on drawRow:row clipRect:clipRect
if tableView's selectedRowIndexes's containsIndex:row then -- filter as desired
highlightColor's setFill()
current application's NSRectFill(tableView's rectOfRow:row)
end if
continue drawRow:row clipRect:clipRect -- super
end drawRow:clipRect:
# set the highlight color of stuff behind the row (grid lines, etc)
on drawBackgroundInClipRect:clipRect
highlightColor's setFill()
current application's NSRectFill(clipRect)
continue drawBackgroundInClipRect:clipRect -- super
end drawBackgroundInClipRect:
end script
In the Interface Editor, use the Identity Inspector to set the class of your table view to the MyTableView class. Finally, in your table view setup set its highlighting to none, since it will be done by your subclass (again, assuming a tableView outlet is connected to the table view):
tableView's setSelectionHighlightStyle: current application's NSTableViewSelectionHighlightStyleNone
For a view-based table view example, the process is similar, but NSTableRowView is the one to subclass. Here the name of the script/class I am using will be MyTableRowView:
script MyTableRowView -- the name of your custom class
property parent : class "NSTableRowView" -- the parent class to override
property highlightColor : a reference to current application's NSColor's redColor -- whatever
# draw the selected row
on drawSelectionInRect:dirtyRect
continue drawSelectionInRect:dirtyRect
highlightColor's setFill()
current application's NSRectFill(dirtyRect)
end drawSelectionInRect:
end script
In the Interface Editor, set the table view's highlight to regular using the Attributes Inspector, and add a tableView:rowViewForRow: method to the table view's delegate:
on tableView:tableView rowViewForRow:row
set rowIdentifier to "MyTableRow"
set myRowView to tableView's makeViewWithIdentifier:rowIdentifier owner:me
if myRowView is missing value then
set myRowView to current application's MyTableRowView's alloc's initWithFrame:current application's NSZeroRect
myRowView's setIdentifier:rowIdentifier
end if
return myRowView
end tableView:rowViewForRow:
There are other options, of course, but that should get you started, and help with translating some of those Objective-C answers/examples.

Related

Ember JS Change the color and title of a button component when a date is picked from date-picker

I have a web app in which there are two components - date picker and button.
When I select a date from date-picker, the button's title and color should change.
This is my hbs code where two components are given:
{{bootstrap-datepicker value=expiresAt todayHighlight=true todayBtn=true startDate=startDate changeDate="changeDateAction" autoclose=true}}
{{button-custom title="Previous Date" startDate=startDate status=1 id="button1"}}
The button-custom is created by me.
When I select a date, the function in datepicker named changeDateAction() will be called. I have a function in button component's controller, named changeValues() which when called will do my task.
How can I call changeValues() (which is in button-custom.js) from changeDateAction() which is in another file?
Please be as simple as possible as I'm beginner in Ember JS. Thanks in advance.
It seems like you'd like to inform a component (button-custom) about a change in a sibling component (bootstrap-datepicker). You've already set up an action handler (changeDateAction) that informs the parent component/controller about the change. In order to propagate that change to button-custom, I'd suggest to just pass the effect you'd like to achieve down to it:
{{bootstrap-datepicker changeDate="changeDateAction" (...)}}
{{button-custom title=title color=color (...)}}
Like this, you can control the appearance of the button from the outside by modifying title and color. Like that, the logic is moved to the parent component/controller, and the button component becomes a "dumb" presentational component.
The basic concept behind this is called "Data down, Actions up" (DDAU), and i'd highly recommend to read up on it (for example here if you're learning Ember!

How to setUp UiTableViewController below the battery bar

newBie here. I have added an UItableViewController into storyBoard. I use this as a setting page.
HomeVC ----> Setting VC
In code : I use the below code to bring the tableView below the battery Bar:
self.tableView.contentInset = UIEdgeInsets(top: 20,left: 0,bottom: 0,right: 0)
Problem:
How to move the TableView down below the battery bar so that I can add a button above the table in StoryBoard
Please help.
For this you should use a normal view controller and drag a table on the view controller this way you can make the table size whatever you like. This will also allow you to place buttons wherever you like.
Don't forget to assign the TableViewDataSource and TableViewDelegate to your view controller.
Good luck!
After doing some search on UiTableViewController, to use it as setting page I have to set static cell to it. This UiTableViewController will occupy the entire view.
To set the tableView below the battery icon,
use:self.tableView.contentInset = UIEdgeInsets(top: 20,left: 0,bottom: 0,right: 0)
However, No need to do so. In the first TableViewSection, you can create a few tableView cell, just leave the first cell blank which acts as a margin below the battery bar.

QT QIcon properties for custom widget in designer

I have been working for a little while now on creating a QT custom designer widget for GUI menus. The idea being that you simply drag it into the designer, select the number of frames you'd like, how many buttons per frame, etc. and it generates and sizes everything for you.
The way the widget is structured there are properties to configure each button for the frame you are in. For example, you would use the button0Text field to enter text under Button0 while editing in frame 0, then use it again to edit Button0 which is in frame 1. Both buttons would retain the individual changes for each frame.
The Problem
Normally when I switch frames all of my properties are updated to reflect the status of the frame. The exception being QIcon. The correct icon is retained in the actual graphical representation and builds correctly, however the file path in the property list is always of the last edited for that property. I think this will be extremely confusing to an end user and I have found no way to fix it. So for example, if I set text and icons in frame 0 then switch to frame 1 the text in the property list will update to reflect the state of frame 1 but the icon path names will still show my last edit in frame 0 and not the actual icon in frame 1.
I have tried things as simple as:
setProperty("button0Icon", getButton0Icon());
That code works on properties like text, but not for the icon. I try executing it immediately after changing frames.
I have also tried:
#ifndef Q_WS_QWS
QDesignerFormWindowInterface *form = QDesignerFormWindowInterface::findFormWindow(this);
if(form){
QDesignerFormEditorInterface *editor = form->core();
QExtensionManager *manager = editor->extensionManager();
QDesignerPropertySheetExtension *sheet;
sheet = qt_extension<QDesignerPropertySheetExtension*>(manager, this);
int propertyIndex = sheet->indexOf("button0Icon");
sheet->setChanged(propertyIndex, true);
sheet->setProperty(propertyIndex, getButton0Icon());
}
#endif
And:
int propertyIndex = this->metaObject()->indexOfProperty("button0Icon");
QMetaProperty property = this->metaObject()->property(propertyIndex);
property.write(this, QIcon());
Nothing seems to update the property list in the designer.
I have all properties, including all QIcon properties properly declared in the header file with Q_PROPERTY and assigned getter and setter functions.
To be clear, the icon values are indeed retained through each frame when compiled. So it is functioning, just unclear for most users.
If anyone has any experience with this or any ideas please let me know. Thanks.
I have discovered that QIcon does not store file names/paths. The file names are only used for the creation of the QIcon. I think this is most likely the reason I do not get any feedback in the Property Browser for my QIcon properties.
Instead I have chosen to hide this property in the designer and add three new ones. Three QUrl properties, each of which is used to supply an image file. I use three because I want to construct a QIcon that contains Modes/States for normal, disabled, and pressed operations.
I take each of these QUrls and save them in QStringLists behind the scenes so their values are stored. I then construct my QIcon using the file names provided from the QUrls.
I would much prefer to be using the native QIcon in the designer for this, any thoughts or feedback are appreciated.

All checkboxes are get selected in List instead of only clicked one in codename one

I have created my own Renderer class and I am doing something like
MyClass extends Container implements ListCellRenderer
I added some TextAreas Labels with CheckBox into this class..
and setting this as a renderer to "List"
So my code for initListModel is:
#Override
protected boolean initListModelReceiptLineList(List cmp) {
cmp.setRenderer(new RendererPOReceiptList(receiptLineList));
//valid data in receiptLineList
cmp.setModel(new DefaultListModel(receiptLineList));
return true;
}
Everything is running fine, even data are also set in label & textareas..
running good in device and in emulator..
But,
The issue is, when I select 1st checkbox, all checkboxes are selected..
Anyone have any idea please,
Thanks,
Akash
The renderer is stateless hence you shouldn't check the checkbox, you check the model. Your renderer needs to select the value of the checkbox with every renderer.
This all might be complex stuff which is why I wouldn't recommend building your own and instead using a MultiList (or just adding checkboxes to a container).

Change C++ model with QML

I want to extend the example called "Object ListModel Example" from Qt documentation
(you can get it on http://qt-project.org/doc/qt-4.8/declarative-modelviews-objectlistmodel.html).
I am trying to add a simple GUI functionality: a menu item that changes the content
(i.e. name) of the first data item in the model. Something like this:
MenuItem {
text: "Item 123"
onClicked: {
myModel.setProperty(0,"name","Item 123") //this gives me error
}
}
I am able to create a menu in QML but I cannot find the correct way to make changes in the model.
Btw, what is a difference between setContextProperty and qmlRegisterType (only the first one is used in this example but many other examples include the second one).
That kind of model is really not suitable for modification. There is no way for the view to be notified of changes. A better option is to use a QAbstractItemModel: http://qt-project.org/doc/qt-4.8/declarative-modelviews-abstractitemmodel.html
A simpler way to use a QAbstractItemModel is via QStandardItemModel: http://qt-project.org/doc/qt-4.8/qstandarditemmodel.html
setContextProperty() adds a single named property to the context. qmlRegisterType() registers a QObject-derived type with the QML engine, allowing it to instantiate that type. For example, the QDeclarativeItem type is registered with the engine as "Item", which is how the engine knows what to create when Item {} appears in QML code.