Merge branch '2107_viewer_wrap_scroll_left_right'

* 2107_viewer_wrap_scroll_left_right:
  Applied MC indentation policy.
  Optimization of mcview_hexedit_save_changes() function.
  Type accuracy.
  Optimization: removed superfluous actions.
  Ticket #2107: viewer: enable left/right scrolling in wrap mode.
This commit is contained in:
Andrew Borodin 2010-03-29 12:01:45 +04:00
commit 00ddfc0327
4 changed files with 41 additions and 55 deletions

View File

@ -329,17 +329,14 @@ mcview_execute_cmd (mcview_t * view, unsigned long command)
case CK_ViewToggleWrapMode:
/* Toggle between wrapped and unwrapped view */
mcview_toggle_wrap_mode (view);
view->dirty++;
break;
case CK_ViewToggleHexEditMode:
/* Toggle between hexview and hexedit mode */
mcview_toggle_hexedit_mode (view);
view->dirty++;
break;
case CK_ViewToggleHexMode:
/* Toggle between hex view and text view */
mcview_toggle_hex_mode (view);
view->dirty++;
break;
case CK_ViewGoto:
{
@ -365,7 +362,6 @@ mcview_execute_cmd (mcview_t * view, unsigned long command)
break;
case CK_ViewToggleMagicMode:
mcview_toggle_magic_mode (view);
view->dirty++;
break;
case CK_ViewToggleNroffMode:
mcview_toggle_nroff_mode (view);
@ -471,12 +467,12 @@ mcview_handle_key (mcview_t * view, int key)
if ((command != CK_Ignore_Key) && (mcview_execute_cmd (view, command) == MSG_HANDLED))
return MSG_HANDLED;
if (mcview_check_left_right_keys (view, key))
if (mcview_check_left_right_keys (view, key) == MSG_HANDLED)
return MSG_HANDLED;
if (check_movement_keys (key, view->data_area.height + 1, view,
mcview_cmk_move_up, mcview_cmk_move_down,
mcview_cmk_moveto_top, mcview_cmk_moveto_bottom))
mcview_cmk_moveto_top, mcview_cmk_moveto_bottom) == MSG_HANDLED)
return MSG_HANDLED;
#ifdef MC_ENABLE_DEBUGGING_CODE

View File

@ -281,55 +281,54 @@ mcview_display_hex (mcview_t * view)
gboolean
mcview_hexedit_save_changes (mcview_t * view)
{
struct hexedit_change_node *curr, *next;
int fp, answer;
char *text, *error;
int answer = 0;
if (view->change_list == NULL)
return TRUE;
retry_save:
assert (view->filename != NULL);
fp = mc_open (view->filename, O_WRONLY);
if (fp == -1)
goto save_error;
for (curr = view->change_list; curr != NULL; curr = next)
while (answer == 0)
{
next = curr->next;
int fp;
char *text;
struct hexedit_change_node *curr, *next;
if (mc_lseek (fp, curr->offset, SEEK_SET) == -1 || mc_write (fp, &(curr->value), 1) != 1)
goto save_error;
assert (view->filename != NULL);
/* delete the saved item from the change list */
view->change_list = next;
view->dirty++;
mcview_set_byte (view, curr->offset, curr->value);
g_free (curr);
fp = mc_open (view->filename, O_WRONLY);
if (fp != -1)
{
for (curr = view->change_list; curr != NULL; curr = next)
{
next = curr->next;
if (mc_lseek (fp, curr->offset, SEEK_SET) == -1
|| mc_write (fp, &(curr->value), 1) != 1)
goto save_error;
/* delete the saved item from the change list */
view->change_list = next;
view->dirty++;
mcview_set_byte (view, curr->offset, curr->value);
g_free (curr);
}
if (mc_close (fp) == -1)
message (D_ERROR, _(" Save file "),
_(" Error while closing the file: \n %s \n"
" Data may have been written or not. "), unix_error_string (errno));
view->dirty++;
return TRUE;
}
save_error:
text = g_strdup_printf (_(" Cannot save file: \n %s "), unix_error_string (errno));
(void) mc_close (fp);
answer = query_dialog (_(" Save file "), text, D_ERROR, 2, _("&Retry"), _("&Cancel"));
g_free (text);
}
if (mc_close (fp) == -1)
{
error = g_strdup (unix_error_string (errno));
message (D_ERROR, _(" Save file "),
_(" Error while closing the file: \n %s \n"
" Data may have been written or not. "), error);
g_free (error);
}
mcview_update (view);
return TRUE;
save_error:
error = g_strdup (unix_error_string (errno));
text = g_strdup_printf (_(" Cannot save file: \n %s "), error);
g_free (error);
(void) mc_close (fp);
answer = query_dialog (_(" Save file "), text, D_ERROR, 2, _("&Retry"), _("&Cancel"));
g_free (text);
if (answer == 0)
goto retry_save;
return FALSE;
}

View File

@ -79,7 +79,6 @@ mcview_toggle_magic_mode (mcview_t * view)
filename = g_strdup (view->filename);
command = g_strdup (view->command);
mcview_done (view);
mcview_load (view, command, filename, 0);
g_free (filename);
g_free (command);

View File

@ -173,10 +173,6 @@ mcview_move_left (mcview_t * view, off_t columns)
if (old_cursor > 0 || view->hexedit_lownibble)
view->hexedit_lownibble = !view->hexedit_lownibble;
}
else if (view->text_wrap_mode)
{
/* nothing to do */
}
else
{
if (view->dpy_text_column >= columns)
@ -207,10 +203,6 @@ mcview_move_right (mcview_t * view, off_t columns)
if (old_cursor < last_byte || !view->hexedit_lownibble)
view->hexedit_lownibble = !view->hexedit_lownibble;
}
else if (view->text_wrap_mode)
{
/* nothing to do */
}
else
{
view->dpy_text_column += columns;