Beispiel #1
0
void FindInFilesPanel::update_replace_buttons() {

	String text = get_replace_text();
	bool disabled = text.empty() || _finder->is_searching();

	_replace_all_button->set_disabled(disabled);
}
Beispiel #2
0
void FindInFilesPanel::_on_replace_all_clicked() {

	String replace_text = get_replace_text();

	PoolStringArray modified_files;

	for (Map<String, TreeItem *>::Element *E = _file_items.front(); E; E = E->next()) {

		TreeItem *file_item = E->value();
		String fpath = file_item->get_metadata(0);

		Vector<Result> locations;
		for (TreeItem *item = file_item->get_children(); item; item = item->get_next()) {

			if (!item->is_checked(0))
				continue;

			Map<TreeItem *, Result>::Element *F = _result_items.find(item);
			ERR_FAIL_COND(F == NULL);
			locations.push_back(F->value());
		}

		if (locations.size() != 0) {
			// Results are sorted by file, so we can batch replaces
			apply_replaces_in_file(fpath, locations, replace_text);
			modified_files.append(fpath);
		}
	}

	// Hide replace bar so we can't trigger the action twice without doing a new search
	_replace_container->hide();

	emit_signal(SIGNAL_FILES_MODIFIED, modified_files);
}
Beispiel #3
0
void FindReplaceBar::_replace() {

	if (result_line != -1 && result_col != -1) {
		text_edit->begin_complex_operation();

		text_edit->select(result_line, result_col, result_line, result_col + get_search_text().length());
		text_edit->insert_text_at_cursor(get_replace_text());

		text_edit->end_complex_operation();
	}

	search_current();
}
Beispiel #4
0
bool Gobby::FindDialog::replace_all()
{
	// TODO: Add helper function to get textsessionview? Maybe even add
	// to Folder?
	SessionView* view = m_folder->get_current_document();
	TextSessionView* text_view = dynamic_cast<TextSessionView*>(view);
	g_assert(text_view != NULL);

	GtkTextIter begin;
	GtkTextBuffer* buffer = GTK_TEXT_BUFFER(text_view->get_text_buffer());
	gtk_text_buffer_get_start_iter(buffer, &begin);

	unsigned int replace_count = 0;
	GtkTextIter match_start, match_end;
	while(find_range(&begin, NULL, SEARCH_FORWARD,
	                 &match_start, &match_end))
	{
		Glib::ustring replace_text = get_replace_text();
		gtk_text_buffer_delete(buffer, &match_start, &match_end);
		gtk_text_buffer_insert(buffer, &match_start,
		                       replace_text.c_str(),
		                       replace_text.bytes());

		++ replace_count;
		begin = match_start;
	}

	Glib::ustring message;
	bool result;

	if(replace_count == 0)
	{
		message = _("No occurrence has been replaced");
		result = false;
	}
	else
	{
		message = Glib::ustring::compose(
			ngettext("%1 occurrence has been replaced",
			         "%1 occurrences have been replaced",
			         replace_count), replace_count);
		result = true;
	}

	m_status_bar->add_info_message(message, 5);
	return result;
}
Beispiel #5
0
void FindInFilesPanel::_on_replace_all_clicked() {

	String replace_text = get_replace_text();
	ERR_FAIL_COND(replace_text.empty());

	String last_fpath;
	PoolIntArray locations;
	PoolStringArray modified_files;

	for (int i = 0; i < _results_display->get_item_count(); ++i) {

		Array meta = _results_display->get_item_metadata(i);

		String fpath = meta[0];

		// Results are sorted by file, so we can batch replaces
		if (fpath != last_fpath) {
			if (locations.size() != 0) {
				apply_replaces_in_file(last_fpath, locations, replace_text);
				modified_files.append(last_fpath);
				locations.resize(0);
			}
		}

		locations.append(meta[1]); // line_number
		locations.append(meta[2]); // begin
		locations.append(meta[3]); // end

		last_fpath = fpath;
	}

	if (locations.size() != 0) {
		apply_replaces_in_file(last_fpath, locations, replace_text);
		modified_files.append(last_fpath);
	}

	// Hide replace bar so we can't trigger the action twice without doing a new search
	set_with_replace(false);

	emit_signal(SIGNAL_FILES_MODIFIED, modified_files);
}
Beispiel #6
0
bool Gobby::FindDialog::replace()
{
	SessionView* view = m_folder->get_current_document();
	TextSessionView* text_view = dynamic_cast<TextSessionView*>(view);
	g_assert(text_view != NULL);

	// Get selected string
	Glib::ustring sel_str = text_view->get_selected_text();
	Glib::ustring find_str = get_find_text();

	// Lowercase both if we are comparing insensitive
	if(!m_check_case->get_active() )
	{
		sel_str = sel_str.casefold();
		find_str = find_str.casefold();
	}

	// Replace them if they are the same
	if(sel_str == find_str)
	{
		GtkTextBuffer* buffer =
			GTK_TEXT_BUFFER(text_view->get_text_buffer());

		// Replace occurrence
		Glib::ustring replace_text = get_replace_text();
		gtk_text_buffer_delete_selection(buffer, TRUE, TRUE);
		gtk_text_buffer_insert_at_cursor(buffer, replace_text.c_str(),
		                                 replace_text.bytes());

		// and find the next
		find_and_select(NULL, get_direction());
		return true;
	}
	else
	{
		// Search the first occurrence
		return find();
	}
}
Beispiel #7
0
void FindReplaceDialog::_replace() {

	if (is_replace_all_mode()) {

		//line as x so it gets priority in comparison, column as y
		Point2i orig_cursor(text_edit->cursor_get_line(),text_edit->cursor_get_column());
		Point2i prev_match=Point2(-1,-1);


		bool selection_enabled = text_edit->is_selection_active();
		Point2i selection_begin,selection_end;
		if (selection_enabled) {
			selection_begin=Point2i(text_edit->get_selection_from_line(),text_edit->get_selection_from_column());
			selection_end=Point2i(text_edit->get_selection_to_line(),text_edit->get_selection_to_column());
		}
		int vsval = text_edit->get_v_scroll();
		//int hsval = text_edit->get_h_scroll();

		text_edit->cursor_set_line(0);
		text_edit->cursor_set_column(0);

		int rc=0;

		while(_search()) {

			if (!text_edit->is_selection_active()) {
				//search selects
				break;
			}

			//replace area
			Point2i match_from(text_edit->get_selection_from_line(),text_edit->get_selection_from_column());
			Point2i match_to(text_edit->get_selection_to_line(),text_edit->get_selection_to_column());

			if (match_from < prev_match)
				break; //done

			prev_match=match_to;

			if (selection_enabled && is_replace_selection_only()) {

				if (match_from<selection_begin || match_to>selection_end)
					continue;

				//replace but adjust selection bounds

				text_edit->insert_text_at_cursor(get_replace_text());
				if (match_to.x==selection_end.x)
					selection_end.y+=get_replace_text().length() - get_search_text().length();
			} else {
				//just replace
				text_edit->insert_text_at_cursor(get_replace_text());
			}
			rc++;

		}
		//restore editor state (selection, cursor, scroll)
		text_edit->cursor_set_line(orig_cursor.x);
		text_edit->cursor_set_column(orig_cursor.y);

		if (selection_enabled && is_replace_selection_only()) {
			//reselect
			text_edit->select(selection_begin.x,selection_begin.y,selection_end.x,selection_end.y);
		} else {
			text_edit->deselect();
		}

		text_edit->set_v_scroll(vsval);
//		text_edit->set_h_scroll(hsval);
		error_label->set_text("Replaced "+itos(rc)+" ocurrence(s).");


		//hide();
	} else {

		if (text_edit->get_selection_text()==get_search_text()) {

			text_edit->insert_text_at_cursor(get_replace_text());
		}

		_search();
	}

}
Beispiel #8
0
void FindReplaceBar::_replace_all() {

	// line as x so it gets priority in comparison, column as y
	Point2i orig_cursor(text_edit->cursor_get_line(), text_edit->cursor_get_column());
	Point2i prev_match = Point2(-1, -1);

	bool selection_enabled = text_edit->is_selection_active();
	Point2i selection_begin, selection_end;
	if (selection_enabled) {
		selection_begin = Point2i(text_edit->get_selection_from_line(), text_edit->get_selection_from_column());
		selection_end = Point2i(text_edit->get_selection_to_line(), text_edit->get_selection_to_column());
	}

	int vsval = text_edit->get_v_scroll();

	text_edit->cursor_set_line(0);
	text_edit->cursor_set_column(0);

	String replace_text = get_replace_text();
	int search_text_len = get_search_text().length();

	int rc = 0;

	replace_all_mode = true;

	text_edit->begin_complex_operation();

	while (search_next()) {

		// replace area
		Point2i match_from(result_line, result_col);
		Point2i match_to(result_line, result_col + search_text_len);

		if (match_from < prev_match)
			break; // done

		prev_match = Point2i(result_line, result_col + replace_text.length());

		text_edit->select(result_line, result_col, result_line, match_to.y);

		if (selection_enabled && is_selection_only()) {

			if (match_from < selection_begin || match_to > selection_end)
				continue;

			// replace but adjust selection bounds
			text_edit->insert_text_at_cursor(replace_text);
			if (match_to.x == selection_end.x)
				selection_end.y += replace_text.length() - search_text_len;
		} else {
			// just replace
			text_edit->insert_text_at_cursor(replace_text);
		}

		rc++;
	}

	text_edit->end_complex_operation();

	replace_all_mode = false;

	// restore editor state (selection, cursor, scroll)
	text_edit->cursor_set_line(orig_cursor.x);
	text_edit->cursor_set_column(orig_cursor.y);

	if (selection_enabled && is_selection_only()) {
		// reselect
		text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y);
	} else {
		text_edit->deselect();
	}

	text_edit->set_v_scroll(vsval);
	set_error(vformat(TTR("Replaced %d occurrence(s)."), rc));
}