How to restore selected path in FolderBrowserDialog - c#-4.0

In my application i just want to restore the path which was selected previously..
using (FolderBrowserDialog dlgDirestorySelector = new FolderBrowserDialog())
{
string directoryName;
dlgDirestorySelector.ShowNewFolderButton = false;
if (dlgDirestorySelector.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
directoryName = dlgDirestorySelector.SelectedPath;
}
//Processing code
}

You want to set the RootFolder property before you show the dialog.
Alternatively if the folder path is custom (and not a special folder), you simply need to set the SelectedPath property before showing the dialog (there are some rules around the path being set, explained in the "Remarks" section of the documentation I linked).

Related

Hyperlink to open/download a File (Acumatica)

Is there any way to make a hyperlink to a file that will open its contents or download it from the table it belongs? (In a sense, do exactly the same thing as AllowEdit but open/download the file instead.) Example:
Where the Default Specification files are from files found on the customer:
Please note that what displays is the comment of the file. If anyone has any suggestions on how to display the file name instead, that would be appreciated as well.
You can get the filename like this:
UploadFileMaintenance uploadFileMaintenance = PXGraph.CreateInstance<UploadFileMaintenance>();
foreach (Guid note in PXNoteAttribute.GetFileNotes(cache, dacRecord))
{
FileInfo file = uploadFileMaintenance.GetFileWithNoData(note);
PXTrace.WriteInformation(file.Name);
}
To download the file, create a DAC field of string type. You can initialize the string to the file name in the FieldDefaulting or FieldSelecting event. Declare an Action and use the LinkCommand attribute in the ASPX file to make that field control a link.
In that Action event handler, you can redirect the browser to the file in order to download/open it:
UploadFileMaintenance uploadFileMaintenance = PXGraph.CreateInstance<UploadFileMaintenance>();
Guid[] notes = PXNoteAttribute.GetFileNotes(cache, dacRecord);
if (notes != null && notes.Length > 0)
{
FileInfo downloadFile = uploadFileMaintenance.GetFile(notes[0]);
if (downloadFile != null)
{
throw new PXRedirectToFileException(downloadFile.UID, true);
}
}

How to override template file item-list.html.twig for field_slider_images in Drupal 8?

I want to override the item listing template file core/themes/classy/templates/dataset/item-list.html.twig for listing the fields field_slider_images as well as field_blog_tags respectively of their's multiple values of the field.
I have selected "Unordered List" in the view.
Please do check the attached image.
I have created following files :
item-list--field-blog-tags.html.twig
item-list--field-slider-images.html.twig
But, this is not rendered for the listing of the fields.
When I have created item-list.html.twig then only it will access.
However, both fields have different data to style and I am not able to get the current field name which is loading it's data in item-list.html.twig.
Had a brief look at this and it doesn't seem that 'item-list' to have suggestions, which is quite unfortunate.
In this situation there are two options:
Create your own suggestion which would accomplish exactly what you need.
You'll have to do something like this:
/
/*add new variable to theme with suggestion name*/
function hook_theme_registry_alter(&$theme_registry) {
$theme_registry['item_list']['variables']['suggestion'] = '';
}
//send a value to newly added variable to use it build the suggestion
function hook_ENTITY_TYPE_view(array &$build, $entity, $display, $view_mode) {
//add condition here if field exists or whatever, do the same for other field
$build['field_slider_images']['#suggestion'] = 'field_slider_images';
}
//use newly added variable to build suggestion
function hook_theme_suggestions_THEME_HOOK(array $variables) {//THEME_HOOK=item_list
$suggestions = array();
if(isset($variables['suggestion'])){
$suggestions[] = 'item_list__' . $variables['suggestion'];
}
return $suggestions;
}
Now you should be able to use item-list--field-slider-images.html.twig
Second option is to do what others in core did: use a new theme
function hook_ENTITY_TYPE_view(array &$build, $entity, $display, $view_mode) {
//add condition here if field exists or whatever, do the same for other field
$build['field_slider_images']['#theme'] = array(
'item_list',
'item_list__field_slider_images',
);
}

Allow all file types to be selected in Extendscript's File object openDlg() method on MacOS

