Skip to content

Commit

Permalink
feat: changing the way the button in the TextWithButton works (#1068)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaaa authored Nov 5, 2024
1 parent 7261a38 commit c30f7d8
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class TextWithButton
private Text text;
private Label button;
private Composite baseComposite;
private String textWithDynamicVariables;

public TextWithButton(final Composite parent, int style)
{
Expand All @@ -54,32 +55,38 @@ public TextWithButton(final Composite parent, int style)
button.setImage(buttonShowImage);
button.addMouseListener(new MouseAdapter()
{
String textWhenButtonIsPressed;

@Override
public void mouseUp(final MouseEvent e)
{
button.setImage(buttonShowImage);
text.setText(textWhenButtonIsPressed);
}

@Override
public void mouseDown(final MouseEvent e)
{
button.setImage(buttonHideImage);
textWhenButtonIsPressed = text.getText();
// text is not editable means that the button isn't pressed now and we have to show dynamic variables
if (!text.getEditable())
{
showDynamicVariables();
return;
}

button.setImage(buttonHideImage);
textWithDynamicVariables = text.getText();
text.setEditable(false);
try
{
text.setText(VariablesPlugin.getDefault().getStringVariableManager()
.performStringSubstitution((textWhenButtonIsPressed), false));
.performStringSubstitution((textWithDynamicVariables), false));
}
catch (CoreException e1)
{
Logger.log(e1);
}
}

private void showDynamicVariables()
{
text.setEditable(true);
button.setImage(buttonShowImage);
text.setText(textWithDynamicVariables);
}

});
button.addDisposeListener(e -> {
buttonHideImage.dispose();
Expand All @@ -97,9 +104,12 @@ public void addMouseTrackListener(MouseTrackAdapter mouseTrackAdapter)
text.addMouseTrackListener(mouseTrackAdapter);
}

/*
* Always return text with dynamic variables.
*/
public String getText()
{
return text.getText();
return text.getEditable() ? text.getText() : textWithDynamicVariables;
}

public Control getControl()
Expand Down

0 comments on commit c30f7d8

Please sign in to comment.