Skip to content

Commit 5c0a3a1

Browse files
committed
fix: block signals modified the store upon startup
Using the sensitivity option for all relevant buttons until the first init including the initial tab are added
1 parent 76b3e2a commit 5c0a3a1

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

crates/rnote-ui/src/appwindow/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ impl RnAppWindow {
240240
// Anything that needs to be done right before showing the appwindow
241241

242242
self.refresh_ui();
243+
imp.sidebar.get().activate_doc_settings_buttons();
243244
}
244245

245246
fn setup_icon_theme(&self) {

crates/rnote-ui/src/settingspanel/mod.rs

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ impl RnSettingsPanel {
838838
}
839839
));
840840

841+
imp.doc_show_format_borders_row.set_sensitive(false);
841842
imp.doc_show_format_borders_row
842843
.connect_active_notify(clone!(
843844
#[weak]
@@ -860,13 +861,17 @@ impl RnSettingsPanel {
860861
.sync_create()
861862
.build();
862863

864+
imp.doc_format_border_color_button.set_sensitive(false);
863865
imp.doc_format_border_color_button
864866
.connect_rgba_notify(clone!(
865867
#[weak(rename_to=settingspanel)]
866868
self,
867869
#[weak]
868870
appwindow,
869871
move |button| {
872+
if !button.get_sensitive() {
873+
return;
874+
}
870875
let format_border_color = button.rgba().into_compose_color();
871876
let Some(canvas) = appwindow.active_tab_canvas() else {
872877
return;
@@ -892,10 +897,14 @@ impl RnSettingsPanel {
892897
}
893898
));
894899

900+
imp.doc_background_color_button.set_sensitive(false);
895901
imp.doc_background_color_button.connect_rgba_notify(clone!(
896902
#[weak]
897903
appwindow,
898904
move |button| {
905+
if !button.get_sensitive() {
906+
return;
907+
}
899908
let background_color = button.rgba().into_compose_color();
900909
let Some(canvas) = appwindow.active_tab_canvas() else {
901910
return;
@@ -917,14 +926,18 @@ impl RnSettingsPanel {
917926
}
918927
));
919928

929+
imp.doc_document_layout_row.set_sensitive(false);
920930
imp.doc_document_layout_row
921931
.get()
922932
.connect_selected_item_notify(clone!(
923933
#[weak(rename_to=settings_panel)]
924934
self,
925935
#[weak]
926936
appwindow,
927-
move |_| {
937+
move |row| {
938+
if !row.get_sensitive() {
939+
return;
940+
}
928941
let document_layout = settings_panel.document_layout();
929942
let Some(canvas) = appwindow.active_tab_canvas() else {
930943
return;
@@ -944,14 +957,18 @@ impl RnSettingsPanel {
944957
}
945958
));
946959

960+
imp.doc_background_patterns_row.set_sensitive(false);
947961
imp.doc_background_patterns_row
948962
.get()
949963
.connect_selected_item_notify(clone!(
950964
#[weak(rename_to=settings_panel)]
951965
self,
952966
#[weak]
953967
appwindow,
954-
move |_| {
968+
move |row| {
969+
if !row.get_sensitive() {
970+
return;
971+
}
955972
let pattern = settings_panel.background_pattern();
956973
let Some(canvas) = appwindow.active_tab_canvas() else {
957974
return;
@@ -1030,11 +1047,15 @@ impl RnSettingsPanel {
10301047
}
10311048
));
10321049

1050+
imp.doc_background_pattern_color_button.set_sensitive(false);
10331051
imp.doc_background_pattern_color_button
10341052
.connect_rgba_notify(clone!(
10351053
#[weak]
10361054
appwindow,
10371055
move |button| {
1056+
if !button.get_sensitive() {
1057+
return;
1058+
}
10381059
let Some(canvas) = appwindow.active_tab_canvas() else {
10391060
return;
10401061
};
@@ -1058,6 +1079,8 @@ impl RnSettingsPanel {
10581079
}
10591080
));
10601081

1082+
imp.doc_background_pattern_width_unitentry
1083+
.set_sensitive(false);
10611084
imp.doc_background_pattern_width_unitentry
10621085
.get()
10631086
.connect_notify_local(
@@ -1066,6 +1089,9 @@ impl RnSettingsPanel {
10661089
#[weak]
10671090
appwindow,
10681091
move |unit_entry, _| {
1092+
if !unit_entry.get_sensitive() {
1093+
return;
1094+
}
10691095
let Some(canvas) = appwindow.active_tab_canvas() else {
10701096
return;
10711097
};
@@ -1092,6 +1118,8 @@ impl RnSettingsPanel {
10921118
),
10931119
);
10941120

1121+
imp.doc_background_pattern_height_unitentry
1122+
.set_sensitive(false);
10951123
imp.doc_background_pattern_height_unitentry
10961124
.get()
10971125
.connect_notify_local(
@@ -1100,6 +1128,9 @@ impl RnSettingsPanel {
11001128
#[weak]
11011129
appwindow,
11021130
move |unit_entry, _| {
1131+
if !unit_entry.get_sensitive() {
1132+
return;
1133+
}
11031134
let Some(canvas) = appwindow.active_tab_canvas() else {
11041135
return;
11051136
};
@@ -1144,12 +1175,17 @@ impl RnSettingsPanel {
11441175
}
11451176
));
11461177

1178+
imp.background_pattern_invert_color_button
1179+
.set_sensitive(false);
11471180
imp.background_pattern_invert_color_button
11481181
.get()
11491182
.connect_clicked(clone!(
11501183
#[weak]
11511184
appwindow,
1152-
move |_| {
1185+
move |button| {
1186+
if !button.get_sensitive() {
1187+
return;
1188+
}
11531189
let Some(canvas) = appwindow.active_tab_canvas() else {
11541190
return;
11551191
};
@@ -1184,6 +1220,26 @@ impl RnSettingsPanel {
11841220
));
11851221
}
11861222

1223+
// All relevant buttons are set as sensitive : false upon startup
1224+
// until the first tab is added. This way setting the correct values
1225+
// in the doc part of the settings won't send back a widget flag
1226+
// that modifies the store
1227+
pub fn activate_doc_settings_buttons(&self) {
1228+
let imp = self.imp();
1229+
imp.doc_show_format_borders_row.set_sensitive(true);
1230+
imp.doc_format_border_color_button.set_sensitive(true);
1231+
imp.doc_background_color_button.set_sensitive(true);
1232+
imp.doc_document_layout_row.set_sensitive(true);
1233+
imp.doc_background_patterns_row.set_sensitive(true);
1234+
imp.doc_background_pattern_color_button.set_sensitive(true);
1235+
imp.doc_background_pattern_width_unitentry
1236+
.set_sensitive(true);
1237+
imp.doc_background_pattern_height_unitentry
1238+
.set_sensitive(true);
1239+
imp.background_pattern_invert_color_button
1240+
.set_sensitive(true);
1241+
}
1242+
11871243
fn setup_shortcuts(&self, appwindow: &RnAppWindow) {
11881244
let imp = self.imp();
11891245
let penshortcut_stylus_button_primary_row = imp.penshortcut_stylus_button_primary_row.get();

crates/rnote-ui/src/sidebar.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,10 @@ impl RnSidebar {
124124
}
125125
));
126126
}
127+
128+
pub(crate) fn activate_doc_settings_buttons(&self) {
129+
let imp = self.imp();
130+
131+
imp.settings_panel.get().activate_doc_settings_buttons();
132+
}
127133
}

0 commit comments

Comments
 (0)