2012-08-26 19:03:12 +00:00
using System ;
using System.Drawing ;
using System.IO ;
2012-09-01 16:30:35 +00:00
using System.Linq ;
2012-08-26 19:03:12 +00:00
using System.Windows.Forms ;
using ANX.ContentCompiler.GUI.Dialogues ;
2012-08-29 19:02:13 +00:00
using ANX.Framework.Content.Pipeline ;
using ANX.Framework.Content.Pipeline.Tasks ;
2012-09-10 19:10:39 +00:00
using ANX.Framework.NonXNA.Development ;
2012-08-26 19:03:12 +00:00
namespace ANX.ContentCompiler.GUI
{
2012-09-10 19:10:39 +00:00
[Developer("SilentWarrior/Eagle Eye Studios")]
[PercentageComplete(71)] //TODO: Implement parameter handling, Tour, HelpButton, WebsiteButton, Preview!
[TestState(TestStateAttribute.TestState.InProgress)]
2012-08-26 19:03:12 +00:00
public partial class MainWindow : Form
{
#region Fields
2012-09-10 19:10:39 +00:00
2012-08-26 19:03:12 +00:00
public static String DefaultOutputPath = "bin" ;
2012-09-10 19:10:39 +00:00
public static String SettingsFile =
Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) ,
"ANX Content Compiler" + Path . DirectorySeparatorChar + "settings.ees" ) ;
2012-08-27 19:09:10 +00:00
private readonly bool _firstStart = true ;
2012-08-29 19:02:13 +00:00
private ContentProject _contentProject ;
2012-09-10 19:10:39 +00:00
private Point _lastPos ;
private bool _menuMode ;
private bool _mouseDown ;
2012-08-26 19:03:12 +00:00
#endregion
#region Properties
2012-09-10 19:10:39 +00:00
2012-08-26 19:03:12 +00:00
public static MainWindow Instance { get ; private set ; }
public String ProjectName { get ; set ; }
public String ProjectPath { get ; set ; }
public String ProjectFolder { get ; set ; }
public String ProjectOutputDir { get ; set ; }
public String ProjectImportersDir { get ; set ; }
2012-09-09 15:44:49 +00:00
public RecentProjects RecentProjects { get ; set ; }
2012-09-10 19:10:39 +00:00
2012-08-26 19:03:12 +00:00
#endregion
2012-08-27 19:09:10 +00:00
#region Init
2012-09-10 19:10:39 +00:00
public MainWindow ( string [ ] args )
2012-08-26 19:03:12 +00:00
{
InitializeComponent ( ) ;
Instance = this ;
2012-08-27 19:09:10 +00:00
_firstStart = ! File . Exists ( SettingsFile ) ;
if ( _firstStart )
2012-08-28 21:14:49 +00:00
{
2012-08-27 19:09:10 +00:00
Settings . Defaults ( ) ;
2012-08-28 21:14:49 +00:00
Settings . Save ( SettingsFile ) ;
2012-09-09 15:44:49 +00:00
RecentProjects = new RecentProjects ( ) ;
RecentProjects . Save ( ) ;
2012-08-28 21:14:49 +00:00
}
2012-08-27 19:09:10 +00:00
else
2012-09-09 15:44:49 +00:00
{
2012-08-27 19:09:10 +00:00
Settings . Load ( SettingsFile ) ;
2012-09-09 15:44:49 +00:00
RecentProjects = RecentProjects . Load ( ) ;
}
2012-08-26 19:03:12 +00:00
treeViewItemAddFolder . MouseEnter + = TreeViewItemMouseEnter ;
treeViewItemAddFolder . MouseLeave + = TreeViewItemeLeave ;
treeViewItemDelete . MouseEnter + = TreeViewItemMouseEnter ;
treeViewItemRename . MouseEnter + = TreeViewItemMouseEnter ;
2012-08-27 19:09:10 +00:00
SetUpColors ( ) ;
}
private void MainWindowShown ( object sender , EventArgs e )
{
if ( _firstStart )
ShowFirstStartStuff ( ) ;
ChangeEnvironmentStartState ( ) ;
2012-08-26 19:03:12 +00:00
}
2012-09-10 19:10:39 +00:00
2012-08-26 19:03:12 +00:00
#endregion
#region NewProject
2012-09-10 19:10:39 +00:00
2012-08-29 15:57:35 +00:00
public void NewProject ( object sender , EventArgs e )
2012-08-26 19:03:12 +00:00
{
using ( var dlg = new NewProjectScreen ( ) )
{
if ( dlg . ShowDialog ( ) = = DialogResult . OK )
{
ProjectName = dlg . textBoxName . Text ;
2012-09-10 19:10:39 +00:00
ProjectFolder = ! String . IsNullOrEmpty ( dlg . textBoxLocation . Text )
? dlg . textBoxLocation . Text
: Path . Combine ( Settings . DefaultProjectPath , ProjectName ) ;
2012-08-29 19:02:13 +00:00
ProjectPath = Path . Combine ( ProjectFolder , ProjectName + ".cproj" ) ;
2012-08-26 19:03:12 +00:00
}
else
{
return ;
}
}
using ( var dlg2 = new NewProjectOutputScreen ( ) )
{
if ( dlg2 . ShowDialog ( ) = = DialogResult . OK )
{
2012-09-10 19:10:39 +00:00
ProjectOutputDir = ! String . IsNullOrEmpty ( dlg2 . textBoxLocation . Text )
? dlg2 . textBoxLocation . Text
: Path . Combine ( ProjectFolder , DefaultOutputPath ) ;
2012-08-26 19:03:12 +00:00
}
else
return ;
}
using ( var dlg3 = new NewProjectImportersScreen ( ) )
{
if ( dlg3 . ShowDialog ( ) = = DialogResult . OK )
ProjectImportersDir = dlg3 . textBoxLocation . Text ;
else
return ;
}
2012-09-10 19:10:39 +00:00
bool importersEnabled = ! String . IsNullOrEmpty ( ProjectImportersDir ) ;
int importers = 0 ;
int processors = 0 ;
2012-08-26 19:03:12 +00:00
2012-09-10 19:10:39 +00:00
using (
var dlg4 = new NewProjectSummaryScreen ( ProjectName , ProjectFolder , ProjectOutputDir , importersEnabled ,
ProjectImportersDir , importers , processors ) )
2012-08-26 19:03:12 +00:00
{
dlg4 . ShowDialog ( ) ;
}
2012-08-29 19:02:13 +00:00
_contentProject = new ContentProject ( ProjectName )
{
OutputDirectory = ProjectOutputDir ,
2012-09-01 16:30:35 +00:00
InputDirectory = ProjectFolder ,
2012-08-29 19:02:13 +00:00
Configuration = "Release" ,
Creator = "ANX Content Compiler (4.0)" ,
ContentRoot = "Content" ,
Platform = TargetPlatform . Windows
} ;
2012-08-26 19:03:12 +00:00
ChangeEnvironmentOpenProject ( ) ;
}
2012-09-10 19:10:39 +00:00
2012-08-26 19:03:12 +00:00
#endregion
2012-08-28 21:14:49 +00:00
#region OpenProject
2012-09-10 19:10:39 +00:00
2012-08-30 22:02:16 +00:00
public void OpenProjectDialog ( object sender , EventArgs e )
2012-08-28 21:14:49 +00:00
{
using ( var dlg = new OpenProjectScreen ( ) )
{
2012-09-09 15:44:49 +00:00
if ( dlg . ShowDialog ( ) ! = DialogResult . OK ) return ;
if ( dlg . listBoxRecentProjects . SelectedItem = = null )
2012-08-30 22:02:16 +00:00
OpenProject ( dlg . textBoxLocation . Text ) ;
2012-09-09 15:44:49 +00:00
else
2012-09-10 19:10:39 +00:00
OpenProject ( ( string ) dlg . listBoxRecentProjects . SelectedItem ) ;
2012-08-28 21:14:49 +00:00
}
}
2012-09-10 19:10:39 +00:00
2012-08-30 22:02:16 +00:00
public void OpenProject ( string path )
{
if ( ! File . Exists ( path ) )
2012-09-09 15:44:49 +00:00
{
MessageBox . Show ( "No file found at this location: " + path , "Project not found" ) ;
return ;
}
2012-08-30 22:02:16 +00:00
_contentProject = ContentProject . Load ( path ) ;
ProjectName = _contentProject . Name ;
ProjectOutputDir = _contentProject . OutputDirectory ;
ProjectFolder = _contentProject . InputDirectory ;
ProjectImportersDir = _contentProject . ReferenceIncludeDirectory ;
ProjectPath = path ;
if ( string . IsNullOrEmpty ( _contentProject . Creator ) )
_contentProject . Creator = "ANX Content Compiler (4.0)" ;
ChangeEnvironmentOpenProject ( ) ;
}
2012-09-10 19:10:39 +00:00
2012-08-28 21:14:49 +00:00
#endregion
2012-08-29 19:02:13 +00:00
#region SaveProject
2012-09-10 19:10:39 +00:00
2012-08-29 19:02:13 +00:00
public void SaveProject ( object sender , EventArgs e )
{
2012-09-08 22:31:50 +00:00
if ( _contentProject = = null ) return ;
2012-08-29 19:02:13 +00:00
if ( String . IsNullOrEmpty ( ProjectPath ) )
SaveProjectAs ( sender , e ) ;
_contentProject . Save ( ProjectPath ) ;
2012-09-09 15:44:49 +00:00
if ( RecentProjects . Contains ( ProjectPath ) )
RecentProjects . Remove ( ProjectPath ) ;
RecentProjects . Add ( ProjectPath ) ;
2012-08-29 19:02:13 +00:00
}
2012-09-10 19:10:39 +00:00
2012-08-29 19:02:13 +00:00
#endregion
#region SaveProjectAs
2012-09-10 19:10:39 +00:00
2012-08-29 19:02:13 +00:00
public void SaveProjectAs ( object sender , EventArgs e )
{
using ( var dlg = new SaveFileDialog ( ) )
{
dlg . Title = "Save project as" ;
dlg . AddExtension = true ;
dlg . Filter = "ANX Content Project (*.cproj)|*.cproj|Compressed Content Project (*.ccproj)|*.ccproj" ;
if ( dlg . ShowDialog ( ) = = DialogResult . OK )
{
ProjectPath = dlg . FileName ;
SaveProject ( sender , e ) ;
}
}
}
2012-09-10 19:10:39 +00:00
#endregion
#region CleanProject
public void CleanProject ( )
{
if ( Directory . Exists ( ProjectOutputDir ) )
Directory . Delete ( ProjectOutputDir , true ) ;
}
2012-08-29 19:02:13 +00:00
#endregion
2012-09-09 15:44:49 +00:00
#region BuildProject
2012-09-10 19:10:39 +00:00
2012-09-09 15:44:49 +00:00
public void BuildProject ( object sender , EventArgs e )
{
DisableUI ( ) ;
2012-09-10 19:10:39 +00:00
var builderTask = new BuildContent
{
BuildLogger = new CCompilerBuildLogger ( ) ,
OutputDirectory = _contentProject . OutputDirectory ,
TargetPlatform = _contentProject . Platform ,
TargetProfile = _contentProject . Profile ,
CompressContent = false
} ;
2012-09-09 15:44:49 +00:00
try
{
2012-09-10 19:10:39 +00:00
foreach ( var dir in _contentProject . BuildItems . Select ( buildItem = > Path . GetDirectoryName ( buildItem . OutputFilename ) ) . Where ( dir = > ! Directory . Exists ( dir ) ) )
{
Directory . CreateDirectory ( dir ) ;
}
2012-09-09 15:44:49 +00:00
builderTask . Execute ( _contentProject . BuildItems ) ;
2012-09-10 19:10:39 +00:00
ribbonTextBox . AddMessage ( "[Info] Build process successfully finished." ) ;
2012-09-09 15:44:49 +00:00
}
2012-09-10 19:10:39 +00:00
catch ( Exception ex )
2012-09-09 15:44:49 +00:00
{
2012-09-10 19:10:39 +00:00
ribbonTextBox . AddMessage ( "[ERROR] " + ex + "\n Stack: " + ex . StackTrace ) ;
2012-09-09 15:44:49 +00:00
EnableUI ( ) ;
}
EnableUI ( ) ;
}
private void DisableUI ( )
{
buttonMenu . Enabled = false ;
buttonQuit . Enabled = false ;
editingState . Enabled = false ;
treeView . Enabled = false ;
propertyGrid . Enabled = false ;
ribbonButtonNew . Enabled = false ;
ribbonButtonSave . Enabled = false ;
ribbonButtonLoad . Enabled = false ;
ribbonButtonClean . Enabled = false ;
}
private void EnableUI ( )
{
buttonMenu . Enabled = true ;
buttonQuit . Enabled = true ;
editingState . Enabled = true ;
treeView . Enabled = true ;
propertyGrid . Enabled = true ;
ribbonButtonNew . Enabled = true ;
ribbonButtonSave . Enabled = true ;
ribbonButtonLoad . Enabled = true ;
ribbonButtonClean . Enabled = true ;
}
2012-09-10 19:10:39 +00:00
2012-09-09 15:44:49 +00:00
#endregion
2012-09-01 16:30:35 +00:00
#region FileMethods
2012-09-10 19:10:39 +00:00
/// <summary>
/// Adds a file to the project
/// </summary>
/// <param name="file">the file to add</param>
2012-09-01 16:30:35 +00:00
private void AddFile ( string file )
{
if ( ! File . Exists ( file ) )
throw new FileNotFoundException ( ) ;
2012-09-10 19:10:39 +00:00
string folder = _contentProject . ContentRoot ;
TreeNode node = treeView . SelectedNode ;
2012-09-01 16:30:35 +00:00
if ( node ! = null )
folder = node . Name ;
2012-09-10 19:10:39 +00:00
string absPath = ProjectFolder + Path . DirectorySeparatorChar + folder + Path . DirectorySeparatorChar +
Path . GetFileName ( file ) ;
2012-09-01 16:30:35 +00:00
if ( ! Directory . Exists ( Path . Combine ( ProjectFolder , folder ) ) )
Directory . CreateDirectory ( Path . Combine ( ProjectFolder , folder ) ) ;
2012-09-08 22:03:13 +00:00
File . Copy ( file , absPath , true ) ;
2012-09-01 16:30:35 +00:00
var item = new BuildItem
{
2012-09-10 19:10:39 +00:00
AssetName =
folder . Equals ( _contentProject . ContentRoot )
? Path . GetFileNameWithoutExtension ( file )
: folder . Replace ( _contentProject . ContentRoot + Path . DirectorySeparatorChar , "" ) +
Path . DirectorySeparatorChar + Path . GetFileNameWithoutExtension ( file ) ,
2012-09-01 16:30:35 +00:00
SourceFilename = absPath ,
2012-09-10 19:10:39 +00:00
OutputFilename =
ProjectOutputDir + Path . DirectorySeparatorChar + folder + Path . DirectorySeparatorChar +
Path . GetFileNameWithoutExtension ( file ) + ".xnb" , //<- Change this if you want some other extension (i.e. to annoy modders or whatever)
ImporterName = ImporterManager . GuessImporterByFileExtension ( file ) //,
//ProcessorName = ProcessorManager.GuessImporterByFileExtension(file) //<- This still needs to be implemented, Pipeline devs! *poke*
2012-09-01 16:30:35 +00:00
} ;
_contentProject . BuildItems . Add ( item ) ;
}
2012-09-10 19:10:39 +00:00
/// <summary>
/// Wrapper for adding moar files! (Just a foreach loop, nothing special)
/// </summary>
/// <param name="files">files to add</param>
2012-09-01 16:30:35 +00:00
public void AddFiles ( string [ ] files )
{
2012-09-10 19:10:39 +00:00
foreach ( string file in files )
2012-09-01 16:30:35 +00:00
{
AddFile ( file ) ;
}
ChangeEnvironmentOpenProject ( ) ;
}
2012-09-08 22:03:13 +00:00
public void AddFolder ( string name )
{
string folder = _contentProject . ContentRoot ;
2012-09-10 19:10:39 +00:00
TreeNode node = treeView . SelectedNode ;
2012-09-08 22:03:13 +00:00
if ( node ! = null )
folder = node . Name ;
else
node = treeView . Nodes [ 0 ] ;
2012-09-10 19:10:39 +00:00
var newFolder = new TreeNode ( name ) { Name = folder + Path . DirectorySeparatorChar + name } ;
2012-09-08 22:03:13 +00:00
node . Nodes . Add ( newFolder ) ;
}
public void RemoveFile ( string name )
{
}
public void RemoveFiles ( string [ ] files )
{
}
public void RemoveFolder ( string name )
{
}
2012-09-10 19:10:39 +00:00
2012-09-01 16:30:35 +00:00
#endregion
2012-08-26 19:03:12 +00:00
#region EnvironmentStates
2012-09-10 19:10:39 +00:00
/// <summary>
/// Changes the current editor state to the "No project open" state
/// </summary>
2012-08-27 19:09:10 +00:00
public void ChangeEnvironmentStartState ( )
2012-08-26 19:03:12 +00:00
{
editingState . Visible = false ;
startState . Visible = true ;
Text = "ANX Content Compiler 4" ;
labelTitle . Text = "ANX Content Compiler 4" ;
2012-09-01 16:30:35 +00:00
treeView . Nodes . Clear ( ) ;
propertyGrid . SelectedObject = null ;
2012-08-26 19:03:12 +00:00
}
2012-09-10 19:10:39 +00:00
/// <summary>
/// Changes the current editor state to edit mode
/// </summary>
2012-08-27 19:09:10 +00:00
public void ChangeEnvironmentOpenProject ( )
2012-08-26 19:03:12 +00:00
{
startState . Visible = false ;
editingState . Visible = true ;
Text = ProjectName + " - ANX Content Compiler 4" ;
labelTitle . Text = "ANX Content Compiler 4 - " + ProjectName ;
2012-09-01 16:30:35 +00:00
ProjectFolder = _contentProject . InputDirectory ;
treeView . Nodes . Clear ( ) ;
2012-09-10 19:10:39 +00:00
var rootNode = new TreeNode ( ProjectName + "(" + _contentProject . ContentRoot + ")" )
{ Name = _contentProject . ContentRoot } ;
2012-09-01 16:30:35 +00:00
treeView . Nodes . Add ( rootNode ) ;
2012-09-10 19:10:39 +00:00
TreeNode lastNode = rootNode ;
//aaaand here comes the nasty part. Watch out, it bites...um bugs!
foreach (
var parts in
_contentProject . BuildItems . Select (
buildItem = > buildItem . AssetName . Split ( Path . DirectorySeparatorChar ) ) . Where (
parts = > parts . Length > = 2 ) ) //all BuildItems which names contain more than two elements (ContentRoot + FileName), Split by SeperatorChar (=> platform independent coding :))
2012-09-01 16:30:35 +00:00
{
2012-09-08 22:03:13 +00:00
string folder = "" ;
string parent = _contentProject . ContentRoot ;
2012-09-10 19:10:39 +00:00
for ( int i = 0 ; i < parts . Length - 1 ; i + + ) //Examine everything between ContentRoot and fileName. If we find something, add a folder!
2012-09-01 16:30:35 +00:00
{
2012-09-10 19:10:39 +00:00
if ( parts [ i ] = = null ) continue ;
if ( i > 0 ) //if there is already a path we need to add the new part with a SeperatorChar!
2012-09-08 22:03:13 +00:00
folder + = Path . DirectorySeparatorChar + parts [ i ] ;
2012-09-01 16:30:35 +00:00
else
2012-09-10 19:10:39 +00:00
folder = parts [ 0 ] ; //Yay! We are first! Let's make ourselves comfortable here!
2012-09-08 22:03:13 +00:00
2012-09-10 19:10:39 +00:00
if ( parts . Length > 2 & & i < parts . Length - 2 ) // if we have more than two parts we have another parent than the content root!
2012-09-08 22:03:13 +00:00
parent + = Path . DirectorySeparatorChar + parts [ i ] ;
//else if (parts.Length == 2)
2012-09-10 19:10:39 +00:00
// parent += Path.DirectorySeparatorChar + parts[0];
2012-09-08 22:03:13 +00:00
}
2012-09-10 19:10:39 +00:00
lastNode = treeView . RecursiveSearch ( parent ) ; //Search for parent node! Often an Exception Candidate! Check the 'parent' var then.
var node = new TreeNode ( parts [ parts . Length - 2 ] )
{ Name = _contentProject . ContentRoot + Path . DirectorySeparatorChar + folder } ; //Finally glue a new folder node together
2012-09-08 22:03:13 +00:00
if ( ! ContainsTreeNode ( lastNode , node ) )
{
2012-09-10 19:10:39 +00:00
lastNode . Nodes . Add ( node ) ; // If the folder is new, add it - else it's just wasted memory :)
2012-09-01 16:30:35 +00:00
}
lastNode = rootNode ;
}
2012-09-10 19:10:39 +00:00
if ( _contentProject . BuildItems . Count > 0 ) //Only do this when there are items, it'll get nasty soon if there isn't one!
2012-09-01 16:30:35 +00:00
{
2012-09-10 19:10:39 +00:00
foreach ( BuildItem buildItem in _contentProject . BuildItems )
2012-09-01 16:30:35 +00:00
{
2012-09-10 19:10:39 +00:00
String [ ] parts = null ; //Split by seperator char
2012-09-01 16:30:35 +00:00
if ( buildItem . AssetName . Contains ( "\\" ) )
parts = buildItem . AssetName . Split ( '\\' ) ;
else if ( buildItem . AssetName . Contains ( "/" ) )
parts = buildItem . AssetName . Split ( '/' ) ;
/ * if ( parts . Length > = 2 )
{
for ( int i = 0 ; i < parts . Length - 1 ; i + + )
{
lastNode = lastNode . Nodes [ parts [ i ] ] ;
}
} * /
2012-09-10 19:10:39 +00:00
//Add the actual files to the tree in their apropriate subdirs
2012-09-08 22:03:13 +00:00
string path = _contentProject . ContentRoot ;
2012-09-10 19:10:39 +00:00
if ( parts ! = null )
2012-09-01 16:30:35 +00:00
{
for ( int i = 0 ; i < parts . Length - 1 ; i + + )
{
2012-09-08 22:03:13 +00:00
path + = String . IsNullOrEmpty ( path ) ? parts [ i ] : Path . DirectorySeparatorChar + parts [ i ] ;
2012-09-01 16:30:35 +00:00
}
}
2012-09-08 22:03:13 +00:00
if ( parts ! = null )
2012-09-01 16:30:35 +00:00
{
2012-09-10 19:10:39 +00:00
TreeNode node = treeView . RecursiveSearch ( path ) ;
2012-09-01 16:30:35 +00:00
if ( node = = null ) throw new ArgumentNullException ( "Node not found!" ) ;
var item = new TreeNode ( parts [ parts . Length - 1 ] ) { Name = buildItem . AssetName } ;
node . Nodes . Add ( item ) ;
}
2012-09-10 19:10:39 +00:00
else //if the node is "forever alone", put him into the rootNode to make some friends!
2012-09-01 16:30:35 +00:00
{
var item = new TreeNode ( buildItem . AssetName ) { Name = buildItem . AssetName } ;
treeView . Nodes [ 0 ] . Nodes . Add ( item ) ;
}
}
}
2012-08-26 19:03:12 +00:00
}
2012-09-10 19:10:39 +00:00
2012-08-26 19:03:12 +00:00
#endregion
#region ButtonHandlers
2012-09-10 19:10:39 +00:00
2012-08-26 19:03:12 +00:00
private void ButtonQuitClick ( object sender , EventArgs e )
{
Application . Exit ( ) ;
}
2012-09-10 19:10:39 +00:00
2012-08-27 19:09:10 +00:00
private void ButtonMenuClick ( object sender , EventArgs e )
{
ToggleMenuMode ( ) ;
}
2012-09-10 19:10:39 +00:00
private void RibbonButtonCleanClick ( object sender , EventArgs e )
{
if ( ! Directory . Exists ( ProjectOutputDir ) ) return ;
if ( MessageBox . Show (
"You are about to delete stuff you previously built! That already built content will be lost forever (which is a very long time!). Still want to continue?" ,
"Delete Output?" , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) = = DialogResult . Yes )
{
CleanProject ( ) ;
MessageBox . Show ( "Your build directory has been emptied. Goodbye Files!" , "Success" , MessageBoxButtons . OK ,
MessageBoxIcon . Information ) ;
}
}
2012-08-26 19:03:12 +00:00
#endregion
#region WindowMoveMethods
2012-09-10 19:10:39 +00:00
2012-08-26 19:03:12 +00:00
private void LabelTitleMouseMove ( object sender , MouseEventArgs e )
{
2012-08-27 19:09:10 +00:00
if ( ! _mouseDown ) return ;
2012-09-10 19:10:39 +00:00
int xoffset = MousePosition . X - _lastPos . X ;
int yoffset = MousePosition . Y - _lastPos . Y ;
2012-08-26 19:03:12 +00:00
Left + = xoffset ;
Top + = yoffset ;
2012-08-27 19:09:10 +00:00
_lastPos = MousePosition ;
2012-08-26 19:03:12 +00:00
}
private void LabelTitleMouseDown ( object sender , MouseEventArgs e )
{
2012-08-27 19:09:10 +00:00
_mouseDown = true ;
_lastPos = MousePosition ;
2012-08-26 19:03:12 +00:00
}
private void LabelTitleMouseUp ( object sender , MouseEventArgs e )
{
2012-08-27 19:09:10 +00:00
_mouseDown = false ;
2012-08-26 19:03:12 +00:00
}
2012-09-10 19:10:39 +00:00
2012-08-26 19:03:12 +00:00
#endregion
#region TreeVieItemDesignMethods
2012-09-10 19:10:39 +00:00
private void TreeViewItemeLeave ( object sender , EventArgs e )
2012-08-26 19:03:12 +00:00
{
2012-09-10 19:10:39 +00:00
( ( ToolStripItem ) sender ) . BackColor = Color . FromArgb ( 0 , 64 , 64 , 64 ) ;
2012-08-26 19:03:12 +00:00
}
2012-09-10 19:10:39 +00:00
private void TreeViewItemMouseEnter ( object sender , EventArgs e )
2012-08-26 19:03:12 +00:00
{
2012-09-10 19:10:39 +00:00
( ( ToolStripItem ) sender ) . BackColor = Color . Green ;
2012-08-26 19:03:12 +00:00
}
2012-09-10 19:10:39 +00:00
2012-08-26 19:03:12 +00:00
#endregion
2012-08-27 19:09:10 +00:00
#region MenuMethods
2012-09-10 19:10:39 +00:00
2012-08-27 19:09:10 +00:00
public void ToggleMenuMode ( )
{
_menuMode = ! _menuMode ;
if ( _menuMode )
{
buttonMenu . BackColor = Settings . AccentColor3 ;
menuState . Visible = true ;
}
else
{
menuState . Visible = false ;
buttonMenu . BackColor = Settings . AccentColor ;
}
}
#endregion
#region ShowFirstStartStuff
2012-09-10 19:10:39 +00:00
2012-08-27 19:09:10 +00:00
private void ShowFirstStartStuff ( )
{
using ( var dlg = new FirstStartScreen ( ) )
{
if ( dlg . ShowDialog ( ) = = DialogResult . OK )
{
}
}
}
2012-09-10 19:10:39 +00:00
2012-08-27 19:09:10 +00:00
#endregion
#region SetUpColors
2012-09-10 19:10:39 +00:00
2012-08-27 19:09:10 +00:00
private void SetUpColors ( )
{
BackColor = Settings . MainColor ;
ForeColor = Settings . ForeColor ;
buttonQuit . FlatAppearance . MouseOverBackColor = Settings . LightMainColor ;
buttonQuit . FlatAppearance . MouseDownBackColor = Settings . AccentColor ;
buttonMenu . BackColor = Settings . AccentColor ;
buttonMenu . FlatAppearance . MouseOverBackColor = Settings . AccentColor2 ;
buttonMenu . FlatAppearance . MouseDownBackColor = Settings . AccentColor3 ;
labelTitle . ForeColor = Settings . ForeColor ;
labelProperties . ForeColor = Settings . ForeColor ;
labelFileTree . ForeColor = Settings . ForeColor ;
treeView . BackColor = Settings . DarkMainColor ;
propertyGrid . BackColor = Settings . DarkMainColor ;
propertyGrid . ForeColor = Settings . ForeColor ;
propertyGrid . HelpBackColor = Settings . MainColor ;
propertyGrid . LineColor = Settings . MainColor ;
propertyGrid . ViewBackColor = Settings . DarkMainColor ;
propertyGrid . ViewForeColor = Settings . ForeColor ;
}
2012-09-10 19:10:39 +00:00
2012-08-27 19:09:10 +00:00
#endregion
2012-08-29 15:57:35 +00:00
#region Exit
2012-09-10 19:10:39 +00:00
2012-08-29 15:57:35 +00:00
private void MainWindowFormClosed ( object sender , FormClosedEventArgs e )
{
Settings . Save ( SettingsFile ) ;
2012-09-09 15:44:49 +00:00
RecentProjects . Save ( ) ;
2012-08-29 15:57:35 +00:00
}
private void MainWindowFormClosing ( object sender , FormClosingEventArgs e )
{
}
2012-09-10 19:10:39 +00:00
2012-08-29 15:57:35 +00:00
#endregion
2012-09-01 16:30:35 +00:00
#region TreeViewEvents
2012-09-10 19:10:39 +00:00
2012-09-01 16:30:35 +00:00
private void TreeViewAfterSelect ( object sender , TreeViewEventArgs e )
{
if ( treeView . SelectedNode = = treeView . TopNode )
propertyGrid . SelectedObject = _contentProject ;
else
{
2012-09-10 19:10:39 +00:00
foreach (
BuildItem buildItem in
_contentProject . BuildItems . Where (
buildItem = > buildItem . AssetName . Equals ( treeView . SelectedNode . Name ) ) )
2012-09-01 16:30:35 +00:00
{
propertyGrid . SelectedObject = buildItem ;
}
}
}
2012-09-08 22:03:13 +00:00
private bool ContainsTreeNode ( TreeNode haystack , TreeNode needle )
{
return haystack . Nodes . Cast < TreeNode > ( ) . Any ( node = > node . Name . Equals ( needle . Name ) ) ;
}
2012-09-01 16:30:35 +00:00
#endregion
#region PropertyGridEvents
2012-09-10 19:10:39 +00:00
2012-09-01 16:30:35 +00:00
private void PropertyGridPropertyValueChanged ( object s , PropertyValueChangedEventArgs e )
{
ProjectName = _contentProject . Name ;
ProjectImportersDir = _contentProject . ReferenceIncludeDirectory ;
ProjectFolder = _contentProject . InputDirectory ;
ProjectOutputDir = _contentProject . OutputDirectory ;
if ( e . ChangedItem . Label . Equals ( "ContentRoot" ) )
{
foreach ( BuildItem buildItem in _contentProject . BuildItems )
{
2012-09-10 19:10:39 +00:00
buildItem . AssetName = buildItem . AssetName . Replace ( ( string ) e . OldValue , _contentProject . ContentRoot ) ;
2012-09-01 16:30:35 +00:00
}
2012-09-10 19:10:39 +00:00
treeView . Nodes [ 0 ] . RecursivelyReplacePartOfName ( ( string ) e . OldValue , _contentProject . ContentRoot ) ;
2012-09-01 16:30:35 +00:00
}
ChangeEnvironmentOpenProject ( ) ;
}
2012-09-10 19:10:39 +00:00
2012-09-01 16:30:35 +00:00
#endregion
2012-09-10 19:10:39 +00:00
2012-08-26 19:03:12 +00:00
}
}