示例#1
0
文件: module.c 项目: chan18/ljedit
static void pls_lang_active(GtkAction* action, GtkSourceLanguage* lang) {
	gint page_num;
	GtkTextBuffer* buf;

	page_num = gtk_notebook_get_current_page(puss_get_doc_panel(g_self->app));
	if( page_num < 0 )
		return;

	buf = g_self->app->doc_get_buffer_from_page_num(page_num);

#if GTK_MAJOR_VERSION==2
	if( !buf || !GTK_IS_SOURCE_BUFFER(buf) )
		return;
#else
	if( !buf || !GTK_SOURCE_IS_BUFFER(buf) )
		return;
#endif

	if( lang ) {
		gtk_source_buffer_set_language(GTK_SOURCE_BUFFER(buf), lang);
		add_fill_favory_language(lang);

	} else {
		gtk_source_buffer_set_language(GTK_SOURCE_BUFFER(buf), g_self->last_favory_lang);
	}
}
示例#2
0
static void
set_language (GeditDocument     *doc,
              GtkSourceLanguage *lang,
              gboolean           set_by_user)
{
	GeditDocumentPrivate *priv;
	GtkSourceLanguage *old_lang;

	gedit_debug (DEBUG_DOCUMENT);

	priv = gedit_document_get_instance_private (doc);

	old_lang = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (doc));

	if (old_lang == lang)
	{
		return;
	}

	gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (doc), lang);

	if (set_by_user)
	{
		const gchar *language = get_language_string (doc);

		gedit_document_set_metadata (doc,
					     GEDIT_METADATA_ATTRIBUTE_LANGUAGE, language,
					     NULL);
	}

	priv->language_set_by_user = set_by_user;
}
static void
gb_view_source_lang_activate (GbViewSource *source,
                              GtkMenuItem  *menu_item)
{
    GbViewSourcePrivate *priv;
    GtkSourceLanguageManager *lm;
    GtkSourceLanguage *lang;
    const gchar *lang_id;

    ENTRY;

    g_return_if_fail(GB_IS_VIEW_SOURCE(source));
    g_return_if_fail(GTK_IS_MENU_ITEM(menu_item));

    priv = source->priv;

    if ((lang_id = g_object_get_data(G_OBJECT(menu_item), "language-id"))) {
        lm = gtk_source_language_manager_get_default();
        lang = gtk_source_language_manager_get_language(lm, lang_id);
        gtk_source_buffer_set_language(priv->buffer, lang);
        gb_menu_button_set_label(GB_MENU_BUTTON(priv->lang_combo),
                                 gtk_source_language_get_name(lang));
    }

    EXIT;
}
示例#4
0
void set_language(){
	if(cfg_lang()){
			GtkSourceLanguageManager *lm;
			lm=gtk_source_language_manager_new();
			char* currentfile=(char*)tpad_fp_get_current();
			if(currentfile!=NULL){
				long unsigned int i= 0,pos= 0;
				size_t mlewn = sizeof(currentfile)/sizeof(currentfile[1]);
				size_t blew = strlen(currentfile) + 1;

				if(blew > mlewn) mlewn = blew;

				 char fil[mlewn];

    			for(i=0; currentfile[i]; i++){
        			if(currentfile[i]=='\\') fil[pos++]='\\';
        			fil[pos++]=currentfile[i];
    				}
    			fil[pos]=0;
				gboolean result_uncertain;
				gchar *content_type;
				content_type = g_content_type_guess (fil, NULL, 0, &result_uncertain);
				if (result_uncertain){
					g_free (content_type);
					content_type = NULL;
					}
				GtkSourceLanguage *lang = NULL;
				lang = gtk_source_language_manager_guess_language (lm, fil, content_type);
				gtk_source_buffer_set_language (GTK_SOURCE_BUFFER(mBuff),GTK_SOURCE_LANGUAGE(lang));
				gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER(mBuff), (gboolean) cfg_lang());
				if(cfg_lang()) (lang) ? gtk_source_buffer_set_highlight_syntax(GTK_SOURCE_BUFFER(mBuff),TRUE) : gtk_source_buffer_set_highlight_syntax(GTK_SOURCE_BUFFER(mBuff),FALSE);	
				if(content_type) g_free (content_type);
		}
	}
	else {
		gtk_source_buffer_set_language(GTK_SOURCE_BUFFER(mBuff),NULL);
		gtk_source_buffer_set_highlight_syntax(GTK_SOURCE_BUFFER(mBuff),FALSE); 
	     }
	if(cfg_undo() >= 1 && cfg_undo() <= UNDO_MAX) gtk_source_buffer_set_max_undo_levels ((GtkSourceBuffer *)mBuff,(gint)cfg_undo());
	else {
		gtk_source_buffer_set_max_undo_levels ((GtkSourceBuffer *)mBuff,(gint)-1);
		cfg_set_undo(0);
	}
		(cfg_line_wrap()) ? gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view),GTK_WRAP_WORD) : gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view),GTK_WRAP_NONE);
}
示例#5
0
void
gui_editor_show (GUIEditor * self)
{
  gtk_widget_show (GTK_WIDGET (self->widget));
  gtk_widget_show (GTK_WIDGET (self->scroll));
  gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW(self->widget), TRUE);
  self->language = gtk_source_language_manager_get_language(self->lang_manager,"8085_asm");
  if (self->language != NULL){
	gtk_source_buffer_set_language (self->buffer, self->language);
	gtk_source_buffer_set_style_scheme (self->buffer, gtk_source_style_scheme_manager_get_scheme(self->style_scheme_manager,"classic"));
	gtk_source_buffer_set_highlight_syntax (self->buffer, TRUE);
  }
  self->mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER(self->buffer));
  gtk_source_view_set_show_line_marks (GTK_SOURCE_VIEW(self->widget), TRUE);
}
示例#6
0
/**
 * peacock_file_construct:
 * @file: 
 * 
 * Sort of a post constructor, constructor.
 **/
