ModPlus.AutoCAD.Module.2016 by modplus.org

<PackageReference Include="ModPlus.AutoCAD.Module.2016" Version="10.0.0" />

 MpDrawings

using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.ApplicationServices.Core; using Autodesk.AutoCAD.Internal; using Autodesk.AutoCAD.Runtime; using ModPlusAPI; using ModPlusAPI.Windows.Helpers; using System; using System.CodeDom.Compiler; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Controls; using System.Windows.Input; namespace ModPlus { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] internal class MpDrawings { private readonly DocumentCollection _docs = Application.get_DocumentManager(); [System.Runtime.CompilerServices.Nullable(0)] internal Image ImgIcon; [System.Runtime.CompilerServices.Nullable(0)] internal TextBlock TbHeader; [System.Runtime.CompilerServices.Nullable(0)] internal StackPanel ExpOpenDrawings; [System.Runtime.CompilerServices.Nullable(0)] internal ListBox Drawings; [System.Runtime.CompilerServices.Nullable(0)] internal Button BtCloseDwg; private bool _contentLoaded; internal unsafe MpDrawings() : this() { if (double.TryParse(RegistryUtils.GetValue("DrawingsWinTop"), out double result)) this.set_Top(result); else this.set_Top(180); if (double.TryParse(RegistryUtils.GetValue("DrawingsWinLeft"), out double result2)) this.set_Left(result2); else this.set_Left(60); InitializeComponent(); WindowHelpers.ChangeStyleForResourceDictionary(this.get_Resources()); Language.SetLanguageProviderForResourceDictionary(this.get_Resources()); this.add_MouseEnter(new MouseEventHandler((object)this, (IntPtr)(void*))); this.add_MouseLeave(new MouseEventHandler((object)this, (IntPtr)(void*))); this.add_MouseLeftButtonDown(new MouseButtonEventHandler((object)this, (IntPtr)(void*))); Application.get_DocumentManager().add_DocumentCreated(new DocumentCollectionEventHandler((object)this, (IntPtr)(void*))); Application.get_DocumentManager().add_DocumentDestroyed(new DocumentDestroyedEventHandler((object)this, (IntPtr)(void*))); Application.get_DocumentManager().add_DocumentActivated(new DocumentCollectionEventHandler((object)this, (IntPtr)(void*))); GetDocuments(); OnMouseLeaving(); } private void DocumentManager_DocumentActivated(object sender, DocumentCollectionEventArgs e) { GetDocuments(); CheckUnused(); } private unsafe void GetDocuments() { Drawings.remove_SelectionChanged(new SelectionChangedEventHandler((object)this, (IntPtr)(void*))); try { Drawings.get_Items().Clear(); foreach (Document doc in _docs) { Document val = doc; ListBoxItem val2 = new ListBoxItem(); string fileName = Path.GetFileName(val.get_Name()); val2.set_Content((object)fileName); val2.set_ToolTip((object)val.get_Name()); Drawings.get_Items().Add((object)val2); Drawings.set_SelectedItem((object)val2); } } catch { } finally { Drawings.add_SelectionChanged(new SelectionChangedEventHandler((object)this, (IntPtr)(void*))); } } private void CheckUnused() { try { foreach (ListBoxItem item in (IEnumerable)Drawings.get_Items()) { ListBoxItem val = item; if (val.get_Content().Equals(Path.GetFileName(_docs.get_MdiActiveDocument().get_Name())) & val.get_ToolTip().Equals(_docs.get_MdiActiveDocument().get_Name())) Drawings.set_SelectedItem((object)val); } } catch { } } private void DocumentManager_DocumentDestroyed(object sender, DocumentDestroyedEventArgs e) { GetDocuments(); CheckUnused(); } private void DocumentManager_DocumentCreated(object sender, DocumentCollectionEventArgs e) { GetDocuments(); CheckUnused(); } private void Window_MouseEnter(object sender, MouseEventArgs e) { if (_docs.get_Count() > 0) { ImgIcon.set_Visibility(2); TbHeader.set_Visibility(0); ExpOpenDrawings.set_Visibility(0); ExpOpenDrawings.set_Visibility(0); if (_docs.get_Count() != Drawings.get_Items().get_Count()) { string[] array = new string[_docs.get_Count()]; string[] docnames = new string[_docs.get_Count()]; int num = 0; foreach (Document doc in _docs) { Document val = doc; string fileName = Path.GetFileName(val.get_Name()); array.SetValue(fileName, num); docnames.SetValue(val.get_Name(), num); num++; } using (IEnumerator<ListBoxItem> enumerator2 = (from ListBoxItem lbi in (IEnumerable)Drawings.get_Items() where !docnames.Contains(lbi.get_ToolTip()) select lbi).GetEnumerator()) { if (enumerator2.MoveNext()) { ListBoxItem current = enumerator2.Current; Drawings.get_Items().Remove((object)current); } } } try { Drawings.get_Items().Clear(); foreach (Document doc2 in _docs) { Document val2 = doc2; ListBoxItem val3 = new ListBoxItem(); string fileName2 = Path.GetFileName(val2.get_Name()); val3.set_Content((object)fileName2); val3.set_ToolTip((object)val2.get_Name()); Drawings.get_Items().Add((object)val3); } } catch { } try { using (IEnumerator<ListBoxItem> enumerator4 = (from ListBoxItem lbi in (IEnumerable)Drawings.get_Items() where lbi.get_ToolTip().ToString() == _docs.get_MdiActiveDocument().get_Name() select lbi).GetEnumerator()) { if (enumerator4.MoveNext()) { ListBoxItem current2 = enumerator4.Current; Drawings.set_SelectedItem((object)current2); } } } catch { } this.Focus(); } } private void Window_MouseLeave(object sender, MouseEventArgs e) { if (_docs.get_Count() > 0) OnMouseLeaving(); } private void OnMouseLeaving() { if (Variables.get_DrawingsFloatMenuCollapseTo().Equals(0)) { ImgIcon.set_Visibility(0); TbHeader.set_Visibility(2); } else { ImgIcon.set_Visibility(2); TbHeader.set_Visibility(0); } ExpOpenDrawings.set_Visibility(2); Utils.SetFocusToDwgView(); } private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { this.DragMove(); } private void Drawings_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { ListBoxItem lbi = Drawings.get_SelectedItem(); using (IEnumerator<Document> enumerator = (from Document doc in (IEnumerable)_docs let filename = Path.GetFileName(doc.get_Name()) where (doc.get_Name() == lbi.get_ToolTip().ToString()) & (filename == lbi.get_Content().ToString()) select doc).GetEnumerator()) { if (enumerator.MoveNext()) { Document current = enumerator.Current; if ((DisposableWrapper)_docs.get_MdiActiveDocument() != (DisposableWrapper)null && (DisposableWrapper)_docs.get_MdiActiveDocument() != (DisposableWrapper)current) _docs.set_MdiActiveDocument(current); } } } catch { } } private void BtCloseDwg_Click(object sender, RoutedEventArgs e) { try { if (Drawings.get_SelectedIndex() != -1) { ListBoxItem lbi = Drawings.get_SelectedItem(); using (IEnumerator<Document> enumerator = (from Document doc in (IEnumerable)_docs where doc.get_Name() == lbi.get_ToolTip().ToString() select doc).GetEnumerator()) { if (enumerator.MoveNext()) { Document current = enumerator.Current; if ((DisposableWrapper)_docs.get_MdiActiveDocument() == (DisposableWrapper)current) { Application.get_DocumentManager().get_MdiActiveDocument().SendStringToExecute("_CLOSE ", true, false, false); if (Drawings.get_Items().get_Count() == 1) OnMouseLeaving(); } } } } } catch { } } [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "6.0.4.0")] public void InitializeComponent() { if (!_contentLoaded) { _contentLoaded = true; Uri uri = new Uri("/ModPlus_2016;component/mpdrawings.xaml", UriKind.Relative); Application.LoadComponent((object)this, uri); } } [System.Runtime.CompilerServices.NullableContext(0)] [DebuggerNonUserCode] [GeneratedCode("PresentationBuildTasks", "6.0.4.0")] [EditorBrowsable(EditorBrowsableState.Never)] unsafe void Connect(int connectionId, object target) { switch (connectionId) { case 1: ImgIcon = target; break; case 2: TbHeader = target; break; case 3: ExpOpenDrawings = target; break; case 4: Drawings = target; Drawings.add_SelectionChanged(new SelectionChangedEventHandler((object)this, (IntPtr)(void*))); break; case 5: BtCloseDwg = target; BtCloseDwg.add_Click(new RoutedEventHandler((object)this, (IntPtr)(void*))); break; default: _contentLoaded = true; break; } } } }