[gnome-latex: 104/205] File browser integrated



commit 478ad7f7c2e8611b1f969fc3988f8d2ec0d1df15
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Sat Nov 7 22:49:51 2009 +0100

    File browser integrated
    
    The hidden files (beginning with a point) are ignored.
    
    CMake 2.6.4 minimum is now required. When we type "make", the
    translations are build, so we can avoid typing "make translations".
    
    I have forgotten to include the GPL header in some *.h files.

 CMakeLists.txt          |   9 +--
 TODO                    |   3 +-
 src/CMakeLists.txt      |   3 +-
 src/cb_latex.c          |   1 +
 src/cb_latex.h          |  19 +++++
 src/external_commands.h |  19 +++++
 src/file_browser.c      | 184 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/file_browser.h      |  32 +++++++++
 src/main.c              |  11 +--
 src/main.h              |  15 +++-
 src/prefs.h             |  19 +++++
 src/symbols.c           |   2 -
 src/symbols.h           |  21 ++++++
 src/ui.h                |  19 +++++
 14 files changed, 340 insertions(+), 17 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5dc97fa..178aae8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,11 +1,11 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6.2)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6.4)
 
 PROJECT(latexila)
 
 # version
 SET(latexila_MAJOR 0)
 SET(latexila_MINOR 0)
-SET(latexila_PATCH 2)
+SET(latexila_PATCH "2.99")
 SET(latexila_VERSION ${latexila_MAJOR}.${latexila_MINOR}.${latexila_PATCH})
 
 MESSAGE(STATUS "*** Building LaTeXila ${latexila_VERSION} ***")
