Skip to content

Commit

Permalink
Add support for dragging tab out of window to open tab in new window …
Browse files Browse the repository at this point in the history
…with Hdy.TabView DocumentView
  • Loading branch information
colinkiama committed Mar 21, 2024
1 parent 6682f25 commit a5b47bb
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Widgets/DocumentView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Scratch.Widgets.DocumentView : Gtk.Box {
document_change (_current_document, this);
_current_document.focus ();
save_focused_document_uri (current_document);
if (tab_view.selected_page != value.tab) {
if (tab_view.selected_page != value.tab && value.tab != null) {
tab_view.selected_page = value.tab;
}
}
Expand Down Expand Up @@ -81,6 +81,10 @@ public class Scratch.Widgets.DocumentView : Gtk.Box {
tab_view.menu_model = new GLib.Menu ();
tab_view.setup_menu.connect (tab_view_setup_menu);
tab_view.notify["selected-page"].connect (() => {
if (tab_view.selected_page == null) {
return;
}

current_document = tab_view.selected_page.child as Services.Document;
});

Expand Down Expand Up @@ -132,6 +136,7 @@ public class Scratch.Widgets.DocumentView : Gtk.Box {

tab_view.page_detached.connect (on_doc_removed);
tab_view.page_reordered.connect (on_doc_reordered);
tab_view.create_window.connect (on_doc_to_new_window);

notify["outline-visible"].connect (update_outline_visible);
Scratch.saved_state.bind ("outline-width", this, "outline-width", DEFAULT);
Expand Down Expand Up @@ -405,6 +410,11 @@ public class Scratch.Widgets.DocumentView : Gtk.Box {
save_opened_files ();
}

private unowned Hdy.TabView? on_doc_to_new_window (Hdy.TabView tab_view) {
var other_window = new MainWindow (false);
return other_window.document_view.tab_view;
}

private bool on_focus_in_event () {
var doc = current_document;
if (doc == null) {
Expand Down

0 comments on commit a5b47bb

Please sign in to comment.