From a1a526ea5939d544aa27991919dea123dc473848 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Mon, 21 Jun 1999 10:07:24 +0000 Subject: [PATCH] r16: Started code for handling application directories. --- ROX-Filer/pixmaps/application.xpm | 141 ++++++++++++++++++++++-------- ROX-Filer/src/apps.c | 16 ++++ ROX-Filer/src/apps.h | 8 ++ ROX-Filer/src/dnd.c | 179 ++++++++++++++++++++++++++++++++++++++ ROX-Filer/src/dnd.h | 19 ++++ ROX-Filer/src/filer.c | 26 +++++- 6 files changed, 352 insertions(+), 37 deletions(-) rewrite ROX-Filer/pixmaps/application.xpm (96%) create mode 100644 ROX-Filer/src/apps.c create mode 100644 ROX-Filer/src/apps.h create mode 100644 ROX-Filer/src/dnd.c create mode 100644 ROX-Filer/src/dnd.h diff --git a/ROX-Filer/pixmaps/application.xpm b/ROX-Filer/pixmaps/application.xpm dissimilarity index 96% index 07f0c83d..e2d75d66 100644 --- a/ROX-Filer/pixmaps/application.xpm +++ b/ROX-Filer/pixmaps/application.xpm @@ -1,34 +1,107 @@ -/* XPM */ -static char * application_xpm[] = { -"44 28 3 1", -" c None", -". c #000000000000", -"X c #FFFFFFFFFFFF", -" ", -" ", -" ", -" ", -" .. ", -" .XX. ", -" .XX. ", -" .XXXX. ", -" .XXXX. ", -" .XX..XX. ", -" .XX..XX. ", -" .XX. .XX. ", -" .XX. .XX. ...... ...... ", -" .XX. ..XX. .XXXXX. .XXXXX. ", -" .XX. .XX. .XXXXXX. .XXXXXX. ", -" .XX. .XX. .XX..XXX..XX..XXX.", -" .XX........XX. .XX. .XX..XX. .XX.", -" .XXXXXXXXXXXXXX. .XX. .XX..XX. .XX.", -" .XXXXXXXXXXXXXX. .XX..XXX..XX..XXX.", -" .XXX..........XXX. .XXXXXX. .XXXXXX. ", -" .XX. .XX. .XXXXX. .XXXXX. ", -" .XXX. .XXX. .XX... .XX... ", -" .XX. .XX. .XX. .XX. ", -" .XXX. .XXX. .XX. .XX. ", -" .XX. .XX. .XX. .XX. ", -"..XXX.. ..XXX...XX. .XX. ", -".XXXXX. .XXXXX..XX. .XX. ", -"....... ........... .... "}; +/* XPM */ +static char * application_xpm[] = { +"44 24 80 1", +" c None", +". c #DCA4A4", +"+ c #FF0000", +"@ c #F04646", +"# c #F52F2F", +"$ c #000000", +"% c #464646", +"& c #F91717", +"* c #FA1111", +"= c #380000", +"- c #2F2F2F", +"; c #E67575", +"> c #FD0505", +", c #E82929", +"' c #550000", +") c #E18C8C", +"! c #D7BBBB", +"~ c #EB5E5E", +"{ c #FE0101", +"] c #EA6464", +"^ c #651010", +"/ c #8D0000", +"( c #010101", +"_ c #A5A5A5", +": c #EC5858", +"< c #F62626", +"[ c #757575", +"} c #AA0000", +"| c #8D8D8D", +"1 c #E41F1F", +"2 c #832F2F", +"3 c #933E3E", +"4 c #BBBBBB", +"5 c #C13434", +"6 c #A34E4E", +"7 c #FE0404", +"8 c #BFB0B0", +"9 c #171717", +"0 c #311515", +"a c #E20000", +"b c #5E5E5E", +"c c #E13737", +"d c #F13D3D", +"e c #E28585", +"f c #A4A4A4", +"g c #474747", +"h c #B25E5E", +"i c #8C8C8C", +"j c #D82F2F", +"k c #E83E3E", +"l c #B90F0F", +"m c #1C0000", +"n c #D40F0F", +"o c #C11717", +"p c #710000", +"q c #B10808", +"r c #F62929", +"s c #982727", +"t c #EA0808", +"u c #E67373", +"v c #F91A1A", +"w c #6E3737", +"x c #E38484", +"y c #D3D3D3", +"z c #997D7D", +"A c #020202", +"B c #D2D2D2", +"C c #D6BBBB", +"D c #030303", +"E c #191919", +"F c #D27D7D", +"G c #BCBCBC", +"H c #BDBDBD", +"I c #B8B8B8", +"J c #560000", +"K c #C60000", +"L c #A66E6E", +"M c #A90000", +"N c #BF4E4E", +"O c #767676", +" .++@ ", +" #++# ", +" .++++$% ", +" &*@++=- ", +" ;+>,++'$ .)@ !~@~! );; .@@; ", +" !&{]^++/(_ #+++#~++++# .&+++~#++++; ", +" :+<['++}(| !;+++12;+++34 .@+++56@+++[ ", +" !+7890++a(b )++/$-b/++}- c++=$b-a++'[ ", +" d+eb$f+++(g ~++'$$-h++}$i &++$$$bj++'$ ", +" .++k}l@+++=9 @++m$b )++}$% ++n$$f @++'$i", +" #+@o}c@&++'$ &++$$i )++p$%.++q$$ @++m$i", +" ;+rf$$%%s++/$f ++n$$4 @++=$%)++p$- ++t$$i", +" &+u-$%%%2++}$i .++q$$ ++1$$[~++'$% )++s$$4", +";+v[$b ++a$b )++'$- ~++w((_@++$$[ &+&($9 ", +"++x9$4 +++$% ~++p$%;++)$(-y&++m$z@+&z(A[ ", +"+++'[ @+++++q @++++++#.b$(fB+++++++~C9DE ", +"))'m .)))''= +++='6.y[$$| )++q''F!G%$9H ", +" $$$i g(((((++o($$$$$-f )++'($$(($bI ", +" iii4 _||||h++}($fiif @++'(%i||4 ", +" )++JAg @++($i ", +" !~&++K}s .@+++}}L ", +" .@@@jM}N ;@@@o}}. ", +" 4b9$$-g[ f%$$$%%_ ", +" f%%%%%gO [%%%%%%_ "}; diff --git a/ROX-Filer/src/apps.c b/ROX-Filer/src/apps.c new file mode 100644 index 00000000..a4acb714 --- /dev/null +++ b/ROX-Filer/src/apps.c @@ -0,0 +1,16 @@ +/* vi: set cindent: + * $Id$ + * + * ROX-Filer, filer for the ROX desktop project + * By Thomas Leonard, . + */ + +/* apps.c - code for handling application directories */ + +#include "gui_support.h" + +/* An application has been double-clicked (or run in some other way) */ +void run_app(char *path) +{ + report_error("run_app", "Running app..."); +} diff --git a/ROX-Filer/src/apps.h b/ROX-Filer/src/apps.h new file mode 100644 index 00000000..0f46b61d --- /dev/null +++ b/ROX-Filer/src/apps.h @@ -0,0 +1,8 @@ +/* vi: set cindent: + * $Id$ + * + * ROX-Filer, filer for the ROX desktop project + * By Thomas Leonard, . + */ + +void run_app(char *path); diff --git a/ROX-Filer/src/dnd.c b/ROX-Filer/src/dnd.c new file mode 100644 index 00000000..cec79709 --- /dev/null +++ b/ROX-Filer/src/dnd.c @@ -0,0 +1,179 @@ +/* vi: set cindent: + * $Id$ + * + * ROX-Filer, filer for the ROX desktop project + * By Thomas Leonard, . + */ + +/* dnd.c - code for handling drag and drop */ + +#include +#include + +#include +#include +#include +#include + +#include "filer.h" +#include "pixmaps.h" +#include "gui_support.h" +#include "support.h" + +enum +{ + TARGET_RAW, + TARGET_URI_LIST, + TARGET_XDS, +}; + +/* Static prototypes */ +static void create_uri_list(GString *string, + Collection *collection, + FilerWindow *filer_window); +static FileItem *selected_item(Collection *collection); + + +static FileItem *selected_item(Collection *collection) +{ + int i; + + g_return_val_if_fail(collection != NULL, NULL); + g_return_val_if_fail(IS_COLLECTION(collection), NULL); + g_return_val_if_fail(collection->number_selected == 1, NULL); + + for (i = 0; i < collection->number_of_items; i++) + if (collection->items[i].selected) + return (FileItem *) collection->items[i].data; + + g_warning("selected_item: number_selected is wrong\n"); + + return NULL; +} + +/* The user has held the mouse button down over an item and moved - + * start a drag. + */ +void drag_selection(Collection *collection, + GdkEventMotion *event, + gint number_selected, + gpointer user_data) +{ + FilerWindow *filer_window = (FilerWindow *) user_data; + GtkWidget *widget; + MaskedPixmap *image; + GdkDragContext *context; + GtkTargetList *target_list; + GtkTargetEntry target_table[] = + { + {"text/uri-list", 0, TARGET_URI_LIST}, + {"application/octet-stream", 0, TARGET_RAW}, + }; + + widget = GTK_WIDGET(collection); + + target_list = gtk_target_list_new(target_table, + number_selected == 1 ? 2 : 1); + + context = gtk_drag_begin(widget, + target_list, + GDK_ACTION_COPY, + (event->state & GDK_BUTTON1_MASK) ? 1 : 2, + (GdkEvent *) event); + g_dataset_set_data(context, "filer_window", filer_window); + + image = number_selected == 1 ? selected_item(collection)->image + : &default_pixmap[TYPE_MULTIPLE]; + + gtk_drag_set_icon_pixmap(context, + gtk_widget_get_colormap(widget), + image->pixmap, + image->mask, + 0, 0); +} + +/* Called when a remote app wants us to send it some data */ +void drag_data_get(GtkWidget *widget, + GdkDragContext *context, + GtkSelectionData *selection_data, + guint info, + guint32 time) +{ + char *to_send = "E"; /* Default to sending an error */ + int to_send_length = 1; + gboolean delete_once_sent = FALSE; + GdkAtom type = XA_STRING; + GString *string; + FilerWindow *filer_window; + + filer_window = g_dataset_get_data(context, "filer_window"); + g_return_if_fail(filer_window != NULL); + + switch (info) + { + case TARGET_RAW: + report_error("drag_data_get", "send file contents"); + /* + to_send = gtk_editable_get_chars(GTK_EDITABLE(text), + 0, -1); + to_send_length = gtk_text_get_length(GTK_TEXT(text)); + delete_once_sent = TRUE; + type = text_plain; + */ + break; + case TARGET_URI_LIST: + string = g_string_new(NULL); + create_uri_list(string, + COLLECTION(widget), + filer_window); + to_send = string->str; + to_send_length = string->len; + g_string_free(string, FALSE); + break; + default: + report_error("drag_data_get", + "Internal error - bad info type\n"); + break; + } + + gtk_selection_data_set(selection_data, + type, + 8, + to_send, + to_send_length); + + if (delete_once_sent) + g_free(to_send); +} + +/* Append all the URIs in the selection to the string */ +static void create_uri_list(GString *string, + Collection *collection, + FilerWindow *filer_window) +{ + GString *leader; + int i, num_selected; + + leader = g_string_new("file://"); + g_string_append(leader, our_host_name()); + g_string_append(leader, filer_window->path); + if (leader->str[leader->len - 1] != '/') + g_string_append_c(leader, '/'); + + num_selected = collection->number_selected; + + for (i = 0; num_selected > 0; i++) + { + if (collection->items[i].selected) + { + FileItem *item = (FileItem *) collection->items[i].data; + + g_string_append(string, leader->str); + g_string_append(string, item->leafname); + g_string_append(string, "\r\n"); + num_selected--; + } + } + + g_string_free(leader, TRUE); +} diff --git a/ROX-Filer/src/dnd.h b/ROX-Filer/src/dnd.h new file mode 100644 index 00000000..b3ce374f --- /dev/null +++ b/ROX-Filer/src/dnd.h @@ -0,0 +1,19 @@ +/* vi: set cindent: + * $Id$ + * + * ROX-Filer, filer for the ROX desktop project + * By Thomas Leonard, . + */ + +#include +#include + +void drag_selection(Collection *collection, + GdkEventMotion *event, + gint number_selected, + gpointer user_data); +void drag_data_get(GtkWidget *widget, + GdkDragContext *context, + GtkSelectionData *selection_data, + guint info, + guint32 time); diff --git a/ROX-Filer/src/filer.c b/ROX-Filer/src/filer.c index 9a6fd2a2..4b539a17 100644 --- a/ROX-Filer/src/filer.c +++ b/ROX-Filer/src/filer.c @@ -23,6 +23,7 @@ #include "pixmaps.h" #include "menu.h" #include "dnd.h" +#include "apps.h" static int number_of_windows = 0; static FilerWindow *window_with_selection = NULL; @@ -300,10 +301,29 @@ void open_item(Collection *collection, { FilerWindow *filer_window = (FilerWindow *) user_data; FileItem *item = (FileItem *) item_data; + GdkEventButton *event; - if (item->base_type == TYPE_DIRECTORY) - filer_opendir(make_path(filer_window->path, - item->leafname)->str); + switch (item->base_type) + { + case TYPE_APPDIR: + event = (GdkEventButton *) gtk_get_current_event(); + if (event->type != GDK_2BUTTON_PRESS || + (event->state & GDK_SHIFT_MASK) == 0) + { + run_app(make_path(filer_window->path, + item->leafname)->str); + break; + } + /* FALLTHROUGH */ + case TYPE_DIRECTORY: + filer_opendir(make_path(filer_window->path, + item->leafname)->str); + break; + default: + report_error("open_item", + "I don't know how to open that"); + break; + } } void filer_opendir(char *path) -- 2.11.4.GIT