| 1 | package # hide from PAUSE | ||
| 2 | App::DBBrowser::Options::ReadWrite; | ||
| 3 | |||
| 4 | use warnings; | ||
| 5 | use strict; | ||
| 6 | use 5.016; | ||
| 7 | |||
| 8 | use App::DBBrowser::Auxil; | ||
| 9 | use App::DBBrowser::Options::Defaults; | ||
| 10 | |||
| 11 | |||
| 12 | sub new { | ||
| 13 | my ( $class, $info, $options ) = @_; | ||
| 14 | bless { | ||
| 15 | i => $info, | ||
| 16 | o => $options | ||
| 17 | }, $class; | ||
| 18 | } | ||
| 19 | |||
| 20 | |||
| 21 | sub write_config_file { | ||
| 22 | my ( $sf, $lo, $plugin ) = @_; | ||
| 23 | my $ax = App::DBBrowser::Auxil->new( $sf->{i}, $sf->{o}, {} ); | ||
| 24 | if ( $plugin ) { | ||
| 25 | my $file_fs = sprintf( $sf->{i}{plugin_config_file_fmt}, $plugin ); | ||
| 26 | $ax->write_json( $file_fs, $lo ); | ||
| 27 | } | ||
| 28 | else { | ||
| 29 | $ax->write_json( $sf->{i}{f_global_settings}, $lo ); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | |||
| 34 | sub read_config_file { | ||
| 35 | my ( $sf, $driver, $plugin ) = @_; | ||
| 36 | my $ax = App::DBBrowser::Auxil->new( $sf->{i}, $sf->{o}, {} ); | ||
| 37 | my $op_df = App::DBBrowser::Options::Defaults->new( $sf->{i}, {} ); | ||
| 38 | my $lo = {}; | ||
| 39 | if ( $plugin ) { | ||
| 40 | my $file_fs = sprintf( $sf->{i}{plugin_config_file_fmt}, $plugin ); | ||
| 41 | $lo = $ax->read_json( $file_fs ) // {}; | ||
| 42 | if ( ! %{$lo//{}} ) { | ||
| 43 | $lo = $op_df->defaults( $driver ); | ||
| 44 | } | ||
| 45 | |||
| 46 | ####### 19.02.2026 ############ | ||
| 47 | if ( exists $lo->{table}{max_width_exp} || exists $lo->{table}{min_col_width} || ! exists $lo->{table}{expanded_line_spacing}) { | ||
| 48 | $lo->{table}{expanded_line_spacing} = 1 if ! exists $lo->{table}{expanded_line_spacing}; | ||
| 49 | |||
| 50 | $lo->{table}{expanded_max_width} = delete $lo->{table}{max_width_exp} if exists $lo->{table}{max_width_exp}; | ||
| 51 | $lo->{table}{col_trim_threshold} = delete $lo->{table}{min_col_width} if exists $lo->{table}{min_col_width}; | ||
| 52 | |||
| 53 | my $file_fs = sprintf( $sf->{i}{plugin_config_file_fmt}, $plugin ); | ||
| 54 | $sf->write_config_file( $lo, $plugin ) if -f $file_fs; | ||
| 55 | } | ||
| 56 | ############################### | ||
| 57 | |||
| 58 | ####### 23.06.2026 ############ | ||
| 59 | if ( ! defined $lo->{insert}{max_cols_plain} ) { | ||
| 60 | my $file_fs = sprintf( $sf->{i}{plugin_config_file_fmt}, $plugin ); | ||
| 61 | $lo->{insert}{max_cols_plain} = 25; | ||
| 62 | $sf->write_config_file( $lo, $plugin ) if -f $file_fs; | ||
| 63 | } | ||
| 64 | ############################### | ||
| 65 | |||
| 66 | } | ||
| 67 | else { | ||
| 68 | $lo = $ax->read_json( $sf->{i}{f_global_settings} ) // {}; | ||
| 69 | if ( ! %{$lo//{}} ) { | ||
| 70 | $lo = $op_df->defaults_pre_plugin(); | ||
| 71 | } | ||
| 72 | $sf->{i}{tc_default}{mouse} = $lo->{table}{mouse}; | ||
| 73 | $sf->{i}{tcu_default}{mouse} = $lo->{table}{mouse}; | ||
| 74 | } | ||
| 75 | if ( defined wantarray ) { | ||
| 76 | return $lo; | ||
| 77 | } | ||
| 78 | else { | ||
| 79 | for my $section ( keys %$lo ) { | ||
| 80 | for my $opt ( keys %{$lo->{$section}} ) { | ||
| 81 | $sf->{o}{$section}{$opt} = $lo->{$section}{$opt}; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | |||
| 89 | |||
| 90 | |||
| 91 | 1; | ||
| 92 | |||
| 93 | |||
| 94 | __END__ |