How to close the specfic editor in the vscode programmatically? - vscode-extensions

I'm the developer for the vscode extension.
When the debugger activated, I opened a specific file in the right column editor to show the other related file for the current debug file using the below command.
vscode.commands.executeCommand('vscode.open', vscode.Uri.file('/main.c.dbgasm'), 2);
Now I want to close it. But I have no idea to close the right column editor. There are some close editor commands but they do not fit my needs which shown below.
workbench.action.closeActiveEditor
workbench.action.closeAllEditors
workbench.action.closeAllGroups
workbench.action.closeEditorsInGroup
workbench.action.closeOtherEditors
workbench.action.closeUnmodifiedEditors
Can anyone have idea about it?

You can use the window.tabGroups.close() method.
// the 'all' array is 0-based, so this is the second editor group
const sourceGroup = vscode.window.tabGroups.all[1];
// this would get the first tab in the second editor group
// if you don't know where in the editor group the file you want to close is
// you can filter the tabs by label,url or path, see below
const myTab = sourceGroup.tabs[0];
await vscode.window.tabGroups.close(myTab, false);
To filter the tabs in an editor group by their path, try this:
const sourceGroup = vscode.window.tabGroups.all[0]; // 'all' array is 0-based
// note small "c" to match how Uri.fsPath looks
const myPath = "c:\\Users\\Mark\\OneDrive\\Test Bed\\howdy.js";
const foundTab = sourceGroup.tabs.filter(tab =>
(tab.input instanceof vscode.TabInputText) && (tab.input.uri.fsPath === myPath)
);
// close() takes an array or a single tab
if (foundTab?.length === 1) await vscode.window.tabGroups.close(foundTab, false);

Related

How to paste the text from clipboard into textbox and assert in testcafe?

I have a text field in a table and I want to copy the contents of the clipboard to textfield
As paste option is not available in testcafe, so tried the below:
const execPaste = ClientFunction(() => document.execCommand("paste"));
t..click(Selector(".table > tbody > tr:nth-child(5) > td:nth-child(3)"))
.typeText(
Selector(".table > tbody > tr:nth-child(5) > td:nth-child(3)"),
JSON.stringify(execPaste())
);
console.log(JSON.stringify(execPaste()));
and in the console log I see "{"_then":[],"_taskPromise":null}" and not the value which is copied from the clipboard
Please help
The ClientFunction returns a Promise, so to get the ClientFunction value, you need to await this promise:
JSON.stringify(await execPaste())
To paste a value from the clipboard, you can focus the element where you are going to paste the value and then call the document.execCommand("paste") method. If I understand your code correctly, the first click is supposed to focus the target element.
Please try to change your code example in the following way:
const execPaste = ClientFunction(() => document.execCommand("paste"));
await t.click(Selector(".table > tbody > tr:nth-child(5) > td:nth-child(3)"));
await execPaste();

CKEditor 5 copy selected content from one editor to another

