Пример #1
0
void document_loader_done_loading_cb (DocumentLoader *doclod, gboolean result, Document *doc, gpointer user_data)
{
  DocumentManager *docmg = DOCUMENT_MANAGER(user_data);
  DocumentManagerDetails *docmgdet = DOCUMENT_MANAGER_GET_PRIVATE(docmg);
  if (result) {
    gboolean untitled;
    docmgdet->editors = g_slist_append(docmgdet->editors, doc);
    GtkWidget *document_tab;
    document_tab = get_close_tab_widget(doc);
    GtkWidget *document_widget;
    g_object_get(doc, "untitled", &untitled, "editor_widget", &document_widget, NULL);
    gtk_widget_show(document_widget);
    gtk_notebook_append_page (GTK_NOTEBOOK (main_window.notebook_editor), document_widget, document_tab);
    gtk_notebook_set_current_page (GTK_NOTEBOOK (main_window.notebook_editor), -1);
    _document_manager_set_current_document(docmg, doc);
    g_signal_connect(G_OBJECT(doc), "save_update", G_CALLBACK(document_save_update_cb), docmg);
    g_signal_connect(G_OBJECT(doc), "zoom_update", G_CALLBACK(document_zoom_update_cb), docmg);
    if (OBJECT_IS_DOCUMENT_SCINTILLA(doc)) {
      g_signal_connect(G_OBJECT(doc), "save_start", G_CALLBACK(document_save_start_cb), NULL);
      g_signal_connect(G_OBJECT(doc), "type_changed", G_CALLBACK(document_type_changed_cb), docmg);
      g_signal_connect(G_OBJECT(doc), "pos_changed", G_CALLBACK(document_pos_changed_cb), docmg);
      g_signal_connect(G_OBJECT(doc), "need_reload", G_CALLBACK(document_need_reload_cb), docmg);
      g_signal_connect(G_OBJECT(doc), "ovr_changed", G_CALLBACK(document_ovr_changed_cb), NULL);
      g_signal_connect(G_OBJECT(doc), "marker_not_found", G_CALLBACK(document_marker_not_found_cb), NULL);
      g_signal_connect(G_OBJECT(doc), "open_request", G_CALLBACK(document_open_request_cb), docmg);
    }
    g_signal_emit (G_OBJECT (docmg), signals[NEW_DOCUMENT], 0, doc);
    gtk_widget_grab_focus(document_widget);
    if (!untitled) document_manager_session_save(docmg);
  }
  g_object_unref(doclod);
}
Пример #2
0
/* 
* syntax_window:
* this función accept debug info, show it in syntax pane and apply style to text.
* lines has form line number space message dot like next example:
* 59 invalid operator.\n
* lines end with \n 
* if data hasn't got that format it'll be shown be error will not be styled.
*/
void syntax_window(GtkSyntaxCheckWindow *win, Documentable *document, gchar *data)
{
  GtkSyntaxCheckWindowPrivate *priv = GTK_SYNTAX_CHECK_WINDOW_GET_PRIVATE(win);
  if (!document && !OBJECT_IS_DOCUMENT_SCINTILLA(document)) return;
  if (!data) return;
  gchar *copy;
  gchar *token;
  gchar *line_number=NULL;
  gchar *first_error = NULL;
  /* clear document before start any styling action */
  document_scintilla_clear_sintax_style(DOCUMENT_SCINTILLA(document));
  gtk_widget_show(GTK_WIDGET(win));
  GtkTreeIter iter;
  if (!priv->lint_store) priv->lint_store = gtk_list_store_new (1, G_TYPE_STRING); /* create a new one */
  /*clear tree */
  gtk_list_store_clear(priv->lint_store);
  copy = data;

  document_scintilla_set_sintax_annotation(DOCUMENT_SCINTILLA(document));
  /* lines has form line number space message dot like 
  * 59 invalid operator.\n
  * lines end with \n
  */

  while ((token = strtok(copy, "\n"))) {
    gtk_list_store_append (priv->lint_store, &iter);
    gtk_list_store_set (priv->lint_store, &iter, 0, token, -1);
    gchar *anotationtext=g_strdup(token);
    if (g_ascii_isdigit(*token)){
    line_number = strchr(token, ' ');
      line_number= strncpy(line_number,token,(int)(line_number-token));
    if (atoi(line_number)>0) {
      if (!first_error) {
      first_error = line_number;
      }
      guint current_line_number=atoi(line_number)-1;
      document_scintilla_set_sintax_line(DOCUMENT_SCINTILLA(document), current_line_number);
      token=anotationtext + (int)(line_number-token+1);
      /* if first char is an E then set error style, else if first char is W set warning style */
      if (strncmp(token,"E",1)==0){
        token+=1;
        document_scintilla_add_sintax_annotation(DOCUMENT_SCINTILLA(document) , current_line_number, token, STYLE_ANNOTATION_ERROR);
      } else if (strncmp(token,"W",1)==0){
        token+=1;
        document_scintilla_add_sintax_annotation(DOCUMENT_SCINTILLA(document) , current_line_number, token, STYLE_ANNOTATION_WARNING);
      }
    }
    }
    g_free(anotationtext);
    copy = NULL;
  }
  gtk_tree_view_set_model(GTK_TREE_VIEW(priv->lint_view), GTK_TREE_MODEL(priv->lint_store));
}