| 1 |
/* gtkmm example Copyright (C) 2016 gtkmm development team |
| 2 |
* |
| 3 |
* This program is free software; you can redistribute it and/or modify |
| 4 |
* it under the terms of the GNU General Public License as published by |
| 5 |
* the Free Software Foundation; either version 2 of the License, or |
| 6 |
* (at your option) any later version. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License along |
| 14 |
* with this program; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include "exampleapplication.h" |
| 18 |
#include "exampleappwindow.h" |
| 19 |
|
| 20 |
ExampleApplication::ExampleApplication() |
| 21 |
: Gtk::Application("org.gtkmm.examples.application", Gio::Application::Flags::HANDLES_OPEN) |
| 22 |
{ |
| 23 |
// Delete a window when it is removed from the application. |
| 24 |
signal_window_removed().connect([](Gtk::Window* window) { delete window; }); |
| 25 |
} |
| 26 |
|
| 27 |
Glib::RefPtr<ExampleApplication> ExampleApplication::create() |
| 28 |
{ |
| 29 |
return Glib::make_refptr_for_instance<ExampleApplication>(new ExampleApplication()); |
| 30 |
} |
| 31 |
|
| 32 |
ExampleAppWindow* ExampleApplication::create_appwindow() |
| 33 |
{ |
| 34 |
auto appwindow = new ExampleAppWindow(); |
| 35 |
|
| 36 |
// Make sure that the application runs for as long this window is still open. |
| 37 |
add_window(*appwindow); |
| 38 |
|
| 39 |
// A window can be added to an application with Gtk::Application::add_window() |
| 40 |
// or Gtk::Window::set_application(). When all added windows have been removed, |
| 41 |
// the application stops running (Gtk::Application::run() returns), |
| 42 |
// unless Gio::Application::hold() has been called. |
| 43 |
|
| 44 |
return appwindow; |
| 45 |
} |
| 46 |
|
| 47 |
void ExampleApplication::on_activate() |
| 48 |
{ |
| 49 |
// The application has been started, so let's show a window. |
| 50 |
auto appwindow = create_appwindow(); |
| 51 |
appwindow->present(); |
| 52 |
} |
| 53 |
|
| 54 |
void ExampleApplication::on_open(const Gio::Application::type_vec_files& files, |
| 55 |
const Glib::ustring& /* hint */) |
| 56 |
{ |
| 57 |
// The application has been asked to open some files, |
| 58 |
// so let's open a new view for each one. |
| 59 |
ExampleAppWindow* appwindow = nullptr; |
| 60 |
auto windows = get_windows(); |
| 61 |
if (windows.size() > 0) |
| 62 |
appwindow = dynamic_cast<ExampleAppWindow*>(windows[0]); |
| 63 |
|
| 64 |
if (!appwindow) |
| 65 |
appwindow = create_appwindow(); |
| 66 |
|
| 67 |
for (const auto& file : files) |
| 68 |
appwindow->open_file_view(file); |
| 69 |
|
| 70 |
appwindow->present(); |
| 71 |
} |