static void
peacock_file_construct (PeacockFile *file)
{
	GtkSourceLanguagesManager *lang_manager;
	GtkSourceLanguage *lang;

	/*
	 * Get the highlighting style for HTML and apply it to
	 * the GtkSourceBuffer.
	 */
	lang_manager = gtk_source_languages_manager_new ();
	lang = gtk_source_languages_manager_get_language_from_mime_type (
		lang_manager, "text/html");

	gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (file), lang);
	gtk_source_buffer_set_highlight (GTK_SOURCE_BUFFER (file), TRUE);
}
示例#7
0
static void
set_language (GeditDocument     *doc,
              GtkSourceLanguage *lang,
              gboolean           set_by_user)
{
	GtkSourceLanguage *old_lang;

	gedit_debug (DEBUG_DOCUMENT);

	old_lang = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (doc));

	if (old_lang == lang)
	{
		return;
	}

	gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (doc), lang);

	if (lang != NULL)
	{
		gboolean syntax_hl;

		syntax_hl = g_settings_get_boolean (doc->priv->editor_settings,
						    GEDIT_SETTINGS_SYNTAX_HIGHLIGHTING);

		gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc),
							syntax_hl);
	}
	else
	{
		gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (doc),
							FALSE);
	}

	if (set_by_user)
	{
		const gchar *language = get_language_string (doc);

		gedit_document_set_metadata (doc,
					     GEDIT_METADATA_ATTRIBUTE_LANGUAGE, language,
					     NULL);
	}

	doc->priv->language_set_by_user = set_by_user;
}
示例#8
0
文件: editor.c 项目: ueno/c-smie
static void
load_ready (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
  GtkSourceFileLoader *loader = GTK_SOURCE_FILE_LOADER (source_object);
  EditorApplicationWindow *window = EDITOR_APPLICATION_WINDOW (user_data);
  GtkTextIter iter;
  GFile *location;
  GtkSourceLanguageManager *manager;
  GtkSourceLanguage *language;
  gchar *filename;
  GError *error = NULL;

  if (!gtk_source_file_loader_load_finish (loader, res, &error))
    {
      g_warning ("Error while loading the file: %s", error->message);
      g_error_free (error);
      g_clear_object (&window->file);
      goto out;
    }

  gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (window->buffer), &iter);
  gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (window->buffer), &iter);

  location = gtk_source_file_loader_get_location (loader);
  filename = g_file_get_path (location);
  manager = gtk_source_language_manager_get_default ();
  language = gtk_source_language_manager_guess_language (manager,
							 filename,
							 NULL);
  g_free (filename);
  if (language)
    gtk_source_buffer_set_language (window->buffer, language);

  if (grammar_filename)
    set_indenter (window, grammar_filename);

 out:
  g_object_unref (loader);
  gtk_window_present (GTK_WINDOW (window));
}
示例#9
0
文件: Debugger.c 项目: wrapl/wrapl
static module_t *add_module(const char *Name) {
//	printf("Adding module: %s\n", Name);
	gdk_threads_enter();
	module_t *Module = new(module_t);
	Module->Name = Name;
	Module->Source = gtk_source_buffer_new(SourceTags);
	gtk_source_buffer_set_language(Module->Source, SourceLanguage);
	gtk_source_buffer_set_style_scheme(Module->Source, StyleScheme);
	gtk_text_view_set_buffer(SourceView, Module->Source);
	GtkTreeIter Iter;
	gtk_list_store_append(Modules, &Iter);
	gtk_list_store_set(Modules, &Iter, 0, Name, 1, Module, -1);
	Module->ModulePath = gtk_tree_model_get_path(Modules, &Iter);
	DisplayedModule = Module;
	gtk_tree_store_append(Globals, &Iter, 0);
	gtk_tree_store_set(Globals, &Iter, 0, Module->Name, 1, 0, 2, 0, 3, 0, 5, -1, -1);
	Module->GlobalsPath = gtk_tree_model_get_path(Globals, &Iter);
	//Module->Breakpoints = Riva$Memory$alloc_atomic(1);
	//Module->Breakpoints[0] = BreakOnNewModule;
	//Module->MaxBreakpoint = 1;
	gdk_threads_leave();
	return Module;
};
示例#10
0
static void
gb_editor_tab_guess_language (GbEditorTab *tab)
{
   GtkSourceLanguageManager *manager;
   GbEditorTabPrivate *priv;
   GtkSourceLanguage *lang;
   gboolean result_uncertain;
   gchar *content_type;
   gchar *filename;

   g_return_if_fail (GB_IS_EDITOR_TAB (tab));

   priv = tab->priv;

   if (!priv->file) {
      return;
   }

   manager = gtk_source_language_manager_get_default ();

   filename = g_file_get_path (priv->file);

   content_type = g_content_type_guess (filename, NULL, 0, &result_uncertain);

   if (result_uncertain) {
      g_free (content_type);
      content_type = NULL;
   }

   lang = gtk_source_language_manager_guess_language (manager, filename, content_type);
   gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (priv->document), lang);

   gb_editor_tab_reload_snippets (tab, lang);

   g_free (content_type);
   g_free (filename);
}
static void
ide_editor_view_actions_language (GSimpleAction *action,
                                  GVariant      *variant,
                                  gpointer       user_data)
{
  IdeEditorView *self = user_data;
  GtkSourceLanguageManager *manager;
  GtkSourceLanguage *language;
  GtkSourceBuffer *buffer;
  const gchar *name;

  g_assert (IDE_IS_EDITOR_VIEW (self));

  manager = gtk_source_language_manager_get_default ();
  name = g_variant_get_string (variant, NULL);
  buffer = GTK_SOURCE_BUFFER (self->document);

  if (name != NULL)
    {
      language = gtk_source_language_manager_get_language (manager, name);
      gtk_source_buffer_set_language (buffer, language);
      ide_editor_view_actions_update (self);
    }
}
示例#12
0
static void mape_edit_view_set_filename(MapeEditView* view,
                                        const gchar* filename)
{
	MapeMapgenType new_type;
	GtkSourceBuffer* buf;

	gchar* basename;
	gchar* utf8_file;
	gchar* utf8_file_casefold;
	gchar* utf8_landscape_txt_casefold;

	const gchar* lang_name;
	const gchar* lang_filename;
	GtkSourceLanguage* lang;
	GtkSourceStyleScheme* style;
	GtkWidget* error_dialog;

	buf = GTK_SOURCE_BUFFER(
		gtk_text_view_get_buffer(GTK_TEXT_VIEW(view->view) )
	);

	if (view->file_path != filename)
	{
		if(filename != NULL)
		{
			view->file_path = g_strdup(filename);
		}
		else
		{
			view->file_path = NULL;
		}
	}

	if(filename != NULL)
	{
		basename = g_path_get_basename(filename);

		/* Determine document type */
		utf8_file = g_filename_to_utf8(
			basename,
			-1,
			NULL,
			NULL,
			NULL
		);

		g_free(basename);

		if(utf8_file != NULL)
		{
			utf8_file_casefold = g_utf8_casefold(utf8_file, -1);
			utf8_landscape_txt_casefold = g_utf8_casefold("landscape.txt", -1);
			g_free(utf8_file);

			if(g_utf8_collate(utf8_file_casefold, utf8_landscape_txt_casefold) == 0)
				new_type = MAPE_MAPGEN_LANDSCAPE_TXT;
			else
				new_type = MAPE_MAPGEN_MAP_C;
			g_free(utf8_file_casefold);
			g_free(utf8_landscape_txt_casefold);
		}
	}
	else
	{
		new_type = MAPE_MAPGEN_MAP_C;
	}

	if(new_type != view->type)
	{
		view->type = new_type;
		switch(view->type)
		{
		case MAPE_MAPGEN_LANDSCAPE_TXT:
			lang_name = "c4landscape";
			lang_filename = "Landscape.txt";
			break;
		case MAPE_MAPGEN_MAP_C:
			lang_name = "c4mapscript";
			lang_filename = "Map.c";
			break;
		default:
			lang_name = NULL;
			g_assert_not_reached();
			break;
		}

		/* Set language according to document type */
		lang = gtk_source_language_manager_get_language(
			view->lang_manager,
			lang_name
		);

		style = gtk_source_style_scheme_manager_get_scheme(
			view->style_manager,
			"mape"
		);

		if(lang == NULL || style == NULL)
		{
			/* TODO: Show location where we search in */
			error_dialog = gtk_message_dialog_new(
				NULL,
				GTK_DIALOG_MODAL,
				GTK_MESSAGE_ERROR,
				GTK_BUTTONS_OK,
				"Syntax Highlighting Not Available"
			);

			gtk_message_dialog_format_secondary_text(
				GTK_MESSAGE_DIALOG(error_dialog),
				"The syntax highlighting file for %s files "
				"could not be located. Perhaps mape has not "
				"been properly installed. Syntax "
				"highlighting is disabled.",
				lang_filename
			);

			gtk_window_set_title(GTK_WINDOW(error_dialog), "Mape");

			gtk_dialog_run(GTK_DIALOG(error_dialog) );
			gtk_widget_destroy(error_dialog);
		}
		else
		{
			gtk_source_buffer_set_language(buf, lang);
			gtk_source_buffer_set_style_scheme(buf, style);
		}
	}
}
示例#13
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;	
}
示例#14
0
AtlantisDocument* atlantis_document_construct (GType object_type, const char* path) {
#line 73 "document.c"
	GError * _inner_error_;
	AtlantisDocument * self;
	char* _tmp0_;
	char* _tmp1_;
	GtkSourceLanguageManager* slm;
	GtkSourceLanguage* lang;
	GtkSourceLanguageManager* _tmp2_;
	GtkSourceLanguage* _tmp3_;
#line 11 "document.vala"
	g_return_val_if_fail (path != NULL, NULL);
#line 84 "document.c"
	_inner_error_ = NULL;
	self = g_object_newv (object_type, 0, NULL);
#line 13 "document.vala"
	self->priv->fileName = (_tmp0_ = atlantis_document_uri_to_filename (self, path), _g_free0 (self->priv->fileName), _tmp0_);
#line 14 "document.vala"
	self->priv->baseName = (_tmp1_ = g_path_get_basename (self->priv->fileName), _g_free0 (self->priv->baseName), _tmp1_);
#line 91 "document.c"
	slm = NULL;
	lang = NULL;
#line 18 "document.vala"
	slm = (_tmp2_ = gtk_source_language_manager_new (), _g_object_unref0 (slm), _tmp2_);
#line 19 "document.vala"
	lang = (_tmp3_ = _g_object_ref0 (gtk_source_language_manager_get_language (slm, "vala")), _g_object_unref0 (lang), _tmp3_);
#line 21 "document.vala"
	if (lang != NULL) {
#line 100 "document.c"
		char* content;
		char* _tmp6_;
		gboolean _tmp5_;
		char* _tmp4_ = NULL;
		content = NULL;
#line 24 "document.vala"
		_tmp5_ = g_file_get_contents (self->priv->fileName, &_tmp4_, NULL, &_inner_error_);
#line 24 "document.vala"
		content = (_tmp6_ = _tmp4_, _g_free0 (content), _tmp6_);
#line 24 "document.vala"
		_tmp5_;
#line 112 "document.c"
		if (_inner_error_ != NULL) {
			_g_free0 (content);
			_g_object_unref0 (slm);
			_g_object_unref0 (lang);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
#line 25 "document.vala"
		g_object_set ((GtkTextBuffer*) self, "text", content, NULL);
#line 26 "document.vala"
		gtk_source_buffer_set_language ((GtkSourceBuffer*) self, lang);
#line 27 "document.vala"
		gtk_source_buffer_set_highlight_syntax ((GtkSourceBuffer*) self, TRUE);
#line 127 "document.c"
		_g_free0 (content);
	}
	_g_object_unref0 (slm);
	_g_object_unref0 (lang);
	return self;
}
示例#15
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;	
}
示例#16
0
void
modeline_parser_apply_modeline (GtkSourceView *view)
{
	ModelineOptions options;
	GtkTextBuffer *buffer;
	GtkTextIter iter, liter;
	gint line_count;
	
	options.language_id = NULL;
	options.set = MODELINE_SET_NONE;

	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
	gtk_text_buffer_get_start_iter (buffer, &iter);

	line_count = gtk_text_buffer_get_line_count (buffer);

	/* Parse the modelines on the 10 first lines... */
	while ((gtk_text_iter_get_line (&iter) < 10) &&
	       !gtk_text_iter_is_end (&iter))
	{
		gchar *line;

		liter = iter;
		gtk_text_iter_forward_to_line_end (&iter);
		line = gtk_text_buffer_get_text (buffer, &liter, &iter, TRUE);

		parse_modeline (line,
				1 + gtk_text_iter_get_line (&iter),
				line_count,
				&options);

		gtk_text_iter_forward_line (&iter);

		g_free (line);
	}

	/* ...and on the 10 last ones (modelines are not allowed in between) */
	if (!gtk_text_iter_is_end (&iter))
	{
		gint cur_line;
		guint remaining_lines;

		/* we are on the 11th line (count from 0) */
		cur_line = gtk_text_iter_get_line (&iter);
		/* g_assert (10 == cur_line); */

		remaining_lines = line_count - cur_line - 1;

		if (remaining_lines > 10)
		{
			gtk_text_buffer_get_end_iter (buffer, &iter);
			gtk_text_iter_backward_lines (&iter, 9);
		}
	}

	while (!gtk_text_iter_is_end (&iter))
	{
		gchar *line;

		liter = iter;
		gtk_text_iter_forward_to_line_end (&iter);
		line = gtk_text_buffer_get_text (buffer, &liter, &iter, TRUE);

		parse_modeline (line,
				1 + gtk_text_iter_get_line (&iter),
				line_count,
				&options);

		gtk_text_iter_forward_line (&iter);

		g_free (line);
	}

	/* Try to set language */
	if (has_option (&options, MODELINE_SET_LANGUAGE) && options.language_id)
	{
		GtkSourceLanguageManager *manager;
		GtkSourceLanguage *language;

		manager = pluma_get_language_manager ();
		language = gtk_source_language_manager_get_language
				(manager, options.language_id);

		if (language != NULL)
		{
			gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (buffer),
							language);
		}
	}

	ModelineOptions *previous = g_object_get_data (G_OBJECT (buffer), 
	                                               MODELINE_OPTIONS_DATA_KEY);

	/* Apply the options we got from modelines and restore defaults if
	   we set them before */
	if (has_option (&options, MODELINE_SET_INSERT_SPACES))
	{
		gtk_source_view_set_insert_spaces_instead_of_tabs
							(view, options.insert_spaces);
	}
	else if (check_previous (view, previous, MODELINE_SET_INSERT_SPACES))
	{
		gtk_source_view_set_insert_spaces_instead_of_tabs
							(view,
							 pluma_prefs_manager_get_insert_spaces ());
	}
	
	if (has_option (&options, MODELINE_SET_TAB_WIDTH))
	{
		gtk_source_view_set_tab_width (view, options.tab_width);
	}
	else if (check_previous (view, previous, MODELINE_SET_TAB_WIDTH))
	{
		gtk_source_view_set_tab_width (view, 
		                               pluma_prefs_manager_get_tabs_size ());
	}
	
	if (has_option (&options, MODELINE_SET_INDENT_WIDTH))
	{
		gtk_source_view_set_indent_width (view, options.indent_width);
	}
	else if (check_previous (view, previous, MODELINE_SET_INDENT_WIDTH))
	{
		gtk_source_view_set_indent_width (view, -1);
	}
	
	if (has_option (&options, MODELINE_SET_WRAP_MODE))
	{
		gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), options.wrap_mode);
	}
	else if (check_previous (view, previous, MODELINE_SET_WRAP_MODE))
	{
		gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), 
		                             pluma_prefs_manager_get_wrap_mode ());
	}
	
	if (has_option (&options, MODELINE_SET_RIGHT_MARGIN_POSITION))
	{
		gtk_source_view_set_right_margin_position (view, options.right_margin_position);
	}
	else if (check_previous (view, previous, MODELINE_SET_RIGHT_MARGIN_POSITION))
	{
		gtk_source_view_set_right_margin_position (view, 
		                                           pluma_prefs_manager_get_right_margin_position ());
	}
	
	if (has_option (&options, MODELINE_SET_SHOW_RIGHT_MARGIN))
	{
		gtk_source_view_set_show_right_margin (view, options.display_right_margin);
	}
	else if (check_previous (view, previous, MODELINE_SET_SHOW_RIGHT_MARGIN))
	{
		gtk_source_view_set_show_right_margin (view, 
		                                       pluma_prefs_manager_get_display_right_margin ());
	}
	
	if (previous)
	{
		*previous = options;
		previous->language_id = g_strdup (options.language_id);
	}
	else
	{
		previous = g_slice_new (ModelineOptions);
		*previous = options;
		previous->language_id = g_strdup (options.language_id);
		
		g_object_set_data_full (G_OBJECT (buffer), 
		                        MODELINE_OPTIONS_DATA_KEY, 
		                        previous,
		                        (GDestroyNotify)free_modeline_options);
	}
	
	g_free (options.language_id);
}
void save_as_file(GtkButton *button) {
  /** Save the current editor content as the choosen file. **/

  #ifdef DEBUG
    DEBUG_FUNC_MARK
  #endif





  GtkWidget *file_chooser = gtk_file_chooser_dialog_new( _("Save as file"),
                                                        GTK_WINDOW(gui->main_window),
                                                        GTK_FILE_CHOOSER_ACTION_SAVE,
                                                        _("Cancel"),  GTK_RESPONSE_CANCEL,
                                                        _("Save as"), GTK_RESPONSE_ACCEPT,
                                                        NULL) ;


  /** Retrieve the stored filepath: **/
  gpointer stored_filepath = g_object_get_data(G_OBJECT(current_editor.current_buffer), "filepath") ;

  /** Storing last opened file folder. **/
  if (open_file_dirname != NULL) {
    g_free(open_file_dirname) ;
  }
  open_file_dirname = g_strdup(g_path_get_dirname(stored_filepath)) ;

  gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_chooser), open_file_dirname );

  gint res;

  GtkFileChooser *chooser;
  chooser = GTK_FILE_CHOOSER(file_chooser);


  gtk_file_chooser_set_do_overwrite_confirmation(chooser, TRUE);

  res = gtk_dialog_run(GTK_DIALOG(file_chooser)) ;

  if (res == GTK_RESPONSE_ACCEPT) {

    char *filepath ;
    filepath = gtk_file_chooser_get_filename(chooser);

    /** Getting current editor content **/
    GtkTextIter iter_start, iter_end  ;
    GError *error = NULL              ;

    gtk_text_buffer_get_start_iter(current_editor.current_buffer, &iter_start);
    gtk_text_buffer_get_end_iter(current_editor.current_buffer,   &iter_end);

    gchar *file_content = gtk_text_buffer_get_text(current_editor.current_buffer, &iter_start, &iter_end, FALSE) ;


    if (! g_file_set_contents(filepath, file_content, -1, &error) ) {
      /** Failed to save editor content as file, display an error message and return. **/

      char *msg = g_strdup_printf(_("Failed to save file:\n%s"), filepath) ;

      display_message_dialog(_("Cannot save file !!!"), msg, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE) ;

      free(msg) ;

      return ;

    }

    /** Mark the TextBuffer as not modfied. **/
    gtk_text_buffer_set_modified(current_editor.current_buffer, FALSE) ;

    /** Only useful if the content type has changed like a new file saved as a *.c file. **/
    GtkSourceLanguage        *source_language         = NULL ;
    GtkSourceLanguageManager *source_language_manager = gtk_source_language_manager_get_default();

    gboolean result_uncertain ;
    gchar *content_type ;

    content_type = g_content_type_guess( g_path_get_basename(filepath), (const guchar *) file_content, strlen(file_content), &result_uncertain) ;

    if (content_type && source_language_manager) {

      source_language = gtk_source_language_manager_guess_language(source_language_manager, g_path_get_basename(filepath), content_type);

      if (source_language) {

        set_syntax_highlight_radio(gtk_source_language_get_id(source_language)) ;

        gtk_source_buffer_set_language(GTK_SOURCE_BUFFER(current_editor.current_buffer), source_language) ;

        g_object_set_data(G_OBJECT(current_editor.current_textview), "lang_id", (char *) gtk_source_language_get_id(source_language)) ;
      }

      g_free(content_type) ;
    }



    /** Update the notebook label tab **/
    GtkWidget *notebook_tab = gtk_notebook_get_tab_label(GTK_NOTEBOOK(gui->editor_notebook), current_editor.current_notebook_page);

    /** The tab contains an mimetype icon, the filename and the page closing button. **/
    GList *tab_compound_list = gtk_container_get_children(GTK_CONTAINER(notebook_tab)) ;

    tab_compound_list = g_list_first(tab_compound_list) ;

    while (tab_compound_list->data != NULL) {
        /** We iterate over the notebook tab component **/
        if  (g_object_get_data(G_OBJECT(tab_compound_list->data), "tab_filename_widget")) {
          /** Set the new filename in the tab. **/
          gtk_label_set_text(GTK_LABEL(tab_compound_list->data), g_path_get_basename(filepath)) ;
        }

        if  (g_object_get_data(G_OBJECT(tab_compound_list->data), "tab_icon") && source_language) {


          uint8_t c ;
          for ( c=0 ; ; c++) {
    
              if (gtk_source_language_get_mime_types(source_language) == NULL) {
     
                break ;
              }
    
              char *mimetype = gtk_source_language_get_mime_types(source_language)[c] ;

              if (mimetype == NULL) {
                  /** don't find an specific mimetype for this new file extension use default icon. **/
                  g_object_set(G_OBJECT(tab_compound_list->data),"file", PATH_TO_MIMETYPE_ICON "unknown.png", NULL) ;
                  break ;
              }

              /** We search for an image filename ending with the corresponding mimetype: **/
              char *ptr = strchr(mimetype, '/') ;

              if (ptr != NULL) {

                /** Simply pointer arithmetic to exchange the '/' (used in mimetypes) and the '-' (used in the images names) character **/
                mimetype[ptr - mimetype] = '-' ;


                gchar *filepath = g_strdup_printf("%s%s.png", PATH_TO_MIMETYPE_ICON, mimetype) ;

                if ( g_file_test(filepath, G_FILE_TEST_EXISTS) ) {
                  /** We found an corresponding image for this mimetype. **/
                  g_object_set(G_OBJECT(tab_compound_list->data),"file", filepath, NULL) ;
                  free(filepath) ;
                  break ;
                }

                free(filepath) ;

              }

          }
        }

        if (tab_compound_list->next == NULL) {
          break ;
        }

        tab_compound_list = tab_compound_list->next ;
    }

    g_free(file_content)   ;

    /** Storing filepath for further saving operations. **/
    g_object_set_data(G_OBJECT(current_editor.current_buffer), "filepath", filepath) ;

    /** setting the base filename in the bottom bar. **/
    gtk_label_set_text(GTK_LABEL(gui->bottom_bar->filename_label), g_path_get_basename(filepath)) ;


    if (settings.rm_trailing_spaces) {
      /** Deleting trailing spaces. **/
      char *trailing_spaces_deleting ;
      trailing_spaces_deleting = g_strdup_printf("sed -i 's/[[:space:]]$//' '%s'", (char *) filepath) ;
      int ret ;
      if ((ret = system(trailing_spaces_deleting)) == -1) {
        g_warning( _("Removing trailing space failure:\n%s\n"), trailing_spaces_deleting) ;
      }

      free(trailing_spaces_deleting) ;
    }
   
    File_Editor *file_editor = (File_Editor *) g_object_get_data(G_OBJECT(current_editor.current_textview), "file_editor") ;
   
    gtk_notebook_set_menu_label_text(GTK_NOTEBOOK(gui->editor_notebook), file_editor->scrolled_window, g_path_get_basename(filepath) ) ;
   
    #ifdef RELOADING_FUNC
    /** Update Last modification timestamp. **/
    File_Editor *file_editor = (File_Editor *) g_object_get_data(G_OBJECT(current_editor.current_textview), "file_editor") ;
    g_stat(filepath, &file_editor->file_info) ;
    #endif
   
   

  }

  /** @NOTE: the filepath must not be free because it is set as data from the file_editor->buffer for further use. **/

  gtk_widget_destroy(file_chooser);
}
static void
gb_view_source_set_file_attribs (GbViewSource *source,
                                 GFile        *file)
{
    GtkSourceLanguageManager *lm;
    GbViewSourcePrivate *priv;
    GtkSourceLanguage *lang;
    const gchar *icon_name;
    GFileInfo *info;
    gchar *path;

    ENTRY;

    g_return_if_fail(GB_IS_VIEW_SOURCE(source));
    g_return_if_fail(G_IS_FILE(file));

    priv = source->priv;

    if (!(path = g_file_get_path(file))) {
        path = g_file_get_uri(file);
    }

    if ((icon_name = gb_path_get_icon_name(path))) {
        gb_view_set_icon_name(GB_VIEW(source), icon_name);
    }

    info = g_file_query_info(file, "standard::*", 0, NULL, NULL);

    /*
     * Get the relative path to the file from the project.
     */
    {
        const gchar *directory;
        GtkWidget *window;
        GbProject *project;

        gb_view_set_name(GB_VIEW(source), path);

        window = gtk_widget_get_toplevel(GTK_WIDGET(source));
        if (GB_IS_WINDOW(window)) {
            project = gb_window_get_project(GB_WINDOW(window));
            directory = gb_project_get_directory(project);
            if (g_str_has_prefix(path, directory)) {
                gb_view_set_name(GB_VIEW(source), path + strlen(directory));
            }
        }
    }

    lm = gtk_source_language_manager_get_default();
    lang = gtk_source_language_manager_guess_language(
               lm, path, g_file_info_get_content_type(info));
    if (lang) {
        gb_menu_button_set_label(GB_MENU_BUTTON(priv->lang_combo),
                                 gtk_source_language_get_name(lang));
    } else {
        gb_menu_button_set_label(GB_MENU_BUTTON(priv->lang_combo), "");
    }
    gtk_source_buffer_set_language(priv->buffer, lang);

    g_object_unref(info);
    g_free(path);

    EXIT;
}