I use the ace editor with the vim keybindings on my site. Whenever someone goes into normal mode and types a command, it shows up in a dialog at the bottom. I defined a function like so:
ace.config.loadModule("ace/keyboard/vim", m => {
m.CodeMirror.Vim.defineEx("write", "w", () => submitForm())
})
The neat thing is, whenever that function errors, it shows the error in another dialog. My question is, is this feature exposed to users? Can I use that dialog to show messages like the editor does when the function errors? Here's a screenshot to show an example:
Typing a command -
Error pops up (another dialog in front of the one that I use to type the command) -
there is no documented api for this, but judging by
https://github.com/ajaxorg/ace/blob/v1.4.9/lib/ace/keyboard/vim.js#L4983, it should be possible to use the following
editor.state.cm.openNotification(domNodeOrHtmlString, {bottom: true, duration: 5000})
to create the dom node you can use the buildDom function from ace.
var domNode = ace.require("ace/lib/dom").buildDom(["span", {style: "color:red"}, "xxxxx"])
Related
I have started using the imgui system for visualizing "whatever". I am in my first few hours, and am running up against what seem to be common snags.
However, although I can see some pretty good support for the C++ versions of ImGui (which I'll transition to eventually), the python imgui content is mostly obscured.
What I am looking for is the solution to the following problem:
while not glfw.window_should_close(window):
...
imgui.new_frame()
imgui.begin("foo-window", closable=True)
imgui.end()
Everything works fine. However, the window doesn't close. I understand that the window doesn't close because it is always created every loop.
What I am looking for is:
How do I detect and identify that the particular window has been closed, and block it from being re-generated?
I'm not at all familiar with the imGui for Python, but if it at all follows the similar pattern as in imGui for c++, then you need to follow this pattern:
static bool show_welcome_popup = true;
if(show_welcome_popup)
{
showWelcomePopup(&show_welcome_popup);
}
void showWelcomePopup(bool* p_open)
{
//The window gets created here. Passing the bool to ImGui::Begin causes the "x" button to show in the top right of the window. Pressing the "x" button toggles the bool passed to it as "true" or "false"
//If the window cannot get created, it will call ImGui::End
if(!ImGui::Begin("Welcome", p_open))
{
ImGui::End();
}
else
{
ImGui::Text("Welcome");
ImGui::End();
}
}
JerryWebOS's answer is basically correct, but to add to that here's the python version. Note that the documentation for pyimgui is a good source to find answers to questions like this one.
https://pyimgui.readthedocs.io/en/latest/reference/imgui.core.html?highlight=begin#imgui.core.begin
imgui.begin() returns a tuple of two bools: (expanded, opened).
You can use this to detect when the user closes the window, and skip rendering the window in the next frames accordingly:
window_is_open = True
while not glfw.window_should_close(window):
...
imgui.new_frame()
if window_is_open:
_, window_is_open = imgui.begin("foo-window", closable=True)
...
imgui.end()
I'm trying to add a button to the current record with the Client Script button definition on a script record, but for some reason it's not finding my function. I'm returning my function tryThisand there is a button on the page which I created on the script record with the function tryThis defined in the appropriate field, but the code doesn't run. Here's my script:
define (['N/currentRecord','N/search','N/record'] ,
function(currentRecord,search,record) {
function tryThis(context){
log.debug({
title: 'try this',
details: 'try this'
});
}
function pageInit(context) {
}
return {
pageInit: pageInit,
tryThis: tryThis
};
});
Nothing happens :(
Yes, the script is deployed.
How can I use this button on a client script??
This doesn't exactly answer your question directly, but I hope it may help. I tested this, and there appears to be nothing wrong with the way you've set it up - the only thing that seems to be not working is the log module, which I've come across before in client scripts.
Try running your function using a console.log() or alert() instead (both work for me).
Hopefully someone with more detailed knowledge of the N/log module's design and behavior will chip in, as the documentation seems to indicate that this should work.
At the bottom of your Client Script record in Edit mode you will find where you can easily set the button and function to call.
firstly let my say that the mdc documentation is difficult for non-pros like me.
I'm using Elixir Phoenix and Brunch.
I import and everything is fine.
import {MDCTab, MDCTabFoundation} from '#material/tabs'; import
{MDCTabBar, MDCTabBarFoundation} from '#material/tabs'; import
{MDCTabBarScroller, MDCTabBarScrollerFoundation} from
'#material/tabs';
I manually instantiate the tab bar in a separate function that I export
export var Tabbable = {
run: function(MDCTabBar, el){
var myDynamicTabBar = window.myDynamicTabBar = new MDCTabBar(document.querySelector('#' + el));
Which is following the documentation like this
const tabBar = new MDCTabBar(document.querySelector('#my-mdc-tab-bar'));
but is slightly different to the documentation's use of the tab bar in their code snippet
var dynamicTabBar = window.dynamicTabBar = new mdc.tabs.MDCTabBar(document.querySelector('#dynamic-tab-bar'));
But, whenever I try to use mdc I get a 'not defined' error. Therefore, I'm not using it :-)
Now, when the user clicks the tab bar I capture that like this:
myDynamicTabBar.listen('MDCTabBar:change', function ({detail: tabs}) {
var nthChildIndex = tabs.activeTabIndex;
updatePanel(nthChildIndex);
});
The subtle difference is that my myDynamicTabBar is MDCTabBar but the documentation's dynamicTabBar is mdc.tabs.MDCTabBar
My tab control works, but it throws an error only visible in the console:
Uncaught Error: Invalid tab component given as activeTab: Tab not
found within this component's tab list
which is likely because I'm not using mdc.tabs? The documentation notes the change event happens on the MDCTabBar.
Therefore, how do I get rid of this annoying error in the console?
And why can I not access the global mdc? I have tried this in my Brunch file
globals: { mdc: "#material"}
But no good.
I'm right behind you on this! I'm frustrated with the docs too :(
You answered your own question in this Elixir thread which is very informative.
I found the real solution in this thread https://github.com/hyperapp/hyperapp/issues/546
MDCTabBar automatically initiates its children. So initiating tabs will result in that error.
The fix is to just initiate MDCTabBar
Is there a way in nightwatch to check whether a popup window appears after each click event?
I have a problem that randomly an error message appear and I don't want to write for each click event the same callback function.
I have already tried out the after and afterEach commands in the Global.js but then the commands will only run after the whole test suite.
I also have tried it local within a test file, although it also does not cover all single click events, even though the official website writes "... while beforeEach and afterEach are ran before and after each testcase (test step)"?
Solution I'm looking for:
.waitForElementVisible('selector')
.click('selector')
.click('selector')
Solution I have come up with so far:
.waitForElementVisible('selector')
.click('selector', isPresent)
.click('selector', isPresent)
isPresent as a callback function, which does the checking and close the popup window if it appears.
Is there another way to write a function (with or without after and/or forEach), so that it will be called after each click event or after each command. Thus, I don't have to write the isPresent repetitive code?
You can insert something like this in your page object file:
var popupCommand = {
popupCheck:function(){
return this.waitForElementVisible('selector', 5000)
.click('selector', isPresent)
.click('selector', isPresent)
},
module.exports = {
commands:[popupCommand],
elements:{
firstElement: {selector: 'xpath',locateStrategy: 'xpath'},
secondElement: {selector: 'css'},
}
}
Where 'popupCommand' will be the name of your page object file, for example 'Popup'. And also you will have to insert your isPresent callback function here so you can use it.
I did my best to explain you as much as possible what and how to do that :)
you should yse .switchWindow() method.
Why don't you write your own custom command specific for that case, so that way you will avoid repetitive code?
I don't know when this started, but I think it happened after I did some refactoring using the IDE with renaming.
Anyway, if I attach the script through the form, they fire. However, my user event, nor client scripts fire though there is a deployment record. That deployment record uses the same script that works IF it is attached via the form custom code area.
What happened?
EDIT:
For Instance:
Trying to add a button to opportunity:
function userEventBeforeLoad(type, form, request){
var list = form.getSubList("item");
list.addButton('custpage_customconfigurebutton', 'Configure', 'clientStartConfigurator()');
}
Upload Script
Add to "Script"
Deploy:
It never fires when I "Create Opportunity"?
NONE of my user event scripts are firing
EDIT 2 (NEW SCREENS as requested
Following lines of code working for me
function userEventBeforeLoad(type, form, request) {
//nlapiLogExecution('error', 'type', type);
var list = form.getSubList("item");
list.addButton('custpage_customconfigurebutton', 'Configure',"alert('Hello World')");
}
I suspect you might have an error in your clientStartConfigurator(). To verify, you can also use the browser console on click of your button to see whether you're successfully returning from your respective function or not.
Hope this will help you.