Integrate Stack Overflow into IDEs? - eclipse

Okay, this is just a crazy idea I have. Stack Overflow looks very structured and integrable into development applications. So would it be possible, even useful, to have a Stack Overflow plugin for, say, Eclipse?
Which features of Stack Overflow would you like to have directly integrated into your IDE so you can use it "natively" without changing to a browser?
EDIT: I'm thinking about ways of deeper integration than just using the web page inside the IDE. Like when you use a certain Java class and have a problem, answers from SO might flare up. There would probably be cases where something like this is annoying, but others may be very helpful.

Following up on Josh's answer. This VS Macro will search StackOverflow for highlighted text in the Visual Studio IDE. Just highlight and press Alt+F1
Public Sub SearchStackOverflowForSelectedText()
Dim s As String = ActiveWindowSelection().Trim()
If s.Length > 0 Then
DTE.ItemOperations.Navigate("http://www.stackoverflow.com/search?q=" & _
Web.HttpUtility.UrlEncode(s))
End If
End Sub
Private Function ActiveWindowSelection() As String
If DTE.ActiveWindow.ObjectKind = EnvDTE.Constants.vsWindowKindOutput Then
Return OutputWindowSelection()
End If
If DTE.ActiveWindow.ObjectKind = "{57312C73-6202-49E9-B1E1-40EA1A6DC1F6}" Then
Return HTMLEditorSelection()
End If
Return SelectionText(DTE.ActiveWindow.Selection)
End Function
Private Function HTMLEditorSelection() As String
Dim hw As HTMLWindow = ActiveDocument.ActiveWindow.Object
Dim tw As TextWindow = hw.CurrentTabObject
Return SelectionText(tw.Selection)
End Function
Private Function OutputWindowSelection() As String
Dim w As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
Dim ow As OutputWindow = w.Object
Dim owp As OutputWindowPane = ow.OutputWindowPanes.Item(ow.ActivePane.Name)
Return SelectionText(owp.TextDocument.Selection)
End Function
Private Function SelectionText(ByVal sel As EnvDTE.TextSelection) As String
If sel Is Nothing Then
Return ""
End If
If sel.Text.Length = 0 Then
SelectWord(sel)
End If
If sel.Text.Length <= 2 Then
Return ""
End If
Return sel.Text
End Function
Private Sub SelectWord(ByVal sel As EnvDTE.TextSelection)
Dim leftPos As Integer
Dim line As Integer
Dim pt As EnvDTE.EditPoint = sel.ActivePoint.CreateEditPoint()
sel.WordLeft(True, 1)
line = sel.TextRanges.Item(1).StartPoint.Line
leftPos = sel.TextRanges.Item(1).StartPoint.LineCharOffset
pt.MoveToLineAndOffset(line, leftPos)
sel.MoveToPoint(pt)
sel.WordRight(True, 1)
End Sub
To install:
go to Tools - Macros - IDE
create a new Module with a name of your choice under "MyMacros". Or use an existing module.
paste the above code into the module
add a reference to the System.Web namespace (for HttpUtility) to the module
close the macro IDE window
go to Tools - Options - Environment - Keyboard
type "google" in the Show Commands Containing textbox. The SearchGoogleForSelectedText macro should show up
click in the Press Shortcut Keys textbox, then press ALT+F1
click the Assign button
click OK
This is all taken from Jeff Atwood's Google Search VS Macro post, just modified to search StackOverflow instead.

I don't think I'll be able to get any work done with SO integrated into an IDE. Its almost as bad, if not worst than integrating Digg/Reddit into an IDE.

In Visual Studio, you could add a shortcut to search for a highlighted term in StackOverflow. Jeff Atwood wrote about doing something similar with Google in his Google search VS.NET macro blog entry.
Using this approach would allow you to highlight a term or error message (or any other selectable text in the IDE), press the shortcut keys, and then see all the matching results on StackOverflow.
I'm sure there's a way to do this in other IDE's as well.

If StackOverflow can begin identifying the language that each code snippet contains, then I could see an code-completion/code-snippet plugin to an IDE that responds to a special syntax for performing searches on SO and inserting the code portion of accepted answers.
Eg: in my source I might type:
//# read an XML file
The //# syntax prompts the plugin to start a search and display a list of question titles. When I pick one, it inserts the code portion of the accepted answer.

