Example #1
0
void
close_tab(void) {
	Document *doc;
	GtkWidget *scroll;
	int index;

	/* Since a keypress only works on the currently active
	 * tab anyway, we might as well ask the index of the current
	 * page here and use that, instead of passing the index as
	 * a parameter.
	 * Also, since we need both the GtkScrolledWindow and the Document
	 * it is of no use to call get_active_document().
	 */
	index = gtk_notebook_get_current_page(GTK_NOTEBOOK(lightpad->tabs));
	scroll = gtk_notebook_get_nth_page(GTK_NOTEBOOK(lightpad->tabs), index);
	doc = g_object_get_data(G_OBJECT(scroll), "doc");
	if(doc->modified) {
		int save = check_for_save(doc);
		switch(save) {
			case GTK_RESPONSE_YES:
				if(save_to_file(doc, TRUE) < 0)
					return;
			case GTK_RESPONSE_NO: break;
			default: return;
		}
	}
	gtk_widget_destroy(scroll); /* this destroys both scroll's child and its container */
}
Example #2
0
File: main.c Project: 4179e1/misc
/*
Called when the user clicks the 'Quit' menu. We need to prompt for save if the
file has been modified and then break out of the GTK+ main loop.
*/
void on_quit_menu_item_activate (GtkMenuItem *menuitem, TutorialTextEditor *editor)
{
        if (check_for_save (editor) == TRUE)
        {
              on_save_menu_item_activate (NULL, editor);  
        }
        gtk_main_quit();
}
Example #3
0
File: open.c Project: Moeryn/bmc
/**
 * \fn void open_file_with_path(BrailleMusicEditor *editor, const gchar *path)
 * \brief This function opens a file with the path parameter 
 * and show it in editor's textview.
 * \param editor The GUI structure.
 * 
 * This function will check if there is unsaved changes in the editor 
 * calling check_for_save function.
 */
void open_file_with_path(BrailleMusicEditor *editor, const gchar *path) {
    gint resp=check_for_save (editor);
    if (resp == 1){
	save_file(editor->textview, editor);
	open_file_(editor,path);
    }			
    else if(resp == 0)
	open_file_(editor, path);
    editor->text_changed = FALSE;
} 
Example #4
0
File: main.c Project: 4179e1/misc
/*
When the window is requested to be closed, we need to check if they have 
unsaved work. We use this callback to prompt the user to save their work before
they exit the application. From the "delete-event" signal, we can choose to
effectively cancel the close based on the value we return.
*/
gboolean 
on_window_delete_event (GtkWidget *widget, GdkEvent *event, 
                        TutorialTextEditor *editor)
{
        if (check_for_save (editor) == TRUE)
        {
              on_save_menu_item_activate (NULL, editor);  
        }
        return FALSE;   /* propogate event */
}
Example #5
0
File: open.c Project: Moeryn/bmc
/**
 * \fn void open_file(GtkWidget *widget, BrailleMusicEditor *editor)
 * \brief That function is called when selecting open file.
 * \param widget The widget which triggered the call.
 * \param editor The GUI structure.
 * 
 * This function will show un file selection dialog and
 * check if there is unsaved changes in the editor 
 * calling check_for_save function.
 */
