void GUI::add_program_file(gchar * filepath){ if (this->is_empty_notebook){ this->is_empty_notebook = false; gtk_notebook_remove_page(GTK_NOTEBOOK(this->programs_notebook), this->empty_notebook_index); } GuiNotebookItem notebook_item; notebook_item.vmachine = NULL; notebook_item.filepath = filepath; // netobook label notebook_item.notebook_label_text = this->extract_file_name(notebook_item.filepath); notebook_item.notebook_label = gtk_label_new (notebook_item.notebook_label_text); // create inner notebook vbox notebook_item.notebook_vbox = gtk_vbox_new(FALSE, 0); // create scrolled_window notebook_item.notebook_scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (notebook_item.notebook_scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start (GTK_BOX (notebook_item.notebook_vbox), notebook_item.notebook_scrolled_window, TRUE, // vbox gives widget all remaining space TRUE, // widget expands to fill given space 0); // pixel of padding around the widget // create notebook_source_view notebook_item.source_buffer = gtk_source_buffer_new (NULL); notebook_item.source_view = gtk_source_view_new_with_buffer(notebook_item.source_buffer); gtk_container_add (GTK_CONTAINER (notebook_item.notebook_scrolled_window), notebook_item.source_view); gtk_source_view_set_auto_indent ( GTK_SOURCE_VIEW (notebook_item.source_view), TRUE); // make a tab be two spaces gtk_source_view_set_indent_width (GTK_SOURCE_VIEW (notebook_item.source_view), 2); gtk_source_view_set_highlight_current_line (GTK_SOURCE_VIEW (notebook_item.source_view), TRUE); gtk_source_view_set_show_line_numbers ( GTK_SOURCE_VIEW (notebook_item.source_view), TRUE); gtk_source_view_set_right_margin_position ( GTK_SOURCE_VIEW (notebook_item.source_view), 80); // default is 70 chars gtk_source_view_set_show_right_margin ( GTK_SOURCE_VIEW (notebook_item.source_view), TRUE); gtk_text_view_set_wrap_mode ( GTK_TEXT_VIEW (notebook_item.source_view), GTK_WRAP_WORD_CHAR); gtk_text_view_set_editable ( GTK_TEXT_VIEW (notebook_item.source_view), FALSE); gtk_text_view_set_cursor_visible ( GTK_TEXT_VIEW (notebook_item.source_view), FALSE); /* setup view */ PangoFontDescription * font_desc = NULL; font_desc = pango_font_description_from_string ("monospace"); if (font_desc != NULL){ gtk_widget_modify_font (notebook_item.source_view, font_desc); pango_font_description_free (font_desc); } // get file content gchar * buffer; GError * error_here = NULL; if (g_file_get_contents (notebook_item.filepath, &buffer, NULL, &error_here)){ gtk_source_buffer_begin_not_undoable_action (notebook_item.source_buffer); gtk_source_buffer_begin_not_undoable_action (notebook_item.source_buffer); gtk_text_buffer_set_text (GTK_TEXT_BUFFER (notebook_item.source_buffer), buffer, -1); gtk_source_buffer_end_not_undoable_action (notebook_item.source_buffer); gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (notebook_item.source_buffer), FALSE); /* move cursor to the beginning */ gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (notebook_item.source_buffer), ¬ebook_item.iter); gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (notebook_item.source_buffer), ¬ebook_item.iter); { GtkTextIter start, end; char *text; gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (notebook_item.source_buffer), &start, &end); text = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (notebook_item.source_buffer), &start, &end, TRUE); g_assert (!strcmp (text, buffer)); g_free (text); } g_free (buffer); GtkWidget * vm_frame; vm_frame = gtk_frame_new ("VM operations"); // create buttons notebook_item.notebook_button_hbox = gtk_hbox_new (FALSE, 0); notebook_item.run_step_button = gtk_button_new_with_label ("Run Step"); notebook_item.run_button = gtk_button_new_with_label ("Run"); notebook_item.view_vm_mem = gtk_button_new_with_label ("View Vm memory"); // create time out input notebook_item.timeout_field = gtk_entry_new_with_max_length(10); GtkWidget * timeout_label; timeout_label = gtk_label_new("Timeout:"); g_signal_connect (notebook_item.run_step_button, "clicked", G_CALLBACK (GUI::run_step_button_clicked), gpointer(this)); g_signal_connect (notebook_item.run_button, "clicked", G_CALLBACK (GUI::run_button_clicked), gpointer(this)); g_signal_connect (notebook_item.view_vm_mem, "clicked", G_CALLBACK (GUI::view_vm_mem_clicked), gpointer(this)); gtk_box_pack_start (GTK_BOX (notebook_item.notebook_button_hbox), notebook_item.view_vm_mem, FALSE, // vbox gives widget all remaining space FALSE, // widget expands to fill given space 5); // pixel of padding around the widget gtk_box_pack_start (GTK_BOX (notebook_item.notebook_button_hbox), notebook_item.run_step_button, FALSE, // vbox gives widget all remaining space FALSE, // widget expands to fill given space 5); // pixel of padding around the widget gtk_box_pack_start (GTK_BOX (notebook_item.notebook_button_hbox), timeout_label, FALSE, // vbox gives widget all remaining space FALSE, // widget expands to fill given space 5); // pixel of padding around the widget gtk_box_pack_start (GTK_BOX (notebook_item.notebook_button_hbox), notebook_item.timeout_field, FALSE, // vbox gives widget all remaining space FALSE, // widget expands to fill given space 5); // pixel of padding around the widget gtk_box_pack_start (GTK_BOX (notebook_item.notebook_button_hbox), notebook_item.run_button, FALSE, // vbox gives widget all remaining space FALSE, // widget expands to fill given space 5); // pixel of padding around the widget gtk_container_add(GTK_CONTAINER (vm_frame), notebook_item.notebook_button_hbox); gtk_box_pack_start (GTK_BOX (notebook_item.notebook_vbox), vm_frame, FALSE, // vbox gives widget all remaining space FALSE, // widget expands to fill given space 5); gtk_notebook_append_page( GTK_NOTEBOOK(this->programs_notebook), notebook_item.notebook_vbox, notebook_item.notebook_label); this->gui_notebook_item_list.push_back(notebook_item); gtk_widget_show_all(this->programs_notebook); } else { g_print("WRONG \n"); } }
void modeline_parser_apply_modeline (GtkSourceView *view) { ModelineOptions options; GtkTextBuffer *buffer; GtkTextIter iter, liter; gint line_count; GSettings *settings; options.language_id = NULL; options.set = MODELINE_SET_NONE; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); gtk_text_buffer_get_start_iter (buffer, &iter); line_count = gtk_text_buffer_get_line_count (buffer); /* Parse the modelines on the 10 first lines... */ while ((gtk_text_iter_get_line (&iter) < 10) && !gtk_text_iter_is_end (&iter)) { gchar *line; liter = iter; gtk_text_iter_forward_to_line_end (&iter); line = gtk_text_buffer_get_text (buffer, &liter, &iter, TRUE); parse_modeline (line, 1 + gtk_text_iter_get_line (&iter), line_count, &options); gtk_text_iter_forward_line (&iter); g_free (line); } /* ...and on the 10 last ones (modelines are not allowed in between) */ if (!gtk_text_iter_is_end (&iter)) { gint cur_line; guint remaining_lines; /* we are on the 11th line (count from 0) */ cur_line = gtk_text_iter_get_line (&iter); /* g_assert (10 == cur_line); */ remaining_lines = line_count - cur_line - 1; if (remaining_lines > 10) { gtk_text_buffer_get_end_iter (buffer, &iter); gtk_text_iter_backward_lines (&iter, 9); } } while (!gtk_text_iter_is_end (&iter)) { gchar *line; liter = iter; gtk_text_iter_forward_to_line_end (&iter); line = gtk_text_buffer_get_text (buffer, &liter, &iter, TRUE); parse_modeline (line, 1 + gtk_text_iter_get_line (&iter), line_count, &options); gtk_text_iter_forward_line (&iter); g_free (line); } /* Try to set language */ if (has_option (&options, MODELINE_SET_LANGUAGE) && options.language_id) { if (g_ascii_strcasecmp (options.language_id, "text") == 0) { gedit_document_set_language (GEDIT_DOCUMENT (buffer), NULL); } else { GtkSourceLanguageManager *manager; GtkSourceLanguage *language; manager = gedit_get_language_manager (); language = gtk_source_language_manager_get_language (manager, options.language_id); if (language != NULL) { gedit_document_set_language (GEDIT_DOCUMENT (buffer), language); } else { gedit_debug_message (DEBUG_PLUGINS, "Unknown language `%s'", options.language_id); } } } ModelineOptions *previous = g_object_get_data (G_OBJECT (buffer), MODELINE_OPTIONS_DATA_KEY); settings = g_settings_new ("org.gnome.gedit.preferences.editor"); /* Apply the options we got from modelines and restore defaults if we set them before */ if (has_option (&options, MODELINE_SET_INSERT_SPACES)) { gtk_source_view_set_insert_spaces_instead_of_tabs (view, options.insert_spaces); } else if (check_previous (view, previous, MODELINE_SET_INSERT_SPACES)) { gboolean insert_spaces; insert_spaces = g_settings_get_boolean (settings, GEDIT_SETTINGS_INSERT_SPACES); gtk_source_view_set_insert_spaces_instead_of_tabs (view, insert_spaces); } if (has_option (&options, MODELINE_SET_TAB_WIDTH)) { gtk_source_view_set_tab_width (view, options.tab_width); } else if (check_previous (view, previous, MODELINE_SET_TAB_WIDTH)) { guint tab_width; g_settings_get (settings, GEDIT_SETTINGS_TABS_SIZE, "u", &tab_width); gtk_source_view_set_tab_width (view, tab_width); } if (has_option (&options, MODELINE_SET_INDENT_WIDTH)) { gtk_source_view_set_indent_width (view, options.indent_width); } else if (check_previous (view, previous, MODELINE_SET_INDENT_WIDTH)) { gtk_source_view_set_indent_width (view, -1); } if (has_option (&options, MODELINE_SET_WRAP_MODE)) { gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), options.wrap_mode); } else if (check_previous (view, previous, MODELINE_SET_WRAP_MODE)) { GtkWrapMode mode; mode = g_settings_get_enum (settings, GEDIT_SETTINGS_WRAP_MODE); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), mode); } if (has_option (&options, MODELINE_SET_RIGHT_MARGIN_POSITION)) { gtk_source_view_set_right_margin_position (view, options.right_margin_position); } else if (check_previous (view, previous, MODELINE_SET_RIGHT_MARGIN_POSITION)) { guint right_margin_pos; g_settings_get (settings, GEDIT_SETTINGS_RIGHT_MARGIN_POSITION, "u", &right_margin_pos); gtk_source_view_set_right_margin_position (view, right_margin_pos); } if (has_option (&options, MODELINE_SET_SHOW_RIGHT_MARGIN)) { gtk_source_view_set_show_right_margin (view, options.display_right_margin); } else if (check_previous (view, previous, MODELINE_SET_SHOW_RIGHT_MARGIN)) { gboolean display_right_margin; display_right_margin = g_settings_get_boolean (settings, GEDIT_SETTINGS_DISPLAY_RIGHT_MARGIN); gtk_source_view_set_show_right_margin (view, display_right_margin); } if (previous) { g_free (previous->language_id); *previous = options; previous->language_id = g_strdup (options.language_id); } else { previous = g_slice_new (ModelineOptions); *previous = options; previous->language_id = g_strdup (options.language_id); g_object_set_data_full (G_OBJECT (buffer), MODELINE_OPTIONS_DATA_KEY, previous, (GDestroyNotify)free_modeline_options); } g_object_unref (settings); g_free (options.language_id); }
void sourceview_prefs_init(Sourceview* sv) { GtkSourceDrawSpacesFlags flags = 0; /* We create a new GSettings object here because if we used the one from * the editor might be destroyed while the plugin is still alive */ sv->priv->settings = g_settings_new (PREF_SCHEMA); sv->priv->docman_settings = g_settings_new (DOCMAN_PREF_SCHEMA); sv->priv->msgman_settings = g_settings_new (MSGMAN_PREF_SCHEMA); /* Bind simple options to GSettings */ g_settings_bind (sv->priv->settings, HIGHLIGHT_SYNTAX, sv->priv->document, "highlight-syntax", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, HIGHLIGHT_CURRENT_LINE, sv->priv->view, "highlight-current-line", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, TAB_SIZE, sv->priv->view, "tab-width", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, HIGHLIGHT_BRACKETS, sv->priv->document, "highlight-matching-brackets", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, VIEW_MARKS, sv->priv->view, "show-line-marks", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, RIGHTMARGIN_POSITION, sv->priv->view, "right-margin-position", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, VIEW_RIGHTMARGIN, sv->priv->view, "show-right-margin", G_SETTINGS_BIND_GET); g_settings_bind (sv->priv->settings, VIEW_LINENUMBERS, sv->priv->view, "show-line-numbers", G_SETTINGS_BIND_GET); /* Init non-simple options */ gtk_source_view_set_indent_width(GTK_SOURCE_VIEW(sv->priv->view), -1); /* Same as tab width */ gtk_source_view_set_insert_spaces_instead_of_tabs(GTK_SOURCE_VIEW(sv->priv->view), !g_settings_get_boolean (sv->priv->settings, USE_TABS)); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (sv->priv->view), g_settings_get_boolean (sv->priv->docman_settings, DOCMAN_VIEW_EOL) ? GTK_WRAP_WORD : GTK_WRAP_NONE); if (g_settings_get_boolean (sv->priv->docman_settings, DOCMAN_VIEW_WHITE_SPACES)) flags |= (GTK_SOURCE_DRAW_SPACES_SPACE | GTK_SOURCE_DRAW_SPACES_TAB); if (g_settings_get_boolean (sv->priv->docman_settings, DOCMAN_VIEW_EOL)) flags |= GTK_SOURCE_DRAW_SPACES_NEWLINE; gtk_source_view_set_draw_spaces (GTK_SOURCE_VIEW (sv->priv->view), flags); init_fonts(sv); on_notify_autocompletion(sv->priv->settings, AUTOCOMPLETION, sv); /* Register notifications */ REGISTER_NOTIFY (sv->priv->settings, USE_TABS, on_notify_use_tab_for_indentation); REGISTER_NOTIFY (sv->priv->settings, AUTOCOMPLETION, on_notify_autocompletion); REGISTER_NOTIFY (sv->priv->docman_settings, DOCMAN_VIEW_WHITE_SPACES, on_notify_view_spaces); REGISTER_NOTIFY (sv->priv->docman_settings, DOCMAN_VIEW_EOL, on_notify_view_eol); REGISTER_NOTIFY (sv->priv->docman_settings, DOCMAN_VIEW_LINE_WRAP, on_notify_line_wrap); REGISTER_NOTIFY (sv->priv->settings, FONT_THEME, on_notify_font_theme); REGISTER_NOTIFY (sv->priv->settings, FONT, on_notify_font); g_signal_connect (sv->priv->msgman_settings, "changed::" MSGMAN_COLOR_ERROR, G_CALLBACK (on_notify_indic_colors), sv); g_signal_connect (sv->priv->msgman_settings, "changed::" MSGMAN_COLOR_WARNING, G_CALLBACK (on_notify_indic_colors), sv); }
void modeline_parser_apply_modeline (GtkSourceView *view) { ModelineOptions options; GtkTextBuffer *buffer; GtkTextIter iter, liter; gint line_count; options.language_id = NULL; options.set = MODELINE_SET_NONE; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); gtk_text_buffer_get_start_iter (buffer, &iter); line_count = gtk_text_buffer_get_line_count (buffer); /* Parse the modelines on the 10 first lines... */ while ((gtk_text_iter_get_line (&iter) < 10) && !gtk_text_iter_is_end (&iter)) { gchar *line; liter = iter; gtk_text_iter_forward_to_line_end (&iter); line = gtk_text_buffer_get_text (buffer, &liter, &iter, TRUE); parse_modeline (line, 1 + gtk_text_iter_get_line (&iter), line_count, &options); gtk_text_iter_forward_line (&iter); g_free (line); } /* ...and on the 10 last ones (modelines are not allowed in between) */ if (!gtk_text_iter_is_end (&iter)) { gint cur_line; guint remaining_lines; /* we are on the 11th line (count from 0) */ cur_line = gtk_text_iter_get_line (&iter); /* g_assert (10 == cur_line); */ remaining_lines = line_count - cur_line - 1; if (remaining_lines > 10) { gtk_text_buffer_get_end_iter (buffer, &iter); gtk_text_iter_backward_lines (&iter, 9); } } while (!gtk_text_iter_is_end (&iter)) { gchar *line; liter = iter; gtk_text_iter_forward_to_line_end (&iter); line = gtk_text_buffer_get_text (buffer, &liter, &iter, TRUE); parse_modeline (line, 1 + gtk_text_iter_get_line (&iter), line_count, &options); gtk_text_iter_forward_line (&iter); g_free (line); } /* Try to set language */ if (has_option (&options, MODELINE_SET_LANGUAGE) && options.language_id) { GtkSourceLanguageManager *manager; GtkSourceLanguage *language; manager = pluma_get_language_manager (); language = gtk_source_language_manager_get_language (manager, options.language_id); if (language != NULL) { gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (buffer), language); } } ModelineOptions *previous = g_object_get_data (G_OBJECT (buffer), MODELINE_OPTIONS_DATA_KEY); /* Apply the options we got from modelines and restore defaults if we set them before */ if (has_option (&options, MODELINE_SET_INSERT_SPACES)) { gtk_source_view_set_insert_spaces_instead_of_tabs (view, options.insert_spaces); } else if (check_previous (view, previous, MODELINE_SET_INSERT_SPACES)) { gtk_source_view_set_insert_spaces_instead_of_tabs (view, pluma_prefs_manager_get_insert_spaces ()); } if (has_option (&options, MODELINE_SET_TAB_WIDTH)) { gtk_source_view_set_tab_width (view, options.tab_width); } else if (check_previous (view, previous, MODELINE_SET_TAB_WIDTH)) { gtk_source_view_set_tab_width (view, pluma_prefs_manager_get_tabs_size ()); } if (has_option (&options, MODELINE_SET_INDENT_WIDTH)) { gtk_source_view_set_indent_width (view, options.indent_width); } else if (check_previous (view, previous, MODELINE_SET_INDENT_WIDTH)) { gtk_source_view_set_indent_width (view, -1); } if (has_option (&options, MODELINE_SET_WRAP_MODE)) { gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), options.wrap_mode); } else if (check_previous (view, previous, MODELINE_SET_WRAP_MODE)) { gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), pluma_prefs_manager_get_wrap_mode ()); } if (has_option (&options, MODELINE_SET_RIGHT_MARGIN_POSITION)) { gtk_source_view_set_right_margin_position (view, options.right_margin_position); } else if (check_previous (view, previous, MODELINE_SET_RIGHT_MARGIN_POSITION)) { gtk_source_view_set_right_margin_position (view, pluma_prefs_manager_get_right_margin_position ()); } if (has_option (&options, MODELINE_SET_SHOW_RIGHT_MARGIN)) { gtk_source_view_set_show_right_margin (view, options.display_right_margin); } else if (check_previous (view, previous, MODELINE_SET_SHOW_RIGHT_MARGIN)) { gtk_source_view_set_show_right_margin (view, pluma_prefs_manager_get_display_right_margin ()); } if (previous) { *previous = options; previous->language_id = g_strdup (options.language_id); } else { previous = g_slice_new (ModelineOptions); *previous = options; previous->language_id = g_strdup (options.language_id); g_object_set_data_full (G_OBJECT (buffer), MODELINE_OPTIONS_DATA_KEY, previous, (GDestroyNotify)free_modeline_options); } g_free (options.language_id); }