【问题标题】:Eclipse make (readonly) file writableEclipse 使(只读)文件可写
【发布时间】:2013-01-29 09:11:24
【问题描述】:

我创建了 Eclipse 插件(按钮),它将一些文本插入到活动的打开文件中。我鼓舞了http://wiki.eclipse.org/FAQ_How_do_I_insert_text_in_the_active_text_editor%3F

public class PasteTextAction implements IWorkbenchWindowActionDelegate {

  private IWorkbenchWindow window;

  public void run(IAction aAction) {

    IWorkbenchPage page = window.getActivePage();
    IEditorPart part = page.getActiveEditor();
    if (!(part instanceof AbstractTextEditor))
      return;
    ITextEditor editor = (ITextEditor) part;
    IDocumentProvider dp = editor.getDocumentProvider();
    IDocument doc = dp.getDocument(editor.getEditorInput());

    try {
      int offset = doc.getLineOffset(doc.getNumberOfLines() - 4);
      doc.replace(offset, 0, "pasteText\n");
    } catch (BadLocationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

  }

  public void selectionChanged(IAction aAction, ISelection aSelection) {

  }

  public void dispose() {

  }

  public void init(IWorkbenchWindow aWindow) {
    window = aWindow;
  }

}

效果很好。

但我对只读文件或 ClearCase 版本控制系统下的文件有问题。它将文本粘贴到编辑器中,但它不会尝试将文件设置为可写,或者如果文件无法设置为可写,则不会粘贴它。 (它不会为 ClearCase 文件打开 CheckOut 窗口)。

如何以编程方式设置文件可写?

【问题讨论】:

    标签: java eclipse eclipse-plugin clearcase


    【解决方案1】:

    请注意,Eclipse 插件中的任何 java 解决方案都只能用于快照视图。
    (前提是你有right Java version

    如果您在动态视图中,setWritable(true);工作。
    您必须执行cleartool checkout -nc filePath


    OP kubedancomments:

    我使用快照视图。
    也许我不想设置文件可写,因为setWritable(true); hijack the file(我不想劫持文件)。
    我想打开CheckOut 窗口。如果我从剪贴板粘贴文本,则会出现相同的行为。

    没有简单的方法来显示本机ClearCase "Checkout" dialog box
    您必须重新创建它(管理 UCM 活动以及使用 UCM Web 视图),就像 ClearCase 插件在 Eclipse 中所做的那样:

    【讨论】:

    • 我使用快照视图。 Mayby 我不想设置文件可写,因为setWritable(true); 劫持文件(我不想劫持文件)。我想打开 CheckOut 窗口。如果我从剪贴板粘贴文本,则会出现相同的行为。
    • @kubedan 不确定是否可以从 Eclipse 中完成,而无需重新创建结帐对话框。查看我的编辑。
    • 在 Eclipse 中是否有一些(openfile)监听器可以在我的插件中调用?比 eclipse 创建 CheckOut 窗口本身。我想模拟同样的情况,就像我通过 Ctrl+V 粘贴文本一样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    相关资源
    最近更新 更多