# **************************************************************************** #
#                                                                              #
#                                                         :::      ::::::::    #
#    JulooCpp.py                                        :+:      :+:    :+:    #
#                                                     +:+ +:+         +:+      #
#    By: jaguillo <jaguillo@student.42.fr>          +#+  +:+       +#+         #
#                                                 +#+#+#+#+#+   +#+            #
#    Created: 2015/04/07 14:14:38 by jaguillo          #+#    #+#              #
#    Updated: 2015/04/08 18:20:12 by jaguillo         ###   ########.fr        #
#                                                                              #
# **************************************************************************** #

import sublime, sublime_plugin

class JulooCppCommand(sublime_plugin.TextCommand):

	def run(self, edit, **args):
		pattern = """
#include "%(hpp)s"

%(class)s::%(class)s(void)
{
}

%(class)s::%(class)s(%(class)s const &src)
{
	*this = src;
}

%(class)s::~%(class)s(void)
{
}

%(class)s			&%(class)soperator=(%(class)s const &rhs)
{
	// *this = rhs;
	return (*this);
}
"""
		name = self.view.file_name().split('/')[-1]
		className = name.split('.')[0]
		name = name.replace(".cpp", ".hpp")
		self.view.run_command("juloo_write", {"point": 0, "data": pattern % {'hpp': name, 'class': className}})
		self.view.run_command("juloo_header", {"action": "insert"})

class JulooHppCommand(sublime_plugin.TextCommand):

	def run(self, edit, **args):
		pattern = """
#ifndef %(hdef)s
# define %(hdef)s

class	%(class)s
{
public:
	%(class)s(void);
	%(class)s(%(class)s const &src);
	~%(class)s(void);

	%(class)s			&operator=(%(class)s const &rhs);

private:
};

#endif
"""
		name = self.view.file_name().split('/')[-1]
		className = name.split('.')[0]
		name = ''.join([i if ord(i) >= ord('A') and ord(i) <= ord('Z') else '_' for i in name.upper()])
		self.view.run_command("juloo_write", {"point": 0, "data": pattern % {'hdef': name, 'class': className}})
		self.view.run_command("juloo_header", {"action": "insert"})

@@ -668,18 +668,18 @@
 04/0
-8 18:20:12
+9 16:55:49
  by 
@@ -1184,16 +1184,17 @@
 (class)s
+:
 operator
@@ -1758,16 +1758,24 @@
 &src);%0A%09
+virtual 
 ~%25(class
@@ -1833,16 +1833,28 @@
 &rhs);%0A%0A
+protected:%0A%0A
 private:

Add virtual keyword for destructor