project: implemented the ability to delete items from projects

This commit is contained in:
itsmattkc
2020-03-28 12:33:28 +11:00
parent a2a432a0e8
commit b54388894c
6 changed files with 69 additions and 7 deletions
+5
View File
@@ -133,6 +133,11 @@ void ProjectPanel::Overwrite()
}
}
void ProjectPanel::DeleteSelected()
{
explorer_->DeleteSelected();
}
void ProjectPanel::Edit(Item* item)
{
explorer_->Edit(item);
+2
View File
@@ -52,6 +52,8 @@ public:
virtual void Insert() override;
virtual void Overwrite() override;
virtual void DeleteSelected() override;
public slots:
void Edit(Item *item);
+19 -5
View File
@@ -475,7 +475,7 @@ void ProjectViewModel::MoveItemInternal(Item *item, Item *destination)
beginMoveRows(item_index.parent(), item_index.row(), item_index.row(), destination_index, destination->child_count());
ItemPtr item_ptr = item->parent()->shared_ptr_from_raw(item);
ItemPtr item_ptr = item->get_shared_ptr();
destination->add_child(item_ptr);
@@ -541,10 +541,6 @@ ProjectViewModel::AddItemCommand::AddItemCommand(ProjectViewModel* model, Item*
{
}
ProjectViewModel::AddItemCommand::~AddItemCommand()
{
}
void ProjectViewModel::AddItemCommand::redo_internal()
{
model_->AddChild(parent_, child_);
@@ -558,3 +554,21 @@ void ProjectViewModel::AddItemCommand::undo_internal()
done_ = false;
}
ProjectViewModel::RemoveItemCommand::RemoveItemCommand(ProjectViewModel *model, ItemPtr item, QUndoCommand *parent) :
UndoCommand(parent),
model_(model),
item_(item)
{
}
void ProjectViewModel::RemoveItemCommand::redo_internal()
{
parent_ = item_->parent();
model_->RemoveChild(parent_, item_.get());
}
void ProjectViewModel::RemoveItemCommand::undo_internal()
{
model_->AddChild(parent_, item_);
}
+22 -2
View File
@@ -151,8 +151,6 @@ public:
public:
AddItemCommand(ProjectViewModel* model, Item* folder, ItemPtr child, QUndoCommand* parent = nullptr);
virtual ~AddItemCommand() override;
protected:
virtual void redo_internal() override;
@@ -164,6 +162,28 @@ public:
ItemPtr child_;
bool done_;
};
/**
* @brief An undo command for removing an item
*/
class RemoveItemCommand : public UndoCommand {
public:
RemoveItemCommand(ProjectViewModel* model, ItemPtr item, QUndoCommand* parent = nullptr);
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
ProjectViewModel* model_;
ItemPtr item_;
Item* parent_;
};
private:
/**
* @brief Retrieve the index of `item` in its parent
@@ -406,3 +406,22 @@ void ProjectExplorer::DeselectAll()
{
CurrentView()->selectionModel()->clearSelection();
}
void ProjectExplorer::DeleteSelected()
{
QList<Item*> selected = SelectedItems();
if (selected.isEmpty()) {
return;
}
QUndoCommand* command = new QUndoCommand();
foreach (Item* item, selected) {
ItemPtr item_ptr = item->get_shared_ptr();
new ProjectViewModel::RemoveItemCommand(&model_, item_ptr, command);
}
Core::instance()->undo_stack()->pushIfHasChildren(command);
}
@@ -77,6 +77,8 @@ public:
void DeselectAll();
void DeleteSelected();
public slots:
void set_view_type(ProjectToolbar::ViewType type);