Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added combo box in plugin configuration to select prefered home direct… #1095

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion treebrowser/src/treebrowser.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ static gboolean CONFIG_SHOW_TREE_LINES = TRUE;
static gboolean CONFIG_SHOW_BOOKMARKS = FALSE;
static gint CONFIG_SHOW_ICONS = 2;
static gboolean CONFIG_OPEN_NEW_FILES = TRUE;
static gint CONFIG_HOME_DIRECTORIES = 0;

/* ------------------
* TREEVIEW STRUCT
Expand Down Expand Up @@ -412,6 +413,20 @@ get_default_dir(void)
return g_get_current_dir();
}

static gchar*
get_project_home_dir(void)
{
GeanyProject *project = geany->app->project;
const gchar *dir;

if (project)
dir = project->base_path;
else
dir = geany->prefs->default_open_path;

return utils_get_locale_from_utf8(dir);
}

static gchar *
get_terminal(void)
{
Expand Down Expand Up @@ -1442,7 +1457,14 @@ on_button_go_home(void)
{
gchar *uri;

uri = g_strdup(g_get_home_dir());
if (CONFIG_HOME_DIRECTORIES == 1) {
// try first project home, then user home
uri = get_project_home_dir();
if (EMPTY(uri)) SETPTR(uri, g_strdup(g_get_home_dir()));
}
else {
uri = g_strdup(g_get_home_dir());
}
treebrowser_chroot(uri);
g_free(uri);
}
Expand Down Expand Up @@ -1997,6 +2019,7 @@ static struct
GtkWidget *SHOW_BOOKMARKS;
GtkWidget *SHOW_ICONS;
GtkWidget *OPEN_NEW_FILES;
GtkWidget *HOME_DIRECTORYIES;
} configure_widgets;

static void
Expand All @@ -2021,6 +2044,7 @@ load_settings(void)
CONFIG_SHOW_BOOKMARKS = utils_get_setting_boolean(config, "treebrowser", "show_bookmarks", CONFIG_SHOW_BOOKMARKS);
CONFIG_SHOW_ICONS = utils_get_setting_integer(config, "treebrowser", "show_icons", CONFIG_SHOW_ICONS);
CONFIG_OPEN_NEW_FILES = utils_get_setting_boolean(config, "treebrowser", "open_new_files", CONFIG_OPEN_NEW_FILES);
CONFIG_HOME_DIRECTORIES = utils_get_setting_integer(config, "treebrowser", "home_directories", CONFIG_HOME_DIRECTORIES);

g_key_file_free(config);
}
Expand Down Expand Up @@ -2055,6 +2079,7 @@ save_settings(void)
g_key_file_set_boolean(config, "treebrowser", "show_bookmarks", CONFIG_SHOW_BOOKMARKS);
g_key_file_set_integer(config, "treebrowser", "show_icons", CONFIG_SHOW_ICONS);
g_key_file_set_boolean(config, "treebrowser", "open_new_files", CONFIG_OPEN_NEW_FILES);
g_key_file_set_integer(config, "treebrowser", "home_directories", CONFIG_HOME_DIRECTORIES);

data = g_key_file_to_data(config, NULL, NULL);
utils_write_file(CONFIG_FILE, data);
Expand Down Expand Up @@ -2088,6 +2113,7 @@ on_configure_response(GtkDialog *dialog, gint response, gpointer user_data)
CONFIG_SHOW_BOOKMARKS = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(configure_widgets.SHOW_BOOKMARKS));
CONFIG_SHOW_ICONS = gtk_combo_box_get_active(GTK_COMBO_BOX(configure_widgets.SHOW_ICONS));
CONFIG_OPEN_NEW_FILES = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(configure_widgets.OPEN_NEW_FILES));
CONFIG_HOME_DIRECTORIES = gtk_combo_box_get_active(GTK_COMBO_BOX(configure_widgets.HOME_DIRECTORYIES));

if (save_settings() == TRUE)
{
Expand Down Expand Up @@ -2169,6 +2195,16 @@ plugin_configure(GtkDialog *dialog)
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 6);
gtk_combo_box_set_active(GTK_COMBO_BOX(configure_widgets.SHOW_ICONS), CONFIG_SHOW_ICONS);

hbox = gtk_hbox_new(FALSE, 0);
label = gtk_label_new(_("Home directory"));
configure_widgets.HOME_DIRECTORYIES = gtk_combo_box_text_new();
gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT(configure_widgets.HOME_DIRECTORYIES), _("User home"));
gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT(configure_widgets.HOME_DIRECTORYIES), _("Project base"));
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 6);
gtk_box_pack_start(GTK_BOX(hbox), configure_widgets.HOME_DIRECTORYIES, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 6);
gtk_combo_box_set_active(GTK_COMBO_BOX(configure_widgets.HOME_DIRECTORYIES), CONFIG_HOME_DIRECTORIES);

configure_widgets.SHOW_HIDDEN_FILES = gtk_check_button_new_with_label(_("Show hidden files"));
#if GTK_CHECK_VERSION(3, 20, 0)
gtk_widget_set_focus_on_click(configure_widgets.SHOW_HIDDEN_FILES, FALSE);
Expand Down