Skip to content

Commit

Permalink
- Allow users to create custom actions - Closes Issue #48
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryCasiano committed Aug 20, 2020
1 parent 11f884a commit 2e6b2b3
Show file tree
Hide file tree
Showing 15 changed files with 458 additions and 11 deletions.
4 changes: 2 additions & 2 deletions fedora/font-manager.spec
Expand Up @@ -8,7 +8,7 @@

Name: font-manager
Version: %{MajorVersion}.%{MinorVersion}.%{PatchVersion}.%{build_timestamp}
Release: 9
Release: 10
Summary: A simple font management application for Gtk+ Desktop Environments
License: GPLv3+
Url: http://fontmanager.github.io/
Expand Down Expand Up @@ -125,5 +125,5 @@ appstream-util validate-relax --nonet %{buildroot}/%{_datadir}/metainfo/*.appdat
%{_libdir}/nemo/extensions-3.0/nemo-font-manager.so

%changelog
* Sat Sep 21 2019 JerryCasiano <JerryCasiano@gmail.com> 0.7.8-9
* Sat Sep 21 2019 JerryCasiano <JerryCasiano@gmail.com> 0.7.8-10
- Refer to https://github.com/FontManager/font-manager/commits/master for changes.
3 changes: 2 additions & 1 deletion lib/common/FontManager.css
Expand Up @@ -139,7 +139,8 @@ treeview {
border-color: alpha(@borders, 0.75);
}

#FontManagerAliasList row {
#FontManagerAliasList row,
#FontManagerUserActionRow {
border-radius: 0.25em;
}

Expand Down
3 changes: 2 additions & 1 deletion meson.build
Expand Up @@ -17,6 +17,7 @@ fontconfig = dependency('fontconfig', version: '>= 2.1')
freetype = dependency('freetype2', version: '>= 2.5')
json = dependency('json-glib-1.0', version: '>= 0.15')
gio = dependency('gio-2.0', version: '>= 2.44')
gio_unix = dependency('gio-unix-2.0', version: '>= 2.44')
glib = dependency('glib-2.0', version: '>= 2.62')
gmodule = dependency('gmodule-2.0', version: '>= 2.44')
gobject = dependency('gobject-2.0', version: '>= 2.44')
Expand All @@ -27,7 +28,7 @@ sqlite = dependency('sqlite3', version: '>= 3.8')
xml = dependency('libxml-2.0', version: '>= 2.9')

base_deps = declare_dependency(
dependencies: [m_dep, json, gio, glib, gmodule, gobject, gtk, pango, sqlite, xml],
dependencies: [m_dep, json, gio, gio_unix, glib, gmodule, gobject, gtk, pango, sqlite, xml],
include_directories: include_directories('.', 'lib/common', 'lib/orthographies', 'lib/unicode')
)

Expand Down
Expand Up @@ -22,6 +22,8 @@ namespace FontManager {

public class Cacheable : Object, Json.Serializable {

public signal void changed ();

public virtual bool deserialize_property (string prop_name,
out Value val,
ParamSpec pspec,
Expand Down
15 changes: 15 additions & 0 deletions src/font-manager/Dialogs.vala
Expand Up @@ -55,6 +55,21 @@ namespace FontManager {

namespace FileSelector {

public string? get_executable () {
var dialog = new Gtk.FileChooserNative(_("Select executable"),
main_window,
Gtk.FileChooserAction.OPEN,
_("_Select"),
_("_Cancel"));
dialog.set_current_folder("/usr/bin");
dialog.set_select_multiple(false);
string? selection = null;
if (dialog.run() == Gtk.ResponseType.ACCEPT)
selection = dialog.get_filename();
dialog.destroy();
return selection;
}

public string? get_target_directory () {
var dialog = new Gtk.FileChooserNative(_("Select Destination"),
main_window,
Expand Down
19 changes: 19 additions & 0 deletions src/font-manager/FontList.vala
Expand Up @@ -281,6 +281,7 @@ Start search using %s to filter based on characters."""). printf(Path.DIR_SEPARA
public string selected_iter { get; protected set; default = "0"; }
public string? selected_family { get; private set; default = null; }
public Font? selected_font { get; private set; default = null; }
public UserActionModel? user_actions { get; set; default = null; }

Gtk.Menu context_menu;
Gtk.MenuItem? filename = null;
Expand All @@ -291,6 +292,12 @@ Start search using %s to filter based on characters."""). printf(Path.DIR_SEPARA
set_rubber_banding(true);
get_selection().set_mode(Gtk.SelectionMode.MULTIPLE);
context_menu = get_context_menu();
notify["user-actions"].connect(() => {
context_menu = get_context_menu();
user_actions.items_changed.connect(() => {
context_menu = get_context_menu();
});
});
selected_font = new Font();
}

Expand Down Expand Up @@ -428,6 +435,7 @@ Start search using %s to filter based on characters."""). printf(Path.DIR_SEPARA
filename.get_style_context().add_class("SensitiveChildLabel");
filename.get_child().opacity = 0.7;
filename.show();
filename.label = selected_font.is_valid() ? Path.get_basename(selected_font.filepath) : null;
popup_menu.append(filename);
var label = ((Gtk.Bin) filename).get_child();
label.set("hexpand", true, "justify", Gtk.Justification.FILL, "margin", 2, null);
Expand All @@ -443,6 +451,17 @@ Start search using %s to filter based on characters."""). printf(Path.DIR_SEPARA
if (entry.action_name == "install")
installable = item;
}
if (user_actions != null && user_actions.get_n_items() > 0) {
foreach (var entry in user_actions) {
var item = new Gtk.MenuItem.with_label(entry.action_name);
if (entry.comment != null)
item.set_tooltip_text(entry.comment);
item.get_child().set_halign(Gtk.Align.CENTER);
item.activate.connect(() => { entry.run(selected_font); });
item.show();
popup_menu.append(item);
}
}
/* Wayland complains if not set */
popup_menu.realize.connect(() => {
Gdk.Window child = popup_menu.get_window();
Expand Down
2 changes: 2 additions & 0 deletions src/font-manager/MainWindow.vala
Expand Up @@ -129,6 +129,8 @@ namespace FontManager {
Object(title: About.DISPLAY_NAME, icon_name: About.ICON);
fontlist_pane.fontlist = new FontList();
initialize_preference_pane(preference_pane);
var user_action_list = ((UserActionList) preference_pane.get_page("UserActions"));
fontlist.user_actions = user_action_list.model;
add_actions();
if (settings != null)
use_csd = settings.get_boolean("use-csd");
Expand Down
2 changes: 2 additions & 0 deletions src/font-manager/font-manager-gresources.xml
Expand Up @@ -25,6 +25,8 @@
<file compressed="true" preprocess="xml-stripblanks">ui/font-manager-subpixel-geometry-icon.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/font-manager-subpixel-geometry.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/font-manager-title-button-style.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/font-manager-user-action-list.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/font-manager-user-action-row.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/font-manager-user-data.ui</file>
</gresource>
</gresources>
1 change: 0 additions & 1 deletion src/font-manager/preferences/Desktop.vala
Expand Up @@ -18,7 +18,6 @@
* If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
*/


namespace FontManager {

internal const string GNOME_INTERFACE_ID = "org.gnome.desktop.interface";
Expand Down
14 changes: 10 additions & 4 deletions src/font-manager/preferences/Preferences.vala
Expand Up @@ -27,6 +27,7 @@ namespace FontManager {
pane.add_page(new SubstitutionPreferences(), "Substitutions", _("Substitutions"));
pane.add_page(new DisplayPreferences(), "Display", _("Display"));
pane.add_page(new RenderingPreferences(), "Rendering", _("Rendering"));
pane.add_page(new UserActionList(), "UserActions", _("User Actions"));
return;
}

Expand Down Expand Up @@ -56,10 +57,15 @@ namespace FontManager {
return;
}

public Gtk.Widget get_page (string name) {
var scroll = ((Gtk.Container) stack.get_child_by_name(name));
var viewport = scroll.get_children().nth_data(0);
var widget = ((Gtk.Container) viewport).get_children().nth_data(0);
public Gtk.Widget? get_page (string name) {
Gtk.Widget? widget = null;
var child = ((Gtk.Container) stack.get_child_by_name(name));
if (child is Gtk.ScrolledWindow) {
var viewport = child.get_children().nth_data(0);
widget = ((Gtk.Container) viewport).get_children().nth_data(0);
} else {
widget = child;
}
return widget;
}

Expand Down
2 changes: 1 addition & 1 deletion src/font-manager/preferences/Sources.vala
Expand Up @@ -45,9 +45,9 @@ Note that not all environments/applications will honor these settings.""");
controls.get_style_context().add_class(Gtk.STYLE_CLASS_VIEW);
controls.add_button.sensitive = (sources != null);
help = new InlineHelp();
help.margin = 1;
help.margin_start = help.margin_end = 2;
help.message.set_text(help_text);
((Gtk.Image) help.get_child()).set_pixel_size(22);
controls.box.pack_end(help, false, false, 0);
box.pack_start(controls, false, false, 1);
add_separator(box, Gtk.Orientation.HORIZONTAL);
Expand Down

0 comments on commit 2e6b2b3

Please sign in to comment.