MCPcopy Index your code
hub / github.com/benfry/processing4 / checkFiles

Method checkFiles

app/src/processing/app/ui/ChangeDetector.java:90–243  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

88
89
90 private void checkFiles() {
91 List<String> filenames = new ArrayList<>();
92 List<String> extensions = new ArrayList<>();
93 sketch.getSketchCodeFiles(filenames, extensions);
94
95 SketchCode[] codes = sketch.getCode();
96
97 // Separate codes with and without files
98 Map<Boolean, List<SketchCode>> existsMap = Arrays.stream(codes)
99 .collect(Collectors.groupingBy(code -> filenames.contains(code.getFileName())));
100
101
102 // ADDED FILES
103
104 List<String> codeFilenames = Arrays.stream(codes)
105 .map(SketchCode::getFileName)
106 .collect(Collectors.toList());
107
108 // Get filenames which are in filesystem but don't have code
109 List<String> addedFilenames = filenames.stream()
110 .filter(f -> !codeFilenames.contains(f))
111 .collect(Collectors.toList());
112
113 // Take action if there are any added files which were not previously ignored
114 boolean added = !addedFilenames.isEmpty();
115
116
117 // REMOVED FILES
118
119 // Get codes that do not have a file
120 List<SketchCode> removedCodes = Optional.ofNullable(existsMap.get(Boolean.FALSE))
121 .orElse(Collections.emptyList());
122 List<SketchCode> removedCodesFinal = removedCodes.stream()
123 .filter(code -> !ignoredRemovals.contains(code))
124 .collect(Collectors.toList());
125
126 // Show prompt if there are any removed codes which were not previously ignored
127 boolean removed = !removedCodesFinal.isEmpty();
128
129
130 /// MODIFIED FILES
131
132 // Get codes that have a file with different modification time
133 List<SketchCode> modifiedCodes =
134 existsMap.getOrDefault(Boolean.TRUE, Collections.emptyList());
135 List<SketchCode> modifiedCodesFinal = new ArrayList<>();
136 for (SketchCode code : modifiedCodes) {
137 if (ignoredModifications.contains(code)) continue;
138 long fileLastModified = code.getFile().lastModified();
139 long codeLastModified = code.getLastModified();
140 long diff = fileLastModified - codeLastModified;
141 if (fileLastModified == 0L || diff > MODIFICATION_WINDOW_MILLIS) {
142 modifiedCodesFinal.add(code);
143 }
144 }
145
146 // Show prompt if any open codes were modified
147 boolean modified = !modifiedCodesFinal.isEmpty();

Callers 1

windowGainedFocusMethod · 0.95

Calls 15

showReloadPromptMethod · 0.95
showWarningMethod · 0.95
getSketchCodeFilesMethod · 0.80
getCodeMethod · 0.80
mapMethod · 0.80
isEmptyMethod · 0.80
getFileMethod · 0.80
getLastModifiedMethod · 0.80
loadNewTabMethod · 0.80
updateSketchCodesMethod · 0.80
createTempFileMethod · 0.80
copyToMethod · 0.80

Tested by

no test coverage detected