[gnome-latex: 121/205] New function open_new_document_without_uri ()



commit 22d18d21546acf2be6b9fcb112586d9933776592
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Tue Nov 17 19:00:24 2009 +0100

    New function open_new_document_without_uri ()

 src/callbacks.c    | 18 ++++++++++++++++++
 src/callbacks.h    |  1 +
 src/file_browser.c | 19 +++----------------
 src/main.c         | 26 ++------------------------
 4 files changed, 24 insertions(+), 40 deletions(-)
---
diff --git a/src/callbacks.c b/src/callbacks.c
index a18a127..14fa81c 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -821,6 +821,24 @@ cb_show_edit_toolbar (GtkToggleAction *toggle_action, gpointer user_data)
                gtk_widget_hide (latexila.edit_toolbar);
 }
 
+void
+open_new_document_without_uri (const gchar *filename)
+{
+       GError *error = NULL;
+
+       gchar *uri = g_filename_to_uri (filename, NULL, &error);
+       if (error != NULL)
+       {
+               print_warning ("can not open the file \"%s\": %s", filename,
+                               error->message);
+               g_error_free (error);
+       }
+       else
+               open_new_document (filename, uri);
+
+       g_free (uri);
+}
+
 void
 open_new_document (const gchar *filename, const gchar *uri)
 {
diff --git a/src/callbacks.h b/src/callbacks.h
index 4990c30..9ed7d17 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -62,6 +62,7 @@ void cb_recent_item_activated (GtkRecentAction *action, gpointer user_data);
 void cb_show_side_pane (GtkToggleAction *toggle_action, gpointer user_data);
 void cb_show_edit_toolbar (GtkToggleAction *toggle_action, gpointer user_data);
 
+void open_new_document_without_uri (const gchar *filename);
 void open_new_document (const gchar *filename, const gchar *uri);
 void change_font_source_view (void);
 
diff --git a/src/file_browser.c b/src/file_browser.c
index ada56d9..39e4e6a 100644
--- a/src/file_browser.c
+++ b/src/file_browser.c
@@ -285,7 +285,7 @@ cb_file_browser_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
        if (g_file_test (full_path, G_FILE_TEST_IS_DIR))
        {
                g_free (latexila.prefs.file_browser_dir);
-               latexila.prefs.file_browser_dir = full_path;
+               latexila.prefs.file_browser_dir = g_strdup (full_path);
                fill_list_store_with_current_dir ();
        }
 
@@ -299,22 +299,9 @@ cb_file_browser_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
 
        // open the file
        else
-       {
-               GError *error = NULL;
-               gchar *uri = g_filename_to_uri (full_path, NULL, &error);
-               if (error != NULL)
-               {
-                       print_warning ("can not open the file \"%s\": %s", full_path,
-                                       error->message);
-                       g_error_free (error);
-                       error = NULL;
-               }
-               else
-                       open_new_document (full_path, uri);
+               open_new_document_without_uri (full_path);
 
-               g_free (full_path);
-               g_free (uri);
-       }
+       g_free (full_path);
 }
 
 static gint
diff --git a/src/main.c b/src/main.c
index 0f2338d..0f8312c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -317,18 +317,7 @@ main (int argc, char *argv[])
                        && latexila.prefs.reopen_files_on_startup ; i++)
        {
                gchar *path = latexila.prefs.list_opened_docs[i];
-               gchar *uri = g_filename_to_uri (path, NULL, &error);
-               if (error != NULL)
-               {
-                       print_warning ("can not open the file \"%s\": %s", path,
-                                       error->message);
-                       g_error_free (error);
-                       error = NULL;
-               }
-               else
-                       open_new_document (path, uri);
-
-               g_free (uri);
+               open_new_document_without_uri (path);
        }
 
        /* if --new-document option is used */
@@ -348,19 +337,8 @@ main (int argc, char *argv[])
                        g_free (current_dir);
                }
 
-               gchar *uri = g_filename_to_uri (path, NULL, &error);
-               if (error != NULL)
-               {
-                       print_warning ("can not open the file \"%s\": %s", argv[i],
-                                       error->message);
-                       g_error_free (error);
-                       error = NULL;
-               }
-               else
-                       open_new_document (path, uri);
-
+               open_new_document_without_uri (path);
                g_free (path);
-               g_free (uri);
        }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]