I'm writing a Blackberry app. I have a custom list field where I can select an item in the list which pushes the edit screen onto the stack. I edit the item and save, and when I pop that screen off so I am back on my list screen, I want to view the update I just made reflected in the list. I have done this on other screens which just had LabelFields and it worked fine. However, with the list screen, calling invalidate() seems to do nothing. I know the value has saved correctly through print lines, and I see the paint() method in the listfield is getting called. But the only way I can get the list field to update is to delete it from the screen and re-add it. That seems wrong. What am I doing wrong?
public class ListTasksScreen extends MainScreen{
private TaskList tasks;
private CustomListField taskListField;
public ListTasksScreen (TaskList tasks){
super();
this.tasks = tasks;
Vector incompleteTasks = tasks.getIncompleteTasks();
taskListField = new CustomListField(incompleteTasks, tasks);
add(taskListField);
}
public void updateTaskList(TaskList t)
{
Vector incompleteTasks = t.getIncompleteTasks();
taskListField= new TaskListField(incompletetTasks, t);
//I just want to call taskListField.invalidate() here.
//the only thing that seems to work is deleting taskListField
//and re-adding
this.delete(taskListField);
add(taskListField);
}
}
Is there a typo in your code above? in the updateTaskList method you do:
taskListField= new TaskListField(incompletetTasks, t);
should it be:
taskListField= new CustomListField(incompletetTasks, t);
Anyway, I think the reason you are having problems is because when you update your task list you are actually creating a new CustomListField object. When you first do add(taskListField) you are passing a reference to the field to the screen, so it has its own reference. When you call taskListField= new CustomListField(incompletetTasks, t); you are only updating your own reference, not the one in the screen. So if you call invalidate the screen will repaint using the original reference, which must be using references to the original versions of incompleteTasks and tasks too.
The reason it works the other way is because you are actually removing the old reference and adding the new one, so the screen now knows of the updated data.
What you should do is add a method to your CustomListField that allows you to update the task list object. Then when you call that method on the existing reference to taskListField and then call invalidate, your paint method should now use the new values when it calls drawListRow in the callback.
to add item and update list:
add item to array/vector of list items
perform insert new row (listField.insert(listField.getSize());)
Related
I managed to get a custom button added to the Git history context menu thanks to the help offered here.
I'm continuing work at the same extension and am again stuck. Once the button I've added to the context menu is clicked I need to get a reference to the commit that is selected when it is clicked. The idea is that I then need to grab the code changes associate with that commit.
I've gotten as far as getting a reference to the ActiveWindow which has a caption of "History - master". Which makes me believe I'm close. However, ActiveWindow.Selection is null. So I'm not sure where to go next to get the selected commit.
This is what I'm using to get the ActiveWindow property.
EnvDTE80.DTE2 dte = ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2;
Anyone know how to grab a reference to the selected commit? Then use that to grab information about the commit including the changed files?
My question looks similar to this one, but for Git instead of TFS.
Thanks in advance for the help!
Took forever, but I finally managed to get at the selected commit. It involves reflection because a lot of the types used in the git extension are internal. There's got to be a better way to do this.
The IGitCommit that I'm able to retrieve doesn't have the changes for the commit populated. Hopefully getting the changes that are part of the commit isn't as challenging.
private IGitCommit GetSelectedCommit()
{
ThreadHelper.ThrowIfNotOnUIThread();
EnvDTE80.DTE2 dte = ServiceProvider.GetService(typeof(DTE)) as EnvDTE80.DTE2;
// GUID found via dte.ActiveWindow.ObjectKind
Guid gitHistoryWindowGuid = new Guid("116D2292-E37D-41CD-A077-EBACAC4C8CC4");
IVsUIShell vsUIShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell));
int toolWindowReturn = vsUIShell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fFrameOnly, ref gitHistoryWindowGuid, out IVsWindowFrame vsWindowFrame);
WindowFrame windowFrame = (WindowFrame)vsWindowFrame;
ToolWindowView toolWindowView = (ToolWindowView)windowFrame.FrameView;
// panel is of innaccessible type Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ContentHostingPanel
// so use base System.Windows.Controls.Grid
Grid contentHostingPanel = (Grid)toolWindowView.Content;
// Type Microsoft.VisualStudio.Platform.WindowManagement.Controls.GenericPaneContentPresenter is internal
// so use base ContentPresenter
ContentPresenter genericPaneContentPresenter = contentHostingPanel.Children[1] as ContentPresenter;
// Microsoft.VisualStudio.TeamFoundation.ToolWindowBase.ToolWindowBaseProxy is innaccessible
// so use base ContentPresenter
ContentPresenter toolWindowBaseProxy = (ContentPresenter)genericPaneContentPresenter.Content;
// Is of type Microsoft.TeamFoundation.Git.Controls.History.HistoryView,
// but this class is defined as internal so using base UserControl.
UserControl historyView = (UserControl)toolWindowBaseProxy.Content;
// Is of type Microsoft.TeamFoundation.Git.Controls.History.HistoryViewModel,
// but this class is defined as internal so using base Microsoft.TeamFoundation.MVVM.ViewModelBase.
ViewModelBase historyViewModel = (ViewModelBase)historyView.DataContext;
// Use reflection to get at properties of internal type HistoryViewModel and ObservableCollection<GitHistoryItem>
object gitHistoryItem = ((IList)historyViewModel.GetType().GetProperty("SelectedItems").GetValue(historyViewModel, null))[0];
IGitCommit gitCommit = (IGitCommit)gitHistoryItem.GetType().GetProperty("Commit").GetValue(gitHistoryItem, null);
return gitCommit;
}
I have a view-based NSOutlineView with a dataSource/delegate model instead of binding to a tree controller (I want control over the insert/update animations).
I'm replacing an item in my model and would like to update that specific row in the outline view without having to call reloadData().
I cannot get this to work. Either the item does not update at all or the item's expanded state doesn't update. There seems to be some caching being done inside of NSOutlineView according to this, but even with these suggestions, I could not get it to work.
What I have:
(1) The outline view represents a folder structure
(2) At first, there is a singe file:
(3) The file is then replaced with a folder item:
// Model update
let oldFileItem = rootItem.children.first!
rootItem.children.remove(at: 0)
rootItem.children.append(Item(title: "Folder", children:[], isExpandable:true))
Expected result:
Actual result (reloadItem):
outlineView.reloadItem(oldFileItem) // I kept a reference
Icon and title reloaded, but note that the expansion triangle is missing.
I can somewhat understand that reloadItem() might not work in this case, because the old item is not part of the data model anymore. Strangely enough, the item's title and icon update, but not the expansion state.
Actual result (reloadData(forRowIndexes:columnIndexes:):
outlineView.reloadData(forRowIndexes: IndexSet(integer:0), columnIndexes: IndexSet(integer:0))
No effect whatsoever. This is the one that I would have expected to work.
Actual result (remove/insert):
outlineView.removeItems(at: IndexSet(integer:0), inParent: rootItem, withAnimation: [])
outlineView.insertItems(at: IndexSet(integer:0), inParent: rootItem, withAnimation: [])
No effect whatsoever.
The docs say about removeItems(): "The method does nothing if parent is not expanded." and isExpanded does indeed return false for the root node, although its children are visible. Is this special behavior for items that are direct children of the root node? What am I missing here?
For reference, my data model:
class Item:NSObject {
var title:String
var children:[Item]
var isExpandable:Bool
init(title:String, children:[Item], isExpandable:Bool) {
self.title = title
self.children = children
self.isExpandable = isExpandable
}
}
For reference:
It turned out to be an issue with how I used the API. NSOutlineView.removeItems/insertItems expect nil for the inParent parameter for the root item. I was handing in the actual root item. Using nil instead of the root item solved the problem.
i have made a program, which include a lot of controls. The controls would be showed and hided according to the choice of the user. That means that controls overlapped on each other at design time. now i want to change the forecolor and backcolor of all controls at design time. but i founded so hard to accomplish this task, because all the control overlapping each other. so I decided to make a for loop method to iterate the controls in the form and then check each control in turn whether it has controls. when the control has also controls in it, I call the same method and pass the control to it to change the properties for the subcontrols too. The method like so:
void setColor(ref Control con)
{
con.BackColor= System.Drawing.Color.Black;
con.ForeColor=System.Drawing.Color.Yellow;
if (con.Controls.Count > 0) { setColor(ref con); }
}
so my Form include tabControl with multiple tabPages. I iterate the tabPages and wanted to pass it to this method, but I become error "Indexer may not be passed as an out or ref parameter"
I pass it so: setColor(ref tabControl1.Controls[i]);
can you please help me to solve this problem?
I have resolved the problem.
I have removed the "ref" from method and wrote the method simply like the following:
void SetColor(Control con)
{
con.BackColor = System.Drawing.Color.Black;
con.ForeColor = System.Drawing.Color.Yellow;
if (con.Controls.Count > 0)
{
for (int i=0; i<con.Controls.Count;i++)
SetColor(con.Controls[i]);
}
}
and call it so: setColor(this.Controls[i]);
I found this function to remove a gui element but i think it is outdated. So far I haven't been able to find anyone else who knows how to remove any part of a gui, whether its an entire dat.GUI() or just an added element to a dat.GUI(). The first would probably be enough for what i need (just removing the dat.GUI() all together) but either one would be super helpful!
supposed to remove a dat.GUI()
gui = new dat.GUI();
...
removeGui(gui);
function removeGui(gui, parent)
{
if(!parent)
{
parent = dat.GUI.autoPlaceContainer;
}
parent.removeChild(gui.domElement);
}
But gives back the error: cannot call method 'removeChild' of undefined, so i am guessing that autoPlaceContainer is wrong.
The original author of this function left these notes:
where the parameters gui represents the DAT.GUI you want to remove and parent is the parent container where if you didn't specify a domElement when instantiating DAT.GUI then you don't need to pass a parent.
var gui = new dat.GUI();
item = gui.add(text, 'message');
To delete:
gui.remove(item);
If your item is inside a folder, you have to do:
folder.remove(item);
If you want to remove the entire dat.GUI element along with all of its listeners, you can use gui.destroy()
If you want to reset the dat.GUI's values, you can use datGUI.__controllers.forEach(controller => controller.setValue(controller.initialValue));
You can delete dat.GUI element like this:
gui.remove()
You can try hiding it using:
gui.hide()
Change the remove function in the dat.gui.js file: "slice" wants to be "splice".
The answer can be found here: https://github.com/ulyssesp/dat.gui/commit/86f43c0be5db08c9a6d7339aa8287620306fb0b5
I am trying to use an edit control along with a spin control using MFC visual studio .net 2003. I have carried out the basic settings for the spin control like setting the "AutoBuddy" property and "SetBuddyInteger" property to True so that the Spin control works in coordination with the edit control next to it. In my Spin control's event handler, I am facing a problem when I am trying to call my Invalidate() function. The float value in my edit control does not update and stays zero. If I remove the Invalidate(), then the value increments but my paint function is not updated obviously. A code of the following is given below:
void CMyDlg::OnSpinA(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
// TODO: Add your control notification handler code here
UpdateData();
m_A = m_ASpinCtrl.GetPos(); // m_A is my edit control float value variable
Invalidate(); // Invalidate is to be called to update my paint function to redraw the drawing
UpdateData(false);
*pResult = 0;
}
I have carried out the tab order correctly as well for the two controls.
Any suggestions on where I am going wrong?
Thanks in advance.
If you just want to have a spinning integer, you don't have to override anything.
The spin control has to be right next to the edit control in the tab order. With AutoBuddy that's all you have to do.
m_A when getting the position back would do something weird and would not return you the correct value. Try using the pointer to get your position and value and then carry out the invalidate().
{
LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
// TODO: Add your control notification handler code here
UpdateData();
CString tempStr;
m_A += pNMUpDown->iDelta;
tempStr.Format("%f",m_A);
m_ACtrl.SetWindowText(tempStr); // Like a CEdit m_ACtrl to display your string
Invalidate();
UpdateData(false);
*pResult = 0;
}
This should work perfectly well. Let me know if you still get any problems.