Context in GPS Plugin - gnat-gps

I created a button in the toolbar using
GPS.Toolbar().append(button)
In the On_Click function of the button I want it to print the current file's name.
I wrote print GPS.Current_Context().file()
But it does'nt work and give me the error : Current_Context has no attribute file
Anyone knows why?

Use EditorBuffer to get the current view's name:
EditorBuffer.get().current_view().title()
This will give you the title of the current editor tab, which is the name of the edited file.

Related

How to change the selection color of a sidebar?

Is there any way to change the selection color of a sidebar item?
For example the default color of macOS 10.14.x dark theme is blue, would it be possible to change this color?
I took a look here: Cocoa osx NSTableview change row highlight color
but I had difficulty translating to Applescript, thanks in advance.
Without a sample or MCVE project it is going to be tricky providing a drop-in solution. The topics and answers you linked to are overriding the NSTableView or NSTableRowView classes, so I can give you a generic solution for that. Subclassing in AppleScriptObjC can be a bit of a pain, depending on what you need to reference, but is fairly straightforward. Essentially you are putting a custom class in between the regular class and your application, where you can intercept the various standard method calls.
For a cell-based table view example, add a new empty file to your project by using the File > New > File... menu item. The name of the _file _isn't important (e.g. TableViewHighlight.applescript or whatever), the name of the script is what will be used by Xcode. Here I am using MyTableView for the class name and referencing a tableView outlet property from the AppDelegate:
script MyTableView -- the name of your custom class
property parent : class "NSTableView" -- the parent class to override
property tableView : a reference to current application's NSApp's delegate's tableView
property highlightColor : a reference to current application's NSColor's greenColor -- whatever
# set the row highlight color
on drawRow:row clipRect:clipRect
if tableView's selectedRowIndexes's containsIndex:row then -- filter as desired
highlightColor's setFill()
current application's NSRectFill(tableView's rectOfRow:row)
end if
continue drawRow:row clipRect:clipRect -- super
end drawRow:clipRect:
# set the highlight color of stuff behind the row (grid lines, etc)
on drawBackgroundInClipRect:clipRect
highlightColor's setFill()
current application's NSRectFill(clipRect)
continue drawBackgroundInClipRect:clipRect -- super
end drawBackgroundInClipRect:
end script
In the Interface Editor, use the Identity Inspector to set the class of your table view to the MyTableView class. Finally, in your table view setup set its highlighting to none, since it will be done by your subclass (again, assuming a tableView outlet is connected to the table view):
tableView's setSelectionHighlightStyle: current application's NSTableViewSelectionHighlightStyleNone
For a view-based table view example, the process is similar, but NSTableRowView is the one to subclass. Here the name of the script/class I am using will be MyTableRowView:
script MyTableRowView -- the name of your custom class
property parent : class "NSTableRowView" -- the parent class to override
property highlightColor : a reference to current application's NSColor's redColor -- whatever
# draw the selected row
on drawSelectionInRect:dirtyRect
continue drawSelectionInRect:dirtyRect
highlightColor's setFill()
current application's NSRectFill(dirtyRect)
end drawSelectionInRect:
end script
In the Interface Editor, set the table view's highlight to regular using the Attributes Inspector, and add a tableView:rowViewForRow: method to the table view's delegate:
on tableView:tableView rowViewForRow:row
set rowIdentifier to "MyTableRow"
set myRowView to tableView's makeViewWithIdentifier:rowIdentifier owner:me
if myRowView is missing value then
set myRowView to current application's MyTableRowView's alloc's initWithFrame:current application's NSZeroRect
myRowView's setIdentifier:rowIdentifier
end if
return myRowView
end tableView:rowViewForRow:
There are other options, of course, but that should get you started, and help with translating some of those Objective-C answers/examples.

Create a TAnimate in Borland 2006

I have the following problem. I am using the Borland 2006 Compiler and I am trying to include an animation in my applicaton. First I added the TAnimate Object and then in the ObjectInspector under "FileName", every time I try to add an .avi, the Compiler says "AVI cannot be opened". Am I doing something wrong or isn't it that simple to just put a .gif or .avi into that Objectproperty?
Edit // Here ist Some CodeExample, everytime i press the button, it throws an exception and tells me that the avi File cannot be opened
void __fastcall THauptmenue_Login::Button1Click(TObject *Sender)
{
Animate1->FileName = ("C:\\Users\\Kevin\\Desktop\\C++ Gifs");
}
The FileName you showed doesn't look complete. It looks more like a path to a folder instead of a file.
In the Object Inspector, beside the FileName text box is a [...] button which brings up a file browser dialog which can add a full path and name to a file.
addendum:
If you are using the Object Inspector to pick a filename from the disk you do not need to specify a FileName property value in the code.
This overwrites any previous FileName property value.
Animate1->FileName = "C:\\Users\\Kevin\\Desktop\\C++ Gifs";

How can I add a context sensitive help button for a specific dialog control

I have an MFC app (10 year old app), which has context sensitive help for each dialog. I want to add help on a specific combobox, as well as a little question mark button next to this control. Users can either select the combobox and hit F1, or they can click on the button next to the combobox, and it will jump to a help page that is specifically about this combobox, rather than general help for the whole dialog.
In the dialog resource properties, I have set "Context Help" to True.
In the combobox properties, I've set "Help ID" to True.
In myapp.hpp, I have added "HIDC_MYCOMBOBOX = mycombobox_help.htm" to the [ALIAS] section, and included the resource.hm file in the [MAP] section.
Again in app.hpp file, the dialog uses "HIDD_MYDIALOG =
mydialog_help.htm"
Yet selecting the combobox and pressing F1 still brings up mydialog_help.htm, instead of mycombobox.htm.
What am I missing to use a separate help page for the control?
Is it possible to redirect the control to an anchor in the main page? Something, along the lines of...
HIDC_MYCOMBOBOX = mydialog_help.htm#mycombobox
I have added a "?" button to run the following code, but this also doesn't give the context for the control, and just opens the mydialog_help.htm.
HELPINFO lhelpinfo;
lhelpinfo.cbSize = sizeof(lhelpinfo);
lhelpinfo.iContextType = HELPINFO_WINDOW;
lhelpinfo.iCtrlId = IDC_BALANCING_METHOD;
lhelpinfo.hItemHandle = GetDlgItem(IDC_BALANCING_METHOD)->m_hWnd;
lhelpinfo.dwContextId = HIDC_BALANCING_METHOD;
lhelpinfo.MousePos = POINT();
CDialog::OnHelpInfo(&lhelpinfo);

Taking data from a Dialog in Qt and using it in a Ui

So I'm making a text editor using Qt and right now I have a button that opens a dialog called "Format text". I want it to work kind of like the dialog in notepad called "font" where you select a few text attributes from some drop down lists and it shows you what your text will look like. Right now I have it working where you can select the font style, font color, and font size and hit preview and it shows you in a box in the dialog what your text will look like. However, I have a button called "okay" which is supposed to change the highlighted text or the text you are about to type, but I can't figure out how to display those changes on the main window. The .ui files are private and a lot of the already made functions and pointers are the same in every ui file so if I change the ui file to pubic I have to change a whole bunch of things. Can anyway give me a simple answer? I'm trying to do this with as little confusion as possible. More coding and less confusion is better than less coding and more confusion for someone of my skill level. Sorry that this is all one giant paragraph and that I didn't provide any code, but I didn't think the code was necessary, however if you do need some of the code i'd be happy to share it.
Thank you for your help and your time. I hope you all have a nice evening.
QDialog have a signal called finished(), you can connect this signal with your slot. To accomplish your work, pass a QSettings or for simplicity QStringList to dialog settings (responsible for changing font, color ...), the QStringList will save user defined settings, after closing the dialog, iterate through QStringList member to alert Main window.
A pseudo code will look like this
Class Editor:
Editor::Editor()
{
TextSettings textSettings;
textSettings.setSettings(settings); // settings is a member
connect(textSettings, &finished(int)), this, SLOT(alertEditor(int)))
}
Editor::alertEditor(int s)
{
if(s == 0)
{
for (int i = 0; i < settings.size(); ++i)
settings.at(i).toLocal8Bit().constData(); // extract various user settings
}
}
Class TextSettings:
TextSettings::TextSettings(QStringList settings)
{
settings << ui->combobox->currentItem(); // font name as example
}

