Skip to content

Commit

Permalink
add support for contest name directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
chazmcgarvey committed Apr 8, 2013
1 parent c76b63d commit 1a39937
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
33 changes: 30 additions & 3 deletions src/com/dogcows/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public class Editor
*/
private String name;

/**
* The name of the contest.
*/
private String contestName;

/**
* The point value.
*/
private String points;

/**
* The path of the current source file.
*/
Expand Down Expand Up @@ -68,6 +78,8 @@ public Editor(ProblemComponentModel component,
{
this.id = String.valueOf(component.getProblem().getProblemID());
this.name = component.getClassName();
this.contestName = component.getProblem().getRound().getContestName().replaceAll(" ", "-");
this.points = String.valueOf(component.getPoints().intValue());

// Make sure the top-level vimcoder directory exists.
File topDir = VimCoder.getStorageDirectory();
Expand All @@ -77,9 +89,24 @@ public Editor(ProblemComponentModel component,
}

// Make sure the problem directory exists.
this.directory = new File(topDir, id);
if (!directory.isDirectory())
File newStyleDirectory = new File(new File(topDir, contestName), points);
File oldStyleDirectory = new File(topDir, id);
if (newStyleDirectory.isDirectory())
{
this.directory = newStyleDirectory;
}
else if (oldStyleDirectory.isDirectory())
{
this.directory = oldStyleDirectory;
}
else if (VimCoder.isContestDirNames())
{
this.directory = newStyleDirectory;
if (!directory.mkdirs()) throw new IOException(directory.getPath());
}
else
{
this.directory = oldStyleDirectory;
if (!directory.mkdirs()) throw new IOException(directory.getPath());
}

Expand Down Expand Up @@ -116,7 +143,7 @@ public Editor(ProblemComponentModel component,

// Expand the template for the main class and write it to the current
// source file.
sourceFile = new File(directory, name + "." + ext);
this.sourceFile = new File(directory, name + "." + ext);
if (!sourceFile.canRead())
{
String text = Util.expandTemplate(readTemplate(lang + "Template"), terms);
Expand Down
2 changes: 1 addition & 1 deletion src/com/dogcows/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static String readFile(File file) throws IOException
/**
* Read a resource file into a string object.
* The resources should be placed in the directory `resources'
* underneath the parent directory of this class. Reading resources
* underneath the parent directory of this class. Reading resources
* packaged in a jar is allowable.
* @param path Relative path to the resource.
* @return The contents of the resource.
Expand Down
42 changes: 40 additions & 2 deletions src/com/dogcows/VimCoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public class VimCoder
System.getProperty("file.separator") + ".vimcoder");
}

/**
* Whether or not to use the contest name and point value as problem
* directory names.
*/
private static boolean contestDirNames = false;


/**
* The panel given to the Arena applet when it is requested.
Expand Down Expand Up @@ -86,6 +92,11 @@ public class VimCoder
*/
private final static String ROOTDIR = "com.dogcows.VimCoder.config.rootdir";

/**
* The key for the problem directory name preference.
*/
private final static String CONTESTDIRNAMES = "com.dogcows.VimCoder.config.contestdirnames";

/**
* The preferences object for storing plugin settings.
*/
Expand All @@ -110,6 +121,16 @@ public static File getStorageDirectory()
return rootDir;
}

/**
* Get whether or not to save problems in a human-readable directory
* structure.
* @return The directory name setting.
*/
public static boolean isContestDirNames()
{
return contestDirNames;
}


/**
* Instantiate the entry point of the editor plugin.
Expand Down Expand Up @@ -283,16 +304,29 @@ public void configure()
c.anchor = GridBagConstraints.BASELINE_LEADING;
fieldPanel.add(browseButton, c);

final JCheckBox contestDirNamesButton = new JCheckBox(
"Store problems according to contest name and point value.",
contestDirNames
);
contestDirNamesButton.setForeground(Common.FG_COLOR);
contestDirNamesButton.setBackground(Common.WPB_COLOR);
contestDirNamesButton.setFont(rootDirLabel.getFont());
c.gridx = 1;
c.gridy = 1;
c.gridwidth = 2;
fieldPanel.add(contestDirNamesButton, c);

JLabel vimCommandLabel = new JLabel("Vim Command:");
vimCommandLabel.setForeground(Common.FG_COLOR);
c.gridx = 0;
c.gridy = 1;
c.gridy = 2;
c.gridwidth = 1;
fieldPanel.add(vimCommandLabel, c);

final JTextField vimCommandField = new JTextField(vimCommand);
vimCommandField.setPreferredSize(new Dimension(0, 24));
c.gridx = 1;
c.gridy = 1;
c.gridy = 2;
c.weightx = 1.0;
c.gridwidth = 2;
fieldPanel.add(vimCommandField, c);
Expand Down Expand Up @@ -339,6 +373,7 @@ public void actionPerformed(ActionEvent actionEvent)
{
prefs.setProperty(VIMCOMMAND, vimCommandField.getText());
prefs.setProperty(ROOTDIR, rootDirField.getText());
prefs.setProperty(CONTESTDIRNAMES, String.valueOf(contestDirNamesButton.isSelected()));
JOptionPane.showMessageDialog(null, "Preferences were saved successfully.");
}
});
Expand All @@ -362,6 +397,9 @@ private void loadConfiguration()

String dir = prefs.getProperty(ROOTDIR);
if (dir != null) rootDir = new File(dir);

String cn = prefs.getProperty(CONTESTDIRNAMES);
if (cn != null) contestDirNames = Boolean.parseBoolean(cn);
}


Expand Down

0 comments on commit 1a39937

Please sign in to comment.