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 >(), 0, 1 );
217 m_gridLayout-> setColumnResizable( 0,
true,
"25%" );
219 m_editAccountWidget->
220 save().connect( [=]()
224 if( m_editAccountWidget-> isDirty() )
225 m_editAccountWidget-> saveData( _accountGuid );
227 m_gridLayout-> removeWidget( m_editAccountWidget );
228 m_editAccountWidget =
nullptr;
231 m_editAccountWidget->
232 cancel().connect( [=]()
236 auto _zapWidget = [&]()
238 m_gridLayout-> removeWidget( m_editAccountWidget );
239 m_editAccountWidget =
nullptr;
245 if( m_editAccountWidget-> isDirty() )
251 if(
Wt::WMessageBox::show(
"save",
TR(
"gcw.cancelChanges"), Wt::StandardButton::Yes | Wt::StandardButton::No ) == Wt::StandardButton::No )
279 editAccount( selectedAccount() );
288 m_model = std::make_shared< Model >();
290 m_model-> load( m_columnCount );
292 view()-> setModel( m_model );
304 if(
GCW::app()-> gnucashew_session().hasGnuCashewExtensions() )
320 if( !
GCW::app()-> gnucashew_session().hasGnuCashewExtensions() )
332 if( !
GCW::app()-> gnucashew_session().hasGnuCashewExtensions() )
339 catch( std::exception & e )
362 if( !view()-> isExpanded( _parent ) )
370 bool expanded =
false;
371 for(
int row=0; row< view()-> model()-> rowCount( _parent ); row++ )
372 expanded |=
iterate( _jary, view()-> model()-> index( row, 0, _parent ) );
389 if( accountGuid !=
"" )
390 _jary.push_back( accountGuid );
411 jobj[
"selected"] =
Wt::WString( selectedAccount() );
413 for(
int col=0; col< 7; col++ )
418 jobj[
"expanded"] = jary;
435 for(
int row=0; row< view()-> model()-> rowCount( _parent ); row++ )
440 auto child = view()-> model()-> index( row, 0, _parent );
452 if( nodeGuid == _accountGuid )
454 view()-> expand( child );
462 retVal |= expandNode( _accountGuid, child );
473 view()-> expand( _parent );
489 for(
auto value : jary )
490 expandNode( value.orIfNull(
"" ) );
519 for(
int row=0; row< view()-> model()-> rowCount( _parentIndex ); row++ )
521 auto childIndex = findIndex( _accountGuid, view()-> model()-> index( row, 0, _parentIndex ) );
528 if( childIndex.isValid() )
545 auto index = findIndex( _accountGuid );
547 view()-> select ( index );
548 view()-> scrollTo ( index, Wt::ScrollHint::PositionAtCenter );
558 expandTreeNodes( _jobj );
560 setSelected( _jobj.
get(
"selected").
orIfNull( std::string() ) );
570 std::cout << __FILE__ <<
":" << __LINE__ <<
" " << std::endl;
572 std::cout << __FILE__ <<
":" << __LINE__ <<
" " <<
Wt::Json::serialize( toJson() ) << std::endl;
582 std::cout << std::endl << std::endl << __FILE__ <<
":" << __LINE__
583 <<
" " <<
"on_doubleClicked:"
584 <<
" " << index.
row()
586 << 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
DialogCode exec(const WAnimation &animation=WAnimation())
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