Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7899177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:37:55+00:00 2026-06-03T08:37:55+00:00

I’m trying to write my own text editor in C using gtk+-2.0 & gtksourceview-2.0.

  • 0

I’m trying to write my own text editor in C using gtk+-2.0 & gtksourceview-2.0. I’ve been using the gedit source when I get stuck, but they apparently don’t use this functionality and I can’t find an example of its use online. When I open a text file and place its contents into the text buffer this is registered as an undoable action. I would like this process to be not undoable, so I have placed:

gtk_source_undo_manager_begin_not_undoable_action(um);

at the beginning of my open_activated function (provided below), and:

gtk_source_undo_manager_end_not_undoable_action(um);

at the end of this same function. According to the help provided in devHelp it says that everything in between these two lines should not be undoable, but it is. What am I missing? Is there a better way to accomplish this same functionality?

GtkSourceUndoManager *um; (defined globally)

void open_activated(GtkWidget *widget, GtkWindow *parent)
{
  GtkSourceLanguage *lang;
  GtkSourceLanguageManager *lm;
  GtkWidget *dialog;
  int pages = 0;
  GtkWidget *tablabel;

  gtk_source_undo_manager_begin_not_undoable_action(um);

  /* create new tab */
  tablabel = gtk_label_new("New File");
  pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook));
  gtk_container_add(GTK_CONTAINER(scrollwin[pages]),txtinput[pages]);
  gtk_widget_show_all (scrollwin[pages]);
  gtk_notebook_append_page(GTK_NOTEBOOK(notebook),scrollwin[pages],tablabel);
  //gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (txtinput[pages]), TRUE);
  gtk_notebook_set_current_page (GTK_NOTEBOOK(notebook), pages);

  //gtk_text_buffer_set_modified (gtk_text_view_get_buffer((GTK_TEXT_VIEW(txtinput[pages]))), TRUE);

  dialog = gtk_file_chooser_dialog_new("Open File", parent, GTK_FILE_CHOOSER_ACTION_OPEN,GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,GTK_STOCK_OPEN,GTK_RESPONSE_ACCEPT,NULL);
  GtkTextBuffer *buffer;
  //buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txtinput[gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook))]));
  buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txtinput[pages]));


  if(gtk_dialog_run(GTK_DIALOG(dialog))== GTK_RESPONSE_ACCEPT)
  {
    char *path,*string;
    const gchar *filename;
    char temp[40];
    gsize length = -1;
    path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
    paths[pages] = path;
    filename = filenameFromPath(path);
    //printf("%s\n",out);
    strcpy(temp,filename);
    tablabel = gtk_label_new(temp);
    g_file_get_contents(path,&string,&length,NULL);     
    gtk_text_buffer_set_text(buffer,string,-1);

    /* syntax highlighting */
    lm = gtk_source_language_manager_new();
    lang = gtk_source_language_manager_guess_language (lm, path, NULL);
    gtk_source_buffer_set_language (GTK_SOURCE_BUFFER(buffer), lang);

    /* change tab label */
    gtk_notebook_set_tab_label (GTK_NOTEBOOK(notebook), scrollwin[pages], tablabel);

    /* set some sourceview options */
    gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (txtinput[pages]), TRUE);
    gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (txtinput[pages]), 2);

    /* Set the editor's font. */
    PangoFontDescription *font_desc = pango_font_description_new();
    pango_font_description_set_family (font_desc, "monospace");
    gtk_widget_modify_font (txtinput[pages], font_desc);

    g_free(path);
    g_free(string);

  }

  gtk_widget_destroy(dialog);
  gtk_text_buffer_set_modified (gtk_text_view_get_buffer((GTK_TEXT_VIEW(txtinput[pages]))), FALSE);
  changeLabelColor("black");

  gtk_source_undo_manager_end_not_undoable_action(um);

}

Unfortunately there isn’t any gtk_source_undo_manager_new () or gtk_source_undo_manager_get_default () like there is for the language manager. The documentation for the GtkSourceUndoManager is:

Description

The GtkSourceUndoManager interface can be implemented to provide custom undo management to a GtkSourceBuffer. Use gtk_source_buffer_set_undo_manager to install a custom undo manager for a particular source buffer.

Use gtk_source_undo_manager_can_undo_changed and gtk_source_undo_manager_can_redo_changed when respectively the undo state or redo state of the undo stack has changed.

Details

GtkSourceUndoManager

typedef struct _GtkSourceUndoManager GtkSourceUndoManager;

GtkSourceUndoManagerIface

typedef struct {
GTypeInterface parent;

/* Interface functions */
gboolean (*can_undo)                  (GtkSourceUndoManager *manager);
gboolean (*can_redo)                  (GtkSourceUndoManager *manager);

void     (*undo)                      (GtkSourceUndoManager *manager);
void     (*redo)                      (GtkSourceUndoManager *manager);

void     (*begin_not_undoable_action) (GtkSourceUndoManager *manager);
void     (*end_not_undoable_action)   (GtkSourceUndoManager *manager);

/* Signals */
void     (*can_undo_changed)          (GtkSourceUndoManager *manager);
void     (*can_redo_changed)          (GtkSourceUndoManager *manager);
} GtkSourceUndoManagerIface;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:37:57+00:00Added an answer on June 3, 2026 at 8:37 am

    If you’re not implementing a custom undo manager, then just use gtk_source_buffer_begin_not_undoable_action() instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.