~gero-bare/scratch/scratch-command-line-improvements

« back to all changes in this revision

Viewing changes to src/Scratch.vala

  • Committer: Geronimo Bareiro
  • Date: 2016-01-19 16:28:08 UTC
  • Revision ID: gero.bare@gmail.com-20160119162808-5askj71rcy928g6y
Improved error mesages.
Fixed problem when passed a non-existent file, with a non-existent parent directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
174
174
                                    // Otherwise we simple use the error notification from glib
175
175
                                    msg = e.message;
176
176
                                }
 
177
 
 
178
                                // Escape to the outer catch clause, and overwrite
 
179
                                // the weird glib's standard errors.
 
180
                                throw new Error (e.domain, e.code, msg);
177
181
                            }
178
182
                        }
179
183
 
180
184
                        var info = file.query_info ("standard::*", FileQueryInfoFlags.NONE, null);
 
185
                        string err_msg = _("File \"%s\" cannot be opened.\n%s");
 
186
                        string reason = "";
 
187
 
181
188
                        switch (info.get_file_type ()) {
182
189
                            case FileType.REGULAR:
183
190
                            case FileType.SYMBOLIC_LINK:
184
191
                                files += file;
185
192
                                break;
186
193
                            case FileType.MOUNTABLE:
187
 
                                string reason = _("Is a mountable location.");
188
 
                                msg = _("File \"%s\" cannot be opened.\n%s").printf ("<b>%s</b>".printf (file.get_uri ()), reason);    
 
194
                                reason = _("It is a mountable location.");
189
195
                                break;
190
196
                            case FileType.DIRECTORY:
191
 
                                string reason = _("Is a directory.");
192
 
                                msg = _("File \"%s\" cannot be opened.\n%s").printf ("<b>%s</b>".printf (file.get_uri ()), reason);
 
197
                                reason = _("It is a directory.");
193
198
                                break;
194
199
                            case FileType.SPECIAL:
195
 
                                string reason = _("Is a \"special\" file such as a socket,\n fifo, block device, or character device.");
196
 
                                msg = _("File \"%s\" cannot be opened.\n%s").printf ("<b>%s</b>".printf (file.get_uri ()), reason);
 
200
                                reason = _("It is a \"special\" file such as a socket,\n fifo, block device, or character device.");
197
201
                                break;
198
202
                            default:
199
 
                                string reason = _("Is a \"unknown\" file type.");
200
 
                                msg = _("File \"%s\" cannot be opened.\n%s").printf ("<b>%s</b>".printf (file.get_uri ()), reason);
 
203
                                reason = _("It is an \"unknown\" file type.");
201
204
                                break;
202
205
                        }
 
206
 
 
207
                        if (reason.length > 0) {
 
208
                            msg = err_msg.printf ("<b>%s</b>".printf (file.get_uri ()), reason);    
 
209
                        }
 
210
 
203
211
                    } catch (Error e) {
204
212
                        warning (e.message);
205
213
                    }