Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion gresources/nemo-file-management-properties.glade
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,23 @@ along with . If not, see <http://www.gnu.org/licenses/>.
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="restore_tabs_on_startup_checkbutton">
<property name="label" translatable="yes">Restore last window tabs on startup</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="use-underline">True</property>
<property name="xalign">0</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">3</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="expand_row_on_dnd_dwell_checkbutton">
<property name="label" translatable="yes">Automatically expand rows during drag-and-drop</property>
Expand All @@ -1269,7 +1286,7 @@ along with . If not, see <http://www.gnu.org/licenses/>.
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
<property name="position">5</property>
</packing>
</child>
</object>
Expand Down
8 changes: 8 additions & 0 deletions libnemo-private/nemo-global-preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ typedef enum
#define NEMO_WINDOW_STATE_DEVICES_EXPANDED "devices-expanded"
#define NEMO_WINDOW_STATE_NETWORK_EXPANDED "network-expanded"

/* Saved session (last closed window) */
#define NEMO_WINDOW_STATE_SAVED_SPLIT_VIEW "saved-split-view"
#define NEMO_WINDOW_STATE_SAVED_TABS_LEFT "saved-tabs-left"
#define NEMO_WINDOW_STATE_SAVED_TABS_RIGHT "saved-tabs-right"
#define NEMO_WINDOW_STATE_SAVED_ACTIVE_TAB_LEFT "saved-active-tab-left"
#define NEMO_WINDOW_STATE_SAVED_ACTIVE_TAB_RIGHT "saved-active-tab-right"

/* Sorting order */
#define NEMO_PREFERENCES_SORT_DIRECTORIES_FIRST "sort-directories-first"
#define NEMO_PREFERENCES_SORT_FAVORITES_FIRST "sort-favorites-first"
Expand All @@ -137,6 +144,7 @@ typedef enum
#define NEMO_PREFERENCES_CLOSE_DEVICE_VIEW_ON_EJECT "close-device-view-on-device-eject"

#define NEMO_PREFERENCES_START_WITH_DUAL_PANE "start-with-dual-pane"
#define NEMO_PREFERENCES_RESTORE_TABS_ON_STARTUP "restore-tabs-on-startup"
#define NEMO_PREFERENCES_IGNORE_VIEW_METADATA "ignore-view-metadata"
#define NEMO_PREFERENCES_SHOW_BOOKMARKS_IN_TO_MENUS "show-bookmarks-in-to-menus"
#define NEMO_PREFERENCES_SHOW_PLACES_IN_TO_MENUS "show-places-in-to-menus"
Expand Down
32 changes: 32 additions & 0 deletions libnemo-private/org.nemo.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@
<summary>Whether to default to showing dual-pane view when a new window is opened</summary>
<description>If set to true, new Nemo windows will default to showing two panes</description>
</key>
<key name="restore-tabs-on-startup" type="b">
<default>false</default>
<summary>Restore the previous window tabs on startup</summary>
<description>If set to true, Nemo will restore the last saved window tab state when launched without explicit locations.</description>
</key>
<key name="ignore-view-metadata" type="b">
<default>false</default>
<summary>Whether to ignore folder metadata for view zoom levels and layouts</summary>
Expand Down Expand Up @@ -702,6 +707,33 @@
<summary>Side pane view</summary>
<description>The side pane view to show in newly opened windows.</description>
</key>

<!-- Saved session (last closed window) -->
<key name="saved-split-view" type="b">
<default>false</default>
<summary>Whether split view was enabled when the last window was closed</summary>
<description>Internal setting used to restore the last closed window's split view and tabs.</description>
</key>
<key name="saved-tabs-left" type="as">
<default>[]</default>
<summary>Saved tab URIs for the left pane</summary>
<description>Internal setting used to restore the last closed window's tabs for the left pane.</description>
</key>
<key name="saved-tabs-right" type="as">
<default>[]</default>
<summary>Saved tab URIs for the right pane</summary>
<description>Internal setting used to restore the last closed window's tabs for the right pane.</description>
</key>
<key name="saved-active-tab-left" type="i">
<default>0</default>
<summary>Index of the active tab in the left pane</summary>
<description>Internal setting used to restore which tab was active in the left pane.</description>
</key>
<key name="saved-active-tab-right" type="i">
<default>0</default>
<summary>Index of the active tab in the right pane</summary>
<description>Internal setting used to restore which tab was active in the right pane.</description>
</key>
</schema>

<schema id="org.nemo.plugins" path="/org/nemo/plugins/" gettext-domain="nemo">
Expand Down
28 changes: 28 additions & 0 deletions src/nemo-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,34 @@ nemo_application_quit (NemoApplication *self)
GList *windows;