@@ -24,10 +24,7 @@ IF(ENABLE_NLS)
   MESSAGE(STATUS "Native language support enabled.")
   FIND_PACKAGE(Gettext REQUIRED)
   FILE(GLOB latexila_PO_FILES ${latexila_SOURCE_DIR}/po/*.po)
-  GETTEXT_CREATE_TRANSLATIONS(po/latexila.pot ${latexila_PO_FILES})
-  # with ALL it doesn't work, wait the new version of FindGettext module...
-  # so we must run "make translations"
-  #GETTEXT_CREATE_TRANSLATIONS(po/latexila.pot ALL ${latexila_PO_FILES})
+  GETTEXT_CREATE_TRANSLATIONS(po/latexila.pot ALL ${latexila_PO_FILES})
 ELSE(ENABLE_NLS)
   MESSAGE(STATUS "Native language support disabled.")
 ENDIF(ENABLE_NLS)
diff --git a/TODO b/TODO
index ec23a59..ecd1acc 100644
--- a/TODO
+++ b/TODO
@@ -2,7 +2,8 @@ TODO LaTeXila
 
 [-] File browser in the side bar
        x tabs to switch between "Symbols" and "File Browser"
-       - file browser integrated
+       x file browser integrated
+       - sort the files in alphabetical order
 
 [-] Templates
        - create a few default templates
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 076da59..3d3f22a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -6,7 +6,8 @@ SET(latexila_src main.c                 main.h
                 external_commands.c    external_commands.h
                 prefs.c                prefs.h
                 ui.c                   ui.h
-                tool_menu_action.c     tool_menu_action.h)
+                tool_menu_action.c     tool_menu_action.h
+                file_browser.c         file_browser.h)
 ADD_EXECUTABLE(latexila ${latexila_src})
 TARGET_LINK_LIBRARIES(latexila ${GTK2_LIBRARIES})
 
diff --git a/src/cb_latex.c b/src/cb_latex.c
index 8751783..9537fa2 100644
--- a/src/cb_latex.c
+++ b/src/cb_latex.c
@@ -25,6 +25,7 @@
 #include "main.h"
 #include "config.h"
 #include "print.h"
+#include "cb_latex.h"
 
 static void text_buffer_insert (gchar *text_before, gchar *text_after,
                gchar *text_if_no_selection);
diff --git a/src/cb_latex.h b/src/cb_latex.h
index 0cf9589..e2c73b9 100644
--- a/src/cb_latex.h
+++ b/src/cb_latex.h
@@ -1,3 +1,22 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright © 2009 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila 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 LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef CB_LATEX_H
 #define CB_LATEX_H
 
diff --git a/src/external_commands.h b/src/external_commands.h
index a207049..26db6b2 100644
--- a/src/external_commands.h
+++ b/src/external_commands.h
@@ -1,3 +1,22 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright © 2009 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila 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 LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef EXTERNAL_COMMANDS_H
 #define EXTERNAL_COMMANDS_H
 
diff --git a/src/file_browser.c b/src/file_browser.c
new file mode 100644
index 0000000..e1ff9fc
--- /dev/null
+++ b/src/file_browser.c
@@ -0,0 +1,184 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright © 2009 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila 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 LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <locale.h>
+#include <libintl.h>
+#include <string.h> // for strcmp
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksourceview.h>
+
+#include "main.h"
+#include "config.h"
+#include "print.h"
+#include "file_browser.h"
+#include "callbacks.h"
+
+static void fill_list_store_with_current_dir (void);
+static void cb_file_browser_row_activated (GtkTreeView *tree_view,
+               GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data);
+
+void
+init_file_browser (void)
+{
+       GtkListStore *store = gtk_list_store_new (N_COLUMNS_FILE_BROWSER,
+                       GDK_TYPE_PIXBUF, G_TYPE_STRING);
+       latexila.file_browser.list_store = store;
+       latexila.file_browser.current_dir = g_strdup (g_get_home_dir ());
+
+       fill_list_store_with_current_dir ();
+
+       GtkWidget *tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
+       g_signal_connect (G_OBJECT (tree_view), "row-activated",
+                       G_CALLBACK (cb_file_browser_row_activated), NULL);
+       
+       GtkCellRenderer *renderer;
+       GtkTreeViewColumn *column;
+
+       renderer = gtk_cell_renderer_pixbuf_new ();
+       column = gtk_tree_view_column_new_with_attributes (NULL, renderer, "pixbuf",
+                       COLUMN_FILE_BROWSER_PIXBUF, NULL);
+       gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
+
+       renderer = gtk_cell_renderer_text_new ();
+       column = gtk_tree_view_column_new_with_attributes (NULL, renderer, "text",
+                       COLUMN_FILE_BROWSER_FILE, NULL);
+       gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
+
+       gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
+
+       // with a scrollbar
+       GtkWidget *scrollbar = gtk_scrolled_window_new (NULL, NULL);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollbar),
+                       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+       gtk_container_add (GTK_CONTAINER (scrollbar), tree_view);
+       gtk_box_pack_start (GTK_BOX (latexila.file_browser.vbox), scrollbar,
+                       TRUE, TRUE, 0);
+}
+
+static void
+fill_list_store_with_current_dir (void)
+{
+       GError *error = NULL;
+       GDir *dir = g_dir_open (latexila.file_browser.current_dir, 0, &error);
+       if (error != NULL)
+       {
+               print_warning ("File browser: %s", error->message);
+               g_error_free (error);
+
+               // avoid infinite loop
+               if (strcmp (latexila.file_browser.current_dir, g_get_home_dir ()) == 0)
+                       return;
+
+               g_free (latexila.file_browser.current_dir);
+               latexila.file_browser.current_dir = g_strdup (g_get_home_dir ());
+               fill_list_store_with_current_dir ();
+               return;
+       }
+
+       gtk_list_store_clear (latexila.file_browser.list_store);
+
+       GtkTreeIter iter;
+
+       // get the pixbufs
+       GdkPixbuf *pixbuf_dir = gtk_widget_render_icon (latexila.side_pane,
+                       GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
+       GdkPixbuf *pixbuf_file = gtk_widget_render_icon (latexila.side_pane,
+                       GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
+
+       // append first the parent directory
+       gtk_list_store_append (latexila.file_browser.list_store, &iter);
+       gtk_list_store_set (latexila.file_browser.list_store, &iter,
+                       COLUMN_FILE_BROWSER_PIXBUF, pixbuf_dir,
+                       COLUMN_FILE_BROWSER_FILE, "..",
+                       -1);
+
+       // append all the files contained in the directory
+       const gchar *read_name = NULL;
+       while ((read_name = g_dir_read_name (dir)) != NULL)
+       {
+               // not show hidden files
+               if (read_name[0] == '.')
+                       continue;
+
+               gchar *full_path = g_build_filename (latexila.file_browser.current_dir,
+                               read_name, NULL);
+
+               GdkPixbuf *pixbuf;
+               if (g_file_test (full_path, G_FILE_TEST_IS_DIR))
+                       pixbuf = pixbuf_dir;
+               else
+                       pixbuf = pixbuf_file;
+
+               gtk_list_store_append (latexila.file_browser.list_store, &iter);
+               gtk_list_store_set (latexila.file_browser.list_store, &iter,
+                               COLUMN_FILE_BROWSER_PIXBUF, pixbuf,
+                               COLUMN_FILE_BROWSER_FILE, read_name,
+                               -1);
+
+               g_free (full_path);
+       }
+
+       g_object_unref (pixbuf_dir);
+       g_object_unref (pixbuf_file);
+       g_dir_close (dir);
+}
+
+static void
+cb_file_browser_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
+               GtkTreeViewColumn *column, gpointer user_data)
+{
+       GtkTreeIter iter;
+       GtkTreeModel *model = GTK_TREE_MODEL (latexila.file_browser.list_store);
+       gtk_tree_model_get_iter (model, &iter, path);
+       
+       gchar *file = NULL;
+       gtk_tree_model_get (model, &iter, COLUMN_FILE_BROWSER_FILE, &file, -1);
+
+       gchar *full_path = g_build_filename (latexila.file_browser.current_dir,
+                       file, NULL);
+
+       // open the directory
+       if (g_file_test (full_path, G_FILE_TEST_IS_DIR))
+       {
+               g_free (latexila.file_browser.current_dir);
+               latexila.file_browser.current_dir = full_path;
+               fill_list_store_with_current_dir ();
+       }
+
+       // 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);
+
+               g_free (full_path);
+               g_free (uri);
+       }
+}
diff --git a/src/file_browser.h b/src/file_browser.h
new file mode 100644
index 0000000..bf6c313
--- /dev/null
+++ b/src/file_browser.h
@@ -0,0 +1,32 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright © 2009 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila 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 LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef FILE_BROWSER_H
+#define FILE_BROWSER_H
+
+void init_file_browser (void);
+
+enum
+{
+       COLUMN_FILE_BROWSER_PIXBUF,
+       COLUMN_FILE_BROWSER_FILE,
+       N_COLUMNS_FILE_BROWSER
+};
+
+#endif /* FILE_BROWSER_H */
diff --git a/src/main.c b/src/main.c
index 1179b3e..e0c7aa7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -30,6 +30,7 @@
 #include "config.h"
 #include "callbacks.h"
 #include "symbols.h"
+#include "file_browser.h"
 #include "print.h"
 #include "prefs.h"
 #include "ui.h"
@@ -157,7 +158,7 @@ main (int argc, char *argv[])
        init_ui (main_vbox);
        
        /* horizontal pane
-        * left: side pane (symbol tables and the file navigator)
+        * left: side pane (symbol tables and the file browser)
         * right: the source view and the log zone
         */
        GtkWidget *main_hpaned = gtk_hpaned_new ();
@@ -187,8 +188,9 @@ main (int argc, char *argv[])
                        tab_label);
        init_symbols ();
 