I have two editors on the screen, one read-only. What I want to do is allow the user to select content from the read-only editor and paste it into the current position of the other by clicking a button. (the logic may manipulate the text which is one reason I don't want to use the system's clipboard.)
So far I have the function that is able to paste the text like as follows. (I am using the Angular wrapper which explains the presence of the CKEditorComponent reference.
doPaste(pasteEvent: PasteEvent, editorComponent: CKEditorComponent) {
const editor = editorComponent.editorInstance;
editor.model.change(writer => {
writer.insertText(pasteEvent.text, editor.model.document.selection.getFirstPosition() );
});
}
What I can't find from the documentation is how to extract the selected text. What I have so far is:
clickPasteSelectedPlain(editorComponent: CKEditorComponent) {
const editor = editorComponent.editorInstance;
const selection = editor.model.document.selection;
console.log('clickPasteAll selection', selection);
console.log('clickPasteAll selectedcontent', editor.model.document.getSelectedContent);
}
The selection appears to change depending on what is selected in the editor's view. The getSelectedContent function is undefined. How do I get the content?
With a bit of poking around I figured out how to do this. I'll document it here on the chance that it will help someone down the road avoid the process of discovery that I went through.
On the source document I have a ckeditor element like this:
<div *ngIf="document">
<ckeditor #ckEditor
[editor]="Editor" [config]="ckconfig" [disabled]="true"
[(ngModel)]="document.text"></ckeditor>
<button mat-flat-button (click)="clickPasteSelectedPlain(ckEditor)">Paste Selected Text Plain</button>
</div>
In the component the function called on the click event is like this:
#Output() paste = new EventEmitter<PasteEvent>();
...
clickPasteSelectedPlain(editorComponent: CKEditorComponent) {
const editor = editorComponent.editorInstance;
this.paste.emit({
content: editor.model.getSelectedContent(editor.model.document.selection),
obj: this.document,
quote: false
});
}
The PasteEvent is defined as an exported interface which I will omit here to save space. The content key will refer to a DocumentFragment.
Note that I am passing the CKEditorComponent as a parameter. You could also access it via an Angular #ViewChild declaration but note that my ckeditor is inside an *ngIf structure. I think that works well in Angular 6 but in the past I have had difficulty with #ViewChild references when the target was conditionally in the DOM. This method always works but use whatever method you want.
The event fired by the emit is processed with a method that looks like this:
doPaste(pasteEvent: PasteEvent, editorComponent: CKEditorComponent) {
const editor = editorComponent.editorInstance;
editor.model.insertContent(pasteEvent.content);
}
Because the content is a DocumentFragment the paste operation will include all formatting and text attributes contained in the selected source. But that's all there is to it.

Using a loop within the menu UI script beginner

I am trying to create a dynamic menu that creates the names of the sheets in it. I dont often code and need some help. currently the code ON_Open creates a menu, creates its first item in the menu, then add a seperator and then goes into a loop. it checks how many sheets there are and starts at the first one. stores the name and makes a menu item with that name, then advances to the next sheet. gets its name and makes the next menu item. i can get the loop to work with the menu UI syntax.im not worried about the names. i will try to figure that out next,just want it to create the menus first
function onOpen() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var numsheets = spreadsheet.getNumSheets();
SpreadsheetApp.getUi
.createMenu('SWMS CREATER')
.addItem('Create New SWMS', 'showPrompt')
.addSeparator()
for ( var i = 0; i < numsheets.length;i++ ) {
var ui = SpreadsheetApp.getUi();
var subMenu = ui.createMenu('Test Menu');
subMenu.addItem('Test script'i ,'showPrompt');
}
}
The OP is trying to create a dynamic menu that lists each of the sheets in the spreadsheet. The OP's code is very close to working - there are just a small, but significant, number of adjustments.
function onOpen() {
var ui = SpreadsheetApp.getUi();
var menu = ui.createMenu('OPSWMS CREATER')
.addItem('Create New SWMS', 'showPrompt')
.addSeparator();
var sheetList = SpreadsheetApp.getActiveSpreadsheet().getSheets();
var subMenu = ui.createMenu('OPTest Menu');
for (var i = 0; i < sheetList.length; i++) {
subMenu.addItem(sheetList[i].getName(), 'showPrompt');
}
menu.addSubMenu(subMenu).addToUi();
}
Summary of major differences:
1) variable ui moved out of the loop; and then re-used where possible.
2) variable menu established and also moved out of the loop. This is re-used to add the subMenu in the last line of code.
3) added a semi-colon after .addSeparator() (though optional)
4) used .getSheets() to get all the sheets. This is the first key element missing from the OP code.
5) dropped var numsheets line. You don't need this because you can get the same count on sheetList.
6) within the loop, two things to note
sheetList[i] the i in square brackets ([i]) returns the relevant item from "sheetList";
.getName() returns the name of the sheet. Combined, sheetList[i].getName() gives you the name of the sheet, and lets you add it as a menu item selection.
7) menu.addSubMenu(subMenu).addToUi(); This add the contents of the loop to the menu. This is the second key element missing from the OP code.
Credit:
Akshin Jalilov's answer to Google Apps Script: Dynamically creating spreadsheet menu items

How to check multiple PDF files for annotations/comments?

