~philip.scott/pantheon-notes/open-with

« back to all changes in this revision

Viewing changes to src/Application.vala

  • Committer: felescoto95 at hotmail
  • Date: 2016-03-15 22:51:33 UTC
  • Revision ID: felescoto95@hotmail.com-20160315225133-6ytxygbj01t99jwr
working with CMD args

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
namespace Notes {
3
 
    public Notes.PagesList pages_list;
4
 
    public Notes.Editor editor;
5
 
    public Notes.Services.Settings settings;
6
 
    public Notes.Window window;
7
3
    public string NOTES_DIR;
 
4
    public static const string APP_NAME = "Notes";
 
5
    public static const string CODE_NAME = "pantheon-notes";
8
6
}
9
7
 
10
8
public class Notes.Application : Granite.Application {
 
9
    private Notes.Window window;
 
10
 
11
11
    public const string PROGRAM_NAME = N_("Notes");
12
12
    public const string COMMENT = N_("Simple notes editing");
13
13
    public const string ABOUT_STOCK = N_("About Notes");
14
14
 
15
15
    public bool running = false;
16
16
 
 
17
    public static int main (string[] args) {
 
18
        Application app = Application.instance;
 
19
        return app.run (args);
 
20
    }
 
21
 
 
22
    construct {
 
23
        flags |= ApplicationFlags.HANDLES_OPEN;
 
24
 
 
25
        program_name = APP_NAME;
 
26
        exec_name = "pantheon-notes";
 
27
        app_years = "2011-2015";
 
28
        app_icon = "accessories-notes";
 
29
        app_launcher = "pantheon-notes.desktop";
 
30
        application_id = "org.elementary." + CODE_NAME.down ();
 
31
        main_url = "https://launchpad.net/pantheon-notes";
 
32
        bug_url = "https://bugs.launchpad.net/pantheon-notes";
 
33
        help_url = "https://elementary.io/help/pantheon-notes";
 
34
        translate_url = "https://translations.launchpad.net/pantheon-notes";
 
35
        about_authors = { "Felipe Escoto <felescoto95@hotmail.com>", null};
 
36
        about_documenters = { "",null };
 
37
        about_artists = { "", null};
 
38
        about_translators = _("translator-credits");
 
39
        about_license_type = Gtk.License.GPL_3_0;
 
40
    }
 
41
 
17
42
    public Application () {
18
 
        Object (application_id: "org.pantheon-notes");
 
43
        Intl.setlocale (LocaleCategory.ALL, Intl.get_language_names ()[0]);
 
44
        Environment.set_application_name (APP_NAME);
 
45
        Environment.set_prgname (APP_NAME);
 
46
    }
 
47
 
 
48
    public static Application _instance = null;
 
49
 
 
50
    public static Application instance {
 
51
        get {
 
52
            if (_instance == null)
 
53
                _instance = new Application ();
 
54
            return _instance;
 
55
        }
19
56
    }
20
57
 
21
58
    public override void activate () {
 
59
        this.hold ();
 
60
        stdout.printf ("activated\n");
 
61
        this.release ();
 
62
    }
 
63
 
 
64
    public override int command_line (ApplicationCommandLine command_line) {
 
65
        this.hold ();
 
66
        int res = _command_line (command_line);
 
67
        this.release ();
 
68
        return res;
 
69
    }
 
70
 
 
71
    private void app_window () {
22
72
        if (!running) {
23
 
            settings = new Notes.Services.Settings ();
 
73
            var settings = new Notes.Services.Settings ();
24
74
 
25
75
            if (settings.notes_location == "") {
26
76
                settings.notes_location = Path.build_filename (Environment.get_user_data_dir (), CODE_NAME);
36
86
 
37
87
        window.show_app ();
38
88
    }
 
89
 
 
90
    private void file_window (string file) {
 
91
        var window = new Notes.Window.with_file (this, file);
 
92
 
 
93
        window.show_app ();
 
94
    }
 
95
 
 
96
    private int _command_line (ApplicationCommandLine command_line) {
 
97
        string? file = null;
 
98
 
 
99
        OptionEntry[] options = new OptionEntry[1];
 
100
        options[0] = { "file", 0, 0, OptionArg.FILENAME, ref file, "World name to load", "Open file" };
 
101
 
 
102
        string[] args = command_line.get_arguments ();
 
103
        string*[] _args = new string[args.length];
 
104
        for (int i = 0; i < args.length; i++) {
 
105
            _args[i] = args[i];
 
106
        }
 
107
 
 
108
        try {
 
109
            var opt_context = new OptionContext ("- OptionContext example");
 
110
            opt_context.set_help_enabled (true);
 
111
            opt_context.add_main_entries (options, null);
 
112
            unowned string[] tmp = _args;
 
113
            opt_context.parse (ref tmp);
 
114
        } catch (OptionError e) {
 
115
            command_line.print ("error: %s\n", e.message);
 
116
            command_line.print ("Run '%s --help' to see a full list of available command line options.\n", args[0]);
 
117
            return 0;
 
118
        }
 
119
 
 
120
        if (file != null) {
 
121
            file_window (file);
 
122
        } else {
 
123
            app_window ();
 
124
        }
 
125
 
 
126
        return 0;
 
127
    }
39
128
}