-       // file navigator
-       GtkWidget *vbox_file_navigator = gtk_vbox_new (FALSE, 0);
+       // file browser
+       GtkWidget *vbox_file_browser = gtk_vbox_new (FALSE, 0);
+       latexila.file_browser.vbox = vbox_file_browser;
 
        tab_label = gtk_hbox_new (FALSE, 3);
        label = gtk_label_new (_("File Browser"));
@@ -199,7 +201,8 @@ main (int argc, char *argv[])
        gtk_widget_show_all (tab_label);
 
        gtk_notebook_append_page (GTK_NOTEBOOK (side_pane_notebook),
-                       vbox_file_navigator, tab_label);
+                       vbox_file_browser, tab_label);
+       init_file_browser ();
 
        /* vertical pane
         * top: source view
diff --git a/src/main.h b/src/main.h
index 1a1d567..df622eb 100644
--- a/src/main.h
+++ b/src/main.h
@@ -57,11 +57,19 @@ typedef struct
 // symbols tables
 typedef struct
 {
-       GtkWidget                       *vbox;
-       GtkListStore            *list_stores[7];
-       GtkIconView                     *icon_view;
+       GtkWidget               *vbox;
+       GtkListStore    *list_stores[7];
+       GtkIconView             *icon_view;
 } symbols_t;
 
+// file browser
+typedef struct
+{
+       GtkWidget               *vbox;
+       GtkListStore    *list_store;
+       gchar                   *current_dir;
+} file_browser_t;
+
 // preferences, settings
 typedef struct
 {
@@ -105,6 +113,7 @@ typedef struct
        document_t              *active_doc;
        action_log_t    action_log;
        symbols_t               symbols;
+       file_browser_t  file_browser;
        preferences_t   prefs;
        actions_t               actions;
        GtkWindow               *main_window;
diff --git a/src/prefs.h b/src/prefs.h
index 0ca6a9e..af638f2 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -1,3 +1,22 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright © 2009 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila 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 LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef PREFS_H
 #define PREFS_H
 
diff --git a/src/symbols.c b/src/symbols.c
index 2d0922a..b0f00dd 100644
--- a/src/symbols.c
+++ b/src/symbols.c
@@ -23,8 +23,6 @@
 #include <libintl.h>
 #include <gtk/gtk.h>
 #include <gtksourceview/gtksourceview.h>
-#include <gtksourceview/gtksourcelanguage.h>
-#include <gtksourceview/gtksourcelanguagemanager.h>
 
 #include "main.h"
 #include "config.h"
diff --git a/src/symbols.h b/src/symbols.h
index a8a0c2f..0f5138a 100644
--- a/src/symbols.h
+++ b/src/symbols.h
@@ -1,7 +1,28 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright © 2009 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila 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 LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef SYMBOLS_H
 #define SYMBOLS_H
 
 void init_symbols (void);
+
+//TODO this callbacks are used only in symbols.c => static
 void cb_category_symbols_selected (GtkIconView *icon_view, gpointer user_data);
 void cb_symbol_selected (GtkIconView *icon_view, gpointer user_data);
 
diff --git a/src/ui.h b/src/ui.h
index 3c19cca..92b480f 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -1,3 +1,22 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright © 2009 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila 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 LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifndef UI_H
 #define UI_H
 


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