Renaming Controller classes in MonoTouch MonoDevelop - xamarin.ios

What is the the best way to rename a class which inherits a UIViewController and has a designer.cs class linked to a storyboard?
I first tried to Rename the .cs file in MonoDevelop. This worked but the designer.cs file did not get renamed with it, and neither did the class name.
I then renamed the class name. This successfully changed the class name in both the .cs and .designer.cs files but still did not change the .designer.cs filename. It also did not change the name of the "Custom Class" for the controller in Xcode.
So in XCode I changed the name of the Custom Class and saved then switched back to MonoDevelop , to my horror it had created a new .cs with the same name as the renamed one and a new .designer.cs file which it put under the original (renamed) .cs file next to the old (not renamed) a.designer.cs file!
Can anyone tell me the sequence of steps I should have taken?

Renaming the file is tricky, since MD doesn't support renaming grouped files. You'd have to manually edit the csproj, or remove the files from the project, rename in Finder, and add them back.
Renaming the class is somewhat easier, but the key is to understand that the class actually has two names - the .NET name, and the Obj-C name. Renaming the .NET name should be easy, you can simply use the rename command in MD.
The Obj-C name is applied to the class on the [Register("SomeName")] attribute, and is the name that's used in xibs and in Xcode. However, beware that MonoDevelop will attempt to create .NET counterparts of any classes that it thinks were created in Xcode. This means you should change the Obj-C name in MonoDevelop first, then switch to Xcode and change the Custom Class there.

You have to go into the .csproj file and add a tag. For example:
<Compile Include="MainWindow.cs" />
<Compile Include="MainWindow.designer.cs">
<DependentUpon>MainWindow.cs</DependentUpon>
</Compile>
This will then show the correct relationship between the files in the MonoDevelop project window.
Incidentally, my experience so far is that this dependency is purely for convenience. Add the new designer.cs file into the solution and the code compiles just fine: dependency seems to be a sort of documentation.
ALSO: To delete or rename these dependent files, you can't do that in the MonoDevelop project pane: you do have to go to Finder (if you're in OSX, Explorer if you're in Windows) and deal with the files there, to rename or otherwise manipulate them, THEN repair the MonoDevelop csproj file by hand. The good news is, it's not hard, and it works fine when you do this, and you get a cool new hardcore understanding about how the project is knit together.