Problem: I routinely receive PDF reports and annotate (highlight etc.) some of them. I had the bad habit of saving the annotated PDFs together with the non-annotated PDFs. I now have hundreds of PDF files in the same folder, some annotated and some not. Is there a way to check every PDF file for annotations and copy only the annotated ones to a new folder?
Thanks a lot!
I'm on Win 7 64bit, I have Adobe Acrobat XI installed and I'm able to do some beginner coding in Python and Javascript
Please ignore the following suggestion, since the answers already solved the problem.
EDIT: Following Mr. Wyss' suggestion, I created the following code for Acrobat's Javascript console to be run only once at the beginning:
counter = 1;
// Open a new report
var rep = new Report();
rep.size = 1.2;
rep.color = color.blue;
rep.writeText("Files WITH Annotations");
Then this code should be applied to all PDFs:
this.syncAnnotScan();
annots = this.getAnnots();
path = this.path;
if (annots) {
rep.color = color.black;
rep.writeText(" ");
rep.writeText(counter.toString()+"- "+path);
rep.writeText(" ");
if (counter% 20 == 0) {
rep.breakPage();
}
counter++;
}
And, at last, one code to be run only once at the end:
//Now open the report
var docRep = rep.open("files_with_annots.pdf");
There are two problems with this solution:
1. The "Action Wizard" seems to always apply the same code afresh to each PDF (that means that the "counter" variable, for instance, is meaningless; it will always be = 1. But more importantly, var "rep" will be unassigned when the middle code is run on different PDFs).
2. How can I make the codes that should be run only once run only at the beginning or at the end, instead of running everytime for every single PDF (like it does by default)?
Thank you very much again for your help!
This would be possible using the Action Wizard to put together an action.
The function to determine whether there are annotations in the document would be done in Acrobat JavaScript. Roughly, the core function would look like this:
this.syncAnnotScan() ; // updates all annots
var myAnnots = this.getAnnots() ;
if (myAnnots != null) {
// do something if there are annots
} else {
// do something if there are no annots
}
And that should get you there.
I am not completely positive, but I think there is also a Preflight check which tells you whether there are annotations in the document. If so, you would create a Preflight droplet, which would sort out the annotated and not annotated documents.
Mr. Wyss is right, here's a step-by-step guide:
In Acrobat XI Pro, go to the 'Tools' panel on the right side
Click on the 'Action Wizard' tab (you must first make it visible, though)
Click on 'Create New Action...', choose 'More tools' > 'Execute Javascript' and add it to right-hand pane > click on 'Execute Javascript' > 'Specify Settings' (uncheck 'prompt user' if you want) > paste this code:
.
this.syncAnnotScan();
var annots = this.getAnnots();
var fname = this.documentFileName;
fname = fname.replace(",", ";");
var errormsg = "";
if (annots) {
try {
this.saveAs({
cPath: "/c/folder/"+fname,
bPromptToOverwrite: false //make this 'true' if you want to be prompted on overwrites
});
} catch(e) {
for (var i in e)
{errormsg+= (i + ": " + e[i]+ " / ");}
app.alert({
cMsg: "Error! Unable to save the file under this name ('"+fname+"'- possibly an unicode string?) See this: "+errormsg,
cTitle: "Damn you Acrobat"
});
}
;}
annots = 0;
Save and run it! All your annotated PDFs will be saved to 'c:\folder' (but only if this folder already exists!)
Be sure to enable first Javascript in 'Edit' > 'Preferences...' > 'Javascript' > 'Enable Acrobat Javascript'.
VERY IMPORTANT: Acrobat's JS has a bug that doesn't allow Docs to be saved with commas (",") in their names (e.g., "Meeting with suppliers, May 11th.pdf" - this will get an error). Therefore, I substitute in the code above all "," for ";".

Get value by getProperties in Titanium

I have two window :
window1 : have an option_dialog width 3 option : 'Video','Image','Document'
var optionsDialogOpts = {
options:['Video','Image','Document'],
title:'Type'
};
var dialog_search_click = Titanium.UI.createOptionDialog(optionsDialogOpts);
dialog_search_click.addEventListener('click',function(e){
//spinner_search_click.setTitle(e.index);
if(e.index==0)
{
//save option select All
Ti.App.Properties.setString('option_dialog','0');
}
if(e.index==1)
{
Ti.App.Properties.setString('option_dialog','1');
}
if(e.index==2)
{
Ti.App.Properties.setString('option_dialog','2');
}
})
window2 : display option that selected in window1..
var option=Ti.App.Properties.getString('option_dialog');
Ti.API.info(option);
In the first time, option is displayed in window2 is true but when click back to window1 and select other option in option_dialog and go to window 2,it also only display option as the first time ,not change.Can you help me.
This code is right but, I thought one error with this.
your window1 and window2 both code in one .JS file. so this problem is ocurring.
var option=Ti.App.Properties.getString('option_dialog');
This line is not update always, it store information once.
You try this type,
add a new Button on Second window and check on Click Event this is working properly.
button.addeventListener('click',function(){
var option=Ti.App.Properties.getString('option_dialog');
alert("Option :- " + option);
});
If, this is working then. I think you can understand, What i want to say.
Cheers.....!