CHANGED: #1471 ProcEditor is now fully implemented. It can add/remove/move up/move down procedure actions.

This commit is contained in:
dfighter1985 2012-07-24 19:58:20 +02:00
parent 6fd1b1bc06
commit 3ad60b477e
4 changed files with 191 additions and 1 deletions

View file

@ -103,6 +103,40 @@ namespace NLGUI
return false;
}
bool swap( uint32 i1, uint32 i2 )
{
if( i1 == i2 )
return false;
if( i1 >= Actions.size() )
return false;
if( i2 >= Actions.size() )
return false;
CProcAction a = Actions[ i1 ];
Actions[ i1 ] = Actions[ i2 ];
Actions[ i2 ] = a;
return true;
}
bool addAction( const std::string &name )
{
Actions.push_back( CProcAction() );
Actions.back().Action = name;
return true;
}
bool removeAction( uint32 i )
{
if( i >= Actions.size() )
return false;
std::vector< CProcAction >::iterator itr = Actions.begin() + i;
Actions.erase( itr );
return true;
}
};
typedef std::map< std::string, CProcedure > TProcedureMap;

View file

@ -17,6 +17,8 @@
#include "proc_editor.h"
#include "action_editor.h"
#include <QMessageBox>
#include <QInputDialog>
#include "nel/gui/interface_group.h"
#include "nel/gui/widget_manager.h"
@ -28,7 +30,11 @@ namespace GUIEditor
actionEditor = new ActionEditor;
connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) );
connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( hide() ) );
connect( editButton, SIGNAL( clicked( bool ) ), actionEditor, SLOT( show() ) );
connect( editButton, SIGNAL( clicked( bool ) ), this, SLOT( onEditButtonClicked() ) );
connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddButtonClicked() ) );
connect( removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveButtonClicked() ) );
connect( upButton, SIGNAL( clicked( bool ) ), this, SLOT( onUpButtonClicked() ) );
connect( downButton, SIGNAL( clicked( bool ) ), this, SLOT( onDownButtonClicked() ) );
}
ProcEditor::~ProcEditor()
@ -53,4 +59,136 @@ namespace GUIEditor
setWindowTitle( QString( "Procedure Editor - %1" ).arg( currentProc ) );
}
void ProcEditor::onEditButtonClicked()
{
actionEditor->show();
}
void ProcEditor::onAddButtonClicked()
{
bool ok;
QString name =
QInputDialog::getText( this,
tr( "Adding new Action" ),
tr( "Please specify the name of the new action handler" ),
QLineEdit::Normal,
QString(),
&ok );
if( ok )
{
CProcedure *proc =
CWidgetManager::getInstance()->getParser()->getProc( currentProc.toStdString() );
if( proc != NULL )
{
proc->addAction( name.toStdString() );
actionList->addItem( name );
}
else
nlinfo( "Cannot find procedure %s", currentProc.toStdString().c_str() );
}
}
void ProcEditor::onRemoveButtonClicked()
{
QListWidgetItem *item = actionList->item( actionList->currentRow() );
if( item == NULL )
return;
QMessageBox::StandardButton button =
QMessageBox::question( this,
tr( "Removing an Action" ),
tr( "Are you sure you want to remove '%1'" ).arg( item->text() ),
QMessageBox::Yes | QMessageBox::Cancel );
if( button != QMessageBox::Yes )
return;
CProcedure *proc =
CWidgetManager::getInstance()->getParser()->getProc( currentProc.toStdString() );
if( proc != NULL )
{
if( !proc->removeAction( static_cast< uint32 >( actionList->currentRow() ) ) )
nlinfo( "Action #%d not found in procedure %s.", actionList->currentRow(), currentProc.toStdString().c_str() );
item = actionList->takeItem( actionList->currentRow() );
delete item;
}
else
nlinfo( "Cannot find procedure %s", currentProc.toStdString().c_str() );
}
void ProcEditor::onUpButtonClicked()
{
int row = actionList->currentRow();
if( row == 0 )
return;
QListWidgetItem *item = actionList->item( row );
if( item == NULL )
return;
QListWidgetItem *prevItem = actionList->item( row - 1 );
if( prevItem == NULL )
return;
CProcedure *proc = CWidgetManager::getInstance()->getParser()->getProc( currentProc.toStdString() );
if( proc == NULL )
return;
if( !proc->swap( row - 1, row ) )
return;
swapListItems( row - 1, row );
actionList->setCurrentRow( row - 1 );
}
void ProcEditor::onDownButtonClicked()
{
int row = actionList->currentRow();
if( row == ( actionList->count() - 1 ) )
return;
QListWidgetItem *item = actionList->item( row );
if( item == NULL )
return;
QListWidgetItem *nextItem = actionList->item( row + 1 );
if( nextItem == NULL )
return;
CProcedure *proc = CWidgetManager::getInstance()->getParser()->getProc( currentProc.toStdString() );
if( proc == NULL )
return;
if( !proc->swap( row, row + 1 ) )
return;
swapListItems( row, row + 1 );
actionList->setCurrentRow( row + 1 );
}
void ProcEditor::swapListItems( int row1, int row2 )
{
if( row1 == row2 )
return;
if( row1 >= actionList->count() )
return;
if( row2 >= actionList->count() )
return;
if( row1 > row2 ){
std::swap( row1, row2 );
}
QListWidgetItem *item1 = actionList->item( row1 );
if( item1 == NULL )
return;
QListWidgetItem *item2 = actionList->item( row2 );
if( item2 == NULL )
return;
actionList->takeItem( row1 );
actionList->takeItem( row2 - 1 );
actionList->insertItem( row1, item2 );
actionList->insertItem( row2, item1 );
}
}

View file

@ -33,7 +33,16 @@ namespace GUIEditor
void setCurrentProc( const QString &name );
private Q_SLOTS:
void onEditButtonClicked();
void onAddButtonClicked();
void onRemoveButtonClicked();
void onUpButtonClicked();
void onDownButtonClicked();
private:
void swapListItems( int row1, int row2 );
ActionEditor *actionEditor;
QString currentProc;
};

View file

@ -97,6 +97,15 @@ namespace GUIEditor
QListWidgetItem *item = procList->item( procList->currentRow() );
if( item == NULL )
return;
QMessageBox::StandardButton button =
QMessageBox::question( this,
tr( "Removing a procedure" ),
tr( "Are you sure you want to remove '%1'" ).arg( item->text() ),
QMessageBox::Yes | QMessageBox::Cancel );
if( button != QMessageBox::Yes )
return;
if( !parser->removeProc( item->text().toStdString() ) )
return;