How to fix function declaration formatting in PhpStorm (2020.1.2) if signature longer then defined row length? - phpstorm

For example I have function declaration like this:
public function someLongMethodWithLongParamName(int $longparamName): VeryLongReturnValueType {}
with row length limit that less than chars count of function signature.
If I type Ctrl + Alt + L PhpStorm will format this row, but in strange way:
public function someLongMethodWithLongParamName(int $longparamName
): VeryLongReturnValueType {
}
(PhpStorm left parameter in the line of method name). If I will add one more parameter, PhpStorm will format line correct:
public function someLongMethodWithLongParamName(
int $longparamName,
bool $flag
): VeryLongReturnValueType {
}
Maybe someone deal with such bug?
P.S. Here are my Code Style settings:

Looks like you want it to wrap parameter & its type also? Then remove the Place ')' on new line checkbox in Method declaration parameters settings from your screenshot.

Related

Problem with parameters of ROOT TF1 function declaration

I use a user-defined function to fit a data set in ROOT. The TF1 class declaration in my code is:
double t=1000;
double a=0.1*t, b=0.9*t;
...
TF1 *ffit = new TF1("ffit",fit,a,b,2);
ffit->FixParameter(0,t);
ffit->SetParameter(1,1);
...
TGraph *g = new TGraph(n,x,y);
g->Fit("ffit","R");
I expect it will work, but actually it does not. There is a segmentation violation together with a mess appearing when I run this code. However, when I just put 100 and 900 instead of a and b in the declaration of TF1 function, it works well.
So, what is the problem here? How can I overcome this issue?
The function fit is as followed:
double fit(double *x, double *par)
{
double y=par[0], g=par[1], y0=x[0];
double r=(y0*(y-y0))/y;
return (pow(r,1.5)*g);
}
P/s: I am using ROOT v6.14

Customize html output for a field's droplist options

I have a field called icon, which is a droplist sourced from folder in the content tree. I would like the list to not just show the text value(shown in the screen shot) but also to utilize an icon font and display what the actual icon would look like. Basically customizing the content editor's droplist for this field from:
<option value="gears">gears</option>
to
<option value="gears">gears <span class="my-icon-font-gears"></span></option>
Is there any documentation on how to modify the outputted html for a droplist, and to modify the content editor page to load another link, in this case a font-file.
I created a module on the marketplace that does something similar. You can have a look here. There is some documentation on there explaining how to use it.
The code is also on Git if you want to have a look.
Suggest you use the Droplink field type instead of the Droplist, since the value is stored by GUID and this will lead to less longer term problems if the link item is renamed or moved. In any case you need a custom field, inherit from Sitecore.Shell.Applications.ContentEditor.LookupEx (which is the DropLink field type) and override the DoRender() method with the custom markup you require.
It's not possible to embed a span tag since the option tag cannot contain other tags as it is invalid HTML. Adding it will cause the browser to strip it out. You can however set the class on the option itself and style that.
`<option value="gears" style="my-icon-font-gears">gears</option>`
Here is some sample code to achieve the field.
using System;
using System.Web.UI;
using Sitecore;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Globalization;
namespace MyProject.CMS.Custom.Controls
{
public class StyledLookupEx : Sitecore.Shell.Applications.ContentEditor.LookupEx
{
private string _styleClassField;
private string StyleClassField
{
get
{
if (String.IsNullOrEmpty(_styleClassField))
_styleClassField = StringUtil.ExtractParameter("StyleClassField", this.Source).Trim();
return _styleClassField;
}
}
// This method is copied pasted from the base class apart from thhe single lined marked below
protected override void DoRender(HtmlTextWriter output)
{
Assert.ArgumentNotNull(output, "output");
Item[] items = this.GetItems(Sitecore.Context.ContentDatabase.GetItem(this.ItemID, Language.Parse(this.ItemLanguage)));
output.Write("<select" + this.GetControlAttributes() + ">");
output.Write("<option value=\"\"></option>");
bool flag1 = false;
foreach (Item obj in items)
{
string itemHeader = this.GetItemHeader(obj);
bool flag2 = this.IsSelected(obj);
if (flag2)
flag1 = true;
/* Option markup modified with class added */
output.Write("<option value=\"" + this.GetItemValue(obj) + "\"" + (flag2 ? " selected=\"selected\"" : string.Empty) + " class=\"" + obj[StyleClassField] + "\" >" + itemHeader + "</option>");
}
bool flag3 = !string.IsNullOrEmpty(this.Value) && !flag1;
if (flag3)
{
output.Write("<optgroup label=\"" + Translate.Text("Value not in the selection list.") + "\">");
output.Write("<option value=\"" + this.Value + "\" selected=\"selected\">" + this.Value + "</option>");
output.Write("</optgroup>");
}
output.Write("</select>");
if (!flag3)
return;
output.Write("<div style=\"color:#999999;padding:2px 0px 0px 0px\">{0}</div>", Translate.Text("The field contains a value that is not in the selection list."));
}
}
}
This field adds a custom properties to allow you to specify the linked field to use for the style class. The assumption is that you have another single line text field on the linked item to specify the CSS class.
Usage: Set the source property of the field in the following format:
Datasource={path-or-guid-to-options}&StyleClassField={fieldname}
e.g. Datasource=/sitecore/content/lookup/iconfonts&StyleClassField=IconClassName
To use this new field compile the above code in to project, switch over to the core database and then create a new field type – you can duplicate the existing Droplink field located in /sitecore/system/Field types/Link Types/Droplink. Delete the existing Control field and instead set the ASSEMBLY and CLASS fields to point to your implementation.
You also need to load a custom CSS stylesheet with the style defintions into the Content Editor, which you can achieve that by following this blog post.

