Skip to content

Commit

Permalink
#5697: Implement the copy filter functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Aug 8, 2021
1 parent 3ac4c73 commit a71c7c7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
84 changes: 47 additions & 37 deletions radiant/ui/filters/editor/FilterDialog.cpp
Expand Up @@ -249,50 +249,53 @@ void FilterDialog::onSave(wxCommandEvent& ev)
EndModal(wxID_OK);
}

void FilterDialog::onAddFilter(wxCommandEvent& ev)
void FilterDialog::showEditDialogForNewFilter(const FilterPtr& newFilter)
{
// Construct a new filter with an empty name (this indicates it has not been there before when saving)
FilterPtr workingCopy(new Filter("", false, false));
workingCopy->name = _("NewFilter");
// Instantiate a new editor, will block
auto* editor = new FilterEditor(*newFilter, this, false);

// Instantiate a new editor, will block
FilterEditor* editor = new FilterEditor(*workingCopy, this, false);
auto editorResult = editor->ShowModal();

int editorResult = editor->ShowModal();

editor->Destroy();
editor->Destroy();

if (editorResult != wxID_OK)
{
// User hit cancel, we're done
return;
}
if (editorResult != wxID_OK)
{
// User hit cancel, we're done
return;
}

if (workingCopy->rules.empty())
{
// Empty ruleset, notify user
IDialogPtr dialog = GlobalDialogManager().createMessageBox(_("Empty Filter"),
_("No rules defined for this filter, cannot insert."), ui::IDialog::MESSAGE_ERROR);
if (newFilter->rules.empty())
{
// Empty ruleset, notify user
auto dialog = GlobalDialogManager().createMessageBox(_("Empty Filter"),
_("No rules defined for this filter, cannot insert."), ui::IDialog::MESSAGE_ERROR);

dialog->run();
return;
}
dialog->run();
return;
}

std::pair<FilterMap::iterator, bool> result = _filters.insert(
FilterMap::value_type(workingCopy->name, workingCopy)
);
auto result = _filters.emplace(newFilter->name, newFilter);

if (!result.second)
{
// Empty ruleset, notify user
IDialogPtr dialog = GlobalDialogManager().createMessageBox(_("Name Conflict"),
_("Cannot add, filter with same name already exists."), ui::IDialog::MESSAGE_ERROR);
if (!result.second)
{
// Empty ruleset, notify user
auto dialog = GlobalDialogManager().createMessageBox(_("Name Conflict"),
_("Cannot add, filter with same name already exists."), ui::IDialog::MESSAGE_ERROR);

dialog->run();
return;
}
dialog->run();
return;
}

update();
update();
}

void FilterDialog::onAddFilter(wxCommandEvent& ev)
{
// Construct a new filter with an empty name (this indicates it has not been there before when saving)
auto newFilter = std::make_shared<Filter>("", false, false);
newFilter->name = _("NewFilter");

showEditDialogForNewFilter(newFilter);
}

void FilterDialog::onViewFilter(wxCommandEvent& ev)
Expand Down Expand Up @@ -403,10 +406,17 @@ void FilterDialog::onCopyFilter(wxCommandEvent& ev)
return; // not found or read-only
}

// TODO: Copy
// Construct a new filter with an empty name (this indicates it has not been there before when saving)
auto newFilter = std::make_shared<Filter>("", false, false);
newFilter->name = f->second->name + " " + _("Copy");

// Update all widgets
update();
// Copy all the rules
for (const auto& existingRule : f->second->rules)
{
newFilter->rules.push_back(existingRule);
}

showEditDialogForNewFilter(newFilter);
}

void FilterDialog::onFilterSelectionChanged(wxDataViewEvent& ev)
Expand Down
2 changes: 2 additions & 0 deletions radiant/ui/filters/editor/FilterDialog.h
Expand Up @@ -88,6 +88,8 @@ class FilterDialog :
void onDeleteFilter(wxCommandEvent& ev);
void onCopyFilter(wxCommandEvent& ev);

void showEditDialogForNewFilter(const FilterPtr& filter);

void onFilterSelectionChanged(wxDataViewEvent& ev);
};

Expand Down

0 comments on commit a71c7c7

Please sign in to comment.