OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
diskview.c File Reference
#include <stdlib.h>
#include <string.h>
#include <gdk/gdkkeysyms.h>
#include "mape/group.h"
#include "mape/fileicon.h"
#include "mape/configfile.h"
#include "mape/mattexview.h"
#include "mape/editview.h"
#include "mape/diskview.h"
Include dependency graph for diskview.c:

Go to the source code of this file.

Functions

MapeDiskViewmape_disk_view_new (MapeFileIconSet *icon_set, MapeMatTexView *mat_tex, MapeEditView *edit_view, MapeConfigFile *config, GError **error)
 
void mape_disk_view_destroy (MapeDiskView *disk_view)
 
gboolean mape_disk_view_extend_to_path (MapeDiskView *disk_view, const gchar *filepath, GError **error)
 

Function Documentation

void mape_disk_view_destroy ( MapeDiskView disk_view)

Definition at line 974 of file diskview.c.

References MapeDiskView_::group_top, and MapeDiskView_::tree_store.

Referenced by mape_window_destroy().

975 {
976  /* Close open groups */
977  GtkTreeIter iter;
978  if(gtk_tree_model_get_iter_first(disk_view->tree_store, &iter))
979  mape_disk_view_close_groups(disk_view, &iter);
980 
981  /* TODO: unref cell renderers? */
982  /*mape_file_icon_set_destroy(disk_view->icon_set);*/
983  g_object_unref(disk_view->group_top);
984 
985  g_object_unref(G_OBJECT(disk_view->tree_store) );
986  free(disk_view);
987 }
MapeGroup * group_top
Definition: diskview.h:53
GtkTreeModel * tree_store
Definition: diskview.h:42

Here is the caller graph for this function:

gboolean mape_disk_view_extend_to_path ( MapeDiskView disk_view,
const gchar *  filepath,
GError **  error 
)

Definition at line 989 of file diskview.c.

References MAPE_DISK_VIEW_ERROR_NOENT, MapeDiskView_::tree_store, and MapeDiskView_::view.

Referenced by mape_window_new().

992 {
993  gchar** path_components;
994  gchar** cur_component;
995  gchar* file;
996  GtkTreeIter parent;
997  GtkTreeIter child;
998  gboolean result;
999  GtkTreePath* path;
1000  gboolean got_parent;
1001 
1002  path_components = g_strsplit_set(filepath, "/\\", 0);
1003 
1004  /* Begin at top-level: no parent */
1005  got_parent = FALSE;
1006 
1007  for(cur_component = path_components;
1008  *cur_component != NULL;
1009  ++ cur_component)
1010  {
1011  file = *cur_component;
1012  if(*file == '\0') continue;
1013  if(strcmp(file, ".") == 0) continue;
1014 
1015  if(strcmp(file, "..") == 0)
1016  {
1017  if(got_parent == FALSE)
1018  {
1019  g_set_error(
1020  error,
1021  g_quark_from_static_string(
1022  "MAPE_DISK_VIEW_ERROR"
1023  ),
1025  "%s: Invalid path",
1026  filepath
1027  );
1028 
1029  g_strfreev(path_components);
1030  return FALSE;
1031  }
1032  else
1033  {
1034  child = parent;
1035 
1036  got_parent = gtk_tree_model_iter_parent(
1037  GTK_TREE_MODEL(disk_view->tree_store),
1038  &parent,
1039  &child
1040  );
1041  }
1042  }
1043  else
1044  {
1045  if(got_parent == FALSE)
1046  {
1047  result = mape_disk_view_find_iter(
1048  disk_view,
1049  &child,
1050  NULL,
1051  file
1052  );
1053  }
1054  else
1055  {
1056  result = mape_disk_view_find_iter(
1057  disk_view,
1058  &child,
1059  &parent,
1060  file
1061  );
1062  }
1063 
1064  /* File is not reachable in file system */
1065  if(result == FALSE)
1066  {
1067  g_set_error(
1068  error,
1069  g_quark_from_static_string(
1070  "MAPE_DISK_VIEW_ERROR"
1071  ),
1073  "%s: No such file or directory",
1074  filepath
1075  );
1076 
1077  g_strfreev(path_components);
1078  return FALSE;
1079  }
1080 
1081  if(g_ascii_strcasecmp(file, "Material.ocg") == 0)
1082  {
1083  /* Assume end of path */
1084  result = mape_disk_view_load_materials(
1085  disk_view,
1086  &child,
1087  error
1088  );
1089 
1090  g_strfreev(path_components);
1091  return result;
1092  }
1093  else
1094  {
1095  /* Convert child to path to preserve
1096  position while expanding */
1097  path = gtk_tree_model_get_path(
1098  disk_view->tree_store,
1099  &child
1100  );
1101 
1102  gtk_tree_view_expand_row(
1103  GTK_TREE_VIEW(disk_view->view),
1104  path,
1105  FALSE
1106  );
1107 
1108  /* Child is new parent for next iteration */
1109  gtk_tree_model_get_iter(
1110  disk_view->tree_store,
1111  &parent,
1112  path
1113  );
1114  got_parent = TRUE;
1115 
1116  gtk_tree_path_free(path);
1117  }
1118  }
1119  }
1120 
1121  /* All nodes expanded without opening Material.ocg */
1122  g_strfreev(path_components);
1123  return TRUE;
1124 }
GtkWidget * view
Definition: diskview.h:40
GtkTreeModel * tree_store
Definition: diskview.h:42

Here is the caller graph for this function:

MapeDiskView* mape_disk_view_new ( MapeFileIconSet icon_set,
MapeMatTexView mat_tex,
MapeEditView edit_view,
MapeConfigFile config,
GError **  error 
)

