Skip to content

Commit

Permalink
Fix several crashes and radiobuttons
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Apr 28, 2023
1 parent 57c4478 commit c6d84cb
Show file tree
Hide file tree
Showing 17 changed files with 417 additions and 282 deletions.
531 changes: 308 additions & 223 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,33 @@ repository = "https://github.com/qarmin/szyszka"
rust-version = "1.65.0"

[dependencies]
gdk4 = "0.6.0"
gio = "0.17.0"
glib = "0.17.0"
gdk4 = "0.6.3"
gio = "0.17.9"
glib = "0.17.9"

# For checking path
walkdir = "2.3.2"
walkdir = "2.3.3"

humansize = "2.1.3"
chrono = "0.4.23"
chrono = "0.4.24"

# For opening files
open = "3.2.0"
open = "4.1.0"

# For slugs
slugmin = "1.0.2"

# Language
i18n-embed = { version = "0.13.8", features = ["fluent-system", "desktop-requester"] }
i18n-embed-fl = "0.6.5"
rust-embed = "6.4.2"
once_cell = "1.17.0"
i18n-embed-fl = "0.6.6"
rust-embed = "6.6.1"
once_cell = "1.17.1"

[dependencies.gtk4]
version = "0.6.0"
version = "0.6.6"
default-features = false # just in case
features = ["v4_6"]

# Optimize all dependencies except application/workspaces, even in debug builds
[profile.dev.package."*"]
opt-level = 3
4 changes: 4 additions & 0 deletions src/class_dialog_rule_add_number.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use gtk4::prelude::CheckButtonExt;

