From dd63dfdc506660ea13304020818586df183ac4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Sat, 17 Oct 2015 15:53:09 +0200 Subject: [PATCH] Move windows to singleton and remove transient error --- src/dialogs.cc | 3 +-- src/juci.cc | 7 +++---- src/juci.h | 1 - src/singletons.cc | 8 ++++++++ src/singletons.h | 3 +++ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/dialogs.cc b/src/dialogs.cc index e8588e5..cbaaad7 100644 --- a/src/dialogs.cc +++ b/src/dialogs.cc @@ -12,13 +12,12 @@ std::string open_dialog(const std::string &title, else gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().string().c_str()); dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); - // dialog.set_transient_for(parent); TODO add parent + dialog.set_transient_for(*Singleton::window()); for (auto &button : buttons) dialog.add_button(button.first, button.second); return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : ""; } - std::string Dialog::select_folder() { return open_dialog("Please choose a folder", {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Open", Gtk::RESPONSE_OK)}, diff --git a/src/juci.cc b/src/juci.cc index 6171496..a01c77f 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -37,9 +37,8 @@ int app::on_command_line(const Glib::RefPtr &cmd) { } void app::on_activate() { - window = std::unique_ptr(new Window()); - add_window(*window); - window->show(); + add_window(*Singleton::window()); + Singleton::window()->show(); bool first_directory=true; for(auto &directory: directories) { if(first_directory) { @@ -64,7 +63,7 @@ void app::on_activate() { } } for(auto &file: files) - window->notebook.open(file); + Singleton::window()->notebook.open(file); } app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_NON_UNIQUE | Gio::APPLICATION_HANDLES_COMMAND_LINE) { diff --git a/src/juci.h b/src/juci.h index e672254..76a66d7 100644 --- a/src/juci.h +++ b/src/juci.h @@ -11,7 +11,6 @@ class app : public Gtk::Application { void on_activate(); private: - std::unique_ptr window; std::vector directories; std::vector files; void init_logging(); diff --git a/src/singletons.cc b/src/singletons.cc index b8734ec..a24cc82 100644 --- a/src/singletons.cc +++ b/src/singletons.cc @@ -6,6 +6,7 @@ std::unique_ptr Singleton::Config::terminal_=std::unique_ptr Singleton::Config::window_ = std::unique_ptr(new Window::Config()); std::unique_ptr Singleton::terminal_=std::unique_ptr(); std::unique_ptr Singleton::directories_=std::unique_ptr(); +std::unique_ptr Singleton::window_=std::unique_ptr(); Terminal *Singleton::terminal() { if(!terminal_) @@ -18,6 +19,13 @@ Directories *Singleton::directories() { directories_=std::unique_ptr(new Directories()); return directories_.get(); } + +Window *Singleton::window() { + if(!window_) + window_=std::unique_ptr(new Window()); + return window_.get(); +} + std::unique_ptr Singleton::status_=std::unique_ptr(); Gtk::Label *Singleton::status() { if(!status_) diff --git a/src/singletons.h b/src/singletons.h index 4f6fbab..f22f57b 100644 --- a/src/singletons.h +++ b/src/singletons.h @@ -10,6 +10,7 @@ #include "terminal.h" #include "notebook.h" #include "menu.h" +#include "window.h" class Singleton { public: @@ -34,11 +35,13 @@ public: static Directories *directories(); static Gtk::Label *status(); static Gtk::Label *info(); + static Window *window(); private: static std::unique_ptr terminal_; static std::unique_ptr status_; static std::unique_ptr info_; static std::unique_ptr directories_; + static std::unique_ptr window_; }; #endif // JUCI_SINGLETONS_H_