Skip to content

Commit

Permalink
Opening project from single file is possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
atakansarioglu committed Oct 21, 2018
1 parent 043e2a1 commit b8a632a
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 94 deletions.
1 change: 1 addition & 0 deletions BigBug/BigBug.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
</Compile>
<Compile Include="IniFile.cs" />
<Compile Include="Program.cs" />
<Compile Include="ProjectScanner.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SerialReceiver.cs" />
<Compile Include="Settings.cs" />
Expand Down
46 changes: 22 additions & 24 deletions BigBug/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 31 additions & 57 deletions BigBug/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public MainForm()
// Restore Baud rate and MaxDataRows from the settings.
textBaud.Text = (settings.LoadSetting("General.Baud") != "") ? settings.LoadSetting("General.Baud") : "9600";
int maxDataRowsSetting = 0;
if (int.TryParse(settings.LoadSetting("General.MaxDataRows"), out maxDataRowsSetting))
if (int.TryParse(settings.LoadSetting("User.MaxDataRows"), out maxDataRowsSetting))
maxDataRows = maxDataRowsSetting;
selectedPort = settings.LoadSetting("General.Port");

Expand All @@ -76,13 +76,29 @@ public MainForm()
private void buttonNewProject_Click(object sender, EventArgs e)
{
// Load Recent opened folder and set it to the folder browser initial path.
browserNewProject.SelectedPath = settings.LoadSetting("General.Recent");
browserNewProject.SelectedPath = settings.LoadSetting("General.RecentProject");

// Show browser.
if (browserNewProject.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// If a folder selected, send a click event to RefreshProject button.
buttonRefreshProject_Click(null, null);
// Get supported file extensions.
string supportedFileExtensionsString = (settings.LoadSetting("User.FileExtensions") != "") ? settings.LoadSetting("User.FileExtensions") : Properties.Resources.supportedFileExtensions;
string[] supportedFileExtensions = supportedFileExtensionsString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

// Use ProjectScanner to scan all files.
if (!ProjectScanner.Scan(browserNewProject.SelectedPath, supportedFileExtensions, ref bbCodeBase))
{
MessageBox.Show("No BBCode Descriptor has been found under the selected path.");
}

// Remember the project name including the number of recognized BBCode entries.
projectName = Path.GetFileName(browserNewProject.SelectedPath) + " #" + bbCodeBase.GetCodeCount();

// Set visuals for ProjectOpen state.
SetVisuals(GetVisuals() | VisualStates.ProjectOpen);

// Save teh successfuly opened project path.
settings.SaveSetting("General.RecentProject", browserNewProject.SelectedPath);
}
}

Expand Down Expand Up @@ -224,74 +240,32 @@ private void buttonSave_Click(object sender, EventArgs e)
}

/**
* @brief Opens or re-opens a project from the selected location and scans all BBCode descriptors to fill the BBCodeBase.
* @brief Opens a single-file project from the selected location and scans all BBCode descriptors to fill the BBCodeBase.
* @param sender
* @param e
*/
private void buttonRefreshProject_Click(object sender, EventArgs e)
private void buttonNewSingleFileProject_Click(object sender, EventArgs e)
{
string selectedProjectPath = "";
string[] fileList = { };

try
{
// Open the
selectedProjectPath = Path.GetFileName(browserNewProject.SelectedPath);
fileList = Directory.GetFiles(browserNewProject.SelectedPath, "*.*", SearchOption.AllDirectories);
}
catch { };
// Load Recent opened folder and set it to the folder browser initial path.
browserOpenSingleFile.FileName = settings.LoadSetting("General.RecentSingleFile");

// Get the selected path and make sure that its not empty.
if (selectedProjectPath != "")
// Show browser.
if (browserOpenSingleFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// Get supported file extensions.
string supportedFileExtensionsString = (settings.LoadSetting("General.FileExtensions") != "") ? settings.LoadSetting("General.FileExtensions") : Properties.Resources.supportedFileExtensions;
string[] supportedFileExtensions = supportedFileExtensionsString.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);

// Create an empty BBCode database.
bbCodeBase = new BBCodeBase();

// Iterate all files under the selected path.
foreach (string fileName in fileList)
// Use ProjectScanner to scan the selected file.
if (!ProjectScanner.Scan(browserOpenSingleFile.FileName, new string[] { }, ref bbCodeBase))
{
// Check the file extension for allowed extensions.
if (File.Exists(fileName) && supportedFileExtensions.Contains(Path.GetExtension(fileName).TrimStart('.')))
{
// Open the file as text.
StreamReader sr = File.OpenText(fileName);

// Get pure, relative file name.
string sourceFile = fileName.Replace(browserNewProject.SelectedPath, "");

// Iterate all lines until the end.
string lineText;
int lineNumber = 0;
while (!sr.EndOfStream)
{
// Read single line.
lineText = sr.ReadLine();
lineNumber++;

// Try to parse the line with descriptor parser. Result is not null if successful.
BBCodeObject bbCode = BBCodeDescriptorParser.Parse(lineText, sourceFile, lineNumber);

// Add to the database (only if not null).
bbCodeBase.AddBBCode(bbCode);
}

// Close the file.
sr.Close();
}
MessageBox.Show("No BBCode Descriptor has been found under the selected path.");
}

// Remember the project name including the number of recognized BBCode entries.
projectName = Path.GetFileName(browserNewProject.SelectedPath) + " #" + bbCodeBase.GetCodeCount();
projectName = Path.GetFileName(browserOpenSingleFile.FileName) + " #" + bbCodeBase.GetCodeCount();

// Set visuals for ProjectOpen state.
SetVisuals(GetVisuals() | VisualStates.ProjectOpen);

// Save teh successfuly opened project path.
settings.SaveSetting("General.Recent", browserNewProject.SelectedPath);
settings.SaveSetting("General.RecentSingleFile", browserOpenSingleFile.FileName);
}
}

Expand Down
10 changes: 5 additions & 5 deletions BigBug/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="openFile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>664, 17</value>
</metadata>
<metadata name="timerSerialPortListUpdate.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>434, 17</value>
</metadata>
Expand All @@ -130,10 +127,13 @@
<value>206, 17</value>
</metadata>
<metadata name="sp.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>779, 17</value>
<value>664, 17</value>
</metadata>
<metadata name="saveFile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>851, 17</value>
<value>736, 17</value>
</metadata>
<metadata name="browserOpenSingleFile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>845, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>76</value>
Expand Down
Loading

0 comments on commit b8a632a

Please sign in to comment.