public void testMakeFileReadOnly() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); PsiFile psiFile = fileManager.findFile(file); final EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); ReadOnlyAttributeUtil.setReadOnlyAttribute(file, true); final String expected = "beforePropertyChange writable\n" + "propertyChanged writable\n"; new WaitFor(500){ @Override protected boolean condition() { return expected.equals(listener.getEventsString()); } }.assertCompleted(listener.getEventsString()); ReadOnlyAttributeUtil.setReadOnlyAttribute(file, false); }
@Override public void apply() throws IOException { if (!myContent.isAvailable()) return; boolean isReadOnly = !myFile.isWritable(); ReadOnlyAttributeUtil.setReadOnlyAttribute(myFile, false); Document doc = FileDocumentManager.getInstance().getCachedDocument(myFile); DocumentUndoProvider.startDocumentUndo(doc); try { myFile.setBinaryContent(myContent.getBytes(), -1, myTimestamp); } finally { DocumentUndoProvider.finishDocumentUndo(doc); } ReadOnlyAttributeUtil.setReadOnlyAttribute(myFile, isReadOnly); }
public Consumer<MouseEvent> getClickConsumer() { return new Consumer<MouseEvent>() { public void consume(MouseEvent mouseEvent) { final VirtualFile file = getCurrentFile(); if (!isReadOnlyApplicableForFile(file)) { return; } FileDocumentManager.getInstance().saveAllDocuments(); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { try { ReadOnlyAttributeUtil.setReadOnlyAttribute(file, file.isWritable()); myStatusBar.updateWidget(ID()); } catch (IOException e) { Messages.showMessageDialog(getProject(), e.getMessage(), UIBundle.message("error.dialog.title"), Messages.getErrorIcon()); } } }); } }; }
public void actionPerformed(final AnActionEvent e) { ApplicationManager.getApplication().runWriteAction( new Runnable() { public void run() { // Save all documents. We won't be able to save changes to the files that became read-only afterwards. FileDocumentManager.getInstance().saveAllDocuments(); try { VirtualFile[] files = getFiles(e.getDataContext()); for (VirtualFile file : files) { ReadOnlyAttributeUtil.setReadOnlyAttribute(file, file.isWritable()); } } catch (IOException exc) { Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); Messages.showMessageDialog( project, exc.getMessage(), CommonBundle.getErrorTitle(), Messages.getErrorIcon() ); } } } ); }
private static boolean clearReadOnlyFlag(final VirtualFile virtualFile, final Project project) { final boolean[] success = new boolean[1]; CommandProcessor.getInstance().executeCommand(project, new Runnable() { @Override public void run() { Runnable action = new Runnable() { @Override public void run() { try { ReadOnlyAttributeUtil.setReadOnlyAttribute(virtualFile, false); success[0] = true; } catch (IOException e1) { Messages.showMessageDialog(project, e1.getMessage(), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); } } }; ApplicationManager.getApplication().runWriteAction(action); } }, "", null); return success[0]; }
public void testMakeFileReadOnly() throws Exception { FileManager fileManager = myPsiManager.getFileManager(); VirtualFile file = myPrjDir1.createChildData(null, "a.txt"); PsiFile psiFile = fileManager.findFile(file); final EventsTestListener listener = new EventsTestListener(); myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); ReadOnlyAttributeUtil.setReadOnlyAttribute(file, true); String string = listener.getEventsString(); final String expected = "beforePropertyChange\n" + "propertyChanged\n"; new WaitFor(500){ @Override protected boolean condition() { return expected.equals(listener.getEventsString()); } }.assertCompleted(expected); ReadOnlyAttributeUtil.setReadOnlyAttribute(file, false); }
public void actionPerformed(final AnActionEvent e){ ApplicationManager.getApplication().runWriteAction( new Runnable(){ public void run(){ // Save all documents. We won't be able to save changes to the files that became read-only afterwards. FileDocumentManager.getInstance().saveAllDocuments(); try { VirtualFile[] files=getFiles(e.getDataContext()); for (VirtualFile file : files) { ReadOnlyAttributeUtil.setReadOnlyAttribute(file, file.isWritable()); } } catch(IOException exc){ Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); Messages.showMessageDialog( project, exc.getMessage(), CommonBundle.getErrorTitle(),Messages.getErrorIcon() ); } } } ); }
@Override public Consumer<MouseEvent> getClickConsumer() { return mouseEvent -> { final VirtualFile file = getCurrentFile(); if (!isReadOnlyApplicableForFile(file)) { return; } FileDocumentManager.getInstance().saveAllDocuments(); try { WriteAction.run(() -> ReadOnlyAttributeUtil.setReadOnlyAttribute(file, file.isWritable())); myStatusBar.updateWidget(ID()); } catch (IOException e) { Messages.showMessageDialog(getProject(), e.getMessage(), UIBundle.message("error.dialog.title"), Messages.getErrorIcon()); } }; }
public void actionPerformed(final AnActionEvent e){ ApplicationManager.getApplication().runWriteAction( new Runnable(){ public void run(){ // Save all documents. We won't be able to save changes to the files that became read-only afterwards. FileDocumentManager.getInstance().saveAllDocuments(); try { VirtualFile[] files=getFiles(e.getDataContext()); for (VirtualFile file : files) { ReadOnlyAttributeUtil.setReadOnlyAttribute(file, file.isWritable()); } } catch(IOException exc){ Project project = e.getData(CommonDataKeys.PROJECT); Messages.showMessageDialog( project, exc.getMessage(), CommonBundle.getErrorTitle(),Messages.getErrorIcon() ); } } } ); }
private static boolean clearReadOnlyFlag(final VirtualFile virtualFile, final Project project) { final boolean[] success = new boolean[1]; CommandProcessor.getInstance().executeCommand(project, () -> { Runnable action = () -> { try { ReadOnlyAttributeUtil.setReadOnlyAttribute(virtualFile, false); success[0] = true; } catch (IOException e1) { Messages.showMessageDialog(project, e1.getMessage(), CommonBundle.getErrorTitle(), Messages.getErrorIcon()); } }; ApplicationManager.getApplication().runWriteAction(action); }, "", null); return success[0]; }
public void processFiles(final Collection<VirtualFile> virtualFiles, String changelist) { ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { try { for (VirtualFile file : virtualFiles) { ReadOnlyAttributeUtil.setReadOnlyAttribute(file, false); file.refresh(false, false); } } catch (IOException e) { //ignore } } }); }
public void testChangingROStatusForFile() throws Exception { VirtualFile f = createFile("f.txt"); assertEquals(2, getRevisionsFor(f).size()); ReadOnlyAttributeUtil.setReadOnlyAttribute(f, true); assertEquals(3, getRevisionsFor(f).size()); ReadOnlyAttributeUtil.setReadOnlyAttribute(f, false); assertEquals(4, getRevisionsFor(f).size()); }
public void testIgnoringROStatusChangeForUnversionedFiles() throws Exception { int before = getRevisionsFor(myRoot).size(); VirtualFile f = createFile("f.hprof"); ReadOnlyAttributeUtil.setReadOnlyAttribute(f, true); // shouldn't throw assertEquals(before, getRevisionsFor(myRoot).size()); }
public boolean mergeContent(final Conflict conflict, final ContentTriplet contentTriplet, final Project project, final VirtualFile targetFile, final String localPathToDisplay, final VcsRevisionNumber serverVersion) throws IOException, VcsException { Assert.assertEquals(getExpectedBaseContent(myId2item.get(conflict.getBitemid())), contentTriplet.baseContent); Assert.assertEquals(getExpectedYoursContent(myId2item.get(conflict.getBitemid())), contentTriplet.localContent); Assert.assertEquals(getExpectedTheirsContent(myId2item.get(conflict.getBitemid())), contentTriplet.serverContent); ReadOnlyAttributeUtil.setReadOnlyAttribute(targetFile, false); setFileContent(targetFile, TestMultipleConflicts.this.mergeContent(myId2item.get(conflict.getBitemid()))); return true; }
public boolean mergeContent(final Conflict conflict, final ContentTriplet contentTriplet, final Project project, final VirtualFile targetFile, final String localPathToDisplay, final VcsRevisionNumber serverVersion) throws IOException, VcsException { Assert.assertEquals(getExpectedBaseContent(), contentTriplet.baseContent); Assert.assertEquals(getExpectedYoursContent(), contentTriplet.localContent); Assert.assertEquals(getExpectedTheirsContent(), contentTriplet.serverContent); ReadOnlyAttributeUtil.setReadOnlyAttribute(targetFile, false); setFileContent(targetFile, TestSingleConflict.this.mergeContent()); return true; }
public Consumer<MouseEvent> getClickConsumer() { return new Consumer<MouseEvent>() { public void consume(MouseEvent mouseEvent) { final Project project = getProject(); if (project == null) { return; } final FileEditorManager editorManager = FileEditorManager.getInstance(project); final VirtualFile[] files = editorManager.getSelectedFiles(); if (!isReadOnlyApplicableForFiles(files)) { return; } FileDocumentManager.getInstance().saveAllDocuments(); ApplicationManager.getApplication().runWriteAction(new Runnable() { public void run() { try { ReadOnlyAttributeUtil.setReadOnlyAttribute(files[0], files[0].isWritable()); myStatusBar.updateWidget(ID()); } catch (IOException e) { Messages.showMessageDialog(project, e.getMessage(), UIBundle.message("error.dialog.title"), Messages.getErrorIcon()); } } }); } }; }
public void apply() throws IOException { ReadOnlyAttributeUtil.setReadOnlyAttribute(myFile, isReadOnly); }
public void setFileReadOnly(File file, boolean readOnly) throws IOException { if (file.canWrite() != readOnly) return; ReadOnlyAttributeUtil.setReadOnlyAttribute(file.getAbsolutePath(), readOnly); }