PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/browser/RenameBrowserTask.java

#
Java | 131 lines | 80 code | 10 blank | 41 comment | 6 complexity | e814e38db4014a72669621dbb98ef973 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * jEdit - Programmer's Text Editor
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright Š 2011 Matthieu Casanova
  7. * Portions Copyright (C) 2000, 2003 Slava Pestov
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.browser;
  23. //{{{ Imports
  24. import org.gjt.sp.jedit.OperatingSystem;
  25. import org.gjt.sp.jedit.io.FavoritesVFS;
  26. import org.gjt.sp.jedit.io.VFS;
  27. import org.gjt.sp.jedit.io.VFSFile;
  28. import org.gjt.sp.jedit.io.VFSManager;
  29. import org.gjt.sp.jedit.jEdit;
  30. import org.gjt.sp.util.Log;
  31. import java.io.IOException;
  32. //}}}
  33. /**
  34. * @author Matthieu Casanova
  35. * @version $Id: ListDirectoryBrowserTask.java 19692 2011-07-22 15:27:56Z kpouer $
  36. */
  37. class RenameBrowserTask extends AbstractBrowserTask
  38. {
  39. //{{{ BrowserIORequest constructor
  40. /**
  41. * Creates a new browser I/O request.
  42. *
  43. * @param browser The VFS browser instance
  44. * @param path1 The first path name to operate on
  45. * @param path2 The second path name to operate on
  46. */
  47. RenameBrowserTask(VFSBrowser browser,
  48. Object session, VFS vfs, String path1, String path2,
  49. Runnable awtRunnable)
  50. {
  51. super(browser, session, vfs, path1, awtRunnable);
  52. this.path2 = path2;
  53. } //}}}
  54. //{{{ _run() method
  55. @Override
  56. public void _run()
  57. {
  58. try
  59. {
  60. setCancellable(true);
  61. String[] args = {path, path2};
  62. setStatus(jEdit.getProperty("vfs.status.renaming", args));
  63. path = vfs._canonPath(session, path, browser);
  64. path2 = vfs._canonPath(session, path2, browser);
  65. if (!(vfs instanceof FavoritesVFS))
  66. {
  67. VFSFile file = vfs._getFile(session, path2, browser);
  68. if (file != null)
  69. {
  70. if ((OperatingSystem.isCaseInsensitiveFS())
  71. && path.equalsIgnoreCase(path2))
  72. {
  73. // allow user to change name
  74. // case
  75. }
  76. else
  77. {
  78. VFSManager.error(browser, path,
  79. "ioerror.rename-exists",
  80. new String[]{path2});
  81. return;
  82. }
  83. }
  84. }
  85. if (!vfs._rename(session, path, path2, browser))
  86. VFSManager.error(browser, path, "ioerror.rename-error",
  87. new String[]{path2});
  88. }
  89. catch (IOException io)
  90. {
  91. setCancellable(false);
  92. Log.log(Log.ERROR, this, io);
  93. String[] pp = {io.toString()};
  94. VFSManager.error(browser, path, "ioerror.directory-error", pp);
  95. }
  96. finally
  97. {
  98. try
  99. {
  100. vfs._endVFSSession(session, browser);
  101. }
  102. catch (IOException io)
  103. {
  104. setCancellable(false);
  105. Log.log(Log.ERROR, this, io);
  106. String[] pp = {io.toString()};
  107. VFSManager.error(browser, path, "ioerror.directory-error", pp);
  108. }
  109. }
  110. } //}}}
  111. //{{{ toString() method
  112. public String toString()
  113. {
  114. return getClass().getName() + "[type=RENAME"
  115. + ",vfs=" + vfs + ",path=" + path
  116. + ",path2=" + path2 + ']';
  117. } //}}}
  118. //{{{ Private members
  119. private String path2;
  120. //}}}
  121. }