mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-13 15:45:42 +08:00
Allow to delete data directory from application view
* allow to re-init applicazion list (needed because directories can be deleted) * context menu for "delete data directory"
This commit is contained in:
@@ -419,7 +419,7 @@ namespace BlackGui
|
||||
void CCopyConfigurationComponent::initOtherSwiftVersions()
|
||||
{
|
||||
ui->cb_OtherVersions->clear();
|
||||
const QMap<QString, CApplicationInfo> otherVersions = CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion();
|
||||
const QMap<QString, CApplicationInfo> otherVersions = CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(true);
|
||||
for (const QString &directory : otherVersions.keys())
|
||||
{
|
||||
const CApplicationInfo info(otherVersions.value(directory));
|
||||
|
||||
@@ -40,9 +40,9 @@ namespace BlackGui
|
||||
m_sortOrder = Qt::DescendingOrder;
|
||||
}
|
||||
|
||||
void CApplicationInfoListModel::otherSwiftVersionsFromDataDirectories()
|
||||
void CApplicationInfoListModel::otherSwiftVersionsFromDataDirectories(bool reinit)
|
||||
{
|
||||
this->update(CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories());
|
||||
this->update(CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories(reinit));
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace BlackGui
|
||||
virtual ~CApplicationInfoListModel() {}
|
||||
|
||||
//! \copydoc BlackMisc::CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories
|
||||
void otherSwiftVersionsFromDataDirectories();
|
||||
void otherSwiftVersionsFromDataDirectories(bool reinit);
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -8,9 +8,14 @@
|
||||
*/
|
||||
|
||||
#include "applicationinfoview.h"
|
||||
#include "blackmisc/fileutils.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QDir>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackGui::Models;
|
||||
using namespace BlackGui::Menus;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -19,6 +24,7 @@ namespace BlackGui
|
||||
CApplicationInfoView::CApplicationInfoView(QWidget *parent) : CViewBase(parent)
|
||||
{
|
||||
this->standardInit(new CApplicationInfoListModel(this));
|
||||
this->setCustomMenu(new CApplicationInfoMenu(this));
|
||||
}
|
||||
|
||||
int CApplicationInfoView::otherSwiftVersionsFromDataDirectories()
|
||||
@@ -28,5 +34,41 @@ namespace BlackGui
|
||||
m_acceptRowSelection = (others.size() > 0);
|
||||
return others.size();
|
||||
}
|
||||
|
||||
void CApplicationInfoView::deleteSelectedDataDirectories()
|
||||
{
|
||||
if (!this->hasSelection()) { return; }
|
||||
const QMessageBox::StandardButton reply = QMessageBox::question(this, "Delete?", "Delete selected data directories?", QMessageBox::Yes | QMessageBox::No);
|
||||
if (reply != QMessageBox::Yes) { return; }
|
||||
|
||||
QStringList deletedDirectories;
|
||||
for (const CApplicationInfo &info : this->selectedObjects())
|
||||
{
|
||||
const QString d = CFileUtils::fixWindowsUncPath(info.getApplicationDataDirectory());
|
||||
QDir dir(d);
|
||||
if (!dir.exists()) { continue; }
|
||||
if (dir.removeRecursively())
|
||||
{
|
||||
deletedDirectories << d;
|
||||
}
|
||||
}
|
||||
if (deletedDirectories.isEmpty()) { return; }
|
||||
this->otherSwiftVersionsFromDataDirectories();
|
||||
}
|
||||
|
||||
void CApplicationInfoMenu::customMenu(CMenuActions &menuActions)
|
||||
{
|
||||
if (!this->view()) { return; }
|
||||
if (!this->view()->isEmpty())
|
||||
{
|
||||
m_menuActionDeleteDirectory = menuActions.addAction(m_menuActionDeleteDirectory, CIcons::delete16(), "Delete data directories", CMenuAction::pathNone(), this, { this->view(), &CApplicationInfoView::deleteSelectedDataDirectories });
|
||||
}
|
||||
this->nestedCustomMenu(menuActions);
|
||||
}
|
||||
|
||||
CApplicationInfoView *CApplicationInfoMenu::view() const
|
||||
{
|
||||
return static_cast<CApplicationInfoView *>(this->parent());
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
|
||||
#include "blackgui/views/viewbase.h"
|
||||
#include "blackgui/models/applicationinfolistmodel.h"
|
||||
#include "blackgui/menus/menudelegate.h"
|
||||
#include "blackgui/blackguiexport.h"
|
||||
|
||||
class QWidget;
|
||||
#include <QAction>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -31,7 +32,28 @@ namespace BlackGui
|
||||
|
||||
//! BlackMisc::CApplicationInfoList::otherSwiftVersionsFromDataDirectories
|
||||
int otherSwiftVersionsFromDataDirectories();
|
||||
|
||||
//! Delete the selected directories
|
||||
void deleteSelectedDataDirectories();
|
||||
};
|
||||
}
|
||||
|
||||
//! Menu base class for aircraft model view menus
|
||||
class CApplicationInfoMenu : public Menus::IMenuDelegate
|
||||
{
|
||||
public:
|
||||
//! Constructor
|
||||
CApplicationInfoMenu(CApplicationInfoView *modelView) : Menus::IMenuDelegate(modelView)
|
||||
{}
|
||||
|
||||
//! \copydoc Menus::IMenuDelegate::customMenu
|
||||
virtual void customMenu(Menus::CMenuActions &menuActions);
|
||||
|
||||
private:
|
||||
//! Model view
|
||||
CApplicationInfoView *view() const;
|
||||
|
||||
QAction *m_menuActionDeleteDirectory = nullptr; //!< action to delete menu
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user