From 229c7569ade185293a5eff98e9cebfffd5415586 Mon Sep 17 00:00:00 2001 From: daleclack Date: Wed, 23 Jun 2021 22:26:32 +0800 Subject: [PATCH] Add Input Dialog --- XeRelease_Gtkmm3/src/MyDialog.cc | 39 ++++++++++++++++++++++++++++++++ XeRelease_Gtkmm3/src/MyDialog.hh | 14 +++++++++++- XeRelease_Gtkmm3/src/MyWin.cc | 24 +++++++++++++++++++- XeRelease_Gtkmm3/src/MyWin.hh | 6 +++++ 4 files changed, 81 insertions(+), 2 deletions(-) diff --git a/XeRelease_Gtkmm3/src/MyDialog.cc b/XeRelease_Gtkmm3/src/MyDialog.cc index 073df9f..6f3767f 100644 --- a/XeRelease_Gtkmm3/src/MyDialog.cc +++ b/XeRelease_Gtkmm3/src/MyDialog.cc @@ -1,4 +1,43 @@ #include "MyDialog.hh" +#include + +MyDialog::MyDialog(Gtk::Window &parent) +:label2(" ") +{ + //Initalize MsgBox + set_icon_name("Xe-Release"); + set_default_size(300,150); + add_button("OK",Gtk::RESPONSE_OK); + add_button("Cancel",Gtk::RESPONSE_CANCEL); + set_transient_for(parent); + //Add Widgets + entry.set_text("default config"); + entry.signal_activate().connect(sigc::bind(sigc::mem_fun(*this,&MyDialog::response),Gtk::RESPONSE_OK)); + vbox=get_content_area(); + vbox->pack_start(msg_label,Gtk::PACK_SHRINK); + vbox->pack_start(label2,Gtk::PACK_SHRINK); + vbox->pack_start(entry,Gtk::PACK_SHRINK); +} + +void MyDialog::set_filename(const char *filename){ + strcpy(filename1,filename); +} + +void MyDialog::set_msg(Glib::ustring msg){ + msg_label.set_label(msg); +} + +void MyDialog::on_response(int response_id){ + //Save Text into file + if(response_id==Gtk::RESPONSE_OK){ + FILE *fp=fopen(filename1,"wt+"); + Glib::ustring str=entry.get_text(); + fprintf(fp,"%s",str.c_str()); + fclose(fp); + } + entry.set_text("default config"); + hide(); +} MsgBox::MsgBox(Gtk::Window &parent) :hbox(Gtk::ORIENTATION_HORIZONTAL,5) diff --git a/XeRelease_Gtkmm3/src/MyDialog.hh b/XeRelease_Gtkmm3/src/MyDialog.hh index bcae41f..67b5835 100644 --- a/XeRelease_Gtkmm3/src/MyDialog.hh +++ b/XeRelease_Gtkmm3/src/MyDialog.hh @@ -3,7 +3,19 @@ #include class MyDialog : public Gtk::Dialog{ - +public: + MyDialog(Gtk::Window &parent); + void set_filename(const char *filename); + void set_msg(Glib::ustring msg); +protected: + void on_response(int response_id) override; +private: + //Child widgets + Gtk::Label msg_label,label2; + Gtk::Entry entry; + Gtk::Box *vbox; + //File Proprties + char filename1[57]; }; class MsgBox : public Gtk::Dialog{ diff --git a/XeRelease_Gtkmm3/src/MyWin.cc b/XeRelease_Gtkmm3/src/MyWin.cc index 5c1164a..c8e9840 100644 --- a/XeRelease_Gtkmm3/src/MyWin.cc +++ b/XeRelease_Gtkmm3/src/MyWin.cc @@ -11,7 +11,8 @@ enum Releases{ MyWin::MyWin() :btn_box(Gtk::ORIENTATION_VERTICAL,5), btn_ver("Xe-Ver"), -msg_dialog(*this) +msg_dialog(*this), +input_dialog(*this) { //Initalize window set_icon_name("Xe-Release"); @@ -61,6 +62,9 @@ void MyWin::titlebar_init(){ popover.bind_model(gmenu); //Add Menu Actions + add_action("config1",sigc::mem_fun(*this,&MyWin::config_lts)); + add_action("config2",sigc::mem_fun(*this,&MyWin::config_stable)); + add_action("config3",sigc::mem_fun(*this,&MyWin::config_devel)); add_action("back1",sigc::mem_fun(*this,&MyWin::background1)); add_action("back2",sigc::mem_fun(*this,&MyWin::background2)); add_action("about",sigc::mem_fun(*this,&MyWin::about_dialog)); @@ -94,6 +98,24 @@ void MyWin::background2(){ sized.reset(); } +void MyWin::config_lts(){ + input_dialog.set_msg("Input Xe LTS Config"); + input_dialog.set_filename("config_lts"); + input_dialog.show_all(); +} + +void MyWin::config_stable(){ + input_dialog.set_msg("Input Xe Stable Config"); + input_dialog.set_filename("config_stable"); + input_dialog.show_all(); +} + +void MyWin::config_devel(){ + input_dialog.set_msg("Input Xe Devel Config"); + input_dialog.set_filename("config_devel"); + input_dialog.show_all(); +} + void MyWin::main_releases(){ int version=combo.get_active_row_number(); switch (version) diff --git a/XeRelease_Gtkmm3/src/MyWin.hh b/XeRelease_Gtkmm3/src/MyWin.hh index e9484b8..0d2b391 100644 --- a/XeRelease_Gtkmm3/src/MyWin.hh +++ b/XeRelease_Gtkmm3/src/MyWin.hh @@ -25,11 +25,17 @@ private: //Dialogs MsgBox msg_dialog; + MyDialog input_dialog; //Backgrounds void background1(); void background2(); + //Version Configs + void config_lts(); + void config_stable(); + void config_devel(); + //Signal Handlers void about_dialog(); void main_releases();