Is there a html helper that can crop text (say, for an actionlink) so that it fits into a table column without wrapping? I remember reading about a helper that crops and then adds ... to the end, but cannot find it again. Otherwise, I will just make my own helper.
No there isn't. There is an example of one in the ASP.NET MVC Music Store tutorials which is where you may have seen it.
Copied from the tutorial:
public static stringTruncate(this HtmlHelperhelper,string input,int length)
{
if(input.Length <= length)
{
returninput;
}
else
{
returninput.Substring(0, length) +"...";
}
}
Related
Xcode 10.1, Swift 4.2, macOS 10.14.2
I am trying to make a simple to do list app for macOS where there are a series of NSTableView rows and inside each one is an NSTextField. Each field is a to-do item. I want the NSTableView rows to expand to fit the size of the text within each NSTextField.
I have all of the following working:
Setting the text in the NSTextField makes the NSTableView row expand as needed. Auto layout constraints are set in my storyboard.
Using tableView.reloadData(forRowIndexes: ..., columnIndexes: ...) sets the text and resizes the table row correctly.
But doing tableView.reloadData() always resets every NSTextField to a single line of text as shown here:
Interestingly, if you click into the NSTextField after reloading the whole table, the field resizes to fit its content again:
I believe I have set all the appropriate auto layout constraints on my NSTextField and I'm using a custom subclass for it as well (from a helpful answer here):
class FancyField: NSTextField{
override var intrinsicContentSize: NSSize {
// Guard the cell exists and wraps
guard let cell = self.cell, cell.wraps else {return super.intrinsicContentSize}
// Use intrinsic width to jibe with autolayout
let width = super.intrinsicContentSize.width
// Set the frame height to a reasonable number
self.frame.size.height = 150.0
// Calcuate height
let height = cell.cellSize(forBounds: self.frame).height
return NSMakeSize(width, height)
}
override func textDidChange(_ notification: Notification) {
super.textDidChange(notification)
super.invalidateIntrinsicContentSize()
}
}
⭐️Here is a sample project: https://d.pr/f/90CTEh
I'm at a loss as to what else I can try. Any ideas?
I think there is some basic problems with the constraints in interface builder. Resizing the window makes everything wonky. Also you should call validateEditing() in the textDidChange(forBounds:) in your FancyField class.
I created a sample project, that does what you want on Github
Write a comment if you have any problems with it.
Thinking a little about it, thought i would add the meat of the code here. Only thing that really needs to work, is the update on the NSTextField when the "Tasks" is being updated. Following is the code required for the NSTextField.
public class DynamicTextField: NSTextField {
public override var intrinsicContentSize: NSSize {
if cell!.wraps {
let fictionalBounds = NSRect(x: bounds.minX, y: bounds.minY, width: bounds.width, height: CGFloat.greatestFiniteMagnitude)
return cell!.cellSize(forBounds: fictionalBounds)
} else {
return super.intrinsicContentSize
}
}
public override func textDidChange(_ notification: Notification) {
super.textDidChange(notification)
if cell!.wraps {
validatingEditing()
invalidateIntrinsicContentSize()
}
}
}
Hope it helps.
I'm building a game where the hero is build with a MovieClip that has nested Movieclips. The nested MovieClips are the moves of the hero which are in different frames. Additionally, there are some MovieClips that are two levels nested.
Now here is the code of what I'm doing:
public function movesCollisions(event:Event):void{
for (var ea:int = 0; ea < enemies.length; ea++){
//parent .child .sibling
if(sketch.slidepunch.sketchfist.hitTestObject(enemies[ea])){
enemies[ea].animstate = "defeated";
//Here this first collision works fine but the next
//collsion below does not, I have no Idea why.
}else if(sketch.archforward.rhandHit.hitTestObject(enemies[ea])){
enemies[ea].animstate = "defeated";
}
}
}
The problem that I'm having is that the hitTestObject does not work when I have the else if conditional. The first one works if I comment out the else statement. How can I fix this issue since I have many more moves that I need to check for collision.
They only way that I have manage to get the moves collision to work has been by creating a different Event.ENTER_FRAME, function for each but it has a big effect on performance.
any guidance is greatly appreciated.
I am new in N2 CMS and i am stuck in dynamic content like add n time item.
This is an example
This object consists of:
WYSIWYG / Richtext Editor (This will be [EditableFreeTextAreaAttribute])
**n-times item**
caption [EditableText]
image [FileAttachment]
My question is, How I can make it N times where i have 1 RTE and n time Caption and image. Currently i am stuck on it. Please suggest me how I can comeup with this.
Thanks.
Take a look at the EditableChildren attribute. Basically you define a content item for the child item - eg. image and caption.
Then your main ContentItem has a rich text editor and a collection of the child content item.
Example:
namespace N2.Templates.Items
{
[PageDefinition("FAQ",
Description = "A list of frequently asked questions with answers.",
SortOrder = 200,
IconUrl = "~/Templates/UI/Img/help.png")]
[AvailableZone("Questions", "Questions")]
[RestrictParents(typeof(IStructuralPage))]
[ConventionTemplate]
public class FaqList : AbstractContentPage, IStructuralPage
{
[N2.Details.EditableChildren("Questions", "Questions", 110, ContainerName=Tabs.Content)]
public virtual IList<Faq> Questions
{
get { return GetChildren<Faq>("Questions"); }
}
}
}
https://github.com/n2cms/n2cms/blob/6b8698468b61cff0ee1825644b05b63d011bf7e8/src/WebForms/WebFormsTemplates/Templates/Items/FaqList.cs
I'm new to vaadin. I came across with a bug that full name is not visible in twin-column component's values. I have very long names inside the left side of the twin-column. I increased the width of the component much as I can. But still some lines are there that not visible full name.
I tried to add some css, even that didn't work.
.v-select-twincol-options .v-select-twincol-break-word{word-wrap: break-word;}
I tried with this css line. Any wrong in here? Or any idea to solve this. Please help me on this..
Thank you in advance.
private TwinColSelect createTemplateSelectTwinColumn()
{
TwinColSelect twinColSelect = new TwinColSelect("Related Templates");
twinColSelect.setNullSelectionAllowed(true);
twinColSelect.setMultiSelect(true);
twinColSelect.setImmediate(true);
twinColSelect.setSizeFull();
Collection<File> templates = getTemplates();
Collections.sort((List<File>) templates, new Comparator<File>()
{
#Override
public int compare(final File f1, final File f2)
{
return f1.getName().compareTo(f2.getName());
}
});
for (File file : templates)
{
twinColSelect.addItem(file.getNodeId());
twinColSelect.setItemCaption(file.getNodeId(), file.getName());
}
return twinColSelect;
}
Method where I'm creating the twinColumn inside a FormLayout
Vaadin's TwinColSelect eventually results in two standard HTML option list controls in the DOM; see the DOM of this example: http://demo.vaadin.com/book-examples/book/#component.select.twincolselect.basic
word-wrap is, however, not possible on option list items.
Consider creating your "own" TwinColSelect from two Vaadin tables. Vaadin tables are much more flexible regarding CSS styling.
I have two QDockWidget's, only one of them is visible at the time, I manage that by toggleViewAction().
What I need to do is that I want the two QDockWidget's to be in the same location, with the same size and docked at the same dockWidgetArea with the same orientation and order relative to other QDockWidgets.
I did most of the that by this code:
void myMainWindow::slotToggleDocks(QAction* action) {
if(action == viewDock1) {
Dock1->setFloating(Dock2->isFloating());
Dock1->resize(Dock2->size());
Dock1->restoreGeometry(Dock2->saveGeometry());
Dock1->move(Dock2->pos());
addDockWidget(dockWidgetArea(Dock2), Dock1);
...
Dock2->hide();
} else if(action == viewDock2) {
Dock2->setFloating(Dock1->isFloating());
Dock2->resize(Dock1->size());
Dock2->restoreGeometry(Dock1->saveGeometry());
Dock2->move(Dock1->pos());
addDockWidget(dockWidgetArea(Dock2), Dock1);
...
Dock1->hide();
}
}
this code make the two have the same location and size and docked to the same area (left, right, ...) but it doesn't guarantee that the Docks will have the same layout with the other QDockWidget's in the same dockWidgetArea.
Meaning if this was the before layout:
Layout before http://holmez.net/qdockwidget/1.png
This is after toggling:
Layout after toggling http://holmez.net/qdockwidget/2.png
This is what I want:
Expected result http://holmez.net/qdockwidget/3.png
I managed to do that by a simple trick, add this line of code:
splitDockWidget(Dock1,Dock2,Qt::Horizontal);
before hiding Dock1, and this line:
splitDockWidget(Dock2,Dock1,Qt::Horizontal);
before hiding Dock2.
This fixed the problem of the arrangement of docked widgets, not sure if this is the best way but it works for me.
What about only using 2 QDockWidgets, but having QStackedWidgets INSIDE of them which you can use to swap views? That's what I'm currently doing, and it works great.
Another advantage is that swapping views is as simple as:
stackedWidget->setCurrentIndex(index);
What about using QTabWidget?
The 2 widgets will have to be in the same Qt::DockWidgetAreas