From 6362d662b750cecb08c096f49b8e29e327cf1724 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Mon, 26 Apr 2021 20:00:18 +0300 Subject: [PATCH] viewsdialog:create safe cut/paste codepath --cut/paste can be applied only if there are no changes in reality otherwise copy/paste is happening --- app/data/viewdata.cpp | 6 +-- app/settings/viewsdialog/viewscontroller.cpp | 50 +++++++++++++------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/app/data/viewdata.cpp b/app/data/viewdata.cpp index e4eb3f087..d054d567e 100644 --- a/app/data/viewdata.cpp +++ b/app/data/viewdata.cpp @@ -81,7 +81,7 @@ View &View::operator=(const View &rhs) alignment = rhs.alignment; m_state = rhs.m_state; m_originFile = rhs.m_originFile; - m_originLayout == rhs.m_originLayout; + m_originLayout = rhs.m_originLayout; m_originView = rhs.m_originView; subcontainments = rhs.subcontainments; @@ -115,8 +115,8 @@ bool View::operator==(const View &rhs) const return (id == rhs.id) && (name == rhs.name) //&& (isActive == rhs.isActive) /*activeness is a state and is not considered*/ - && (isMoveOrigin == rhs.isMoveOrigin) /*changing layouts is a state and is not considered*/ - && (isMoveDestination == rhs.isMoveDestination) /*changing layouts is a state and is not considered*/ + //&& (isMoveOrigin == rhs.isMoveOrigin) /*changing layouts is a state and is not considered*/ + //&& (isMoveDestination == rhs.isMoveDestination) /*changing layouts is a state and is not considered*/ && (onPrimary == rhs.onPrimary) && (screen == rhs.screen) && (screenEdgeMargin == rhs.screenEdgeMargin) diff --git a/app/settings/viewsdialog/viewscontroller.cpp b/app/settings/viewsdialog/viewscontroller.cpp index 47df0fdd8..ebffb5493 100644 --- a/app/settings/viewsdialog/viewscontroller.cpp +++ b/app/settings/viewsdialog/viewscontroller.cpp @@ -288,6 +288,13 @@ void Views::pasteSelectedViews() hascurrentlayoutcuttedviews = true; continue; } + + if (clipboardviews[i].isMoveOrigin) { + //! update cut flags only for real cutted view and not for copied one + clipboardviews[i].isMoveOrigin = false; + clipboardviews[i].isMoveDestination = true; + } + appendViewFromViewTemplate(clipboardviews[i]); } @@ -391,13 +398,12 @@ void Views::save() Latte::Data::ViewsTable newViews = m_model->newViews(); QHash newviewsresponses; - QHash cuttedviews; + QHash cuttedpastedviews; //! add new views that are accepted for(int i=0; iupdateView(alteredViews[i]); } - - if (alteredViews[i].isMoveOrigin) { - cuttedviews[alteredViews[i].id] = alteredViews[i]; - } } //! remove deprecated views that have been removed from user @@ -432,10 +434,29 @@ void Views::save() central->removeView(removedViews[i]); } - //! remove deprecated views that have been removed from Cut operation - for(const auto vid: cuttedviews.keys()){ - if (cuttedviews[vid].state() == Data::View::IsCreated) { - central->removeView(cuttedviews[vid]); + //! remove deprecated views from external layouts that must be removed because of Cut->Paste Action + for(const auto vid: cuttedpastedviews.keys()){ + bool viewidisinteger{true}; + int vid_int = cuttedpastedviews[vid].originView().toInt(&viewidisinteger); + QString vid_str = cuttedpastedviews[vid].originView(); + + if (vid_str.isEmpty() || !viewidisinteger || vid_int<=0) { + //! ignore origin views that have not been created already + continue; + } + + //! Be Careful: Remove deprecated views from Cut->Paste Action + QString origincurrentid = cuttedpastedviews[vid].originLayout(); + Data::Layout originlayout = m_handler->layoutsController()->originalData(origincurrentid); + + Latte::CentralLayout *originActive = m_handler->layoutsController()->isLayoutOriginal(origincurrentid) ? + m_handler->corona()->layoutsManager()->synchronizer()->centralLayout(originlayout.name) : nullptr; + Latte::CentralLayout *origin = originActive ? originActive : new Latte::CentralLayout(this, origincurrentid); + + Data::ViewsTable originviews = Latte::Layouts::Storage::self()->views(origin); + + if (originviews.containsId(vid_str)) { + origin->removeView(originviews[vid_str]); } } @@ -449,11 +470,6 @@ void Views::save() m_model->setOriginalView(vid, newviewsresponses[vid]); } - //! update/remove from model cutted views - for (const auto vid: cuttedviews.keys()) { - m_model->removeView(vid); - } - //! update all table with latest data and make the original one currentViews = m_model->currentViewsData(); m_model->setOriginalData(currentViews);