Example #1
0
static gpointer
_check_strptime_updates_wday (gpointer data)
{
	struct tm tm;

	memset (&tm, '\0', sizeof (tm));
	strptime ("2008:12:24 20:30:45", "%Y:%m:%d %T", &tm);
	/* Check if tm.tm_wday is set to Wednesday (3) now */
	return GBOOLEAN_TO_POINTER (tm.tm_wday == 3);
}
Example #2
0
/* CHECK: we probably need this one public for plugins...
 * maybe even a _list variant. Or maybe it's better make
 * cedit_window_close_tab always run the confirm dialog?
 * we should not allow closing a tab without resetting the
 * CEDIT_IS_CLOSING_ALL flag!
 */
void
_cedit_cmd_file_close_tab (CeditTab    *tab,
			   CeditWindow *window)
{
	cedit_debug (DEBUG_COMMANDS);

	g_return_if_fail (GTK_WIDGET (window) == gtk_widget_get_toplevel (GTK_WIDGET (tab)));

	g_object_set_data (G_OBJECT (window),
			   CEDIT_IS_CLOSING_ALL,
			   GBOOLEAN_TO_POINTER (FALSE));

	g_object_set_data (G_OBJECT (window),
			   CEDIT_IS_QUITTING,
			   GBOOLEAN_TO_POINTER (FALSE));

	g_object_set_data (G_OBJECT (window), 
	                   CEDIT_IS_QUITTING_ALL, 
	                   GINT_TO_POINTER (FALSE));


	if (tab_can_close (tab, GTK_WINDOW (window)))
		cedit_window_close_tab (window, tab);
}
Example #3
0
/* Close all tabs */
static void
file_close_all (CeditWindow *window,
		gboolean     is_quitting)
{
	GList     *unsaved_docs;
	GtkWidget *dlg;

	cedit_debug (DEBUG_COMMANDS);

	g_return_if_fail (!(cedit_window_get_state (window) &
	                    (CEDIT_WINDOW_STATE_SAVING |
	                     CEDIT_WINDOW_STATE_PRINTING |
	                     CEDIT_WINDOW_STATE_SAVING_SESSION)));

	g_object_set_data (G_OBJECT (window),
			   CEDIT_IS_CLOSING_ALL,
			   GBOOLEAN_TO_POINTER (TRUE));

	g_object_set_data (G_OBJECT (window),
			   CEDIT_IS_QUITTING,
			   GBOOLEAN_TO_POINTER (is_quitting));
			   
	unsaved_docs = cedit_window_get_unsaved_documents (window);

	if (unsaved_docs == NULL)
	{
		/* There is no document to save -> close all tabs */
		cedit_window_close_all_tabs (window);

		if (is_quitting)
			gtk_widget_destroy (GTK_WIDGET (window));

		return;
	}

	if (unsaved_docs->next == NULL)
	{
		/* There is only one unsaved document */
		CeditTab      *tab;
		CeditDocument *doc;

		doc = CEDIT_DOCUMENT (unsaved_docs->data);

		tab = cedit_tab_get_from_document (doc);
		g_return_if_fail (tab != NULL);

		cedit_window_set_active_tab (window, tab);

		dlg = cedit_close_confirmation_dialog_new_single (
						GTK_WINDOW (window),
						doc,
						FALSE);
	}
	else
	{
		dlg = cedit_close_confirmation_dialog_new (GTK_WINDOW (window),
							   unsaved_docs,
							   FALSE);
	}

	g_list_free (unsaved_docs);

	g_signal_connect (dlg,
			  "response",
			  G_CALLBACK (close_confirmation_dialog_response_handler),
			  window);

	gtk_widget_show (dlg);
}
Example #4
0
static void
close_confirmation_dialog_response_handler (CeditCloseConfirmationDialog *dlg,
					    gint                          response_id,
					    CeditWindow                  *window)
{
	GList *selected_documents;
	gboolean is_closing_all;

	cedit_debug (DEBUG_COMMANDS);

	is_closing_all = GPOINTER_TO_BOOLEAN (g_object_get_data (G_OBJECT (window),
					    			 CEDIT_IS_CLOSING_ALL));

	gtk_widget_hide (GTK_WIDGET (dlg));

	switch (response_id)
	{
		case GTK_RESPONSE_YES: /* Save and Close */
			selected_documents = cedit_close_confirmation_dialog_get_selected_documents (dlg);
			if (selected_documents == NULL)
			{
				if (is_closing_all)
				{
					/* There is no document to save -> close all tabs */
					/* We call gtk_widget_destroy before close_all_tabs
					 * because close_all_tabs could destroy the cedit window */
					gtk_widget_destroy (GTK_WIDGET (dlg));

					close_all_tabs (window);

					return;
				}
				else
					g_return_if_reached ();
			}
			else
			{
				if (is_closing_all)
				{
					save_and_close_all_documents (selected_documents,
								      window);
				}
				else
				{
					save_and_close_document (selected_documents,
								 window);
				}
			}

			g_list_free (selected_documents);

			break;

		case GTK_RESPONSE_NO: /* Close without Saving */
			if (is_closing_all)
			{
				/* We call gtk_widget_destroy before close_all_tabs
				 * because close_all_tabs could destroy the cedit window */
				gtk_widget_destroy (GTK_WIDGET (dlg));

				close_all_tabs (window);

				return;
			}
			else
			{
				const GList *unsaved_documents;

				unsaved_documents = cedit_close_confirmation_dialog_get_unsaved_documents (dlg);
				g_return_if_fail (unsaved_documents->next == NULL);

				close_document (window,
						CEDIT_DOCUMENT (unsaved_documents->data));
			}

			break;
		default: /* Do not close */

			/* Reset is_quitting flag */
			g_object_set_data (G_OBJECT (window),
					   CEDIT_IS_QUITTING,
					   GBOOLEAN_TO_POINTER (FALSE));

			break;
	}

	gtk_widget_destroy (GTK_WIDGET (dlg));
}
Example #5
0
static void
save_and_close_all_documents (const GList  *docs,
			      CeditWindow  *window)
{
	GList  *tabs;
	GList  *l;
	GSList *sl;
	GSList *tabs_to_save_as;
	GSList *tabs_to_save_and_close;
	GList  *tabs_to_close;

	cedit_debug (DEBUG_COMMANDS);

	g_return_if_fail (!(cedit_window_get_state (window) & CEDIT_WINDOW_STATE_PRINTING));

	tabs = gtk_container_get_children (
			GTK_CONTAINER (_cedit_window_get_notebook (window)));

	tabs_to_save_as = NULL;
	tabs_to_save_and_close = NULL;
	tabs_to_close = NULL;

	l = tabs;
	while (l != NULL)
	{
		CeditTab *t;
		CeditTabState state;
		CeditDocument *doc;

		t = CEDIT_TAB (l->data);

		state = cedit_tab_get_state (t);
		doc = cedit_tab_get_document (t);

		/* If the state is: ([*] invalid states)
		   - CEDIT_TAB_STATE_NORMAL: close (and if needed save)
		   - CEDIT_TAB_STATE_LOADING: close, we are sure the file is unmodified
		   - CEDIT_TAB_STATE_REVERTING: since the user wants
		     to return back to the version of the file she previously saved, we can close
		     without saving (CHECK: are we sure this is the right behavior, suppose the case 
		     the original file has been deleted)
		   - [*] CEDIT_TAB_STATE_SAVING: invalid, ClosAll
		     and Quit are unsensitive if the window state is SAVING.
		   - [*] CEDIT_TAB_STATE_PRINTING, CEDIT_TAB_STATE_PRINT_PREVIEWING: there is not a
		     real reason for not closing in this case, we do not save to avoid to run
		     two operations using the message area at the same time (may be we can remove
		     this limitation in the future). Note that ClosAll
		     and Quit are unsensitive if the window state is PRINTING.
		   - CEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW: close (and if needed save)
		   - CEDIT_TAB_STATE_LOADING_ERROR: close without saving (if the state is LOADING_ERROR then the
		     document is not modified)
		   - CEDIT_TAB_STATE_REVERTING_ERROR: we do not close since the document contains errors
		   - CEDIT_TAB_STATE_SAVING_ERROR: we do not close since the document contains errors
		   - CEDIT_TAB_STATE_GENERIC_ERROR: we do not close since the document contains
		     errors (CHECK: we should problably remove this state)
		   - [*] CEDIT_TAB_STATE_CLOSING: this state is invalid in this case
		*/

		g_return_if_fail (state != CEDIT_TAB_STATE_PRINTING);
		g_return_if_fail (state != CEDIT_TAB_STATE_PRINT_PREVIEWING);
		g_return_if_fail (state != CEDIT_TAB_STATE_CLOSING);
		g_return_if_fail (state != CEDIT_TAB_STATE_SAVING);

		if ((state != CEDIT_TAB_STATE_SAVING_ERROR) &&
		    (state != CEDIT_TAB_STATE_GENERIC_ERROR) &&
		    (state != CEDIT_TAB_STATE_REVERTING_ERROR))
		{
			if ((g_list_index ((GList *)docs, doc) >= 0) &&
			    (state != CEDIT_TAB_STATE_LOADING) &&
			    (state != CEDIT_TAB_STATE_LOADING_ERROR) &&			    
			    (state != CEDIT_TAB_STATE_REVERTING)) /* CHECK: is this the right behavior with REVERTING ?*/
			{			
				/* The document must be saved before closing */
				g_return_if_fail (document_needs_saving (doc));
				
				/* FIXME: manage the case of local readonly files owned by the
				   user is running cedit - Paolo (Dec. 8, 2005) */
				if (cedit_document_is_untitled (doc) ||
				    cedit_document_get_readonly (doc))
				{
					g_object_set_data (G_OBJECT (t),
							   CEDIT_IS_CLOSING_TAB,
							   GBOOLEAN_TO_POINTER (TRUE));

					tabs_to_save_as = g_slist_prepend (tabs_to_save_as,
									   t);
				}
				else
				{
					tabs_to_save_and_close = g_slist_prepend (tabs_to_save_and_close,
										  t);
				}
			}
			else
			{
				/* The document must be closed without saving */
				tabs_to_close = g_list_prepend (tabs_to_close,
								t);
			}
		}

		l = g_list_next (l);
	}

	g_list_free (tabs);

	/* Close all tabs to close (in a sync way) */
	cedit_window_close_tabs (window, tabs_to_close);
	g_list_free (tabs_to_close);

	/* Save and close all the files in tabs_to_save_and_close */
	sl = tabs_to_save_and_close;
	while (sl != NULL)
	{
		save_and_close (CEDIT_TAB (sl->data),
				window);
		sl = g_slist_next (sl);
	}
	g_slist_free (tabs_to_save_and_close);

	/* Save As and close all the files in tabs_to_save_as  */
	if (tabs_to_save_as != NULL)
	{
		CeditTab *tab;

		tabs_to_save_as = g_slist_reverse (tabs_to_save_as );

		g_return_if_fail (g_object_get_data (G_OBJECT (window),
						     CEDIT_LIST_OF_TABS_TO_SAVE_AS) == NULL);

		g_object_set_data (G_OBJECT (window),
				   CEDIT_LIST_OF_TABS_TO_SAVE_AS,
				   tabs_to_save_as);

		tab = CEDIT_TAB (tabs_to_save_as->data);

		save_as_and_close (tab, window);
	}
}