~l-admin-3/evnc/automatic-cleanup-branch

« back to all changes in this revision

Viewing changes to src/Widgets/BookmarksMenu.vala

  • Committer: Marcus Wichelmann
  • Date: 2015-07-09 18:17:05 UTC
  • Revision ID: marcus.wichelmann@hotmail.de-20150709181705-aliu5vv3gvha1p0a
Automatic code cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
*/
18
18
 
19
19
namespace evnc.Widgets {
20
 
        public class BookmarksMenu : Gtk.Menu {
21
 
                public signal void on_bookmark_selected (string host, string port, string user);
22
 
                public signal void on_new_bookmark_clicked ();
23
 
 
24
 
                private SettingsManager options;
25
 
 
26
 
                public BookmarksMenu () {
27
 
                        options = new SettingsManager ();
28
 
 
29
 
                        update_menu ();
30
 
                }
31
 
 
32
 
                private void update_menu () {
33
 
                        foreach (Gtk.Widget item in this.get_children ()) {
34
 
                                this.remove(item);
35
 
                        }
36
 
 
37
 
                        for (int i = 0; i < options.bookmark_list.length; i++) {
38
 
                                var parameters = options.bookmark_list[i].split ("|");
39
 
 
40
 
                                // Parameteranzahl korrekt?
41
 
                                if (parameters.length >= 4) {
42
 
                                        var item = new Gtk.MenuItem.with_label (parameters[0]);
43
 
                                        var item_sub_menu = new Gtk.Menu ();
44
 
                                        var item_open = new Gtk.MenuItem.with_label (_("Connect"));
45
 
                                        var item_remove = new Gtk.MenuItem.with_label (_("Remove"));
46
 
 
47
 
                                        // FIXME: I need the current iterator for the signals.
48
 
                                        var index = i;
49
 
 
50
 
                                        item_open.activate.connect (() => {
51
 
                                                on_bookmark_selected (parameters[1], parameters[2], parameters[3]);
52
 
                                        });
53
 
 
54
 
                                        item_remove.activate.connect (() => {
55
 
                                                var bookmarks_new = new string[options.bookmark_list.length - 1];
56
 
                                                var count = 0;
57
 
 
58
 
                                                for (int b = 0; b < options.bookmark_list.length; b++) {
59
 
                                                        if (b != index) {
60
 
                                                                bookmarks_new[count] = options.bookmark_list[b];
61
 
                                                                count++;
62
 
                                                        }
63
 
                                                }
64
 
 
65
 
                                                options.bookmark_list = bookmarks_new;
66
 
                                                update_menu ();
67
 
                                        });
68
 
 
69
 
                                        item_sub_menu.add (item_open);
70
 
                                        item_sub_menu.add (item_remove);
71
 
 
72
 
                                        item.submenu = item_sub_menu;
73
 
 
74
 
                                        this.add (item);
75
 
                                }
76
 
                        }
77
 
 
78
 
                        if (options.bookmark_list.length > 0) {
79
 
                                this.add (new Gtk.SeparatorMenuItem ());
80
 
                        }
81
 
 
82
 
                        var create_item = new Gtk.MenuItem.with_label (_("Add new bookmark"));
83
 
                        create_item.activate.connect (() => {
84
 
                                on_new_bookmark_clicked ();
85
 
                        });
86
 
 
87
 
                        this.add (create_item);
88
 
                        this.show_all ();
89
 
                }
90
 
 
91
 
                public void add_bookmark (string new_bookmark) {
92
 
                        var bookmarks_new = new string[options.bookmark_list.length + 1];
93
 
                        var count = 1;
94
 
 
95
 
                        bookmarks_new[0] = new_bookmark;
96
 
 
97
 
                        for (int i = 0; i < options.bookmark_list.length; i++) {
98
 
                                bookmarks_new[count] = options.bookmark_list[i];
99
 
                                count++;
100
 
                        }
101
 
 
102
 
                        options.bookmark_list = bookmarks_new;
103
 
 
104
 
                        update_menu ();
105
 
                }
106
 
        }
 
20
    public class BookmarksMenu : Gtk.Menu {
 
21
        public signal void on_bookmark_selected (string host, string port, string user);
 
22
        public signal void on_new_bookmark_clicked ();
 
23
 
 
24
        private SettingsManager options;
 
25
 
 
26
        public BookmarksMenu () {
 
27
            options = new SettingsManager ();
 
28
 
 
29
            update_menu ();
 
30
        }
 
31
 
 
32
        private void update_menu () {
 
33
            foreach (Gtk.Widget item in this.get_children ()) {
 
34
                this.remove (item);
 
35
            }
 
36
 
 
37
            for (int i = 0; i < options.bookmark_list.length; i++) {
 
38
                var parameters = options.bookmark_list[i].split ("|");
 
39
 
 
40
                // Parameteranzahl korrekt?
 
41
                if (parameters.length >= 4) {
 
42
                    var item = new Gtk.MenuItem.with_label (parameters[0]);
 
43
                    var item_sub_menu = new Gtk.Menu ();
 
44
                    var item_open = new Gtk.MenuItem.with_label (_ ("Connect"));
 
45
                    var item_remove = new Gtk.MenuItem.with_label (_ ("Remove"));
 
46
 
 
47
                    // FIXME: I need the current iterator for the signals.
 
48
                    var index = i;
 
49
 
 
50
                    item_open.activate.connect (() => {
 
51
                        on_bookmark_selected (parameters[1], parameters[2], parameters[3]);
 
52
                    });
 
53
 
 
54
                    item_remove.activate.connect (() => {
 
55
                        var bookmarks_new = new string[options.bookmark_list.length - 1];
 
56
                        var count = 0;
 
57
 
 
58
                        for (int b = 0; b < options.bookmark_list.length; b++) {
 
59
                            if (b != index) {
 
60
                                bookmarks_new[count] = options.bookmark_list[b];
 
61
                                count++;
 
62
                            }
 
63
                        }
 
64
 
 
65
                        options.bookmark_list = bookmarks_new;
 
66
                        update_menu ();
 
67
                    });
 
68
 
 
69
                    item_sub_menu.add (item_open);
 
70
                    item_sub_menu.add (item_remove);
 
71
 
 
72
                    item.submenu = item_sub_menu;
 
73
 
 
74
                    this.add (item);
 
75
                }
 
76
            }
 
77
 
 
78
            if (options.bookmark_list.length > 0) {
 
79
                this.add (new Gtk.SeparatorMenuItem ());
 
80
            }
 
81
 
 
82
            var create_item = new Gtk.MenuItem.with_label (_ ("Add new bookmark"));
 
83
            create_item.activate.connect (() => {
 
84
                on_new_bookmark_clicked ();
 
85
            });
 
86
 
 
87
            this.add (create_item);
 
88
            this.show_all ();
 
89
        }
 
90
 
 
91
        public void add_bookmark (string new_bookmark) {
 
92
            var bookmarks_new = new string[options.bookmark_list.length + 1];
 
93
            var count = 1;
 
94
 
 
95
            bookmarks_new[0] = new_bookmark;
 
96
 
 
97
            for (int i = 0; i < options.bookmark_list.length; i++) {
 
98
                bookmarks_new[count] = options.bookmark_list[i];
 
99
                count++;
 
100
            }
 
101
 
 
102
            options.bookmark_list = bookmarks_new;
 
103
 
 
104
            update_menu ();
 
105
        }
 
106
    }
107
107
}
 
 
b'\\ No newline at end of file'