I don't know about Eclipse, but for Visual Studio, if someone really wanted this they could easily add the SO RSS feed for the "Start Page News Channel" so the SO question list appeared in the start page, or even better, narrow it down with a tag (like for C#). It's not exactly "integration", but it would provide a quick look at recent things with extremely little effort. However, not sure how "useful" it would be.

You have the RSS plugin for Eclipse to read the StackOverflow feed.
But I'm with you, a SO Eclipse plugin would be really cool.

You could just set it as your Start Page in Visual Studio.
Not sure what benefit this would provide... but to each his own.

Related

Can not find get_Item() method for ListTemplates

I'm working on a C#/VSTO application for automate some tasks in MS Word. I'm trying to change the start number of a numbered list using a ListTemplate. I've seen several examples of accessing a ListTemplate like this:
ListTemplate template =
app.ListGalleries[WdListGalleryType.wdNumberGallery].ListTemplates.get_Item(ref n);
However, Visual Studio doesn't recognize get_Item() as a method for ListTemplates. Other methods of ListTemplates are listed in the VS popup so I'm not sure what the issue is? How do I go about referencing a ListTemplate? Thanks!
When I check in VSTO there is no get_Item for ListTemplates. Instead, one uses the index. For example
ListTemplate template =app.ListGalleries[Word.WdListGalleryType.wdNumberGallery].ListTemplates[Word.WdListGalleryType.wdNumberGallery];

Debug Watch Expression: How to customize the display of an object in Eclipse

In Eclipse's watch window ("Expressions"), is there a way to have eclipse interpret the contents of a class/structure, rather than having to open the tree? Currently the "value" for any class/structure is {...}, and opening it consumes multiple lines in the Expressions window.
i.e, suppose I have a class complex with real and imag.
class complex_t {
double real, imag;
}
Is there an XML file somewhere in eclipse to indicate that complex_t should display the values for .real and .imag instead of {...}? I've been searching on Visualizers, but I think that is something else.
Visual Studio, had this functionality say 10 years ago or so and I found it very handy (autoexp.dat). I don't use VS anymore but I think it might now be called Native Visualizer (NatVis). I even found that that Boost provides these XML files to visualizing objects in their library. (https://svn.boost.org/trac/boost/wiki/DebuggerVisualizers). No mention of Eclipse, which is an indication that the answer is no.
Edit: I'm looking for a solution for C/C++ (specifically for Code Composer Studio actually).
Below josivan does have a solution for Java though.
If you want to show details during debug you can do something like
Window > Preferences > Java > Debug > Detail Formatters
Click in Add, Choose your class. In area "Detail formatter code snippet" you define what you want. For example:
return "[r: " + real + ", i: " + imag + "]";
On debug Perpective you can see details of your class.
Take a look in the imagem bellow.
In eclipse help you can get more details. And here are a good article about it.

problems with prefs.get and set ImageJ Macro

I'm trying to write a macro to save preferences and read them after closing and reopening ImageJ.
The saving works, but the macro isn't reading the file. Moreover when I try to use one of these two lines an error occurs that the variable "Prefs" is unknown.
int myNumber = Prefs.get("my.persistent.number", 0);
Prefs.savePreferences();
What am I doing wrong? please help me :-)
The ImageJ macro language itself does not support storing custom preferences. (Only the set of built-in options (accessible via Edit > Options in the menu) can be saved, restored and adjusted.) You need to resort to calling the Java class via call("ij.Prefs.get", "my.persistent.number", "0");.
The following ImageJ macro works in an up-to-date Fiji/ImageJ installation:
myNumber = call("ij.Prefs.get", "my.persistent.number", "0");
print(myNumber);
call("ij.Prefs.set", "my.persistent.number", 3);
In the first run, it prints 0; every following run will print 3; after restarting Fiji, it will print 3 again. In case it does not work for you even after updating to the newest version, please report a bug via Help > Report a bug, which will also submit essential information about your installation to the developers to help them fix the issue.
Using one of the many scripting languages however, you can access the ij.Prefs java class directly, as you are trying to do it. Just do not forget to import the class before using it. This is an example Javascript:
importClass(Packages.ij.Prefs);
myNumber = Prefs.get("my.persistent.number", 0);
Prefs.set("my.persistent.number", myNumber);
Hope that helps.

