If I have multiple classes in one file, is there a tool to make them into separate files? - objective-c

Some colleagues, now departed, had the habit of adding new classes within a related class file.
This makes refactoring painful.
Is there a tool, perhaps within XCode or AppCode or just a simple script, that will split up these monster files?

It appears there is a tool to help with this in AppCode, but it only semi-automates the process.
I'm using AppCode 2.0, I don't know if the same tool is available in AppCode 1.x.
To extract one class from a file to a new file, right-click the#interface or #implementation line and select Refactor > Move. Alternatively press F6 on that line. You can now enter a new file name, though you probably want to copy+paste the class name in here. At this point you can also select any defines you want to move.
I have done some work on a script to extract all classes in a file. I'd love to share this one day, when I get the chance to remove our clients code from the unit tests!

I don't think so there is any tool for this. However you can write your own osx application for doing the same.
The application will ask to browse the file, and it will search for #interface....#endand#implementation....~#end` and will create a file from this. If a single file contains two classes then it will result in for files (two headers and two implementation). Then the original file can be deleted manually or automatically.
I think this above task can be completed in few hours.
Here you can go for save the original file in a folder, just in case you want to rollback.

Related

Edit files as if concatenated as one -- Do any IDEs or text editors have this feature?

Background: I am working with Angular (but my problem is not particular to any language or framework). In Angular, each component requires four separate files. So, we often find ourselves with 40+ files open. But, most of these files can be tiny, less than 20 lines each.
Many IDEs allow you to open your files in multiple windows. Each window can have a different panel, and each panel can have different tabs. This is great, but honestly, still isn't enough.
What I want: In addition to windows, panels, and tabs, I'd like to add another level of organization.
I speculate this has probably existed for decades, but I just don't know what it's called. At the very least, I speculate this has existed at least since Angular was a thing.
For example, here is a screenshot of VSCode with four files open across four panels. (Code taken from Angular dynamic component tutorial):
And here is a quick mockup showing what I'm looking for. Four files are open, but the three shortest ones are "concatenated" into one editor. Arrow-key down from the bottom of one file will bring you to the first line of the next file.
Notably, these files are not actually concatenated on-disk.
TLDR: What text editor can allow me to edit multiple files as if they were concatenated, as in the mockup above?
If the files stay as separate windows/tabs, the file editor would have to shrink each tab to a minimal height, and then tile them vertically. If any editor can do it, I suspect it would be emacs or vim. You might also be able to do it by opening separate editor windows and using a tiling window manager.
We can achieve a similar effect with some text editing magic. It would be something like:
Add a header to each file consisting of a unique separator (e.g. # === magic separator === filename my_file.js ===)
Use cat to combine all the files into one file
Edit this one file
When done, use the separator to break them up and put the text back into the original files
You could easily write some scripts for combining and splitting so you can do it quickly. You can also set up a background script that automatically runs the splitter as you edit the combined file. However, the combined file would essentially be a new file, so you could not view changes on it with git, and VS Code's CodeLens/Inline blame wouldn't work.
One option would be to develop your codebase with the combined files checked in to VCS, and then only have the splitter script as part of your "build" step. So you would make your changes, run ./build.sh which splits the files into some temp directory, and then run your application from there.
Lastly, and I hate to be snide, but the fact is that this problem is best solved by avoiding poorly designed frameworks that do not consider developer ergonomics. Many other languages give the developer much freedom and many tools to organize their code as they wish, rather than imposing constraints like requiring many small components to be in separate files. Java for example also had a similar problem (dunno if more recent versions fixed it) - you can only have one class per file, which creates a huge mess if you like having many small files. C# does not have this limitation and as a result C# codebases can be much tidier than Java codebases.

How to open and modify .gtk plugin

I have found a plugin (EELSTools.gtk from http://www.dmscripting.com) which I want to modify.
The plugin contains nearly every function I need, but I want also to integrate some extra functions.
Does anyone know how to open .gtk files?
You can't and shouldn't.
*.gtk files are packages files with the purpose of encapsulation. This might either be because of convenience, but it might as well be, because the author does not want to make the code open-source. (Note that there are some proprietory plugins as well, they are also .gtk files.)
If you have found a plugin and want to expand on it, the best way forward is to contact the plugin-author.
The *.gtk files get loaded before *.s files. If you install your own script from DM Menu Install Script File or Install Script, you can add it to the menu that the *.gtk file has, e.g. EELSTools. It is added at the end of the list. For example, I put a measure ZLP width script in EELSTools.

How to rename a file in IntelliJ without finding usages?

I am developing a Node.js project in IntelliJ.
The only way to rename files seems to be Shift+F6 which attempts to find all usages which takes too long (~30s - 1min).
Is there a way to simply rename the file without searching for usages?
This only happens when code is stored in Modules (which is necessary to be able to compact empty middle packages).
Best way I have found is to map ALT+SHIFT+F6 to Reveal in Finder. Then just press enter and type in new name.
It's good because its very similar to SHIFT+F6 rename refactor.
No.
IntelliJ must find the usages to rename them, otherwise you're just renaming the file, not refactoring. If you only want to rename the file, use the mv command from a terminal. You can also tell IntelliJ not to look in strings and text, which speeds things up somewhat, but is probably a bad idea in a javascript project (where almost everything is string or text).
I use rename a lot, and on my codebase, which is pretty big, it only takes a couple of seconds. Maybe intellij needs more memory to operate in, so you could try increasing that.
If You are doing it many times, You can create a custom scope for the refactoring:
There You can narrow the scope to few files/folders/modules etc. And for very narrow scope it will work as normal rename.

How to fork a project in objective-c

Say you create a project. Then you want to do something else. You want to create another project that uses all the files of the previous project. You then modify it a little bit.
In vb.net it's simple. You just copy the vbproj file and that's it.
In objective-c copying the xcproj will result in a project file that won't compile.
Solution?
Note:
I do not want to do simple copy. If I do simple copy changes will not be propagated. I want if the fork change so will the original file.
As far as I know changing the project file name will make the project fail to compile. So just copying the project file doesn't work unless I do something wrong.
I think it's utterly ridiculous that there is no easy way to make the project work after changing the name of the xcodeproj file? I can't even open that xcodeproj file in textedit. In vb.net I can hack the project file straight. Why not in xcode?
There are two options which I would prefer :-
If there are classes which are constant and are not changing, you can make library which is called as Cocoa Touch Static Library
OR
Just copy folder to another location, rename application name and changes you want to do and run it!
Hope this info helps you..
I long for the day when you can simply choose "save as template" from Xcode(!)
In the meantime it might save you some headache to check out Project Duplicator from the AppStore. I haven't tried it out myself yet, but it sounds like it's designed to do exactly what you're asking for.
If you want to do it the manually way you could duplicate the folder with all corresponding files in the Finder and go about renaming everything from there.
You can create multiple targets for your project.
look at this link.

Implement a self extracting archive?

I know i can use 7z or winrar but i want to learn this for myself.
How would i implement a self extracting archive? I can use C# or C++ but let me run down the problem.
When i open the exe i need some kind of GUI asking where to extract the files. Once the user says ok I should obviously extract them. I implemented a simple example in C# winforms already BUT my problem is HOW do i get the filenames and binary of the files into an exe?
One upon a time i ask Is it safe to add extra data to end of exe? and the answer suggested if i just add data to the end of the exe it may be picked up by a virus scanner. Now its pretty easy to write the length of the archive as the last 4bytes and just append the data to my generic exe and i do believe my process can read my own exe so this could work. But it feels hacky and i rather not have people accuse me of writing virus just because i am using this technique. Whats the proper way to implement this?
Note: I checked the self-extracting tag and many of the question is how to manipulate self extracting and not how to implement. Except this one which is asking something else Self-extracting self-checking executable
-edit- I made two self extracting with 7z and compared them. It looks like... well it IS the 7z.sfx file but with a regular 7z archive appended. So... there is nothing wrong with doing this? Is there a better way? I'm targeting windows and can use the C# compiler to help but i don't know how much extra work or how difficult it may be programmatically and maybe adding data to end of exe isnt bad?
It is possible. I used the following technique once, when we needed to distribute updates for the application, but the computers were configured so that the end user had no permissions to change application files. The update was supposed to log on to administrator account and update required files (so we came across identical problem: how to distribute many files as a single executable).
The solution were file resources in C#. All you need to do is:
Create a resource file in your C# project (file ending with .resx).
Add new resource of type "file". You can easily add existing files as byte[] resources.
In program you can simply extract resource as file:
System.IO.FileStream file = new System.IO.FileStream("C:\\PathToFile",
System.IO.FileMode.OpenOrCreate);
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(file);
writer.Write(UpdateApplication.Data.DataValue, 0, UpdateApplication.Data.DataValue.Length);
(Here UpdateApplication.Data denotes binary resource).
Our solution lacked compression, but I believe this is easily achieved with libraries such as C#ZipLib.
I hope this solution is virus-scanner-safe, as this method creates complete, valid executable file.