[gnome-latex: 187/205] File browser: bug fix (permissions to open dir)
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex: 187/205] File browser: bug fix (permissions to open dir)
- Date: Fri, 14 Dec 2018 11:02:36 +0000 (UTC)
commit 3b0c8fba566eaa8582700cc2e08af7831cd3cfc6
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Mon Jan 25 16:16:57 2010 +0100
File browser: bug fix (permissions to open dir)
TODO | 1 -
src/file_browser.c | 54 +++++++++++++++++++++++++++++++++++-------------------
src/templates.c | 20 ++++++++++----------
src/templates.h | 10 +++++-----
4 files changed, 50 insertions(+), 35 deletions(-)
---
diff --git a/TODO b/TODO
index b59d209..3a60010 100644
--- a/TODO
+++ b/TODO
@@ -2,7 +2,6 @@ TODO LaTeXila
- File browser
- list with all parent directories
- - sort with GtkTreeSortable?
- Some various improvements:
- Make a copy of a file before saving it for the first time (with a name like "file~")
diff --git a/src/file_browser.c b/src/file_browser.c
index 4740980..2d1d79c 100644
--- a/src/file_browser.c
+++ b/src/file_browser.c
@@ -29,7 +29,7 @@
#include "callbacks.h"
#include "external_commands.h"
-static void fill_list_store_with_current_dir (void);
+static void fill_list_store_with_dir (const gchar *directory);
static void cb_go_to_home_dir (GtkButton *button, gpointer user_data);
static void cb_go_to_parent_dir (GtkButton *button, gpointer user_data);
static void cb_jump_dir_current_doc (GtkButton *button, gpointer user_data);
@@ -106,7 +106,7 @@ init_file_browser (GtkWidget *vbox)
G_TYPE_STRING // file
);
- fill_list_store_with_current_dir ();
+ fill_list_store_with_dir (NULL);
GtkWidget *tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
g_object_unref (list_store);
@@ -146,24 +146,48 @@ init_file_browser (GtkWidget *vbox)
void
cb_file_browser_refresh (GtkButton *button, gpointer user_data)
{
- fill_list_store_with_current_dir ();
+ fill_list_store_with_dir (NULL);
}
static void
-fill_list_store_with_current_dir (void)
+fill_list_store_with_dir (const gchar *directory)
{
+ // if directory is NULL, open the current directory
GError *error = NULL;
- GDir *dir = g_dir_open (latexila.prefs.file_browser_dir, 0, &error);
+ GDir *dir;
+ if (directory == NULL)
+ dir = g_dir_open (latexila.prefs.file_browser_dir, 0, &error);
+ else
+ dir = g_dir_open (directory, 0, &error);
+
if (error != NULL)
{
print_warning ("File browser: %s", error->message);
+
+ // warning dialog
+ GtkWidget *dialog = gtk_message_dialog_new (latexila.main_window,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_CLOSE,
+ _("File Browser"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", error->message);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
g_error_free (error);
return;
}
gtk_list_store_clear (list_store);
+ if (directory != NULL)
+ {
+ g_free (latexila.prefs.file_browser_dir);
+ latexila.prefs.file_browser_dir = g_strdup (directory);
+ }
+
/* append all the files contained in the directory */
const gchar *read_name = NULL;
GList *directory_list = NULL;
@@ -261,18 +285,15 @@ fill_list_store_with_current_dir (void)
static void
cb_go_to_home_dir (GtkButton *button, gpointer user_data)
{
- g_free (latexila.prefs.file_browser_dir);
- latexila.prefs.file_browser_dir = g_strdup (g_get_home_dir ());
- fill_list_store_with_current_dir ();
+ fill_list_store_with_dir (g_get_home_dir ());
}
static void
cb_go_to_parent_dir (GtkButton *button, gpointer user_data)
{
gchar *path = g_path_get_dirname (latexila.prefs.file_browser_dir);
- g_free (latexila.prefs.file_browser_dir);
- latexila.prefs.file_browser_dir = path;
- fill_list_store_with_current_dir ();
+ fill_list_store_with_dir (path);
+ g_free (path);
}
static void
@@ -282,9 +303,8 @@ cb_jump_dir_current_doc (GtkButton *button, gpointer user_data)
return;
gchar *path = g_path_get_dirname (latexila.active_doc->path);
- g_free (latexila.prefs.file_browser_dir);
- latexila.prefs.file_browser_dir = path;
- fill_list_store_with_current_dir ();
+ fill_list_store_with_dir (path);
+ g_free (path);
}
static void
@@ -305,11 +325,7 @@ cb_file_browser_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
// open the directory
if (g_file_test (full_path, G_FILE_TEST_IS_DIR))
- {
- g_free (latexila.prefs.file_browser_dir);
- latexila.prefs.file_browser_dir = g_strdup (full_path);
- fill_list_store_with_current_dir ();
- }
+ fill_list_store_with_dir (full_path);
// view the document
else if (g_str_has_suffix (full_path, ".pdf"))
diff --git a/src/templates.c b/src/templates.c
index 5ff5bc3..55e8673 100644
--- a/src/templates.c
+++ b/src/templates.c
@@ -130,7 +130,7 @@ cb_new (void)
if (path != NULL && gtk_tree_model_get_iter (model, &iter, path))
{
gtk_tree_model_get (model, &iter,
- COLUMN_TEMPLATE_CONTENTS, &contents,
+ COL_TEMPLATE_CONTENTS, &contents,
-1);
}
else
@@ -271,7 +271,7 @@ void
init_templates (void)
{
/* default templates */
- default_store = gtk_list_store_new (N_COLUMNS_TEMPLATE,
+ default_store = gtk_list_store_new (N_COLS_TEMPLATE,
GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
add_template_from_string (default_store, _("Empty"),
@@ -307,7 +307,7 @@ init_templates (void)
/* personnal templates */
- personnal_store = gtk_list_store_new (N_COLUMNS_TEMPLATE,
+ personnal_store = gtk_list_store_new (N_COLS_TEMPLATE,
GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
nb_personnal_templates = 0;
@@ -384,9 +384,9 @@ add_template_from_string (GtkListStore *store, const gchar *name,
GtkTreeIter iter;
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
- COLUMN_TEMPLATE_PIXBUF, pixbuf,
- COLUMN_TEMPLATE_NAME, name,
- COLUMN_TEMPLATE_CONTENTS, contents,
+ COL_TEMPLATE_PIXBUF, pixbuf,
+ COL_TEMPLATE_NAME, name,
+ COL_TEMPLATE_CONTENTS, contents,
-1);
g_object_unref (pixbuf);
@@ -423,9 +423,9 @@ create_icon_view (GtkListStore *store)
gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
GTK_SELECTION_SINGLE);
gtk_icon_view_set_text_column (GTK_ICON_VIEW (icon_view),
- COLUMN_TEMPLATE_NAME);
+ COL_TEMPLATE_NAME);
gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icon_view),
- COLUMN_TEMPLATE_PIXBUF);
+ COL_TEMPLATE_PIXBUF);
return icon_view;
}
@@ -512,7 +512,7 @@ save_rc_file (void)
gboolean valid_iter = gtk_tree_model_get_iter_first (model, &iter);
while (valid_iter)
{
- gtk_tree_model_get (model, &iter, COLUMN_TEMPLATE_NAME, names_i, -1);
+ gtk_tree_model_get (model, &iter, COL_TEMPLATE_NAME, names_i, -1);
valid_iter = gtk_tree_model_iter_next (model, &iter);
names_i++;
}
@@ -565,7 +565,7 @@ save_contents (void)
while (valid_iter)
{
gchar *contents;
- gtk_tree_model_get (model, &iter, COLUMN_TEMPLATE_CONTENTS, &contents, -1);
+ gtk_tree_model_get (model, &iter, COL_TEMPLATE_CONTENTS, &contents, -1);
gchar *file = g_strdup_printf ("%s/%d.tex", rc_dir, i);
diff --git a/src/templates.h b/src/templates.h
index 3df3520..a23fe11 100644
--- a/src/templates.h
+++ b/src/templates.h
@@ -1,7 +1,7 @@
/*
* This file is part of LaTeXila.
*
- * Copyright © 2009 Sébastien Wilmet
+ * Copyright © 2009, 2010 Sébastien Wilmet
*
* LaTeXila is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,10 +27,10 @@ void init_templates (void);
enum templates
{
- COLUMN_TEMPLATE_PIXBUF,
- COLUMN_TEMPLATE_NAME,
- COLUMN_TEMPLATE_CONTENTS,
- N_COLUMNS_TEMPLATE
+ COL_TEMPLATE_PIXBUF,
+ COL_TEMPLATE_NAME,
+ COL_TEMPLATE_CONTENTS,
+ N_COLS_TEMPLATE
};
#endif /* TEMPLATES_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]