Commit 5d8dbe2e authored by Clint Rogers's avatar Clint Rogers

Closes #3566, saves the most-recently-chosen crop options to GSettings

when OK is clicked, then restores them and simulates a UI event when the 
crop tool is activated again.
parent 2c79d059
......@@ -240,6 +240,24 @@
</key>
</schema>
<schema id="org.yorba.shotwell.crop-settings" path="/apps/shotwell/crop-settings/">
<key name="last-crop-menu-choice" type="i">
<default>1</default>
<summary>Most-recently-used crop aspect ratio menu choice.</summary>
<description>A numeric code representing the last crop menu choice the user made.</description>
</key>
<key name="last-crop-width" type="i">
<default>1</default>
<summary>Most-recently-used crop custom aspect ratio's numerator.</summary>
<description>A nonzero, positive integer representing the width part of the last custom crop ratio the user entered.</description>
</key>
<key name="last-crop-height" type="i">
<default>1</default>
<summary>Most-recently-used crop custom aspect ratio's denominator.</summary>
<description>A nonzero, positive integer representing the height part of the last custom crop ratio the user entered.</description>
</key>
</schema>
<schema id="org.yorba.shotwell.preferences.editing" path="/apps/shotwell/preferences/editing/">
<key name="external-photo-editor" type="s">
<default>""</default>
......
......@@ -834,9 +834,12 @@ public class CropTool : EditingTool {
} else {
set_normal_constraint_mode();
if (selected_constraint.aspect_ratio != ANY_ASPECT_RATIO) {
custom_init_width = selected_constraint.basis_width;
custom_init_height = selected_constraint.basis_height;
if (selected_constraint.aspect_ratio != ANY_ASPECT_RATIO) {
// user may have switched away from 'Custom' without
// accepting, so set these to default back to saved
// values.
custom_init_width = Config.Facade.get_instance().get_last_crop_width();
custom_init_height = Config.Facade.get_instance().get_last_crop_height();
custom_aspect_ratio = ((float) custom_init_width) / ((float) custom_init_height);
}
}
......@@ -846,7 +849,7 @@ public class CropTool : EditingTool {
if (!get_selected_constraint().is_pivotable)
reticle_orientation = ReticleOrientation.LANDSCAPE;
if (get_constraint_aspect_ratio() != pre_aspect_ratio) {
if (get_constraint_aspect_ratio() != pre_aspect_ratio) {
Box new_crop = constrain_crop(scaled_crop);
crop_resized(new_crop);
......@@ -1007,6 +1010,7 @@ public class CropTool : EditingTool {
// set up the constraint combo box
crop_tool_window.constraint_combo.set_model(constraint_list);
crop_tool_window.constraint_combo.set_active(Config.Facade.get_instance().get_last_crop_menu_choice());
// set up the pivot reticle button
update_pivot_button_state();
......@@ -1032,13 +1036,43 @@ public class CropTool : EditingTool {
scaled_crop = crop.get_scaled_similar(uncropped_dim,
Dimensions.for_rectangle(canvas.get_scaled_pixbuf_position()));
custom_init_width = scaled_crop.get_width();
custom_init_height = scaled_crop.get_height();
// get the custom width and height from the saved config and
// set up the initial custom values with it.
custom_width = Config.Facade.get_instance().get_last_crop_width();
custom_height = Config.Facade.get_instance().get_last_crop_height();
custom_init_width = custom_width;
custom_init_height = custom_height;
pre_aspect_ratio = ((float) custom_init_width) / ((float) custom_init_height);
constraint_mode = ConstraintMode.NORMAL;
base.activate(canvas);
// make sure the window has its regular size before going into
// custom mode, which will resize it and needs to save the old
// size first.
crop_tool_window.show_all();
crop_tool_window.hide();
// was 'custom' the most-recently-chosen menu item?
if (constraints[Config.Facade.get_instance().get_last_crop_menu_choice()].aspect_ratio ==
CUSTOM_ASPECT_RATIO) {
// yes, switch to custom mode, make the entry fields appear.
set_custom_constraint_mode();
}
// since we no longer just run with the default, but rather
// a saved value, we'll behave as if the saved constraint has
// just been changed to so that everything gets updated and
// the canvas stays in sync.
Box new_crop = constrain_crop(scaled_crop);
crop_resized(new_crop);
scaled_crop = new_crop;
canvas.invalidate_area(new_crop);
canvas.repaint();
pre_aspect_ratio = get_constraint_aspect_ratio();
}
private void bind_canvas_handlers(PhotoCanvas canvas) {
......@@ -1243,6 +1277,14 @@ public class CropTool : EditingTool {
}
private void on_crop_ok() {
// user's clicked OK, save the combobox choice and width/height.
// safe to do, even if not in 'custom' mode - the previous values
// will just get saved again.
Config.Facade.get_instance().set_last_crop_menu_choice(
crop_tool_window.constraint_combo.get_active());
Config.Facade.get_instance().set_last_crop_width(custom_width);
Config.Facade.get_instance().set_last_crop_height(custom_height);
// scale screen-coordinate crop to photo's coordinate system
Box crop = scaled_crop.get_scaled_similar(
Dimensions.for_rectangle(canvas.get_scaled_pixbuf_position()),
......
......@@ -43,6 +43,9 @@ public enum ConfigurableProperty {
HIDE_PHOTOS_ALREADY_IMPORTED,
IMPORT_DIR,
KEEP_RELATIVITY,
LAST_CROP_HEIGHT,
LAST_CROP_MENU_CHOICE,
LAST_CROP_WIDTH,
LAST_USED_SERVICE,
LIBRARY_PHOTOS_SORT_ASCENDING,
LIBRARY_PHOTOS_SORT_BY,
......@@ -144,7 +147,16 @@ public enum ConfigurableProperty {
case KEEP_RELATIVITY:
return "KEEP_RELATIVITY";
case LAST_CROP_HEIGHT:
return "LAST_CROP_HEIGHT";
case LAST_CROP_MENU_CHOICE:
return "LAST_CROP_MENU_CHOICE";
case LAST_CROP_WIDTH:
return "LAST_CROP_WIDTH";
case LAST_USED_SERVICE:
return "LAST_USED_SERVICE";
......@@ -408,7 +420,7 @@ public abstract class ConfigurationFacade : Object {
return "";
}
}
public virtual void set_desktop_background(string filename) {
try {
get_engine().set_string_property(ConfigurableProperty.DESKTOP_BACKGROUND_FILE,
......@@ -781,6 +793,70 @@ public abstract class ConfigurationFacade : Object {
}
}
//
// last crop height
//
public virtual int get_last_crop_height() {
try {
return get_engine().get_int_property(ConfigurableProperty.LAST_CROP_HEIGHT);
} catch (ConfigurationError err) {
on_configuration_error(err);
return 1;
}
}
public virtual void set_last_crop_height(int choice) {
try {
get_engine().set_int_property(ConfigurableProperty.LAST_CROP_HEIGHT, choice);
} catch (ConfigurationError err) {
on_configuration_error(err);
}
}
//
// last crop menu choice
//
public virtual int get_last_crop_menu_choice() {
try {
return get_engine().get_int_property(ConfigurableProperty.LAST_CROP_MENU_CHOICE);
} catch (ConfigurationError err) {
on_configuration_error(err);
// in the event we can't get a reasonable value from the configuration engine, we
// return the empty string since it won't match the name of any existing publishing
// service -- this will cause the publishing subsystem to select the first service
// loaded that supports the user's media type
return 0;
}
}
public virtual void set_last_crop_menu_choice(int choice) {
try {
get_engine().set_int_property(ConfigurableProperty.LAST_CROP_MENU_CHOICE, choice);
} catch (ConfigurationError err) {
on_configuration_error(err);
}
}
//
// last crop width
//
public virtual int get_last_crop_width() {
try {
return get_engine().get_int_property(ConfigurableProperty.LAST_CROP_WIDTH);
} catch (ConfigurationError err) {
on_configuration_error(err);
return 1;
}
}
public virtual void set_last_crop_width(int choice) {
try {
get_engine().set_int_property(ConfigurableProperty.LAST_CROP_WIDTH, choice);
} catch (ConfigurationError err) {
on_configuration_error(err);
}
}
//
// last used service
//
......@@ -913,7 +989,7 @@ public abstract class ConfigurationFacade : Object {
return 5.0;
}
}
public virtual void set_printing_content_height(double content_height) {
try {
get_engine().set_double_property(ConfigurableProperty.PRINTING_CONTENT_HEIGHT,
......
......@@ -15,6 +15,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
private const string VIDEO_SCHEMA_NAME = ROOT_SCHEMA_NAME + ".video";
private const string PRINTING_SCHEMA_NAME = ROOT_SCHEMA_NAME + ".printing";
private const string SHARING_SCHEMA_NAME = ROOT_SCHEMA_NAME + ".sharing";
private const string CROP_SCHEMA_NAME = ROOT_SCHEMA_NAME + ".crop-settings";
private const string SYSTEM_DESKTOP_SCHEMA_NAME = "org.gnome.desktop.background";
private const string PLUGINS_ENABLE_DISABLE_SCHEMA_NAME = ROOT_SCHEMA_NAME +
".plugins.enable-state";
......@@ -54,6 +55,9 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
schema_names[ConfigurableProperty.HIDE_PHOTOS_ALREADY_IMPORTED] = UI_PREFS_SCHEMA_NAME;
schema_names[ConfigurableProperty.IMPORT_DIR] = FILES_PREFS_SCHEMA_NAME;
schema_names[ConfigurableProperty.KEEP_RELATIVITY] = UI_PREFS_SCHEMA_NAME;
schema_names[ConfigurableProperty.LAST_CROP_HEIGHT] = CROP_SCHEMA_NAME;
schema_names[ConfigurableProperty.LAST_CROP_MENU_CHOICE] = CROP_SCHEMA_NAME;
schema_names[ConfigurableProperty.LAST_CROP_WIDTH] = CROP_SCHEMA_NAME;
schema_names[ConfigurableProperty.LAST_USED_SERVICE] = SHARING_SCHEMA_NAME;
schema_names[ConfigurableProperty.LIBRARY_PHOTOS_SORT_ASCENDING] = UI_PREFS_SCHEMA_NAME;
schema_names[ConfigurableProperty.LIBRARY_PHOTOS_SORT_BY] = UI_PREFS_SCHEMA_NAME;
......@@ -107,6 +111,9 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
key_names[ConfigurableProperty.HIDE_PHOTOS_ALREADY_IMPORTED] = "hide-photos-already-imported";
key_names[ConfigurableProperty.IMPORT_DIR] = "import-dir";
key_names[ConfigurableProperty.KEEP_RELATIVITY] = "keep-relativity";
key_names[ConfigurableProperty.LAST_CROP_HEIGHT] = "last-crop-height";
key_names[ConfigurableProperty.LAST_CROP_MENU_CHOICE] = "last-crop-menu-choice";
key_names[ConfigurableProperty.LAST_CROP_WIDTH] = "last-crop-width";
key_names[ConfigurableProperty.LAST_USED_SERVICE] = "last-used-service";
key_names[ConfigurableProperty.LIBRARY_PHOTOS_SORT_ASCENDING] = "library-photos-sort-ascending";
key_names[ConfigurableProperty.LIBRARY_PHOTOS_SORT_BY] = "library-photos-sort-by";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment