Commit ab81a846 authored by Edward Wang's avatar Edward Wang Committed by Jean-Baptiste Kempf

Qt: add rename directory option

Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent f217d32d
......@@ -67,6 +67,8 @@
#define I_POP_INFO N_("Information...")
#define I_POP_NEWFOLDER I_DIR_OR_FOLDER( N_("Create Directory..."), \
N_("Create Folder...") )
#define I_POP_RENAMEFOLDER I_DIR_OR_FOLDER( N_("Rename Directory..."), \
N_("Rename Folder...") )
#define I_POP_EXPLORE I_DIR_OR_FOLDER( N_("Show Containing Directory..."), \
N_("Show Containing Folder...") )
#define I_POP_STREAM N_("Stream...")
......
......@@ -957,6 +957,19 @@ void PLModel::createNode( QModelIndex index, QString name )
PL_UNLOCK;
}
void PLModel::renameNode( QModelIndex index, QString name )
{
if( name.isEmpty() || !index.isValid() ) return;
PL_LOCK;
if ( !index.isValid() ) index = rootIndex();
input_item_t* p_input = this->getInputItem( index );
input_item_SetName( p_input, qtu( name ) );
playlist_t *p_playlist = pl_Get( p_intf );
input_item_WriteMeta( VLC_OBJECT(p_playlist), p_input );
PL_UNLOCK;
}
bool PLModel::action( QAction *action, const QModelIndexList &indexes )
{
QModelIndex index;
......@@ -1077,6 +1090,9 @@ bool PLModel::isSupportedAction( actions action, const QModelIndex &index ) cons
return getURI( index ).startsWith( "file://" );
case ACTION_CREATENODE:
return ( canEdit() && isTree() );
case ACTION_RENAMENODE:
return ( index != rootIndex() ) && !isLeaf( index );
break;
case ACTION_CLEAR:
return rowCount() && canEdit();
case ACTION_ENQUEUEFILE:
......
......@@ -76,6 +76,7 @@ public:
virtual void rebuild( playlist_item_t * p = NULL ) { model()->rebuild( p ); }
virtual void doDelete( QModelIndexList list ) { model()->doDelete( mapListToSource( list ) ); }
virtual void createNode( QModelIndex a, QString b ) { model()->createNode( mapToSource( a ), b ); }
virtual void renameNode( QModelIndex a, QString b ) { model()->renameNode( mapToSource( a ), b ); }
virtual void removeAll() { model()->removeAll(); }
virtual QModelIndex rootIndex() const { return mapFromSource( model()->rootIndex() ); }
......@@ -165,6 +166,7 @@ public:
virtual void rebuild( playlist_item_t * p = NULL );
virtual void doDelete( QModelIndexList selected );
virtual void createNode( QModelIndex index, QString name );
virtual void renameNode( QModelIndex index, QString name );
virtual void removeAll();
/* Lookups */
......
......@@ -51,6 +51,12 @@
I_DIR_OR_FOLDER( N_( "Enter name for new directory:" ), \
N_( "Enter name for new folder:" ) )
#define I_RENAME_DIR \
I_DIR_OR_FOLDER( N_("Rename Directory"), N_( "Rename Folder" ) )
#define I_RENAME_DIR_NAME \
I_DIR_OR_FOLDER( N_( "Enter a new name for the directory:" ), \
N_( "Enter a new name for the folder:" ) )
#include <QHeaderView>
#include <QMenu>
#include <QKeyEvent>
......@@ -198,6 +204,9 @@ bool StandardPLPanel::popup( const QPoint &point )
ADD_MENU_ENTRY( addIcon, qtr(I_POP_NEWFOLDER),
VLCModelSubInterface::ACTION_CREATENODE )
ADD_MENU_ENTRY( QIcon(), qtr(I_POP_RENAMEFOLDER),
VLCModelSubInterface::ACTION_RENAMENODE )
menu.addSeparator();
/* In PL or ML, allow to add a file/folder */
ADD_MENU_ENTRY( addIcon, qtr(I_PL_ADDF),
......@@ -325,6 +334,14 @@ void StandardPLPanel::popupAction( QAction *action )
model->createNode( index, temp );
break;
case VLCModelSubInterface::ACTION_RENAMENODE:
temp = QInputDialog::getText( PlaylistDialog::getInstance( p_intf ),
qtr( I_RENAME_DIR ), qtr( I_RENAME_DIR_NAME ),
QLineEdit::Normal, model->getTitle( index ), &ok);
if ( !ok ) return;
model->renameNode( index, temp );
break;
case VLCModelSubInterface::ACTION_ENQUEUEFILE:
uris = THEDP->showSimpleOpen();
if ( uris.isEmpty() ) return;
......
......@@ -65,6 +65,7 @@ public:
virtual void rebuild( playlist_item_t * p = NULL ) = 0;
virtual void doDelete( QModelIndexList ) = 0;
virtual void createNode( QModelIndex, QString ) = 0;
virtual void renameNode( QModelIndex, QString ) = 0;
virtual void removeAll() = 0;
virtual QModelIndex rootIndex() const = 0;
......@@ -89,6 +90,7 @@ public:
ACTION_SORT,
ACTION_EXPLORE,
ACTION_CREATENODE,
ACTION_RENAMENODE,
ACTION_CLEAR,
ACTION_ENQUEUEFILE,
ACTION_ENQUEUEDIR,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment