1#line 2 "src/Gui/AccountsTreeView.cpp"
4#define EDIT_FORM_AS_SPLIT_PAGE
9#include <Wt/Json/Array.h>
10#include <Wt/Json/Parser.h>
11#include <Wt/Json/Serializer.h>
13#include <Wt/WTreeTableNode.h>
14#include <Wt/WMessageBox.h>
21AccountsTreeView(
const std::string & _selectedAccountGuid,
int _columnCount )
22: m_columnCount( _columnCount )
32: m_columnCount( _columnCount )
42 addStyleClass(
"AccountsTreeView" );
44 m_gridLayout = setLayout( std::make_unique< Wt::WGridLayout >() );
47 m_view = m_gridLayout-> addWidget( std::make_unique< Wt::WTreeView >(), 0, 0 );
49 view()-> setSelectionBehavior( Wt::SelectionBehavior::Rows );
50 view()-> setSelectionMode( Wt::SelectionMode::Single );
51 view()-> setAlternatingRowColors(
true );
53 view()-> setAttributeValue(
"oncontextmenu",
"event.cancelBubble=true;event.returnValue=false;return false;" );
56 std::vector< std::string > cols =
88 for(
int i=0; i< m_columnCount; i++ )
89 m_columns.push_back(
TR8(
"gcw.AccountsTreeView.column." + cols.at(i) ) );
105 if( _event.button() == Wt::MouseButton::Right )
107 std::cout << __FILE__ <<
":" << __LINE__ <<
" right-click pop-up menu" << std::endl;
114 while( m_popup.count() )
115 m_popup.removeItem( m_popup.itemAt(0) );
117 m_popup.addItem(
"icons/folder_new.gif",
"Create a New Folder",
this, &WEB::FolderTableView::on_pbAddFolder_triggered );
118 m_popup.addItem(
"Rename",
this, &WEB::FolderTableView::on_pbRenameItem_triggered );
120 std::string fileName =
Wt::asString(m_tableView.model()-> data( index.row(), 0 )).
toUTF8();
123 if( isFolder(fileName) )
124 m_popup.addItem(
"Delete this Folder",
this, &WEB::FolderTableView::on_pbDeleteItem_triggered );
126 m_popup.addItem(
"Delete this File",
this, &WEB::FolderTableView::on_pbDeleteItem_triggered );
128 m_popup.addSeparator();
129 m_popup.addItem(
"Upload a file",
this, &WEB::FolderTableView::on_pbUploadFile_triggered );
130 m_popup.addItem(
"Refresh",
this, &WEB::FolderTableView::refresh );
131 m_popup.addSeparator();
132 m_popup.addItem(
"Properties",
this, &WEB::FolderTableView::on_pbProperties_triggered );
135 if( !m_tableView.isSelected(index) )
137 m_tableView.clearSelection();
138 m_tableView.select(index);
141 if( m_popup.isHidden() )
143 m_popup.popup(event);
172 auto selected = view()-> selectedIndexes();
173 if( selected.size() == 1 )
177 model()-> data( *selected.begin(),
190 if( _accountGuid ==
"" )
193#ifdef EDIT_FORM_AS_POPUP_DIALOG
198#ifdef EDIT_FORM_AS_SPLIT_PAGE
204 if( m_editAccountWidget )
208 Wt::WMessageBox::show(
"AccountsTree",
"Please close the account you are editing", Wt::StandardButton::Ok );
216 m_editAccountWidget = m_gridLayout-> addWidget( std::make_unique< GCW::Gui::AccountEditor >( _accountGuid ), 0, 1 );
217 m_gridLayout-> setColumnResizable( 0,
true,
"25%" );
219 m_editAccountWidget->
220 save().connect( [=]()
223 m_gridLayout-> removeWidget( m_editAccountWidget );
224 m_editAccountWidget =
nullptr;
227 m_editAccountWidget->
228 cancel().connect( [=]()
231 m_gridLayout-> removeWidget( m_editAccountWidget );
232 m_editAccountWidget =
nullptr;
244 editAccount( selectedAccount() );
253 m_model = std::make_shared< Model >();
255 m_model-> load( m_columnCount );
257 view()-> setModel( m_model );
269 if(
GCW::app()-> gnucashew_session().hasGnuCashewExtensions() )
285 if( !
GCW::app()-> gnucashew_session().hasGnuCashewExtensions() )
297 if( !
GCW::app()-> gnucashew_session().hasGnuCashewExtensions() )
304 catch( std::exception & e )
327 if( !view()-> isExpanded( _parent ) )
335 bool expanded =
false;
336 for(
int row=0; row< view()-> model()-> rowCount( _parent ); row++ )
337 expanded |=
iterate( _jary, view()-> model()-> index( row, 0, _parent ) );
354 if( accountGuid !=
"" )
355 _jary.push_back( accountGuid );
376 jobj[
"selected"] =
Wt::WString( selectedAccount() );
378 for(
int col=0; col< 7; col++ )
383 jobj[
"expanded"] = jary;
400 for(
int row=0; row< view()-> model()-> rowCount( _parent ); row++ )
405 auto child = view()-> model()-> index( row, 0, _parent );
417 if( nodeGuid == _accountGuid )
419 view()-> expand( child );
427 retVal |= expandNode( _accountGuid, child );
438 view()-> expand( _parent );
454 for(
auto value : jary )
455 expandNode( value.orIfNull(
"" ) );
484 for(
int row=0; row< view()-> model()-> rowCount( _parentIndex ); row++ )
486 auto childIndex = findIndex( _accountGuid, view()-> model()-> index( row, 0, _parentIndex ) );
493 if( childIndex.isValid() )
510 auto index = findIndex( _accountGuid );
512 view()-> select ( index );
513 view()-> scrollTo ( index, Wt::ScrollHint::PositionAtCenter );
523 expandTreeNodes( _jobj );
525 setSelected( _jobj.
get(
"selected").
orIfNull( std::string() ) );
535 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << std::endl;
537 std::cout << __FILE__ <<
":" << __LINE__ <<
" " <<
Wt::Json::serialize( toJson() ) << std::endl;
547 std::cout << std::endl << std::endl << __FILE__ <<
":" << __LINE__
548 <<
" " <<
"on_doubleClicked:"
549 <<
" " << index.
row()
551 << std::endl << std::endl
static bool iterate(Wt::Json::Array &_jary, Wt::WModelIndex _parent)
AccountsTreeView(int _columnCount)
auto toJson() const -> Wt::Json::Object
auto on_doubleClicked(const Wt::WModelIndex &index, const Wt::WMouseEvent &event) -> void
auto expandNode(const std::string &_accountGuid, Wt::WModelIndex _parent=Wt::WModelIndex()) -> bool
auto configItem() -> GCW::Dbo::Vars::Item::Ptr
Config Item.
auto expandTreeNodes(Wt::Json::Object &_jobj) -> bool
auto findIndex(const std::string &_accountGuid, Wt::WModelIndex _parentIndex=Wt::WModelIndex()) -> Wt::WModelIndex
Find Index by AccountGuid.
auto loadConfig() -> void
auto on_showPopup_triggered(const Wt::WModelIndex &_index, const Wt::WMouseEvent &_event) -> void
auto iterate(Wt::Json::Array &_jary, Wt::WModelIndex _parent=Wt::WModelIndex()) const -> bool
auto fromJson(Wt::Json::Object &_jobj) -> bool
auto setSelected(const std::string &_accountGuid) -> bool
auto selectedAccount() const -> std::string
auto editSelectedAccount() -> void
auto saveConfig() -> void
auto editAccount(const std::string &_accountGuid) -> void
static constexpr const int User
const Value & get(const std::string &name) const
const WString & orIfNull(const WString &v) const
cpp17::any data(ItemDataRole role=ItemDataRole::Display) const
std::string toUTF8() const
WString & arg(const std::wstring &value)
void parse(const std::string &input, Value &result, bool validateUTF8=true)
std::string serialize(const Object &obj, int indentation=1)
WString asString(const cpp17::any &v, const WString &formatString=WString())
auto get(const std::string &_keyValue, const std::string &_cfyValue="*", bool _add=true) -> GCW::Dbo::Vars::Item::Ptr