[gtkmm-documentation] Add Gtk::FileChooserNative example



commit 0120657e0f1f5f18bc8bad59c5f6edefe75a5659
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri Jun 30 15:34:50 2017 +0200

    Add Gtk::FileChooserNative example
    
    Bug 783801

 examples/Makefile.am                               |    6 ++
 .../dialogs/filechoosernative/examplewindow.cc     |   74 ++++++++++++++++++++
 .../book/dialogs/filechoosernative/examplewindow.h |   37 ++++++++++
 examples/book/dialogs/filechoosernative/main.cc    |   27 +++++++
 4 files changed, 144 insertions(+), 0 deletions(-)
---
diff --git a/examples/Makefile.am b/examples/Makefile.am
index c4ece4b..6e2a89f 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -38,6 +38,7 @@ check_PROGRAMS =                                      \
        book/dialogs/aboutdialog/example                \
        book/dialogs/colorchooserdialog/example \
        book/dialogs/filechooserdialog/example          \
+       book/dialogs/filechoosernative/example          \
        book/dialogs/fontchooserdialog/example  \
        book/dialogs/messagedialog/example              \
        book/dialogs/simple/example                     \
@@ -306,6 +307,11 @@ book_dialogs_filechooserdialog_example_SOURCES =   \
        book/dialogs/filechooserdialog/examplewindow.h  \
        book/dialogs/filechooserdialog/main.cc
 
+book_dialogs_filechoosernative_example_SOURCES =       \
+       book/dialogs/filechoosernative/examplewindow.cc \
+       book/dialogs/filechoosernative/examplewindow.h  \
+       book/dialogs/filechoosernative/main.cc
+
 book_dialogs_fontchooserdialog_example_SOURCES =               \
        book/dialogs/fontchooserdialog/examplewindow.cc \
        book/dialogs/fontchooserdialog/examplewindow.h  \
diff --git a/examples/book/dialogs/filechoosernative/examplewindow.cc 
b/examples/book/dialogs/filechoosernative/examplewindow.cc
new file mode 100644
index 0000000..eef07c7
--- /dev/null
+++ b/examples/book/dialogs/filechoosernative/examplewindow.cc
@@ -0,0 +1,74 @@
+/* gtkmm example Copyright (C) 2017 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "examplewindow.h"
+#include <iostream>
+
+ExampleWindow::ExampleWindow()
+: m_ButtonBox(Gtk::Orientation::VERTICAL),
+  m_Button_File_Open("Choose File To Open"),
+  m_Button_File_Save("Choose File To Save")
+{
+  set_title("Gtk::FileChooserNative example");
+
+  add(m_ButtonBox);
+
+  m_ButtonBox.pack_start(m_Button_File_Open, Gtk::PackOptions::EXPAND_WIDGET);
+  m_Button_File_Open.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
+    &ExampleWindow::on_button_file_clicked), Gtk::FileChooser::Action::OPEN));
+
+  m_ButtonBox.pack_start(m_Button_File_Save, Gtk::PackOptions::EXPAND_WIDGET);
+  m_Button_File_Save.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
+    &ExampleWindow::on_button_file_clicked), Gtk::FileChooser::Action::SAVE));
+}
+
+ExampleWindow::~ExampleWindow()
+{
+}
+
+void ExampleWindow::on_button_file_clicked(Gtk::FileChooser::Action action)
+{
+  const bool open = (action == Gtk::FileChooser::Action::OPEN);
+  auto dialog = Gtk::FileChooserNative::create("Please choose a file", *this, action);
+
+  // Show the dialog and wait for a user response:
+  const int result = dialog->run();
+
+  // Handle the response:
+  switch (result)
+  {
+  case Gtk::ResponseType::ACCEPT:
+  {
+    std::cout << (open ? "Open" : "Save") << " clicked." << std::endl;
+
+    // Notice that this is a std::string, not a Glib::ustring.
+    auto filename = dialog->get_filename();
+    std::cout << "File selected: " <<  filename << std::endl;
+    break;
+  }
+
+  case Gtk::ResponseType::CANCEL:
+    std::cout << "Cancel clicked." << std::endl;
+    break;
+
+  case Gtk::ResponseType::DELETE_EVENT:
+    std::cout << "Dialog closed." << std::endl;
+    break;
+
+  default:
+    std::cout << "Unexpected button clicked." << std::endl;
+    break;
+  }
+}
diff --git a/examples/book/dialogs/filechoosernative/examplewindow.h 
b/examples/book/dialogs/filechoosernative/examplewindow.h
new file mode 100644
index 0000000..57688f2
--- /dev/null
+++ b/examples/book/dialogs/filechoosernative/examplewindow.h
@@ -0,0 +1,37 @@
+/* gtkmm example Copyright (C) 2017 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTKMM_EXAMPLEWINDOW_H
+#define GTKMM_EXAMPLEWINDOW_H
+
+#include <gtkmm.h>
+
+class ExampleWindow : public Gtk::Window
+{
+public:
+  ExampleWindow();
+  virtual ~ExampleWindow();
+
+protected:
+  // Signal handlers:
+  void on_button_file_clicked(Gtk::FileChooser::Action action);
+
+  // Child widgets:
+  Gtk::ButtonBox m_ButtonBox;
+  Gtk::Button m_Button_File_Open;
+  Gtk::Button m_Button_File_Save;
+};
+
+#endif // GTKMM_EXAMPLEWINDOW_H
diff --git a/examples/book/dialogs/filechoosernative/main.cc b/examples/book/dialogs/filechoosernative/main.cc
new file mode 100644
index 0000000..629c67a
--- /dev/null
+++ b/examples/book/dialogs/filechoosernative/main.cc
@@ -0,0 +1,27 @@
+/* gtkmm example Copyright (C) 2017 gtkmm development team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "examplewindow.h"
+#include <gtkmm/application.h>
+
+int main(int argc, char* argv[])
+{
+  auto app = Gtk::Application::create("org.gtkmm.example");
+
+  ExampleWindow window;
+
+  // Shows the window and returns when it is closed.
+  return app->run(window, argc, argv);
+}


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