I'm having trouble updating a text view in my AppleScript Xcode (12.5.1) project.
I have:
Bound my text view to my "msg" property, and
Selected "Continuously updates value" in the bindings inspector.
However, when I update the "msg" property the change is not displayed in my text view.
Although my msg property has been updated with the "initializing..." string (as evidenced by the alert message) my text view is not updating.
bindings inspector
connections inspector here
App running with "msg" property displayed in text view (indicating successful binding)
inside appInit function
myAppDelegate code:
property parent : class "NSObject"
property msg : "zig" -- the message
-- IBOutlets
property theWindow : missing value
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
activate
display alert msg -- "zig" property successfully displayed in text view. Binding is apparently set.
set msg to ("initializing…" as string) -- text view not updated.
appInit()
end applicationWillFinishLaunching_
on appInit()
activate
display alert msg -- "initializing"; msg property updated, just not being updated in text view...
end appInit```
Bindings to properties use key-value observing (KVO), which is a mechanism that allows objects to be notified of changes to properties of other objects. AppleScriptObjC properties are set up for this when bound via Xcode, but in order to use this mechanism when changing the property in your script, you need to use a setter to trigger the notification - otherwise the property itself will be changed, but the object will not be notified of the change.
Examples would be:
set my msg to "initializing…" -- using the `my` keyword
setMsg_("initializing…") -- also my setMsg:("initializing…") -- using the built-in setter method
Note that the property will be a Cocoa value, so it will need to be coerced to a string when using it (later in the appInit dialog, for example).
Related
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.
Problem: can't trigger Vue-Select3 item dropdown selection programmatically in unit-tests.
I have tried with both vue-test-utils and #testing-library/vue as well as triggering a click event programmatically in a browser to force list item selection. However, none of these worked. The only way I managed to trigger selection is by getting a VueSelect instance and emitting 'input' event. I also tried to trigger different events on dropdown container, etc.
// Failed
// testing-library
const dropdownItem = getAllByTestId('dropdown-item')
fireEvent.click(dropdownItem[0])
// test-utils
wrapper.find('[data-testid=dropdown-item]').trigger('click')
// In browser
document.querySelectorAll('.vs__dropdown-item')[0].click()
// Success
wrapper.find(VueSelect).vm.$emit('input', payload)
Current result: When a click event is triggered nothing happens.
Expected result: When a click event is triggered Vue-Select should select the item and emit 'input' event.
I found a way of selecting an option directly. You can use the select function of the VueSelect component, like that:
const wrapper = mount(YourComponent)
const vueSelect = wrapper.find(VueSelect)
vueSelect.vm.select(yourOptionToSelect)
That will work if you just want to select a specific option.
But yes, if you want to simulate the click on one of the options, that would not be helpful. And I know that this way of changing the state of a component is not the preferred way of doing this, but it is the only solution I've found.
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!
I am trying to show a popup message on the content editor on click of publish . I have my handler called in the "publish:begin"event.
public void PublishCatcherDialog(object sender, EventArgs args)
{
//Some custom code here including "id" declaration
ClientPipelineArgs args = new ClientPipelineArgs();
args.Parameters.Add("id", id);
Sitecore.Context.ClientPage.Start(this, "DialogProcessor", args);
}
However I see that in Sitecore 8 , Sitecore.Context.ClientPage.Start gives a null exception error , so does "SheerResponse".
Most blogs out there have the code for a button click trigger that gives the appropriate command context and Sitecore.Context . How to do in in this scenario (code triggered)?
If you suggest Speak , where would I declare the .js association to this pipeline? I see the sitecore dlls still use this above code to show modal dialogs , so it cannot be completely obselete...
I feel am missing a simple inheritance somewhere that would set the context .
I need to trigger the alert when I click on the "Publish" button on the publish wizard dialog. It looks like a "submit" action on publishform.aspx
Image here
Edit 1
Since you need to show a popup when the user click on the publish button, you will need to override the Sitecore Publish XML UI found in the path Website/sitecore/shell/Applications/Dialogs/publish.
Copy the Publish.xml and paste it in the Override folder. Path is Website\sitecore\shell\Override. Note that the folder may be empty. To keep the standard create the same directory structure. Example: Website\sitecore\shell\Override\Applications\Dialogs\publish
Now create a class that should inherite the Sitecore.Shell.Applications.Dialogs.Publish.PublishForm
Your code will be as follows:
using Sitecore.Shell.Applications.Dialogs.Publish;
public class PublishWizardOverride : PublishForm
{
protected override void OnNext(object sender, EventArgs formEventArgs)
{
// Your code to display your popup goes here
base.OnNext(sender, formEventArgs);
}
}
Then open the copied xml file from the Override folder and change the CodeBeside with your namespace and assembly
Note: You may required to check the page on which the user is so that the popup does not appear on all Next Button clicks.
Sitecore event handlers run in the background so they don't have access to the UI.
If you are trying to open a custom dialog before the publish wizard dialog, you will need to override the appropriate command. For publishing a single item, you would inherit Sitecore.Shell.Framework.Commands.PublishItem and replace the item:publish command in the config. For publishing the "site", you would inherit itecore.Shell.Framework.Commands.System.Publish and replace the system:publish command in the config. You would override the execute method of the command and run your code before calling base.Execute(context);.
If you want to do something similar for Experience Editor mode, you would add a processor to the client-side publish pipeline. You add a step in the core database under /sitecore/client/Applications/ExperienceEditor/Pipelines/Publish. You should be able to duplicate and tweak the OpenPublishDialog step which uses the javascript file at /sitecore/shell/client/Sitecore/ExperienceEditor/Pipelines/Publish/Publish.OpenPublishDialog.js.
In my GUI application, I have some labels in my mainwindow the visibility of the labels are controlled from checkboxes in a dialog which opens when a button (setting) is pressed. Now, it all works fine, i.e. if I open the settings dialog I can check or uncheck the checkboxes; consequently the labels are also set visible or invisible.
mysettingsdialog.cpp
void mysettingsdialog::onclick(bool checked) //by AJ kpi conf
{
if(myCheckBox->isChecked()==true)
{
emit setlabelvisible();
}
else
{
emit setlabelinvisible();
}
}
mainwindow.cpp
MySettingsDialog* myset=new MySettingsDialog(this);
connect(myset,SIGNAL(setlabelvisible()),this,SLOT(enable1()));
connect(myset,SIGNAL(setlabelinvisible()),this,SLOT(disable1()));
void MainWindow::enable1()
{
ui->label->setVisible(true);
qDebug()<<"VISIBLE label";
}
void MainWindow::disable1()
{
ui->label->setVisible(false);
qDebug()<<"INVISIBLE label";
}
Now the problem is, every time my application restarts it does not retain the previous state of the checkboxes. So I was thinking to save the state of the checkbox in a variable and writing it to a file, so whenever my application starts it will read the file and set the status of check box accordingly.
My question is, how can I store the "state" of checkbox in a variable and write it to file. And again use the same to set the state of checkbox ???
I mean reading / writing values from file for QLabels and QLineEdits is easy enough but I am baffled about how to do it with checkbox.
Create a container to store the pointer of each checkbox.
Create another container to store the "state" of each checkbox. For a binary check box, you can use isChecked() to query whether or not a checkbox is checked. Otherwise you can call checkState() to return the state as enum if you use a tri-state check box (see the edit).
When loading settings, assign the state to each check box accordingly.
You may use QSettings to manage the settings and save them as an ini file.
Edit
Just mention there is an option for a tri-state check box. From the document:
QCheckBox optionally provides a third state to indicate "no change".
This is useful whenever you need to give the user the option of
neither checking nor unchecking a checkbox. If you need this third
state, enable it with setTristate(), and use checkState() to query the
current toggle state.