]> granicus.if.org Git - graphviz/commitdiff
graph modified dialog implemented , BYTE defined in smyrnadefs , cleaned up test...
authorarif <devnull@localhost>
Thu, 23 Apr 2009 18:06:03 +0000 (18:06 +0000)
committerarif <devnull@localhost>
Thu, 23 Apr 2009 18:06:03 +0000 (18:06 +0000)
cmd/smyrna/gui/menucallbacks.c
cmd/smyrna/main.c
cmd/smyrna/smyrnadefs.h
cmd/smyrna/viewport.c
cmd/smyrna/viewport.h

index e595ccc74a6387f758ef37e495eae30fe0aa6848..8ee07e46fb0d365b2d1a9e38593dc2ff6ce23926 100755 (executable)
@@ -82,44 +82,32 @@ void mOptionsSlot(GtkWidget * widget, gpointer user_data)
 
 void mQuitSlot(GtkWidget * widget, gpointer user_data)
 {
-    //1 check all graphs 1 by 1 to see any unsaved
-    int respond;
-    int gIndex;
-#ifdef UNUSED
-    int active_graph = view->activeGraph;      //stores the active graph in case quit aborted
-#endif
-    for (gIndex = 0; gIndex < view->graphCount; gIndex++) {
-       view->activeGraph = gIndex;
-       if (view->Topview->Graphdata.Modified)
-       {
-           sprintf(buf,
-                   "graph %s has been modified \n , would you like to save it before quitting the the program?",
-                    view->Topview->Graphdata.GraphFileName);
-           Dlg =
-               (GtkMessageDialog *) gtk_message_dialog_new(NULL,
-                                                           GTK_DIALOG_MODAL,
-                                                           GTK_MESSAGE_QUESTION,
-                                                           GTK_BUTTONS_NONE,
-                                                           buf);
-           gtk_dialog_add_button((GtkDialog *) Dlg, "YES", 100);
-           gtk_dialog_add_button((GtkDialog *) Dlg, "NO", 101);
-           gtk_dialog_add_button((GtkDialog *) Dlg, "Cancel", 102);
-
-           respond = gtk_dialog_run((GtkDialog *) Dlg);
-           if (respond == 100) //save and continue
-           {
-               if (!save_graph())
-                   break;
-           }
-           if (respond == 102) //save and continue
-           {
-               break;
-           }
-       }
-    }
-    gtk_main_quit();
+       if (close_graph(view,view->activeGraph));
+               gtk_main_quit();
 }
 
+int show_close_nosavedlg(void)
+{
+  GtkWidget *dialog;
+  char buf[512];
+  int rv;      /*return value*/
+  sprintf(buf,"%s has been modified. Do you want to save it before closing?",view->Topview->Graphdata.GraphFileName);
+  dialog = gtk_message_dialog_new(NULL,
+            GTK_DIALOG_MODAL,
+            GTK_MESSAGE_QUESTION,
+            GTK_BUTTONS_NONE,
+            buf);
+
+  gtk_window_set_title(GTK_WINDOW(dialog), "Smyrna Warning");
+  gtk_dialog_add_button(dialog,"Yes",0);
+  gtk_dialog_add_button(dialog,"No",1);
+  gtk_dialog_add_button(dialog,"Cancel",2);
+  rv=gtk_dialog_run(GTK_DIALOG(dialog));
+  gtk_widget_destroy(dialog);
+  return rv;
+}
+
+
 
 //edit
 void mCutSlot(GtkWidget * widget, gpointer user_data)
index 9fa995ed2ff6565bee456342bdf34203cf9f0c3c..4eb030e63e6ce5c77992e9d7843aa96149fc318a 100755 (executable)
@@ -129,62 +129,6 @@ static void close_cgraph(Agraph_t* g)
 }
 
 
-static Agraph_t* test_cgraph(Agraph_t* g,char* filename)
-{
-
-       Agnode_t *v;
-       Agedge_t *e;
-       FILE *input_file;
-       char buf[512];
-       if (g)
-               close_cgraph(g);
-       
-       if (!(input_file = fopen(filename, "r")))
-       {
-               g_print("Cannot open %s\n", filename);
-               return 0;
-    }
-    if (!(g = agread(input_file, NIL(Agdisc_t *)))) 
-       {
-               g_print("Cannot read graph in  %s\n", filename);
-               fclose (input_file);
-               return 0;
-    }
-
-    for (v = agfstnode(g); v; v = agnxtnode(g, v)) 
-       {
-               agbindrec(v, "temp_node_record", sizeof(temp_node_record), TRUE);//graph custom data
-       }
-    for (v = agfstnode(g); v; v = agnxtnode(g, v)) 
-       {
-               for (e = agfstout(g, v); e; e = agnxtout(g, e)) 
-               {
-                       strcpy(buf, agget(aghead(e), "pos"));
-               }
-       }
-
-       return g;
-}
-static void test_md5()
-{
-               char buf[512];
-               BYTE digest[16];
-               md5_state_t pms;
-               int ind=0;
-
-               strcpy(buf,"sdfsdfsdfasdf asdfas dasdf asdf asdfas fsd asd fasdf asd fasdf sda fsdf asdf sda fasfsdf sdf sdf");
-               /* Initialize the algorithm. */
-               md5_init(&pms);
-               for (ind =0 ; ind < 1500000 ; ind ++)
-               {
-                       md5_append(&pms,buf,32);
-               }
-               md5_finish(&pms,digest);
-               for (ind=0;ind < 16;ind ++)
-               {
-                       printf ("%x ",digest[ind]);
-               }
-}
 
 
 
