From 53f771690c5e4e3b6d0c65777ae01ec586a9030e Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 5 Aug 2014 15:34:29 +0200 Subject: [PATCH] Save the last directory where we loaded a tile image from. --- .../tile_editor/tile_editor_main_window.cpp | 14 ++++++++++++-- .../plugins/tile_editor/tile_editor_main_window.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp b/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp index 62aea3fcb..a6571c3e7 100644 --- a/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp +++ b/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp @@ -684,7 +684,9 @@ void TileEditorMainWindow::onActionAddTile(int tabId) QFileDialog::Options options; QString selectedFilter; - QStringList fileNames = QFileDialog::getOpenFileNames(this, "Choose Tile Texture", "." , "Images (*.png);;All Files (*.*)", &selectedFilter, options); + QStringList fileNames = QFileDialog::getOpenFileNames(this, "Choose Tile Texture", m_lastTileDir , "Images (*.png);;All Files (*.*)", &selectedFilter, options); + if( fileNames.empty() ) + return; TileConstants::TNodeTileType type = tabToType( tabId ); @@ -719,6 +721,10 @@ void TileEditorMainWindow::onActionAddTile(int tabId) lv->reset(); lv->setRootIndex( rootIdx ); lv->setCurrentIndex( lv->model()->index( 0, 0, rootIdx ) ); + + QString fn = fileNames[ 0 ].replace( '\\', '/' ); + int slashIdx = fn.lastIndexOf( '/' ); + m_lastTileDir = fn.left( slashIdx ); } void TileEditorMainWindow::onActionDeleteTile( int tabId ) @@ -787,7 +793,7 @@ void TileEditorMainWindow::onActionReplaceImage( int tabId ) QString fileName = QFileDialog::getOpenFileName( this, tr( "Select tile image" ), - "", + m_lastTileDir, tr( "PNG files (*.png)" ) ); if( fileName.isEmpty() ) return; @@ -803,6 +809,10 @@ void TileEditorMainWindow::onActionReplaceImage( int tabId ) tr( "Error replacing tile image" ), error ); } + + QString fn = fileName.replace( '\\', '/' ); + int slashIdx = fn.lastIndexOf( '/' ); + m_lastTileDir = fn.left( slashIdx ); } void TileEditorMainWindow::onTileBankLoaded() diff --git a/code/studio/src/plugins/tile_editor/tile_editor_main_window.h b/code/studio/src/plugins/tile_editor/tile_editor_main_window.h index 550c6bb75..9dee6954d 100644 --- a/code/studio/src/plugins/tile_editor/tile_editor_main_window.h +++ b/code/studio/src/plugins/tile_editor/tile_editor_main_window.h @@ -123,6 +123,7 @@ private: QString m_fileName; QString m_lastOpenDir; + QString m_lastTileDir; }; #endif // TILE_EDITOR_MAIN_WINDOW_H