示例#1
0
static void language_css_trigger_completion (Language_Provider *lgcss, guint ch)
{
    g_return_if_fail(lgcss);
    Language_CSSDetails *lgcssdet = LANGUAGE_CSS_GET_PRIVATE(lgcss);
    gint current_pos;
    gchar *member_function_buffer = NULL;

    current_pos = gtk_scintilla_get_current_pos(lgcssdet->sci);
    gboolean auto_brace;
    g_object_get(lgcssdet->prefmg, "auto_complete_braces", &auto_brace, NULL);

    if (IsOpenBrace(ch) && auto_brace) {
        InsertCloseBrace (lgcssdet->sci, current_pos, ch);
        return;
    }

    switch(ch) {
    case ('\r'):
    case ('\n'):
        autoindent_brace_code (lgcssdet->sci, lgcssdet->prefmg);
        break;
    case (';'):
        cancel_calltip (lgcssdet->sci);
        break;
    case (':'):
        show_calltip (lgcss);
        break;
    default:
        member_function_buffer = documentable_get_current_word(lgcssdet->doc);
        if (member_function_buffer && strlen(member_function_buffer)>=3) show_autocompletion (LANGUAGE_CSS(lgcss), current_pos);
        g_free(member_function_buffer);
    }
}
示例#2
0
static void autoindent_brace_code (GtkScintilla *sci, PreferencesManager *pref)
{
  gint current_pos;
  gint current_line;
  gint previous_line;
  gint previous_line_indentation;
  gint previous_line_end;

  current_pos = gtk_scintilla_get_current_pos(sci);
  current_line = gtk_scintilla_line_from_position(sci, current_pos);

  gphpedit_debug (DEBUG_DOCUMENT);

  if (current_line>0) {
    gtk_scintilla_begin_undo_action(sci);
    previous_line = current_line-1;
    previous_line_indentation = gtk_scintilla_get_line_indentation(sci, previous_line);

    previous_line_end = gtk_scintilla_get_line_end_position(sci, previous_line);
    indent_line(sci, current_line, previous_line_indentation);
    gphpedit_debug_message (DEBUG_DOCUMENT, "previous_line=%d, previous_indent=%d\n", previous_line, previous_line_indentation);
    gint pos;
    gboolean tabs_instead_spaces;
    g_object_get(pref,"tabs_instead_spaces", &tabs_instead_spaces, NULL);
    if(tabs_instead_spaces){
      pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation/gtk_scintilla_get_tab_width(sci));
    } else {
      pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation);
    }
    gtk_scintilla_goto_pos(sci, pos);
    gtk_scintilla_end_undo_action(sci);
  }
}
示例#3
0
static void autoindent_brace_code (GtkScintilla *sci, PreferencesManager *pref)
{
    gint current_pos;
    gint current_line;
    gint previous_line;
    gint previous_line_indentation;
    gint previous_line_start;
    gint previous_line_end;
    gchar *previous_char_buffer;
    gint previous_char_buffer_length;
    gchar *previous_line_buffer;
    gint previous_line_buffer_length;

    current_pos = gtk_scintilla_get_current_pos(sci);
    current_line = gtk_scintilla_line_from_position(sci, current_pos);

    gphpedit_debug (DEBUG_DOCUMENT);

    if (current_line>0) {
        gtk_scintilla_begin_undo_action(sci);
        previous_line = current_line-1;
        previous_line_indentation = gtk_scintilla_get_line_indentation(sci, previous_line);

        previous_line_end = gtk_scintilla_get_line_end_position(sci, previous_line);
        previous_char_buffer = gtk_scintilla_get_text_range (sci, previous_line_end-1, previous_line_end, &previous_char_buffer_length);
        if (is_css_char_autoindent(*previous_char_buffer)) {
            gint indentation_size;
            g_object_get(pref, "indentation_size", &indentation_size, NULL);
            previous_line_indentation+=indentation_size;
        } else if (is_css_char_autounindent(*previous_char_buffer)) {
            gint indentation_size;
            g_object_get(pref, "indentation_size", &indentation_size, NULL);
            previous_line_indentation-=indentation_size;
            if (previous_line_indentation < 0) previous_line_indentation = 0;
            previous_line_start = gtk_scintilla_position_from_line(sci, previous_line);
            previous_line_buffer = gtk_scintilla_get_text_range (sci, previous_line_start, previous_line_end, &previous_line_buffer_length);
            gboolean unindent = TRUE;
            gint char_act = 0;
            while (char_act <= previous_line_buffer_length)
            {
                char c = previous_line_buffer[char_act];
                if (!(g_ascii_iscntrl(c) || g_ascii_isspace(c) || is_css_char_autounindent(c))) {
                    unindent = FALSE;
                    break;
                }
                char_act++;
            }
            if (unindent) gtk_scintilla_set_line_indentation(sci, previous_line, previous_line_indentation);
            g_free(previous_line_buffer);
        }
        g_free(previous_char_buffer);
        indent_line(sci, current_line, previous_line_indentation);
        gphpedit_debug_message (DEBUG_DOCUMENT, "previous_line=%d, previous_indent=%d\n", previous_line, previous_line_indentation);
        gint pos;
        gboolean tabs_instead_spaces;
        g_object_get(pref,"tabs_instead_spaces", &tabs_instead_spaces, NULL);
        if(tabs_instead_spaces) {
            pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation/gtk_scintilla_get_tab_width(sci));
        } else {
            pos = gtk_scintilla_position_from_line(sci, current_line)+(previous_line_indentation);
        }
        gtk_scintilla_goto_pos(sci, pos);
        gtk_scintilla_end_undo_action(sci);
    }
}
示例#4
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);
	}
}