void open_file(GtkWidget *widget, BrailleMusicEditor *editor)
{
    gint resp=check_for_save (editor);
    if (resp == 1){
	save_file(widget, editor);
	open_file_with_selection(editor);
    }			
    else if(resp == 0)
	open_file_with_selection(editor);
    editor->text_changed = FALSE;
}
Example #6
0
File: main.c Project: 4179e1/misc
/*
Called when the user clicks the 'Open' menu. We need to prompt for save if the
file has been modified, allow the user to choose a file to open, and then call
load_file() on that file.
*/
void on_open_menu_item_activate (GtkMenuItem *menuitem, TutorialTextEditor *editor)
{
        gchar                   *filename;
        
        if (check_for_save (editor) == TRUE)
        {
              on_save_menu_item_activate (NULL, editor);  
        }
        
        filename = get_open_filename (editor);
        if (filename != NULL) load_file (editor, filename); 
}
Example #7
0
G_MODULE_EXPORT
gboolean on_menu_quit_activate(void)
{
  gint wx = 0, wy = 0, width = 0, height = 0;
  gchar buf[16];
  int i = 0;
  gint length = g_list_length(gummi->tabmanager->tabs);

  motion_pause_compile_thread(gummi->motion);
  for (i = 0; i < length; i++) {
    gtk_notebook_set_current_page(gui->tabmanagergui->notebook, i);
    tabmanager_set_active_tab(i);

    gint ret = check_for_save(g_active_editor);
    if (GTK_RESPONSE_YES == ret) {
      gui_save_file(g_active_tab, FALSE);
    }
    else if (GTK_RESPONSE_CANCEL == ret || GTK_RESPONSE_DELETE_EVENT == ret) {
      motion_resume_compile_thread(gummi->motion);
      return TRUE;
    }
  }

  /* Stop compile thread */
  if (length > 0) motion_stop_compile_thread(gummi->motion);

  gboolean is_maximized;
  g_object_get(gui->mainwindow, "is-maximized", &is_maximized, NULL);

  if (!is_maximized) {
    gtk_window_get_size(gui->mainwindow, &width, &height);
    gtk_window_get_position(gui->mainwindow, &wx, &wy);

    config_begin();
    config_set_value("mainwindow_x", g_ascii_dtostr(buf, 16, (double)wx));
    config_set_value("mainwindow_y", g_ascii_dtostr(buf, 16, (double)wy));
    config_set_value("mainwindow_w", g_ascii_dtostr(buf, 16, (double)width));
    config_set_value("mainwindow_h", g_ascii_dtostr(buf, 16, (double)height));
    config_commit();
  }

  gtk_main_quit();

  for (i = 0; i < length; i++)
    editor_destroy(GU_TAB_CONTEXT(g_list_nth_data
                                  (gummi->tabmanager->tabs, i))->editor);

  printf("   ___ \n"
         "  {o,o}    Thanks for using Gummi!\n"
         "  |)__)    I welcome your feedback at:\n"
         "  -\"-\"-    http://gummi.midnightcoding.org\n\n");
  return FALSE;
}
Example #8
0
File: main.c Project: 4179e1/misc
/*
Called when the user clicks the 'New' menu. We need to prompt for save if the
file has been modified, and then delete the buffer and clear the modified flag.
*/
void on_new_menu_item_activate (GtkMenuItem *menuitem, TutorialTextEditor *editor)
{
        GtkTextBuffer           *buffer;
        
        if (check_for_save (editor) == TRUE)
        {
              on_save_menu_item_activate (NULL, editor);  
        }
        
        /* clear editor for a new file */
        editor->filename = NULL;
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->text_view));
        gtk_text_buffer_set_text (buffer, "", -1);
        gtk_text_buffer_set_modified (buffer, FALSE);
        
        reset_default_status (editor);
}
Example #9
0
G_MODULE_EXPORT
void on_menu_close_activate (GtkWidget *widget, void* user) {
    GuTabContext* tab = NULL;
    
    tab = (user)? GU_TAB_CONTEXT (user): g_active_tab;
    
    gint ret = check_for_save (tab->editor);
    
    if (GTK_RESPONSE_YES == ret)
        gui_save_file (tab, FALSE);
    else if (GTK_RESPONSE_CANCEL == ret || GTK_RESPONSE_DELETE_EVENT == ret)
        return;
    
    /* Kill typesetter command */
    motion_kill_typesetter(gummi->motion);

    if (!tabmanager_remove_tab (tab)) {
        motion_start_errormode (gummi->motion, "");
        gui_set_hastabs_sensitive (FALSE);
    } else {
        gui_set_filename_display (g_active_tab, TRUE, FALSE);
    }
}