How might I obtain the IContextMenu that is displayed in an IShellView context menu?

Building a file open dialog replacement. Much of it works now, but I would like to generate the view-mode drop-down for the toolbar directly from the shell view object.
Looking at IShellView2, I can see IShellView2::GetView() will give me the FOLDERVIEWMODE's supported. However, that doesn't give me the names of these modes, nor format that popup menu for me, nor immediately give me a way to actually set one of those modes (it would appear it is necessary to destroy the shell view window and create a replacement one for the current folder and specify the new FOLDERVIEWMODE desired... yeesh).
At any rate, if one right clicks on an IShellView window, one gets a context menu, the first submenu of which is exactly what I want to place in my drop-down toolbar button (ie. the "view" fly-out menu (e.g. Small Icons, Medium Icons, etc.)).
It seems like there ought to be a way to grab that submenu directly from the IShellView, rather than having to hardcode my values (and that way, if a given instance of IShellView supports extra view modes, they'd be there. Similarly, those which should be disabled would be, since it would all be under the IShellView's control).
I have read Raymond Chen's excellent How to host an IContextMenu. Unfortunately, that just gives me a very simplistic context menu - the one for the folder itself, or for a file in a given folder, but NOT the context menu for the IShellView's shell view window (from which I might obtain the view fly-out).
I have tried the following, based on Chen's article:
CComQIPtr<IContextMenu> pcm(m_shell_view); // <<-- FAIL resulting pointer is NULL <<<
// create a blank menu
CMenu menu;
if (!menu.CreatePopupMenu())
throw CContextException("Unable to create an empty menu in which to store the context menu: ");
// obtain the full popup menu we need
if (FAILED(m_hresult = pcm->QueryContextMenu(menu, 0, SCRATCH_QCM_FIRST, SCRATCH_QCM_LAST, CMF_NORMAL)))
throw CLabeledException("Unable to query the context menu for the current folder");
// display the menu to the user
// menu.getsubmenu
::TrackPopupMenu(menu, ::GetSystemMetrics(SM_MENUDROPALIGNMENT)|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, m_shell_view_hwnd, NULL);
Unfortunately, the attempt to query the m_shell_view (which is an IShellView*) for its IContextMenu interface fails. This "works":
// retrieve our current folder's PIDL
PidlUtils::Pidl pidl(m_folder);
// get the context menu for the current folder
CComPtr<IContextMenu> pcm;
if (FAILED(m_hresult = GetUIObjectOf(m_owner->m_hWnd, pidl, IID_PPV_ARGS(&pcm))))
throw CLabeledException("Unable to obtain the PIDL for the current folder");
But here I get only a very few options in the context menu (Open, Explore, ...). Not the detailed context menu that I get if I simply right click on the shell view itself.
I'm out of ideas as to how to proceed. Help?! ;)
Try IShellView::GetItemObject with SVGIO_BACKGROUND as uItem to get a IContextMenu on the view object : http://msdn.microsoft.com/en-us/library/bb774832%28VS.85%29.aspx
There is the SHCreateDefaultContextMenu (Vista an up) that may be of help. Bjarke Viksoe website contains great info as well.
SVGIO_BACKGROUND will get you the background context menu of the shell view. You may need to call repeatedly pShellView->SelectItem for each PIDL you may have, then do the GetUIObjectOf call (then QI for IContextMenu, create a menu, call IContextMenu(3)::QueryContextMenu and finally display it with TrackPopupMenu).