#[derive(Clone)]
pub struct GuiAddNumber {
pub check_button_add_number_before_name: gtk4::CheckButton,
Expand All @@ -13,6 +15,8 @@ impl GuiAddNumber {
let check_button_add_number_before_name: gtk4::CheckButton = builder.object("check_button_add_number_before_name").unwrap();
let check_button_add_number_after_name: gtk4::CheckButton = builder.object("check_button_add_number_after_name").unwrap();

check_button_add_number_after_name.set_group(Some(&check_button_add_number_before_name));

let entry_add_number_start_number: gtk4::Entry = builder.object("entry_add_number_start_number").unwrap();
let entry_add_number_step: gtk4::Entry = builder.object("entry_add_number_step").unwrap();
let entry_add_number_zeros: gtk4::Entry = builder.object("entry_add_number_zeros").unwrap();
Expand Down
4 changes: 4 additions & 0 deletions src/class_dialog_rule_add_text.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use gtk4::prelude::*;

#[derive(Clone)]
pub struct GuiAddText {
pub check_button_add_text_before_name: gtk4::CheckButton,
Expand All @@ -11,6 +13,8 @@ impl GuiAddText {
let check_button_add_text_before_name: gtk4::CheckButton = builder.object("check_button_add_text_before_name").unwrap();
let check_button_add_text_after_name: gtk4::CheckButton = builder.object("check_button_add_text_after_name").unwrap();

check_button_add_text_before_name.set_group(Some(&check_button_add_text_after_name));

let entry_add_text_text_to_add: gtk4::Entry = builder.object("entry_add_text_text_to_add").unwrap();

Self {
Expand Down
9 changes: 5 additions & 4 deletions src/class_dialog_rule_normalize.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use gtk4::prelude::*;
use gtk4::CheckButton;

#[derive(Clone)]
pub struct GuiNormalize {
pub check_button_normalize_everything: gtk4::CheckButton,
pub check_button_normalize_partial: gtk4::CheckButton,
pub check_button_normalize_everything: CheckButton,
pub check_button_normalize_partial: CheckButton,
}

impl GuiNormalize {
pub fn create_from_builder(builder: &gtk4::Builder) -> Self {
let check_button_normalize_everything: gtk4::CheckButton = builder.object("check_button_normalize_everything").unwrap();
let check_button_normalize_partial: gtk4::CheckButton = builder.object("check_button_normalize_partial").unwrap();
let check_button_normalize_everything: CheckButton = builder.object("check_button_normalize_everything").unwrap();
let check_button_normalize_partial: CheckButton = builder.object("check_button_normalize_partial").unwrap();

check_button_normalize_partial.set_group(Some(&check_button_normalize_everything));

Expand Down
5 changes: 5 additions & 0 deletions src/class_dialog_rule_purge.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use gtk4::prelude::*;

#[derive(Clone)]
pub struct GuiPurge {
pub check_button_purge_name: gtk4::CheckButton,
Expand All @@ -11,6 +13,9 @@ impl GuiPurge {
let check_button_purge_extension: gtk4::CheckButton = builder.object("check_button_purge_extension").unwrap();
let check_button_purge_both: gtk4::CheckButton = builder.object("check_button_purge_both").unwrap();

check_button_purge_both.set_group(Some(&check_button_purge_name));
check_button_purge_extension.set_group(Some(&check_button_purge_name));

Self {
check_button_purge_name,
check_button_purge_extension,
Expand Down
7 changes: 7 additions & 0 deletions src/class_dialog_rule_replace.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use gtk4::prelude::*;

#[derive(Clone)]
pub struct GuiReplace {
pub check_button_replace_name: gtk4::CheckButton,
Expand All @@ -17,12 +19,17 @@ impl GuiReplace {
let check_button_replace_extension: gtk4::CheckButton = builder.object("check_button_replace_extension").unwrap();
let check_button_replace_both: gtk4::CheckButton = builder.object("check_button_replace_both").unwrap();

check_button_replace_extension.set_group(Some(&check_button_replace_name));
check_button_replace_both.set_group(Some(&check_button_replace_name));

let entry_replace_text_to_remove: gtk4::Entry = builder.object("entry_replace_text_to_remove").unwrap();
let entry_replace_text_to_change: gtk4::Entry = builder.object("entry_replace_text_to_change").unwrap();

let check_button_replace_case_sensitive: gtk4::CheckButton = builder.object("check_button_replace_case_sensitive").unwrap();
let check_button_replace_case_insensitive: gtk4::CheckButton = builder.object("check_button_replace_case_insensitive").unwrap();

check_button_replace_case_sensitive.set_group(Some(&check_button_replace_case_insensitive));

Self {
check_button_replace_name,
check_button_replace_extension,
Expand Down
7 changes: 7 additions & 0 deletions src/class_dialog_rule_size_letters.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use gtk4::prelude::*;

#[derive(Clone)]
pub struct GuiSizeLetters {
pub check_button_letters_type_uppercase: gtk4::CheckButton,
Expand All @@ -13,10 +15,15 @@ impl GuiSizeLetters {
let check_button_letters_type_uppercase: gtk4::CheckButton = builder.object("check_button_letters_type_uppercase").unwrap();
let check_button_letters_type_lowercase: gtk4::CheckButton = builder.object("check_button_letters_type_lowercase").unwrap();

check_button_letters_type_lowercase.set_group(Some(&check_button_letters_type_uppercase));

let check_button_letters_usage_name: gtk4::CheckButton = builder.object("check_button_letters_usage_name").unwrap();
let check_button_letters_usage_extension: gtk4::CheckButton = builder.object("check_button_letters_usage_extension").unwrap();
let check_button_letters_usage_both: gtk4::CheckButton = builder.object("check_button_letters_usage_both").unwrap();

check_button_letters_usage_extension.set_group(Some(&check_button_letters_usage_name));
check_button_letters_usage_both.set_group(Some(&check_button_letters_usage_name));

Self {
check_button_letters_type_uppercase,
check_button_letters_type_lowercase,
Expand Down
4 changes: 3 additions & 1 deletion src/example_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ pub fn update_examples(window_rules: &GuiDialogRules, notebook_number: Option<u3
let text_to_change: String = window_rules.entry_example_before.text().to_string();
let label_example_after = window_rules.label_example_after.clone();

let single_rule = read_rule_from_window(window_rules, notebook_number);
let Some(single_rule) = read_rule_from_window(window_rules, notebook_number) else {
return;
};

let mut all_rules = Rules::new();
all_rules.rules.push(single_rule);
Expand Down
4 changes: 1 addition & 3 deletions src/gui_connection/connect_add_files_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ pub fn connect_add_files_button(gui_data: &GuiData) {

for file_entry in &folder {
let (path, name) = split_path(file_entry);
let full_name = if let Some(t) = file_entry.to_str() {
t
} else {
let Some(full_name) = file_entry.to_str() else {
println!("Failed to read name of {file_entry:?} (some characters may be missing in this name)");
continue;
};
Expand Down
8 changes: 3 additions & 5 deletions src/gui_connection/connect_add_folders_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn connect_add_folders_button(gui_data: &GuiData) {
if check_folders_inside {
if ignore_folders {
for folder in folders_to_check {
for entry in WalkDir::new(folder).max_depth(9999).into_iter().filter_map(std::result::Result::ok) {
for entry in WalkDir::new(folder).max_depth(9999).into_iter().filter_map(Result::ok) {
if let Ok(metadata) = entry.metadata() {
if metadata.is_file() {
new_entries.push(entry.path().to_path_buf());
Expand All @@ -111,7 +111,7 @@ pub fn connect_add_folders_button(gui_data: &GuiData) {
}
} else {
for folder in folders_to_check {
for entry in WalkDir::new(folder).max_depth(9999).into_iter().filter_map(std::result::Result::ok) {
for entry in WalkDir::new(folder).max_depth(9999).into_iter().filter_map(Result::ok) {
new_entries.push(entry.path().to_path_buf());
}
}
Expand All @@ -135,9 +135,7 @@ pub fn connect_add_folders_button(gui_data: &GuiData) {

for file_entry in &folders {
let (path, name) = split_path(file_entry);
let full_name = if let Some(t) = file_entry.to_str() {
t
} else {
let Some(full_name) = file_entry.to_str() else {
println!("Failed to read name of {file_entry:?} (some characters may be missing in this name)");
continue;
};
Expand Down
4 changes: 3 additions & 1 deletion src/gui_connection/connect_rule_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ pub fn connect_rule_add(gui_data: &GuiData) {
let mut rule = rules.borrow_mut();
let rule = &mut *rule;

let single_rule = read_rule_from_window(&window_rules, None);
let Some(single_rule) = read_rule_from_window(&window_rules, None) else {
return;
};

if let Some(edit_mode) = rule.edit_mode {
rule.rules[edit_mode].rule_type = single_rule.rule_type;
Expand Down
9 changes: 3 additions & 6 deletions src/gui_connection/connect_rule_buttons_modify_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ pub fn connect_rule_modify_one_down(gui_data: &GuiData) {
break;
}

if !list_store.iter_next(&previous_iter) {
panic!();
}
assert!(list_store.iter_next(&previous_iter));
}

current_iter = previous_iter;
Expand Down Expand Up @@ -272,9 +270,8 @@ pub fn connect_rule_modify_edit(gui_data: &GuiData) {
break;
}

if !model.iter_next(&iter) {
panic!();
}
assert!(model.iter_next(&iter));

item_number += 1;
}

Expand Down
43 changes: 34 additions & 9 deletions src/gui_connection/connect_select_records.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use gtk4::prelude::*;
use gtk4::TreeIter;
use gtk4::{ResponseType, TreeIter};

use crate::gui_data::GuiData;
use crate::help_function::{get_all_boxes_from_widget, get_list_store_from_tree_view, regex_check, ColumnsResults};
Expand Down Expand Up @@ -143,7 +143,10 @@ pub fn connect_select_custom(gui_data: &GuiData) {
// Accept Dialog
{
let window_main = gui_data.window_main.clone();
let confirmation_dialog_delete = gtk4::Dialog::with_buttons(Some("Select custom"), Some(&window_main), gtk4::DialogFlags::MODAL, &[("Ok", gtk4::ResponseType::Ok), ("Close", gtk4::ResponseType::Cancel)]);
let confirmation_dialog_delete = gtk4::Dialog::builder().title("Select custom").modal(true).transient_for(&window_main).build();
confirmation_dialog_delete.add_button("Ok", ResponseType::Ok);
confirmation_dialog_delete.add_button("Close", ResponseType::Cancel);

let label: gtk4::Label = gtk4::Label::new(Some("Usage: */folder-nr*/* or name-version-*.txt"));

let radio_path = gtk4::CheckButton::with_label("Path");
Expand All @@ -153,6 +156,14 @@ pub fn connect_select_custom(gui_data: &GuiData) {
let radio_future_name_path = gtk4::CheckButton::with_label("Path + Future Name");
let radio_is_dir = gtk4::CheckButton::with_label("Directory/File");

radio_current_name.set_group(Some(&radio_path));
radio_future_name.set_group(Some(&radio_path));
radio_current_name_path.set_group(Some(&radio_path));
radio_future_name_path.set_group(Some(&radio_path));
radio_is_dir.set_group(Some(&radio_path));

radio_path.set_active(true);

let entry_path = gtk4::Entry::new();
let entry_current_name = gtk4::Entry::new();
let entry_future_name = gtk4::Entry::new();
Expand Down Expand Up @@ -187,15 +198,16 @@ pub fn connect_select_custom(gui_data: &GuiData) {
grid.attach(&entry_future_name_path, 1, 5, 1, 1);
grid.attach(&check_button_is_dir, 1, 6, 1, 1);

get_all_boxes_from_widget(&confirmation_dialog_delete)[0].clone().append(&grid);
// TODO Why 3? This may brake newer versions
get_all_boxes_from_widget(&confirmation_dialog_delete)[3].clone().append(&grid);

confirmation_dialog_delete.show();

let tree_view = tree_view.clone();
confirmation_dialog_delete.connect_response(move |_chooser, response_type| {
confirmation_dialog_delete.connect_response(move |chooser, response_type| {
let wildcard_type: WildcardType;
let wildcard: String;
if response_type == gtk4::ResponseType::Ok {
if response_type == ResponseType::Ok {
if radio_path.is_active() {
wildcard_type = WildcardType::Path;
wildcard = entry_path.text().to_string();
Expand Down Expand Up @@ -283,6 +295,8 @@ pub fn connect_select_custom(gui_data: &GuiData) {
}
}
}

chooser.hide();
});
}
});
Expand All @@ -301,7 +315,9 @@ pub fn connect_unselect_custom(gui_data: &GuiData) {
// Accept Dialog
{
let window_main = gui_data.window_main.clone();
let confirmation_dialog_delete = gtk4::Dialog::with_buttons(Some("Unselect custom"), Some(&window_main), gtk4::DialogFlags::MODAL, &[("Ok", gtk4::ResponseType::Ok), ("Close", gtk4::ResponseType::Cancel)]);
let confirmation_dialog_delete = gtk4::Dialog::builder().title("Unselect custom").modal(true).transient_for(&window_main).build();
confirmation_dialog_delete.add_button("Ok", ResponseType::Ok);
confirmation_dialog_delete.add_button("Close", ResponseType::Cancel);
let label: gtk4::Label = gtk4::Label::new(Some("Usage: */folder-nr*/* or name-version-*.txt"));

let radio_path = gtk4::CheckButton::with_label("Path");
Expand All @@ -311,6 +327,14 @@ pub fn connect_unselect_custom(gui_data: &GuiData) {
let radio_future_name_path = gtk4::CheckButton::with_label("Path + Future Name");
let radio_is_dir = gtk4::CheckButton::with_label("Directory/File");

radio_current_name.set_group(Some(&radio_path));
radio_future_name.set_group(Some(&radio_path));
radio_current_name_path.set_group(Some(&radio_path));
radio_future_name_path.set_group(Some(&radio_path));
radio_is_dir.set_group(Some(&radio_path));

radio_path.set_active(true);

let entry_path = gtk4::Entry::new();
let entry_current_name = gtk4::Entry::new();
let entry_future_name = gtk4::Entry::new();
Expand Down Expand Up @@ -345,13 +369,13 @@ pub fn connect_unselect_custom(gui_data: &GuiData) {
grid.attach(&entry_future_name_path, 1, 5, 1, 1);
grid.attach(&check_button_is_dir, 1, 6, 1, 1);

get_all_boxes_from_widget(&confirmation_dialog_delete)[0].clone().append(&grid);
get_all_boxes_from_widget(&confirmation_dialog_delete)[3].clone().append(&grid); // TODO may broke

confirmation_dialog_delete.show();

let tree_view = tree_view.clone();
confirmation_dialog_delete.connect_response(move |_, response| {
if response == gtk4::ResponseType::Ok {
confirmation_dialog_delete.connect_response(move |dialog, response| {
if response == ResponseType::Ok {
let wildcard: String;
let wildcard_type: WildcardType;

Expand Down Expand Up @@ -442,6 +466,7 @@ pub fn connect_unselect_custom(gui_data: &GuiData) {
}
}
}
dialog.hide();
});
}
});
Expand Down
Loading

0 comments on commit c6d84cb

Please sign in to comment.