windows = gtk_application_get_windows (GTK_APPLICATION (app));

/* Save session state once, before we destroy all windows.
* Save the last non-desktop window we find. */
{
NemoWindow *last_window = NULL;

for (GList *l = windows; l != NULL; l = l->next) {
GtkWindow *w = GTK_WINDOW (l->data);

if (!NEMO_IS_WINDOW (w)) {
continue;
}

NemoWindow *nw = NEMO_WINDOW (w);

/* Avoid saving the desktop window */
if (nw->details != NULL && nw->details->disable_chrome) {
continue;
}

last_window = nw;
}

if (last_window != NULL) {
nemo_window_save_session_state (last_window);
}
}

g_list_foreach (windows, (GFunc) gtk_widget_destroy, NULL);

/* we have been asked to force quit */
Expand Down
5 changes: 5 additions & 0 deletions src/nemo-file-management-properties.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
#define NEMO_FILE_MANAGEMENT_PROPERTIES_DETECT_CONTENT_MEDIA_WIDGET "media_detect_content_checkbutton"
#define NEMO_FILE_MANAGEMENT_PROPERTIES_SHOW_ADVANCED_PERMISSIONS_WIDGET "show_advanced_permissions_checkbutton"
#define NEMO_FILE_MANAGEMENT_PROPERTIES_START_WITH_DUAL_PANE_WIDGET "start_with_dual_pane_checkbutton"
#define NEMO_FILE_MANAGEMENT_PROPERTIES_RESTORE_TABS_ON_STARTUP_WIDGET "restore_tabs_on_startup_checkbutton"
#define NEMO_FILE_MANAGEMENT_PROPERTIES_IGNORE_VIEW_METADATA_WIDGET "ignore_view_metadata_checkbutton"
#define NEMO_FILE_MANAGEMENT_PROPERTIES_BOOKMARKS_IN_TO_MENUS_WIDGET "bookmarks_in_to_checkbutton"
#define NEMO_FILE_MANAGEMENT_PROPERTIES_PLACES_IN_TO_MENUS_WIDGET "places_in_to_checkbutton"
Expand Down Expand Up @@ -1067,6 +1068,10 @@ nemo_file_management_properties_dialog_setup (GtkBuilder *builder,
NEMO_FILE_MANAGEMENT_PROPERTIES_START_WITH_DUAL_PANE_WIDGET,
NEMO_PREFERENCES_START_WITH_DUAL_PANE);

bind_builder_bool (builder, nemo_preferences,
NEMO_FILE_MANAGEMENT_PROPERTIES_RESTORE_TABS_ON_STARTUP_WIDGET,
NEMO_PREFERENCES_RESTORE_TABS_ON_STARTUP);

