static void set_readonly (GeditDocument *doc, gboolean readonly) { gedit_debug (DEBUG_DOCUMENT); g_return_if_fail (GEDIT_IS_DOCUMENT (doc)); readonly = readonly != FALSE; if (doc->priv->readonly != readonly) { doc->priv->readonly = readonly; g_object_notify (G_OBJECT (doc), "read-only"); } }
static void menu_position (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, GeditDocumentsPanel *panel) { GtkTreePath *path; GdkRectangle rect; gint wy; GtkRequisition requisition; GtkWidget *w; GtkAllocation allocation; gedit_debug (DEBUG_PANEL); w = panel->priv->treeview; path = get_current_path (panel); gtk_tree_view_get_cell_area (GTK_TREE_VIEW (w), path, NULL, &rect); gtk_tree_path_free (path); wy = rect.y; gdk_window_get_origin (gtk_widget_get_window (w), x, y); gtk_widget_get_preferred_size (GTK_WIDGET (menu), &requisition, NULL); gtk_widget_get_allocation (w, &allocation); if (gtk_widget_get_direction (w) == GTK_TEXT_DIR_RTL) { *x += allocation.x + allocation.width - requisition.width - 10; } else { *x += allocation.x + 10; } wy = MAX (*y + 5, *y + wy + 5); wy = MIN (wy, *y + allocation.height - requisition.height - 5); *y = wy; *push_in = TRUE; }
static gchar * get_current_word (GeditDocument *doc, gint *start, gint *end) { const CheckRange *range; GtkTextIter end_iter; GtkTextIter current_iter; gint range_end; gedit_debug (DEBUG_PLUGINS); g_return_val_if_fail (doc != NULL, NULL); g_return_val_if_fail (start != NULL, NULL); g_return_val_if_fail (end != NULL, NULL); range = get_check_range (doc); g_return_val_if_fail (range != NULL, NULL); gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), &end_iter, range->end_mark); range_end = gtk_text_iter_get_offset (&end_iter); gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (doc), ¤t_iter, range->current_mark); end_iter = current_iter; if (!gtk_text_iter_is_end (&end_iter)) { gedit_debug_message (DEBUG_PLUGINS, "Current is not end"); gtk_text_iter_forward_word_end (&end_iter); } *start = gtk_text_iter_get_offset (¤t_iter); *end = MIN (gtk_text_iter_get_offset (&end_iter), range_end); gedit_debug_message (DEBUG_PLUGINS, "Current word extends [%d, %d]", *start, *end); if (!(*start < *end)) return NULL; return gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc), ¤t_iter, &end_iter, TRUE); }
static GtkTreePath * get_current_path (GeditDocumentsPanel *panel) { gint notebook_num; gint page_num; GtkWidget *notebook; gedit_debug (DEBUG_PANEL); notebook = _gedit_window_get_notebook (panel->priv->window); notebook_num = gedit_multi_notebook_get_notebook_num (panel->priv->mnb, GEDIT_NOTEBOOK (notebook)); page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); return gtk_tree_path_new_from_indices (notebook_num, page_num, -1); }
void _gedit_cmd_documents_move_to_new_window (GSimpleAction *action, GVariant *parameter, gpointer user_data) { GeditWindow *window = GEDIT_WINDOW (user_data); GeditTab *tab; gedit_debug (DEBUG_COMMANDS); tab = gedit_window_get_active_tab (window); if (tab == NULL) return; _gedit_window_move_tab_to_new_window (window, tab); }
static void gedit_word_completion_window_activate (GeditWindowActivatable *activatable) { GeditWordCompletionPluginPrivate *priv; GtkSourceCompletionWords *provider; gedit_debug (DEBUG_PLUGINS); priv = GEDIT_WORD_COMPLETION_PLUGIN (activatable)->priv; provider = create_provider (); g_object_set_data_full (G_OBJECT (priv->window), WINDOW_PROVIDER, provider, (GDestroyNotify)g_object_unref); }
static void gedit_document_finalize (GObject *object) { GeditDocument *doc = GEDIT_DOCUMENT (object); gedit_debug (DEBUG_DOCUMENT); if (doc->priv->untitled_number > 0) { release_untitled_number (doc->priv->untitled_number); } g_free (doc->priv->content_type); g_free (doc->priv->short_name); G_OBJECT_CLASS (gedit_document_parent_class)->finalize (object); }
static void treeview_selection_changed (GtkTreeSelection *selection, GeditDocumentsPanel *panel) { GtkTreeIter iter; gedit_debug (DEBUG_PANEL); if (gtk_tree_selection_get_selected (selection, NULL, &iter)) { GeditNotebook *notebook; GeditTab *tab; gtk_tree_model_get (panel->priv->model, &iter, NOTEBOOK_COLUMN, ¬ebook, TAB_COLUMN, &tab, -1); if (tab != NULL) { gedit_multi_notebook_set_active_tab (panel->priv->mnb, tab); if (notebook != NULL) g_object_unref (notebook); g_object_unref (tab); } else if (notebook != NULL) { panel->priv->setting_active_notebook = TRUE; gtk_widget_grab_focus (GTK_WIDGET (notebook)); panel->priv->setting_active_notebook = FALSE; tab = gedit_multi_notebook_get_active_tab (panel->priv->mnb); if (tab != NULL) { g_signal_connect (gedit_tab_get_document (tab), "changed", G_CALLBACK (document_changed), panel); } g_object_unref (notebook); } } }
static void gedit_documents_panel_dispose (GObject *object) { GeditDocumentsPanel *panel = GEDIT_DOCUMENTS_PANEL (object); gedit_debug (DEBUG_PANEL); if (panel->priv->refresh_idle_id != 0) { g_source_remove (panel->priv->refresh_idle_id); panel->priv->refresh_idle_id = 0; } g_clear_object (&panel->priv->window); G_OBJECT_CLASS (gedit_documents_panel_parent_class)->dispose (object); }
void _gedit_cmd_edit_cut (GSimpleAction *action, GVariant *parameter, gpointer user_data) { GeditWindow *window = GEDIT_WINDOW (user_data); GeditView *active_view; gedit_debug (DEBUG_COMMANDS); active_view = gedit_window_get_active_view (window); g_return_if_fail (active_view); gedit_view_cut_clipboard (active_view); gtk_widget_grab_focus (GTK_WIDGET (active_view)); }
static void update_ui_real (GeditWindow *window, WindowData *data) { GeditDocument *doc; GeditView *view; gboolean autospell; GtkAction *action; gedit_debug (DEBUG_PLUGINS); doc = gedit_window_get_active_document (window); view = gedit_window_get_active_view (window); autospell = (doc != NULL && gedit_automatic_spell_checker_get_from_document (doc) != NULL); if (doc != NULL) { GeditTab *tab; GeditTabState state; tab = gedit_window_get_active_tab (window); state = gedit_tab_get_state (tab); /* If the document is loading we can't get the metadata so we endup with an useless speller */ if (state == GEDIT_TAB_STATE_NORMAL) { action = gtk_action_group_get_action (data->action_group, "AutoSpell"); g_signal_handlers_block_by_func (action, auto_spell_cb, window); set_auto_spell (window, doc, autospell); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), autospell); g_signal_handlers_unblock_by_func (action, auto_spell_cb, window); } } gtk_action_group_set_sensitive (data->action_group, (view != NULL) && gtk_text_view_get_editable (GTK_TEXT_VIEW (view))); }
static void set_language_cb (GSimpleAction *action, GVariant *parameter, gpointer data) { GeditSpellPlugin *plugin = GEDIT_SPELL_PLUGIN (data); GeditSpellPluginPrivate *priv; GeditDocument *doc; GeditSpellChecker *spell; const GeditSpellCheckerLanguage *lang; GtkWidget *dlg; GtkWindowGroup *wg; gchar *data_dir; gedit_debug (DEBUG_PLUGINS); priv = plugin->priv; doc = gedit_window_get_active_document (priv->window); g_return_if_fail (doc != NULL); spell = get_spell_checker_from_document (doc); g_return_if_fail (spell != NULL); lang = gedit_spell_checker_get_language (spell); data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); dlg = gedit_spell_language_dialog_new (GTK_WINDOW (priv->window), lang, data_dir); g_free (data_dir); wg = gedit_window_get_group (priv->window); gtk_window_group_add_window (wg, GTK_WINDOW (dlg)); gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); g_signal_connect (dlg, "response", G_CALLBACK (language_dialog_response), spell); gtk_widget_show (dlg); }
static void set_language (GeditDocument *doc, GtkSourceLanguage *lang, gboolean set_by_user) { GtkSourceLanguage *old_lang; gedit_debug (DEBUG_DOCUMENT); old_lang = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (doc)); if (old_lang == lang) { return; } gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (doc), lang); if (lang != NULL) { gboolean syntax_hl; syntax_hl = g_settings_get_boolean (doc->priv->editor_settings, GEDIT_SETTINGS_SYNTAX_HIGHLIGHTING); gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), syntax_hl); } else { gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc), FALSE); } if (set_by_user) { const gchar *language = get_language_string (doc); gedit_document_set_metadata (doc, GEDIT_METADATA_ATTRIBUTE_LANGUAGE, language, NULL); } doc->priv->language_set_by_user = set_by_user; }
static void multi_notebook_tab_removed (GeditMultiNotebook *mnb, GeditNotebook *notebook, GeditTab *tab, GeditDocumentsPanel *panel) { gedit_debug (DEBUG_PANEL); g_signal_handlers_disconnect_by_func (gedit_tab_get_document (tab), G_CALLBACK (document_changed), panel); g_signal_handlers_disconnect_by_func (tab, G_CALLBACK (sync_name_and_icon), panel); refresh_list (panel); }
static void set_content_type_no_guess (GeditDocument *doc, const gchar *content_type) { GeditDocumentPrivate *priv; gchar *dupped_content_type; gedit_debug (DEBUG_DOCUMENT); priv = gedit_document_get_instance_private (doc); if (priv->content_type != NULL && content_type != NULL && g_str_equal (priv->content_type, content_type)) { return; } g_free (priv->content_type); /* For compression types, we try to just guess from the content */ if (gedit_utils_get_compression_type_from_content_type (content_type) != GTK_SOURCE_COMPRESSION_TYPE_NONE) { dupped_content_type = get_content_type_from_content (doc); } else { dupped_content_type = g_strdup (content_type); } if (dupped_content_type == NULL || g_content_type_is_unknown (dupped_content_type)) { priv->content_type = get_default_content_type (); g_free (dupped_content_type); } else { priv->content_type = dupped_content_type; } g_object_notify (G_OBJECT (doc), "content-type"); }
static void gedit_document_finalize (GObject *object) { GeditDocumentPrivate *priv; gedit_debug (DEBUG_DOCUMENT); priv = gedit_document_get_instance_private (GEDIT_DOCUMENT (object)); if (priv->untitled_number > 0) { release_untitled_number (priv->untitled_number); } g_free (priv->content_type); g_free (priv->short_name); G_OBJECT_CLASS (gedit_document_parent_class)->finalize (object); }
/* If @line is bigger than the lines of the document, the cursor is moved * to the last line and FALSE is returned. */ gboolean gedit_document_goto_line (GeditDocument *doc, gint line) { GtkTextIter iter; gedit_debug (DEBUG_DOCUMENT); g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE); g_return_val_if_fail (line >= -1, FALSE); gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (doc), &iter, line); gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &iter); return gtk_text_iter_get_line (&iter) == line; }
static void gedit_spell_plugin_deactivate (GeditWindowActivatable *activatable) { GeditSpellPluginPrivate *priv; gedit_debug (DEBUG_PLUGINS); priv = GEDIT_SPELL_PLUGIN (activatable)->priv; g_action_map_remove_action (G_ACTION_MAP (priv->window), "check-spell"); g_action_map_remove_action (G_ACTION_MAP (priv->window), "config-spell"); g_action_map_remove_action (G_ACTION_MAP (priv->window), "auto-spell"); g_signal_handler_disconnect (priv->window, priv->tab_added_id); g_signal_handler_disconnect (priv->window, priv->tab_removed_id); }
static void multi_notebook_tab_added (GeditMultiNotebook *mnb, GeditNotebook *notebook, GeditTab *tab, GeditDocumentsPanel *panel) { gedit_debug (DEBUG_PANEL); g_signal_connect (tab, "notify::name", G_CALLBACK (sync_name_and_icon), panel); g_signal_connect (tab, "notify::state", G_CALLBACK (sync_name_and_icon), panel); refresh_list (panel); }
void _gedit_cmd_edit_overwrite_mode (GSimpleAction *action, GVariant *state, gpointer user_data) { GeditWindow *window = GEDIT_WINDOW (user_data); GeditView *active_view; gboolean overwrite; gedit_debug (DEBUG_COMMANDS); active_view = gedit_window_get_active_view (window); g_return_if_fail (active_view); overwrite = g_variant_get_boolean (state); g_simple_action_set_state (action, state); gtk_text_view_set_overwrite (GTK_TEXT_VIEW (active_view), overwrite); gtk_widget_grab_focus (GTK_WIDGET (active_view)); }
void _gedit_cmd_edit_redo (GtkAction *action, GeditWindow *window) { GeditView *active_view; GtkSourceBuffer *active_document; gedit_debug (DEBUG_COMMANDS); active_view = gedit_window_get_active_view (window); g_return_if_fail (active_view); active_document = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); gtk_source_buffer_redo (active_document); gedit_view_scroll_to_cursor (active_view); gtk_widget_grab_focus (GTK_WIDGET (active_view)); }
static void save_encoding_metadata (GeditDocument *doc) { const GtkSourceEncoding *encoding; const gchar *charset; gedit_debug (DEBUG_DOCUMENT); encoding = gtk_source_file_get_encoding (doc->priv->file); if (encoding == NULL) { encoding = gtk_source_encoding_get_utf8 (); } charset = gtk_source_encoding_get_charset (encoding); gedit_document_set_metadata (doc, GEDIT_METADATA_ATTRIBUTE_ENCODING, charset, NULL); }
static void set_language_cb (GtkAction *action, ActionData *action_data) { GeditDocument *doc; GeditSpellChecker *spell; const GeditSpellCheckerLanguage *lang; GtkWidget *dlg; GtkWindowGroup *wg; gchar *data_dir; gedit_debug (DEBUG_PLUGINS); doc = gedit_window_get_active_document (action_data->window); g_return_if_fail (doc != NULL); spell = get_spell_checker_from_document (doc); g_return_if_fail (spell != NULL); lang = gedit_spell_checker_get_language (spell); data_dir = gedit_plugin_get_data_dir (action_data->plugin); dlg = gedit_spell_language_dialog_new (GTK_WINDOW (action_data->window), lang, data_dir); g_free (data_dir); wg = gedit_window_get_group (action_data->window); gtk_window_group_add_window (wg, GTK_WINDOW (dlg)); gtk_window_set_modal (GTK_WINDOW (dlg), TRUE); g_signal_connect (dlg, "response", G_CALLBACK (language_dialog_response), spell); gtk_widget_show (dlg); }
static void impl_deactivate (GeditPlugin *plugin, GeditWindow *window) { GtkUIManager *manager; WindowData *data; gedit_debug (DEBUG_PLUGINS); manager = gedit_window_get_ui_manager (window); data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY); g_return_if_fail (data != NULL); gtk_ui_manager_remove_ui (manager, data->ui_id); gtk_ui_manager_remove_action_group (manager, data->action_group); g_signal_handler_disconnect (window, data->tab_added_id); g_signal_handler_disconnect (window, data->tab_removed_id); g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL); }
static void multi_notebook_tab_switched (GeditMultiNotebook *mnb, GeditNotebook *old_notebook, GeditTab *old_tab, GeditNotebook *new_notebook, GeditTab *new_tab, GeditDocumentsPanel *panel) { gedit_debug (DEBUG_PANEL); if (!panel->priv->setting_active_notebook && !_gedit_window_is_removing_tabs (panel->priv->window)) { GtkTreeIter iter; if (get_iter_from_tab (panel, new_notebook, new_tab, &iter) && gtk_tree_store_iter_is_valid (GTK_TREE_STORE (panel->priv->model), &iter)) { select_iter (panel, &iter); } } }
void _gedit_cmd_edit_redo (GSimpleAction *action, GVariant *parameter, gpointer user_data) { GeditWindow *window = GEDIT_WINDOW (user_data); GeditView *active_view; GtkSourceBuffer *active_document; gedit_debug (DEBUG_COMMANDS); active_view = gedit_window_get_active_view (window); g_return_if_fail (active_view); active_document = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view))); gtk_source_buffer_redo (active_document); gedit_view_scroll_to_cursor (active_view); gtk_widget_grab_focus (GTK_WIDGET (active_view)); }
static void gedit_word_completion_view_deactivate (GeditViewActivatable *activatable) { GeditWordCompletionPluginPrivate *priv; GtkSourceCompletion *completion; GtkSourceCompletionProvider *provider; GtkTextBuffer *buf; gedit_debug (DEBUG_PLUGINS); priv = GEDIT_WORD_COMPLETION_PLUGIN (activatable)->priv; completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (priv->view)); buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->view)); gtk_source_completion_remove_provider (completion, priv->provider, NULL); gtk_source_completion_words_unregister (GTK_SOURCE_COMPLETION_WORDS (priv->provider), buf); }
void _gedit_cmd_view_show_side_pane (GtkAction *action, GeditWindow *window) { gboolean visible; GeditPanel *panel; gedit_debug (DEBUG_COMMANDS); visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); panel = gedit_window_get_side_panel (window); if (visible) { gtk_widget_show (GTK_WIDGET (panel)); gtk_widget_grab_focus (GTK_WIDGET (panel)); } else { gtk_widget_hide (GTK_WIDGET (panel)); } }
static void gedit_spell_plugin_activate (GeditWindowActivatable *activatable) { GeditSpellPlugin *plugin; GeditSpellPluginPrivate *priv; GList *views, *l; gedit_debug (DEBUG_PLUGINS); plugin = GEDIT_SPELL_PLUGIN (activatable); priv = plugin->priv; g_action_map_add_action_entries (G_ACTION_MAP (priv->window), action_entries, G_N_ELEMENTS (action_entries), activatable); priv->message_cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (gedit_window_get_statusbar (priv->window)), "spell_plugin_message"); update_ui (plugin); views = gedit_window_get_views (priv->window); for (l = views; l != NULL; l = g_list_next (l)) { GeditView *view = GEDIT_VIEW (l->data); set_auto_spell_from_metadata (plugin, view); } priv->tab_added_id = g_signal_connect (priv->window, "tab-added", G_CALLBACK (tab_added_cb), activatable); priv->tab_removed_id = g_signal_connect (priv->window, "tab-removed", G_CALLBACK (tab_removed_cb), activatable); }
static gboolean show_tab_popup_menu (GeditDocumentsPanel *panel, GeditTab *tab, GdkEventButton *event) { GtkWidget *menu; gedit_debug (DEBUG_PANEL); menu = gedit_notebook_popup_menu_new (panel->priv->window, tab); if (event != NULL) { gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, event->time); } else { gtk_menu_popup (GTK_MENU (menu), NULL, NULL, (GtkMenuPositionFunc)menu_position, panel, 0, gtk_get_current_event_time ()); gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE); } return TRUE; }