20#ifndef RULE_EDITOR_DIALOG_BASE_H
21#define RULE_EDITOR_DIALOG_BASE_H
23#include <wx/treectrl.h>
24#include <wx/srchctrl.h>
25#include <wx/bmpbuttn.h>
26#include <wx/splitter.h>
27#include <wx/scrolwin.h>
31#include <unordered_map>
75 wxTreeItemId aTreeItemId ) :
108 const wxSize& aInitialSize = wxDefaultSize );
251 wxTreeItemId aParentTreeItemId );
290 virtual void OnSave( wxCommandEvent& aEvent ) = 0;
292 virtual void OnCancel( wxCommandEvent& aEvent ) = 0;
294 bool Show(
bool show )
override;
315 wxTreeItemId aParentTreeItemId );
407 bool filterRuleTree(
const wxTreeItemId& aItem,
const wxString& aFilter );
423 void restoreRuleTree(
const wxTreeItemId& aParent,
const int& aNodeId );
433 wxTreeItemId aParentTreeItemId );
443 std::vector<RULE_TREE_NODE>& aResult );
452 wxTreeItemId aDestTreeItemId );
464 void onResize( wxSizeEvent& event );
466 void onClose( wxCloseEvent& aEvt );
502 std::unordered_map<int, std::tuple<wxString, std::vector<int>, wxTreeItemId>>
m_treeHistoryData;
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER, const wxString &name=wxDialogNameStr)
void populateRuleTreeCtrl(const std::vector< RULE_TREE_NODE > &aRuleTreeNodes, const RULE_TREE_NODE &aRuleTreeNode, wxTreeItemId aParentTreeItemId)
Populates the rule tree with nodes and their children.
void onRuleTreeItemSelectionChanged(wxTreeEvent &aEvent)
Updates action buttons based on the selected tree item.
void moveRuleTreeItemChildrensTooOnDrag(wxTreeItemId aSrcTreeItemId, wxTreeItemId aDestTreeItemId)
Recursively moves all child nodes of a source item to a destination during drag.
void DeleteRuleTreeItem(wxTreeItemId aItemId, const int &aNodeId)
Deletes a tree item and removes its corresponding node from history.
void onRuleTreeItemMouseMotion(wxMouseEvent &aEvent)
Handles drag motion to move the item along with the cursor.
wxTreeItemId m_draggedItem
void UpdateRuleTreeItemText(wxTreeItemId aItemId, wxString aItemText)
Updates the text of a specified rule tree item.
wxPanel * GetContentPanel()
Retrieves the current content panel.
void onNewRuleOptionClick(wxCommandEvent &aEvent)
Creates a new rule when the "New Rule" option is clicked.
wxTextCtrl * m_filterText
void onRuleTreeItemLeftDown(wxMouseEvent &aEvent)
Initiates drag operation for a tree item on mouse down.
void onMoveUpRuleOptionClick(wxCommandEvent &aEvent)
Moves a rule item up in the tree when "Move Up" is clicked.
virtual void RuleTreeItemSelectionChanged(RULE_TREE_ITEM_DATA *aCurrentRuleTreeItemData)=0
Pure virtual method to handle tree item selection changes.
void onClose(wxCloseEvent &aEvt)
bool Show(bool show) override
void SetModified()
Marks the dialog as modified, indicating unsaved changes.
void RefreshContentScrollArea()
Recalculates the scrolled content area's virtual size based on the current content panel's best size,...
wxBitmapButton * m_addRuleButton
void onMoveDownRuleOptionClick(wxCommandEvent &aEvent)
Moves a rule item down in the tree when "Move Down" is clicked.
void AppendNewRuleTreeItem(const RULE_TREE_NODE &aRuleTreeNode, wxTreeItemId aParentTreeItemId)
Adds a new rule tree item under the specified parent and updates the tree history.
void InitRuleTreeItems(const std::vector< RULE_TREE_NODE > &aRuleTreeNodes)
Initializes the rule tree by adding nodes, setting up the structure, and saving its state.
void saveRuleTreeState(const wxTreeItemId &aItem, const int &aNodeId=0)
Saves the state of a tree item to history.
static RULE_EDITOR_DIALOG_BASE * GetDialog(wxWindow *aWindow)
Static method to retrieve the rule editor dialog instance associated with a given window.
wxTreeItemId m_previousId
void onRuleTreeItemLeftUp(wxMouseEvent &aEvent)
Completes the drag operation on mouse release.
void onRuleTreeItemActivated(wxTreeEvent &aEvent)
Handles double-click activation of a tree item.
void SetContentPanel(wxPanel *aContentPanel)
Replaces the current content panel with a new one based on the selected constraint type.
virtual void OnSave(wxCommandEvent &aEvent)=0
wxTreeCtrl * m_ruleTreeCtrl
wxButton * m_cancelRuleButton
void OnCharHook(wxKeyEvent &aEvt) override
std::vector< RULE_TREE_NODE > m_defaultTreeItems
virtual void AddNewRule(RULE_TREE_ITEM_DATA *aRuleTreeItemData)=0
Pure virtual method to add a new rule to the tree.
wxButton * m_saveRuleButton
RULE_EDITOR_TREE_CONTEXT_OPT_ID
Enumeration representing the available context menu options for the rule editor tree.
void onDuplicateRuleOptionClick(wxCommandEvent &aEvent)
Duplicates the selected rule when "Duplicate Rule" is clicked.
wxScrolledWindow * m_scrolledContentWin
wxTreeCtrl * GetRuleTreeCtrl()
Gets the tree control used for displaying and managing rules.
void ClearModified()
Clears the modified flag, typically after saving.
bool m_enableDuplicateRule
RULE_TREE_ITEM_DATA * m_selectedData
void restoreRuleTree(const wxTreeItemId &aParent, const int &aNodeId)
Restores a tree item from history and appends it under a parent.
bool TransferDataToWindow() override
wxBitmapButton * m_deleteRuleButton
RULE_EDITOR_DIALOG_BASE(wxWindow *aParent, const wxString &aTitle, const wxSize &aInitialSize=wxDefaultSize)
friend class DIALOG_DRC_RULE_EDITOR
virtual void RemoveRule(int aNodeId)=0
Pure virtual method to remove a rule from the tree.
wxTreeItemId appendRuleTreeItem(const RULE_TREE_NODE &aRuleTreeNode, wxTreeItemId aParentTreeItemId)
Appends a new rule item to the tree.
std::unordered_map< int, std::tuple< wxString, std::vector< int >, wxTreeItemId > > m_treeHistoryData
void onResize(wxSizeEvent &event)
void onDeleteRuleOptionClick(wxCommandEvent &aEvent)
Deletes the selected rule when "Delete Rule" is clicked.
wxSearchCtrl * m_filterSearch
virtual std::vector< RULE_TREE_NODE > GetDefaultRuleTreeItems()=0
Pure virtual method to get the default rule tree items.
int m_defaultSashPosition
virtual void DuplicateRule(RULE_TREE_ITEM_DATA *aRuleTreeItemData)=0
Pure virtual method to duplicate an existing rule in the tree.
bool IsModified() const
Returns whether the dialog has unsaved changes.
wxTreeItemId GetPreviouslySelectedRuleTreeItemId()
Retrieves the previously selected rule tree item ID.
bool TransferDataFromWindow() override
~RULE_EDITOR_DIALOG_BASE() override
void onRuleTreeItemRightClick(wxTreeEvent &aEvent)
Handles right-click on a rule tree item to create a context menu.
void getRuleTreeChildNodes(const std::vector< RULE_TREE_NODE > &aNodes, int aParentId, std::vector< RULE_TREE_NODE > &aResult)
Retrieves child nodes of a given parent node.
wxBitmapButton * m_copyRuleButton
void onFilterSearch(wxCommandEvent &aEvent)
Applies filter to the rule tree based on the search string.
wxBitmapButton * m_moveTreeItemUpButton
wxSplitterWindow * m_splitter
virtual bool isEnabled(RULE_TREE_ITEM_DATA *aRuleTreeItemData, RULE_EDITOR_TREE_CONTEXT_OPT aOption)=0
Pure virtual method to verify if a context menu option for a rule tree item should be enabled.
virtual void UpdateRuleTypeTreeItemData(RULE_TREE_ITEM_DATA *aRuleTreeItemData)=0
Pure virtual method to update the rule tree item data.
void updateRuleTreeItemMoveOptionState()
Updates the state of move options (up/down) for the selected item.
wxDragImage * m_dragImage
RULE_TREE_ITEM_DATA * GetCurrentlySelectedRuleTreeItemData()
Retrieves the currently selected rule tree item data.
wxBoxSizer * m_buttonsSizer
virtual void OnCancel(wxCommandEvent &aEvent)=0
void updateRuleTreeActionButtonsState(RULE_TREE_ITEM_DATA *aRuleTreeItemData)
Updates the action buttons based on the current selection.
void finishInitialization()
void SetControlsEnabled(bool aEnable)
Enables or disables controls within the rule editor dialog.
bool filterRuleTree(const wxTreeItemId &aItem, const wxString &aFilter)
Recursively filters tree items to show only those matching the filter.
wxBitmapButton * m_moveTreeItemDownButton
A class representing additional data associated with a wxTree item.
void SetTreeItemId(wxTreeItemId aTreeItemId)
wxTreeItemId GetTreeItemId() const
wxTreeItemId m_treeItemId
void SetParentTreeItemId(wxTreeItemId aParentTreeItemId)
wxTreeItemId m_parentTreeItemId
wxTreeItemId GetParentTreeItemId() const
RULE_TREE_ITEM_DATA(int aNodeId, wxTreeItemId aParentTreeItemId, wxTreeItemId aTreeItemId)
A modified version of the wxInfoBar class that allows us to:
RULE_EDITOR_TREE_CONTEXT_OPT
Enumeration representing the available context menu options for the rule editor tree.
Structure representing a node in a rule tree, collection of this used for building the rule tree.
std::shared_ptr< RULE_EDITOR_DATA_BASE > m_nodeData
std::optional< int > m_nodeTypeMap
std::vector< RULE_TREE_NODE > m_childNodes