2010-09-13 19:24:53 +02:00
|
|
|
/*
|
2010-09-18 08:55:13 +02:00
|
|
|
* ld-window-main.c
|
2010-09-13 19:24:53 +02:00
|
|
|
*
|
|
|
|
* This file is a part of logdiag.
|
2017-02-03 23:06:48 +01:00
|
|
|
* Copyright Přemysl Janouch 2010, 2011, 2012
|
2010-09-13 19:24:53 +02:00
|
|
|
*
|
|
|
|
* See the file LICENSE for licensing information.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-01-24 04:42:18 +01:00
|
|
|
#include <liblogdiag/liblogdiag.h>
|
2010-09-13 19:24:53 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-09-17 19:03:03 +02:00
|
|
|
#include "ld-window-main.h"
|
2010-09-30 05:19:31 +02:00
|
|
|
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-09-17 19:16:53 +02:00
|
|
|
struct _LdWindowMainPrivate
|
2010-09-13 19:24:53 +02:00
|
|
|
{
|
2011-06-10 18:18:58 +02:00
|
|
|
GSettings *settings;
|
2010-09-18 08:55:13 +02:00
|
|
|
GtkUIManager *ui_manager;
|
2010-12-15 13:42:43 +01:00
|
|
|
GtkActionGroup *action_group;
|
2010-09-18 08:55:13 +02:00
|
|
|
|
2010-09-13 19:24:53 +02:00
|
|
|
GtkWidget *vbox;
|
2012-08-10 03:38:11 +02:00
|
|
|
GtkWidget *paned;
|
2010-09-13 19:24:53 +02:00
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *toolbar;
|
2012-08-10 03:38:11 +02:00
|
|
|
|
2012-08-30 00:54:38 +02:00
|
|
|
GtkWidget *library_view;
|
|
|
|
GtkWidget *lv_window;
|
|
|
|
GtkWidget *lv_viewport;
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-09-25 16:14:09 +02:00
|
|
|
LdLibrary *library;
|
2010-12-07 00:59:05 +01:00
|
|
|
|
2010-12-16 11:34:02 +01:00
|
|
|
LdDiagram *diagram;
|
2010-12-15 13:42:43 +01:00
|
|
|
gchar *filename;
|
|
|
|
|
2011-02-16 07:50:07 +01:00
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
LdDiagramView *view;
|
2010-09-13 19:24:53 +02:00
|
|
|
|
|
|
|
GtkWidget *statusbar;
|
2012-10-09 07:05:32 +02:00
|
|
|
GtkWidget *zoom_label;
|
2011-01-10 04:58:32 +01:00
|
|
|
guint statusbar_symbol_context_id;
|
2010-09-13 19:24:53 +02:00
|
|
|
guint statusbar_menu_context_id;
|
2012-10-07 23:59:34 +02:00
|
|
|
guint statusbar_hint_context_id;
|
|
|
|
|
|
|
|
guint statusbar_hint_drag;
|
2010-09-17 18:48:02 +02:00
|
|
|
};
|
|
|
|
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-09-15 19:31:57 +02:00
|
|
|
/* ===== Local functions =================================================== */
|
|
|
|
|
2010-10-28 14:10:42 +02:00
|
|
|
static void ld_window_main_finalize (GObject *gobject);
|
2012-10-09 06:36:29 +02:00
|
|
|
static void load_library_directories (LdLibrary *library);
|
2010-09-18 08:55:13 +02:00
|
|
|
|
2010-10-28 14:10:42 +02:00
|
|
|
static void on_ui_proxy_connected (GtkUIManager *ui, GtkAction *action,
|
2010-09-17 19:16:53 +02:00
|
|
|
GtkWidget *proxy, LdWindowMain *window);
|
2010-10-28 14:10:42 +02:00
|
|
|
static void on_ui_proxy_disconnected (GtkUIManager *ui, GtkAction *action,
|
2010-09-17 19:16:53 +02:00
|
|
|
GtkWidget *proxy, LdWindowMain *window);
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-10-28 14:10:42 +02:00
|
|
|
static void on_menu_item_selected (GtkWidget *item, LdWindowMain *window);
|
2015-01-19 02:23:20 +01:00
|
|
|
static void on_menu_item_deselected (GtkMenuItem *item, LdWindowMain *window);
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-12-15 13:42:43 +01:00
|
|
|
static gboolean on_delete (LdWindowMain *self, GdkEvent *event,
|
|
|
|
gpointer user_data);
|
|
|
|
static void update_title (LdWindowMain *self);
|
|
|
|
static void action_set_sensitive (LdWindowMain *self, const gchar *name,
|
|
|
|
gboolean sensitive);
|
|
|
|
|
2011-02-16 07:50:07 +01:00
|
|
|
static void on_view_zoom_changed (LdDiagramView *view,
|
2011-02-04 20:19:01 +01:00
|
|
|
GParamSpec *pspec, LdWindowMain *self);
|
|
|
|
|
2011-01-31 22:07:58 +01:00
|
|
|
static void on_diagram_changed (LdDiagram *diagram, LdWindowMain *self);
|
|
|
|
static void on_diagram_history_changed (LdDiagram *diagram,
|
|
|
|
GParamSpec *pspec, LdWindowMain *self);
|
2011-01-16 15:39:11 +01:00
|
|
|
static void on_diagram_selection_changed (LdDiagram *diagram,
|
|
|
|
LdWindowMain *self);
|
|
|
|
|
2010-12-15 13:42:43 +01:00
|
|
|
static gchar *diagram_get_name (LdWindowMain *self);
|
|
|
|
static void diagram_set_filename (LdWindowMain *self, gchar *filename);
|
|
|
|
static void diagram_new (LdWindowMain *self);
|
2011-02-13 20:17:21 +01:00
|
|
|
static gboolean diagram_open (LdWindowMain *self, const gchar *filename);
|
2012-08-12 07:25:06 +02:00
|
|
|
static gboolean diagram_save (LdWindowMain *self, GtkWindow *dialog_parent,
|
|
|
|
const gchar *filename);
|
2010-12-15 13:42:43 +01:00
|
|
|
|
|
|
|
static GtkFileFilter *diagram_get_file_filter (void);
|
|
|
|
static void diagram_show_open_dialog (LdWindowMain *self);
|
|
|
|
static void diagram_show_save_as_dialog (LdWindowMain *self);
|
|
|
|
|
|
|
|
static gboolean may_close_diagram (LdWindowMain *self,
|
|
|
|
const gchar *dialog_message);
|
|
|
|
static gboolean may_quit (LdWindowMain *self);
|
|
|
|
|
2012-10-08 04:40:41 +02:00
|
|
|
static void on_symbol_selected (LdCategoryView *view,
|
|
|
|
LdSymbol *symbol, const gchar *path, LdWindowMain *self);
|
|
|
|
static void on_symbol_deselected (LdCategoryView *view,
|
|
|
|
LdSymbol *symbol, const gchar *path, LdWindowMain *self);
|
|
|
|
|
2010-12-15 13:42:43 +01:00
|
|
|
static void on_action_new (GtkAction *action, LdWindowMain *self);
|
|
|
|
static void on_action_open (GtkAction *action, LdWindowMain *self);
|
|
|
|
static void on_action_save (GtkAction *action, LdWindowMain *self);
|
|
|
|
static void on_action_save_as (GtkAction *action, LdWindowMain *self);
|
|
|
|
static void on_action_quit (GtkAction *action, LdWindowMain *self);
|
2010-12-12 17:56:59 +01:00
|
|
|
static void on_action_about (GtkAction *action, LdWindowMain *self);
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2011-01-31 22:07:58 +01:00
|
|
|
static void on_action_undo (GtkAction *action, LdWindowMain *self);
|
|
|
|
static void on_action_redo (GtkAction *action, LdWindowMain *self);
|
2011-01-16 15:39:11 +01:00
|
|
|
static void on_action_delete (GtkAction *action, LdWindowMain *self);
|
|
|
|
static void on_action_select_all (GtkAction *action, LdWindowMain *self);
|
|
|
|
|
2011-03-06 15:57:58 +01:00
|
|
|
static void on_action_main_toolbar (GtkToggleAction *action,
|
|
|
|
LdWindowMain *self);
|
2012-08-10 03:38:11 +02:00
|
|
|
static void on_action_library_pane (GtkToggleAction *action,
|
2011-03-06 15:57:58 +01:00
|
|
|
LdWindowMain *self);
|
|
|
|
static void on_action_grid (GtkToggleAction *action, LdWindowMain *self);
|
|
|
|
|
2011-02-04 20:19:01 +01:00
|
|
|
static void on_action_zoom_in (GtkAction *action, LdWindowMain *self);
|
|
|
|
static void on_action_zoom_out (GtkAction *action, LdWindowMain *self);
|
|
|
|
static void on_action_normal_size (GtkAction *action, LdWindowMain *self);
|
|
|
|
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-09-15 19:31:57 +02:00
|
|
|
/* ===== Local variables =================================================== */
|
|
|
|
|
2010-09-13 19:24:53 +02:00
|
|
|
/* Actions for menus, toolbars, accelerators. */
|
2010-12-12 17:56:59 +01:00
|
|
|
static GtkActionEntry wm_action_entries[] =
|
2010-09-13 19:24:53 +02:00
|
|
|
{
|
2011-02-12 02:07:39 +01:00
|
|
|
{"FileMenu", NULL, N_("_File"), NULL, NULL, NULL},
|
|
|
|
{"New", GTK_STOCK_NEW, N_("_New"), "<Ctrl>N",
|
|
|
|
N_("Create a new diagram"),
|
2010-12-15 13:42:43 +01:00
|
|
|
G_CALLBACK (on_action_new)},
|
2011-02-12 02:07:39 +01:00
|
|
|
{"Open", GTK_STOCK_OPEN, N_("_Open..."), "<Ctrl>O",
|
|
|
|
N_("Open a diagram"),
|
2010-12-15 13:42:43 +01:00
|
|
|
G_CALLBACK (on_action_open)},
|
2011-02-12 02:07:39 +01:00
|
|
|
{"Save", GTK_STOCK_SAVE, N_("_Save"), "<Ctrl>S",
|
|
|
|
N_("Save the current diagram"),
|
2010-12-15 13:42:43 +01:00
|
|
|
G_CALLBACK (on_action_save)},
|
2011-02-12 02:07:39 +01:00
|
|
|
{"SaveAs", GTK_STOCK_SAVE_AS, N_("Save _As..."), "<Shift><Ctrl>S",
|
|
|
|
N_("Save the current diagram with another name"),
|
2010-12-15 13:42:43 +01:00
|
|
|
G_CALLBACK (on_action_save_as)},
|
2011-01-31 22:07:58 +01:00
|
|
|
/*
|
2011-02-12 02:07:39 +01:00
|
|
|
* {"Export", NULL, N_("_Export"), NULL,
|
|
|
|
* N_("Export the diagram"),
|
2011-01-31 22:07:58 +01:00
|
|
|
* NULL},
|
|
|
|
*/
|
2011-02-12 02:07:39 +01:00
|
|
|
{"Quit", GTK_STOCK_QUIT, N_("_Quit"), "<Ctrl>Q",
|
|
|
|
N_("Quit the application"),
|
2010-12-15 13:42:43 +01:00
|
|
|
G_CALLBACK (on_action_quit)},
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2011-02-12 02:07:39 +01:00
|
|
|
{"EditMenu", NULL, N_("_Edit"), NULL, NULL, NULL},
|
|
|
|
{"Undo", GTK_STOCK_UNDO, N_("_Undo"), "<Ctrl>Z",
|
|
|
|
N_("Undo the last action"),
|
2011-01-31 22:07:58 +01:00
|
|
|
G_CALLBACK (on_action_undo)},
|
2011-02-12 02:07:39 +01:00
|
|
|
{"Redo", GTK_STOCK_REDO, N_("_Redo"), "<Shift><Ctrl>Z",
|
|
|
|
N_("Redo the last undone action"),
|
2011-01-31 22:07:58 +01:00
|
|
|
G_CALLBACK (on_action_redo)},
|
2010-12-12 17:56:59 +01:00
|
|
|
/*
|
2011-02-12 02:07:39 +01:00
|
|
|
* {"Cut", GTK_STOCK_CUT, N_("Cu_t"), "<Ctrl>X", NULL, NULL},
|
|
|
|
* {"Copy", GTK_STOCK_COPY, N_("_Copy"), "<Ctrl>C", NULL, NULL},
|
|
|
|
* {"Paste", GTK_STOCK_PASTE, N_("_Paste"), "<Ctrl>V", NULL, NULL},
|
2010-12-12 17:56:59 +01:00
|
|
|
*/
|
2011-02-12 02:07:39 +01:00
|
|
|
{"Delete", GTK_STOCK_DELETE, N_("_Delete"), "Delete",
|
|
|
|
N_("Delete the contents of the selection"),
|
2011-01-16 15:39:11 +01:00
|
|
|
G_CALLBACK (on_action_delete)},
|
2011-02-12 02:07:39 +01:00
|
|
|
{"SelectAll", GTK_STOCK_SELECT_ALL, N_("Select _All"), "<Ctrl>A",
|
|
|
|
N_("Select all objects in the diagram"),
|
2011-01-16 15:39:11 +01:00
|
|
|
G_CALLBACK (on_action_select_all)},
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2011-02-12 02:07:39 +01:00
|
|
|
{"ViewMenu", NULL, N_("_View"), NULL, NULL, NULL},
|
|
|
|
{"ZoomIn", GTK_STOCK_ZOOM_IN, N_("_Zoom In"), "<Ctrl>plus",
|
|
|
|
N_("Zoom into the diagram"),
|
2011-02-04 20:19:01 +01:00
|
|
|
G_CALLBACK (on_action_zoom_in)},
|
2011-02-12 02:07:39 +01:00
|
|
|
{"ZoomOut", GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), "<Ctrl>minus",
|
|
|
|
N_("Zoom out of the diagram"),
|
2011-02-04 20:19:01 +01:00
|
|
|
G_CALLBACK (on_action_zoom_out)},
|
2011-02-12 02:07:39 +01:00
|
|
|
{"NormalSize", GTK_STOCK_ZOOM_100, N_("_Normal Size"), "<Ctrl>0",
|
|
|
|
N_("Reset zoom level back to the default"),
|
2011-02-04 20:19:01 +01:00
|
|
|
G_CALLBACK (on_action_normal_size)},
|
2010-12-12 17:56:59 +01:00
|
|
|
|
2011-02-12 02:07:39 +01:00
|
|
|
{"HelpMenu", NULL, N_("_Help"), NULL, NULL, NULL},
|
|
|
|
{"About", GTK_STOCK_ABOUT, N_("_About"), NULL,
|
|
|
|
N_("Show a dialog about this application"),
|
2010-12-12 17:56:59 +01:00
|
|
|
G_CALLBACK (on_action_about)}
|
2010-09-13 19:24:53 +02:00
|
|
|
};
|
|
|
|
|
2011-03-06 15:57:58 +01:00
|
|
|
static GtkToggleActionEntry wm_toggle_action_entries[] =
|
|
|
|
{
|
|
|
|
{"MainToolbar", NULL, N_("_Main Toolbar"), NULL,
|
|
|
|
N_("Toggle displaying of the main toolbar"),
|
|
|
|
G_CALLBACK (on_action_main_toolbar), TRUE},
|
2012-08-10 03:38:11 +02:00
|
|
|
{"LibraryPane", NULL, N_("_Library Pane"), NULL,
|
|
|
|
N_("Toggle displaying of the library pane"),
|
|
|
|
G_CALLBACK (on_action_library_pane), TRUE},
|
2011-03-06 15:57:58 +01:00
|
|
|
{"ShowGrid", NULL, N_("Show _Grid"), NULL,
|
|
|
|
N_("Toggle displaying of the grid"),
|
|
|
|
G_CALLBACK (on_action_grid), TRUE}
|
|
|
|
};
|
|
|
|
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-12-15 13:42:43 +01:00
|
|
|
/* ===== Generic widget methods ============================================ */
|
2010-09-13 19:24:53 +02:00
|
|
|
|
|
|
|
/**
|
2010-09-17 19:16:53 +02:00
|
|
|
* ld_window_main_new:
|
2011-02-19 13:22:06 +01:00
|
|
|
* @filename: (allow-none): a file to open.
|
2010-09-13 19:24:53 +02:00
|
|
|
*
|
|
|
|
* Create an instance.
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
2011-02-19 13:22:06 +01:00
|
|
|
ld_window_main_new (const gchar *filename)
|
2010-09-13 19:24:53 +02:00
|
|
|
{
|
2011-02-19 13:22:06 +01:00
|
|
|
GtkWidget *self;
|
|
|
|
self = g_object_new (LD_TYPE_WINDOW_MAIN, NULL);
|
|
|
|
|
|
|
|
if (filename)
|
|
|
|
diagram_open (LD_WINDOW_MAIN (self), filename);
|
|
|
|
|
|
|
|
return self;
|
2010-09-13 19:24:53 +02:00
|
|
|
}
|
|
|
|
|
2011-01-04 14:52:57 +01:00
|
|
|
G_DEFINE_TYPE (LdWindowMain, ld_window_main, GTK_TYPE_WINDOW);
|
|
|
|
|
2010-09-13 19:24:53 +02:00
|
|
|
static void
|
2010-09-17 19:16:53 +02:00
|
|
|
ld_window_main_class_init (LdWindowMainClass *klass)
|
2010-09-13 19:24:53 +02:00
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
2010-09-18 08:55:13 +02:00
|
|
|
object_class->finalize = ld_window_main_finalize;
|
|
|
|
|
2010-09-17 19:16:53 +02:00
|
|
|
g_type_class_add_private (klass, sizeof (LdWindowMainPrivate));
|
2010-09-13 19:24:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-09-17 19:16:53 +02:00
|
|
|
ld_window_main_init (LdWindowMain *self)
|
2010-09-13 19:24:53 +02:00
|
|
|
{
|
2010-09-17 19:16:53 +02:00
|
|
|
LdWindowMainPrivate *priv;
|
2010-09-13 19:24:53 +02:00
|
|
|
GError *error;
|
|
|
|
|
|
|
|
self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE
|
2010-09-17 19:16:53 +02:00
|
|
|
(self, LD_TYPE_WINDOW_MAIN, LdWindowMainPrivate);
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-12-12 17:56:59 +01:00
|
|
|
/* Construct menu and toolbar. */
|
2010-09-18 08:55:13 +02:00
|
|
|
priv->ui_manager = gtk_ui_manager_new ();
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-09-18 08:55:13 +02:00
|
|
|
g_signal_connect (priv->ui_manager, "connect-proxy",
|
2010-10-28 14:10:42 +02:00
|
|
|
G_CALLBACK (on_ui_proxy_connected), self);
|
2010-09-18 08:55:13 +02:00
|
|
|
g_signal_connect (priv->ui_manager, "disconnect-proxy",
|
2010-10-28 14:10:42 +02:00
|
|
|
G_CALLBACK (on_ui_proxy_disconnected), self);
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-12-15 13:42:43 +01:00
|
|
|
priv->action_group = gtk_action_group_new ("MainActions");
|
2011-02-12 02:07:39 +01:00
|
|
|
gtk_action_group_set_translation_domain
|
|
|
|
(priv->action_group, GETTEXT_DOMAIN);
|
2011-03-06 15:57:58 +01:00
|
|
|
gtk_action_group_add_actions
|
|
|
|
(priv->action_group, wm_action_entries,
|
2010-12-12 17:56:59 +01:00
|
|
|
G_N_ELEMENTS (wm_action_entries), self);
|
2011-03-06 15:57:58 +01:00
|
|
|
gtk_action_group_add_toggle_actions
|
|
|
|
(priv->action_group, wm_toggle_action_entries,
|
|
|
|
G_N_ELEMENTS (wm_toggle_action_entries), self);
|
2010-12-15 13:42:43 +01:00
|
|
|
gtk_ui_manager_insert_action_group (priv->ui_manager,
|
|
|
|
priv->action_group, 0);
|
2010-09-13 19:24:53 +02:00
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
gtk_ui_manager_add_ui_from_file
|
2010-09-18 08:55:13 +02:00
|
|
|
(priv->ui_manager, PROJECT_SHARE_DIR "gui/window-main.ui", &error);
|
2010-09-13 19:24:53 +02:00
|
|
|
if (error)
|
|
|
|
{
|
2011-02-13 20:17:21 +01:00
|
|
|
g_message ("building UI failed: %s", error->message);
|
2010-09-13 19:24:53 +02:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
2010-09-18 08:55:13 +02:00
|
|
|
priv->menu = gtk_ui_manager_get_widget (priv->ui_manager, "/MenuBar");
|
2010-12-12 17:56:59 +01:00
|
|
|
priv->toolbar = gtk_ui_manager_get_widget (priv->ui_manager, "/Toolbar");
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-12-12 17:56:59 +01:00
|
|
|
/* Create the remaining widgets. */
|
2012-10-08 09:11:32 +02:00
|
|
|
priv->library_view = ld_category_tree_view_new (NULL);
|
2011-06-13 11:10:39 +02:00
|
|
|
|
2011-02-16 07:50:07 +01:00
|
|
|
priv->view = LD_DIAGRAM_VIEW (ld_diagram_view_new ());
|
|
|
|
priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
2011-02-20 12:54:15 +01:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2011-02-16 07:50:07 +01:00
|
|
|
gtk_container_add (GTK_CONTAINER (priv->scrolled_window),
|
|
|
|
GTK_WIDGET (priv->view));
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-12-12 17:56:59 +01:00
|
|
|
priv->statusbar = gtk_statusbar_new ();
|
|
|
|
priv->statusbar_menu_context_id = gtk_statusbar_get_context_id
|
|
|
|
(GTK_STATUSBAR (priv->statusbar), "menu");
|
2011-01-10 04:58:32 +01:00
|
|
|
priv->statusbar_symbol_context_id = gtk_statusbar_get_context_id
|
|
|
|
(GTK_STATUSBAR (priv->statusbar), "symbol");
|
2012-10-07 23:59:34 +02:00
|
|
|
priv->statusbar_hint_context_id = gtk_statusbar_get_context_id
|
|
|
|
(GTK_STATUSBAR (priv->statusbar), "hint");
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2012-08-30 00:54:38 +02:00
|
|
|
priv->lv_viewport = gtk_viewport_new (NULL, NULL);
|
2012-08-10 03:38:11 +02:00
|
|
|
gtk_viewport_set_shadow_type
|
2012-08-30 00:54:38 +02:00
|
|
|
(GTK_VIEWPORT (priv->lv_viewport), GTK_SHADOW_NONE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->lv_viewport), priv->library_view);
|
2010-09-15 19:31:57 +02:00
|
|
|
|
2012-08-30 00:54:38 +02:00
|
|
|
priv->lv_window = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->lv_window),
|
2012-08-10 03:38:11 +02:00
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
2012-08-30 00:54:38 +02:00
|
|
|
gtk_container_add (GTK_CONTAINER (priv->lv_window), priv->lv_viewport);
|
2012-08-10 03:38:11 +02:00
|
|
|
|
2015-01-20 07:41:54 +01:00
|
|
|
priv->paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
|
2012-08-10 03:38:11 +02:00
|
|
|
gtk_paned_pack1 (GTK_PANED (priv->paned),
|
2012-08-30 00:54:38 +02:00
|
|
|
priv->lv_window, FALSE, FALSE);
|
2012-08-10 03:38:11 +02:00
|
|
|
gtk_paned_pack2 (GTK_PANED (priv->paned),
|
|
|
|
priv->scrolled_window, TRUE, TRUE);
|
2012-10-07 09:00:11 +02:00
|
|
|
gtk_paned_set_position (GTK_PANED (priv->paned), 180);
|
2012-08-10 03:38:11 +02:00
|
|
|
|
|
|
|
/* Pack all widgets into the window. */
|
2015-01-20 07:41:54 +01:00
|
|
|
priv->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2010-12-12 17:56:59 +01:00
|
|
|
gtk_box_pack_start (GTK_BOX (priv->vbox), priv->menu, FALSE, FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (priv->vbox), priv->toolbar, FALSE, FALSE, 0);
|
2012-08-10 03:38:11 +02:00
|
|
|
gtk_box_pack_start (GTK_BOX (priv->vbox), priv->paned, TRUE, TRUE, 0);
|
2010-12-12 17:56:59 +01:00
|
|
|
gtk_box_pack_end (GTK_BOX (priv->vbox), priv->statusbar, FALSE, FALSE, 0);
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-12-12 17:56:59 +01:00
|
|
|
gtk_container_add (GTK_CONTAINER (self), priv->vbox);
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-12-12 17:56:59 +01:00
|
|
|
/* Configure the window. */
|
2010-12-15 13:42:43 +01:00
|
|
|
g_signal_connect (self, "delete-event", G_CALLBACK (on_delete), NULL);
|
2010-09-18 08:55:13 +02:00
|
|
|
|
2010-12-12 17:56:59 +01:00
|
|
|
gtk_window_add_accel_group (GTK_WINDOW (self),
|
|
|
|
gtk_ui_manager_get_accel_group (priv->ui_manager));
|
2012-10-07 09:00:11 +02:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (self), 640, 440);
|
2010-12-12 17:56:59 +01:00
|
|
|
gtk_window_set_position (GTK_WINDOW (self), GTK_WIN_POS_CENTER);
|
2010-10-29 18:47:00 +02:00
|
|
|
|
2010-12-15 13:42:43 +01:00
|
|
|
/* Initialize the backend. */
|
2010-12-16 11:34:02 +01:00
|
|
|
priv->diagram = ld_diagram_new ();
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2011-01-31 22:07:58 +01:00
|
|
|
g_signal_connect_after (priv->diagram, "changed",
|
|
|
|
G_CALLBACK (on_diagram_changed), self);
|
|
|
|
g_signal_connect (priv->diagram, "notify::can-undo",
|
|
|
|
G_CALLBACK (on_diagram_history_changed), self);
|
|
|
|
g_signal_connect (priv->diagram, "notify::can-redo",
|
|
|
|
G_CALLBACK (on_diagram_history_changed), self);
|
2011-01-16 15:39:11 +01:00
|
|
|
g_signal_connect_after (priv->diagram, "selection-changed",
|
|
|
|
G_CALLBACK (on_diagram_selection_changed), self);
|
2010-09-13 19:24:53 +02:00
|
|
|
|
2010-12-12 17:56:59 +01:00
|
|
|
priv->library = ld_library_new ();
|
2012-10-09 06:36:29 +02:00
|
|
|
load_library_directories (priv->library);
|
2010-09-18 08:55:13 +02:00
|
|
|
|
2011-02-16 07:50:07 +01:00
|
|
|
ld_diagram_view_set_diagram (priv->view, priv->diagram);
|
|
|
|
ld_diagram_view_set_library (priv->view, priv->library);
|
2010-12-12 17:56:59 +01:00
|
|
|
|
2012-10-08 09:11:32 +02:00
|
|
|
ld_category_view_set_category (LD_CATEGORY_VIEW (priv->library_view),
|
2012-08-30 00:54:38 +02:00
|
|
|
ld_library_get_root (priv->library));
|
2011-06-13 11:10:39 +02:00
|
|
|
|
2012-10-08 04:40:41 +02:00
|
|
|
g_signal_connect_after (priv->library_view, "symbol-selected",
|
|
|
|
G_CALLBACK (on_symbol_selected), self);
|
|
|
|
g_signal_connect_after (priv->library_view, "symbol-deselected",
|
|
|
|
G_CALLBACK (on_symbol_deselected), self);
|
|
|
|
|
2010-12-15 13:42:43 +01:00
|
|
|
diagram_set_filename (self, NULL);
|
|
|
|
|
2012-10-07 23:59:34 +02:00
|
|
|
priv->statusbar_hint_drag = gtk_statusbar_push
|
|
|
|
(GTK_STATUSBAR (priv->statusbar), priv->statusbar_hint_context_id,
|
|
|
|
_("Drag symbols from the library pane to add them to the diagram."));
|
|
|
|
|
2012-10-09 07:05:32 +02:00
|
|
|
priv->zoom_label = gtk_label_new ("");
|
|
|
|
gtk_label_set_single_line_mode (GTK_LABEL (priv->zoom_label), TRUE);
|
|
|
|
gtk_box_pack_end (GTK_BOX (gtk_statusbar_get_message_area
|
|
|
|
(GTK_STATUSBAR (priv->statusbar))), priv->zoom_label, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
g_signal_connect (priv->view, "notify::zoom",
|
|
|
|
G_CALLBACK (on_view_zoom_changed), self);
|
|
|
|
g_object_notify (G_OBJECT (priv->view), "zoom");
|
|
|
|
|
2011-01-31 22:07:58 +01:00
|
|
|
action_set_sensitive (self, "Undo", FALSE);
|
|
|
|
action_set_sensitive (self, "Redo", FALSE);
|
2010-12-15 13:42:43 +01:00
|
|
|
action_set_sensitive (self, "Delete", FALSE);
|
2011-01-09 13:54:20 +01:00
|
|
|
action_set_sensitive (self, "NormalSize", FALSE);
|
2010-12-12 17:56:59 +01:00
|
|
|
|
2011-02-16 07:50:07 +01:00
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (priv->view));
|
2011-01-09 05:52:27 +01:00
|
|
|
|
2010-12-12 17:56:59 +01:00
|
|
|
/* Realize the window. */
|
2010-09-13 19:24:53 +02:00
|
|
|
gtk_widget_show_all (GTK_WIDGET (self));
|
2011-06-10 18:18:58 +02:00
|
|
|
|
|
|
|
/* Set up GSettings. */
|
|
|
|
priv->settings = g_settings_new ("org." PROJECT_NAME);
|
|
|
|
|
|
|
|
g_settings_bind (priv->settings, "show-main-toolbar",
|
|
|
|
gtk_action_group_get_action (priv->action_group,
|
|
|
|
"MainToolbar"), "active", G_SETTINGS_BIND_DEFAULT);
|
2012-08-10 03:38:11 +02:00
|
|
|
g_settings_bind (priv->settings, "show-library-pane",
|
2011-06-10 18:18:58 +02:00
|
|
|
gtk_action_group_get_action (priv->action_group,
|
2012-08-10 03:38:11 +02:00
|
|
|
"LibraryPane"), "active", G_SETTINGS_BIND_DEFAULT);
|
2011-06-10 18:18:58 +02:00
|
|
|
g_settings_bind (priv->settings, "show-grid",
|
|
|
|
gtk_action_group_get_action (priv->action_group,
|
|
|
|
"ShowGrid"), "active", G_SETTINGS_BIND_DEFAULT);
|
2010-09-13 19:24:53 +02:00
|
|
|
}
|
|
|
|
|
2010-09-18 08:55:13 +02:00
|
|
|
static void
|
|
|
|
ld_window_main_finalize (GObject *gobject)
|
|
|
|
{
|
|
|
|
LdWindowMain *self;
|
|
|
|
|
|
|
|
self = LD_WINDOW_MAIN (gobject);
|
|
|
|
|
|
|
|
/* Dispose of objects. Note that GtkObject has floating ref. by default
|
|
|
|
* and gtk_object_destroy () should be used for it.
|
|
|
|
*/
|
|
|
|
g_object_unref (self->priv->library);
|
2010-12-16 11:34:02 +01:00
|
|
|
g_object_unref (self->priv->diagram);
|
2010-09-18 08:55:13 +02:00
|
|
|
g_object_unref (self->priv->ui_manager);
|
2010-12-15 13:42:43 +01:00
|
|
|
g_object_unref (self->priv->action_group);
|
2011-06-10 18:18:58 +02:00
|
|
|
g_object_unref (self->priv->settings);
|
2010-12-15 13:42:43 +01:00
|
|
|
|
|
|
|
if (self->priv->filename)
|
|
|
|
g_free (self->priv->filename);
|
2010-09-18 08:55:13 +02:00
|
|
|
|
|
|
|
/* Chain up to the parent class. */
|
|
|
|
G_OBJECT_CLASS (ld_window_main_parent_class)->finalize (gobject);
|
|
|
|
}
|
|
|
|
|
2012-10-09 06:36:29 +02:00
|
|
|
static void
|
|
|
|
load_library_directories (LdLibrary *library)
|
|
|
|
{
|
|
|
|
GFile *file_program, *file_user;
|
|
|
|
const gchar *program_dir;
|
|
|
|
gchar *user_dir;
|
|
|
|
|
|
|
|
program_dir = PROJECT_SHARE_DIR "library";
|
|
|
|
user_dir = g_build_filename (g_get_user_data_dir (),
|
|
|
|
PROJECT_NAME, "library", NULL);
|
|
|
|
|
|
|
|
file_program = g_file_new_for_path (program_dir);
|
|
|
|
file_user = g_file_new_for_path (user_dir);
|
|
|
|
|
|
|
|
ld_library_load (library, program_dir);
|
|
|
|
|
|
|
|
/* Don't try to load the same directory twice. */
|
|
|
|
if (!g_file_equal (file_program, file_user))
|
|
|
|
ld_library_load (library, user_dir);
|
|
|
|
|
|
|
|
g_object_unref (file_user);
|
|
|
|
g_object_unref (file_program);
|
|
|
|
|
|
|
|
g_free (user_dir);
|
|
|
|
}
|
|
|
|
|
2010-12-15 13:42:43 +01:00
|
|
|
/*
|
|
|
|
* on_delete:
|
|
|
|
*
|
|
|
|
* Handle requests to close the window.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
on_delete (LdWindowMain *self, GdkEvent *event, gpointer user_data)
|
|
|
|
{
|
|
|
|
return !may_quit (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* update_title:
|
|
|
|
*
|
|
|
|
* Update the title of the window.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
update_title (LdWindowMain *self)
|
|
|
|
{
|
|
|
|
gchar *title;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
g_return_if_fail (LD_IS_WINDOW_MAIN (self));
|
|
|
|
|
|
|
|
name = diagram_get_name (self);
|
|
|
|
title = g_strdup_printf ("%s%s - %s",
|
2010-12-16 11:34:02 +01:00
|
|
|
ld_diagram_get_modified (self->priv->diagram) ? "*" : "",
|
2010-12-15 13:42:43 +01:00
|
|
|
name, PROJECT_NAME);
|
|
|
|
gtk_window_set_title (GTK_WINDOW (self), title);
|
|
|
|
|
|
|
|
g_free (title);
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* action_set_sensitive:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @sensitive: the sensitivity state.
|
2010-12-15 13:42:43 +01:00
|
|
|
*
|
|
|
|
* Set sensitivity of an action.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
action_set_sensitive (LdWindowMain *self, const gchar *name, gboolean sensitive)
|
|
|
|
{
|
|
|
|
GtkAction *action;
|
|
|
|
|
|
|
|
g_return_if_fail (LD_IS_WINDOW_MAIN (self));
|
|
|
|
g_return_if_fail (name != NULL);
|
|
|
|
|
|
|
|
action = gtk_action_group_get_action (self->priv->action_group, name);
|
|
|
|
g_return_if_fail (action != NULL);
|
|
|
|
|
|
|
|
gtk_action_set_sensitive (action, sensitive);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ===== Menu items processing ============================================= */
|
|
|
|
|
2010-09-13 19:24:53 +02:00
|
|
|
static void
|
2010-10-28 14:10:42 +02:00
|
|
|
on_ui_proxy_connected (GtkUIManager *ui, GtkAction *action,
|
2010-09-17 19:16:53 +02:00
|
|
|
GtkWidget *proxy, LdWindowMain *window)
|
2010-09-13 19:24:53 +02:00
|
|
|
{
|
|
|
|
if (GTK_IS_MENU_ITEM (proxy))
|
|
|
|
{
|
|
|
|
g_signal_connect (proxy, "select",
|
2010-10-28 14:10:42 +02:00
|
|
|
G_CALLBACK (on_menu_item_selected), window);
|
2010-09-13 19:24:53 +02:00
|
|
|
g_signal_connect (proxy, "deselect",
|
2010-10-28 14:10:42 +02:00
|
|
|
G_CALLBACK (on_menu_item_deselected), window);
|
2010-09-13 19:24:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-28 14:10:42 +02:00
|
|
|
on_ui_proxy_disconnected (GtkUIManager *ui, GtkAction *action,
|
2010-09-17 19:16:53 +02:00
|
|
|
GtkWidget *proxy, LdWindowMain *window)
|
2010-09-13 19:24:53 +02:00
|
|
|
{
|
|
|
|
if (GTK_IS_MENU_ITEM (proxy))
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func
|
2010-10-28 14:10:42 +02:00
|
|
|
(proxy, G_CALLBACK (on_menu_item_selected), window);
|
2010-09-13 19:24:53 +02:00
|
|
|
g_signal_handlers_disconnect_by_func
|
2010-10-28 14:10:42 +02:00
|
|
|
(proxy, G_CALLBACK (on_menu_item_deselected), window);
|
2010-09-13 19:24:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-28 14:10:42 +02:00
|
|
|
on_menu_item_selected (GtkWidget *item, LdWindowMain *window)
|
2010-09-13 19:24:53 +02:00
|
|
|
{
|
|
|
|
GtkAction *action;
|
|
|
|
gchar *tooltip;
|
|
|
|
|
|
|
|
action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (item));
|
|
|
|
g_object_get (G_OBJECT (action), "tooltip", &tooltip, NULL);
|
|
|
|
|
|
|
|
if (tooltip != NULL)
|
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (window->priv->statusbar),
|
|
|
|
window->priv->statusbar_menu_context_id, tooltip);
|
|
|
|
|
|
|
|
g_free (tooltip);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-01-19 02:23:20 +01:00
|
|
|
on_menu_item_deselected (GtkMenuItem *item, LdWindowMain *window)
|
2010-09-13 19:24:53 +02:00
|
|
|
{
|
|
|
|
gtk_statusbar_pop (GTK_STATUSBAR (window->priv->statusbar),
|
|
|
|
window->priv->statusbar_menu_context_id);
|
|
|
|
}
|
|
|
|
|
2010-12-15 13:42:43 +01:00
|
|
|
|
|
|
|
/* ===== Diagram handling ================================================== */
|
|
|
|
|
2011-01-31 22:07:58 +01:00
|
|
|
static void
|
|
|
|
on_diagram_changed (LdDiagram *diagram, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
update_title (self);
|
2012-10-07 23:59:34 +02:00
|
|
|
|
|
|
|
if (self->priv->statusbar_hint_drag)
|
|
|
|
{
|
|
|
|
gtk_statusbar_remove (GTK_STATUSBAR (self->priv->statusbar),
|
|
|
|
self->priv->statusbar_hint_context_id,
|
|
|
|
self->priv->statusbar_hint_drag);
|
|
|
|
self->priv->statusbar_hint_drag = 0;
|
|
|
|
}
|
2011-01-31 22:07:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_diagram_history_changed (LdDiagram *diagram,
|
|
|
|
GParamSpec *pspec, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
action_set_sensitive (self, "Undo", ld_diagram_can_undo (diagram));
|
|
|
|
action_set_sensitive (self, "Redo", ld_diagram_can_redo (diagram));
|
|
|
|
}
|
|
|
|
|
2011-01-16 15:39:11 +01:00
|
|
|
static void
|
|
|
|
on_diagram_selection_changed (LdDiagram *diagram, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
gboolean selection_empty;
|
|
|
|
|
|
|
|
selection_empty = !ld_diagram_get_selection (diagram);
|
|
|
|
action_set_sensitive (self, "Delete", !selection_empty);
|
|
|
|
}
|
|
|
|
|
2010-12-15 13:42:43 +01:00
|
|
|
/*
|
|
|
|
* diagram_get_name:
|
|
|
|
*
|
|
|
|
* Get the name of the currently opened diagram.
|
|
|
|
*/
|
|
|
|
static gchar *
|
|
|
|
diagram_get_name (LdWindowMain *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (LD_IS_WINDOW_MAIN (self), NULL);
|
|
|
|
|
|
|
|
if (self->priv->filename)
|
2011-02-13 20:17:21 +01:00
|
|
|
return g_filename_display_basename (self->priv->filename);
|
2010-12-15 13:42:43 +01:00
|
|
|
else
|
|
|
|
return g_strdup (_("Unsaved Diagram"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* diagram_set_filename:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @filename: (allow-none): the new filename. %NULL for a new file.
|
2010-12-15 13:42:43 +01:00
|
|
|
*
|
2010-12-16 11:34:02 +01:00
|
|
|
* Set the filename corresponding to the currently opened diagram.
|
2010-12-15 13:42:43 +01:00
|
|
|
* The function takes ownership of the string.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
diagram_set_filename (LdWindowMain *self, gchar *filename)
|
|
|
|
{
|
|
|
|
g_return_if_fail (LD_IS_WINDOW_MAIN (self));
|
|
|
|
|
|
|
|
if (self->priv->filename)
|
|
|
|
g_free (self->priv->filename);
|
|
|
|
self->priv->filename = filename;
|
|
|
|
|
|
|
|
update_title (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* diagram_new:
|
|
|
|
*
|
|
|
|
* Create a new diagram.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
diagram_new (LdWindowMain *self)
|
|
|
|
{
|
|
|
|
g_return_if_fail (LD_IS_WINDOW_MAIN (self));
|
|
|
|
|
2011-02-13 20:17:21 +01:00
|
|
|
if (!may_close_diagram (self, _("Save the changes to diagram \"%s\" before"
|
|
|
|
" closing it and creating a new one?")))
|
2010-12-15 13:42:43 +01:00
|
|
|
return;
|
|
|
|
|
2010-12-16 11:34:02 +01:00
|
|
|
ld_diagram_clear (self->priv->diagram);
|
|
|
|
ld_diagram_set_modified (self->priv->diagram, FALSE);
|
2010-12-15 13:42:43 +01:00
|
|
|
|
2011-02-19 14:06:11 +01:00
|
|
|
ld_diagram_view_set_x (self->priv->view, 0);
|
|
|
|
ld_diagram_view_set_y (self->priv->view, 0);
|
2011-02-16 07:50:07 +01:00
|
|
|
ld_diagram_view_set_zoom (self->priv->view, 1);
|
2011-02-04 20:19:01 +01:00
|
|
|
|
2010-12-15 13:42:43 +01:00
|
|
|
diagram_set_filename (self, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* diagram_save:
|
|
|
|
*
|
|
|
|
* Save the current diagram.
|
|
|
|
*/
|
2012-08-12 07:25:06 +02:00
|
|
|
static gboolean
|
|
|
|
diagram_save (LdWindowMain *self, GtkWindow *dialog_parent,
|
|
|
|
const gchar *filename)
|
2010-12-15 13:42:43 +01:00
|
|
|
{
|
|
|
|
GError *error;
|
|
|
|
|
2012-08-12 07:25:06 +02:00
|
|
|
g_return_val_if_fail (LD_IS_WINDOW_MAIN (self), FALSE);
|
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
2010-12-15 13:42:43 +01:00
|
|
|
|
|
|
|
error = NULL;
|
2012-08-12 07:25:06 +02:00
|
|
|
ld_diagram_save_to_file (self->priv->diagram, filename, &error);
|
2010-12-15 13:42:43 +01:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
GtkWidget *message_dialog;
|
|
|
|
|
2011-01-28 17:39:40 +01:00
|
|
|
g_warning ("saving failed: %s", error->message);
|
2010-12-15 13:42:43 +01:00
|
|
|
g_error_free (error);
|
|
|
|
|
2012-08-12 07:25:06 +02:00
|
|
|
message_dialog = gtk_message_dialog_new (dialog_parent,
|
2010-12-15 13:42:43 +01:00
|
|
|
GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
|
2011-02-13 20:17:21 +01:00
|
|
|
_("Failed to save the diagram"));
|
2010-12-15 13:42:43 +01:00
|
|
|
gtk_message_dialog_format_secondary_text
|
|
|
|
(GTK_MESSAGE_DIALOG (message_dialog),
|
2011-02-13 20:17:21 +01:00
|
|
|
_("Try again or save it under another name."));
|
2010-12-15 13:42:43 +01:00
|
|
|
gtk_dialog_run (GTK_DIALOG (message_dialog));
|
|
|
|
gtk_widget_destroy (message_dialog);
|
2012-08-12 07:25:06 +02:00
|
|
|
return FALSE;
|
2010-12-15 13:42:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-16 11:34:02 +01:00
|
|
|
ld_diagram_set_modified (self->priv->diagram, FALSE);
|
2010-12-15 13:42:43 +01:00
|
|
|
update_title (self);
|
2012-08-12 07:25:06 +02:00
|
|
|
return TRUE;
|
2010-12-15 13:42:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-13 20:17:21 +01:00
|
|
|
/*
|
|
|
|
* diagram_open:
|
|
|
|
*
|
|
|
|
* Open a diagram from a file.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
diagram_open (LdWindowMain *self, const gchar *filename)
|
|
|
|
{
|
|
|
|
GError *error;
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
ld_diagram_load_from_file (self->priv->diagram, filename, &error);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
GtkWidget *message_dialog;
|
|
|
|
|
|
|
|
g_warning ("loading failed: %s", error->message);
|
|
|
|
|
|
|
|
message_dialog = gtk_message_dialog_new (GTK_WINDOW (self),
|
|
|
|
GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
|
|
|
|
_("Failed to open the file"));
|
2012-10-09 18:06:00 +02:00
|
|
|
|
|
|
|
if (error->domain != G_FILE_ERROR)
|
|
|
|
{
|
|
|
|
gchar *display_filename;
|
|
|
|
|
|
|
|
display_filename = g_filename_display_name (filename);
|
|
|
|
gtk_message_dialog_format_secondary_text
|
|
|
|
(GTK_MESSAGE_DIALOG (message_dialog),
|
|
|
|
_("Failed to open file `%s': Invalid contents."), filename);
|
|
|
|
g_free (display_filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_message_dialog_format_secondary_text
|
|
|
|
(GTK_MESSAGE_DIALOG (message_dialog),
|
|
|
|
"%s", error->message);
|
|
|
|
|
2011-02-13 20:17:21 +01:00
|
|
|
gtk_dialog_run (GTK_DIALOG (message_dialog));
|
|
|
|
gtk_widget_destroy (message_dialog);
|
2012-10-09 18:06:00 +02:00
|
|
|
|
|
|
|
g_error_free (error);
|
2011-02-13 20:17:21 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ld_diagram_set_modified (self->priv->diagram, FALSE);
|
|
|
|
diagram_set_filename (self, g_strdup (filename));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-12-15 13:42:43 +01:00
|
|
|
/*
|
|
|
|
* diagram_get_file_filter:
|
|
|
|
*
|
2011-01-28 17:39:40 +01:00
|
|
|
* Return value: a new #GtkFileFilter object for diagrams.
|
2010-12-15 13:42:43 +01:00
|
|
|
*/
|
|
|
|
static GtkFileFilter *
|
|
|
|
diagram_get_file_filter (void)
|
|
|
|
{
|
|
|
|
GtkFileFilter *filter;
|
|
|
|
|
|
|
|
filter = gtk_file_filter_new ();
|
2011-02-13 20:17:21 +01:00
|
|
|
gtk_file_filter_set_name (filter, _("Logdiag Diagrams (*.ldd)"));
|
2010-12-15 13:42:43 +01:00
|
|
|
gtk_file_filter_add_pattern (filter, "*.ldd");
|
|
|
|
return filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* diagram_show_open_dialog:
|
|
|
|
*
|
|
|
|
* Show a dialog for opening a diagram.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
diagram_show_open_dialog (LdWindowMain *self)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
g_return_if_fail (LD_IS_WINDOW_MAIN (self));
|
|
|
|
|
2011-02-13 20:17:21 +01:00
|
|
|
if (!may_close_diagram (self, _("Save the changes to diagram \"%s\" before"
|
|
|
|
" closing it and opening another one?")))
|
2010-12-15 13:42:43 +01:00
|
|
|
return;
|
|
|
|
|
2011-02-13 20:17:21 +01:00
|
|
|
dialog = gtk_file_chooser_dialog_new (_("Open..."), GTK_WINDOW (self),
|
2010-12-15 13:42:43 +01:00
|
|
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL);
|
|
|
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog),
|
|
|
|
diagram_get_file_filter ());
|
|
|
|
|
|
|
|
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
2011-02-13 20:17:21 +01:00
|
|
|
diagram_open (self, filename);
|
|
|
|
g_free (filename);
|
2010-12-15 13:42:43 +01:00
|
|
|
}
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* diagram_show_save_as_dialog:
|
|
|
|
*
|
|
|
|
* Show a dialog for saving the diagram.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
diagram_show_save_as_dialog (LdWindowMain *self)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
g_return_if_fail (LD_IS_WINDOW_MAIN (self));
|
|
|
|
|
2011-02-13 20:17:21 +01:00
|
|
|
dialog = gtk_file_chooser_dialog_new (_("Save As..."), GTK_WINDOW (self),
|
2010-12-15 13:42:43 +01:00
|
|
|
GTK_FILE_CHOOSER_ACTION_SAVE,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL);
|
|
|
|
g_object_set (dialog, "do-overwrite-confirmation", TRUE, NULL);
|
|
|
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog),
|
|
|
|
diagram_get_file_filter ());
|
|
|
|
|
2012-08-12 07:25:06 +02:00
|
|
|
if (self->priv->filename)
|
|
|
|
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog),
|
|
|
|
self->priv->filename);
|
|
|
|
|
|
|
|
while (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
|
2010-12-15 13:42:43 +01:00
|
|
|
{
|
2012-08-12 07:25:06 +02:00
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
|
|
|
|
if (diagram_save (self, GTK_WINDOW (dialog), filename))
|
|
|
|
{
|
|
|
|
diagram_set_filename (self, filename);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_free (filename);
|
2010-12-15 13:42:43 +01:00
|
|
|
}
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* may_close_diagram:
|
2011-01-28 17:39:40 +01:00
|
|
|
* @dialog_message: the dialog message to display to the user if the diagram
|
2010-12-15 13:42:43 +01:00
|
|
|
* has been modified.
|
|
|
|
*
|
|
|
|
* When no changes have been made to the current diagram, the function
|
|
|
|
* lets the caller proceed. Otherwise the user is asked for further actions.
|
|
|
|
* If he chooses to save the diagram, the function will handle this action.
|
|
|
|
*
|
2011-01-28 17:39:40 +01:00
|
|
|
* Return value: %FALSE if the current action should be cancelled.
|
|
|
|
* %TRUE if the caller may proceed.
|
2010-12-15 13:42:43 +01:00
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
may_close_diagram (LdWindowMain *self, const gchar *dialog_message)
|
|
|
|
{
|
|
|
|
GtkWidget *message_dialog;
|
|
|
|
gchar *name;
|
|
|
|
gint result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (LD_IS_WINDOW_MAIN (self), TRUE);
|
|
|
|
g_return_val_if_fail (dialog_message != NULL, TRUE);
|
|
|
|
|
2010-12-16 11:34:02 +01:00
|
|
|
if (!ld_diagram_get_modified (self->priv->diagram))
|
2010-12-15 13:42:43 +01:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
name = diagram_get_name (self);
|
|
|
|
|
|
|
|
/* TODO: Show the time since the diagram was last saved.
|
|
|
|
* (Record the event with g_get_current_time().)
|
|
|
|
*/
|
|
|
|
message_dialog = gtk_message_dialog_new (GTK_WINDOW (self),
|
|
|
|
GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE,
|
|
|
|
dialog_message, name);
|
|
|
|
gtk_message_dialog_format_secondary_text
|
|
|
|
(GTK_MESSAGE_DIALOG (message_dialog),
|
2011-02-13 20:17:21 +01:00
|
|
|
_("If you don't save, changes will be permanently lost."));
|
2010-12-15 13:42:43 +01:00
|
|
|
gtk_dialog_add_buttons (GTK_DIALOG (message_dialog),
|
2011-02-13 20:17:21 +01:00
|
|
|
_("Close _without Saving"), GTK_RESPONSE_NO,
|
2010-12-15 13:42:43 +01:00
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_SAVE, GTK_RESPONSE_YES,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
result = gtk_dialog_run (GTK_DIALOG (message_dialog));
|
|
|
|
gtk_widget_destroy (message_dialog);
|
|
|
|
g_free (name);
|
|
|
|
|
|
|
|
switch (result)
|
|
|
|
{
|
|
|
|
case GTK_RESPONSE_NO:
|
|
|
|
return TRUE;
|
|
|
|
case GTK_RESPONSE_YES:
|
2012-08-12 07:25:06 +02:00
|
|
|
on_action_save (NULL, self);
|
2010-12-15 13:42:43 +01:00
|
|
|
return TRUE;
|
|
|
|
case GTK_RESPONSE_CANCEL:
|
|
|
|
case GTK_RESPONSE_DELETE_EVENT:
|
|
|
|
return FALSE;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* may_quit:
|
|
|
|
*
|
|
|
|
* A variant on may_close_diagram() for the occasion of closing
|
|
|
|
* the whole application.
|
|
|
|
*
|
2011-01-28 17:39:40 +01:00
|
|
|
* Return value: %TRUE if the application may quit, %FALSE otherwise.
|
2010-12-15 13:42:43 +01:00
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
may_quit (LdWindowMain *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (LD_IS_WINDOW_MAIN (self), TRUE);
|
|
|
|
|
|
|
|
return may_close_diagram (self,
|
2011-02-13 20:17:21 +01:00
|
|
|
_("Save the changes to diagram \"%s\" before closing?"));
|
2010-12-15 13:42:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ===== User interface actions ============================================ */
|
|
|
|
|
2012-10-08 04:40:41 +02:00
|
|
|
static void
|
|
|
|
on_symbol_selected (LdCategoryView *view,
|
|
|
|
LdSymbol *symbol, const gchar *path, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
const gchar *symbol_name;
|
|
|
|
|
|
|
|
symbol_name = ld_symbol_get_human_name (symbol);
|
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (self->priv->statusbar),
|
|
|
|
self->priv->statusbar_menu_context_id, symbol_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_symbol_deselected (LdCategoryView *view,
|
|
|
|
LdSymbol *symbol, const gchar *path, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
gtk_statusbar_pop (GTK_STATUSBAR (self->priv->statusbar),
|
|
|
|
self->priv->statusbar_menu_context_id);
|
|
|
|
}
|
|
|
|
|
2011-02-04 20:19:01 +01:00
|
|
|
static void
|
2011-02-16 07:50:07 +01:00
|
|
|
on_view_zoom_changed (LdDiagramView *view, GParamSpec *pspec,
|
|
|
|
LdWindowMain *self)
|
2011-02-04 20:19:01 +01:00
|
|
|
{
|
2012-10-09 07:05:32 +02:00
|
|
|
gchar *zoom;
|
|
|
|
|
2011-02-04 20:19:01 +01:00
|
|
|
action_set_sensitive (self, "ZoomIn",
|
2011-02-16 07:50:07 +01:00
|
|
|
ld_diagram_view_can_zoom_in (self->priv->view));
|
2011-02-04 20:19:01 +01:00
|
|
|
action_set_sensitive (self, "ZoomOut",
|
2011-02-16 07:50:07 +01:00
|
|
|
ld_diagram_view_can_zoom_out (self->priv->view));
|
2011-02-04 20:19:01 +01:00
|
|
|
action_set_sensitive (self, "NormalSize",
|
2011-02-16 07:50:07 +01:00
|
|
|
ld_diagram_view_get_zoom (self->priv->view) != 1);
|
2012-10-09 07:05:32 +02:00
|
|
|
|
|
|
|
zoom = g_strdup_printf (_("%d%%"),
|
|
|
|
(gint) (ld_diagram_view_get_zoom (self->priv->view) * 100 + 0.5));
|
|
|
|
gtk_label_set_text (GTK_LABEL (self->priv->zoom_label), zoom);
|
|
|
|
g_free (zoom);
|
2011-02-04 20:19:01 +01:00
|
|
|
}
|
|
|
|
|
2011-01-24 06:00:47 +01:00
|
|
|
static void
|
2010-12-15 13:42:43 +01:00
|
|
|
on_action_new (GtkAction *action, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
diagram_new (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_action_open (GtkAction *action, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
diagram_show_open_dialog (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_action_save (GtkAction *action, LdWindowMain *self)
|
|
|
|
{
|
2012-08-12 07:25:06 +02:00
|
|
|
if (!self->priv->filename
|
|
|
|
|| !diagram_save (self, GTK_WINDOW (self), self->priv->filename))
|
|
|
|
diagram_show_save_as_dialog (self);
|
2010-12-15 13:42:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_action_save_as (GtkAction *action, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
diagram_show_save_as_dialog (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_action_quit (GtkAction *action, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
if (may_quit (self))
|
|
|
|
gtk_widget_destroy (GTK_WIDGET (self));
|
|
|
|
}
|
|
|
|
|
2010-09-13 19:24:53 +02:00
|
|
|
static void
|
2010-12-12 17:56:59 +01:00
|
|
|
on_action_about (GtkAction *action, LdWindowMain *self)
|
2010-09-13 19:24:53 +02:00
|
|
|
{
|
2010-12-12 17:56:59 +01:00
|
|
|
gtk_show_about_dialog (GTK_WINDOW (self),
|
2010-09-13 19:24:53 +02:00
|
|
|
"program-name", PROJECT_NAME,
|
2015-02-09 20:28:12 +01:00
|
|
|
"logo-icon-name", PROJECT_NAME,
|
2010-09-13 19:24:53 +02:00
|
|
|
"version", PROJECT_VERSION,
|
2011-03-04 17:42:32 +01:00
|
|
|
"translator-credits", _("translator-credits"),
|
2018-06-25 03:06:21 +02:00
|
|
|
"copyright", "Copyright Přemysl Janouch 2010 - 2018",
|
2011-02-07 18:03:15 +01:00
|
|
|
"website", PROJECT_URL,
|
2010-09-13 19:24:53 +02:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2011-01-31 22:07:58 +01:00
|
|
|
static void
|
|
|
|
on_action_undo (GtkAction *action, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
ld_diagram_undo (self->priv->diagram);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_action_redo (GtkAction *action, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
ld_diagram_redo (self->priv->diagram);
|
|
|
|
}
|
|
|
|
|
2011-01-16 15:39:11 +01:00
|
|
|
static void
|
|
|
|
on_action_delete (GtkAction *action, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
ld_diagram_remove_selection (self->priv->diagram);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_action_select_all (GtkAction *action, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
ld_diagram_select_all (self->priv->diagram);
|
|
|
|
}
|
2011-02-04 20:19:01 +01:00
|
|
|
|
2011-03-06 15:57:58 +01:00
|
|
|
static void
|
|
|
|
on_action_main_toolbar (GtkToggleAction *action, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
gtk_widget_set_visible (self->priv->toolbar,
|
|
|
|
gtk_toggle_action_get_active (action));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-10 03:38:11 +02:00
|
|
|
on_action_library_pane (GtkToggleAction *action, LdWindowMain *self)
|
2011-03-06 15:57:58 +01:00
|
|
|
{
|
2012-08-30 00:54:38 +02:00
|
|
|
gtk_widget_set_visible (self->priv->lv_window,
|
2011-03-06 15:57:58 +01:00
|
|
|
gtk_toggle_action_get_active (action));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_action_grid (GtkToggleAction *action, LdWindowMain *self)
|
|
|
|
{
|
|
|
|
ld_diagram_view_set_show_grid (self->priv->view,
|
|
|
|
gtk_toggle_action_get_active (action));
|
|
|
|
}
|
|
|
|
|
2011-02-04 20:19:01 +01:00
|
|
|
static void
|
|
|
|
on_action_zoom_in (GtkAction *action, LdWindowMain *self)
|
|
|
|
{
|
2011-02-16 07:50:07 +01:00
|
|
|
ld_diagram_view_zoom_in (self->priv->view);
|
2011-02-04 20:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_action_zoom_out (GtkAction *action, LdWindowMain *self)
|
|
|
|
{
|
2011-02-16 07:50:07 +01:00
|
|
|
ld_diagram_view_zoom_out (self->priv->view);
|
2011-02-04 20:19:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_action_normal_size (GtkAction *action, LdWindowMain *self)
|
|
|
|
{
|
2011-02-16 07:50:07 +01:00
|
|
|
ld_diagram_view_set_zoom (self->priv->view, 1);
|
2011-02-04 20:19:01 +01:00
|
|
|
}
|