Unicode and PDF tooltips / messageboxes with iTextSharp

I need to find a way to add a quite long string in a quite small space in a PDF document.
I am using iTextSharp. I have already tried adding comment annotations (balloons) with PdfAnnotation.CreateText() and I didn't like the way they looked/worked. It made the page too heavy (I had many comments per page) and their behavior was odd in many ways (thank Adobe for that).
Now I was thinking of adding some simple tooltips on 'chunks' in the page or popping-up messageboxes with javascript (like illustrated here : http://www.codehacker.com/ITEXTSHARP/chap15.aspx#). To my great disappointment however, it seems that Acrobat (?) doesn't support Unicode characters in those situations. E.g. I do this:
var javascript = new PdfAnnotation(
w, 200f, 550f, 300f, 650f,
PdfAction.JavaScript("app.alert('" + "Αρνάκι άσπρο και παχύ!" + "');\r", w));
chunk.SetAnnotation(javascript);
...and, in the best case, a messagebox with gibberish pops up when the user clicks on the chunk.
Is there any setting for making Unicode acceptable for the code above or another way to do what I want?
EDIT:
I have now seen this: https://stackoverflow.com/a/163065/964053
and I've tried modifying my code like that:
var javascript = new PdfAnnotation(
w, 200f, 550f, 300f, 650f,
PdfAction.JavaScript((char)0xFEFF + "app.alert('" + "Αρνάκι άσπρο και παχύ!" + "');\r", w));
chunk.SetAnnotation(javascript);
But nothing seems to change...
EDIT2 :
Using octal representation e.g. (\141) doesn't seem to help either...
EDIT3 :
This seems to work nice until you double clink on it, but I need to make the tooltip size itself based on the contents size:
var lToolTip = PdfFormField.CreatePopup(
w, new Rectangle(tc.Left, tc.Bottom, tc.Right, tc.Top), val, true);
chunk.SetAnnotation(lToolTip);
The rectangle provided doesn't seem to be used in any way...
Any ideas?
I don't know what PdfFormField.CreatePopup() is supposed to create, but I see a small mark on my page that displays a popup when you hover the mouse over it.
I'm kind of lost in your edits, it's not clear what works for you and what doesn't, but regarding the unicode problem in JavaScript: are you aware that there are two versions of the javaScript() method?
See javaScript(java.lang.String, com.itextpdf.text.pdf.PdfWriter, boolean)
If you add the boolean value true, the JavaScript string should be interpreted as Unicode. If this doesn't solve your problem, I'll delete this answer, and if you clarify your question (cutting away the irrelevant parts), I'll do another attempt.

how to stop macros running when opening a Word document using OLE Interop?

As the title suggests, I have a .Net application which uses interop to open documents in Word. I have set
app.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable
before opening the document. According to the documentation, thhis "Disables all macros in all files opened programmatically, without showing any security alerts"
However, when I attempt to open one specific document I get a dialog box on the screen that says "could not load an object because it is not available on this machine". It's a customer document but I believe it contains a macro with references to a COM object which I don't have installed.
Am I doing something stupid? is there any way to actually disable macros when opening a Word document?
Try:
WordBasic.DisableAutoMacros 1
Bizarrely, this relies on a throwback to pre-VBA days, but still seems to be the most-reliable way to ensure that no auto macros are triggered (in any document - you may want to turn it back using the parameter "0").
I recently had a project where I had to process 6,000 Word templates (yes, templates, not documents) many of which had oddball stuff like macros, etc. I was able to process all but 6 using this technique. (I never did figure out what the problem was with those 6).
EDIT: for a discussion of how to call this from C#, see: http://www.dotnet247.com/247reference/msgs/56/281785.aspx
For c# you can use
(_wordApp.WordBasic as dynamic).DisableAutoMacros();
The whole code I'm using is:
using Word = Microsoft.Office.Interop.Word;
private Word.Application _wordApp;
...
_wordApp = new Word.Application
{
Visible = false,
ScreenUpdating = false,
DisplayAlerts = Word.WdAlertLevel.wdAlertsNone,
FileValidation = MsoFileValidationMode.msoFileValidationSkip
};
_wordApp.Application.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;
(_wordApp.WordBasic as dynamic).DisableAutoMacros();