Skip to content

Commit

Permalink
Fix Minor Code-style Conflicts (#688)
Browse files Browse the repository at this point in the history
* Fix Minor Code-style Conflicts

* Update AdjustTool.vala

* Update AdjustTool.vala

* Update src/editing_tools/AdjustTool.vala

Co-authored-by: Ryo Nakano <26003928+ryonakano@users.noreply.github.com>

* Update src/editing_tools/AdjustTool.vala

Co-authored-by: Ryo Nakano <26003928+ryonakano@users.noreply.github.com>

* Update AdjustTool.vala

* Update src/editing_tools/AdjustTool.vala

Co-authored-by: Jeremy Wootten <jeremy@elementaryos.org>

* Update AdjustTool.vala

* Update AdjustTool.vala

* Update AdjustTool.vala

* Update src/editing_tools/AdjustTool.vala

Co-authored-by: Jeremy Wootten <jeremy@elementaryos.org>

* Fix lint

* Fix Lacking closing parenthesis

* Fix unreachable else

* Check type before invalid cast; rely on signature to exclude null

Co-authored-by: Ryo Nakano <26003928+ryonakano@users.noreply.github.com>
Co-authored-by: Jeremy Wootten <jeremy@elementaryos.org>
Co-authored-by: Jeremy Paul Wootten <jeremywootten@gmail.com>
  • Loading branch information
4 people authored Dec 13, 2021
1 parent 3a72990 commit 327828b
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 126 deletions.
77 changes: 43 additions & 34 deletions src/Commands.vala
Original file line number Diff line number Diff line change
Expand Up @@ -261,23 +261,26 @@ public abstract class GenericPhotoTransformationCommand : SingleDataSourceComman
}

public override bool compress (Command command) {
if (!can_compress (command))
return false;

GenericPhotoTransformationCommand generic = command as GenericPhotoTransformationCommand;
if (generic == null)
if (!can_compress (command)) {
return false;
}

if (generic.source != source)
return false;
if (command is GenericPhotoTransformationCommand) {
var generic = (GenericPhotoTransformationCommand)command;
if (generic.source != source) {
return false;
}

// execute this new (and successive) command
generic.execute ();
// execute this new (and successive) command
generic.execute ();

// save it's new transformation state as ours
transformed_state = generic.transformed_state;
// save it's new transformation state as ours
transformed_state = generic.transformed_state;

return true;
return true;
} else {
return false;
}
}

private void on_state_broken () {
Expand Down Expand Up @@ -728,16 +731,18 @@ public class RevertSingleCommand : GenericPhotoTransformationCommand {
}

public override bool compress (Command command) {
RevertSingleCommand revert_single_command = command as RevertSingleCommand;
if (revert_single_command == null)
return false;
if (command is RevertSingleCommand) {
var revert_single_command = (RevertSingleCommand)command;
if (revert_single_command.source != source) {
return false;
}

if (revert_single_command.source != source)
// no need to execute anything; multiple successive reverts on the same photo are as good
// as one
return true;
} else {
return false;

// no need to execute anything; multiple successive reverts on the same photo are as good
// as one
return true;
}
}
}

Expand Down Expand Up @@ -773,15 +778,17 @@ public class EnhanceSingleCommand : GenericPhotoTransformationCommand {
}

public override bool compress (Command command) {
EnhanceSingleCommand enhance_single_command = command as EnhanceSingleCommand;
if (enhance_single_command == null)
return false;
if (command is EnhanceSingleCommand) {
var enhance_single_command = (EnhanceSingleCommand)command;
if (enhance_single_command.source != source) {
return false;
}

if (enhance_single_command.source != source)
// multiple successive enhances on the same photo are as good as a single
return true;
} else {
return false;

// multiple successive enhances on the same photo are as good as a single
return true;
}
}
}

Expand Down Expand Up @@ -809,15 +816,17 @@ public class UnEnhanceSingleCommand : GenericPhotoTransformationCommand {
}

public override bool compress (Command command) {
UnEnhanceSingleCommand unenhance_single_command = command as UnEnhanceSingleCommand;
if (unenhance_single_command == null)
return false;
if (command is UnEnhanceSingleCommand) {
var unenhance_single_command = (UnEnhanceSingleCommand)command;
if (unenhance_single_command.source != source) {
return false;
}

if (unenhance_single_command.source != source)
// multiple successive enhances on the same photo are as good as a single
return true;
} else {
return false;

// multiple successive enhances on the same photo are as good as a single
return true;
}
}
}

Expand Down
170 changes: 85 additions & 85 deletions src/editing_tools/AdjustTool.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public class EditingTools.AdjustTool : EditingTool {
public RGBHistogramManipulator histogram_manipulator;

public AdjustToolWindow (Gtk.Window container) {
Object (
transient_for: container
);
Object (transient_for: container);
}

construct {
Expand Down Expand Up @@ -216,17 +214,16 @@ public class EditingTools.AdjustTool : EditingTool {
}

public override bool compress (Command command) {
AdjustResetCommand reset_command = command as AdjustResetCommand;
if (reset_command == null) {
if (command is AdjustResetCommand) {
var reset_command = (AdjustResetCommand) command;
if (reset_command.owner != owner) {
return false;
}
// multiple successive resets on the same photo as good as a single
return true;
} else {
return false;
}

if (reset_command.owner != owner) {
return false;
}

// multiple successive resets on the same photo as good as a single
return true;
}
}

Expand Down Expand Up @@ -278,28 +275,29 @@ public class EditingTools.AdjustTool : EditingTool {
}

public override bool compress (Command command) {
var slider_adjustment = (SliderAdjustmentCommand) command;
if (slider_adjustment == null) {
return false;
}
if (command is SliderAdjustmentCommand) {
var slider_adjustment = (SliderAdjustmentCommand) command;

// same photo
if (slider_adjustment.owner != owner) {
return false;
}
// same photo
if (slider_adjustment.owner != owner) {
return false;
}

// same adjustment
if (slider_adjustment.transformation_type != transformation_type) {
return false;
}
// same adjustment
if (slider_adjustment.transformation_type != transformation_type) {
return false;
}

// execute the command
slider_adjustment.execute ();
// execute the command
slider_adjustment.execute ();

// save it's transformation as ours
new_transformation = slider_adjustment.new_transformation;
// save it's transformation as ours
new_transformation = slider_adjustment.new_transformation;

return true;
return true;
} else {
return false;
}
}
}

Expand Down Expand Up @@ -335,26 +333,26 @@ public class EditingTools.AdjustTool : EditingTool {

public override bool compress (Command command) {
// can compress both normal enhance and one with the adjust tool running
var enhance_single = (EnhanceSingleCommand) command;
if (enhance_single != null) {
if (command is EnhanceSingleCommand) {
var enhance_single = (EnhanceSingleCommand) command;
var photo = (Photo) enhance_single.get_source ();

// multiple successive enhances are as good as a single, as long as it's on the
// same photo
return photo.equals (owner.canvas.photo);
}

AdjustEnhanceCommand enhance_command = (AdjustEnhanceCommand) command;
if (enhance_command == null) {
return false;
}
if (command is AdjustEnhanceCommand) {
var enhance_command = (AdjustEnhanceCommand) command;

if (enhance_command.owner != owner) {
return false;
}

if (enhance_command.owner != owner) {
// multiple successive as good as a single
return true;
} else {
return false;
}

// multiple successive as good as a single
return true;
}
}

Expand Down Expand Up @@ -468,6 +466,7 @@ public class EditingTools.AdjustTool : EditingTool {
} else {
histogram_pixbuf = draw_to_pixbuf.copy ();
}

virgin_histogram_pixbuf = histogram_pixbuf.copy ();

DataCollection? owner = canvas.photo.get_membership ();
Expand Down Expand Up @@ -532,7 +531,7 @@ public class EditingTools.AdjustTool : EditingTool {
}

private void on_reset () {
AdjustResetCommand command = new AdjustResetCommand (this, transformations);
var command = new AdjustResetCommand (this, transformations);
AppWindow.get_command_manager ().execute (command);
}

Expand Down Expand Up @@ -568,7 +567,7 @@ public class EditingTools.AdjustTool : EditingTool {
private void slider_updated (PixelTransformation new_transformation, string name) {
PixelTransformation old_transformation = transformations.get_transformation (
new_transformation.get_transformation_type ());
SliderAdjustmentCommand command = new SliderAdjustmentCommand (this, old_transformation,
var command = new SliderAdjustmentCommand (this, old_transformation,
new_transformation, name);
AppWindow.get_command_manager ().execute (command);
}
Expand Down Expand Up @@ -767,49 +766,50 @@ public class EditingTools.AdjustTool : EditingTool {
// if the caller doesn't want the widget's signals to fire with the change.
private void update_slider (PixelTransformation transformation) {
switch (transformation.get_transformation_type ()) {
case PixelTransformationType.TONE_EXPANSION:
var expansion = (ExpansionTransformation) transformation;

if (!disable_histogram_refresh) {
adjust_tool_window.histogram_manipulator.set_left_nub_position (
expansion.get_black_point ());
adjust_tool_window.histogram_manipulator.set_right_nub_position (
expansion.get_white_point ());
}
break;

case PixelTransformationType.SHADOWS:
adjust_tool_window.shadows_slider.set_value (
((ShadowDetailTransformation) transformation).get_parameter ());
break;

case PixelTransformationType.HIGHLIGHTS:
adjust_tool_window.highlights_slider.set_value (
((HighlightDetailTransformation) transformation).get_parameter ());
break;

case PixelTransformationType.EXPOSURE:
adjust_tool_window.exposure_slider.set_value (
((ExposureTransformation) transformation).get_parameter ());
break;

case PixelTransformationType.SATURATION:
adjust_tool_window.saturation_slider.set_value (
((SaturationTransformation) transformation).get_parameter ());
break;

case PixelTransformationType.TINT:
adjust_tool_window.tint_slider.set_value (
((TintTransformation) transformation).get_parameter ());
break;

case PixelTransformationType.TEMPERATURE:
adjust_tool_window.temperature_slider.set_value (
((TemperatureTransformation) transformation).get_parameter ());
break;

default:
error ("Unknown adjustment: %d", (int) transformation.get_transformation_type ());
case PixelTransformationType.TONE_EXPANSION:
var expansion = (ExpansionTransformation) transformation;

if (!disable_histogram_refresh) {
adjust_tool_window.histogram_manipulator.set_left_nub_position (
expansion.get_black_point ());
adjust_tool_window.histogram_manipulator.set_right_nub_position (
expansion.get_white_point ());
}

break;

case PixelTransformationType.SHADOWS:
adjust_tool_window.shadows_slider.set_value (
((ShadowDetailTransformation) transformation).get_parameter ());
break;

case PixelTransformationType.HIGHLIGHTS:
adjust_tool_window.highlights_slider.set_value (
((HighlightDetailTransformation) transformation).get_parameter ());
break;

case PixelTransformationType.EXPOSURE:
adjust_tool_window.exposure_slider.set_value (
((ExposureTransformation) transformation).get_parameter ());
break;

case PixelTransformationType.SATURATION:
adjust_tool_window.saturation_slider.set_value (
((SaturationTransformation) transformation).get_parameter ());
break;

case PixelTransformationType.TINT:
adjust_tool_window.tint_slider.set_value (
((TintTransformation) transformation).get_parameter ());
break;

case PixelTransformationType.TEMPERATURE:
adjust_tool_window.temperature_slider.set_value (
((TemperatureTransformation) transformation).get_parameter ());
break;

default:
error ("Unknown adjustment: %d", (int) transformation.get_transformation_type ());
}
}

Expand Down
Loading

0 comments on commit 327828b

Please sign in to comment.