Skip to content

Commit

Permalink
[Gtk4Prep] BreadcrumbEntry: Use EventControllerKey (#2389)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremypw authored Jan 23, 2024
1 parent 2e0aa6c commit 54fe65a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 36 deletions.
45 changes: 13 additions & 32 deletions libcore/Widgets/BasicBreadcrumbsEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace Files.View.Chrome {
protected const double YPAD = 0; /* y padding */

private Gdk.Window? entry_window = null;
private Gtk.EventControllerKey key_controller;

protected bool context_menu_showing = false;

Expand All @@ -82,15 +83,7 @@ namespace Files.View.Chrome {

elements = new Gee.ArrayList<BreadcrumbElement> ();
old_elements = new Gee.ArrayList<BreadcrumbElement> ();
connect_signals ();

minimum_width = 100;
notify["scale-factor"].connect (() => {
breadcrumb_icons.scale = scale_factor;
});
}

protected virtual void connect_signals () {
realize.connect_after (after_realize);
activate.connect (on_activate);
button_release_event.connect (on_button_release_event);
Expand All @@ -99,8 +92,17 @@ namespace Files.View.Chrome {
motion_notify_event.connect_after (after_motion_notify);
focus_in_event.connect (on_focus_in);
focus_out_event.connect (on_focus_out);
key_press_event.connect (on_key_press_event);
changed.connect (on_entry_text_changed);

key_controller = new Gtk.EventControllerKey (this) {
propagation_phase = BUBBLE
};
key_controller.key_pressed.connect (on_key_press_event);

minimum_width = 100;
notify["scale-factor"].connect (() => {
breadcrumb_icons.scale = scale_factor;
});
}

/** Navigatable Interface **/
Expand Down Expand Up @@ -180,24 +182,15 @@ namespace Files.View.Chrome {

/** Signal handling **/
/*********************/
public virtual bool on_key_press_event (Gdk.EventKey event) {
if (event.is_modifier == 1) {
return true;
}

Gdk.ModifierType state;
event.get_state (out state);
public virtual bool on_key_press_event (uint keyval, uint keycode, Gdk.ModifierType state) {
var mods = state & Gtk.accelerator_get_default_mod_mask ();
bool only_control_pressed = (mods == Gdk.ModifierType.CONTROL_MASK);

uint keyval;
event.get_keyval (out keyval);
switch (keyval) {
/* Do not trap unmodified Down and Up keys - used by some input methods */
case Gdk.Key.KP_Down:
case Gdk.Key.Down:
if (only_control_pressed) {
go_down ();
activate_path ("");
return true;
}

Expand All @@ -216,14 +209,6 @@ namespace Files.View.Chrome {
activate_path ("");
return true;

case Gdk.Key.l:
if (only_control_pressed) {
set_entry_text (current_dir_path);
grab_focus ();
return true;
} else {
break;
}
default:
break;
}
Expand Down Expand Up @@ -367,10 +352,6 @@ namespace Files.View.Chrome {
entry_text_changed (text);
}

protected virtual void go_down () {
activate_path ("");
}

protected virtual void go_up () {
text = FileUtils.get_parent_path_from_path (text);
set_position (-1);
Expand Down
7 changes: 3 additions & 4 deletions src/View/Widgets/BreadcrumbsEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,23 @@ namespace Files.View.Chrome {

/** Overridden Navigatable interface functions **/
/************************************************/
public override bool on_key_press_event (Gdk.EventKey event) {
uint keyval;
event.get_keyval (out keyval);
public override bool on_key_press_event (uint keyval, uint keycode, Gdk.ModifierType state) {
switch (keyval) {
case Gdk.Key.Return:
case Gdk.Key.KP_Enter:
case Gdk.Key.ISO_Enter:
if (search_mode) {
return true;
}

break;
case Gdk.Key.KP_Tab:
case Gdk.Key.Tab:
complete ();
return true;
}

return base.on_key_press_event (event);
return base.on_key_press_event (keyval, keycode, state);
}

public override void reset () {
Expand Down

0 comments on commit 54fe65a

Please sign in to comment.