Don't allow project files to be renamed or deleted in project tree pane.
This prevents any potential breakage of a project due to the file changes. It is overly zealous because the project manager doesn't actually have any knowledge of which files belong to the project. Fixes: https://gitlab.com/kicad/code/kicad/-/issues/9654
This commit is contained in:
parent
48c3734eea
commit
802cfc1a7d
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -72,6 +72,26 @@ void PROJECT_TREE_ITEM::SetState( int state )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PROJECT_TREE_ITEM::CanDelete() const
|
||||||
|
{
|
||||||
|
if( m_type == TREE_FILE_TYPE::DIRECTORY
|
||||||
|
|| m_type == TREE_FILE_TYPE::LEGACY_PROJECT
|
||||||
|
|| m_type == TREE_FILE_TYPE::JSON_PROJECT
|
||||||
|
|| m_type == TREE_FILE_TYPE::LEGACY_SCHEMATIC
|
||||||
|
|| m_type == TREE_FILE_TYPE::SEXPR_SCHEMATIC
|
||||||
|
|| m_type == TREE_FILE_TYPE::LEGACY_PCB
|
||||||
|
|| m_type == TREE_FILE_TYPE::SEXPR_PCB
|
||||||
|
|| m_type == TREE_FILE_TYPE::DRAWING_SHEET
|
||||||
|
|| m_type == TREE_FILE_TYPE::FOOTPRINT_FILE
|
||||||
|
|| m_type == TREE_FILE_TYPE::SCHEMATIC_LIBFILE
|
||||||
|
|| m_type == TREE_FILE_TYPE::SEXPR_SYMBOL_LIB_FILE
|
||||||
|
|| m_type == TREE_FILE_TYPE::DESIGN_RULES )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const wxString PROJECT_TREE_ITEM::GetDir() const
|
const wxString PROJECT_TREE_ITEM::GetDir() const
|
||||||
{
|
{
|
||||||
if( TREE_FILE_TYPE::DIRECTORY == m_type )
|
if( TREE_FILE_TYPE::DIRECTORY == m_type )
|
||||||
|
@ -84,7 +104,7 @@ const wxString PROJECT_TREE_ITEM::GetDir() const
|
||||||
bool PROJECT_TREE_ITEM::Rename( const wxString& name, bool check )
|
bool PROJECT_TREE_ITEM::Rename( const wxString& name, bool check )
|
||||||
{
|
{
|
||||||
// this is broken & unsafe to use on linux.
|
// this is broken & unsafe to use on linux.
|
||||||
if( m_type == TREE_FILE_TYPE::DIRECTORY )
|
if( !CanRename() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( name.IsEmpty() )
|
if( name.IsEmpty() )
|
||||||
|
@ -128,6 +148,9 @@ bool PROJECT_TREE_ITEM::Rename( const wxString& name, bool check )
|
||||||
|
|
||||||
void PROJECT_TREE_ITEM::Delete()
|
void PROJECT_TREE_ITEM::Delete()
|
||||||
{
|
{
|
||||||
|
if( !CanDelete() )
|
||||||
|
return;
|
||||||
|
|
||||||
wxString errMsg;
|
wxString errMsg;
|
||||||
|
|
||||||
if( !KIPLATFORM::ENV::MoveToTrash( GetFileName(), errMsg ) )
|
if( !KIPLATFORM::ENV::MoveToTrash( GetFileName(), errMsg ) )
|
||||||
|
|
|
@ -80,6 +80,16 @@ public:
|
||||||
void Activate( PROJECT_TREE_PANE* aTreePrjFrame );
|
void Activate( PROJECT_TREE_PANE* aTreePrjFrame );
|
||||||
void SetState( int state );
|
void SetState( int state );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a file can be deleted via the project tree pane.
|
||||||
|
*
|
||||||
|
* @note Any of the files that could potentially break a project are flagged as cannot delete
|
||||||
|
* or rename.
|
||||||
|
*
|
||||||
|
* @return false if the file managed by this item cannot be deleted or true if it can.
|
||||||
|
*/
|
||||||
|
bool CanDelete() const;
|
||||||
|
bool CanRename() const { return CanDelete(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TREE_FILE_TYPE m_type; // = TREE_PROJECT, TREE_DIRECTORY ...
|
TREE_FILE_TYPE m_type; // = TREE_PROJECT, TREE_DIRECTORY ...
|
||||||
|
|
|
@ -642,6 +642,9 @@ void PROJECT_TREE_PANE::onRight( wxTreeEvent& Event )
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
can_delete = item->CanDelete();
|
||||||
|
can_rename = item->CanRename();
|
||||||
|
|
||||||
wxString full_file_name = item->GetFileName();
|
wxString full_file_name = item->GetFileName();
|
||||||
|
|
||||||
switch( item->GetType() )
|
switch( item->GetType() )
|
||||||
|
@ -653,7 +656,6 @@ void PROJECT_TREE_PANE::onRight( wxTreeEvent& Event )
|
||||||
if( item->GetId() == m_TreeProject->GetRootItem() )
|
if( item->GetId() == m_TreeProject->GetRootItem() )
|
||||||
{
|
{
|
||||||
can_switch_to_project = false;
|
can_switch_to_project = false;
|
||||||
can_delete = false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -665,7 +667,6 @@ void PROJECT_TREE_PANE::onRight( wxTreeEvent& Event )
|
||||||
case TREE_FILE_TYPE::DIRECTORY:
|
case TREE_FILE_TYPE::DIRECTORY:
|
||||||
can_switch_to_project = false;
|
can_switch_to_project = false;
|
||||||
can_edit = false;
|
can_edit = false;
|
||||||
can_rename = false;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue