Obtained open/close with changing mode
This commit is contained in:
parent
c736e15ecd
commit
4d65a51e09
45
include/ui.h
45
include/ui.h
|
@ -103,14 +103,39 @@ void on_savefile_action(GSimpleAction *action,
|
||||||
|
|
||||||
|
|
||||||
static const GActionEntry app_actions[] = {
|
static const GActionEntry app_actions[] = {
|
||||||
{ "quit", on_quit_action },
|
{ "quit", on_quit_action, NULL, NULL, NULL },
|
||||||
{ "about", on_about_action },
|
{ "about", on_about_action, NULL, NULL, NULL },
|
||||||
{ "preferences", on_preferences_action },
|
{ "preferences", on_preferences_action, NULL, NULL, NULL },
|
||||||
{ "togglesidebar", on_togglesidebar_action },
|
{ "togglesidebar", on_togglesidebar_action, NULL, NULL, NULL },
|
||||||
{ "editmode", on_editmode_action },
|
{ "editmode", on_editmode_action, NULL, NULL, NULL },
|
||||||
{ "runmode", on_runmode_action },
|
{ "runmode", on_runmode_action, NULL, NULL, NULL },
|
||||||
{ "presentmode", on_presentmode_action },
|
{ "presentmode", on_presentmode_action, NULL, NULL, NULL },
|
||||||
{ "openfile", on_openfile_action },
|
{ "openfile", on_openfile_action, NULL, NULL, NULL },
|
||||||
{ "closefile", on_closefile_action },
|
{ "closefile", on_closefile_action, NULL, NULL, NULL },
|
||||||
{ "savefile", on_savefile_action },
|
{ "savefile", on_savefile_action, NULL, NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void uiApplicationEnableAction(const char *name);
|
||||||
|
|
||||||
|
void uiApplicationDisableAction(const char *name);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Actions responses
|
||||||
|
//
|
||||||
|
void on_openfile_response(GtkNativeDialog *native,
|
||||||
|
int response,
|
||||||
|
GemGraphClientWindow *self);
|
||||||
|
|
||||||
|
void on_openfile_response_complete(GObject *source_object,
|
||||||
|
GAsyncResult *result,
|
||||||
|
GemGraphClientWindow *self);
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
//
|
||||||
|
// Window primitives
|
||||||
|
//
|
||||||
|
|
||||||
|
void uiWindowStackChange(const char *mode);
|
||||||
|
|
||||||
|
void uiWindowSendNotification(const char *message);
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "../../include/base.h"
|
#include "../../include/base.h"
|
||||||
#include "../../include/ui.h"
|
#include "../../include/ui.h"
|
||||||
|
|
||||||
|
@ -67,7 +69,7 @@ void on_preferences_action(GSimpleAction *action,
|
||||||
|
|
||||||
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
|
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
|
||||||
|
|
||||||
g_application_quit(G_APPLICATION(self));
|
uiWindowSendNotification("Not implemented !");
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_togglesidebar_action(GSimpleAction *action,
|
void on_togglesidebar_action(GSimpleAction *action,
|
||||||
|
@ -78,7 +80,7 @@ void on_togglesidebar_action(GSimpleAction *action,
|
||||||
|
|
||||||
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
|
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
|
||||||
|
|
||||||
g_application_quit(G_APPLICATION(self));
|
uiWindowSendNotification("Not implemented !");
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_editmode_action(GSimpleAction *action,
|
void on_editmode_action(GSimpleAction *action,
|
||||||
|
@ -122,7 +124,24 @@ void on_openfile_action(GSimpleAction *action,
|
||||||
|
|
||||||
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
|
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
|
||||||
|
|
||||||
g_application_quit(G_APPLICATION(self));
|
// Create a new file selection dialog, using the "open" mode
|
||||||
|
GtkFileChooserNative *native =
|
||||||
|
gtk_file_chooser_native_new("Open File",
|
||||||
|
GTK_WINDOW(self),
|
||||||
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||||
|
"_Open",
|
||||||
|
"_Cancel");
|
||||||
|
|
||||||
|
// Connect the "response" signal of the file selection dialog;
|
||||||
|
// this signal is emitted when the user selects a file, or when
|
||||||
|
// they cancel the operation
|
||||||
|
g_signal_connect (native,
|
||||||
|
"response",
|
||||||
|
G_CALLBACK(on_openfile_response),
|
||||||
|
self);
|
||||||
|
|
||||||
|
// Present the dialog to the user
|
||||||
|
gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_closefile_action(GSimpleAction *action,
|
void on_closefile_action(GSimpleAction *action,
|
||||||
|
@ -133,7 +152,12 @@ void on_closefile_action(GSimpleAction *action,
|
||||||
|
|
||||||
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
|
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
|
||||||
|
|
||||||
g_application_quit(G_APPLICATION(self));
|
uiApplicationDisableAction("closefile");
|
||||||
|
uiApplicationDisableAction("savefile");
|
||||||
|
uiApplicationDisableAction("runmode");
|
||||||
|
uiApplicationDisableAction("editmode");
|
||||||
|
uiApplicationDisableAction("presentmode");
|
||||||
|
uiWindowStackChange("home");
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_savefile_action(GSimpleAction *action,
|
void on_savefile_action(GSimpleAction *action,
|
||||||
|
@ -144,6 +168,69 @@ void on_savefile_action(GSimpleAction *action,
|
||||||
|
|
||||||
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
|
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(self));
|
||||||
|
|
||||||
g_application_quit(G_APPLICATION(self));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Responses
|
||||||
|
*/
|
||||||
|
void on_openfile_response(GtkNativeDialog *native,
|
||||||
|
int response,
|
||||||
|
GemGraphClientWindow *self)
|
||||||
|
{
|
||||||
|
g_autoptr (GFile) file;
|
||||||
|
GtkFileChooser *chooser;
|
||||||
|
|
||||||
|
if (response == GTK_RESPONSE_ACCEPT) {
|
||||||
|
chooser = GTK_FILE_CHOOSER(native);
|
||||||
|
file = gtk_file_chooser_get_file(chooser);
|
||||||
|
|
||||||
|
// Load asynchroneously not to block control flow
|
||||||
|
g_file_load_contents_async (file,
|
||||||
|
NULL,
|
||||||
|
(GAsyncReadyCallback)on_openfile_response_complete,
|
||||||
|
self);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_object_unref (native);
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_openfile_response_complete(GObject *source_object,
|
||||||
|
GAsyncResult *result,
|
||||||
|
GemGraphClientWindow *self)
|
||||||
|
{
|
||||||
|
GFile *file = G_FILE(source_object);
|
||||||
|
|
||||||
|
char *contents = NULL;
|
||||||
|
gsize length = 0;
|
||||||
|
|
||||||
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
|
// Gives you the contents of the file as a byte array, or
|
||||||
|
// set the error argument
|
||||||
|
g_file_load_contents_finish(file,
|
||||||
|
result,
|
||||||
|
&contents,
|
||||||
|
&length,
|
||||||
|
NULL,
|
||||||
|
&error);
|
||||||
|
|
||||||
|
// In case of error, print a warning to the standard error output
|
||||||
|
if (error != NULL)
|
||||||
|
{
|
||||||
|
g_printerr("Unable to open “%s”: %s\n",
|
||||||
|
g_file_peek_path(file),
|
||||||
|
error->message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_print("File content is :\n%s\n", contents);
|
||||||
|
|
||||||
|
uiApplicationEnableAction("closefile");
|
||||||
|
uiApplicationEnableAction("savefile");
|
||||||
|
uiApplicationEnableAction("runmode");
|
||||||
|
uiApplicationEnableAction("editmode");
|
||||||
|
uiApplicationEnableAction("presentmode");
|
||||||
|
uiWindowStackChange("edit");
|
||||||
|
}
|
||||||
|
|
|
@ -34,18 +34,31 @@ G_DEFINE_TYPE (GemGraphClientApplication,
|
||||||
gem_graph_client_application,
|
gem_graph_client_application,
|
||||||
GTK_TYPE_APPLICATION)
|
GTK_TYPE_APPLICATION)
|
||||||
|
|
||||||
GemGraphClientApplication *gem_graph_client_application_new(
|
|
||||||
const char *application_id,
|
|
||||||
GApplicationFlags flags)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail(application_id != NULL, NULL);
|
|
||||||
|
|
||||||
return g_object_new(GEM_GRAPH_CLIENT_TYPE_APPLICATION,
|
static GemGraphClientApplication *application;
|
||||||
"application-id", application_id,
|
|
||||||
"flags", flags,
|
/* -------------------------------------------------------------------------- */
|
||||||
NULL);
|
|
||||||
|
void uiApplicationEnableAction(const char *name) {
|
||||||
|
g_simple_action_set_enabled(
|
||||||
|
(GSimpleAction *)g_action_map_lookup_action(
|
||||||
|
G_ACTION_MAP(application),
|
||||||
|
name),
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiApplicationDisableAction(const char *name) {
|
||||||
|
g_simple_action_set_enabled(
|
||||||
|
(GSimpleAction *)g_action_map_lookup_action(
|
||||||
|
G_ACTION_MAP(application),
|
||||||
|
name),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Window actual presentation on screen
|
||||||
|
*
|
||||||
|
*/
|
||||||
static void gem_graph_client_application_activate(GApplication *app)
|
static void gem_graph_client_application_activate(GApplication *app)
|
||||||
{
|
{
|
||||||
GtkWindow *window;
|
GtkWindow *window;
|
||||||
|
@ -58,9 +71,53 @@ static void gem_graph_client_application_activate(GApplication *app)
|
||||||
"application", app,
|
"application", app,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
uiWindowStackChange("home");
|
||||||
|
|
||||||
gtk_window_present(window);
|
gtk_window_present(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Action records are registered here
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void gem_graph_client_application_init(GemGraphClientApplication *self)
|
||||||
|
{
|
||||||
|
g_action_map_add_action_entries(G_ACTION_MAP(self),
|
||||||
|
app_actions,
|
||||||
|
G_N_ELEMENTS(app_actions),
|
||||||
|
self);
|
||||||
|
|
||||||
|
// Setup shortcuts
|
||||||
|
gtk_application_set_accels_for_action(GTK_APPLICATION(self),
|
||||||
|
"app.quit",
|
||||||
|
(const char *[]) { "<primary>q", NULL });
|
||||||
|
gtk_application_set_accels_for_action(GTK_APPLICATION(self),
|
||||||
|
"app.editmode",
|
||||||
|
(const char *[]) { "<primary>e", NULL });
|
||||||
|
gtk_application_set_accels_for_action(GTK_APPLICATION(self),
|
||||||
|
"app.runmode",
|
||||||
|
(const char *[]) { "<primary>r", NULL });
|
||||||
|
gtk_application_set_accels_for_action(GTK_APPLICATION(self),
|
||||||
|
"app.presentmode",
|
||||||
|
(const char *[]) { "<primary>p", NULL });
|
||||||
|
gtk_application_set_accels_for_action(GTK_APPLICATION(self),
|
||||||
|
"app.savefile",
|
||||||
|
(const char *[]) { "<primary>s", NULL });
|
||||||
|
|
||||||
|
application = self;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Disable unneeded/inoperant actions
|
||||||
|
//
|
||||||
|
uiApplicationDisableAction("savefile");
|
||||||
|
uiApplicationDisableAction("closefile");
|
||||||
|
uiApplicationDisableAction("editmode");
|
||||||
|
uiApplicationDisableAction("runmode");
|
||||||
|
uiApplicationDisableAction("presentmode");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void gem_graph_client_application_class_init(
|
static void gem_graph_client_application_class_init(
|
||||||
GemGraphClientApplicationClass *klass)
|
GemGraphClientApplicationClass *klass)
|
||||||
{
|
{
|
||||||
|
@ -69,19 +126,14 @@ static void gem_graph_client_application_class_init(
|
||||||
app_class->activate = gem_graph_client_application_activate;
|
app_class->activate = gem_graph_client_application_activate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GemGraphClientApplication *gem_graph_client_application_new(
|
||||||
static void gem_graph_client_application_init(GemGraphClientApplication *self)
|
const char *application_id,
|
||||||
|
GApplicationFlags flags)
|
||||||
{
|
{
|
||||||
g_action_map_add_action_entries(G_ACTION_MAP(self),
|
g_return_val_if_fail(application_id != NULL, NULL);
|
||||||
app_actions,
|
|
||||||
G_N_ELEMENTS(app_actions),
|
|
||||||
self);
|
|
||||||
|
|
||||||
gtk_application_set_accels_for_action(GTK_APPLICATION (self),
|
|
||||||
"app.quit",
|
|
||||||
(const char *[]) { "<primary>q", NULL });
|
|
||||||
|
|
||||||
|
return g_object_new(GEM_GRAPH_CLIENT_TYPE_APPLICATION,
|
||||||
|
"application-id", application_id,
|
||||||
|
"flags", flags,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// XXX changer tous les noms
|
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
<object class="GtkStack" id="side_stack">
|
<object class="GtkStack" id="side_stack">
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkStackPage">
|
<object class="GtkStackPage">
|
||||||
<property name="name">side_run</property>
|
<property name="name">run</property>
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="GtkLabel" id="labelsiderun">
|
<object class="GtkLabel" id="labelsiderun">
|
||||||
<property name="justify">center</property>
|
<property name="justify">center</property>
|
||||||
|
@ -66,9 +66,9 @@
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkStackPage">
|
<object class="GtkStackPage">
|
||||||
<property name="name">side_home</property>
|
<property name="name">home</property>
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="GtkLabel" id="labelsidehome">
|
<object class="GtkLabel" id="labelhome">
|
||||||
<property name="justify">center</property>
|
<property name="justify">center</property>
|
||||||
<property name="label" translatable="yes"><b>Sidebar: home</b></property>
|
<property name="label" translatable="yes"><b>Sidebar: home</b></property>
|
||||||
<property name="use-markup">True</property>
|
<property name="use-markup">True</property>
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkStackPage">
|
<object class="GtkStackPage">
|
||||||
<property name="name">side_presentation</property>
|
<property name="name">presentation</property>
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="GtkLabel" id="labelsidepresentation">
|
<object class="GtkLabel" id="labelsidepresentation">
|
||||||
<property name="justify">center</property>
|
<property name="justify">center</property>
|
||||||
|
@ -90,7 +90,7 @@
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkStackPage">
|
<object class="GtkStackPage">
|
||||||
<property name="name">side_edit</property>
|
<property name="name">edit</property>
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="GtkLabel" id="labelsideedit">
|
<object class="GtkLabel" id="labelsideedit">
|
||||||
<property name="justify">center</property>
|
<property name="justify">center</property>
|
||||||
|
@ -106,7 +106,7 @@
|
||||||
<object class="GtkStack" id="main_stack">
|
<object class="GtkStack" id="main_stack">
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkStackPage">
|
<object class="GtkStackPage">
|
||||||
<property name="name">main_run</property>
|
<property name="name">run</property>
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="GtkLabel">
|
<object class="GtkLabel">
|
||||||
<property name="halign">center</property>
|
<property name="halign">center</property>
|
||||||
|
@ -118,7 +118,7 @@
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkStackPage">
|
<object class="GtkStackPage">
|
||||||
<property name="name">main_home</property>
|
<property name="name">home</property>
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="GtkLabel">
|
<object class="GtkLabel">
|
||||||
<property name="justify">center</property>
|
<property name="justify">center</property>
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkStackPage">
|
<object class="GtkStackPage">
|
||||||
<property name="name">main_presentation</property>
|
<property name="name">presentation</property>
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="GtkLabel">
|
<object class="GtkLabel">
|
||||||
<property name="halign">center</property>
|
<property name="halign">center</property>
|
||||||
|
@ -142,7 +142,7 @@
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkStackPage">
|
<object class="GtkStackPage">
|
||||||
<property name="name">main_edit</property>
|
<property name="name">edit</property>
|
||||||
<property name="child">
|
<property name="child">
|
||||||
<object class="GtkLabel">
|
<object class="GtkLabel">
|
||||||
<property name="halign">center</property>
|
<property name="halign">center</property>
|
||||||
|
|
|
@ -36,6 +36,8 @@ float rotation_angles[N_AXIS] = { 0.0 }; // Rotation angles on each axis
|
||||||
|
|
||||||
static GtkWidget *gl_area = NULL;
|
static GtkWidget *gl_area = NULL;
|
||||||
|
|
||||||
|
static GemGraphClientWindow *window;
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void on_axis_value_change(GtkAdjustment *adjustment, gpointer data);
|
static void on_axis_value_change(GtkAdjustment *adjustment, gpointer data);
|
||||||
|
@ -204,6 +206,7 @@ struct _GemGraphClientWindow
|
||||||
GtkPaned *main_paned;
|
GtkPaned *main_paned;
|
||||||
GtkMenuButton *main_button_mode;
|
GtkMenuButton *main_button_mode;
|
||||||
GtkToggleButton *main_button_sidebar;
|
GtkToggleButton *main_button_sidebar;
|
||||||
|
GtkOverlay *toast_overlay;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_FINAL_TYPE (GemGraphClientWindow,
|
G_DEFINE_FINAL_TYPE (GemGraphClientWindow,
|
||||||
|
@ -243,9 +246,45 @@ static void gem_graph_client_window_class_init(GemGraphClientWindowClass *klass)
|
||||||
gtk_widget_class_bind_template_child(widget_class,
|
gtk_widget_class_bind_template_child(widget_class,
|
||||||
GemGraphClientWindow,
|
GemGraphClientWindow,
|
||||||
main_button_sidebar);
|
main_button_sidebar);
|
||||||
|
gtk_widget_class_bind_template_child(widget_class,
|
||||||
|
GemGraphClientWindow,
|
||||||
|
toast_overlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gem_graph_client_window_init(GemGraphClientWindow *self)
|
static void gem_graph_client_window_init(GemGraphClientWindow *self)
|
||||||
{
|
{
|
||||||
gtk_widget_init_template(GTK_WIDGET(self));
|
gtk_widget_init_template(GTK_WIDGET(self));
|
||||||
|
|
||||||
|
window = self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void uiWindowStackChange(const char *mode)
|
||||||
|
{
|
||||||
|
if (window->main_stack == NULL) {
|
||||||
|
g_printerr("Can't find self->main_stack !\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (window->side_stack == NULL) {
|
||||||
|
g_printerr("Can't find self->side_stack !\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gtk_stack_set_visible_child_full(window->main_stack,
|
||||||
|
mode,
|
||||||
|
GTK_STACK_TRANSITION_TYPE_CROSSFADE);
|
||||||
|
gtk_stack_set_visible_child_full(window->side_stack,
|
||||||
|
mode,
|
||||||
|
GTK_STACK_TRANSITION_TYPE_CROSSFADE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiWindowSendNotification(const char *message)
|
||||||
|
{
|
||||||
|
if (window->toast_overlay == NULL) {
|
||||||
|
g_printerr("Can't find self->toast_overlay !\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//gtk_overlay_add_overlay(self->toast_overlay, //XXX);
|
||||||
|
g_print("NOTIFICATION: %s\n", message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue