Child:
[r24]
(diff)
Download this file
pluginSave.old
114 lines (95 with data), 3.5 kB
package test;
import GUI.ListItem;
import GUI.RunPlugins;
import GUI.swingUtils;
import definitions.Messages;
import definitions.is;
import java.io.File;
import script.Plugin;
import script.log;
import studio.core;
/**
*
* @author Nuno Brito, 19th of September 2013 in Darmstadt, Germany.
*/
public class pluginSave extends Plugin{
// we add imports to define the libraries that will be needed on this script
String textSave = "Save changes";
/**
* this method is called after the plugin is installed (only one time)
*/
void install(){
// we call the startup method to get the hook listed on "startup()" launched
// this way we avoided the need to restart winbuilder to activate the hook
startup();
}
/**
* this method is only called when the plugin in uninstalled (only one time)
*/
void uninstall(){
// nothing to do here. You can use this method to do basic cleanup
// of whatever files / traces should be removed from this plugin
}
/**
The initial method that is called upon the startup routine of WinBuilder.
Keep it light, too much code will slow down the overall startup
*/
@Override
public void startup(){
// we are adding a hook here. This hook allows running the "main" method on this script
// hooks are a way of running methods on scripts when a specific message is output to the screen
// this way, hooks can be attached to any message and run any scripts as needed
// we run this at startup to ensure it stays active when the user builds a boot disk
log.hooks.addAction(Messages.ReadyToUse, thisFile, "main");
log.hooks.addAction(Messages.TextWasModified, thisFile, "showSaveButton");
log.hooks.addAction(Messages.TextWasLoaded, thisFile, "hideSaveButton");
log.hooks.addAction("Single-click at " + textSave, thisFile, "doSaveFile");
log.hooks.addAction("Gained focus on Search Box", thisFile, "hideSaveButton");
}
void doSaveFile(){
File target = core.studio.getSPDX().file;
String text = core.studio.getTextBox().getText();
utils.files.SaveStringToFile(target, text);
String message = log.write(is.INFO, "SPDX file %1 was saved to disk",
core.studio.getSPDX().toString());
swingUtils.showMessage(message);
// refresh everything on the tree view
swingUtils.refreshAll(core.studio.getTree());
}
void showSaveButton(){
/**
log.write(is.INFO, "Showing the save button");
list = core.studio.getList();
SortedListModel model = new SortedListModel();
ListItem item = new ListItem();
item.title = "Save";
model.add(item);
list.setModel(model);
*/
if(core.studio.textWasModified == false){
// nothing to show, just exit
return;
}
// a search is being done, nothing to do here
if(core.searchBoxActive){
return;
}
if(core.studio.getTextBox().isEnabled() == false){
// nothing to show, just exit
return;
}
ListItem item = new ListItem();
item.title = textSave;
item.singleClick = true;
File icon = core.getIcon("disk-black.png");
item.setIcon(icon);
RunPlugins.addItem(item);
}
void hideSaveButton(){
RunPlugins.removeItem(textSave);
}
void main(){
// let's warn the end-user about what is going on here
log.write(is.INFO, "PLUGIN ADDED: SPDX save");
}
}