How to input a function into GNUoctave?

I need to input a function through console into a second one.
I have this function
trapez(fun,a,b,n)
so if I type this in the command line
trapez(#(x) x.^3,0,1,2)
it works perfectly but I need to run a program that uses a string input from the user like: 'x^4'and it gets used in the trapez function. I need the 'x^4' to become a function usable for trapez.
I have tried this:
t=input('func')
trapez(t,a,b,n)
and
t=input('func')
str2func(t)
but I get this error: error creating function handle "#x.^2"
Use the inline function:
f = inline("x^2");
f(2)
=> 4

Flex: NumericStepper rounding up decimal number

I have the following NumericStepper:
<s:NumericStepper id="estimertTidCell" value="{isNaN(hostComponent.estimertTid)?0:hostComponent.estimertTid}" stepSize="0.5" maximum="5" change="hostComponent.estimertTid=estimertTidCell.value"/>
When i set the value to e.g. 1.5 through the NumericStepper and store the value, the alert in the following code correctly displays 1.5:
private var _estimertTid:Number;
[Bindable]
public function get estimertTid():Number {
return _estimertTid;
}
public function set estimertTid(value:Number):void {
_estimertTid = value;
Alert.show("numeric stepper set:" + value);
invalidateSkinState();
}
Problem: My problem is that once the NumericStepper refreshes, or reloads the variable, it displays 2 instead of 1.5, or 4 instead of 3.5 etc. Anyone got any ideas of what is causing this behavior? I would think that by setting the stepSize=0.5 it would correctly display those decimal numbers.
Additional information: When i display the same variable in a spark Label, the value is correctly displayed as a decimal number.
At last! I found a small note that snapInterval has to be set to the same as stepSize or the value will be rounded up. So i hope my troubles help someone else in the future.
Set snapInterval to the same as stepSze to avoid numbers rounding up

Java: Is there any method in JTextPane that does the same thing as append() in JTextArea?

The program lets the user type in a command in a textfield then whatever they typed will show in the text area. If it is keywords such as yes it will turn green, however I cannot set just one line of text green in a text area so I need to use a text pane.
The problem is that if I use a text pane I can't use the append method anymore.
private final static String newline = "\n";
private void enterPressed(java.awt.event.KeyEvent evt) {
int key = evt.getKeyCode();
if (key == KeyEvent.VK_ENTER)
{
String textfieldEnterdValue = textfield1.getText().toString();
this.TextArea1.append("> "+tb1EnterdValue+newline);
this.tb1.setText("");
if((tb1EnterdValue.equals("yes")) )
{
TextArea1.setForeground(Color.green);
}
}
JTextPane uses Document as a model. This is necessary to support the use of multiple colors and fonts.
So, to append to a JTextPane, you need to modify the Document.
The following methods are available :
insertString(int pos, String value, AttributeSet att)
remove(int pos, int length)
For example, this will append value to the end of the document.
Document d = textPane.getDocument();
d.insertString(d.getLength(), value, null);
Additionally, you may want to call scrollRectToVisible(Rectangle) with the result of modelToView(int) to ensure the newly added line is on screen.
I think you'll need to do that directly on the underlying document.
Something like this:
String value = textfield1.getText(); // no need for toString() here!
textPane.getDocument().insertString(textPane.getCaretPosition(), value, null);