Skip to content

Commit

Permalink
BBSListViewBase: Update save function to be able to exclude multi dirs (
Browse files Browse the repository at this point in the history
#1300)

板一覧などサイドバーのビューをXMLに保存するする処理を変更して
除外するディレクトリを複数指定できるようにします。
  • Loading branch information
ma8ma authored Dec 9, 2023
1 parent ef94beb commit ca45e8d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/bbslist/bbslistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ BBSListViewMain::~BBSListViewMain()
void BBSListViewMain::save_xml()
{
const std::string file = CACHE::path_xml_listmain();
save_xml_impl( file, ROOT_NODE_NAME, SUBDIR_ETCLIST );
constexpr std::string_view remove_dirs[] = { SUBDIR_ETCLIST };
save_xml_impl( file, ROOT_NODE_NAME, remove_dirs );
}


Expand Down
38 changes: 22 additions & 16 deletions src/bbslist/bbslistviewbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3202,35 +3202,41 @@ bool BBSListViewBase::slot_query_tooltip( int x, int y, bool keyboard_tooltip,



//
// XML保存
//
// remove_dir != empty()の時はその名前のディレクトリを削除する
//
void BBSListViewBase::save_xml_impl( const std::string& file, const std::string& root, const std::string& remove_dir )
/** @brief 板一覧などサイドバーのビューをXMLに保存する
*
* @details remove_dirs != empty() の時は指定された名前のディレクトリを除外して保存する。
* @param[in] file XMLを保存するファイルパス
* @param[in] root DOMのルート要素名
* @param[in] remove_dirs 除外するディレクトリ名のリスト
*/
void BBSListViewBase::save_xml_impl( const std::string& file, const std::string& root,
JDLIB::span<const std::string_view> remove_dirs )
{
if( file.empty() ) return;
if( root.empty() ) return;
if( ! get_ready_tree() ) return;

#ifdef _DEBUG
std::cout << "BBSListViewBase::save_xml file = " << file << " root = " << root
<< " remove_dir = " << remove_dir << std::endl;
<< " remove_dirs size = " << remove_dirs.size() << std::endl;
#endif

tree2xml( root );

// 指定したディレクトリを取り除く
if( ! remove_dir.empty() )
{
if( ! remove_dirs.empty() ) {
XML::Dom* domroot = m_document.get_root_element( root );
const auto is_remove_dir = [&remove_dir]( const XML::Dom* child ) {
return child->nodeName() == "subdir" && child->getAttribute( "name" ) == remove_dir;
};
auto it = std::find_if( domroot->begin(), domroot->end(), is_remove_dir );
if( it != domroot->end() )
{
domroot->removeChild( *it );

for( std::string_view remove_dir : remove_dirs ) {
if( remove_dir.empty() ) continue;

const auto is_remove_dir = [&remove_dir]( const XML::Dom* child ) {
return child->nodeName() == "subdir" && child->getAttribute( "name" ) == remove_dir;
};
auto it = std::find_if( domroot->begin(), domroot->end(), is_remove_dir );
if( it != domroot->end() ) {
domroot->removeChild( *it );
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/bbslist/bbslistviewbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "skeleton/view.h"
#include "skeleton/edittreeview.h"

#include "jdlib/span.h"
#include "xml/document.h"

#include "columns.h"
Expand All @@ -19,6 +20,7 @@
#include <map>
#include <memory>
#include <string>
#include <string_view>
#include <unordered_set>


Expand Down Expand Up @@ -181,8 +183,9 @@ namespace BBSLIST
// xml保存
virtual void save_xml() = 0;

// remove_dir != empty()の時はその名前のディレクトリを削除する
void save_xml_impl( const std::string& file, const std::string& root, const std::string& remove_dir );
// remove_dirs で指定した名前のディレクトリを除外して保存する
void save_xml_impl( const std::string& file, const std::string& root,
JDLIB::span<const std::string_view> remove_dirs );

// idからポップアップメニュー取得
Gtk::Menu* id2popupmenu( const std::string& id );
Expand Down
2 changes: 1 addition & 1 deletion src/bbslist/favoriteview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ FavoriteListView::~FavoriteListView()
void FavoriteListView::save_xml()
{
const std::string file = CACHE::path_xml_favorite();
save_xml_impl( file, fv::kRootNodeName, "" );
save_xml_impl( file, fv::kRootNodeName, {} );
}


Expand Down
2 changes: 1 addition & 1 deletion src/bbslist/historyview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void HistoryViewBase::show_view()
// xml保存
void HistoryViewBase::save_xml()
{
save_xml_impl( m_file_xml, hv::kRootNodeName, "" );
save_xml_impl( m_file_xml, hv::kRootNodeName, {} );
}


Expand Down

0 comments on commit ca45e8d

Please sign in to comment.