Is there any way to reindent lines in Swift Playgrounds 4? - swiftui

Been playing around writing SwiftUI apps on Swift Playgrounds 4 and it automatically indents lines properly as you write them, but I don’t see a method for reindenting all the lines in a selection or in a file.
Obviously when you’re writing SwiftUI you often embed or un-embed elements in stacks, navigation views, and other blocks so reindenting is a frequent need to keep code readable.
Seems you have to delete and reinsert a line break on each line to automatically reindent the lines or manually insert a tab on each line one at a time. You can’t even select several lines at once at press tab to indent them all at once, it just overwrites the selection with the tab.
Is there really no quick way to reindent lines in Swift Playgrounds 4?

Ohh if you hold down the ⌘ cmd key it shows all the keyboard shortcuts.
Re-indenting is ^ control + I
Not sure how you’d do this if you didn’t happen to have a hardware keyboard though…

Related

How to get spaces instead of tabs in eclipse

After doing a little research, I found out that eclipse hides its settings in multiple levels. So, I think, I got all the levels covered here.
Here I have set eclipse to insert spaces instead of tabs. And eclipse even acknowledges there that I have indeed set it up to insert 4 spaces instead of a tab (See the text under Tabulators: it says, "The current indentation size is 4, using spaces").
Then for the general text editor, I have also set it up to insert spaces instead of the tabs.
And eclipse couldn't have gotten things more wrong even if it had tried!
Unfortunately, despite all those settings, when I press tab, eclipse inserts 2 spaces. Then, I press tab again, and it inserts 2 spaces. Why 2 spaces? Are there still more hidden settings somewhere?
Anyways, this broken system works a bit, until I have one level more of indentation, for example, for a for-loop or an if-block. If I press, tab again, instead of adding 2 more spaces, it converts the 6 spaces into a tab.
And a tab which is not even 4 spaces wide, but instead a tab which looks like a 6- or 8-spaces wide tab.
Ctrl + I also adds tabs, not spaces.
The formatter is also setup as #Neuron suggested in his answer.
So, where else is eclipse hiding more settings?
I fixed it by going to..
Window ⟶ Preferences ⟶ C/C++ ⟶ Code Style ⟶ Formatter
There you need to edit the currently set profile. Click "Edit..." (top right-ish). Now go to Indentation (already open) ⟶ General Settings ⟶ Tab Policy and change this from "Tabs only" to "Spaces only".
If you still have the default profile, give your profile a new name.
Why is this so weird and convoluted? I don't know.

Command pattern for undo/redo: when to NOT merge undo commands?

I'm implementing an undo/redo feature in our graphical Qt5-based app, using QUndoCommands which have a nice mergeWith() feature: for example, if the user repeatedly clicks the font size increase button on my app, rather than creating a ton of commands in the undo list, it just updates one command on the QUndoStack. So a single undo will go back to the original font size.
That's great, but there are times I don't want to automatically merge commands. For example, if I drag an item to a new location and drop it there, then drag the same item to another location: my app should create 2 move commands, not merge them both into one command.
So, here's a list of events that I think create a logical break, where the user will expect a command NOT to be merged with the next command, even if the next command changes the same property of the same object:
mouse release
widget lose focus
timer (after ??? seconds)
text typing, after ??? characters (or this can be handled with the timer?)
text typing, after certain keys are pressed, such as backspace?
As indicated by the question marks in my list, I'm not really sure in what situations to suppress merging commands. So my question is, are there any best practices in this regard? Where can I find them?
FWIW, I did not find any best practices, but for my software I suppressed merges on focus change (which in my app also occurs on mouse release on the graphics part). Additionally, for typing, I suppress merges if the input position changes in a way other that as expected for deleting or typing 1 character, and if the user switches between deleting characters and typing characters.
I did not bother with the timer, or with maximum characters when typing.

Two column TPopupMenu to list shortcuts right aligned

Using Borland/CodeGear/Ebarcadero C++ Builder 2009. Is it possible to show shortcuts (or other text), right aligned in a second column in a TPopupMenu ?
For instance:
[image] Open File ctrl-O
[image] Close File ctrl-W
[image] BlahBlah ctrl-B
etc.
If so, how ?
I checked the break property on an item, but the results is not exactly what I want, since items are selectable on their own, instead of the complete line. Also it's not drawn that nicely.
Your feedback appreciated.
A menu item can have an image (see the TMenuItem.ImageIndex property), and can have a shortcut assigned (see the TMenuItem.ShortCut property). The VCL will automatically draw those elements for you, exactly as you have shown.
By default, they are a little squished together. You can use the TMenuItem.OnMeasureItem event to extend the Width:
If you still do not like the way the default drawing looks, or you want different text than the ShortCut to appear on the right side, you will have to owner-draw the menu items yourself (see the TMenuItem.OnDrawItem and TMenuItem.OnAdvancedDrawItem events), then you can make the menu items appear however you want.

Display tooltip for a selected word

I'm writing a simple text editor using Python 2.7, pyqt library. I basically want to display the meaning of a word when the user selects the word in the text editor.
So far I can detect the word under the cursor, look it up in my dictionary and return the meaning (using a print statement) so I know I can get the guts to work.
My trouble is displaying the meaning of the word in a tooltip that doesn't dissapear in less than 2 miliseconds. So far I have been using this:
QtGui.QToolTip.showText(QtGui.QCursor.pos(), tool_tip_text)
Ideally want to show the meaning just over where the selection was made, so far this displays the tooltip so quickly that I can't even read the meaning of the word under the cursor. It just pops up and dissapears almost immediately. Can anyone share how to make the tooltip remain visible for at least 5 seconds, or until the user de-selects the word.
I am not using the QHELPEVENT (not even quite sure how the helpevent is triggered) I am just calling my lookup_word_in_dictionary() function when a word has been selected.
Any samples are much appreciated.
Thanks, I found a solution, creating my own popup class, subclassed from QWidget
and used a simple timer to hide the tooltip
QTimer.singleShot(5000, self.hide_tooltip) #check to see if the tooltip shold be hidden after 5 secs
you can replace QToolTip by QSplashScreen,if you are Chinese ,please look at this post .
BTW , can you share the method that you detect the word under the cursor with me ?

Qt - Display several, selectable lines

Im writing a tool that simulates Turing machines.
Here, Ive got a transition table of a such a machine
When a cell is double-clicked, a little dialog pops up (which is a custom widget, derived from QFrame) and should allow editing the contens of a cell. A cell may contain several rules (those |q2, 3, R| and such) and I want that little dialog to show these. The thing is that a user should be able to add and remove rules. At first, I wanted to use QLabels for that, which is fine with the adding aspect, but how do I remove existing rules? I planned having the user select the rules and click "Remove" but do I make sure the entire rule (QLabel) is selected?
Or should I take a completely ddifferennt approach to removing? Like letting every label have an own checkbox?
I would like to keep it as simple as possible. For example, QTableWidget is too "fat" for this, I feel like
You should use a QListWidget - this will allow multiple lines, multiple selection, without the cells or horizontal/vertical headers.
http://qt-project.org/doc/qt-4.8/qlistwidget.html