OSDN Git Service

タブで分けるようにしたけどテスト不足
authorazyobuzin <azyobuzin@users.sourceforge.jp>
Thu, 19 May 2011 14:22:00 +0000 (23:22 +0900)
committerazyobuzin <azyobuzin@users.sourceforge.jp>
Thu, 19 May 2011 14:22:00 +0000 (23:22 +0900)
HatenaDiaryClient/HatenaDiaryClient.csproj
HatenaDiaryClient/Models/Model.cs
HatenaDiaryClient/Models/Settings.cs
HatenaDiaryClient/Models/Tab.cs [new file with mode: 0644]
HatenaDiaryClient/ViewModels/MainWindowViewModel.cs
HatenaDiaryClient/Views/MainWindow.xaml

index e35136a..549a62b 100644 (file)
@@ -70,6 +70,7 @@
       <SubType>Designer</SubType>
     </ApplicationDefinition>
     <Compile Include="Models\Settings.cs" />
+    <Compile Include="Models\Tab.cs" />
     <Compile Include="ViewModels\SettingsWindowViewModel.cs" />
     <Compile Include="Views\SettingsWindow.xaml.cs">
       <DependentUpon>SettingsWindow.xaml</DependentUpon>
index f09cf7c..cc4f10e 100644 (file)
@@ -18,7 +18,8 @@ namespace Azyobuzi.HatenaDiaryClient.Models
 
         internal Model()
         {
-            Editing = new BlogItem();
+            this.Tabs = new DispatcherCollection<Tab>(DispatcherHelper.UIDispatcher);
+            this.Tabs.Add(new Tab() { Editing = new BlogItem(), TitleText = "新規" });
         }
 
         private Settings settings;
@@ -70,12 +71,14 @@ namespace Azyobuzi.HatenaDiaryClient.Models
         private HatenaDiary diary = new HatenaDiary();
         private HatenaFotolife fotolife = new HatenaFotolife();
 
-        public BlogItem Editing { private set; get; }
+        public DispatcherCollection<Tab> Tabs { private set; get; }
 
-        public void Post()
+        public void Post(Tab tab)
         {
-            var re = diary.PostEntry(this.Editing.Title, this.Editing.Content);
-            this.Editing.Entry = re;
+            var re = diary.PostEntry(tab.Editing.Title, tab.Editing.Content);
+            tab.Editing.Entry = re;
+            tab.TitleText = re.Title;
+            tab.Modified = false;
         }
     }
 }
index 4f52265..a7e9fd4 100644 (file)
@@ -7,7 +7,7 @@ using Livet;
 
 namespace Azyobuzi.HatenaDiaryClient.Models
 {
-    public class Settings : NotifyObject, ICloneable
+    public class Settings : NotifyObject
     {
         private static readonly string settingsFile =
             Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) + @"\settings.xml";
@@ -68,11 +68,5 @@ namespace Azyobuzi.HatenaDiaryClient.Models
                 xs.Serialize(sw, this);
             }
         }
-
-        public object Clone()
-        {
-            this.Save();
-            return Load();
-        }
     }
 }
diff --git a/HatenaDiaryClient/Models/Tab.cs b/HatenaDiaryClient/Models/Tab.cs
new file mode 100644 (file)
index 0000000..aa6f4e8
--- /dev/null
@@ -0,0 +1,63 @@
+using System.ComponentModel;
+using Livet;
+
+namespace Azyobuzi.HatenaDiaryClient.Models
+{
+    class Tab : NotifyObject
+    {
+
+        BlogItem _Editing;
+
+        public BlogItem Editing
+        {
+            get
+            { return _Editing; }
+            set
+            {
+                if (_Editing == value)
+                    return;
+                if (this._Editing != null)
+                    this._Editing.PropertyChanged -= this.Editing_PropertyChanged;
+                _Editing = value;
+                this._Editing.PropertyChanged += this.Editing_PropertyChanged;
+                RaisePropertyChanged("Editing");
+            }
+        }
+
+        private void Editing_PropertyChanged(object sender, PropertyChangedEventArgs e)
+        {
+            this.Modified = true;
+        }
+        
+        string _TitleText;
+
+        public string TitleText
+        {
+            get
+            { return _TitleText; }
+            set
+            {
+                if (_TitleText == value)
+                    return;
+                _TitleText = value;
+                RaisePropertyChanged("TitleText");
+            }
+        }
+        
+        bool _Modified;
+
+        public bool Modified
+        {
+            get
+            { return _Modified; }
+            set
+            {
+                if (_Modified == value)
+                    return;
+                _Modified = value;
+                RaisePropertyChanged("Modified");
+            }
+        }
+      
+    }
+}
index 3e90155..774c07c 100644 (file)
@@ -65,15 +65,32 @@ namespace Azyobuzi.HatenaDiaryClient.ViewModels
             }
         }
 
-        public BlogItem Editing
+        public DispatcherCollection<Tab> Tabs
         {
             get
             {
-                return model.Editing;
+                return this.model.Tabs;
             }
         }
 
         
+        Tab _SelectedTab;
+
+        public Tab SelectedTab
+        {
+            get
+            { return _SelectedTab; }
+            set
+            {
+                if (_SelectedTab == value)
+                    return;
+                _SelectedTab = value;
+                RaisePropertyChanged("SelectedTab");
+            }
+        }
+      
+
+        
         #region PostCommand
         DelegateCommand _PostCommand;
 
@@ -89,12 +106,14 @@ namespace Azyobuzi.HatenaDiaryClient.ViewModels
 
         private bool CanPost()
         {
-            return this.model.SetIdPassword && !string.IsNullOrEmpty(this.Editing.Content);
+            return this.model.SetIdPassword &&
+                this.SelectedTab != null &&
+                !string.IsNullOrEmpty(this.SelectedTab.Editing.Content);
         }
 
         private void Post()
         {
-            this.model.Post();
+            this.model.Post(this.SelectedTab);
         }
         #endregion
         
index 2ebe78b..f4c9ccb 100644 (file)
@@ -28,7 +28,6 @@
         <Grid.RowDefinitions>
             <RowDefinition Height="auto"/>
             <RowDefinition Height="auto"/>
-            <RowDefinition Height="auto"/>
             <RowDefinition/>
         </Grid.RowDefinitions>
         
                 </StackPanel>
             </Button>
         </WrapPanel>
-        
-        <Grid Grid.Row="2" Background="LightBlue">            
-            <Grid.ColumnDefinitions>
-                <ColumnDefinition Width="auto"/>
-                <ColumnDefinition/>
-            </Grid.ColumnDefinitions>
-            
-            <TextBlock Grid.Column="0" Text="タイトル :" Margin="3,3,3,3" VerticalAlignment="Center" Foreground="White"/>
-            <TextBox Grid.Column="1" Margin="3,3,3,3" Text="{Binding Editing.Title, UpdateSourceTrigger=PropertyChanged}"/>
-        </Grid>
-        
-        <TextBox Grid.Row="3" TextWrapping="Wrap" AcceptsReturn="True" AcceptsTab="True" Text="{Binding Editing.Content, UpdateSourceTrigger=PropertyChanged}"/>
+
+        <TabControl Grid.Row="2" ItemsSource="{Binding Tabs}" SelectedItem="{Binding SelectedTab}">
+            <TabControl.ItemTemplate>
+                <DataTemplate>
+                    <DataTemplate.Resources>
+                        <Style x:Key="ModifiedText" TargetType="TextBlock">
+                            <Style.Triggers>
+                                <DataTrigger Binding="{Binding Modified}" Value="True">
+                                    <DataTrigger.Setters>
+                                        <Setter Property="Text" Value="*"/>
+                                    </DataTrigger.Setters>
+                                </DataTrigger>
+                            </Style.Triggers>
+                        </Style>
+                    </DataTemplate.Resources>
+                    
+                    <StackPanel Orientation="Horizontal">
+                        <TextBlock Text="{Binding TitleText}"/>
+                        <TextBlock Style="{StaticResource ModifiedText}" />
+                    </StackPanel>
+                </DataTemplate>
+            </TabControl.ItemTemplate>
+            <TabControl.ContentTemplate>
+                <DataTemplate>
+                    <Grid>
+                        <Grid.RowDefinitions>
+                            <RowDefinition Height="auto"/>
+                            <RowDefinition/>
+                        </Grid.RowDefinitions>
+                        
+                        <Grid Grid.Row="0" Background="LightBlue">
+                            <Grid.ColumnDefinitions>
+                                <ColumnDefinition Width="auto"/>
+                                <ColumnDefinition/>
+                            </Grid.ColumnDefinitions>
+
+                            <TextBlock Grid.Column="0" Text="タイトル :" Margin="3,3,3,3" VerticalAlignment="Center" Foreground="White"/>
+                            <TextBox Grid.Column="1" Margin="3,3,3,3" Text="{Binding Editing.Title, UpdateSourceTrigger=PropertyChanged}"/>
+                        </Grid>
+
+                        <TextBox Grid.Row="1" TextWrapping="Wrap" AcceptsReturn="True" AcceptsTab="True" Text="{Binding Editing.Content, UpdateSourceTrigger=PropertyChanged}"/>
+                    </Grid>
+                </DataTemplate>
+            </TabControl.ContentTemplate>
+        </TabControl>
     </Grid>
 </Window>