Line comment format in Visual Studio Code - visual-studio-code

Is there a way to remove the space inserted after the line comment character(s), and to start the comment at the start of the line in Visual Studio Code? (thus being able to use the commented-out-code comment style)
Before:
void fn() {
code();
}
After (applying Toggle Line Comment command):
void fn() {
// code();
}
Desired:
void fn() {
// code();
}
I would prefer either a global switch or a per language configuration.
E.g. in Sublime Text 3 you can achieve this by copying the Comments.tmPreferences file from the package of a given language to into the user packages, and changing the value of the TM_COMMENT_START and TM_COMMENT_DISABLE_INDENT settings shell variables. E.g. the original Groovy.sublime-package\Comments.tmPreferences:
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>name</key>
<string>Comments</string>
<key>scope</key>
<string>source.groovy</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
<array>
<dict>
<key>name</key>
<string>TM_COMMENT_START</string>
<key>value</key>
<string>// </string>
</dict>
...
On the other hand in Visual Studio Code in the language-configuration.json file of a given language the comments.lineComment values already lack the extra space, so they are inserted somewhere else. E.g. the original groovy\language-configuration.json:
{
"comments": {
"lineComment": "//",
"blockComment": [ "/*", "*/" ]
},
...

Related

Flutter Desktop MacOS: how to open a file from Finder with Flutter app

I've written a Flutter Desktop MacOS application that uses a command line argument to process a file:
void main(List<String> args) async {
if (args.isNotEmpty) {
runApp(MyApp(args.first))
} else ...;
}
which works as expected when I run it from the shell:
# this command is ok:
/Applications/TommyView.app/Contents/MacOS/TommyView Pictures/hey.png
But when I assign this app to all *.png images, and want to run it from Finder, it shows:
(or sometimes another error depending on Info.plist: TommyView cannot open files in the “PNG image” format.)
Also I noticed that the execution goes to "else" case (i.e. args are empty).
I guess some magic is missing in Info.plist. Please help to figure out.
You need to declare file types that your application handles using CFBundleDocumentTypes in your Info.plist.
More importantly though, command line arguments aren't how your application will receive files to open on macOS, so that Dart code won't work. To handle files you would need to implement application(_:openFile:) (which can be called at any time, not just at launch) in your macOS Runner, and then pass the files to Dart using platform channels.
Thanks, #smorgan, for your response. Let me improve your answer by adding a piece of code for other Flutter developers:
In MainFlutterWindow.swift add the following:
class MainFlutterWindow: NSWindow {
open var currentFile: String? // add this variable
override func awakeFromNib() {
...
// interop with Flutter
let channel = FlutterMethodChannel(name: "myChannel", binaryMessenger: flutterViewController.engine.binaryMessenger)
channel.setMethodCallHandler({
(call: FlutterMethodCall, result: FlutterResult) -> Void in
if (call.method == "getCurrentFile") {
result(self.currentFile)
} else {
result(FlutterMethodNotImplemented)
}
})
...
}
}
in AppDelegate.swift you need to handle openFile:
#NSApplicationMain
class AppDelegate: FlutterAppDelegate {
...
// called when a user double-clicks on a file in Finder
override func application(_ sender: NSApplication, openFile filename: String) -> Bool {
(mainFlutterWindow as! MainFlutterWindow).currentFile = filename
return true
}
}
now in your main.dart:
void main(List<String> args) async {
WidgetsFlutterBinding.ensureInitialized();
final startFile = await getStartFile(args);
runApp(MyApp(startFile));
}
Future<String> getStartFile(List<String> args) async {
if (args.isNotEmpty) return args.first;
if (Platform.isMacOS) {
// in MacOS, we need to make a call to Swift native code to check if a file has been opened with our App
const hostApi = MethodChannel("myChannel");
final String? currentFile = await hostApi.invokeMethod("getCurrentFile");
if (currentFile != null) return currentFile;
}
return "";
}
[Optional] add file extensions to Info.plist to make it "visible" in MacOS recommended apps:
<dict>
...
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>jpg</string>
<string>jpeg</string>
<string>png</string>
<string>gif</string>
<string>webp</string>
<string>bmp</string>
<string>wbmp</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
I hope it will help.

flutter_inappwebview - no html-video

I'm using flutter_inappwebview in a Flutter-app to display local html (from assets). (I know: not ideal. I would prefer to program the whole thing in Dart, but that is not an option right now). It works great..apart from one thing. Can't get the video in html to work.
Problem
The video works fine when I open the html in any browser (directly from assets folder). So the html should be ok. All other html works fine in the app. So files and pubspec-import should be ok. In the app, the page shows a video-player, but no content on both iOS-sim and iOS device. In the Android-sim it works.
Code
I'm using:
flutter_inappwebview: ^3.2.0
sdk: ">=2.7.0 <3.0.0"
I use the inappview like this, after the imports. Server is already running (flutter reports: flutter: Server running on http://localhost:8080)
InAppWebViewController webViewController;
InAppWebView webView;
class OfflineViewer extends StatefulWidget {
#override
_ViewerState createState() => _ViewerState();
}
class _ViewerState extends State<OfflineViewer> {
#override
Widget build(BuildContext context) {
return InAppWebView(
initialUrl: "http://localhost:8080/assets/source/intro.html",
onWebViewCreated: (InAppWebViewController controller) {
webViewController = controller;
},
);
}
}
The video-tag in the loaded intro.html is:
<video height="600" controls>
<source src="intro.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
Things I tried:
Different video-formats (webm, ogg) > no difference.
Loading an online video into the html instead of local > works. Video loads and plays.
Different methods of embedding video (video-tag, iframe, video.js) > no difference.
Setting InAppWebViewOptions, like:
cacheEnabled: true,
javaScriptCanOpenWindowsAutomatically: true,
useOnLoadResource: true,
javaScriptEnabled: true,
mediaPlaybackRequiresUserGesture: false,
What makes this hard to solve (for me) is that I can't catch the html-errors once it's embedded in the app, whereas the standalone html doesn't give an error. Any ideas on how to solve or even troubleshoot this are highly appreciated.
Greetings,
Mark
Got it sorted. Just posting this in case anyone else has the same problem. Cause of the problem was: the HTTPServer-class creates a blob-server. It returns a video in one chunk (status 200). iOS doesn't accept that and wants status 206 (parts).
Based on https://stackoverflow.com/a/54004600/6007404 I created a JS-file which converts all the video's in the document. Just add it to any html-file with video:
if(navigator.platform && /iPad|iPhone|iPod|Mac/.test(navigator.platform)){
window.addEventListener("load", streamVideoBlobs);
}
function streamVideoBlobs(){
var allVideos = document.getElementsByTagName("video");
for(var i = 0, max = allVideos.length; i < max; i++)
{
iOSVideoConvert(allVideos[i]);
}
}
async function iOSVideoConvert(video){
let blob = await fetch(video.src).then(r => r.blob());
var videoUrl=createObjectURL(blob);
video.src = videoUrl;
}
function createObjectURL(object) {
return (window.URL) ? window.URL.createObjectURL(object) : window.webkitURL.createObjectURL(object);
}
Apart from that, you'll have to set
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
in your info.plist. (You can also use NSAllowsArbitraryLoads, but that's more allowance then needed and Apple might flag it down when submitting the app).
Not sure but you may be missing the NSAppTransportSecurity setting in your Info.plist. This allows you to load unsafe content which http://localhost:8080 is.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
https://stackoverflow.com/a/61999847/15258962
this make me realized ,the problem is not the WebView, its the LocalServer side.
I change the localServer logic to serve basic64 encoded video source when a video tag appeared ,and its worked for me

Eclipse Editor Plugin: Textmarker overwrites style information in the editor

Im trying to create a lightweight C++ Editor with the help of libclang.
I use a new problemmarker type to mark the compiler warnings and errors given by clang and the token ranges to do syntax coloring.
As you can see in the picture above, the squiggly lines of the error markers overwrite the syntax coloring. Is there a PresentationReconciler that takes into account that some marked lines could still have other style information?
I added some code snippets that might be relevant to solve the problem:
my plugin.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.editors">
<editor
name="CXX Editor"
extensions="cpp"
icon="icons/sample.gif"
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
class="cppeditor.editors.CppEditor"
id="cppeditor.editors.CppEditor">
</editor>
</extension>
<extension
id="cppeditor.problemmarker"
name="clang Error"
point="org.eclipse.core.resources.markers">
<super
type="org.eclipse.core.resources.problemmarker">
</super>
<super
type="org.eclipse.core.resources.textmarker">
</super>
<persistent
value="true">
</persistent>
</extension>
</plugin>
The method to add markers to the IFile resource:
public void addMarkerToFile(IFile file, IDocument fileDocument) throws CoreException, BadLocationException{
IMarker marker = file.createMarker("cppeditor.problemmarker");
marker.setAttribute(IMarker.SEVERITY, this.severity);
marker.setAttribute(IMarker.MESSAGE, this.message);
marker.setAttribute(IMarker.LINE_NUMBER, this.line);
int startOffset = fileDocument.getLineOffset(this.line-1);
int endOffset = fileDocument.getNumberOfLines() > this.line ?
fileDocument.getLineOffset(this.line) : fileDocument.getLength()-1;
marker.setAttribute(IMarker.CHAR_START, startOffset);
marker.setAttribute(IMarker.CHAR_END, endOffset);
}
The "createPresentation" method of the PresentationRepairer
#Override
public void createPresentation(TextPresentation presentation, ITypedRegion region) {
CppDocument doc = (CppDocument) this.fDocument;
Token[] newTokens = doc.getTokens();
if(newTokens != oldTokens){
for(Token t : newTokens){
addRange(
presentation,
t.getStart(),
t.getEnd() - t.getStart(),
attributeMap.get(t.getKind()));
}
oldTokens = newTokens;
}
}
note: I already asked this question in the eclipse forums but nobody answered it... (see here)
I found the answer myself. After adding markers to the file, the "createPresentation" method is called again, this time because the marker region was invalidated.
This is why the if(newTokens != oldTokens) broke the syntax highlighting at the invalidated areas. I removed the if to fix the problem.

Xamarin: Issue with latest FB API

Latest FB login API has three parameters
public unsafe virtual void LogInWithReadPermissions (string[] permissions, UIViewController fromViewController, [BlockProxy (typeof(Trampolines.NIDLoginManagerRequestTokenHandler))] LoginManagerRequestTokenHandler handler)
I am using MVVMCross. For fb login, I tried created an instance of the view i am in, and pass it as a parameter for LogInWithReadPermissions()
VIEWMODEL:
private async void DoFacebookSignIn()
{
try
{
await facebookService. Login();
DoAutoLogin();
}
}
SERVICE:
private readonly string[] permitions = new string[] { "email", "public_profile" };
public async System.Threading.Tasks.Task LogIn()
{
LoginManager.LogInWithReadPermissionsAsync (permitions);
LoginManagerLoginResult result = await LogInWithReadPermissionsAsync();
if (result.IsCancelled)
{
ServiceFactory.UserMessageService.ShowToast("Facebook login is canceled");
}
}
private Task<LoginManagerLoginResult> LogInWithReadPermissionsAsync()
{
var tcs = new TaskCompletionSource<LoginManagerLoginResult> ();
LoginManager.LogInWithReadPermissions (permitions,null, (LoginManagerLoginResult result, NSError error) =>
{
if(error.IsNotNull ())
{
tcs.SetException (new IosErrorException(error));
} else
{
tcs.SetResult (result);
}
});
return tcs.Task;
}
But its failing, Do i need to pass view info from Viewmodel, when I am calling this func? How to pass view instance from view model ? Can anyone help?
UPDATE
It's failing at the service:
func LogInWithReadPermissionsAsync()
line3: (LoginManager.LogInWithReadPermissions...)
without giving any error. Its just crashing.
The Facebook API version: "Xamarin.Facebook.iOS" version="4.13.1"
UPDATE
Removed unused code.
I got the solution.
The code was fine I just needed to 'Whitelist Facebook Servers for Network Requests' by adding
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
If you're recompiling with iOS SDK 9.0, add the following to your application's plist if you're using a version of the SDK v4.5 or older:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbauth</string>
<string>fbauth2</string>
<string>fb-messenger-api20140430</string>
</array>
If you're using Facebook.MessengerShareKit from versions older than the v4.6 release, also add:
<string>fb-messenger-platform-20150128</string>
<string>fb-messenger-platform-20150218</string>
<string>fb-messenger-platform-20150305</string>
If you're using v4.6.0 of the SDK, you only need to add:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
As mentioned in Xamarin Facebook iOS SDK here.

OS X, Why is Help NSMenuItem in NSMenu disabled after registering the Help Book?

OS X, Why is Help NSMenuItem in mainMenu disabled after registering the Help Book
Tags: OSX, HelpBook, NSMenuItem, AHRegisterHelpBookWithURL
The HelpBook is unusable because the Help menu is disabled.
When the Help Menu is selected, the Help sub menu appears this way:
Spotlight Search searchBar here - BLUE
HungryMe Help - GREYED OUT
The MainWindow.nib contains the Menu. The Help Menu Item is enabled in Xcode.
THE HELP BOOK
The HelpBook Info.plist follows;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en_US</string>
<key>CFBundleIdentifier</key>
<string>com.DrummingGrouse.HungryMe.help</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>HungryMe</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>hbwr</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>HPDBookAccessPath</key>
<string></string>
<key>HPDBookIconPath</key>
<string>shrd/EyeOnly.png</string>
<key>HPDBookIndexPath</key>
<string></string>
<key>HPDBookKBProduct</key>
<string></string>
<key>HPDBookKBURL</key>
<string></string>
<key>HPDBookRemoteURL</key>
<string></string>
<key>HPDBookTitle</key>
<string>HungryMe Help</string>
<key>HPDBookType</key>
<string>3</string>
</dict>
</plist>
The test Title Page, HungryMe.html, follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" AppleTitle="com.DrummingGrouse.HungryMe.help" />
<title>HungryMe</title>
</head>
<body>
<a name="hungryme_page"></a>
<div class="container">
<p>This is some text. <img src="../shrd/EyeOnly.png" align="middle"> This is some more text.</p>
<div class="content">
<h1>Getting Started - Cooking with HungryMe</h1>
<p>HungryMe has a main window with Category elements on the left and Recipe elements on the right.</p>
<p>The display of a recipe's details is done as follows:</p>
<p> 1. Select a recipe Category in the left table of the main window. Select "Browse All" if you wish to have all recipes to be listed.</p>
<p>2. Double click the desired recipe and a separate window will appear displaying the details for the selected recipe. Multiple recipes can be displayed simultaneously.</p>
<!-- end .content --></div>
<!-- end .container --></div>
</body>
</html>
The App's Info.plist has:
CFBundleHelpBookFolder HungryMe.help
CFBundleHelpBookName com.DrummingGrouse.HungryMe.help
The Apple Help Programming Guide has:
The CFBundleHelpBookName key identifies the help book. The value associated with this key
should be a string specifying the help book title, as defined by the AppleTitle tag in the
title page of the book. For example, here is how you would enter the title
of the SurfWriter Help book:
<key>CFBundleHelpBookName</key>
<string>com.mycompany.surfwriter.help</string>
The Help Book bundle, HungryMe.help, is added to the Xcode project's Resources/ folder.
The Bundle is structured this way:
HungryMe.help/
Contents/
Info.plist
Resources/
shrd/ <shared artwork>
English.lproj/
HungryMe.html <title page>
pgs/ <the rest of the content pages>
gfx/ <localized artwork>
sty/ <style sheets, generated list template>
scrpt/ <scripts>
The Help Menu Item that would display the HelpBook is greyed out whether or not the
Help Book is registered using AHRegisterHelpBookWithURL.
If AHRegisterHelpBookWithURL is used, the err returned in code below is Zero.
OSStatus RegisterMyHelpBook(void)
{
CFBundleRef myApplicationBundle;
CFURLRef myBundleURL;
OSStatus err = noErr;
myApplicationBundle = NULL;
myBundleURL = NULL;
myApplicationBundle = CFBundleGetMainBundle();// 1
if (myApplicationBundle == NULL) {err = fnfErr; return err;}
myBundleURL = CFBundleCopyBundleURL(myApplicationBundle);// 2
if (myBundleURL == NULL) {err = fnfErr; return err;}
if (err == noErr){
err = AHRegisterHelpBookWithURL(myBundleURL);// 3
}
return err;
}
The following code, executed at launch time,
NSMenu *mainMenu = [[NSApplication sharedApplication] mainMenu];
NSMenuItem *menuItemHelp = [mainMenu itemWithTitle:#"Help"];
NSMenu *menuHelp = [menuItemHelp submenu];
NSMenuItem *menuItemHelpHungryMe = [menuHelp itemAtIndex:0];
DLog(#"menuItemHelpHungryMe=%#",menuItemHelpHungryMe);
DLog(#"menuHelp=%#",menuHelp);
Produces the following output.
2012-11-16 11:30:03.167 HungryMe[62153:303] -[AppDelegate applicationDidFinishLaunching:]
menuItemHelpHungryMe=<NSMenuItem: 0x1b6e3c0 HungryMe Help>
2012-11-16 11:30:03.168 HungryMe[62153:303] -[AppDelegate applicationDidFinishLaunching:]
menuHelp=<NSMenu: 0x1b6e3a0>
Title: Help
Supermenu: 0x1b6c8e0 (MainMenu), autoenable: YES
Items: (
"<NSMenuItem: 0x1b6e3c0 HungryMe Help>"
)
I observed that menuHelp above has only one item.
The Help Menu Item titled "HungryMe Help" is greyed out regardless of whether or not the Help Menu
is enabled in the NIB .
I deleted the Help Menu Item from the NIB file and then re-added it in Xcode. The Help Menu then became enabled for reasons I don't understand. The following code made the Help Viewer appear:
- (IBAction) showHelp:(id)sender {
int status = MyGotoHelpPage();
DLog(#"status for HelpBook load is %d",status);
}
OSStatus MyGotoHelpPage (void)
{
CFBundleRef myApplicationBundle = NULL;
CFStringRef myBookName = NULL;
OSStatus err = noErr;
myApplicationBundle = CFBundleGetMainBundle();// 1
//if (myApplicationBundle == NULL) {err = fnfErr; goto bail;}// 2
myBookName =
CFBundleGetValueForInfoDictionaryKey( myApplicationBundle, CFSTR("CFBundleHelpBookName"));
if (myBookName == NULL) {err = fnfErr; return err;}
if (CFGetTypeID(myBookName) != CFStringGetTypeID()) {// 4
err = paramErr;
}
err = AHGotoPage (myBookName, NULL,NULL);// load title page
return err;
}
The Help Viewer appears with a message: "The selected topic is currently unavailable."
This is progress.