mirror of https://github.com/daleclack/My_GtkUi
Restore runner
This commit is contained in:
parent
340917fa52
commit
107134c3c3
|
@ -27,7 +27,7 @@ set(SOURCES src/core/main.cpp src/core/MainWin.cpp src/core/MyStack.cpp
|
|||
src/core/MyItem.cpp src/ui/MyDock.cpp src/ui/MyFinder.cpp src/ui/MyPrefs.cpp
|
||||
src/ui/AppView.cpp src/file_app/FileColumnView.cpp src/file_app/FileGridView.cpp
|
||||
src/file_app/FileWindow.cpp src/game_app/GameApp.cpp src/calc_app/calc.cpp
|
||||
src/calc_app/CalcApp.cpp)
|
||||
src/calc_app/CalcApp.cpp src/run_app/RunApp.cpp)
|
||||
|
||||
#Compile resources with GCR_CMake
|
||||
|
||||
|
@ -138,7 +138,7 @@ if(WIN32)
|
|||
set_property(SOURCE icon.rc APPEND PROPERTY
|
||||
OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/icon.ico
|
||||
)
|
||||
add_executable(My_GtkUI ${app_WINRC} ${SOURCES} ${RESOURCE_FILE})
|
||||
add_executable(My_GtkUI WIN32 ${app_WINRC} ${SOURCES} ${RESOURCE_FILE})
|
||||
else()
|
||||
add_executable(My_GtkUI ${SOURCES} ${RESOURCE_FILE})
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_DECLARE_FINAL_TYPE(RunApp, run_app, RUN, APP, GtkWindow)
|
||||
|
||||
RunApp *run_app_new(GtkWindow *parent);
|
|
@ -1,19 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
class GtkRunner : public Gtk::Dialog{
|
||||
public:
|
||||
GtkRunner();
|
||||
protected:
|
||||
void on_response(int response_id) override;
|
||||
private:
|
||||
//Child Widgets
|
||||
Gtk::Box hbox;
|
||||
Gtk::Entry app_entry;
|
||||
Gtk::Button open_btn;
|
||||
//File Dialog
|
||||
Glib::RefPtr<Gtk::FileChooserNative> dialog;
|
||||
void file_dialog();
|
||||
void dialog_response(int response);
|
||||
};
|
|
@ -0,0 +1,81 @@
|
|||
#include "RunApp.h"
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
|
||||
struct _RunApp
|
||||
{
|
||||
GtkWindow parent_instance;
|
||||
GtkWidget *main_box, *entry_box, *btn_box;
|
||||
GtkWidget *entry_run;
|
||||
GtkWidget *btnok, *btncel, *btnpath;
|
||||
GtkWidget *label, *label2;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(RunApp, run_app, GTK_TYPE_WINDOW)
|
||||
|
||||
static void btnok_clicked(GtkButton *btn, RunApp *self)
|
||||
{
|
||||
auto text = gtk_editable_get_text(GTK_EDITABLE(self->entry_run));
|
||||
std::thread run_app(system, text);
|
||||
run_app.detach();
|
||||
gtk_window_destroy(GTK_WINDOW(self));
|
||||
}
|
||||
|
||||
static void btncancel_clicked(GtkButton *btn, RunApp *self)
|
||||
{
|
||||
gtk_window_destroy(GTK_WINDOW(self));
|
||||
}
|
||||
|
||||
static void btnpath_clicked(GtkButton *btn, RunApp *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void run_app_init(RunApp *self)
|
||||
{
|
||||
// Initalize windows
|
||||
gtk_window_set_title(GTK_WINDOW(self), "Run a command");
|
||||
gtk_window_set_icon_name(GTK_WINDOW(self), "myrunner");
|
||||
gtk_window_set_default_size(GTK_WINDOW(self), 300, 150);
|
||||
|
||||
// Create widgets
|
||||
self->main_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
|
||||
self->entry_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
|
||||
self->btn_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
|
||||
self->entry_run = gtk_entry_new();
|
||||
self->btnok = gtk_button_new_with_label("OK");
|
||||
self->btncel = gtk_button_new_with_label("Cancel");
|
||||
self->btnpath = gtk_button_new_with_label("...");
|
||||
self->label = gtk_label_new(" ");
|
||||
self->label2 = gtk_label_new(" ");
|
||||
gtk_editable_set_text(GTK_EDITABLE(self->entry_run), "vlc");
|
||||
gtk_widget_set_halign(self->entry_box, GTK_ALIGN_CENTER);
|
||||
gtk_widget_set_halign(self->btn_box, GTK_ALIGN_END);
|
||||
|
||||
// Pack widgets
|
||||
gtk_box_append(GTK_BOX(self->entry_box), self->entry_run);
|
||||
gtk_box_append(GTK_BOX(self->entry_box), self->btnpath);
|
||||
gtk_box_append(GTK_BOX(self->btn_box), self->btnok);
|
||||
gtk_box_append(GTK_BOX(self->btn_box), self->btncel);
|
||||
gtk_box_append(GTK_BOX(self->main_box), self->label);
|
||||
gtk_box_append(GTK_BOX(self->main_box), self->entry_box);
|
||||
gtk_box_append(GTK_BOX(self->main_box), self->label2);
|
||||
gtk_box_append(GTK_BOX(self->main_box), self->btn_box);
|
||||
|
||||
// Link signals
|
||||
g_signal_connect(self->btnok, "clicked", G_CALLBACK(btnok_clicked), self);
|
||||
g_signal_connect(self->btncel, "clicked", G_CALLBACK(btncancel_clicked), self);
|
||||
g_signal_connect(self->btnpath, "clicked", G_CALLBACK(btnpath_clicked), self);
|
||||
|
||||
// Set Child
|
||||
gtk_window_set_child(GTK_WINDOW(self), self->main_box);
|
||||
}
|
||||
|
||||
static void run_app_class_init(RunAppClass *klass)
|
||||
{
|
||||
}
|
||||
|
||||
RunApp *run_app_new(GtkWindow *parent)
|
||||
{
|
||||
return RUN_APP(g_object_new(run_app_get_type(),
|
||||
"transient-for", parent, NULL));
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
#include "Runner.hh"
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
|
||||
GtkRunner::GtkRunner() : hbox(Gtk::Orientation::HORIZONTAL, 5),
|
||||
open_btn("...")
|
||||
{
|
||||
// Ininalize window
|
||||
set_title("Run a Command");
|
||||
set_icon_name("myrunner");
|
||||
set_default_size(300, 150);
|
||||
add_button("OK", Gtk::RESPONSE_OK);
|
||||
add_button("Cancel", Gtk::RESPONSE_CANCEL);
|
||||
set_default_response(Gtk::RESPONSE_OK);
|
||||
|
||||
// Initalize Box
|
||||
hbox.set_halign(Gtk::Align::CENTER);
|
||||
hbox.set_valign(Gtk::Align::CENTER);
|
||||
hbox.append(app_entry);
|
||||
hbox.append(open_btn);
|
||||
|
||||
// Initalize entry
|
||||
app_entry.set_activates_default();
|
||||
app_entry.set_text("vlc");
|
||||
|
||||
open_btn.signal_clicked().connect(sigc::mem_fun(*this, &GtkRunner::file_dialog));
|
||||
|
||||
// Add Widgets
|
||||
auto pbox = get_content_area();
|
||||
pbox->append(hbox);
|
||||
|
||||
show_all_children();
|
||||
}
|
||||
|
||||
void GtkRunner::on_response(int response_id)
|
||||
{
|
||||
if (response_id == Gtk::RESPONSE_OK)
|
||||
{
|
||||
// Start The Application
|
||||
std::string program = app_entry.get_text();
|
||||
std::string program_file = Glib::filename_from_utf8(program);
|
||||
std::thread first(system, program_file.c_str());
|
||||
first.detach();
|
||||
}
|
||||
hide();
|
||||
}
|
||||
|
||||
void GtkRunner::file_dialog()
|
||||
{
|
||||
dialog = Gtk::FileChooserNative::create("Open a program",
|
||||
Gtk::FILE_CHOOSER_ACTION_OPEN, "OK", "Cancel");
|
||||
|
||||
dialog->signal_response().connect(sigc::mem_fun(*this, &GtkRunner::dialog_response));
|
||||
|
||||
auto filter_app = Gtk::FileFilter::create();
|
||||
filter_app->set_name("Applications");
|
||||
filter_app->add_mime_type("application/*");
|
||||
dialog->add_filter(filter_app);
|
||||
|
||||
auto filter_any = Gtk::FileFilter::create();
|
||||
filter_any->set_name("Any Files");
|
||||
filter_any->add_pattern("*");
|
||||
dialog->add_filter(filter_any);
|
||||
|
||||
dialog->show();
|
||||
}
|
||||
|
||||
void GtkRunner::dialog_response(int response)
|
||||
{
|
||||
if (response == Gtk::RESPONSE_ACCEPT)
|
||||
{
|
||||
Glib::ustring filename = dialog->get_filename();
|
||||
Glib::ustring text = Glib::filename_to_utf8(filename);
|
||||
app_entry.set_text(text);
|
||||
}
|
||||
dialog.reset();
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
#include "FileWindow.h"
|
||||
#include "GameApp.h"
|
||||
#include "CalcApp.h"
|
||||
#include "RunApp.h"
|
||||
|
||||
enum PadPage
|
||||
{
|
||||
|
@ -279,6 +280,13 @@ static gboolean calc_win_closed(GtkWidget *calc_win, MyDock *dock)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void padrun_clicked(GtkWidget *widget, MyDock *dock)
|
||||
{
|
||||
// Create "Run App" Window and show
|
||||
RunApp *run_win = run_app_new(dock->parent_win);
|
||||
gtk_window_present(GTK_WINDOW(run_win));
|
||||
}
|
||||
|
||||
static void my_dock_get_widgets(MyDock *self)
|
||||
{
|
||||
// Get widgets
|
||||
|
@ -395,6 +403,9 @@ static void my_dock_init(MyDock *self)
|
|||
g_signal_connect(self->padcalc, "clicked", G_CALLBACK(padcalc_clicked), self);
|
||||
g_signal_connect(self->calc_win, "close-request", G_CALLBACK(calc_win_closed), self);
|
||||
|
||||
// Signal for app runner
|
||||
g_signal_connect(self->padrun, "clicked", G_CALLBACK(padrun_clicked), self);
|
||||
|
||||
// Add finder
|
||||
self->finder = my_finder_new(GTK_ORIENTATION_HORIZONTAL, 5);
|
||||
gtk_box_append(GTK_BOX(self->finder_box), self->finder);
|
||||
|
|
Loading…
Reference in New Issue