Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/proposals/CreateFileCorrectionProposal.java

Issue 11364134: Merge libv1. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload due to error Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/proposals/CreateFileCorrectionProposal.java
diff --git a/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/proposals/CreateFileCorrectionProposal.java b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/proposals/CreateFileCorrectionProposal.java
new file mode 100644
index 0000000000000000000000000000000000000000..22a3a64e302e3e08c15caa1c134a29dc32ad2e48
--- /dev/null
+++ b/editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/proposals/CreateFileCorrectionProposal.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2012, the Dart project authors.
+ *
+ * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.dart.tools.ui.internal.text.correction.proposals;
+
+import com.google.dart.tools.internal.corext.refactoring.util.ExecutionUtils;
+import com.google.dart.tools.internal.corext.refactoring.util.RunnableEx;
+import com.google.dart.tools.ui.DartPluginImages;
+import com.google.dart.tools.ui.internal.text.correction.ICommandAccess;
+import com.google.dart.tools.ui.internal.util.CoreUtility;
+import com.google.dart.tools.ui.text.dart.IDartCompletionProposal;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+
+import java.io.ByteArrayInputStream;
+
+/**
+ * Correction proposal for creating new {@link IFile}.
+ *
+ * @coverage dart.editor.ui.correction
+ */
+public class CreateFileCorrectionProposal implements IDartCompletionProposal, ICommandAccess {
+
+ private final int relevance;
+ private final String label;
+ private final IFile file;
+ private final String content;
+
+ public CreateFileCorrectionProposal(int relevance, String label, IFile file, String content) {
+ this.relevance = relevance;
+ this.label = label;
+ this.file = file;
+ this.content = content;
+ }
+
+ @Override
+ public void apply(IDocument document) {
+ ExecutionUtils.runLog(new RunnableEx() {
+ @Override
+ public void run() throws Exception {
+ // ensure that folder with 'newFile' exists
+ {
+ IContainer container = file.getParent();
+ if (container instanceof IFolder && !container.exists()) {
+ CoreUtility.createFolder((IFolder) container, true, false, null);
+ }
+ }
+ // do create
+ file.create(new ByteArrayInputStream(content.getBytes("UTF-8")), true, null);
+ file.setCharset("UTF-8", null);
+ }
+ });
+ }
+
+ @Override
+ public String getAdditionalProposalInfo() {
+ return content;
+ }
+
+ @Override
+ public String getCommandId() {
+ return null;
+ }
+
+ @Override
+ public IContextInformation getContextInformation() {
+ return null;
+ }
+
+ @Override
+ public String getDisplayString() {
+ return label;
+ }
+
+ @Override
+ public Image getImage() {
+ return DartPluginImages.get(DartPluginImages.IMG_CORRECTION_LINKED_RENAME);
+ }
+
+ @Override
+ public int getRelevance() {
+ return relevance;
+ }
+
+ @Override
+ public Point getSelection(IDocument document) {
+ return null;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698