bind_builder_bool (builder, nemo_preferences,
NEMO_FILE_MANAGEMENT_PROPERTIES_IGNORE_VIEW_METADATA_WIDGET,
NEMO_PREFERENCES_IGNORE_VIEW_METADATA);
Expand Down
78 changes: 68 additions & 10 deletions src/nemo-main-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,34 @@ open_windows (NemoMainApplication *application,
gint i;

if (files == NULL || files[0] == NULL) {
/* Open a window pointing at the default location. */
open_window (application, NULL, screen, geometry);
/* No explicit locations requested: try restoring the last session. */
NemoWindow *window;
gboolean have_geometry;
gboolean do_restore;

window = nemo_main_application_create_window (NEMO_APPLICATION (application), screen);

have_geometry = geometry != NULL && strcmp (geometry, "") != 0;
if (have_geometry && !gtk_widget_get_visible (GTK_WIDGET (window))) {
/* never maximize windows opened from shell if a
* custom geometry has been requested.
*/
gtk_window_unmaximize (GTK_WINDOW (window));
eel_gtk_window_set_initial_geometry_from_string (GTK_WINDOW (window),
geometry,
APPLICATION_WINDOW_MIN_WIDTH,
APPLICATION_WINDOW_MIN_HEIGHT,
FALSE);
}

do_restore = g_settings_get_boolean (nemo_preferences, NEMO_PREFERENCES_RESTORE_TABS_ON_STARTUP);

if (!do_restore || !nemo_window_restore_saved_tabs (window)) {
/* Fall back to a safe default location */
GFile *home = g_file_new_for_path (g_get_home_dir ());
nemo_window_go_to (window, home);
g_object_unref (home);
}
} else {
if (open_in_existing_window) {
/* Open one tab at each requested location in an existing window */
Expand Down Expand Up @@ -533,6 +559,7 @@ nemo_main_application_open (GApplication *app,
gboolean open_in_tabs = FALSE;
gchar *geometry = NULL;
gboolean open_in_existing_window = strcmp (options, "EXISTING_WINDOW") == 0;
gboolean default_no_args = FALSE;
const char splitter = '=';

g_debug ("Open called on the GApplication instance; %d files", n_files);
Expand All @@ -541,7 +568,12 @@ nemo_main_application_open (GApplication *app,
/* Check if local command line passed --geometry or --tabs */
if (strlen (options) > 0) {
gchar** split_options = g_strsplit (options, &splitter, 2);
if (strcmp (split_options[0], "NULL") != 0) {
if (g_str_has_prefix (split_options[0], "DEFAULT")) {
default_no_args = TRUE;
if (g_str_has_prefix (split_options[0], "DEFAULT+")) {
geometry = g_strdup (split_options[0] + strlen ("DEFAULT+"));
}
} else if (strcmp (split_options[0], "NULL") != 0) {
geometry = g_strdup (split_options[0]);
}
sscanf (split_options[1], "%d", &open_in_tabs);
Expand All @@ -556,7 +588,13 @@ nemo_main_application_open (GApplication *app,
geometry ? geometry : "none",
open_in_existing_window ? "yes" : "no");

open_windows (self, files, n_files, gdk_screen_get_default (), geometry, open_in_tabs, open_in_existing_window);
if (default_no_args) {
/* Treat this as a no-arg launch; open_windows() will attempt session restore
* and fall back to Home if restore isn't possible. */
open_windows (self, NULL, 0, gdk_screen_get_default (), geometry, open_in_tabs, open_in_existing_window);
} else {
open_windows (self, files, n_files, gdk_screen_get_default (), geometry, open_in_tabs, open_in_existing_window);
}

g_clear_pointer (&geometry, g_free);
}
Expand Down Expand Up @@ -798,9 +836,11 @@ nemo_main_application_local_command_line (GApplication *application,

GFile **files;
gint idx, len;
gboolean used_default_location;

len = 0;
files = NULL;
used_default_location = FALSE;

/* Convert args to GFiles */
if (remaining != NULL) {
Expand All @@ -822,32 +862,50 @@ nemo_main_application_local_command_line (GApplication *application,
}

if (files == NULL && !no_default_window) {
/* Original behavior: default to Home when no URIs are provided. */
files = g_malloc0 (2 * sizeof (GFile *));
len = 1;

files[0] = g_file_new_for_path (g_get_home_dir ());
files[1] = NULL;

/* Mark that this was a no-arg launch, not an explicit URI. */
used_default_location = TRUE;
}
/* Invoke "Open" to open in existing window or create new windows */

/* Invoke "Open" to open in existing window or create new windows.
*/
if (len > 0) {
gchar* concatOptions = g_malloc0(64);
if (open_in_existing_window) {
g_stpcpy (concatOptions, "EXISTING_WINDOW");
} else {
if (self->priv->geometry == NULL) {
g_snprintf (concatOptions, 64, "NULL=%d", open_in_tabs);
/* If Home was synthesized because no URIs were passed, signal that
* to the primary instance so it can attempt session restore. */
if (used_default_location) {
g_snprintf (concatOptions, 64, "DEFAULT=%d", open_in_tabs);
} else {
g_snprintf (concatOptions, 64, "NULL=%d", open_in_tabs);
}
} else {
g_snprintf (concatOptions, 64, "%s=%d", self->priv->geometry, open_in_tabs);
if (used_default_location) {
g_snprintf (concatOptions, 64, "DEFAULT+%s=%d", self->priv->geometry, open_in_tabs);
} else {
g_snprintf (concatOptions, 64, "%s=%d", self->priv->geometry, open_in_tabs);
}
}
}
g_application_open (application, files, len, concatOptions);
g_free (concatOptions);
}

for (idx = 0; idx < len; idx++) {
g_object_unref (files[idx]);
if (files != NULL) {
for (idx = 0; idx < len; idx++) {
g_object_unref (files[idx]);
}
g_free (files);
}
g_free (files);

out:
g_option_context_free (context);
Expand Down
3 changes: 3 additions & 0 deletions src/nemo-window-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ void nemo_window_set_active_pane (NemoWindow
NemoWindowPane *new_pane);
NemoWindowPane * nemo_window_get_active_pane (NemoWindow *window);

gboolean nemo_window_restore_saved_tabs (NemoWindow *window);
void nemo_window_save_session_state (NemoWindow *window);


/* sync window GUI with current slot. Used when changing slots,
* and when updating the slot state.
Expand Down
Loading