Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Re #204: Add and remove pages when navigating
Browse files Browse the repository at this point in the history
This is the harshest version of removing pages when we're not using
them. We only keep extra pages in the stack until we're done with them.
But the pages are still created and keep state, so they don't lose
positions etc

Also now pass the main window around so that we don't assume a
base/parent when it might not be set.

This won't work as-is with the libhandy redesign (because we need to
keep all of the main tabs as children so we populate the switcher).
  • Loading branch information
IBBoard committed Mar 11, 2021
1 parent db22c3b commit a73266a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/DefaultTimeline.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public abstract class DefaultTimeline : ScrollWidget, IPage {
public unowned MainWindow window {
set {
main_window = value;
tweet_list.main_window = main_window;
}
}
public TweetListBox tweet_list = new TweetListBox ();
Expand Down
1 change: 1 addition & 0 deletions src/ListStatusesPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ListStatusesPage : ScrollWidget, Cb.MessageReceiver, IPage {
public unowned MainWindow window {
set {
main_window = value;
tweet_list.main_window = main_window;
}
}
public unowned Account account;
Expand Down
20 changes: 13 additions & 7 deletions src/MainWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ public class MainWidget : Gtk.Box {
stack.notify["transition-running"].connect(() => {
if (stack.transition_running == false) {
var visible_child = stack.visible_child;
stack.get_children().foreach((w) => { if (w != visible_child) { w.hide(); }});
stack.get_children().foreach((w) => { if (w != visible_child) { stack.remove(w); }});
}
});
this.add (stack);

stack.add (stack_impostor);

pages = new IPage[11];
pages[0] = new HomeTimeline (Page.STREAM, account);
pages[1] = new MentionsTimeline (Page.MENTIONS, account);
Expand All @@ -85,7 +83,7 @@ public class MainWidget : Gtk.Box {
account.user_stream.register ((Cb.MessageReceiver)page);

page.create_radio_button (dummy_button);
stack.add (page);

if (page.get_radio_button () != null) {
top_box.add (page.get_radio_button ());
page.get_radio_button ().clicked.connect (() => {
Expand Down Expand Up @@ -146,12 +144,18 @@ public class MainWidget : Gtk.Box {
args = history.get_current_bundle ();
}

IPage page = pages[page_id];

if (page_id == current_page) {
stack_impostor.clone (pages[page_id]);
stack_impostor.clone (page);
var transition_type = stack.transition_type;
stack.transition_type = Gtk.StackTransitionType.NONE;
if (stack_impostor.parent == null) {
stack.add(stack_impostor);
}
stack.set_visible_child (stack_impostor);
stack.transition_type = transition_type;
stack.remove(page);
}

if (current_page != -1)
Expand All @@ -166,18 +170,20 @@ public class MainWidget : Gtk.Box {
/* XXX The following will cause switch_page to be called twice
because setting the active property of the button will cause
the clicked event to be emitted, which will call switch_page. */
IPage page = pages[page_id];
Gtk.ToggleButton button = page.get_radio_button ();
page_switch_lock = true;
if (button != null)
button.active = true;
else
dummy_button.active = true;

if (page.parent == null) {
stack.add(page);
}
/* on_join first, then set_visible_child so the new page is still !child-visible,
so e.g. GtkStack transitions inside the page aren't animated */
page.on_join (page_id, args);
page.show();
page.show_all();
stack.set_visible_child (page);
((MainWindow)this.parent).set_window_title (page.get_title (), stack.transition_type);

Expand Down
3 changes: 3 additions & 0 deletions src/ProfilePage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class ProfilePage : ScrollWidget, IPage, Cb.MessageReceiver {
set {
main_window = value;
user_lists.main_window = value;
tweet_list.main_window = main_window;
followers_list.main_window = main_window;
followers_list.main_window = main_window;
}
}
public unowned Account account;
Expand Down
1 change: 1 addition & 0 deletions src/SearchPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SearchPage : IPage, Cb.MessageReceiver, Gtk.Box {
public unowned MainWindow window {
set {
main_window = value;
tweet_list.main_window = main_window;
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/TweetInfoPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class TweetInfoPage : IPage, ScrollWidget, Cb.MessageReceiver {
public unowned MainWindow window {
set {
main_window = value;
replied_to_list_box.main_window = main_window;
replies_list_box.main_window = main_window;
self_replies_list_box.main_window = main_window;
mentioned_replies_list_box.main_window = main_window;
}
}
public unowned Account account;
Expand Down
3 changes: 2 additions & 1 deletion src/widgets/TweetListBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class TweetListBox : ListBox {
return _action_entry;
}
}
public MainWindow main_window { private get; set; }

public TweetListBox () {
}
Expand All @@ -48,7 +49,7 @@ public class TweetListBox : ListBox {
assert (obj is Cb.Tweet);

var row = new TweetListEntry ((Cb.Tweet) obj,
(MainWindow) get_toplevel (),
main_window,
this.account);
row.fade_in ();
return row;
Expand Down
11 changes: 8 additions & 3 deletions ui/tweet-info-page.ui
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<child>
<object class="GtkLabel" id="missing_tweet_label">
<property name="visible">0</property>
<property name="no-show-all">1</property>
<property name="margin-top">18</property>
<property name="margin-bottom">18</property>
<property name="margin-start">6</property>
Expand All @@ -41,6 +42,7 @@
<child>
<object class="TweetListBox" id="replied_to_list_box">
<property name="visible">0</property>
<property name="no-show-all">1</property>
<property name="can-focus">False</property>
<property name="selection-mode">none</property>
</object>
Expand Down Expand Up @@ -439,21 +441,24 @@

<child>
<object class="TweetListBox" id="self_replies_list_box">
<property name="visible">1</property>
<property name="visible">0</property>
<property name="no-show-all">1</property>
<property name="selection-mode">none</property>
<property name="hexpand">1</property>
</object>
</child>
<child>
<object class="TweetListBox" id="mentioned_replies_list_box">
<property name="visible">1</property>
<property name="visible">0</property>
<property name="no-show-all">1</property>
<property name="selection-mode">none</property>
<property name="hexpand">1</property>
</object>
</child>
<child>
<object class="TweetListBox" id="replies_list_box">
<property name="visible">1</property>
<property name="visible">0</property>
<property name="no-show-all">1</property>
<property name="selection-mode">none</property>
<property name="hexpand">1</property>
</object>
Expand Down

0 comments on commit a73266a

Please sign in to comment.