Definition at line 823 of file diskview.c.

References MapeDiskView_::col_file, MapeDiskView_::config, MapeDiskView_::edit_view, MapeDiskView_::group_top, MapeDiskView_::icon_set, MAPE_DISK_VIEW_COLUMN_COUNT, MAPE_DISK_VIEW_COLUMN_FILE, MAPE_DISK_VIEW_COLUMN_ICON, MapeDiskView_::mat_tex, MapeDiskView_::renderer_file, MapeDiskView_::renderer_icon, MapeDiskView_::tree_store, MapeDiskView_::view, and MapeDiskView_::window.

Referenced by mape_window_new().

828 {
829  MapeDiskView* view;
830 
831  view = malloc(sizeof(MapeDiskView) );
832 
833  view->group_top = NULL;
834  view->icon_set = icon_set;
835  view->mat_tex = mat_tex;
836  view->edit_view = edit_view;
837  view->config = config;
838 
839  view->tree_store = GTK_TREE_MODEL(
840  gtk_tree_store_new(
842  GDK_TYPE_PIXBUF,
843  G_TYPE_STRING,
844  G_TYPE_POINTER
845  )
846  );
847 
848  view->renderer_icon = gtk_cell_renderer_pixbuf_new();
849  view->renderer_file = gtk_cell_renderer_text_new();
850 
851  /*view->col_icon = gtk_tree_view_column_new_with_attributes(
852  "Icon",
853  view->renderer_icon,
854  "pixbuf", MAPE_DISK_VIEW_COLUMN_ICON,
855  NULL
856  );*/
857 
858  view->col_file = gtk_tree_view_column_new();
859 
860 /* view->col_file = gtk_tree_view_column_new_with_attributes(
861  "Filename",
862  view->renderer_file,
863  "text", MAPE_DISK_VIEW_COLUMN_FILE,
864  "pixbuf", MAPE_DISK_VIEW_COLUMN_ICON,
865  NULL
866  );*/
867 
868  gtk_tree_view_column_pack_start(
869  view->col_file,
870  view->renderer_icon,
871  FALSE
872  );
873 
874  gtk_tree_view_column_pack_start(
875  view->col_file,
876  view->renderer_file,
877  TRUE
878  );
879 
880  gtk_tree_view_column_set_attributes(
881  view->col_file,
882  view->renderer_icon,
883  "pixbuf", MAPE_DISK_VIEW_COLUMN_ICON,
884  NULL
885  );
886 
887  gtk_tree_view_column_set_attributes(
888  view->col_file,
889  view->renderer_file,
891  NULL
892  );
893 
894  gtk_tree_view_column_set_spacing(
895  view->col_file,
896  5
897  );
898 
899  view->view = gtk_tree_view_new_with_model(
900  GTK_TREE_MODEL(view->tree_store)
901  );
902 
903  gtk_widget_add_events(
904  view->view,
905  GDK_BUTTON_PRESS_MASK |
906  GDK_KEY_PRESS_MASK
907  );
908 
909  gtk_tree_view_append_column(GTK_TREE_VIEW(view->view), view->col_file);
910 
911  gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view->view), FALSE);
912  gtk_tree_sortable_set_sort_column_id(
913  GTK_TREE_SORTABLE(view->tree_store),
915  GTK_SORT_ASCENDING
916  );
917 
918  g_signal_connect(
919  G_OBJECT(view->view),
920  "row-expanded",
921  G_CALLBACK(mape_disk_view_cb_row_expanded),
922  view
923  );
924 
925  g_signal_connect(
926  G_OBJECT(view->view),
927  "button-press-event",
928  G_CALLBACK(mape_disk_view_cb_button_press_event),
929  view
930  );
931 
932  g_signal_connect(
933  G_OBJECT(view->view),
934  "key-press-event",
935  G_CALLBACK(mape_disk_view_cb_key_press_event),
936  view
937  );
938 
939  if(mape_disk_view_load(view, NULL, error) == FALSE)
940  {
941  /* TODO: Free cell renderers? */
942  gtk_widget_destroy(view->view);
943  g_object_unref(G_OBJECT(view->tree_store) );
944 
945  free(view);
946  return NULL;
947  }
948 
949  gtk_widget_show(view->view);
950 
951  view->window = gtk_scrolled_window_new(NULL, NULL);
952  gtk_container_add(
953  GTK_CONTAINER(view->window),
954  view->view
955  );
956 
957  gtk_scrolled_window_set_policy(
958  GTK_SCROLLED_WINDOW(view->window),
959  GTK_POLICY_AUTOMATIC,
960  GTK_POLICY_AUTOMATIC
961  );
962 
963  gtk_scrolled_window_set_shadow_type(
964  GTK_SCROLLED_WINDOW(view->window),
965  GTK_SHADOW_IN
966  );
967 
968  gtk_widget_set_size_request(view->window, 150, -1);
969  gtk_widget_show(view->window);
970 
971  return view;
972 }
GtkTreeViewColumn * col_file
Definition: diskview.h:47
MapeGroup * group_top
Definition: diskview.h:53
GtkCellRenderer * renderer_file
Definition: diskview.h:45
GtkWidget * view
Definition: diskview.h:40
MapeConfigFile * config
Definition: diskview.h:54
GtkCellRenderer * renderer_icon
Definition: diskview.h:44
GtkWidget * window
Definition: diskview.h:39
MapeMatTexView * mat_tex
Definition: diskview.h:49
GtkTreeModel * tree_store
Definition: diskview.h:42
MapeEditView * edit_view
Definition: diskview.h:50
MapeFileIconSet * icon_set
Definition: diskview.h:52

Here is the caller graph for this function: