void ScriptTextEditor::_edit_option(int p_op) { switch(p_op) { case EDIT_UNDO: { code_editor->get_text_edit()->undo(); code_editor->get_text_edit()->call_deferred("grab_focus"); } break; case EDIT_REDO: { code_editor->get_text_edit()->redo(); code_editor->get_text_edit()->call_deferred("grab_focus"); } break; case EDIT_CUT: { code_editor->get_text_edit()->cut(); code_editor->get_text_edit()->call_deferred("grab_focus"); } break; case EDIT_COPY: { code_editor->get_text_edit()->copy(); code_editor->get_text_edit()->call_deferred("grab_focus"); } break; case EDIT_PASTE: { code_editor->get_text_edit()->paste(); code_editor->get_text_edit()->call_deferred("grab_focus"); } break; case EDIT_SELECT_ALL: { code_editor->get_text_edit()->select_all(); code_editor->get_text_edit()->call_deferred("grab_focus"); } break; case EDIT_MOVE_LINE_UP: { TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = script; if (scr.is_null()) return; tx->begin_complex_operation(); if (tx->is_selection_active()) { int from_line = tx->get_selection_from_line(); int from_col = tx->get_selection_from_column(); int to_line = tx->get_selection_to_line(); int to_column = tx->get_selection_to_column(); for (int i = from_line; i <= to_line; i++) { int line_id = i; int next_id = i - 1; if (line_id == 0 || next_id < 0) return; swap_lines(tx, line_id, next_id); } int from_line_up = from_line > 0 ? from_line-1 : from_line; int to_line_up = to_line > 0 ? to_line-1 : to_line; tx->select(from_line_up, from_col, to_line_up, to_column); } else { int line_id = tx->cursor_get_line(); int next_id = line_id - 1; if (line_id == 0 || next_id < 0) return; swap_lines(tx, line_id, next_id); } tx->end_complex_operation(); tx->update(); } break; case EDIT_MOVE_LINE_DOWN: { TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; tx->begin_complex_operation(); if (tx->is_selection_active()) { int from_line = tx->get_selection_from_line(); int from_col = tx->get_selection_from_column(); int to_line = tx->get_selection_to_line(); int to_column = tx->get_selection_to_column(); for (int i = to_line; i >= from_line; i--) { int line_id = i; int next_id = i + 1; if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count()) return; swap_lines(tx, line_id, next_id); } int from_line_down = from_line < tx->get_line_count() ? from_line+1 : from_line; int to_line_down = to_line < tx->get_line_count() ? to_line+1 : to_line; tx->select(from_line_down, from_col, to_line_down, to_column); } else { int line_id = tx->cursor_get_line(); int next_id = line_id + 1; if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count()) return; swap_lines(tx, line_id, next_id); } tx->end_complex_operation(); tx->update(); } break; case EDIT_INDENT_LEFT: { TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; tx->begin_complex_operation(); if (tx->is_selection_active()) { tx->indent_selection_left(); } else { int begin = tx->cursor_get_line(); String line_text = tx->get_line(begin); // begins with tab if (line_text.begins_with("\t")) { line_text = line_text.substr(1, line_text.length()); tx->set_line(begin, line_text); } // begins with 4 spaces else if (line_text.begins_with(" ")) { line_text = line_text.substr(4, line_text.length()); tx->set_line(begin, line_text); } } tx->end_complex_operation(); tx->update(); //tx->deselect(); } break; case EDIT_INDENT_RIGHT: { TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; tx->begin_complex_operation(); if (tx->is_selection_active()) { tx->indent_selection_right(); } else { int begin = tx->cursor_get_line(); String line_text = tx->get_line(begin); line_text = '\t' + line_text; tx->set_line(begin, line_text); } tx->end_complex_operation(); tx->update(); //tx->deselect(); } break; case EDIT_CLONE_DOWN: { TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; int from_line = tx->cursor_get_line(); int to_line = tx->cursor_get_line(); int column = tx->cursor_get_column(); if (tx->is_selection_active()) { from_line = tx->get_selection_from_line(); to_line = tx->get_selection_to_line(); column = tx->cursor_get_column(); } int next_line = to_line + 1; tx->begin_complex_operation(); for (int i = from_line; i <= to_line; i++) { if (i >= tx->get_line_count() - 1) { tx->set_line(i, tx->get_line(i) + "\n"); } String line_clone = tx->get_line(i); tx->insert_at(line_clone, next_line); next_line++; } tx->cursor_set_column(column); if (tx->is_selection_active()) { tx->select(to_line + 1, tx->get_selection_from_column(), next_line - 1, tx->get_selection_to_column()); } tx->end_complex_operation(); tx->update(); } break; case EDIT_TOGGLE_COMMENT: { TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; tx->begin_complex_operation(); if (tx->is_selection_active()) { int begin = tx->get_selection_from_line(); int end = tx->get_selection_to_line(); // End of selection ends on the first column of the last line, ignore it. if(tx->get_selection_to_column() == 0) end -= 1; for (int i = begin; i <= end; i++) { String line_text = tx->get_line(i); if (line_text.begins_with("#")) line_text = line_text.substr(1, line_text.length()); else line_text = "#" + line_text; tx->set_line(i, line_text); } } else { int begin = tx->cursor_get_line(); String line_text = tx->get_line(begin); if (line_text.begins_with("#")) line_text = line_text.substr(1, line_text.length()); else line_text = "#" + line_text; tx->set_line(begin, line_text); } tx->end_complex_operation(); tx->update(); //tx->deselect(); } break; case EDIT_COMPLETE: { code_editor->get_text_edit()->query_code_comple(); } break; case EDIT_AUTO_INDENT: { TextEdit *te = code_editor->get_text_edit(); String text = te->get_text(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; int begin,end; if (te->is_selection_active()) { begin=te->get_selection_from_line(); end=te->get_selection_to_line(); } else { begin=0; end=te->get_line_count()-1; } scr->get_language()->auto_indent_code(text,begin,end); te->set_text(text); } break; case EDIT_TRIM_TRAILING_WHITESAPCE: { trim_trailing_whitespace(); } break; case SEARCH_FIND: { code_editor->get_find_replace_bar()->popup_search(); } break; case SEARCH_FIND_NEXT: { code_editor->get_find_replace_bar()->search_next(); } break; case SEARCH_FIND_PREV: { code_editor->get_find_replace_bar()->search_prev(); } break; case SEARCH_REPLACE: { code_editor->get_find_replace_bar()->popup_replace(); } break; case SEARCH_LOCATE_FUNCTION: { quick_open->popup(get_functions()); } break; case SEARCH_GOTO_LINE: { goto_line_dialog->popup_find_line(code_editor->get_text_edit()); } break; case DEBUG_TOGGLE_BREAKPOINT: { int line=code_editor->get_text_edit()->cursor_get_line(); bool dobreak = !code_editor->get_text_edit()->is_line_set_as_breakpoint(line); code_editor->get_text_edit()->set_line_as_breakpoint(line,dobreak); ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(),line+1,dobreak); } break; case DEBUG_REMOVE_ALL_BREAKPOINTS: { List<int> bpoints; code_editor->get_text_edit()->get_breakpoints(&bpoints); for(List<int>::Element *E=bpoints.front();E;E=E->next()) { int line = E->get(); bool dobreak = !code_editor->get_text_edit()->is_line_set_as_breakpoint(line); code_editor->get_text_edit()->set_line_as_breakpoint(line,dobreak); ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(),line+1,dobreak); } } case DEBUG_GOTO_NEXT_BREAKPOINT: { List<int> bpoints; code_editor->get_text_edit()->get_breakpoints(&bpoints); if (bpoints.size() <= 0) { return; } int line=code_editor->get_text_edit()->cursor_get_line(); // wrap around if (line >= bpoints[bpoints.size() - 1]) { code_editor->get_text_edit()->cursor_set_line(bpoints[0]); } else { for(List<int>::Element *E=bpoints.front();E;E=E->next()) { int bline = E->get(); if (bline > line) { code_editor->get_text_edit()->cursor_set_line(bline); return; } } } } break; case DEBUG_GOTO_PREV_BREAKPOINT: { List<int> bpoints; code_editor->get_text_edit()->get_breakpoints(&bpoints); if (bpoints.size() <= 0) { return; } int line=code_editor->get_text_edit()->cursor_get_line(); // wrap around if (line <= bpoints[0]) { code_editor->get_text_edit()->cursor_set_line(bpoints[bpoints.size() - 1]); } else { for(List<int>::Element *E=bpoints.back();E;E=E->prev()) { int bline = E->get(); if (bline < line) { code_editor->get_text_edit()->cursor_set_line(bline); return; } } } } break; case HELP_CONTEXTUAL: { String text = code_editor->get_text_edit()->get_selection_text(); if (text == "") text = code_editor->get_text_edit()->get_word_under_cursor(); if (text != "") { emit_signal("request_help_search",text); } } break; } }
long mergesort_lp_file_internal(FILE *LPREL, FILE *LPNEW, FILE *COMB, FILE *TMP) { char line1[MPQS_STRING_LENGTH], line2[MPQS_STRING_LENGTH]; char line[MPQS_STRING_LENGTH]; char *line_new = line1, *line_new_old = line2; long q_new, q_new_old = -1, q, i = 0, c = 0; long comb_in_progress; if ( !fgets(line_new, MPQS_STRING_LENGTH, LPNEW) ) { /* LPNEW is empty: copy LPREL to TMP. Could be done by a rename if we didn't want to count the lines (again)... however, this case will not normally happen */ i = append_file(TMP, LPREL); return COMB ? 0 : i; } /* we now have a line_new from LPNEW */ if (!fgets(line, MPQS_STRING_LENGTH, LPREL)) { /* LPREL is empty: copy LPNEW to TMP... almost. */ flint_fputs(line_new, TMP); if (!COMB) { /* full relations mode */ i = append_file(TMP, LPNEW); return i + 1; } /* LP mode: check for combinable relations */ q_new_old = atol(line_new); /* we need to retain a copy of the old line just for a moment, because we may yet have to write it to COMB. Do this by swapping the two buffers */ swap_lines(); comb_in_progress = 0; i = 0; while (fgets(line_new, MPQS_STRING_LENGTH, LPNEW)) { q_new = atol(line_new); if (q_new_old == q_new) { /* found combinables, check whether we're already busy on this particular large prime */ if (!comb_in_progress) { /* if not, write first line to COMB, creating and opening the file first if it isn't open yet */ flint_fputs(line_new_old, COMB); comb_in_progress = 1; } /* in any case, write the current line, and count it */ flint_fputs(line_new, COMB); i++; } else { /* not combinable */ q_new_old = q_new; comb_in_progress = 0; /* and dump it to the TMP file */ flint_fputs(line_new, TMP); /* and stash it away for a moment */ swap_lines(); comb_in_progress = 0; } } /* while */ fclose(TMP); return i; } /* normal case: both LPNEW and LPREL are not empty */ q_new = atol(line_new); q = atol(line); for(;;) { /* main merging loop */ i = comb_in_progress = 0; /* first the harder case: let LPNEW catch up with LPREL, and possibly overtake it, checking for combinables coming from LPNEW alone */ while (q > q_new) { if (!COMB || !comb_in_progress) flint_fputs(line_new, TMP); if (!COMB) c++; /* in FREL mode, count lines written */ else if (!comb_in_progress) { q_new_old = q_new; swap_lines(); } if (!fgets(line_new, MPQS_STRING_LENGTH, LPNEW)) { flint_fputs(line, TMP); if (!COMB) c++; else c += i; i = append_file(TMP, LPREL); return COMB ? c : c + i; } q_new = atol(line_new); if (!COMB) continue; /* LP mode only: */ if (q_new_old != q_new) /* not combinable */ comb_in_progress = 0; /* next loop will deal with it, or loop may end */ else { /* found combinables, check whether we're already busy on this large prime */ if (!comb_in_progress) { flint_fputs(line_new_old, COMB); comb_in_progress = 1; } /* in any case, write the current line, and count it */ flint_fputs(line_new, COMB); i++; } } /* while q > q_new */ /* q <= q_new */ if (COMB) c += i; /* accumulate count of combinables */ i = 0; /* and clear it */ comb_in_progress = 0;/* redundant */ /* now let LPREL catch up with LPNEW, and possibly overtake it */ while (q < q_new) { flint_fputs(line, TMP); if (!COMB) c++; if (!fgets(line, MPQS_STRING_LENGTH, LPREL)) { flint_fputs(line_new, TMP); i = append_file(TMP, LPNEW); return COMB ? c : c + i + 1; } else q = atol(line); } /* q >= q_new */ /* Finally, it may happen that q == q_new, indicating combinables whose large prime is already in LPREL, and appears now one or more times in LPNEW. Thus in this sub-loop we advance LPNEW. The `line' from LPREL is left alone, and will be written to TMP the next time around the main for loop; we only write it to COMB here -- unless all we find is an exact duplicate of the line we already have, that is. (There can be at most one such, and if so it is simply discarded.) */ while (q == q_new) { if (!strcmp(line_new, line)) { /* duplicate -- move right ahead to the next LPNEW line */ ;/* do nothing here */ } else if (!COMB) { /* full relations mode: write line_new out first, keep line */ flint_fputs(line_new, TMP); c++; } else { /* LP mode, and combinable relation */ if (!comb_in_progress) { flint_fputs(line, COMB); comb_in_progress = 1; } flint_fputs(line_new, COMB); i++; } /* NB comb_in_progress is cleared by q_new becoming bigger than q, thus the current while loop terminating, the next time through the main for loop */ /* common ending: get another line_new, if any */ if (!fgets(line_new, MPQS_STRING_LENGTH, LPNEW)) { flint_fputs(line, TMP); if (!COMB) c++; else c += i; i = append_file(TMP, LPREL); return COMB ? c : c + i; } else q_new = atol(line_new); } /* while */ if (COMB) c += i; /* accumulate count of combinables */ } }