How do I find currently loaded mode (syntax) in Ace Editor? - ace-editor

Well as the title says - how do I find out what the currently loaded mode is in Ace Editor?
editor.getSession().getMode() does not really return anything I can use - have looked through the objects returned somewhat - but could not find anything.
editor.getTheme() returns a string to me that I can use however - just seems funny if they did not do somewhat the same for mode

To retrieve the name of the mode you use:
editor.getSession().getMode().$id

I tried Hugeen's answer and experienced the undefined error just like lorefnon reported. This is what worked for me:
// get the editor instance
var editor = ace.edit('editorid');
// get the current mode
var mode = editor.session.$modeId;
// modeid returns the full string (ace/mode/html), cut to the mode name only
mode = mode.substr(mode.lastIndexOf('/') + 1);
Hope that helps someone!

The clean way to get this without any somersaults:
var mode = editor.session.mode;

Related

UnicodeString::Length() interferes with debugger display

The debugger seems to suppress viewing the contents of a UnicodeString in the Local Variable and Watch windows whenever the current function contains a UnicodeString::Length() call.
Running C++ Builder 10.3 Rio Enterprise (upgraded to 10.31 to try to solve the issue) where I have started a new project, added a button and put the following code in for the button. This a stripped down version of a large piece of code to track down and reproduce the issue.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TFDQuery* qry = new TFDQuery(NULL);
UnicodeString search = "SELECT *\rFROM Client\rWHERE id>0;";
UnicodeString currLine;
int to, len;
qry->SQL->Clear();
to = search.Pos("\r");
while (to > 0) {
currLine = search.SubString(1, to-1);
qry->SQL->Add(currLine);
//len = search.Length()-1; // Offending line
search = search.SubString(to+1, 999999);
to = search.Pos("\r");
}
currLine = search;
qry->SQL->Add(currLine);
}
The picture below shows two different runs of this code. One is exactly as shown above (with one line commented out). The other shows with the line included.
My concern is that the the debugger only shows the apparent address of the variable named "search" and if I expand it, it shows "????", not the contents of the variable as shown by the arrow. Also note, the breakpoint is above the line that causes the debugger to switch views. Any ideas how I can get the contents of "search" to appear if I actually calculate the length of the substring (rather than placing "999999" for its length)?
After some experimenting, I can now partially answer my own question with a potential workaround. Replacing the "search.Length()" with "wcslen(search.c_str())" seems to work, at least it does not have the side effect of displaying only addresses for UnicodeStrings in the watch list and and local variables windows. At this point, I haven't thoroughly tested if this eventually raises some other problem. But why should I have to do this for such a fundamental type to the language?

VBScript Nothing returns garbage

We have to use VBScript as an embedded script engine in our Hospital Information System.
When we use nothing to set the value of a control (textbox/checkbox/...) it worked always fine. Since somepoint it sets now the textbox to "?>".
item("TEXTBOX").value = nothing ' Leads to -> "?>"
It is not completly clear what causes this, maybe a windows update is responsible, every rollup ~ since KB3212646 Win7 2017-01 seems to cause this error.
My Question is now, has someone else also seem this error, so that it is clear that MS causes this error or is our HIS publisher responsible for not handling nothing correct.
I know setting a textbox to Nothing is not best practice instead "" should be better, but since the item object could be more the just a textbox e.g. a combobox/checkbox this seems, from an objectoriented perpsective, better. Or am I completly wrong?
Following #Ansgar comment, you should apparently change everywhere you have = nothing to = "" in your example
item("TEXTBOX").value = ""
Beware to keep the nothing if you have the Set keyword in left
Set some_object = Nothing

How to open a file from network drive/path with default program?

from my application I want to open files (jpg, pdf, ..) with the default windows-program from network drives. I know start, but it doesn't seem to work for network paths.
I tried the following commands, but all I get is the windows dialog telling me that he doesn't know how to open that file and whether I want to use a web-service to ask for a programm or choose manually.
From cmd.exe (P:\ is a network drive):
cmd /c "start \server\path\to\image.jpg"
> cmd /c "start P:\path\to\image.jpg"
The path to the file is correct and clicking on it in the explorer works fine.
Thanks
UPDATE: I found the problem. See my answer below.
I think the function you need is ShellExecute - it would look something like this:
ShellExecute(ParentWindowHandl, "open", "Z:\SQLWriter.doc", NULL, SW_SHOWNORMAL);
P.S. I know I should post this as comment, but can't comment on all posts yet.
I tried these two commands:
start Z:\SQLWriter.doc
start \192.168.10.230\MyFolder\SQLWriter.doc
Both the commands worked perfectly. I didn't get any error messages.
You can use these if you want it to launch.
SHELLEXECUTEINFO ExecuteInfo;
memset(&ExecuteInfo, 0, sizeof(ExecuteInfo));
ExecuteInfo.cbSize = sizeof(ExecuteInfo);
ExecuteInfo.fMask = 0;
ExecuteInfo.hwnd = 0;
ExecuteInfo.lpVerb = "open"; // Operation to perform
ExecuteInfo.lpFile = "cmd.exe"; // Application name
ExecuteInfo.lpParameters = "start P:\Myfile.jpg"; // Additional parameters
ExecuteInfo.lpDirectory = 0; // Default directory
ExecuteInfo.nShow = SW_SHOW;
ExecuteInfo.hInstApp = 0;
if(ShellExecuteEx(&ExecuteInfo) == FALSE)
Or you can go through this link: http://www.codeguru.com/forum/showthread.php?t=302501
Ok, I have found the problem. Seems like the windows registry was a bit confused.
As commented before, other files like text and doc work, so the only problem was JPEG files.
Double Clicking them in the Windows Explorer worked fine for them, but using the start command showed me the popup described above. Selecting a program here once and marking it as permanent resolved my problem. Further calls with start now correctly open the image directly.

How to use EM_SETHANDLE on edit control?

I am unable to figure out how to properly use the EM_SETHANDLE mechanism to set the text for an edit control. Get and Set window text will be too slow for my application.
From the documentation I understand that the allocated buffer will be sued by the control and it works partially for me.
When the text is entered in the control, it is seen in the buffer but when the buffer is updated using memcpy etc (no bug in the code), the updated text won't show properly. I even tried EM_SETHANDLE (SetHandle() ) after every update but it fails after a couple of attempts. There is some kind of heap allocation failure. RedrawWindow() won't work either.
I am unable to get any proper info on the net on the usage. Help!
My code, leaving the app specific details, looks like this.
// init
HANDLE m_hMem = HeapAlloc(...)
m_edit.SetHandle(m_hMem)
// on some event
char *pbuf = (char*)m_hMem;
memcpy(...)
thanks in advance
The docs for EM_GETHANDLE tells you that this memory has to be movable memory allocated by LocalAlloc.
I'm guess you can get away with something like this:
int cbCh = sizeof(TCHAR) > 1 ? sizeof(TCHAR) : IsUsingComCtlV6() ? sizeof(WCHAR) : sizeof(char);
HLOCAL hOrgMem = SendMessage(hEdit,EM_GETHANDLE,0,0);
HLOCAL hNewMem = LocalReAlloc(hOrgMem,cbCh * cchYourTextLength,LMEM_MOVEABLE);
if (hNewMem)
{
//LocalLock, assign string, LocalUnlock
SendMessage(hEdit,EM_SETHANDLE,(WPARAM)hNewMem,0);
}
Looks like you need to allocate the memory with LocalAlloc. See the companion message EM_GETHANDLE: http://msdn.microsoft.com/en-us/library/bb761576(v=vs.85).aspx

Remove a keyboard shortcut binding in Visual Studio using Macros

I have a lot of custom keyboard shortcuts set up. To avoid having to set them up every time I install a new visual studio (happens quite a lot currectly, with VS2010 being in beta/RC) I have created a macro, that sets up all my custom commands, like this:
DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T, Ctrl+A"
My main problem is that Ctrl+T is set up to map to the transpose char command by default. So I want to remove that default value in my macro.
I have tried the following two lines, but both throw an exception
DTE.Commands.Item("Edit.CharTranspose").Bindings = ""
DTE.Commands.Item("Edit.CharTranspose").Bindings = Nothing
Although they kind of work, because they actually remove the binding ;) But I would prefer the solution that doesn't throw an exception.
How is that done?
I have coped with the same issue. I use a macro to assign key bindings for a set of align macros.
Dim NewBindings() = {"Global::Alt+="}
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignEquals").Bindings = NewBindings
NewBindings(0) = "Global::Alt+Num -"
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignMinus").Bindings = NewBindings
...
And to remove key bindings i use the following statements :
Dim DelBindings() = {}
DTE.Commands.Item("Macros.Dev.AlignUtils.AlignPlus").Bindings = DelBindings
It works fine under Visual Studio 2005.
I followed a little more pragmatic way (using your example):
DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T"
DTE.Commands.Item("ReSharper.ReSharper_UnitTest_RunSolution").Bindings = "Global::Ctrl+T, Ctrl+A"
With the first assignment Ctrl+T is unassigned from any other function and then becomes unbound with the second assignment.
Works like a charm for me.
You do not need to change it with macro, Just go to
Menu>Tools>Options -- Keyboard and then select what you want to change the shortcut from the dropdown and assignyour desiered short cut

Resources