Add Input Dialog

This commit is contained in:
daleclack 2021-06-23 22:26:32 +08:00
parent beb3c0b938
commit 229c7569ad
4 changed files with 81 additions and 2 deletions

View File

@ -1,4 +1,43 @@
#include "MyDialog.hh" #include "MyDialog.hh"
#include <cstdio>
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) MsgBox::MsgBox(Gtk::Window &parent)
:hbox(Gtk::ORIENTATION_HORIZONTAL,5) :hbox(Gtk::ORIENTATION_HORIZONTAL,5)

View File

@ -3,7 +3,19 @@
#include <gtkmm.h> #include <gtkmm.h>
class MyDialog : public Gtk::Dialog{ 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{ class MsgBox : public Gtk::Dialog{

View File

@ -11,7 +11,8 @@ enum Releases{
MyWin::MyWin() MyWin::MyWin()
:btn_box(Gtk::ORIENTATION_VERTICAL,5), :btn_box(Gtk::ORIENTATION_VERTICAL,5),
btn_ver("Xe-Ver"), btn_ver("Xe-Ver"),
msg_dialog(*this) msg_dialog(*this),
input_dialog(*this)
{ {
//Initalize window //Initalize window
set_icon_name("Xe-Release"); set_icon_name("Xe-Release");
@ -61,6 +62,9 @@ void MyWin::titlebar_init(){
popover.bind_model(gmenu); popover.bind_model(gmenu);
//Add Menu Actions //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("back1",sigc::mem_fun(*this,&MyWin::background1));
add_action("back2",sigc::mem_fun(*this,&MyWin::background2)); add_action("back2",sigc::mem_fun(*this,&MyWin::background2));
add_action("about",sigc::mem_fun(*this,&MyWin::about_dialog)); add_action("about",sigc::mem_fun(*this,&MyWin::about_dialog));
@ -94,6 +98,24 @@ void MyWin::background2(){
sized.reset(); 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(){ void MyWin::main_releases(){
int version=combo.get_active_row_number(); int version=combo.get_active_row_number();
switch (version) switch (version)

View File

@ -25,11 +25,17 @@ private:
//Dialogs //Dialogs
MsgBox msg_dialog; MsgBox msg_dialog;
MyDialog input_dialog;
//Backgrounds //Backgrounds
void background1(); void background1();
void background2(); void background2();
//Version Configs
void config_lts();
void config_stable();
void config_devel();
//Signal Handlers //Signal Handlers
void about_dialog(); void about_dialog();
void main_releases(); void main_releases();