Commit f74fbb57 authored by Daniel García Moreno's avatar Daniel García Moreno

Escape management in only one method

I've moved the leave full screen on escape from the media_viewer to the
existing escape method in state.rs to have all the behaviour in only one
place.

Doing this I've also added the functionality to go back to the chat when
we're in the MediaViewer and to do this I've to modify a little the
autocomplete, to avoid the close when we press escape on the
autocomplete popover.

I've also changed the key management on key press instead of key release
because the keypress is grabbed by child windows or popovers and the
release isn't.

Close #277
parent 6999de57
Pipeline #17950 failed with stage
in 16 seconds
......@@ -198,25 +198,5 @@ impl App {
next_media_button.connect_clicked(move |_| {
op.lock().unwrap().next_media();
});
// Connecting escape key to leave fullscreen mode
let main_window = self.ui.builder
.get_object::<gtk::ApplicationWindow>("main_window")
.expect("Cant find main_window in ui file.");
let op = self.op.clone();
main_window.connect_key_release_event(move |w, k| {
// leave full screen only if we're currently in fullscreen
if let Some(win) = w.get_window() {
if !win.get_state().contains(gdk::WindowState::FULLSCREEN) {
return Inhibit(false);
}
}
if k.get_keyval() == gdk::enums::key::Escape {
op.lock().unwrap().leave_full_screen();
}
Inhibit(false)
});
}
}
......@@ -44,14 +44,13 @@ impl App {
});
let op = self.op.clone();
let chat: gtk::Widget = self.ui.builder
.get_object("room_view_stack")
.expect("Couldn't find room_view_stack in ui file.");
chat.connect_key_release_event(move |_, k| {
let main_window = self.ui.builder
.get_object::<gtk::ApplicationWindow>("main_window")
.expect("Cant find main_window in ui file.");
main_window.connect_key_press_event(move |w, k| {
match k.get_keyval() {
gdk::enums::key::Escape => {
op.lock().unwrap().escape();
Inhibit(true)
Inhibit(op.lock().unwrap().escape(w))
},
_ => Inhibit(false)
}
......
......@@ -80,10 +80,7 @@ pub struct AppOp {
pub more_members_btn: gtk::Button,
pub unsent_messages: HashMap<String, (String, i32)>,
pub highlighted_entry: Vec<String>,
pub popover_position: Option<i32>,
pub popover_search: Option<String>,
pub popover_closing: bool,
pub inhibit_escape: bool,
pub state: AppState,
pub since: Option<String>,
......@@ -138,10 +135,7 @@ impl AppOp {
member_limit: 50,
unsent_messages: HashMap::new(),
highlighted_entry: vec![],
popover_position: None,
popover_search: None,
popover_closing: false,
inhibit_escape: false,
logged_in: false,
loading_more: false,
......
extern crate gtk;
extern crate gdk;
use self::gtk::prelude::*;
use self::gdk::WindowExt;
use appop::AppOp;
use appop::room::RoomPanel;
......@@ -72,11 +74,31 @@ impl AppOp {
}
}
pub fn escape(&mut self) {
if let AppState::Chat = self.state {
self.room_panel(RoomPanel::NoRoom);
self.active_room = None;
self.clear_tmp_msgs();
pub fn escape(&mut self, w: &gtk::ApplicationWindow) -> bool {
if self.inhibit_escape {
return true;
}
// leave full screen only if we're currently in fullscreen
if let Some(win) = w.get_window() {
if win.get_state().contains(gdk::WindowState::FULLSCREEN) {
self.leave_full_screen();
return true;
}
}
match self.state {
AppState::Chat => {
self.room_panel(RoomPanel::NoRoom);
self.active_room = None;
self.clear_tmp_msgs();
true
},
AppState::MediaViewer => {
self.hide_media_viewer();
true
},
_ => { false }
}
}
}
......@@ -293,6 +293,7 @@ impl Autocomplete {
self.popover_search = None;
let visible = self.popover.is_visible();
self.popover.popdown();
self.op.lock().unwrap().inhibit_escape = false;
visible
}
......@@ -418,11 +419,11 @@ impl Autocomplete {
let mut widget_list : HashMap<String, gtk::EventBox> = HashMap::new();
if list.len() > 0 {
let guard = self.op.lock().unwrap();
for m in list.iter() {
let alias = &m.alias.clone().unwrap_or_default().trim_right_matches(" (IRC)").to_owned();
let widget;
{
let guard = self.op.lock().unwrap();
let mb = widgets::MemberBox::new(&m, &guard);
widget = mb.widget(true);
}
......@@ -453,10 +454,12 @@ impl Autocomplete {
}
self.popover.popup();
self.op.lock().unwrap().inhibit_escape = true;
}
else {
self.autocomplete_enter();
}
return widget_list;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment