예제 #1
0
NetlistEditor *
netlist_editor_new (GtkSourceBuffer * textbuffer) {
	NetlistEditor * nle;
	GtkBuilder *gui;
	GError *perror = NULL;
	GtkWidget * toplevel;
	GtkScrolledWindow * scroll;
	GtkSourceView * source_view;
	GtkSourceLanguageManager * lm;
	GtkButton * save, * close;
	GtkSourceLanguage *lang=NULL;

	if (!textbuffer) 
		return NULL;

	if ((gui = gtk_builder_new ()) == NULL) {
		oregano_error (_("Could not create the netlist dialog"));
		return NULL;
	} 
	gtk_builder_set_translation_domain (gui, NULL);
	
	nle = NETLIST_EDITOR (g_object_new (netlist_editor_get_type (), NULL));

	if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/view-netlist.ui", 
	    &perror) <= 0) {
			gchar *msg;
		msg = perror->message;
		oregano_error_with_title (_("Could not create the netlist dialog"), msg);
		g_error_free (perror);
		return NULL;
	}
	
	toplevel = GTK_WIDGET (gtk_builder_get_object (gui, "toplevel"));
	gtk_window_set_default_size (GTK_WINDOW (toplevel), 800, 600);
	gtk_window_set_title (GTK_WINDOW (toplevel), "Net List Editor\n");
	
	scroll = GTK_SCROLLED_WINDOW (gtk_builder_get_object (gui, "netlist-scrolled-window"));
	
	source_view = GTK_SOURCE_VIEW (gtk_source_view_new ());

	lm = GTK_SOURCE_LANGUAGE_MANAGER (gtk_source_language_manager_new ());

	setup_language_manager_path (lm);

	g_object_set_data_full (G_OBJECT (source_view), "language-manager",
		lm, (GDestroyNotify) g_object_unref);

	lang = gtk_source_language_manager_get_language (lm, "netlist");

	if (lang) {
		NG_DEBUG ("\"%s\" from \"%s\"", gtk_source_language_get_name (lang), OREGANO_LANGDIR "/netlist.lang");
		gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (textbuffer), lang);
		gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (textbuffer), TRUE);
		gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (textbuffer), TRUE);
	} 
	else {
		g_warning ("Can't load netlist.lang in %s", OREGANO_LANGDIR "/netlist.lang");
	}

	gtk_text_view_set_editable (GTK_TEXT_VIEW (source_view), TRUE);
	gtk_text_view_set_buffer (GTK_TEXT_VIEW (source_view), GTK_TEXT_BUFFER (textbuffer));	

	gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (source_view));
	
	close = GTK_BUTTON (gtk_builder_get_object (gui, "btn_close"));
	g_signal_connect_swapped (G_OBJECT (close), "clicked", 
		G_CALLBACK (g_object_unref), G_OBJECT (nle));
	save = GTK_BUTTON (gtk_builder_get_object (gui, "btn_save"));
	g_signal_connect (G_OBJECT (save), "clicked", 
		G_CALLBACK (netlist_editor_save), nle);
	
	//  Set tab, fonts, wrap mode, colors, etc. according
	//  to preferences 
	nle->priv->view = GTK_TEXT_VIEW (source_view);
	nle->priv->toplevel = GTK_WINDOW (toplevel);
	nle->priv->save = save;
	nle->priv->close = close;
	nle->priv->buffer = textbuffer;

	gtk_widget_show_all (GTK_WIDGET (toplevel));
	
	return nle;	
}
예제 #2
0
NetlistEditor *
netlist_editor_new (GtkSourceBuffer * textbuffer) {
	gchar** lang_files;
	NetlistEditor * nle;
	GladeXML * gui;
	GtkWidget * toplevel;
	GtkScrolledWindow * scroll;
	GtkSourceView * source_view;
	GtkSourceLanguageManager * lm;
	GtkButton * save, * sim, * close, * print;
	GtkSourceLanguage *lang=NULL;
	const GSList *list;

	if (!textbuffer) 
		return NULL;
	
	nle = NETLIST_EDITOR (g_object_new (netlist_editor_get_type (), NULL));
	
	netlist_editor_get_config (nle);
		
	if (!g_file_test (OREGANO_GLADEDIR "/view-netlist.glade2", G_FILE_TEST_EXISTS)) {
		gchar *msg;
		msg = g_strdup_printf (
			_("The file %s could not be found. You might need to reinstall Oregano to fix this."),
			OREGANO_GLADEDIR "/view-netlist.glade2");
		oregano_error_with_title (_("Could not create the netlist dialog"), msg);
		g_free (msg);
		return NULL;
	}

	gui = glade_xml_new (OREGANO_GLADEDIR "/view-netlist.glade2", NULL, NULL);
	
	toplevel = glade_xml_get_widget (gui, "toplevel");
	gtk_window_set_default_size (GTK_WINDOW (toplevel), 800, 600);
	gtk_window_set_title (GTK_WINDOW (toplevel), "Net List Editor\n");
	
	scroll = GTK_SCROLLED_WINDOW (glade_xml_get_widget (gui, "netlist-scrolled-window"));
	
	source_view = GTK_SOURCE_VIEW (gtk_source_view_new ());
	lm = GTK_SOURCE_LANGUAGE_MANAGER (gtk_source_language_manager_new ());

	setup_language_manager_path (lm);

	g_object_set_data_full (G_OBJECT (source_view), "language-manager",
		lm, (GDestroyNotify) g_object_unref);

	lang = gtk_source_language_manager_get_language (lm, "netlist");

	if (lang) {
		gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (textbuffer), lang);
		gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (textbuffer), TRUE);
		gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (textbuffer), TRUE);
	} else {
		g_warning ("Can't load netlist.lang in %s", OREGANO_LANGDIR "/netlist.lang");
	}

	gtk_text_view_set_editable (GTK_TEXT_VIEW (source_view), TRUE);
	gtk_text_view_set_buffer (GTK_TEXT_VIEW (source_view), GTK_TEXT_BUFFER (textbuffer));	

	gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (source_view));
	
	close = GTK_BUTTON (glade_xml_get_widget (gui, "btn_close"));
	g_signal_connect_swapped (G_OBJECT (close), "clicked", G_CALLBACK (g_object_unref), G_OBJECT (nle));
	save = GTK_BUTTON (glade_xml_get_widget (gui, "btn_save"));
	g_signal_connect (G_OBJECT (save), "clicked", G_CALLBACK (netlist_editor_save), nle);
	sim = GTK_BUTTON (glade_xml_get_widget (gui, "btn_sim"));
	g_signal_connect (G_OBJECT (sim), "clicked", G_CALLBACK (netlist_editor_simulate), nle);
	print = GTK_BUTTON (glade_xml_get_widget (gui, "btn_print"));	
	g_signal_connect (G_OBJECT (print), "clicked", G_CALLBACK (netlist_editor_print), nle);
	/*
	 *  Set tab, fonts, wrap mode, colors, etc. according
	 *  to preferences 
	 */
	
	nle->priv->lm = lm;
	nle->priv->view = GTK_TEXT_VIEW (source_view);
	nle->priv->toplevel = GTK_WINDOW (toplevel);
	nle->priv->sim = sim;
	nle->priv->save = save;
	nle->priv->close = close;
	nle->priv->buffer = textbuffer;

	gtk_widget_show_all (GTK_WIDGET (toplevel));
	
	return nle;	
}