use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.
the class PeersViewBase method addPeersMenu.
protected static boolean addPeersMenu(final DownloadManager man, String column_name, Menu menu) {
new MenuItem(menu, SWT.SEPARATOR);
MenuItem copy_me_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(copy_me_item, "menu.copy.my.peer");
copy_me_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
String str = getMyPeerDetails();
if (str.isEmpty()) {
str = "<no usable peers>";
}
ClipboardCopy.copyToClipBoard(str);
}
});
if (man == null) {
return (true);
}
PEPeerManager pm = man.getPeerManager();
if (pm == null) {
return (true);
}
if (TorrentUtils.isReallyPrivate(man.getTorrent())) {
return (true);
}
MenuItem copy_all_peers = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(copy_all_peers, "menu.copy.all.peers");
copy_all_peers.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
List<PEPeer> peers = pm.getPeers();
String str = getMyPeerDetails();
for (PEPeer peer : peers) {
int port = peer.getTCPListenPort();
if (port > 0) {
String address = peer.getIp() + ":" + port;
str += (str.isEmpty() ? "" : ",") + address;
}
}
if (str.isEmpty()) {
str = "<no usable peers>";
}
ClipboardCopy.copyToClipBoard(str);
}
});
MenuItem add_peers_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(add_peers_item, "menu.add.peers");
add_peers_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("dialog.add.peers.title", "dialog.add.peers.msg");
String def = COConfigurationManager.getStringParameter("add.peers.default", "");
entryWindow.setPreenteredText(String.valueOf(def), false);
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (!entryWindow.hasSubmittedInput()) {
return;
}
String sReturn = entryWindow.getSubmittedInput();
if (sReturn == null) {
return;
}
COConfigurationManager.setParameter("add.peers.default", sReturn);
PEPeerManager pm = man.getPeerManager();
if (pm == null) {
return;
}
String[] bits = sReturn.split(",");
for (String bit : bits) {
bit = bit.trim();
int pos = bit.lastIndexOf(':');
if (pos != -1) {
String host = bit.substring(0, pos).trim();
String port = bit.substring(pos + 1).trim();
try {
int i_port = Integer.parseInt(port);
pm.addPeer(host, i_port, 0, NetworkManager.getCryptoRequired(NetworkManager.CRYPTO_OVERRIDE_NONE), null);
} catch (Throwable e) {
}
} else {
pm.addPeer(bit, 6881, 0, NetworkManager.getCryptoRequired(NetworkManager.CRYPTO_OVERRIDE_NONE), null);
}
}
}
});
}
});
return (true);
}
use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.
the class TorrentUtil method repositionManual.
public static void repositionManual(final TableView tv, final DownloadManager[] dms, final Shell shell, final boolean isSeedingView) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("MyTorrentsView.dialog.setPosition.title", "MyTorrentsView.dialog.setPosition.text");
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (!entryWindow.hasSubmittedInput()) {
return;
}
String sReturn = entryWindow.getSubmittedInput();
if (sReturn == null)
return;
int newPosition = -1;
try {
newPosition = Integer.valueOf(sReturn).intValue();
} catch (NumberFormatException er) {
// Ignore
}
Core core = CoreFactory.getSingleton();
if (core == null) {
return;
}
int size = core.getGlobalManager().downloadManagerCount(isSeedingView);
if (newPosition > size)
newPosition = size;
if (newPosition <= 0) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setText(MessageText.getString("MyTorrentsView.dialog.NumberError.title"));
mb.setMessage(MessageText.getString("MyTorrentsView.dialog.NumberError.text"));
mb.open();
return;
}
moveSelectedTorrentsTo(tv, dms, newPosition);
}
});
}
use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.
the class SBC_AllTrackersView method addRemovalMenu.
private void addRemovalMenu(List<Tag> all_tags, List<Tag> tracker_prop_tags, List<AllTrackersTracker> trackers, boolean hasSelection, Menu menu, boolean is_future) {
Map<Tag, String> existing_removal_templates = new TreeMap<>(TagUtils.getTagComparator());
for (Tag t : all_tags) {
TagFeatureProperties tfp = (TagFeatureProperties) t;
TagProperty[] props = tfp.getSupportedProperties();
String template_name = null;
boolean has_true_constraint = false;
boolean has_any_constraint = false;
for (TagProperty prop : props) {
String tp_name = prop.getName(false);
if (tp_name.equals(TagFeatureProperties.PR_TRACKER_TEMPLATES)) {
String[] val = prop.getStringList();
if (val.length == 1) {
String[] bits = val[0].split(":", 2);
if (bits[0].equals("x")) {
template_name = bits[1];
}
}
} else if (tp_name.equals(TagFeatureProperties.PR_CONSTRAINT)) {
String[] val = prop.getStringList();
if (val != null && val.length > 0) {
String constraint = val[0];
has_any_constraint = constraint != null && !constraint.trim().isEmpty();
has_true_constraint = has_any_constraint && constraint.equalsIgnoreCase("true");
}
}
}
if (template_name != null) {
if (is_future) {
if (has_true_constraint) {
existing_removal_templates.put(t, template_name);
}
} else {
if (!has_any_constraint) {
existing_removal_templates.put(t, template_name);
}
}
}
}
Menu tt_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
MenuItem tt_item = new MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(tt_item, is_future ? "alltorrents.remove.from.torrents.future" : "alltorrents.remove.from.torrents.now");
tt_item.setMenu(tt_menu);
// merge into existing
Menu tt_merge_menu = new Menu(tt_menu.getShell(), SWT.DROP_DOWN);
MenuItem tt_merge_item = new MenuItem(tt_menu, SWT.CASCADE);
Messages.setLanguageText(tt_merge_item, "alltorrents.merge.into.existing");
tt_merge_item.setMenu(tt_merge_menu);
if (existing_removal_templates.isEmpty()) {
tt_merge_item.setEnabled(false);
} else {
for (Tag tag : existing_removal_templates.keySet()) {
MenuItem item = new MenuItem(tt_merge_menu, SWT.PUSH);
item.setText(tag.getTagName(true));
item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
String name = existing_removal_templates.get(tag);
TrackersUtil tut = TrackersUtil.getInstance();
List<List<String>> existing_trackers = tut.getMultiTrackers().get(name);
List<List<String>> new_trackers = new ArrayList<>();
for (AllTrackersTracker tracker : trackers) {
List<String> l = new ArrayList<>();
l.add(tracker.getTrackerName());
new_trackers.add(l);
}
if (existing_trackers != null) {
new_trackers = TorrentUtils.mergeAnnounceURLs(existing_trackers, new_trackers);
}
tut.addMultiTracker(name, new_trackers);
TagFeatureProperties tfp = (TagFeatureProperties) tag;
TagProperty prop = tfp.getProperty(TagFeatureProperties.PR_TRACKER_TEMPLATES);
prop.setStringList(new String[] { "x:" + name });
prop.syncListeners();
if (is_future) {
// constraint already set
} else {
List<DownloadManager> dms = CoreFactory.getSingleton().getGlobalManager().getDownloadManagers();
for (DownloadManager dm : dms) {
tag.addTaggable(dm);
}
}
}
});
}
}
new MenuItem(tt_menu, SWT.SEPARATOR);
MenuItem tt_create_item = new MenuItem(tt_menu, SWT.PUSH);
Messages.setLanguageText(tt_create_item, "alltorrents.merge.new");
tt_create_item.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("alltorrents.new.action.title", "alltorrents.new.action.msg");
entryWindow.prompt(new UIInputReceiverListener() {
@Override
public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
if (!entryWindow.hasSubmittedInput()) {
return;
}
String new_name = entryWindow.getSubmittedInput().trim();
TrackersUtil tut = TrackersUtil.getInstance();
Set<String> existing_names = new HashSet<>(tut.getMultiTrackers().keySet());
for (Tag t : all_tags) {
existing_names.add(t.getTagName(true));
}
if (existing_names.contains(new_name)) {
int num = 1;
while (true) {
String test = new_name + "_" + num++;
if (!existing_names.contains(test)) {
new_name = test;
break;
}
}
}
TagType tt = TagManagerFactory.getTagManager().getTagType(TagType.TT_DOWNLOAD_MANUAL);
try {
Tag new_tag = tt.createTag(new_name, true);
new_tag.setPublic(false);
TagFeatureProperties tfp = (TagFeatureProperties) new_tag;
if (is_future) {
TagProperty prop = tfp.getProperty(TagFeatureProperties.PR_CONSTRAINT);
prop.setStringList(new String[] { "true" });
}
List<List<String>> urls = new ArrayList<>();
for (AllTrackersTracker tracker : trackers) {
List<String> l = new ArrayList<>();
l.add(tracker.getTrackerName());
urls.add(l);
}
tut.addMultiTracker(new_name, urls);
TagProperty prop = tfp.getProperty(TagFeatureProperties.PR_TRACKER_TEMPLATES);
prop.setStringList(new String[] { "x:" + new_name });
prop.syncListeners();
if (!is_future) {
List<DownloadManager> dms = CoreFactory.getSingleton().getGlobalManager().getDownloadManagers();
for (DownloadManager dm : dms) {
new_tag.addTaggable(dm);
}
}
} catch (Throwable e) {
Debug.out(e);
}
}
});
}
});
tt_item.setEnabled(hasSelection);
}
use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.
the class ConfigView method _initialize.
private void _initialize(final Composite composite) {
GridData gridData;
/*
/--cConfig-----------------------------------------------------------\
| ###SashForm#form################################################## |
| # /--cLeftSide-\ /--cRightSide---------------------------------\ # |
| # | ##tree#### | | ***cHeader********************************* | # |
| # | # # | | * lHeader usermodeHint * | # |
| # | # # | | ******************************************* | # |
| # | # # | | ###Composite cConfigSection################ | # |
| # | # # | | # # | # |
| # | # # | | # # | # |
| # | # # | | # # | # |
| # | ########## | | # # | # |
| # |txtFilter X | | ########################################### | # |
| # \------------/ \---------------------------------------------/ # |
| ################################################################## |
| [Buttons] |
\--------------------------------------------------------------------/
*/
try {
Display d = composite.getDisplay();
GridLayout configLayout;
assert cConfig != null;
SashForm form = new SashForm(cConfig, SWT.HORIZONTAL);
gridData = new GridData(GridData.FILL_BOTH);
form.setLayoutData(gridData);
Composite cLeftSide = new Composite(form, SWT.BORDER);
gridData = new GridData(GridData.FILL_BOTH);
cLeftSide.setLayoutData(gridData);
FormLayout layout = new FormLayout();
cLeftSide.setLayout(layout);
BubbleTextBox bubbleTextBox = new BubbleTextBox(cLeftSide, SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL | SWT.SINGLE);
final Text txtFilter = bubbleTextBox.getTextWidget();
Composite cFilterArea = bubbleTextBox.getMainWidget();
txtFilter.addModifyListener(e -> filterTree(txtFilter.getText()));
tree = new Tree(cLeftSide, SWT.NONE);
FontData[] fontData = tree.getFont().getFontData();
fontData[0].setStyle(SWT.BOLD);
filterFoundFont = new Font(d, fontData);
FormData formData;
formData = new FormData();
formData.bottom = new FormAttachment(100, -5);
formData.left = new FormAttachment(0, 2);
formData.right = new FormAttachment(100, -2);
bubbleTextBox.setMessageAndLayout(MessageText.getString("ConfigView.filter"), formData);
formData = new FormData();
formData.top = new FormAttachment(0, 0);
formData.left = new FormAttachment(0, 0);
formData.right = new FormAttachment(100, 0);
formData.bottom = new FormAttachment(cFilterArea, -5);
tree.setLayoutData(formData);
Composite cRightSide = new Composite(form, SWT.NULL);
configLayout = new GridLayout();
configLayout.marginHeight = 3;
configLayout.marginWidth = 0;
cRightSide.setLayout(configLayout);
// Header
Composite cHeader = new Composite(cRightSide, SWT.BORDER);
configLayout = new GridLayout();
configLayout.marginHeight = 3;
configLayout.marginWidth = 0;
configLayout.numColumns = 2;
configLayout.marginRight = 5;
cHeader.setLayout(configLayout);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
cHeader.setLayoutData(gridData);
cHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
cHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
lHeader = new Label(cHeader, SWT.NULL);
lHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
lHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
fontData = lHeader.getFont().getFontData();
fontData[0].setStyle(SWT.BOLD);
int fontHeight = (int) (fontData[0].getHeight() * 1.2);
fontData[0].setHeight(fontHeight);
headerFont = new Font(d, fontData);
lHeader.setFont(headerFont);
gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_BEGINNING);
lHeader.setLayoutData(gridData);
usermodeHint = new Label(cHeader, SWT.NULL);
usermodeHint.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
usermodeHint.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL);
usermodeHint.setLayoutData(gridData);
Menu headerMenu = new Menu(cHeader.getShell(), SWT.POP_UP);
final MenuItem menuShortCut = new MenuItem(headerMenu, SWT.PUSH);
Messages.setLanguageText(menuShortCut, "label.set.shortcut");
menuShortCut.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
final TreeItem tree_item = (TreeItem) lHeader.getData("TreeItem");
if (tree_item != null) {
final String id = (String) tree_item.getData("ID");
if (id != null) {
UIInputReceiver entryWindow = new SimpleTextEntryWindow("config.dialog.shortcut.title", "config.dialog.shortcut.text");
entryWindow.setPreenteredText(COConfigurationManager.getStringParameter("config.section.shortcut.key." + id, ""), false);
entryWindow.setTextLimit(1);
entryWindow.prompt(ew -> {
if (!ew.hasSubmittedInput()) {
return;
}
String sReturn = ew.getSubmittedInput();
if (sReturn != null) {
sReturn = sReturn.trim();
if (sReturn.length() > 1) {
sReturn = sReturn.substring(0, 1);
}
COConfigurationManager.setParameter("config.section.shortcut.key." + id, sReturn);
updateHeader(tree_item);
}
});
}
}
}
});
cHeader.setMenu(headerMenu);
lHeader.setMenu(headerMenu);
usermodeHint.setMenu(headerMenu);
// Config Section
cConfigSection = new Composite(cRightSide, SWT.NULL);
layoutConfigSection = new StackLayout();
cConfigSection.setLayout(layoutConfigSection);
gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalIndent = 2;
cConfigSection.setLayoutData(gridData);
form.setWeights(new int[] { 20, 80 });
tree.addListener(SWT.Selection, e -> {
if (!(e.widget instanceof Tree)) {
return;
}
Tree tree = (Tree) e.widget;
// and you close its parent.
if (tree.getSelection().length > 0) {
showSection(tree.getSelection()[0], false, null);
}
});
// Double click = expand/contract branch
tree.addListener(SWT.DefaultSelection, e -> {
TreeItem item = (TreeItem) e.item;
if (item != null) {
item.setExpanded(!item.getExpanded());
}
});
} catch (Exception e) {
Logger.log(new LogEvent(LOGID, "Error initializing ConfigView", e));
return;
}
// Add sections
/**
* How to add a new section
* 1) Create a new implementation of ConfigSectionSWT in a new file
* (Use the ConfigSectionTMP.java as a template if it's still around)
* 2) import it into here
* 3) add it to the internal sections list
*/
pluginSections = ConfigSectionRepository.getInstance().getList();
BaseConfigSection[] internalSections = { new ConfigSectionMode(), new ConfigSectionStartShutdown(), new ConfigSectionBackupRestoreSWT(), new ConfigSectionConnection(), new ConfigSectionConnectionProxySWT(), new ConfigSectionConnectionAdvanced(), new ConfigSectionConnectionEncryption(), new ConfigSectionConnectionDNS(), new ConfigSectionTransfer(), new ConfigSectionTransferAutoSpeedSelect(), new ConfigSectionTransferAutoSpeedClassic(), new ConfigSectionTransferAutoSpeedV2(), new ConfigSectionTransferLAN(), new ConfigSectionFile(), new ConfigSectionFileMove(), new ConfigSectionFileTorrents(), new ConfigSectionFileTorrentsDecoding(), new ConfigSectionFilePerformance(), new ConfigSectionInterfaceSWT(), new ConfigSectionInterfaceLanguageSWT(), new ConfigSectionInterfaceStartSWT(), new ConfigSectionInterfaceDisplaySWT(), new ConfigSectionInterfaceTagsSWT(), new ConfigSectionInterfaceTablesSWT(), new ConfigSectionInterfaceColorSWT(), new ConfigSectionInterfaceAlertsSWT(), new ConfigSectionInterfacePasswordSWT(), new ConfigSectionInterfaceLegacySWT(), new ConfigSectionIPFilterSWT(), new ConfigSectionPluginsSWT(), new ConfigSectionStats(), new ConfigSectionTracker(), new ConfigSectionTrackerClient(), new ConfigSectionTrackerServerSWT(), new ConfigSectionSecuritySWT(), new ConfigSectionSharing(), new ConfigSectionLogging() };
pluginSections.addAll(0, Arrays.asList(internalSections));
ConfigSectionRebuildRunner rebuildSectionRunnable = configSection -> Utils.execSWTThread(() -> ensureSectionBuilt(findTreeItem(configSection.getConfigSectionID()), true));
for (BaseConfigSection section : pluginSections) {
section.setRebuildRunner(rebuildSectionRunnable);
String section_key = section.getSectionNameKey();
String section_name = MessageText.getString(section_key);
try {
TreeItem treeItem;
String location = section.getParentSectionID();
if (location == null || location.length() == 0 || location.equalsIgnoreCase(ConfigSection.SECTION_ROOT)) {
// int position = findInsertPointFor(section_name, tree);
// if ( position == -1 ){
treeItem = new TreeItem(tree, SWT.NULL);
// }else{
// treeItem = new TreeItem(tree, SWT.NULL, position);
// }
} else {
TreeItem treeItemFound = findTreeItem(tree, location);
if (treeItemFound != null) {
if (location.equalsIgnoreCase(ConfigSection.SECTION_PLUGINS)) {
// Force ordering by name here.
int position = findInsertPointFor(section_name, treeItemFound);
if (position == -1) {
treeItem = new TreeItem(treeItemFound, SWT.NULL);
} else {
treeItem = new TreeItem(treeItemFound, SWT.NULL, position);
}
} else {
treeItem = new TreeItem(treeItemFound, SWT.NULL);
}
} else {
treeItem = new TreeItem(tree, SWT.NULL);
}
}
ScrolledComposite sc = new ScrolledComposite(cConfigSection, SWT.H_SCROLL | SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setLayoutData(new GridData(GridData.FILL_BOTH));
ScrollBar verticalBar = sc.getVerticalBar();
if (verticalBar != null) {
verticalBar.setIncrement(16);
}
sc.addListener(SWT.Resize, (event) -> setupSC((ScrolledComposite) event.widget));
Messages.setLanguageText(treeItem, section_key);
treeItem.setData(TREEITEMDATA_PANEL, sc);
treeItem.setData("ID", section.getConfigSectionID());
treeItem.setData(TREEITEMDATA_CONFIGSECTION, section);
sc.setData(TREEITEMDATA_ITEM, treeItem);
sections.put(treeItem, section);
} catch (Exception e) {
Logger.log(new LogEvent(LOGID, "ConfigSection plugin '" + section.getConfigSectionID() + "' caused an error", e));
}
}
final Display d = composite.getDisplay();
final Listener shortcut_listener = e -> {
if ((e.stateMask & (SWT.MOD1 | SWT.CONTROL)) == 0 && e.keyCode != SWT.COMMAND) {
return;
}
char key = e.character;
if (key <= 26 && key > 0) {
key += 'a' - 1;
}
if ((e.stateMask & SWT.SHIFT) != 0) {
key = Character.toUpperCase(key);
}
if (!Character.isISOControl(key)) {
for (TreeItem ti : sections.keySet()) {
if (ti.isDisposed()) {
continue;
}
String id = (String) ti.getData("ID");
if (id != null) {
String shortcut = COConfigurationManager.getStringParameter("config.section.shortcut.key." + id, "");
if (shortcut.equals(String.valueOf(key))) {
// findFocus( cConfig );
selectSection(id, true);
e.doit = false;
break;
}
}
}
}
};
d.addFilter(SWT.KeyDown, shortcut_listener);
cConfigSection.addDisposeListener(e -> d.removeFilter(SWT.KeyDown, shortcut_listener));
if (composite instanceof Shell) {
initApplyCloseButton();
} else {
initSaveButton();
}
if (startSection != null) {
if (selectSection(startSection, false)) {
return;
}
}
Runnable r = () -> {
TreeItem selection = getLatestSelection();
TreeItem[] items = { selection };
tree.setSelection(items);
// setSelection doesn't trigger a SelectionListener, so..
showSection(selection, false, null);
};
if (Constants.isOSX) {
// Catalina (public beta at least) bug whereby scrollbar is borked if we
// synchronously attempt to set the visible section
Utils.execSWTThreadLater(250, r);
} else {
r.run();
}
}
use of com.biglybt.pif.ui.UIInputReceiver in project BiglyBT by BiglySoftware.
the class FilesViewMenuUtil method askForRenameFilenameAndExecSupport.
private static void askForRenameFilenameAndExecSupport(DiskManagerFileInfo fileInfo, TableView tv) {
SimpleTextEntryWindow dialog = new SimpleTextEntryWindow("FilesView.rename.filename.title", "FilesView.rename.filename.text");
// need to do this otherwise the dialog may grab an in-the-process-of-closing
dialog.setParentShell(Utils.findAnyShell());
// previous shell as parent and get immediately closed via dispose...
dialog.setRememberLocationSize("file.rename.dialog.pos");
dialog.setEnableSpecialEscapeHandling(true);
String file_name = fileInfo.getFile(true).getName();
// false -> it's not "suggested", it's a previous value
dialog.setPreenteredText(file_name, false);
int pos = file_name.lastIndexOf('.');
if (pos > 0) {
String suffix = fileInfo.getDownloadManager().getDownloadState().getAttribute(DownloadManagerState.AT_INCOMP_FILE_SUFFIX);
if (suffix != null && file_name.substring(pos).equals(suffix)) {
pos--;
while (pos > 0 && file_name.charAt(pos) != '.') {
pos--;
}
}
if (pos > 0) {
dialog.selectPreenteredTextRange(new int[] { 0, pos });
}
}
dialog.allowEmptyInput(false);
dialog.prompt(new UIInputReceiverListener() {
boolean fired = false;
@Override
public void UIInputReceiverClosed(UIInputReceiver receiver) {
synchronized (renameQueue) {
if (fired) {
return;
}
fired = true;
renameActive = false;
if (!receiver.hasSubmittedInput()) {
if (receiver.userHitEscape()) {
renameQueue.clear();
} else {
processRenameQueue();
}
return;
}
}
File existing_file = fileInfo.getFile(true);
File f_target = new File(existing_file.getParentFile(), receiver.getSubmittedInput());
DownloadManager manager = fileInfo.getDownloadManager();
boolean needsUnpause = manager.pause(true);
moveFile(fileInfo.getDownloadManager(), fileInfo, existing_file, f_target, false, new Runnable() {
@Override
public void run() {
if (needsUnpause) {
manager.resume();
}
invalidateRows(tv, Collections.singletonList(fileInfo));
processRenameQueue();
}
});
}
});
}
Aggregations