Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxGUI/history: add pop-up command menu with an item for delete command from history #3310

Closed

Conversation

tmszi
Copy link
Member

@tmszi tmszi commented Dec 21, 2023

Add pop-up command menu with an item for delete command from history.

wxgui_add_popup_command_menu_with_delete_cmd_item

@tmszi tmszi added enhancement New feature or request GUI wxGUI related labels Dec 21, 2023
@tmszi tmszi added this to the 8.4.0 milestone Dec 21, 2023
@tmszi tmszi self-assigned this Dec 21, 2023
)[0]
self.showNotification.emit(message=_("Deleting <{}>").format(cmd))
try:
with open(history_path, "r+") as f:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest creating the general function in grassdb/history.py for deleting the entry from the history file (similar as read_history, update_history). Maybe update_history could be renamed to add_entry_to_history ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored update_history() func to add or delete command from the history file.

if self._confirmDialog(question, title=_("Delete command")) == wx.ID_YES:
history_path = get_current_mapset_gui_history_path()
if history_path:
del_line_number = self._model.model.GetIndexOfNode(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new method in history/tree.py?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added DeleteEntryFromHistory() method.

showTraceback=False,
)
return
self._model.CreateModel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just DeleteNode instead of creating the model from scratch. We could e.g. have two methods in the history/tree.py: renaming UpdateModel to AddEntryToModel and adding a new method DeleteEntryFromModel and we can decide which method to call according to some new "add" or "delete" flag in UpdateHistoryModelByCommand. Just idea. :-)

Copy link
Member Author

@tmszi tmszi Dec 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored UpdateModel() method to add/delete tree command node to/from model.

data=data,
)
else:
self.model.RemoveNode(node)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During my testing I investigate that RemoveNode() method of self.model = TreeModel(ModuleNode) instance not working as expected, node is not removed.

def RemoveNode(self, node):
"""Removes node. If node is root, removes root's children, root is kept."""
if node.parent:
node.parent.children.remove(node)
else:
# node is root
del node.children[:]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at the comment below.

@lindakarlovska
Copy link
Contributor

@tmszi I have created some changes and posted them as the PR into your fork.

I divided the logic of Add and Delete commands as I was also thinking that the Add signal will be much more complex in the future, so it makes sense to have it separately.

The problem with RemoveNode was that the node of the Tree differs from the node of the Model. It takes me quite a lot of time to figure that out - quite a betrayal. :-)

I also added the delete signal. Except for editing the history log file, it also updates the cmd buffer (that thing was missing in the original code).

Please, could I ask you to test it?

@tmszi
Copy link
Member Author

tmszi commented Jan 14, 2024

Closed by better implementation PR #3342.

@tmszi tmszi closed this Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request GUI wxGUI related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants