]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikwindow.c
Fix intermittent problem of map redraw.
[andy/viking.git] / src / vikwindow.c
index ccdaa6b637c3685e8e9f8f8da3fea5463ce8ecb5..37eb13da9d803eb6c558bf181cce866bb0cabc02 100644 (file)
@@ -23,7 +23,7 @@
 #include "acquire.h"
 #include "datasources.h"
 
-#define VIKING_TITLE " - Viking " VIKING_VERSION " " VIKING_VERSION_NAME " " VIKING_URL
+#define VIKING_TITLE " - Viking"
 
 #include <glib/gprintf.h>
 #include <stdlib.h>
@@ -40,6 +40,8 @@
 #define make_dir(dir) mkdir(dir,0777)
 #endif
 
+#define VIKING_WINDOW_WIDTH      1000
+#define VIKING_WINDOW_HEIGHT     800
 #define DRAW_IMAGE_DEFAULT_WIDTH 1280
 #define DRAW_IMAGE_DEFAULT_HEIGHT 1024
 #define DRAW_IMAGE_DEFAULT_SAVE_AS_PNG TRUE
@@ -106,6 +108,7 @@ static void register_vik_icons (GtkIconFactory *icon_factory);
 static void load_file ( GtkAction *a, VikWindow *vw );
 static gboolean save_file_as ( GtkAction *a, VikWindow *vw );
 static gboolean save_file ( GtkAction *a, VikWindow *vw );
+static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw );
 static gboolean window_save ( VikWindow *vw );
 
 struct _VikWindow {
@@ -124,6 +127,8 @@ struct _VikWindow {
   guint16 tool_layer_id;
   guint16 tool_tool_id;
 
+  GtkActionGroup *action_group;
+
   gint pan_x, pan_y;
 
   guint draw_image_width, draw_image_height;
@@ -179,6 +184,26 @@ GType vik_window_get_type (void)
   return vw_type;
 }
 
+void vik_window_selected_layer(VikWindow *vw, VikLayer *vl)
+{
+  int i, j, tool_count;
+  VikLayerInterface *layer_interface;
+
+  if (!vw->action_group) return;
+
+  for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
+    GtkAction *action;
+    layer_interface = vik_layer_get_interface(i);
+    tool_count = layer_interface->tools_count;
+
+    for (j = 0; j < tool_count; j++) {
+      action = gtk_action_group_get_action(vw->action_group,
+           layer_interface->tools[j].name);
+      g_object_set(action, "sensitive", i == vl->type, NULL);
+    }
+  }
+}
+
 static void window_finalize ( GObject *gob )
 {
   VikWindow *vw = VIK_WINDOW(gob);
@@ -210,6 +235,7 @@ static void window_init ( VikWindow *vw )
   GtkWidget *main_vbox;
   GtkWidget *hpaned;
 
+  vw->action_group = NULL;
 
   vw->viking_vvp = vik_viewport_new();
   vw->viking_vlp = vik_layers_panel_new();
@@ -253,7 +279,7 @@ static void window_init ( VikWindow *vw )
   g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "motion_notify_event", G_CALLBACK(draw_mouse_motion), vw);
   g_signal_connect_swapped (G_OBJECT(vw->viking_vlp), "update", G_CALLBACK(draw_update), vw);
 
-  gtk_window_set_default_size ( GTK_WINDOW(vw), 1000, 800);
+  gtk_window_set_default_size ( GTK_WINDOW(vw), VIKING_WINDOW_WIDTH, VIKING_WINDOW_HEIGHT);
 
   hpaned = gtk_hpaned_new ();
   gtk_paned_add1 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vlp) );
@@ -277,7 +303,11 @@ VikWindow *vik_window_new ()
 
 static gboolean delete_event( VikWindow *vw )
 {
+#ifdef VIKING_PROMPT_IF_MODIFIED
   if ( vw->modified )
+#else
+  if (0)
+#endif
   {
     GtkDialog *dia;
     dia = GTK_DIALOG ( gtk_message_dialog_new ( GTK_WINDOW(vw), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
@@ -967,6 +997,7 @@ static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw )
     vw->current_tool = TOOL_RULER;
   }
   else {
+    /* TODO: only enable tools from active layer */
     for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
       for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
        if (!strcmp(vik_layer_get_interface(i)->tools[j].name, gtk_action_get_name(a))) {
@@ -1054,7 +1085,11 @@ static void load_file ( GtkAction *a, VikWindow *vw )
   if ( gtk_dialog_run ( GTK_DIALOG(vw->open_dia) ) == GTK_RESPONSE_OK )
   {
     gtk_widget_hide ( vw->open_dia );
+#ifdef VIKING_PROMPT_IF_MODIFIED
     if ( (vw->modified || vw->filename) && newwindow )
+#else
+    if ( vw->filename && newwindow )
+#endif
       g_signal_emit ( G_OBJECT(vw), window_signals[VW_OPENWINDOW_SIGNAL], 0, gtk_file_selection_get_selections (GTK_FILE_SELECTION(vw->open_dia) ) );
     else {
       gchar **files = gtk_file_selection_get_selections (GTK_FILE_SELECTION(vw->open_dia) );
@@ -1145,6 +1180,14 @@ static void window_close ( GtkAction *a, VikWindow *vw )
     gtk_widget_destroy ( GTK_WIDGET(vw) );
 }
 
+static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw )
+{
+  if (save_file( NULL, vw))
+    window_close( NULL, vw);
+  else
+    return(FALSE);
+}
+
 static void zoom_to_cb ( GtkAction *a, VikWindow *vw )
 {
   gdouble xmpp = vik_viewport_get_xmpp ( vw->viking_vvp ), ympp = vik_viewport_get_ympp ( vw->viking_vvp );
@@ -1542,6 +1585,7 @@ static GtkActionEntry entries[] = {
   { "GenImg",    GTK_STOCK_CLEAR,        "_Generate Image File",          NULL,         "Save a snapshot of the workspace into a file", (GCallback)draw_to_image_file_cb },
   { "GenImgDir", GTK_STOCK_DND_MULTIPLE, "Generate _Directory of Images", NULL,         "FIXME:IMGDIR",                                 (GCallback)draw_to_image_dir_cb  },
   { "Exit",      GTK_STOCK_QUIT,         "E_xit",                         "<control>W", "Exit the program",                             (GCallback)window_close          },
+  { "SaveExit",  GTK_STOCK_QUIT,         "Save and Exit",                 NULL, "Save and Exit the program",                             (GCallback)save_file_and_exit          },
 
   { "GotoLL",    GTK_STOCK_QUIT,         "_Go to Lat\\/Lon...",           NULL,         "Go to arbitrary lat\\/lon coordinate",         (GCallback)draw_goto_cb          },
   { "GotoUTM",   GTK_STOCK_QUIT,         "Go to UTM...",                  NULL,         "Go to arbitrary UTM coordinate",               (GCallback)draw_goto_cb          },
@@ -1688,6 +1732,15 @@ static void window_create_ui( VikWindow *window )
 
   gtk_ui_manager_insert_action_group (uim, action_group, 0);
 
+  for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
+    for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
+      GtkAction *action = gtk_action_group_get_action(action_group,
+                           vik_layer_get_interface(i)->tools[j].name);
+      g_object_set(action, "sensitive", FALSE, NULL);
+    }
+  }
+  window->action_group = action_group;
+
   accel_group = gtk_ui_manager_get_accel_group (uim);
   gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
   gtk_ui_manager_ensure_update (uim);