Skip to content

Commit

Permalink
separated search/replace dialog code from action after the ok is clic…
Browse files Browse the repository at this point in the history
…ked so that will be possible to make the dialog non modal (#2426)
  • Loading branch information
giuspen committed Jan 20, 2024
1 parent 0fd34b5 commit e333c67
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/ct/ct_actions.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ct_actions.h
*
* Copyright 2009-2023
* Copyright 2009-2024
* Giuseppe Penone <[email protected]>
* Evgenii Gurianov <https://github.com/txe>
*
Expand Down Expand Up @@ -255,6 +255,8 @@ class CtActions
// helpers for find actions
void find_again_iter(const bool fromIterativeDialog);
void find_back_iter(const bool fromIterativeDialog);
void find_in_selected_node_ok_clicked();
void find_in_multiple_nodes_ok_clicked();

private:
// helper for view actions
Expand Down
37 changes: 23 additions & 14 deletions src/ct/ct_actions_find.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ct_actions_find.cc
*
* Copyright 2009-2023
* Copyright 2009-2024
* Giuseppe Penone <[email protected]>
* Evgenii Gurianov <https://github.com/txe>
*
Expand Down Expand Up @@ -65,10 +65,12 @@ void CtActions::find_in_selected_node()
_s_state.curr_find_pattern = pattern;
_s_state.curr_find_type = CtCurrFindType::SingleNode;
}
else {
pattern = _s_state.curr_find_pattern;
}
Glib::RefPtr<Glib::Regex> re_pattern = _create_re_pattern(pattern);
find_in_selected_node_ok_clicked();
}

void CtActions::find_in_selected_node_ok_clicked()
{
Glib::RefPtr<Glib::Regex> re_pattern = _create_re_pattern(_s_state.curr_find_pattern);
if (not re_pattern) return;

bool forward = _s_options.direction_fw;
Expand All @@ -90,6 +92,8 @@ void CtActions::find_in_selected_node()
}
CtTreeIter::clear_hit_exclusion_from_search();

Glib::RefPtr<Gtk::TextBuffer> curr_buffer = _pCtMainWin->get_text_view().get_buffer();

while (_parse_node_content_iter(_pCtMainWin->curr_tree_iter(),
curr_buffer,
re_pattern,
Expand All @@ -104,7 +108,7 @@ void CtActions::find_in_selected_node()
if (0 == _s_state.matches_num) {
CtDialogs::no_matches_dialog(_pCtMainWin,
"'" + _s_options.str_find + "' - 0 " + _("Matches"),
str::format(_("<b>The pattern '%s' was not found</b>"), str::xml_escape(pattern)));
str::format(_("<b>The pattern '%s' was not found</b>"), str::xml_escape(_s_state.curr_find_pattern)));
}
else if (all_matches) {
CtDialogs::match_dialog(_s_options.str_find, _pCtMainWin, _s_state);
Expand All @@ -127,9 +131,6 @@ void CtActions::find_in_multiple_nodes()

CtTextView& ctTextView = _pCtMainWin->get_text_view();
Glib::RefPtr<Gtk::TextBuffer> curr_buffer = ctTextView.get_buffer();
CtStatusBar& ctStatusBar = _pCtMainWin->get_status_bar();
CtTreeStore& ctTreeStore = _pCtMainWin->get_tree_store();
CtTreeView& ctTreeView = _pCtMainWin->get_tree_view();

Glib::ustring title;
Glib::ustring pattern;
Expand All @@ -155,12 +156,20 @@ void CtActions::find_in_multiple_nodes()
return;
}
}
else {
pattern = _s_state.curr_find_pattern;
}
Glib::RefPtr<Glib::Regex> re_pattern = _create_re_pattern(pattern);
find_in_multiple_nodes_ok_clicked();
}

void CtActions::find_in_multiple_nodes_ok_clicked()
{
Glib::RefPtr<Glib::Regex> re_pattern = _create_re_pattern(_s_state.curr_find_pattern);
if (not re_pattern) return;

CtTextView& ctTextView = _pCtMainWin->get_text_view();
Glib::RefPtr<Gtk::TextBuffer> curr_buffer = ctTextView.get_buffer();
CtStatusBar& ctStatusBar = _pCtMainWin->get_status_bar();
CtTreeStore& ctTreeStore = _pCtMainWin->get_tree_store();
CtTreeView& ctTreeView = _pCtMainWin->get_tree_view();

CtTreeIter starting_tree_iter = _pCtMainWin->curr_tree_iter();
Gtk::TreeIter node_iter;
int current_cursor_pos = curr_buffer->property_cursor_position();
Expand Down Expand Up @@ -252,7 +261,7 @@ void CtActions::find_in_multiple_nodes()
if (not _s_state.matches_num) {
CtDialogs::no_matches_dialog(_pCtMainWin,
"'" + _s_options.str_find + "' - 0 " + _("Matches"),
str::format(_("<b>The pattern '%s' was not found</b>"), str::xml_escape(pattern)));
str::format(_("<b>The pattern '%s' was not found</b>"), str::xml_escape(_s_state.curr_find_pattern)));
}
else {
if (all_matches) {
Expand Down

0 comments on commit e333c67

Please sign in to comment.