diff --git a/src/Application.vala b/src/Application.vala index ad86524bb0..a22961b15f 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -298,6 +298,17 @@ public class Files.Application : Gtk.Application { prefs, "sort-directories-first", GLib.SettingsBindFlags.DEFAULT); } + public View.Window? create_empty_window () { + if (this.get_windows ().length () >= MAX_WINDOWS) { //Can be assumed to be limited in length + return null; + } + + var win = new View.Window (this); + add_window (win as Gtk.Window); + plugins.interface_loaded (win as Gtk.Widget); + return win; + } + public View.Window? create_window (GLib.File? location = null, ViewMode viewmode = ViewMode.PREFERRED) { @@ -308,13 +319,7 @@ public class Files.Application : Gtk.Application { private View.Window? create_window_with_tabs (GLib.File[] locations = {}, ViewMode viewmode = ViewMode.PREFERRED) { - if (this.get_windows ().length () >= MAX_WINDOWS) { //Can be assumed to be limited in length - return null; - } - - var win = new View.Window (this); - add_window (win as Gtk.Window); - plugins.interface_loaded (win as Gtk.Widget); + var win = create_empty_window (); win.open_tabs (locations, viewmode); return win; diff --git a/src/View/Window.vala b/src/View/Window.vala index f0c208a920..3b08654bc9 100644 --- a/src/View/Window.vala +++ b/src/View/Window.vala @@ -40,6 +40,7 @@ public class Files.View.Window : Hdy.ApplicationWindow { {"singleclick-select", null, null, "false", change_state_single_click_select}, {"show-remote-thumbnails", null, null, "true", change_state_show_remote_thumbnails}, {"show-local-thumbnails", null, null, "false", change_state_show_local_thumbnails}, + {"tabhistory-restore", action_tabhistory_restore, "s" }, {"folders-before-files", null, null, "true", change_state_folders_before_files}, {"forward", action_forward, "i"}, {"back", action_back, "i"} @@ -53,18 +54,29 @@ public class Files.View.Window : Hdy.ApplicationWindow { } } + private ViewContainer? current_container { + get { + if (tab_view.selected_page != null) { + return (ViewContainer) tab_view.selected_page.child; + } + + return null; + } + } + public Gtk.Builder ui; public Files.Application marlin_app { get; construct; } private unowned UndoManager undo_manager; public Hdy.HeaderBar headerbar; public Chrome.ViewSwitcher view_switcher; - public Granite.Widgets.DynamicNotebook tabs; + public Hdy.TabView tab_view; + public Hdy.TabBar tab_bar; private Gtk.Paned lside_pane; public SidebarInterface sidebar; - public ViewContainer? current_tab = null; private Chrome.ButtonWithMenu button_forward; private Chrome.ButtonWithMenu button_back; private Chrome.LocationBar? location_bar; + private Gtk.MenuButton tab_history_button; private bool locked_focus { get; set; default = false; } private bool tabs_restored = false; @@ -197,23 +209,39 @@ public class Files.View.Window : Hdy.ApplicationWindow { headerbar.pack_start (location_bar); headerbar.pack_end (menu_button); - tabs = new Granite.Widgets.DynamicNotebook.with_accellabels ( - new Granite.AccelLabel (_("New Tab"), "t"), - new Granite.AccelLabel (_("Undo Close Tab"), "t") - ) { - show_tabs = true, - allow_restoring = true, - allow_duplication = true, - allow_new_window = true, - group_name = Config.APP_NAME + tab_view = new Hdy.TabView () { + menu_model = new Menu () }; - this.configure_event.connect_after ((e) => { - tabs.set_size_request (e.width / 2, -1); - return false; - }); + var app_instance = (Gtk.Application)(GLib.Application.get_default ()); + + var new_tab_button = new Gtk.Button.from_icon_name ("list-add-symbolic") { + action_name = "win.tab", + action_target = new Variant.string ("NEW") + }; + new_tab_button.tooltip_markup = Granite.markup_accel_tooltip ( + app_instance.get_accels_for_action ("win.tab::NEW"), + _("New Tab") + ); - tabs.show (); + tab_history_button = new Gtk.MenuButton () { + image = new Gtk.Image.from_icon_name ("document-open-recent-symbolic", MENU), + tooltip_text = _("Closed Tabs"), + use_popover = false + }; + + tab_bar = new Hdy.TabBar () { + autohide = false, + expand_tabs = false, + inverted = true, + start_action_widget = new_tab_button, + end_action_widget = tab_history_button, + view = tab_view + }; + + var tab_box = new Gtk.Box (VERTICAL, 0); + tab_box.add (tab_bar); + tab_box.add (tab_view); sidebar = new Sidebar.SidebarWindow (); free_space_change.connect (sidebar.on_free_space_change); @@ -223,7 +251,7 @@ public class Files.View.Window : Hdy.ApplicationWindow { position = Files.app_settings.get_int ("sidebar-width") }; lside_pane.pack1 (sidebar, false, false); - lside_pane.pack2 (tabs, true, true); + lside_pane.pack2 (tab_box, true, true); var grid = new Gtk.Grid (); grid.attach (headerbar, 0, 0); @@ -270,12 +298,12 @@ public class Files.View.Window : Hdy.ApplicationWindow { location_bar.escape.connect (grab_focus); location_bar.path_change_request.connect ((path, flag) => { - current_tab.is_frozen = false; + current_container.is_frozen = false; uri_path_change_request (path, flag); }); location_bar.focus_file_request.connect ((loc) => { - current_tab.focus_location_if_in_current_directory (loc, true); + current_container.focus_location_if_in_current_directory (loc, true); }); headerbar.focus_in_event.connect ((event) => { @@ -323,78 +351,150 @@ public class Files.View.Window : Hdy.ApplicationWindow { return false; }); - tabs.new_tab_requested.connect (() => { - add_tab (); + tab_view.setup_menu.connect (tab_view_setup_menu); + + tab_view.close_page.connect (tab_view_close_page); + + tab_view.notify["selected-page"].connect (() => { + change_tab (tab_view.selected_page); }); - tabs.close_tab_requested.connect ((tab) => { - var view_container = (ViewContainer)(tab.page); - tab.restore_data = view_container.location.get_uri (); + tab_view.create_window.connect (() => { + return marlin_app.create_empty_window ().tab_view; + }); - /* If closing tab is current, set current_tab to null to ensure - * closed ViewContainer is destroyed. It will be reassigned in tab_changed - */ - if (view_container == current_tab) { - current_tab = null; - } + tab_view.page_attached.connect ((tab, pos) => { + var view_container = (ViewContainer) tab.child; + view_container.window = this; + }); - view_container.close (); + tab_view.page_detached.connect (on_page_detached); - if (tabs.n_tabs == 1) { - add_tab (); - } + sidebar.request_focus.connect (() => { + return !current_container.locked_focus && !locked_focus; + }); - return true; + sidebar.sync_needed.connect (() => { + loading_uri (current_container.uri); }); - tabs.tab_switched.connect ((old_tab, new_tab) => { - if (new_tab != null) { - change_tab (tabs.get_tab_position (new_tab)); + sidebar.path_change_request.connect (uri_path_change_request); + sidebar.connect_server_request.connect (connect_to_server); + } + + private bool tab_view_close_page (Hdy.TabPage page) { + var view_container = (ViewContainer) page.child; + + if (tab_history_button.menu_model == null) { + tab_history_button.menu_model = new Menu (); + } + + var path = view_container.location.get_uri (); + var path_in_menu = false; + var menu = (Menu) tab_history_button.menu_model; + for (var i = 0; i < menu.get_n_items (); i++) { + if (path == menu.get_item_attribute_value (i, Menu.ATTRIBUTE_TARGET, VariantType.STRING).get_string ()) { + path_in_menu = true; + break; } - }); + } - tabs.tab_restored.connect ((label, restore_data, icon) => { - add_tab_by_uri (restore_data); - }); + if (!path_in_menu) { + menu.append ( + FileUtils.sanitize_path (path, null, false), + "win.tabhistory-restore::%s".printf (path) + ); + } - tabs.tab_duplicated.connect ((tab) => { - add_tab_by_uri (((ViewContainer)(tab.page)).uri); - }); + view_container.close (); + tab_view.close_page_finish (page, true); - tabs.tab_moved.connect ((tab) => { - /* Called when tab dragged out of notebook */ - var vc = (ViewContainer)(tab.page) ; - /* Close view now to disconnect signal handler closures which can trigger after slot destruction */ - vc.close (); + if (tab_view.n_pages == 0) { + add_tab (); + } - marlin_app.create_window (vc.location, real_mode (vc.view_mode)); + return Gdk.EVENT_STOP; + } - /* remove_tab function uses Idle loop to close tab */ - remove_tab (tab); - }); + private void tab_view_setup_menu (Hdy.TabPage? page) { + if (page == null) { + return; + } + var action_close = new SimpleAction ("tabmenu-close", null); + var action_close_end = new SimpleAction ("tabmenu-close-end", null); + var action_close_others = new SimpleAction ("tabmenu-close-others", null); + var action_duplicate = new SimpleAction ("tabmenu-duplicate", null); + var action_move_to_new_window = new SimpleAction ("tabmenu-move-to-window", null); - tabs.tab_added.connect ((tab) => { - var vc = (ViewContainer)(tab.page) ; - vc.window = this; - }); + add_action (action_close); + add_action (action_close_end); + add_action (action_close_others); + add_action (action_duplicate); + add_action (action_move_to_new_window); - tabs.tab_removed.connect (on_tab_removed); + marlin_app.set_accels_for_action ("win.tabmenu-close", {"W"}); + marlin_app.set_accels_for_action ("win.tabmenu-duplicate", {"T"}); + marlin_app.set_accels_for_action ("win.tabmenu-move-to-window", {"N"}); - sidebar.request_focus.connect (() => { - return !current_tab.locked_focus && !locked_focus; + var tab_menu = (Menu) tab_view.menu_model; + tab_menu.remove_all (); + + var open_tab_section = new Menu (); + open_tab_section.append (_("Open in New Window"), "win.tabmenu-move-to-window"); + open_tab_section.append (_("Duplicate Tab"), "win.tabmenu-duplicate"); + + var close_tab_section = new Menu (); + /// TRANSLATORS: For RTL this should be "to the left" + close_tab_section.append (_("Close Tabs to the Right"), "win.tabmenu-close-end"); + close_tab_section.append (_("Close Other Tabs"), "win.tabmenu-close-others"); + close_tab_section.append (_("Close Tab"), "win.tabmenu-close"); + + tab_menu.append_section (null, open_tab_section); + tab_menu.append_section (null, close_tab_section); + + action_close.activate.connect (() => { + remove_tab (page); }); - sidebar.sync_needed.connect (() => { - loading_uri (current_tab.uri); + var tab_position = tab_view.get_page_position (page) + 1; + if (tab_position == tab_view.n_pages) { + action_close_end.set_enabled (false); + } else { + action_close_end.activate.connect (() => { + for (var i = tab_position; i < tab_view.n_pages; i++) { + remove_tab (tab_view.get_nth_page (i)); + } + }); + } + + if (tab_view.n_pages == 1) { + action_close_others.set_enabled (false); + } else { + action_close_others.activate.connect (() => { + for (var i = 0; i < tab_view.n_pages; i++) { + if (tab_view.get_nth_page (i) == page) { + continue; + } + + remove_tab (tab_view.get_nth_page (i)); + } + }); + } + + action_duplicate.activate.connect (() => { + var view_container = (ViewContainer) page.child; + add_tab (view_container.location, view_container.view_mode); }); - sidebar.path_change_request.connect (uri_path_change_request); - sidebar.connect_server_request.connect (connect_to_server); + action_move_to_new_window.activate.connect (() => { + var view_container = (ViewContainer) page.child; + move_content_to_new_window (view_container); + }); } - private void on_tab_removed () { - if (tabs.n_tabs == 0) { + private void on_page_detached () { + if (tab_view.n_pages == 0) { add_tab (); } @@ -405,27 +505,15 @@ public class Files.View.Window : Hdy.ApplicationWindow { this.title = title; } - private void change_tab (int offset) { - ViewContainer? old_tab = current_tab; - current_tab = (ViewContainer)((tabs.get_tab_by_index (offset)).page); - - if (current_tab == null || old_tab == current_tab) { - return; - } - + private void change_tab (Hdy.TabPage page) { if (restoring_tabs > 0) { //Return if some restored tabs still loading return; } - if (old_tab != null) { - old_tab.set_active_state (false); - old_tab.is_frozen = false; - } - - loading_uri (current_tab.uri); - current_tab.set_active_state (true, false); /* changing tab should not cause animated scrolling */ - sidebar.sync_uri (current_tab.uri); - location_bar.sensitive = !current_tab.is_frozen; + loading_uri (current_container.uri); + current_container.set_active_state (true, false); /* changing tab should not cause animated scrolling */ + sidebar.sync_uri (current_container.uri); + location_bar.sensitive = !current_container.is_frozen; save_active_tab_position (); } @@ -443,8 +531,7 @@ public class Files.View.Window : Hdy.ApplicationWindow { var location = GLib.File.new_for_path (PF.UserUtils.get_real_user_home ()); add_tab (location, mode); /* Ensure default tab's slot is active so it can be focused */ - current_tab = (ViewContainer)(tabs.current.page); - current_tab.set_active_state (true, false); + current_container.set_active_state (true, false); } } else { /* Open tabs at each requested location */ @@ -482,12 +569,11 @@ public class Files.View.Window : Hdy.ApplicationWindow { bool is_child; var existing_tab_position = location_is_duplicate (location, out is_child); if (existing_tab_position >= 0) { - tabs.current = tabs.get_tab_by_index (existing_tab_position); - change_tab (existing_tab_position); + tab_view.selected_page = tab_view.get_nth_page (existing_tab_position); if (is_child) { /* Select the child */ - ((ViewContainer)(tabs.current.page)).focus_location_if_in_current_directory (location); + current_container.focus_location_if_in_current_directory (location); } return; @@ -496,22 +582,11 @@ public class Files.View.Window : Hdy.ApplicationWindow { mode = real_mode (mode); var content = new View.ViewContainer (this); - var tab = new Granite.Widgets.Tab.with_accellabels ( - "", - null, - content, - new Granite.AccelLabel (_("Close Tab"), "w"), - new Granite.AccelLabel (_("Duplicate Tab"), "t"), - new Granite.AccelLabel (_("Open in New Window"), "n") - ) { - ellipsize_mode = Pango.EllipsizeMode.MIDDLE - }; - change_tab ((int)tabs.insert_tab (tab, -1)); - tabs.current = tab; + var page = tab_view.append (content); content.tab_name_changed.connect ((tab_name) => { - check_for_tabs_with_same_name (); // Also sets tab_label. + check_for_tabs_with_same_name (); // Also sets tab_label }); content.loading.connect ((is_loading) => { @@ -526,8 +601,9 @@ public class Files.View.Window : Hdy.ApplicationWindow { } } - tab.working = is_loading; + page.loading = is_loading; update_headerbar (); + if (restoring_tabs == 0 && !is_loading) { save_tabs (); } @@ -542,6 +618,8 @@ public class Files.View.Window : Hdy.ApplicationWindow { } else { content.add_view (mode, location); } + + tab_view.selected_page = page; } private int location_is_duplicate (GLib.File location, out bool is_child) { @@ -553,8 +631,9 @@ public class Files.View.Window : Hdy.ApplicationWindow { parent_path = FileUtils.get_parent_path_from_path (location.get_path ()); int existing_position = 0; - foreach (Granite.Widgets.Tab tab in tabs.tabs) { - var tab_location = ((ViewContainer)(tab.page)).location; + for (int i = 0; i < tab_view.n_pages; i++) { + var tab = (Hdy.TabPage) tab_view.get_nth_page (i); + var tab_location = ((ViewContainer) tab.child).location; string tab_uri = tab_location.get_uri (); if (FileUtils.same_location (uri, tab_uri)) { @@ -572,10 +651,9 @@ public class Files.View.Window : Hdy.ApplicationWindow { /** Compare every tab label with every other and resolve ambiguities **/ private void check_for_tabs_with_same_name () { - // Take list copy so foreach clauses can be nested safely - var copy_tabs = tabs.tabs.copy (); - foreach (unowned var tab in tabs.tabs) { - var content = (ViewContainer)(tab.page); + for (int i = 0; i < tab_view.n_pages; i++) { + var tab = (Hdy.TabPage) tab_view.get_nth_page (i); + unowned var content = (ViewContainer) tab.child; if (content.tab_name == Files.INVALID_TAB_NAME) { set_tab_label (content.tab_name, tab, content.tab_name); continue; @@ -598,8 +676,9 @@ public class Files.View.Window : Hdy.ApplicationWindow { set_tab_label (basename, tab, content.tab_name); // Compare with every other tab for same label - foreach (unowned var tab2 in copy_tabs) { - var content2 = (ViewContainer)(tab2.page); + for (int j = 0; j < tab_view.n_pages; j++) { + var tab2 = (Hdy.TabPage) tab_view.get_nth_page (j); + unowned var content2 = (ViewContainer) tab2.child; if (content2 == content || content2.tab_name == Files.INVALID_TAB_NAME) { continue; } @@ -626,14 +705,14 @@ public class Files.View.Window : Hdy.ApplicationWindow { } /* Just to append "as Administrator" when appropriate */ - private void set_tab_label (string label, Granite.Widgets.Tab tab, string? tooltip = null) { + private void set_tab_label (string label, Hdy.TabPage tab, string? tooltip = null) { string lab = label; if (Files.is_admin ()) { lab += (" " + _("(as Administrator)")); } - tab.label = lab; + tab.title = lab; /* Needs change to Granite to allow (visible) tooltip amendment. * This compiles because tab is a widget but the tootip is overridden by that set internally */ @@ -643,7 +722,7 @@ public class Files.View.Window : Hdy.ApplicationWindow { tt += (" " + _("(as Administrator)")); } - tab.set_tooltip_text (tt); + tab.tooltip = tt; } } @@ -655,15 +734,26 @@ public class Files.View.Window : Hdy.ApplicationWindow { return !sidebar.has_favorite_uri (uri); } + private void move_content_to_new_window (ViewContainer view_container) { + add_window (view_container.location, view_container.view_mode); + remove_content (view_container); + } + public void remove_content (ViewContainer view_container) { - remove_tab (tabs.get_tab_by_widget ((Gtk.Widget)view_container)); + for (int n = 0; n < tab_view.n_pages; n++) { + var tab = tab_view.get_nth_page (n); + if (tab.get_child () == view_container) { + remove_tab (tab); + return; + } + } } - private void remove_tab (Granite.Widgets.Tab? tab) { + private void remove_tab (Hdy.TabPage? tab) { if (tab != null) { /* Use Idle in case of rapid closing of multiple tabs during restore */ Idle.add_full (Priority.LOW, () => { - tab.close (); + tab_view.close_page (tab); return GLib.Source.REMOVE; }); } @@ -697,9 +787,9 @@ public class Files.View.Window : Hdy.ApplicationWindow { private void action_bookmark (GLib.SimpleAction action, GLib.Variant? param) { /* Note: Duplicate bookmarks will not be created by BookmarkList */ - unowned var selected_files = current_tab.view.get_selected_files (); + unowned var selected_files = current_container.view.get_selected_files (); if (selected_files == null) { - sidebar.add_favorite_uri (current_tab.location.get_uri ()); + sidebar.add_favorite_uri (current_container.location.get_uri ()); } else if (selected_files.first ().next == null) { sidebar.add_favorite_uri (selected_files.first ().data.uri); } // Ignore if more than one item selected @@ -707,7 +797,7 @@ public class Files.View.Window : Hdy.ApplicationWindow { private void action_find (GLib.SimpleAction action, GLib.Variant? param) { /* Do not initiate search while slot is frozen e.g. during loading */ - if (current_tab == null || current_tab.is_frozen) { + if (current_container == null || current_container.is_frozen) { return; } @@ -739,30 +829,46 @@ public class Files.View.Window : Hdy.ApplicationWindow { private void action_reload () { /* avoid spawning reload when key kept pressed */ - if (tabs.current.working) { + if (tab_view.selected_page.loading) { warning ("Too rapid reloading suppressed"); return; } - current_tab.reload (); + current_container.reload (); sidebar.reload (); } + private void action_tabhistory_restore (SimpleAction action, GLib.Variant? parameter) { + add_tab_by_uri (parameter.get_string ()); + + var menu = (Menu) tab_history_button.menu_model; + for (var i = 0; i < menu.get_n_items (); i++) { + if (parameter == menu.get_item_attribute_value (i, Menu.ATTRIBUTE_TARGET, VariantType.STRING)) { + menu.remove (i); + break; + } + } + + if (menu.get_n_items () == 0) { + tab_history_button.menu_model = null; + } + } + private void action_view_mode (GLib.SimpleAction action, GLib.Variant? param) { - if (current_tab == null) { // can occur during startup + if (tab_view == null || current_container == null) { // can occur during startup return; } ViewMode mode = real_mode ((ViewMode)(param.get_uint32 ())); - current_tab.change_view_mode (mode); + current_container.change_view_mode (mode); /* ViewContainer takes care of changing appearance */ } private void action_back (SimpleAction action, Variant? param) { - current_tab.go_back (param.get_int32 ()); + current_container.go_back (param.get_int32 ()); } private void action_forward (SimpleAction action, Variant? param) { - current_tab.go_forward (param.get_int32 ()); + current_container.go_forward (param.get_int32 ()); } private void action_go_to (GLib.SimpleAction action, GLib.Variant? param) { @@ -792,7 +898,7 @@ public class Files.View.Window : Hdy.ApplicationWindow { break; case "UP": - current_tab.go_up (); + current_container.go_up (); break; default: @@ -801,19 +907,19 @@ public class Files.View.Window : Hdy.ApplicationWindow { } private void action_zoom (GLib.SimpleAction action, GLib.Variant? param) { - if (current_tab != null) { - assert (current_tab.view != null); + if (current_container != null) { + assert (current_container.view != null); switch (param.get_string ()) { case "ZOOM_IN": - current_tab.view.zoom_in (); + current_container.view.zoom_in (); break; case "ZOOM_OUT": - current_tab.view.zoom_out (); + current_container.view.zoom_out (); break; case "ZOOM_NORMAL": - current_tab.view.zoom_normal (); + current_container.view.zoom_normal (); break; default: @@ -829,23 +935,24 @@ public class Files.View.Window : Hdy.ApplicationWindow { break; case "CLOSE": - remove_tab (tabs.current); + remove_tab (tab_view.selected_page); break; case "NEXT": - tabs.next_page (); + tab_view.select_next_page (); break; case "PREVIOUS": - tabs.previous_page (); + tab_view.select_previous_page (); break; case "TAB": - add_tab (current_tab.location, current_tab.view_mode); + add_tab (current_container.location, current_container.view_mode); break; case "WINDOW": - tabs.tab_moved (tabs.current, 0, 0); + //Move current tab to a new window + move_content_to_new_window (current_container); break; default: @@ -900,8 +1007,8 @@ public class Files.View.Window : Hdy.ApplicationWindow { } public void after_undo_redo () { - if (current_tab.slot.directory.is_recent) { - current_tab.reload (); + if (current_container.slot.directory.is_recent) { + current_container.reload (); } doing_undo_redo = false; @@ -974,7 +1081,7 @@ public class Files.View.Window : Hdy.ApplicationWindow { return mode; case ViewMode.CURRENT: - return current_tab.view_mode; + return current_container.view_mode; default: break; @@ -989,11 +1096,11 @@ public class Files.View.Window : Hdy.ApplicationWindow { headerbar.destroy (); /* stop unwanted signals if quit while pathbar in focus */ - tabs.tab_removed.disconnect (on_tab_removed); /* Avoid infinite loop */ + tab_view.page_detached.disconnect (on_page_detached); /* Avoid infinite loop */ - foreach (var tab in tabs.tabs) { - current_tab = null; - ((View.ViewContainer)(tab.page)).close (); + for (int i = 0; i < tab_view.n_pages; i++) { + var tab_page = (Hdy.TabPage) tab_view.get_nth_page (i); + ((View.ViewContainer) tab_page.child).close (); } this.destroy (); @@ -1039,9 +1146,9 @@ public class Files.View.Window : Hdy.ApplicationWindow { } VariantBuilder vb = new VariantBuilder (new VariantType ("a(uss)")); - foreach (var tab in tabs.tabs) { - assert (tab != null); - var view_container = (ViewContainer)(tab.page) ; + for (int i = 0; i < tab_view.n_pages; i++) { + var tab = (Hdy.TabPage) tab_view.get_nth_page (i); + var view_container = (ViewContainer) tab.child; /* Do not save if "File does not exist" or "Does not belong to you" */ if (!view_container.can_show_folder) { @@ -1060,9 +1167,10 @@ public class Files.View.Window : Hdy.ApplicationWindow { } private void save_active_tab_position () { - if (tabs.current != null) { - Files.app_settings.set_int ("active-tab-position", tabs.get_tab_position (tabs.current)); - } + Files.app_settings.set_int ( + "active-tab-position", + tab_view.get_page_position (tab_view.selected_page) + ); } public uint restore_tabs () { @@ -1125,15 +1233,14 @@ public class Files.View.Window : Hdy.ApplicationWindow { active_tab_position = 0; } - tabs.current = tabs.get_tab_by_index (active_tab_position); - current_tab = (ViewContainer?)(tabs.current.page); + tab_view.selected_page = tab_view.get_nth_page (active_tab_position); string path = ""; - if (current_tab != null) { - path = current_tab.get_tip_uri (); + if (current_container != null) { + path = current_container.get_tip_uri (); if (path == null || path == "") { - path = current_tab.get_root_uri (); + path = current_container.get_root_uri (); } } @@ -1144,8 +1251,8 @@ public class Files.View.Window : Hdy.ApplicationWindow { private void expand_miller_view (string tip_uri, string unescaped_root_uri) { /* It might be more elegant for Miller.vala to handle this */ - var tab = tabs.current; - var view = (ViewContainer)(tab.page) ; + var tab = tab_view.selected_page; + var view = (ViewContainer)(tab.child); var mwcols = (Miller)(view.view) ; var unescaped_tip_uri = FileUtils.sanitize_path (tip_uri); @@ -1175,21 +1282,21 @@ public class Files.View.Window : Hdy.ApplicationWindow { } private void update_headerbar () { - if (restoring_tabs > 0 || current_tab == null) { + if (restoring_tabs > 0 || current_container == null) { return; } /* Update browser buttons */ - set_back_menu (current_tab.get_go_back_path_list ()); - set_forward_menu (current_tab.get_go_forward_path_list ()); - button_back.sensitive = current_tab.can_go_back; - button_forward.sensitive = (current_tab.can_show_folder && current_tab.can_go_forward); - location_bar.sensitive = !current_tab.is_loading; + set_back_menu (current_container.get_go_back_path_list ()); + set_forward_menu (current_container.get_go_forward_path_list ()); + button_back.sensitive = current_container.can_go_back; + button_forward.sensitive = (current_container.can_show_folder && current_container.can_go_forward); + location_bar.sensitive = !current_container.is_loading; /* Update viewmode switch, action state and settings */ - var mode = current_tab.view_mode; + var mode = current_container.view_mode; view_switcher.set_mode (mode); - view_switcher.sensitive = current_tab.can_show_folder; + view_switcher.sensitive = current_container.can_show_folder; get_action ("view-mode").change_state (new Variant.uint32 (mode)); Files.app_settings.set_enum ("default-viewmode", mode); } @@ -1231,8 +1338,8 @@ public class Files.View.Window : Hdy.ApplicationWindow { } private void update_labels (string uri) { - if (current_tab != null) { /* Can happen during restore */ - set_title (current_tab.tab_name); /* Not actually visible on elementaryos */ + if (current_container != null) { /* Can happen during restore */ + set_title (current_container.tab_name); /* Not actually visible on elementaryos */ update_location_bar (uri); sidebar.sync_uri (uri); } @@ -1242,12 +1349,12 @@ public class Files.View.Window : Hdy.ApplicationWindow { debug ("Mount %s removed", mount.get_name ()); GLib.File root = mount.get_root (); - foreach (var page in tabs.get_children ()) { - var view_container = (View.ViewContainer)page ; + for (int i = 0; i < tab_view.n_pages; i++) { + var view_container = (View.ViewContainer) tab_view.get_nth_page (i); GLib.File location = view_container.location; if (location == null || location.has_prefix (root) || location.equal (root)) { - if (view_container == current_tab) { + if (view_container == current_container) { view_container.focus_location (GLib.File.new_for_path (PF.UserUtils.get_real_user_home ())); } else { remove_content (view_container); @@ -1262,14 +1369,14 @@ public class Files.View.Window : Hdy.ApplicationWindow { if (file != null) { switch (flag) { case Files.OpenFlag.NEW_TAB: - add_tab (file, current_tab.view_mode); + add_tab (file, current_container.view_mode); break; case Files.OpenFlag.NEW_WINDOW: - add_window (file, current_tab.view_mode); + add_window (file, current_container.view_mode); break; default: grab_focus (); - current_tab.focus_location (file); + current_container.focus_location (file); break; } } else { @@ -1280,8 +1387,8 @@ public class Files.View.Window : Hdy.ApplicationWindow { /** Use this function to standardise how locations are generated from uris **/ private GLib.File? get_file_from_uri (string uri) { string? current_uri = null; - if (current_tab != null && current_tab.location != null) { - current_uri = current_tab.location.get_uri (); + if (current_container != null && current_container.location != null) { + current_uri = current_container.location.get_uri (); } string path = FileUtils.sanitize_path (uri, current_uri); @@ -1293,6 +1400,6 @@ public class Files.View.Window : Hdy.ApplicationWindow { } public new void grab_focus () { - current_tab.grab_focus (); + current_container.grab_focus (); } }