| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -265,6 +265,34 @@ static public int showYesNoQuestion(Frame editor, String title, | |||
| 265 | 265 | "<br>" + secondary, title, | |
| 266 | 266 | JOptionPane.YES_NO_OPTION, | |
| 267 | 267 | JOptionPane.QUESTION_MESSAGE); | |
| 268 | + } else { | ||
| 269 | + int result = showCustomQuestion(editor, title, primary, secondary, | ||
| 270 | + 0, "Yes", "No"); | ||
| 271 | + if (result == 0) { | ||
| 272 | + return JOptionPane.YES_OPTION; | ||
| 273 | + } else if (result == 1) { | ||
| 274 | + return JOptionPane.NO_OPTION; | ||
| 275 | + } else { | ||
| 276 | + return JOptionPane.CLOSED_OPTION; | ||
| 277 | + } | ||
| 278 | + } | ||
| 279 | + } | ||
| 280 | + | ||
| 281 | + | ||
| 282 | + /** | ||
| 283 | + * @param highlight A valid array index for options[] that specifies the | ||
| 284 | + * default (i.e. safe) choice. | ||
| 285 | + * @return The (zero-based) index of the selected value, -1 otherwise. | ||
| 286 | + */ | ||
| 287 | + static public int showCustomQuestion(Frame editor, String title, | ||
| 288 | + String primary, String secondary, | ||
| 289 | + int highlight, String... options) { | ||
| 290 | + Object result; | ||
| 291 | + if (!Platform.isMacOS()) { | ||
| 292 | + return JOptionPane.showOptionDialog(editor, | ||
| 293 | + "<html><body><b>" + primary + "</b><br>" + secondary, title, | ||
| 294 | + JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, | ||
| 295 | + options, options[highlight]); | ||
| 268 | 296 | } else { | |
| 269 | 297 | // Pane formatting adapted from the Quaqua guide | |
| 270 | 298 | // http://www.randelshofer.ch/quaqua/guide/joptionpane.html | |
@@ -275,29 +303,23 @@ static public int showYesNoQuestion(Frame editor, String title, | |||
| 275 | 303 | "p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }"+ | |
| 276 | 304 | "</style> </head>" + | |
| 277 | 305 | "<b>" + primary + "</b>" + | |
| 278 | - "<p>" + secondary + "</p>", | ||
| 306 | + "<p>" + secondary, // + "</p>", | ||
| 279 | 307 | JOptionPane.QUESTION_MESSAGE); | |
| 280 | 308 | ||
| 281 | - String[] options = new String[] { | ||
| 282 | - "Yes", "No" | ||
| 283 | - }; | ||
| 284 | 309 | pane.setOptions(options); | |
| 285 | 310 | ||
| 286 | 311 | // highlight the safest option ala apple hig | |
| 287 | - pane.setInitialValue(options[0]); | ||
| 312 | + pane.setInitialValue(options[highlight]); | ||
| 288 | 313 | ||
| 289 | 314 | JDialog dialog = pane.createDialog(editor, null); | |
| 290 | 315 | dialog.setVisible(true); | |
| 291 | 316 | ||
| 292 | - Object result = pane.getValue(); | ||
| 293 | - if (result == options[0]) { | ||
| 294 | - return JOptionPane.YES_OPTION; | ||
| 295 | - } else if (result == options[1]) { | ||
| 296 | - return JOptionPane.NO_OPTION; | ||
| 297 | - } else { | ||
| 298 | - return JOptionPane.CLOSED_OPTION; | ||
| 299 | - } | ||
| 317 | + result = pane.getValue(); | ||
| 318 | + } | ||
| 319 | + for (int i = 0; i < options.length; i++) { | ||
| 320 | + if (result != null && result.equals(options[i])) return i; | ||
| 300 | 321 | } | |
| 322 | + return -1; | ||
| 301 | 323 | } | |
| 302 | 324 | ||
| 303 | 325 | ||
@@ -340,4 +362,4 @@ static public void loge(String message) { | |||
| 340 | 362 | System.err.println(message); | |
| 341 | 363 | } | |
| 342 | 364 | } | |
| 343 | - } | ||
| 365 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -227,6 +227,20 @@ public void reload() { | |||
| 227 | 227 | } | |
| 228 | 228 | ||
| 229 | 229 | ||
| 230 | + /** | ||
| 231 | + * Load a tab that the user added to the sketch or modified with an external | ||
| 232 | + * editor. | ||
| 233 | + */ | ||
| 234 | + public void loadNewTab(String filename, String ext, boolean newAddition) { | ||
| 235 | + if (newAddition) { | ||
| 236 | + insertCode(new SketchCode(new File(folder, filename), ext)); | ||
| 237 | + } else { | ||
| 238 | + replaceCode(new SketchCode(new File(folder, filename), ext)); | ||
| 239 | + } | ||
| 240 | + sortCode(); | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + | ||
| 230 | 244 | protected void replaceCode(SketchCode newCode) { | |
| 231 | 245 | for (int i = 0; i < codeCount; i++) { | |
| 232 | 246 | if (code[i].getFileName().equals(newCode.getFileName())) { | |
@@ -685,7 +699,11 @@ public void handleDeleteCode() { | |||
| 685 | 699 | } | |
| 686 | 700 | ||
| 687 | 701 | ||
| 688 | - protected void removeCode(SketchCode which) { | ||
| 702 | + /** | ||
| 703 | + * Remove a SketchCode from the list of files without deleting its file. | ||
| 704 | + * @see #handleDeleteCode() | ||
| 705 | + */ | ||
| 706 | + public void removeCode(SketchCode which) { | ||
| 689 | 707 | // remove it from the internal list of files | |
| 690 | 708 | // resort internal list of files | |
| 691 | 709 | for (int i = 0; i < codeCount; i++) { | |
@@ -757,6 +775,16 @@ public boolean isModified() { | |||
| 757 | 775 | } | |
| 758 | 776 | ||
| 759 | 777 | ||
| 778 | + /** | ||
| 779 | + * Ensure that all SketchCodes are up-to-date, so that sc.save() works. | ||
| 780 | + */ | ||
| 781 | + public void updateSketchCodes() { | ||
| 782 | + // if (current.isModified()) { | ||
| 783 | + current.setProgram(editor.getText()); | ||
| 784 | + // } | ||
| 785 | + } | ||
| 786 | + | ||
| 787 | + | ||
| 760 | 788 | /** | |
| 761 | 789 | * Save all code in the current sketch. This just forces the files to save | |
| 762 | 790 | * in place, so if it's an untitled (un-saved) sketch, saveAs() should be | |
@@ -767,9 +795,7 @@ public boolean save() throws IOException { | |||
| 767 | 795 | ensureExistence(); | |
| 768 | 796 | ||
| 769 | 797 | // first get the contents of the editor text area | |
| 770 | - // if (current.isModified()) { | ||
| 771 | - current.setProgram(editor.getText()); | ||
| 772 | - // } | ||
| 798 | + updateSketchCodes(); | ||
| 773 | 799 | ||
| 774 | 800 | // don't do anything if not actually modified | |
| 775 | 801 | //if (!modified) return false; | |
@@ -911,9 +937,7 @@ public boolean saveAs() throws IOException { | |||
| 911 | 937 | ||
| 912 | 938 | // grab the contents of the current tab before saving | |
| 913 | 939 | // first get the contents of the editor text area | |
| 914 | - if (current.isModified()) { | ||
| 915 | - current.setProgram(editor.getText()); | ||
| 916 | - } | ||
| 940 | + updateSketchCodes(); | ||
| 917 | 941 | ||
| 918 | 942 | File[] copyItems = folder.listFiles(new FileFilter() { | |
| 919 | 943 | public boolean accept(File file) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments