Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronise and save symbol outline width. #1389

Merged
merged 2 commits into from
Dec 20, 2023
Merged
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
5 changes: 5 additions & 0 deletions data/io.elementary.code.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
<summary>Symbol outline visibility</summary>
<description>Whether or not the symbol outline is visible</description>
</key>
<key name="outline-width" type="i">
<default>160</default>
<summary>Symbol outline width</summary>
<description>Width of the symbol outline sidebar</description>
</key>
<key name="last-opened-path" type="s">
<default>''</default>
<summary>Last opened path</summary>
Expand Down
30 changes: 27 additions & 3 deletions src/Services/Document.vala
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ namespace Scratch.Services {
public Gtk.Stack main_stack;
public Scratch.Widgets.SourceView source_view;
private Scratch.Services.SymbolOutline? outline = null;
private Scratch.Widgets.DocumentView doc_view {
get {
return ((MainWindow) get_toplevel ()).document_view;
}
}

public string original_content = "";
private string last_save_content = "";
public bool saved = true;
Expand Down Expand Up @@ -1150,16 +1156,34 @@ namespace Scratch.Services {

if (outline != null) {
outline_widget_pane.pack2 (outline.get_widget (), false, false);
var position = int.max (outline_widget_pane.get_allocated_width () * 4 / 5, 100);
outline_widget_pane.set_position (position);
outline.parse_symbols ();
Idle.add (() => {
set_outline_width (doc_view.outline_width);
outline_widget_pane.notify["position"].connect (sync_outline_width);
outline.parse_symbols ();
return Source.REMOVE;
});
}
} else if (!show && outline != null) {
outline_widget_pane.notify["position"].disconnect (sync_outline_width);
outline_widget_pane.get_child2 ().destroy ();
outline = null;
}
}

private void sync_outline_width () {
var width = outline_widget_pane.get_allocated_width () - outline_widget_pane.position;
if (width != doc_view.outline_width) {
doc_view.outline_width = width;
}
}

public void set_outline_width (int width) {
if (outline != null) {
var aw = outline_widget_pane.get_allocated_width ();
outline_widget_pane.position = (aw - width);
}
}

private void unmounted_cb () {
warning ("Folder containing the file was unmounted");
mounted = false;
Expand Down
8 changes: 7 additions & 1 deletion src/Widgets/DocumentView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook {

public bool is_closing = false;
public bool outline_visible { get; set; default = false; }
public int outline_width { get; set; }

private Gtk.CssProvider style_provider;

Expand Down Expand Up @@ -108,7 +109,12 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook {
granite_settings.notify["prefers-color-scheme"].connect (update_inline_tab_colors);

notify["outline-visible"].connect (update_outline_visible);

Scratch.saved_state.bind ("outline-width", this, "outline-width", DEFAULT);
this.notify["outline-width"].connect (() => {
foreach (var doc in docs) {
doc.set_outline_width (outline_width);
}
});
// Handle Drag-and-drop of files onto add-tab button to create document
Gtk.TargetEntry uris = {"text/uri-list", 0, TargetType.URI_LIST};
Gtk.drag_dest_set (this, Gtk.DestDefaults.ALL, {uris}, Gdk.DragAction.COPY);
Expand Down