Many people also has to think about the version control system. This way works for me:
Quit MonoDevelop
In the version control system, rename the files
Open the csproj file in a text editor - search&replace
Open MonoDevelop
Open the XxxViewController.cs - search&replace
Open the XxxViewController.designer.cs - search&replace
Open the XxxViewController.xib - search&replace
You might be tempted to use Refactor/Rename instead of search & replace in step 5 but that will cause MonoDevelop to rename XxxViewController.designer.cs to XxxViewController_1.cs for some reason.
Also, you might be tempted to remove the files from the project before renaming them in the version control system and then add them back into your project again (so that you won't have to edit the csproj file manually). This will work but the "DependentUpon" part will disappear from the csproj file, which causes the designer file to not be below its counterpart. No big deal but it looks less nice in the Solution Explorer.

I tried all the solutions above and didn't work. Finally I just used the "Replace in Files" looking the whole solution. After that I did a "Rebuild" in the project and worked fine.

Related

Renaming project name shown in JetBrains Toolbox

I've recently made a new Empty Project in IntelliJ IDEA and added a couple Gradle based modules to it. The project and the modules are under W:\IJ Workspace\ProjectName directory - the project itself is in W:\IJ Workspace\ProjectName\ProjectName folder, and the modules are in W:\IJ Workspace\ProjectName\ModuleName folders.
JetBrains Toolbox shows the project and its correct directory (W:\IJ Workspace\ProjectName\ProjectName) but the name it displays - is the name of first module I created in the project, not ProjectName. Is there any way to change the name Toolbox is displaying for that project? Or is there a way to manually add a project to Toolbox, forcing it to use its actual name?
Do this while IDE is closed (at very least while that project is closed).
Locate a folder with project settings (.idea subfolder, usually that would be PROJECT_ROOT/.idea).
See if you have .name file there. If not -- create new one.
Open that .name file in any text editor and write desired project name there -- it's a plain text file with a single line of text (no new lines).
Save the file and launch IDE.
Next time you open that project is should use the name from that .name file.
P.S. This works in PhpStorm (where IDE also has a special "Rename Project" action) but should work in IntelliJ IDEA (and other IDEA-based IDEs) as well.

javax.microedition.io.file does not exist in BlueJ

Trying j2me app development. I got a simple Hello to work, and a simple TextBox user as well. But when I tried to compile code for a file browser I got "javax.microedition.io.file does not exist".
The WTK according to the Sun website is supposed to include JSR75. And there's a camera demo .java file that uses it.
I've looked in various places (the WTK, BlueJ, even Netbeans) for menu options to turn it on. Nothing. And a search of this forum turned up exactly ONE message and it pertains to another IDE, and it seemed to work for him in BlueJ.
So what am I missing and how do I get it?
In NetBeans, you go to Project Properties (right-click the project, and select Properties). Then click "Platform" and mark "File Connection and PIM Optional Packages 1.0".
On a whim I did a search for JSR75 jar download and found a few zipped jar files that seemed to contain the file classes. I unzipped one of them and put it in the Libraries/Userlib directory of BlueJ; and now I seem to have the File... Classes. Reading and writing seem to work in the emulator.
I'll take another look at Netbeans when I get a chance.

Rename Android Studio project causing a bunch of errors and java files missing

Following some links here I tried to rename a project. I went to c:\path\to\AndroidStudioProject and renamed the folder there, then found the .idea file and changed that. Now the project loads but java files are missing! However, on clicking java (in the bar at the top), then com I can see them each with a small red j.
I then looked in module Gradle build where there were 3 files, one with the new name and 2 older ones which stated that they did not belong so I deleted them, copying the compile info into the new one. Naturally on doing a Sync Now I get a bunch of errors.
Why does this have to be such a complex operation? Can anyone assist?
After you rename the folder, open the project in Android Studio. From there, right click something that needs to be renamed (e.g., module, package names, etc.) and use Refactor->Rename from the context menu. Keep doing this until everything that can be refactored is.
You will need to manually change the value of applicationId in the app-level build.gradle. Obviously, things like #string/app_name will also have to be changed manually. I recommend making these manual adjustments from inside Android Studio rather than directly editing the files. That way you'll know immediately if you break something.

Move solution in Source Control

I have a project under source control in Visual Studio 2012 using TFS2010. When I added this project, the solution was not added in the correct file folder location. I want to move the solution, but every time I try to do it within the Source Control Explorer I encounter an error: "The project file 'path/to/project.csproj' has been moved, renamed, or is not on your computer." What is causing this error? What is the proper way to move the solution to where I want it to be?
Move the solution file in TFS (this is more relevant if you have history you want to maintain)
Open the solution, it will complain that it can't load your projects, either edit the path to the project in the properties window, or remove each project and then re-add it. Check-in your changes
Delete the .suo file and try once. Has helped me in the past. This file is usually hidden. Restart VS after deleting.
The problem is the solution file has relative paths to the project files. I usually do any moving around when I first create the solution (before there are projects in it). However, in your case I would just use Source Control Explorer to move the solution, then edit the .sln file in a text editor and fix up the relative paths to the proj files.

VS2012 Assembly is incorrectly specified as a file

I am getting this warning on assembly references in a VS2012 Winforms application project. In this case the references are for Infragistics controls used by the app, which are located in the bin folder.
This issue has been addressed in the following link, but the answer ("set the Build Action" property) doesn't work because there is no Build Action property in VS2012 for referenced assemblies.
VS2005: Assembly '<assembly>' is incorrectly specified as a file.
What's the fix?
You probably refer to the wrong Assembly.
You need to "set the Build Action" for the Assembly which located in Bin folder, NOT from references.
Go to Solution Explorer > Expand the Bin folder, right click on the
Assembly that give warning, and you should be able to set the Build
Action
Again, it is not the assembly that located in the References panel but it is from Bin Folder
Have you tried removing the references, saving the solution and exiting Visual Studio - then re-opening the solution and re-adding the references?
The problem is almost certainly lurking in the project file (.csproj if this is a C# app) if you fancy opening it up in a text editor and having a look - might also help if you were to paste it here.
Alternatively, have you tried recreate the project from scratch? May be a quicker solution than trying to work out what's happened.

Resources