Skip to content

Commit

Permalink
Add menu item toggle to show/hide closed positions.
Browse files Browse the repository at this point in the history
  • Loading branch information
krazkidd committed Jul 22, 2024
1 parent 27398eb commit 22fdcab
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
4 changes: 3 additions & 1 deletion include/ui/MainFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace kdeck
ID_Logout = wxID_HIGHEST + 2,
ID_Exchange_Announcements = wxID_HIGHEST + 3,
ID_Exchange_Schedule = wxID_HIGHEST + 4,
ID_Exchange_Status = wxID_HIGHEST + 5
ID_Exchange_Status = wxID_HIGHEST + 5,
ID_View_ShowClosedPositions = wxID_HIGHEST + 6,
};

class MainFrame : public wxFrame
Expand All @@ -34,6 +35,7 @@ namespace kdeck

wxMenuItem *mnuLogin;
wxMenuItem *mnuLogout;
wxMenuItem *mnuShowClosedPositions;

PortfolioPanel* pnlPortfolio;

Expand Down
3 changes: 2 additions & 1 deletion include/ui/PortfolioPanel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ namespace kdeck
{
class Api;
class BalancePanel;
class Config;

class PortfolioPanel : public wxScrolledWindow
{
public:
PortfolioPanel(wxWindow* parent, wxWindowID winid = wxID_ANY);

void UpdateStuff(Api* api);
void UpdateStuff(const Config* config, Api* api);

private:
BalancePanel* pnlBalance;
Expand Down
20 changes: 19 additions & 1 deletion src/ui/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ namespace kdeck

///////////////////////////////////////////////////////////////////////////

wxMenu *menuView = new wxMenu;

mnuShowClosedPositions = menuView->AppendCheckItem(ID_View_ShowClosedPositions, "Show Closed Positions", "Show Closed Positions");

mnuShowClosedPositions->Enable(false);

///////////////////////////////////////////////////////////////////////////

wxMenu *menuHelp = new wxMenu;
menuHelp->Append(wxID_ABOUT);

Expand All @@ -63,6 +71,7 @@ namespace kdeck
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, "&File");
menuBar->Append(menuExchange, "&Exchange");
menuBar->Append(menuView, "&View");
menuBar->Append(menuHelp, "&Help");

SetMenuBar(menuBar);
Expand All @@ -87,10 +96,13 @@ namespace kdeck

void MainFrame::UpdateStuff()
{
pnlPortfolio->UpdateStuff(&api);
pnlPortfolio->UpdateStuff(&config, &api);

mnuLogin->Enable(!api.IsLoggedIn());
mnuLogout->Enable(api.IsLoggedIn());

mnuShowClosedPositions->Enable(api.IsLoggedIn());
mnuShowClosedPositions->Check(config.GetShowClosedPositions());
}

// helpers ////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -239,6 +251,12 @@ namespace kdeck
case ID_Exchange_Status:
DoShowExchangeStatus();

break;
case ID_View_ShowClosedPositions:
config.SetShowClosedPositions(mnuShowClosedPositions->IsChecked());

UpdateStuff();

break;
case wxID_ABOUT:
wxMessageBox(wxString::Format("%s v%s", kProjectName, kProjectVersion), wxString::Format("About %s", kProjectName), wxOK | wxICON_INFORMATION);
Expand Down
13 changes: 12 additions & 1 deletion src/ui/PortfolioPanel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <wx/wx.h>

Check notice on line 1 in src/ui/PortfolioPanel.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on src/ui/PortfolioPanel.cpp

File src/ui/PortfolioPanel.cpp does not conform to LLVM style guidelines. (lines 3, 11, 12, 13, 14, 16, 17, 18, 19, 20, 22, 23, 25, 26, 27, 29, 31, 33, 35, 36, 38, 39, 40, 42, 43, 44, 46, 48, 49, 50, 51, 52, 54, 56, 58, 59, 60, 61, 62, 63, 65, 67, 68, 69, 70, 71, 72, 74, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89)

Check failure on line 1 in src/ui/PortfolioPanel.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

src/ui/PortfolioPanel.cpp:1:10 [clang-diagnostic-error]

'wx/wx.h' file not found

#include "api/Api.hpp"
#include "config/Config.hpp"
#include "ui/BalancePanel.hpp"
#include "ui/PortfolioPanel.hpp"
#include "ui/EventPositionPanel.hpp"
Expand Down Expand Up @@ -38,7 +39,7 @@ namespace kdeck
SetScrollRate(10, 10);
}

void PortfolioPanel::UpdateStuff(Api* api)
void PortfolioPanel::UpdateStuff(const Config* config, Api* api)
{
pnlBalance->UpdateStuff(api);

Expand All @@ -56,10 +57,20 @@ namespace kdeck

for (auto event : api->GetEventPositions())
{
if (0 == *event->event_exposure && !config->GetShowClosedPositions())
{
continue;
}

boxSizer->Add(new EventPositionPanel(pnlPositions, wxID_ANY, event), flags);

for (auto market : api->GetMarketPositions(*event->event_ticker))
{
if (0 == *market->market_exposure && !config->GetShowClosedPositions())
{
continue;
}

boxSizer->Add(new MarketPositionPanel(pnlPositions, wxID_ANY, market), flags);
}
}
Expand Down

0 comments on commit 22fdcab

Please sign in to comment.