Skip to content

Commit bc2579a

Browse files
committed
nemo-main-application.c: When selecting files from the commandline,
re-use existing windows that already display the correct locataion.
1 parent 80544ae commit bc2579a

1 file changed

Lines changed: 88 additions & 11 deletions

File tree

src/nemo-main-application.c

Lines changed: 88 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,62 @@ nemo_main_application_open_location (NemoApplication *application,
557557
}
558558
}
559559

560+
static NemoWindowSlot *
561+
find_existing_slot_for_location (NemoApplication *application,
562+
GFile *location)
563+
{
564+
GList *windows;
565+
GList *l;
566+
567+
windows = gtk_application_get_windows (GTK_APPLICATION (application));
568+
for (l = windows; l != NULL; l = l->next) {
569+
NemoWindow *window;
570+
GList *p;
571+
572+
if (!NEMO_IS_WINDOW (l->data)) {
573+
continue;
574+
}
575+
576+
window = NEMO_WINDOW (l->data);
577+
578+
for (p = window->details->panes; p != NULL; p = p->next) {
579+
NemoWindowPane *pane = p->data;
580+
GList *s;
581+
582+
for (s = pane->slots; s != NULL; s = s->next) {
583+
NemoWindowSlot *slot = s->data;
584+
GFile *slot_location;
585+
gboolean match;
586+
587+
slot_location = nemo_window_slot_get_location (slot);
588+
if (slot_location == NULL) {
589+
continue;
590+
}
591+
592+
match = g_file_equal (slot_location, location);
593+
g_object_unref (slot_location);
594+
595+
if (match) {
596+
return slot;
597+
}
598+
}
599+
}
600+
}
601+
602+
return NULL;
603+
}
604+
605+
static void
606+
present_window (NemoWindow *window)
607+
{
608+
if (eel_check_is_wayland ()) {
609+
gtk_window_present (GTK_WINDOW (window));
610+
} else {
611+
gtk_window_present_with_time (GTK_WINDOW (window),
612+
gdk_x11_get_server_time (gtk_widget_get_window (GTK_WIDGET (window))));
613+
}
614+
}
615+
560616
static void
561617
nemo_main_application_show_items (NemoApplication *application,
562618
GFile **uris,
@@ -604,33 +660,54 @@ nemo_main_application_show_items (NemoApplication *application,
604660
GPtrArray *group = (GPtrArray *) value;
605661
GFile *first = g_ptr_array_index (group, 0);
606662
GFile *parent;
607-
NemoWindow *window;
663+
GFile *target;
664+
NemoWindowSlot *existing_slot;
608665
GList *sel_list = NULL;
609666
guint j;
610667

611668
parent = g_file_get_parent (first);
612-
613-
window = nemo_main_application_create_window (application, gdk_screen_get_default ());
614-
if (startup_id != NULL) {
615-
gtk_window_set_startup_id (GTK_WINDOW (window), startup_id);
616-
}
669+
target = (parent != NULL) ? parent : first;
617670

618671
if (parent != NULL) {
619672
for (j = 0; j < group->len; j++) {
620673
sel_list = g_list_prepend (sel_list,
621674
nemo_file_get ((GFile *) g_ptr_array_index (group, j)));
622675
}
623676
sel_list = g_list_reverse (sel_list);
677+
}
678+
679+
existing_slot = find_existing_slot_for_location (application, target);
680+
681+
if (existing_slot != NULL) {
682+
NemoWindow *window = nemo_window_slot_get_window (existing_slot);
683+
NemoView *view;
684+
685+
nemo_window_slot_make_hosting_pane_active (existing_slot);
624686

625-
nemo_window_slot_open_location_full (nemo_window_get_active_slot (window), parent,
687+
if (sel_list != NULL) {
688+
view = nemo_window_slot_get_current_view (existing_slot);
689+
if (view != NULL) {
690+
nemo_view_set_selection (view, sel_list);
691+
}
692+
}
693+
694+
present_window (window);
695+
} else {
696+
NemoWindow *window;
697+
698+
window = nemo_main_application_create_window (application, gdk_screen_get_default ());
699+
if (startup_id != NULL) {
700+
gtk_window_set_startup_id (GTK_WINDOW (window), startup_id);
701+
}
702+
703+
nemo_window_slot_open_location_full (nemo_window_get_active_slot (window), target,
626704
0, sel_list, NULL, NULL);
705+
}
627706

707+
if (sel_list != NULL) {
628708
nemo_file_list_free (sel_list);
629-
g_object_unref (parent);
630-
} else {
631-
nemo_window_slot_open_location_full (nemo_window_get_active_slot (window), first,
632-
0, NULL, NULL, NULL);
633709
}
710+
g_clear_object (&parent);
634711
}
635712

636713
g_hash_table_destroy (groups);

0 commit comments

Comments
 (0)