PIPS
directory_menu.c File Reference
#include <sys/param.h>
#include <sys/stat.h>
#include "genC.h"
#include "misc.h"
#include "database.h"
#include "linear.h"
#include "ri.h"
#include "ri-util.h"
#include "pipsdbm.h"
#include <gtk/gtk.h>
#include "gpips.h"
+ Include dependency graph for directory_menu.c:

Go to the source code of this file.

Macros

#define MAXNAMELEN   MAXNAMLEN
 lint More...
 

Enumerations

enum  { MENU_PATH_DATA_HANDLER = 54829 , GPIPS_MAX_DIRECTORY_MENU_SIZE = 80 }
 

Functions

static GtkWidget * directory_gen_pullright (GtkWidget *widget)
 
static void generate_a_directory_menu_notify (GtkWidget *widget, gpointer data)
 
GtkWidget * generate_a_directory_menu (char *directory)
 

Variables

char vcid_directory_menu [] = "$Id: directory_menu.c 23065 2016-03-02 09:05:50Z coelho $"
 Generate a menu from the current directory to serve as a directory chooser. More...
 

Macro Definition Documentation

◆ MAXNAMELEN

#define MAXNAMELEN   MAXNAMLEN

lint

To have SunOS 5.5 happy about MAXNAMELEN (in SunOS 4, it is already defined in sys/dirent.h): To have SunOS4 still working:

Definition at line 45 of file directory_menu.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MENU_PATH_DATA_HANDLER 
GPIPS_MAX_DIRECTORY_MENU_SIZE 

Maximum size of the directory menu of the main frame:

Definition at line 61 of file directory_menu.c.

61  {
62  MENU_PATH_DATA_HANDLER = 54829,
63  /* Maximum size of the directory menu of the main frame: */
65 };
@ GPIPS_MAX_DIRECTORY_MENU_SIZE
Maximum size of the directory menu of the main frame:
@ MENU_PATH_DATA_HANDLER

Function Documentation

◆ directory_gen_pullright()

static GtkWidget* directory_gen_pullright ( GtkWidget *  widget)
static

First get the parent directory name that is the title:

Build the new directory name:

Well, there is already a menu... we've been already here. Free it first:

Free the associated directory name:

Then initialize it with a new directory menu:

Definition at line 74 of file directory_menu.c.

74  {
75  GtkWidget * parent_menu;
76 
77  parent_menu = gtk_widget_get_parent(widget);
78 
79  char directory[MAXNAMELEN + 1];
80  const char * parent_directory;
81 
82  debug(2, "directory_gen_pullright", "widget = %#x (%s), parent = %#x\n",
83  widget, gpips_gtk_menu_item_get_label(GTK_WIDGET(GTK_MENU_ITEM(widget))), parent_menu);
84 
85  /* First get the parent directory name that is the title: */
86  parent_directory = gtk_menu_get_title(GTK_MENU(parent_menu));
87  debug(2, "directory_gen_pullright", " parent_directory = %s\n",
88  parent_directory);
89 
90  /* Build the new directory name: */
91  (void) sprintf(directory, "%s/%s", parent_directory, gpips_gtk_menu_item_get_label(GTK_WIDGET(GTK_MENU_ITEM(widget))));
92 
93  if (gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)) != NULL) {
94  /* Well, there is already a menu... we've been already here.
95  Free it first: */
96  /* Free the associated directory name: */
97  GtkWidget * submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget));
98  gtk_menu_item_set_submenu(GTK_MENU_ITEM(widget), NULL);
99  gtk_widget_destroy(submenu);
100  }
101 
102  /* Then initialize it with a new directory menu: */
103 
104  return generate_a_directory_menu(directory);
105 }
GtkWidget * generate_a_directory_menu(char *directory)
#define MAXNAMELEN
lint
const char * gpips_gtk_menu_item_get_label(GtkWidget *w)
Definition: gtk_utils.c:43
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189

References debug(), generate_a_directory_menu(), gpips_gtk_menu_item_get_label(), and MAXNAMELEN.

Referenced by generate_a_directory_menu().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generate_a_directory_menu()

GtkWidget* generate_a_directory_menu ( char *  directory)

Get all the files in the directory:

Generate a corresponding entry for each file:

Skip the "." directory:

Since a menu item cannot be selected as an item, add an plain item with the same name. Not beautiful hack... :-(

And disable non-subdirectory entry:

Definition at line 124 of file directory_menu.c.

124  {
125  gen_array_t file_list;
126  int file_list_length;
127  int return_code;
128  int i;
129 
130  GtkWidget * menu;
131 
132  menu = gtk_menu_new();
133  gtk_menu_set_title(GTK_MENU(menu), directory);
134 
135 // menu = (Menu) xv_create((int) NULL, MENU,
136 // /* The string is *not* copied in MENU_TITLE_ITEM: */
137 // MENU_TITLE_ITEM, strdup(directory),
138 // /* and furthermore MENU_TITLE_ITEM is write
139 // only, so add the info somewhere else: */
140 // XV_KEY_DATA, MENU_PATH_DATA_HANDLER, strdup(directory),
141 // /* Add its own notifying procedure: */
142 // MENU_NOTIFY_PROC, generate_a_directory_menu_notify, NULL);
143 
144  pips_debug(2, "menu = %p (%s)\n", (void *) menu, directory);
145 
147  GtkWidget * please_close = gtk_menu_item_new_with_label(
148  "* Close the current workspace before changing directory *");
149  gtk_widget_set_sensitive(please_close, FALSE);
150  gtk_menu_append(GTK_MENU(menu), please_close);
151  pips_user_warning("Close the current workspace before changing "
152  "directory.\n");
153  } else {
154  GtkWidget * file_item;
155  /* Get all the files in the directory: */
156  file_list = gen_array_make(0);
157  return_code = safe_list_files_in_directory(file_list, directory, ".*",
159  file_list_length = gen_array_nitems(file_list);
160 
161  if (return_code == -1 || file_list_length == 0) {
162  file_item = gtk_menu_item_new_with_label(
163  "* No file in this directory or cannot be open *");
164  gtk_widget_set_sensitive(file_item, FALSE);
165  gtk_menu_append(GTK_MENU(menu), file_item);
166  } else if (file_list_length > GPIPS_MAX_DIRECTORY_MENU_SIZE) {
167  file_item
168  = gtk_menu_item_new_with_label(
169  "* Too many files. Type directly in the Directory line of the main panel *");
170  gtk_widget_set_sensitive(file_item, FALSE);
171  gtk_menu_append(GTK_MENU(menu), file_item);
172  user_warning("generate_a_directory_menu",
173  "Too many files in the \"%s\" directory.\n", directory);
174  } else
175  /* Generate a corresponding entry for each file: */
176  for (i = 0; i < file_list_length; i++) {
177  string file_name = gen_array_item(file_list, i);
178  /* Skip the "." directory: */
179  if (strcmp(file_name, ".") != 0) {
180  struct stat buf;
181  char complete_file_name[MAXNAMELEN + 1];
182 
183  file_item = gtk_menu_item_new_with_label(file_name);
184  gtk_menu_append(GTK_MENU(menu), file_item);
185 
186  (void) sprintf(complete_file_name, "%s/%s", directory,
187  file_name);
188  if (((stat(complete_file_name, &buf) == 0) && (buf.st_mode
189  & S_IFDIR))) {
190  /* Since a menu item cannot be selected as an item, add an
191  plain item with the same name. Not beautiful
192  hack... :-( */
193  gtk_menu_item_set_submenu(GTK_MENU_ITEM(file_item),
194  directory_gen_pullright(file_item));
195  g_signal_connect(G_OBJECT(file_item), "activate",
196  G_CALLBACK(generate_a_directory_menu_notify), NULL);
197  pips_debug(2, " file_item = %p (%s)\n",
198  (void *) file_item, file_name);
199  } else {
200  gtk_widget_set_sensitive(file_item, FALSE);
201  }
202  /* And disable non-subdirectory entry: */
203  }
204  }
205  gen_array_full_free(file_list);
206  }
207  gtk_widget_show_all(menu);
208  return menu;
209 }
size_t gen_array_nitems(const gen_array_t a)
Definition: array.c:131
void gen_array_full_free(gen_array_t a)
Definition: array.c:77
gen_array_t gen_array_make(size_t size)
declarations...
Definition: array.c:40
void * gen_array_item(const gen_array_t a, size_t i)
Definition: array.c:143
bool directory_exists_p(const char *name)
Definition: file.c:314
int safe_list_files_in_directory(gen_array_t files, string dir, string re, bool(*file_name_predicate)(const char *))
returns a sorted arg list of files matching regular expression re in directory 'dir' and with file_na...
Definition: file.c:250
static void generate_a_directory_menu_notify(GtkWidget *widget, gpointer data)
static GtkWidget * directory_gen_pullright(GtkWidget *widget)
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_user_warning
Definition: misc-local.h:146
#define user_warning(fn,...)
Definition: misc-local.h:262
string db_get_current_workspace_name(void)
the function is used to check that there is some current workspace...
Definition: workspace.c:82
static char buf[BSZ]
Definition: split_file.c:157
static string file_name

References buf, db_get_current_workspace_name(), directory_exists_p(), directory_gen_pullright(), file_name, gen_array_full_free(), gen_array_item(), gen_array_make(), gen_array_nitems(), generate_a_directory_menu_notify(), GPIPS_MAX_DIRECTORY_MENU_SIZE, MAXNAMELEN, pips_debug, pips_user_warning, safe_list_files_in_directory(), and user_warning.

Referenced by directory_gen_pullright(), and generate_directory_menu().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generate_a_directory_menu_notify()

static void generate_a_directory_menu_notify ( GtkWidget *  widget,
gpointer  data 
)
static

Definition at line 107 of file directory_menu.c.

107  {
108  GtkWidget * parent;
109  const char * parent_path_name;
110  const char * directory_name;
111  char full_directory_name[MAXNAMELEN + 1];
112  directory_name = gpips_gtk_menu_item_get_label(widget);
113  parent = gtk_widget_get_parent(widget);
114  if(parent == NULL || ! GTK_IS_MENU(parent))
115  parent_path_name = "";
116  else
117  parent_path_name = gtk_menu_get_title(GTK_MENU(parent));
118 
119  (void) sprintf(full_directory_name, "%s/%s", parent_path_name,
120  directory_name);
121  (void) end_directory_notify(full_directory_name);
122 }
success end_directory_notify(const char *dir)
Definition: gtk_select.c:103

References end_directory_notify(), gpips_gtk_menu_item_get_label(), and MAXNAMELEN.

Referenced by generate_a_directory_menu().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ vcid_directory_menu

char vcid_directory_menu[] = "$Id: directory_menu.c 23065 2016-03-02 09:05:50Z coelho $"

Generate a menu from the current directory to serve as a directory chooser.

Definition at line 31 of file directory_menu.c.