Ejemplo n.º 1
1
GString *save_as_temp_file(void)
{
	gchar *write_buffer = NULL;
	gsize text_length;
	gint status;
	gchar *rawfilename;
	GString *filename;
	int file_handle;

	file_handle = g_file_open_tmp("gphpeditXXXXXX",&rawfilename,NULL);
	if (file_handle != -1) {
		filename = g_string_new(rawfilename);
		
		text_length = gtk_scintilla_get_length(GTK_SCINTILLA(main_window.current_editor->scintilla));
		write_buffer = g_malloc0(text_length+1); // Include terminating null

		if (write_buffer == NULL) {
			g_warning ("%s", _("Cannot allocate write buffer"));
			return NULL;
		}
		
		gtk_scintilla_get_text(GTK_SCINTILLA(main_window.current_editor->scintilla), text_length+1, write_buffer);
	
		status = write (file_handle, write_buffer, text_length+1);
		
		g_free (write_buffer);
		g_free(rawfilename);
		close(file_handle);

		return filename;
	}
	
	return NULL;
}
Ejemplo n.º 2
0
void syntax_add_lines(gchar *output)
{
	GtkTreeIter   iter;
	gchar *copy;
	gchar *token;
	gchar *line_number;
	gchar *first_error = NULL;
	gint line_start;
	gint line_end;
	gint indent;

	first_error = 0;
	copy = output;

	while ((token = strtok(copy, "\n"))) {
		if ((strncmp(token, "PHP Warning:  ", MIN(strlen(token), 14))!=0) && (strncmp(token, "Content-type", MIN(strlen(token), 12))!=0)) { 
			gtk_list_store_append (main_window.lint_store, &iter);
			gtk_list_store_set (main_window.lint_store, &iter, 0, token, -1);
	
			line_number = strrchr(token, ' ');
			line_number++;
	
			if (atoi(line_number)>0) {
				if (!first_error) {
					first_error = line_number;
				}
				indent = gtk_scintilla_get_line_indentation(GTK_SCINTILLA(main_window.current_editor->scintilla), atoi(line_number)-1);
	
				line_start = gtk_scintilla_position_from_line(GTK_SCINTILLA(main_window.current_editor->scintilla), atoi(line_number)-1);
				line_start += (indent/preferences.indentation_size);
	
				line_end = gtk_scintilla_get_line_end_position(GTK_SCINTILLA(main_window.current_editor->scintilla), atoi(line_number)-1);
			
				gtk_scintilla_start_styling(GTK_SCINTILLA(main_window.current_editor->scintilla), line_start, 128);
				gtk_scintilla_set_styling(GTK_SCINTILLA(main_window.current_editor->scintilla), line_end-line_start, INDIC2_MASK);
			}
			else {
				g_print("Line number is 0\n");
			}
		}
		copy = NULL;
	}

	if (first_error) {
		goto_line(first_error);
	}
}
Ejemplo n.º 3
0
void syntax_add_lines(gchar *output){
	GtkTreeIter   iter;
	gchar *copy;
	gchar *token;
	int line_number;
	int first_error;
	gint line_start;
	gint line_end;
	gint indent;
	
	line_number=0;
	first_error=0;
	copy=output;

	Editor *editor=main_window_get_current_editor();
	while( (token = strtok(copy, "\n")) ) {
		if( ((strncmp(token, "PHP Warning:  ", MIN(strlen(token), 14))!=0)) && ((strncmp(token, "Content-type", MIN(strlen(token), 12))!=0)) ) { 
			gtk_list_store_append(main_window_get_lint_store(), &iter);
			gtk_list_store_set(main_window_get_lint_store(), &iter, 0, token, -1);
	
			line_number = (atoi( (strrchr(token, ' ')) )) -1;
	
			if(line_number<=0) g_print("Line number is %d\n", line_number);

			if(!first_error) first_error = line_number;

			indent = gtk_scintilla_get_line_indentation(GTK_SCINTILLA(editor->scintilla), line_number);

			line_start = gtk_scintilla_position_from_line(GTK_SCINTILLA(editor->scintilla), line_number);
			line_start += indent / preferences.indentation_size;
	
			line_end = gtk_scintilla_get_line_end_position(GTK_SCINTILLA(editor->scintilla), line_number);
	
			gtk_scintilla_start_styling(GTK_SCINTILLA(editor->scintilla), line_start, 128);
			gtk_scintilla_set_styling(GTK_SCINTILLA(editor->scintilla), line_end-line_start, INDIC2_MASK);
		}
		copy = NULL;
	}

	if(first_error) goto_line_int(first_error);
}//syntax_add_lines
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	GtkWidget *win, *sci;
	GtkBuilder *builder;
	GError *error = NULL;
	gchar *sample_text;

	gtk_init(&argc, &argv);

	builder = gtk_builder_new();
	if (!gtk_builder_add_from_file(builder, DEMO_UI_FILE, &error))
	{
		g_printerr("Error: %s\n", error->message);
		g_error_free(error);
		return 1;
	}

	win = GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
	gtk_window_set_default_size(GTK_WINDOW(win), 640, 480);
	g_signal_connect(win, "destroy", gtk_main_quit, NULL);

	sci = GTK_WIDGET(gtk_builder_get_object(builder, "scintilla1"));

	sample_text = read_text_file(DEMO_SAMPLE_FILE);
	if (sample_text != NULL)
	{
		gtk_scintilla_set_text(GTK_SCINTILLA(sci), sample_text);
		g_free(sample_text);
	}

	gtk_scintilla_set_keywords(GTK_SCINTILLA(sci), 0, "int char return");

	gtk_widget_show_all(win);
	gtk_main();

	return 0;
}
Ejemplo n.º 5
0
static void language_cobol_setup_lexer(Language_Provider *lgcobol)
{
  g_return_if_fail(lgcobol);
  Language_COBOLDetails *lgcoboldet = LANGUAGE_COBOL_GET_PRIVATE(lgcobol);

  gtk_scintilla_clear_document_style (lgcoboldet->sci);
  gtk_scintilla_set_lexer(lgcoboldet->sci, SCLEX_COBOL);
  gtk_scintilla_set_style_bits(lgcoboldet->sci, 7);

  gtk_scintilla_set_keywords(lgcoboldet->sci, 0, "configuration data declaratives division environment environment-division file file-control function i-o i-o-control identification input input-output linkage local-storage output procedure program program-id receive-control section special-names working-storage");
  gtk_scintilla_set_keywords(lgcoboldet->sci, 1, "accept add alter apply assign call chain close compute continue control convert copy count delete display divide draw drop eject else enable end-accept end-add end-call end-chain end-compute end-delete end-display end-divide end-evaluate end-if end-invoke end-multiply end-perform end-read end-receive end-return end-rewrite end-search end-start end-string end-subtract end-unstring end-write erase evaluate examine exec execute exit go goback generate if ignore initialize initiate insert inspect invoke leave merge move multiply open otherwise perform print read receive release reload replace report reread rerun reserve reset return rewind rewrite rollback run search seek select send set sort start stop store string subtract sum suppress terminate then transform unlock unstring update use wait when wrap write");
  gtk_scintilla_set_keywords(lgcoboldet->sci, 2, "a access acquire actual address advancing after all allowing alphabet alphabetic alphabetic-lower alphabetic-upper alphanumeric alphanumeric-edited also alternate and any are area areas as ascending at attribute author auto auto-hyphen-skip auto-skip automatic autoterminate background-color background-colour backward basis beep before beginning bell binary blank blink blinking block bold bottom box boxed by c01 c02 c03 c04 c05 c06 c07 c08 c09 c10 c11 c12 cancel cbl cd centered cf ch chaining changed character characters chart class clock-units cobol code code-set col collating color colour column com-reg comma command-line commit commitment common communication comp comp-0 comp-1 comp-2 comp-3 comp-4 comp-5 comp-6 comp-x compression computational computational-1 computational-2 computational-3 computational-4 computational-5 computational-6 computational-x computational console contains content control-area controls conversion converting core-index corr corresponding crt crt-under csp currency current-date cursor cycle cyl-index cyl-overflow date date-compiled date-written day day-of-week dbcs de debug debug-contents debug-item debug-line debug-name debug-sub-1 debug-sub-2 debug-sub-3 debugging decimal-point default delimited delimiter depending descending destination detail disable disk disp display-1 display-st down duplicates dynamic echo egcs egi emi empty-check encryption end end-of-page ending enter entry eol eop eos equal equals error escape esi every exceeds exception excess-3 exclusive exhibit extend extended-search external externally-described-key factory false fd fh--fcd fh--keydef file-id file-limit file-limits file-prefix filler final first fixed footing for foreground-color foreground-colour footing format from full giving global greater grid group heading high high-value high-values highlight id in index indexed indic indicate indicator indicators inheriting initial installation into invalid invoked is japanese just justified kanji kept key keyboard label last leading left left-justify leftline length length-check less limit limits lin linage linage-counter line line-counter lines lock lock-holding locking low low-value low-values lower lowlight manual mass-update master-index memory message method mode modified modules more-labels multiple name named national national-edited native nchar negative next no no-echo nominal not note nstd-reels null nulls number numeric numeric-edited numeric-fill o-fill object object-computer object-storage occurs of off omitted on oostackptr optional or order organization other others overflow overline packed-decimal padding page page-counter packed-decimal paragraph password pf ph pic picture plus pointer pop-up pos position positioning positive previous print-control print-switch printer printer-1 printing prior private procedure-pointer procedures proceed process processing prompt protected public purge queue quote quotes random range rd readers ready record record-overflow recording records redefines reel reference references relative remainder remarks removal renames reorg-criteria repeated replacing reporting reports required resident return-code returning reverse reverse-video reversed rf rh right right-justify rolling rounded s01 s02 s03 s04 s05 same screen scroll sd secure security segment segment-limit selective self selfclass sentence separate sequence sequential service setshadow shift-in shift-out sign size skip1 skip2 skip3 sort-control sort-core-size sort-file-size sort-merge sort-message sort-mode-size sort-option sort-return source source-computer space spaces space-fill spaces standard standard-1 standard-2 starting status sub-queue-1 sub-queue-2 sub-queue-3 subfile super symbolic sync synchronized sysin sysipt syslst sysout syspch syspunch system-info tab tallying tape terminal terminal-info test text than through thru time time-of-day time-out timeout times title to top totaled totaling trace track-area track-limit tracks trailing trailing-sign transaction true type typedef underline underlined unequal unit until up updaters upon upper upsi-0 upsi-1 upsi-2 upsi-3 upsi-4 upsi-5 upsi-6 upsi-7 usage user using value values variable varying when-compiled window with words write-only write-verify writerszero x zero zero-fill zeros zeroes");

  gchar *font;
  guint size;
  g_object_get(lgcoboldet->prefmg, "style_font_name", &font,"font_size", &size, NULL);

  gchar *style_name;
  g_object_get(lgcoboldet->prefmg, "style_name", &style_name, NULL);

  GtkSourceStyleScheme	*scheme = gtk_source_style_scheme_manager_get_scheme (main_window.stylemg, style_name);
  /* COBOL LEXER STYLE */
  set_scintilla_lexer_default_style(GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_DEFAULT, font, size);
  set_scintilla_lexer_variable_style(GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_WORD, font, size);
  set_scintilla_lexer_variable_style(GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_WORD2, font, size);
  set_scintilla_lexer_string_style(GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_STRING, font, size);
  set_scintilla_lexer_simple_string_style(GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_CHARACTER, font, size);
  set_scintilla_lexer_operator_style(GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_OPERATOR, font, size);
  set_scintilla_lexer_number_style(GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_NUMBER, font, size);
  set_scintilla_lexer_comment_style (GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_COMMENT, font, size);
  set_scintilla_lexer_comment_style (GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_COMMENTLINE, font, size);
  set_scintilla_lexer_doc_comment_style(GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_COMMENTDOC, font, size);
  set_scintilla_lexer_type_style(GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_IDENTIFIER, font, size);
  set_scintilla_lexer_preprocessor_style(GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_PREPROCESSOR, font, size);
  set_scintilla_lexer_xml_element_style(GTK_WIDGET(lgcoboldet->sci), scheme, SCE_C_UUID, font, size);

  g_free(font);
  g_free(style_name);

  gtk_scintilla_set_property(lgcoboldet->sci, "fold.compact", "1");
  gtk_scintilla_set_property(lgcoboldet->sci, "fold", "1");
  gtk_scintilla_colourise(lgcoboldet->sci, 0, -1);

  gtk_scintilla_set_word_chars(GTK_SCINTILLA(lgcoboldet->sci), "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-");  
}
Ejemplo n.º 6
0
static gboolean auto_complete_callback(gpointer data)
{
    Calltip_Data *dat = (Calltip_Data *) data;
    Language_CSSDetails *lgcssdet = LANGUAGE_CSS_GET_PRIVATE(dat->lgcss);
    gint current_pos;
    current_pos = documentable_get_current_position(lgcssdet->doc);
    GtkScintilla *scintilla = lgcssdet->sci;
    if (current_pos == dat->old_pos) {
        gchar *prefix = documentable_get_current_word(lgcssdet->doc);
        gchar *calltip = symbol_manager_get_symbols_matches (lgcssdet->symbolmg, prefix, SYMBOL_FUNCTION | SYMBOL_CLASS | SYMBOL_VAR, TAB_CSS);
        if (calltip && strlen(calltip)!=0) gtk_scintilla_user_list_show(GTK_SCINTILLA(scintilla), 1, calltip);
        g_free(prefix);
        g_free(calltip);
    }
    g_slice_free(Calltip_Data, dat);
    lgcssdet->completion_timer_set=FALSE;
    return FALSE;
}
Ejemplo n.º 7
0
static gboolean calltip_callback(gpointer data)
{
    Calltip_Data *dat = (Calltip_Data *) data;
    Language_CSSDetails *lgcssdet = LANGUAGE_CSS_GET_PRIVATE(dat->lgcss);
    gint current_pos;
    current_pos = documentable_get_current_position(lgcssdet->doc);
    GtkScintilla *scintilla = lgcssdet->sci;
    if (current_pos == dat->old_pos) {
        gchar *prefix = documentable_get_current_word(lgcssdet->doc);
        gchar *calltip = symbol_manager_get_calltip (lgcssdet->symbolmg, prefix, TAB_CSS);
        if (calltip) {
            gtk_scintilla_call_tip_show(GTK_SCINTILLA(scintilla), current_pos, calltip);
            g_free(calltip);
        }
        g_free(prefix);
    }
    g_slice_free(Calltip_Data, dat);
    lgcssdet->calltip_timer_set = FALSE;
    return FALSE;
}
Ejemplo n.º 8
0
void syntax_check_run(void)
{
	GtkTreeIter iter;
	GString *command_line;
	gchar *output;
	gboolean using_temp;
	GString *filename;
	
	/* Tim: this doesn't work if php_binary_location is not an absolute path 

	struct stat *buf = NULL;
	if (stat(preferences.php_binary_location, buf)==-1) {
		g_print("PHP command line binary not found.\n");
	}
	else */
	if (main_window.current_editor) {
		if (main_window.current_editor->saved==TRUE) {
			filename = g_string_new(editor_convert_to_local(main_window.current_editor));
			using_temp = FALSE;
		}
		else {
			filename = save_as_temp_file();
			using_temp = TRUE;
		}

		command_line = g_string_new(preferences.php_binary_location);
		command_line = g_string_append(command_line, " -q -l -d html_errors=Off -f ");
		command_line = g_string_append(command_line, filename->str);

		g_print("eject:%s\n", command_line->str);

		output = run_php_lint(command_line->str);
		g_string_free(command_line, TRUE);

		
		main_window.lint_store = gtk_list_store_new (1, G_TYPE_STRING);

		gtk_scintilla_start_styling(GTK_SCINTILLA(main_window.current_editor->scintilla), 0, INDIC2_MASK);
		gtk_scintilla_set_styling(GTK_SCINTILLA(main_window.current_editor->scintilla),
		                          gtk_scintilla_get_length(GTK_SCINTILLA(main_window.current_editor->scintilla)), 0);

		gtk_list_store_clear(main_window.lint_store);
		if (output) {
			syntax_add_lines(output);
			g_free(output);
		}
		else {
			gtk_list_store_append (main_window.lint_store, &iter);
			gtk_list_store_set (main_window.lint_store, &iter, 0, _("Error calling PHP CLI (is PHP command line binary installed? If so, check if it's in your path or set php_binary in ~/.gnome2/gPHPEdit)\n"), -1);
		}
		gtk_tree_view_set_model(GTK_TREE_VIEW(main_window.lint_view), GTK_TREE_MODEL(main_window.lint_store));
		
		if (using_temp) {
			unlink(filename->str);
		}
		g_string_free(filename, TRUE);
	}
	else {
		main_window.lint_store = gtk_list_store_new (1, G_TYPE_STRING);
		gtk_list_store_clear(main_window.lint_store);
		gtk_list_store_append (main_window.lint_store, &iter);
		gtk_list_store_set (main_window.lint_store, &iter, 0, _("You don't have any files open to check\n"), -1);
		gtk_tree_view_set_model(GTK_TREE_VIEW(main_window.lint_view), GTK_TREE_MODEL(main_window.lint_store));
	}
}
Ejemplo n.º 9
0
void plugin_exec(gint plugin_num)
{
	Plugin *plugin;
	gchar *stdout = NULL;
	GError *error = NULL;
	gint exit_status;
	GString *command_line = NULL;
	gint wordStart;
	gint wordEnd;
	gchar *current_selection;
	gint ac_length;
	gchar *data;
	
	if (main_window.current_editor == NULL) {
		return;
	}
	
	plugin = (Plugin *)g_list_nth_data(Plugins, plugin_num);
	if (!plugin) {
		g_print(_("Plugin is null!\n"));
	}
	//g_print("Plugin No: %d:%d (%s):%s\n", plugin_num, plugin->type, plugin->name, plugin->filename->str);
	command_line = g_string_new(plugin->filename->str);
	command_line = g_string_prepend(command_line, "'");
	command_line = g_string_append(command_line, "' '");
	
	if (plugin->type == GPHPEDIT_PLUGIN_TYPE_SELECTION) {
		wordStart = gtk_scintilla_get_selection_start(GTK_SCINTILLA(main_window.current_editor->scintilla));
		wordEnd = gtk_scintilla_get_selection_end(GTK_SCINTILLA(main_window.current_editor->scintilla));
		current_selection = gtk_scintilla_get_text_range (GTK_SCINTILLA(main_window.current_editor->scintilla), wordStart, wordEnd, &ac_length);
		
		command_line = g_string_append(command_line, current_selection);
	}
	else if (plugin->type == GPHPEDIT_PLUGIN_TYPE_FILENAME) {
		command_line = g_string_append(command_line, editor_convert_to_local(main_window.current_editor));		
	}
	command_line = g_string_append(command_line, "'");
	
	//g_print("SPAWNING: %s\n", command_line->str);
	
	if (g_spawn_command_line_sync(command_line->str,&stdout,NULL, &exit_status,&error)) {
		data = strstr(stdout, "\n");
		data++;
		
		//g_print("COMMAND: %s\nSTDOUT:%s\nOUTPUT: %s\n", command_line->str, stdout, data);
		
		if (g_strncasecmp(stdout, "INSERT", MIN(strlen(stdout), 6))==0) {
			if (data) {
				gtk_scintilla_insert_text(GTK_SCINTILLA(main_window.current_editor->scintilla), 
					gtk_scintilla_get_current_pos(GTK_SCINTILLA(main_window.current_editor->scintilla)), data);
			}
		}
		else if (g_strncasecmp(stdout, "REPLACE", MIN(strlen(stdout), 7))==0) {
			if (data) {
				gtk_scintilla_replace_sel(GTK_SCINTILLA(main_window.current_editor->scintilla), data);
			}
		}
		else if (g_strncasecmp(stdout, "MESSAGE", MIN(strlen(stdout),7))==0) {
				info_dialog(plugin->name, data);
		}
		else if (g_strncasecmp(stdout, "OPEN", MIN(strlen(stdout), 4))==0) {
			if (DEBUG_MODE) { g_print("DEBUG: main_window.c:plugin_exec: Opening file :date: %s\n", data); }
			switch_to_file_or_open(data, 0);
		}
		else if (g_strncasecmp(stdout, "DEBUG", MIN(strlen(stdout), 5))==0) {
			debug_dump_editors();
			DEBUG_MODE = TRUE;
		}
		
		g_free(stdout);

	}
	else {
		g_print(_("Spawning %s gave error %s\n"), plugin->filename->str, error->message);
	}
}
Ejemplo n.º 10
0
void tab_python_set_lexer(Editor *editor)
{
	scintilla_python_set_lexer(GTK_SCINTILLA(editor->scintilla), preferences);
}
Ejemplo n.º 11
0
int syntax_check_run(void) {
	GtkTreeIter iter;
	GString *command_line;
	gchar *stderr;
	gchar *stdout;
	GString *filename;
	GError *error;
	gboolean using_temp;

	stdout=NULL;
	stderr=NULL;

	error=NULL;
	int return_code=0;
	
	Editor *editor=main_window_get_current_editor();
	GtkListStore *lint_store=main_window_get_lint_store();
	if(!editor) {
		// No 'working' files.
		lint_store=gtk_list_store_new(1, G_TYPE_STRING);
		gtk_list_store_clear(lint_store);
		gtk_list_store_append(lint_store, &iter);
		gtk_list_store_set(lint_store, &iter, 0, _("You don't have any files open to check\n"), -1);
		gtk_tree_view_set_model(GTK_TREE_VIEW(main_window_get_lint_view()), GTK_TREE_MODEL(lint_store));
		return E_PHP_SYNTAX_NO_OPEN_FILES;
	}

	if(editor->saved==TRUE) {
		filename = g_string_new(editor_convert_to_local(editor));
		using_temp = FALSE;
	} else {
		filename = save_as_temp_file();
		using_temp = TRUE;
	}

	command_line = g_string_new(preferences.php_binary_location);
	command_line = g_string_append(command_line, " -q -l -d html_errors=Off -f ");
	command_line = g_string_append(command_line, filename->str);

	stdout=run_php_lint(command_line->str, FALSE);
	stderr=run_php_lint(command_line->str, TRUE);
	g_string_free(command_line, TRUE);
	
	
	lint_store = gtk_list_store_new(1, G_TYPE_STRING);
	
	gtk_scintilla_start_styling(GTK_SCINTILLA(editor->scintilla), 0, INDIC2_MASK);
	gtk_scintilla_set_styling(GTK_SCINTILLA(editor->scintilla),
					gtk_scintilla_get_length(GTK_SCINTILLA(editor->scintilla)), 0);
	
	gtk_list_store_clear(lint_store);
	return_code=0;
	if(stdout||stderr) {
		gtk_list_store_append(lint_store, &iter);
		gtk_list_store_set(lint_store, &iter, 0, _(stdout), -1);
		syntax_add_lines(stderr);
		return_code = E_PHP_SYNTAX_ERROR;
	} else {
		gtk_list_store_append(lint_store, &iter);
		gtk_list_store_set(lint_store, &iter, 0, _("Error calling PHP CLI.  Is PHP command line binary installed? If so, check if it's in your path or set php_binary in ~/.gnome2/connectED.\n"), -1);
		return_code = E_PHP_SYNTAX_CLI_NOT_FOUND;
	}
	gtk_tree_view_set_model(GTK_TREE_VIEW(main_window_get_lint_view()), GTK_TREE_MODEL(lint_store));
		
	if(using_temp) unlink(filename->str);
	
	g_free(stdout);
	g_free(stderr);
		
	g_string_free(filename, TRUE);

	return return_code;
}//syntax_check