diary r93 - in trunk: . data src



Author: pwithnall
Date: Wed Oct 22 06:30:18 2008
New Revision: 93
URL: http://svn.gnome.org/viewvc/diary?rev=93&view=rev

Log:
2008-10-22  Philip Withnall  <philip tecnocode co uk>

	* data/almanah.ui:
	* src/main-window.c (almanah_main_window_new),
	(mw_entry_buffer_cursor_position_cb),
	(mw_entry_buffer_has_selection_cb): Ensure the Cut/Copy/Delete 
actions
	are only sensitive when a text range is selected in the current 
entry.
	Also ensure that the entry text view has the default focus.



Modified:
   trunk/ChangeLog
   trunk/data/almanah.ui
   trunk/src/main-window.c

Modified: trunk/data/almanah.ui
==============================================================================
--- trunk/data/almanah.ui	(original)
+++ trunk/data/almanah.ui	Wed Oct 22 06:30:18 2008
@@ -33,6 +33,7 @@
 					<object class="GtkAction" id="dry_ui_cut">
 						<property name="stock-id">gtk-cut</property>
 						<property name="name">edit-cut</property>
+						<property name="sensitive">False</property><!-- Disabled until a selection range is made -->
 						<signal name="activate" handler="mw_cut_activate_cb"/>
 					</object>
 				</child>
@@ -40,6 +41,7 @@
 					<object class="GtkAction" id="dry_ui_copy">
 						<property name="stock-id">gtk-copy</property>
 						<property name="name">edit-copy</property>
+						<property name="sensitive">False</property><!-- Disabled until a selection range is made -->
 						<signal name="activate" handler="mw_copy_activate_cb"/>
 					</object>
 				</child>
@@ -54,6 +56,7 @@
 					<object class="GtkAction" id="dry_ui_delete">
 						<property name="stock-id">gtk-delete</property>
 						<property name="name">edit-delete</property>
+						<property name="sensitive">False</property><!-- Disabled until a selection range is made -->
 						<signal name="activate" handler="mw_delete_activate_cb"/>
 					</object>
 				</child>
@@ -83,18 +86,21 @@
 						<property name="stock-id">gtk-bold</property>
 						<property name="name">format-bold</property>
 					</object>
+					<accelerator key="B" modifiers="GDK_CONTROL_MASK"/>
 				</child>
 				<child>
 					<object class="GtkToggleAction" id="dry_ui_italic">
 						<property name="stock-id">gtk-italic</property>
 						<property name="name">format-italic</property>
 					</object>
+					<accelerator key="I" modifiers="GDK_CONTROL_MASK"/>
 				</child>
 				<child>
 					<object class="GtkToggleAction" id="dry_ui_underline">
 						<property name="stock-id">gtk-underline</property>
 						<property name="name">format-underline</property>
 					</object>
+					<accelerator key="U" modifiers="GDK_CONTROL_MASK"/>
 				</child>
 				<child>
 					<object class="GtkAction" id="dry_ui_help">
@@ -203,7 +209,7 @@
 				</child>
 				<child>
 					<object class="GtkHPaned" id="hpaned1">
-						<property name="can_focus">True</property>
+						<property name="can-focus">True</property>
 						<child>
 							<object class="GtkVBox" id="vbox3">
 								<child>
@@ -225,6 +231,7 @@
 												<property name="width-request">300</property>
 												<property name="height-request">300</property>
 												<property name="can-focus">True</property>
+												<property name="has-focus">True</property>
 												<property name="wrap-mode">GTK_WRAP_WORD</property>
 												<signal name="focus-out-event" handler="mw_entry_view_focus_out_event_cb"/>
 											</object>

Modified: trunk/src/main-window.c
==============================================================================
--- trunk/src/main-window.c	(original)
+++ trunk/src/main-window.c	Wed Oct 22 06:30:18 2008
@@ -36,7 +36,8 @@
 static void almanah_main_window_init (AlmanahMainWindow *self);
 static void almanah_main_window_dispose (GObject *object);
 static gboolean mw_delete_event_cb (GtkWindow *window, gpointer user_data);
-static void mw_entry_buffer_cursor_position_changed_cb (GObject *object, GParamSpec *pspec, AlmanahMainWindow *main_window);
+static void mw_entry_buffer_cursor_position_cb (GObject *object, GParamSpec *pspec, AlmanahMainWindow *main_window);
+static void mw_entry_buffer_has_selection_cb (GObject *object, GParamSpec *pspec, AlmanahMainWindow *main_window);
 static void mw_bold_toggled_cb (GtkToggleAction *action, AlmanahMainWindow *main_window);
 static void mw_italic_toggled_cb (GtkToggleAction *action, AlmanahMainWindow *main_window);
 static void mw_underline_toggled_cb (GtkToggleAction *action, AlmanahMainWindow *main_window);
@@ -61,6 +62,9 @@
 	GtkToggleAction *bold_action;
 	GtkToggleAction *italic_action;
 	GtkToggleAction *underline_action;
+	GtkAction *cut_action;
+	GtkAction *copy_action;
+	GtkAction *delete_action;
 
 	gboolean updating_formatting_actions;
 
@@ -165,6 +169,9 @@
 	priv->bold_action = GTK_TOGGLE_ACTION (gtk_builder_get_object (builder, "dry_ui_bold"));;
 	priv->italic_action = GTK_TOGGLE_ACTION (gtk_builder_get_object (builder, "dry_ui_italic"));
 	priv->underline_action = GTK_TOGGLE_ACTION (gtk_builder_get_object (builder, "dry_ui_underline"));
+	priv->cut_action = GTK_ACTION (gtk_builder_get_object (builder, "dry_ui_cut"));
+	priv->copy_action = GTK_ACTION (gtk_builder_get_object (builder, "dry_ui_copy"));
+	priv->delete_action = GTK_ACTION (gtk_builder_get_object (builder, "dry_ui_delete"));
 
 	/* Set up text formatting */
 	gtk_text_buffer_create_tag (priv->entry_buffer, "bold", 
@@ -188,7 +195,10 @@
 #endif /* ENABLE_SPELL_CHECKING */
 
 	/* Make sure we're notified if the cursor moves position so we can check the tag stack */
-	g_signal_connect (priv->entry_buffer, "notify::cursor-position", G_CALLBACK (mw_entry_buffer_cursor_position_changed_cb), main_window);
+	g_signal_connect (priv->entry_buffer, "notify::cursor-position", G_CALLBACK (mw_entry_buffer_cursor_position_cb), main_window);
+
+	/* Similarly, make sure we're notified when there's a selection so we can change the status of cut/copy/paste actions */
+	g_signal_connect (priv->entry_buffer, "notify::has-selection", G_CALLBACK (mw_entry_buffer_has_selection_cb), main_window);
 
 	/* Connect up the formatting actions */
 	g_signal_connect (priv->bold_action, "toggled", G_CALLBACK (mw_bold_toggled_cb), main_window);
@@ -400,7 +410,7 @@
 }
 
 static void
-mw_entry_buffer_cursor_position_changed_cb (GObject *object, GParamSpec *pspec, AlmanahMainWindow *main_window)
+mw_entry_buffer_cursor_position_cb (GObject *object, GParamSpec *pspec, AlmanahMainWindow *main_window)
 {
 	GtkTextIter iter;
 	AlmanahMainWindowPrivate *priv = main_window->priv;
@@ -460,6 +470,16 @@
 	priv->updating_formatting_actions = FALSE;
 }
 
+static void
+mw_entry_buffer_has_selection_cb (GObject *object, GParamSpec *pspec, AlmanahMainWindow *main_window)
+{
+	gboolean has_selection = gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (object));
+
+	gtk_action_set_sensitive (main_window->priv->cut_action, has_selection);
+	gtk_action_set_sensitive (main_window->priv->copy_action, has_selection);
+	gtk_action_set_sensitive (main_window->priv->delete_action, has_selection);
+}
+
 static gboolean
 mw_delete_event_cb (GtkWindow *window, gpointer user_data)
 {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]