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 571397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:30:10+00:00 2026-05-13T13:30:10+00:00

I’m making a trivial text editor (as an exercise) in GTK using Glade, GtkBuilder,

  • 0

I’m making a trivial text editor (as an exercise) in GTK using Glade, GtkBuilder, and C. I have an edit menu with Cut, Copy, and Paste as well as a GtkTextView for the text. GtkTextView automatically binds the cut/copy/paste sequences for itself (and even provides menu items if you right click). I want to connect the Cut, Copy, and Paste menu items in my menu bar to my text view so they will act as expected.

Note that this is a two-way connection. (1) When one of the Cut, Copy, or Paste GtkMenuItem’s is activated, it tells the GtkTextView to do something. (2) When a selection is made or cleared in the GtkTextView, Cut and Copy are enabled or disabled respectively (see gedit as an example). Moreover, (3) whether or not Paste is enabled depends on the state of the clipboard.

How do I connect my Cut, Copy, and Paste menu items to the text view? Is there a way to do it in Glade, or will my C program need some extra code for this? Is there a streamlined way to do this, or do I need to implement all three behaviors stated in the above paragraph manually?

  • 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-05-13T13:30:10+00:00Added an answer on May 13, 2026 at 1:30 pm

    You will need some extra C code, but not much. For this example I am assuming you’re using GtkActions for your menu items, but if you’re not the solution should be similar.

    First make the callbacks for the cut, copy, and paste actions in Glade. When you connect the signals, pass some data structure containing at least pointers to the cut, copy, and paste actions, and the text view, as user data.

    void
    on_cut(GtkAction *action, SomeStruct *data)
    {
        g_signal_emit_by_name(data->view, "cut-clipboard", NULL);
        gtk_action_set_sensitive(data->paste_action, TRUE);
    }
    
    void
    on_copy(GtkAction *action, SomeStruct *data)
    {
        g_signal_emit_by_name(data->view, "copy-clipboard", NULL);
        gtk_action_set_sensitive(data->paste_action, TRUE);
    }
    
    void
    on_paste(GtkAction *action, SomeStruct *data)
    {
        g_signal_emit_by_name(data->view, "paste-clipboard", NULL);
    }
    

    Next, connect to the notify::has-selection signal of your GtkTextBuffer:

    void
    on_has_selection_notify(GtkTextBuffer *buffer, GParamSpec *pspec, SomeStruct *data)
    {
        gboolean has_selection = gtk_text_buffer_get_has_selection(buffer);
        gtk_action_set_sensitive(data->cut_action, has_selection);
        gtk_action_set_sensitive(data->copy_action, has_selection);
    }
    

    To determine the initial state of the paste action (in case there is text on the clipboard when you start the application) run the following code while you’re constructing your interface:

    gtk_action_set_sensitive(data->paste_action, 
        gtk_clipboard_wait_is_text_available(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)));
    

    This assumes there’s no way for the user to clear the clipboard manually (most programs don’t let you do that.)

    Caveat lector: the code as typed here is all untested.

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

Sidebar

Related Questions

No related questions found

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.