ResourceBrowser: removed duplicate Action enumeration
There's absolutely no need for duplicating the Action enumeration in ResourceBrowser as there's already one in ResourceAction class. Replacing the enumeration with ResourceAction's one makes code clearer and reduces redundancy.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#ifndef _RESOURCE_BROWSER_H
|
||||
#define _RESOURCE_BROWSER_H
|
||||
|
||||
#include "ResourceAction.h"
|
||||
#include "ResourcePreviewer.h"
|
||||
#include "ResourceTreeModel.h"
|
||||
#include "side_bar_widget.h"
|
||||
@@ -40,20 +41,6 @@ class ResourceBrowser : public sideBarWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Actions
|
||||
{
|
||||
EditProperties,
|
||||
LoadProject,
|
||||
LoadInNewTrackSongEditor,
|
||||
LoadInNewTrackBBEditor,
|
||||
LoadInActiveInstrumentTrack,
|
||||
DownloadIntoCollection,
|
||||
UploadToWWW,
|
||||
DeleteLocalResource,
|
||||
ImportFile,
|
||||
NumActions
|
||||
} ;
|
||||
|
||||
ResourceBrowser( QWidget * _parent );
|
||||
virtual ~ResourceBrowser();
|
||||
|
||||
@@ -72,9 +59,9 @@ private slots:
|
||||
|
||||
|
||||
private:
|
||||
void triggerAction( Actions _action, ResourceItem * _item );
|
||||
void triggerAction( ResourceAction::Action _action, ResourceItem * _item );
|
||||
|
||||
QAction * m_actions[NumActions];
|
||||
QAction * m_actions[ResourceAction::NumActions];
|
||||
|
||||
// the object that will preview individual resources
|
||||
ResourcePreviewer m_previewer;
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include "ResourceAction.h"
|
||||
#include "ResourceBrowser.h"
|
||||
#include "ResourceFileMapper.h"
|
||||
#include "ResourceTreeModel.h"
|
||||
@@ -44,30 +43,30 @@
|
||||
|
||||
struct ActionDesc
|
||||
{
|
||||
ResourceBrowser::Actions action;
|
||||
ResourceAction::Action action;
|
||||
const char * pixmap;
|
||||
const char * text;
|
||||
} ;
|
||||
|
||||
static ActionDesc resourceBrowserActions[] =
|
||||
{
|
||||
{ ResourceBrowser::EditProperties, "edit_draw",
|
||||
{ ResourceAction::EditProperties, "edit_draw",
|
||||
QT_TRANSLATE_NOOP( "ResourceBrowser", "Show/edit properties" ) },
|
||||
{ ResourceBrowser::LoadProject, "project_open",
|
||||
{ ResourceAction::LoadProject, "project_open",
|
||||
QT_TRANSLATE_NOOP( "ResourceBrowser", "Load project" ) },
|
||||
{ ResourceBrowser::LoadInNewTrackSongEditor, "songeditor",
|
||||
{ ResourceAction::LoadInNewTrackSongEditor, "songeditor",
|
||||
QT_TRANSLATE_NOOP( "ResourceBrowser", "Load in new track in Song Editor" ) },
|
||||
{ ResourceBrowser::LoadInNewTrackBBEditor, "bb_track",
|
||||
{ ResourceAction::LoadInNewTrackBBEditor, "bb_track",
|
||||
QT_TRANSLATE_NOOP( "ResourceBrowser", "Load in new track in B+B Editor" ) },
|
||||
{ ResourceBrowser::LoadInActiveInstrumentTrack, "instrument_track",
|
||||
{ ResourceAction::LoadInActiveInstrumentTrack, "instrument_track",
|
||||
QT_TRANSLATE_NOOP( "ResourceBrowser", "Load into active instrument track" ) },
|
||||
{ ResourceBrowser::DownloadIntoCollection, "mimetypes/folder-downloads",
|
||||
{ ResourceAction::DownloadIntoCollection, "mimetypes/folder-downloads",
|
||||
QT_TRANSLATE_NOOP( "ResourceBrowser", "Download into collection" ) },
|
||||
{ ResourceBrowser::UploadToWWW, "mimetypes/network-workgroup",
|
||||
{ ResourceAction::UploadToWWW, "mimetypes/network-workgroup",
|
||||
QT_TRANSLATE_NOOP( "ResourceBrowser", "Upload to WWW" ) },
|
||||
{ ResourceBrowser::DeleteLocalResource, "edit-delete",
|
||||
{ ResourceAction::DeleteLocalResource, "edit-delete",
|
||||
QT_TRANSLATE_NOOP( "ResourceBrowser", "Delete resource" ) },
|
||||
{ ResourceBrowser::ImportFile, "project_import",
|
||||
{ ResourceAction::ImportFile, "project_import",
|
||||
QT_TRANSLATE_NOOP( "ResourceBrowser", "Import file" ) }
|
||||
} ;
|
||||
|
||||
@@ -168,7 +167,7 @@ ResourceBrowser::ResourceBrowser( QWidget * _parent ) :
|
||||
for( int i = 0; i < (int) ( sizeof( resourceBrowserActions ) /
|
||||
sizeof( ActionDesc ) ); ++i )
|
||||
{
|
||||
Actions a = resourceBrowserActions[i].action;
|
||||
ResourceAction::Action a = resourceBrowserActions[i].action;
|
||||
m_actions[a] = new QAction(
|
||||
embed::getIconPixmap(
|
||||
resourceBrowserActions[i].pixmap ),
|
||||
@@ -212,16 +211,16 @@ void ResourceBrowser::showContextMenu( const QPoint & _pos )
|
||||
case ResourceItem::TypePreset:
|
||||
case ResourceItem::TypePluginSpecificResource:
|
||||
case ResourceItem::TypePlugin:
|
||||
m.addAction( m_actions[LoadInNewTrackSongEditor] );
|
||||
m.addAction( m_actions[LoadInNewTrackBBEditor] );
|
||||
m.addAction( m_actions[LoadInActiveInstrumentTrack] );
|
||||
m.addAction( m_actions[ResourceAction::LoadInNewTrackSongEditor] );
|
||||
m.addAction( m_actions[ResourceAction::LoadInNewTrackBBEditor] );
|
||||
m.addAction( m_actions[ResourceAction::LoadInActiveInstrumentTrack] );
|
||||
break;
|
||||
case ResourceItem::TypeProject:
|
||||
m.addAction( m_actions[LoadProject] );
|
||||
m.addAction( m_actions[ResourceAction::LoadProject] );
|
||||
break;
|
||||
case ResourceItem::TypeForeignProject:
|
||||
case ResourceItem::TypeMidiFile:
|
||||
m.addAction( m_actions[ImportFile] );
|
||||
m.addAction( m_actions[ResourceAction::ImportFile] );
|
||||
break;
|
||||
case ResourceItem::TypeImage:
|
||||
case ResourceItem::TypeDirectory:
|
||||
@@ -235,25 +234,25 @@ void ResourceBrowser::showContextMenu( const QPoint & _pos )
|
||||
m.addSeparator();
|
||||
if( item->isLocalResource() )
|
||||
{
|
||||
m.addAction( m_actions[DeleteLocalResource] );
|
||||
m.addAction( m_actions[UploadToWWW] );
|
||||
m.addAction( m_actions[ResourceAction::DeleteLocalResource] );
|
||||
m.addAction( m_actions[ResourceAction::UploadToWWW] );
|
||||
}
|
||||
else
|
||||
{
|
||||
m.addAction( m_actions[DownloadIntoCollection] );
|
||||
m.addAction( m_actions[ResourceAction::DownloadIntoCollection] );
|
||||
}
|
||||
}
|
||||
|
||||
m.addSeparator();
|
||||
m.addAction( m_actions[EditProperties] );
|
||||
m.addAction( m_actions[ResourceAction::EditProperties] );
|
||||
|
||||
// show and exec menu
|
||||
QAction * a = m.exec( m_treeView->mapToGlobal( _pos ) );
|
||||
if( a )
|
||||
{
|
||||
// trigger action if one has been selected
|
||||
triggerAction( static_cast<Actions>( a->data().toInt() ),
|
||||
item );
|
||||
triggerAction( static_cast<ResourceAction::Action>( a->data().toInt() ),
|
||||
item );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -274,8 +273,8 @@ void ResourceBrowser::setFocusAndPreview( const QModelIndex & _idx )
|
||||
{
|
||||
// transfor focus to the treeview. for some reason you have to
|
||||
// setFocus to the line edit above it first.
|
||||
m_filterEdit->setFocus(Qt::MouseFocusReason);
|
||||
m_treeView->setFocus(Qt::MouseFocusReason);
|
||||
m_filterEdit->setFocus( Qt::MouseFocusReason );
|
||||
m_treeView->setFocus( Qt::MouseFocusReason );
|
||||
|
||||
startItemPreview( _idx );
|
||||
}
|
||||
@@ -300,8 +299,6 @@ void ResourceBrowser::currentChanged( const QModelIndex & current,
|
||||
|
||||
// start previewing the sound we just changed to
|
||||
startItemPreview( current );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -317,28 +314,28 @@ void ResourceBrowser::stopPreview()
|
||||
void ResourceBrowser::triggerDefaultAction( const QModelIndex & _idx )
|
||||
{
|
||||
ResourceItem * item = m_treeModel.item( _idx );
|
||||
Actions action = NumActions;
|
||||
ResourceAction::Action action = ResourceAction::NumActions;
|
||||
switch( item->type() )
|
||||
{
|
||||
case ResourceItem::TypeSample:
|
||||
action = LoadInNewTrackBBEditor;
|
||||
action = ResourceAction::LoadInNewTrackBBEditor;
|
||||
break;
|
||||
case ResourceItem::TypePreset:
|
||||
case ResourceItem::TypePluginSpecificResource:
|
||||
case ResourceItem::TypePlugin:
|
||||
action = LoadInNewTrackSongEditor;
|
||||
action = ResourceAction::LoadInNewTrackSongEditor;
|
||||
break;
|
||||
case ResourceItem::TypeProject:
|
||||
action = LoadProject;
|
||||
action = ResourceAction::LoadProject;
|
||||
break;
|
||||
case ResourceItem::TypeForeignProject:
|
||||
case ResourceItem::TypeMidiFile:
|
||||
action = ImportFile;
|
||||
action = ResourceAction::ImportFile;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if( action != NumActions )
|
||||
if( action != ResourceAction::NumActions )
|
||||
{
|
||||
triggerAction( action, item );
|
||||
}
|
||||
@@ -364,28 +361,27 @@ void ResourceBrowser::manageDirectories()
|
||||
|
||||
|
||||
|
||||
void ResourceBrowser::triggerAction( Actions _action, ResourceItem * _item )
|
||||
void ResourceBrowser::triggerAction( ResourceAction::Action _action,
|
||||
ResourceItem * _item )
|
||||
{
|
||||
switch( _action )
|
||||
{
|
||||
case LoadProject:
|
||||
case ResourceAction::LoadProject:
|
||||
if( engine::mainWindow()->mayChangeProject() )
|
||||
{
|
||||
ResourceFileMapper mapper( _item );
|
||||
if( _item->isLocalResource() )
|
||||
{
|
||||
engine::getSong()->loadProject(
|
||||
mapper.fileName() );
|
||||
engine::getSong()->loadProject( mapper.fileName() );
|
||||
}
|
||||
else
|
||||
{
|
||||
engine::getSong()->
|
||||
createNewProjectFromTemplate(
|
||||
mapper.fileName() );
|
||||
createNewProjectFromTemplate( mapper.fileName() );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ImportFile:
|
||||
case ResourceAction::ImportFile:
|
||||
ResourceAction( _item ).importProject( engine::getSong() );
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user