Ejemplo n.º 1
0
 public void save() {
   ensureLocation();
   for (int i = 0; i < sets.size(); i++) {
     ScopeSet set = (ScopeSet) sets.get(i);
     set.save();
   }
   IDialogSettings settings = HelpUIPlugin.getDefault().getDialogSettings();
   if (activeSet != null) settings.put(ACTIVE_SET, activeSet.getName());
 }
Ejemplo n.º 2
0
 /** @return Returns the activeSet. */
 public ScopeSet getActiveSet() {
   if (activeSet == null) {
     IDialogSettings settings = HelpUIPlugin.getDefault().getDialogSettings();
     String name = settings.get(ACTIVE_SET);
     activeSet = findSet(name);
     if (activeSet == null) {
       return (ScopeSet) sets.get(0);
     }
     if (!activeSet.isImplicit()) lastExplicitSet = activeSet;
   }
   return activeSet;
 }
Ejemplo n.º 3
0
 public void save() {
   getPreferenceStore();
   if (preferenceStore.needsSaving() || needsSaving) {
     try {
       if (defaultSet != -1) preferenceStore.setValue(KEY_DEFAULT, defaultSet > 0);
       preferenceStore.save();
       needsSaving = false;
     } catch (IOException e) {
       String message = Messages.bind(Messages.ScopeSet_errorSaving, name);
       HelpUIPlugin.logError(message, e);
     }
   }
 }
Ejemplo n.º 4
0
 public IPreferenceStore getPreferenceStore() {
   if (preferenceStore == null) {
     preferenceStore = new PreferenceStore(getFileName(this.name));
     try {
       File file = new File(getFileName(this.name));
       if (file.exists()) {
         preferenceStore.load();
       }
     } catch (IOException e) {
       String message = Messages.bind(Messages.ScopeSet_errorLoading, name);
       HelpUIPlugin.logError(message, e);
     }
   }
   return preferenceStore;
 }
Ejemplo n.º 5
0
 private void loadScopeSets() {
   sets = new ArrayList();
   IPath location = HelpUIPlugin.getDefault().getStateLocation();
   location = location.append("scope_sets"); // $NON-NLS-1$
   File dir = location.toFile();
   defSet = null;
   if (dir.exists() && dir.isDirectory()) {
     File[] files =
         dir.listFiles(
             new FilenameFilter() {
               public boolean accept(File dir, String name) {
                 return name.endsWith(ScopeSet.EXT) || name.endsWith(HistoryScopeSet.EXT);
               }
             });
     for (int i = 0; i < files.length; i++) {
       File file = files[i];
       String name = file.getName();
       int loc = name.lastIndexOf(ScopeSet.EXT);
       if (loc != -1) {
         ScopeSet set = new ScopeSet(name.substring(0, loc));
         sets.add(set);
         if (set.isDefault()) defSet = set;
         continue;
       }
       loc = name.lastIndexOf(HistoryScopeSet.EXT);
       if (loc != -1) {
         HistoryScopeSet set = new HistoryScopeSet(name.substring(0, loc), null);
         sets.add(set);
       }
     }
   }
   if (sets.size() == 1) {
     activeSet = (ScopeSet) sets.get(0);
   }
   if (defSet == null) {
     defSet = new ScopeSet();
     sets.add(defSet);
   }
 }
Ejemplo n.º 6
0
 /** @param name The name to set. */
 public void setName(String name) {
   String oldFileName = getFileName(this.name);
   File oldFile = new File(oldFileName);
   if (oldFile.exists()) {
     // store under the old name already exists
     if (preferenceStore == null) {
       // just rename the file
       oldFile.renameTo(new File(getFileName(name)));
     } else {
       // remove the old file, set the new file name,
       // then save to create the new file
       oldFile.delete();
       preferenceStore.setFilename(getFileName(name));
       try {
         preferenceStore.save();
       } catch (IOException e) {
         String message = Messages.bind(Messages.ScopeSet_errorSaving, name);
         HelpUIPlugin.logError(message, e);
       }
     }
   }
   this.name = name;
 }
Ejemplo n.º 7
0
 private String getFileName(String name) {
   IPath location = HelpUIPlugin.getDefault().getStateLocation();
   location = location.append(SCOPE_DIR_NAME);
   location = location.append(encodeFileName(name) + getExtension());
   return location.toOSString();
 }
Ejemplo n.º 8
0
 public static void ensureLocation() {
   IPath location = HelpUIPlugin.getDefault().getStateLocation();
   location = location.append(ScopeSet.SCOPE_DIR_NAME);
   File dir = location.toFile();
   if (dir.exists() == false) dir.mkdir();
 }