Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1a39937

Browse files
add support for contest name directory structure
1 parent c76b63d commit 1a39937

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

‎src/com/dogcows/Editor.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ public class Editor
3131
*/
3232
private String name;
3333

34+
/**
35+
* The name of the contest.
36+
*/
37+
private String contestName;
38+
39+
/**
40+
* The point value.
41+
*/
42+
private String points;
43+
3444
/**
3545
* The path of the current source file.
3646
*/
@@ -68,6 +78,8 @@ public Editor(ProblemComponentModel component,
6878
{
6979
this.id = String.valueOf(component.getProblem().getProblemID());
7080
this.name = component.getClassName();
81+
this.contestName = component.getProblem().getRound().getContestName().replaceAll(" ", "-");
82+
this.points = String.valueOf(component.getPoints().intValue());
7183

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

7991
// Make sure the problem directory exists.
80-
this.directory = new File(topDir, id);
81-
if (!directory.isDirectory())
92+
File newStyleDirectory = new File(new File(topDir, contestName), points);
93+
File oldStyleDirectory = new File(topDir, id);
94+
if (newStyleDirectory.isDirectory())
95+
{
96+
this.directory = newStyleDirectory;
97+
}
98+
else if (oldStyleDirectory.isDirectory())
99+
{
100+
this.directory = oldStyleDirectory;
101+
}
102+
else if (VimCoder.isContestDirNames())
103+
{
104+
this.directory = newStyleDirectory;
105+
if (!directory.mkdirs()) throw new IOException(directory.getPath());
106+
}
107+
else
82108
{
109+
this.directory = oldStyleDirectory;
83110
if (!directory.mkdirs()) throw new IOException(directory.getPath());
84111
}
85112

@@ -116,7 +143,7 @@ public Editor(ProblemComponentModel component,
116143

117144
// Expand the template for the main class and write it to the current
118145
// source file.
119-
sourceFile = new File(directory, name + "." + ext);
146+
this.sourceFile = new File(directory, name + "." + ext);
120147
if (!sourceFile.canRead())
121148
{
122149
String text = Util.expandTemplate(readTemplate(lang + "Template"), terms);

‎src/com/dogcows/Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static String readFile(File file) throws IOException
104104
/**
105105
* Read a resource file into a string object.
106106
* The resources should be placed in the directory `resources'
107-
* underneath the parent directory of this class.Reading resources
107+
* underneath the parent directory of this class.Reading resources
108108
* packaged in a jar is allowable.
109109
* @param path Relative path to the resource.
110110
* @return The contents of the resource.

‎src/com/dogcows/VimCoder.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public class VimCoder
5454
System.getProperty("file.separator") + ".vimcoder");
5555
}
5656

57+
/**
58+
* Whether or not to use the contest name and point value as problem
59+
* directory names.
60+
*/
61+
private static boolean contestDirNames = false;
62+
5763

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

95+
/**
96+
* The key for the problem directory name preference.
97+
*/
98+
private final static String CONTESTDIRNAMES = "com.dogcows.VimCoder.config.contestdirnames";
99+
89100
/**
90101
* The preferences object for storing plugin settings.
91102
*/
@@ -110,6 +121,16 @@ public static File getStorageDirectory()
110121
return rootDir;
111122
}
112123

124+
/**
125+
* Get whether or not to save problems in a human-readable directory
126+
* structure.
127+
* @return The directory name setting.
128+
*/
129+
public static boolean isContestDirNames()
130+
{
131+
return contestDirNames;
132+
}
133+
113134

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

307+
final JCheckBox contestDirNamesButton = new JCheckBox(
308+
"Store problems according to contest name and point value.",
309+
contestDirNames
310+
);
311+
contestDirNamesButton.setForeground(Common.FG_COLOR);
312+
contestDirNamesButton.setBackground(Common.WPB_COLOR);
313+
contestDirNamesButton.setFont(rootDirLabel.getFont());
314+
c.gridx = 1;
315+
c.gridy = 1;
316+
c.gridwidth = 2;
317+
fieldPanel.add(contestDirNamesButton, c);
318+
286319
JLabel vimCommandLabel = new JLabel("Vim Command:");
287320
vimCommandLabel.setForeground(Common.FG_COLOR);
288321
c.gridx = 0;
289-
c.gridy = 1;
322+
c.gridy = 2;
323+
c.gridwidth = 1;
290324
fieldPanel.add(vimCommandLabel, c);
291325

292326
final JTextField vimCommandField = new JTextField(vimCommand);
293327
vimCommandField.setPreferredSize(new Dimension(0, 24));
294328
c.gridx = 1;
295-
c.gridy = 1;
329+
c.gridy = 2;
296330
c.weightx = 1.0;
297331
c.gridwidth = 2;
298332
fieldPanel.add(vimCommandField, c);
@@ -339,6 +373,7 @@ public void actionPerformed(ActionEvent actionEvent)
339373
{
340374
prefs.setProperty(VIMCOMMAND, vimCommandField.getText());
341375
prefs.setProperty(ROOTDIR, rootDirField.getText());
376+
prefs.setProperty(CONTESTDIRNAMES, String.valueOf(contestDirNamesButton.isSelected()));
342377
JOptionPane.showMessageDialog(null, "Preferences were saved successfully.");
343378
}
344379
});
@@ -362,6 +397,9 @@ private void loadConfiguration()
362397

363398
String dir = prefs.getProperty(ROOTDIR);
364399
if (dir != null) rootDir = new File(dir);
400+
401+
String cn = prefs.getProperty(CONTESTDIRNAMES);
402+
if (cn != null) contestDirNames = Boolean.parseBoolean(cn);
365403
}
366404

367405

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /