Merge lp:~philip.scott/screenshot-tool/dont-overwrite into lp:~elementary-apps/screenshot-tool/trunk

Proposed by Felipe Escoto
Status: Merged
Approved by: Danielle Foré
Approved revision: 232
Merged at revision: 234
Proposed branch: lp:~philip.scott/screenshot-tool/dont-overwrite
Merge into: lp:~elementary-apps/screenshot-tool/trunk
Diff against target: 24 lines (+13/-1)
1 file modified
src/ScreenshotWindow.vala (+13/-1)
To merge this branch: bzr merge lp:~philip.scott/screenshot-tool/dont-overwrite
Reviewer Review Type Date Requested Status
Danielle Foré Approve
Review via email: mp+307121@code.launchpad.net

Commit message

Don't overwrite files

Description of the change

Don't overwrite files, instead append the (%d) as when you download a file

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Just one tiny code style issue ;)

232. By Felipe Escoto

Don't overwrite files

Revision history for this message
Danielle Foré (danrabbit) wrote :

Works and looks good to me :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ScreenshotWindow.vala'
2--- src/ScreenshotWindow.vala 2016-09-29 03:16:03 +0000
3+++ src/ScreenshotWindow.vala 2016-09-30 18:16:43 +0000
4@@ -320,7 +320,19 @@
5 output = output.replace (type, "");
6 }
7
8- string file_name = Path.build_filename (folder_dir, output + "." + format);
9+ string file_name = "";
10+ int attempt = 0;
11+
12+ // Check if file exists
13+ do {
14+ if (attempt == 0) {
15+ file_name = Path.build_filename (folder_dir, "%s.%s".printf (output, format));
16+ } else {
17+ file_name = Path.build_filename (folder_dir, "%s (%d).%s".printf (output, attempt, format));
18+ }
19+
20+ attempt++;
21+ } while (File.new_for_path (file_name).query_exists ());
22
23 try {
24 screenshot.save (file_name, format);

Subscribers

People subscribed via source and target branches

to all changes: