I'm finishing a nice app with a relatively small text editor. During implementation of the syntax highlight I found myself in need to change foreground colour attribute of recognized tokens. I noticed that there is a property of NSTextStorage:
var fixesAttributesLazily: Bool { get }
The documentation, regarding it is:
A Boolean value indicating whether the text storage object fixes attributes lazily. (read-only)
Discussion
When subclassing, the default value of this property is NO, meaning that your subclass fixes attributes immediately when they are changed. The system’s concrete subclass overrides this property and sets it to YES.
I really don't know how to interpret this ... but this is what I did:
I'm changing the attributes of th recognised tokens inside textStorage(textStorage: NSTextStorage, didProcessEditing editedMask: NSTextStorageEditActions, range editedRange: NSRange, changeInLength delta: Int) (which is a delegate method of NSTextStorage). Here I'm checking the value of this property - it's FALSE.
I subclassed NSTextStorage exactly as Apple suggest (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TextStorageLayer/Tasks/Subclassing.html) and overrode the property. The text view started to behave very strange. Actually with small text it performs OK, but as soon as I open a 4 Mbytes file - it hangs and ... well ... bad things start to happen to my mac. Actually this behaviour doesn't depend on the value of the fixesAttributesLazily property. Maybe my implementation of NSTextStorage is bad or at least not sophisticated.
Any trick of applying attributes in background or lazily or ... something like this is welcomed.
In additional: I know that there are many ways to optimise a syntax highlighted. It may highlight partially, use some kind of logic, based on the changed range ... etc. What I'm looking for is a way to process attribute changes in background. For example currently when I paste 4 Mbyte file to the text view, it first highlights it (which takes 2-3 seconds) and then it visualises it. The effect I'm looking for is the text to appear right away and after time - the colors.
The project I'm working on is written in Swift.
Thanks to everyone in advance for the help. You may reach me via ivailon at gmail dot com for specifics, since I don't want to expose the app here ... at least not yet ;-)
Related
I am on Matlab R2018a. I want to disable FontSmoothing for text legend entries.
Setting the FontSmoothing property default vaue to 'off' for text objects doesn't seem to apply to text objects created by a legend ;
Using the old syntax [lgd,object_h]=legend(...) is horrible under recent releases : for some reason it leads to a drawnow inside the legend call, thus if I then want to edit the relevant properties of some of object_h (here to set their FontSmoothing to 'off'), there will be two draws, leading to a less responsive call and ugly behavior (two screen refreshes instead of just one). Although this behavior makes it unacceptable to me, I can though use these handles to then set their FontSmoothing property to 'off' and it works.
Not using the old syntax but only the new one lgd=legend(...) thus seems to be the only recourse. I seem to be able to find the text objects by accessing lgd.EntryContainer.NodeChildren(1).Label (1 for the first text object, 2 for the second one, etc). Problem is, property setting seems iffy at best :
set(lgd.EntryContainer.NodeChildren(1).Label,'FontSmoothing','off') doesn't change anything.
set(lgd.EntryContainer.NodeChildren(1).Label,'FontSize',somevalue) doesn't change anything either.
set(lgd.EntryContainer.NodeChildren(1).Label,'String','sometext') does work though.
Anyone have any idea how to proceed ?
I'm currently learning MATLAB's GUIDE gui programming. I notice that when I place some objects in a figure, a corresponding 'CreateFcn' callback function is creating in the associated .m file. MATLAB's comments state that this function is executed when the object is created (I would consider this a constructor for the object).
However, I've noticed that not all objects seem to have this 'CreateFcn' constructor. Static text objects do not appear to have this callback function. And as of currently, it seems like this function just makes the code more difficult to read. Thus I'm curious if I can delete.
By deleting it, I tend to get an error in my code stating that the function can't be found. So my question: is it possible to delete the 'CreateFcn' method to declutter my code?
Thanks,
Surely it is possible.
Double-click the object to open up the inspector window, locate the "CreateFcn" property and set its value to an empty string. Then go to the .m file and remove the code of CreateFcn. This way MATLAB wouldn't complain about the missing CreateFcn anymore.
CreateFcn is not really a constructor per se, since it happens after all properties of the object are already set. It is more like an optional post-constructor event that gives user an opportunity to further customize the object's initial behavior dynamically. For example, you can customize the object's color at creation depending on the background color on which the object appears. For most control objects, the default behavior is probably already good enough for you. So you can safely remove those CreateFcns until you find a good excuse to use one.
1) Goto the View --> Property Inspector
2) expand the Creation and deletion control, remove the text from CreateFcn and DeleteFcn 3) close the property inspector save the respective GUI (Don't forget to save)
4) remove the callbacks in m-script.
I use (current-window-configuration) to save the size, layout etc of windows, and (set-window-configuration ...) to restore them, so that I can toggle between several window setups. However (current-window-configuration) also saves the current point in buffers, and I would like to only save the window sizes and which buffers they hold. I have tried two different ways to make this happen:
According to the function help of current-window-configuration, the variable window-persistent-parameters controls whats get saved. So now I only need a list of the available window-parameters. But when I look at this variable it's value is ((clone-of . t)), and I can't find a list of the available window parameters online.
I also tried looking at the object returned by current-window-configuration. It is a window configuration object, and gets printed as #<window-configuration>. Is there a way to get into this object, see whats inside and change stuff?
The parameters for window-persistent-parameters may be found in this manual page, though it does not seem to help with your question. A different set of parameters may be found by running (window-state-get nil).
The functions that deal with objects returned by (current-window-configuration) are listed here, but it also mentions:
Other primitives to look inside of window configurations would make sense, but are not implemented because we did not need them. See the file winner.el for some more operations on windows configurations.
At any rate, all these look like really low level stuff, so you might be better off just using winner.el rather than a custom made solution.
In a UITextField used for entering decimal numbers I would like to get rid of possible leading zeros (The behavior should be like the one of the Calculator App). Normally this would be rather easy to implement but I just cannot figure out how to restore the cursor position.
UITextField has a property SelectedTextRange of type UITextRange which can be used to get the cursor position. However, there seems no easy way to get the current index nor to create a new UITextRange object that contains the new values.
I could find the solution in objective c: Finding the cursor position in a UITextField
It is however very unclear to me how to rewrite that in Monotouch. Any help with this would be highly appreciated.
Thanks,
Manuel
It looks like MonoTouch (at least the 5.3 alpha I'm looking now) is not exposing every methods in UITextField (and UITextView), in particular those that comes from UITextInput (but the properties are there).
This means that methods like GetPosition are presently missing - which makes it hard to duplicate the code from the link you provided.
UPDATE It was a bug where UITextInput methods were not added to UITextField and UITextView. This will be fixed in the next releases. IOW the next stable release, 5.2.11, will have the missing methods.
The code is:
DropTarget target = new DropTarget(sqlViewer.getTextWidget(),
DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK);
Transfer[] types = new Transfer[] {TreeLeafListTransfer.getInstance(),
TextTransfer.getInstance(), FileTransfer.getInstance()};
target.setTransfer(types);
target.addDropListener(new DropTreeLeafAdapter(sqlViewer));
And it works normally for a view, but fails in an editor. What's the difference?
upd: Whtat is most strange - if I surround it with a try/catch block, it still fails without exception.
edit: The problem is bigger than just DnD not working. The whole editor fails to instantiate because of this block. Just an empty window appears.
it works normally for a view, but fails in an editor. What's the difference?
The difference should be in the transfert type:
To recap, transfer types allow drag sources to specify what kinds of object they allow to be dragged out of their widget, and they allow drop targets to specify what kinds of objects they are willing to receive.
For each transfer type, there is a subclass of org.eclipse.swt.dnd.Transfer. These subclasses implement the marshaling behavior that converts between objects and bytes, allowing drag and drop transfers between applications.
May be the list of Transfer type you are using is not quite compatible with the target (an Editor)? See this thread for more test around that.
Another item to consider is the proper setup of a TransferDropTargetListener (like in this thread).
Since I have not yet fully tested eclipse DnD, I cannot give you much more details on this topic, but hopefully that will give you something to start your own analysis.