Skip to content

Commit

Permalink
Show running branch if not master (elementary#1258)
Browse files Browse the repository at this point in the history
* Provide branch build from as Constant.BRANCH; show in header

* Only insert branch label if will be shown; tooltip

* Expose branch in window title

* Exclude development focus in meson

* Handle no git command

* Use find_program()

* Use meson option instead of defined develpment focus

* Revert using PROJECT_NAME in window title

* Add modified branch name to application_id when present

* Show branch in Dock when installed with development option
  • Loading branch information
Jeremy Wootten authored Feb 10, 2023
1 parent 78e66a0 commit 6d31b6b
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion data/io.elementary.code.desktop.in.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Desktop Entry]
Type=Application
Name=Code
Name=@NAME@
Comment=Edit code files
GenericName=Code Editor
Exec=@EXEC_NAME@ %U
Expand Down
6 changes: 6 additions & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ install_data(
config_data = configuration_data()
config_data.set('EXEC_NAME', meson.project_name())

if (branch != '')
config_data.set('NAME', 'Code - ' + branch)
else
config_data.set('NAME', 'Code')
endif

# Set the executable name and translate the desktop files
desktop_in_file = configure_file(
input: 'io.elementary.code.desktop.in.in',
Expand Down
7 changes: 7 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ dependencies = [
vte_dep
]

git = find_program('git', required: false)
branch = ''
if get_option('development') and git.found ()
output = run_command('git','branch','--show-current', check: false)
branch = output.stdout().strip()
endif

subdir('data')
subdir('src')
if get_option('plugins')
Expand Down
1 change: 1 addition & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
option ('plugins', type : 'boolean', value : true)
option('have_pkexec', type : 'boolean', value : 'true', description : 'Allow launching with pkexec. Should not be used in FlatPak')
option('development', type : 'boolean', value : false, description : 'Build is a development branch')
3 changes: 3 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ namespace Scratch {
flags |= ApplicationFlags.HANDLES_COMMAND_LINE;

application_id = Constants.PROJECT_NAME;
if (Constants.BRANCH != "") {
application_id += "." + Constants.BRANCH.replace ("/", ".").replace ("-", "_");
}

add_main_option_entries (ENTRIES);

Expand Down
18 changes: 13 additions & 5 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ namespace Scratch {
public const string ACTION_RESTORE_PROJECT_DOCS = "action_restore_project_docs";

public static Gee.MultiMap<string, string> action_accelerators = new Gee.HashMultiMap<string, string> ();
private static string base_title;

private const ActionEntry[] ACTION_ENTRIES = {
{ ACTION_FIND, action_fetch, "s" },
Expand Down Expand Up @@ -148,7 +149,6 @@ namespace Scratch {
public MainWindow (bool restore_docs) {
Object (
icon_name: Constants.PROJECT_NAME,
title: _("Code"),
restore_docs: restore_docs
);
}
Expand Down Expand Up @@ -199,12 +199,19 @@ namespace Scratch {
Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);

if (Constants.BRANCH != "") {
base_title = _("Code (%s)").printf (Constants.BRANCH);
} else {
base_title = _("Code");
}

Hdy.init ();
}

construct {
application = ((Gtk.Application)(GLib.Application.get_default ()));
app = (Scratch.Application)application;
title = base_title;

weak Gtk.IconTheme default_theme = Gtk.IconTheme.get_default ();
default_theme.add_resource_path ("/io/elementary/code");
Expand Down Expand Up @@ -340,7 +347,7 @@ namespace Scratch {

private void init_layout () {
toolbar = new Scratch.HeaderBar ();
toolbar.title = title;
toolbar.title = base_title;

// SearchBar
search_bar = new Scratch.Widgets.SearchBar (this);
Expand Down Expand Up @@ -482,7 +489,7 @@ namespace Scratch {

document_view.request_placeholder.connect (() => {
content_stack.visible_child = welcome_view;
title = _("Code");
title = base_title;
toolbar.document_available (false);
set_widgets_sensitive (false);
});
Expand All @@ -502,7 +509,8 @@ namespace Scratch {
if (doc != null) {
search_bar.set_text_view (doc.source_view);
// Update MainWindow title
title = doc.get_basename ();
/// TRANSLATORS: First placeholder is document name, second placeholder is app name
title = _("%s - %s").printf (doc.get_basename (), base_title);

toolbar.set_document_focus (doc);
sidebar.choose_project_button.set_document (doc);
Expand All @@ -515,7 +523,7 @@ namespace Scratch {
Utils.action_from_group (ACTION_SAVE_AS, actions).set_enabled (doc.file != null);
doc.check_undoable_actions ();
} else {
title = _("Code");
title = base_title;
Utils.action_from_group (ACTION_SAVE_AS, actions).set_enabled (false);
}
});
Expand Down
1 change: 1 addition & 0 deletions src/config.vala.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ namespace Constants {
public const string INSTALL_PREFIX = @PREFIX@;
public const string DATADIR = @DATADIR@;
public const string LOCALEDIR = @LOCALEDIR@;
public const string BRANCH = @BRANCH@;
}
2 changes: 2 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ conf_data.set_quoted('PREFIX', get_option('prefix'))
conf_data.set_quoted('PLUGINDIR', pluginsdir)
conf_data.set_quoted('DATADIR', join_paths (get_option('prefix'), get_option('datadir')))
conf_data.set_quoted('LOCALEDIR', join_paths (get_option('prefix'), get_option('localedir')))
conf_data.set_quoted('BRANCH', branch)

config_header = configure_file(
input : 'config.vala.in',
output : 'config.vala',
Expand Down

0 comments on commit 6d31b6b

Please sign in to comment.