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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:14:11+00:00 2026-06-03T22:14:11+00:00

I am creating a text editor using gtk+-2.0 gtksourceview-2.0. I want to be able

  • 0

I am creating a text editor using gtk+-2.0 gtksourceview-2.0. I want to be able to save the tabs within the notebook for use after I close the editor and reopen it at a later date. I don’t see anything in devhelp under gtk_notebook_* that looks promising. I could save the paths to these files in a database table, then read the table from the db and create the tabs on application startup, but that seems a little clunky. Many editors have this functionality built in. For one geany, but I know there are others.

Is this possible in gtk? I’m relatively new to C, are there other ways to store these paths (other than in a database)? Thanks.

  • 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-03T22:14:13+00:00Added an answer on June 3, 2026 at 10:14 pm

    I initially thought that writing to/from a config file would be slow, I had similiar thoughts about writing to/from a db. While there were a couple of good suggestions provided: sqlite and config file parsers, ultimately I decided that writing/reading a few lines to/from a text file the old fashioned way wouldn’t be that costly.

    I put together a demo program before I incorporate these concepts into my editor, which I have provided below. Feel free to critique this program, especially with regards to memory usage. This program demonstrates the following steps:

    (if I make a list it seems to mess with my code block)

    1) check to see if the config file exists, 2) remove the config file if it does exist, 3) write the paths to the config file, 4) read the paths from the config file

    /*
     * Compile Command:
     * gcc ledit_config.c -o ledit_config 
     * 
     */
    
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>   // system
    
    #define NUM_TABS 10
    
    char paths[NUM_TABS][200];
    
    void write_config();
    void read_config();
    
    int main ()
    {
      write_config();
      read_config();
    }
    
    void write_config()
    {
      char *config_file;
      char temp[200];
      int i=0;
    
      /* change to the user's home directory (for fopen) */
      (int)chdir(getenv("HOME"));
      config_file = ".config/ledit/files";
    
      /* populate paths array with random paths */
      strcpy(paths[0], "~/Documents/code/glade/tutorial1/scratch_files/scratch.py");
      strcpy(paths[4], "~/Documents/code/glade/tutorial1/scratch_files/scratch.c");
      strcpy(paths[7], "~/Documents/code/glade/tutorial1/scratch_files/scratch.glade");
    
      if (fopen(config_file, "r") == NULL) /* file does not exist */
      {
        system("mkdir -p $HOME/.config/ledit/");
        FILE *fp;
        fp=fopen(config_file, "w");
    
        for(i = 0;i < NUM_TABS;++i)
        {
          strcpy(temp,paths[i]);
          strcat(temp, "\n");
          if (strlen(temp) > strlen("\n")) /* check to see if element actually contains more than just "\n" */
          {
            fprintf(fp, "%s",temp);
          }
        }
    
        fclose(fp);
      }
      else /* file does exist */
      {
        system("rm $HOME/.config/ledit/files");
        FILE *fp;
        fp=fopen(config_file, "w");
    
        for(i = 0;i < NUM_TABS;++i)
        {
          strcpy(temp,paths[i]);
          strcat(temp, "\n");
          if (strlen(temp) > strlen("\n")) /* check to see if element actually contains more than just "\n" */
          {
            fprintf(fp, "%s",temp);
          }
        }
    
        fclose(fp);
      }
    
    }
    
    void read_config()
    {
      char line[200];
      char *config_file;
      int i=0;
    
      /* change to the user's home directory (for fopen) */
      (int)chdir(getenv("HOME"));
      config_file = ".config/ledit/files";
    
      /* empty the paths array */
      for(i = 0;i < NUM_TABS;++i)
        strcpy(paths[i], "");
    
      /* read the config file and poplulate array */
      i = 0;
      FILE* fp = fopen(config_file,"r");
      while(fgets(line,sizeof(line),fp) != NULL)
      {
        strcpy(paths[i], line);
        i++;
      }
      fclose(fp);
    
      /* print out paths array for verification */
      for(i = 0;i < NUM_TABS;++i)
        printf("%s",paths[i]);
    
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a text editor in C using gtk+-2.0 gtksourceview-2.0. I am having
I'm creating a text editor and I want users to be able to select
When creating a cross-browser rich text editor. Which would you use and why? Keep
I want to creating a graphical editor which a physician can use to create
I'm creating the MaskedTextBox in WP7.1 In that i want to select all text
We have a Silverlight application using the RichTextBox as a rich text editor for
I'm writing a text editor using C#, I know i'm just reinventing the wheel
I've been looking into creating a Rich Text editor, and at first I was
When creating a Tumblr post, and using the HTML editor option, when I add
I've been working on creating a Spell check dialog for the tinyMCE editor using

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.