Beispiel #1
0
bool
sc_toggle_page_mode(girara_session_t* session, girara_argument_t*
                    UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

  if (zathura->document == NULL) {
    girara_notify(session, GIRARA_WARNING, _("No document opened."));
    return false;
  }

  unsigned int page_id = zathura_document_get_current_page_number(zathura->document);

  int pages_per_row = 1;
  girara_setting_get(zathura->ui.session, "pages-per-row", &pages_per_row);

  int value = 1;
  if (pages_per_row == 1) {
    value = zathura->shortcut.toggle_page_mode.pages;
  } else {
    zathura->shortcut.toggle_page_mode.pages = pages_per_row;
  }

  girara_setting_set(zathura->ui.session, "pages-per-row", &value);
  adjust_view(zathura);

  page_set(zathura, page_id);
  render_all(zathura);
  refresh_view(zathura);

  return true;
}
Beispiel #2
0
int audioedit_delete_selection(struct view *v)
{
    int rc = -1;
    long first, last;
    char undo_label[200];

    get_region_of_interest(&first, &last, v);

    sprintf(undo_label, "Delete audio data from %ld to %ld.", first, last);
    if (start_save_undo(undo_label, v) < 0)
        return -1;
    rc = save_undo_data_remove(first, last, 1);
    close_undo();
    if (rc == 1) /* canceled */
        return -1;

    begin_operation("Deleting audio data") ;
    rc = soundfile_remove_samples(first, last - first + 1, 1);
    end_operation();

    if (rc == 0) {
        adjust_view(v);
        v->selection_region = FALSE;
        resample(first, prefs.n_samples-1);
    }
    return rc;
}
Beispiel #3
0
void truncate_wavfile(struct view *v, int save_undo)
{
    int rc;
    long first, last;
    long end_pos = soundfile_count_samples();
    char undo_label[200];

    get_region_of_interest(&first, &last, v);

    if (save_undo) {
        /* split undo-data to undo separately in case of failure */
        sprintf(undo_label, "Delete audio data from %ld to %ld.", last+1, end_pos);
        if (start_save_undo(undo_label, v) < 0)
            return;
        rc = save_undo_data_remove(last+1, end_pos, 1);
        close_undo();
        if (rc == 1) /* canceled */
            return;
    }

    begin_operation("Deleting audio data") ;
    rc = soundfile_remove_samples(last+1, end_pos, 1);
    end_operation();

    if (rc != 0) {
        /* failure; FIX: needs cleanup of undo and more */
        return;
    }

    if (save_undo) {
        /* second part of undo */
        sprintf(undo_label, "Delete audio data from 0 to %ld.", first-1);
        if (start_save_undo(undo_label, v) < 0)
            return;
        rc = save_undo_data_remove(0, first-1, 1);
        close_undo();
        /* cancel ignored */
    }

    begin_operation("Deleting audio data") ;
    rc = soundfile_remove_samples(0, first-1, 1);
    end_operation();

    if (rc != 0) {
        /* failure; FIX: needs cleanup of undo and more */
        return;
    }

    adjust_view(v);

    v->first_sample = 0;
    v->last_sample  = v->n_samples - 1;
    v->selection_region = FALSE;

    resample(0, prefs.n_samples-1);
}
Beispiel #4
0
void
BasicGrid::reflow_impl() noexcept {
	base::reflow_impl();
	reflow_view(geometry().frame());
	adjust_view();
	queue_header_render();
	queue_cell_render(0, row_count());
	enqueue_actions(
		UI::UpdateActions::render |
		UI::UpdateActions::flag_noclear
	);
}
Beispiel #5
0
bool
sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
                 girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;
  g_return_val_if_fail(argument != NULL, false);

  zathura_document_set_adjust_mode(zathura->document, argument->n);
  adjust_view(zathura);

  return false;
}
Beispiel #6
0
bool
cb_view_resized(GtkWidget* UNUSED(widget), GtkAllocation* UNUSED(allocation), zathura_t* zathura)
{
  if (zathura == NULL || zathura->document == NULL) {
    return false;
  }

  /* adjust the scale according to settings. If nothing needs to be resized,
     it does not trigger the resize event.

     The right viewport size is already in the document object, due to a
     previous call to adjustment_changed. We don't want to use the allocation in
     here, because we would have to subtract scrollbars, etc. */
  adjust_view(zathura);

  return false;
}
Beispiel #7
0
Datei: edit.c Projekt: vigna/ne
int word_wrap2(buffer * const b) {
	static char avcmd[16];

	if (b->cur_pos > b->cur_line_desc->line_len) return OK;

	bool non_blank_added = false;
	int avshift;
	char * line = b->cur_line_desc->line;
	int64_t pos, original_line;

	/* If the char to our left is a space, we need to insert
	   a non-space to attach our WORDWRAP_BOOKMARK to because
	   spaces at the split point get removed, which effectively
	   leaves our bookmark on the current line. */
	delay_update();
	pos = prev_pos(line, b->cur_pos, b->encoding);
	if (pos >= 0 && (non_blank_added = ne_isspace(get_char(&line[pos], b->encoding), b->encoding))) {
		start_undo_chain(b);
		insert_one_char(b, b->cur_line_desc, b->cur_line, b->cur_pos, 'X');
		line = b->cur_line_desc->line;
		goto_pos(b, next_pos(line, b->cur_pos, b->encoding));
	}
	b->bookmark[WORDWRAP_BOOKMARK].pos   = b->cur_pos;
	b->bookmark[WORDWRAP_BOOKMARK].line  = original_line = b->cur_line;
	b->bookmark[WORDWRAP_BOOKMARK].cur_y = b->cur_y;
	b->bookmark_mask |= (1 << WORDWRAP_BOOKMARK);
	paragraph(b);
	goto_line_pos(b, b->bookmark[WORDWRAP_BOOKMARK].line, b->bookmark[WORDWRAP_BOOKMARK].pos);
	line = b->cur_line_desc->line;
	b->bookmark[WORDWRAP_BOOKMARK].cur_y += b->bookmark[WORDWRAP_BOOKMARK].line - original_line;
	if (avshift = b->cur_y - b->bookmark[WORDWRAP_BOOKMARK].cur_y) {
		snprintf(avcmd, 16, "%c%d", avshift > 0 ? 'T' :'B', avshift > 0 ? avshift : -avshift);
		adjust_view(b, avcmd);
	}
	b->bookmark_mask &= ~(1 << WORDWRAP_BOOKMARK);
	if (non_blank_added) {
		goto_pos(b, prev_pos(b->cur_line_desc->line, b->cur_pos, b->encoding));
		delete_one_char(b, b->cur_line_desc, b->cur_line, b->cur_pos);
		end_undo_chain(b);
	}
	return stop ? STOPPED : OK;
}
Beispiel #8
0
bool
sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
                 girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;
  g_return_val_if_fail(argument != NULL, false);

  if (argument->n < ZATHURA_ADJUST_NONE || argument->n >= ZATHURA_ADJUST_MODE_NUMBER) {
    girara_error("Invalid adjust mode: %d", argument->n);
    girara_notify(session, GIRARA_ERROR, _("Invalid adjust mode: %d"), argument->n);
  } else {
    girara_debug("Setting adjust mode to: %d", argument->n);

    zathura_document_set_adjust_mode(zathura->document, argument->n);
    adjust_view(zathura);
  }

  return false;
}
Beispiel #9
0
void
BasicGrid::set_cursor(
	UI::index_type col,
	UI::index_type row
) noexcept {
	col = value_clamp(col, 0, max_ce(0, col_count() - 1));
	row = value_clamp(row, 0, max_ce(0, row_count() - 1));
	if (col != m_cursor.col || row != m_cursor.row) {
		if (
			value_in_bounds(m_cursor.row, 0, row_count()) &&
			value_in_bounds(m_cursor.col, 0, col_count())
		) {
			queue_cell_render(
				m_cursor.row, m_cursor.row + 1,
				m_cursor.col, m_cursor.col + 1
			);
		}
		if (row_count() > 0) {
			queue_cell_render(
				row, row + 1,
				col, col + 1
			);
		}
		enqueue_actions(
			UI::UpdateActions::render |
			UI::UpdateActions::flag_noclear
		);
		m_cursor.col = col;
		m_cursor.row = row;
		adjust_view();
		if (is_focused()) {
			App::instance.m_ui.csline->set_location(
				std::to_string(m_cursor.row) + ", " +
				std::to_string(m_cursor.col)
			);
		}
	}
}
Beispiel #10
0
int audioedit_insert_silence(struct view *v)
{
    long first, last;

    get_region_of_interest(&first, &last, v);
    if (v->selection_region) {
        char undo_label[200];

        sprintf(undo_label, "Insert silence from %ld to %ld.", first, last);
        if (start_save_undo(undo_label, v) < 0)
            return -1;
        save_undo_data_insert(first, last, 1);
        close_undo();

        begin_operation("Inserting silence") ;
        soundfile_insert_silence(first, last - first + 1, 1);
        end_operation();

        adjust_view(v);
        resample(first, prefs.n_samples-1);
        return 0;
    }
    return -1;
}
Beispiel #11
0
int audioedit_paste_selection(struct view *v)
{
    int rc = -1;
    long sample_count;

    sample_count = audioedit_count_samples_in_clipdata();
    if (sample_count > 0)
    {
        long first, last;
        char undo_label[200];
        get_region_of_interest(&first, &last, v);

        sprintf(undo_label, "Paste audio data from %ld to %ld.", first, last);
        if (start_save_undo(undo_label, v) < 0)
            return -1;
        save_undo_data_insert(first, last, 1);
        close_undo();

        begin_operation("Inserting space for clipboard data") ;
        rc = soundfile_shift_samples_right(first, sample_count, 1);
        end_operation();

        if (rc == 0) {
            begin_operation("Inserting clipboard data");
            rc = soundfile_load_file(CLIPBOARD_FILE, first, sample_count, 1);
            end_operation();

            adjust_view(v);
            v->selection_region = FALSE;

            resample(first, prefs.n_samples-1);
        }
    }

    return rc;
}
Beispiel #12
0
void
BasicGrid::content_action(
	UI::ProtoGrid::ContentAction action,
	UI::index_type row_begin,
	UI::index_type count
) noexcept {
	using CA = UI::ProtoGrid::ContentAction;

	DUCT_ASSERTE(row_count() == signed_cast(m_sel.size()));
	// Cast insert_after in terms of insert_before
	if (CA::insert_after == action) {
		++row_begin;
	}
	row_begin = value_clamp(row_begin, 0, row_count());
	auto const row_end = min_ce(row_begin + count, row_count());
	auto clear_flag = UI::UpdateActions::none;
	switch (action) {
	// Select
	case CA::select: // fall-through
	case CA::unselect: {
		bool const enable = CA::select == action;
		auto const end = m_sel.begin() + row_end;
		for (auto it = m_sel.begin() + row_begin; end > it; ++it) {
			*it = enable;
		}
		queue_cell_render(row_begin, row_end);
		clear_flag = UI::UpdateActions::flag_noclear;
	}	break;

	case CA::select_toggle: {
		auto const end = m_sel.begin() + row_end;
		for (auto it = m_sel.begin() + row_begin; end > it; ++it) {
			*it = !*it;
		}
		queue_cell_render(row_begin, row_end);
		clear_flag = UI::UpdateActions::flag_noclear;
	}	break;

	// Insert
	case CA::insert_after: // fall-through
	case CA::insert_before:
		for (UI::index_type i = 0; i < count; ++i) {
			if (content_insert(row_begin + i)) {
				m_sel.insert(m_sel.begin() + row_begin + i, false);
				content_action_internal(CA::insert_before, row_begin + i, 1);
			}
		}
		if (row_count() == 1) {
			set_cursor(m_cursor.col, 0);
		} else if (row_begin <= m_cursor.row) {
			set_cursor(m_cursor.col, m_cursor.row + count);
		}
		adjust_view();
		break;

	// Erase
	case CA::erase:
		for (UI::index_type i = 0; i < count; ++i) {
			if (content_erase(row_begin)) {
				m_sel.erase(m_sel.cbegin() + row_begin);
				content_action_internal(CA::erase, row_begin, 1);
			}
		}
		break;

	case CA::erase_selected:
		for (UI::index_type index = 0; index < row_count();) {
			if (m_sel[index] && content_erase(index)) {
				m_sel.erase(m_sel.cbegin() + index);
				content_action_internal(CA::erase, index, 1);
			} else {
				++index;
			}
		}
		break;
	} // switch (action)

	// Post action
	switch (action) {
	case CA::erase:
	case CA::erase_selected:
		// Let cursor clamp to new bounds
		set_cursor(m_cursor.col, m_cursor.row);
		adjust_view();
		break;

	default:
		break;
	}
	enqueue_actions(
		UI::UpdateActions::render |
		clear_flag
	);
}
Beispiel #13
0
Datei: edit.c Projekt: vigna/ne
int shift(buffer * const b, char *p, char *msg, int msg_size) {
	const bool use_tabs = b->opt.tabs && b->opt.shift_tabs;
	const int64_t init_line = b->cur_line, init_pos = b->cur_pos, init_y = b->cur_y;

	line_desc *ld = NULL, *start_line_desc = NULL;
	int64_t shift_size = 1;
	char dir = '>';
	int shift_mag = b->opt.tab_size, rc = 0;

	/* Parse parm p; looks like [<|>] ### [s|t], but we allow them
	   in any order, once, with optional white space. */
	if (p) {
		int dir_b = 0, size_b = 0, st_b = 0;
		while (*p) {
			if (isasciispace(*p)) p++;
			else if (!dir_b && (dir_b = (*p == '<' || *p == '>'))) dir = *p++;
			else if (!size_b && (size_b = isdigit((unsigned char)*p))) {
				errno = 0;
				shift_size = strtoll(p, &p, 10);
				if (errno) return INVALID_SHIFT_SPECIFIED;
			} else if (!st_b && (st_b = (*p == 's' || *p == 'S'))) {
				shift_mag = 1;
				p++;
			} else if (!st_b && (st_b = (*p == 't' || *p == 'T'))) p++;
			else return INVALID_SHIFT_SPECIFIED;
		}
	}
	shift_size *= max(1, shift_mag);
	if (shift_size == 0) return INVALID_SHIFT_SPECIFIED;

	int64_t first_line = b->cur_line, last_line = b->cur_line, left_col = 0;

	if (b->marking) {
		if (b->mark_is_vertical) left_col = min(calc_width(b->cur_line_desc, b->block_start_pos, b->opt.tab_size, b->encoding),
		                                        calc_width(b->cur_line_desc, b->cur_pos,         b->opt.tab_size, b->encoding));
		first_line = min(b->block_start_line, b->cur_line);
		last_line  = max(b->block_start_line, b->cur_line);
	}

	/* If we're shifting left (dir=='<'), verify that we have sufficient white space
	   to remove on all the relevant lines before making any changes, i. */

	if (dir == '<') {
		shift_size = -shift_size; /* signed shift_size now also indicates direction. */
		for (int64_t line = first_line; !rc && line <= last_line; line++) {
			int64_t pos;
			goto_line(b, line);
			pos = calc_pos(b->cur_line_desc, left_col, b->opt.tab_size, b->encoding);
			while (pos < b->cur_line_desc->line_len &&
			       left_col - calc_width(b->cur_line_desc, pos, b->opt.tab_size, b->encoding) > shift_size) {
				if (isasciispace(b->cur_line_desc->line[pos]))
					pos = next_pos(b->cur_line_desc->line, pos, b->encoding);
				else {
					rc = INSUFFICIENT_WHITESPACE;
					break;
				}
			}
		}
	}


	if (!rc) {
		start_undo_chain(b);
		for (int64_t line = first_line; line <= last_line; line++) {
			int64_t pos, c_pos, c_col_orig, offset;
			b->attr_len = -1;
			goto_line(b, line);
			b->cur_pos = -1;
			ld = b->cur_line_desc;
			if (line == first_line) start_line_desc = ld;
			pos = calc_pos(ld, left_col, b->opt.tab_size, b->encoding);
			/* If left_col is in the middle of a tab, pos will be on that tab. */
			/* whitespace adjustment strategy:
			   1. Starting from left_col, advance to the right to the first non-blank character C.
			   2. Note C's col. The desired new column is this value +/- shift_size.
			   3. Move left looking for the first tab or non-whitespace or the left_col, whichever comes first.
			      Whitespace changes all take place at that transition point.
			   4. While C's col is wrong
			        if C's col is too far to the right,
			          if we're on a space, delete it;
			          else if there's a tab to our left, delete it;
			          else we should not have started, because it's not possible!
			        if C's col is too far to the left,
			           if its needs to be beyond the next tab stop,
			             insert a tab and move right;
			           else insert a space. */
			/* 1. */
			while (pos < ld->line_len && isasciispace(ld->line[pos]))
				pos = next_pos(ld->line, pos, b->encoding);
			if (pos >= ld->line_len) continue; /* We ran off the end of the line. */
			/* line[pos] should be the first non-blank character. */
			/* 2. */
			c_pos = pos;
			c_col_orig = calc_width(ld, c_pos, b->opt.tab_size, b->encoding);
			/* 3. */
			while (pos && ld->line[pos-1] == ' ')
				pos = prev_pos(ld->line, pos, b->encoding);
			/* If pos is non-zero, it should be on a blank, with only blanks between here and c_pos. */
			/* 4. */
			/* offset = how_far_we_have_moved - how_far_we_want_to_move. */
			while (!stop && (offset = calc_width(ld, c_pos, b->opt.tab_size, b->encoding)-c_col_orig - shift_size)) {
				if (offset > 0) { /* still too far right; remove whitespace */
					if (ld->line[pos] == ' ') {
						delete_stream(b, ld, b->cur_line, pos, 1);
						c_pos--;
					}
					else if (pos) { /* should be a tab just to our left */
						pos = prev_pos(ld->line, pos, b->encoding); /* now we're on the tab */
						if (ld->line[pos] == '\t') {
							delete_stream(b, ld, b->cur_line, pos, 1);
							c_pos--;
						}
						else break; /* Should have been a tab. This should never happen! Give up on this line and go mangle the next one. */
					}
					else break; /* This should never happen; give up on this line and go mangle the next one. */
				}
				else if (offset < 0) { /* too far left; insert whitespace */
					char c = ' ';
					if (use_tabs && (b->opt.tab_size - calc_width(ld, pos, b->opt.tab_size, b->encoding) % b->opt.tab_size) <= -offset )
						c = '\t';
					if (insert_one_char(b, ld, b->cur_line, pos, c)) {
						break;
					}
					pos++;
					c_pos++;
				}
			}
		}
		end_undo_chain(b);
		if (b->syn) {
			b->attr_len = -1;
			need_attr_update = true;
			update_syntax_states(b, -1, start_line_desc, (line_desc *)ld->ld_node.next);
		}
		update_window_lines(b, b->top_line_desc, 0, ne_lines - 2, false);
	}

	/* put the screen back where way we found it. */
	goto_line_pos(b, init_line, init_pos);
	delay_update();
	const int64_t avshift = b->cur_y - init_y;
	if (avshift) {
		snprintf(msg, msg_size, "%c%" PRId64, avshift > 0 ? 'T' :'B', avshift > 0 ? avshift : -avshift);
		adjust_view(b, msg);
	}

	return rc;
}