about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/log_dialog.cpp37
-rw-r--r--src/log_dialog.h24
-rw-r--r--src/logger.cpp42
-rw-r--r--src/logger.h6
-rw-r--r--src/tracker_frame.cpp26
-rw-r--r--src/tracker_frame.h5
7 files changed, 136 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1904518..9432f2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -58,6 +58,7 @@ set(SOURCE_FILES
58 "src/paintings_pane.cpp" 58 "src/paintings_pane.cpp"
59 "src/items_pane.cpp" 59 "src/items_pane.cpp"
60 "src/options_pane.cpp" 60 "src/options_pane.cpp"
61 "src/log_dialog.cpp"
61 "vendor/whereami/whereami.c" 62 "vendor/whereami/whereami.c"
62) 63)
63 64
diff --git a/src/log_dialog.cpp b/src/log_dialog.cpp new file mode 100644 index 0000000..3f0a8ad --- /dev/null +++ b/src/log_dialog.cpp
@@ -0,0 +1,37 @@
1#include "log_dialog.h"
2
3#include "logger.h"
4
5wxDEFINE_EVENT(LOG_MESSAGE, wxCommandEvent);
6
7LogDialog::LogDialog(wxWindow* parent)
8 : wxDialog(parent, wxID_ANY, "Debug Log", wxDefaultPosition, wxDefaultSize,
9 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
10 SetSize(FromDIP(wxSize{512, 280}));
11
12 text_area_ =
13 new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize,
14 wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP);
15 text_area_->SetValue(TrackerReadPastLog());
16
17 wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL);
18 top_sizer->Add(text_area_,
19 wxSizerFlags().DoubleBorder().Expand().Proportion(1));
20
21 SetSizer(top_sizer);
22
23 Bind(LOG_MESSAGE, &LogDialog::OnLogMessage, this);
24}
25
26void LogDialog::LogMessage(const std::string& message) {
27 wxCommandEvent* event = new wxCommandEvent(LOG_MESSAGE);
28 event->SetString(message);
29 QueueEvent(event);
30}
31
32void LogDialog::OnLogMessage(wxCommandEvent& event) {
33 if (!text_area_->IsEmpty()) {
34 text_area_->AppendText("\n");
35 }
36 text_area_->AppendText(event.GetString());
37}
diff --git a/src/log_dialog.h b/src/log_dialog.h new file mode 100644 index 0000000..c29251f --- /dev/null +++ b/src/log_dialog.h
@@ -0,0 +1,24 @@
1#ifndef LOG_DIALOG_H_EEFD45B6
2#define LOG_DIALOG_H_EEFD45B6
3
4#include <wx/wxprec.h>
5
6#ifndef WX_PRECOMP
7#include <wx/wx.h>
8#endif
9
10wxDECLARE_EVENT(LOG_MESSAGE, wxCommandEvent);
11
12class LogDialog : public wxDialog {
13 public:
14 explicit LogDialog(wxWindow* parent);
15
16 void LogMessage(const std::string& message);
17
18 private:
19 void OnLogMessage(wxCommandEvent& event);
20
21 wxTextCtrl* text_area_;
22};
23
24#endif /* end of include guard: LOG_DIALOG_H_EEFD45B6 */
diff --git a/src/logger.cpp b/src/logger.cpp index 09fc331..8a08b58 100644 --- a/src/logger.cpp +++ b/src/logger.cpp
@@ -3,8 +3,10 @@
3#include <chrono> 3#include <chrono>
4#include <fstream> 4#include <fstream>
5#include <mutex> 5#include <mutex>
6#include <sstream>
6 7
7#include "global.h" 8#include "global.h"
9#include "log_dialog.h"
8 10
9namespace { 11namespace {
10 12
@@ -14,19 +16,49 @@ class Logger {
14 16
15 void LogLine(const std::string& text) { 17 void LogLine(const std::string& text) {
16 std::lock_guard guard(file_mutex_); 18 std::lock_guard guard(file_mutex_);
17 logfile_ << "[" << std::chrono::system_clock::now() << "] " << text 19 std::ostringstream line;
18 << std::endl; 20 line << "[" << std::chrono::system_clock::now() << "] " << text;
21
22 logfile_ << line.str() << std::endl;
19 logfile_.flush(); 23 logfile_.flush();
24
25 if (log_dialog_ != nullptr) {
26 log_dialog_->LogMessage(line.str());
27 }
28 }
29
30 std::string GetContents() {
31 std::lock_guard guard(file_mutex_);
32
33 std::ifstream file_in(GetAbsolutePath("debug.log"));
34 std::ostringstream buffer;
35 buffer << file_in.rdbuf();
36
37 return buffer.str();
38 }
39
40 void SetLogDialog(LogDialog* log_dialog) {
41 std::lock_guard guard(file_mutex_);
42 log_dialog_ = log_dialog;
20 } 43 }
21 44
22 private: 45 private:
23 std::ofstream logfile_; 46 std::ofstream logfile_;
24 std::mutex file_mutex_; 47 std::mutex file_mutex_;
48 LogDialog* log_dialog_ = nullptr;
25}; 49};
26 50
51Logger& GetLogger() {
52 static Logger* instance = new Logger();
53 return *instance;
54}
55
27} // namespace 56} // namespace
28 57
29void TrackerLog(std::string text) { 58void TrackerLog(std::string text) { GetLogger().LogLine(text); }
30 static Logger* instance = new Logger(); 59
31 instance->LogLine(text); 60std::string TrackerReadPastLog() { return GetLogger().GetContents(); }
61
62void TrackerSetLogDialog(LogDialog* log_dialog) {
63 GetLogger().SetLogDialog(log_dialog);
32} 64}
diff --git a/src/logger.h b/src/logger.h index a27839f..f669790 100644 --- a/src/logger.h +++ b/src/logger.h
@@ -3,6 +3,12 @@
3 3
4#include <string> 4#include <string>
5 5
6class LogDialog;
7
6void TrackerLog(std::string message); 8void TrackerLog(std::string message);
7 9
10std::string TrackerReadPastLog();
11
12void TrackerSetLogDialog(LogDialog* log_dialog);
13
8#endif /* end of include guard: LOGGER_H_9BDD07EA */ 14#endif /* end of include guard: LOGGER_H_9BDD07EA */
diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index 4a4e3b5..6a4ab2e 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp
@@ -18,6 +18,8 @@
18#include "ipc_dialog.h" 18#include "ipc_dialog.h"
19#include "ipc_state.h" 19#include "ipc_state.h"
20#include "items_pane.h" 20#include "items_pane.h"
21#include "log_dialog.h"
22#include "logger.h"
21#include "options_pane.h" 23#include "options_pane.h"
22#include "paintings_pane.h" 24#include "paintings_pane.h"
23#include "settings_dialog.h" 25#include "settings_dialog.h"
@@ -50,6 +52,7 @@ enum TrackerFrameIds {
50 ID_ZOOM_OUT = 5, 52 ID_ZOOM_OUT = 5,
51 ID_OPEN_SAVE_FILE = 6, 53 ID_OPEN_SAVE_FILE = 6,
52 ID_IPC_CONNECT = 7, 54 ID_IPC_CONNECT = 7,
55 ID_LOG_DIALOG = 8,
53}; 56};
54 57
55wxDEFINE_EVENT(STATE_RESET, wxCommandEvent); 58wxDEFINE_EVENT(STATE_RESET, wxCommandEvent);
@@ -80,6 +83,8 @@ TrackerFrame::TrackerFrame()
80 wxMenu *menuView = new wxMenu(); 83 wxMenu *menuView = new wxMenu();
81 zoom_in_menu_item_ = menuView->Append(ID_ZOOM_IN, "Zoom In\tCtrl-+"); 84 zoom_in_menu_item_ = menuView->Append(ID_ZOOM_IN, "Zoom In\tCtrl-+");
82 zoom_out_menu_item_ = menuView->Append(ID_ZOOM_OUT, "Zoom Out\tCtrl--"); 85 zoom_out_menu_item_ = menuView->Append(ID_ZOOM_OUT, "Zoom Out\tCtrl--");
86 menuView->AppendSeparator();
87 menuView->Append(ID_LOG_DIALOG, "Show Log Window\tCtrl-L");
83 88
84 zoom_in_menu_item_->Enable(false); 89 zoom_in_menu_item_->Enable(false);
85 zoom_out_menu_item_->Enable(false); 90 zoom_out_menu_item_->Enable(false);
@@ -106,6 +111,7 @@ TrackerFrame::TrackerFrame()
106 ID_CHECK_FOR_UPDATES); 111 ID_CHECK_FOR_UPDATES);
107 Bind(wxEVT_MENU, &TrackerFrame::OnZoomIn, this, ID_ZOOM_IN); 112 Bind(wxEVT_MENU, &TrackerFrame::OnZoomIn, this, ID_ZOOM_IN);
108 Bind(wxEVT_MENU, &TrackerFrame::OnZoomOut, this, ID_ZOOM_OUT); 113 Bind(wxEVT_MENU, &TrackerFrame::OnZoomOut, this, ID_ZOOM_OUT);
114 Bind(wxEVT_MENU, &TrackerFrame::OnOpenLogWindow, this, ID_LOG_DIALOG);
109 Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, &TrackerFrame::OnChangePage, this); 115 Bind(wxEVT_NOTEBOOK_PAGE_CHANGED, &TrackerFrame::OnChangePage, this);
110 Bind(wxEVT_MENU, &TrackerFrame::OnOpenFile, this, ID_OPEN_SAVE_FILE); 116 Bind(wxEVT_MENU, &TrackerFrame::OnOpenFile, this, ID_OPEN_SAVE_FILE);
111 Bind(wxEVT_SPLITTER_SASH_POS_CHANGED, &TrackerFrame::OnSashPositionChanged, 117 Bind(wxEVT_SPLITTER_SASH_POS_CHANGED, &TrackerFrame::OnSashPositionChanged,
@@ -270,6 +276,26 @@ void TrackerFrame::OnZoomOut(wxCommandEvent &event) {
270 } 276 }
271} 277}
272 278
279void TrackerFrame::OnOpenLogWindow(wxCommandEvent &event) {
280 if (log_dialog_ == nullptr) {
281 log_dialog_ = new LogDialog(this);
282 log_dialog_->Show();
283 TrackerSetLogDialog(log_dialog_);
284
285 log_dialog_->Bind(wxEVT_CLOSE_WINDOW, &TrackerFrame::OnCloseLogWindow,
286 this);
287 } else {
288 log_dialog_->SetFocus();
289 }
290}
291
292void TrackerFrame::OnCloseLogWindow(wxCloseEvent& event) {
293 TrackerSetLogDialog(nullptr);
294 log_dialog_ = nullptr;
295
296 event.Skip();
297}
298
273void TrackerFrame::OnChangePage(wxBookCtrlEvent &event) { 299void TrackerFrame::OnChangePage(wxBookCtrlEvent &event) {
274 zoom_in_menu_item_->Enable(event.GetSelection() == 1); 300 zoom_in_menu_item_->Enable(event.GetSelection() == 1);
275 zoom_out_menu_item_->Enable(event.GetSelection() == 1); 301 zoom_out_menu_item_->Enable(event.GetSelection() == 1);
diff --git a/src/tracker_frame.h b/src/tracker_frame.h index 55e7759..7704208 100644 --- a/src/tracker_frame.h +++ b/src/tracker_frame.h
@@ -15,6 +15,7 @@
15 15
16class AchievementsPane; 16class AchievementsPane;
17class ItemsPane; 17class ItemsPane;
18class LogDialog;
18class OptionsPane; 19class OptionsPane;
19class PaintingsPane; 20class PaintingsPane;
20class SubwayMap; 21class SubwayMap;
@@ -49,6 +50,7 @@ class ApConnectEvent : public wxEvent {
49 50
50struct StateUpdate { 51struct StateUpdate {
51 std::vector<ItemState> items; 52 std::vector<ItemState> items;
53 bool progression_items = false;
52 std::vector<std::string> paintings; 54 std::vector<std::string> paintings;
53 bool achievements = false; 55 bool achievements = false;
54 bool open_panels_tab = false; 56 bool open_panels_tab = false;
@@ -94,6 +96,8 @@ class TrackerFrame : public wxFrame {
94 void OnCheckForUpdates(wxCommandEvent &event); 96 void OnCheckForUpdates(wxCommandEvent &event);
95 void OnZoomIn(wxCommandEvent &event); 97 void OnZoomIn(wxCommandEvent &event);
96 void OnZoomOut(wxCommandEvent &event); 98 void OnZoomOut(wxCommandEvent &event);
99 void OnOpenLogWindow(wxCommandEvent &event);
100 void OnCloseLogWindow(wxCloseEvent &event);
97 void OnChangePage(wxBookCtrlEvent &event); 101 void OnChangePage(wxBookCtrlEvent &event);
98 void OnOpenFile(wxCommandEvent &event); 102 void OnOpenFile(wxCommandEvent &event);
99 void OnSashPositionChanged(wxSplitterEvent &event); 103 void OnSashPositionChanged(wxSplitterEvent &event);
@@ -114,6 +118,7 @@ class TrackerFrame : public wxFrame {
114 PaintingsPane *paintings_pane_; 118 PaintingsPane *paintings_pane_;
115 SubwayMap *subway_map_; 119 SubwayMap *subway_map_;
116 TrackerPanel *panels_panel_ = nullptr; 120 TrackerPanel *panels_panel_ = nullptr;
121 LogDialog *log_dialog_ = nullptr;
117 122
118 wxMenuItem *zoom_in_menu_item_; 123 wxMenuItem *zoom_in_menu_item_;
119 wxMenuItem *zoom_out_menu_item_; 124 wxMenuItem *zoom_out_menu_item_;