mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Janitor: Skip undo/redo if field is marked as non-writable
This commit is contained in:
@@ -44,6 +44,7 @@
|
|||||||
#include "cafPdmFieldHandle.h"
|
#include "cafPdmFieldHandle.h"
|
||||||
#include "cafPdmObjectHandle.h"
|
#include "cafPdmObjectHandle.h"
|
||||||
#include "cafPdmUiObjectHandle.h"
|
#include "cafPdmUiObjectHandle.h"
|
||||||
|
#include "cafPdmXmlFieldHandle.h"
|
||||||
#include "cafSelectionManager.h"
|
#include "cafSelectionManager.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
@@ -61,6 +62,21 @@ CmdUiCommandSystemImpl::CmdUiCommandSystemImpl()
|
|||||||
m_disableUndoForFieldChange = false;
|
m_disableUndoForFieldChange = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool CmdUiCommandSystemImpl::isFieldWritable( PdmFieldHandle* fieldToUpdate ) const
|
||||||
|
{
|
||||||
|
if ( !fieldToUpdate ) return false;
|
||||||
|
|
||||||
|
auto xmlCapability = fieldToUpdate->xmlCapability();
|
||||||
|
if ( !xmlCapability ) return false;
|
||||||
|
|
||||||
|
if ( !xmlCapability->isIOWritable() ) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ class CmdUiCommandSystemImpl : public PdmUiCommandSystemInterface
|
|||||||
public:
|
public:
|
||||||
CmdUiCommandSystemImpl();
|
CmdUiCommandSystemImpl();
|
||||||
|
|
||||||
|
bool isFieldWritable( PdmFieldHandle* fieldToUpdate ) const override;
|
||||||
void fieldChangedCommand( const std::vector<PdmFieldHandle*>& fieldsToUpdate, const QVariant& newUiValue ) override;
|
void fieldChangedCommand( const std::vector<PdmFieldHandle*>& fieldsToUpdate, const QVariant& newUiValue ) override;
|
||||||
void setCurrentContextMenuTargetWidget( QWidget* targetWidget ) override;
|
void setCurrentContextMenuTargetWidget( QWidget* targetWidget ) override;
|
||||||
void populateMenuWithDefaultCommands( const QString& uiConfigName, QMenu* menu ) override;
|
void populateMenuWithDefaultCommands( const QString& uiConfigName, QMenu* menu ) override;
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ class PdmUiFieldHandle;
|
|||||||
class PdmUiCommandSystemInterface
|
class PdmUiCommandSystemInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual bool isFieldWritable( PdmFieldHandle* fieldToUpdate ) const = 0;
|
||||||
virtual void fieldChangedCommand( const std::vector<PdmFieldHandle*>& fieldsToUpdate, const QVariant& newUiValue ) = 0;
|
virtual void fieldChangedCommand( const std::vector<PdmFieldHandle*>& fieldsToUpdate, const QVariant& newUiValue ) = 0;
|
||||||
virtual void setCurrentContextMenuTargetWidget( QWidget* targetWidget ) = 0;
|
virtual void setCurrentContextMenuTargetWidget( QWidget* targetWidget ) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -102,16 +102,21 @@ void PdmUiCommandSystemProxy::setUiValueToField( PdmUiFieldHandle* uiFieldHandle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_commandInterface )
|
if ( m_commandInterface && !fieldsToUpdate.empty() )
|
||||||
{
|
{
|
||||||
caf::PdmUiObjectHandle* uiOwnerObjectHandle = uiObj( editorField->ownerObject() );
|
auto firstField = fieldsToUpdate.front();
|
||||||
if ( uiOwnerObjectHandle && uiOwnerObjectHandle->useUndoRedoForFieldChanged() )
|
if ( m_commandInterface->isFieldWritable( firstField ) )
|
||||||
{
|
{
|
||||||
m_commandInterface->fieldChangedCommand( fieldsToUpdate, newUiValue );
|
caf::PdmUiObjectHandle* uiOwnerObjectHandle = uiObj( editorField->ownerObject() );
|
||||||
return;
|
if ( uiOwnerObjectHandle && uiOwnerObjectHandle->useUndoRedoForFieldChanged() )
|
||||||
|
{
|
||||||
|
m_commandInterface->fieldChangedCommand( fieldsToUpdate, newUiValue );
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback to update field values without undo/redo support
|
||||||
for ( auto fieldHandle : fieldsToUpdate )
|
for ( auto fieldHandle : fieldsToUpdate )
|
||||||
{
|
{
|
||||||
fieldHandle->uiCapability()->setValueFromUiEditor( newUiValue, true );
|
fieldHandle->uiCapability()->setValueFromUiEditor( newUiValue, true );
|
||||||
@@ -186,8 +191,8 @@ std::vector<PdmFieldHandle*> PdmUiCommandSystemProxy::fieldsFromSelection( PdmFi
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Search one level in the project tree for fields in child objects
|
// Search one level in the project tree for fields in child objects
|
||||||
// Searching in deeper levels is currently not supported, and is considered difficult to match correctly
|
// Searching in deeper levels is currently not supported, and is considered difficult to match
|
||||||
// and robust
|
// correctly and robust
|
||||||
//
|
//
|
||||||
// Check for identical owner class to guard for matching field names in multiple child objects of a
|
// Check for identical owner class to guard for matching field names in multiple child objects of a
|
||||||
// different type
|
// different type
|
||||||
|
|||||||
Reference in New Issue
Block a user