I am trying to get a reference to a File object using the File.openDlg() method using Extendscript, but when I do this it only seems to allow me to select a specific file type. I want the dialog to allow me to open any type of file. When I use File.openDialog() I am able to select any file type, but because I am launching the OS specific file chooser when a modal dialog button is clicked, it causes the open file chooser to keep popping up--I don't know why it keeps looping, but I suspect it has to do with the "modalness" of the dialog that is currently up when the method is called. So, I am left with simply using the File.openDlg() method, but I don't understand how to inform the MacOS to allow a user to select any file type.
In Adobe's documentation the signature for the .openDlg method is as follows:
fileObj.OpenDlg ([prompt][,filter][,multiSelect])
Then it specifies that the [filter] paramter is:
In Mac OS, a filter function that takes a File instance and returns true if the file
should be included in the display, false if it should not.
So, because I do not want any filetype masking I call the method like so:
newFootageSrc.openDlg("Select your file", function(file) {return true;}, false);
This doesn't work, so I found older Adobe documentation where this was specified for the [filter] param:
In Mac OS, a string containing the name of a function defined in the current
JavaScript scope that takes a File object argument. The function is called
foreach file about to be displayed in the dialog, and the file is displayed
only whenthe function returns true
So, I simply made a named function like this
function allFileTypesOSX(file){ return true; }
And then referenced allFileTypesOSX in the method call like this:
newFootageSrc.openDlg("Select your file", "allFileTypesOSX", false);
That didn't work, so I thought maybe just passing in the identifier itself rather than string would do the trick:
newFootageSrc.openDlg("Select your file", allFileTypesOSX, false);
But alas, that didn't work. Has anybody successfully been able to control file types in the MacOS dialog using ExtendScript?
I know I have this working in scripts at home, so I'll double check the syntax I use when I get home, but I do something along these lines (I'm supporting both windows and mac users).
var fileMask;
if(isWindows()) fileMask = '*.psd';
if(isMac()) fileMask = function(file){file.name.match(/\.psd$/i) ? true:false;}
var files = File.openDialog ('prompt', fileMask, true);
Its more similar to original attempt - you should be passing the actual filter function, not its name.
ETA: If you're not trying to actually limit the selectable files - have you tried just passing null, or leaving the parameter out altogether? They are all optional.
ETA: actual code from a working script (for Photoshop, works in CS3+). By 'works' I mean users on macs are able to select the files they need. I don't have a mac myself to actually see what they see. In a different script I found the following comment to myself above the isSupported function: 'returns true or false depending on if file is a png. 'Filter' doesn't seem to be working right on macs so this is a double check'. If the filter function isn't working as per the documentation this will definately be a problem for you when using the openDlg version of the method.
var filter;
if (isWindows()) {
filter = ["PNG:*.png"];
}
else {
filter = isSupported;
}
win.btnAdd.onClick = function() {
var f = File.openDialog("Open File", filter, false) ;
if (f == undefined)
return;
if (isSupported(f)) {
files = new Array();
files[0]=f;
win.lstImages.text = f.name;
methodInvoker.EnableControls();
} else {
alert("'" + decodeURI(f.name) + "' is an unsupported file.");
}
};
isSupported = function(file) {
try {
//macs will send a file or a folder through here. we need to respond true to folder to allow users to navigate through their directory structure
if (file instanceof Folder)
return true;
else
return file.name.match(/\.png$/i) != null;
} catch (e) {
alert("Error in isSupported method: " + e);
}
}

How to set the default directory in Komodo from an an extension?

I'm working on a KomodoIDE/KomodoEdit extension that creates a new file and then opens it in a new editing tab using
...
var obsvc = Components.classes["#mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService);
...
Display.initWithPath(Target.path);
Display.append(what);
try {
obsvc.notifyObservers(null, 'open-url', "file://" + Display.path);
} catch (e) {
alert(e);
}
which works, but I would also like it to set Komodo's default directory to the same directory where this file lives, but I don't see a way to do that automatically.
I found the doCommand...
ko.commands.doCommand('cmd_openDirectory')
but this just launches a file dialog that asks the user to pick a directory. I'd like to do something to set it programatically using something like...
obsvc.notifyObservers(null, 'open-directory', "file://" + Display.path);
(which I know doesn't work but is sort of the idea).
I just discovered that the ko.places.manager object has a function to set the default Places window-pane directory. Below is an example of how I used it. The uri should be set to the full directory path and, in the case of Windows, backslashes should get escaped...
function SetPlace(ko, uri) {
try {
ko.places.manager.openDirURI("file:///" + uri.replace(/\\/g, "\\\\") );
} catch(e) {
alert("Could not set place to: " + uri.replace(/\\/g, "\\\\") + "\n" + e);
}
}
The nsIFile interface provides this:
// Get current working directory
var file = Components.classes["#mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("CurProcD", Components.interfaces.nsIFile);
The Komodo preferences service would also be an option:
var gprefs = Components.classes["#activestate.com/koPrefService;1"].
getService(Components.interfaces.koIPrefService).prefs;
gprefs.setStringPref("mruDirectory", "Display.path);
References
How do I get the path of the project folder
Getting Special Files
Komodo JS Macro - insert a relative path from the current editor file
mruDirectory
XPCOM API Reference
Komodo Profile Structure
Where does Komodo Store File Preferences
Getting/Setting a Komodo Preference

Cannot save all of the property settings for this Web Part - Sharepoint

"Cannot save all of the property settings for this Web Part. The
default namespace "http://schemas.microsoft.com/WebPart/v2" is a
reserved namespace for base Web Part properties. Custom Web Part
properties require a unique namespace (specified through an
XmlElementAttribute on the property, or an XmlRootAttribute on the
class)."
No where do I get help regarding this error.
This is when adding custom properties to my webpart, why cant I save the properties when I edit my webpart and click on save/apply? (then I get that error)
Code--
[DefaultProperty("Text"), ToolboxData("<{0}:CustomPropertyWebPart runat=server></{0}:CustomPropertyWebPart>"),
XmlRoot(Namespace = "ExecuteStoreProc")]
public class CustomPropertyWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
const string c_MyStringDefault = "Sample String";
}
// Create a custom category in the property sheet.
[Category("Custom Properties")]
// Assign the default value.
[DefaultValue(c_MyStringDefault)]
// Property is available in both Personalization
// and Customization mode.
[WebPartStorage(Storage.Personal)]
// The caption that appears in the property sheet.
[FriendlyNameAttribute("Custom String")]
// The tool tip that appears when pausing the mouse pointer over
// the friendly name in the property pane.
[Description("Type a string value.")]
// Display the property in the property pane.
[Browsable(true)]
[XmlElement(ElementName = "MyString")]
// The accessor for this property.
public string MyString
{
get
{
return _myString;
}
set
{
_myString = value;
}
}
Can you try going to Site Settings > Galleries > Web Part > New
In that window, put a checkbox next to the webpart you are trying to add, then click Populate
If its populate correctly then it is working otherwise there is some error in the webpart.
Return to your webpage where you want to add the webpart, try to add the webpart by selecting it in the gallery.
If this works (you were able to add it to your page), you can open the webpart added in your webpart gallery (Site Settings > Galleries > Web Part) and compare it to your own .dwp file to see what you did wrong.
Hope this helps

Resources