[glom] Window_PrintLayout_Edit: Use std::unique_ptr<> for the menu, instead of new and delete.



commit 06778b078426b9f7258b3384724ac713fdaf5a36
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Feb 5 10:47:21 2016 +0100

    Window_PrintLayout_Edit: Use std::unique_ptr<> for the menu, instead of new and delete.
    
    I am not very happy with passing the raw pointer to gtkmm's
    attach_to_widget(), but that seems to be the normal use of
    unique_ptr<>::operator*() and unique_ptr<>::get(),
    as long as we don't expect the receiving API to take any
    ownership.

 .../print_layouts/window_print_layout_edit.cc      |    9 +++++----
 .../print_layouts/window_print_layout_edit.h       |    2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/glom/mode_design/print_layouts/window_print_layout_edit.cc 
b/glom/mode_design/print_layouts/window_print_layout_edit.cc
index 97112b5..50927f0 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.cc
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.cc
@@ -279,9 +279,10 @@ void Window_PrintLayout_Edit::init_menu()
     g_warning("GMenu not found");
 
   //Menubar:
-  auto pMenuBar = new Gtk::MenuBar(gmenu);
-  m_box_menu->pack_start(*pMenuBar, Gtk::PACK_SHRINK);
-  pMenuBar->show();
+  auto menubar = std::make_unique<Gtk::MenuBar>(gmenu);
+  menubar->show();
+  m_box_menu->pack_start(*(Gtk::manage(menubar.release())), Gtk::PACK_SHRINK);
+
 
   //TODO: Create a generic checking method to test that
   //  all actions from the action group are in the GMenu?
@@ -706,7 +707,7 @@ void Window_PrintLayout_Edit::setup_context_menu()
   if(!gmenu)
     g_warning("GMenu not found");
 
-  m_context_menu = new Gtk::Menu(gmenu);
+  m_context_menu = std::make_unique<Gtk::Menu>(gmenu);
   m_context_menu->attach_to_widget(*this);
 }
 
diff --git a/glom/mode_design/print_layouts/window_print_layout_edit.h 
b/glom/mode_design/print_layouts/window_print_layout_edit.h
index e96a527..fdb7844 100644
--- a/glom/mode_design/print_layouts/window_print_layout_edit.h
+++ b/glom/mode_design/print_layouts/window_print_layout_edit.h
@@ -205,7 +205,7 @@ private:
   PrintLayoutToolbar m_toolbar;
   
   //Context menu for clicking on empty space on the canvas:
-  Gtk::Menu* m_context_menu;
+  std::unique_ptr<Gtk::Menu> m_context_menu;
 };
 
 } //namespace Glom


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]