~fabrixxm/oliver

bed7af2b387222a57c031b9c9bb0df01993b8e85 — fabrixxm 5 months ago 189e67b
Multi-window mode: open projects in new windows

- move action 'open' to 'app'
- create a new window if needed
4 files changed, 26 insertions(+), 24 deletions(-)

M src/application.vala
M src/gtk/help-overlay.ui
M src/window.blp
M src/window.vala
M src/application.vala => src/application.vala +21 -1
@@ 26,6 26,7 @@ namespace Oliver {

        construct {
            ActionEntry[] action_entries = {
                { "open", this.on_open_action },
                { "about", this.on_about_action },
                { "preferences", this.on_preferences_action },
                { "quit", this.quit }


@@ 33,7 34,7 @@ namespace Oliver {
            this.add_action_entries (action_entries, this);
            this.set_accels_for_action ("app.quit", {"<primary>q"});

            this.set_accels_for_action ("win.open", {"<primary>o"});
            this.set_accels_for_action ("app.open", {"<primary>o"});
            this.set_accels_for_action ("win.find", {"<primary>f"});
            this.set_accels_for_action ("win.rescan", {"<primary>r"});
        }


@@ 60,6 61,25 @@ namespace Oliver {
            }
        }

        private void on_open_action () {
            var fd = new Gtk.FileDialog ();
            var win = (Oliver.Window) this.active_window;
            if (win.projectFolder != null) {
                win = new Oliver.Window (this);
            }
            fd.select_folder.begin (win, null, (obj,res) => {
                try {
                    File? folder = fd.select_folder.end (res);
                    if (folder != null) {
                        win.present ();
                        win.open_project (folder);
                    }
                } catch (Error e) {
                    warning ("Error selecting folder: %s", e.message);
                }
            });
        }

        private void on_about_action () {
            string[] developers = { "Fabio Comuni" };
            var about = new Adw.AboutWindow () {

M src/gtk/help-overlay.ui => src/gtk/help-overlay.ui +2 -2
@@ 11,8 11,8 @@
            <property name="title" translatable="yes" context="shortcut window">General</property>
            <child>
              <object class="GtkShortcutsShortcut">
                <property name="title" translatable="yes" context="shortcut window">Open project</property>
                <property name="action-name">win.open</property>
                <property name="title" translatable="yes" context="shortcut window">Open Project</property>
                <property name="action-name">app.open</property>
              </object>
            </child>
            <child>

M src/window.blp => src/window.blp +3 -3
@@ 88,7 88,7 @@ template $OliverWindow : Adw.ApplicationWindow {
              hexpand: false;
              styles ["suggested-action", "pill"]
              label: _("Open Project");
              action-name: 'win.open';
              action-name: 'app.open';
            };
          };
        }


@@ 169,8 169,8 @@ template $OliverWindow : Adw.ApplicationWindow {
menu primary_menu {
  section {
    item {
      label: _("_Open Project");
      action: "win.open";
      label: _("_Open Project...");
      action: "app.open";
    }

    item {

M src/window.vala => src/window.vala +0 -18
@@ 103,10 103,6 @@ namespace Oliver {
        private void add_actions () {
            SimpleAction a;

            a = new SimpleAction("open", null);
            a.activate.connect(this.on_open_action);
            this.add_action(a);

            a = new SimpleAction("rescan", null);
            a.activate.connect(this.on_rescan_action);
            this.bind_property("isValidProject", a, "enabled", BindingFlags.SYNC_CREATE);


@@ 356,20 352,6 @@ namespace Oliver {
            }
        }

        private void on_open_action () {
            var fd = new Gtk.FileDialog ();
            fd.select_folder.begin (this, null, (obj,res) => {
                try {
                    File? folder = fd.select_folder.end (res);
                    if (folder != null) {
                        this.open_project (folder);
                    }
                } catch (Error e) {
                    warning ("Error selecting folder: %s", e.message);
                }
            });
        }

        private void on_rescan_action() {
            this.scan();
        }