Fixed Mixer delete and rename

This commit is contained in:
Bruno
2021-04-26 13:47:48 +02:00
parent d89290f9b2
commit 98861cea6c
3 changed files with 18 additions and 17 deletions

View File

@@ -182,7 +182,7 @@ void Mixer::update()
failure = nullptr; // prevent delete (already done in recreateSource) failure = nullptr; // prevent delete (already done in recreateSource)
} }
// delete the source // delete the source
deleteSource(failure, false); deleteSource(failure);
} }
// update views // update views
@@ -451,7 +451,7 @@ bool Mixer::recreateSource(Source *s)
return true; return true;
} }
void Mixer::deleteSource(Source *s, bool withundo) void Mixer::deleteSource(Source *s)
{ {
if ( s != nullptr ) if ( s != nullptr )
{ {
@@ -464,10 +464,6 @@ void Mixer::deleteSource(Source *s, bool withundo)
// delete source // delete source
session_->deleteSource(s); session_->deleteSource(s);
// store new state in history manager
if (withundo)
Action::manager().store(name + std::string(" source deleted"));
// log // log
Log::Notify("Source %s deleted.", name.c_str()); Log::Notify("Source %s deleted.", name.c_str());
} }
@@ -571,12 +567,12 @@ void Mixer::deleteSelection()
// ignore if selection empty // ignore if selection empty
if (N > 0) { if (N > 0) {
// adapt Action::manager undo action depending on case // adapt Action::manager undo info depending on case
std::string undomessage; std::ostringstream info;
if (N > 1) if (N > 1)
undomessage = std::to_string(N) + std::string(" sources deleted"); info << N << " sources deleted";
else else
undomessage = selection().front()->name() + std::string(" deleted"); info << selection().front()->name() << ": deleted";
// get clones first : this way we store the history of deletion in the right order // get clones first : this way we store the history of deletion in the right order
SourceList selection_clones_; SourceList selection_clones_;
@@ -587,14 +583,14 @@ void Mixer::deleteSelection()
} }
// delete all clones // delete all clones
while ( !selection_clones_.empty() ) { while ( !selection_clones_.empty() ) {
deleteSource( selection_clones_.front(), false);// this also removes element from selection() deleteSource( selection_clones_.front());// this also removes element from selection()
selection_clones_.pop_front(); selection_clones_.pop_front();
} }
// empty the selection // empty the selection
while ( !selection().empty() ) while ( !selection().empty() )
deleteSource( selection().front(), false ); // this also removes element from selection() deleteSource( selection().front() ); // this also removes element from selection()
Action::manager().store( undomessage ); Action::manager().store(info.str());
} }
} }
@@ -647,7 +643,7 @@ void Mixer::groupSelection()
// store in action manager // store in action manager
std::ostringstream info; std::ostringstream info;
info << sessiongroup->name() << " source inserted, " << sessiongroup->session()->numSource() << " sources flatten."; info << sessiongroup->name() << " inserted: " << sessiongroup->session()->numSource() << " sources flatten.";
Action::manager().store(info.str()); Action::manager().store(info.str());
// give the hand to the user // give the hand to the user
@@ -662,11 +658,14 @@ void Mixer::renameSource(Source *s, const std::string &newname)
// tentative new name // tentative new name
std::string tentativename = s->name(); std::string tentativename = s->name();
std::list<std::string> others = session_->getNameList();
others.remove(tentativename);
// refuse to rename to an empty name // refuse to rename to an empty name
if ( !newname.empty() ) if ( !newname.empty() )
tentativename = newname; tentativename = newname;
tentativename = BaseToolkit::uniqueName(tentativename, session_->getNameList()); tentativename = BaseToolkit::uniqueName(tentativename, others);
// ok to rename // ok to rename
s->setName(tentativename); s->setName(tentativename);

View File

@@ -58,7 +58,7 @@ public:
// operations on sources // operations on sources
void addSource (Source *s); void addSource (Source *s);
void deleteSource (Source *s, bool withundo=true); void deleteSource (Source *s);
void renameSource (Source *s, const std::string &newname = ""); void renameSource (Source *s, const std::string &newname = "");
void attach (Source *s); void attach (Source *s);
void detach (Source *s); void detach (Source *s);

View File

@@ -2628,8 +2628,10 @@ void Navigator::RenderSourcePannel(Source *s)
// Action on source // Action on source
if ( ImGui::Button( ICON_FA_SHARE_SQUARE " Clone", ImVec2(ImGui::GetContentRegionAvail().x, 0)) ) if ( ImGui::Button( ICON_FA_SHARE_SQUARE " Clone", ImVec2(ImGui::GetContentRegionAvail().x, 0)) )
Mixer::manager().addSource ( Mixer::manager().createSourceClone() ); Mixer::manager().addSource ( Mixer::manager().createSourceClone() );
if ( ImGui::Button( ICON_FA_BACKSPACE " Delete", ImVec2(ImGui::GetContentRegionAvail().x, 0)) ) if ( ImGui::Button( ICON_FA_BACKSPACE " Delete", ImVec2(ImGui::GetContentRegionAvail().x, 0)) ) {
Mixer::manager().deleteSource(s); Mixer::manager().deleteSource(s);
Action::manager().store(sname + std::string(": deleted"));
}
} }
ImGui::End(); ImGui::End();
} }