File: fileDialog.js

package info (click to toggle)
cinnamon 6.4.13-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,304 kB
  • sloc: javascript: 54,298; ansic: 51,499; python: 21,971; xml: 2,803; sh: 96; makefile: 27; perl: 13
file content (54 lines) | stat: -rw-r--r-- 1,294 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const Util = imports.misc.util;
const GLib = imports.gi.GLib;

function open(callback, params) {
	_launchDialog(0, callback, params);
}

function openFolder(callback, params) {
	_launchDialog(1, callback, params);
}

function save(callback, params) {
	_launchDialog(2, callback, params);
}

function _launchDialog(type, callback, params) {
	let args = ["cinnamon-file-dialog"];
	if (params.selectMultiple) type += 3; //add 3 to use the select-multiple version
	args.push(String(type));
	if (params.path) args.push("-p", params.path.replace("~", GLib.get_home_dir()));
	if (params.name) args.push("-n", params.name);
	if (params.directory) args.push("-d", params.directory.replace("~", GLib.get_home_dir()));
	if (params.filters) {
		let filterList = [];
		for (let i = 0; i < params.filters.length; i++) {
			filterList.push(params.filters[i].getString());
		}
		args.push("-f", filterList.join(","));
	}
	Util.spawn_async(args, callback);
}

function Filter(name) {
	this._init(name);
}

Filter.prototype = {
	_init: function(name) {
		this.name = name;
		this.rules = [];
	},

	addMimeType: function(mime) {
		this.rules.push("m="+mime);
	},

	addPattern: function(pattern) {
		this.rules.push("p="+pattern);
	},

	getString: function() {
		return this.name + ";" + this.rules.join(":");
	}
}