mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-23 21:22:48 +01:00
Introduce undo button
This commit is contained in:
@@ -5,6 +5,9 @@ import BitwiseResultViewModel from './BitwiseResultViewModel';
|
|||||||
import { Expression, ExpressionElement } from '../expression-interfaces';
|
import { Expression, ExpressionElement } from '../expression-interfaces';
|
||||||
import { Operator, Operand, ListOfNumbers } from '../expression';
|
import { Operator, Operand, ListOfNumbers } from '../expression';
|
||||||
import calc from '../../core/calc';
|
import calc from '../../core/calc';
|
||||||
|
import { Integer } from '../../core/Integer';
|
||||||
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
|
import { faUndo } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
|
||||||
type BitwiseResultViewProps = {
|
type BitwiseResultViewProps = {
|
||||||
expression: Expression;
|
expression: Expression;
|
||||||
@@ -93,6 +96,7 @@ type ExpressionElementRowProps = {
|
|||||||
class ExpressionElementTableRow extends React.Component<ExpressionElementRowProps> {
|
class ExpressionElementTableRow extends React.Component<ExpressionElementRowProps> {
|
||||||
|
|
||||||
infoWasShown: boolean = false;
|
infoWasShown: boolean = false;
|
||||||
|
originalValue: Integer | null = null;
|
||||||
|
|
||||||
constructor(props: ExpressionElementRowProps) {
|
constructor(props: ExpressionElementRowProps) {
|
||||||
super(props);
|
super(props);
|
||||||
@@ -118,6 +122,9 @@ class ExpressionElementTableRow extends React.Component<ExpressionElementRowProp
|
|||||||
</td>
|
</td>
|
||||||
<td className="other">{this.getAlternative()}</td>
|
<td className="other">{this.getAlternative()}</td>
|
||||||
<td className="info accent1" data-test-name='ignore'>{this.props.showInfoColumn ? this.getInfo(maxNumberOfBits) : null}</td>
|
<td className="info accent1" data-test-name='ignore'>{this.props.showInfoColumn ? this.getInfo(maxNumberOfBits) : null}</td>
|
||||||
|
<td className='undo' data-test-name='ignore'>
|
||||||
|
{this.originalValue != null ? <button title='Undo all changes' onClick={() => this.undo()}><FontAwesomeIcon icon={faUndo}/></button> : null}
|
||||||
|
</td>
|
||||||
</tr>;
|
</tr>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,6 +158,15 @@ class ExpressionElementTableRow extends React.Component<ExpressionElementRowProp
|
|||||||
return formatter.numberToString(op.value, op.base == 'bin' ? 'dec' : op.base);
|
return formatter.numberToString(op.value, op.base == 'bin' ? 'dec' : op.base);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undo() {
|
||||||
|
if(this.originalValue == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.props.expressionItem.getUnderlyingOperand().setValue(this.originalValue);
|
||||||
|
this.originalValue = null;
|
||||||
|
this.forceUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
flipBit(args: FlipBitEventArg) {
|
flipBit(args: FlipBitEventArg) {
|
||||||
|
|
||||||
const op = this.props.expressionItem.getUnderlyingOperand();
|
const op = this.props.expressionItem.getUnderlyingOperand();
|
||||||
@@ -158,6 +174,9 @@ class ExpressionElementTableRow extends React.Component<ExpressionElementRowProp
|
|||||||
|
|
||||||
const maxBitSize = op.value.maxBitSize;
|
const maxBitSize = op.value.maxBitSize;
|
||||||
const space = (totalLength - index - maxBitSize);
|
const space = (totalLength - index - maxBitSize);
|
||||||
|
|
||||||
|
this.originalValue = op.value;
|
||||||
|
|
||||||
if(totalLength > op.value.maxBitSize && space > 0) {
|
if(totalLength > op.value.maxBitSize && space > 0) {
|
||||||
op.setValue(calc.addSpace(op.value, space));
|
op.setValue(calc.addSpace(op.value, space));
|
||||||
}
|
}
|
||||||
@@ -166,10 +185,13 @@ class ExpressionElementTableRow extends React.Component<ExpressionElementRowProp
|
|||||||
const newValue = calc.flipBit(op.value, pad + index);
|
const newValue = calc.flipBit(op.value, pad + index);
|
||||||
op.setValue(newValue);
|
op.setValue(newValue);
|
||||||
this.props.onBitFlipped();
|
this.props.onBitFlipped();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onChangeSign () {
|
onChangeSign () {
|
||||||
var op = this.props.expressionItem.getUnderlyingOperand();
|
var op = this.props.expressionItem.getUnderlyingOperand();
|
||||||
|
this.originalValue = op.value;
|
||||||
op.setValue(op.value.signed ? op.value.toUnsigned() : op.value.toSigned());
|
op.setValue(op.value.signed ? op.value.toUnsigned() : op.value.toSigned());
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,11 @@ a.hashLink { font-size: 1.1em;}
|
|||||||
|
|
||||||
button { border: none; text-decoration: underline;}
|
button { border: none; text-decoration: underline;}
|
||||||
|
|
||||||
|
.undo button {
|
||||||
|
opacity: 0.4;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Light */
|
/* Light */
|
||||||
.light { background: #fafafa; }
|
.light { background: #fafafa; }
|
||||||
.light .header-cmd { color: #919191 }
|
.light .header-cmd { color: #919191 }
|
||||||
|
|||||||
Reference in New Issue
Block a user