Пример #1
0
/*! \brief Handles changes in the treeview selection.
 *  \par Function Description
 *  This is the callback function that is called every time the user
 *  select a row the library treeview of the dialog.
 *
 *  If the selection is not a selection of a footprint, it does
 *  nothing. Otherwise it updates the preview and Element data.
 *
 *  \param [in] selection The current selection in the treeview.
 *  \param [in] user_data The library dialog.
 */
static void
library_window_callback_tree_selection_changed (GtkTreeSelection * selection,
						gpointer user_data)
{
  GtkTreeView *view;
  GtkTreeModel *model;
  GtkTreeIter iter;
  GhidLibraryWindow *library_window = (GhidLibraryWindow *) user_data;
  LibraryEntryType *entry = NULL;
  gchar *m4_args;

  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
    return;

  view = gtk_tree_selection_get_tree_view (selection);
  gtk_tree_model_get (model, &iter, MENU_ENTRY_COLUMN, &entry, -1);

  if (entry == NULL)
    return;

  /* -1 flags this is an element file part and the file path is in
     |  entry->AllocateMemory.
   */
  if (entry->Template == (char *) -1)
    {
      if (LoadElementToBuffer (PASTEBUFFER, entry->AllocatedMemory, true))
	SetMode (PASTEBUFFER_MODE);
      goto out;
    }

  /* Otherwise, it's a m4 element and we need to create a string of
     |  macro arguments to be passed to the library command in
     |  LoadElementToBuffer()
   */
  m4_args = g_strdup_printf ("'%s' '%s' '%s'", EMPTY (entry->Template),
			     EMPTY (entry->Value), EMPTY (entry->Package));

  if (LoadElementToBuffer (PASTEBUFFER, m4_args, false))
    SetMode (PASTEBUFFER_MODE);
  g_free (m4_args);

out:

  /* update the preview with new symbol data */
  g_object_set (library_window->preview,
		"element-data", PASTEBUFFER->Data->Element, NULL);
}
Пример #2
0
static void
libnode_select (Widget w, void *v, XmListCallbackStruct * cbs)
{
  char *args;
  LibraryEntryType *e =
    Library.Menu[last_pick].Entry + cbs->item_position - 1;

  if (e->Template == (char *) -1)
    {
      if (LoadElementToBuffer (PASTEBUFFER, e->AllocatedMemory, true))
	SetMode (PASTEBUFFER_MODE);
      return;
    }
  args = Concat("'", EMPTY (e->Template), "' '",
		EMPTY (e->Value), "' '", EMPTY (e->Package), "'", NULL);
  if (LoadElementToBuffer (PASTEBUFFER, args, false))
    SetMode (PASTEBUFFER_MODE);
}
Пример #3
0
static int
CommandLoadElementToBuffer (int argc, char **argv, int x, int y)
{
  char *filename;

  switch (argc)
    {
    case 1:			/* filename is passed in commandline */
      filename = argv[0];
      if (filename && LoadElementToBuffer (PASTEBUFFER, filename, true))
	SetMode (PASTEBUFFER_MODE);
      break;

    default:			/* usage */
      Message (false, "Usage: le [name]\n  loads element data to buffer\n");
      return (1);
    }
  return (0);
}
Пример #4
0
/* Returns zero on success, non-zero on error.  */
int
LoadFootprintByName (BufferType *Buffer, char *Footprint)
{
  int i;
  FootprintHashEntry *fpe;
  LibraryMenuType *menu;
  LibraryEntryType *entry;
  char *with_fp = NULL;

  if (!footprint_hash)
    make_footprint_hash ();

  fpe = search_footprint_hash (Footprint);
  if (!fpe)
    {
      with_fp = Concat (Footprint, ".fp", NULL);
      fpe = search_footprint_hash (with_fp);
      if (fpe)
	Footprint = with_fp;
    }
  if (!fpe)
    {
      Message(_("Unable to load footprint %s\n"), Footprint);
      return 1;
    }

  menu = & Library.Menu[fpe->menu_idx];
  entry = & menu->Entry[fpe->entry_idx];

  if (entry->Template == (char *) -1)
    {
      i = LoadElementToBuffer (Buffer, entry->AllocatedMemory, true);
      if (with_fp)
	free (with_fp);
      return i ? 0 : 1;
    }
  else
    {
      char *args;

      args = Concat("'", EMPTY (entry->Template), "' '",
		    EMPTY (entry->Value), "' '", EMPTY (entry->Package), "'", NULL);
      i = LoadElementToBuffer (Buffer, args, false);

      free (args);
      if (with_fp)
	free (with_fp);
      return i ? 0 : 1;
    }

#ifdef DEBUG
  {
    int j;
    printf("Library path: %s\n", Settings.LibraryPath);
    printf("Library tree: %s\n", Settings.LibraryTree);

    printf("Library:\n");
    for (i=0; i<Library.MenuN; i++)
      {
	printf("  [%02d] Name: %s\n", i, Library.Menu[i].Name);
	printf("       Dir:  %s\n", Library.Menu[i].directory);
	printf("       Sty:  %s\n", Library.Menu[i].Style);
	for (j=0; j<Library.Menu[i].EntryN; j++)
	  {
	    printf("       [%02d] E: %s\n", j, Library.Menu[i].Entry[j].ListEntry);
	    if (Library.Menu[i].Entry[j].Template == (char *) -1)
	      printf("            A: %s\n", Library.Menu[i].Entry[j].AllocatedMemory);
	    else
	      {
		printf("            T: %s\n", Library.Menu[i].Entry[j].Template);
		printf("            P: %s\n", Library.Menu[i].Entry[j].Package);
		printf("            V: %s\n", Library.Menu[i].Entry[j].Value);
		printf("            D: %s\n", Library.Menu[i].Entry[j].Description);
	      }
	    if (j == 10)
	      break;
	  }
      }
  }
#endif
}