* Copyright (C) 2001 Ken Steen.
* Copyright (C) 2011 xaizek.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "instance.h"
#include <assert.h>
#include "cfg/config.h"
#include "engine/abbrevs.h"
#include "engine/autocmds.h"
#include "engine/cmds.h"
#include "engine/keys.h"
#include "engine/options.h"
#include "engine/parsing.h"
#include "engine/variables.h"
#include "int/path_env.h"
#include "modes/dialogs/msg_dialog.h"
#include "lua/vlua.h"
#include "ui/tabs.h"
#include "ui/ui.h"
#include "utils/str.h"
#include "utils/utils.h"
#include "bracket_notation.h"
#include "bmarks.h"
#include "dir_stack.h"
#include "filelist.h"
#include "flist_hist.h"
#include "opt_handlers.h"
#include "plugins.h"
#include "registers.h"
#include "status.h"
#include "trash.h"
#include "undo.h"
#include "vifm.h"
void
instance_init_variables(void)
{
init_variables();
vle_parser_set_notation(&spec_to_wstr);
}
void
instance_stop(void)
{
ui_shutdown();
stop_process();
}
void
instance_start_restart(RestartType type)
{
view_t *tmp_view;
curr_stats.restart_in_progress = type;
vle_keys_user_clear();
vle_cmds_clear();
vle_aucmd_remove(NULL, NULL);
vle_abbr_reset();
cfg_clear_histories(tabs_count(&lwin) == 0 && tabs_count(&rwin) == 0);
* alternative would be to re-initialize options from current state below
* instead of resetting to defaults, but not many options would benefit from
* that, history is kinda special. */
load_history_option();
* of values from status. */
(void)stats_reset(&cfg);
vle_opts_restore_defaults();
tmp_view = curr_view;
curr_view = other_view;
load_view_options(other_view);
vle_opts_restore_defaults();
curr_view = tmp_view;
ft_reset(curr_stats.exec_env_type == EET_EMULATOR_WITH_X);
un_reset();
dir_stack_clear();
regs_reset();
marks_clear_all();
bmarks_clear();
clear_envvars();
instance_init_variables();
update_path_env(1);
reset_views();
plugs_free(curr_stats.plugs);
vlua_finish(curr_stats.vlua);
curr_stats.vlua = vlua_init();
curr_stats.plugs = plugs_create(curr_stats.vlua);
}
void
instance_finish_restart(int run_startup_commands)
{
flist_hist_save(&lwin);
flist_hist_save(&rwin);
if(stroscmp(curr_stats.color_scheme, DEF_CS_NAME) != 0 &&
cs_exists(curr_stats.color_scheme))
{
cs_load_primary(curr_stats.color_scheme);
}
else
{
cs_load_defaults();
}
cs_load_pairs();
instance_load_config();
plugs_load(curr_stats.plugs, curr_stats.plugins_dirs);
if(run_startup_commands)
{
vifm_reexec_startup_commands();
}
curr_stats.restart_in_progress = RT_NONE;
if(cfg.use_trash)
{
* at default location. */
(void)trash_set_specs(cfg.trash_dir);
}
vle_aucmd_execute("DirEnter", flist_get_dir(&lwin), &lwin);
vle_aucmd_execute("DirEnter", flist_get_dir(&rwin), &rwin);
update_screen(UT_REDRAW);
}
void
instance_load_config(void)
{
cfg_load();
* limit is known. For this reason it's allowed to grow unlimited and
* diverge from the size limit imposed by the 'history' option. Setting an
* option in the configuration to the default value of 15 or not setting it
* there at all leaves the directory history size larger than it should be.
* Enforce the expected size here to avoid the history growing unbounded. */
opt_t *history_opt = vle_opts_find("history", OPT_GLOBAL);
assert(history_opt != NULL && "'history' option must be there.");
cfg_resize_histories(history_opt->val.int_val);
}
void
instance_try_choose_files(view_t *view, int nfiles, char *files[])
{
flist_set_marking(view, 1);
if(curr_stats.choose_one)
{
int real_nfiles = nfiles;
if(real_nfiles == 0)
{
dir_entry_t *entry = NULL;
while(iter_marked_entries(view, &entry))
{
++real_nfiles;
}
}
if(real_nfiles > 1)
{
show_error_msgf("File Choosing Error",
"A single-item choice was requested, but %d items are selected.",
real_nfiles);
return;
}
}
vifm_choose_files(view, nfiles, files);
}