@@ -196,15 +140,6 @@ int main(int argc, char *argv[])
     GdkGLConfig *glconfig;
     char* initFileName;
        Agraph_t* g=NULL;
-       Agraph_t* testg=NULL;
-
-//     testg=test_cgraph(testg,"c:/4elt.gv");
-//     agclose(testg);
-//     test_cgraph(testg,"c:/4elt.gv");
-       test_md5();
-
-
-
        smyrnaDir = getenv ("SMYRNA_PATH");
 #ifndef _WIN32
     if (!smyrnaDir)
index 7a286411fe705a7197ad2747b0ef3a3674a3778b..b211ceae4a330300bdbcda05aafe9300c6cf1250 100644 (file)
@@ -44,6 +44,8 @@
 #include "glcompset.h"
 #include "hier.h"
 
+typedef unsigned char       BYTE;
+
 #define IS_TEST_MODE_ON                                                        0
 #define        DEFAULT_MAGNIFIER_WIDTH                                 300
 #define        DEFAULT_MAGNIFIER_HEIGHT                                225
index 39871fefff70fa84693a484ebcc69d67a3b407ec..bef23b77aaba4516ecdf0c053bb8c81a897f32d3 100755 (executable)
@@ -62,14 +62,9 @@ void clear_viewport(ViewInfo * view)
     /*free topview if there is one */
     if (view->activeGraph >= 0) 
                cleartopview(view->Topview);
-    if (view->graphCount) {
-       /*all cgraph graphs should be freed */
-       for (ind = 0; ind < view->graphCount; ind++) {
-           agclose(view->g[ind]);
-       }
-       /*frees itself */
-    }
-    free(view);
+    if (view->graphCount) 
+               agclose(view->g[view->activeGraph]);
+       init_viewport(view);
 }
 static void* get_glut_font(int ind)
 {
@@ -99,7 +94,7 @@ static void* get_glut_font(int ind)
        }
 
 }
-static fill_key(BYTE* b,BYTE* data)
+static void fill_key(BYTE* b,BYTE* data)
 {
        int ind=0;
        for (ind=0;ind < 16;ind ++)
@@ -108,30 +103,56 @@ static fill_key(BYTE* b,BYTE* data)
        }
 
 }
+static int compare_keys(BYTE* b1,BYTE* b2)
+{
+       /*1 keys are equal*/
+       /*0 not equal*/
+
+       int ind=0;
+       int eq=1;
+       for (ind=0;ind < 16;ind ++)
+       {
+               if (b1[ind] != b2[ind])
+               {
+                       eq=0;
+               }
+       }
+       return eq;
+}
 
 
-void close_graph(ViewInfo * view,int graphid)
+int close_graph(ViewInfo * view,int graphid)
 {
        int ind=0;
        int modified=0;
-       /*check if graph has been modified*/
+       if (view->activeGraph < 0)
+               return 1;
        fill_key(view->final_key,get_md5_key(view->g[graphid]));
-       printf ("graph original identification:");
-       for (ind=0;ind < 16;ind ++)
-       {
-               printf ("%x ",view->orig_key[ind]);
-       }
-       printf ("graph final identification:");
-       for (ind=0;ind < 16;ind ++)
+       if (!compare_keys(view->final_key,view->orig_key))
+               view->Topview->Graphdata.Modified=1;
+       if (view->Topview->Graphdata.Modified)
        {
-               printf ("%x ",view->final_key[ind]);
-       }
+               switch (show_close_nosavedlg())
+               {
+                       case 0: /*save and close*/
+                               save_graph();
+                               clear_viewport(view);
+                               return 1;
+                               break;
+                       case 1:/*dont save but close*/
+                               clear_viewport(view);
+                               return 1;
+                               break;
+                       case 2:/*cancel do nothing*/
+                               return 0;
+                               break;
+                       default:
+                               break;
+               }
+    }
+       clear_viewport(view);
+       return 1;
 
-       if (graphid >= 0) 
-               cleartopview(view->Topview);
-    agclose(view->g[0]);
-       view->graphCount = view->graphCount -1;
-       view->activeGraph=-1;
 }
 
 char *get_attribute_value(char *attr, ViewInfo * view, Agraph_t * g)
@@ -977,9 +998,12 @@ void glexpose(void) {
     expose_event(view->drawing_area, NULL, NULL);
 }
 int gl_main_expose(void) {
-       if(view->Topview->animate==1)
-               expose_event(view->drawing_area, NULL, NULL);
-       return 1;
+       if (view->activeGraph >= 0)
+       {
+               if(view->Topview->animate==1)
+                       expose_event(view->drawing_area, NULL, NULL);
+               return 1;
+       }
 }
 
 
@@ -1001,3 +1025,5 @@ void please_dont_wait(void)
     gtk_widget_hide(glade_xml_get_widget(xml, "frmWait"));
 }
 
+
+
index 924bb84d62d5905d4b5c5f4fe6d7a6bc881bb73f..3e14974b49befcce342c7b9ecf1be139cac4afc2 100755 (executable)
@@ -27,7 +27,7 @@ void init_viewport(ViewInfo * view);
 void set_viewport_settings_from_template(ViewInfo * view, Agraph_t *);
 void clear_viewport(ViewInfo * view);
 int add_graph_to_viewport_from_file(char *fileName);
-void close_graph(ViewInfo * view,int graphid);
+int close_graph(ViewInfo * view,int graphid);
 int save_graph(void);
 int save_graph_with_file_name(Agraph_t * graph, char *fileName);
 int save_as_graph(void);