Skip to content

Commit

Permalink
Switch to using C++ smart pointers in most cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kosude committed Jun 10, 2024
1 parent f63406c commit 34710b1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
12 changes: 2 additions & 10 deletions texedit/gui/layout/panes/preview_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,14 @@ namespace te::gui {
}

PreviewPane::~PreviewPane() {
// delete last loaded document if applicable
if (_document) {
delete _document;
}
}

void PreviewPane::SetPDFLocation(const wxString &path) {
try {
// document is heap-allocated, so replace it here
if (_document) {
delete _document;
}
_document = new pdfr::PDFDocument(path);
_document = std::make_unique<pdfr::PDFDocument>(path);

// RenderDocument() stores the new document's rendered images into the canvas object to be drawn later
_canvas->RenderDocument(_document);
_canvas->RenderDocument(_document.get());
} catch (except::PDFException *e) {
// TODO: show error message in the preview pane.
wxLogError("%s", e->what());
Expand Down
9 changes: 5 additions & 4 deletions texedit/gui/layout/panes/preview_pane.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
#ifndef __texedit__preview_pane_hpp__
#define __texedit__preview_pane_hpp__

#include <wx/wx.h>
#include <wx/webview.h>

#include "pane_base.hpp"
#include "gui/pdf_viewer/pdf_canvas.hpp"

#include <wx/wx.h>
#include <wx/webview.h>
#include <memory>

namespace te::pdfr {
class PDFDocument;
}
Expand All @@ -30,7 +31,7 @@ namespace te::gui {
private:
wxBoxSizer *_sizer;

pdfr::PDFDocument *_document{nullptr};
std::unique_ptr<pdfr::PDFDocument> _document{nullptr};
PDFCanvas *_canvas;
};
}
Expand Down
5 changes: 2 additions & 3 deletions texedit/gui/main_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace te::gui {
BuildMenuBar();

// use logger for message redirects
_logger = new util::GlobalLogger(_layout.GetOutputPane()->GetListBox());
wxLog::SetActiveTarget(_logger);
_logger = std::make_unique<util::GlobalLogger>(_layout.GetOutputPane()->GetListBox());
wxLog::SetActiveTarget(_logger.get());

// TODO: temp --
_layout.GetPreviewPane()->SetPDFLocation("HelloWorld.pdf");
Expand All @@ -37,7 +37,6 @@ namespace te::gui {
MainFrame::~MainFrame() {
// reset logging to default behaviour before deleting the logger object
wxLog::SetActiveTarget(nullptr);
delete _logger;
}

void MainFrame::BuildMenuBar() {
Expand Down
3 changes: 2 additions & 1 deletion texedit/gui/main_frame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <wx/wx.h>
#include <wx/treebase.h>
#include <memory>

namespace te::gui {
class MainFrame : public wxFrame {
Expand All @@ -25,7 +26,7 @@ namespace te::gui {

private:
LayoutManager _layout;
util::GlobalLogger *_logger;
std::unique_ptr<util::GlobalLogger> _logger;

proc::ProcessManager _proc_mgr;
proc::CompilerProcess *_compiler_proc;
Expand Down

0 comments on commit 34710b1

Please sign in to comment.