Skip to content

Commit

Permalink
Fix menu item not working when nothing selected
Browse files Browse the repository at this point in the history
  • Loading branch information
muriloventuroso committed Aug 27, 2018
1 parent 9a8ce39 commit 25ed298
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
22 changes: 12 additions & 10 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ namespace EasySSH {

public const string ACTION_PREFIX = "win.";
public const string ACTION_NEW_CONN = "action_new_conn";
public const string ACTION_EDIT_CONN = "action_edit_conn";
public const string ACTION_REMOVE_CONN = "action_remove_conn";
public const string ACTION_PREFERENCES = "action_preferences";

public SimpleActionGroup actions { get; construct; }
Expand All @@ -40,8 +38,6 @@ namespace EasySSH {

private const ActionEntry[] action_entries = {
{ ACTION_NEW_CONN, action_new_conn },
{ ACTION_EDIT_CONN, action_edit_conn },
{ ACTION_REMOVE_CONN, action_remove_conn },
{ ACTION_PREFERENCES, action_preferences },
};

Expand Down Expand Up @@ -146,6 +142,12 @@ namespace EasySSH {
sourcelist.load_ssh_config ();
sourcelist.save_hosts ();
});
sourcelist.host_edit_clicked.connect ((name) => {
sourcelist.edit_conn(name);
});
sourcelist.host_remove_clicked.connect ((name) => {
sourcelist.remove_conn(name);
});
}

private void get_default_filemanager () {
Expand Down Expand Up @@ -287,14 +289,14 @@ namespace EasySSH {

main_actions.get_action ("Paste").set_sensitive (can_paste);
}
private void action_new_conn () {
sourcelist.new_conn();
public void action_edit_conn (string name) {
sourcelist.edit_conn(name);
}
private void action_edit_conn () {
sourcelist.edit_conn();
public void action_remove_conn (string name) {
sourcelist.remove_conn(name);
}
private void action_remove_conn () {
sourcelist.remove_conn();
private void action_new_conn () {
sourcelist.new_conn();
}
private void action_preferences () {
if (preferences_dialog == null) {
Expand Down
34 changes: 23 additions & 11 deletions src/Views/SourceListView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,27 @@
namespace EasySSH {
public class Item : Granite.Widgets.SourceList.Item {
private Gtk.Menu host_menu;

public signal void host_edit_clicked (string name);
public signal void host_remove_clicked (string name);
public Item (string name = "") {
this.name = name;
Object (
name: name
);
}
construct {
host_menu = new Gtk.Menu ();

var host_edit = new Gtk.MenuItem.with_label (_("Edit"));
host_edit.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_EDIT_CONN;
var host_remove = new Gtk.MenuItem.with_label (_("Remove"));
host_remove.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_REMOVE_CONN;
host_menu.append(host_edit);
host_menu.append(host_remove);
host_edit.activate.connect (() => {
host_edit_clicked (name);
});
host_menu.append (host_edit);

var host_remove = new Gtk.MenuItem.with_label (_("Remove"));
host_remove.activate.connect (() => {
host_remove_clicked (name);
});
host_menu.append (host_remove);

host_menu.show_all();
}
Expand All @@ -52,6 +60,8 @@ namespace EasySSH {
public Granite.Widgets.SourceList source_list;
public MainWindow window { get; construct; }
private EasySSH.Settings settings;
public signal void host_edit_clicked (string name);
public signal void host_remove_clicked (string name);

public SourceListView (MainWindow window) {
Object (window: window);
Expand Down Expand Up @@ -220,6 +230,8 @@ namespace EasySSH {
});
n.tab_moved.connect(on_tab_moved);
n.tab_switched.connect(on_tab_switched);
item.host_edit_clicked.connect ((name) => {host_edit_clicked (name);});
item.host_remove_clicked.connect ((name) => {host_remove_clicked (name);});

}

Expand Down Expand Up @@ -600,15 +612,15 @@ namespace EasySSH {
show_all();
}

public void edit_conn() {
public void edit_conn(string name) {
clean_box();
var host = hostmanager.get_host_by_name(source_list.selected.name);
var host = hostmanager.get_host_by_name(name);

box.add(new ConnectionEditor(this, host));
show_all();
}
public void remove_conn() {
var host = hostmanager.get_host_by_name(source_list.selected.name);
public void remove_conn(string name) {
var host = hostmanager.get_host_by_name(name);
confirm_remove_dialog (host);
}
private void confirm_remove_dialog (Host host) {
Expand Down
10 changes: 6 additions & 4 deletions src/Widgets/Connection.vala
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ namespace EasySSH {
connect_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
connect_button.clicked.connect (add_tab);
var edit_button = new Gtk.Button.with_label (_("Edit"));
edit_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_EDIT_CONN;

edit_button.clicked.connect (() => {
window.action_edit_conn (host.name);
});
var remove_button = new Gtk.Button.with_label (_("Remove"));
remove_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
remove_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_REMOVE_CONN;

remove_button.clicked.connect (() => {
window.action_remove_conn (host.name);
});
var buttons = new Gtk.ButtonBox (Gtk.Orientation.HORIZONTAL);
buttons.layout_style = Gtk.ButtonBoxStyle.CENTER;
buttons.spacing = 6;
Expand Down

0 comments on commit 25ed298

Please sign in to comment.