Changed internal viewer to use vfs_path_t objects.
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Этот коммит содержится в:
родитель
db58cd9ca7
Коммит
87291354e3
@ -219,7 +219,9 @@ mcview_handle_editkey (mcview_t * view, int key)
|
||||
return MSG_NOT_HANDLED;
|
||||
}
|
||||
|
||||
if ((view->filename != NULL) && (view->filename[0] != '\0') && (view->change_list == NULL))
|
||||
if ((view->filename_vpath != NULL)
|
||||
&& (*(vfs_path_get_last_path_str (view->filename_vpath)) != '\0')
|
||||
&& (view->change_list == NULL))
|
||||
view->locked = mcview_lock_file (view);
|
||||
|
||||
if (node == NULL)
|
||||
|
@ -143,11 +143,15 @@ mcview_display_status (mcview_t * view)
|
||||
widget_move (view, top, left);
|
||||
tty_draw_hline (-1, -1, ' ', width);
|
||||
|
||||
file_label = view->filename ? view->filename : view->command ? view->command : "";
|
||||
file_label =
|
||||
view->filename_vpath != NULL ?
|
||||
vfs_path_get_last_path_str (view->filename_vpath) : view->command != NULL ?
|
||||
view->command : "";
|
||||
file_label_width = str_term_width1 (file_label) - 2;
|
||||
if (width > 40)
|
||||
{
|
||||
char buffer[BUF_TINY];
|
||||
|
||||
widget_move (view, top, width - 32);
|
||||
if (view->hex_mode)
|
||||
tty_printf ("0x%08" PRIxMAX, (uintmax_t) view->hex_cursor);
|
||||
|
@ -347,13 +347,10 @@ mcview_hexedit_save_changes (mcview_t * view)
|
||||
int fp;
|
||||
char *text;
|
||||
struct hexedit_change_node *curr, *next;
|
||||
vfs_path_t *tmp_vpath;
|
||||
|
||||
assert (view->filename != NULL);
|
||||
assert (view->filename_vpath != NULL);
|
||||
|
||||
tmp_vpath = vfs_path_from_str (view->filename);
|
||||
fp = mc_open (tmp_vpath, O_WRONLY);
|
||||
vfs_path_free (tmp_vpath);
|
||||
fp = mc_open (view->filename_vpath, O_WRONLY);
|
||||
if (fp != -1)
|
||||
{
|
||||
for (curr = view->change_list; curr != NULL; curr = next)
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "lib/search.h"
|
||||
#include "lib/widget.h"
|
||||
#include "lib/vfs/vfs.h" /* vfs_path_t */
|
||||
|
||||
#include "src/keybind-defaults.h" /* global_keymap_t */
|
||||
|
||||
@ -89,8 +90,8 @@ typedef struct mcview_struct
|
||||
{
|
||||
Widget widget;
|
||||
|
||||
char *filename; /* Name of the file */
|
||||
char *workdir; /* Name of the working directory */
|
||||
vfs_path_t *filename_vpath; /* Name of the file */
|
||||
vfs_path_t *workdir_vpath; /* Name of the working directory */
|
||||
char *command; /* Command used to pipe data in */
|
||||
|
||||
enum view_ds datasource; /* Where the displayed data comes from */
|
||||
|
@ -79,7 +79,7 @@ mcview_toggle_magic_mode (mcview_t * view)
|
||||
|
||||
mcview_altered_magic_flag = 1;
|
||||
view->magic_mode = !view->magic_mode;
|
||||
filename = g_strdup (view->filename);
|
||||
filename = vfs_path_to_str (view->filename_vpath);
|
||||
command = g_strdup (view->command);
|
||||
|
||||
mcview_done (view);
|
||||
@ -184,8 +184,8 @@ mcview_init (mcview_t * view)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
view->filename = NULL;
|
||||
view->workdir = NULL;
|
||||
view->filename_vpath = NULL;
|
||||
view->workdir_vpath = NULL;
|
||||
view->command = NULL;
|
||||
view->search_nroff_seq = NULL;
|
||||
|
||||
@ -232,16 +232,12 @@ void
|
||||
mcview_done (mcview_t * view)
|
||||
{
|
||||
/* Save current file position */
|
||||
if (mcview_remember_file_position && view->filename != NULL)
|
||||
if (mcview_remember_file_position && view->filename_vpath != NULL)
|
||||
{
|
||||
vfs_path_t *vpath;
|
||||
|
||||
vpath = vfs_path_from_str (view->filename);
|
||||
save_file_position (vpath, -1, 0,
|
||||
save_file_position (view->filename_vpath, -1, 0,
|
||||
view->hex_mode ? view->hex_cursor : view->dpy_start,
|
||||
view->saved_bookmarks);
|
||||
view->saved_bookmarks = NULL;
|
||||
vfs_path_free (vpath);
|
||||
}
|
||||
|
||||
/* Write back the global viewer mode */
|
||||
@ -254,10 +250,10 @@ mcview_done (mcview_t * view)
|
||||
|
||||
/* view->widget needs no destructor */
|
||||
|
||||
g_free (view->filename);
|
||||
view->filename = NULL;
|
||||
g_free (view->workdir);
|
||||
view->workdir = NULL;
|
||||
vfs_path_free (view->filename_vpath);
|
||||
view->filename_vpath = NULL;
|
||||
vfs_path_free (view->workdir_vpath);
|
||||
view->workdir_vpath = NULL;
|
||||
g_free (view->command);
|
||||
view->command = NULL;
|
||||
|
||||
@ -418,14 +414,20 @@ mcview_get_title (const Dlg_head * h, size_t len)
|
||||
const mcview_t *view = (const mcview_t *) find_widget_type (h, mcview_callback);
|
||||
const char *modified = view->hexedit_mode && (view->change_list != NULL) ? "(*) " : " ";
|
||||
const char *file_label;
|
||||
char *view_filename;
|
||||
char *ret_str;
|
||||
|
||||
view_filename =
|
||||
view->filename_vpath != NULL ? vfs_path_to_str (view->filename_vpath) : NULL;
|
||||
|
||||
len -= 4;
|
||||
|
||||
file_label = view->filename != NULL ? view->filename :
|
||||
view->command != NULL ? view->command : "";
|
||||
file_label = view_filename != NULL ? view_filename : view->command != NULL ? view->command : "";
|
||||
file_label = str_term_trim (file_label, len - str_term_width1 (_("View: ")));
|
||||
|
||||
return g_strconcat (_("View: "), modified, file_label, (char *) NULL);
|
||||
ret_str = g_strconcat (_("View: "), modified, file_label, (char *) NULL);
|
||||
g_free (view_filename);
|
||||
return ret_str;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -436,7 +438,7 @@ mcview_lock_file (mcview_t * view)
|
||||
vfs_path_t *fullpath;
|
||||
gboolean ret;
|
||||
|
||||
fullpath = vfs_path_build_filename (view->workdir, view->filename, (char *) NULL);
|
||||
fullpath = vfs_path_append_vpath_new (view->workdir_vpath, view->filename_vpath, (char *) NULL);
|
||||
ret = lock_file (fullpath);
|
||||
vfs_path_free (fullpath);
|
||||
|
||||
@ -451,7 +453,7 @@ mcview_unlock_file (mcview_t * view)
|
||||
vfs_path_t *fullpath;
|
||||
gboolean ret;
|
||||
|
||||
fullpath = vfs_path_build_filename (view->workdir, view->filename, (char *) NULL);
|
||||
fullpath = vfs_path_append_vpath_new (view->workdir_vpath, view->filename_vpath, (char *) NULL);
|
||||
ret = unlock_file (fullpath);
|
||||
vfs_path_free (fullpath);
|
||||
|
||||
|
@ -277,12 +277,12 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
|
||||
assert (view->bytes_per_line != 0);
|
||||
|
||||
view->filename = g_strdup (file);
|
||||
view->filename_vpath = vfs_path_from_str (file);
|
||||
|
||||
if ((view->workdir == NULL) && (file != NULL))
|
||||
if ((view->workdir_vpath == NULL) && (file != NULL))
|
||||
{
|
||||
if (!g_path_is_absolute (file))
|
||||
view->workdir = vfs_get_current_dir ();
|
||||
view->workdir_vpath = vfs_path_clone (vfs_get_raw_current_dir ());
|
||||
else
|
||||
{
|
||||
/* try extract path form filename */
|
||||
@ -290,12 +290,12 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
|
||||
dirname = g_path_get_dirname (file);
|
||||
if (strcmp (dirname, ".") != 0)
|
||||
view->workdir = dirname;
|
||||
view->workdir_vpath = vfs_path_from_str (dirname);
|
||||
else
|
||||
{
|
||||
g_free (dirname);
|
||||
view->workdir = vfs_get_current_dir ();
|
||||
view->workdir_vpath = vfs_path_clone (vfs_get_raw_current_dir ());
|
||||
}
|
||||
g_free (dirname);
|
||||
}
|
||||
}
|
||||
|
||||
@ -320,10 +320,10 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
g_snprintf (tmp, sizeof (tmp), _("Cannot open \"%s\"\n%s"),
|
||||
file, unix_error_string (errno));
|
||||
mcview_show_error (view, tmp);
|
||||
g_free (view->filename);
|
||||
view->filename = NULL;
|
||||
g_free (view->workdir);
|
||||
view->workdir = NULL;
|
||||
vfs_path_free (view->filename_vpath);
|
||||
view->filename_vpath = NULL;
|
||||
vfs_path_free (view->workdir_vpath);
|
||||
view->workdir_vpath = NULL;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
@ -334,10 +334,10 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
g_snprintf (tmp, sizeof (tmp), _("Cannot stat \"%s\"\n%s"),
|
||||
file, unix_error_string (errno));
|
||||
mcview_show_error (view, tmp);
|
||||
g_free (view->filename);
|
||||
view->filename = NULL;
|
||||
g_free (view->workdir);
|
||||
view->workdir = NULL;
|
||||
vfs_path_free (view->filename_vpath);
|
||||
view->filename_vpath = NULL;
|
||||
vfs_path_free (view->workdir_vpath);
|
||||
view->workdir_vpath = NULL;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
@ -345,10 +345,10 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
{
|
||||
mc_close (fd);
|
||||
mcview_show_error (view, _("Cannot view: not a regular file"));
|
||||
g_free (view->filename);
|
||||
view->filename = NULL;
|
||||
g_free (view->workdir);
|
||||
view->workdir = NULL;
|
||||
vfs_path_free (view->filename_vpath);
|
||||
view->filename_vpath = NULL;
|
||||
vfs_path_free (view->workdir_vpath);
|
||||
view->workdir_vpath = NULL;
|
||||
goto finish;
|
||||
}
|
||||
|
||||
@ -365,8 +365,12 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
|
||||
if (view->magic_mode && (type != COMPRESSION_NONE))
|
||||
{
|
||||
g_free (view->filename);
|
||||
view->filename = g_strconcat (file, decompress_extension (type), (char *) NULL);
|
||||
char *tmp_filename;
|
||||
|
||||
vfs_path_free (view->filename_vpath);
|
||||
tmp_filename = g_strconcat (file, decompress_extension (type), (char *) NULL);
|
||||
view->filename_vpath = vfs_path_from_str (tmp_filename);
|
||||
g_free (tmp_filename);
|
||||
}
|
||||
mcview_set_datasource_file (view, fd, &st);
|
||||
}
|
||||
@ -383,14 +387,12 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
mcview_compute_areas (view);
|
||||
mcview_update_bytes_per_line (view);
|
||||
|
||||
if (mcview_remember_file_position && view->filename != NULL && start_line == 0)
|
||||
if (mcview_remember_file_position && view->filename_vpath != NULL && start_line == 0)
|
||||
{
|
||||
long line, col;
|
||||
off_t new_offset, max_offset;
|
||||
vfs_path_t *tmp_vpath;
|
||||
|
||||
tmp_vpath = vfs_path_from_str (view->filename);
|
||||
load_file_position (tmp_vpath, &line, &col, &new_offset, &view->saved_bookmarks);
|
||||
load_file_position (view->filename_vpath, &line, &col, &new_offset, &view->saved_bookmarks);
|
||||
max_offset = mcview_get_filesize (view) - 1;
|
||||
if (max_offset < 0)
|
||||
new_offset = 0;
|
||||
@ -403,7 +405,6 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
view->dpy_start = new_offset - new_offset % view->bytes_per_line;
|
||||
view->hex_cursor = new_offset;
|
||||
}
|
||||
vfs_path_free (tmp_vpath);
|
||||
}
|
||||
else if (start_line > 0)
|
||||
mcview_moveto (view, start_line - 1, 0);
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user