Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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 @@ -135,6 +135,11 @@
<summary>Request dark Gtk stylesheet variant</summary>
<description>Switches between dark and light style</description>
</key>
<key name="follow-system-style" type="b">
<default>false</default>
<summary>Follow the FreeDesktop.org dark style preference</summary>
<description>Use the Dark style if the system prefers a dark style, or Solarized Light otherwise. Overrides control of prefer-dark-style.</description>
</key>
<key name="cyclic-search" type="b">
<default>false</default>
<summary>Whether search is cyclic</summary>
Expand Down
16 changes: 15 additions & 1 deletion src/Widgets/DocumentView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook {

update_inline_tab_colors ();
Scratch.settings.changed["style-scheme"].connect (update_inline_tab_colors);
Scratch.settings.changed["follow-system-style"].connect (update_inline_tab_colors);
var granite_settings = Granite.Settings.get_default ();
granite_settings.notify["prefers-color-scheme"].connect (update_inline_tab_colors);

// Handle Drag-and-drop of files onto add-tab button to create document
Gtk.TargetEntry uris = {"text/uri-list", 0, TargetType.URI_LIST};
Expand All @@ -107,8 +110,19 @@ public class Scratch.Widgets.DocumentView : Granite.Widgets.DynamicNotebook {
}

private void update_inline_tab_colors () {
var style_scheme = "";
if (settings.get_boolean ("follow-system-style")) {
var system_prefers_dark = Granite.Settings.get_default ().prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
if (system_prefers_dark) {
style_scheme = "solarized-dark";
} else {
style_scheme = "solarized-light";
}
} else {
style_scheme = Scratch.settings.get_string ("style-scheme");
}

var sssm = Gtk.SourceStyleSchemeManager.get_default ();
var style_scheme = Scratch.settings.get_string ("style-scheme");
if (style_scheme in sssm.scheme_ids) {
var theme = sssm.get_scheme (style_scheme);
var text_color_data = theme.get_style ("text");
Expand Down
63 changes: 48 additions & 15 deletions src/Widgets/HeaderBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ namespace Scratch.Widgets {
font_size_grid.add (zoom_default_button);
font_size_grid.add (zoom_in_button);

var follow_system_switchmodelbutton = new Granite.SwitchModelButton (_("Follow System Style")) {
margin_top = 3
};

// Intentionally never attached so we can have a non-selected state
var color_button_none = new Gtk.RadioButton (null);

Expand All @@ -144,8 +148,23 @@ namespace Scratch.Widgets {
color_button_dark.halign = Gtk.Align.CENTER;
style_color_button (color_button_dark, STYLE_SCHEME_DARK);

var menu_separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
menu_separator.margin_top = 12;
var color_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 3) {
homogeneous = true,
margin_top = 6,
margin_bottom = 6
};

color_box.add (color_button_white);
color_box.add (color_button_light);
color_box.add (color_button_dark);

var color_revealer = new Gtk.Revealer ();
color_revealer.add (color_box);

var menu_separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL) {
margin_bottom = 3,
margin_top = 3
};

var toggle_sidebar_accellabel = new Granite.AccelLabel.from_action_name (
_("Toggle Sidebar"),
Expand All @@ -161,21 +180,21 @@ namespace Scratch.Widgets {
preferences_menuitem.text = _("Preferences");
preferences_menuitem.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_PREFERENCES;

var menu_grid = new Gtk.Grid ();
menu_grid.margin_bottom = 3;
menu_grid.orientation = Gtk.Orientation.VERTICAL;
menu_grid.width_request = 200;
menu_grid.attach (font_size_grid, 0, 0, 3, 1);
menu_grid.attach (color_button_white, 0, 1, 1, 1);
menu_grid.attach (color_button_light, 1, 1, 1, 1);
menu_grid.attach (color_button_dark, 2, 1, 1, 1);
menu_grid.attach (menu_separator, 0, 2, 3, 1);
menu_grid.attach (toggle_sidebar_menuitem, 0, 3, 3, 1);
menu_grid.attach (preferences_menuitem, 0, 6, 3);
menu_grid.show_all ();
var menu_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) {
margin_bottom = 3,
width_request = 200
};
menu_box.add (font_size_grid);
menu_box.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
menu_box.add (follow_system_switchmodelbutton);
menu_box.add (color_revealer);
menu_box.add (menu_separator);
menu_box.add (toggle_sidebar_menuitem);
menu_box.add (preferences_menuitem);
menu_box.show_all ();

var menu = new Gtk.Popover (null);
menu.add (menu_grid);
menu.add (menu_box);

var app_menu = new Gtk.MenuButton ();
app_menu.image = new Gtk.Image.from_icon_name ("open-menu", Gtk.IconSize.LARGE_TOOLBAR);
Expand Down Expand Up @@ -217,6 +236,20 @@ namespace Scratch.Widgets {
}
});

follow_system_switchmodelbutton.bind_property (
"active",
color_revealer,
"reveal-child",
GLib.BindingFlags.SYNC_CREATE | BindingFlags.INVERT_BOOLEAN
);

Scratch.settings.bind (
"follow-system-style",
follow_system_switchmodelbutton,
"active",
SettingsBindFlags.DEFAULT
);

var gtk_settings = Gtk.Settings.get_default ();

switch (Scratch.settings.get_string ("style-scheme")) {
Expand Down
21 changes: 19 additions & 2 deletions src/Widgets/SourceView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ namespace Scratch.Widgets {
restore_settings ();
settings.changed.connect (restore_settings);

var granite_settings = Granite.Settings.get_default ();
granite_settings.notify["prefers-color-scheme"].connect (restore_settings);

scroll_event.connect ((key_event) => {
if ((Gdk.ModifierType.CONTROL_MASK in key_event.state) && key_event.delta_y < 0) {
((Scratch.Application) GLib.Application.get_default ()).get_last_window ().action_zoom_in ();
Expand Down Expand Up @@ -287,8 +290,22 @@ namespace Scratch.Widgets {
critical (e.message);
}

var scheme = style_scheme_manager.get_scheme (Scratch.settings.get_string ("style-scheme"));
source_buffer.style_scheme = scheme ?? style_scheme_manager.get_scheme ("classic");
var gtk_settings = Gtk.Settings.get_default ();
if (settings.get_boolean ("follow-system-style")) {
var system_prefers_dark = Granite.Settings.get_default ().prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
gtk_settings.gtk_application_prefer_dark_theme = system_prefers_dark;

if (system_prefers_dark) {
source_buffer.style_scheme = style_scheme_manager.get_scheme ("solarized-dark");
} else {
source_buffer.style_scheme = style_scheme_manager.get_scheme ("solarized-light");
}
} else {
gtk_settings.gtk_application_prefer_dark_theme = settings.get_boolean ("prefer-dark-style");
var scheme = style_scheme_manager.get_scheme (Scratch.settings.get_string ("style-scheme"));
source_buffer.style_scheme = scheme ?? style_scheme_manager.get_scheme ("classic");
}

git_diff_gutter_renderer.set_style_scheme (source_buffer.style_scheme);
style_changed (source_buffer.style_scheme);
}
Expand Down