Feature request for a "shelf" option ( #51)#52
Feature request for a "shelf" option ( #51)#52DevHyperCoder wants to merge 5 commits intomwh:masterfrom
Conversation
| // https://stackoverflow.com/a/23497087 | ||
| GtkWidget* | ||
| find_child(GtkWidget* parent, const gchar* name) | ||
| { |
There was a problem hiding this comment.
Indentation of this entire function is severely off.
| } | ||
| while ((children = g_list_next(children)) != NULL); |
There was a problem hiding this comment.
} and while typically go on the same line for do .. while loops so that it's not confused as a regular while loop.
| } | |
| while ((children = g_list_next(children)) != NULL); | |
| } while ((children = g_list_next(children)) != NULL); |
| || strcmp(argv[i], "--and-exit") == 0) { | ||
| and_exit = true; | ||
| } else if (strcmp(argv[i], "-X") == 0 | ||
| || strcmp(argv[i], "--individual-exit") == 0) { |
There was a problem hiding this comment.
Kind of a long name for a cli arg, something simpler might be better. But I guess not that big of a deal since there's the short form -X.
|
|
||
| # clangd | ||
| compile_commands.json | ||
| .cache/ |
There was a problem hiding this comment.
IMO these should go into user's global ignore file rather than on the project's one.
| gtk_main_quit(); | ||
| } | ||
|
|
||
| if(individual_exit) { |
There was a problem hiding this comment.
Use spaces before and after the parens. e.g if (x) {
| return; | ||
| } | ||
|
|
||
| GtkWidget* button = find_child(vbox,dd->text); |
There was a problem hiding this comment.
Space after the comma.
| GtkWidget* button = find_child(vbox,dd->text); | |
| GtkWidget* button = find_child(vbox, dd->text); |
| } | ||
| if (and_exit) | ||
|
|
||
| if (and_exit){ |
There was a problem hiding this comment.
What happens when user invokes both -x and -X ? Seems like -x will take priority. It's more typical that the latter argument provided via cli to override the previous one.
Instead of using two bools, I'd use a single enum enum { QUIT_NONE, QUIT_ALL, QUIT_ITEM } where QUIT_ALL would be the current -x and QUIT_ITEM would be -X.
There was a problem hiding this comment.
Should do the trick. Though the names could be better.
diff --git a/dragon.c b/dragon.c
index ae3bac0..4c253f6 100644
--- a/dragon.c
+++ b/dragon.c
@@ -35,13 +35,12 @@ char *progname;
bool verbose = false;
int mode = 0;
int thumb_size = 96;
-bool and_exit;
-bool individual_exit; // TODO docs ; man
bool keep;
bool print_path = false;
bool icons_only = false;
bool always_on_top = false;
+static enum { QUIT_NONE, QUIT_ALL, QUIT_ITEM } quit_mode;
static char *stdin_files;
#define MODE_HELP 1
@@ -142,11 +141,9 @@ void drag_end(GtkWidget *widget, GdkDragContext *context, gpointer user_data) {
free(action_str);
}
- if (and_exit){
+ if (quit_mode == QUIT_ALL) {
gtk_main_quit();
- }
-
- if(individual_exit) {
+ } else if (quit_mode == QUIT_ITEM) {
if (uri_count == 0) {
gtk_main_quit();
return;
@@ -412,7 +409,7 @@ drag_data_received (GtkWidget *widget,
} else if (verbose)
fputs("Received nothing\n", stderr);
gtk_drag_finish (context, TRUE, FALSE, time);
- if (and_exit)
+ if (quit_mode == QUIT_ALL)
gtk_main_quit();
}
@@ -538,10 +535,10 @@ int main (int argc, char **argv) {
mode = MODE_TARGET;
} else if (strcmp(argv[i], "-x") == 0
|| strcmp(argv[i], "--and-exit") == 0) {
- and_exit = true;
+ quit_mode = QUIT_ALL;
} else if (strcmp(argv[i], "-X") == 0
|| strcmp(argv[i], "--individual-exit") == 0) {
- individual_exit = true;
+ quit_mode = QUIT_ITEM;
} else if (strcmp(argv[i], "-k") == 0
|| strcmp(argv[i], "--keep") == 0) {
keep = true;|
Does the code formatting in this repo conform to any existing utility (like |
N-R-K
left a comment
There was a problem hiding this comment.
The --help output needs to be updated as well. Otherwise mostly seems okay, can't say for sure since I'm not too well versed on glib nor gtk.
| } | ||
|
|
||
| if (GTK_IS_CONTAINER(parent)) { | ||
| GList *children = gtk_container_get_children(GTK_CONTAINER(parent)); |
There was a problem hiding this comment.
Is it possible for this to return NULL ? If it is then it's going to lead to a null-deref down below.
| bool icons_only = false; | ||
| bool always_on_top = false; | ||
|
|
||
| static enum { QUIT_NONE, QUIT_ALL, QUIT_ITEM } quit_mode; |
There was a problem hiding this comment.
If the cli arg will be kept --individual-exit then probably should rename QUIT_ITEM to QUIT_INDIVIDUAL.
| if (quit_mode == QUIT_ALL){ | ||
| gtk_main_quit(); | ||
| } | ||
|
|
||
| if (quit_mode == QUIT_ITEM) { |
There was a problem hiding this comment.
Space after ). Also since they are mutually exclusive, else if makes more sense IMO.
| if (quit_mode == QUIT_ALL){ | |
| gtk_main_quit(); | |
| } | |
| if (quit_mode == QUIT_ITEM) { | |
| if (quit_mode == QUIT_ALL) { | |
| gtk_main_quit(); | |
| } else if (quit_mode == QUIT_ITEM) { |
| if (button != NULL) { | ||
| gtk_container_remove(GTK_CONTAINER(vbox), button); | ||
| } else { | ||
| fprintf(stderr, "Could not find button with label: %s",dd->text); |
There was a problem hiding this comment.
| fprintf(stderr, "Could not find button with label: %s",dd->text); | |
| fprintf(stderr, "Could not find button with label: %s", dd->text); |
| and_exit = true; | ||
| quit_mode = QUIT_ALL; | ||
| } else if (strcmp(argv[i], "-X") == 0 | ||
| || strcmp(argv[i], "--individual-exit") == 0) { |
There was a problem hiding this comment.
The naming isn't exactly intuitive to me. I wouldn't expect this option to cause the application to exit once all the individual items have been dragged out of it.
How about naming it --item-remove, --remove-individual, --once-each or similar and then use this option together with --and-exit to trigger an exit once all items have been moved out? Whereas if the option wasn't specified, --and-exit would still cause a quit after the first successful drag.
There was a problem hiding this comment.
Yeah --once-each sounds like a better naming option to me as well.
| } | ||
|
|
||
| void drag_end(GtkWidget *widget, GdkDragContext *context, gpointer user_data) { | ||
| uri_count--; |
There was a problem hiding this comment.
This will break target mode together with shelf mode (or 'drag once mode') and cause URIs to be overridden as that uses the uri_count counter for indexing. Besides, imo it would be better to have this near the code that is responsible for handling individual entiries when quit_mode == QUIT_ITEM.
And finally, what if -X is used together with --all?
There was a problem hiding this comment.
so you mean i should decrement uri_count near the if statement ? Or should i make it use a different counter
In relation with #51