Skip to content

Commit

Permalink
Add tool options panel position
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Nov 24, 2024
1 parent e42e3c7 commit 36168ff
Show file tree
Hide file tree
Showing 14 changed files with 368 additions and 230 deletions.
6 changes: 2 additions & 4 deletions api/lib/src/protocol/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ class DocumentEvent extends ReplayEvent with _$DocumentEvent {
String id,
) = LayerRemoved;

const factory DocumentEvent.layersMerged(
List<String> layers,
[bool duplicate = false],
) = LayersMerged;
const factory DocumentEvent.layersMerged(List<String> layers,
[@Default(false) bool duplicate]) = LayersMerged;

const factory DocumentEvent.layerOrderChanged(
String id,
Expand Down
28 changes: 21 additions & 7 deletions api/lib/src/protocol/event.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3410,7 +3410,7 @@ abstract class _$$LayersMergedImplCopyWith<$Res> {
_$LayersMergedImpl value, $Res Function(_$LayersMergedImpl) then) =
__$$LayersMergedImplCopyWithImpl<$Res>;
@useResult
$Res call({List<String> layers});
$Res call({List<String> layers, bool duplicate});
}

/// @nodoc
Expand All @@ -3427,20 +3427,26 @@ class __$$LayersMergedImplCopyWithImpl<$Res>
@override
$Res call({
Object? layers = null,
Object? duplicate = null,
}) {
return _then(_$LayersMergedImpl(
null == layers
? _value._layers
: layers // ignore: cast_nullable_to_non_nullable
as List<String>,
null == duplicate
? _value.duplicate
: duplicate // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}

/// @nodoc
@JsonSerializable()
class _$LayersMergedImpl extends LayersMerged {
const _$LayersMergedImpl(final List<String> layers, {final String? $type})
const _$LayersMergedImpl(final List<String> layers,
[this.duplicate = false, final String? $type])
: _layers = layers,
$type = $type ?? 'layersMerged',
super._();
Expand All @@ -3456,26 +3462,32 @@ class _$LayersMergedImpl extends LayersMerged {
return EqualUnmodifiableListView(_layers);
}

@override
@JsonKey()
final bool duplicate;

@JsonKey(name: 'type')
final String $type;

@override
String toString() {
return 'DocumentEvent.layersMerged(layers: $layers)';
return 'DocumentEvent.layersMerged(layers: $layers, duplicate: $duplicate)';
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LayersMergedImpl &&
const DeepCollectionEquality().equals(other._layers, _layers));
const DeepCollectionEquality().equals(other._layers, _layers) &&
(identical(other.duplicate, duplicate) ||
other.duplicate == duplicate));
}

@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(_layers));
int get hashCode => Object.hash(
runtimeType, const DeepCollectionEquality().hash(_layers), duplicate);

/// Create a copy of DocumentEvent
/// with the given fields replaced by the non-null parameter values.
Expand All @@ -3494,13 +3506,15 @@ class _$LayersMergedImpl extends LayersMerged {
}

abstract class LayersMerged extends DocumentEvent {
const factory LayersMerged(final List<String> layers) = _$LayersMergedImpl;
const factory LayersMerged(final List<String> layers,
[final bool duplicate]) = _$LayersMergedImpl;
const LayersMerged._() : super._();

factory LayersMerged.fromJson(Map<String, dynamic> json) =
_$LayersMergedImpl.fromJson;

List<String> get layers;
bool get duplicate;

/// Create a copy of DocumentEvent
/// with the given fields replaced by the non-null parameter values.
Expand Down
4 changes: 3 additions & 1 deletion api/lib/src/protocol/event.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/lib/bloc/document_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ class DocumentBloc extends ReplayBloc<DocumentEvent, DocumentState> {
...aboveLayers.expand((e) => current.page.getLayer(e).content),
]);
final newLayers = layers
.where((e) => duplicate || !mergedLayers.contains(e.id))
.where((e) => event.duplicate || !mergedLayers.contains(e.id))
.map((e) => e.id == mainLayer ? layer : e)
.toList();
return _saveState(
Expand Down
26 changes: 24 additions & 2 deletions app/lib/cubits/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ enum ToolbarPosition {
};
}

enum OptionsPanelPosition {
top,
bottom;

String getLocalizedName(BuildContext context) => switch (this) {
OptionsPanelPosition.top => AppLocalizations.of(context).top,
OptionsPanelPosition.bottom => AppLocalizations.of(context).bottom,
};
}

enum ThemeDensity {
system,
maximize,
Expand Down Expand Up @@ -208,6 +218,8 @@ class ButterflySettings with _$ButterflySettings, LeapSettings {
@Default(UtilitiesState()) UtilitiesState utilities,
@Default(StartupBehavior.openHomeScreen) StartupBehavior onStartup,
@Default(true) bool colorToolbarEnabled,
@Default(OptionsPanelPosition.top)
OptionsPanelPosition optionsPanelPosition,
}) = _ButterflySettings;

factory ButterflySettings.fromPrefs(SharedPreferences prefs) {
Expand Down Expand Up @@ -303,6 +315,10 @@ class ButterflySettings with _$ButterflySettings, LeapSettings {
: StartupBehavior.openHomeScreen,
colorToolbarEnabled: prefs.getBool('color_toolbar_enabled') ?? true,
showSaveButton: prefs.getBool('show_save_button') ?? true,
optionsPanelPosition: prefs.containsKey('options_panel_position')
? OptionsPanelPosition.values
.byName(prefs.getString('options_panel_position')!)
: OptionsPanelPosition.top,
);
}

Expand Down Expand Up @@ -372,6 +388,7 @@ class ButterflySettings with _$ButterflySettings, LeapSettings {
await prefs.setString('on_startup', onStartup.name);
await prefs.setBool('color_toolbar_enabled', colorToolbarEnabled);
await prefs.setBool('show_save_button', showSaveButton);
await prefs.setString('options_panel_position', optionsPanelPosition.name);
}

ExternalStorage? getRemote(String? identifier) {
Expand Down Expand Up @@ -464,11 +481,16 @@ class SettingsCubit extends Cubit<ButterflySettings>
return save();
}

Future<void> resetToolbarSize() {
emit(state.copyWith(toolbarSize: ToolbarSize.normal));
Future<void> resetToolbarSize() => changeToolbarSize(ToolbarSize.normal);

Future<void> changeOptionsPanelPosition(OptionsPanelPosition position) {
emit(state.copyWith(optionsPanelPosition: position));
return save();
}

Future<void> resetOptionsPanelPosition() =>
changeOptionsPanelPosition(OptionsPanelPosition.top);

void changeLocaleTemporarily(String locale) {
emit(state.copyWith(localeTag: locale));
}
Expand Down
Loading

0 comments on commit 36168ff

Please sign in to comment.